Re: __getitem__ method on (meta)classes

2005-03-15 Thread Bengt Richter
gt;... return self.vals[index] >... >py> lst = 'abcd' >py> x = 'b' >py> e1 = enum(lst) >py> v = e1(x) >py> (x in lst) and (e1[v] == x) >True For that, why not just class enum(list): def __call__(self, val): return self.index(val) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: __getitem__ method on (meta)classes

2005-03-14 Thread Bengt Richter
__getitem__=classmethod(__getitem__) ...baz.lst = lst ...return baz ... >>> f = foo([1,2,3])() >>> type(f).__getitem__ > >>> type(f).__getitem__(0) 1 Leaving out the classmethod: >>> def foo(lst): ...class baz(object): ... def __getitem_

Re: __getitem__ method on (meta)classes

2005-03-14 Thread Bengt Richter
self): return 'Hi' ... >>> c=C() >>> C.ordinary_method >>> c.ordinary_method > >>> c.ordinary_method() 'Hi' >>> C.ordinary_method >>> C.ordinary_method(c) 'Hi' Note the difference between ordinary and classmethod: >>> type(c).ordinary_method >>> type(finst).__getitem__ > BTW, I see a class factory, but no "(meta)"class per se. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

decorating classes with metaclass

2005-03-14 Thread Bengt Richter
differing in the arguments passed. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python-list Digest, Vol 18, Issue 208

2005-03-14 Thread Bengt Richter
at almost the entire industry has standardized on >power-of-2 word sizes, octal is nearly useless but is still carried >about for backwards compatibility. > Actually, octal was really handy for PDP-11/45 core dumps, even though it had a power-of-2 (4 -> 16 bits) word size. The reason wa

Re: Add Properties to Instances?

2005-03-14 Thread Bengt Richter
On 14 Mar 2005 13:07:29 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote, in part: >> On 14 Mar 2005 01:19:23 -0800, "Martin Miller" ><[EMAIL PROTECTED]> >> wrote, in part: >> >What still puzzles me, though, is why

Re: a program to delete duplicate files

2005-03-14 Thread Bengt Richter
aven't yet seen an answer to this, >but it's a question for experimentation rather than theory. ISTM 2(m-1) reads is not necessary, so "the question" to me doesn't involve that ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: urllib (and urllib2) read all data from page on open()?

2005-03-14 Thread Bengt Richter
>> print r2.status, r2.reason >404 Not Found >>>> data2 = r2.read() >>>> conn.close() > >As far as I can understand, you can read() data only when you want >to. > >Caveat: >There's a warning that says "This module defines classes

Re: Add Properties to Instances?

