Re: [Python-Dev] PEP: __source__ proposal

2004-12-04 Thread Nick Coghlan
ach line of the original source for modification (e.g. to fix a minor bug in one function of a class definition). When the 'edit' is complete, it can be saved or cancelled. 1. The feature mentioned in the last paragraph is hard to show in the expected output :) -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: help needed

2004-12-04 Thread Nick Coghlan
In response to your first message, I offered some ideas on how to get more useful responses, along with a couple of general techniques for finding the problem yourself. Reposting almost exactly the same message 8 or so hours later wasn't a suggestion featured in either category. Cheers, Nick.

Re: Bug in py32win manual for file_locking for Python 2.4

2004-12-04 Thread Nick Coghlan
Pekka Niiranen wrote: However, using highbits=0x7fff # equals hex(sys.maxint) gives no errors, but does locking work if highbits are not exactly 0x? Try using highbits=-0x7fff as your mask. That should set the MSB without tripping over the sys.maxint limit. Cheers, Nick. -- http:/

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Nick Coghlan
Peter Otten wrote: Tim Peters wrote: See the Python (language, not library) reference manual, section 3.3.8 ("Coercion rules"), bullet point starting with: Exception to the previous item: if the left operand is an instance of a built-in type or a new-style class, and the right operand is

Re: [Python-Dev] PEP: __source__ proposal

2004-12-04 Thread Nick Coghlan
John Roth wrote: I don't see enough here to make a very intelligent comment, so I'll risk it and make what might be a rather uninformed comment. This was a misdirected reply on my part - the rest of the discussion can be found in the python-dev archives on python.org or gmane. I think your commen

Re: Help with modules/packages.

2004-12-04 Thread Nick Coghlan
Christopher J. Bottaro wrote: Hello, I want to be able to say stuff like "import CJB.ClassA" and "import CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()". CJB will be a directory containing files "ClassA.py" and "ClassB.py". Now that I think about it, that can't work b

Re: long number multiplication

2004-12-04 Thread Nick Coghlan
I.V. Aprameya Rao wrote: hi i have been wondering, how does python store its very long integers and perform aritmetic on it. i needed to implement this myself and was thinking of storing the digits of an integer in a list. however this would be very slow for operations like division etc. so if

Re: Recursive list comprehension

2004-12-06 Thread Nick Coghlan
Peter Nuttall wrote: I think you do it with a generator like this: def flatten(nested): for sublist in nested: for element in sublist: yield element n=[['N', 'F'], ['E'], ['D']] output=[] for value in flatten(n): output.append(value) print output I highly recommend learning about the

Re: Recursive list comprehension

2004-12-06 Thread Nick Coghlan
Peter Otten wrote: Nick Coghlan wrote: from itertools import chain n = [['N', 'F'], ['E'], ['D']] print [chain(*n)] However, [generator] is not the same as list(generator): Heh - good point. As you say, replacing with list() gives the intended answer. Wit

Float to int conversions (was: int(float(sys.maxint)) buglet)

2004-12-06 Thread Nick Coghlan
ints. See the code for the gory details (the relevant function is 'float_int'): http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/floatobject.c?rev=2.134&view=markup Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisb

exec and thread.start_new

2004-12-06 Thread Nick Coghlan
module. 2. The 'in dict()' workaround is simple and effective Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to understand a little python

2004-12-07 Thread Nick Coghlan
his description, the relevant word is almost certainly "descriptors") Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: long number multiplication

2004-12-07 Thread Nick Coghlan
n or division. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: win32 extensions for Python 2.4

2004-12-07 Thread Nick Coghlan
but i won't be bothered to download it. :) It's on the sourceforge download page. So long as you don't want to use Pythonwin, version 203 should work fine. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --

Re: deferred decorator

2004-12-08 Thread Nick Coghlan
ds. does anyone know how to port this recipe to the new class style? Override __getattribute__. I don't know why you think it doesn't let you override all attribute accesses, as that's exactly what it is for. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED]

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Nick Coghlan
the user's variables, easily avoiding namespace conflicts. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I do this? (eval() on the left hand side)

