Re: Frankenstring

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

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

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

Re: all possible combinations

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

Re: Generating a list of None

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

Re: Filtering out non-readable characters

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

Re: Generating a list of None

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

Re: Filtering out non-readable characters

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

Re: Copying attributes

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

Re: PEP on path module for standard library

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

Re: dictionary that discards old items

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

Re: Copying attributes

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

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

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

Re: Filtering out non-readable characters

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

Re: Filtering out non-readable characters

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

Re: Filtering out non-readable characters

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

Re: dictionary that discards old items

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

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

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

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

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

Re: multiple inheritance super()

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

Re: Wrapping a class set method

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

Re: functions without parentheses

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

Re: functions without parentheses

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

Re: A replacement for lambda

2005-07-30 Thread Bengt Richter
doc = "Just an example") > Again, the '@' is not necessary ;-) >This looks like the abuse of lambda case, but these aren't >assignments, they're keyword arguments. You could leave off the >keywords, but it's not noticably prettier. fget can be done with a >lambda, but the the others can't. Well, they can, but it's not pretty ;-) > >Giving clases the same functionality seems to be the reasonable thing >to do. It's symmetric. And if anonymous function objects are good, >then anonymous class objects ought to be good as well. I agree. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: A replacement for lambda

2005-07-30 Thread Bengt Richter
t everyone else thought about it. As a >result, the code examples tend to be ugly. > >As previously hinted, this feature is lifted from Oz. try http://groups-beta.google.com/groups?as_q=anonymous+def&as_ugroup=comp.lang.python for much discussion of this ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: functions without parentheses

2005-07-30 Thread Bengt Richter
On Sat, 30 Jul 2005 08:14:16 +0100, [EMAIL PROTECTED] (phil hunt) wrote: >On Fri, 29 Jul 2005 06:37:52 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: >> >>I suggested in a previous thread that one could support such a syntax by >>supporting an invisible binary opera

Re: Comparison of functions

2005-07-30 Thread Bengt Richter
'classobj', ''), ) 4294967296 | ((0,), 4294967296L) -4294967296 | ((0,), -4294967296L) -- Sorted: -4294967296 -1.0 1 4294967296 2j (1+0j) at 0x02EE8E2C> at 0x02EE8DF4> <__main__.D object at 0x02F0044C> __main__.C <__main__.C instance at 0x02F004CC> Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: A replacement for lambda

2005-07-31 Thread Bengt Richter
On Sun, 31 Jul 2005 00:30:36 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: > >> On Fri, 29 Jul 2005 18:07:31 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote: >>>I know, lambda bashing (and defending) in the group is one of

Re: Printing Docstrings Without Importing

2005-07-31 Thread Bengt Richter
t>python docstr2html.py docstr2html.py doc strings as of Sun Jul 31 20:04:55 2005 C:\pywk\ut\docstr2html.py Prints html to display docstrings of modules specified on command line, with optional globbing and html page title default override. Usage: [python] docstr2html.py [-title "some title"] (file_pattern)+ Note: If redirecting stdout, some windows versions require [python] to be explicit. You can use file specs like someplace\*.py (wild cards) and it should do all the files and put it all in tables in the html output. Note that is uses all file specs as patterns, and ignores without complaint any that don't match anything. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: keylogger in Python

2005-07-31 Thread Bengt Richter
e and all manner of stuff. Try typing spyxx.hlp and see if spy++ help comes up. Or possibly run an older spy.exe for an example of interactively selecting what to monitor. Then you could write a C module to provide a python interface to those capabilities. Have fun ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces

2005-08-01 Thread Bengt Richter
nction.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: 'function' object has no attribute 'foo' >>> vars(function) {} Ok, to make the statement execute, execute function: >>> function() >>> a=function.foo >>> a 'something' >>> vars(function) {'foo': 'something'} Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How override ALL function calls? (Is there a "function call function"?)

2005-08-01 Thread Bengt Richter
ch function call. See the debugger chapter in the library manual. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing Docstrings Without Importing

2005-08-02 Thread Bengt Richter
gate down to the spcific module docstring output quickly if you have a lot of them. Of course, I think I'd put styling in the header rather than hack more raw html if I were to go another round. I'll post the latest once I can see my postings in context with my own newsreader again.

