gmpy moving to code.google.com

2007-02-26 Thread Alex Martelli
If you're interested in gmpy (the Python wrapper of GMP, for unlimited-precision arithmetic, rationals, random number generation, number-theoretical functions, etc), please DO check out http://code.google.com/p/gmpy/ -- gmpy 1.02 is there (as far as I can tell) in a workable state. Source on

Re: reference or pointer to some object?

2005-01-13 Thread Alex Martelli
Jeff Shannon [EMAIL PROTECTED] wrote: Because Python uses a fundamentally different concept for variable names than C/C++/Java (and most other static languages). In those languages, variables can be passed by value or by reference; neither term really applies in Python. (Or, if you

Re: hash patent by AltNet; Python is prior art?

2005-01-15 Thread Alex Martelli
GerritM [EMAIL PROTECTED] wrote: How can this type of fundamental knowledge be patented? I am afraid this is again an example of a total failure of the current patent system. As a European citizen, you have a chance to make a difference to software patentability in Europe -- think globally,

Re: pickling extension class

2005-01-18 Thread Alex Martelli
harold fellermann [EMAIL PROTECTED] wrote: File /sw/lib/python2.4/pickle.py, line 760, in save_global raise PicklingError( pickle.PicklingError: Can't pickle type 'hyper.PeriodicGrid': it's not found as hyper.PeriodicGrid dir(hyper) ['Dir', 'Neighbors', 'PeriodicGrid',

Re: pickling extension class

2005-01-18 Thread Alex Martelli
harold fellermann [EMAIL PROTECTED] wrote: ... Here it goes...: OOPS, error (exceptions.ImportError): No module named hyper So, the __import__ in pickle fails -- indeed, __import__('foo') when 'foo' ``is imported from a subpackage'' is _supposed_ to fail, as 'hyper' is not the name you

Re: what would you like to see in a 2nd edition Nutshell?

2005-01-18 Thread Alex Martelli
kery [EMAIL PROTECTED] wrote: ... Any schedule for publication of 2nd Ed? I just bought 1st Ed. The 2nd edition Python Cookbook appears to be on-track for PyCon (late March) for the very first ink-on-paper -- probably April in bookstores. The 2nd edition Python in a Nutshell is more

Re: what would you like to see in a 2nd edition Nutshell?

2005-01-18 Thread Alex Martelli
Steven Chan [EMAIL PROTECTED] wrote: I completely agree. I'm also waiting for an advanced Python/project management book that helps folks out with large-scale projects. I won't schedule that project until the Nutshell 2nd ed is substantially done... and I'm not _promising_ I'll schedule it

Re: Contributor's List

2005-01-18 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... Is this mean't to only cover additional entries which were added in the 2nd edition, or is it also mean't to encompass entries which were carried over from the 1st edition as well. The latter: it covers all entries. If it is both, then the editing must have

Re: Zen of Python

2005-01-21 Thread Alex Martelli
Timothy Fitz [EMAIL PROTECTED] wrote: ... Perhaps Tim Peters is far too concise for my feeble mind wink It's Zen, it's beyond Mind. Let it speak to your True Self! Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Configuring Python for Tk on Mac

2005-01-21 Thread Alex Martelli
Craig Ringer [EMAIL PROTECTED] wrote: ... I've just checked the OSX 10.3 machine here, and it fails to import tkinter there too. I'd say Apple just don't build Python with Tk support. No idea about any 10.2, sorry, but on 10.3 that's not the problem: Tk support is there alright, it's Tcl/Tk

Re: Unbinding multiple variables

2005-01-21 Thread Alex Martelli
Johnny Lin [EMAIL PROTECTED] wrote: ... my understanding about locals() from the nutshell book was that i should treat that dictionary as read-only. is it safe to use it to delete entries? Speaking as the Nutshell author: it's safe, it just doesn't DO anything. I _hoped_ locals() would

Re: default value in a list

2005-01-22 Thread Alex Martelli
TB [EMAIL PROTECTED] wrote: Is there an elegant way to assign to a list from a list of unknown size? For example, how could you do something like: a, b, c = (line.split(':')) if line could have less than three fields? import itertools as it a, b, c = it.islice( it.chain(

Re: Zen of Python

2005-01-22 Thread Alex Martelli
Dave Benjamin [EMAIL PROTECTED] wrote: Can we get a show of hands for all of those who have written or are currently maintaining code that uses the leaky listcomp feature? Have written: guilty -- basically to show how NOT to do things. Currently maintaining: you _gotta_ be kidding!-) I

Re: list unpack trick?

2005-01-22 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: ... or (readable): if len(list) n: list.extend((n - len(list)) * [item]) I find it just as readable without the redundant if guard -- just: alist.extend((n - len(alist)) * [item]) of course, this guard-less version depends on N*[x]

Re: Reload Tricks

2005-01-22 Thread Alex Martelli
Kamilche [EMAIL PROTECTED] wrote: I want my program to be able to reload its code dynamically. I have a large hierarchy of objects in memory. The inheritance hierarchy of these objects are scattered over several files. Michael Hudson has a nice custom metaclass for that in Activestate's

Re: need help on need help on generator...

2005-01-22 Thread Alex Martelli
Francis Girard [EMAIL PROTECTED] wrote: ... But besides the fact that generators are either produced with the new yield reserved word or by defining the __new__ method in a class definition, I don't know much about them. Having __new__ in a class definition has nothing much to do with

Re: need help on need help on generator...

2005-01-22 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: 5. Several builtin functions return iterators rather than lists, specifically xrange(), enumerate() and reversed(). Other builtins that yield sequences (range(), sorted(), zip()) return lists. Yes for enumerate and reversed, no for xrange: xx=xrange(7)

Re: finding name of instances created

2005-01-22 Thread Alex Martelli
André Roberge [EMAIL PROTECTED] wrote: alex = CreateRobot() anna = CreateRobot() alex.move() anna.move() H -- while I've long since been identified as a 'bot, I can assure you that my wife Anna isn't! Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: need help on need help on generator...

2005-01-22 Thread Alex Martelli
Francis Girard [EMAIL PROTECTED] wrote: ... A 'def' of a function whose body uses 'yield', and in 2.4 the new genexp construct. Ok. I guess I'll have to update to version 2.4 (from 2.3) to follow the discussion. It's worth upgrading even just for the extra speed;-). Since you

Re: list unpack trick?

2005-01-22 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: Alex Martelli wrote: or (readable): if len(list) n: list.extend((n - len(list)) * [item]) I find it just as readable without the redundant if guard -- just: alist.extend((n - len(alist)) * [item]) the guard makes

Re: need help on need help on generator...

2005-01-22 Thread Alex Martelli
Craig Ringer [EMAIL PROTECTED] wrote: . data = ''.join(x for x in infile) Maybe ''.join(infile) is a better way to express this functionality? Avoids 2.4 dependency and should be faster as well as more concise. Might it be worth providing a way to have file objects seek back to the current

Re: Class introspection and dynamically determining function arguments

2005-01-22 Thread Alex Martelli
Diez B. Roggisch [EMAIL PROTECTED] wrote: Nick Coghlan wrote: If this only has to work for classes created for the purpose (rather than for an arbitrary class): Certainly a step into the direction I meant - but still missing type declarations. And that's what at least I'd like to see

Re: default value in a list

2005-01-22 Thread Alex Martelli
Nick Craig-Wood [EMAIL PROTECTED] wrote: ... Or this version if you want something other than as the default a, b, b = (line.split(':') + 3*[None])[:3] Either you mean a, b, c -- or you're being subtler than I'm grasping. BTW This is a feature I miss from perl... Hmmm, I understand

Re: circular iteration

2005-01-22 Thread Alex Martelli
Simon Brunning [EMAIL PROTECTED] wrote: ... is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] I don''t know if it's faster, but: import itertools

Re: Zen of Python

2005-01-22 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: If it changed the semantics of for-loops in general, that would be quite inconvenient to me -- once in a while I do rely on Python's semantics (maintaining the loop control variable after a break; I don't

Re: Zen of Python

2005-01-22 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: Dave Benjamin [EMAIL PROTECTED] writes: Can we get a show of hands for all of those who have written or are currently maintaining code that uses the leaky listcomp feature? It's really irrelevant whether anyone is using a feature or not. If the

Re: What YAML engine do you use?

2005-01-22 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... lists. I think it would be great if the Python library exposed an interface for parsing constant list and dict expressions, e.g.: [1, 2, 'Joe Smith', 8237972883334L, # comment {'Favorite fruits': ['apple', 'banana', 'pear']}, #

Re: debugging process

2005-01-22 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... I think that this must have something to do with python expecting itself to by in a TTY? Can anyone give any idea of where I should be going with this? http://pexpect.sourceforge.net/ Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Reload Tricks

2005-01-23 Thread Alex Martelli
Kamilche [EMAIL PROTECTED] wrote: Well, I look forward to seeing the new version. I have the old version of the Python cookbook, it was very useful! I hope the new one is even better -- many more recipes, all updated to Python 2.3 and 2.4. The old one will remain useful for all those who need

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Alex Martelli
Mike C. Fletcher [EMAIL PROTECTED] wrote: weakref.ref( self, self.close ) but the self.close reference in the instance is going away *before* the object is called. Uh -- what's holding on to this weakref.ref instance? I guess the weakreference _itself_ is going away right after

Re: best way to do a series of regexp checks with groups

2005-01-24 Thread Alex Martelli
Nick Craig-Wood [EMAIL PROTECTED] wrote: Here is a different solution... class Result: def set(self, value): self.value = value return value m = Result() if m.set(re.search(r'add (\d+) (\d+)', line)): do_add(m.value.group(1), m.value.group(2)) elif

Re: compile python to binary

2005-01-24 Thread Alex Martelli
Doug Holton [EMAIL PROTECTED] wrote: ... oh, you mean that python compiler didn't mean the python compiler. I wouldn't assume a novice uses terms the same way you would. It was quite clear from his message that py2exe and the like were what he was referring to, if you had read his first

Re: best way to do a series of regexp checks with groups

2005-01-24 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: I get a bit uneasy from the repeated calls to m.group... If I was going to build a class around the re, I think I might lean towards something like: class ReWithMemory(object): def search(self, are, aline): self.mo = re.search(are,

Re: python without OO

2005-01-26 Thread Alex Martelli
Davor [EMAIL PROTECTED] wrote: no one ever had to document structured patterns - which definitely exist - but seem to be obvious enough that there is no need to write a book about them... You _gotta_ be kidding -- what do you think, e.g., Wirth's Algorithms plus Data Structures Equals

Re: fast list lookup

2005-01-26 Thread Alex Martelli
Klaus Neuner [EMAIL PROTECTED] wrote: what is the fastest way to determine whether list l (with len(l)3) contains a certain element? if thecertainelement in l: is the fastest way unless there are properties of l which you're not telling us about, or unless what you need is not just to

Re: python without OO

2005-01-27 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... Some complexity is not needed, and I am sure even in Python something could be dropped. But it is difficult to find what can be removed. Remember that Saint-Exupery quote? Something like a work of art is finished when there is nothing left to remove?

Re: python without OO

2005-01-27 Thread Alex Martelli
PA [EMAIL PROTECTED] wrote: Yes. But even with the best tool and the best intents, projects still fail. In fact, most IT projects are considered failures: http://www.economist.com/business/PrinterFriendly.cfm?Story_ID=3423238 The main thesis of the article you quote (although it

Re: exclude binary files from os.walk

2005-01-27 Thread Alex Martelli
rbt [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2005-01-26, rbt [EMAIL PROTECTED] wrote: Is there an easy way to exclude binary files (I'm working on Windows XP) from the file list returned by os.walk()? Sure, assuming you can provide a rigorous definition of 'binary files'.

Re: exclude binary files from os.walk

2005-01-27 Thread Alex Martelli
Craig Ringer [EMAIL PROTECTED] wrote: That's not really safe when dealing with utf-8 files though, and IIRC with UCS2 or UCS4 as well. The Unicode BOM its self might (I'm not sure) qualify as ASCII. Nope, both bytes in the BOM have the high-order bit set -- they're 0xFF and 0xFE -- so they

Re: Please suggest on the book to follow

2005-01-27 Thread Alex Martelli
[EMAIL PROTECTED] wrote: santanu [EMAIL PROTECTED] writes: I know a little python (not the OOP part) learnt by studying the online tutorial. Now I would like to learn it more thoroughly. I think there's supposed to be a new version of Python in a Nutshell Just a 2nd edition. I'm just

Re: String Fomat Conversion

2005-01-27 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: ... Beware of mixing iterator methods and readline: _mixing_, yes. But -- starting the iteration after some other kind of reading (readline, or read(N), etc) -- is OK... http://docs.python.org/lib/bltin-file-objects.html next( )

Re: Question about 'None'

2005-01-28 Thread Alex Martelli
flamesrock [EMAIL PROTECTED] wrote: ... (The reason I ask is sortof unrelated. I wanted to use None as a variable for which any integer, including negative ones have a greater value so that I wouldn't need to implement any tests or initializations for a loop that finds the maximum of a

Re: limited python virtual machine

2005-01-28 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: ... If I could see how to go from 'object' (or 'int', 'str', 'file', etc.) to 'eval' or '__import__', that would help out a lot... object.__subclasses__() [type 'type', type 'weakref', type 'int', type 'basestring', type 'list', type 'NoneType', type

Re: limited python virtual machine

2005-01-29 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: Alex Martelli wrote: Steven Bethard [EMAIL PROTECTED] wrote: ... If I could see how to go from 'object' (or 'int', 'str', 'file', etc.) to 'eval' or '__import__', that would help out a lot... object.__subclasses__() ... Traipse through

Re: Pystone benchmark: Win vs. Linux (again)

2005-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: Franco Fiorese [EMAIL PROTECTED] writes: * Windows XP Pro: 16566.7 pystones/second * Linux (kernel 2.6.9 NPTL): 12346.2 pystones/second I have repeated the test, on Linux, also with other distributions and kernel but a relevant

Re: Dynamic class methods misunderstanding

2005-01-29 Thread Alex Martelli
Bill Mill [EMAIL PROTECTED] wrote: ... class Test: def __init__(self, method): self.m = new.instancemethod(method, self, Test) Beautiful! thank you very much. Looking into the new module in python 2.4, that's equivalent to: self.m = type(self.__init__)(method, self,

Re: limited python virtual machine

2005-01-29 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote: ... object.__subclasses__() ... One thing my company has done is written a ``safe_eval()`` that uses a regex to disable double-underscore access. will the regex catch getattr(object, 'subclasses'.join(['_'*2]*2)...?-) Alex --

Re: limited python virtual machine

2005-01-29 Thread Alex Martelli
Stephen Thorne [EMAIL PROTECTED] wrote: On Sat, 29 Jan 2005 08:53:45 -0600, Skip Montanaro [EMAIL PROTECTED] wrote: One thing my company has done is written a ``safe_eval()`` that uses a regex to disable double-underscore access. Alex will the regex catch

Re: limited python virtual machine

2005-01-29 Thread Alex Martelli
Skip Montanaro [EMAIL PROTECTED] wrote: Alex I dunno, maybe I'm just being pessimistic, I guess... No, I think you are being realistic. I thought one of the basic tenets of computer security was that which is not expressly allowed is forbidden. Any attempt at security that attempts to

Re: limited python virtual machine

2005-01-30 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: ... If you _can_ execute (whatever) in a separate process, then an approach based on BSD's jail or equivalent features of other OS's may be able to give you all you need, without needing other restrictions to be coded in the interpreter (or whatever

Re: Need programming tip

2005-01-30 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... 1511156 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (1/4) - 21/27 1511157 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (2/4) - 21/27 ... would be to look for (1/ in the subject string then find the denominator and loop

Re: Coding style article with interesting section on white space

2005-01-30 Thread Alex Martelli
[EMAIL PROTECTED] wrote: Michael Tobis wrote: (unwisely taking the bait...) If you like your language to look like this http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html then more power to you. Thanks for pointing out that interesting article on Fortran 90 bugs. How long would a

Re: Coding style article with interesting section on white space

2005-01-30 Thread Alex Martelli
[EMAIL PROTECTED] wrote: I had in mind the Polyhedron Fortran 90 benchmarks for Windows and Linux on Intel x86 at http://www.polyhedron.co.uk/compare/linux/f90bench_p4.html and http://www.polyhedron.co.uk/compare/win32/f90bench_p4.html . The speed differences of Absoft, Intel, and Lahey

Re: Dynamic class methods misunderstanding

2005-01-31 Thread Alex Martelli
Christos TZOTZIOY Georgiou [EMAIL PROTECTED] wrote: ... class Test: def __init__(self, method): self.m = new.instancemethod(method, self, Test) ... self.m = method.__get__(self, Test) Almost true; not all builtin functions are descriptors though. ...

Re: Nested scopes and class variables

2005-01-31 Thread Alex Martelli
Dave Benjamin [EMAIL PROTECTED] wrote: I ran into an odd little edge case while experimenting with functions that create classes on the fly (don't ask me why): Why not?. But classes have little to do with it, in my view. def f(x): ... class C(object): ... x = x You bind x,

Re: variable declaration

2005-01-31 Thread Alex Martelli
Alexander Zatvornitskiy [EMAIL PROTECTED] wrote: Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Since the lack of declarations is such a crucial design choice for Python,

Re: how do i create such a thing?

2005-01-31 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: Of if you only want to deal with the case where the attribute doesn't exist, you can use getattr, which gets called when the attribute can't be found anywhere else: py class DefaultAttr(object): ... def __init__(self, default): ...

Re: implicit conversion

2005-01-31 Thread Alex Martelli
Benjamin Schmeling [EMAIL PROTECTED] wrote: ... I don't know how to achieve implicit conversion at this point, turning an long automatically into an bigint. The other way round, turning an bigint into long can be realized by defining __long__. Perhaps adding to your bigint class a

Re: variable declaration

2005-01-31 Thread Alex Martelli
Robert Brewer [EMAIL PROTECTED] wrote: Bah. Nothing teaches you a new language like having your job depend upon it. People who study languages merely for personal growth learn 50% of the syntax and 1% of the concepts, and then fritter that learning away on inconsequential newsgroups the world

Re: variable declaration

2005-01-31 Thread Alex Martelli
Michael Tobis [EMAIL PROTECTED] wrote: With all due respect, I think so go away if you don't like it is excessive, and so go away if you don't like it and you obviously don't like it so definitely go away is more so. The writer is obviously I disagree: I believe that, if the poster really

Re: variable declaration

2005-02-01 Thread Alex Martelli
Michael Tobis [EMAIL PROTECTED] wrote: Alex Martelli wrote: Michael Tobis [EMAIL PROTECTED] wrote: he can perfectly well correct his misexpression if he cares to -- not my job to try to read his mind and perform exegesis on his words. Well, I hate to try to tell you your job

Re: how do i create such a thing?

2005-02-01 Thread Alex Martelli
Lowell Kirsh [EMAIL PROTECTED] wrote: What might these exceptions be? It's HIGHLY advisable to have your __getattr__ methods raise AttributeError for any requested name that starts and ends with double underscores, possibly with some specific and specifically designed exceptions. For

Re: variable declaration

2005-02-01 Thread Alex Martelli
Michael Tobis [EMAIL PROTECTED] wrote: ... I don't know that it's ever necessary to rebind, but it is, in fact, common, and perhaps too easy. In numeric Python, avoiding rebinding turns out to be a nontrivial skill. Well, a for-statement is BASED on rebinding, for example. Maybe you don't

Re: Next step after pychecker

2005-02-02 Thread Alex Martelli
Philippe Fremy [EMAIL PROTECTED] wrote: Any other idea of a fun python improvement project I could join without too much hassle ? I can't help but thinking that pychecker ought to be able to do a better job. Have a look at pypy -- around the key idea of reimplementing Python's runtime in

Re: How do you do arrays

2005-02-02 Thread Alex Martelli
Kartic [EMAIL PROTECTED] wrote: ... I am not sure what book you are using but I don't think it is a very good one. Hmmm, considering he said it's Python in a Nutshell, I disagree with you;-). If he had understood that he probably wanted to use lists, not arrays, the top paragraph on p. 47

Re: returning True, False or None

2005-02-04 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: I have lists containing values that are all either True, False or None, e.g.: [True, None, None, False] [None, False, False, None ] [False, True, True, True ] etc. For a given list: * If all values are None, the

Re: changing local namespace of a function

2005-02-05 Thread Alex Martelli
Bo Peng [EMAIL PROTECTED] wrote: ... Thank again for everyone's help. I have learned a lot from the posts, especially the wrapdict class. Hmmm, you do realize that wrapdict uses a lot of indirection while my equivalent approach, just posted, is very direct, right? To reiterate the latter,

Re: empty classes as c structs?

2005-02-05 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: ... Michael Spencer also posted an interesting idea recently about setting up a view of an existing dictionary, rather than as a separate object: class attr_view(object): def __init__(self, data): object.__setattr__(self, _data, data) def

a type without a __mro__?

2005-02-05 Thread Alex Martelli
Can anybody suggest where to find (within the standard library) or how to easily make (e.g. in a C extension) a type without a __mro__, except for those (such as types.InstanceType) which are explicitly recorded in the dispatch table copy._deepcopy_dispatch...? Weird request, I know, so let me

Re: changing local namespace of a function

2005-02-05 Thread Alex Martelli
Bo Peng [EMAIL PROTECTED] wrote: M.E.Farmer wrote: I really don't see your need. Maybe it is just my laziness. It is almost intolerable for me to write lines and lines of code like d['z'] = func(d['x']+d['y']+d['whatever']['as']+d[a][0] ) It is ugly, unreadable and error prone.

Re: returning True, False or None

2005-02-05 Thread Alex Martelli
Brian van den Broek [EMAIL PROTECTED] wrote: ... * If all values are None, the function should return None. * If at least one value is True, the function should return True. * Otherwise, the function should return False. ... for val in (x for x in lst if x is not None): return val

Re: variable declaration

2005-02-05 Thread Alex Martelli
Alexander Zatvornitskiy [EMAIL PROTECTED] wrote: Hi, Alex! 31 jan 2005 at 13:46, Alex Martelli wrote: (sorry for the delay,my mail client don't highlight me your answer) AM Since the lack of declarations is such a crucial design choice for AM Python, then, given that you're convinced

Re: a type without a __mro__?

2005-02-05 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: Alex Martelli wrote: Can anybody suggest where to find (within the standard library) or how to easily make (e.g. in a C extension) a type without a __mro__, except ^^ for those

Re: variable declaration

2005-02-05 Thread Alex Martelli
Alexander Zatvornitskiy [EMAIL PROTECTED] wrote: ... AM The fact that in Python there are ONLY statements, NO declarations, === def qq(): global z z=5 === What is global? Statement? Ok, I fill lack of var statement:) 'global' is an ugly wart, to all intents and purposes working as if

Re: variable declaration

2005-02-05 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: Alex Martelli wrote: 'global' is an ugly wart, to all intents and purposes working as if it was a declaration. If I had to vote about the one worst formal defect of Python, it would surely be 'global'. Fortunately, it's reasonably easy to avoid

Re: variable declaration

2005-02-05 Thread Alex Martelli
Arthur [EMAIL PROTECTED] wrote: On Sat, 5 Feb 2005 17:00:15 +0100, [EMAIL PROTECTED] (Alex Martelli) wrote: I consider this one of the worst ideas to have been proposed on this newsgroup over the years, which _IS_ saying something. \ I would disagree, but only to the extent that nothing

Re: Alternative to standard C for

2005-02-05 Thread Alex Martelli
Georg Brandl [EMAIL PROTECTED] wrote: Slight terminology glitch -- it does return an iterator, not a generator. Generators are functions that return iterators. xrange returns an ITERABLE, not an ITERATOR. Videat: a = xrange(23, 43) a.next() Traceback (most recent call last): File stdin,

Re: variable declaration

2005-02-05 Thread Alex Martelli
Nick Coghlan [EMAIL PROTECTED] wrote: ... _temp = x.y x.y = type(temp).__irebind__(temp, z) ... I was thinking of something simpler: x.y x.y = z That is, before the assignment attempt, x.y has to resolve to *something*, but the interpreter isn't particularly fussy

Re: variable declaration

2005-02-05 Thread Alex Martelli
Arthur [EMAIL PROTECTED] wrote: Do the STUPID firms use Python as well. Yes, they're definitely starting to do so. Why? The single most frequent reason is that some techie sneaked it in, for example just for testing or to do a prototype or even without any actual permission. Firms hardly

Re: a type without a __mro__?

2005-02-06 Thread Alex Martelli
John Lenton [EMAIL PROTECTED] wrote: class C(type): def __getattribute__(self, attr): if attr == '__mro__': raise AttributeError, What, *me*, a __mro__? Nevah! return super(C, self).__getattribute__(attr) class D(object): __metaclass__ = C

Re: Multiple constructors

2005-02-06 Thread Alex Martelli
Philip Smith [EMAIL PROTECTED] wrote: Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix Indeed, you can never define ``multiple versions'' of the same name in the same scope: one scope + one name - one object.

Re: Word for a non-iterator iterable?

2005-02-06 Thread Alex Martelli
Leif K-Brooks [EMAIL PROTECTED] wrote: Is there a word for an iterable object which isn't also an iterator, and therefor can be iterated over multiple times without being exhausted? Sequence is close, but a non-iterator iterable could technically provide an __iter__ method without

Re: [EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-06 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: Markus Wankus wrote: Google his name - he has been banned from Netbeans and Eclipse (and Hibernate, and others...) for good reason. Can you imagine how much of a Troll you need to be to *actually* get banned from the newsgroups of open source

Re: bytecode obfuscation

2005-02-06 Thread Alex Martelli
snacktime [EMAIL PROTECTED] wrote: ... How difficult is it to turn python bytecode into it's original source? It's pretty easy, not really the original source (you lose comments etc) but close enough to read and understand. Is it that much different than java (this is what they will

Re: bad generator performance

2005-02-06 Thread Alex Martelli
Johannes Ahl-mann [EMAIL PROTECTED] wrote: a non-recursive solution to traversing a recursive data type is bound to get ugly, isn't it? Not necessarily: sometimes using an explicit stack can be quite pretty, depending. E.g.: def all_leaves(root): stack = [root] while stack:

Re: variable declaration

2005-02-06 Thread Alex Martelli
Roy Smith [EMAIL PROTECTED] wrote: which is good news for sellers of books, tools, training, consultancy services, and for Python programmers everywhere -- more demand always helps. *BUT* the price is eternal vigilance... I'm not sure what that last sentence is supposed to mean, but I

Re: Python versus Perl ?

2005-02-06 Thread Alex Martelli
Reinhold Birkenfeld [EMAIL PROTECTED] wrote: ... Perl also has excellent pattern matching compared to sed, not sure about how Python measures up, but this seems to make perl ideally suited to text processing. Python has regular expressions much like Perl. The only difference is that

Re: Confused with methods

2005-02-06 Thread Alex Martelli
jfj [EMAIL PROTECTED] wrote: I don't understand. We can take a function and attach it to an object, and then call it as an instance method as long as it has at least one argument: # class A: pass def foo(x): print x A.foo = foo a=A() a.foo() #

Re: empty classes as c structs?

2005-02-06 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: Hmm... interesting. This isn't the main intended use of Bunch/Struct/whatever, but it does seem like a useful thing to have... I wonder if it would be worth having, say, a staticmethod of Bunch that produced such a view, e.g.: class Bunch(object):

Re: empty classes as c structs?

2005-02-06 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: Seems pretty reasonable -- the only thing I worry about is that classmethods and other attributes (e.g. properties) that are accessible from instances can lead to subtle bugs when a user accidentally initializes a Bunch object with the attributes of

Re: loops - list/generator comprehensions

2005-02-06 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: at the OP's original code, the line: [(x[0], x[2]) for x in os.walk(.)] is the equivalent of: [dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')] Just a nit: you need parentheses in your second LC too, i.e.: [(dirpath,

Re: Confused with methods

2005-02-06 Thread Alex Martelli
jfj [EMAIL PROTECTED] wrote: If I say: x=b.foo x(1) Then, without looking at the previous code, one can say that x is a function which takes one argument. One can say whatever one wishes, but saying it does not make it true. One can say that x is a green frog, but that's false: x is a

Re: Confused with methods

2005-02-06 Thread Alex Martelli
jfj [EMAIL PROTECTED] wrote: Isn't that inconsistent? That Python has many callable types, not all of which are descriptors? I don't see any inconsistency there. Sure, a more generalized currying (argument-prebinding) capability would be more powerful, but not more consistent

Re: empty classes as c structs?

2005-02-06 Thread Alex Martelli
Brian van den Broek [EMAIL PROTECTED] wrote: ... (I'm just a hobbyist, so if this suggestion clashes with some well established use of 'Bag' in CS terminology, well, never mind.) Yep: a Bag is a more common and neater name for a multiset -- a set-like container which holds each item ``a

Re: string issue

2005-02-06 Thread Alex Martelli
Bill Mill [EMAIL PROTECTED] wrote: ... You are modifying the list as you iterate over it. Instead, iterate over a copy by using: for ip in ips[:]: ... Once you know it, it's neat, and I use it sometimes. However, it's a little too magical for my tastes; I'd rather be more

Re: remove duplicates from list *preserving order*

2005-02-07 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote: ... I have a list[1] of objects from which I need to remove duplicates. I have to maintain the list order though, so solutions like set(lst), etc. will not work for me. What are my options? So far, I can see: I think the recipe by that subject in

Re: declarations summary

2005-02-07 Thread Alex Martelli
Michael Tobis [EMAIL PROTECTED] wrote: ... .x = 1 .def foo(): . if False: . global x . x = 2 .foo() .print x prints 1 Wrong: x = 1 def foo(): ... if False: ... global x ... x = 2 ... foo() print x 2 And indeed, that IS the problem. Pythonistas appear to be

Re: Confused with methods

2005-02-07 Thread Alex Martelli
On 2005 Feb 07, at 22:15, jfj wrote: Alex Martelli wrote: jfj [EMAIL PROTECTED] wrote: Then, without looking at the previous code, one can say that x is a function which takes one argument. One can say whatever one wishes, but saying it does not make it true. One can say that x is a green frog

Re: Confused with methods

2005-02-07 Thread Alex Martelli
Diez B. Roggisch [EMAIL PROTECTED] wrote: ... If there a good reason that the __get__ of a boundmethod does not create a new boundmethod wrapper over the first boundmethod? I already gave you the good reason: Hmmm, not sure the code below is ``a good reason'' to avoid changing the

Re: Confused with methods

2005-02-07 Thread Alex Martelli
Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-02-06, Alex Martelli schreef [EMAIL PROTECTED]: Isn't that inconsistent? That Python has many callable types, not all of which are descriptors? I don't see any inconsistency there. Sure, a more generalized currying (argument

  1   2   3   4   5   6   7   8   9   10   >