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

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

2005-11-12 Thread Bengt Richter
://groups.google.com/group/comp.lang.python/browse_thread/thread/41495e4f5d3e1c2a/84c158ff18d08ece#84c158ff18d08ece It probably stuck subconsciously in my mind and just came back when I wanted a StopIteration expression for terminating a generator expression. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: help make it faster please

2005-11-12 Thread Bengt Richter
On Sat, 12 Nov 2005 10:46:53 +0100, Sybren Stuvel <[EMAIL PROTECTED]> wrote: >Bengt Richter enlightened us with: >> I suspect it's not possible to get '' in the list from >> somestring.split() > >Time to adjust your suspicions: > >>>>

Re: about try statement

2005-11-12 Thread Bengt Richter
. try: return 1/den ... finally: print 'exception can not bypass finally' ... except Exception, e: ... print '%s: %s' %(e.__class__.__name__, e) ... return 'succeeded in returning something' ... >>> foo(0) exception

Re: Hash map with multiple keys per value ?

2005-11-12 Thread Bengt Richter
lpha', 'b': 'alpha', 'e': 'alpha', 'd': 'alpha'} >>> ad['b'] {'a': 'alpha', 'c': 'alpha', 'e': 'alpha', 'd': 'alpha'} And since an Al

Re: weird problem with os.chmod

2005-11-12 Thread Bengt Richter
ligt, men det gar bra pa Svenska om det ar omogligt at oversatta ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-12 Thread Bengt Richter
e deprecated and repurposed. It could typographically serve nicely as a lisp quote then. But in python, how would 'whatever be different from lambda:whatever ? (where of course whatever could be any expression parenthesized as necessary) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterator addition

2005-11-13 Thread Bengt Richter
t blank-separated expressions, but nothing parens couldn't overcome, IWT. Built-in operators with symbols such as +, -, *, / etc. would of course not be treated as as objects in the above sense. I.e., even if expr1 had a __unaryop__ method, expr1 - expr2 could not become expr1.__unaryop__(-expr2) unless you forced the issue with expr1 (-expr2) Ok, this should be fun ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Multikey Dict?

2005-11-13 Thread Bengt Richter
only if you need to extend with new field names. > >Also, I would like if I didn't have to keep the key data both in the >dict of dicts and in the dicts :) IIUC I guess you don't have to. > >If I could just say to Python: john and graham (and ...) are all a part >of a

Re: Iterator addition

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 17:28:59 -0600, [EMAIL PROTECTED] wrote: [...] > >On Sun, Nov 13, 2005 at 09:44:43PM +, Bengt Richter wrote: >> even if expr1 had a __unaryop__ method, >> expr1 - expr2 >> could not become >> expr1.__unaryop__(-expr2) >> unless yo

Re: Hash map with multiple keys per value ?

2005-11-13 Thread Bengt Richter
. Usually it's only a matter of minutes, not a day and counting ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-14 Thread Bengt Richter
ld result in [7, 5] > >-- You may be interested in reviewing http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3 before continuing this topic ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying small chunks from long string

2005-11-14 Thread Bengt Richter
orter string in place... > I imagine you should be able to change a very few lines to switch between ways of getting your input stream of editable chunks and accumulating your output. OTOH, this is all guesswork without more context ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-14 Thread Bengt Richter
ns.x = 'x value' >>> ptr = ns['x'] >>> ptr[:] 'x value' Now make a function that will use the pointer >>> def set(p, v): ... p[:] = v ... >>> set(ptr, 123) Check indirect result >>> ns.x 123 >>> ptr[:] 123 >>> ptr[:] += 321 >>> ns.x 444 Pseudo-value-semantics: >>> from ns_horne import NSHorne >>> ns = NSHorne() >>> ns.z = [1,2] >>> pz = ns['z'] >>> pz[:] [1, 2] >>> ns.z2 = pz[:] >>> ns.z [1, 2] >>> ns.z2 [1, 2] >>> pz[:][0]='z via pz' >>> ns.z ['z via pz', 2] >>> ns.z2 [1, 2] >>> pz[:] ['z via pz', 2] Or value semantics without confusing with pointer stuff: >>> ns.z3 = ns.z2 now equal values, but not the same objects: >>> ns.z3, ns.z2 ([1, 2], [1, 2]) >>> ns.z2[1]='z2 via ns.z2' >>> ns.z3 [1, 2] >>> ns.z2 [1, 'z2 via ns.z2'] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-15 Thread Bengt Richter
On 15 Nov 2005 08:51:59 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >Op 2005-11-14, Bengt Richter schreef <[EMAIL PROTECTED]>: [...] >> You may be interested in reviewing >> >> >> http://groups.google.com/group/comp.lang.python/browse_thread/

