Re: question about True values

2006-10-28 Thread Carl Banks
Steven D'Aprano wrote: > On Fri, 27 Oct 2006 11:25:09 -0700, Carl Banks wrote: > > > Steven D'Aprano wrote: > >> But in this specific instance, I don't see any advantage to explicitly > >> testing the length of a list. Antoon might think that is su

Re: question about True values

2006-10-29 Thread Carl Banks
Steven D'Aprano wrote: > Carl Banks: > > Overall, your objections don't really apply, since you're arguing what > > ought to be whereas my argument is pragmatic. Practically speaking, in > > realistic situations, "if len(a)>0" will work for

Re: question about True values

2006-10-29 Thread Carl Banks
r some abstact notion of unity of style more important than practical considerations of how your data is used. In that case you might as well just go with what the authority tells you to. (And hope that your users don't do much numerical stuff.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Event driven server that wastes CPU when threaded doesn't

2006-10-29 Thread Carl Banks
the SQL server events the same as it does with your clients. Being that SQL is so common, I bet someone's already written higher-level protocol handlers. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python tools for managing static websites?

2006-10-31 Thread Carl Banks
bout is vintage 1998. (One of my design goals was freedom to be sloppy with closing tags. HRL keeps track of and automatically closes tags when appropriate, but it doesn't know about tags like embed.) And it's not any sort of enterprise-quality content management. It's just a templating engine with power. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Where do nested functions live?

2006-11-01 Thread Carl Banks
e) for obj in func.func_code.co_consts: if isinstance(obj,codetype): if obj.co_name == name: return new.function(obj,func.func_globals) raise ValueError("function with name %s not found in %r" % (name,func)) Not exactly something I'd recommend for ordinary usage, but it can be done. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Hooking file open

2006-11-01 Thread Carl Banks
s, I don't think the database modules (dbm, gdbm, bsddb) use Python open, so might want to hook into those as well. You have be careful with extension modules; they often open files their own way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Javascript is turning into Python?!

2006-11-03 Thread Carl Banks
_1.7 Maybe in exchange, Python can borrow the let statement. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Timing a function object versus timeit

2006-11-03 Thread Carl Banks
on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def foo(x): ... return x+1 ... >>> import timeit >>> timeit.Timer("foo(1)","from __main__ import foo") 1.1497418880462646 Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__ function problem

2006-11-07 Thread Carl Banks
al constructor is called __new__, but you shouldn't use __new__ like C++ and Java constructors. Usually there's no reason to use __new__ at all. (The main use case is to return something other than a newly created object, such as a preallocated or cached object. For your normally functi

Re: Inheritance Question

2006-11-11 Thread Carl Banks
that we still have a OneLeg class, because there's still behavior exclusive to one-legged creatures. It belongs in OneLeg, not in AtLeastOneLeg. Hope this long-winded advice helps. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Carl Banks
r > > yield *iterable Since this is nothing but an alternate way to spell a very specific (and not-too-common) for loop, I expect this has zero chance of success. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Carl Banks
e... 3. While not breaking backwards compatibility in the strictest sense, the adverse effect on incorrect code shouldn't be brushed aside. It would be a bad thing if this incorrect code: a = ["hello"] b = "world" a+b suddenly started failing silently instead of raising an exception. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 idea -- + on iterables -> itertools.chain

2006-11-13 Thread Carl Banks
George Sakkis wrote: > Carl Banks wrote: > > George Sakkis wrote: > > > If by 'respond to "+"' is implied that you can get a "TypeError: > > > iterable argument required", as you get now for attempting "x in y" for > > >

Re: Py3K idea: why not drop the colon?

2006-11-13 Thread Carl Banks
__dict__ to catch any post-release accesses, which could cause subtle failures otherwise.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Py3K idea: why not drop the colon?

2006-11-13 Thread Carl Banks
ndancy? The language is designed for > communication between people (programmers) primarily. Redundancy is > often the best way to be explicit and readable. Well, Python *is* quite a notorious redundancy minimizer Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python v PHP: fair comparison?

2006-11-15 Thread Carl Banks
r's whole time, whereas a single Python (or Ruby, or Perl, or even Java) programmer could manage several web sites. (If by "probable" I mean "wishful thinking", that is :) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: why not in python 2.4.3

2006-05-28 Thread Carl Banks
work with 2.4.3. > Why? Define "woks [sic] well". It works fine for me on 2.4.3 (and by "works fine" I mean it ran without an exception and it returned what appeared to be RSS data). If you would give us an exception trace it would help a lot. Maybe Google's serve

Re: announce: DaVinci Rendering Engine

2006-06-02 Thread Carl Banks
K.S.Sreeram wrote: > Hi All, > > I've started working on a new open source graphics library called > DaVinci. DaVinci aims to provide a declarative vector graphics based > framework for building GUIs. > > http://tachyon.in/davinci/ I hope it'll get St. John'

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
parts. > One further point: if you really do conceptualize scalars as > zero-dimensional arrays, where is the value conceptually stored? Think of it this way: an array with n-dimensions of length 3 would have 3**n total entries. How many entries would a 0-dimensional array have? 3**0 == 1. Numeric has had zero-dimensional arrays for a long time, and has had no problem storing them. Think of the rule for accessing an element of an array: it's a base pointer + sum (indices*stride) for all indices. Now generalize it down to zero: there are no indices, so the scalar is stored at the base pointer. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
Steve Holden wrote: > Carl Banks wrote: > > Steve Holden wrote: > > > >>Hey, I have an idea, why don't we look at the language reference manual > >>instead of imagining how we think it might work! > > > > > > I don'

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
With a 1-tuple. How would you index a 0-D array? ... Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: os.link makes a copy, not a link

2006-06-09 Thread Carl Banks
orgetting a step or something? > > Python 2.3.4 running on CentOS 4.3 Are file1 and file2 on the same filesystem? Looks like os.link just calls the OS's link system call, which, for your system, might copy the file. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: memory leak problem with arrays

2006-06-15 Thread Carl Banks
array data, so it'll be freed. This might not be your problem. Details are important when asking questions, and so far you've only given us enough to speculate with. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is fun (useless social thread) ;-)

2006-06-15 Thread Carl Trachte
Original Message Subject: Re: Python is fun (useless social thread) ;-) From:"Carl Trachte" <[EMAIL PROTECTED]> Date:Thu, June 15, 2006 8:21 am To: --