Re: Metaclasses and class variables

2005-08-04 Thread Bengt Richter
: ... @deco ... def foo(): pass ... @Base.deco ... def bar(x, y): print 'two args:', x, y ... >>> TheClass.classvar [('foo', 0), ('bar', 2)] Incidentally, you can see that deco and classvar belong to the Base class, though accessible as instance and class attributes >>> tc = TheClass() >>> tc.classvar [('foo', 0), ('bar', 2)] >>> TheClass.mro() [, , ] >>> vars(tc) {} >>> vars(TheClass).keys() ['__module__', 'foo', 'bar', '__doc__'] >>> vars(Base).keys() ['__module__', 'deco', 'classvar', '__dict__', '__weakref__', '__doc__'] HTH. Add metaclasses and stir to taste ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing a variable number of arguments to a wrapped function.

2005-08-05 Thread Bengt Richter
>else: >plot(xvalues, yvalues) > It seems like you are not changing the order or values of arguments, so I'm wondering if this would work for you: def makeplot(self, *args, **kwargs): plot(*args, **kwargs) and if not, why not. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: why no arg, abs methods for comlex type?

2005-08-06 Thread Bengt Richter
(1+0j) (0.707106781187-0.707106781187j) (1.5701957963e-016-1j) (-0.707106781187-0.707106781187j) (-1-3.1403915926e-016j) (-0.707106781187+0.707106781187j) (-4.71058738891e-016+1j) (0.707106781187+0.707106781187j) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?)

2005-08-07 Thread Bengt Richter
object nsofound with x attr in **= object attribute name space sequence, # and then do nsofound.x=456 -- where x could be a normal property defined by type(nsofound) The property possibility should be interesting ;-) Be kind, I've suggested := for find-and-rebind before, but I haven't thought very far about this combination with extended function namespace ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Chopping off spaces at both ends

2005-08-07 Thread Bengt Richter
;>> 'abc123cab'.strip('bca') '123' I.e., a strip argument as an unordered set of characters that causes stripping so long as characters at the end(s) of the string being stripped are found that are in the set. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP: Specialization Syntax

2005-08-07 Thread Bengt Richter
C object at 0x02EF498C>, (slice(None, None, None),), {}) >>> c[kw='key word arg'] File "", line 1 c[kw='key word arg'] ^ SyntaxError: invalid syntax But here the problem is not in the __getitem__ method: >>> c.__getitem__(kw='key word arg') (<__main__.C object at 0x02EF498C>, (), {'kw': 'key word arg'}) It's just that square bracket expression trailer syntax does not allow the same arg list syntax as parenthesis calling trailer syntax. > method could be changed to allow additional signatures: > > def __getitem__(self, *args, **kwargs): ... > > Should other operators that square brackets be used for > specialization? Didn't quite parse that ;-) You mean list comprehensions? Or ?? > > >References > > [1] Adding Optional Static Typing to Python -- Part II, > Guido van Rossum > http://www.artima.com/weblogs/viewpost.jsp?thread=86641 > > [2] Optional Static Typing -- Stop the Flames!, Guido van Rossum > http://www.artima.com/weblogs/viewpost.jsp?thread=87182 > > >Copyright > > This document has been placed in the public domain. > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP: Specialization Syntax

2005-08-07 Thread Bengt Richter
t seems you could >> do this today easily. I agree with this, until I see some really persuasive use cases. > >The PEP validity is also very much influenced if optional static typing >is planned to be added to the language. I realize defending this PEP is >much harder without static typing and my use cases imply typing of some >sort anyway. > I'll have to catch up with that. Have been very bogged down for a long while. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Euclid's Algorithm in Python?

2005-08-07 Thread Bengt Richter
= 0: > a, b = b, a%b >return a > >Even nicer. > what is the convention for handling signed arguments? E.g., >>> def gcd(a,b): ... while b != 0: ... a, b = b, a%b ... return a ... >>> gcd(3, -12) -3 >>> gcd(-12, 3) 3 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Fat and happy Pythonistas (was Re: Replacement for keyword'global' good idea? ...)