Re: Addressing the last element of a list

2005-11-15 Thread Bengt Richter
On Tue, 15 Nov 2005 03:23:11 -0600, Chris Mellon <[EMAIL PROTECTED]> wrote: >On 11/14/05, Bengt Richter <[EMAIL PROTECTED]> wrote: [...] >> You may be interested in reviewing >> >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/=

Re: Proposal for adding symbols within Python

2005-11-15 Thread Bengt Richter
quot;", line 1, in ? AttributeError: can't set attribute One could also write a more efficient write-once guarantee for function scope using a decorator that munges byte code to guarantee it. Or one could write a custom import that guarantees it for module scope. Or one could change the language ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing multiple instances of commas beginning at specific position

2005-11-15 Thread Bengt Richter
data = """\ ... one, two, threefourADMNSRC, fivesix ... one, two, three,fourADMNSRC,,eighteen, and so on ... """ >>> import re >>> rxc = re.compile(',+') >>> result = ',,,ADMNSRC'.join(','.join(rxc.split(s)) for s in >>> data.split(',,,ADMNSRC')) >>> print result one, two, three,fourADMNSRC, five,six one, two, three,fourADMNSRC,eighteen, and so on Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse file into array

2005-11-15 Thread Bengt Richter
x27;image/jpeg' Or you could substitute the mimetypedict expression from above to make another one-liner ;-) Other ways of setting up your info are certainly possible, and may be more suitable, depending on how you intend to use the info. As mentioned, the mimetypes module may already have much of the data and/or functionality you want. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: compare list

2005-11-15 Thread Bengt Richter
... >>> lisCheck(lisA, lisB) True >>> lisCheck(lisA, lisC) True >>> lisCheck(lisB, lisC) True >>> lisCheck(lisB, [5,3,6]) False >>> lisCheck([1,2,2,3], [2,2]) True >>> lisCheck([1,2,2,3,3], [2,2]) True >>> lisCheck([1,2,2,3,3],

Re: Default method arguments

2005-11-15 Thread Bengt Richter
cope. That prevents >> somebody from the outside scope easily passing _marker as an argument to >> instance.f. > >if you don't want people to be able to easily pass _marker as an argument >to the f method, you probably shouldn't use it as the default value. > LOL ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-15 Thread Bengt Richter
stance method b.g defined yet (A.__init__ only defines f) Make one with a default >>> b.g = lambda self, x='xdefault': x >>> b.g() 'xdefault' >>> b.g('and arg') 'and arg' >>> a.g() 'a.g' >>> If we

Re: is parameter an iterable?

2005-11-16 Thread Bengt Richter
ll last): File "", line 1, in ? ValueError: wrong value >>> raise extab[0] Traceback (most recent call last): File "", line 1, in ? StopIteration: stop stop ;-) >>> extab = [StopIteration, 'stop stop ;-)', ValueError, 'wrong value'] >>> raise extab[2], extab[3] Traceback (most recent call last): File "", line 1, in ? ValueError: wrong value >>> raise extab[0], extab[1] Traceback (most recent call last): File "", line 1, in ? StopIteration: stop stop ;-) Ok, I'll stop ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-17 Thread Bengt Richter
exchange rate for clicks and dollars? > >As far as I know, it varies wildly depending on the context, but I >suspect you can find ranges of estimates on the web. > The growth of virtual worlds with virtual money and virtual/"real" currency exchange is interesting. People are actually making real money investing in and developing virtual real estate and selling virtual currency profits for real-world money ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Simulating call-by-reference

2005-11-17 Thread Bengt Richter
t[0].startswith('_')): print '%15s: %r'%it ... bar: '12' baz: 'abc' foo: 'CAPS' The setattr(MyClass, *m.groupdict().items()[0]) just makes an assignment of whatever comes out to be the first of name-tagged matches (of which there has to at least one here also). If you want several name-tagged matches in a single regex, you could do that and do a setattr for each item in m.groubdict().items(). What else you can do is only limited by your imagination ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading a file in same directory as code with relative path