Re: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Carl Banks
ubclass directly from the metaclass's constructor. You could, of course, also use the closure method I demonstrated above in Thing's __new__ method--essentially you'd be using Thing's __new__ method as the factory function. > The above sample won't work but I hope

Re: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Carl Banks
class; therefore there it doesn't matter whether a member is a class member or an instance member. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Absolute noob to Linux programming needs language choice help

2006-06-24 Thread Carl Banks
is like learning to do stand-up comedy by laughing at your own jokes. For someone looking for looking to learn preferrably only one language, I'd say Python, without knowing more about your intended problem domain. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP thought experiment: Unix style exec for function/method calls

2006-06-25 Thread Carl Banks
ython? (or perhaps replacing the current one with > a new one) Doubt it. > * Has anyone else tried modelling the unix system exec function in > python? If so what did you find? > > * Since I can't find anything in the archives, I'm presuming my > searching abilities are bust today - can anyone suggest any better > search terms or threads to look at? Maybe look to see how tail-recursive optimization in languages such as Scheme work, and whether it can be generalized. > * Am I mad? :) Yep. :) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is fun and useful (was: Python is fun (useless social thread) ; -))

2006-06-25 Thread Jane &amp; Carl
> I believe the applicability of Python and related techniques to > process control, engineering programming, and so on, is vastly > under-appreciated. Conventional wisdom in these domains sees > Visual Basic, Visual C++, and Fortran as suitable vehicles. > You've seen how limiting this is. > > Fo

Re: Numeric help!

2006-06-28 Thread Carl Banks
returns an array with the elements of sat_id, but only where the corresponding element of msvga==z; otherwise the entry is zero. Numeric.ravel flattens an multidimensional array into one dimension, and, of course, Numeric.sum adds up all the elements in the array. How to get count and to work this

