xmlrpc username/password failures
Hi, I'm trying to get xmlrpc working with usernames and passwords and having some issues. This is on Linux (WBEL3.0R1). First of all with python 2.2.3 which comes with WBEL the following simple code fails (passwords & server names altered to protect the innocent): #!/usr/bin/python import xmlrpclib from xmlrpclib import * test = Server('http://3tier:My&[EMAIL PROTECTED]/Forecast') print test.ReturnSimpleInt() Returns the following error: Traceback (most recent call last): File "./testCondon.py", line 8, in ? print test.ReturnSimpleInt() File "/usr/lib/python2.2/xmlrpclib.py", line 821, in __call__ return self.__send(self.__name, args) File "/usr/lib/python2.2/xmlrpclib.py", line 975, in __request verbose=self.__verbose File "/usr/lib/python2.2/xmlrpclib.py", line 833, in request h = self.make_connection(host) File "/usr/lib/python2.2/xmlrpclib.py", line 862, in make_connection return httplib.HTTP(host) File "/usr/lib/python2.2/httplib.py", line 969, in __init__ self._setup(self._connection_class(host, port, strict)) File "/usr/lib/python2.2/httplib.py", line 491, in __init__ self._set_hostport(host, port) File "/usr/lib/python2.2/httplib.py", line 502, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: 'My&[EMAIL PROTECTED]' Strangely enough, the URL is not considered invalid by Python 2.4 (compiled fresh on WBEL), but I get 401 Unauthorized even though I can cut/paste the URL into my browser (firefox 1.0) and I'm given access...so I *know* it is not a typo: Traceback (most recent call last): File "./testCondon.py", line 8, in ? print test.ReturnSimpleInt() File "/usr/lib/python2.4/xmlrpclib.py", line 1096, in __call__ return self.__send(self.__name, args) File "/usr/lib/python2.4/xmlrpclib.py", line 1383, in __request verbose=self.__verbose File "/usr/lib/python2.4/xmlrpclib.py", line 1137, in request headers xmlrpclib.ProtocolError: The _only_ thing I was able to find in google about this is this one bug: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=944396&group_id=5470 which seems to indicate that username:[EMAIL PROTECTED] is not *actually* an RFC valid syntax. However the xmlrpclib documenation clearly indicates that that is *the* syntax to use: http://docs.python.org/lib/module-xmlrpclib.html What gives? What is the "right" way to do it? Thanks, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: a sequence question
David Isaac wrote: If that is right, I still cannot extract it from the doc cited above. So where should I have looked? Ouch. The terminology's evolved, and it looks to me like the docs for the older builtins haven't been updated to track it. The terminology has pretty much settled to 'iterable' for anything which returns a sensible result from iter(obj), 'iterator' for any iterable which returns itself from iter(obj), 'reiterable' for any iterable which is not an iterator, and 'sequence' for any reiterable which supports len(obj) and integer indexing. That's not the terminology the older docs use, though, even in the most recent versions of that page [1]. For most of them it's OK, since the text clarifies what the term means in context (e.g. that 'sequence' actually means 'iterable' for some function signatures). zip() doesn't do that though - it actually accepts iterables, but only talks about sequences. A bug report on Sourceforge would help in getting the problem fixed for the 2.5 docs (possibly even the 2.4.1 docs if it happens soon). 2.3's a lost cause though, since 2.3.5 is already out the door and only another security bug is likely to trigger a new 2.3 release. For the 'left-to-right' evaluation thing, that's technically an implementation artifact of the CPython implementation, since the zip() docs don't make any promises. So updating the docs to include that information would probably be a bigger issue, as it involves behaviour which is currently not defined by the library. Cheers, Nick. [1] http://www.python.org/dev/doc/devel/lib/built-in-funcs.html -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
Steven Bethard wrote: > Hmmm... This does seem sensible. And sidesteps the issue about > suggesting that subclasses use Namespace.update instead of > namespaceinstance.update -- the latter just won't work! (This is a Good > Thing, IMHO.) Yeah, I thought so too. It also crystallised for me that the real problem was that we were trying to use the attribute namespace for something different from what it is usually used for, and so Python's normal lookup sequence was a hindrance rather than a help. I guess Guido knew what he was doing when he provided the __getattribute__ hook ;) One other point is that dealing correctly with meta-issues like this greatly boosts the benefits from having this module in the standard library. I would expect most of the 'roll-your-own' solutions that are out there deal badly with this issue. "Inherit from namespaces.Namespace" is a simpler instruction than "figure out how to write an appropriate __getattribute__ method". Anyway, it is probably worth digging into the descriptor machinery a bit further in order to design a lookup scheme that is most appropriate for namespaces, but the above example has convinced me that object.__getattribute__ is NOT it :) Yeah, I'm going to look into this a bit more too, but let me know if you have any more insights in this area. My gut feel is that we want to get rid of all the decriptor behaviour for normal names, but keep it for special names. After all, if people actually wanted that machinery for normal attributes, they'd be using a normal class rather than a namespace. I'm also interested in this because I'd like to let the 'Record' class (see below) be able to store anything in the defaults, including descriptors and have things 'just work'. The __getattribute__ I posted comes close to handling that, but we need __setattr__ and __delattr__ as well in order to deal fully with the issue, since override descriptors like property() can affect those operations. Fortunately, they should be relatively trivial: # Module helper function def _isspecial(name): return name.startswith("__") and name.endswith("__") # And in Namespace def __getattribute__(self, name): """Namespaces only use __dict__ and __getattr__ for non-magic attribute names. Class attributes and descriptors like property() are ignored """ getattribute = super(Namespace, self).__getattribute__ try: return getattribute("__dict__")[name] except KeyError: if _isspecial(name) # Employ the default lookup system for magic names return getattribute(name) else: # Skip the default lookup system for normal names if hasattr(self, "__getattr__"): return getattribute("__getattr__")(name) else: raise AttributeError('%s instance has no attribute %s' % (type(self).__name__, name)) def __setattr__(self, name, val): """Namespaces only use __dict__ for non-magic attribute names. Descriptors like property() are ignored""" if _isspecial(name): super(Namespace, self).__setattr__(name, val) else: self.__dict__[name] = val def __delattr__(self, name): """Namespaces only use __dict__ for non-magic attribute names. Descriptors like property() are ignored""" if _isspecial(name): super(Namespace, self).__delattr__(name) else: del self.__dict__[name] In action: Py> def get(self): print "Getting" ... Py> def set(self, val): print "Setting" ... Py> def delete(self): print "Deleting" ... Py> prop = property(get, set, delete) Py> class C(object): ... x = prop ... Py> c = C() Py> c.x Getting Py> c.x = 1 Setting Py> del c.x Deleting Py> class NS(namespaces.Namespace): ... x = prop ... Py> ns = NS() Py> ns.x Traceback (most recent call last): File "", line 1, in ? File "namespaces.py", line 40, in __getattribute__ raise AttributeError('%s instance has no attribute %s' AttributeError: NS instance has no attribute x Py> ns.x = 1 Py> del ns.x Py> ns.__x__ Getting Py> ns.__x__ = 1 Setting Py> del ns.__x__ Deleting I've attached my latest local version of namespaces.py (based on the recent PEP draft) which includes all of the above. Some other highlights are: NamespaceView supports Namespace instances in the constructor NamespaceChain inherits from NamespaceView (as per my last message about that) LockedView is a new class that supports 'locking' a namespace, so you can only modify existing names, and cannot add or remove them NamespaceChain and LockedView are the main reason I modified NamespaceView to directly support namespaces - so that subclassed could easily support using either. Record inherits from LockedView and is designed to make it easy to define and create fully specified "data
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
Nick Coghlan wrote: There *is* a problem with using __getattr__ though - any attribute in the chained namespaces that is shadowed by a class attribute (like 'update') will be picked up from the class, not from the chained namespaces. So we do need to use __getattribute__ to change that lookup order. However, given the amount of grief the default lookup behaviour causes, I think the place to do that is in Namespace itself: class Namespace(object): # otherwise unchanged def __getattribute__(self, name): """Namespaces do NOT default to looking in their class dict for non-magic attributes """ getattribute = super(Namespace, self).__getattribute__ try: return getattribute("__dict__")[name] except KeyError: if name.startswith('__') and name.endswith('__'): # Employ the default lookup system for magic names return getattribute(name) else: # Skip the default lookup system for normal names if hasattr(self, "__getattr__"): return getattribute("__getattr__")(name) else: raise AttributeError(name) Hmmm... This does seem sensible. And sidesteps the issue about suggesting that subclasses use Namespace.update instead of namespaceinstance.update -- the latter just won't work! (This is a Good Thing, IMHO.) Anyway, it is probably worth digging into the descriptor machinery a bit further in order to design a lookup scheme that is most appropriate for namespaces, but the above example has convinced me that object.__getattribute__ is NOT it :) Yeah, I'm going to look into this a bit more too, but let me know if you have any more insights in this area. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? BOM decoded with UTF8
What are you talking about? The BOM and UTF-16 go hand-and-hand. Without a Byte Order Mark, you can't unambiguosly determine whether big or little endian UTF-16 was used. In the old days, UCS-2 was *implicitly* big-endian. It was only when Microsoft got that wrong that little-endian version of UCS-2 came along. So while the BOM is now part of all relevant specifications, it is still "Microsoft crap". For more details, see: http://www.unicode.org/faq/utf_bom.html#BOM "some higher level protocols", "can be useful" - not "is inherent part of all byte-level encodings". Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python UPS / FedEx Shipping Module
Gabriel Cooper said the following on 2/11/2005 2:23 PM: I've made UPS and FedEx shipping rate request modules in python using XML. Is there an interest in putting this on the web? I am interested in it for educational value, if not anything else. Please post the web address from which to download. Thanks! -Kartic -- http://mail.python.org/mailman/listinfo/python-list
connecting to Sybase/MsSQL from python
Hi, I'm hoping someone on the list has connected to sybase/MsSQL with something that works with DBAPI 2.0 from a linux box (SUSE 9.2) because I can't seem to get it done. I found Object Craft's python code that uses FreeTDS. But I can't get it compiled. The code is looking for "sybdb.h" (first error) - of course I don't have "sybdb.h". It is not in Object Crafts code nor in the FreeTDS source. I'm guessing that I need sybase develop lib's but I don't know where they are to be found. So is there a kind sole out there that can help with instructions on what is needed to get python talking to MsSQL. jOHN -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question
Dan Perl wrote: > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hello All, > > What is the python equivalent of the following statement? > > > > while (n--) > > Like other posters said, you should give more details with your question. > What do you mean by equivalent? The following is *functionally* equivalent: > for n in range(start, 0, -1): > > Of course, there is always: > while n: > ... > n -= 1 errrmmm it's a C while stmt with post-decrement; that's NOT the same as: for (; n; n--) ... If n is initially 3, the loop body is executed with n set to 2,1,0 and after exit n is -1. The nearest Python equivalents of "while (n--) func(n);" are (making the charitable assumption that initially n >= 0): ! while n: ! n -= 1 ! func(n) and ! for n in range(n-1, -1, -1): ! func(n) > > But unfortunately, no, I don't think there is an equivalent in python that > has the conciseness of the C statement. The pre- and post-increment > and -decrement in C/C++/Java are very powerful and I miss them in python. Unfortunately?? What are you missing? The ability to write cryptic crap that you don't understand & that's so "powerful" that you can get into deep kaka really quickly? Hope you weren't writing software for embedded devices -- like heart pacemakers :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Commerical graphing packages?
Erik Johnson wrote: I am aware of ChartDirector (http://www.advsofteng.com/ ) which explicitly supports python and seems to be about the right level of sophistication. I don't really know of any other packages in this space, do you? I am seeking feedback and reccomendations from people who have used this package or similar ones. I am particularly interested to hear about any limitations or problems you ran into with whatever package you are using. We use both the Python and C++ bindings of ChartDirector (although their license always spans /all/ supported bindings. It's all pretty straight-forward, well-documented, and the license fee is a bargain compared to other packages we've used in the past. What it is not suitable for is maybe allowing for 3d-views of data cubes - changeable on the fly. -- Vincent Wehren -- http://mail.python.org/mailman/listinfo/python-list
pre-check for string-to-number conversion
I am reading an ASCII data file and converting some of the strings to integers or floats. However, some of the data is corrupted and the conversion doesn't work. I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. I would like to simply perform a pre-check before I do the conversion, but I can't figure out how to do it. I see that strings have a function called isdigit(), but that simply checks whether all characters in the string are digits -- not what I need. Any suggestions? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: listerator clonage
Cyril BAZIN wrote: Hello, I want to build a function which return values which appear two or more times in a list: This is very similar to removing duplicate items from a list which was the subject of a long recent thread, full of suggested approaches. Here's one way to do what you want: >>> l = [1, 7, 3, 4, 3, 2, 1] >>> seen = set() >>> set(x for x in l if x in seen or seen.add(x)) set([1, 3]) >>> This is a 'generator expression' applied as an argument to the set constructor. It relies on the fact that seen.add returns None, and is therefore always false. this is equivalent to: >>> def _generate_duplicates(iterable): ... seen = set() ... for x in iterable: ... if x in seen: # it's a duplicate ... yield x ... else: ... seen.add(x) ... >>> generator = _generate_duplicates(l) >>> generator >>> set(generator) set([1, 3]) >>> # In case you want to preserve the order and number of the duplicates, you >>> # would use a list >>> generator = _generate_duplicates(l) >>> list(generator) [3, 1] >>> So, I decided to write a little example which doesn't work: #l = [1, 7, 3, 4, 3, 2, 1] #i = iter(l) #for x in i: #j = iter(i) #for y in j: #if x == y: #print x In thinked that the instruction 'j= iter(i)' create a new iterator 'j' based on 'i' (some kind of clone). I wrote this little test which show that 'j = iter(i)' is the same as 'j = i' (that makes me sad): I don't think your algorithm would work even if iter(iterator) did return a copy or separate iterator. If, however, you do have an algorithm that needs that capability, you can use itertools.tee Cheers Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
George Sakkis wrote: For the record, here's the arbitrary and undocumented (?) order among some main builtin types: None < 0 == 0.0 < {} < [] < "" < () If you're curious, you can check the source code. Look for default_3way_compare in object.c. Basically the rundown for dissimilar types is: * None is smaller than anything * Numbers (as defined by PyNumber_Check) are smaller than everything else * All other types are compared by type name (and by the address of the type object if the type names are the same). Pretty arbitrary, yeah. ;) Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Big development in the GUI realm
Arich Chanachai wrote: > I have never seen a commercial license for a library which stated that you did not have to pay the license fee until you have made that much money in sales from the software which you created, in part, from that library. I would be in favor of such a license, but I haven't seen anything of the sort. http://www.fastio.com/licensePlain.html See their license option for shareware developers. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
PHP session equivalent?
There are a lot of things about PHP I was not too keen on and hence why my company is primarily doing Python these days, but one thing I was quite impressed with was the ease with which it provided session functionality... And then in another CGI script do basically the same thing and get the value of $my_var back. Setting of a session ID cookie happens automagically. This is quite handy and simple. I don't think it's quite so simple in Python (which is not to say I think PHP is better than Python). Doing a little extra work is no big deal, but could someone be so kind as to lay out what needs to be done for a Python CGI script to get essentially the same functionality? Are there Python modules that implement a lot of this already? We are currently running under an Apache server (on SuSE Linux 8.2). I'm not clear on whether some session functionality is provided there? We may be moving to Zope before too long (trying to find some time to evaluate it), so a method that is not strictly dependent on Apache would be preferable (in the short term that may suffice). Thanks for taking the time to read my post! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: exception handling for a function returning several values
[EMAIL PROTECTED] wrote: If a function that normally returns N values raises an exception, what should it return? Depends on what you want to do with the result of the function. N values of None seems reasonable to me, so I would write code such as def foo(x): try: # code setting y and z return y,z except: return None,None y,z = foo(x) You almost never want a bare except. What exception are you catching? My suspicion is that the code would be better written as: def foo(x): # code settying y and z return y, z try: y, z = foo(x) except FooError: y, z = None, None but I'm not sure if you really want y and z to be None if foo fails. What do you do with y and z? Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
On Sat, 12 Feb 2005 09:42:41 +0100 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > the relevant part for this thread is *locale-*. if wctype depends on > the locale, it cannot be used for generic build. (custom interpreters > are an- other thing, but they shouldn't be shipped as "python"). You are right. But isalpha behavior looks strange for me anyway: why cyrillic character '\u0430' is recognized as alpha one for de_DE locale, but is not for C? -- Denis S. Otkidach http://www.python.ru/ [ru] -- http://mail.python.org/mailman/listinfo/python-list
Re: pre-check for string-to-number conversion
[EMAIL PROTECTED] wrote: I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. Stop worrying and learn to love exceptions. :) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
listerator clonage
Hello, I want to build a function which return values which appear two or more times in a list: So, I decided to write a little example which doesn't work: #l = [1, 7, 3, 4, 3, 2, 1] #i = iter(l) #for x in i: #j = iter(i) #for y in j: #if x == y: #print x In thinked that the instruction 'j= iter(i)' create a new iterator 'j' based on 'i' (some kind of clone). I wrote this little test which show that 'j = iter(i)' is the same as 'j = i' (that makes me sad): #l = [1, 7, 3, 4, 2] #i = iter(l) #j = iter(i) #k = i #i, j, k (, , ) Just in order to test, I wrote these little test: #l = [1, 7, 3, 4, 2] #i = iter(l) #import pickle #j = pickle.loads(pickle.dumps(i)) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\pickle.py", line 1386, in dumps Pickler(file, protocol, bin).dump(obj) File "C:\Python24\lib\pickle.py", line 231, in dump self.save(obj) File "C:\Python24\lib\pickle.py", line 313, in save rv = reduce(self.proto) File "C:\Python24\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle listiterator objects #import copy #j = copy.copy(i) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\copy.py", line 95, in copy return _reconstruct(x, rv, 0) File "C:\Python24\lib\copy.py", line 320, in _reconstruct y = callable(*args) File "C:\Python24\lib\copy_reg.py", line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: object.__new__(listiterator) is not safe, use listiterator.__new__() So, I would like to know if there is a way to 'clone' a 'listiterator' object. I know that is possible in Java for example... If it is impossible, have you better ideas to find duplicate entries in a list... Thanks, Cyril -- http://mail.python.org/mailman/listinfo/python-list
Python in EDA
Hi, I am new to Python and coming from the EDA/VLSI Design background. I wanted to know if there are some active projects going on EDA modules written in Python. Usually, use of scripting tools in VLSI Design is on a per-project basis and rarely reaches the level of a general framework, mostly due to extensibility and speed performance limitations. That Python overcomes atleat one of them...may be a good reason to look at Python based EDA. I was interested in knowing if such efforts are on. Apart from that also any input on EDA softwares using Python will be useful. regards, Vishal -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
As I mention below, I mistook the function from my utilities file for a Python built-in; here's the implementation: #def isnumber(x): #"Is x a number? We say it is if it has an __int__ method." #return hasattr(x, '__int__') -- http://mail.python.org/mailman/listinfo/python-list
[perl-python] 20050211 generating expression by nested loops
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return dict([('%d,%d'%(i+1,j+1),(i+1,j+1)) for j in range(n) for i in range(j)]) print combo2(5) # this construct uses a irregular syntax to generate a expression # built by nested loops. Semantically, this expression generation is # akin to applying a function to a tree. Morons in the computing # industry and academia like to call this "list comprehension". # In Python, this syntax irregularity works like this, for example: # double each number from 1 to 5 myExpression = [ i*2 for i in range(1,6)] print myExpression # built a list of couples of the form (n*2,n*3) myExpression = [ (i*2,i*3) for i in range(1,6)] print myExpression # in general the this expression generating syntax has the form # [ ] # the iteration part can be nested. myExpression = [ (i,j) for i in range(1,6) for j in range(1,4)] print myExpression # remember, this jargonized "list comprehension" is nothing more than # a irregular syntax for building a expression from nested loops. Its # purpose is primarily of syntactical convenience. Advanced languages # such as functional languages often have this power without the # syntax irregularity. # For Python's official tutorial on this topic, see # http://python.org/doc/tut/node7.html #- # Perl does not contain facilities to generate expressions based on # trees. Of course, one can just do with for loops. One can however # write a function that are syntactically more succinct in generating # expression thru trees than the so-called "list comprehension"), See # http://xahlee.org/PerlMathematica_dir/perlMathematica.html # look for the function named Table. his is Perl-Python a-day. To subscribe, see http://xahlee.org/perl-python/python.html Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble using telentlib
Nitin Chaumal said the following on 2/11/2005 5:41 PM: I sarched the existing threads but didnt find an answer to this. I am writing simple script which uses telentlib to open a session with a unix machine and run "tail -f logfile.txt" on one of the logfiles. import telnetlib HOST = "192.X.X.X" user = "myname" password = "mypass" tn = telnetlib.Telnet(HOST) tn.read_until("login: ") tn.write(user + "\n") if password: tn.read_until("Password: ") tn.write(password + "\n") tn.write("tail -f /tmp/logfile.txt\n") # what do i write here ? # tn.write("exit\n") Nitin, You can not have two writes together. Reads and writes should alternate. To get the log file this is what you should do: # Modified my working version for your purpose. # Hope there are not errors! def SaveLog(user, password): telnet_resp = [] tn = telnetlib.Telnet(host) tn.read_until("login: ") tn.write(user + "\n") if password: telnet_resp.append( tn.read_until("Password: ") ) tn.write(password + "\n") tn.read_until("$ ") tn.write("tail -f /tmp/logfile.txt\n") telnet_resp.append(tn.read_until("$ ")) tn.write("exit\n") telnet_resp.append(tn.read_all() ) tn.close() telnet_out = open(OUTPUT, 'a') telnet_out.write('\n'.join(telnet_resp)) telnet_out.close() Alternatively, if your box has FTP access, you can FTP the log file to a CStringIO file and operate on it. Thanks, -Kartic -- http://mail.python.org/mailman/listinfo/python-list
Re: Python UPS / FedEx Shipping Module
Gabriel Cooper wrote: I've made UPS and FedEx shipping rate request modules in python using XML. Is there an interest in putting this on the web? I'd be interested in at least looking at them, hoping to learn something of value, even if I don't have (or believe I don't have) any current use for them. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Loading functions from a file during run-time
if the file you want to include is not txt, but instead py, it should be easy. for example you have fs.py you just - fs=__import__("fs") f=[a for a in dir(fs) if a[0:2]!='__'] #no you have f1(),f2(),f3() as f[0],f[1],f[2] then excute desired function, for example f2(): exec("fs."+f[1]+"()") if you have top level variable in that file, just modify this to test typs.FunctionType(import types first) -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to raw_input ?
BOOGIEMAN wrote: On Fri, 11 Feb 2005 18:00:08 +0100, den wrote: Did you try this: import msvcrt msvcrt.getch() Yes, that's what I need. Thank you. BTW, sometimes program continues without me pressing any button, why ? Probably because you had already hit a key earlier, and it was still in the keyboard queue. You can flush it first: print prompt while msvcrt.kbhit(): msvcrt.getch() msvcrt.getch() Pack that up in a subroutine and call it when you need to pause and continue only when the user has seen your prompt. Any previous keystrokes will be discarded by the loop, then it will wait for a new one to be hit. -Peter -- http://mail.python.org/mailman/listinfo/python-list
A REAL money maker. IT WORKS!!!!
Try this out, it works Turn $10 into $10,000 with PayPal, easy and quick. PLEASE TAKE A MOMENT TO READ THIS INFORMATION. THIS REALLY WORKS!!! " I WAS SHOCKED WHEN I SAW HOW MUCH MONEY CAME FLOODING INTO MY PAYPAL ACCOUNT." -Mark 2004 Dear Friend, This is a new program, as you will see. It can be for the U.S. Canada, S.E Asia or the U.K. This is a fantastic opportunity. Try it for yourself!! EVERYTHING DONE ONLINE! With just $10 or £5 and a PayPal PREMIER or BUSINESS account, you could make $$Thousands$$ in 2 SIMPLE STEPS! GUARANTEED - you will have $10,000 in two weeks. Only $10, a PayPal PREMIER or BUSINESS account and 30 minutes are all that is needed to get this going. If you want to make a few thousand dollars real quick, then PLEASE take a moment to read and understand the MLM program I'm sharing with you. No it's not what you think. YOU DON´T have to send $10 to five or six people to buy a report, receipt or get on their mailing list. Nor will you need to invest more money. You will be able to complete it in LESS THAN 30 MINUTES and you will NEVER FORGET THE DAY YOU FIRST VIEWED THIS ONLINE. If you're already running a home business, you can easily do this one along with it. If not, this is the FASTEST and EASIEST way to earn serious money online that you've ever seen so far in the history of the Internet! This program works no matter what country you are in, or what currency you use. It doesn't matter how old or how young you are. And you certainly won't need any special knowledge or talent. You won't need to run a website, or make phone calls, or make photocopies, or send out letters through the mail, or pay for advertising, etc. The only things you will need are: * an email address * A Premier or Business PayPal account with at least $10 deposited in it * 30 minutes of your time ONLY 2 SIMPLE AND EASY STEPS! ! If you are doing other programs, by all means stay with them. The more the merrier, BUT PLEASE READ ON!! First of all, there are only TWO POSITIONS, not realistic and much, MUCH FASTER. Because it is so easy, the response rate for this program is VERY HIGH and VERY FAST, and you will receive your reward in FOURTEEN DAYS. That's only TWO WEEKS! Not one or two months. Just in time for next months BILLS. TRUE STORY -- Grace Kelly tells how she ran this gifting summation four times last year. The first time, she received $6,000 in cash in two weeks and then $14,000 in cash the next three times. THIS CAN AND WILL WORK FOR YOU! HERE ARE THE DETAILS: Post this letter in 50 message boards, chat rooms, or newsgroup. You don't need to post 200 like other programs or email 100 people just to get started. Even if you are already in a program like the "send twenty dollars to six people", CONTINUE IT and stay with it, THOSE DO PAY OUT, but do yourself a favor, DO THIS ONE TODAY as well, RIGHT NOW!!! It is simple and takes a very small investment, only $10 and a PayPal PREMIER or BUSINESS account. IT WORKS AND IS DONE IN 2 SIMPLE AND EASY STEPS! ! This program WILL PAY FASTER before the other programs you are working on even trickle in!! Follow the simple instructions and in two weeks, you should have $10,000 because most PEOPLE WILL RESPOND due to the LOW ONE TIME INVESTMENT, SPEED AND HIGH PROFIT POTENTIAL, PLUS, since its done ALL ONLINE, there is no time-wasted mailing out letters and such!!! We are not even figuring a 50% response! So let's all keep it going and help each other in these tough times. We all owe money to bill collectors, and creditors. But, with this, if people take the time to help each other, the good fortune will follow. SO, Take the measly minutes this SIMPLE and REWARDING program offers and give the gift that gives back TODAY!!! HERE´S WHAT YOU NEED TO DO: STEP 1 Ok, if you're not already a PayPal user, the very first thing you need to do is use the PayPal link below and SIGN UP. It takes just two minutes! Here's the URL. Just click on the PayPal link below: https://www.paypal.com/cgi-bin/webscr?cmd=_registration-run Be sure to use this link so you can sign up for a free PREMIER or BUSINESS account. You'll need to have a PREMIER or BUSINESS account (and not a PERSONAL account) otherwise you won't be able to receive credit card payments from other people. STEP 2 It is an undeniable law of the universe that we must first give in order to receive. So the first thing to do when you have your Premier/Business PayPal account is to IMMEDIATELY send a $10 payment from your PayPal account to the person at POSITION #1, if... Your birthday is BETWEEN JAN 1 THRU JUNE 30, OR, if... -- your birthday is BETWEEN JULY 1 THRU DEC 31, send the gift to the person at POSITION # 2. Along with a note saying: "HERE IS A $10 GIFT FOR YOU." Be certain to add this note, as this is what KEEPS THIS PROGRAM LEGAL. Instructions on how to send a payment are under "SEND MONEY" at the PayPal Site. It's so Easy!!! When you send your $10 payment to the first address in the list, do it with a great big smile
Re: dos box appears when clicking .pyc
Change the association for .pyc files to pythonw.exe from python.exe. Larry Bates Philippe C. Martin wrote: Hi, For a few months now, I have been used .pyc script under XP without getting the "DOS" box. I just re-installed the scripts on another XP box and am now getting the DOS box ! Something to do with the registry ? Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: pre-check for string-to-number conversion
[EMAIL PROTECTED] wrote: I am reading an ASCII data file and converting some of the strings to integers or floats. However, some of the data is corrupted and the conversion doesn't work. I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. You should reconsider this thought. It's quite clean and fast: for s in get_ASCII_strings_from_data_file(): try: f = float(s) except ValueError: do_whatever_you_need_to_do_for_invalid_data() I would like to simply perform a pre-check before I do the conversion, but I can't figure out how to do it. Again, this is the less Pythonic approach, but one option would be to use regular expressions: matcher = re.compile(r'[\d.]+') for s in get_ASCII_strings_from_data_file(): if matcher.match(s): f = float(s) else: do_whatever_you_need_to_do_for_invalid_data() but note that this won't except valid floats like '1e10'. You'll also note that this is actually less concise than the exception based approach. Steve -- http://mail.python.org/mailman/listinfo/python-list
Your message to RT-Announce awaits moderator approval
Your mail to 'RT-Announce' with the subject Delivery by mail Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.bestpractical.com/cgi-bin/mailman/confirm/rt-announce/bda8c0080f85efcae5a36066961c5d0b2ce4bda8 -- http://mail.python.org/mailman/listinfo/python-list
exception handling for a function returning several values
If a function that normally returns N values raises an exception, what should it return? N values of None seems reasonable to me, so I would write code such as def foo(x): try: # code setting y and z return y,z except: return None,None y,z = foo(x) If I try to use y or z inappropriately when they are None, the program will stop. An alternative is to return an error flag in addition to y and z from function foo and check the value of the error flag in the calling program. This seems a bit awkward. -- http://mail.python.org/mailman/listinfo/python-list
Your message to RT-Announce awaits moderator approval
Your mail to 'RT-Announce' with the subject Delivery service mail Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.bestpractical.com/cgi-bin/mailman/confirm/rt-announce/6ab5b93a64f4deebfc5dd70071f59d9bb20418d3 -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
Steven Bethard wrote: Should namespace chaining be supported? One suggestion would add a NamespaceChain object to the module:: This does have the advantage of keeping the basic namespace simple. However, it may also be worth having native chaining support in Namespace: I think I prefer the separate NamespaceChain object because it allows you to chain namespaces other than just Namespace objects -- any object that supports getattr is okay. If chaining is builtin, all namespaces (except the last one?) have to be Namespace objects... I like NamespaceChain too - I was simply thinking it might be good to have a recursive chaining method associated with actual Namespace objects as well. However, now that I look more closely at NamespaceChain, it makes more sense to me to explicitly make the 'head' of the chain a namespace view in its own right. This should also make the local binding, chained lookup behaviour fairly obvious (since it will work just as it does for any class with __getattr__ defined, but not __setattr__ or __delattr__). That is, something like: class NamespaceChain(NamespaceView): def __init__(self, head, *args): NamespaceView.__init__(self, head) self.__namespaces__ = args def __getattr__(self, name): """Return the first such attribute found in the object list This is only invoked for attributes not found in the head namespace. """ for obj in self.__namespaces__: try: return getattr(obj, name) except AttributeError: pass raise AttributeError(name) Python gives us the local set and local del for free. The 'nested namespaces' approach that prompted my original suggestion can then be spelt by using: parent = Namespace() child1 = NamespaceChain({}, parent) child2 = NamespaceChain({}, child1) There *is* a problem with using __getattr__ though - any attribute in the chained namespaces that is shadowed by a class attribute (like 'update') will be picked up from the class, not from the chained namespaces. So we do need to use __getattribute__ to change that lookup order. However, given the amount of grief the default lookup behaviour causes, I think the place to do that is in Namespace itself: class Namespace(object): # otherwise unchanged def __getattribute__(self, name): """Namespaces do NOT default to looking in their class dict for non-magic attributes """ getattribute = super(Namespace, self).__getattribute__ try: return getattribute("__dict__")[name] except KeyError: if name.startswith('__') and name.endswith('__'): # Employ the default lookup system for magic names return getattribute(name) else: # Skip the default lookup system for normal names if hasattr(self, "__getattr__"): return getattribute("__getattr__")(name) else: raise AttributeError(name) The above is a pretty simple approach - it completely bypasses the descriptor machinery for non-magic names. This means that the instance namespace does NOT get polluted by any non-magic names in the class dictionary, but magic names can be accessed normally. And subclasses can add their own methods, and this feature will continue to 'just work'. For example: Py> ns = namespaces.Namespace() Py> ns.update Traceback (most recent call last): File "", line 1, in ? File "namespaces.py", line 30, in __getattribute__ raise AttributeError(name) AttributeError: update Py> type(ns).update Py> ns.__init__ (side note: I don't think I have ever written a __getattribute__ method without introducing an infinite recursion on the first attempt. . .) Anyway, it is probably worth digging into the descriptor machinery a bit further in order to design a lookup scheme that is most appropriate for namespaces, but the above example has convinced me that object.__getattribute__ is NOT it :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Serge Orlov wrote: > To summarize the discussion: either it's a bug in glibc or there is an option to specify modern POSIX locale. POSIX locale consist of characters from the portable character set, unicode is certainly portable. Yes, but U+00E4 is not in the portable character set. The portable character set is defined here: http://www.opengroup.org/onlinepubs/007908799/xbd/charset.html Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: pre-check for string-to-number conversion
Yes, I suppose exceptions are the best way to handle this problem. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
"Martin v. Löwis" wrote: > Serge Orlov wrote: > > To summarize the discussion: either it's a bug in glibc or there > is an >> option to specify modern POSIX locale. POSIX locale consist of >> characters from the portable character set, unicode is certainly >> portable. > > Yes, but U+00E4 is not in the portable character set. The portable > character set is defined here: > > http://www.opengroup.org/onlinepubs/007908799/xbd/charset.html Thanks for the link. They write (in 1997 or earlier ?): The wide-character value for each member of the Portable Character Set will equal its value when used as the lone character in an integer character constant. Wide-character codes for other characters are locale- and *implementation-dependent* Emphasis is mine. So how many libc implementations with non-unicode wide-character codes do we have in 2005? I'm really interested to know. Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
Steven Bethard wrote: Is there a good way to determine if an object is a numeric type? . . . Ideas? Maybe this can help? def isnumber(x): try: return(x == x-0) except: return False print '1:\t', isnumber(1) print '1.25:\t', isnumber(1.25) print '1.0 / 7:\t', isnumber(1.0 / 7) print '1+0j:\t', isnumber((1+0j)) print '"spam":\t', isnumber("spam") output: 1: True 1.25: True 1.0/7: True 1+0j: True "spam": False Ooops! While checking other posts I realized that this is almost the same as Dan Bishop's solution. Marco -- http://mail.python.org/mailman/listinfo/python-list
Re: frozenset() without arguments should return a singleton
"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi! > > frozenset() doesn't behave as the other immutable empty data types in > 2.4: > > .>>> '' is '' > True > .>>> () is () > True I believe the reference manual describes this sort of behavior for immutables as an *optional* optimization. 0 is 0 and has been since at least 1.3. I am not sure both of your statements above have been true as long, but I not longer have 1.3 to check ;-). > .>>> frozenset() is frozenset() > False > frozenset() called without arguments (or on empty sequences) > should always return a singleton object. If we interpret 'should' as 'preferably by me', ok. >It is immutable, so I can't see a reason why it should take up more >resources than necessary. It will take some programmer's time to add the special case check and run the test suite, and check in the changes. Yours? And perhaps some execution time for each frozenset call. Since frozenset is not much used, and multiple empty frozensets very rare, and the difference mostly invisible, the frozenset implementor probably went on to other things. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Commerical graphing packages?
Check out GRACE. It's not specifically designed for Python, but I've been using with Python for a couple of years or more. I'm very happy with it, and it's free. It works both interactively and in batch mode. Do a google on GRACE. -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
marco wrote: Steven Bethard wrote: Is there a good way to determine if an object is a numeric type? Maybe this can help? def isnumber(x): try: return(x == x-0) except: return False Not exactly foolproof: >>> def isnumber(x): ... try: return (x == x-0) ... except: return False ... >>> import numarray >>> a = numarray.arange(1.1, 5.5) >>> a array([ 1.1, 2.1, 3.1, 4.1, 5.1]) >>> print '%s:\t' % a, isnumber(a) [ 1.1 2.1 3.1 4.1 5.1]: [1 1 1 1 1] The result is actually this: >>> a == a-0 array([1, 1, 1, 1, 1], type=Bool) And if you try to call bool() on it (as perhaps your isnumber() routine already should have, rather than relying on == to return a boolean): >>> bool(a == (a-0)) Traceback (most recent call last): File "", line 1, in ? File "C:\a\python24\Lib\site-packages\numarray\generic.py", line 477, in __nonzero__ raise RuntimeError("An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a).") RuntimeError: An array doesn't make sense as a truth value. Use sometrue(a) or alltrue(a). Yuck. Of course, most of the other definitions of "is a number" that have been posted may likewise fail (defined as not doing what the OP would have wanted, in this case) with a numarray arange. Or maybe not. (Pretty much all of them will call an arange a number... would the OP's function work properly with that?) -Peter -- http://mail.python.org/mailman/listinfo/python-list
ANN: pyMinGW support for Python 2.3.5 (final) is available
This is to inform those interested in compiling Python in MinGW that an updated version of pyMinGW is now available. Get it from here: http://jove.prohosting.com/iwave/ipython/pyMinGW.html Regards Khalid -- http://mail.python.org/mailman/listinfo/python-list
Re: connecting to Sybase/MsSQL from python
"John Fabiani" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] > Hi, > I'm hoping someone on the list has connected to sybase/MsSQL with > something > that works with DBAPI 2.0 from a linux box (SUSE 9.2) because I can't seem > to get it done. I found Object Craft's python code that uses FreeTDS. > But > I can't get it compiled. The code is looking for "sybdb.h" (first > error) - > of course I don't have "sybdb.h". It is not in Object Crafts code nor in > the FreeTDS source. I'm guessing that I need sybase develop lib's but I > don't know where they are to be found. > > So is there a kind sole out there that can help with instructions on what > is > needed to get python talking to MsSQL. > > jOHN Use mxODBC? -- Vincent Wehren -- http://mail.python.org/mailman/listinfo/python-list
Re: Big development in the GUI realm
Jeremy Bowers wrote: On Fri, 11 Feb 2005 14:45:09 -0800, Robert Kern wrote: Until such matters are unequivocally determined in a court that has jurisdiction over you, do you really want to open yourself to legal risk and certain ill-will from the community? Huh? What are you talking about? I'm just pointing out the inability of the law to handle it. I have no intention of doing anything with it, except inasmuch as it makes it difficult to license my own works since I don't believe any license works. (But I use the LGPL anyways.) Sorry, it seemed like you were proposing a method to "get around" the intention of the copyright holder. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
dos box appears when clicking .pyc
Hi, For a few months now, I have been used .pyc script under XP without getting the "DOS" box. I just re-installed the scripts on another XP box and am now getting the DOS box ! Something to do with the registry ? Regards, Philippe -- *** Philippe C. Martin SnakeCard LLC www.snakecard.com *** -- http://mail.python.org/mailman/listinfo/python-list
Re: Big development in the GUI realm
Jeremy Bowers wrote: On Fri, 11 Feb 2005 18:24:22 +0100, Damjan wrote: What you described is not ok according to the GPL - since you distributed a binary thats derived from GPL software (and you didn't publish it source code under the GPL too). No you didn't. You distributed a binary completely free of any GPL code whatsoever. The *user* combined your binary and the GPL to produce another binary, which will never be distributed at all. In copyright terms, which is what the GPL works under since that is the law it has, what you distributed is completely unrelated to the GPL'ed program; there's no grounds to call it "derived". You might be on firmer ground if it were legally clear exactly what "derived work" means. Unfortunately, the courts have been skirting around the issue of defining "derived work" particularly as it pertains to software. It is entirely possible that a judge would conclude that your software is a derived work of the GPL software. Until such matters are unequivocally determined in a court that has jurisdiction over you, do you really want to open yourself to legal risk and certain ill-will from the community? I'll reiterate my strategy: follow the intentions of the copyright owner unless if I have actual case law on my side. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Hack with os.walk()
Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent element.setProp( "name", os.path.basename(directory)) for root, dirs, files in os.walk( directory ): for fileName in files: element.addChild( parseFile( os.path.join( root, fileName )) for dirName in filter( acceptDirectory, dirs): walkDirectory( os.path.join( root, dirName ), element ) return ### Note, this is inside for loop What it does, is it recurses through all directories, and, with libxml2's bindings, builds an XML document which maps directly to the file hierarchy. For every file is parseFile() called, which returns a "file element" which is appended; the resulting structure looks the way one expect -- like a GUI tree view. The current code works, but I find it hackish, and it probably is inefficient, considering that os.walk() is not called once(as it usually is), but for every directory level. My problem, AFAICT, with using os.walk() the usual way, is that in order to construct the /hierarchial/ XML document, I need to be aware of the directory depth, and a recursive function handles that nicely; os.walk() simply concentrates on figuring out paths to all files in a directory, AFAICT. I guess I could solve it with using os.walk() in a traditional way, by somehow pushing libxml2 nodes on a stack, after keeping track of the directory levels etc(string parsing..). Or, one could write ones own recursive directory parser.. My question is: what is the least ugly? What is the /proper/ solution for my problem? How would you write it in the cleanest way? Cheers, Frans -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
Fredrik Lundh wrote: Steven Bethard wrote: Is there a good way to determine if an object is a numeric type? assert operator.isNumberType(i) Interesting, thanks! If I read the source right, PyNumber_Check (which operator.isNumberType is an alias for) basically just returns True if the object's type has a __int__ or __float__ method defined: int PyNumber_Check(PyObject *o) { return o && o->ob_type->tp_as_number && (o->ob_type->tp_as_number->nb_int || o->ob_type->tp_as_number->nb_float); } Did I read that right? Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: exception handling for a function returning several values
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I try to use y or z inappropriately when they are None, the program > will stop. An alternative is to return an error flag in addition to y > and z from function foo and check the value of the error flag in the > calling program. This seems a bit awkward. It seems to me you would be undermining the intent of exceptions here. If there is some reason foo() can't proceed with x, then either some sort of a "standard exception" gets thrown as a result of trying to, or you can detect the condition within foo() and raise a custom exception which adequately decribes the problem. Smart callers of foo() are then coded with the knowledge that not all values of 'x' are guaranteed to produce the "normal" results, and have one or more 'except' clauses for them to do whatever it is they think is most appropriate with that exception. HTH! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: connecting to Sybase/MsSQL from python
On Feb 11, 2005, at 8:12 PM, John Fabiani wrote: So is there a kind sole out there that can help with instructions on what is needed to get python talking to MsSQL. Has anyone ever used this product: http://www.object-craft.com.au/projects/mssql/ Any feedback, positive or negative? ___/ / __/ / / Ed Leafe http://leafe.com/ http://dabodev.com/ Come to PyCon http://www.python.org/pycon/2005/ -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
Nick Coghlan wrote: Py> class NS(namespaces.Namespace): ... x = prop ... Oops - c&p error here. This was actually: Py> class NS(namespaces.Namespace): ... x = prop ... __x__ = prop ... Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
John Lenton wrote: On Fri, Feb 11, 2005 at 01:17:55PM -0700, Steven Bethard wrote: George Sakkis wrote: "Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Is there a good way to determine if an object is a numeric type? In your example, what does your application consider to be numeric? Well, here's the basic code: def f(max=None): ... while max is None or n <= max: ... # complicated incrementing of n So for 'max', technically all I need is <= support. However, the code also depends on the fact that after incrementing 'n' enough, it will eventually exceed 'max'. Currently, ints, longs, floats, and Decimals will all meet this behavior. But I'd rather not specify only those 4 (e.g. with a typecheck), since someone could relatively easily create their own new numeric type with the same behavior. Do you know a better way to test for this kind of behavior? Why don't you express just this need as an assertion? assert 0 <= max <= max + 1, 'Argument must not be zany' Well a TypeError might be raised in executing the expression: py> max = complex(0, 1) py> assert 0 <= max <= max + 1, 'Argument must not be zany' Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= but I do like the max <= max + 1 idea. Maybe I should do something like: py> def assertnumber(x): ... try: ... 1 < x ... except TypeError: ... raise TypeError('%s is not comparable to int' % ... type(x).__name__) ... try: ... if not x <= x + 1: ... raise TypeError ... except TypeError: ... raise TypeError('%s is not monotonic' % ... type(x).__name__) ... py> assertnumber(1) py> assertnumber(1.0) py> assertnumber(complex(0, 1)) Traceback (most recent call last): File "", line 1, in ? File "", line 5, in assertnumber TypeError: complex is not comparable to int py> assertnumber('a') Traceback (most recent call last): File "", line 1, in ? File "", line 11, in assertnumber TypeError: str is not monotonic py> class C(object): ... def __add__(self, other): ... return 0 ... def __lt__(self, other): ... return True ... py> assertnumber(C()) Traceback (most recent call last): File "", line 1, in ? File "", line 11, in assertnumber TypeError: C is not monotonic Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
Nick Coghlan wrote: Steven Bethard wrote: >>> ns = Namespace(eggs=1) >>> Namespace.update(ns, [('spam', 2)], ham=3) >>> ns Namespace(eggs=1, ham=3, spam=2) Note that update should be used through the class, not through the instances, to avoid the confusion that might arise if an 'update' attribute added to a Namespace instance hid the update method. I'd like to see the PEP text itself encourage the more inheritance friendly style used in the __init__ method: type(ns).update(ns, [('spam', 2)], ham=3) Where in the PEP do you think this belongs? Or did you mean you wanted it in the docstrings of the Namespace functions? Note that support for the various mapping methods, e.g. __(get|set|del)item__, __len__, __iter__, __contains__, items, keys, values, etc. was intentionally omitted as these methods did not seem to be necessary for the core uses of an attribute-value mapping. If such methods are truly necessary for a given use case, this may suggest that a dict object is a more appropriate type for that use. The 'vars' builtin also makes it trivial to use dictionary style operations to manipulate the contents of a Namespace. Right, I had meant to mention that. Thanks! Should namespace chaining be supported? One suggestion would add a NamespaceChain object to the module:: This does have the advantage of keeping the basic namespace simple. However, it may also be worth having native chaining support in Namespace: I think I prefer the separate NamespaceChain object because it allows you to chain namespaces other than just Namespace objects -- any object that supports getattr is okay. If chaining is builtin, all namespaces (except the last one?) have to be Namespace objects... class NamespaceChain(object): """NamespaceChain(*objects) -> new attribute lookup chain The new NamespaceChain object's attributes are defined by the attributes of the provided objects. When an attribute is requested, the sequence is searched sequentially for an object with such an attribute. The first such attribute found is returned, or an AttributeError is raised if none is found. Note that this chaining is only provided for getattr and delattr operations -- setattr operations must be applied explicitly to the appropriate objects. Hmm, I'm not so sure about this. I think that the right model is the way that a class instance is currently chained with its class. That is, assume we have the following: c = cls() ns = Namespace(vars(c), vars(cls)) # Using modified NS above nc = NamespaceChain(Namespace(vars(c)), Namespace(vars(cls))) I would expect modification of attributes on ns or nc to behave similarly to modification of attributes on c - attribute retrieval follows the chain, but attribute modification (set/del) always operates on the first namespace in the chain. Yeah, that makes sense. I hadn't quite wrapped my head around what setattr _aught_ to do in these cases, so I wasn't willing to commit to anything yet. ;) I'll update NamespaceChain to work like classes do... Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: PHP session equivalent?
Erik Johnson wrote: > There are a lot of things about PHP I was not too keen on and hence > why > my company is primarily doing Python these days, but one thing I was quite > impressed with was the ease with which it provided session > functionality... Like you I think it is a big plus of PHP as a beginner's web development tool that it provides session management out of the box. It would certainly make python more attractive for beginners if they could use session management out of the box, too. (I know that there are lots of web development frameworks, but they are to be too difficult to learn, if you are new to web development). There is no module for session management in the python standard library. But there are lots of python frameworks that would do this job well (my favorite: cherrypy). If you think that a whole framework would be overkill, you either could try to recylce the session part of an existing framework, or you could write a module for yourself. I have written a module which is quite similar to the php session management, except for that it does no url rewriting when cookies are not allowed. If you are interested, I will mail you a copy. -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
George Sakkis wrote: George Sakkis wrote: "Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Is there a good way to determine if an object is a numeric type? In your example, what does your application consider to be numeric? Well, here's the basic code: def f(max=None): ... while max is None or n <= max: ... # complicated incrementing of n So for 'max', technically all I need is <= support. However, the code also depends on the fact that after incrementing 'n' enough, it will eventually exceed 'max'. Currently, ints, longs, floats, and Decimals will all meet this behavior. But I'd rather not specify only those 4 (e.g. with a typecheck), since someone could relatively easily create their own new numeric type with the same behavior. Do you know a better way to test for this kind of behavior? The problem is more conceptional rather than technical. Yup. So what you're saying is that 3 <= "3.0" should not be allowed, but 3 <= SomeUserDefinedNumericClass(3) is ok, although your program knows nothing a priori about SomeUserDefinedNumericClass. The idea suggested before, try if "x+1" fails or not does not get you far; any class that overrides __add__ may fool this test: class Dummy: def __add__(self,other): return 0 Right but by the same logic, we can fool protocols that are builtin to Python: py> class C(object): ... def __iter__(self): ... return 0 ... py> for x in C(): ... print x ... Traceback (most recent call last): File "", line 1, in ? TypeError: iter() returned non-iterator of type 'int' I'm not trying to catch the case where someone is deliberately violating the protocol. Only the case where they've provided an object that doesn't conform to the protcol. Clearly, complex objects don't conform to the protocol I want -- they don't support comparisons to ints. This is easy to check: try: x <= 1 except TypeError: raise TypeError('%s does not support comparisons to ints' % type(x).__name__) Now str objects also don't conform my protocol -- they aren't comparable to integers in any meaningful sense. Ideally, I should be able to use the same code as above for str objects (and get a TypeError like "str objects cannot be compared with int objects"), but unfortunately, the Python wart of cross-type default comparisons gets in the way. I look forward to the day when Python 3.0 removes such comparisons. =) Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
Oops, my bad. The utilities file I use gets loaded automatically when I start my interpreter, so I mistook isnumber for a built-in function. A battle-tested isnumber function is defined in Peter Norvig's utils.py (http://aima.cs.berkeley.edu/python/utils.py): #def isnumber(x): #"Is x a number? We say it is if it has an __int__ method." #return hasattr(x, '__int__') Michael -- Michael D. Hartl, Ph.D. Chief Technology Officer http://quarksports.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Concurrent Python
Hi ! You can found few ideas here : http://candygram.sourceforge.net @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
On Fri, Feb 11, 2005 at 01:17:55PM -0700, Steven Bethard wrote: > George Sakkis wrote: > >"Steven Bethard" <[EMAIL PROTECTED]> wrote in message > >news:[EMAIL PROTECTED] > > > >>Is there a good way to determine if an object is a numeric type? > > > >In your example, what does your application consider to be numeric? > > Well, here's the basic code: > > def f(max=None): > ... > while max is None or n <= max: > ... > # complicated incrementing of n > > So for 'max', technically all I need is <= support. However, the code > also depends on the fact that after incrementing 'n' enough, it will > eventually exceed 'max'. Currently, ints, longs, floats, and Decimals > will all meet this behavior. But I'd rather not specify only those 4 > (e.g. with a typecheck), since someone could relatively easily create > their own new numeric type with the same behavior. Do you know a better > way to test for this kind of behavior? Why don't you express just this need as an assertion? assert 0 <= max <= max + 1, 'Argument must not be zany' (or whatever error message is suitable) -- John Lenton ([EMAIL PROTECTED]) -- Random fortune: Oxymorons? I saw one yesterday - the pamphlet on "Taco Bell Nutritional Information" signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: check if object is number
> > So what you're saying is that 3 <= "3.0" should not be allowed, but > > 3 <= SomeUserDefinedNumericClass(3) is ok, although your program knows > > nothing a priori about SomeUserDefinedNumericClass. The idea suggested > > before, try if "x+1" fails or not does not get you far; any class that > > overrides __add__ may fool this test: > > > > class Dummy: > > def __add__(self,other): > > return 0 > > Right but by the same logic, we can fool protocols that are builtin to > Python: > > py> class C(object): > ... def __iter__(self): > ... return 0 > ... > py> for x in C(): > ... print x > ... > Traceback (most recent call last): >File "", line 1, in ? > TypeError: iter() returned non-iterator of type 'int' > > I'm not trying to catch the case where someone is deliberately violating > the protocol. Only the case where they've provided an object that > doesn't conform to the protcol. Note however that in my example there's no TypeError; 0 (or any value for that matter) is perfectly valid for __add__, while __iter__ must return an iterator. > Clearly, complex objects don't conform to the protocol I want -- they > don't support comparisons to ints. This is easy to check: > > try: > x <= 1 > except TypeError: > raise TypeError('%s does not support comparisons to ints' % > type(x).__name__) > > Now str objects also don't conform my protocol -- they aren't comparable > to integers in any meaningful sense. Ideally, I should be able to use > the same code as above for str objects (and get a TypeError like "str > objects cannot be compared with int objects"), but unfortunately, the > Python wart of cross-type default comparisons gets in the way. I look > forward to the day when Python 3.0 removes such comparisons. =) Me too... the way comparison works as of now is error-prone, to say the least. Comparing ints with strings is no more valid than adding them, and python (correctly) raises TypeError for the latter, but not for the former. For the record, here's the arbitrary and undocumented (?) order among some main builtin types: >>> None < 0 == 0.0 < {} < [] < "" < () True George -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces module (a.k.a. bunch, struct, generic object, etc.) PEP
rzed wrote: I would bet that subclassing is *still* going to be common, though, as each of us individually roll our own version to get that one vital feature the standard doesn't cover (for me, it's update with numerous other types) This is certainly what I expect to happen. It's the main reason I think the relevant documentation (including the PEP and docstrings) should encourage the type(self).method() style of accessing class methods to avoid shadowing problems while still properly supporting inheritance. The other important aspect is for the classes to be designed to be inheritance friendly. Though I'd like it to have a shorter name. I'm lazy. 'from namespaces import Namespace as ns' :) I thought about suggesting simply 'space' as a name, but I think that's way too vague. We're using it as a namespace, so we might as well call it one :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Fredrik Lundh wrote: > Serge Orlov wrote: > >> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430') >> [u'\xb5\xba\xe4\u0430'] >> >> I can't find the strict definition of isalpha, but I believe average >> C program shouldn't care about the current locale alphabet, so >> isalpha is a union of all supported characters in all alphabets > > btw, what does isalpha have to do with this example? It has to do with this thread. u'\xe4'.isalpha() returns false in Suse. It's in the same boat as \w Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Fredrik Lundh wrote: > Serge Orlov wrote: > >> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430') >> [u'\xb5\xba\xe4\u0430'] >> >> I can't find the strict definition of isalpha, but I believe average >> C program shouldn't care about the current locale alphabet, so >> isalpha is a union of all supported characters in all alphabets > > nope. isalpha() depends on the locale, as does all other ctype > functions (this also applies to wctype, on some platforms). I mean "all supported characters in all alphabets [in the current locale]". For example in ru_RU.koi8-r isalpha should return true for characters in English and Russian alphabets. In ru_RU.koi8-u -- for characters in English, Russia and Ukrain alphabets, in ru_RU.utf-8 -- for all supported by the implementation alphabetic characters in unicode. IMHO iswalpha in POSIX locale can return true for all alphabetic characters in unicode instead of being limited by English alphabet. Serge. true in -- http://mail.python.org/mailman/listinfo/python-list
Returned mail: Data format error
The original message was received at Sat, 12 Feb 2005 06:04:57 +0100 from [134.224.55.190] - The following addresses had permanent fatal errors - python-list@python.org *** ** A csatolmány Message.scr I-Worm.Mydoom.R virussal fertõzött, ** a csatolmány törölve lett. *** -- http://mail.python.org/mailman/listinfo/python-list
Re: listerator clonage
Cyril BAZIN wrote: > Hello, > > I want to build a function which return values which appear two or > more times in a list: > > So, I decided to write a little example which doesn't work: > #l = [1, 7, 3, 4, 3, 2, 1] > #i = iter(l) > #for x in i: > #j = iter(i) > #for y in j: > #if x == y: > #print x Py> i = [1,2,5,4,3,3,6,8,2,2,6] Py> o = [] Py> for item in i: ... if i.count(item) > 1 and item not in o: ... o.append(item) ... Py> print o [2, 3, 6] > In thinked that the instruction 'j= iter(i)' create a new iterator 'j' > based on 'i' (some kind of clone). I wrote this little test which show > that 'j = iter(i)' is the same as 'j = i' (that makes me sad): > > #l = [1, 7, 3, 4, 2] > #i = iter(l) > #j = iter(i) > #k = i > #i, j, k > (, 0x02167B50>, ) Generally speaking Python sequence objects are iterable already no need to cast them like java. And yes iter() does create an iterator object. Py> i = [1,2,5,4,3,3,6,8,2,2,6] Py> e = iter(i) Py> e Py> e.next() 1 Py> e.next() 2 Py> e.next() 5 Py> for item in e: ... print item ... 4 3 3 6 8 2 2 6 But if you want a copy of a list then you can do it many other ways. Py> i = [1,2,5,4,3,3,6,8,2,2,6] Py> l = list(i) Py>l [1, 2, 5, 4, 3, 3, 6, 8, 2, 2, 6] Py>i [1, 2, 5, 4, 3, 3, 6, 8, 2, 2, 6] Or, Py> i = [1,2,5,4,3,3,6,8,2,2,6] Py> l = i[:] Py>l [1, 2, 5, 4, 3, 3, 6, 8, 2, 2, 6] Py>i [1, 2, 5, 4, 3, 3, 6, 8, 2, 2, 6] or you can even use copy, Py> import copy Py> i = [1,2,5,4,3,3,6,8,2,2,6] Py> l = copy.copy(i) Py> l [1, 2, 5, 4, 3, 3, 6, 8, 2, 2, 6] > Just in order to test, I wrote these little test: > #l = [1, 7, 3, 4, 2] > #i = iter(l) > #import pickle > #j = pickle.loads(pickle.dumps(i)) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\lib\pickle.py", line 1386, in dumps > Pickler(file, protocol, bin).dump(obj) > File "C:\Python24\lib\pickle.py", line 231, in dump > self.save(obj) > File "C:\Python24\lib\pickle.py", line 313, in save > rv = reduce(self.proto) > File "C:\Python24\lib\copy_reg.py", line 69, in _reduce_ex > raise TypeError, "can't pickle %s objects" % base.__name__ > TypeError: can't pickle listiterator objects > > #import copy > #j = copy.copy(i) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\lib\copy.py", line 95, in copy > return _reconstruct(x, rv, 0) > File "C:\Python24\lib\copy.py", line 320, in _reconstruct > y = callable(*args) > File "C:\Python24\lib\copy_reg.py", line 92, in __newobj__ > return cls.__new__(cls, *args) > TypeError: object.__new__(listiterator) is not safe, use listiterator.__new__() > > So, I would like to know if there is a way to 'clone' a 'listiterator' > object. I know that is possible in Java for example... Just pickle the list not the iterator. > If it is impossible, have you better ideas to find duplicate entries > in a list... See code example above. > Thanks, > > Cyril Hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Serge Orlov wrote: > The wide-character value for each member of the Portable > Character Set will equal its value when used as the lone character > in an integer character constant. Wide-character codes for other > characters are locale- and *implementation-dependent* > > Emphasis is mine. the relevant part for this thread is *locale-*. if wctype depends on the locale, it cannot be used for generic build. (custom interpreters are an- other thing, but they shouldn't be shipped as "python"). -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
On Fri, 11 Feb 2005 18:49:53 +0100 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > >> >>> re.compile(ur'\w+', re.U).findall(u'\xb5\xba\xe4\u0430') > >> [u'\xb5\xba\xe4\u0430'] > > > > I can't find the strict definition of isalpha, but I believe average > > C program shouldn't care about the current locale alphabet, so isalpha > > is a union of all supported characters in all alphabets > > btw, what does isalpha have to do with this example? The same problem is with isalpha. In most distributions: >>> for c in u'\xb5\xba\xe4\u0430': print c.isalpha(), ... True True True True And in SuSE 9.2: >>> for c in u'\xb5\xba\xe4\u0430': print c.isalpha(), ... False False False False -- Denis S. Otkidach http://www.python.ru/ [ru] -- http://mail.python.org/mailman/listinfo/python-list
Re: listerator clonage
Cyril, Here's some code that (I think) does what you want: l = [1, 7, 3, 4, 3, 2, 1] s, dups = set(), set() for x in i: if x in s: dups.add(x) s.add(x) print dups I'm sure there are more elegant ways to do it, but this seemed to be the most straightforward way I could think of. Hope this helps, Alan McIntyre ESRG LLC http://www.esrgtech.com Cyril BAZIN wrote: Hello, I want to build a function which return values which appear two or more times in a list: So, I decided to write a little example which doesn't work: #l = [1, 7, 3, 4, 3, 2, 1] #i = iter(l) #for x in i: #j = iter(i) #for y in j: #if x == y: #print x In thinked that the instruction 'j= iter(i)' create a new iterator 'j' based on 'i' (some kind of clone). I wrote this little test which show that 'j = iter(i)' is the same as 'j = i' (that makes me sad): #l = [1, 7, 3, 4, 2] #i = iter(l) #j = iter(i) #k = i #i, j, k (, , ) Just in order to test, I wrote these little test: #l = [1, 7, 3, 4, 2] #i = iter(l) #import pickle #j = pickle.loads(pickle.dumps(i)) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\pickle.py", line 1386, in dumps Pickler(file, protocol, bin).dump(obj) File "C:\Python24\lib\pickle.py", line 231, in dump self.save(obj) File "C:\Python24\lib\pickle.py", line 313, in save rv = reduce(self.proto) File "C:\Python24\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle listiterator objects #import copy #j = copy.copy(i) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\copy.py", line 95, in copy return _reconstruct(x, rv, 0) File "C:\Python24\lib\copy.py", line 320, in _reconstruct y = callable(*args) File "C:\Python24\lib\copy_reg.py", line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: object.__new__(listiterator) is not safe, use listiterator.__new__() So, I would like to know if there is a way to 'clone' a 'listiterator' object. I know that is possible in Java for example... If it is impossible, have you better ideas to find duplicate entries in a list... Thanks, Cyril -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: pyMinGW support for Python 2.3.5 (final) is available
A.B., Khalid <[EMAIL PROTECTED]> wrote: > This is to inform those interested in compiling Python in MinGW that > an updated version of pyMinGW is now available. Ha anyone tried cross compiling python with mingw? At work we compile our software for lots of platforms (including windows) on a linux build host. The windows builds are done with a mingw cross compiler. It would be interesting if we could do this with python + extensions also. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Unittesting for web applications
Can someone suggest me some good resources for learning how to use unittests for web applications? Do we always have to cook up our own webpage scrapers to test the code? - Sandip -- Sandip Bhattacharya*Puroga Technologies * [EMAIL PROTECTED] Work: http://www.puroga.com *Home/Blog: http://www.sandipb.net/blog PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3 -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050211 generating expression by nested loops
On 11 Feb 2005, Xah Lee wrote: > # this construct uses a irregular syntax to generate a expression > # built by nested loops. Semantically, this expression generation is > # akin to applying a function to a tree. Morons in the computing > # industry and academia like to call this "list comprehension". People who try to change existing terminology in a language by declaring the terminology used by __everyone__ are generally those considered moronic. Xah Lee - I know you have been declared a Troll on many an occasion, and it does seem a fitting declaration based on your behaviour. Consider that all you are achieving is making yourself look foolish to both the established perl community and the established python communities. Your code examples are NOT exemplars for either language or community. By trying to get new users to ignore existing terminology you ARE doing those people a disservice. (If indeed your goal is as stated to try and help new users). Taking 'list comprehension' for example. There is a long standing concept that is decades old (centuries old even?) called "set comprehension". This is taught in schools and says "from this set of things take these values perhaps based on a condition". List comprehension alludes to this and as soon as I saw the syntax and what it was called it was very clear what this "moronic" description meant. Clearly not everyone is in the same boat. However what will they search for? If told it's a "list comprehension", suppose they search for that - what will their #1 search result be? On google, the number 1 result is this: http://docs.python.org/tut/node7.html * This is the python tutorial section that deals with data structures and includes a section on "moronically named" list comprehensions. One can debate whether naming something distinctly and clearly which results in the #1 search result being a tutorial on the structure as being a good or a bad thing. I'll make no judgement here. So by trying to get people to call it something else - do new users get better results ? If you were doing new users a service then the answer should be yes. Is it, and are you doing them a service? Let's try the same thing for "irregular syntax": * http://www.google.com/search?num=100&q=irregular+syntax None of these 100 results contains any reference to list comprehensions. Not so successful. None of the 3 results out of that 100 that do relate to python refer even vaguely to python's list syntax. (2 relate to a scheme programmer finding python hard, and the other relates to Latin) Well, you also incorrectly (or perhaps misleadingly) stated this: * Semantically, this expression generation is akin to applying a function to a tree. If you provide an iterator on the tree (say a tree walker of some kind) then this becomes technically true (__kinda__) , but the common case is iterating over list of somekind. So again, assuming a new user, what might they use as a search term using your description ? Let's try "applying a function to a tree python". (last term to try and ensure it's on topic) Do any of those search results do something as useful as, say, point at a tutorial or documentation page on list comprehensions ? Oddly no. The closest that comes to it is one of your pages, which is taling about Perl & Mathematica. (Removing "python" makes it even further removed from being relevant) Based on seeing your perl and python code I would suggest you go away and improve your idiomatic perl & python code before posting any more of these things. Or at least try to cease attacking people declaring their established terminology as moronic, etc. Posting naive translations (which is what you've been doing) between languages can occasionally be useful to help people get started. However acting as if they are "masterful" translations and/or descriptions when they are not is not helpful in the slightest. It's very saddening to see something posted which new users will read and assume, based on the tone on the post, that it's the _correct_ way of describing things when it clearly is NOT, and will just end up misleading them and sending them down blind alleys. Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Concurrent Python
On Fri, 11 Feb 2005, Dominic Fox wrote: ... > http://www.codepoetics.com/code/concurrent.py > > Comments and constructive criticism welcome. For an alternative approach (based on using generators forming a dataflow component system) you might find our project interesting - the core concurrency stuff is packaged up separately with API docs (and trivial example) here: http://kamaelia.sourceforge.net/Docs/Axon.html Best Regards, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in EDA
On 11 Feb 2005 [EMAIL PROTECTED] wrote: > Hi, > > I am new to Python and coming from the EDA/VLSI Design background. > > I wanted to know if there are some active projects going on EDA modules > written in Python. You may want to take a look at MyHDL & APVM/Oroboro: * http://jandecaluwe.com/Tools/MyHDL/Overview.html * http://apvm.sourceforge.net/ (and specifically http://apvm.sourceforge.net/oro_025.html) The former aims to used python as an HDL allowing a subset of python to be used to design hardware, the latter is aimed at helping verilog based hardware verification (by the looks of things). Both use python generators to handle concurrency. For a brief and nice introduction to generators, it's well worth reading this article: * http://www-106.ibm.com/developerworks/linux/library/l-pythrd.html Best Regards, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Iterate through dictionary of file objects and file names
Hi all, I'm trying to get some ideas on the best way to do this. In this particular coding snippet, I was thinking of creating a dictionary of file objects and file names. These would be optional files that I could open and parse. At the end, I would easily close off the files by iterating through the dictionary. ---< CODE FOLLOWS >--- optionalfiles = {fileAreaCode: "areacode.11", fileBuild: "build.11"} # Try to see if optional file exists, if so, open. try: for key, optionalFile in optionalFiles.iteritems(): key = open(optionalFile, "r") except IOError: key = False ... # Close optionally open files for key, optionalFile in optionalFiles.iteritems(): if optionalFile: print "Closing: %s" % optionalFile key.close() ---< END CODE >--- My questions are: Is this even possible in a dictionary to have a key of a file object? If so, how do I initialise an empty file object? I mean, something along the lines of: fileAreaCode = open("", "r") If not, any suggestions on achieving openning optional files in a loop? Otherwise I'm stuck with: ---< BEGIN >--- # Optional input files try: fileAreaCode = open("areacode.11", "r") except: fileAreaCode = False try: fileBuild = open("build.11", "r") except: fileBuild = False ... # Close files for optionalFile in [fileAreaCode, fileBuild]: if optionalFile: print "Closing: %s" % str(optionalFile) optionalFile.close() ---< END >--- Thanks, Julian -- http://mail.python.org/mailman/listinfo/python-list
Web interface GUI??
I am a newbye. I am looking for a multi-platform user interface solution (windows, linux). Untill now, I used wxPython which worked fine at the beginning (MDK9, Windows NT4). Nevertheless, I was very disapointed when I noticed that my applications did not work with recent linux distributions (MDK10.1, FC3). This was because of the wxPython version...and it seemed to be very difficult to come back to an older wxPython version with these new distributions, because of dependencies problems. So I am looking for another solution with a web interface that should work with linux and windows XP. I had a look to zope but was afraid with the complexity and debug difficulties. Are there some other solutions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Web interface GUI??
Luc wrote: So I am looking for another solution with a web interface that should work with linux and windows XP. I had a look to zope but was afraid with the complexity and debug difficulties. Are there some other solutions? Yes. A lot: http://www.python.org/moin/WebProgramming I know someone who successfully created a web application that runs from CD-ROM, using Snakelets. So you may want to have a look at that one first, because this is quite similar to what you want to do, right? Then again I'm biased ofcourse. Just have a quick look at the available libraries and decide which one fits your needs most. --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: ActivePython 2.3.5.236 and ActivePython 2.4.0.244 are available
Got it. Thanks.I'm just curious.:) "Trent Mick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > mep wrote: > > ActivePython-2.4.0-243-win32-ix86.msi : 29M > > ActivePython-2.4.0-244-win32-ix86.msi : 18M > > What make so much difference of the size of them, which distinct monir > > version number for 1 only. > > Any explaination? > > > > > Yes, build 243 accidentally included some debug-build bits from > the included PyWin32 build in the package. These debug bits are > only intended for the separate Windows "debug" package. I fixed > this for build 244. > > $ diff -qr ActivePython-2.4.0-243-win32-ix86 ActivePython-2.4.0-244-win32-ix86 | grep "Only in" > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/isapi: PyISAPI_loader_d.dll > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/isapi: PyISAPI_loader_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: dde_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: dde_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: Pythonwin_d.exe > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: Pythonwin_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: scintilla_d.dll > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: win32ui_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: win32ui_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: win32uiole_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/pythonwin: win32uiole_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: dbi_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: dbi_d.pyd > Only in ActivePython-2.4.0-244-win32-ix86/INSTALLDIR/Lib/site-packages/win32/Demos: BackupRead_BackupWrite.py > Only in ActivePython-2.4.0-244-win32-ix86/INSTALLDIR/Lib/site-packages/win32/Demos: BackupSeek_streamheaders.py > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32/libs: pywintypes_d.lib > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: mmapfile_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: mmapfile_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: odbc_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: odbc_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: perfmondata_d.dll > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: perfmondata_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: perfmon_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: perfmon_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: pythonservice_d.exe > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: pythonservice_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32/scripts : setup_d.py > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: servicemanager_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: servicemanager_d.pyd > Only in ActivePython-2.4.0-244-win32-ix86/INSTALLDIR/Lib/site-packages/win32/test: test_win32event.py > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: timer_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: timer_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win2kras_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win2kras_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32api_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32api_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32clipboard_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32clipboard_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32event_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32event_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32evtlog_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32evtlog_d.pyd > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32file_d.pdb > Only in ActivePython-2.4.0-243-win32-ix86/INSTALLDIR/Lib/site-packages/win32: win32file_d.pyd > Only in ActiveP
Re: Unittesting for web applications
I believe there are xUnit clones named Httpunit and Htmlunit, as well as a number of variants. See the huge list of xUnit clones on: http://www.xprogramming.com/ in the downloads section. I don't think any of them are Python based, though. You might also want to look at some of the Htmlunit integration into FIT and Fitnesse. You can frequently get discussions on the Yahoo TDD list. John Roth "Sandip Bhattacharya" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Can someone suggest me some good resources for learning how to use unittests for web applications? Do we always have to cook up our own webpage scrapers to test the code? - Sandip -- Sandip Bhattacharya*Puroga Technologies * [EMAIL PROTECTED] Work: http://www.puroga.com *Home/Blog: http://www.sandipb.net/blog PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3 -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterate through dictionary of file objects and file names
Julian Yap wrote: In this particular coding snippet, I was thinking of creating a dictionary of file objects and file names. These would be optional files that I could open and parse. At the end, I would easily close off the files by iterating through the dictionary. Hi, File objects as keys sounds pretty dangerous. I'm curious why the first thought that popped into your head wasn't using the file NAMES as keys instead? Here's my go at it. (Is Google Groups nice to indentation using spaces? I can't remember.) optionalFiles = dict.fromkeys(['areacode.11', 'build.11'], None) # To open optionalFiles... for fileName in optionalFiles: try: optionalFiles[fileName] = open(fileName, "r") print "Opened: %s" % fileName except IOError: # Values are already initialized to None. print "File not found: %s" % fileName # To close optionalFiles... for fileName, fileObject in optionalFiles.iteritems(): if fileObject: fileObject.close() print "Closed: %s" % fileName # Rebinding fileObject here won't modify the dictionary, # so access it through the key. optionalFiles[fileName] = None -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: PHP session equivalent?
Walter Burleigh wrote: > Erik Johnson wrote: > >> There are a lot of things about PHP I was not too keen on and hence >> why >> my company is primarily doing Python these days, but one thing I was quite >> impressed with was the ease with which it provided session >> functionality... > > Like you I think it is a big plus of PHP as a beginner's web development > tool that it provides session management out of the box. It would certainly > make python more attractive for beginners if they could use session > management out of the box, too. (I know that there are lots of web > development frameworks, but they are to be too difficult to learn, if you > are new to web development). > > There is no module for session management in the python standard library. > But there are lots of python frameworks that would do this job well (my > favorite: cherrypy). If you think that a whole framework would be overkill, > you either could try to recylce the session part of an existing framework, > or you could write a module for yourself. > > I have written a module which is quite similar to the php session > management, except for that it does no url rewriting when cookies are not > allowed. If you are interested, I will mail you a copy. If you need session management, and do not want a complicated web app framework, check out pso: http://pso.sf.net Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: [EVALUATION] - E01: The Java Failure - May Python Helps?
Ilias Lazaridis wrote: [...] My question is essentially: How many of those constructs are already supported by python (and the surrounding open-source-projects): http://lazaridis.com/case/stack/index.html [...] The Signal/Noise ratio of this thread was very disapointing to me. I've expected better things from the python community. Thanks to everyone which has provided in-topic replies. . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Commerical graphing packages?
[EMAIL PROTECTED] writes: > Check out GRACE. It's not specifically designed for Python, but I've > been using with Python for a couple of years or more. I'm very happy > with it, and it's free. It works both interactively and in batch mode. > Do a google on GRACE. If you're generating lots of graphs programatically, eg. on a web server, grace is not what you want. Yes, it has a command language, but IIRC it depends on X11, and windows even pop up as it runs in batch mode. Bleh. Gets the job done for interactive editing of publication-quality scientific graphs, though. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing web applications
Josef Meile <[EMAIL PROTECTED]> writes: > > I'm looking for frameworks to make testing web applications - > > i.e. parsing and filling out forms - easier. I found Puffin, which > > looks good but not very usable in the current state. I know that I > > once read about other nice frameworks, but could not find one via > > google. Any hints? > Zope + Formulator is a nice combination to validating and designing > forms and add some functionality. If you want a more complicated content > management framework, then you can additionally install plain CMF or > Plone, which is based on CMF. There is also something called Silva, but > it doesn't have many products as the other two; however, it is also > nice. > > I have heard also about CherryPy, Quixote, Twisted Matrix and Webware, > but I haven't tested them. Once I saw that somebody posted a link, which > compares some of them, but I lost that thread :-( Did you read the question? :-) John -- http://mail.python.org/mailman/listinfo/python-list
[PATCH] Re: frozenset() without arguments should return a singleton
Terry Reedy schrieb: frozenset() called without arguments (or on empty sequences) should always return a singleton object. If we interpret 'should' as 'preferably by me', ok. It will take some programmer's time to add the special case check and run the test suite, and check in the changes. Yours? And perhaps some execution time for each frozenset call. Since frozenset is not much used, and multiple empty frozensets very rare, and the difference mostly invisible, the frozenset implementor probably went on to other things. I read 'not much used' and 'very rare' as 'I rarely use them'. Others may. It does not take much additional execution time, I just checked, a partial test is already in there that should be enough for the 'frozenset()' case. Additional tests for empty iterables would however be more costly and therefore not necessarily worth doing. Up to the maintainers. I don't have any experience in writing extension modules for the standard library and 'running the test suite'. Implementing the check is trivial, though. Could anyone please 'run the test suite' ? I tested it a bit, though, seems to work, including subclassing. Stefan --- Objects/setobject.c.ORIG2005-02-12 14:04:54.0 +0100 +++ Objects/setobject.c 2005-02-12 14:41:04.0 +0100 @@ -76,6 +76,8 @@ return (PyObject *)so; } +PyObject *frozen_empty_set = NULL; + static PyObject * frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -83,7 +85,14 @@ if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) return NULL; - if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) { + if (iterable == NULL) { + if (type == &PyFrozenSet_Type) { + if (frozen_empty_set == NULL) + frozen_empty_set = make_new_set(type, NULL); + Py_INCREF(frozen_empty_set); + return frozen_empty_set; + } + } else if (PyFrozenSet_CheckExact(iterable)) { Py_INCREF(iterable); return iterable; } --- Objects/setobject.c.ORIG2005-02-12 14:04:54.0 +0100 +++ Objects/setobject.c 2005-02-12 14:41:04.0 +0100 @@ -76,6 +76,8 @@ return (PyObject *)so; } +PyObject *frozen_empty_set = NULL; + static PyObject * frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -83,7 +85,14 @@ if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) return NULL; - if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) { + if (iterable == NULL) { + if (type == &PyFrozenSet_Type) { + if (frozen_empty_set == NULL) + frozen_empty_set = make_new_set(type, NULL); + Py_INCREF(frozen_empty_set); + return frozen_empty_set; + } + } else if (PyFrozenSet_CheckExact(iterable)) { Py_INCREF(iterable); return iterable; } -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to raw_input ?
Skip Montanaro wrote: How about modifying it to raw_input("Press ENTER to continue ") You want him to just capitalize ENTER in the current message? -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Web interface GUI??
Irmen de Jong a écrit: > Luc wrote: > >> So I am looking for another solution with a web interface that should >> work with linux and windows XP. >> I had a look to zope but was afraid with the complexity and debug >> difficulties. >> Are there some other solutions? > > Yes. A lot: http://www.python.org/moin/WebProgramming > I know someone who successfully created a web application > that runs from CD-ROM, using Snakelets. So you may want > to have a look at that one first, because this is quite > similar to what you want to do, right? > Then again I'm biased ofcourse. > Just have a quick look at the available libraries and > decide which one fits your needs most. > > --Irmen Thanks. It seems to be a good starting point -- http://mail.python.org/mailman/listinfo/python-list
Re: Commerical graphing packages?
Erik Johnson wrote: I am wanting to generate dynamic graphs for our website and ... >I am aware of ChartDirector (http://www.advsofteng.com/ ) which I have used ChartDirector extensively as an activeX (not from python though). We found the API to be well-though and clean. The tool is definitely worth the value. Simple to use and productive. It saved us a lot of time. A great product. François -- http://mail.python.org/mailman/listinfo/python-list
Docs. for logging module typo
The documentation for SMTPHandler say "The toaddrs should be a list of strings without domain names (That's what the mailhost is for)." which does not seem to be correct. The toaddr should be a list of strings like '[EMAIL PROTECTED]'. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Docs. for logging module typo
Peter Mott wrote: > The documentation for SMTPHandler say "The toaddrs should be a list of > strings without domain > names (That's what the mailhost is for)." which does not seem to be correct. > The toaddr should be > a list of strings like '[EMAIL PROTECTED]'. please report bugs and other issues via Python's issue tracker: www.python.org => bugs -- http://mail.python.org/mailman/listinfo/python-list
Newbie needs help with canvas.create_image !
Ok, this is my problem: With code below I get a red box with given width and height. When I use that create_image, nothing happens. I only see that same red box. Why is that? The loop.bmp is working fine when I use show() method. win = Toplevel() canvas = Canvas(win, width=100, height=100, background='red') canvas.pack() im = Image.open("loop.bmp") photo = ImageTk.PhotoImage(im) canvas.create_image(8, 8, anchor="nw", image=photo) (Interestingly loop.bmp appears to the red box if I try to pack that canvas.create_image ( canvas.create_image.pack()) and ofcourse I also get an error message that It can't be done. But anyway the picture appears ...weird) -- http://mail.python.org/mailman/listinfo/python-list
Re: a sequence question
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > A bug report on Sourceforge would help in getting the problem fixed for the 2.5 > docs Done. > For the 'left-to-right' evaluation thing, that's technically an implementation > artifact of the CPython implementation, since the zip() docs don't make any > promises. So updating the docs to include that information would probably be a > bigger issue, as it involves behaviour which is currently not defined by the > library. OK, thanks. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs help with canvas.create_image !
Antti Isomursu wrote: > With code below I get a red box with given width and height. When I > use that create_image, nothing happens. I only see that same red box. > Why is that? > The loop.bmp is working fine when I use show() method. > >win = Toplevel() > >canvas = Canvas(win, width=100, height=100, background='red') >canvas.pack() > >im = Image.open("loop.bmp") >photo = ImageTk.PhotoImage(im) > >canvas.create_image(8, 8, anchor="nw", image=photo) the problem might be that the PhotoImage is garbage collected before being displayed. see the note on the bottom of this page for details: http://effbot.org/zone/tkinter-photoimage.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Unittesting for web applications
There's another current thread on c.l.py talking about testing Web applications. Somenone suggested Jython in conjunction with HttpUnit, a combination that worked for me too -- but the name HttpUnit is misleading, since it does functional/black box testing and not unit testing. It beats scraping Web pages though, so it may be sufficient for what you need. You can see a mini-tutorial I wrote at http://agiletesting.blogspot.com/2005/02/web-app-testing-with-jython-and.html I don't know any Python-specific frameworks for Web app unit testing. In the Java world, there's Cactus at http://jakarta.apache.org/cactus/. To quote from that page, "Cactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters, ...)." So this is pretty much Java-centric and may not help you much. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a safe marshaler?
[Irmen de Jong] Interestingly enough, I just ran across "Flatten": http://sourceforge.net/project/showfiles.php?group_id=82591&package_id=91311 "...which aids in serializing/unserializing networked data securely, without having to fear execution of code or the like." Sounds promising! Well, I'm always dubious of OSS projects that don't even have any bugs reported, let alone fixed: no patches submitted, etc, etc. http://sourceforge.net/tracker/?group_id=82591 Though maybe I'm missing something obvious? -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Message could not be delivered
The message could not be delivered *** ** A csatolmány message.zip I-Worm.Mydoom.R virussal fertõzött, ** a csatolmány törölve lett. *** -- http://mail.python.org/mailman/listinfo/python-list
Re: exception handling for a function returning several values
On 2005-02-12, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > If a function that normally returns N values raises an exception, what > should it return? Maybe it shouldn't return anything but instead of cathing the exception it should let the caller handle it. > N values of None seems reasonable to me, so I would > write code such as > > def foo(x): > try: ># code setting y and z >return y,z > except: >return None,None > > y,z = foo(x) > > If I try to use y or z inappropriately when they are None, the program > will stop. An alternative is to return an error flag in addition to y > and z from function foo and check the value of the error flag in the > calling program. This seems a bit awkward. what about the following. def foo(x): # code setting y and z return x,z try y,z = foo(x) except ... : # Handle errors. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
SCons build tool speed
How does the speed of the Scons build tool compare with Ant? Right now with out Ant builds take around an hour. Hoping to speed that up. TIA, Ted -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a safe marshaler?
Alan Kennedy wrote: [Irmen de Jong] Interestingly enough, I just ran across "Flatten": http://sourceforge.net/project/showfiles.php?group_id=82591&package_id=91311 "...which aids in serializing/unserializing networked data securely, without having to fear execution of code or the like." Sounds promising! Well, I'm always dubious of OSS projects that don't even have any bugs reported, let alone fixed: no patches submitted, etc, etc. http://sourceforge.net/tracker/?group_id=82591 Though maybe I'm missing something obvious? Perhaps the SF trackers are simply not used for that project? Consider my own project: http://sourceforge.net/tracker/?group_id=18837 I can assure you that I have fixed and applied a huge amount of bugs and patches during the lifetime of the project. They are just not entered in the trackers, except for a few. --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs help with canvas.create_image !
On Sat, 12 Feb 2005 18:24:11 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Antti Isomursu wrote: > >> With code below I get a red box with given width and height. When I >> use that create_image, nothing happens. I only see that same red box. >> Why is that? >> The loop.bmp is working fine when I use show() method. >> >>win = Toplevel() >> >>canvas = Canvas(win, width=100, height=100, background='red') >>canvas.pack() >> >>im = Image.open("loop.bmp") >>photo = ImageTk.PhotoImage(im) >> >>canvas.create_image(8, 8, anchor="nw", image=photo) > >the problem might be that the PhotoImage is garbage collected before being >displayed. see the note on the bottom of this page for details: > >http://effbot.org/zone/tkinter-photoimage.htm > > I had run into this for the first time recently as well. and found this tutor thread helped. http://starship.python.net/pipermail/python-de/2002q4/002834.html Declaring "im" as global is one way to go (there I said it). In fact, IMO, probably the clearest (though not the prettiest) way to go under under the circumstances. I don't think anyone is particularly defending the circumstances. I have heard the circumstances described as a bug, and the various "solutions" are perhaps better thought of as work-arounds. Art -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: pyMinGW support for Python 2.3.5 (final) is available
[snip] > Ha anyone tried cross compiling python with mingw? At work we compile > our software for lots of platforms (including windows) on a linux > build host. The windows builds are done with a mingw cross compiler. > It would be interesting if we could do this with python + extensions > also. Yes, I was thinking of setting up a cross-compiling system, but why would you use mingw instead of just gcc on Linux? Only cross-compiling I've ever done is on RISC OS. I use VMWare to accomplish a similar goal though, compiling stuff for old 64Mb P233's running RedHat7 is a lot faster when done on a 1Gb/2.5GHz VMWare machine! I just finished compiling Qt/PyQt/QScintilla/SIP for Python 2.4 using MinGW on Windows, and can say that MSVC6 was at least twice as fast, and required less patching to get it working, plus it's one less DLL and the binaries are about 20% smaller. I also can't seem to get PyQt apps working on Win98SE when using the MinGW build (2000 and XP work fine). Maybe I'll fork out the 100usd for Visual Studio .NET 2003 after all -- http://mail.python.org/mailman/listinfo/python-list
Re: Is email package thread safe? (fwd)
On Thu, 10 Feb 2005, Antoon Pardon wrote: Op 2005-02-09, Roman Suzi schreef <[EMAIL PROTECTED]>: On Wed, 9 Feb 2005, Antoon Pardon wrote: Op 2005-02-09, Roman Suzi schreef <[EMAIL PROTECTED]>: Just to be sure, is email package of Python 2.3 thread-safe or not (to use, for example, in python-milter?) Can I assume that everything else without such notice is thread-safe? I doubt it. There is no indication that the email package uses any kind of locking. So multiple thread working on the same message will probably screw things up. Of course, I do not let threads to work on the same message! Why should that be: "off course"? The random module you spoke about was also only thread unsafe if you called the same random generator from various threads. Using a randon generator per thread shouldn't have been a problem. Since you mentioned that, I thought that was the kind of thread safety you were after. I meant that the package doesn't pose other kinds of restrictions. Can it work in _any_ situation work on two different messages at the same time, without any interference? I can't give a guarantee, but there are no global statements and there doesn't seem to be assignments to cross module variables I think it would be a safe bet. Thanks to all who discussed this. Really, I had the same thoughts about 1:1 object-thread relation being thread safe. I am doing further research and if it will give interesting results, I shall post [solved] here. Sincerely yours, Roman Suzi -- [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: pyMinGW support for Python 2.3.5 (final) is available
Simon John wrote: Maybe I'll fork out the 100usd for Visual Studio .NET 2003 after all $100? Where? Last time I looked it was closer to $800. --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Python UPS / FedEx Shipping Module
Are the modules just accessing the published apis for their webservices? I'm just wondering because I used to work for a logistics mgmt company that paid money to be a strategic partner with FedEx/UPS/Airborn etc so that they could information on how to return rates/print labels/generate edi's/calculate arrival times etc. I'd get a good laugh out of it suddenly being freely available now. On Fri, 11 Feb 2005 19:00:25 -0800 (PST), Kartic <[EMAIL PROTECTED]> wrote: > Gabriel Cooper said the following on 2/11/2005 2:23 PM: > > I've made UPS and FedEx shipping rate request modules in python using > > XML. Is there an interest in putting this on the web? > > I am interested in it for educational value, if not anything else. > Please post the web address from which to download. > > Thanks! > -Kartic > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thomas G. Willis http://paperbackmusic.net -- http://mail.python.org/mailman/listinfo/python-list