2005-08-07 Thread Bengt Richter
it can be looked up somewhere by the name. The idea is that this form of decoration could transform the AST arbitrarily before code generation, and be a very flexible tool for mischief of course, but also useful tricky things IWT. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python -- (just) a successful experiment?

2005-08-08 Thread Bengt Richter
ded in their heroic coding effo= >rt, goes to name their new module, package, or application with a "py" othe= >r than to the right of the dot. > Probably better to have the PSF hire a patent/trademark lawyer to reserve rights to py... names and the "py"-prefixing business process ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP: Specialization Syntax

2005-08-08 Thread Bengt Richter
On Sun, 07 Aug 2005 21:41:33 -0400, Nicolas Fleury <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: [...] >> But here the problem is not in the __getitem__ method: >> >> >>> c.__getitem__(kw='key word arg') >> (<__main__.C object at 0x

Re: Fat and happy Pythonistas (was Re: Replacement forkeyword'global' good idea? ...)

2005-08-08 Thread Bengt Richter
On Sun, 7 Aug 2005 23:52:40 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> I think the relationship of abstract entities and their concrete >> representat

Re: PEP: Specialization Syntax

2005-08-08 Thread Bengt Richter
On Mon, 08 Aug 2005 16:18:50 -0400, Nicolas Fleury <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Sun, 07 Aug 2005 21:41:33 -0400, Nicolas Fleury <[EMAIL PROTECTED]> wrote: >>>I mean should angle brackets <> like in C++, or another operator, be >

Re: PEP: Specialization Syntax

2005-08-08 Thread Bengt Richter
On Tue, 09 Aug 2005 00:14:25 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: [...] >Here is a decorator object to set up function call dispatch according to type. >It only uses positional arguments, but could be fleshed out, I think. >Not tested beyond what you see ;-) > ><

Re: PEP: Specialization Syntax

2005-08-08 Thread Bengt Richter
On Mon, 08 Aug 2005 21:24:15 -0400, Nicolas Fleury <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Mon, 08 Aug 2005 16:18:50 -0400, Nicolas Fleury <[EMAIL PROTECTED]> wrote: >>>I wrote the PEP to see if was the only one that would benefit from >>>

Re: Decline and fall of scripting languages ?

2005-08-09 Thread Bengt Richter
means, but taken at face value would seem to warrant a further look into details. This turned up also http://eddie.sourceforge.net/txt/WP_1.0.html which I hadn't seen before, and which looks interesting though maybe stale? I guess this is a home for erlang: http://www.erlang.se/ Much

Re: namespaces

2005-08-09 Thread Bengt Richter
OAD_DEREF 0 (TABLE) 9 CALL_FUNCTION1 12 RETURN_VALUE I.e., the original globally bound translate replaces its global binding with the closure it creates on first execution, and also uses that closure to get the first result, which is a little tricky, I'd say ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces

2005-08-09 Thread Bengt Richter
to the namespace of a module by adding an object whose class defines the property, like mod ..= objhavingproperty # same tuple ambiguity as with 'somestr' % x something analogous to += on immutables would have to be done for builtin objects I suppose. Just adding more mulch/worms to the idea garden ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Does any one recognize this binary data storage format

