Re: unsigned 32 bit arithmetic type?

2006-10-25 Thread Robin Becker
Martin v. Löwis wrote: > Robin Becker schrieb: >> def add32(x, y): >> "Calculate (x + y) modulo 2**32" >> return ((x&0xL)+(y&0xL)) & 0xL > > That's redundant; it is sufficient to write > > return (x+y) & 0x > >> def calcChecksum(d

Re: Python's CRT licensing on Windows <-- FUD

2006-10-25 Thread Martin v. Löwis
sturlamolden schrieb: > Is further "distribution" okay if it is only accompanied by the python > runtime DLL (as is the case when using Py2Exe) or should the entire > python-2.4.4.msi from python.org be "distributed"? As Fredrik Lundh says: Ask your lawyer. We cannot really interpret the Microsoft

Re: Sorting by item_in_another_list

2006-10-25 Thread Paul McGuire
"J. Clifford Dyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > ZeD wrote: >> Paul Rubin wrote: >> A = [0,1,2,3,4,5,6,7,8,9,10] B = [2,3,7,8] desired_result = [2,3,7,8,0,1,4,5,6,9,10] >>> How about: >>> >>> desired_result = B + sorted(x for x in A if x not in

Re: unsigned 32 bit arithmetic type?

2006-10-25 Thread Robin Becker
sturlamolden wrote: > import numpy > def CalcTableChecksum(Table, Length=None): >tmp = numpy.array(Table,dtype=numpy.uint32) >if Length == None: Length = tmp.size >endptr = ((Length+3) & ~3) / 4 >return (tmp[0:endptr]).sum() > it's probably wonderful, but I don't think I can ask p

Re: python GUIs comparison (want)

2006-10-25 Thread Stephen Eilert
BartlebyScrivener wrote: > Well, I am woefully unqualified to speak to the general state of Python > gui frameworks, but I am in a similar situation as the OP, i.e., a > beginner looking to TRY some easy gui programming in Python. Not being > a computer science person, just an amateur scripter, I

Re: unsigned 32 bit arithmetic type?

2006-10-25 Thread Martin v. Löwis
Robin Becker schrieb: > I can see the advantage in the summation case where all the numbers are > known positive, however the full problem includes cases where there's an > "adjustment" to the sum and that usually ends up like this > > adjustment = unpack('>l', table[8:8+4])[0] > checksum

Re: Python's CRT licensing on Windows <-- FUD

