Re: How do I dynamically create functions without lambda?

2006-02-02 Thread Alex Martelli
Benji York <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Disagree -- far more people THINK they're clever, than really ARE > > clever. According to a recent article in the Financial Times, over 40% > > of a typical financial firm's employees firmly b

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
from) statements are exceptions to this. import x.y binds or rebinds name x "on the fly", as well as attribute y of x. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
er), that's what it should do if it allowed the following name to be a compound one, too. Unfortunately, none of this suggests that it's reasonable to have def x.y(z): ... mean the same as def y(x, z): ... and I have no idea of how it would generalize to def x.y.z(t): ... (while import x.y.z generalizes in a pretty obvious way wrt import x.y). So, I'm not supporting the OP's idea; just rejecting the specific objections to it. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
'' similarly. But, as I said, "I'm not supporting the OP's idea; just rejecting the specific objections to it". For once, I have a hard time articulating exactly why I'd dislike such semantics for hypothetic syntax "def x.y", besides minor points such as the difficulties wrt generalizing to "def x.y.z"... but I do know which objections are NOT the ones which make me feel such dislike!-) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: ... > your idea. Could you summarize how exactly "f(x,y=z)" should be > resolved, i.e. where it should look for "f"? Lexically: local scope, outer functions outwards, globals, builtins. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
ooks in superclass namespaces. Nope: >>> class B: ... def f(self): print 'b.f' ... >>> class A(B): pass ... >>> a=A() >>> a.__class__.f(a) b.f >>> Inheritance applies in any lookup of an attribute in a class, just as well as on an instance of the class. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: OO conventions