2005-08-09 Thread Bengt Richter
uot;) ... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)])) ... m = int(dhex, 16) ... x = ((m>>52)&0x7ff) - 0x3ff - 52 ... s = (m>>63)&0x1 ... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52) ... return (1

Re: Does any one recognize this binary data storage format

2005-08-09 Thread Bengt Richter
On Wed, 10 Aug 2005 03:47:06 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On Tue, 09 Aug 2005 21:50:06 -, Grant Edwards <[EMAIL PROTECTED]> wrote: > >>On 2005-08-09, Scott David Daniels <[EMAIL PROTECTED]> wrote: >>> Grant Edwards wrote: >>>>>

Re: Does any one recognize this binary data storage format

2005-08-10 Thread Bengt Richter
ect route ? >ie. convert them to the double float directly from the byte values ? Yes. Use struct.unpack ;-) BTW, my second post was doing ''.join(chr(int(h[i:i+2],16)) for i in xrange(0,16,2)) to undo the hexlify you had done (I'd forgotten that there's a binascii.unhexlif

Re: interpreter frame

2005-08-10 Thread Bengt Richter
e file in order to get the line of code, which an interactive session does not satisfy? (Maybe a strategically located StringIO instance encapsulating the latest interactive chunk as "source file" could solve it?) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: "Compile time" checking?

2005-08-10 Thread Bengt Richter
tput whether v is '2' or 2. > >For this reason I tend to debug print statements like this now: > > if debug: print "v=%s" % (v,) I usually prefer %r over %s for debug prints if debug: print "v=%r" % (v,) since it represents (repr's ;-) the v t

Re: help in algorithm

2005-08-11 Thread Bengt Richter
sterable('banana')-clusterable('bananana') 0 i.e., resulting from >>> abs(clusterable('banana'))-abs(clusterable('bananana')) set([]) >>> abs(clusterable('banana')) set(['na', 'ab', 'ba', 'an']) >>> abs(clusterable('bananana')) set(['na', 'ab', 'ba', 'an']) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 328, absolute/relative import

2005-08-11 Thread Bengt Richter
ista) mistakenly shadowing standard library modules with >name-colliding local ones well after PEP 328 is fully implemented. >Gotta keep people on their feet! :-) > Will/should an __init__.py in the current directory be required, to control what happens (and lessen the probability of accidental collision from a random working directory)? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Pre-PEP Proposal: Codetags

2005-08-11 Thread Bengt Richter
I agree that the OP's proposal is not a core language matter. Perhaps this is another PEEP candidate (i.e., a "Python Evironment Enhancement Proposal" to put in a "PEEP" application/tools/environment-oriented clone of the PEP process). Maybe a PEEP top page in the wiki with l

Re: command line reports

2005-08-11 Thread Bengt Richter
ious report with the current one, so I only use one line by the >time the code is finished. > >I was also hoping that there was a set of tools out there for spinners, >meters, etc... The question with python for this kind of thing is usually, "Which will be faster, googling for it, or writing it?" ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: need help with python syntax

2005-08-11 Thread Bengt Richter
ways True. BTW, if you have a dict d which might define 'bgcolor' as '#ee' or 'white' you could check for either white something like (untested) if d['bgcolor'] in ('#ee', 'white'): # put most common white code first for

Re: PEP 328, absolute/relative import

2005-08-11 Thread Bengt Richter
On Thu, 11 Aug 2005 14:55:57 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> Will/should an __init__.py in the current directory be required, >> to control what happens (and lessen the probability of accidental >> collision from a random wor

Re: Help sorting a list by file extension

2005-08-11 Thread Bengt Richter
is depends on the extension being nicely splittable with a single '.', but that should be the case for you I think, if you make sure you eliminate directory names and file names that don't end that way. You can look before you leap or catch the conversion exceptions, but to do that, you'll need a loop instead of a listcomprehension. >>> [name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in namelist)] ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20'] >>> sorted(namelist) ['test.1', 'test.10', 'test.15', 'test.2', 'test.20', 'test.3', 'test.4'] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: how to append semicolon to a variable

2005-08-13 Thread Bengt Richter
repr(x) for x in (couch, price, sdate, city)) "'couch'; 32; '01/01/2004'; 'newyork'" Note: if you want ';' appended to each item instead of just between items, you can just add ';' to the whole thing >>> '; '.join(str(x) for x in (couch, price, sdate, city)) + ';' 'couch; 32; 01/01/2004; newyork;' Which avoids the trailing blank you would get if you appended '; ' to every item before joining them, as in >>> ''.join(('%s; '%x) for x in (couch, price, sdate, city)) 'couch; 32; 01/01/2004; newyork; ' or >>> ''.join((str(x) + '; ') for x in (couch, price, sdate, city)) 'couch; 32; 01/01/2004; newyork; ' HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: catching all exceptions

2005-08-13 Thread Bengt Richter
thing() ... except Exception, e: ... print '%s: %s'% (e.__class__.__name__, e) ... except 'ugh': ... print 'Caught "ugh"' ... except: ... print sys.exc_info() ... >>> import sys # forgot, will need when above executes ;-) >>> >>> test(lambda:strexraiser('ugh')) Caught "ugh" >>> test(lambda:strexraiser('gak')) ('gak', None, ) >>> test(lambda:1/0) ZeroDivisionError: integer division or modulo by zero Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