2006-10-25 Thread sturlamolden
Martin v. Löwis wrote: > As Fredrik Lundh says: Ask your lawyer. We cannot really interpret the > Microsoft license for you (I can only give it to you in case you don't > have it), and I can't formally give you permission to do copy something > that Microsoft has the copyright to. I wasn't askin

chained attrgetter

2006-10-25 Thread David S.
Does something like operator.getattr exist to perform a chained attr lookup? I came up with the following, but I can not help but think it is already done and done better. Peace, David S. def compose(funcs): """ return composite of funcs this does not support extended call syntax, so

Re: python GUIs comparison (want)

2006-10-25 Thread Douglas Soares de Andrade
Stephen Eilert escreveu: > BartlebyScrivener wrote: > >> Well, I am woefully unqualified to speak to the general state of Python >> gui frameworks, but I am in a similar situation as the OP, i.e., a >> beginner looking to TRY some easy gui programming in Python. Not being >> a computer science p

Re: unsigned 32 bit arithmetic type?

2006-10-25 Thread Robin Becker
Martin v. Löwis wrote: > As I said: you need to fix the final outcome: > > py> x = 0xL > py> hex(x) > '0xL' > > > and so on. Whether you perform the modulo operation after > each step, or only at the end, has no impact on the result. All hail congruency classe

cleaner way to write this?

2006-10-25 Thread John Salerno
Hi guys. I'm looking for a nicer, more compact way of writing this code. It doesn't have to be anything fancy, just something without the duplication and preferably only one return statement. def create_db_name(self): dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',

Re: cleaner way to write this?

2006-10-25 Thread Farshid Lashkari
John Salerno wrote: > Hi guys. I'm looking for a nicer, more compact way of writing this code. > It doesn't have to be anything fancy, just something without the > duplication and preferably only one return statement. > > def create_db_name(self): > dlg = wx.TextEntryDialog(self.fram

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > if dlg.ShowModal() == wx.ID_OK: > db_name = dlg.GetValue() > dlg.Destroy() > return db_name > else: > dlg.Destroy() > return I like if dlg.ShowModal() == wx.ID_OK:

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > I like > > if dlg.ShowModal() == wx.ID_OK: > db_name = dlg.GetValue() > else: > db_name = None > dlg.Destroy() > return db_name > > better than > > db_name = None > if dlg.ShowModal() == wx.ID_OK: > db_name = dlg.GetValue()

Re: cleaner way to write this?

2006-10-25 Thread Farshid Lashkari
Paul Rubin wrote: > I like > > if dlg.ShowModal() == wx.ID_OK: > db_name = dlg.GetValue() > else: > db_name = None > dlg.Destroy() > return db_name > > better than > > db_name = None > if dlg.ShowModal() == wx.ID_OK: > db_name = dlg.GetValue() >

ANN: Diamanda Wiki and MyghtyBoard Forum Test 1

2006-10-25 Thread [EMAIL PROTECTED]
Diamanda Wiki and MyghtyBoard Forum Test 1 Diamanda is a wiki django application and Myghty Board is a bulletin board application. Both written in Django >= 0.95. Download: http://sourceforge.net/project/showfiles.php?group_id=163611&package_id=208996 or the latest code from SVN at http://code.g

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
John Salerno wrote: > Hi guys. I'm looking for a nicer, more compact way of writing this code. Ok, one more thing. Let's assume I'm using this (or the other): def create_db_name(self): dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',

Re: Sorting by item_in_another_list

2006-10-25 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> ZeD wrote: >>> Paul Rubin wrote: >>> > A = [0,1,2,3,4,5,6,7,8,9,10] > B = [2,3,7,8] > > desired_result = [2,3,7,8,0,1,4,

Re: unsigned 32 bit arithmetic type?

2006-10-25 Thread sturlamolden
Robin Becker wrote: > it's probably wonderful, but I don't think I can ask people to add numpy to > the > list of requirements for reportlab :) Maybe NumPy makes it into the core Python tree one day. At some point other Python users than die-hard scientists and mathematicans will realise that f

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > I just need some advice for how to structure > the check of the empty string. How about return db_name or None since the empty string taken as a boolean is False. -- http://mail.python.org/mailman/listinfo/python-list

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > John Salerno <[EMAIL PROTECTED]> writes: >> I just need some advice for how to structure >> the check of the empty string. > > How about > > return db_name or None > > since the empty string taken as a boolean is False. But if the user doesn't enter any text, I don't wan

Re: Sorting by item_in_another_list

2006-10-25 Thread J. Clifford Dyer
Right you are. I was a bit hasty. Many thanks. Cliff Paul McGuire wrote: > > From the original post: > > "I have two lists, A and B, such that B is a subset of A." > -- http://mail.python.org/mailman/listinfo/python-list

Re: https client certificate validation

2006-10-25 Thread Heikki Toivonen
Yogesh Chawla - PD wrote: > After writing a basic script using HTTPSConnection, I > found this in the docs: > > Warning: This does not do any certificate > verification! Right, for production you use almost certainly need to use some 3rd party SSL library, of which there are several. > I then tr

Re: call Mac gcc -framework from CTypes how

2006-10-25 Thread p . lavarre
> can I somehow call the IONotificationPortCreate in the > Framework that Apple built instead, $ cd /System/Library/Frameworks/ $ cd IOKit.framework/Versions/Current/ $ file IOKit ... Mach-O dynamically linked shared library ... $ nm -m IOKit | grep IONotificationPortCreate ... (__TEXT,__text) ext

Re: Python's CRT licensing on Windows <-- FUD

2006-10-25 Thread Istvan Albert
sturlamolden wrote: > Maybe someone have gone through the trouble and got a clear answer from > Microsoft. As far as companies go the EULA is as clear of an answer as you can possibly hope for. As for the original post, don't bother with it this issue, the chances that MS will start harassing yo

question about True values

2006-10-25 Thread John Salerno
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? >>> s = 'hello' >>> s == True False >>> if s: print 'hi' hi >>> Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Diamanda Wiki and MyghtyBoard Forum Test 1

2006-10-25 Thread Jonathan Ellis
[EMAIL PROTECTED] wrote: > Diamanda Wiki and MyghtyBoard Forum Test 1 > > Diamanda is a wiki django application and Myghty Board is a bulletin > board application. Both written in Django >= 0.95. Might want to re-think your bboard app's name; people might think it runs on Myghty. :) -Jonathan -

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > But if the user doesn't enter any text, I don't want the method to > return at all (even None). I need an error dialog to pop up and tell > him to enter a value (or press Cancel). Oh, I see. You really want something like repeat...while, which Python doe

new-style classes, __hash__. is the documentation wrong?

2006-10-25 Thread gabor
hi, if you have a new-style class, it will have a __hash__ method, even if you don't define it, because it inherits from object(). and, if you implement __eq__, then that default-hash-value will be probably wrong. i understand that this is a bug, and described here: http://www.python.org/sf/6

Re: ANN: Diamanda Wiki and MyghtyBoard Forum Test 1

2006-10-25 Thread [EMAIL PROTECTED]
> Might want to re-think your bboard app's name; people might think it > runs on Myghty. :) > > -Jonathan It did in very early stages ;) I've kept the name and if someone wants - using myghty templates in Django is very easy. -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining SSL certificate info from SSL object - BUG?

2006-10-25 Thread Heikki Toivonen
John Nagle wrote: > The Python SSL object offers two methods from obtaining > the info from an SSL certificate, "server()" and "issuer()". > The actual values in the certificate are a series of name/value > pairs in ASN.1 binary format. But what "server()" and "issuer()" > return are strings,

Re: SSL follow up

2006-10-25 Thread Heikki Toivonen
Yogesh Chawla - PD wrote: > I have 2 questions. 1) How do we get the Server cert > in python. John wrote: "Nor does there seem to be a > way to get at the certificate itself from within > Python." Perhaps pycurl will allow us to do this. Is > there another method to get the server cert? Here's

Re: Python's CRT licensing on Windows

2006-10-25 Thread Dale Strickland-Clark
To paraphrase an applicant for a job vacancy we're currently filling when asked to give an example of their problem solving skills: A client had a problem with Windows XP on his laptop. I reformatted his hard disk and installed Red Hat. Problem solved. -- Dale Strickland-Clark Riverhall Systems

Re: question about True values

2006-10-25 Thread skip
John> I'm a little confused. Why doesn't s evaluate to True in the first John> part, but it does in the second? Is the first statement something John> different? >>> s = 'hello' >>> s == True False >>> if s: ... print 'hi' hi s is not equal to the bool

Re: question about True values

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > I'm a little confused. Why doesn't s evaluate to True in the first > part, but it does in the second? Is the first statement something > different? No. True and False are boolean values, where booleans are a different data type from strings, just like st

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > Oh, I see. You really want something like repeat...while, which Python > doesn't have. Anyway I start to prefer something like (untested): > > def create_db_name(self): > try: > while True: >dlg = wx.TextEntryDialog(self.frame, 'Ente

Re: Python and SSL enabled

2006-10-25 Thread Heikki Toivonen
matey wrote: > I am have version 2.3.4. I want to write a python script to access a > secure HTTPS. > > I tried the following: > > import urllib > urllib.urlopen("https://somesecuresite.com";) > s = f.read() > f.close() I hope you know the Python stdlib SSL does not provide certificate checking

Re: question about True values

2006-10-25 Thread Mike Kent
John Salerno wrote: > I'm a little confused. Why doesn't s evaluate to True in the first part, > but it does in the second? Is the first statement something different? > > >>> s = 'hello' > >>> s == True > False > >>> if s: > print 'hi' > > > hi > >>> > > Thanks. Excellent question!

Re: question about True values

2006-10-25 Thread John Coleman
Paul Rubin wrote: > John Salerno <[EMAIL PROTECTED]> writes: > > I'm a little confused. Why doesn't s evaluate to True in the first > > part, but it does in the second? Is the first statement something > > different? > > No. True and False are boolean values, where booleans are a different > data

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > > def create_db_name(self): > > try: > > while True: > >dlg = wx.TextEntryDialog(self.frame, 'Enter a database > > name:', > >'Create New Database') > >if dl

Re: question about True values

2006-10-25 Thread John Salerno
Paul Rubin wrote: > No. True and False are boolean values, where booleans are a different > data type from strings, just like strings are different from integers. > > >>> if s: > print 'hi' > > converts s to a boolean during evaluation. Oh!!! I get it now! I was thinking that if s w

Re: question about True values

2006-10-25 Thread Robert Kern
John Salerno wrote: > I'm a little confused. Why doesn't s evaluate to True in the first part, > but it does in the second? Is the first statement something different? > > >>> s = 'hello' > >>> s == True > False > >>> if s: > print 'hi' > > > hi > >>> They are, indeed, quite

Re: question about True values

2006-10-25 Thread Fredrik Lundh
John Salerno wrote: > I'm a little confused. Why doesn't s evaluate to True in the first part, > but it does in the second? Is the first statement something different? > > >>> s = 'hello' > >>> s == True > False > >>> if s: > print 'hi' "true" != "True". comparing a value to another v

Re: question about True values

2006-10-25 Thread Tim Chase
> I'm a little confused. Why doesn't s evaluate to True in the first part, > but it does in the second? Is the first statement something different? > > >>> s = 'hello' > >>> s == True > False > >>> if s: > print 'hi' The "if s" does an implicit (yeah, I know, "explicit is better than

Re: question about True values

2006-10-25 Thread Paul Rubin
"John Coleman" <[EMAIL PROTECTED]> writes: > > then "x == 3" is false, but "int(x) == 3" is true. > But then why is 3.0 == 3 true? They are different types. The 3 gets converted to float, like when you say x = 3.1 + 3 the result is 6.1. -- http://mail.python.org/mailman/listinfo/python-list

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > Right. The above handles that case, I believe. Oh, you're right! It's amazing how this went from a simple, two-line method to a big mess of error-checking. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > if (10 > 5) > would be the same as > if (10 > 5) == True Yes. -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-25 Thread John Salerno
John Coleman wrote: > But then why is 3.0 == 3 true? They are different types. > Good question. Does one type get converted to the other automatically? That's all I can think of... -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-25 Thread John Salerno
Robert Kern wrote: > They are, indeed, quite different things. Finding the truth value of an > object is not the same thing as testing if the object is equal to the > object True. Yeah, I had this in the back of my mind, but I was thinking that this test would be written as if s is True And

Using classes in python

2006-10-25 Thread trevor lock
Hello,I've just started using python and have observed the following :class foo:    a=[]    def __init__(self, val):    self.a.append ( val )    def getA(self):    print self.a    return self.az = foo(5)y = foo(4)z.getA()>> [5, 4]I was expecting that everytime I created an i

Re: new-style classes, __hash__. is the documentation wrong?

2006-10-25 Thread Klaas
gabor wrote: > > If a class defines mutable objects and implements a __cmp__() or > __eq__() method, it should not implement __hash__(), since the > dictionary implementation requires that a key's hash value is immutable > (if the object's hash value changes, it will be in the wrong hash buck

Re: question about True values

2006-10-25 Thread Tim Chase
> So I suppose > > if (10 > 5) > > would be the same as > > if (10 > 5) == True > > because (10 > 5) does evaluate to "True". Yes...and similarly, if ((10 > 5) == True) == True for the same reason...as does if (((10 > 5) == True) == True) == True as does... :*) -tkc -- http://mail.pyt

with statements and exceptions

2006-10-25 Thread John Salerno
I'm thinking about using a with statement for opening a file, instead of the usual try/except block, but I don't understand where you handle an exception if the file doesn't open. For example: with open('myfile', 'r'): BLOCK I assume that BLOCK can/will contain all the other stuff you want

Re: ZODB for inverted index?

2006-10-25 Thread Klaas
[EMAIL PROTECTED] wrote: > Hello, Hi. I'm not familiar with ZODB, but you might consider berkeleydb, which behaves like a disk-backed + memcache dictionary. -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-25 Thread John Coleman
Paul Rubin wrote: > "John Coleman" <[EMAIL PROTECTED]> writes: > > > then "x == 3" is false, but "int(x) == 3" is true. > > But then why is 3.0 == 3 true? They are different types. > > The 3 gets converted to float, like when you say > > x = 3.1 + 3 > > the result is 6.1. Yes - it just seems th

Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Kenneth McDonald
This is possible with pure Python classes. Just add the method as new attribute of the class. However, that won't work for the builtins. I know that this is somewhat dangerous, and also that I could subclass the builtins, but not being able to do things like '[1,2,3]'.length drives me a little

How to identify generator/iterator objects?

2006-10-25 Thread Kenneth McDonald
I'm trying to write a 'flatten' generator which, when give a generator/iterator that can yield iterators, generators, and other data types, will 'flatten' everything so that it in turns yields stuff by simply yielding the instances of other types, and recursively yields the stuff yielded by the

Re: with statements and exceptions

2006-10-25 Thread John Salerno
John Salerno wrote: > I'm thinking about using a with statement for opening a file, instead of > the usual try/except block, but I don't understand where you handle an > exception if the file doesn't open. For example: > > with open('myfile', 'r'): > BLOCK > > I assume that BLOCK can/will c

Re: with statements and exceptions

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > def create_sql_script(self): > with open('labtables.sql') as sql_script: > return sql_script.read() > > Does the file still get closed even though I have a return statement > inside the with block? Yes, I think so. I'm not run

Re: cleaner way to write this?

2006-10-25 Thread Neil Cerutti
On 2006-10-25, John Salerno <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: > >> Right. The above handles that case, I believe. > > Oh, you're right! It's amazing how this went from a simple, > two-line method to a big mess of error-checking. :) >From Kernighan & Pike, _The Practice of Programmin

Re: question about True values

2006-10-25 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb: > the string class's "nil" value. Each of the builtin types has such an > "empty" or "nil" value: > > string "" > list[] > tuple () > dict{} > int 0 > float

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread bearophileHUGS
Kenneth McDonald: > not being able to do things like '[1,2,3]'.length > drives me a little nuts. This is interesting, why? (In a computer language too much purity is often bad. And isn't [1,2,3].len better?) I think you can't add methods to Python builtin classes, I think you can do it with Ruby.

Re: How to identify generator/iterator objects?

2006-10-25 Thread Paddy
Kenneth McDonald wrote: > I'm trying to write a 'flatten' generator which, when give a > generator/iterator that can yield iterators, generators, and other data > types, will 'flatten' everything so that it in turns yields stuff by > simply yielding the instances of other types, and recursively yi

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Neil Cerutti wrote: > This completes our C version [of a csv reading library]. It > handles arbitrarily large inputs and does something sensible > even with perverse data. The price is that it is more than four > times as long as the first prototype and some of the code is > intricate. S

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > def create_db_name(self): > try: > while True: >dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:', >'Create New Database') >if dlg.ShowModal() != wx.ID_OK: >

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Paddy
Kenneth McDonald wrote: > This is possible with pure Python classes. Just add the method as new > attribute of the class. However, that won't work for the builtins. > > I know that this is somewhat dangerous, and also that I could subclass > the builtins, but not being able to do things like '[1,2

Is there a python development site for putting up python libraries that people might be interest in working on?

2006-10-25 Thread Kenneth McDonald
Over the last couple of years, I've built a module called rex that lays on top of (and from the user's point of view, hides) the re module. rex offers the following advantages over re. * Construction of re's is object oriented, and does not require any knowledge of re syntax. * rex is _very goo

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > Interesting idea to use try/finally to ensure that dlg.Destroy() runs > even with a return earlier in the method. Would this be considered > appropriate use though, or would it be misusing try/finally? I thought > the point of a try block was for when you

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Neil Cerutti
On 2006-10-25, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Kenneth McDonald: >> not being able to do things like '[1,2,3]'.length >> drives me a little nuts. > > This is interesting, why? > (In a computer language too much purity is often bad. And isn't > [1,2,3].len better?) > > I think you can

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Tim Chase
> the builtins, but not being able to do things like > '[1,2,3]'.length drives me a little nuts. You mean like '[1,2,3]'.__len__() That gets you the length of the string, which is what one would expect, calling the __len__() method on a string. The same works for an array:

[OT] Need Python Programmer for contract work

2006-10-25 Thread Blake Girardot
Hi, Sorry to intrude on the list, but I am looking for an experienced Python programmer to do some maintenance on an existing 800 line python script and this seemed like it might be a good source. The script reads IPTC info from images and then does some various file handling based on the values

Re: cleaner way to write this?

2006-10-25 Thread Fredrik Lundh
Paul Rubin wrote: >> but given that try/except and try/finally used to be separate >> blocks, > > That old separation was just an artifact of how the parser was > originally written, I believe. $ more Misc/HISTORY New features in 0.9.6: - stricter try stmt syntax: cannot mix except and

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > Interesting idea to use try/finally to ensure that dlg.Destroy() runs > even with a return earlier in the method. Note that the code is wrong, the dialog should either be created outside the while loop, or destroyed inside it. I don't know wx so I'm not

Re: Is there a python development site for putting up python libraries that people might be interest in working on?

2006-10-25 Thread bearophileHUGS
Kenneth McDonald: > * Construction of re's is object oriented, and does not require any > knowledge of re syntax. I have partially done something similar, so I am interested. Does rex outputs normal REs? Or does it wraps them in some way? A normal RE output has some advantages, even if you can't h

Re: cleaner way to write this?

2006-10-25 Thread Michael S
How about this? def create_db_name(self): dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:', 'Create New Database') db_name = None #or db_name = "" if dlg.ShowModal() == wx.ID_OK: db_name = dlg.GetValue()

Re: cleaner way to write this?

2006-10-25 Thread John Salerno
Paul Rubin wrote: > John Salerno <[EMAIL PROTECTED]> writes: >> Interesting idea to use try/finally to ensure that dlg.Destroy() runs >> even with a return earlier in the method. > > Note that the code is wrong, the dialog should either be created > outside the while loop, or destroyed inside it.

Re: chained attrgetter

2006-10-25 Thread Alexey Borzenkov
On Oct 25, 10:00 pm, "David S." <[EMAIL PROTECTED]> wrote: > Does something like operator.getattr exist to perform a chained attr > lookup? Do you mean something like class cattrgetter: def __init__(self, name): self.names = name.split('.') def __call__(self, obj): for nam

Re: Is there a python development site for putting up python libraries that people might be interest in working on?

2006-10-25 Thread Martin v. Löwis
Kenneth McDonald schrieb: > I would like to avoid putting this up on sourceforge as I think it would > do much better at a site aimed specifically at Python development. As somebody else said: you should put the code and announce the package at the Cheeseshop: cheeseshop.python.org. This doesn't

Re: question about True values

2006-10-25 Thread Martin v. Löwis
John Coleman schrieb: > Yes - it just seems that there isn't a principled reason for implicitly > converting 3 to 3.0 in 3.0 == 3 but not implicitly converting "cat" to > boolean in "cat" == true. Sure there is: equality should be transitive. So while we have 3 == 3L == 3.0 == 3.0+0j and can there

Re: Using classes in python

2006-10-25 Thread Éric Daigneault
trevor lock wrote: > Hello, > > I've just started using python and have observed the following : > > class foo: > a=[] > def __init__(self, val): > self.a.append ( val ) > def getA(self): > print self.a > return self.a > > z = foo(5) > y = foo(4) > z.

Re: How to identify generator/iterator objects?

2006-10-25 Thread Leo Kislov
Kenneth McDonald wrote: > I'm trying to write a 'flatten' generator which, when give a > generator/iterator that can yield iterators, generators, and other data > types, will 'flatten' everything so that it in turns yields stuff by > simply yielding the instances of other types, and recursively yi

Re: How to identify generator/iterator objects?

2006-10-25 Thread Michael Spencer
Kenneth McDonald wrote: > I'm trying to write a 'flatten' generator which, when give a > generator/iterator that can yield iterators, generators, and other data > types, will 'flatten' everything so that it in turns yields stuff by > simply yielding the instances of other types, and recursively

Re: How to identify generator/iterator objects?

2006-10-25 Thread Martin v. Löwis
Kenneth McDonald schrieb: > To do this, I need to determine (as fair as I can see), what are > Is there a way to do this? Or perhaps another (better) way to achieve > this flattening effect? itertools doesn't seem to have anything that > will do it. As others have pointed out, there is a proper te

Re: cleaner way to write this?

2006-10-25 Thread Bruno Desthuilliers
John Salerno a écrit : > Paul Rubin wrote: > >> John Salerno <[EMAIL PROTECTED]> writes: >> >>> I just need some advice for how to structure >>> the check of the empty string. >> >> >> How about >> >> return db_name or None >> >> since the empty string taken as a boolean is False. > > > But

Re: cleaner way to write this?

2006-10-25 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > > But if the user doesn't enter any text, I don't want the method to > > return at all (even None). > > John, please re-read the FineManual(tm). None is the default return > value of a function - even if there's no return statement. Correct, but i

Re: question about True values

2006-10-25 Thread John Coleman
Martin v. Löwis wrote: > John Coleman schrieb: > > Yes - it just seems that there isn't a principled reason for implicitly > > converting 3 to 3.0 in 3.0 == 3 but not implicitly converting "cat" to > > boolean in "cat" == true. > > Sure there is: equality should be transitive. So while we have > 3

Re: Save/Store whole class (or another object) in a file

2006-10-25 Thread Gabriel Genellina
At Wednesday 25/10/2006 11:32, [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > thanks for the reply,but unfortunately this does not work with the type > > of classes I am dealing with. When trying to pickle the class I get the > > following error: > > > > File "/usr

Re: How to identify generator/iterator objects?

2006-10-25 Thread Leo Kislov
Michael Spencer wrote: > Kenneth McDonald wrote: > > I'm trying to write a 'flatten' generator which, when give a > > generator/iterator that can yield iterators, generators, and other data > > types, will 'flatten' everything so that it in turns yields stuff by > > simply yielding the instances o

Re: Is there a python development site for putting up python libraries that people might be interest in working on?

2006-10-25 Thread Steven Bethard
Kenneth McDonald wrote: > I would like to avoid putting this up on sourceforge as I think it would > do much better at a site aimed specifically at Python development. I've been using python-hosting.com for the argparse module and found it to be a pretty good solution. They offer free Trac/Subv

Re: Getting a lot of SPAM from this list

2006-10-25 Thread TiNo
How do you send and receive this email?24 Oct 2006 22:12:35 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>: I've given up on email pretty much.  I no longer have a public emailaddress of any type.  I just give out a URL (including on my resume,business cards, etc), which leads to a HTTPS contac

Re: 255 argument limit?

2006-10-25 Thread [EMAIL PROTECTED]
> >It appears that there is a 255 argument limit in Python 2.4.3? > maybe the argument limit is for the sake of not making functions too complicated. if your function takes more than 200 arguments it can probably go to thedailywtf.com, better be strict like i am and even avoid making a 100 arg

Re: question about True values

2006-10-25 Thread George Sakkis
Martin v. Löwis wrote: > [EMAIL PROTECTED] schrieb: > > the string class's "nil" value. Each of the builtin types has such an > > "empty" or "nil" value: > > > > string "" > > list[] > > tuple () > > dict{} > > int

Tortoise, Hare, Hell, None

2006-10-25 Thread Clarence
Five and a half years ago, Tim Peters (glory be to his name) made the following statement: > In that respect, None is unique among non-keyword names, and for that reason > alone it should be a keyword instead of a global. I expect that will happen > someday, too. But it's a race between that and

Re: Getting a lot of SPAM from this list

2006-10-25 Thread Fredrik Lundh
TiNo wrote: > How do you send and receive this email? email? -- http://mail.python.org/mailman/listinfo/python-list

FAQ - How do I declare that a CTypes function returns void?

2006-10-25 Thread p . lavarre
Now at http://pyfaq.infogami.com/suggest we have: FAQ: How do I declare that CTypes function returns void? A: c_void = None is not doc'ed, but is suggested by: >>> ctypes.POINTER(None) >>> Remembering c_void = c_int from K&R C often works, but if you say a restype is c_int, then doctest's of th

Re: cleaner way to write this?

2006-10-25 Thread Steve Holden
Paul Rubin wrote: > John Salerno <[EMAIL PROTECTED]> writes: > >> if dlg.ShowModal() == wx.ID_OK: >> db_name = dlg.GetValue() >> dlg.Destroy() >> return db_name >> else: >> dlg.Destroy() >> return > > > I like > > i

FAQ - How do I declare that a CTypes function returns unsigned char?

2006-10-25 Thread p . lavarre
Now at http://pyfaq.infogami.com/suggest we have: FAQ: How do I declare that a CTypes function returns unsigned char? A: c_uchar = ctypes.c_ubyte This irregularity actually is doc'ed, it's just pointlessly annoying. Hope this helps (and of course I trust you'll dispute if I'm nuts), -- http:/

Re: question about True values

2006-10-25 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "John Coleman" <[EMAIL PROTECTED]> wrote: > Very good point, though one could argue perhaps that when one is > comparing an object with a truth value then one is implicitly asking > for the truth value of that object On the contrary -- since there is normally no n

Re: cleaner way to write this?

2006-10-25 Thread Steve Holden
John Salerno wrote: > Paul Rubin wrote: > > >>Oh, I see. You really want something like repeat...while, which Python >>doesn't have. Anyway I start to prefer something like (untested): >> >> def create_db_name(self): >> try: >>while True: >> dlg = wx.TextEn

Re: Using classes in python

2006-10-25 Thread Gabriel Genellina
At Wednesday 25/10/2006 16:19, trevor lock wrote: I've just started using python and have observed the following : class foo: a=[] def __init__(self, val): self.a.append ( val ) It's a common pitfall. As seen just a few days ago: http://groups.google.com/group/comp.lang.py

<    1   2   3   >