2005-11-17 Thread Bengt Richter
_', '__name__', 'os'] ..\clp\showmydir.py C:\pywk\clp\showmydir.py C:\pywk\clp C:\pywk\clp\data.xml (Hm, that's an interesting outcome for __file__ ) HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Hot to split string literals that will across two or more lines ?

2005-11-17 Thread Bengt Richter
er you please. Sometimes if the substring source code is machine generated, it is handy to bracket the substrings between a header line and a trailer line, e.g., print ( "a string which is very loo" "ong." ) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Immutable instances, constant values

2005-11-18 Thread Bengt Richter
range' Just some thoughts. Oh, names are kind of protected by [:], but really should throw an exception if you try to mutate. >>> Colors.names ['red', 'green', 'blue'] >>> Colors.names[2] 'blue' >>> Colors.names[2] = 'indigo' >>> Colors.names[2] 'blue' It would be easy to return a tuple. It's not that easy to protect against Colors.names = something since __metaclass__ skips factory local to global if not in class scope, and passing a '__metaclass__': mcdefinition in the dict arg to type does not result in a call, it just becomes another passive class variable. Must be a way though. Too tired for now... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-18 Thread Bengt Richter
On 18 Nov 2005 06:56:38 -0800, "Anton Vredegoor" <[EMAIL PROTECTED]> wrote: [...] >Pardon me, but I'm Anton, not Antoon (well maybe I am but lets keep >this distinction in order to avoid mental hash collisions) D'oh. I'm sorry. Please pardon _me_

Re: Yield in a wrapper function

2005-11-18 Thread Bengt Richter
... >>> wrapper(-1) >>> import sys >>> for c in wrapper(-1): sys.stdout.write(c); sys.stdout.flush() ... ABC>>> >>> for c in wrapper(+1): sys.stdout.write(c); sys.stdout.flush() ... XYZ>>> Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Behaviour of enumerated types (was: Re: Immutable instances, constant values)

2005-11-18 Thread Bengt Richter
On Fri, 18 Nov 2005 23:43:10 +1100 (EST), Ben Finney <[EMAIL PROTECTED]> wrote: >Bengt Richter <[EMAIL PROTECTED]> wrote: >> Ben Finney <[EMAIL PROTECTED]> wrote: >> >I've recently packaged 'enum' in PyPI. >> [...] >> My notion of e

Re: Behaviour of enumerated types

2005-11-18 Thread Bengt Richter
On Sat, 19 Nov 2005 11:10:42 +1100 (EST), Ben Finney <[EMAIL PROTECTED]> wrote: >Bengt Richter <[EMAIL PROTECTED]> wrote: >> Ben Finney <[EMAIL PROTECTED]> wrote: >> >Getting a numeric index might be useful in a language such as >> >Pascal, with

Re: Immutable instances, constant values

2005-11-19 Thread Bengt Richter
utes may not be set >>> states[0] = 'something' Traceback (most recent call last): File "", line 1, in ? TypeError: object does not support item assignment But a slice returns a list, so the transient list absorbs the assignment and disappears >&g

Re: Obtaining an member function by name

2005-11-19 Thread Bengt Richter
ot;", line 1, in ? TypeError: unbound method bar() must be called with foo instance as first argument (got int inst ance instead) >>> foo.bar(fooinst) (<__main__.foo instance at 0x02EF756C>, 'bar is the name') Someone can explain. If you do some of your own work, it will help even the load. Have you looked at any documentation? Start at http://www.python.org/ and click a few things. There seems to be a beginners guide link under documentation in the sidebar to the left ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining an member function by name

2005-11-19 Thread Bengt Richter
instance of the class without confusions. Nit2: using new-style classes, which derive from object (or also other bases, but at least object or type) is now recommended, so you get the full-fledged attribute machinery that supports much of the latest magic. So write the above more like class Foo(object): def bar(self): return self, 'bar is the name' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie-question about a list

2005-11-19 Thread Bengt Richter
ed. > It's called a list comprehension. You can find that term in various indices of the various docs. In a minute I found these. I'm sure there's more if you google. http://docs.python.org/ http://docs.python.org/tut/node18.html#l2h-61 http://docs.python.org/ref/lists.html#l2h-345 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Behaviour of enumerated types

