Re: constructing an object from another instance of the same class

2010-06-21 Thread Carl Banks
      arg = Base(arg) >         # Do something with arg. > > is a simple and explicit solution of the problem. What if someone wants to call bar with an argument that mimics a Base but isn't a subclass? Your function would try to convert it to an actual Base. Something to think about

Re: Python dynamic attribute creation

2010-06-25 Thread Carl Banks
e you or argue with you. I'm just telling you why it's like that. I will also tell you that claims like "it's doesn't use good OOP principles" or "C++ does it that way" carry almost no credit. How C++ does something is a suggestion, nothing more. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python dynamic attribute creation

2010-06-26 Thread Carl Banks
why I said the questionable thing is not so much related with dynamic > programming or not. Because it makes dynamicism harder to do. Like I said, Python's goal isn't simply to make dynamicism possible, it's to make it easy. "foo.new_attr = 'blah'" is eas

Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
an ASCII nightmare. Still, it hasn't stopped binary APIs in other kinds of libraries. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
On Jun 27, 4:35 pm, Ben Finney wrote: > Carl Banks writes: > > Seriously, almost every other kind of library uses a binary API. > > Except for the huge number that deal with text protocols or languages. No, not really. Almost all types of libraries have binary APIs, including

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
On Jun 27, 3:20 pm, Roy Smith wrote: > In article > <14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>, >  Carl Banks wrote: > > > > > Seriously, almost every other kind of library uses a binary API. What > > makes databases so special that

Re: Why Python3

2010-06-27 Thread Carl Banks
te cruft, and can devote that time to fixing bugs and maintaining useful stuff instead. So they will benefit even if they don't actually use new features. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
On Jun 27, 8:19 pm, Owen Jacobson wrote: > On 2010-06-27 22:51:59 -0400, Carl Banks said: > > On Jun 27, 3:20 pm, Roy Smith wrote: > >> In article > >> <14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>, > >> Carl Banks wrote: >

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
ssive language like Python. Not everything is a simple inner joins. I defer to the community then, as my knowledge of advanced SQL is minimal. We'll just have accept the risk of injection attacks as a trade off, and try to educate people to use placeholders when writing SQL. Carl Banks -- ht

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
On Jun 27, 8:33 pm, Ben Finney wrote: > Carl Banks writes: > > I'm disappointed, usually when you sit on your reinforced soapbox and > > pretense the air of infinite expertise you at least use reasonable > > logic. > > Kindly stop inventing straw men to at

Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Carl Banks
On Jun 27, 9:02 pm, Stephen Hansen wrote: > On 6/27/10 8:48 PM, Carl Banks wrote: > > > I don't know the exact details of all of these, but I'm going to opine > > that at least some of these are easily expressible with a function > > call API.  Perhaps more

Re: Why Is Escaping Data Considered So Magical?

2010-06-27 Thread Carl Banks
lingly stupid thing about the standard C library, which has lots of mind-boggling stupidity. Whenever I do an audit of someone's C code the first thing I do is search for strncpy and see if they set the nth character to 0. (They usually didn't.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python dynamic attribute creation

2010-06-27 Thread Carl Banks
lemented by inherence. > >>    Most object oriented programming languages starting with Smalltalk > >> have allowed adding attributes (addInstVarName) to classes at runtime. > > > Thanks, I have to admit that I know nothing about Smalltalk. > > Then you really don't kn

Re: Python dynamic attribute creation

