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
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
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
#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
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
&
;, 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
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()
>>>
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
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
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
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
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
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
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
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!!
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
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"""
>>
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
---
>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
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
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:
>> >>
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
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
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
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
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
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
>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
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
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
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
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
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
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
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
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._
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
# and adict is global here
adict = {}
setem('k', 'value')
adict -> {'k':'value'}
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
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. ;-)
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
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
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
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
>>
>
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
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
(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
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,
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
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
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
,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
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
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
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:
>
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
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
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
.
>>> 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
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
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
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>^&
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
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.,
>>
>>
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
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
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
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,
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):
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
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
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
rolling mode.
Seems to work for cmd.exe on NT4
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
= 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
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.
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
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
,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
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
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
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
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
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
print '>%s<' % PaddedStr2('xxx',5,'.')
>xxx..<
>>> print '>%s<' % PaddedStr2('xxx',3,'.')
>xxx<
>>> print '>%s<' % PaddedStr2('xxx',2,'.')
>xxx<
(T
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
Python code with block bracketing, please
program up a suitable code viewer for them ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
and-optimizes inner loops by hoisting
>the bound objection creation, as
>
>data = []
>data_append = data.append
>for x in some_other_data:
> work with x to make y
> data_append(y)
>
Sorry about the me-too. I hadn't seen your post. I should know better ;-)
Re
ten such an expression, so you will this strategy when people try
to squeeze extra performance from their programs.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
und method we saved by binding it to af still is bound to the old
method function,
so a new dynamically created one is not the same:
>>> af.im_func is a2.f.im_func
False
>>> af.im_func
>>> a.f.im_func
at 0x02F99B1C>
>>> a2.f.im_func
at 0x02F99B1C>
t
>has the externally visible effect of degrading performance (to a nullity)
>for arguments that the user might reasonably want to work.
Agreed, but the key thing there is to define "unnecessarily" ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
))
>>> print t2
:D\cimsu
Note that there is only one of each character in t2 (e.g. 'D' and '\\')
And the result is the same for t and t2:
>>> s.lstrip(t)
'aniel Lanois\\For the beauty of Wynona'
>>> s.lstrip(t2)
'aniel Lanois\\For the beauty of Wynona'
If you want to replace an exact prefix, a regex could be a simple way
to get the startswith check and replace in one whack.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
as now. Anyway, lots of stuff
would become possible... e.g., msys, the MinGW-related shell provides
some of this capability, virtualizing windows partitions as /c/* /d/*
and so forth, as well as having virtual mounts of various subdir trees.
Good night...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
al speeches ;-)
>that doesn't matter, of course, since the tuple is removed by the
>garbage collector immediately after it has been unpacked.
I'm too tired to figure a humorous segue ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
cmp=None, key=None, reverse=False) --> new sorted list
>
That's plenty of information, but IMO "key=None" doesn't hint strongly enough
about what you can do with it, so I'd advise reading about all the parameters
;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
f foo(nlines=1):
7: for i, line in enumerate(open(sys.argv[1])):# test default 'r'
8: print '%4s: %s' %(i+1, line.rstrip())
9: if i+1 >= nlines: break
10: print '< 3 lines of %r' % sys.argv[1]
11: foo(3)
12:
<
', 'tuple'), 'BC', 'Sandra']
>>> a
'A'
>>> tup
('a', 'tuple')
>>> b
'B'
>>> c
'C'
>>> d
'Sandra'
>>> dis.dis(compile("a, tup, (b,c), d = ['A', ('a', 'tuple'), 'BC',
>>> 'Sandra']",'','exec'))
1 0 LOAD_CONST 0 ('A')
3 LOAD_CONST 6 (('a', 'tuple'))
6 LOAD_CONST 3 ('BC')
9 LOAD_CONST 4 ('Sandra')
12 BUILD_LIST 4
15 UNPACK_SEQUENCE 4
18 STORE_NAME 0 (a)
21 STORE_NAME 1 (tup)
24 UNPACK_SEQUENCE 2
27 STORE_NAME 2 (b)
30 STORE_NAME 3 (c)
33 STORE_NAME 4 (d)
36 LOAD_CONST 5 (None)
39 RETURN_VALUE
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
omatically.
In short, a whole unopened deluxe set of programming Legos is at your elbow,
besides the
pieces you have encountered so far. Have fun ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
and STORE_FAST etc, but you can see
what's
happening above. I.e., on return from the function call, the returned sequence
(we know it's
a tuple in your example, but it could be some other sequence thing) is upacked
and its elements
are bound to the individual names, just as individual "assignments" would do.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 13 May 2005 14:59:13 -0700, "Matt" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
[...]
>> I'm afraid inheriting explicitly from object will make the exception
>unraisable.
>> Exceptions are still based on "classic" classes for some
On 13 May 2005 09:37:07 -0700, "Matt" <[EMAIL PROTECTED]> wrote:
>
>Christopher J. Bottaro wrote:
>> Christopher J. Bottaro wrote:
>>
>> > Bengt Richter wrote:
>> >
>> >> >>> type(obj)
>> >>
>> >>
found how to do this in a few
>> seconds in PHP. I searched the Python docs for "class name", "classname",
>> "introspection" and "getclass". I looked in the Class section of the
>> tutorial also and also the Programming FAQ. The "
501 - 600 of 974 matches
Mail list logo