Re: Inheritance from builtin list and override of methods.

2006-11-27 Thread Carl Banks
C types that deliberately go though slower Python methods to allow overriding. But that has to be deliberate (for the most part); as Frederick said, most C classes don't do that. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: super() and type()

2006-11-27 Thread Carl Banks
nce C's superclass is B, B.meth ends up calling B.meth again, and you get infinite recursion. Unfortunately, short of hackery, you're stuck with having to write out super(C,self). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance from builtin list and override of methods.

2006-11-28 Thread Carl Banks
t; or __setitem__. > > Why doesn't it? Because the concerns of thousands of legitimate programmers who want good performance out of their sorts outweigh the concerns of the one or two hax0r d00ds who think it would be cool to hook into sort internals. live-long-and-prosper-ly yr&

Re: Detecting recursion loops

2006-11-29 Thread Carl Banks
, you could just inpect the stack frame and look for duplicated function calls. See the documentation for sys._getframe. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: More elegant to get a name: o.__class__.__name__

2006-11-30 Thread Carl Banks
alf wrote: > Hi, > is there a more elegant way to get o.__class__.__name__. For instance I > would imagine name(o). def name_of_type(o): return o.__class__.__name__ name_of_type(o) Carl Banks P.S. name(o) suggests it's the name of the object, not the type P.P.S. you co

Re: Is there a reason not to do this?

2006-11-30 Thread Carl Banks
s sometimes very inconvenient (like when the code requiring an ordinary object is one line smack in the middle of a 100-line function). It actually sounds like Aspect Oriented Programming might be helpful here (if you care to learn another wholly different programming paradigm, that is). You have a concern (persistence) that's pretty much off in another dimension from the purpose of the classes. Or maybe the best way is just to teach an old class new tricks. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a reason not to do this?

2006-12-01 Thread Carl Banks
class hook to get the modifying in-place behavior: def modify_in_place(name,bases,clsdict): cls = globals()[name] for attr,val in clsdict.iteritems(): setattr(cls,attr,val) return cls # Replace second C2 class above with this class C2: __metaclass__ = modify_in_place def m1(self): h() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What are python closures realy like?

2006-12-01 Thread Carl Banks
* (setf (symbol-function 'f1a) (fun_basket 1)) ; Converted F1. ; Converted F2. # * (setf (symbol-function 'f2a) (fun_basket 2)) # * (f1a) 0 1 * (f2a) 0 2 > Any ideas what's going on behind the scene? Every time you call the function, a new closure is created. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-02 Thread Carl Banks
i) in > if n > 2 then d4 s1 d1 d2 even else s1, d1, d2 > > but I'm not sure it is correct! It's not correct, but what you left out is probably low cost. OCaml is compiled to machine code, right? And types can be inferred at compile time, correct? Well then of course it's faster. It seems to me a big help is the ability to fold multiple array operations into a single loop, which is optimization a dynamically-typed language like Python can't easily make. (It'd require are really smart JIT compiler or some concessions in dynamicity.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-02 Thread Carl Banks
Carl Banks wrote: > Matlab has a few *cough* limitations when it comes to hand-optimizing. > When writing naive code, Matlab often is faster than Python with numpy > because it has many commerical man-year of optimizing behind it. > However, Matlab helps v That should say: However,

Re: About alternatives to Matlab

2006-12-03 Thread Carl Banks
in a "better language for the task" (i.e. C). This is something that's quite popular in the numerically-intensive computing community, BTW. Many people use Python to handle boring stuff like file I/O, memory managment, and non-critical numerical calculations, and write C or Fortran extensions to do the numerically-intensive stuff. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-03 Thread Carl Banks
ittle D4 transform to double in speed I'll scrap Python and write the whole thing in OCaml. (Or I can begrudingly admit that it's not really silly to try to optimize a slow language.) [snip] > This is really great work but I can't help but wonder why the authors chose > to use Python when other languages seem better suited. I'd like to work on > raising people's awareness of these alternatives, and probably create some > useful tools in the process. So I'm keen to learn what Python programmers > would want/expect from F# and OCaml. > > What would it take to make you convert? Them not being functional would be a good start Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-03 Thread Carl Banks
Jon Harrop wrote: > Carl Banks wrote: > >> 0.56s C++ (direct arrays) > >> 0.61s F# (direct arrays) > >> 0.62s OCaml (direct arrays) > >> 1.38s OCaml (slices) > >> 2.38s Python (slices) > >> 10s Mathematica 5.1 > > [snip] > >>