2010-06-29 Thread Carl Banks
On Jun 29, 9:48 am, WANG Cong wrote: > On 06/27/10 12:01, Carl Banks wrote: > > > > > > > On Jun 25, 8:24 pm, WANG Cong wrote: > >> Understand, but please consider my proposal again, if we switched to: > > >> setattr(foo, 'new_attr', &quo

Re: Why are String Formatted Queries Considered So Magical?

2010-06-29 Thread Carl Banks
on 2.x will be in use (I'm still on 2.5)... > Imagine the sluggishness in having database engines converted > (especially in a shared provider environment, where the language > specific adapters also need updating -- ODBC drivers, etc.) Thanks, your replies to this subthread have been most enlightening. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why Is Escaping Data Considered So Magical?

2010-06-29 Thread Carl Banks
On Jun 28, 2:44 am, Gregory Ewing wrote: > Carl Banks wrote: > > Indeed, strncpy does not copy that final NUL if it's at or beyond the > > nth element.  Probably the most mind-bogglingly stupid thing about the > > standard C library, which has lots of mind-boggling stupi

Re: Why Is Escaping Data Considered So Magical?

2010-06-30 Thread Carl Banks
On Jun 30, 2:55 am, Cameron Simpson wrote: > On 29Jun2010 21:49, Carl Banks wrote: > | On Jun 28, 2:44 am, Gregory Ewing wrote: > | > Carl Banks wrote: > | > > Indeed, strncpy does not copy that final NUL if it's at or beyond the > | > > nth element.  Proba

Re: A question about the posibility of raise-yield in Python

2010-06-30 Thread Carl Banks
In Scheme it's a special form that looks like an ordinary function call, but you can "return" from the call any number of times. A while back, Stackless Python supported continuations, but it was removed because (IIRC) it made stackless too platform-dependent (plus there wasn't much interest). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorators, with optional arguments

2010-07-02 Thread Carl Banks
return wrap def expose(arg): """Magic function to allow omitting argument.""" if type(arg) is types.FunctionType: print "Calling with arg as function" return expose_as(None)(arg) print "Calling with arg as protocol" return expose_as(arg) I believe it's a good practice to isolate magic so that it's easy to see, and also to ensure there's a non-magical way to do it if that is needed. However, the world won't come to an end if you do it your way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3")

2010-07-02 Thread Carl Banks
on't care no matter how many times you repeat it, because it's simply wrong. So, please do everyone a favor, and stop wasting your own time, and stop repeating this. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: automate minesweeper with python

2010-07-02 Thread Carl Banks
ts window. > > > The pixel can be hard to see depending on your background colors and > > whether your screen is adjusted correctly (I could see the white, but > > not the black).  But on XP Pro is still works. > > works for me too I'm confirming that it even works with Wine emulator in Linux. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: SyntaxError not honoured in list comprehension?

2010-07-04 Thread Carl Banks
ut not "9if 0else 1") 9and 0 9or 0 9in (1,2,3) 9is None > Side effect: If this behaviour is considered as correct, > it makes a correct Python code styling (IDLE, editors, ...) > practically impossible to realise. I'm not sure why an odd corner of the grammar would mess the w

Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3")

2010-07-07 Thread Carl Banks
except syntax, all of these are things you're already doing to support 2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a little more work than supporting 2.3 and 2.6. We all know that Python is quite successful even with a history of backward-incompatible changes and feature additions and even minor paradigm shifts. What I'm interested in is, what things about the 2 to 3 transition is harder than already exists? >From Paul's post it looks like not as much as you'd think--but as he says it's a pretty simple package. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3")

2010-07-07 Thread Carl Banks
mpy is released, maintain a single codebase (translating from 2 version to 3) for awhile, then at some point fork them and maintain them separately. Given that I add features about once every 2 years I don't think it'll be too much of a burden, though. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: "is not" operator?

2010-07-08 Thread Carl Banks
#x27;<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' Happy thing, too. I use "is not" a lot more than "is" and am happy to avoid the extra set of parentheses. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Easy questions from a python beginner

2010-07-11 Thread Carl Banks
on. In Python 2 it's limited since you cannot rebind variables in the surrounding scope; that's possible in Python 3, though. > 6.  Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python?  (Only half > joking)http://www.python.org/dev/pe

Re: Easy questions from a python beginner

2010-07-11 Thread Carl Banks
def foo(): bar() def bar(): print "hello" del bar # bar is an internal function It won't work; foo will raise NameError on bar if you try that. However, del is useful to clean up code you run at module import time, for example: squares = [] for i in xrange(101): squ

Re: Code generator and visitor pattern

2010-07-15 Thread Carl Banks
anguages. Visitor Pattern is probably the worst example of it. In Python it's completely unnecessary (at least in its boilerplate- heavy incarnation as used in C++), and the fact that Python isn't strongly typed, as you put it, is exactly the reason why. Say you have a bunch of unre

Re: Code generator and visitor pattern