2006-02-04 Thread Alex Martelli
elegating the building to a method or function frees your application from such hardwiring and lets it be concentrated (if needed at all) in one spot (the factory). [[With the "registry" pattern you may even be able to remove any hardwiring, but that's a pretty advanced and subtle idea]]. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: OO conventions

2006-02-04 Thread Alex Martelli
re another beast - much more useful than > > staticmethods) > > Does it make any noticeable difference in efficiency, or does nobody > care much about efficiency in Python? Some of us do, at few but crucial moments; that's why we have timeit.py to let you measure the perfo

Re: Learning Python

2006-02-05 Thread Alex Martelli
m), with your use of: input(raw_input(... which means "get a string from the user and use it as a prompt to get any value from the user" (a very peculiar usage). The difference between `int' and `input' is rather enormous. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python

2006-02-05 Thread Alex Martelli
bsolutely unrelated to that spot in the tutorial. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Get System Date?

2006-02-05 Thread Alex Martelli
06 >>> print mm 2 >>> print dd 5 >>> As you see, these are integers (so, for example, mm is not '02' but just 2). Pretty easy to make them into strings, of course, if you want. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Reverse of map()?

2006-02-05 Thread Alex Martelli
and kwds, since it's a rare need. Also, map returns a list, not a tuple, so it's bordering on the absurd to think that your dreamed-for rmap would be designed to return a tuple rather than a list -- you still have to call tuple on the result, any way you build it. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Help!

2006-02-05 Thread Alex Martelli
but im trying to > mirgrate for windows to linux. Python runs on Windows, Linux, Mac (where it comes with the OS, but then that's also true of many Linux distros), and elsewhere. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing a class, please help...

2006-02-05 Thread Alex Martelli
o access such JVM bytecode, use Jython instead. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Literal Escaped Octets

2006-02-05 Thread Alex Martelli
he binary value of its k-th byte is ord(s[k]). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Detecting line endings

2006-02-06 Thread Alex Martelli
attribute. > My worry is that if '\n' *doesn't* signify a line break on the Mac, It does, since a few years, since MacOSX is version of Unix to all practical intents and purposes. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: numeric expression from string?

2006-02-06 Thread Alex Martelli
Brian Blais <[EMAIL PROTECTED]> wrote: > someone might accidentally do damage to their system with an unchecked eval. Nah, it takes malice and deliberation to damage a system from an eval. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Detecting line endings

2006-02-07 Thread Alex Martelli
metadata associated with them showing the line-ending in use ? Not in the filesystems I'm familiar with (they did use to, in filesystems used on VMS and other ancient OSs, but that was a very long time ago). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: The problem of anonymity with decorators

2006-02-07 Thread Alex Martelli
hese last three statement into a def remix(wrapped, fun): ... """ return a function like 'wrapped' but w/name and defaults fm 'fun' """ ...same 3 statements as above, from w = ... onwards... Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Xah's Edu Corner: Unix damage: color names

2006-02-07 Thread alex . gman
So why don't you use Windows XP then? It's just like what you are using now, but even more awesome! -- http://mail.python.org/mailman/listinfo/python-list

Re: Detecting line endings

2006-02-07 Thread Alex Martelli
gt; determines it ? It doesn't. Python doesn't even try to guess: nor would any other sensible programming language. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: how to copy a Python object

2006-02-07 Thread Alex Martelli
getstate/setstate are generally the best approach. An equally good alternative here, omit setstate and just: def __getstate__(self): return dict(lst=self.lst) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Undergraduate project :: python ToDo list

2006-02-08 Thread Alex Martelli
ws several PEPs approved but not implemented for Python 2.5; take a look and write the development mailing list, python-dev@python.org, to volunteer to implement one of them. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python threading, and processes

2006-02-08 Thread Alex Martelli
great use case for async (even-driven) programming; use Twisted (or even build on top of asyncore) and you'll easily saturate your network bandwidth with modest CPU demands. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python good for web crawlers?

2006-02-08 Thread Alex Martelli
or something like that. Goo...can't remember. > > See http://www-db.stanford.edu/~backrub/google.html Yeah, I've heard of them, too. > They've also employed some clever Python programmers, such as Greg > Stein, Alex Martelli (isn't he a bot?) and some obscure du

Re: Is Python good for web crawlers?

2006-02-09 Thread Alex Martelli
John J. Lee <[EMAIL PROTECTED]> wrote: ... > I wonder if that little outfit has considered open-sourcing any of > their web client code? What they've open-sourced so far is listed at <http://code.google.com/projects.html> -- of these, the only crawl/spider is Könguló,

Re: Question about idioms for clearing a list

2006-02-09 Thread Alex Martelli
der to use in such a way, than either set or collections.deque? (For dict, I can see the rationale for not having an 'addkey', even though the presence of class method 'fromkeys' weakens that rationale... but for list, I cannot see any reason that makes sense to me). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Scientific Computing with NumPy

2006-02-10 Thread Alex Martelli
st > of the developers on mac are using 2.4 :-) However, what comes with MacOSX is STILL 2.3 (specifically 2.3.5 with Tiger). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-10 Thread Alex Martelli
ns exactly right is tricky (which is why bisect is a good model!), but this way you get O(log N) performance for a list of length N. If N is not too huge, O(N) might be OK, and is, of course, way simpler to code!-) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a better way?

2006-02-11 Thread Alex Martelli
Charles Krug <[EMAIL PROTECTED]> wrote: > On 2006-02-11, Alex Martelli <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > >> Problem: > >> > >> You have a list of unknown length, such as this: list = >

Re: appending to a list via properties

2006-02-11 Thread Alex Martelli
nt to hoist for performance, you can hoist more: appenders = foo.append, qux.append while some_condition: for appender, anitem in zip(appenders, calculate_something()): appender(anitem) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: PySizeof: almost useful

2006-02-11 Thread Alex Martelli
taking SHIFT bits. > Many thanks to anyone bored enough to review this code. Sorry, I don't have the time, but I hope the above tip can be useful. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: ordered sets operations on lists..

2006-02-11 Thread Alex Martelli
s time to waste, "setification" being only an optimization, it can also be removed: filter(l2.__contains__, l1) etc (very slow for long lists, of course). Personally, I'd always use (depending on guesses regarding lengths of lists) [x for x in l1 if x in l2] or the setified equiva

Re: python 2.5 and hashlib

2006-02-11 Thread Alex Martelli
a draft, being discussed in the last few days on python-dev. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: appending to a list via properties

2006-02-11 Thread Alex Martelli
Xavier Morel <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Carl Banks <[EMAIL PROTECTED]> wrote: > >... > >>> class better_list (list): > >>> tail = property(None, list.append) > >> This is an impress

Re: ordered sets operations on lists..

