Re: functions without parentheses

2005-07-30 Thread Bengt Richter
On Fri, 29 Jul 2005 20:54:42 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Fri, 29 Jul 2005 06:37:52 +, Bengt Richter wrote: > >> I suggested in a previous thread that one could support such a syntax by >> supporting an invisible binary operator bet

Re: functions without parentheses

2005-07-28 Thread Bengt Richter
ite space as potential invisible operator would be that foo() and foo () might be foo.__call__() vs foo.__invisbinop_(()) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping a class set method

2005-07-27 Thread Bengt Richter
ces. A dict subclass overriding __setitem__ should suffice for the usage you show. Then you can give the classes undo/redo methods, or whatever. You could also use a special object instead of a dict subclass, if you wanted some other interface. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple inheritance super()

2005-07-26 Thread Bengt Richter
#x27;__init__' in vars(base): base.__init__(self) replacing your super line above in class D, but I would be leery of using __init__ methods that way unless I had a really good rationale. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [path-PEP] Path inherits from basestring again

2005-07-25 Thread Bengt Richter
confused with "basename" >> types of things. > >Right, that was a concern of mine, too. >"tobase"? -1 >"tostring"? +1 >"tobasestring"? -0 > >Alternative is to set a class attribute "Base" of the Path class. Or export &

Re: [path-PEP] Path inherits from basestring again