mmap -- memory mapped file

2006-06-28 Thread Carl Mackey
hi, i'm new to this list and new to python as well. i have a question on the memory mapped file ability python has. when i use a mmap on a file, will it copy the whole thing to ram or just whatever part of it i'm working on? basically, i'm wondering if it would be ok for me to have multiple mmap'

Re: Numeric help!

2006-06-29 Thread Carl Banks
Sheldon wrote: >Carl Banks wrote: >> I'm not sufficiently sure this isn't a homework problem, so here's a >> partial answer. [snip] > > My days as a student is over for the most part. I am learning python on > my own and Numeric is not properly documented

Re: Numeric help!

2006-06-30 Thread Carl Banks
works much better ! Probably you had a case where the array length was zero, but it wouldn't happen in the present case unless your input arrays are zero by zero. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP thought experiment: Unix style exec for function/method calls

2006-07-02 Thread Carl Banks
statement. > > > > Only if you were to replace the whole stack. If you only replace or > > reuse the top frame, I would think greet would exit and execution would > > resume right after the point from which set_name was called. Or am I > > misunderstanding what you want? > > I think you are. [snip] I'm sorry; I didn't notice the use of cexe also on the call to set_name. So now it makes sense. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: 3d simulation

2006-07-10 Thread Carl Banks
alimoe wrote: > I am interested in coding an app which uses physics and 3d and neural > nets and genetics. Any pointers? PyODE for the physics part. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: When is a subclass not right?

2006-08-24 Thread Carl Banks
s an A, then use an attribute. But that's only a rule of thumb. I personally find another question helpful. If it's reasonable that B could have more than one of A, regardless if it actually does, use an attribute. If it's unreasonable, subclass. Again, rule of thumb. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: When is a subclass not right?

2006-08-25 Thread Carl Banks
David Ells wrote: > Carl Banks wrote: > > The classical advice in choosing whether to subclass or or use > > attribute is whether its more an an "is a" or "has a" relationship. If > > it's more natural to say B is an A, then subclass. If it

Re: Avoiding if..elsif statements

2006-08-25 Thread Carl Banks
unexpected wrote: > Currently, I've implemented a bunch of > if..elsif statements to do this, but it's gotten to be over 30 right > now and has gotten rather tedious. Is there a more efficient way to do > this? Use something other than Perl. :) Carl Banks -- http://m

Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-26 Thread Carl Banks
so using __slots__ probably did save quite a bit of byteage, but that consideration had nothing to do with my decision to use __slots__. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style and else statements

2006-08-29 Thread Carl Banks
omething like this: def foo(thing): if thing: return thing+1 else: return -1 assert False Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Ben Finney wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > However, I have rare cases where I do choose to use the else > > (ususally in the midst of a complicated piece of logic, where it's > > be more distracting than concise). In that case

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Steve Holden wrote: > Carl Banks wrote: > [...] > > However, I have rare cases where I do choose to use the else (ususally > > in the midst of a complicated piece of logic, where it's be more > > distracting than concise). In that case, I'd do somethin

Re: Using eval with substitutions

2006-09-01 Thread Carl Banks
s)" % subexpr) return expr Then you can eval the expanded expression: eval(expand_sym("y")) However, this is just a big potentially dangerous hack. It's probably ok for a little calculator you intend only for personal use, but anything more I highly recommend your script parses the expression and does symbolic expansion itself, without relying on eval. That, however, is quite hard. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What are super()'s semantics?

2006-09-04 Thread Carl Banks
B. Thus, when self is of type D, super(B,self) does not have and MRO of (A,), but (C,A). Therefore, super(B,self).__init__() invokes C.__init__. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What are super()'s semantics?

2006-09-04 Thread Carl Banks
Maric Michaud wrote: > Le lundi 04 septembre 2006 13:48, Carl Banks a écrit : > > Essentially, it's objects that have MROs, not classes. > Wrong, __mro__ is an attribute of types (subtypes of type) but like __class__ > it is not available in the instances. > mro() is standa

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Carl Banks
the first and adds nothing. Whether something is None is an identity test; identity tests should use is. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Carl Banks
quality test. Playing Devil's advocate here: if you were to write "x!=None", then x's __eq__ method is invoked, which might not account for the possibility that the other operand is None. However, if you write "None!=x", then None's __eq__ method is i

Re: Positive lookahead assertion

2006-09-07 Thread Carl Banks
) > > does not. They are more commonly used, and generally more useful, at the end of a regexp: m = re.search(r"foo(?=d)","food") matches, but afterwards m.group(0)=="foo" (without the d). Meanwhile, m = re.search(r"foo(?=d)","fool") doesn't match at all. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: convert loop to list comprehension