2006-02-12 Thread Alex Martelli
it yourself? Yes, it is a point worth making, since the lack of hoisting is a frequent cause of performance loss. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
imetools.Message instance whose headers have metadata (such as content type information). If that doesn't fit your needs well, you may study the sources of urllib.py in your Python's library source directory, to see exactly what it's doing and code your own modified version. Alex Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another n00b: Removing the space in "print 'text', var"

2006-02-12 Thread Alex Martelli
World , how are you today?" > > Have googled, and worked my way through the first 7 chapters of Byte of > Python, but to no avail... Use string formatting: print 'Hello %s, how are you today?' % strName Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Need a bit of help with a list..

2006-02-12 Thread Alex Martelli
rh0dium <[EMAIL PROTECTED]> wrote: ... > Why doesn't this work as expected.. I expect that the the lines within > the sections will get modified - permanently. It is modifying them > during the first section but they never get saved to the new values.. > Can anyone help me and even better expl

Re: Questions for BitTorrent's Author, Bram Cohen

2006-02-12 Thread Alex Martelli
you can get leaner and faster code by redoing it all in C, can't you?" Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
ot;!-) > -- just bought "cookbook" and "nutshell" moments ago btw Nice coincidence, and thanks!-) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
f. This way, f is the filename, m a message object useful for metadata (e.g., content type). Otherwise looks fine. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python very slow compared to C

2006-02-13 Thread Alex Martelli
ls. However, there doesn't appear to be further spreading of such object models; "big" new languages like C# (and indeed the whole underlying CLR framework, which also forced the semantics of VB) are strongly class-based. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How to *Search* with google from inside my programme and get the search result?

2006-02-14 Thread Alex Martelli
Frank Potter <[EMAIL PROTECTED]> wrote: ... > Does google supply some webservice to programmers? I did see Yep, see http://www.google.com/apis/index.html . Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Xah's Edu Corner: accountability & lying thru the teeth

2006-02-15 Thread alex . gman
John Bokma wrote: > Al Balmer <[EMAIL PROTECTED]> wrote: > > > have for a long time, and I can understand that it would be better if > > everyone filtered or ignored him, > > The best would be if everybody instead of posting replies would complain > to his ISP and Usenet provider. Xah is a major an

Re: Safe Python Execution

2006-02-16 Thread Alex Martelli
ggest compiling the code and examining the names used in the code object (co_names attribute of the code object which compile returns) -- refuse to execute the code if it mentions, defines or uses any special name (starting and ending with two underscores). That, plus removing almost all builtins as you do here, should be a good start. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: looping over more than one list

2006-02-16 Thread Alex Martelli
easure cases of interest. If you don't (not especially) then the first solution looks neat, elegant, readable, and concise. But never build up substantial strings with a loop of += of small strings: that's O(N squared) and will MAKE you care about performance even where you otherwise wouldn't!-) Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: days since epoch

2006-02-16 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > hi > how can i get the number of days since epoch using the time module? > or do i have to manually do the arithmetic? Try the datetime module -- better suited to computing days, than the time module, IMHO. Alex -- http://mail.python.org/mailman/

Re: getting the line just before or after a pattern searched

2006-02-16 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > hi > > i have a file something like this > > abcdefgh > ijklmnopq > 12345678 > rstuvwxyz > . > . > . > 12345678 > . > > whenever i search the file and reach 12345678, how do i get the line > just above and below ( or more than 1 line above/below) the

Re: Mac OS X Installation Problem

2006-02-17 Thread Alex Martelli
as far as I can tell. However, when I > type python at the command line, I get "command not found" so, > > 2) How do I get OS X to recognize python at the command line? Edit a ~/.bashrc file to add /usr/local/bin to your PATH. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: web crawler in python or C?

2006-02-17 Thread Alex Martelli
. > Remember Donald Knuth's quote. > "Premature optimization is the root of all evil in programming". I believe Knuth himself said he was quoting Tony Hoare, and indeed referred to this as "Hoare's dictum". Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi-threaded SSL

2006-02-17 Thread Alex Martelli
? SSL is fully implemented in Twisted, AFAIK. Is the example at <http://twistedmatrix.com/projects/core/documentation/examples/echoserv_ ssl.py> at all unclear or mysterious, for example? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: - Copy dictionary entries to attributes