2005-07-25 Thread Bengt Richter
;, then you could form even two-dimensional arrays without all that of punctuation (except that you'd need an explicit ending ';' for the above or () most likely for 2D) (funnyarray() 1 2 3 4 5 6 ) BTW, more OT, wouldn't '|' be more platform-neutral as the joining operator? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary that discards old items

2005-07-23 Thread Bengt Richter
On Sat, 23 Jul 2005 20:07:25 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: >[Raymond Hettinger] >>>class Cache(dict): >>> def __init__(self, n, *args, **kwds): >>> self.n = n >>> self.queue = collections.deque() >>>

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
On Sun, 17 Jul 2005 15:42:08 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Thanks for the nudge. Actually, I know about generator expressions, but >> at some point I must have misinterpreted some bug in my code to mean >> that join in parti

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
assing to translate() or regex.compile(), that will map each character in from into the character at the same position in to, while leaving all characters other than those in from unchanged; from and to must have the same length. """ Meanwhile, if my python feature request #1193128 on sourceforge gets implemented, we'll be able to write s.translate(None, badchars) instead of having to build an identity table to pass as the first argument. Maybe 2.5? (Not being pushy ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-23 Thread Bengt Richter
nce is adequate for the >> reference docs. > >For Py2.5, I've accepted a feature request to allow string.translate's >first argument to be None and then run as if an identity string had >been provided. > My news service has been timing out on postings, but I had a couple that

Re: "Aliasing" an object's __str__ to a different method

2005-07-23 Thread Bengt Richter
e flag and the ability to assign an arbitrary __str__ and/or __repr__ override for a particular instance. See example, where all are toggled by default. >as if they were strings, e.g. mixing them with literal strings via str >(obj). Note that your example set __repr__ also, which is not used for str(x) if x.__str__ exists. > >Clearly there are at least a handful of ways to accomplish this, but >the one that came to mind first was, as I said at the beginning, to >define both behaviors on each object and then have the ability to >point __str__ to one or the other. I suppose now I need to figure out >which is more important, that ease-of-use of overriding __str__ or >whatever benefits new-style classes give (something I'm still a bit >unclear on). > Those aren't your only choices ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Copying attributes

2005-07-23 Thread Bengt Richter
On Sat, 23 Jul 2005 18:30:29 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: [...] >Did it work on a quad face? What about putting in a debug print before places >you use >f.normal, e.g. >assert hasattr(f, 'normal'), 'This "f"\n\n%r\n\ndid not ha

Re: dictionary that discards old items

2005-07-23 Thread Bengt Richter
g, so what is considered best practice to avoid that? __n or such as the n arg? >>> def foo(n, *args, **kw): print n, args, kw ... >>> foo(1) 1 () {} >>> foo(n=5) 5 () {} >>> foo(3, n=5) Traceback (most recent call last): File "", line 1, in ? TypeError: foo() got multiple values for keyword argument 'n' >>> Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP on path module for standard library

2005-07-23 Thread Bengt Richter
y behind the scenes print po.read() po.close() Say, how about if Pathobject('gui://message_box/yn/continue processing?').open().read().lower()!='y': raise SystemExit, "Ok, really not continuing ;-)" An appropriate registered subclass for the given platform, returned when the Pathobject base class instantiates and looks at the first element on open() and delegates would make that possible, and spelled platform-independently as in the code above. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Copying attributes

2005-07-23 Thread Bengt Richter
nv = f.normal > >and it works! But why my new faces (f1 and f2) no? Did it work on a quad face? What about putting in a debug print before places you use f.normal, e.g. assert hasattr(f, 'normal'), 'This "f"\n\n%r\n\ndid not have a normal attribute!!

Re: Filtering out non-readable characters

2005-07-16 Thread Bengt Richter
On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> >>> identity = ''.join([chr(i) for i in xrange(256)]) >> >>> unprintable = ''.join([c for c in identity if c not in >> stri

Re: Generating a list of None

2005-07-16 Thread Bengt Richter
On 16 Jul 2005 02:31:28 -0700, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: >[Bengt Richter] >> how about (untested) >> >> def get_options(opts): >> """Return True or False if an option is set or not""" >>

Re: Filtering out non-readable characters

2005-07-15 Thread Bengt Richter
7;, '9', '=', 'A', 'E', 'I', 'M', 'Q', 'U', 'Y', ']', 'a', 'e', 'i', 'm', 'q', 'u', 'y', '}']) >>> sorted(set(remove_unprintable(identity))) == sorted(set(string.printable)) True >>> sorted((remove_unprintable(identity))) == sorted((string.printable)) True After that, to get clean file text, something like cleantext = remove_unprintable(file('unclean.txt').read()) should do it. Or you should be able to iterate by lines something like (untested) for uncleanline in file('unclean.txt'): cleanline = remove_unprintable(uncleanline) # ... do whatever with clean line If there is something in string.printable that you don't want included, just use your own string of printables. BTW, >>> help(str.translate) Help on method_descriptor: translate(...) S.translate(table [,deletechars]) -> string Return a copy of the string S, where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating a list of None

2005-07-15 Thread Bengt Richter
--- >def get_options(opts): >"""Return True or False if an option is set or not""" >vals = opts.__dict__.values() > >for if vals is [None * len(vals)]: >return False > >return True >--- how about (untested) def get_option

Re: all possible combinations

2005-07-14 Thread Bengt Richter
acbb acbc acca accb accc baaa baab baac baba babb babc baca bacb bacc bbaa bbab bb ac bbba bbbc bbca bbcb bbcc bcaa bcab bcac bcba bcbb bcbc bcca bccb bccc caaa caab caac cab a cabb cabc caca cacb cacc cbaa cbab cbac cbba cbbb cbbc cbca cbcb cbcc ccaa ccab ccac ccba ccbb ccbc ccca cccb Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: extend for loop syntax with if expr like listcomp&genexp ?

2005-07-12 Thread Bengt Richter
On Tue, 12 Jul 2005 23:07:07 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote: >On Monday 11 July 2005 08:53 pm, Bengt Richter wrote: >> On Tue, 12 Jul 2005 10:12:33 +1000, John Machin <[EMAIL PROTECTED]> wrote: >> >Bengt Richter wrote: >> >>

Re: Frankenstring

2005-07-12 Thread Bengt Richter
x27;, '1', '3'] [' ', ' ', '1', '4'] [' ', ' ', '1', '5'] [' ', ' ', '1', '6'] [' ', ' ', '1', '7'] [' ', ' ', '1', '8'] [' ', ' ', '1', '9'] [' ', ' ', '2', '0'] [' ', ' ', '2', '1'] [' ', ' ', '2', '2'] [' ', ' ', '2', '3'] [' ', ' ', '2', '4'] 100 1 3 1 4 9 9 0 9 9 1 9 9 2 9 9 3 9 9 4 9 9 5 9 9 6 9 9 7 9 9 8 9 9 9 I suspect you could get better performance if you made LotzeFile instances able to return interators over buffer chunks and get characters from them, which would be string iterators supplying the characters rather than the custom .next, but the buffer chunks would have to be of some size to make that pay. Testing is the only way to find out what the crossing point is, if you really have to. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: if not DEBUG: log = null_log

2005-07-12 Thread Bengt Richter
uldn't locate it off hand. It would seem pretty safe and useful though. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Inconsistency in hex()

2005-07-12 Thread Bengt Richter
ex of a canonical twos-complement representation of a negative number, but I guess I'll let it go with this mention ;-) BTW, yeah, I know it's not so hard to write >>> '%010X'% (-75 &0xff) 'B5' >>> '%010X'% (-75*256**4 &0xff) 'B5' or a helper or a str subclass that does __mod__ differently but that's not with the batteries ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python parser

2005-07-12 Thread Bengt Richter
a >copy. Grep > > http://pyparsing.sourceforge.net/ > >for "Verilog". > or google for verilog site:sourceforge.net BTW googling for verilog site:pyparsing.sourceforge.net will only get one hit (maybe less if I typoed again ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Frankenstring

2005-07-12 Thread Bengt Richter
happy. > >I'd even consider writing such a beast in C, albeit more as a learning >exercise than as a worthwhile measure to speed up some code. > >Thanks for any hints. > I'd probably subclass file to buffer in good-sized chunks and override the iteration to go by characters through the buffer, updating the buffer when you get to its end, and overriding seek and tell to do the right thing re the buffer and where you are in it for the character iteration via next. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads'C1, C2 and C3'

2005-07-12 Thread Bengt Richter
t, then the second, finally the third" >> >>> chunks = data.rsplit(',', 1) >> >>> chunks >> ['the first bit, then the second', ' finally the third'] >> >>> >> >> Best, >> >> Brian vdB >> Or

Re: Tricky Dictionary Question from newbie

2005-07-12 Thread Bengt Richter
>there's not already a value to "get". If you have a fancy enough >editor, you can teach it to replace setdefault by getorset whenever >you type the former ;-) But it isn't get OR set, it's set_default_if_no_value_then_either_way_effectively_get ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficiency of using long integers to hold bitmaps

2005-07-12 Thread Bengt Richter
27;m sure it can still be improved upon, and I'm not sure it will be worth your while to dig into it, unless you think the problem fun, but there it is. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Puzzled

2005-07-11 Thread Bengt Richter
which changed your trailing 'Or' So, doing .capitalize on all the pieces from split('_') and then joining them: >>> def doit(w): return ''.join([s.capitalize() for s in w.split('_')]) ... >>> doit('logical_or') 'LogicalOr' >>> doit('logical') 'Logical' >>> doit('logical_or_something') 'LogicalOrSomething' >>> doit('UP_aNd_down') 'UpAndDown' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Access descendant class's module namespace from superclass

2005-07-11 Thread Bengt Richter
eggs.py then e.fish('Spam') would pick it up just like Ham. >>> spaminst = g.fish('Spam')() >>> spaminst.fish('__doc__') 'spam.py module doc string' Note that the fishinghole property dynamically returns the module dict, which is mutable, so you can write a really tangled mess if you want to. This already seems dangerously close ;-) >>> e.fishinghole['x'] = 'x in eggs module globals' >>> e.fish('x') 'x in eggs module globals' >>> eggs.x 'x in eggs module globals' >>> g.fishinghole['x'] = 'x in spam module globals' >>> g.fish('x') 'x in spam module globals' >>> eggs.spam.x 'x in spam module globals' But we didn't directly import spam (eggs did, that's why eggs.spam was visible) ... >>> spam Traceback (most recent call last): File "", line 1, in ? NameError: name 'spam' is not defined >>> import spam >>> spam.x 'x in spam module globals' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: extend for loop syntax with if expr like listcomp&genexp ?

2005-07-11 Thread Bengt Richter
On Tue, 12 Jul 2005 10:12:33 +1000, John Machin <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> E.g., so we could write >> >> for x in seq if x is not None: > >Chundrous; looks like that p**l language ... ^--piqued my interest, where'd t

extend for loop syntax with if expr like listcomp&genexp ?

2005-07-11 Thread Bengt Richter
E.g., so we could write for x in seq if x is not None: print repr(x), "isn't None ;-)" instead of for x in (x for x in seq if x is not None): print repr(x), "isn't None ;-)" just a thought. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-11 Thread Bengt Richter
so you wouldn't have to explain it ;-) I.e., the above would act like class Foo: x = Bar() def method_1(self, _anonymous_arg_1): x.y = _anonymous_arg_1 and would do whatever it would do now (probably look for a global x or a closure cell x, but it wouldn't find the class variable in a normal method call) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-11 Thread Bengt Richter
On Mon, 11 Jul 2005 01:44:07 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> Me too. I liked the leading _, but on second thought it is a weird >> language cha

Re: Read-only class properties

2005-07-11 Thread Bengt Richter
On Sun, 10 Jul 2005 21:10:36 -0700, Michael Spencer <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >... >> >> class Foo(object): >> class __metaclass__(type): >> def __setattr__(cls, name, value): >> if type(cls._

Re: Cat and Mouse (wes Re: Efficiency of using long integers to hold bitmaps)

2005-07-10 Thread Bengt Richter
ards better questions is not a bad thing. OTO3H, maybe I should just silently pass up 20-questions invitations and not pollute this pleasant space with perfumes of annoyance (since however diffuse, they are apparently pungent enough for some to notice ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-10 Thread Bengt Richter
# and adict is global here adict = {} setem('k', 'value') adict -> {'k':'value'} Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: computer algebra packages

2005-07-10 Thread Bengt Richter
On Sun, 10 Jul 2005 15:53:22 -0700, Robert Kern <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> Then googling for mascsyma [sic ;-)] got Dang, and I put "[sic]" too. IOW, 'macsyma'.replace('cs','sc') > >I doubt it. ;-)

Re: Read-only class properties

2005-07-10 Thread Bengt Richter
e Answer according to Foo is 42 Foo.notTheAnswer is 'ok' Another Answer according to Foo is 43 AttributeError: setting Foo.TheAnswer to 123 is not allowed AttributeError: setting Foo.AnotherAnswer to 456 is not allowed The Answer according to Bar is 42 Bar.notTheAnswer is 'ok' Another Answer according to Bar is 43 AttributeError: can't set class attribute AttributeError: can't set class attribute Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: computer algebra packages

2005-07-10 Thread Bengt Richter
cts/mascyma/index.xhtml.de leading to screenshots at http://home.arcor.de/mulk/projects/mascyma/screenshots.xhtml.de No idea what the status of all that is, but looks nice. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

AST decoration vs byte-code-munging (Was: Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code))

2005-07-10 Thread Bengt Richter
place like trying to do place = __import__(_AT_AT_MODULE_) wher _AT_AT_MODULE_ gets defined sort of like __METACLASS__.), passing the AST and the _AT_AT_deco call location therein, and the rest of the parameters. AST decoration would introduce macro-like capabilities, but restricted to transfor

Re: decorators as generalized pre-binding hooks

2005-07-10 Thread Bengt Richter
On Sun, 10 Jul 2005 05:35:01 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> ;-) >> We have > >Have we? > >Looks like not a lot of interested takers so far. > >But I'll bite. ;-) > > > > >> So why not >> >

Re: Efficiency of using long integers to hold bitmaps

2005-07-10 Thread Bengt Richter
ill "break" due to storage problems or be fast enough will depend on numbers you didn't provide ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-10 Thread Bengt Richter
12 LOAD_FAST1 (item) 15 JUMP_IF_FALSE8 (to 26) 18 POP_TOP 19 LOAD_FAST1 (item) 22 YIELD_VALUE 23 JUMP_ABSOLUTE6 >> 26 POP_TOP 27 JUMP_ABSOLUTE6 >> 30 POP_BLOCK >> 31 LOAD_CONST 0 (None) 34 RETURN_VALUE A little more info, anyway. HTH. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

decorators as generalized pre-binding hooks

2005-07-09 Thread Bengt Richter
(most recent call last): File "", line 2, in ? File "", line 1, in ? ZeroDivisionError: integer division or modulo by zero orthogonal-musing-ly ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: why UnboundLocalError?

2005-07-09 Thread Bengt Richter
On Sat, 09 Jul 2005 06:17:20 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On Fri, 8 Jul 2005 21:21:36 -0500, Alex Gittens <[EMAIL PROTECTED]> wrote: > >>I'm trying to define a function that prints fields of given widths >>with specified alignments; to do so,

Re: why UnboundLocalError?

2005-07-09 Thread Bengt Richter
om the i-th field, and strings are immutable, so he can't do del fields[i][:widths[i]] # slice deletion illegal if fields[i] is a string and so fields[i] = fields[i][:widths[i]] would be the way to go (see my other post). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-09 Thread Bengt Richter
On Sat, 09 Jul 2005 10:16:17 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Fri, 08 Jul 2005 22:29:30 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: >>>(1) There's no reason to get uncomfortable even if they're remo

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Bengt Richter
IMPORTANT* If this happens *at all*, it won't happen until Python >3.0, which is probably at least 5 years away. And the Python 2.X branch >will still be available then, so if you don't like Python 3.0, you don't >have to use it. > >STeVe Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: why UnboundLocalError?

2005-07-08 Thread Bengt Richter
,6], 'llrr', ['left', 'left12345', 'right', >>> '12345right']) left left1 right12345r 2345 ight Note that for i in xrange(len(items)): item = items[i] # mess with item just to walk through items one ite

Re: python-dev Summary for 2005-06-16 through 2005-06-30

2005-07-08 Thread Bengt Richter
On Fri, 8 Jul 2005 18:15:37 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: >[The HTML version of this Summary is available at >http://www.python.org/dev/summary/2005-06-16_2005-06-30.html] > Not when I just looked, but maybe it takes a while ;-) Regards, Bengt R

Re: Legacy data parsing

2005-07-08 Thread Bengt Richter
NB == == record hdr == EARNINGS VITAL INFORMATION/RENSEIGNEMENTS ESSENTIELS SUR LES GAINS: == == record data == *** 1 [Don't know what [<- 1,34 This is a box of 2 goes in this kind text with top/left 3 of record, but this character row/col 1,34 4 is some text to showand bottom/right at 4,62 ->] 5 how it might get 6 extracted] == earnings record right block [<- 1,34 This is a box of text with top/left character row/col 1,34 and bottom/right at 4,62 ->] HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditionally implementing __iter__ in new style classes

2005-07-07 Thread Bengt Richter
On Thu, 07 Jul 2005 22:04:31 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: > >> On Thu, 07 Jul 2005 09:51:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote: >> >>>[EMAIL PROTECTED] (Bengt Richter) writes: >

method for Exception base class to raise the exception in an expression?

2005-07-07 Thread Bengt Richter
method could be nicer once we have Exception as a new-style class. Just a thought. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Bengt Richter
27;] = def(self, args): suite Personally, I think def(args): suite ought to be allowed as an expression that you could put in parentheses like any other expression if you need/want to write it with multiple lines. Obviously this could both replace and expand the functionality of lambda ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditionally implementing __iter__ in new style classes

2005-07-07 Thread Bengt Richter
On Thu, 07 Jul 2005 09:51:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: > >> On Wed, 06 Jul 2005 17:57:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote: >> >>>I'm trying to implement __iter__ on an abstr

Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread Bengt Richter
. >>> iter(Base()) Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over non-sequence >>> iter(Concrete()) >>> list(iter(Concrete())) [1, 2, 3] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: importing pyc from memory?

2005-07-05 Thread Bengt Richter
he single main.pyc IWT, assuming at least that one is used. Chasing various forms of import of non-builtins recursively to eliminate imports in imported modules before they are converted to marshalled form etc., all to avoid real imports, and statically determining that some imports don't need to be converted to marshalled string import form because a prior import can be proved, should be an interesting exercise, which I can't pursue at this point... ;-) But I may be reading too much between the lines ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: importing pyc from memory?

2005-07-04 Thread Bengt Richter
XML, wouldn't he get code objects? And if so, wouldn't he have to execute them in a constructed module dict and be careful of normal imports in the "scripts" etc etc to simulate import? Anyway, it feels like what he wants to do could be done, but "the devil is in the details," which are missing ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: ^ in redirection (windows)

2005-07-04 Thread Bengt Richter
rected to a file, then stdout redirected to same file. Output >goes in a file: >C:\temp>echo hi 2>x.txt 1>&2 > >C:\temp>type x.txt >hi > >Same as above. Using ^ to avoid special interpretation of the & has no >effect: >C:\temp>echo hi 2>x.txt 1>^&

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-03 Thread Bengt Richter
On Mon, 04 Jul 2005 02:50:07 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On Sun, 03 Jul 2005 22:07:30 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: > >>Bengt Richter wrote: >> >> >>class foo(object): >> x = 1 >> y = 2 >> z = 3 >&g

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-03 Thread Bengt Richter
On Sun, 03 Jul 2005 22:07:30 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> What if parameter name syntax were expanded to allow dotted names as binding >> targets in the local scope for the argument or default values? E.g., >> >>

Re: Assigning to None (was Re: Question about Python)

2005-07-03 Thread Bengt Richter
On Mon, 04 Jul 2005 09:11:19 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sun, 03 Jul 2005 19:19:05 +, Bengt Richter wrote: > >> On Sun, 03 Jul 2005 11:47:07 +1000, Steven D'Aprano <[EMAIL PROTECTED]> >> wrote: >> >>>On

Re: Determining actual elapsed (wall-clock) time

2005-07-03 Thread Bengt Richter
o an external time source. For the latter, Peter, you can probably adapt Paul Rubin' setclock.py found at http://www.nightsong.com/phr/python/setclock.py Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-03 Thread Bengt Richter
object that was), even with a body of pass. I'm not sure about foo(self, **{'self.x':0, 'self.y':0}), but if you didn't capture the dict with a **kw formal parameter, IWT you'd have to be consistent and effect the attribute bindings implied. (Just a non-thought-out bf here, not too serious ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Assigning to None (was Re: Question about Python)

2005-07-03 Thread Bengt Richter
ck() ... for i in xrange(10**6): v = None ... t1 = clock() ... for i in xrange(10**6): v = none ... t2 = clock() ... print 't1-t0 = %f, t2=t1 = %f, ratio = %f' %(t1-t0, t2-t1, (t1-t0)/(t2-t1)) ... >>> test() t1-t0 = 0.971914, t2=t1 = 0.766901,

Re: Inheriting from object

2005-07-03 Thread Bengt Richter
On Sat, 02 Jul 2005 12:26:49 -0700, Scott David Daniels <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Thu, 30 Jun 2005 08:54:31 -0700, Scott David Daniels <[EMAIL PROTECTED]> >> wrote: >>>Or, perhaps: >>>class foo(object):

Re: Inheriting from object

2005-07-02 Thread Bengt Richter
On Sat, 02 Jul 2005 14:17:32 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> BTW, there's something about referring to type(self) by its not >> always dependably bound (though usually global) name that bothers me. >> >> I wonder if

Re: Inheriting from object

2005-07-02 Thread Bengt Richter
ichele Simionato may have posted some idea like this early on that I didn't really follow, but maybe my subconscious snagged and garbled ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find Windows "Application data" directory??

2005-07-01 Thread Bengt Richter
way at much messier approaches >than that. It's actually os.environ['APPDATA'] ;-) Hm, which windows is that? Not NT4 ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Better console for Windows?

2005-07-01 Thread Bengt Richter
rolling mode. Seems to work for cmd.exe on NT4 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: turn text lines into a list

2005-06-27 Thread Bengt Richter
= all_names.split() Of course, the lines better not have embedded spaces or they'll be split into several lines. For lines per se, probably I'd do corenames = """\ rb_basic_islamic sq1_pentagonTile sq_arc501Tile sq_arc503Tile """.splitlines() Note the \ to avoid a blank leading line. >>> """\ ... solid ... embedded space ... leading ... trailing ... both ... """.splitlines() ['solid', 'embedded space', ' leading', 'trailing ', ' both '] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Rebindings [was Re: Favorite non-python language trick?]

2005-06-26 Thread Bengt Richter
On Sun, 26 Jun 2005 14:36:42 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 25 Jun 2005 23:08:10 +, Bengt Richter wrote: > >>>Using := and = for assignment and equality is precisely as stupid as using >>>= and == for assignment and equality.

Re: Favorite non-python language trick?

2005-06-26 Thread Bengt Richter
On Sun, 26 Jun 2005 14:30:15 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 25 Jun 2005 23:08:10 +, Bengt Richter wrote: > [...] >> >> The single line replacing >> """ >> with colour do begin >> red := 0

Re: Controlling assignation

2005-06-26 Thread Bengt Richter
On Mon, 13 Jun 2005 15:52:14 +0200, =?ISO-8859-1?Q?Xavier_D=E9coret?= <[EMAIL PROTECTED]> wrote: <...OTT [OT Title] posted text snipped.../> assignation != assignment ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: slicing a bsddb table, eg. for rec in bsddb["AArdvark":"zebra"]: print rec

2005-06-26 Thread Bengt Richter
,z=26,k=11) >>> sd['b':'z'] [2, 11] >>> sd['b':] [2, 11, 26] >>> sd[:'z'] [1, 2, 11] >>> sd['b':'z'] [2, 11] >>> sd['b'] 2 >>> sorted(sd.items()) [('a', 1), ('b', 2), ('k', 11), ('z', 26)] >>> sd['x':'k'] Traceback (most recent call last): File "", line 1, in ? File "", line 8, in __getitem__ KeyError: 'x' >>> sd['x'] Traceback (most recent call last): File "", line 1, in ? File "", line 14, in __getitem__ KeyError: 'x' Hm, None as an actual key might be a little problematical though ;-) I would think this could be a handy way to get data base records that were selected from a range of sorted keys using sql and loading a dict like the above. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest: collecting tests from many modules?

