Re: what is the difference between the two kinds of brackets?

2007-10-21 Thread Alex Martelli
James Stroud <[EMAIL PROTECTED]> wrote: ... > > I wonder if its the philosophical difference between: > > > > "Anything not expressly allowed is forbidden" > > > > and > > > > "Anything not expressly forbidden is allowed" ? > > > > - Hendrik > > The latter is how I interpret any religious

Re: C++ version of the C Python API?

2007-10-21 Thread Alex Martelli
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote: ... > The most popular ones are Boost.Python, CXX, and PySTL. I think SIP is also pretty popular (see ). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Alex Martelli
Debajit Adhikary <[EMAIL PROTECTED]> wrote: ... > How does "a.extend(b)" compare with "a += b" when it comes to > performance? Does a + b create a completely new list that it assigns > back to a? If so, a.extend(b) would seem to be faster. How could I > verify things like these? That's what the

Re: Best way to generate alternate toggling values in a loop?

2007-10-18 Thread Alex Martelli
Grant Edwards <[EMAIL PROTECTED]> wrote: ... > I like the solution somebody sent me via PM: > > def toggle(): > while 1: > yield "Even" > yield "Odd" I think the itertools-based solution is more elegant: toggle = itertools.cycle(('Even', 'Odd')) and use toggle rather than

Re: Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Alex Martelli
Andrew Durdin <[EMAIL PROTECTED]> wrote: > On 10/17/07, Thomas Wittek <[EMAIL PROTECTED]> wrote: > > > > Writing such constructors for all classes is very tedious. > > So I subclass them from this base class to avoid writing these constructors: > > > > class AutoInitAttributes(object): > >

Re: int to str in list elements..

2007-10-14 Thread Alex Martelli
Abandoned <[EMAIL PROTECTED]> wrote: > Hi.. > I have a list as a=[1, 2, 3 ] (4 million elements) > and > b=",".join(a) > than > TypeError: sequence item 0: expected string, int found > I want to change list to a=['1','2','3'] but i don't want to use FOR > because my list very very big. > I'm

Re: Python on imac

2007-10-14 Thread Alex Martelli
Raffaele Salmaso <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > I use Mac OSX 10.4 and this assertion seems unfounded -- I can't see any > > wx as part of the stock Python (2.3.5). Maybe you mean something else? > Very old version, see > /System/Lib

Re: Python on imac

2007-10-14 Thread Alex Martelli
James Stroud <[EMAIL PROTECTED]> wrote: ... > For OS X 10.4, wx has come as part of the stock python install. You may I use Mac OSX 10.4 and this assertion seems unfounded -- I can't see any wx as part of the stock Python (2.3.5). Maybe you mean something else? Alex -- http://mail.python.or

Re: The fundamental concept of continuations

2007-10-13 Thread Alex Martelli
Matthias Benkard <[EMAIL PROTECTED]> wrote: > continuations. There used to be a project called Stackless Python that > tried to add continuations to Python, but as far as I know, it has always > been separate from the official Python interpreter. I don't know whether > it's still alive. You may

Re: Problem of Readability of Python

2007-10-07 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 07 Oct 2007 13:24:14 -0700, Alex Martelli wrote: > > > And yes, you CAN save about 1/3 of those 85 nanoseconds by having > > '__slots__=["zop"]' in your class A(object)... but that's the

Re: Newbie packages Q

2007-10-07 Thread Alex Martelli
MarkyMarc <[EMAIL PROTECTED]> wrote: ... > > As long as '/python' comes in the list before any other directory that > > might interfere (by dint of having a Test.py or Test/__init__.py), and > > in particular in the non-pathological case where there are no such > > possible interferences, my ass

Re: Newbie packages Q