2006-09-08 Thread Carl Banks
gs does, so it should be avoided. sum is for adding numbers; please stick to using it that way. FWIW, the original loop looked perfectly fine and readable and I'd suggest going with that over these hacked-up listcomp solutions. Don't use a listcomp just for the sake of using a listcomp. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
One problem with my decorator is it makes stack traces a little bloated. (Also attribute errors are raised as KeyError, but that's easily fixable.) Other than that, I've been running it for awhile without any problems. I doubt your approach would have many problems, either. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
mplish this. Internally, the module behaves very much like a class instance. Functions in the module act almost exactly like bound methods, and module-level variables act like instance attributes. The difference between writing a module and a singleton class thus becomes mostly a matter of indentation. In fact, when I made a major switch from using singleton classes to modules, I was able to change it by dedenting once, and pasting a @modmethod decoration above each method, with very few other changes. Carl Banks Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
George Sakkis wrote: > Carl Banks wrote: > > I don't see any major problem with it. In fact, I think it's a very > > good idea to do this, rather than use global statements, when using > > module as a singleton class. > > > > I recently made the same

Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
roblem with Kamilche's approach. The real evil in my mind is using lots of global statements, and anything you can do to stay away from that is a good thing. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Algorithm Question

2006-09-11 Thread Carl Banks
all elements in A that are not a substring of any other element in A} is the generally optimal solution. I suspect you mistyped or omitted something--problem is underspecified at best. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread Carl Banks
d Python code operating on the columns (and even then you should consider whether the user would be better off using keys). In this case you're pretty much stuck with workarounds. You can automatically rename any keywords when mapping the column names, and advise the user that colums with keyw

Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-12 Thread Carl Banks
le;-). Except Fortran doesn't have any reserved words either: PROGRAM KWDS REAL REAL,WRITE WRITE=1.0 REAL=2.0 WRITE(*,*)WRITE,REAL END (Not sure whether it's true in Fortran 9x.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

[ANN] Code Golf Challenge : 1,000 Digits Of Pi

2006-09-18 Thread Carl Drinkwater
em, even if you're new to the site. I hope some of you will find this interesting, and sorry for disturbing you if not! Have fun, Carl. -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.count(-3)

2006-09-21 Thread Carl Banks
this too. Seems like a regression to me. itertools was documented as taking a sequence of integers, not necessarily positive integers. It worked on Python 2.4. Looking at the source (from 2.5 rc2), it looks like they accidentally used PyInt_FromSize_t rather than PyInt_FromSSize_t in the count iter

Re: returning None instead of value: how to fix?

2006-09-22 Thread Carl Banks
aving a single return point). The following should do exactly what you want. def recursive_halve(value): if value < 1: print value return value value = value/2 print value return recursive_halve(value) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Talking to marketing people about Python

2006-09-25 Thread Carl Banks
n't seen too much new stuff in Perl. I could be biased. Still don't know whether labeling something as written in Python is intended to be a "badge of honor" or "advance warning". Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Talking to marketing people about Python

2006-09-25 Thread Carl Banks
or release (what's it been, like 5 years?), which is almost certainly undoing some of its FUD power. Therefore, it would be a good idea for your company to invest in some alternatives to Perl sooner than later. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: for: else: - any practical uses for the else clause?

2006-09-30 Thread Carl Banks
word): action(command) break else: do_general_action() Moral of the story: there are two ways to do a linear search (or linear sequence of tests): either an unrolled sequence of if...elif...elif clauses, or a rolled up for loop with a break. Either way you do it, you can

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Carl Banks
e idea that error == 0 is not self-evident, and often not true. If it helps, consider using string error codes, or defining some constants to check against ("if error == NO_ERROR"). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: re.match -- not greedy?