2005-06-26 Thread Bengt Richter
dy. > >The link to the script is http://rafb.net/paste/results/V0y16g97.html. > I think if you execfile a script and supply the global dict initialized to {'__name__':'__main__'} then I think that will satisfy the if __name__ ... condition and the whole thing will run as if executed interactively from the command line. So IWT you could just loop through a list of test modules doing that. Haven't tried it though. E.g., maybe there are nasty reload problems for shared modules among different tests? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python bytecode grammar

2005-06-26 Thread Bengt Richter
ions above. The sources are all there, and there is pure python equivalents for the python run-time compiler (which is (all?) in C I think). Import compiler and parser etc. and poke around. You'll find interesting things ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 304 (was: Re: Any way to not create .pyc files?)

2005-06-26 Thread Bengt Richter
ems. It also lets you switch I/O sources and sinks with mounts that are external to a particular python program being run. Don't know how factorable all that is in python, but I would think the bulk would be changes in os and hopefully pretty transparent elsewhere. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Interpreter-like help in cmd.Cmd

2005-06-26 Thread Bengt Richter
e("%s\n"%str(doc)) return except AttributeError: pass [1] --> self.stdout.write("%s\n"%str(self.nohelp % (arg,))) return func() else: # ... generates topic listing Probably you can write your own Cmd subclass and override do_help and modify at [1] to do the pydoc call as in Peter's snippet. Hopefully no weird interactions, but it should be easy to try ;-) HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: OO approach to decision sequence?