2005-03-14 Thread Bengt Richter
On 14 Mar 2005 01:19:23 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote: >In answer to my question about instance properties not working, Bengt >Richter suggest using: >> > >>> class InstProp(object): >> > ... def __getattribute__(self, at

Re: newbie: dictionary - howto get key value

2005-03-13 Thread Bengt Richter
equivalent, but note that it only works if everyone has a different phone number. >>> dict((v,k) for k,v in {'sue':3, 'bob':4}.items()) {3: 'sue', 4: 'bob'} >>> dict((v,k) for k,v in {'sue':3, 'bob':4, 'mike':4}.items()) {3: 'sue', 4: 'bob'} Surprised at who got left out? >>> {'sue':3, 'bob':4, 'mike':4}.items() [('sue', 3), ('mike', 4), ('bob', 4)] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: brand new to python

2005-03-13 Thread Bengt Richter
gt;raise NoSuchDomain, domainname > return page Careful with the above return's indentation after you fix the try/excepts. > >## >## >-- I've heard pychecker (http://pychecker.sourceforge.net/) catches a lot of stuff. Maybe it would help you. Having lint-eyes, I haven't yet tried it, though it would probably save me some time ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a problem on this simple code

2005-03-13 Thread Bengt Richter
On Sun, 13 Mar 2005 10:46:52 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Sorry for jumping in with a largely irrelevant comment. I didn't look >> at the code, just sought to illustrate the 6/18 thing further, in a kneejerk >> reactio

Re: is there a problem on this simple code

2005-03-12 Thread Bengt Richter
On 12 Mar 2005 20:12:19 -0800, "John Machin" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> On 12 Mar 2005 17:35:50 -0800, "John Machin" <[EMAIL PROTECTED]> >wrote: >> >> > >> >[EMAIL PROTECTED] wrote: >> >>

Re: dinamically altering a function

2005-03-12 Thread Bengt Richter
On Sat, 12 Mar 2005 23:09:58 -0400, vegetax <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: [...] >> Please pretend things worked the way you want, and post an example. Maybe >> we can make it work. >> >> Regards, >> Bengt Richter > >Ok , the comp

Re: Add Properties to Instances?

2005-03-12 Thread Bengt Richter
On Sun, 13 Mar 2005 03:18:51 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On 12 Mar 2005 09:48:42 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote: > >>I'm trying to create some read-only instance specific properties, but >>the following attempt

Re: is there a problem on this simple code

2005-03-12 Thread Bengt Richter
#x27;", '\\', 'x', '8', '3'] >>> len(r"C\x01\x02\x10'\x83") 18 > >> That's 18 bytes. Is the command supposed to be the ASCII >> characters \x01 or a single byte whose value is 1? > >For a start, according to the OP's code, the command ('C' a.k.a. 67) is >first. The 1 is a meant to be a message number. > >Secondly, the hardware smells like it's got an 8080 or 6502 inside. The >likelihood that it groks Python/C string representation is minimal. >Folk just don't send 18 bytes at 9600 bps when 6 bytes will do. > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Add Properties to Instances?

2005-03-12 Thread Bengt Richter
rt time >>> inst1 = InstProp() >>> inst2 = InstProp() >>> inst1.t = property(lambda self: time.ctime()) >>> inst2.p2 = property(lambda self: 'prop2') >>> inst1.t 'Sat Mar 12 19:10:40 2005' >>> inst2.p2 'prop2' If you want robust writeable and/or deleteable properties, you will have to do a little more work, but it can be done. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: dinamically altering a function

2005-03-12 Thread Bengt Richter
>> ... return obj >> ... >> py> myobj = Object() >> py> fun(myobj, 2) >> <__main__.Object object at 0x01162E30> >> py> myobj.b >> 2 >> py> obj = fun(1) >> py> obj.b >> 1 >> >> This doesn't use any bytecode hacks, but I'm still not certain it's >> really the way to go. What is it you're trying to write this way? Yes, that is a good question ;-) > >OO doesnt work here,i have factored to classes with inheritance but it looks >clumsy and it is clumsy to use, this things are in nature,functions. > >What i want is to declare in the decorator some code that is common to all >these functions, so the functions assume that the decorator will be there >and wont need to duplicate the code provided by it, and the functions are >not known ahead of time, it has to be dynamic. Still not sure what you mean by "the functions are not known ahead of time." Please pretend things worked the way you want, and post an example. Maybe we can make it work. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused with classmethods

2005-03-12 Thread Bengt Richter
t;__main__.A instance at 0x02EF142C> or a different instance >>> foo.__get__(None, A)(A()) <__main__.A instance at 0x02EF18CC> If you don't pass the type, some things won't work fully, but the usual will >>> foo.__get__(a) > As can be seen, the original function is in there in the bound method: >>> foo.__get__(a, A).im_func And you can call it as such if you like: >>> foo.__get__(a, A).im_func('hi, via plain function') hi, via plain function Descriptors are a big deal in the new python. They are at the root of much of the magic. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: dictionary - howto get key value

2005-03-12 Thread Bengt Richter
tdefault(num, []).append(name) if __name__ == '__main__': phone = Twoway({'mike':10,'sue':8,'john':3, 'jack': 3, 'helen' : 10}) print 'jack:', phone['jack'] print 'same phone as jack:', phone[phone['jack']] print 'deleting jack ...'; del phone['jack'] print 'john:', phone['john'] print phone - [13:05] C:\pywk\sovm>py24 twoway.py jack: 3 same phone as jack: ['john', 'jack'] deleting jack ... john: 3 {'mike': 10, 3: ['john'], 8: ['sue'], 10: ['mike', 'helen'], 'sue': 8, 'helen': 10, 'john': 3} Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to turn a variable name into a string?

2005-03-11 Thread Bengt Richter
line 6, in __init__ ValueError: You are missing some env vars: ['unknown'] If you have spaces in your environment names (possible?) that would be nasty and you would have to change the "required" __init__ parameter to split on something other than spaces. You could arrange for case-insensitivity if you liked. And if you really wanted to have local or global bindings for your env names, you could easily do that too, but e.g., myenv.XXX seems like a readable way to group things together. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] a program to delete duplicate files

