Re: dictionary interface

2005-10-06 Thread Bengt Richter
is a total ordering). So I can use whatever >method I want as long as it is achieves this. > >But that is contradicted by the unittest. If you have a unittest for >comparing dictionaries, that means comparing dictionaries has a >testable characteristic and thus is further defined. > >So I don't need a full implementation of dictionary comparison, >I need to know in how far such a comparison is defined and >what I can choose. > A couple of data points that may be of interest: >>> {'a':0j} < {'a':1j} Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= and >>> cmp(0j, 1j) Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= but >>> {'a':0j} == {'a':1j} False >>> {'a':1j} == {'a':1j} True Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Bengt Richter
On 6 Oct 2005 06:44:41 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >Op 2005-10-06, Bengt Richter schreef <[EMAIL PROTECTED]>: >> On 5 Oct 2005 09:27:04 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: >> >>>Antoon Pardon wrote: >>> >>>

Re: updating local()

2005-10-14 Thread Bengt Richter
', 'hey': 'there'} BTW, @presets does not change the signature of the function whose selected locals are being preset from the decoration-time-generated constant, e.g., >>> presets(hey='there')(bar)() Traceback (most recent call last): File "", line 1, in ? TypeError: bar() takes at least 1 argument (0 given) >>> presets(hey='there')(bar)('exx', 'wye') {'y': 'wye', 'x': 'exx', 'hey': 'there'} >>> presets(hey='there')(bar)('exx', 'wye', 'zee') Traceback (most recent call last): File "", line 1, in ? TypeError: bar() takes at most 2 arguments (3 given) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class property (was: Class methods)

2005-10-14 Thread Bengt Richter
. >>> A.x Getting x... 8 >>> vars(A).items() [('__module__', '__main__'), ('__metaclass__', ), ('_x', 8), ('_ _dict__', ), ('__weakref__', ), ('__doc__', None)] >>> A._x 8 >>> vars(A).keys() ['__module__', '__metaclass__', '_x', '__dict__', '__weakref__', '__doc__'] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class property

2005-10-14 Thread Bengt Richter
nt, A.a_cnt (1, 0) >>> A.ratio Getting ratio... 0.0 >>> a=A() >>> A.ratio Getting ratio... 0.5 >>> a=A() >>> A.ratio Getting ratio... 0.3 The old instance is no longer bound, so should it still be counted as it is? You might want to check how to use weak references if not... >>> b2=B() >>> B.ratio Getting ratio... 0.5 >>> b3=B() >>> B.ratio Getting ratio... 0.40002 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-14 Thread Bengt Richter
c use of them could lead to a full-on plate of >spaghetti, where you really wanted code. >They can be impenitrable. Whenever I'm dealing with them in C/C++, I >always line the ?, the :, and the ; characters vertically, which may >seem a bit excessive in terms of whitespace, but provides a nice >hieroglyph over on the right side of the screen, to make things >obvious. >Best, >Chris Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: "no variable or argument declarations are necessary."

2005-10-15 Thread Bengt Richter
id straying into ad hominem irrelevancies. OTOH, I think everyone is entitled at least to ask if a perceived innuendo was real and intentional (and should be encouraged to do so before launching a counter-offence). Sometimes endless niggling and nitpicking gets tiresome, but I don't think that is necessarily troll scat either. And one can always tune out ;-) Anyway, thanks for the pychecker and pylint demos. And I'm glad that we can enjoy your posts again, even if for a limited time. -- Martellibot admirer offering his .02USD for peace ... ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Jargons of Info Tech industry

2005-10-15 Thread Bengt Richter
d email. > >I try to explain Java each day both on my website on the plaintext >only newsgroups. It is so much easier to get my point across in HTML. How about pdf? > >Program listings are much more readable on my website. IMO FOSS pdf could provide all the layout benefits while avoi

Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-15 Thread Bengt Richter
d? >Why is it an "execresence"? > >By the way, dict.org doesn't think "execresence" is a word, >although I interpret the neologism as meaning something like >"execrable utterance": > >dict.org said: >> No definitions found for 'execresence'! > Gotta be something to do with .exe ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Force flushing buffers

2005-10-15 Thread Bengt Richter
>> another name > >Though I will not be using this solution (plan to use flush() explicitly) >for speed reasons, thanks ! I will file this away for future reference :) I suspect Scott's try/finally approach will get you better speed, since it avoids unneeded flush calls and the associated buffer management, but it is best to measure speed when you are concerned. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-15 Thread Bengt Richter
tration" That comes after parents buy some toys for their children, and the children have posession of both the toys and the associated warranty cards. Of course if one is a parent who worries about warranties in a circumstance such as this, "One should be prompt in mailing t