2006-11-19 Thread Carl Banks
if it hits a dead end, it'll go back and try another path. In fact, greediness usually doesn't affect *whether* a regexp matches; it only affects the groupings. I'm suddenly curious if there are any cases at all where greediness changes whether it finds a match. > (pls copy me on responses) Ah, too bad you won't see it then Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: a few extensions for the itertools

2006-11-19 Thread Carl Banks
> > returns default. > > > How are these different from all and any in Python 2.5? 1. These functions apply a predicate to the items. It's simple enough to do with any/all and a genexp, but by the same argument, it's simple enough to do imap and ifilter with a plain genexp.

Re: Note about getattr and '.'

2006-11-22 Thread Carl Banks
nary in any > > future CPython version. > > (Would be good.) > > Why would it be good? > > How many bugs have you found that were caused by this behaviour? It's not bugs. A specialized dictionary could be better optimized if you know it can only hold Python identifiers. Th

Re: Trying to understand Python objects

2006-11-23 Thread Carl Banks
but it's Thanksgiving and I > don't have enough room on the margin for the proof. I think classic > classes are just fine. Absolutely. We don't want newbies' feeble brains to explode. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What's going on here?

2006-11-23 Thread Carl Banks
way. You can't have the base class of all objects creating dicts for its instances--you wouldn't want every int object to have it's own dict. And you can't have Python class instances not have a dict by default. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: The Python Papers Edition One

2006-11-24 Thread Carl Banks
ferentiate it from the monetary sense of the word free. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I access a main frunction from an import module?

2006-11-24 Thread Carl Banks
t to profile.py (from the Python library). Importing from __main__ adversely affects tools such as PyChecker and PyLint. The exception to this would be if abc.py is specifically designed as a utility for interactive use; then it would be ok and useful. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Developing a Python Extension

2006-11-24 Thread Carl Banks
ol: clock_gettime'. You're missing a library. From the clock_gettime man page: NOTE Most systems require the program be linked with the librt library to use these functions. So you need to build the extention with librt. Try adding a 'libraries = ['rt']

Re: The Python Papers Edition One

2006-11-25 Thread Carl Banks
inology; it's a way to differentiate one of two different senses of the word "free". "Specific criteria" is some people's idea of what freedom is, but they're not the last word on it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

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 >

Does this always go right

2006-12-05 Thread Carl . Wolff
lcopy" isolated from changes in original in multithreaded context? The program reports no errors but I want to be really sure about this Thanks Carl. original = {} originalcopy = {} originaldeepcopy = {} class checker(threading.Thread): def __init__(self): threading.Thread.__i

Copy vs Deepcopy in multithreaded contexts

2006-12-05 Thread Carl . Wolff
Helloquestion about copy vs deepcopy used in multithreaded context:suppose the following program below:the original dictionary is modified after the thread is started, the thread works on a copied and deepcopied version of the original dictionary. Is the dictionary named "originalcopy" isolated fro

Re: Does this always go right

2006-12-06 Thread Carl . Wolff
Hello Gabriel, > For your simple test dictionary, copy and deepcopy behaves > identically. If you wish, you should test using values that are > containers themselves. thanks, your answer clarifies a lot. Gtx carl -- http://mail.python.org/mailman/listinfo/python-list

Re: Copy vs Deepcopy in multithreaded contexts

2006-12-06 Thread Carl . Wolff
Hello, this issue is solved, no help needed. Gtx Carl. - Forwarded by Carl Wolff/IT/NL/Imtech on 06-12-2006 10:51 - Carl Wolff/IT/NL/Imtech wrote on 05-12-2006 22:55:20: > Hello > > question about copy vs deepcopy used in multithreaded context: > > suppose the fo

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
Carl J. Van Arsdall wrote: > Isaac Rodriguez wrote: > >> Yes, it would be a bad idea. =) > >> > > > > Saying it is a bad idea and not explaining why will not help anyone. I > > would like you to elaborate on why it is a bad idea to have one file > > pe

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