2005-03-11 Thread Bengt Richter
re-computing full hashes would be optimal. Compare to sort|uniq as a sieve. You wouldn't want to read through any files any further than you had to. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP: Print Without Intervening Space

2005-03-11 Thread Bengt Richter
gt;> printf('%03d %r %3d %5.2f %5d\n',1,'two', 0x3, 4.5, fn(6)) 001 'two' 3 4.5064 >> >> Best regards, >> Marcin >> >You could think about teaching them the linelist.append(fn(x)) way, >which then gives you the choice of > > "".join(linelist) - no gaps > "\n".join(lienlist) - one item per line > " ".join(linelist) - spaces between items. > IMO teachers should lead their students into contact with reality, not insulate them from it with delusionary simplifications that they will have to unlearn in order to progress. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Preserving the argspec of a function after generating a closure

2005-03-11 Thread Bengt Richter
6 LOAD_FAST0 (x) 9 LOAD_FAST1 (y) 12 BINARY_ADD 13 RETURN_VALUE >>> inspect.getargspec(bar) (['x', 'y'], None, None, None) >>> dis.dis(bar) 1 0 LOAD_FAST0 (x) 3 LOAD_FAST1 (y) 6 BINARY_ADD 7 RETURN_VALUE I don't know where this is leading. What was your goal again? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a short-circuiting dictionary "get" method?

2005-03-11 Thread Bengt Richter
t;d['x']. Suppose d['x'] == 3: > > >>> 3 is not None >True > >>> > maybe (untested) value = ('x' in d and [d['x']] or [bsf()])[0] then there's always if 'x' in d: value = d['x'] else: value = bsf() or try: value = d['x'] except KeyError: value = bsf() Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple buffers management

2005-03-10 Thread Bengt Richter
t here to play 20-questions. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterate using tuple as index

2005-03-10 Thread Bengt Richter
#x27;a', 'b', 'c']) >>> for list1_item, list2_item in zip(firstlist, secondlist): ... print list1_item, list2_item ... 1 a 2 b 3 c Or if your lists are very long, you could use an iterator from itertools, e.g., >>> import itertools &

Re: How can I Read/Write multiple sequential Binary/Text data files

2005-03-10 Thread Bengt Richter
ce? > Are you the same person who posted re this format some time ago? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Bengt Richter
# presets.py -- a decorator to preset function local variables without a default-argument hack or closure # also does currying, with adjustment of argument count, eliminating named arguments from right. # 20050310 09:22:15 -- alpha 0.01 release -- bokr # Released to the public domain WITH

Re: Safe string escaping?

2005-03-07 Thread Bengt Richter
>> list(sd) ['f', 'o', 'o', '\n', '\x00'] You could make a de-escaping utility function, e.g., >>> def de_esc(s): return s.decode('string_escape') ... >>> s 'foo\\n\\0' >>> de_esc(s) 'foo\n\x00' You might want to write a test to verify that it does what you expect for the kind of escaped string you are using. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: exclude binary files from os.walk

2005-02-25 Thread Bengt Richter
in all of this >> pertains to files on Windows XP and Python 2.4 > >Please clarify: is your question about identifying binary (non-ascii) files >or about using os.walk? > > I have a feeling it's about walking directories and identifying which files to should be "cooked" (to normalize line endings when opened and read). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple slices

2005-01-26 Thread Bengt Richter
omeoffset+i*somefactor once you get past the limit checks for the virtual slice. By the same token, transforming a few numbers of one virtual slice into similar numbers for a a new virtual slice of that shouldn't be rocket science. And it wouldn't have to be done more than once. Don

Re: Tuple slices

2005-01-26 Thread Bengt Richter
uence gets larger. Of course, you can >always use the standard >C/C++ approach and pass the original sequence along with the (start,stop,step) >indices of the slice, >as Terry Reedy mentioned, but then you lose in expressiveness. I didn't see the leadup to this, but what is the problem with just subclassing tuple to give you the views you want? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: is there better 32 clock() timing?