Re: About alternatives to Matlab

2006-12-04 Thread Carl Banks
ere to get a > > Python prompt, and type "import this", it would print the Zen of > > Python, a set of principles by which the language is designed. One of > > them is "Practicality beats purity." And let's face it, functional > > languages are

Re: About alternatives to Matlab

2006-12-04 Thread Carl Banks
sturlamolden wrote: > Carl Banks wrote: > > > > Ok. Perhaps starting a Python JIT in something like MetaOCaml or > > > Lisp/Scheme > > > would be a good student project? > > > > ...and finishing would be a good project for a well-funded team of >

Re: per instance descriptors

2006-12-06 Thread Carl Banks
class Input(object): def __init__(self,default,name): self.default = default self.name = name # or, create a name automatically def __get__(self,obj,objtype): return getattr(obj,self.name,self.default) def __set__(self,obj,value): setattr(obj,self.name,valu

Re: raw strings in regexps

2006-12-07 Thread Carl Banks
wo backslashes in the pattern match one backslash in the string. Another example: re.match(r"\[",r"\[") => False re.match(r"\[",r"[") => True Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-08 Thread Carl Banks
" It's kind of sad, in a way, that a superficiality would be so crucial. (Not that I think outward appearance is all superficial--I think humans have evolved and/or learned to regard as beautiful that which minimizes effort--but it's not the whole story and not basis for a whole judgment.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-08 Thread Carl Banks
as a typical newbie who tries Lisp.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-09 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Carl Banks wrote: > > [EMAIL PROTECTED] wrote: > > > Okay, since everyone ignored the FAQ, I guess I can too... > > [snip] > > > What Python has is stupid slogans > > > ("It fits your brain." "Only one way to d

Re: Automatic debugging of copy by reference errors?

2006-12-10 Thread Carl Banks
Russ wrote: > If a debugger could tell you how many references exist to an object, > that would be helpful. import sys sys.getrefcount(a) But I doubt it would be very helpful. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic debugging of copy by reference errors?

2006-12-10 Thread Carl Banks
the loci of the duplicate references. Now, to be honest, the biggest benefit of this check is it gives newbies a chance to learn about references some way other than the hard way. It's not meant to catch a common mistake, so much as a potentially very confusing one. (It's really n

Re: One module per class, bad idea?

2006-12-12 Thread Carl Banks
system you have to keep switching files; but I guess some people prefer to switch files rather than to scroll for some reason. I'd say as long as you use package system, and not just a flat modulespace, it's not fundamentally disorganized to use a one class per module rule. In the end

Re: One module per class, bad idea?

2006-12-12 Thread Carl Banks
(I think it's just convention, really. You don't have to use one class per module in Python, and given that freedom, most Python programmers didn't.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-12 Thread Carl Banks
Carl J. Van Arsdall wrote: > Carl Banks wrote: > > Carl J. Van Arsdall wrote: > >> A module per class makes a lot of sense in some cases, or rather, make > >> your module your class (look at the singleton pattern). I actually like > >> to structure all of

Re: Iterating over several lists at once

2006-12-13 Thread Carl Banks
, and that's doubtful. OTOH, something like this has decent shot of appearing in a standard functional or iterator module of some sort. > Thanks for replying me. You're welcome in advance. Also, one note about comp.lang.python and/or python-list: it's conventional here to put replies beneath the quoted text. This is for the benefit of future readers, so they don't have read conversations in reverse order. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional iteration

2006-12-13 Thread Carl Banks
way to nest for and if clauses in listcomps, and the two methods are considered distinct. Although Guido has said that saving indentation levels is important, he hasn't said anything (that I'm aware of) that suggests it's important enough to add this complexity and redundancy

Re: Conditional iteration

2006-12-13 Thread Carl Banks
nvince him. By the way, I'd suggest when posting to comp.lang.python and/or python-list in the future, you put your replies beneath the quoted text for the benefit of any future readers (not to mention present readers). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional iteration

2006-12-14 Thread Carl Banks
at wrote: > Carl Banks wrote: > > > at wrote: > >> Well, all I can say that for me as a user it would make sense... > > > > Which is, like, step one out of a hundred for getting a syntax change > > into the language. > > > >> Curiosity: in what

Re: tuple.index()

2006-12-14 Thread Carl Banks
read, making sense is about step one out of a hundred for getting your change into the language. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional iteration

2006-12-14 Thread Carl Banks
. If you think that this change was made for "psychological" reasons, you are terribly deluded. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional iteration

2006-12-14 Thread Carl Banks
ve with, therefore it has to make sense for the community as a whole, not just one person. But you've completely ignored concerns that don't apply to YOU this whole thread. Carl Banks PS. You're top-posting again. Please respect other readers. -- http://mail.python.org/mailman/listinfo/python-list

Re: tuple.index()

2006-12-14 Thread Carl Banks
tent" fear is a better word. It's like when people are deathly afraid to get on an airplane, but think nothing of riding in a car without a seatbelt. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Has comparison of instancemethods changed between python 2.5 and 2.4?

2006-12-16 Thread Carl Banks
ef same_method(a,b): return a.im_class is b.im_class and a.im_func is b.im_func and a.im_self is b.im_self Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping classes with pure virtual functions

2006-12-17 Thread Carl Banks
ler always knows the exact type of a direct, non-pointer-accessed object. So even if you could create a class_, it would only ever be a Base, and never a derived class. You have to use pointers to get polymorphism. As an alternative, consider wrapping the derived classes instead. It might not be much more work if Boost wraps everything nicely. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary, iterate & update objects

2006-12-18 Thread Carl Banks
ontain Python objects (__dict__ excepted). tuples, frozensets, instancemethods, are immutable but do contain Python objects. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python-hosting.com projects: dead?

2006-12-18 Thread Carl Banks
x27;re overreacting? Try checking the SVN tomorrow. Even Python programs can have downtime. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: what is wrong with my code?

2006-12-20 Thread Carl Banks
t questions to answer. "What is wrong with my code?" is > > a container of many many smaller questions, and you need to focus your > > questions better. > > it says that progress_table is not defined. i don't know why. It looks like you have bigger problems than an undefined variable. Python does not have implicit access to methods and attributes (members) like C++ and Java do. Methods must accept an explicit self parameter that refers to the object (analogous to this in C++ and Java) to access attributes. Your code defines a class, but self is nowhere to be found. I suggest getting a good book and/or reading the tutorial (http://docs.python.org/tut/) and making sure you can do easy stuff first. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: what is wrong with my code?

2006-12-20 Thread Carl Banks
Pyenos wrote: > thanks for your point. so because i have said class blah: i must > explicitly say self for every instantiation of object? http://docs.python.org/tut/ Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-22 Thread Carl Banks
Kent Johnson wrote: > Carl Banks wrote: > > Now, I think this is the best way to use modules, but you don't need to > > use modules to do get higher-level organization; you could use packages > > instead. It's a pain if you're working on two different classe

Re: One module per class, bad idea?

2006-12-22 Thread Carl Banks
t editors should be able to handle dispaying > different files. Actually, I pointed out that decent editors should be able to handle displaying the same file twice. In case you want to edit two different points of the same file side-by-side. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-22 Thread Carl Banks
Paddy wrote: > Carl Banks wrote: > > Erik Johnson wrote: > > > The file has now grown into a 6800 line beast (including docstring, > > > whitespace, and CVS history). Pretty much any time we implement some new > > > functionality, there are at least

Re: One module per class, bad idea?

2006-12-22 Thread Carl Banks
ctoring, it's a partial solution hack that'll lead to more confusion and delay a real solution even more. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Use a Thread to reload a Module?

2006-12-22 Thread Carl Banks
t. For example, can requests come in fast enough to spawn another load_data before the first had ended? You should consider trying to acquire a threading.Lock in load_data and waiting and/or returning immediately if you can't. Other things can go wrong, too. Using threads requires care. But hopefully this'll get you started. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-22 Thread Carl Banks
Gabriel Genellina wrote: > At Friday 22/12/2006 22:58, Carl Banks wrote: > > > > Usually no other files need to change. Ex: you have BigOldModule > > > including ClassA, ClassB and FunctionC. Move each one onto its own > > > module, perhaps including a

Re: One module per class, bad idea?

2006-12-25 Thread Carl Banks
Kent Johnson wrote: > Carl Banks wrote: > > Kent Johnson wrote: > >> Carl Banks wrote: > >>> Now, I think this is the best way to use modules, but you don't need to > >>> use modules to do get higher-level organization; you could use packages >

Re: How to depress the output of an external module ?

2006-12-26 Thread Carl Banks
ion. Try this: fd = os.dup(1) os.close(1) sys.stdout = os.fdopen(fd) It's poor design and extremely inconsiderate for a library to print to stdout except as an overridable default.(Not to mention it gives ammo to people who want dynamically scoped globals.) A long term solution might be to hag

Re: How to depress the output of an external module ?

2006-12-26 Thread Carl Banks
Carl Banks wrote: > [EMAIL PROTECTED] wrote: > > After some trials I found that put "os.close(1)" before calling the > > function will depress the output. In fact, "os.close(1)" closed > > standard output, but I don't know how to open it again af

Re: Getting unicode escape sequence from unicode character?

2006-12-27 Thread Carl Banks
cape": >>> a = u'\u1234' >>> a u'\u1234' >>> print a ሴ >>> ord(a) 4660 >>> hex(ord(a)) '0x1234' >>> a.encode('unicode_escape') '\\u1234' Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: loose methods: Smalltalk asPython

2006-12-27 Thread Carl Banks
van Rossum as I am, simply because > so-and-so says something is bad and therefore it must be true is a > fallacious response. The same could be said of Smalltalk, i.e., because Smalltalk does it therefore it is good is just as fallacious. Regardless, whatever Guido pronounces is what happens. If he's adamantly against something, it's pretty much an academic discussion. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone persuaded by "merits of Lisp vs Python"?

2006-12-28 Thread Carl Banks
the first thing you should have done is to not cross-post this. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone persuaded by "merits of Lisp vs Python"?

2006-12-29 Thread Carl Banks
Paddy wrote: > Carl Banks wrote: > > If you were so keen on avoiding a flame war, the first thing you should > > have done is to not cross-post this. > > I want to cover Pythonistas looking at Lisp and Lispers looking at > Python because of the thread. The cross post

Re: probably a stupid question: MatLab equivalent of "diff" ?

2006-12-29 Thread Carl Banks
Stef Mientki wrote: > Does anyone know the equivalent of the MatLab "diff" function. > The "diff" functions calculates the difference between 2 succeeding > elements of an array. > I need to detect (fast) the falling edge of a binary signal. Using numpy (or predecessors), you can do this easily wi

Re: array of class

2007-01-02 Thread Carl Banks
ter Word. You have to call the class object, same as you'd call a function, so you have to follow it with parentheses: s1.append(Word()) You could, in fact, have an array of classes, and there are actually reasons you might want to do that, but that's pretty advanced. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Why is pow a builtin, anyways?

2007-01-04 Thread Carl Banks
7;Traceback (most recent call last): > File "", line 1, in > sqrt(9) > NameError: name 'sqrt' is not defined' The third argument to the builtin pow is a special usage for cryptography, and something specific like that needs no representation in the builtin n

Re: subclassing a module: misleading(?) error message

2007-01-04 Thread Carl Banks
guments that a normal type constructor does, so you get the error. Does that clear things up? Probably not. For a detailed explanation of how this all works, look for some resources on learning "metaclasses" or "metatypes" in Python. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What is proper way to require a method to be overridden?

2007-01-04 Thread Carl Banks
results in a more informative error message But, in the end, if someone wants to define a class that defiantly refuses to declare a method, you can't stop them. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-05 Thread Carl Banks
p in a dictionary is that, in many real applications, the pin name would often be specified in the input. (This is very often the case whenever people want to know the symbol an object is bound to, for any application.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What is proper way to require a method to be overridden?

2007-01-05 Thread Carl Banks
Fuzzyman wrote: > Carl Banks wrote: > > jeremito wrote: > > > I am writing a class that is intended to be subclassed. What is the > > > proper way to indicate that a sub class must override a method? > > > > You can't (easily). > > > > Well

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-05 Thread Carl Banks
, you might as well just use globals() and do it explicitly, rather than mucking around with Python frame internals. (And it doesn't make the class unusable for more straightforward uses.) for _name in ('aap','dcr'): globals()[_name] = Pin(_name) del _name Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-07 Thread Carl Banks
Martin Miller wrote: > Carl Banks wrote: > > > Martin Miller wrote: > > > ### non-redundant example ### > > > import sys > > > > > > class Pin: > > > def __init__(self, name, namespace=None): > > > self.name = name

Re: beta.python.org content

2006-01-26 Thread Carl Banks
ble. It cuts down on the sensory overload from the previous site. And, it passes the no-style litmus test (i.e.,whether you can still read and understand the site with the style sheets disabled.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: appending to a list via properties

2006-02-11 Thread Carl Banks
, list.append) This is an impressive, spiffy little class. > Well? I suspect it's too sneaky and not commonly useful enough to get serious consideration for the standard library. But definitely submit it to Python Cookbook: http://aspn.activestate.com/ASPN/Python/Cookbook/ Carl Banks P

Re: appending to a list via properties

2006-02-11 Thread Carl Banks
Alex Martelli wrote: > Carl Banks <[EMAIL PROTECTED]> wrote: >... > > > class better_list (list): > > > tail = property(None, list.append) > > > > This is an impressive, spiffy little class. > > Yes, nice use of property. > &

Re: Unexpected behaviour of getattr(obj, __dict__)

2006-02-14 Thread Carl Banks
it. To wit: >>> Parrot.f is Parrot.f False >>> Parrot.__dict__ is Parrot.__dict__ False But wait, it gets weirder. >>> id(Parrot.f) == id(Parrot.f) True >>> id(Parrot.__dict__) == id(Parrot.__dict__) True But that's not all. Redefine Parrot as: class Parrot(object): def f(self): pass def g(self): pass Then, >>> id(Parrot.f) == id(Parrot.g) True your-milage-may-vary-ly yr's, Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Carl Banks
t. > This usually leads to > having each class follow the Singleton pattern, further complicating > the design. Meh. I don't feel too strongly about this, but I'd think an enum as a class is better, because you can't (or, rather, oughtn't) compare constants from different enums. That's a logical demarcation of classes. Sorry if I was a little blunt here. In the end, I really don't see the problems that this enum addresses being all that common; it seems a lot of work for minor benefit. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Carl Banks
Stefan Rank wrote: > on 28.02.2006 07:50 Carl Banks said the following: > > Ben Finney wrote: > >> This PEP specifies an enumeration data type for Python. > > > [snip] > > > > Here's why I think it's not too useful to begin with: the benefits

Re: C++ OpenGL rendering, wxPython GUI?

2006-02-28 Thread Carl Banks
;ve done similar things in GTK on Linux. I had a gtkglarea canvas, PyOpenGL, and my own C extension all making OpenGL calls. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: how do you move to a new line in your text editor?

2006-03-02 Thread Carl Banks
ems to have a variable tab stop) to edit the file with tabs, but save it with spaces. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: how do you move to a new line in your text editor?

2006-03-02 Thread Carl Banks
John Salerno wrote: > Carl Banks wrote: > > John Salerno wrote: > >> So I'm wondering, how do you all handle moving around in your code in > >> cases like this? Is there some sort of consistency to these things that > >> you can write rules for you

Re: Python rocks

2007-06-14 Thread Carl Banks
1] := 10! Out[1]= 3628800 (The more you know....) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: overriding base class

