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

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: 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

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: 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: 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: 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
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

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: 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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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
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
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: 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: 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: 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: 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: Favorite non-python language trick?

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

Re: trouble subclassing str

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

Re: OO approach to decision sequence?

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

Re: Interpreter-like help in cmd.Cmd

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

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

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

Re: python bytecode grammar

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

Re: unittest: collecting tests from many modules?

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

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

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

Re: Controlling assignation

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

Re: Favorite non-python language trick?

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

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

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

Re: turn text lines into a list

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

Re: Better console for Windows?

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

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

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

Re: Inheriting from object

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

Re: Inheriting from object

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

Re: Inheriting from object

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

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

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

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

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

Re: Determining actual elapsed (wall-clock) time

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

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

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

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

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

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

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

Re: OT: ^ in redirection (windows)

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

Re: importing pyc from memory?

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

Re: importing pyc from memory?

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

Re: Conditionally implementing __iter__ in new style classes

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

Re: Conditionally implementing __iter__ in new style classes

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

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

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

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

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

Re: Conditionally implementing __iter__ in new style classes

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

Re: Legacy data parsing

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

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

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

Re: why UnboundLocalError?

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

Re: removing list comprehensions in Python 3.0

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

Re: removing list comprehensions in Python 3.0

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

Re: why UnboundLocalError?

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

Re: why UnboundLocalError?

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

decorators as generalized pre-binding hooks

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

Re: removing list comprehensions in Python 3.0

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

Re: Efficiency of using long integers to hold bitmaps

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

Re: decorators as generalized pre-binding hooks

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

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

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

Re: computer algebra packages

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

Re: Read-only class properties

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

Re: computer algebra packages

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

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

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

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

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

Re: Read-only class properties

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

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

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

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

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

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

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

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

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

Re: Access descendant class's module namespace from superclass

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

Re: Puzzled

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

Re: Efficiency of using long integers to hold bitmaps

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

Re: Tricky Dictionary Question from newbie

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

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

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

Re: Frankenstring

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

Re: python parser

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

Re: Inconsistency in hex()

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

Re: if not DEBUG: log = null_log

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

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