2005-01-26 Thread Bengt Richter
On Tue, 25 Jan 2005 15:46:30 +, Stephen Kellett <[EMAIL PROTECTED]> wrote: >In message <[EMAIL PROTECTED]>, Bengt Richter ><[EMAIL PROTECTED]> writes >>I believe that is quite wrong as a general statement. > >Actually my initial statement should have been

Re: delay and force in Python

2005-01-25 Thread Bengt Richter
to example, >>> print list(x for i,x in enumerate(x for x in xrange(1, 996) if x % 2 ==0) >>> if i<3 or iter([]).next())[2] 6 or in case you just want one item as result, >>> print list(x for i,x in enumerate(x for x in xrange(1, 996) if x % 2 ==0) >>> if i==2 or i==3 and iter([]).next())[0] 6 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Bengt Richter
On Tue, 25 Jan 2005 11:46:04 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >> >>>If you are after readability, you might prefer this... >>> >

Re: is there better 32 clock() timing?

2005-01-25 Thread Bengt Richter
in problem with a CPU clock based reading is that it's very stable unless there's variable clock rate due to power management. Why am I doing this? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Bengt Richter
s really that helpful? def hamming(): def _hamming(): yield 1 for n in imerge(imap(lambda h: 2*h, iter(hg2)), imerge(imap(lambda h: 3*h, iter(hg3)), imap(lambda h: 5*h, iter(hg5: yield n hg2, hg3,

Re: is there better 32 clock() timing?

2005-01-25 Thread Bengt Richter
esponses in >Windows is to write a kernel driver, and even then there are no guarantees. >Windows is NOT a real-time system. If you have an environment where an >unexpected delay of a millisecond or more is going to cause damage, then >you need to redesign your application. For sure. The big requirements picture is missing (not uncommon ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-25 Thread Bengt Richter
On Mon, 24 Jan 2005 20:35:09 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > >>Bengt Richter wrote: >>> So, e.g., for >>> >>> >>> presets = dict(a=1, b=2, deftime

Re: Retrieving modification time of file class was declared in

2005-01-25 Thread Bengt Richter
4-1)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from ut.finfo import finfo >>> finfo(finfo) ('finfo', 'ut.finfo', 'c:\\pywk\\ut\\finfo.pyc', 1106641080) >>> import time >>> time.ctime(finfo(finfo)[-1]) 'Tue Jan 25 00:18:00 2005' HIH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Another scripting language implemented into Python itself?

2005-01-24 Thread Bengt Richter
: "Kneeling, Cobb p lanted a sturdy knee in the small of his back,") funny that googling define:imbed gets nothing. Nor define:embed ?? I've had a number of misses in that kind of search. I wonder if it's temporarily broken (or maybe it hit a licensing snag with the various onl

Re: Question about reading a big binary file and write it into several text (ascii) files

2005-01-24 Thread Bengt Richter
nking XML are you??!! For this, definitely ick ;-) > What you want to do will depend on the big picture, which is not apparent yet ;-) > >Please reply when you guyes can get a chance. >Thanks, Sorry to give nothing but untested suggestion, but I have to go, and I will be off line mostly for a while. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-24 Thread Bengt Richter
On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> So, e.g., for >> >> >>> presets = dict(a=1, b=2, deftime=__import__('time').ctime()) >> >> in the decorator args, the next version wi

Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-23 Thread Bengt Richter
On Sun, 23 Jan 2005 13:14:10 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Sat, 22 Jan 2005 16:22:33 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: >> >> [Steven Bethard] >>>> > If you really want locals that d

Re: list unpack trick?

2005-01-23 Thread Bengt Richter
On Sun, 23 Jan 2005 08:22:36 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On Sun, 23 Jan 2005 15:43:43 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: > >>aurora wrote: >>> I am think more in the line of string.ljust(). So if we have a >>> list.ljust(lengt

Re: list unpack trick?

2005-01-23 Thread Bengt Richter
01:47:27) [GCC 3.2.3 (mingw special 20030504-1)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help(''.ljust) Help on built-in function ljust: ljust(...) S.ljust(width[, fillchar]) -> string

Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-22 Thread Bengt Richter
3 (3) 21 STORE_FAST 1 (c) 6 24 LOAD_CONST 4 (3.1415926535897931) 27 STORE_FAST 4 (pi) 7 30 LOAD_CONST 5 () 33 CALL_FUNCTION0 36 RETURN_VALUE &

Re: default value in a list

2005-01-22 Thread Bengt Richter
x27;.split(':')) >>> print (a, b, c, d, e) ('a', 'b', 'c', None, None) But then, might as well do: >>> def bar(nreq, *args): ... if nreq <= len(args): return args[:nreq] ... return args+ (nreq-len(args))*(None,) ...

Re: Unbinding multiple variables

2005-01-22 Thread Bengt Richter
cted, nor did the y = 123 show at 4: But the d['z'] showed up immediately, as you might expect ... but d['z'] also in that last returned locals(), which you might not expect, since there was no assignment to bare z. But they are apparently the same dict object, so you would expect it. So maybe there is some kind of finalization at exit like closure building. Anyway, d = dict(locals()) would probably behave differently, but I'm going to leave to someone else ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class introspection and dynamically determining function arguments

2005-01-22 Thread Bengt Richter
provides fairly robust mechanism >(called robustApply) for providing a set of possible arguments and using >inspect to pick out which names match the parameters for a function in >order to pass them in to the function/method/callable object. That >said, doing this for __init__'s with attribute values from an object's >dictionary doesn't really seem like the proper way to approach the problem. Sounds like a workaround for parameter passing that maybe should have been keyword-based? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Print a string in binary format

2005-01-21 Thread Bengt Richter
7:-1025:P 26:Q 27:10 -26:-Q-27:-R-28:-1026:Q 27:R 28:10 -27:-R-28:-S-29:-1027:R 28:S 29:10 -28:-S-29:-T-30:-1028:S 29:T 30:10 -29:-T-30:-U-31:-1029:T 30:U 31:10 -30:-U-31:-V-

Re: What YAML engine do you use?

2005-01-21 Thread Bengt Richter
m W3C a long time ago. ... I see the third edition at http://www.w3.org/TR/REC-xml/ is differently styled, (I guess new style sheets) but still pretty readable (glancing at it now). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class introspection and dynamically determining function arguments

2005-01-21 Thread Bengt Richter
c(C.__init__) (['self', 'a', 'b', 'c'], None, None, (1, 'bee', 1.2)) that you want by looking at the unbound method C.__init__ (though im_func may be deprecated eventually?): >>> C.__init__.im_func.func_code.co_varnames ('self', 'a', 'b', 'c') >>> C.__init__.im_func.func_defaults (1, 'bee', 1.2) or by getting the __init__ function as such, by avoiding the attribute access that makes it and unbound or bound method >>> C.__dict__['__init__'].func_code.co_varnames ('self', 'a', 'b', 'c') >>> C.__dict__['__init__'].func_defaults (1, 'bee', 1.2) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Print a string in binary format

2005-01-20 Thread Bengt Richter
0 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 0001 00010001 00010010 00010011 00010100 00010101 00010110 00010111 [...snip stuff you can infer ...] 0111 01110001 01110010 01110011 01110100 01110101 01110110 01110111 0000 0001 0010 0011 0100 0101 0110 0111 Well, you get the idea. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Freezing a mutable (was Re: lambda)

2005-01-20 Thread Bengt Richter
oblems internally, and accepts keys and values of any type without wrapping or other modification -- or do you want a wrapper that can make any object suitable for use as key or value in python's curent definition of dict? Just DYFR please. You still haven't you know ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: list item's position

2005-01-20 Thread Bengt Richter
>> v][0]:] >>> for s in newbar: print repr(s) ... 'str_1 and str_2 both in line two' 'three' 'four' 'str_1 and str_2 both in line five' 'last line' Alternatively: >>> newbar = list(dropwhile(lambda x: 'str_1' not in x or 'str_2' not in x, >>> bars)) >>> for s in newbar: print repr(s) ... 'str_1 and str_2 both in line two' 'three' 'four' 'str_1 and str_2 both in line five' 'last line' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: delay and force in Python

2005-01-19 Thread Bengt Richter
ecursionlimit(n) Set the maximum depth of the Python interpreter stack to n. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. The highest possible limit is platform- dependent. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: rotor replacement

2005-01-19 Thread Bengt Richter
neral. I can easily conceive of information that I'd rather not see publicized without severe access controls. But in general I do believe in open sharing of free information as the most productive for everyone. >Exporting a machine gun is much different from publishing a >description of one. Software is just a precise type of description. Yeah, but ... ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name

2005-01-18 Thread Bengt Richter
On Wed, 19 Jan 2005 04:55:53 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >What am I missing? (this is from 2.4b1, so probably it has been fixed?) > I googled and found a bug report, but initial report kind of passes on it saying nested sequences will probably be tuples, so no pan

Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name

2005-01-18 Thread Bengt Richter
like it expects to refer to the type, not the arg for elt2 in flatten(elt): l.append(elt2) else: l.append(elt) return l Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
On Tue, 18 Jan 2005 17:38:20 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Which make me wonder what plans there are for providing a better >> mechanism than default arguments as a way of initializing local function >> variables. Nested def

Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
s purity drives actual implementation, but purity issues drive a lot of interesting, if not too practical, discussions. Of course, if someone has the energy to become champions of their ideas, and actually implement them for testing and evaluation, more power to them. I don't think we shou

Re: generator expressions: performance anomaly?

2005-01-18 Thread Bengt Richter
deftime=time.ctime()): return x*y, kw.get('which_time')=='now' and time.ctime() or deftime Seem like a minor extension of the default-arg hack. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: lambda