2010-07-15 Thread Carl Banks
On Jul 15, 8:33 pm, Stefan Behnel wrote: > Carl Banks, 16.07.2010 01:14: > > > > > > > Around these parts, we consider the main use of most Design Patterns > > to be to work around limitations of other languages.  Visitor Pattern > > is probably the worst

Re: Pickle MemoryError - any ideas?

2010-07-20 Thread Carl Banks
an not be (re) dumped without getting a MemoryError > > This seems like a bug in pickle? No > Any ideas (other than the obvious - don't save all of these files > contents into a list! Although that is the only "answer" I can see at > the moment :-)). You should at least consider if one of the dbm-style databases (dbm, gdbm, or dbhash) meets your needs. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Exposing buffer interface for non-extension types?

2010-07-20 Thread Carl Banks
ndarray((10,10),type=numpy.float32,buffer=m) As far as I know this procedure won't be too different under PEP 3118; if anything it's simplified in Python 3 since it can discover type and shape information itself. (You'll have to check with the numpy people on that.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Exposing buffer interface for non-extension types?

2010-07-20 Thread Carl Banks
On Jul 20, 6:04 pm, Ken Watford wrote: > On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote: > > On Jul 20, 3:09 pm, Ken Watford wrote: > >> Is there any way to expose the PEP 3118 buffer interface for objects > >> that aren't extension types? > > >

Re: Easy questions from a python beginner

2010-07-22 Thread Carl Banks
the special variables, like __foo__? Python Language Reference > 4.  Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? psyco (q.g.) might help, not sure if it'll help much for lambdas, though. > Thanks

Re: Easy questions from a python beginner

2010-07-22 Thread Carl Banks
guage. And yet your previous thoughts seem oddly constrained by Perl If you really want a language that can accommodate any thought you could possibly have, you should check out Lisp. (defmacro swap (a b) '(let ((t1 ,a) (t2 ,b)) (setq ,b t1) (setq ,a t2))) hygiene-le

Re: Library versions

2010-07-24 Thread Carl Banks
ate a module called foo.py, and it have it import all the objects from the most recent release module. IOW, you should have a foo.py module that looks like this: from foo1 import * Which you update whenever there's a new release. Then in your code you simply use: import foo This is, in

Re: understanding the mro (long)

2010-07-24 Thread Carl Banks
umented as supporting inheritance Furthermore, if you want to stay sane, don't mulitply inherit from any class unless A. you own it, or B. it's explicitly documented as supporting MULTIPLE inheritance Inheritance is always risky if you don't know what you're inheriting from. Carl

Re: Nice way to cast a homogeneous tuple

2010-07-28 Thread Carl Banks
ope that it won't explode when you try to use it :/ Type casts in C and non-pathlogical C++ don't modify the object they are casting. int (and str, float, etc.) is the closest thing to a type cast in Python. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Nice way to cast a homogeneous tuple

2010-07-29 Thread Carl Banks
On Jul 28, 7:45 pm, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > > On Jul 28, 7:32 am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> > Thank

Docstrings and PEP 3174

2010-07-31 Thread Carl Banks
ust throwing it out there. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-31 Thread Carl Banks
a wonderful, holy thing. But, sex outside of marriage, and inheriting from classes you don't know, is deadly sin and you will burn in Hell. > and in my current view from a > maintenance perspective, best practice is to only use super() in the > multiple-inheritance scenarios it was specifically designed for I use super() exclusively for all types of inheritance, unless I'm inheriting from a class I know uses old form (which is none of mine, and I only rarely inherit from classes I don't own). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-31 Thread Carl Banks
On Jul 31, 8:48 pm, Carl Banks wrote: > When you have a class you that don't anything about the implementation > of, that is NOT the place for inheritance. And, just to be clear, if the class is explicity documented as being subclassable and the documentation states the proper pr

Re: Problem with Elementtree and XMLSchem instance type

2010-07-31 Thread Carl Banks
e a way to do this. My general feeling is that ElementTree is a lot handier for reading and writing your own XML formats, than for handling XML files produced by other tools. The lxml package has an ElementTree like interface but with some methods to handle namespace abbreviations. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Elementtree and XMLSchem instance type

2010-08-01 Thread Carl Banks
On Aug 1, 5:43 pm, Lawrence D'Oliveiro wrote: > In message > <96e47fd8-c939-48a2-9a2b-92afa720c...@k1g2000prl.googlegroups.com>, Carl > > Banks wrote: > > My general feeling is that ElementTree is a lot handier for reading > > and writing your own XML formats, t

Re: Why is python not written in C++ ?

2010-08-01 Thread Carl Banks
ass: class Bar { virtual int foo(int); virtual int bar(int); }; might be generated like this in one cfront: struct Bar$$Vtable$ { int (*Bar$$bar$d)(int); int (*Bar$$foo$d)(int); }; and like this in another: struct class_Foo___vtable_ { int (*foo)(int); in

Re: Docstrings and PEP 3174

2010-08-01 Thread Carl Banks
want that in *.pyc files. In PEP 3147 they proposed a fat-format file (so a glob for each version) and it was not popular. > I have > no idea what it does now, There's a short header, then the rest of the file is a single marshaled glob. > but I suspect not that. It might make

Re: simple integer subclass

2010-08-02 Thread Carl Banks
so there's a risk of these objects escaping from the context where they make sense. This is just a bad idea. The type is not the place to implement behavior that makes sense only in a limited context. Instead, do something like this: print "Item %d is %s." % (i+1, s[i]) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is python not written in C++ ?

2010-08-03 Thread Carl Banks
On Aug 3, 2:29 am, John Bokma wrote: > Carl Banks writes: > > On Aug 1, 6:09 pm, John Bokma wrote: > >> Roy Smith writes: > >> > In article <4c55fe82$0$9111$426a3...@news.free.fr>, > >> >  candide wrote: > > >> &g

Re: Why is python not written in C++ ?

2010-08-03 Thread Carl Banks
On Aug 3, 3:19 pm, John Bokma wrote: > Carl Banks writes: > > On Aug 3, 2:29 am, John Bokma wrote: > > [..] > > >> But they call both the C libraries in the same way. > > > Go look at the original claim, the one that you responded to.  "It's &g

Re: Why is python not written in C++ ?

2010-08-03 Thread Carl Banks
#x27;m starting to get the feeling one of these languages is going to hit a sweet spot and turn C into the next Cobol. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__ as a lambda

2010-08-04 Thread Carl Banks
> > and then later, > > C('Hello') > > does not work; the first argument, self, is assigned all rigth, but > you cannot write the second argument with a dot,  self.name . > Or can I somehow? __init__=lambda self,name:setattr(self,'name',name) However

Re: Why is python not written in C++ ?

2010-08-04 Thread Carl Banks
was C++ able to get popular in the first place? > > Building on C's popularity helped. AT&T + Money + C backward compatibility > > And how was Java able to grab some share from it? > > Good question.  Both IBM and Sun put a lot of effort/money behind > Java. Sun + IBM

Re: Why is python not written in C++ ?

2010-08-04 Thread Carl Banks
y, actually. However, omitting generics was probably the second worst thing about Java (the worst thing being the awful AWT design). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there any way to minimize str()/unicode() objects memory usage [Python 2.6.4] ?

2010-08-06 Thread Carl Banks
arch), then you have an numpy integer array that stores the indices into this string where the word boundaries are, and then an Nx7 numpy integer array storing the int return vslues. That's three compact arrays. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
esn't use type- casting? int a, b; double ratio; ratio = (double)a/b; > It is unfortunate that cast's in Python share the same name, but > it is kind of unavoidable because it is about the proper CS name to use. Not really. Very few people call int(), float(), and company "type casts". They aren't type casts at all, they are constructors that sometimes have the same semantics as type casts in C. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
On Aug 7, 8:18 pm, Dennis Lee Bieber wrote: > On Sat, 7 Aug 2010 13:02:56 -0700 (PDT), Carl Banks > declaimed the following in > gmane.comp.python.general: > > > > > Not really.  Very few people call int(), float(), and company "type > > casts".

Re: urgent requirement

2010-08-09 Thread Carl Banks
xpected ctc: > notice period: #1: You should post this on the Python jobs board. http://www.python.org/community/jobs/ #2: I know the economy's bad but not everyone is going to apply to every job posting they see. You should include a least a little information about the job. Carl Ban

Re: Why is python not written in C++ ?

2010-08-09 Thread Carl Banks
cally equivalent) C++. But if you don't actively try to write code that is compatible with both languages, chances are the C code will invoke one of those "'minor' 'backwards' incompatibilies", the most common one being failure to cast a pointer. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Circular imports (again)

2010-08-09 Thread Carl Banks
e modules according to "dependencies", so as to remove the circular import, makes it more confusing. Sometimes organizing by function makes more sense than organizing by dependency, and it's better to live with circular imports than to use a less- sensical organization. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is python not written in C++ ?

2010-08-10 Thread Carl Banks
On Aug 10, 12:06 am, Ulrich Eckhardt wrote: > Carl Banks wrote: > > I highly doubt the Python source would build with a C++ compiler. > > As Christian showed, it doesn't. However, look around the sources a bit. > There are lots of places where e.g. the returnvalue of mall

Deer Esurance

2010-08-11 Thread Carl Banks
If you're going to send me unsolicited email, the least you can do it include pics of Erin. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Pop return from stack?

2010-08-14 Thread Carl Banks
building up some > kind of stack overflow or something which will bite me later. What do you think a few words of data the stack are going to do? Just do it this way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Pop return from stack?

2010-08-15 Thread Carl Banks
f if there wasn't an error def main(): try: run_program() except MyException as exc: print >> sys.stderr, str(exc) sys.exit(1) If you call sys.exit() deep within your call tree, the world won't come to an end, but raising an exception is the preferred

Re: numpy 00 character bug?

2009-06-05 Thread Carl Banks
.  Is there an easy way to avoid this problem? > Pretty much any performance-intensive part of my program is going to be > dealing with these arrays, so I don't want to just replace them with a > slower dictionary instead. > > I can't imagine this issue hasn't come up before; I encountered it by > using NumPy arrays to store Python structs, something I can imagine is > done fairly often.  As such, I apologize for bringing it up again! I doubt a very high percentage of people who use numpy do character manipulation, so I could see it as something that hasn't come up before. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Making the case for repeat

2009-06-05 Thread Carl Banks
wning function, but with iterators you can. In fact, iterators are (almost) orthogonally recombinable; the whole input space of a problem can be spanned simply by combining simple iterators. So, I will have to ultimately agree with Gabriel: itertools are best kept simple and complex interator beha

Re: py3k printing generators -- not!

2009-06-06 Thread Carl Banks
ther solving this? In my experience, if you want a custom print function that prints things the way you want, you have to write it yourself. People's expectations are too different. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Error in linalg.inv ??

2009-06-06 Thread Carl Banks
tines are shaky when ill-conditioned, but it could help newbies and computer science experts to be explicit about it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Get the class name

2009-06-07 Thread Carl Banks
sp code in your .emacs file, defines a command to automatically insert the a super call with the class and method name filled in: http://code.activestate.com/recipes/522990/ Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: preferring [] or () in list of error codes?

2009-06-08 Thread Carl Banks
o go strictly by the book, I would say he ought to be using a set since his collection of numbers has no meaningful order nor does it make sense to list any item twice. I don't think it's very important, however, to stick to rules like that for objects that don't live for more than a single line of code. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: preferring [] or () in list of error codes?

2009-06-08 Thread Carl Banks
On Jun 8, 6:02 pm, Ben Finney wrote: > Carl Banks writes: > > If you want to go strictly by the book, I would say he ought to be > > using a set since his collection of numbers has no meaningful order > > nor does it make sense to list any item twice. > > Yes, a

Re: Function/method returning list of chars in string?

2009-06-09 Thread Carl Banks
On Jun 9, 2:47 am, "Hendrik van Rooyen" wrote: > "Diez B. Roggisch" wrote: > > > I think > > > lb = list(s) > > > is good enough. > > It does the job, of course, but it is not a string method. A. Your post's subject included t

Re: List comprehension and string conversion with formatting

2009-06-09 Thread Carl Banks
ere, chief. [ "%.1f" % x for x in lst ] BTW, I took the liberty of making a few style choices, highly recommended: not to use "i" for floating points ("i" strongly suggests integer value to many programmers), and not using "l" (the letter ell) as

Re: preferring [] or () in list of error codes?

2009-06-09 Thread Carl Banks
cution time to "item in set" if item is always the first element in list. Furthermore, the Python compiler appears to be optimizing this specific case to always use a precompiled set. Well, almost always > You will also note > that  performance to fall off drastically for the last set of values. > I'm not sure what happens there; I guess I'll file a bug report. Please don't; it's not a bug. The slowdown is because at sizes above a certain threshold the Python compiler doesn't try to precompile in- line lists, sets, and tuples. The last case was above that limit. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: preferring [] or () in list of error codes?

2009-06-09 Thread Carl Banks
flawed. > assuming that the list has less than 8K members.  Above 16K > members, sets are much faster than lists.  I'm not sure where the > break is, or even why there's a break. The break comes from the compiler, not the objects themselves. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Using logging module to log into flash drive

2009-06-09 Thread Carl Banks
s way: 1. log messages to a buffer 2. periodically flush the buffer to the flash drive, if it's available The "periodically" part could be accomplished with a thread or scheduled delays, however suits your application. It might not be a final if you need to log messages promptly

Re: SPAM-LOW: Re: Function/method returning list of chars in string?

2009-06-09 Thread Carl Banks
h is a method of str but a constructor of list? Perhaps instead of worrying about symmetry all the time we should just accept the inevitability that things will always be asymmetric and impure from someone's perspective. Terry's symmetry is Hendrik's asymmetry and vice versa. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Carl Banks
ff the bits of the number into the mantissa of a double, along with -1 as the exponent, and return that. Implementation left as exercise, mostly because it really won't make a difference. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.intersect?

2009-06-10 Thread Carl Banks
r is pretty simple I'd say just go with that. Unless you have some other things happening downstream that would also benefit from the source data being in a database, or something. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: object reincarnation

2009-06-11 Thread Carl Banks
te the attributes. I'd also recommend using self.__dict__.clear() for that, it gets all of them (usually) and doesn't need to be updated with you add a new attribute to a class. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Voronoi diagram algorithm (Fortune’s sweepline )

2009-06-11 Thread Carl Banks
image = Image.fromstring("RGBA",shape,pixels) image.save('voronoi.png') if __name__ == '__main__': draw_map(voronoi(([100,100],[356,301],[400,65],[324,145], [200,399]))) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Observer implementations

2009-06-15 Thread Carl Banks
ve forever, and bound classmethods are lightweight and hardly worth the effort. Maybe show us what you need to weak reference classmethods for and we can help you better. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python tutorial

2009-06-15 Thread Carl Banks
d-of-line characters in text files are automatically altered > "slightly when data is read or written. > > I don't see any obvious way to at docs.python.org to get that corrected: Is > there some standard procedure? What's wrong with it? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing json using simplejson

2009-06-15 Thread Carl Banks
it. P.S. Someone will be by to post the "How to ask smart questions" essay shortly. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python tutorial

2009-06-18 Thread Carl Banks
On Jun 17, 5:36 pm, "steve" wrote: > >"Carl Banks" wrote in message > >news:2f6271b1-5ffa-4cec-81f8->>0276ad647__begin_mask_n#9g02mg7!__...__end_mask_i?a63jfad$...@p5g2000pre.googlegroups.com... > >On Jun 15, 7:56 pm, "steve" wrote: > &g

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Carl Banks
nto CPython unless makes extensions are just as easy to write. That is something I have serious doubts they can pull off. Which means a GIL-less unladen-swallow is likely to end being another fork like IronPython and Jython. Those projects already have no GIL. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Carl Banks
t enough? Jesus. I wish people would just say, "This is a limitation of CPython. There are reasons why it's there, and it helps some people, but unfortunately it has drawbacks for others", instead of the typical "all u hav 2 do is rite it in C LOL". Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Carl Banks
On Jun 19, 4:42 pm, Christian Heimes wrote: > OdarR schrieb: > > > On 19 juin, 21:41, Carl Banks wrote: > >> He's saying that if your code involves extensions written in C that > >> release the GIL, the C thread can run on a different core than the > >&

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Carl Banks
On Jun 19, 4:35 pm, a...@pythoncraft.com (Aahz) wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854c...@z7g2000vbh.googlegroups.com>, > Carl Banks   wrote: > >I wish Pythonistas would be more willing to acknowledge the (few) > >drawbacks of the language (or implementatio

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Carl Banks
pecially things that quite reasonably appear to be a silly limitation. Maybe you don't intend to sound like you're saying "shut up and use C", but to me, that's how you come off. If you're going to advise someone to use C, at least try to show some understanding for their concerns--it would go a long way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Carl Banks
edups. Just for the record, I am not taking issue with the advice itself (except that you forgot "use Jython/IronPython which have no GIL"). I'm not even saying that Python was wrong for having the GIL. All I'm saying is that [this is not aimed specifically at you] this advice can be delivered with more respect for the complainer's problem, and less fanboy-like knee-jerk defensiveness of Python. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python class gotcha with scope?

2009-06-20 Thread Carl Banks
interactive prompt: >>> foo.r {'f': 4} You want an instance attribute, a value attached to the instance of the class. You create those in the __init__ method: class foo: def __init__(self): self.r = {} def setn(self,n): self.r["n"] = n Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Idioms and Anti-Idioms Question

2009-06-23 Thread Carl Banks
n't > think of subtle gotchas (e.g. the '\' is removed or the lines become > separated, > because in both cases an IndentationError would be raised). Perhaps it was originally was like this: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: C-extension 2 times slower than exe

2009-06-23 Thread Carl Banks
On Jun 23, 7:20 am, Rolf Wester wrote: > Philip Semanchuk wrote: > > > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > > >> Hi, > > >> I have a C++ program that I would like to steer using Python. I made the > >> wrapper using swig and linked the code (without the main function) into > >> a shar

Re: Best way to enumerate classes in a module

2009-06-24 Thread Carl Banks
t for other readers): this method can't tell the difference between a class defined in the module and a class imported into it. Finally, despite the warning, I think you are ok to use dir() for that purpose. It's not likely to change. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting Python code to C/C++

2009-06-24 Thread Carl Banks
take weeks in C or C++. If that [teaching them this] is the case, it might be best use of time they will ever have. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary self lookup

2009-06-24 Thread Carl Banks
that this idea is worth it. > > Any feedback is welcome. If you don't mind abusing Python syntax, you can do it using something like this: def DictMaker(name,bases,dct): dct.pop('__metaclass__',None) return dct class a: __metaclass__ = DictMaker home = "/home/test" user1 = home + "/user1" user2 = home + "/user2" python_dev = user1 + "/py-dev" print a Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: extending method descriptors

2009-06-25 Thread Carl Banks
nternal','_y_internal'] x = MemberDescriptorWrapper('_x_internal') y = MemberDescriptorWrapper('_y_internal') MemberDescriptorWrapper class would have to implement __get__, __set__, and __del__ methods and have them call the corresponding methods on the slot; details are left as an exercise. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Carl Banks
nique above to wrap up the root Element if you use et.fromstring. [snip] > Why isn't et.parse the only way to do this? Why have XML or fromstring   > at all? Because Fredrick Lundh wanted it that way. Unlike most Python libraries ElementTree is under the control of one person, which

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Carl Banks
On Jun 25, 8:53 pm, Kee Nethery wrote: > On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > > A few minor > > things should be no big deal. > > True and I will eventually get past the minor quirks. As a newbie,   > figured I'd point out the difficult portions, thi

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Carl Banks
On Jun 25, 10:11 pm, Stefan Behnel wrote: > Carl Banks wrote: > >> Why isn't et.parse the only way to do this? Why have XML or fromstring   > >> at all? > > > Because Fredrick Lundh wanted it that way.  Unlike most Python > > libraries ElementTree is und

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-26 Thread Carl Banks
On Jun 25, 11:20 pm, Stefan Behnel wrote: > Carl Banks wrote: > > On Jun 25, 10:11 pm, Stefan Behnel wrote: > >> Carl Banks wrote: > >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring   > >>>> at all? > >>&g

<    10   11   12   13   14   15   16   17   18   >