Re: Thread Question

2006-08-03 Thread Carl Banks
ock.release() If you can't change download_from_web, you might have no choice but to download sequentially. OTOH, if each thread uses a different ZIP file (and a different ZipFile object), you wouldn't have to use a lock. It doesn't sound like you're doing that, though. It shouldn't be a problem if one thread is zipping at the same time another is downloading, unless there's some common data between them for some reason. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Thread Question

2006-08-04 Thread Carl Banks
Ritesh Raj Sarraf wrote: > Carl Banks wrote: > > Then change the zipping part of download_from_web to acquire and > > release this lock; do zipfile operations only between them. > > > > ziplock.acquire() > > try: > > do_all_zipfile_stuff_here() > >

Re: do people really complain about significant whitespace?

2006-08-08 Thread Carl Banks
ce. Though they probably wouldn't have seen it anyways, considering the poor programming skills of most engineers (the classical definition, not computer engineers). The very fact the code formatters exist should tell you that grouping by indentation is superior. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: do people really complain about significant whitespace?

2006-08-09 Thread Carl Banks
ave such a function then you have bigger problems than minor defects in readability. :) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: do people really complain about significant whitespace?

2006-08-09 Thread Carl Banks
ent correctly. So although I personnaly like > Python, I still don't think meaningful indentation is good. Even if this were legal code (it isn't), it's still more transparent than some of the C code I've seen. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about using python as a scripting language

2006-08-09 Thread Carl Banks
I've written an HTML generator--who hasn't--that uses eval and exec to expand in-line Python code. Perfectly ok as long as you don't let untrusted users run the program.) 2. When you construct Python code within your program using no untrusted data Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about using python as a scripting language

2006-08-09 Thread Carl Banks
7;[1,2,3,4]') > > This is just asking for trouble. > > my_list = eval('import shutil; shutil.rmtree('/')') Fortunately, that won't work because eval expects an expression. Unfortunately, this will: my_list = eval('__import__("shutil").rmtree("/")') Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: do people really complain about significant whitespace?

2006-08-09 Thread Carl Banks
Michiel Sikma wrote: > Op 9-aug-2006, om 16:48 heeft Carl Banks het volgende geschreven: > > > Even if this were legal code (it isn't), it's still more transparent > > than some of the C code I've seen. > > > > Carl Banks > > Still kind of too

Re: do people really complain about significant whitespace?

2006-08-10 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Carl Banks wrote: > > Although Python doesn't do this, it is possible to mandate a specific > > indent (4 spaces, say), or at least a reasonable consistent indent > > I like running reindent.py (found in your Python source directory under >

Re: do people really complain about significant whitespace?

2006-08-10 Thread Carl Banks
eing one) Oddly, I never used to use K & R until I was a longtime Python programmer. Then I wanted to get those redundant braces as far out of the way as reasonable; hence K & R. Maybe someday I'll take up a LISP-like style and put the closing brace on the last line of the blo

Re: Curried class methods?

2006-08-17 Thread Carl Banks
setattr(Foo, i, lambda self: self.generalized(i)) > > foo = Foo() > foo.a() > foo.b() > foo.c() > > but this prints "my ctx is c" three times; I'd hoped for a, b, c, of > course. def build(j): setattr(Foo, j, lambda self: self.generalized(

Re: sum and strings

2006-08-19 Thread Carl Banks
t; > Yes, it's three lines. It's also very easy to read. reduce() and > sum() are not. sum() is really for numerical uses; people ought to just stick to using it that way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: sum and strings

2006-08-21 Thread Carl Banks
or the unwary". I'm not so sure special casing was a good idea myself, but... If you allow for a small number of special cases in the language to protect against the most harmful and prone traps, this case would be one of the top ones, IMHO. Carl Banks and, you know, if you really want

Re: Can, and if yes how could this be done elegant?

2006-08-22 Thread Carl Banks
rs, generate branch) with a single class. How close am I? You're doing this recursively, so there's really no way to get rid of the stack entirely. I don't know much about your code, but I quite doubt that it would put much strain your memory at all. We can, perhaps, help you organize your code better, though. But I think you'll need to make another pass at describing your problem. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: classroom constraint satisfaction problem

2006-10-15 Thread Carl Banks
y assigned. Or, work out a way to make sure you don't exhaust too many homerooms. Perhaps there is a known algorithm for doing this. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python wrapper for C++ core

2006-10-17 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Hi All > > Apologies in advance for the pretty basic question - but I can't seem > to find an answer anywhere else. > > I am developing a fluid sim in C++ and have heard that many people use > Python in conjunction with C++ for this sort of thing (especially in > games de

Re: creating many similar properties