2007-06-29 Thread Carl Banks
On Jun 29, 7:36 pm, alf <[EMAIL PROTECTED]> wrote: > Hi, > > I want to develop a following lib: > > lib space user space > > A -> B -> | -> user_class > > however A and B are abstrac enough to have following: > > user_super_base_class -> | -> A -> B -> | -> user_class > > user space

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Carl Banks
(selected value) This is not a joke. I don't mean Python should necessarily do this (though it could be done without any ambiguity or backward incompatibility: there is currently nowhere in Python where two identifiers can be separated by only a space), but new languages should be designed

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
re glob.glob, select.select, or time.time. It's ugly and potentially confusing. And if I were Polynesian I would keep thinking I was seeing plurals. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Carl Banks
if obj is not None: obj._refcount += 1 else: obj = super(CachedResourceMetaclass,self).__call__(*args) obj._key = args obj._refcount = 1 self._cache[args] = obj return obj Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread Carl Banks
{"A"} ||={}. > > Thanks, > Geoffrey Define b as a default dict: b = defaultdict(dict) b[k]['A'] = l Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-17 Thread Carl Banks
://docs.python.org/lib/typesmapping.html > > No, this has already been proposed and discarded. The OP does NOT > want this, because it always generates an empty {} whether it is > needed or not. Not really a big hardship, but if the default value > were some expensive-to-construct c