Re: dis.dis question

2005-10-15 Thread Bengt Richter
text() ... >>> diss(foo) ' 1 0 LOAD_FAST0 (x)\n 3 LOAD_CONST 1 (1)\ n 6 BINARY_ADD \n 7 LOAD_CONST 2 (2)\n 10 BINARY_POWER\n 11 RETURN_VALUE\n' >>> print diss(foo) 1 0 LOAD_FAST0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 LOAD_CONST 2 (2) 10 BINARY_POWER 11 RETURN_VALUE Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why asci-only symbols?

2005-10-15 Thread Bengt Richter
to do on the C API (perhaps nothing, perhaps > allowing UTF-8) Perhaps string equivalence in keys will be treated like numeric equivalence? I.e., a key/name representation is established by the initial key/name binding, but values can be retrieved by "equivalent" key/names with diff

Re: Function to execute only once

2005-10-16 Thread Bengt Richter
d does what you want, you need a callable that can remember state one way or another. A callable could be a function with a mutable closure variable or possibly a function attribute as shown in other posts in the thread, or maybe a class bound method or class method, or even an abused met

Re: Jargons of Info Tech industry

2005-10-16 Thread Bengt Richter
On 16 Oct 2005 00:31:38 GMT, John Bokma <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) wrote: > >> On Tue, 04 Oct 2005 17:14:45 GMT, Roedy Green >> <[EMAIL PROTECTED]> wrote: >> >>>On Tue, 23 Aug 2005 08:32:09 -0500, l v <[EMAIL

Re: Why asci-only symbols?

2005-10-16 Thread Bengt Richter
On Sun, 16 Oct 2005 12:16:58 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Perhaps string equivalence in keys will be treated like numeric equivalence? >> I.e., a key/name representation is established by the initial

Re: override a property

2005-10-17 Thread Bengt Richter
ith a "wish I could here" comment line? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: override a property

2005-10-17 Thread Bengt Richter
e a managed attribute x: | class C(object): | def getx(self): return self.__x | def setx(self, value): self.__x = value | def delx(self): del self.__x | x = property(getx, setx, delx, "I'm the 'x' property.") | Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why asci-only symbols?

2005-10-17 Thread Bengt Richter
On Tue, 18 Oct 2005 01:34:09 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Well, what will be assumed about name after the lines >> >> #-*- coding: latin1 -*- >> name = 'Martin Löwis' >>

Re: How to add one month to datetime?

2005-10-21 Thread Bengt Richter
ll still have to decide whether he likes the semantics ;-) E.g., what does he really want as the date for "one month" after January 30 ? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: override a property

2005-10-21 Thread Bengt Richter
functionality in some helper thing ;-) >b.x = 7 With the above mods put in becker.py, I get: >>> import becker obs0 _x 3 obs0 _x 4 obs1 _x 7 But adding another observer doesn't eliminate the other(s): >>> def obs3(inst,pName,value): ... print 'obs3', inst, pName, value ... >>> becker.A.x.add(obs3) >>> becker.b.x = 777 obs1 _x 777 obs3 _x 777 >>> becker.a.x = 777 obs0 _x 777 obs3 _x 777 HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: coloring a complex number

2005-10-21 Thread Bengt Richter
e asset of the depth and breadth of Python archives >> - for learning (and teaching) and real world production - should not be >> underestimated, IMO. I could be confident if there was an answer to >> getting the functionality I was looking for as above, it would be found >> easily enough by a google search. It is only with the major >> technologies that one can hope to pose a question of almost any kind to >> google and get the kind of relevant hits one gets when doing a Python >> related search. Python is certainly a major technology, in that >> respect. As these archives serve as an extension to the documentation, >> the body of Python documentation is beyond any normal expectation. >> >> True, this asset is generally better for answers than explanations. >> >> I got the answer I needed. Pursuing here some explanation of that answer. >> HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: namespace dictionaries ok?

2005-10-24 Thread Bengt Richter
lf, name): ... self.__delitem__(name) ... def __repr__(self): ... return 'Context(%s)' % ', '.join('%s=%r'% t for t in sorted(self.items())) ... >>> print Context(color='red', size='large', shape='ball') Context(color='red', shape='ball', size='large') >>> ctx = Context(color='red', size='large', shape='ball') >>> print ctx Context(color='red', shape='ball', size='large') >>> ctx Context(color='red', shape='ball', size='large') >>> ctx.color 'red' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntax across languages