2004-12-08 Thread Nick Coghlan
rally, altering the contents of the dicts returned by locals() and globals() is unreliable at best. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.n

Re: [BUG] IMO, but no opinions? Uncle Tim? was: int(float(sys.maxint)) buglet ?

2004-12-08 Thread Nick Coghlan
you like in your own copy of Python . .>>> _int = int .>>> def int(*args): return _int(_int(*args)) .>>> from sys import maxint .>>> int(maxint) .2147483647 .>>> int(-maxint-1) .-2147483648 Pretty! };> Cheers, Nic

Re: How do I do this? (eval() on the left hand side)

2004-12-09 Thread Nick Coghlan
Peter Hansen wrote: Nick Coghlan wrote: Generally, altering the contents of the dicts returned by locals() and globals() is unreliable at best. Nick, could you please comment on why you say this about globals()? I've never heard of any possibility of "unreliability" in updating gl

Re: a newbie question

2004-12-09 Thread Nick Coghlan
on any platform: python -c "import pdb; print pdb.__file__" The rest of the standard library will be in the same directory as pdb.pyc. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: deferred decorator

2004-12-09 Thread Nick Coghlan
Bryan wrote: Nick Coghlan wrote: Bryan wrote: i'm also curious if it's possible to write this recipe using the new class style for the Deffered class.it appears you can nolonger delegate all attributes including special methods to the contained object by using the __getattr__

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
from object or another builtin, that recipe fails. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Rationale behind the deprecation of __getslice__?

2004-12-10 Thread Nick Coghlan
itely solve the OP's problem... It might be better handled at construction time - if the class supplied to __new__ is a subclass of the builtin type, swap the __getslice__ implementation for one which delegates to __getitem__. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED]

Re: Rationale behind the deprecation of __getslice__?

2004-12-10 Thread Nick Coghlan
e development of extended slicing in the first place (it wasn't until 2.3 that Python's builtin sequences supported extended slicing at all). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia -

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Kent Johnson wrote: Nick Coghlan wrote: Simon Brunning wrote: This work - <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295>? Only for old-style classes, though. If you inherit from object or another builtin, that recipe fails. Could you explain, please? I thought __get

Re: building python extensions with .net sdk compiler?

2004-12-11 Thread Nick Coghlan
Mike C. Fletcher wrote: Which is what the patch here: http://www.vrplumber.com/programming/mstoolkit/ does. Has that patch been posted to Python's SourceForge patch tracker? I think the distutils folks will be interested. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Bri

Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Nick Coghlan
ownside is that the total download to get all the pieces you need is on the order of 400 MB. . . Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net

Re: uptime for Win XP?

2004-12-11 Thread Nick Coghlan
han just the up time) There's also info about the 'uptime' utility here: http://support.microsoft.com/kb/q232243/ I don't know if that works for XP. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia -

Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Nick Coghlan
her I nor the win32 gurus can figure out what the heck happened. And reinstallation of 2.3 and the Py2.3 win32all didn't fix it? Very strange. . . Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-11 Thread Nick Coghlan
was already in beta at the time. So I went with the cookbook recipe instead. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.

Re: while 1 vs while True

2004-12-13 Thread Nick Coghlan
#x27;False' are in line for similar treatment (there are obvious backwards compatibility issues in doing so). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Renaming __getattribute__ (PEP?)

2004-12-13 Thread Nick Coghlan
r than working on changing the names of special methods. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Nick Coghlan
pdb and profile for the interpreter you're working with. For usability, you can hide all of the above behind a menu item or desktop shortcut. However, the major target of the feature is Python developers rather than the end-users of applications built using Python. Cheers, Nic

Re: newbie questions

2004-12-13 Thread Nick Coghlan
7;by reference' output parameters as used by C, C++, Java and the like. Regards, Nick. P.S. If you *really*, *really*, *really* want to fake output parameters, just wrap them in a list: def myfunc(outputparam): # Do something outputparam[0] = result x = []# Like declaring x as a pointe

Re: can't find python2.4 source code