2005-08-16 Thread Bengt Richter
know it effectively means 'modulescope' and derives from a time where that was the only unqualified alternative to local. There's been a lot of discussion about this, periodically ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

2005-08-16 Thread Bengt Richter
uot;...open the box and find the i'th item /in/ the box..." is not really finding the i'th item _itself_ "/in/" the box. It is finding one end of a string tied to some point /in/ the box, but the actual item/object is at the other end of the string, not /in/ the box, and many other strings may potentially also be leading to the same object, whether originating from anonymous structural binding points in other objects, or named binding points in name-tag-containing objects/namespaces. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading portions of a wave file

2005-08-16 Thread Bengt Richter
#x27;t you at least try setpos, and fix it if there's a problem? Or report on the problem you _actually_ encounter, which could be useful. That much can't be much harder than looking for an alternative, and may inspire others to help make/find a workable solution for you. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to obtain GMT offset?

2005-08-16 Thread Bengt Richter
;time.timezone gives you the timezone offset in minutes. > ITYM seconds? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to obtain GMT offset?

2005-08-16 Thread Bengt Richter
ython during standard time and retrieve altzone after 1AM (or whenever the official switchover happens)? Lack of property would seem to make constants for both altzone and timezone safer. But then daylight should probably be an accessor function, if it can't be a property ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: class-call a function in a function -problem

2005-08-16 Thread Bengt Richter
File "k.py", line 17, in ? >z.ala() > File "k.py", line 14, in ala >ludzik.l() >TypeError: unbound method l() must be called with ludzik instance as >first argument (got nothing instead) > > >i would be gratefull for resolving this problem for me > HTH Working through the tutorials is not a bad idea ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?)

2005-08-16 Thread Bengt Richter
On Tue, 16 Aug 2005 19:24:04 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> IOW, "...open the box and find the i'th item /in/ the box..." is not >

Re: Making programs work together.

2005-08-16 Thread Bengt Richter
my game to use in a program? > How do I access the data behind your question? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: creating/modifying sparse files on linux

2005-08-17 Thread Bengt Richter
for persistence. Or maybe you could use zipfiles. The kind of data you are creating above would probably compress really well ;-) [1] writing 314+ million identical bytes one by one is silly, of course ;-) BTW, len is a built-in function, and using built-in names for variables is frowned upon as a bug-prone practice. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: question about binary and serial info

2005-08-18 Thread Bengt Richter
', '\x02', ' ', 'A', 'B', 'C', ' ', '0', '1', '2'] The trick is to keep in mind that there is some abstraction that is being represented in various ways, and make allowances for people's saying "hex" when they mean the binary that the hex (characters matching [0-9A-Fa-f]) representation is representing, and similarly with other abstractions (e.g. binary ;-) and their representations (e.g., string representations of binary, or DRAM state representations of binary, etc.) HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Really virtual properties

2005-08-18 Thread Bengt Richter
>>> class Base(object): ... x = property(lambda self: 'Base get_x') ... >>> class Derv(Base): ... x = property(lambda self: 'Derv get_x') ... >>> b = Base() >>> d = Derv() >>> b.x 'Base get_x' >>> d.x 'Derv get_x' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Module Name Conflicts