2005-01-18 Thread Bengt Richter
ementation >limitations is sold as a general principle. People take short cuts in expressing themselves, just as you do. E.g., you say "mutable key" when you really mean a value that will remain constant while you are using it as a dictionary key. The "safe" dictionary that you are "thinking about" will apparently get its "safety" by ensuring that the "mutable key" can't be "mutated" -- or do you want to discuss which copy is the real "key" ;-) (I don't ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: news feed problem -- anyone else?

2005-01-18 Thread Bengt Richter
On 17 Jan 2005 16:48:24 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> I can see postings on google, but my news service >> is having a problem since sometime during the weekend. >> Can get old stuff from other n.g., but no new. >>

Re: List problems in C code ported to Python

2005-01-18 Thread Bengt Richter
void ) >{ > int i, j; > int ds; > int u, v; > > /* setup rotor data */ > for (j=0;j<26;j++) > data[4][j] = ((int)ref_rotor[j]-'A'+26)%26; > > for (i=1;i<4;i++) > { > step[i-1] = step_data[order[i-1]]; > for (j=0;j<26;j++) > { > data[i][j] = ((int)(rotor[order[i-1]][j])-'A' + 26) % 26; > data[8-i][data[i][j]] = j; > } > } > >Now, do I need to start boning up on lists and how to use them or am I >missing the bigger picture?? Again, for the complete code see >http://home.earthlink.net/~lvraab. I'm not asking you to do it for me, >just some pointers on going about this. You are obviously not yet familiar with python, but a few hours with the introduction and tutorials should help a lot. Then post something that compiles. Or a snippet that does something you don't understand. This is about all I have patience for this time. I really have other stuff to do. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

news feed problem -- anyone else?

2005-01-17 Thread Bengt Richter
I can see postings on google, but my news service is having a problem since sometime during the weekend. Can get old stuff from other n.g., but no new. Wondering whether I'll see this via google. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: interpret 4 byte as 32-bit float (IEEE-754)

2005-01-16 Thread Bengt Richter
On Sat, 15 Jan 2005 11:00:36 -0800, Scott David Daniels <[EMAIL PROTECTED]> wrote: >G.Franzkowiak wrote: >> Scott David Daniels schrieb: >> >>> franzkowiak wrote: >>> I've read some bytes from a file and just now I can't interpret 4 bytes in this dates like a real value. An extract f

Re: How to del item of a list in loop?

2005-01-16 Thread Bengt Richter
ut once again ;-) >>> lst = [1, 2, 3] >>> i = 0 >>> for item in lst: ...if item !=2: ...lst[i] = item ...i += 1 ... >>> del lst[i:] >>> lst [1, 3] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: What strategy for random accession of records in massive FASTA file?