2004-12-13 Thread Nick Coghlan
. Does the python24 source code released? http://sourceforge.net/projects/python/ Which is linked from www.python.org However, as Fredrik said, the source tarballs are available on the release page for 2.4 (and yes, they do contain the source code). Cheers, Nick. -- Nick Coghlan | [EMAIL

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Nick Coghlan
ature is a convenience for command line junkies - which seems to be a fairly common trait amongst the developers I know :) -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: [dictionary] how to get key by item

2004-12-13 Thread Nick Coghlan
value, keys in grouped) .>>> r {16: ['mary', 'fred'], 1: ['bar', 'foo'], 42: ['jane'], 7: ['bob']} Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: while 1 vs while True

2004-12-13 Thread Nick Coghlan
* flexible - and in this case, the flexibility eliminates some potential optimisations (in this case, "I know what this is" compile time name binding). I believe modifying a module's globals dictionary from outside the module is in the process of being deprecated - the

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-13 Thread Nick Coghlan
age points out (eventually) - this feature is intended for developers and Python version specific utility scripts like pdb, profile and pychecker.checker, rather than launch scripts for full applications. For end users, I agree with you wholeheartedly - applications should behave like applications

Re: while 1 vs while True

2004-12-15 Thread Nick Coghlan
Paul Rubin wrote: Nick Coghlan <[EMAIL PROTECTED]> writes: Until this code: .>>> import pdb .>>> pdb.True = 0 .>>> pdb.x = "Darn writeable module dictionaries" .>>> from pdb import True .>>> True 0 .>>> from pdb import x .&g

Re: do you master list comprehensions?

2004-12-15 Thread Nick Coghlan
n" "''.join(chain(*data))" 10 loops, best of 3: 1.2 sec per loop ** OUCH!! C:\>python -m timeit -s "data = [map(str, range(x)) for x in range(1000)]; from itertools import chain" "''.join(list(chain(*data)))" 10 loops, best of 3: 107 msec per loop Yikes - loo

Re: jython and concatenation of strings

2004-12-15 Thread Nick Coghlan
#x27;.join(string_list) (Python switches to the unicode version automatically if it finds any unicode strings in the supplied sequence. Jython may not do that - I'm not a Jython user though, so I'm not sure). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] |

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Nick Coghlan
seful for web tools that strip leading whitespace. Prepending every line with . is not an ideal solution though... I think it gets tiresome very quickly. Aye, can't argue with that. It does have the virtues of reliability and portability, though :

Re: do you master list comprehensions?

2004-12-16 Thread Nick Coghlan
Nick Coghlan wrote: (FYI, I filed bug report #1085744 on SF about this) And Raymond Hettinger was able to decipher my somewhat incoherent rambling (tip: don't try to write bug reports in the wee hours of the morning) and produce a potentially useful modification to PySequence_Tuple. Anyw

Re: why not arrays?

2004-12-16 Thread Nick Coghlan
ly to be a pain) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Nick Coghlan
aside from the detail that modifying a module's contents via a reference to that module is far more evil than playing with globals() ;) Even if that module is the one you're running in. . . Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Bris

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
require calls to methods like int() or str() in your application code to make the types work out correctly. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skyst

Re: New versions breaking extensions, etc.

2004-12-10 Thread Nick Coghlan
ual Studio license ;) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

PEP 338: Executing modules inside packages with '-m'

2004-12-11 Thread Nick Coghlan
* PEP: 338 Title: Executing modules inside packages with '-m' Version: $Revision: 1.2 $ Last-Modified: $Date: 2004/12/11 20:31:10 $ Author: Nick Coghlan <[EMAIL PROTECTED]> Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 16-Oct-2004 Python-V

Re: Why are tuples immutable?

2004-12-13 Thread Nick Coghlan
omparing the following class to the builtin tuple: . _tuple = tuple . class tuple(_tuple): pass Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-15 Thread Nick Coghlan
Martin Bless wrote: [Nick Coghlan <[EMAIL PROTECTED]>] One thing I stumbled across with the current implementation: Why doesn't "python -m abc" work with ./abc/ ./abc/__init__.py assuming ./abc/ is directly on the path? In analogy to normal module import? It doesn't wor

Re: Why are tuples immutable?