2005-06-25 Thread Bengt Richter
n F Found a Foo Found a U Found an Uhuh Returning info rather than printing to stdout allows you to access and use it differently, e.g., >>> items[3].art_name() ('a', 'Foo') >>> items[3].art_name()[1] 'Foo' (Don't know if the a/an logic is really general ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: trouble subclassing str

2005-06-25 Thread Bengt Richter
print '>%s<' % PaddedStr2('xxx',5,'.') >xxx..< >>> print '>%s<' % PaddedStr2('xxx',3,'.') >xxx< >>> print '>%s<' % PaddedStr2('xxx',2,'.') >xxx< (T

Re: Favorite non-python language trick?

2005-06-25 Thread Bengt Richter
ttribute o.widget.datapoints[o.collector] = o.dispatcher(o.widget.current_value) mywith() Or if we had a lambda-replacing anonymous def permitting full suites: (def(o=myobject): # read a class attribute print o.__class__.myattribute # set an instance attribute o.widget.datapoints[o.collector] = o.dispatcher(o.widget.current_value) )() Is a one-character prefix to the dot objectionable? >> Also avoids those stupid little colons. > >Using := and = for assignment and equality is precisely as stupid as using >= and == for assignment and equality. Perhaps less stupid: why do we use >== for equals, but not ++ for plus and -- for minus? > I agree, but I think := would be nice in python for RE-binding an existing binding, wherever it is seen from the local context. Thus you could write def foo(): x:=123 and x = 456 def bar(): x = 789 foo() # finds and rebinds local x print x bar() # -> 123 print x # -> 456 foo() # finds and rebinds the global x print x # -> 123 but del x foo() #-> NameError exception, can't find any x to rebind hm, wandered a bit OT there, ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie : checking semantics

2005-05-16 Thread Bengt Richter
Python code with block bracketing, please program up a suitable code viewer for them ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: question about the id()

2005-05-16 Thread Bengt Richter
and-optimizes inner loops by hoisting >the bound objection creation, as > >data = [] >data_append = data.append >for x in some_other_data: > work with x to make y > data_append(y) > Sorry about the me-too. I hadn't seen your post. I should know better ;-) Re

Re: question about the id()

2005-05-16 Thread Bengt Richter
ten such an expression, so you will this strategy when people try to squeeze extra performance from their programs. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: question about the id()

2005-05-15 Thread Bengt Richter
und method we saved by binding it to af still is bound to the old method function, so a new dynamically created one is not the same: >>> af.im_func is a2.f.im_func False >>> af.im_func >>> a.f.im_func at 0x02F99B1C> >>> a2.f.im_func at 0x02F99B1C>

Re: Is isinstance always "considered harmful"?

2005-05-15 Thread Bengt Richter
t >has the externally visible effect of degrading performance (to a nullity) >for arguments that the user might reasonably want to work. Agreed, but the key thing there is to define "unnecessarily" ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: string.lstrip stripping too much?

2005-05-15 Thread Bengt Richter
)) >>> print t2 :D\cimsu Note that there is only one of each character in t2 (e.g. 'D' and '\\') And the result is the same for t and t2: >>> s.lstrip(t) 'aniel Lanois\\For the beauty of Wynona' >>> s.lstrip(t2) 'aniel Lanois\\For the beauty of Wynona' If you want to replace an exact prefix, a regex could be a simple way to get the startswith check and replace in one whack. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying a built-in function for logging purposes

2005-05-15 Thread Bengt Richter
as now. Anyway, lots of stuff would become possible... e.g., msys, the MinGW-related shell provides some of this capability, virtualizing windows partitions as /c/* /d/* and so forth, as well as having virtual mounts of various subdir trees. Good night... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-15 Thread Bengt Richter
al speeches ;-) >that doesn't matter, of course, since the tuple is removed by the >garbage collector immediately after it has been unpacked. I'm too tired to figure a humorous segue ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: converting a set into a sorted list

2005-05-15 Thread Bengt Richter
cmp=None, key=None, reverse=False) --> new sorted list > That's plenty of information, but IMO "key=None" doesn't hint strongly enough about what you can do with it, so I'd advise reading about all the parameters ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying a built-in function for logging purposes

2005-05-15 Thread Bengt Richter
f foo(nlines=1): 7: for i, line in enumerate(open(sys.argv[1])):# test default 'r' 8: print '%4s: %s' %(i+1, line.rstrip()) 9: if i+1 >= nlines: break 10: print '< 3 lines of %r' % sys.argv[1] 11: foo(3) 12: <

Re: A new to Python question

2005-05-14 Thread Bengt Richter
', 'tuple'), 'BC', 'Sandra'] >>> a 'A' >>> tup ('a', 'tuple') >>> b 'B' >>> c 'C' >>> d 'Sandra' >>> dis.dis(compile("a, tup, (b,c), d = ['A', ('a', 'tuple'), 'BC', >>> 'Sandra']",'','exec')) 1 0 LOAD_CONST 0 ('A') 3 LOAD_CONST 6 (('a', 'tuple')) 6 LOAD_CONST 3 ('BC') 9 LOAD_CONST 4 ('Sandra') 12 BUILD_LIST 4 15 UNPACK_SEQUENCE 4 18 STORE_NAME 0 (a) 21 STORE_NAME 1 (tup) 24 UNPACK_SEQUENCE 2 27 STORE_NAME 2 (b) 30 STORE_NAME 3 (c) 33 STORE_NAME 4 (d) 36 LOAD_CONST 5 (None) 39 RETURN_VALUE Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread Bengt Richter
omatically. In short, a whole unopened deluxe set of programming Legos is at your elbow, besides the pieces you have encountered so far. Have fun ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread Bengt Richter
and STORE_FAST etc, but you can see what's happening above. I.e., on return from the function call, the returned sequence (we know it's a tuple in your example, but it could be some other sequence thing) is upacked and its elements are bound to the individual names, just as individual "assignments" would do. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find the classname of an object? (was Python Documentation)

2005-05-13 Thread Bengt Richter
On 13 May 2005 14:59:13 -0700, "Matt" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: [...] >> I'm afraid inheriting explicitly from object will make the exception >unraisable. >> Exceptions are still based on "classic" classes for some

Re: How to find the classname of an object? (was Python Documentation)

2005-05-13 Thread Bengt Richter
On 13 May 2005 09:37:07 -0700, "Matt" <[EMAIL PROTECTED]> wrote: > >Christopher J. Bottaro wrote: >> Christopher J. Bottaro wrote: >> >> > Bengt Richter wrote: >> > >> >> >>> type(obj) >> >> >> >>

Re: How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Bengt Richter
found how to do this in a few >> seconds in PHP. I searched the Python docs for "class name", "classname", >> "introspection" and "getclass". I looked in the Class section of the >> tutorial also and also the Programming FAQ. The "

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