2005-11-19 Thread Bengt Richter
On Sun, 20 Nov 2005 08:42:48 +1100 (EST), Ben Finney <[EMAIL PROTECTED]> wrote: >Bengt Richter <[EMAIL PROTECTED]> wrote: >> On Sat, 19 Nov 2005 11:10:42 +1100 (EST), Ben Finney <[EMAIL PROTECTED]> >> wrote: >> >Bengt Richter <[EMAIL PROTECTED]

Re: exception raised by nested iterator being ignored by for loop

2005-11-19 Thread Bengt Richter
g the file handle >fh = open("test.txt") >for line in fh : >print line.rstrip() > fh.close() > ># using the wrapper class >fh = wrapper("test.txt") >for line in fh :# StopIteration ignored here >print line > HTH (and that the untested code works ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a function access its own name?

2005-11-19 Thread Bengt Richter
x27;__name__', 'baz', 'fren'] Check name(s) ;-) Local binding to the function object first: >>> baz Its outer name: >>> baz.func_name 'bar' Its def name: >>> baz.func_code.co_name 'foo' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
ot tested) defines the signature and arg defaults in the current scope, as opposed to where exec compiles in the decorator. >>> sinxx >>> import math >>> def mxx(x): return x and math.sin(x)/x or 1.0 ... >>> sinxx(0), mxx(0) (1.0, 1.0) >>> sinxx(.1), mxx(.1) (0.99833416647076856, 0.99833416646828155) >>> sinxx(.2), mxx(.2) (0.99334665398326816, 0.99334665397530608) >>> Seems to work, approximately ;-) >>> @fundef(""" ... def poo() ... syntax problems ... """) ... def poo(): pass ... Traceback (most recent call last): File "", line 1, in ? File "", line 10, in doprep ValueError: Unable to translate 'def poo()' ... due to SyntaxError: invalid syntax (line 1) Some hope of somewhat useful exceptions too ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
you have the habit to represent literals like that, all other >big numeric literals or workarounds to create grouping seem cryptic. > >-- >Eric Jacoboni, ne il y a 1435938104 secondes Um, about your sig ... ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
Jacoboni, ne il y a 1435938104 secondes My previous smiley re your sig in this thread context still applies ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: about dictionary