2005-10-25 Thread Bengt Richter
Borland Delphi Object Pascal: """ The following constructs are comments and are ignored by the compiler: { Any text not containing right brace } (* Any text not containing star/right parenthesis *) A comment that contains a dollar sign ($) immediately after the opening { or (* is a /compiler directive/. A mnemonic of the compiler command follows the $ character. """ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Tricky Areas in Python

2005-10-25 Thread Bengt Richter
y: >>> class Sic: ... def getFoo(self): ... print "GET" ... return "FOO" ... def setFoo(self, value): ... print "SET", value ... def delFoo(self): ... print "DEL" ... foo = property(getFoo, setFoo, delFoo) ... >>> sic = Sic() >>> print sic.foo GET FOO >>> sic.foo = 10 >>> print sic.foo 10 >>> del sic.foo >>> print sic.foo GET FOO but it won't go beyond the instance for del foo >>> del sic.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: Sic instance has no attribute 'foo' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Tricky import question.

2005-10-25 Thread Bengt Richter
was called. If you wanted to make your code work, perhaps replacing (untested) __import__(f2) with exec '%s = __import__(f2)'%f2 # bind imported module to name specified by f2 string might have got by the error in eval (c), but I suspect you would want to leave the () off the .main in any case. And why go through all that rigamarole? > >TIA. > Try it both ways and report back what you found out ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Tricky import question.

2005-10-25 Thread Bengt Richter
return mod > >for reasons given here... > >http://www.python.org/doc/2.3.5/lib/built-in-funcs.html > Aha. You didn't mention multi-dot names ;-) But was that the real problem? Your original code wasn't using anything corresponding to mod above. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: namespace dictionaries ok?

2005-10-25 Thread Bengt Richter
x27; >value = 25 >foo( name=name, position=position ) > Just had the thought that if you want to add bindings on the fly modifying the original object, you could use the __call__ method, e.g., >>> class NameSpace(dict): ... __getattr__ = dict.__getitem__ ... __setattr__ = dict.__setitem__ ... __delattr__ = dict.__delitem__ ... def __call__(self, **upd): ... self.update(upd) ... return self ... >>> def show(x): print '-- showing %r'%x; return x ... >>> ns = NameSpace(initial=1) >>> show(ns) -- showing {'initial': 1} {'initial': 1} And updating with a second keyword on the fly: >>> show(show(ns)(second=2)) -- showing {'initial': 1} -- showing {'second': 2, 'initial': 1} {'second': 2, 'initial': 1} FWIW ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Log rolling question

2005-10-25 Thread Bengt Richter
that does date interval addition/subtraction, but it didn't come with the batteries in my version. BTW, make sure all your date stuff is using the same epoch base date, in case you have some odd variant source of numerically encoded dates, e.g., look at >>> import time >>

Re: Read/Write from/to a process