2006-02-18 Thread Alex Martelli
of the attributes are properties, slots or weirder descriptors yet. For plain vanilla class instances, though, self.__dict__.update(settings) may be sufficient. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How many web framework for python ?

2006-02-19 Thread Alex Martelli
wadays. Please eliminate three. PS: I am *not* a crackpot! Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-19 Thread Alex Martelli
anguage, and it's not interpreted. OK, but then we should change <http://python.org/doc/Summary.html>, which starts with "Python is an interpreted, interactive, object-oriented programming language." -- if "it's not interpreted", then why is this crucial page o

Re: Python vs. Lisp -- please explain

2006-02-19 Thread Alex Martelli
esperate task to try to count them all...:-( Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Mac OS X Installation Problem

2006-02-19 Thread Alex Martelli
wrote: > [EMAIL PROTECTED] (Alex Martelli) wrote: > > >Edit a ~/.bashrc file to add /usr/local/bin to your PATH. > > Hi Alex, > > Easier said than done for a non-unix expert. Correct me if I am wrong. Bash > looks at the contents of the PATH variable to decided wh

Re: Mac OS X Installation Problem

2006-02-19 Thread Alex Martelli
#x27;s own Python (2.3.5) will be trivial -- stay tuned! Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How many web framework for python ?

2006-02-20 Thread Alex Martelli
bruno at modulix <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > >... > >>>There are very good web framework for java and ruby , > >>>Is there one for python ? > >> > >

Re: Processing text using python

2006-02-20 Thread Alex Martelli
hefile.read(3) in a loop, move to the next file when the current one is exhausted. What part of this is giving you problems? Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying an instances dict to change attribute lookup

2006-02-20 Thread Alex Martelli
want in Python is by overriding __getattr__ (which gets called when other normal lookup procedures fail and would, absent __getattr__, raise AttributeError), not by trying to install as the __dict__ something whose type isn't exactly __dict__. Other approaches may work, but they depend on implem

Re: number ranges

2006-02-20 Thread Alex Martelli
tive;-). No reason for programming languages, or other formal languages, to follow natural language down this destructive path. In any case, the point is crucial: since Python will never do something as abysmal as introducing a closed interval rather than a semiopen one, the same kind of people who now

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
so far. __slots__ is not a method, so it falls outside that purpose as stated. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
st PC _I_ owned had 4K of RAM (the cheaper model only had 1K, but I splurged for the big one) -- Sinclair ZX80. But I didn't run Python on it (indeed I soon swapped it for one with very similar HW but Forth instead of Basic, called the "Jupiter Ace": Forth's force has always be

Re: changing value of 'self' when subclassing int

2006-02-20 Thread Alex Martelli
the idea, to the point that I never got around to it -- gmpy includes a lot of functionality for bit-level manipulation, but still only with immutable bitlists (mapped into gmpy.mpz instances). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Unintended inheritance

2006-02-20 Thread Alex Martelli
DO get recompiled) rather than relying on semidecent unittests is scant consolation -- there's still no bound to the amount of work that may be needed to repair the wreckage. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Alex Martelli
Peter Hansen <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Zefria <[EMAIL PROTECTED]> wrote: > >... > >>this special case I'm expecting each "carrier" to have up to 150 > >>fighters, and 3 to 5 carriers for each of the tw

Re: Processing text using python

2006-02-20 Thread Alex Martelli
ion on slicing: > > > > "substrings can be specified with the slice notation: two indices > > separated by a colon" > > > Fredrik, how would you use slices to split a string by groups of 3 > characters? I can't answer for him, but maybe:

Re: 2.4.2 + Zone Alarm