2006-10-18 Thread Carl Banks
Lee Harr wrote: > I understand how to create a property like this: > > class RC(object): > def _set_pwm(self, v): > self._pwm01 = v % 256 > def _get_pwm(self): > return self._pwm01 > pwm01 = property(_get_pwm, _set_pwm) > > > But what if I have a whole bunch of these pw

Re: creating many similar properties

2006-10-18 Thread Carl Banks
ing other than touch the class dict upon creation); whereas if you use Michele Simionato's hack, the icky feeling of using a stack frame object goes away after the property is created: you are left with a clean untainted class. Personally, the former doesn't make me feel icky at all. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: creating many similar properties

2006-10-18 Thread Carl Banks
George Sakkis wrote: > There's a subtle common bug here: all _get and _set closures will refer > to the last property only. You have to remember to write "def > _set(self,v,prop=prop)" and similarly for _get to do the right thing. Sorry. My mistake. > By the way, I can't think of a case where t

Re: creating many similar properties

2006-10-18 Thread Carl Banks
Michele Simionato wrote: > Carl Banks wrote: > > Devil's Advocate: he did say "hidden magic TO YOUR CLASS". > > > > If you use a (real) metaclass, then you have the icky feeling of a > > class permanently tainted by the unclean metaclass (even though

Re: creating many similar properties

2006-10-18 Thread Carl Banks
Michele Simionato wrote: > Carl Banks wrote: > > Come on, I don't think anyone's under the impression we're being > > indiscriminate here. > > Ok, but I don't think that in the case at hand we should recommend a > metaclass > solution. You sound

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
[EMAIL PROTECTED] wrote: > The extended slice notation comes from the > numeric community though where they are probably all former FORTRAN > programmers. I think the concept of start, stop, step (or stride?) is > pretty common there. Yep. I do a bit of numerical work and the meaning of abc[::-

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
Demel, Jeff wrote: > I've been programming professionally for over 10 years, and have never > once needed to reverse a string. Maybe it's a lack of imagination on my > part, but I can't think of a single instance this might be necessary. Say you're using a function from a third-party library tha

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
Istvan Albert wrote: > Carl Banks wrote: > > > Say you're using a function from a third-party library that finds the > > first character in a string that meets some requirement. You need to > > find the last such character. > > You seem to imply that invokin

Re: Want to reduce steps of an operation with dictionaries

2006-10-24 Thread Carl Banks
; erroneously (for me) gets: > {'a': 0, 'c': 2, 'd': 3} Filter first, Sort second, Enumerate third, Build Dict last: c = dict((k,v) for (v,k) in enumerate(sorted(j for j in a if j in b))) The inner generator you could do with sets also. c = dict((k,v) for (v,k) in enumerate(sorted(set(a)&set(b Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Want to reduce steps of an operation with dictionaries

2006-10-24 Thread Carl Banks
; In Python {'a':0, 'c':1, 'd':2} == {'a': 0, 'c': 2, 'd': 3} Careful there, chief. The Python interpreter disagrees: >>> {'a':0, 'c':1, 'd':2} == {'a': 0, 'c': 2, 'd': 3} False I inferred that by "re-sequencing", the OP meant the keys in the new dict were to be associated with a new range of integer values (probably specifically the key's index in a sorted list of keys). It was an unfortunate choice of words, as sequencing has a pretty specific meaning in Python. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-25 Thread Carl Banks
t; > The 3 gets converted to float, like when you say > > > > x = 3.1 + 3 > > > > the result is 6.1. > > Yes - it just seems that there isn't a principled reason for implicitly > converting 3 to 3.0 in 3.0 == 3 but not implicitly converting "cat" to > bo

Re: question about True values

2006-10-26 Thread Carl Banks
nor iterators consider "empty" to be "false", the idea that "empty" is "false" is very far from self-evident; therefore lists, tuples, dicts, and sets should also raise exceptions when used as a boolean. I won't mention that, though.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Truth value of iterators [was: question about True values)

2006-10-26 Thread Carl Banks
Ben Finney wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > An iterator is not a sequence, and it's impossible to determine > > whether an iterator is "empty" in general, except by trying to get > > an item from it. [...] > > &g

Re: Truth value of iterators [was: question about True values)

2006-10-26 Thread Carl Banks
lease) (Debian 4.1.1-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> len(iter(())) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'tupleiterator' has no len() >>> bool(iter(())) True Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: question about True values

2006-10-27 Thread Carl Banks
inary trees do have length: it's the number of nodes, just as the number of keys is the length of a dict. I can't think of any objects that use indexing but don't have a length, except for poorly-implemented proxy objects. It's possible to define such types, but would that be a Pythonic use of indexing? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

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
Rocco wrote: > hi > I made the upgrade to python 2.4.3 from 2.4.2. > I want to take from google news some atom feeds with a funtion like > this > import urllib2 > def takefeed(url): > request=urllib2.Request(url) > request.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; >

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: 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: 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

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

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

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