2005-01-15 Thread Bengt Richter
nerally speaking you can ignore the overhead, and the >flush() calls will be automatic as long as you don't mix file and string >operations. The programming convenience is amazing. That part does look good, but will scanning a large file with find cause massive swapouts, or is there some smart prioritization or hidden sequential windowing that limits mmap's impact? > >> -- >> I have come to kick ass, chew bubble gum and do the following: >> >> from __future__ import py3k >> >> And it doesn't work. > >So make it work :-) > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: java 5 could like python?

2005-01-15 Thread Bengt Richter
interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
import sys try: oldnew = __import__(sys.argv[3]) main(sys.argv[1], sys.argv[2], oldnew.old, oldnew.new) except Exception, e: print '%s:%s' %(e.__class__.__name__, e) raise SystemExit, """ Usage: [python] binfupd.py infname outfname oldnewmodulename where infname is read in binary, and outfname is written in binary, replacing instances of old binary data with new specified as python strings named old and new respectively in a module named oldnewmodulename (without .py extension). """ --- REMEMBER: NO WARRANTY FOR ANY PURPOSE! USE AT YOUR OWN RISK! And, if you know where to seek to, that seems like the best way ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
#x27;s as needed in a pool of partially complete t's. But your real requirements are not clear enough here, so you may get help crossing a stream, but no one will be able to say you are already on the side of the stream you want to be later, and there's an easy path without need of crossing twice ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Octal notation: severe deprecation