2006-02-20 Thread Alex Martelli
on the Python bug tracker (http://sourceforge.net/bugs/?group_id=5470) somebody will (look into it, for sure, and hopefully fix it in time for 2.4.3). Thanks, Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Augmented assignment

2006-02-20 Thread Alex Martelli
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > Hi, > Is there any gain in performance because of augmented assignments. > > x += 1 vs x = x+1 > > Or are both of them the same. Just *MEASURE*, man! helen:~/apy alex$ python -mtimeit -s'x=0.0'

Re: number ranges

2006-02-20 Thread Alex Martelli
th whines about it); Python is clearly much better off if such people run away to Ruby, with its (expletive deleted) a..b AND a...b syntaxes just to ensure maximum confusion;-). > 2. How could a stride be included in this notation? The natural way would be (x to y by z), I think. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Alex Martelli
the words I had written. Nevertheless, in your honor, I guess I will redundantly change the ONCE into JUST ONCE in the second edition (I do strive for maximum conciseness in the Nutshell, but I guess I can spare one extra four-letter word, even though this is the only time I ever heard anybody expres

Re: Multiple assignment and the expression on the right side

2006-02-21 Thread Alex Martelli
f some text to fail to see potential issues with the text, which may trip some readers but appears to be perfect to the author -- that's why two heads are better than one, and N>2 even better than two!-). So, again, thanks. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: number ranges

2006-02-21 Thread Alex Martelli
t could be the other way 'round) -- I don't remember how it indicates a step. I do think this is a wart (lack of visual or mnemonic distinction), though I'm sure Ruby enthusiasts would not agree. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-25 Thread Alex Martelli
Mu. -- http://mail.python.org/mailman/listinfo/python-list

Re: sort one list using the values from another list

2006-02-26 Thread Alex Martelli
make the nesting structure of items of _aux more obvious. Of course, each of these has a variant using sorted instead of sort, and for those you could use izip from itertools rather than built-in zip, and do everything within one single statement, etc, etc. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I redirect print function to an output file?

2006-02-26 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > I am using the print function in my python script. > Can you please tell me what can I do to redirect the output to an file? f = open('aaargh', 'w') print>>f, 'killew wabbit' Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Do I need to convert string to integer in python?

2006-02-26 Thread Alex Martelli
ode string when you're done, x = unicode(int(x) / 10) should work. If you want x to become an integer, omit the unicode call around the int(x)/10 expression. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Alex Martelli
ormance indeed, thanks! Except it rejects a w that's JUST an underscore, while it would accept a w that's just a letter, which seems weird to me. Using 'a' as the second argument of the replace call, as somebody else suggested, appears to produce a more sensible uniformity. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-26 Thread Alex Martelli
Crutcher <[EMAIL PROTECTED]> wrote: ... > No, I don't disagree that people do this. The history of "Zen and the > Art of X" dates from "Zen and the Art of Motorcycle Repair", which is That's Maintenance, not Repair. Subtle but important distinction.

Re: sort one list using the values from another list

2006-02-26 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Your solution Steven Bethard looks very intelligent, here is a small > > speed test, because sorting a list according another one is a quite > > common operation. > > (Not all solutions are r

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Alex Martelli
dden to perform any assignment on a function-call. If you're keen on these semantics, use for example f().extend([4]) which IS quite legal (or, if you know the RHS list has only one item, f().append(4) is clearer and more effective). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Alex Martelli
ce, you cannot substitute a function call, nor a constant (literal) list (nor any of several other possible literals and other expressionforms). Wherever Python just needs a value, not a rebindable whatever, then of course you can supply that value in whatever syntax form suits you best, includin

Re: Local variables initialization

2006-02-26 Thread Alex Martelli
emented during Pycon, i.e., today). Personally, I would keep pushing back against this approach even after I'd gone to the trouble of implementing it more solidly -- in no way is clarity served by having magic local variables appear out of the blue (or, rather, the black of black magic). However, whether something CAN be done, and whether it SHOULD be done, are separate issues. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Local variables initialization

2006-02-26 Thread Alex Martelli
', or any other such approach, will suffice. But of course, then the method's body would have to use _.one rather than var_one, _.two rather than var_two, and _.empty_list rather than empty_list (what a strange name -- does it STAY empty throughout the method's execution?!). To me this

Re: sort one list using the values from another list

2006-02-26 Thread Alex Martelli
(d.keys()) AND to be faster (would be pretty weird if it weren't faster...!). E.g., ...: helen:~ alex$ python -mtimeit -s'd=dict(enumerate("tarazoplay"))' 'sorted(d.keys())' 10 loops, best of 3: 6.82 usec per loop helen:~ alex$ python -mtimeit -s'd=dict

Re: Use of __slots__

2006-02-27 Thread Alex Martelli
grammers who fully know what they're doing, so nobody at the time took the trouble of building such strong fences around it (it wouldn't save us many of the huge stream of questions and misunderstandings we're getting all the time about it, anyway). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of __slots__

2006-02-27 Thread Alex Martelli
MrJean1 <[EMAIL PROTECTED]> wrote: > An example of the RARE use case may be this particular one > > <http://mail.python.org/pipermail/python-list/2004-May/220513.html> A benchmark is not a use case. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Alex Martelli
LLY be false (and ditto for true). In set terms, say, "all integers x such that x>x" would be an *intrinsically* empty set, while "all dogs that are in this house right now" would be a set which *just happens* to be empty -- they aren't "one and the same, the sole

Re: PEP 354: Enumerations in Python

2006-02-27 Thread Alex Martelli
Ben Finney <[EMAIL PROTECTED]> wrote: ... > The Python parser knows what to do when a comparison returns > NotImplemented. The parser has nothing to do with it, but the bytecode interpreter sure does;-). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: PyGUI 1.6: A Note for MacOSX Users

2006-03-01 Thread Alex Martelli
", line 184, in init_application_name ns_info['CFBundleName'] = GApplications.application_name TypeError: object does not support item assignment That's when I try (after installing PyGUI): helen:~/Desktop/PyGUI-1.6/Demos alex$ python blobedit.py MacOSX, XCode, Python and PyObjC all at the latest

Re: How much does Python optimize?

2006-03-03 Thread Alex Martelli
e. Someday, range will behave like xrange automagically, ... > Thanks. Yes, this will be a problem for iterations in the order of 10**5 and > upwards only, and those are rare in most applications. So my question was And not crucial when they happen, mostly: helen:~ alex$ python -mtimeit -s'

Re: do design patterns still apply with Python?

2006-03-03 Thread Alex Martelli
gene tani <[EMAIL PROTECTED]> wrote: ... > There's a couple Alex M slideshows and a couple discussions of > Creational/Structural / Behavioral patterns > > http://www.strakt.com/docs/ep04_pydp.pdf And more of my stuff (including slideshows on Design Patterns in Pyth

Re: Python advocacy in scientific computation

2006-03-04 Thread Alex Martelli
uing tasks -- unless either firms, such as Enthought, or volunteers, commit to such tasks, they won't "just happen". Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Random Prime Generator/Modular Arithmetic

2006-03-04 Thread Alex Martelli
ill one. Could you maybe use /dev/random or the like? Cfr <http://world.std.com/~cme/P1363/ranno.html> for an introduction to the subject. (For speed, you may want to look into gmpy.sf.net, but that's quite a separate issue from the strength of your random numbers). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: generators shared among threads

2006-03-04 Thread Alex Martelli
ed thread waits and fills the queue again). [[Alternatively you could subclass Queue and override the hook-method _get, which always gets called in a properly locked and thus serialized condition; but that may be considered a reasonably advanced task, since such subclassing isn't documented in the reference library, only in Queue's sources]]. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Easy immutability in python?

2006-03-04 Thread Alex Martelli
code > repeated each time I need it, but I think it's dumb that > it's that complicated. If you need many immutable classes, inject __setattr__ etc into them (via metaclass or otherwise). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: How to except the unexpected?

2006-03-04 Thread Alex Martelli
t; Why catch an error only to re-raise it? To avoid the following handler[s] -- a pretty common idiom. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Inline assignments

2006-03-05 Thread Alex Martelli
to idiomatic Python itself. Therein, of course, lies the danger -- over-relying on this adapter may mean you never really learn to "think the Python way" and thus to code idiomatic Python, even when that would be most appropriate (i.e., in most cases). Still, Python _is_ a "consen

Re: Why I chose Python over Ruby

2006-03-05 Thread Alex Martelli
(and Smalltalk), but I do not see it as a question of rigor and consistency at all -- e.g., I do not perceive Smalltalk as less rigorous or consistent than C++, on the contrary. So, I agree with your choice, and I think I understand your motivations, but I do not entirely share your motivations, personally speaking. Alex -- http://mail.python.org/mailman/listinfo/python-list

<    9   10   11   12   13   14   15   16   17   18   >