2004-12-17 Thread Nick Coghlan
n certainly *do* the former (using __hash__ and appropriate comparison overrides), but it isn't particularly easy to do correctly, and hence usually isn't a great idea unless copies are *really* expensive (and even then, a shallow copy approach can often suffice). Cheers, Nick. -- Nick Co

Re: Why are tuples immutable?

2004-12-17 Thread Nick Coghlan
s elements (using id() directly would be dangerous, as the dictionary then has no reference keeping the original object alive, thus failing to ensure the uniqueness of the keys - since id() only guarantees uniqueness with respect to currently existing objects). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are tuples immutable?

2004-12-17 Thread Nick Coghlan
(NotHashable()) 10297264 Py> d = {NotHashable(): "Hi"} Py> d {<__main__.NotHashable object at 0x009D1FF0>: 'Hi'} That may be a bug rather than a feature :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia

Re: better lambda support in the future?

2004-12-17 Thread Nick Coghlan
etween them 3. That function is then passed as an argument to another function call All of that is contained in the lambda version, too, but the excessive brevity makes for rather confusing reading. Cheers, Nick. -- Nick Coghlan

Re: Why are tuples immutable?

2004-12-17 Thread Nick Coghlan
Nick Coghlan wrote: Although, it looks like new-style classes currently don't apply this rule - you get the default hash implementation from object no matter what: That may be a bug rather than a feature :) And indeed it is: http://sourceforge.net/tracker/index.php?func=detail&a

Re: Troubleshooting: re.finditer() creates object even when no match found

2004-12-17 Thread Nick Coghlan
code meant to parse out data from my finditer() object. Take a look at itertools.tee Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.pytho

Re: Troubleshooting: re.finditer() creates object even when no match found

2004-12-17 Thread Nick Coghlan
Nick Coghlan wrote: Chris Lasher wrote: Hello, I really like the finditer() method of the re module. I'm having difficulty at the moment, however, because finditer() still creates a callable-iterator oject, even when no match is found. This is undesirable in cases where I would like to circu

Re: better lambda support in the future?

2004-12-18 Thread Nick Coghlan
ss ... Py> for t in sorted(dispatcher.items()): print '%5s: %r'%t ... a: b: c: -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Cool object trick

2004-12-18 Thread Nick Coghlan
Robert Brewer wrote: Bengt Richter wrote: >>> m=type('',(),{})() >>> m.title = 'not so fast ;-)' >>> m.title 'not so fast ;-)' Now THAT is a cool object trick. :) Heh. Look ma, Perlython! Cheers, Nick. -- Nick

Re: better lambda support in the future?

2004-12-18 Thread Nick Coghlan
;. They're probably less evil than sys._getframe hacks, though :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: A rational proposal

2004-12-18 Thread Nick Coghlan
h case, I would also hope to see a __decimal__ special method. The correct answer would then be for Rational.rational to handle decimals in its constructor, and provide an implementation of __decimal__ (similar to the way Decimal.decimal interacts with the other builtin types). Cheers, Nick. -- N

Re: A beginner's problem...

2004-12-18 Thread Nick Coghlan
ort x Py> # Do stuff Py> import module Py> reload(module) Py> from module import x Py> # We now have the updated version of x Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: Plugin system; imp module head scratch

2004-12-18 Thread Nick Coghlan
ent, it is pulling in the __init__.py from the current directory, and assigning it to the name you requested) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystor

Re: Easy "here documents" ??

2004-12-18 Thread Nick Coghlan
Jim Hill wrote: Is there a way to produce a very long multiline string of output with variables' values inserted without having to resort to this wacky """v = %s"""%(variable) business? Try combining Python 2.4's subprocess module with its string

Re: How about "pure virtual methods"?

2004-12-19 Thread Nick Coghlan
they only need a fraction of it. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: dot products

2004-12-19 Thread Nick Coghlan
ase in length, generator expressions generally win in the end due to their reduced memory impact. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- h

Re: newbie question

2004-12-19 Thread Nick Coghlan
ible to alter that determination though: Py> from decimal import Decimal Py> Decimal(1) == int(1) True Py> type(Decimal(1)) Py> type(int(1)) The reason your __abs__ example blows up is because the relevant attribute is missing for string objects - and the