2005-01-14 Thread Bengt Richter
On Fri, 14 Jan 2005 20:13:48 +0100, Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: >> >>>[EMAIL PROTECTED] wrote: >>>> In Mythical Future P

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
g to list the variable names ># as strings in multiple places. It is enought to ># have them in the 'mapping' ># dictionary above > >t2 = Test(dictionary.get('a'), dictionary.get('b'), >dictionary.get('c')) >print t2 > Why don't

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-s

Re: Octal notation: severe deprecation

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 17:43:01 -0600, Jeff Epler <[EMAIL PROTECTED]> wrote: > >--LQksG6bCIzRHxTLp >Content-Type: text/plain; charset=us-ascii >Content-Disposition: inline >Content-Transfer-Encoding: quoted-printable > >On Thu, Jan 13, 2005 at 11:04:21PM +, Bengt Rich

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-s

Re: newbie q

2005-01-13 Thread Bengt Richter
15], [16], [17], [18], [19]] >>> for i in (x[0] for x in something): print i, ... oops, that list() used it up ;-) >>> something = [[x] for x in xrange(10,20)] >>> for i in (x[0] for x in something): print i, ... 10 11 12 13 14 15 16 17 18 19 Really nice. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Octal notation: severe deprecation

2005-01-13 Thread Bengt Richter
g hex literals of negative numbers. def __repr__(self): return '<%s object at %08.16b>' %(type(self).__name__, id(self)) and you could write based literals in the above formats with e.g., with '16x%.16b' % number or '2x%.2b' % number etc. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Bengt Richter
has justified the fact that an >assignment does not return any value, and therefore cannot be used as a >component of an expression. > Hm, that makes me wonder, is there an intermediate "returning of value" in x = y = z = 123 ? >Mea culpa, but I'm not going to *pl

Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Bengt Richter
27;s let(x, y, ...): spec. It provides a new way of factoring. As well as things no one has thought of yet ;-) The other thing to think about is that the let suite could be strictly def-time, which would provide the opportunity to avoid re-calculating things in functions without abusing default args, and using the easy closure-variable creation instead. E.g., let(foo): preset = big_calc() in: def foo(x): return x * preset (This "in:" has no "in xxx:" name, so the effect is immediate execution of the anonymously defined function, which writes through to foo with the def, as permitted by let(foo):). Problems? (Besides NIH, which I struggle with regularly, and had to overcome to accept Tim's starting point in this ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Bengt Richter
... inner() ... print 4, locals() ... >>> foo() 1 {'a': 1, 'b': 2} 2 {'a': 2, 'c': 3, 'b': 2} and b: 2 4 {'a': 1, 'b': 2, 'inner': } of course a difference using the new syntax is that 'inner' is not bound to a persistent name. > >otherwise that would be impossible to do calculations based on scope >variables and "using:" would be useless =), consider example of usage: > >current_position = 1 >current_environment # = ... >current_a_lot_of_other_parameters # = ... >scores = [count_score(move) for move in aviable_moves] using: > def count_score(move): > #walking through current_environment > return score No worry, UIAM. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
fout = open('mynewbinfile', 'wb') for buf in updated_file_stream('myoldbinfile','rb', oldbinstring, newbinstring): fout.write(buf) fout.close() (left as an exercise ;-) (modifying a file "in place" is another exercise) (doing the latter with defined maximum memory buffer usage even when mods increase the length of the file is another ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: why are people still using classic classes?

2005-01-12 Thread Bengt Richter
gt;> def MC(*a): print a; return type(*a) ... >>> class F: ... __metaclass__ = MC ... pass ... ('F', (), {'__module__': '__main__', '__metaclass__': }) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
On Thu, 13 Jan 2005 12:19:06 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote: >On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: >> extensiondict = dict( >> php = 'application/x-php', >> cpp = 'tex

Re: What strategy for random accession of records in massive FASTA file?

2005-01-12 Thread Bengt Richter
ATTCTCAAAGGAATAGACGG >>CW127_A03 >TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG >TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA >GCATTAAACATTCCGCCTGGG >... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: pyserial and com port interrupts

2005-01-12 Thread Bengt Richter
u set baud rates and handshaking etc. I would think. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.updated

2005-01-12 Thread Bengt Richter
#x27;: 10, 'c': 3}] > It's kind of a strange list comp, but I guess you're just illustrating something. But for this case you could just write >>> [d.update({'c':3}) or d for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]] [{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}] taking advantage of normal d.update() returning None and so forcing the 'or' term. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: counting items

2005-01-12 Thread Bengt Richter
(map(totallen, x)) > return 1 Since the requirement is to _count_, not flatten, ISTM your solution is best so far ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
deas? > I think I would refactor along these lines: (untested) extensiondict = dict( php = 'application/x-php', cpp = 'text/x-c-src', # etcetera xsl = 'test/xsl' ) def detectMimeType(filename): extension = os.path.splitext(filename)[1].replace('.', '') try: return extensiondict[extension] except KeyError: basename = os.path.basename(filename) if "Makefile" in basename: return 'text/x-makefile' # XXX case sensitivity? raise NoMimeError Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Another look at language comparisons

2005-01-12 Thread Bengt Richter
/www.tbray.org/ongoing/When/200x/2004/12/08/-big/IMG_3061.jpg >> >> >> LOL, he is working on linux, isn't he? >> >> So it was about bloody time. > >Guido Van Rossum is now working on linux?? Are they both left-handed? Hm, sinister ... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python serial data aquisition

2005-01-11 Thread Bengt Richter
On 11 Jan 2005 07:51:35 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote: >[EMAIL PROTECTED] (Bengt Richter) wrote in message news:<[EMAIL PROTECTED]>... >> On 9 Jan 2005 14:13:28 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote: >> >> >Hi, >> >

Re: Securing a future for anonymous functions in Python

2005-01-11 Thread Bengt Richter
urn preset # return now legal ... print foo() The combination would work like: let(rebindable): factor = 10 in bar: rebindable *= factor rebindable = 2 bar() print rebindable # => 20 rebindable += 5 bar() print rebindable # => 250 You can see this could be used nicely in case functionality, with a dict of named in-functions. What do you think? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing huge Sets() to disk

2005-01-11 Thread Bengt Richter
>[cut] > > The reason I went for sets instead of lists is the speed, >availability of unique, common and other methods. >What would you propose as an elegant solution? >Actually, even those nested for loops take ages. :( If you will explain a little what you are doing with these set "items" perhaps someone will think of another way to represent and use your data. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python serial data aquisition

2005-01-11 Thread Bengt Richter
hand with redundant information that will accomplish the effect of masking and shifting and adjusting sign. If you need this speed, volunteers will magically appear. Maybe even if you don't ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-10 Thread Bengt Richter
>eliminating the need to move the lips (which reduces effort and stops >flies getting in). > >Tim C >Sydney, Australia LOL. Thanks, needed that ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: time module precision

2005-01-09 Thread Bengt Richter
al-time stuff, but I haven't used it. (I just seem to remember reading something about that in the MSDN docs, but I am not sure. And too lazy to go back and look ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python3: accessing the result of 'if'

2005-01-09 Thread Bengt Richter
tements, too. > >if someregexp.match(s) as m: > # blah using m >elif someotherregexp.match(s) as m: > # blah using m > If 'where: ...' were an expression suite ISTM you could write if m where: m = someregexp.match(s) # same-line format blah(m) eli

<    4   5   6   7   8   9   10   >