2005-10-25 Thread Bengt Richter
esetEvent SetEvent WaitForMultipleObjects WaitForMultipleObjectsEx WaitForSingleObject WaitForSingleObjectEx BTW, """ The CreateFile function creates, opens, or truncates a file, pipe, communications resource, disk device, or console. It returns a handle that can be used to access the

Re: [OT] Re: output from external commands

2005-10-25 Thread Bengt Richter
.glob is already >guaranteed to be strings, so using either '%s'%f or str(f) is superfluous. > And so is a listcomp that only reproduces the list returned by glob.glob -- especially by iterating through that same returned list ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: feature request / max size limit on StringIO

2005-10-25 Thread Bengt Richter
simple a job of buffering as you might think. Maybe you'll want to wrap a byte array or an mmap instance to store your info, depending on what you are doing? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Setting Class Attributes

2005-10-25 Thread Bengt Richter
dict. Nothing to do with optimization. In fact, re-using the shared default dict would be faster, though of course generally wrong. > >Worked like a charm, Thanks! > Just wanted to make sure you realize why it made a difference, in case ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Making "import" *SLIGHTLY* more verbose?

2005-10-25 Thread Bengt Richter
xample code that might be useful. I'm suspicious of the default values you provide in your noisy_import though. They are all mutable, though I guess nothing should mutate them. But will they be valid for all the contexts your hook will be invoked from? (Or are they actually useless and always overridden?) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Would there be support for a more general cmp/__cmp__

2005-10-27 Thread Bengt Richter
'__gt__'; return NotImplemented ...def __coerce__(*ignore): print '__coerce__'; return NotImplemented ...def __cmp__(*ignore): print '__cmp__'; return NotImplemented ... >>> sorted((D(),D())) __lt__ __gt__ __cmp__ __cmp__ (I haven't followed the t

Re: Double replace or single re.sub?

2005-10-27 Thread Bengt Richter
27 LOAD_CONST 5 ('face') 30 CALL_FUNCTION2 33 STORE_FAST 0 (newPhrase) 36 LOAD_CONST 0 (None) 39 RETURN_VALUE Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to replace all None values with the string "Null" in a dictionary

2005-10-27 Thread Bengt Richter
>>> mydict = dict(a=1, b=None, c=3, d=None, e=5) >>> mydict {'a': 1, 'c': 3, 'b': None, 'e': 5, 'd': None} >>> mydict.update((k,'Null') for k,v in mydict.items() if v is None) >>> mydict {'a': 1, 'c': 3, 'b': 'Null', 'e': 5, 'd': 'Null'} (too lazy to measure ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-29 Thread Bengt Richter
;> s.count('0010') 1 vs. brute force counting overlapped substrings (not tested beyond what you see ;-) >>> def ovcount(s, sub): ... start = count = 0 ... while True: ... start = s.find(sub, start) + 1 ... if start==0: break ... count += 1 ...

Re: Scanning a file

2005-10-29 Thread Bengt Richter
en(whatever, 'b') >count = 0 >for block in byblocks(f, 1024*1024, len(subst)-1): >count += block.count(subst) >f.close() > >not much "fiddling" needed, as you can see, and what little "fiddling" >is needed is entirely encompassed by the generator... > Do I get a job at google if I find something wrong with the above? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-29 Thread Bengt Richter
On Sat, 29 Oct 2005 10:34:24 +0200, Peter Otten <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> On Fri, 28 Oct 2005 20:03:17 -0700, [EMAIL PROTECTED] (Alex Martelli) >> wrote: >> >>>Mike Meyer <[EMAIL PROTECTED]> wrote: >>> ... >

Re: How do I sort these?

2005-10-29 Thread Bengt Richter
, 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] Now the zipped sort unzipped: >>> zip(*sorted(zip(first,second))) [(1, 1, 1, 1, 1, 2, 2, 2, 2, 2), ('A', 'B', 'C', 'D', 'E

Re: How do I sort these?

2005-10-30 Thread Bengt Richter
On Sun, 30 Oct 2005 10:13:42 +0100, Peter Otten <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > [...] >> Now select from the second list, by first-element position correspondence: >> >>> [second[t[1]] for t in sorted((f,i) for i,f in enumerate(first))] >

Re: Scanning a file

2005-10-30 Thread Bengt Richter
On Sat, 29 Oct 2005 21:10:11 +0100, Steve Holden <[EMAIL PROTECTED]> wrote: >Peter Otten wrote: >> Bengt Richter wrote: >> >> >>>What struck me was >>> >>> >>>>>> gen = byblocks(StringIO.StringIO('no'),1024,le

Re: Controlling output using print with format string

2005-10-30 Thread Bengt Richter
gt; for c in s: ... nc = printf('%1c', c) ... now is the time>>> Just to show multiple args, you could pass all the characters separately, but at once, e.g., (of course you need a format to match) >>> printf('%s'*len(s)+'\n', *s) now is the t

Re: Scanning a file

2005-10-31 Thread Bengt Richter
ve gone differently if the title had been "How to count frames in an MPEG2 file?" and the OP had supplied the info about what marks a frame and whether it is guaranteed not to occur in the data ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-31 Thread Bengt Richter
On Mon, 31 Oct 2005 09:19:10 +0100, Peter Otten <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> I still smelled a bug in the counting of substring in the overlap region, >> and you motivated me to find it (obvious in hindsight, but aren't most ;-) >> >

Re: frozenset/subclassing/keyword args

2005-10-31 Thread Bengt Richter
__new__ method too (by temporarily binding the instance returned by frozenset.__new__ and assigning the name attribute before returning the instance), or you can define __init__ to do that part. See many various posted examples of subclassing immutable types. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Reuse base-class implementation of classmethod?

2005-10-31 Thread Bengt Richter
t): ... @funnycm ... def foo(cls, a, b): ... print cls, a, b # do something ... >>> class B(A): ... pass # just inherit ... >>> a=A() >>> a.foo(1,2) 1 2 >>> b=B() >>> b.foo(1,2) 1 2 >>> A.foo(3,4) 3 4

Re: Running autogenerated code in another python instance

2005-11-02 Thread Bengt Richter
thon might help, with some idea of the kind of visualization aspects being controlled ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

With & marcos via import hooking? (Was Re: Scanning a file)

2005-11-02 Thread Bengt Richter
t hooking and could one rewrite sys.argv so the special import command line opts would not be visible to subsequent processing (and the import hook would be in effect)? IWT so, but probably should read site.py again and figure it out, but appreciate any hints on pitfalls ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: expanding dictionary to function arguments

2005-11-02 Thread Bengt Richter
rgname in argnames if argname not in args]) return func(*actualargs) _f.func_name = func.func_name return _f and then wrap like extract_audio = call_with_args_from_dict(extract_audio) or use as a decorator if you are defining the function to be wrapped, e.g., @call_with_args_from_dict def mux(firstarg, second, etc): ... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Most efficient way of storing 1024*1024 bits

2005-11-02 Thread Bengt Richter
t-set. > Very dependent on what kind of "searches" -- e.g., 1024*1024 suggests the possibility of two dimensions. Quad-trees? How sparse is the data? Etc. What kinds of patterns are you going to search for? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Hexadecimal Conversion in Python

2005-11-02 Thread Bengt Richter
re very very good at descriptions, it's hard to beat presentation of machine representations of what you are talking about ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Hexadecimal Conversion in Python

2005-11-02 Thread Bengt Richter
t ''.join(chr(48+((ord(c)>>b)&1)) for b in xrange(7,-1,- 1)), ... 0101 0110 0111 00110001 00110010 00110011 00101110 00101110 00101110 0001 0010 0011 (cf. 41 42 42 etc above) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a function name from string

2005-11-03 Thread Bengt Richter
ecent call last): > File "", line 1, in ? > File "", line 2, in fn2 >KeyError: 'fn' >>>> > >Using globals() in this case will work, but then won't find functions >defined in the local name space. > >For a lot of uses, it'd be better to build the dictionary by hand >rather than relying on one of the tools that turns a namespace into a >dictionary. IMO it would be nice if name lookup were as cleanly controllable and defined as attribute/method lookup. Is it a topic for py3k? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Anomaly in creating class methods

2005-11-03 Thread Bengt Richter
during the execution of the body of the class definition, where classmethod was called. The function will have no demands except to match its signature when the classmethod descriptor instance calls it with first arg of D. >>> D.f > >>> D.f() __main__.D You could extract t

Re: Class Variable Access and Assignment

2005-11-03 Thread Bengt Richter
scope, but lookahead determines that a is local to inner, period, so that is the reference that is used (and fails). >>> def outer(): ... a = 1 ... def inner(): ... a += 2 ... print a ... print 'outer a', a ... inner() ... print 'outer a', a ... >>> outer() outer a 1 Traceback (most recent call last): File "", line 1, in ? File "", line 7, in outer File "", line 4, in inner UnboundLocalError: local variable 'a' referenced before assignment Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Not Equal to Each Other?

2005-11-03 Thread Bengt Richter
rd)) 7 So the test would be >>> len(set(cellboard))==len(cellboard) False And after repairing the list to uniqueness of elements: >>> cellboard[2] = 2 >>> len(set(cellboard))==len(cellboard) True HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
;-) OTOH, is suppose a function could have a reseved slot for a name space object stack that wouldn't cost much run time to bypass with a machine language check for NULL. BTW2, this kind of stack might play well with a future "with," to guarantee name space popping. Perhaps "with" syntax could even be extended to make typical usage slick ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
to spell "find x and rebind it to expr" (or raise NameError if not found). Extending that to attributes and augassign, b.a +:= 2 could mean find the "a" attribute, and in whatever attribute dict it's found, rebind it there. Or raise an Exception for whatever failure is encountered. This would be nice for rebinding closure variables as well. But it's been discussed, like most of these things ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
l what happens, pretty much in as much detail as you can describe requirements ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
e was the global "a" because a local "a" hadn't been defined until the assignment, which worked to produce a local binding of "a". Personally, I like that better than the current way, because it follows the order of accesses implied by the precedences in expression evaluation and statement execution. But maybe I don't RC ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
e prevented' >>> b.a 'instance attr' >>> B.a 'this could be prevented' The spelled out attribute update works too >>> B.a = shared('alpha') >>> b.a 'alpha' >>> b.a = b.a + ' beta' >>> b.a 'alpha beta' >>> B.a 'alpha beta' But the instance attribute we forced is still there >>> vars(b) {'a': 'instance attr'} You could have shared define __add__ and __iadd__ and __radd__ also, for confusion to taste ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
;Small correction, it expands to b.a = B.a.__class__.__iadd__(b.a,2), >assuming all relevant quantities are defined. For integers, you're >perfectly right. But before you get to that, a (possibly inherited) type(b).a better not have a __get__ method trumping __class__ and the rest ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
On 04 Nov 2005 17:53:34 -0800, Paul Rubin <http://[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >> Hm, "the" fix? Why wouldn't e.g. treating augassign as shorthand for >> a source transformation (i.e., asstgt = expr becomes by simple

Re: Class Variable Access and Assignment

2005-11-04 Thread Bengt Richter
bject that just happens to define >__iadd__(self,type(other) == int). But if it is an esoteric descriptor (or even a simple property, which is a descriptor), the behaviour will depend on the descriptor, and an instance variable can be created or not, as desired, along with any side effect you like. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-05 Thread Bengt Richter
On Fri, 04 Nov 2005 21:14:17 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >> On Thu, 03 Nov 2005 13:37:08 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >> [...] >>>> I think it even less sane, if the same occu

Re: Class Variable Access and Assignment

2005-11-05 Thread Bengt Richter
On Sat, 05 Nov 2005 14:37:19 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 05 Nov 2005 00:25:34 +, Bengt Richter wrote: > >> On Fri, 04 Nov 2005 02:59:35 +1100, Steven D'Aprano <[EMAIL PROTECTED]> >> wrote: >> >>>

Re: re sub help

2005-11-05 Thread Bengt Richter
#x27;, '[startdelim]', 'this\nis\nanother', '[enddelim]', 'this\nis\n\n33 \n4\n', '[startdelim]', '\n77\n888', '[enddelim]', '\n00\n'] Which had the replacing when not i%4 was true >>> for i,s in enumerate(sp): print '%6s: %r'%(not i%4,s) ... True: 'this\nis\na\nsentence' False: '[startdelim]' False: 'this\nis\nanother' False: '[enddelim]' True: 'this\nis\n\n33\n4\n' False: '[startdelim]' False: '\n77\n888' False: '[enddelim]' True: '\n00\n' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-06 Thread Bengt Richter
r of: > >def function(value=[]): >value.append(None) IMO that's not a wart at all, that's a direct design decision, and it's different from the dual referencing that happens in Scenario 4. > >I can live with that. It is a familiar wart, and keeps inheritance of >attributes working the right way. And who knows? If your attributes are >mutable, AND you want Antoon's behaviour, then you get it for free just by >using b.a += 1 instead of b.a = b.a + 1. Not quite, because there is no way to avoid the binding of the __iadd__ return value to b.a by effective setattr (unless you make type(b).a a descriptor that intercepts the attempt -- see another post for example). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python doc problem example: gzip module (reprise)

2005-11-06 Thread Bengt Richter
27;s not complete, but it's quite useful and pretty easy to use. Hm, seems to be updated since I downloaded a copy, guess I'll grab the newest ;-) Hm2, it doubled in size! The creation dates are *** FILE tkinter.pdf *** /CreationDate (D:20030416170500) *** FILE tkinter2.pdf *** /CreationDate (D:20050803114234) So I guess it could double in 2 years 4 months. I'll have to look into it. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't instantiate class

2005-11-06 Thread Bengt Richter
d. (And look for bare except: clauses or other exception handling that might be throwing away a DataUtil definition exception). HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-06 Thread Bengt Richter
On Sun, 06 Nov 2005 12:23:02 -0500, Christopher Subich <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Fri, 04 Nov 2005 10:28:52 -0500, Christopher Subich <[EMAIL PROTECTED]> >> wrote: > >>>is very much within the language specification. Indeed,

Re: Running autogenerated code in another python instance

2005-11-06 Thread Bengt Richter
On Thu, 03 Nov 2005 14:23:53 +1000, Paul Cochrane <[EMAIL PROTECTED]> wrote: >On Wed, 02 Nov 2005 06:33:28 +0000, Bengt Richter wrote: > >> On Wed, 2 Nov 2005 06:08:22 + (UTC), Paul Cochrane <[EMAIL PROTECTED]> >> wrote: >> >>>Hi all, >>

Re: Class Variable Access and Assignment

2005-11-07 Thread Bengt Richter
pursuit of quantum nits ;-) I suspect we all experience the emotions relevant to being misunderstood; we just stop at different nit granularities (modulo horn locking ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-07 Thread Bengt Richter
t; management and development of Python is dynamic and fairly >> open-minded. If there had been an obvious way to change this >> in a way that solved more problems than it caused, I suspect >> that change would have happened already. > >Fine I can live with that. > A

Re: Threading-> Stopping

2005-11-07 Thread Bengt Richter
pretty effective. But this is a social engineering problem more than technical ;-) BTW, would such a thing appropriately be defined in a process PEP? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: struct.calcsize problem

2005-11-07 Thread Bengt Richter
, standard alignment >>> struct.calcsize('>'+hdrFormat) 590 Network (big endian), standard alignment: >>> struct.calcsize('!'+hdrFormat) 590 I guess if you want alignment for anything non-native, you have to specify pad bytes where you need them (with x format character). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression question -- exclude substring

2005-11-07 Thread Bengt Richter
.. >>> list(findit(s)) ['00 target 01'] >>> s2 = s + ' garbage noise3 00 almost 01 target_mark 00 success 01 >>> target_mark' >>> list(findit(s2)) ['00 target 01', '00 success 01'] (I didn't enforce exact adjacency the first time, obviously it would be more efficient to search for end+tmk instead of tmk and back to beg and forward to end ;-) If there can be spurious target_marks, and tricky matching spans, additional logic may be needed. Too lazy to think about it ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: overloading *something

2005-11-08 Thread Bengt Richter
= bob(8) >py> list(b) >[0, 1, 2, 3, 4, 5, 6, 7] >py> doit(*b) >(0, 1, 2, 3, 4, 5, 6, 7) > I think you can also just define __getitem__ if that's handier. E.g., >>> class MyClass(object): ... def __init__(self, limit=1): self.limit=limit ... def __getitem__(self, i): ... if i < self.limit: return i**3 ... raise StopIteration ... >>> myobj = MyClass(5) >>> list(myobj) [0, 1, 8, 27, 64] >>> list(MyClass(10)) [0, 1, 8, 27, 64, 125, 216, 343, 512, 729] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.getmtime on winXP

2005-11-08 Thread Bengt Richter
d you format the number you got from os.path.getmtime? You might want to try some of the above. If you actually created/modified files just before and after the DST change and saw an extra hour difference instead of the time between the two actions, then maybe I'd look into whether the

Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
gt;> ref["foo"] =42 >>> ref['bar'] = 'Ni!' >>> ref {'foo': 42, 'bar': 'Ni!', 'key': "key's value"} >>> ref['key'] "key's value" >>> ref['bar'] 'Ni!' >>> del ref['key'] >>> ref {'foo': 42, 'bar': 'Ni!'} FWIW ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
123 >>> lst[42]['pos'] 123 >>> id(lst[42]['pos']) 49421860 >>> id(a) 49421860 IOW, a is now an alias for the same 123 immutable integer object as is referred to by the 'pos' key in the dict which is the 43rd element (index 42) of lst. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.getmtime on winXP

2005-11-08 Thread Bengt Richter
On Tue, 08 Nov 2005 10:49:56 +0100, =?ISO-8859-1?Q?Jorg_R=F8dsj=F8?= <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> How did you format the number you got from os.path.getmtime? > >I'm not doing any formating at all. I am just looking at the numbers of >secon

Re: os.path.getmtime on winXP

2005-11-08 Thread Bengt Richter
On Tue, 08 Nov 2005 13:33:12 +0100, =?ISO-8859-1?Q?Jorg_R=F8dsj=F8?= <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> By 'getmtime' you mean os.path.getmtime(fer_shure_or_absolute_path_to_file) >> right? >> Doesn't that get you an integer n

Re: How to convert a number to hex number?

2005-11-08 Thread Bengt Richter
x(33**33). Not to mention ([EMAIL PROTECTED] deleted ;-) >>> hex(-255)[2:] 'xff' >>> hex(-255) '-0xff' >>> hex(-255&0xff) '0x1' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: which feature of python do you like most?

2005-11-08 Thread Bengt Richter
und cows might not be good for production. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to convert a number to hex number?

2005-11-08 Thread Bengt Richter
On Wed, 09 Nov 2005 00:42:45 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: > > >Bengt Richter wrote: >> On 08 Nov 2005 08:07:34 -0800, Paul Rubin <http://[EMAIL PROTECTED]> wrote: >> >> >>>"dcrespo" <[EMAIL PROTECTED]> writes: >>&

Re: [ x for x in xrange(10) when p(x) ]

2005-11-10 Thread Bengt Richter
stop()" > >but when I have a number of them in the same expression, the >takewhile/dropwhile becomes to add up. If you don't like Alex'(s?) good advice, you can continue bracketed expressions on several lines, and indent and group for clarity. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to set program name in Python? ($0 in Perl)

2005-11-10 Thread Bengt Richter
rgv[0] doesn't *set* it (afaik). > >setting the name involves overwriting the C level argv array, several large >buckets of worms, and huge portability issues, and is thus better left to non- >standard extensions. > OTOH, if the intent is just to set a value for subsequent ge

Re: Recompile AST?

2005-11-10 Thread Bengt Richter
latest version, but I haven't got the new version. I really must clean up my disk for space ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to set program name in Python? ($0 in Perl)

2005-11-10 Thread Bengt Richter
On Thu, 10 Nov 2005 23:29:28 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> >> > Is there a way to set the program name in Python, similar to $0 in >> >> > Perl? >> >> > >> >> >&

Re: Recompile AST?

2005-11-10 Thread Bengt Richter
On 10 Nov 2005 16:07:56 -0800, "Paul Boddie" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> I've also posted sporadic musings about the possibilities for >> AST-transforming >> custom import functions to do optimizations and macros and special

Re: Command-line tool able to take multiple commands at one time?

2005-11-11 Thread Bengt Richter
u can do tsehe two thgnis in paellarl. Not to menotin emxteerly fblleixe pistisibleios of mpipang keys or kqs-ycuns to aosmlt annhytig inmgibalae, if you wnat to go bnyoed pilan vlnaila. E.g., nnoi-csudvttere rteluss in a spilt wdionw is neicr. (last paragraph filtered through scramble and a paragraph-justifying script specifying 8 margin 40 wide and justify to both edges ;-) So what platform are you on? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [ x for x in xrange(10) when p(x) ]

2005-11-11 Thread Bengt Richter
On 10 Nov 2005 18:20:01 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> If you want to terminate a generator expression after the first sequence of >> elements >> satisfying a condition, and you don't want to use

Re: Change directory not successfully done

2005-11-11 Thread Bengt Richter
t; C:\pywk Check effect >>> os.getcwd() 'C:\\pywk' Seems like it worked. But note: (BTW we now have to specify the old subdirectory from current working dir in order to reach mycd.py ;-) >>> os.system('py24 grammar\\mycd.py') changing cwd C:\pywk to parent => C:\ 0 >>> os.getcwd() 'C:\\pywk' I.e., changed but thrown away with subprocess Does this help? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [ x for x in xrange(10) when p(x) ]

2005-11-11 Thread Bengt Richter
5 or stop() for y in xrange(20) if >>> y<3 or stop())) [(0, 0), (0, 1), (0, 2)] >>> list( ((x,y) for x in xrange(20) if x<5 or stop() for y in (y for y in >>> xrange(20) if y<3 or stop( [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), (3, 0), (3, 1), (3, 2), (4, 0), (4, 1), (4, 2)] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: help make it faster please

2005-11-11 Thread Bengt Richter
print word, freq > >create_words(file("test.txt")) > > >If you can load the whole file in memory then it can be made a little >faster... > >Bear hugs, >bearophile > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: list of lambda

2005-11-11 Thread Bengt Richter
=x.upper():x for x in ['a', 'b', 'c']] >>> l = [lambda x=x.upper():x for x in ['a', 'b', 'c']] >>> for lamb in l: print lamb.func_defaults[0],'=?=',lamb() ... A =?= A B =?= B C =?= C Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: list of lambda

2005-11-11 Thread Bengt Richter
r.__self__ 'a' >>> str.upper That's the unbound method. If we bind it to 'a' in the usual way behind inst.method, >>> type('a') >>> type('a').__dict__ >>> type('a').__dict__['upper'] >>> type('a').__dict__['upper'].__get__('a', type('a')) Or >>> str.upper.__get__('a', str) we get the bound method. So the clue is "... of str objects" vs ".. of str object at ..." Maybe nicer would be Same if it's inherited: >>> class S(str): pass ... >>> S('a').upper >>> S('a').upper() 'A' But if we override, we get 'bound method ...' >>> class S(str): ... def upper(self): return 'S.upper => %r' % str.upper(self) ... >>> S('a').upper >>> S('a').upper() "S.upper => 'A'" A nit. I thought it clever to replace the lambda with the the bound method, but while supplying a callable, it still postpones the upper execution, and will repeat it for each call, whereas lambda x=x.upper():x does the work once up front (in general not always possible, of course). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

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