2007-10-07 Thread Alex Martelli
MarkyMarc <[EMAIL PROTECTED]> wrote: ... > > > > > And sys.path is /python/Test/bpack > > > > sys.path must be a LIST. Are you saying you set yours to NOT be a list, > > but, e.g., a STRING?! (It's hard to tell, as you show no quotes there). ... > > > I also tried to put /python/ and /pyth

Re: Problem of Readability of Python

2007-10-07 Thread Alex Martelli
Licheng Fang <[EMAIL PROTECTED]> wrote: ... > Python Tutorial says an empty class can be used to do this. But if > namespaces are implemented as dicts, wouldn't it incur much overhead > if one defines empty classes as such for some very frequently used > data structures of the program? Just mea

Re: Newbie packages Q

2007-10-07 Thread Alex Martelli
MarkyMarc <[EMAIL PROTECTED]> wrote: ... > > > And sys.path is /python/Test/bpack sys.path must be a LIST. Are you saying you set yours to NOT be a list, but, e.g., a STRING?! (It's hard to tell, as you show no quotes there). > > The 'Test' package is *not* in your sys.path. > > I can say

Re: weakrefs and bound methods

2007-10-07 Thread Alex Martelli
Mathias Panzenboeck <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch wrote: > > ``del b`` just deletes the name `b`. It does not delete the object. > > There's still the name `_` bound to it in the interactive interpreter. > > `_` stays bound to the last non-`None` result in the interpreter.

Re: weakrefs and bound methods

2007-10-07 Thread Alex Martelli
Mathias Panzenboeck <[EMAIL PROTECTED]> wrote: ... > I only inserted them so I can see if the objects are really freed. How can > I see that without a __del__ method? You can use weakref.ref instances with finalizer functions - see the long post I just made on this thread for a reasonably rich

Re: weakrefs and bound methods

2007-10-07 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: ... > Without __del__, what should I have done to test that my code was > deleting objects and not leaking memory? See module gc in the Python standard library. > What should I do when my objects need to perform some special processing > when they a

Re: Can you please give me some advice?

2007-09-30 Thread Alex Martelli
Byung-Hee HWANG <[EMAIL PROTECTED]> wrote: > Hi there, > > What is different between Ruby and Python? Not all that much; Python is more mature, Ruby more fashionable. I am wondering what language > is really mine for work. Somebody tell me Ruby is clean or Python is > really easy! Anyway I wil

Re: Python 3.0 migration plans?

2007-09-28 Thread Alex Martelli
John Nagle <[EMAIL PROTECTED]> wrote: > TheFlyingDutchman wrote: > > It seems that Python 3 is more significant for what it removes than > > what it adds. > > > > What are the additions that people find the most compelling? > > I'd rather see Python 2.5 finished, so it just works. And I'd r

Re: Google and Python

2007-09-24 Thread Alex Martelli
Bryan Olson <[EMAIL PROTECTED]> wrote: ... > > YouTube (one of Google's most valuable properties) is essentially > > all-Python (except for open-source infrastructure components such as > > lighttpd). Also, at Google I'm specifically "Uber Tech Lead, Production > > Systems": while I can't discu

Re: Google and Python

2007-09-20 Thread Alex Martelli
Bryan Olson <[EMAIL PROTECTED]> wrote: ... > TheFlyingDutchman asked of someone: > > Would you know what technique the custom web server uses > > to invoke a C++ app > > No, I expect he would not know that. I can tell you > that GWS is just for Google, and anyone else is almost > certainly bet

Re: Using pseudonyms

2007-09-18 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote: > For that matter, there are plenty of people who are better known by some > nickname that is not their legal name. Yep. For example, some people whose legal name is "Alessandro" (which no American is ever going to be able to spell right -- ONE L, TWO S's, NOT an

Re: super() doesn't get superclass

2007-09-17 Thread Alex Martelli
Ben Finney <[EMAIL PROTECTED]> wrote: > Am I mistaken in thinking that "superclass of foo" is equivalent to > "parent class of foo"? If so, I'd lay heavy odds that I'm not alone in > that thinking. "That thinking" (confusing "parent" with "ancestor") makes sense only (if at all) in a single-inher

Re: can Python be useful as functional?

2007-09-17 Thread Alex Martelli
Rustom Mody <[EMAIL PROTECTED]> wrote: > Can someone help? Heres the non-working code > > def si(l): > p = l.next() > yield p > (x for x in si(l) if x % p != 0) > > There should be an yield or return somewhere but cant figure it out Change last line to for x in (x for x in si(l

Re: how to join array of integers?

2007-09-16 Thread Alex Martelli
Paul Rudin <[EMAIL PROTECTED]> wrote: ... > Isn't it odd that the generator isn't faster, since the comprehension > presumably builds a list first and then iterates over it, whereas the > generator doesn't need to make a list? The generator doesn't, but the implementation of join then does (alm

Re: Just bought Python in a Nutshell

2007-09-15 Thread Alex Martelli
7stud <[EMAIL PROTECTED]> wrote: > Used copies of computer books for out of date editions are always > cheap. "Python in a Nutshell (2nd ed)" is a reference book with a > frustratingly poor index--go figure. It also contains errors not > posted in the errata. You can always enter errata at

Re: "once" assigment in Python

2007-09-14 Thread Alex Martelli
Lorenzo Di Gregorio <[EMAIL PROTECTED]> wrote: > When employing Python it's pretty straightforward to translate the > instance to an object. > > instance = Component(input=wire1,output=wire2) > > Then you don't use "instance" *almost* anymore: it's an object which > gets registered with the simu

Re: Python 3K or Python 2.9?

2007-09-13 Thread Alex Martelli
TheFlyingDutchman <[EMAIL PROTECTED]> wrote: > > >>> Foo.bar(foo, "spam") > > >>> foo.bar("spam") > > That looks like a case of "There's more than one way to do it". ;) > The first form is definitely consistent with the > method declaration, so there's a lot to be said for using that styl

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

2007-09-12 Thread Alex Martelli
Carl Banks <[EMAIL PROTECTED]> wrote: ... > How about this? The decorator could generate a bytecode wrapper that > would have the following behavior, where __setlocal__ and > __execute_function__ are special forms that are not possible in > Python. (The loops would necessarily be unwrapped in

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

2007-09-12 Thread Alex Martelli
Chris Mellon <[EMAIL PROTECTED]> wrote: ... > This is terrible and horrible, please don't use it. That said, > presenting the magic implicit_self context manager! ...which doesn't work in functions -- just try changing your global code: > with implicit_self(t): > print a >

Re: Python 3K or Python 2.9?

2007-09-12 Thread Alex Martelli
Chris Mellon <[EMAIL PROTECTED]> wrote: ... > > Actually you could do the "magic first-parameter insertion" just when > > returning a bound or unbound method object in the function's __get__ > > special method, and that would cover all of the technical issues you ... > This would mean that mi

Re: Python 3K or Python 2.9?

2007-09-12 Thread Alex Martelli
Duncan Booth <[EMAIL PROTECTED]> wrote: ... > As for omitting 'self' from method definitions, at first site you might > think the compiler could just decide that any 'def' directly inside a > class could silently insert 'self' as an additional argument. This > doesn't work though because not ev

Re: concise code (beginner)

2007-09-09 Thread Alex Martelli
bambam <[EMAIL PROTECTED]> wrote: > > O(n) to find the element you wish to remove and move over > > everything after it, > > Is that how lists are stored in cPython? It seems unlikely? So-called "lists" in Python are stored contiguously in memory (more like "vectors" in some other languages), so

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-09 Thread Alex Martelli
Stefan Arentz <[EMAIL PROTECTED]> wrote: > Miki <[EMAIL PROTECTED]> writes: > > > > steps.sort(key = lambda s: s.time) > > This is why attrgetter in the operator module was invented. > > from operator import attrgetter > > ... > > steps.sort(key=attrgettr("time")) > > Personally I prefer the a

Re: unexpected behavior: did i create a pointer?

2007-09-09 Thread Alex Martelli
Arnaud Delobelle <[EMAIL PROTECTED]> wrote: ... > > >>> def lower_list(L): > > > > ... for i, x in enumerate(L): > > ... L[i] = x.lower() > > ...>>> s = ['STRING'] > > >>> lower_list(s) > > >>> print s == ['string'] > > True > > > > >>> def lower_string(s): > > > > ... s = s.lowe

Re: Class design (information hiding)

2007-09-08 Thread Alex Martelli
Gregor Horvath <[EMAIL PROTECTED]> wrote: > Alexander Eisenhuth schrieb: > > > > I'm wodering how the information hiding in python is ment. As I > > understand there doesn't exist public / protected / private mechanism, > > but a '_' and '__' naming convention. > > > > As I figured out there

Re: Sort of an odd way to debug...

2007-09-04 Thread Alex Martelli
xkenneth <[EMAIL PROTECTED]> wrote: ... > What I'd like to do, is define a base class. This base class would > have a function, that gets called every time another function is > called (regardless of whether in the base class or a derived class), > and prints the doc string of each function when

Re: list index()

2007-09-04 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: > It's probable that a simpler implementation using slice > operations will be faster for shortish lengths of subseq. It was > certainly easier to get it working correctly. ;) > > def find(seq, subseq): > for i, j in itertools.izip(xrange(len(seq)-len(sub

Re: Can you use -getattr- to get a function in the current module?

2007-09-03 Thread Alex Martelli
Sergio Correia <[EMAIL PROTECTED]> wrote: > This works: > > # Module spam.py > > import eggs > > print getattr(eggs, 'omelet')(100) > > That is, I just call the function omelet inside the module eggs and > evaulate it with the argument 100. > > But what if the function 'omelet' is in the modu

Re: Adding attributes stored in a list to a class dynamically.

2007-09-02 Thread Alex Martelli
Nathan Harmston <[EMAIL PROTECTED]> wrote: > Hi, > > Sorry if the subject line of post is wrong, but I think that is what > this is called. I want to create objects with > > class Coconuts(object): > def __init__(self, a, b, *args, **kwargs): > self.a = a > self.b = b > > def sp

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Alex Martelli
Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Sep 2, 12:55 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > > Mark Dickinson <[EMAIL PROTECTED]> wrote: > > > Well, for one thing, you're creating half a million xrange objects in > > > the course of th

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Alex Martelli
Paul Rubin <http://[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] (Alex Martelli) writes: > > ...which suggests that creating an xrange object is _cheaper_ than > > indexing a list... > > Why not re-use the xrange instead of keeping a list around? > > Python

Re: Google spreadsheets

2007-09-02 Thread Alex Martelli
iapain <[EMAIL PROTECTED]> wrote: > On Aug 31, 5:40 pm, Michele Simionato <[EMAIL PROTECTED]> > wrote: > > I would like to upload a tab-separated file to a Google spreadsheet > > from Python. Does anybody > > have a recipe handy? TIA, > > > > Michele Simionato > > Probably its irrelevant to p

Re: code check for modifying sequence while iterating over it?

2007-09-02 Thread Alex Martelli
Neal Becker <[EMAIL PROTECTED]> wrote: > After just getting bitten by this error, I wonder if any pylint, pychecker > variant can detect this error? I know pychecker can't (and I doubt pylint can, but I can't download the latest version to check as logilab's website is temporarily down for mainte

Re: localizing a sort

2007-09-02 Thread Alex Martelli
Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Peter Otten wrote: ... > > print ''.join(sorted(a, cmp=lambda x,y: locale.strcoll(x,y))) > >> aeiouàáäèéëìíïòóöùúü > > > > The lambda is superfluous. Just write cmp=locale.strcoll instead. > > No it is not : > >>> print ''.join(sorted(a, cmp=local

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Alex Martelli
Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Sep 2, 9:45 am, [EMAIL PROTECTED] wrote: > > [snip code] > > > > Thanks for that. I realise that improving the algorithm will speed > > things up. I wanted to know why my less than perfect algorithm was so > > much slower in python than exactly the sa

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

2007-09-01 Thread Alex Martelli
Ricardo Aráoz <[EMAIL PROTECTED]> wrote: ... > >> We should remember that the level > >> of security of a 'System' is the same as the level of security of it's > >> weakest component, ... > You win the argument, and thanks you prove my point. You typically > concerned yourself with the techni

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

2007-09-01 Thread Alex Martelli
Russ <[EMAIL PROTECTED]> wrote: ... > > > the inputs. To test the > > > post-conditions, you just need a call at the bottom of the function, > > > just before the return, ... > > there's nothing to stop you putting the calls before every return. > > Oops! I didn't think of that. The idea of

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

2007-09-01 Thread Alex Martelli
Ricardo Aráoz <[EMAIL PROTECTED]> wrote: ... > We should remember that the level > of security of a 'System' is the same as the level of security of it's > weakest component, Not true (not even for security, much less for reliability which is what's being discussed here). It's easy to see how

Re: list index()

2007-09-01 Thread Alex Martelli
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Sat, 01 Sep 2007 13:44:28 -0600, Michael L Torrie wrote: > > > Alex Martelli wrote: > > > >> is the "one obvious way to do it" (the set(...) is just a simple and > >> powerf

Re: list index()

2007-08-31 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > Why wouldn't "the one obvious way" be: > > def inAnotB(A, B): > inA = set(os.listdir(A)) > inBs = set(os.listdir(B)) > return inA.difference(inBs) If you want a set as the result, that's one possibility (although possibly a bi

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

2007-08-31 Thread Alex Martelli
Michele Simionato <[EMAIL PROTECTED]> wrote: ... > I would not call that an attack. If you want to see an attack, wait > for > Alex replying to you observations about the low quality of code at > Google! ;) I'm not going to deny that Google Groups has glitches, particularly in its user interfac

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

2007-08-31 Thread Alex Martelli
Paul Rubin wrote: ... > Hi Alex, I'm a little confused: does Production Systems mean stuff > like the Google search engine, which (as you described further up in > your message) achieves its reliability at least partly by massive > redundancy and failover when somethin

Re: list index()

2007-08-30 Thread Alex Martelli
Ricardo Aráoz <[EMAIL PROTECTED]> wrote: ... > Alex Martelli wrote: > > <[EMAIL PROTECTED]> wrote: > >... > >> In my case of have done os.listdir() on two directories. I want to see > >> what files are in directory A that are not in directory

Re: list index()

2007-08-30 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: ... > In my case of have done os.listdir() on two directories. I want to see > what files are in directory A that are not in directory B. So why would you care about WHERE, in the listdir of B, are to be found the files that are in A but not B?! You should call .inde

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

2007-08-30 Thread Alex Martelli
Russ <[EMAIL PROTECTED]> wrote: ... > programs." Any idea how much Python is used for flight control systems > in commercial > transport aircraft or jet fighters? Are there differences in reliability requirements between the parts of such control systems that run on aircraft themselves, and tho

Re: What's the difference ?

2007-08-29 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: ... > Weird. Hetland's book, "Beginning Python" states that it's a matter of > taste. If your taste is for more verbose AND slower notation without any compensating advantage, sure. > Martelli's "Python Cookbook 2nd Ed." says to use the get() > method instead as you

Re: What's the difference ?

2007-08-29 Thread Alex Martelli
Alex <[EMAIL PROTECTED]> wrote: > Hye, > > I was just wondering what is the difference between > > >> if my_key in mydict: > >> ... > > and > > >> if mydict.has_keys(my_key): Mis-spelled (no final s in the method name). > >> ... > > I've search a bit in the python documentation, and

Re: How to replace a method in an instance.

2007-08-27 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > >>> Of course, a function in a > >>> class is also know as a method. > >> Less obvious but still wrong !-) > > > > I wish the authors of the Python books would get a clue then. > > I'd think that at least some authors of some Python books would ex

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Alex Martelli
rfv-370 <[EMAIL PROTECTED]> wrote: > have made the following small test: > > Before starting my test my UsedPhysicalMemory(PF): 555Mb > > >>>tf=range(0,1000)PF: 710Mb ( so 155Mb for my List) > >>>tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is > >>>not freed?) del

Re: ANN: SCF released GPL

2007-08-26 Thread Alex Martelli
hg <[EMAIL PROTECTED]> wrote: ... > I am looking for a free subversion server resource to put the code ... > if you know of any. Check out code.google.com -- it has a hosting service for open source code, too, these days (and it IS subversion). Alex -- http://mail.python.org/mailman/listinfo

Re: beginner, idiomatic python

2007-08-26 Thread Alex Martelli
bambam <[EMAIL PROTECTED]> wrote: ... > Bags don't seem to be built in to my copy of Python, and A "bag" is a collections.defaultdict(int) [[you do have to import collections -- it's in the standard library, NOT built-in]]. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: beginner, idiomatic python

2007-08-26 Thread Alex Martelli
bambam <[EMAIL PROTECTED]> wrote: > Is it safe to write > > A = [x for x in A if x in U] > > or is that undefined? I understand that the slice operation It's perfectly safe and well-defined, as the assignment rebinds the LHS name only AFTER the RHS list comprehension is done. Alex -- http://

Re: Need a better understanding on how MRO works?

2007-08-26 Thread Alex Martelli
Steven W. Orr <[EMAIL PROTECTED]> wrote: ... > =>accepts whatever dictionary you give it (so you can, though shouldn't, > =>do strange things such as pass globals()...:-). > > In fact, I wanted to make a common routine that could be called from > multiple modules. I have classes that need to b

Re: Does shuffle() produce uniform result ?

2007-08-25 Thread Alex Martelli
tooru honda <[EMAIL PROTECTED]> wrote: ... > def rand2(): > while True: > randata = urandom(2*1024) > for i in xrange(0, 2*1024, 2): > yield int(hexlify(randata[i:i+2]),16)# integer > in [0,65535] another equivalent pos

Re: Need a better understanding on how MRO works?

2007-08-25 Thread Alex Martelli
Steven W. Orr <[EMAIL PROTECTED]> wrote: ... > Thanks Alex. I am humbled, though I was before I started. > I really don't have a lot of understanding of what you're saying so I'll > probably have to study this for about a year or so. > > * (I need to look up what dictproxy is.) I don't have any

Re: Need a better understanding on how MRO works?

2007-08-25 Thread Alex Martelli
Steven W. Orr <[EMAIL PROTECTED]> wrote: ... > name = 'C1' > nclass = new.classobj(name,(D1,),globals()) > globals()[name] = nclass Here, you're creating a VERY anomalous class C1 whose __dict__ is globals(), i.e. the dict of this module object; > name = 'C2' > nclass

Re: Does shuffle() produce uniform result ?

2007-08-25 Thread Alex Martelli
tooru honda <[EMAIL PROTECTED]> wrote: > At the end, I think it is worthwhile to implement my own shuffle and > random methods based on os.urandom. Not only does the resulting code > gets rid of the minuscule bias, but the program also runs much faster. > > When using random.SystemRandom.shuffl

Re: yet another indentation proposal

2007-08-20 Thread Alex Martelli
Michael Tobis <[EMAIL PROTECTED]> wrote: > On Aug 19, 11:51 pm, James Stroud <[EMAIL PROTECTED]> wrote: > > > What's wrong with just saying the current indent level? I'd much rather > > hear "indent 4" than "tab tab tab tab". > > Alternatively, you might also consider writing a simple pre and >

Re: yet another indentation proposal

2007-08-20 Thread Alex Martelli
Aaron <[EMAIL PROTECTED]> wrote: ... > That's probably what I'll end up doing. The only drawback to that is that > it solves the problem for me only. Perhaps I will open source the scripts > and write up some documentation so that other folks in a similar situation > don't have to reinvent the

Re: yet another indentation proposal

2007-08-20 Thread Alex Martelli
Jakub Stolarski <[EMAIL PROTECTED]> wrote: > Why not just use comments and some filter. Just write # _{ at the > beginning and # _} at the end. Then filter just before runing > indenting with those control sequences? Then there's no need to change > interpreter. As I pointed out in another post t

Re: Parser Generator?

2007-08-19 Thread Alex Martelli
Jack <[EMAIL PROTECTED]> wrote: > Thanks for the suggestion. I understand that more work is needed for natural > language > understanding. What I want to do is actually very simple - I pre-screen the > user > typed text. If it's a simple syntax my code understands, like, Weather in > London, I'll

Re: Sorting a list of Unicode strings?

2007-08-19 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > > > Maybe I'm missing something fundamental here, but if I have a list of > > > Unicode strings, and I want to sort these alphabetically, then it > > > places those that begin with unicode characters at the bottom. ... > Anyway, I know _why_

Re: yet another indentation proposal

2007-08-19 Thread Alex Martelli
Paddy <[EMAIL PROTECTED]> wrote: ... > Can screen reaaderss be customized? Open-source ones surely can (e.g., NVDA is an open-source reader for Windows written in Python, -- alas, if you search for NVDA Google appears to be totally convinced you mean NVidia instea

Re: clarification

2007-08-19 Thread Alex Martelli
samwyse <[EMAIL PROTECTED]> wrote: ... > > brain:~ alex$ python -mtimeit -s'sos=[set(range(x,x+4)) for x in > > range(0, 100, 3)]' 'r=set()' 'for x in sos: r.update(x)' > > 10 loops, best of 3: 18.8 usec per loop > > > > brain:~ alex$ python -mtimeit -s'sos=[set(range(x,x+4)) for x in > > r

Re: How to call module functions inside class instance functions?

2007-08-18 Thread Alex Martelli
beginner <[EMAIL PROTECTED]> wrote: ... > testmodule.py > - > """Test Module""" > > def __module_level_func(): > print "Hello" > > class TestClass: > def class_level_func(self): > __module_level_func() > > > main.py > -- > import testmodule >

Re: Understanding closures

2007-08-18 Thread Alex Martelli
Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I want to use variables passed to a function in an inner defined > function. Something like- > > def fun1(method=None): > def fun2(): > if not method: method = 'GET' > print '%s: this is fun2' % method > return >

Re: clarification

2007-08-18 Thread Alex Martelli
samwyse <[EMAIL PROTECTED]> wrote: ... > Finally, does anyone familar with P3K know how best to do the reduction > without using 'reduce'? Right now, sets don't support the 'add' and > 'multiply' operators, so 'sum' and (the currently ficticious) 'product' > won't work at all; while 'any' and

Re: Can python threads take advantage of use dual core ?

2007-08-17 Thread Alex Martelli
Stefan Behnel <[EMAIL PROTECTED]> wrote: ... > Which virtually all computation-intensive extensions do. Also, note the gmpy doesn't (release the GIL), even though it IS computationally intensive -- I tried, but it slows things down horribly even on an Intel Core Duo. I suspect that may partly

Re: using super() to call two parent classes __init__() method

2007-08-16 Thread Alex Martelli
7stud <[EMAIL PROTECTED]> wrote: > When I run the following code and call super() in the Base class's > __init__ () method, only one Parent's __init__() method is called. > > > class Parent1(object): > def __init__(self): > print "Parent1 init called." > self.x = 10 > > cla

Re: Opinions about this new Python book?

2007-08-15 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-08-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > For some reason, the author makes the claim that the term > > "Predicate" is "bandied about quite a bit in the literature" of > > Python. I have 17 or so Python books and I don't think I've >

Re: closing StringIO objects

2007-08-15 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: > The documentation says the following about StringIO.close: > > close( ) > Free the memory buffer. > > Or else... what? Or else the memory buffer sticks around, so you can keep calling getvalue as needed. I believe the freeing will happen anyway,

Re: Help with optimisation

2007-08-13 Thread Alex Martelli
special_dragonfly <[EMAIL PROTECTED]> wrote: ... > dom=xml.dom.minidom.parseString(text_buffer) If you need to optimize code that parses XML, use ElementTree (some other parsers are also fast, but minidom ISN'T). Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Something in the function tutorial confused me.

2007-08-13 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: ... > > Then we get into unpacking assignments and augmented > > assignments, but I don't really want to write two more pages > > worth of summary...;-). > > Thanks very much for taking the time to help clear up my > erroneous model of assignment in Pytho

Re: LRU cache?

2007-08-11 Thread Alex Martelli
Paul Rubin wrote: > Anyone got a favorite LRU cache implementation? I see a few in google > but none look all that good. I just want a dictionary indexed by > strings, that remembers the last few thousand entries I put in it. So what's wrong with Evan Prodromou's lruc

Re: Something in the function tutorial confused me.

2007-08-11 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: ... > OK, I've thought about this some more and I think the source of > my confusion was I thought assignment in Python meant binding a > name to something, not mutating an object. But in the case of > augmented assignment, assignment no longer means that?

Re: Destruction of generator objects

2007-08-10 Thread Alex Martelli
Stefan Bellon <[EMAIL PROTECTED]> wrote: > On Thu, 09 Aug, Graham Dumpleton wrote: > > > result = application(environ, start_response) > > try: > > for data in result: > > if data:# don't send headers until body appears > > write(data) > > i

Re: Something in the function tutorial confused me.

2007-08-10 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote: ... > The Python Language Reference seems a little confused about the > terminology. > > 3.4.7 Emulating numeric types > 6.3.1 Augmented assignment statements > > The former refers to "augmented arithmetic operations", which I > think is a nice termi

Re: Something in the function tutorial confused me.

2007-08-10 Thread Alex Martelli
greg <[EMAIL PROTECTED]> wrote: > Steve Holden wrote: > > > For some reason your reply got right up my nose, > > I'm sorry about that. Sometimes it's hard to judge the > level of experience with Python that a poster has. In Because of this, a Google search for " " python may sometimes help;

Re: Help with Dictionaries and Classes requested please.

2007-08-10 Thread Alex Martelli
Sion Arrowsmith <[EMAIL PROTECTED]> wrote: > special_dragonfly <[EMAIL PROTECTED]> wrote: > >if key in FieldsDictionary: > >FieldsDictionary[key].append(FieldClass(*line.split(","))) > >else: > >FieldsDictionary[key]=[FieldClass(*line.split(","))] > > These

Re: Ipc mechanisms and designs.

2007-08-10 Thread Alex Martelli
king kikapu <[EMAIL PROTECTED]> wrote: > Hi, > > inspired of the topic "The Future of Python Threading", i started to > realize that the only way to utilize the power of multiple cores using > Python, is spawn processes and "communicate" with them. > > If we have the scenario: > > 1. Windows (m

Re: boolean operations on sets

2007-08-06 Thread Alex Martelli
Michael J. Fromberger <[EMAIL PROTECTED]> wrote: ... > Also, it is a common behaviour in many programming languages for logical > connectives to both short-circuit and yield their values, so I'd argue > that most programmers are proabably accustomed to it. The && and || > operators of C and it

Re: Formatting Results so that They Can be Nicely Imported into a Spreadsheet.

2007-08-05 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > Even with the "if i" included, we end up with an > empty list at the start. This because the first "blank" > line wasn't blank, it was a space, so it passes the > "if i" test. ...and you can fix that by changing the test to [... if i.split()].

Re: Efficient Rank Ordering of Nested Lists

2007-08-04 Thread Alex Martelli
Cousin Stanley <[EMAIL PROTECTED]> wrote: ... > for i , item in reversed( enumerate( sorted( single_list ) ) ) : ... > TypeError: argument to reversed() must be a sequence Oops, right. Well then, aux_seq = list(enumerate(sorted(single_list))) for i, item in reversed(aux_seq):

Re: Efficient Rank Ordering of Nested Lists

2007-08-03 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > A naive approach to rank ordering (handling ties as well) of nested > lists may be accomplished via: > >def rankLists(nestedList): > def rankList(singleList): > sortedList = list(singleList) > sortedList.sort() >

Re: Pythonic way for missing dict keys

2007-08-02 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Alex Popescu a écrit : > > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in > > news:[EMAIL PROTECTED]: > (snip) > >> if hasattr(obj, '__call__'): > >># it's a callable > >> > >> but I don't find it so Pythonic to have to check for a __magic__

Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Martelli
Alex Popescu <[EMAIL PROTECTED]> wrote: ... > Have you seen/heard of Jim lately? Cause I haven't. By the time he was > the lead of the AspectJ team his charismatic presence was everywhere (at > least around that project). He wasn't at OSCON this year, but I hope to see him at Pycon next year. I

Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Martelli
NicolasG <[EMAIL PROTECTED]> wrote: > > Open source projects do not require previous professional experience to > > accept volunteers. So, one way out of your dilemma is to make a name > > for yourself as an open source contributor -- help out with Python > > itself and/or with any of the many op

Re: Floats as keys in dict

2007-08-01 Thread Alex Martelli
Brian Elmegaard <[EMAIL PROTECTED]> wrote: > I am making a script to optimiza by dynamic programming. I do not know > the vertices and nodes before the calculation, so I have decided to > store the nodes I have in play as keys in a dict. > > However, the dict keys are then floats and I have to ro

Re: Where do they tech Python officialy ?

2007-08-01 Thread Alex Martelli
Alex Popescu <[EMAIL PROTECTED]> wrote: ... > > and you will both learn a lot _and_ acquire "professional experience" > > that any enlightened employer will recognize as such. > > It depends :-). In my experience I met employers being concerned by my > implication in the oss world :-). Consi

  1   2   3   4   5   6   7   8   9   10   >