2005-11-20 Thread Bengt Richter
e some graph application? Maybe you can find something useful in a link from http://wiki.python.org/moin/PythonGraphApi (which I found by googling for "vertex graph site:python.org" (without the quotes) ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Bengt Richter
tems(), key=lambda t:t[1]&1) [('b', 98), ('d', 100), ('a', 97), ('c', 99)] >>> sorted(dict((c,ord(c)) for c in 'abcd').items(), key=lambda >>> t:(t[1]&1,t[1])) [('b', 98), ('d', 100), ('a',

Re: need help about time.sleep, timer

2005-11-21 Thread Bengt Richter
--- Ok, in the following I'll type 123 abc [ 5:40] C:\pywk\clp\threadstuff>py24 tqinp.py 15 No input for 5 seconds. Using '123' function('123') No input for 5 seconds. Using 'abc' function('abc'

Re: Command line

2005-11-21 Thread Bengt Richter
al system utility formatting, the python functions Fredrik showed make more sense, and are easier to use. ( posting delayed >12 hrs due to news server prob ;-/ ) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
On 20 Nov 2005 21:12:52 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> >> wrote: >> >> Ordering the keys isn't the normal case

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
e', 'varchar')), > ('sal', ('Salary', 'float'))) > >(Unless the Python syntax would be extend to use double curly braces or >something for ordered dictionaries - but I understand that this is not >an option.) > Whatever your odict

Re: best cumulative sum

2005-11-21 Thread Bengt Richter
L has mixed types. The OP didn't mention any requirements, but e.g. his version won't ever promote the first output element, since he walks replacements from L[1] on. ( posting delayed >12 hrs due to news server prob ;-/ ) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr for secondary attribute

2005-11-21 Thread Bengt Richter
names = s.split('.') for name in names[:-1]: A = getattr(A, name) setattr(A, names[-1], val) This should work for no dots or any number, so long as the reference chain is valid. E.g., setbydots(A, 'spam.eggs', newValue) shoul

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
eating a >> new view". dict() doesn't do that; in this use case, it doesn't cost >> you anything to use it. >doesn't cost me anything ? That is good news to me. Well, if you want something specific, it WILL cost you the effort to DYFR in detail ;-) ( posting delayed >12 hrs due to news server prob ;-/ ) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Looking for magic method to override to prevent dict(d) from grabbing subclass inst d contents directly

2005-11-21 Thread Bengt Richter
) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Command line

2005-11-21 Thread Bengt Richter
r one to >peruse the list of standard modules from time to time, until you gain a >familiarity with what is there. > >http://docs.python.org/modindex.html > Worthwhile as oldbies too ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: ignore specific data

2005-11-21 Thread Bengt Richter
me_name* zero or morem and somename+ one or more). What's needed is the final resolution to actual constants or patterns of primitives. Can you define header_start: "The actual fixed constant character string defining the header" header_end: "whatever?" Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
146458 4948 [ 9:15] C:\pywk\clp>wc odict*.py 467 1228 12483 odict.py 511 1500 14728 odictb.py 978 2728 27211 Totals Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 10:06:07 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >Bengt Richter schrieb: >> Ok, so if not in the standard library, what is the problem? Can't find what >> you want with google and PyPI etc.? Or haven't really settled on what y

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 03:07:47 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> Ok, so if not in the standard library, what is the problem? Can't find what >> you want with google and PyPI etc.? Or haven't really settled on wh

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 10:26:22 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > > > d = OrderedDict(); d[1]='one'; d[2]='two' =>> list(d) => [1, 2] > > ok, now we do d[1]='ein' and what is the order? list(

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
['c', 3]] > >That's funny, I thought your subject line said 'list of tuples'. I'll >answer the question in the subject rather than the question in the body: > >>>> aList = ['a', 1, 'b', 2, 'c', 3] >>>> it = iter(aList) >>>> zip(it, it) >[('a', 1), ('b', 2), ('c', 3)] > Thank you for that. That is cool ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
s, when >some folks thought it was truly amazing that call(11) printed >the raw contents of the entire memory to the screen... > You really don't think it was cool? Or could be well defined? ;-) Hm, actually, something tells me I've seen some variation of this before, but I can't think of the context off hand. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
er than the question in the body: >> >> >>> aList = ['a', 1, 'b', 2, 'c', 3] >> >>> it = iter(aList) >> >>> zip(it, it) >> [('a', 1), ('b', 2), ('c', 3)] > >Though it looks nice, it's an implementation dependant solution. What if >someone changes zip to fetch the second item first? > That would be a counter-intuitive thing to do. Most things go left->right in order as the default assumption. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for magic method to override to prevent dict(d) from grabbing subclass inst d contents directly

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 09:30:49 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >> Has anyone found a way besides not deriving from dict? >> Shouldn't there be a way? >> TIA >> (need this for what I hope is an impro

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
;, 3)] >>> it = iter(aList) >>> zip(it) [('a',), (1,), ('b',), (2,), ('c',), (3,)] >>> zip(range(3), range(4)) [(0, 0), (1, 1), (2, 2)] >>> zip(range(4), range(3)) [ (0, 0), (1, 1), (2, 2)] (I just hacked this out, so maybe it's not bullet-proof, but the point is, I think there's no reason not to define the behaviour of zip to cycle through its arguments in the intuitive way). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
git = git() ... def grouper(_): return git.next() ... return grouper ... >>> [tuple(g) for _, g in groupby(aList, grouper(2))] [('a', 1), ('b', 2), ('c', 3)] >>> [tuple(g) for _, g in groupby(aList, grouper(3))] [('a', 1, 'b'), (2, 'c', 3)] >>> [tuple(g) for _, g in groupby(aList, grouper(4))] [('a', 1, 'b', 2), ('c', 3)] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
Dict(d1.items()[0:1]+d2.items()[2:3]) you just want the sugar? d1+d2 would be like using [:] in the above line Not a biggie to do. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
unordered by getting unordered_dict.items() and sorting or ordering them any way you want and calling the OrderedDict constructor. Ditto for ordered dicts, since they give your their ordered items with the items() method as a start. I guess one could pass a key=fun keyword arg to the OrderedDic

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 11:18:19 -0800, "Kay Schluehr" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Mon, 21 Nov 2005 01:27:22 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> >> wrote: > >> Note that is isn't hard to snap a few pieces together to

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
gt; d1 {1: 11, 2: 12, 3: 13} >>> d1[1:] {2: 12, 3: 13} >>> d1[0:1] + d1[2:3] {1: 11, 3: 13} >>> d1.reverse() >>> d1 {3: 13, 2: 12, 1: 11} >>> d1.insert(1, (4,14)) >>> d1 {3: 13, 4: 14, 2: 12, 1: 11} >>> d1.items() [(3, 13), (4, 14), (2, 12), (1, 11)] >>> d1.keys() [3, 4, 2, 1] >>> d1.values() [13, 14, 12, 11] >>> d1[1:2] {4: 14} >>> d1[-1:] {1: 11} Que mas? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
s like feeding overlapping keys in a tuple sequence to dict, then later duplicate keys just replace prior ones by same rules as d[k]=v1; d[k]=v2. I think that makes sense in this context, and can be defined unambigously. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 16:32:25 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> On 22 Nov 2005 07:42:31 -0800, "George Sakkis" <[EMAIL PROTECTED]> wrote: >> >> >"Laurent Rahuel" wrote: >> &

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread Bengt Richter
her, keys, x): return dict((k,another[k]) for k in keys >>> if another[k]>x) ... >>> my_search(another, 'cb', .3) {'b': 0.35806602909756235} >>> my_search(another, 'abcd', .4) {'a': 0.60649466203365532, 'd': 0.77440643221840166} This sounds like homework though ... ? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
;sorted" and "ordered", before we can >go on ? > For me the implication of "sorted" is that there is a sorting algorithm that can be used to create an ordering from a prior state of order, whereas "ordered" could be the result of arbitrary permutation, e.g., manu