Re: input record seperator (equivalent of "$|" of perl)

2004-12-20 Thread Nick Coghlan
le import TemporaryFile Py> demo = TemporaryFile() Py> demo.write(txt) Py> demo.seek(0) Py> demo.read() 'a|b|c|d\n1|2|3|4' Py> demo.seek(0) -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Web forum (made by python)

2004-12-20 Thread Nick Coghlan
problem more than py-dev, since the greater number of contributors increases the chances of at least one regular poster being in a bad mood at any given point in time. That's a subjective impression rather than a scientific fact, though :) -- Nick Coghlan | [EMAIL PROTEC

Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
on composition (although it has the same effect). From a real world programming point of view, though, it's self-documenting, runs faster and uses less memory, so it's really a pure win. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --

Re: A rational proposal

2004-12-21 Thread Nick Coghlan
a suitable intermediate format that makes explicit the degree of precision used in the conversion. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: List limits

2004-12-21 Thread Nick Coghlan
emory, and Python's internal structures are already chewing up some of the address space. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.n

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-21 Thread Nick Coghlan
ed to remind you why you love coding in Python ;) Although coding in C when you have the Python API to lean on is a hell of a lot better than just coding in C. . . Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Bri

Re: Is this a good use for lambda

2004-12-21 Thread Nick Coghlan
Steven Bethard wrote: Nick Coghlan wrote: def compose(list_of_functions): application_order = reversed(list_of_functions) def composed(x): for f in application_order: x = f(x) return x return composed so you either need to call reversed each time in 'composed' o

Re: Why are tuples immutable?

2004-12-21 Thread Nick Coghlan
t(). Or, as I suggested elsewhere in this thread, use a special KeyedById class which *doesn't copy anything anywhere*. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Lazy argument evaluation (was Re: expression form of one-to-many dict?)

2004-12-21 Thread Nick Coghlan
, guarded_operation, lazyval(default_case)) Huh. I think I like the idea of lazy() much better than I like the current PEP 312. There must be something wrong with this idea that I'm missing. . . Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Mutable objects which define __hash__ (was Re: Why are tuples immutable?)

2004-12-22 Thread Nick Coghlan
e of hash() for sorting into hash buckets and "x == y" for key matching. An identity_dict variant that uses id() (or object.__hash__ in Jython) and "x is y" would seem to quite happily meet the use cases you have posted in this th

Re: Lazy argument evaluation (was Re: expression form of one-to-many dict?)