Re: How to setup pyOpenGL3.0.a6 for window xp?

2007-08-17 Thread Carl Banks
oesn't (easily) work with common GUIs like GTK and Wx. If you want to use use OpenGL in a GUI app, then you'll want to find an "OpenGL canvas widget" for that GUI. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python question (PyNoob)

2007-08-20 Thread Carl Banks
2 Python supports timestamp checking and subprocess calling and whatnot, but stuff like dependency trees you'll have to work out yourself. (BTW, if "make" is failing or annoying you, you might want to consider SCons, which for me has been a lot more intelligent and straight

Re: Python question (PyNoob)

2007-08-20 Thread Carl Banks
and several others are misunderstanding the OP: the OP wants to learn some details of Python without having to *relearn* the basics of programming. It's a reasonable request. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: py2exe/distutils: how to include a tree of files?

2007-08-24 Thread Carl Banks
se because "data_files" wasn't too helpful, there was never much incentive to improve it. Which (getting back to py2exe) is unfortunate since you CAN rely on the location when using py2exe, but it is stuck with the unwieldy usage. Oh well. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: "Try:" which only encompasses head of compound statement

2007-08-27 Thread Carl Banks
ld have to check the error code to distinguish, and reraise if not file not found. # this is the point where success or failure # determines what I do next, that's why I handle # the exception here. try: load_myFile() except IOError, e: if e.errno == 2: # file not found is usually errno 2 print "file not found" else: raise else: # load succeeded, do whatever. One other useful technique is recasting: catching an error close to the call, and raising a different error. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Carl Banks
one of the more pleasant ones. (At least not without a good set of slice-matching patterns handy, which I don't know if Haskell has.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: We need PIGs :)

2007-08-30 Thread Carl Banks
y people often call Python a good "glue" language for this reason. And when you have a good "glue" language, formal interface guidelines aren't so important. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Carl Banks
current project, we're struggling with throughput even though we use highly optimized code. Python would be completely out of the question. Now, control towers don't have these constraints, and system failure is not nearly as critical, so Python is a better option there. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Carl Banks
out actually running the code) that the code fulfills the > DBC conditions. I don't see any way to do that with Python > decorators. I don't see any way to do that in Python with built-in DBC syntax, either. :) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Carl Banks
On Fri, 31 Aug 2007 01:15:04 -0400, Roy Smith wrote: > Carl Banks <[EMAIL PROTECTED]> wrote: >> Python really isn't suitable for in-flight controls for various >> reasons, and mission critical concerns is a minor one (systems with >> less underlying complexity

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Carl Banks
reason why Python couldn't be certified if it passed the tests, but it likely wouldn't pass as easily as a compiled language. OTOH, spiffy features like design-by- contract aren't going to improve your chances of getting FAA cert, either. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Carl Banks
tors, dams, and so on? Come on. BTW, I'm not really agreeing with Russ here. His suggestion (that because Python is not used in highly critical systems, it is not suitable for them) is logically flawed. And Alex's point, that Python has a good track record of reliabilty (look at Go

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Carl Banks
On Sat, 01 Sep 2007 08:38:38 -0300, Jorge Godoy wrote: > Carl Banks wrote: > >> This is starting to sound silly, people. Critical is a relative term, >> and one project's critical may be anothers mundane. Sure a flaw in >> your flagship product is a critical proble

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Carl Banks
On Sat, 01 Sep 2007 17:19:49 +0200, Pierre Hanser wrote: > Carl Banks a écrit : >> >> This is starting to sound silly, people. Critical is a relative term, >> and one project's critical may be anothers mundane. Sure a flaw in >> your flagship product is a cr

Re: Why 'class spam(object)' instead of class spam(Object)' ?

2007-09-07 Thread Carl Banks
;str" were once functions. When these symbols became the names of their respective types, they kept the lower-case spelling, and it became convention for built-in types to be spelled lower-case. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed of Python

2007-09-07 Thread Carl Banks
Are there any > way to speed it up? It seems Python automatically created bench1.pyc. Does > Python automatically execute the bench1.pyc to speed it up? Yes, as others have explained. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python syntax wart

2007-09-09 Thread Carl Banks
n community with your eye for syntax. You're relatively new to Python, correct? If so, maybe you should give yourself some time to see if some of Python's unconventional features grow on you. I've found that wherever Python differs from the common ways to do things,

Re: Python syntax wart

2007-09-10 Thread Carl Banks
e implicit line continuations everywhere between the opening keyword and the colon". To be honest, I've always thought this would be a nice feature to have, but now that I've seen what kind of abominations are possible with it, I'm not so sure. Carl Banks P.S. The &quo

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Carl Banks
hat would make insertion and deletion would be quite expensive. Which might be ok for the OP, but it's often better to go with a btree. Which, you know, would be a reasonable candidate for collections module. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Carl Banks
have kept the order separately, but what was the point? I just whipped up a homemade ordered dict class, it worked fine, and I didn't have to worry about keeping them synchronized. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Carl Banks
rstand where the OP is coming from. I've done flight simulations in Java where there are lot of complex calculations using symbols. This is a typical formula (drag force calculation) that I would NOT want to have to use self.xxx for: FX_wind = -0.5 * rho * Vsq * Sref * (C_D_0 + C_D_alphasq*al

Re: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Carl Banks
On Sep 12, 4:52 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > (The loops would necessarily be unwrapped in the actual > bytecode.) And by unwrapped, I mean unrolled. :E3 Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Carl Banks
On Sep 12, 7:23 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Carl Banks <[EMAIL PROTECTED]> wrote: > >... > > > How about this? The decorator could generate a bytecode wrapper that > > would have the following behavior, where __setlocal__ and > > __execu

<    1   2   3   4   5   6   7   8   9   10   >