2005-08-18 Thread Bengt Richter
>>> sys.path.insert(0,'foo2') > >>> import blah as blah2 > >>> sys.modules['blah'] > > >>> blah2.__file__ >'foo1/blah.py' > >>> > How about (untested) import new blah1 = new.module('blah&

Re: while c = f.read(1)

2005-08-18 Thread Bengt Richter
7;s expression vs. statement syntactic >separation? How can I be write this code more nicely? > Yes, it is related as you suspect. I'll leave it to you to make a chunk-buffering one-liner for huge files that iterates by characters, if one-liners turn you on. Otherwise it is easy to write a generator that will do it. Byt the time I post this, someone will probably have done it ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a unique id for bound methods?

2005-08-19 Thread Bengt Richter
>>> print id(c.meth1) 49219180 >>> print id(c.meth2) 49219180 But the ones we forced to persist by binding the expression values to cm1 and cm2 above still have the same ids as before: >>> print id(cm1) 49219020 >>> print id(cm2) 49219060 So the question would be, why do you (think you ;-) need ids for these bound methods as such? I.e., what is the "situation" in your code? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: while c = f.read(1)

2005-08-19 Thread Bengt Richter
On Fri, 19 Aug 2005 16:31:47 +1000, John Machin <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On 18 Aug 2005 22:21:53 -0700, "Greg McIntyre" <[EMAIL PROTECTED]> wrote: >> >> >>>I have a Python snippet: >>> >>> f = op

Re: How to get a unique id for bound methods?

2005-08-19 Thread Bengt Richter
ld save a lot of housekeeping. > Why do you need a name? Can you post an example snippet that shows a callback function being used with Tkinter as you would wish? I have a feeling there is a much simpler solution than you are imagining ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Well, another try Re: while c = f.read(1)

2005-08-20 Thread Bengt Richter
nterests. You're welcome to try again ;-) (BTW, sorry if "James" doesn't mean English is your mother tongue, and I have misinterpreted your manner of expression. If so, this may still be a useful indication to you of how wording can determine response ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: while c = f.read(1)

2005-08-23 Thread Bengt Richter
ubsequent spelling e.g, while c(f.read(1)): # do stuff with c.x though something more menmonic than c might be desirable in that case. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: split function

2005-08-23 Thread Bengt Richter
le = sys.stdout >>> >>> lines = [''.join(line.split()) for line in in_file] # clean out spaces and >>> '\n' >>> for i, line in enumerate(lines): ... for digit in line: ... out_file.write(digit) ... for followingline in lines[i+1:]: ... if digit not in followingline: continue ... line_sans_digit = followingline.replace(digit,'') ... out_file.write(line_sans_digit) ... out_file.write("\n") ... 021433244123 12343 234 34 Also note that I eliminated all duplicate digits from a selected line, rather than just the first match. Easy to change. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to 'touch' a file?

2005-08-23 Thread Bengt Richter
nged? E.g., how would you have interpreted the same words rearranged as follows? '''I'm looking for an easy way to update the modification time of a file (to perform a UNIX-style "touch") without actually modifying it.''' Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: how to deal with space between numbers

2005-08-23 Thread Bengt Richter
line.split()) for line in in_file] # make lines as int >>> lists >>> for i, line in enumerate(lines): ... out = [] ... for digit in line: ... out.append(digit) ... for followingline in lines[i+1:]: ... if digit in followingline: ... out.extend([x for x in followingline if x != digit]) ... out_file.write(' '.join(map(str, out))+"\n") ... 0 1 5 9 2 1 4 3 3 2 4 4 1 2 3 6 7 1 0 5 9 12 10 2 3 4 3 6 7 2 3 4 3 4 6 7 0 1 12 10 5 9 10 1 12 10 9 4 6 7 10 9 (The output now has to have spaces as well, to delimit the numbers). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Line Removal strategy

2005-08-24 Thread Bengt Richter
some undprcified width running through a speckled background is a different problem ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone recognize this numeric storage format - similar to "float", but not quite