2004-12-22 Thread Nick Coghlan
Nick Coghlan wrote: def lazycall(x, *args, **kwds): """Executes x(*args, **kwds)() when called""" return lambda : x(*args, **kwds)() It occurred to me that this should be: def lazycall(x, *args, **kwds): """Executes x()(*args, **kwds) when c

Re: Lazy argument evaluation (was Re: expression form of one-to-many dict?)

2004-12-22 Thread Nick Coghlan
not entirely sure about it myself, since I'm in a similar boat to you w.r.t. lazy evaluation (I usually just define functions that do what I want and pass them around). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia -

Re: A rational proposal

2004-12-22 Thread Nick Coghlan
est: float() + Decimal() fails with a TypeError float() + float(Decimal()) works fine And I believe Decimal's __float__ operation is a 'best effort' kind of thing, so I have no problem with Rationals working the same way. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED]

Re: input record sepArator (equivalent of "$|" of perl)

2004-12-22 Thread Nick Coghlan
John Machin wrote: Nick Coghlan wrote: [snip] delimeter. Hey, Terry, another varmint over here! Heh. Just don't get me started on the issues I have with typing apostrophes in the right spot. My *brain* knows where they go, but for some reason it refuses to let my fingers in on the s

Re: Is this a good use for lambda

2004-12-22 Thread Nick Coghlan
:) Although if you genuinely prefer a functional programming style, I'd go with Terry's answer rather than mine. (Incidentally, I didn't even know what the reduce trap *was* until Terry described it, but the iterative version avoids it automatically) Cheers, Nick. -- Nick

Re: Mutable objects which define __hash__ (was Re: Why are tuples immutable?)

2004-12-22 Thread Nick Coghlan
in using sets to classify mutable objects like lists (such as Antoon's example of applying special processing to certain graph points). Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: Mutable objects which define __hash__ (was Re: Why are tuples immutable?)

2004-12-22 Thread Nick Coghlan
faster than the standard dict() and set(), since they don't have to deal with user-overridable special methods :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://bore

Re: A rational proposal

2004-12-22 Thread Nick Coghlan
playing well with other types have been considered properly. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie namespace question

2004-12-22 Thread Nick Coghlan
ver, if you would prefer not to alter jdbc.py, consider trying: import jdbc jdbc.AdminConfig = AdminConfig Global variables are bad karma to start with, and monkeying with __builtin__ is even worse :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia -

Re: list IndexError

2004-12-23 Thread Nick Coghlan
And just to prove they're both still doing the right thing in that last example: Py> import remove Py> lst = [not bool(x % 10) for x in xrange(1)] Py> len(lst) 1 Py> remove.remove_lc(False, lst) Py> len(lst) 1000 Py> lst = [not bool(x % 10) for x in xra

Re: list IndexError

2004-12-23 Thread Nick Coghlan
they demonstrate what they were meant to demonstrate - that there's a reason filtration is the recommended approach! Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: Lambda going out of fashion

2004-12-23 Thread Nick Coghlan
(*a, **k)) for x, a, k in func_list) Anyway, thats just some ideas if you're concerned about the plan to have lambda disappear in 3K. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: deriving from str

2004-12-23 Thread Nick Coghlan
han the new instance. The __new__ method *creates* the instance, and returns it. See here for the gory details of overriding immutable types: http://www.python.org/doc/newstyle.html Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Mutable objects which define __hash__ (was Re: Why are tuples immutable?)

2004-12-23 Thread Nick Coghlan
case, I don't think we now disagree on anything more substantial than what the __hash__ documentation in the Language Reference should be saying :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane,

Re: Mutable objects which define __hash__ (was Re: Why are tuples immutable?)

2004-12-23 Thread Nick Coghlan
long-held assumptions. Those don't get changed overnight - it takes at least a couple of days :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skyst

Re: Lambda going out of fashion

2004-12-23 Thread Nick Coghlan
stands will disappear for the Python 2.x series. Python 3.0 will be a case of "OK, let's take the things we learned were good and keep them, and throw away the things we realised were bad" Undoubtedly, the two languages will co-exist for quite some time. Cheers, Nick. -- Nick C

Re: Newbie namespace question

2004-12-23 Thread Nick Coghlan
out circular imports. Any extra global configuration properties can be added by updating the 'setConfiguration' function. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia ---

Re: Lambda going out of fashion

2004-12-23 Thread Nick Coghlan
Alex Martelli wrote: Nick Coghlan <[EMAIL PROTECTED]> wrote: ... Perhaps something like: accepts_func( (def (a, b, c) to f(a) + o(b) - o(c)) ) Nice, except I think 'as' would be better than 'to'. 'as' should be a full keyword in 3.0 anyway (rather than a

Re: Lambda going out of fashion

2004-12-23 Thread Nick Coghlan
Nick Coghlan wrote: Indeed, lambda as it currently stands will disappear for the Python 2.x series. Will NOT disappear. I repeat, will NOT disappear. Cheers, Nick. Damn those missing negators. . . -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia

Re: hidding the "console" window + system global shortcut keys

2004-12-24 Thread Nick Coghlan
at, I have no idea :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Optional Static Typing

2004-12-24 Thread Nick Coghlan
compile time code optimisation through static type declarations. The write up is here: http://boredomandlaziness.skystorm.net/2004/12/type-checking-in-python.html Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia

Re: Features for a Python package manager?

2004-12-25 Thread Nick Coghlan
l it after gentoo's portage, with less features of course. > Would this be acceptable? I don't know enough about Portage to answer that question. I do know any package manager which made it into the standard distribution would need to work for at least the big three platforms (

<    1   2   3   4   5   >