Re: sort in the list

2005-11-23 Thread Bengt Richter
t "False" apparently means equality is detected before ordering is tested? >>> (1, 1j, 1) < (1, 1j, 2) True IOW, element-pair < comparisons are evaluated until you get a True or reach the end, and same_complex < same_complex can return a legititmate False if they'

Re: Anyway to clarify this code? (dictionaries)

2005-11-23 Thread Bengt Richter
On 22 Nov 2005 19:52:40 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> >>> def my_search(another, keys, x): return dict((k,another[k]) for k in >> keys if another[k]>x) >> ... >> >

Re: Why are there no ordered dictionaries?

2005-11-23 Thread Bengt Richter
ial primitives, and default behaviour vs selectable modes, ISTM. E.g., it might be nice to have a mode that assumes d[key] is d.items()[k][1] when key is an integer, and otherwise uses dict lookup, for cases where the use case is just string dict keys. But feature creep is sure a threat to clean design. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-23 Thread Bengt Richter
On Wed, 23 Nov 2005 09:54:46 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> >Though it looks nice, it's an implementation dependant solution. What if >> >someone changes zip to fetch the second item first? >> >

Re: Converting a flat list to a list of tuples

2005-11-24 Thread Bengt Richter
On Wed, 23 Nov 2005 13:23:21 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> Are you thinking of something like lines from a file, where there might be >> chunky buffering? ISTM that wouldn't matter if the same next method w

Re: strange behaviour when writing a large amount of data on stdout

2005-11-24 Thread Bengt Richter
iles\Common Files\Microsoft Shared\MSInfo\MSINFO32.exe on my system. Since it's accessible from Word, I wouldn't think it would be too unsafe to run, but I guess the OP might not want to start diagnostic things on arbitrary devices etc., if that's accessible from his session. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: defining the behavior of zip(it, it) (WAS: Converting a flatlist...)

2005-11-24 Thread Bengt Richter
On Wed, 23 Nov 2005 17:55:35 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > >so how equivalent must something be to be equivalent? > quack, quack? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-24 Thread Bengt Richter
really wanted to. But I do think full index and slice read access would be fine. I think also that d1==d2 should effectively be implemented as d1[:] == d2[:] -- i.e, compare the item lists to implement comparisons. Detailed requirements are most of the work ;-) I'm thinking now to try subclassing list in a constrained way instead of dict, but well see. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: strange behaviour when writing a large amount of data on stdout

2005-11-24 Thread Bengt Richter
On 24 Nov 2005 03:22:26 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> If windows has been running a long time (a few days or a week may be long >> ;-) it >> may get fragmented in some smallish memory arena reserved

Re: Python as Guido Intended

2005-11-24 Thread Bengt Richter
er than you, too. If you like Python, it's 'cos you like the >decisions he's made over many years. > >Where my first impulse is to think that one of decisions is wrong, >nine times out of ten in time I'll come to find that I was wrong and >he was right. > You ha

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