2005-08-24 Thread Bengt Richter
gt;Thanks in advance. > Not looking too closely, but I recall something similar (although I suspect that the bit you are "reversing" is a sign bit that shadows a known constant MSB 1 for non-zero numbers, and shouldn't just be reversed): http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe#4aadc71be8aeddbe Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Externally-defined properties?

2005-08-24 Thread Bengt Richter
or instance to use for the property attribute magic >>> a = Accessor() Set obj.obj = 123 indirectly >>> a.xobj = 123 Check >>> vars(obj) {'obj': 123} Set up access to an object attribute in a different module >>> import sys >>> Accessor.sin = Indirect('stdin', sys) >>> a.sin ', mode 'r' at 0x02E8E020> >>> Accessor.pi = Indirect('pi', __import__('math')) >>> a.pi 3.1415926535897931 >>> a.pi = 3 >>> a.pi 3 >>> import math >>> math.pi 3 I'd say there's possibilities for shooting yourself in the foot. Maybe passing a code to Indirect to enable get/set/del selectively would help. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone recognize this numeric storage format - similar to "float", but not quite

2005-08-24 Thread Bengt Richter
re thinking of turned out to be straight IEEE double format, and I think this is not, though I think it looks like one that was answered (by me ;-) quite a while ago (Dec 1 2003). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: execfile in global scope

2005-08-24 Thread Bengt Richter
("""\ ... x = 555 ... """) >>> print '%s\n%s%s' %('-'*30, open('change.py').read(), '-'*30) -- x = 555 ------ >>> dir() ['__builtins__', '__doc__', '__name__'] >>> x = 111 >>> x 111 >>> def changevar(): ... execfile('change.py', globals()) ... >>> x 111 >>> changevar() >>> x 555 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: overload builtin operator

2005-08-26 Thread Bengt Richter
odes found anywhere, and calling node-type-specific or default supplied callbacks to supply replacements for original nodes passed to them, but this will require a number of specialized visitors etc., so I will have to get back to this later. But at least the OP and you nudged me into thinking about AST rewriting again ;-) (also affects my @@sourcedeco ideas ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting from Microsoft Binary Format floats to Python Float

2005-08-26 Thread Bengt Richter
On 26 Aug 2005 07:55:26 -0700, [EMAIL PROTECTED] wrote: >In the '80's, Microsoft had a proprietary binary structure to handle >floating point numbers, In a previous thread, Bengt Richter posted >some example code in how to convert these to python floats; > >http:

Re: list insertion

2005-08-27 Thread Bengt Richter
> sll 2> >>> sll.insert('a') 'a' -> 2> >>> sll.next 2> >>> sll.next.insert('b') 'b' -> 2> >>> sll 'a' -> 'b' -> 2> Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: overload builtin operator

2005-08-27 Thread Bengt Richter
ttr(modsafe, 'test'): modsafe.test() --- Result from running the above and specifying testdiv as the module to import and enforce safediv on, and run test() on: safediv(1.0, 2.0) => 0.5 0.5 safediv(12, 3) => 4 4 safediv(12, 3) => 4 4 safediv(4096, 4) => 1024 1024 print 1/0 => safediv(1, 0) => 0 0 print a/(b*(a-12)) => safediv(12, 0) => 0 0 def foo(x=1/(b-3)): return x => safediv(1, 0) => 0 print foo() => 0 b /= (a-12) => safediv(3, 0) => 0 b after b/=(a-12): 0 Note that the exceptions went away ;-) It was much messier than it should have been, and the code is not very efficient, but at least it's a kind of proof of concept ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: overload builtin operator

2005-08-28 Thread Bengt Richter
On Sun, 28 Aug 2005 04:09:10 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: [... a response to the OP's apparent desire to "overload the divide operator" with a call to his safediv function ...] The part that rewrote the the AugAssign could only work for plain name Augassig

Re: trictionary?

2005-08-29 Thread Bengt Richter
e aspects of classes, your progammer.agility value can increase markedly with a little study ;-) E.g., a name like monsters.random_elf could live right alongside PIRATE and return one a randomly selected elf from a an internal list of elves or via random selection from a list of elf names defined at the same level as PIRATE, etc. etc. You could also dynamically configure these guys according to distance to food and time since last meal, and if you are carrying food, etc. With suitable classes you could put instances in various "spaces" defined by other classes, that define geometric or social or other interactions. > >instead of using stupid index numbers. > >But the loader seems to have a kind of perl-like odor to it, >i.e., next week I won't understand what it does. > If you have to do something tricky, choose names wisely and comment the non-obvious ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: overload builtin operator

2005-08-29 Thread Bengt Richter
at handles non-simple-name-target /= augassigns as well, but though it shows on google groups, I can't see it yet. Still some news server problem, apparently. Or maybe it's just slogging to catch up after previous problem... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: global interpreter lock

2005-08-30 Thread Bengt Richter
I keep explaining that concurrency >systems have improved vastly in recent years. For a long time, >the most sophisticated software services generally have used >multiple lines of execution, and now that's mostly in the form >of threads. No one actually disagrees, but they go right

Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-30 Thread Bengt Richter
I think that would just be a tweak on the trailer syntax. I just really dislike the semicolons ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-30 Thread Bengt Richter
__len__() by returning a type that supports the >"Emulating numeric types" methods from the Python Language >Reference 3.3.7, and also allows the class's methods to tell >that it stands for the length of the dimension in question. > > (OTTOMH ;-) Perhaps the slice t

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