gt;can have a table that is indexed from e.g. -4 to +6. So how am
>I supposed to easily get at that last value?
Give it a handy property? E.g.,
table.as_python_list[-1]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
this. And if there isn't,
>
>Greenlets, perhaps? (for which, see google).
>
Maybe
yield in inner()
could be sugar for the above and become something optimized?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
either
average brute force
or discard outlier timings and average, or return best-of. All these have
different error
properties, and depend on lots of stuff.
I'm wondering whats your application is. Maybe you need a real-time OS?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 30 Aug 2005 23:12:35 +0200, Reinhold Birkenfeld <[EMAIL PROTECTED]>
wrote:
>Bengt Richter wrote:
>> On Tue, 30 Aug 2005 12:18:59 GMT, Michael Hudson <[EMAIL PROTECTED]> wrote:
>>
>>>Talin <[EMAIL PROTECTED]> writes:
>>>
>>>
On Tue, 30 Aug 2005 21:23:39 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> On Tue, 30 Aug 2005 23:12:35 +0200, Reinhold Birkenfeld <[EMAIL PROTECTED]>
>> wrote:
>>>Bengt Richter wrote:
>>>>Maybe
>>>>
On 31 Aug 2005 07:26:48 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>Op 2005-08-30, Bengt Richter schreef <[EMAIL PROTECTED]>:
>> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>
>>>Op 2005-08-30, Terry Reedy schreef <[EMA
On 31 Aug 2005 07:13:26 -0700, "Kay Schluehr" <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
>> That would give a consitent interpretation of seq[-1] and no errors
>> for any value
27;final']
>
>>> a = Zbrxlist(list('abcde'))
>>> a
Zbrxlist(['a', 'b', 'c', 'd', 'e'])
Forgot to provide a __len__ method ;-)
>>> a[len(a.value):len(a.value)] = ['end']
>>> a
Zbrxlist(['a', 'b', 'c', 'd', 'e', 'end'])
lastx refers to the last items by zero-based reverse indexing
>>> a[lastx]
"[Zbrx(0)]: 'end'"
>>> a[lastx:lastx] = ['last']
>>> a
Zbrxlist(['a', 'b', 'c', 'd', 'e', 'last', 'end'])
As expected, or do you want to define different semantics?
You still need to spell len(a) in the slice somehow to indicate
beond the top. E.g.,
>>> a[lastx-1:lastx-1] = ['final']
>>> a
Zbrxlist(['a', 'b', 'c', 'd', 'e', 'last', 'end', 'final'])
Perhaps you can take the above toy and make something that works
they way you had in mind? Nothing like implementation to give
your ideas reality ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
import StringIO as SIO
>>> f = SIO('123xx678xxCxx_and so forth')
>>> for s in ireadlines(f,'xx',4): print repr(s),
...
'123xx678xx' 'Cxx_and so forth'
>>> for s in ireadlines(f,'xx',5): print repr(s),
...
''
oops
>>> f.seek(0)
>>> for s in ireadlines(f,'xx',5): print repr(s),
...
'123xx' '678xx' 'Cxx' '_and so forth'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
imilar fashion,
which gives me the feeling that -xx- as custom infix operator would
work for a lot of contexts. BTW, the ast for "left |isa| right" is
Bitor([Name('left'), Name('isa'), Name('right')])
which probably makes it faster to recognize. Obviously subtrees not
involving the specal op names would be ignored.
I don't know if ast-rewriting on the fly during customizable import
excites anyone, or if those who understand what I'm doing would just
rather I didn't post about it "devant les enfants" ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
am running it in a console window.
Python 2.4b1 (#56, Nov 3 2004, 01:47:27)
[GCC 3.2.3 (mingw special 20030504-1)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 04 Sep 2005 10:10:33 +0200, Peter Otten <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>[it.next() appears to be a noop in the interactive interpreter]
>
>> I guess it could be in the read-eval-print loop
>
>Indeed:
>
>>>> for i in r
r deleting the sentence in which the Python doc tries to
>define mathematical integers.
>
> Integers
>
> [In Python] There are three types of integers:
>
This is a nice site:
http://mathworld.wolfram.com/WholeNumber.html
http://mathworld.wolfram.com/topics/Integers.html
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
the larger context might be fine or not, but no one can say ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
e main language requirement
(stated, that is ;-)
But "capacité de dialoguer avec des usagers non techniques et tous les membres
de l'équipe"
probably means French too ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;
r => [0, 1, 'b', 'a', 4, 5]
but two reverse relative slices match order, so
r = range(10)
r[5:-3] = range(10)[-1:-3] # rh seq is 9, 8
r => [0, 1, 8, 9, 4, 5]
I think this is kind of interesting, and I probably wouldn't have thought of
it if I had not been for Ron's enthusiasm for his "misunderstanding" ;-)
In a way, "misunderstandings" are the mutations of open source evolution of
ideas,
most of which die, but some of which mutate again and may occasionally survive.
So we need them ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t; task most likely, unless communication is
entirely via a mutable task state object, and all that's needed is to
me map to that and mess with exit state there and trigger a final .next()
to wrap up the generator.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 5 Sep 2005 22:56:29 +0200, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>>>as long as you have people that insist that their original misunderstandings
>>>are the only correct way to model the real world, and that all observe
7;100'
>>> bc(-1^3L, 2)
'100'
>>> bc(~3L, 8)
'74'
>>> bc(-1-3L, 8)
'74'
>>> bc(-1^3L, 8)
'74'
>>> bc(~3L)
'96'
>>> bc(-1-3L)
'96'
>>> bc(-1^3L)
'96'
>>> bc(bcdecode(bc(~3L)))
'96'
>>> bc(bcdecode(bc(~3L, 2),2),2)
'100'
>>> bc(~3L, 16)
'fc'
>>> bc(-1-3L, 16)
'fc'
>>> bc(-1^3L, 16)
'fc'
>>> bc(3L)
'03'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
;> import sys
>>> bc(sys.maxint*4, 16)
'01fffc'
>>> bc(~sys.maxint*4, 16)
'fe'
oops, precendence ...
>>> bc(~(sys.maxint*4), 16)
'fe0003'
vs. the useless
>>> hex(~(sys.maxint*4))
'-0x1FF
On Mon, 05 Sep 2005 21:39:31 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On 5 Sep 2005 07:27:41 -0700, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
>
>>I still think there are savings to be had by looping inside the
>>try-except block, which avoids many setup/t
ral other fixes.
>
>Homepage:
>
><http://starship.python.net/crew/theller/py2exe>
>
>Download from the usual location:
>
><http://sourceforge.net/project/showfiles.php?group_id=15583>
>
>Enjoy,
>
>Thomas
>
I haven't tried this, but I am getting interested in cannibalizing some
functionality ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
args = map(float, cmd[1:])
print getattr(algomodule, cmd[0], (lambda name, *ign: 'No such
function: %r'%name).__get__(cmd[0], str))(*args)
this would (theoretically ;-) let you type commands like
sqrt 9
and have alogomodule.sqrt called with float('9'), and then
edit
and edit the module source in notepad, and then
sqrt 16
and have the new function called, etc.
The cmd module will let you set up something fancier than above, and obviously
you don't have to run notepad ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
7;m fairly certain that 'sort' won't start spending CPU time
>until it has collected all its input, so you won't gain much
>there either.
>
Why wouldn't a large sequence sort be internally broken down into parallel
sub-sequence sorts and merges that separate processors can work on?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 06 Sep 2005 10:31:33 GMT, Ron Adam <[EMAIL PROTECTED]> wrote:
>Steve Holden wrote:
[...]
>
>> My point was that you can make those changes in your own code, leaving
>> others to accept the situation as it is.
>
>It's only a suggestion and an interesting idea I thought I would share
>and s
e thought (and some additional considerations)
I hadn't read yours yet, or I would have mentioned it ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
tion is primarily used by graphics applications to
create a console window. Graphics applications are
initialized without a console. Console applications are
normally initialized with a console, unless they are created
as detached processes (by calling the CreateProcess function
with the DETACHED_PROCESS flag).
See Also
CreateProcess, FreeConsole, GetStdHandle
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t;Is it a bug or a control behavour ? I don't understand ?!?!?!?!...
>
Others have pointed out the output formatting and binary representation
problems behind your question, but I thought you might not realize the above.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
s both the true and false results,
>> which may have side effects.
>
>If you are depending on that kind of nit-picking behavior,
>you have a serious design flaw, a bug waiting to bite you,
>and code which shouldn't have been embedded in an expression
>in the first place.
>
Or you might know excatly what you are doing ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
enumerate('dab'))
{'a': 2, 'b': 1, 'd': 3}
though note that dict wants the sequence as a single argument:
>>> dict( ('d', 3), ('a', 2), ('b', 1) )
Traceback (most recent call last):
File "", line 1, in ?
lues
that would appear in full matrix representations of the same.
http://www.rush3d.com/reference/opengl-redbook-1.1/appendixg.html
Also wondering about some helper function to measure sensitivity of
.solve results when getting near-singular, but maybe that's an
out-side-of-the package job.
r the chance is
>that you:
>- Search longer for fitting technologies
>- Adapt your road
- Think more carefully about ego satisfaction cost/benefit vs getting the job
done ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
.org/pub/python/2.4.1/Python-2.4.1.tgz is ~9mb)
and people could also post with url references to particular sources.
Seems like providing source trees could be automated, so there would
only be an initial effort involved.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
e, unless the OS goes to the net for a more accurate time. Usually
drift swamps the second resolution in short order though (a problem for
networked parallel makes BTW?)
Enough rambling ...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
_
of a container being iterated over effectively modifies the initial parameters
of
the iteration control, so there you need either to have intimate knowledge of
how
the iterator does its thing, or you have to insulate yourself from that need.
OTOH, a mutation of the content can be safe, if it doesn't modify the content
yet to be accessed during the iteration.
In the case of a list, the order can be depended on, so it's not that hard.
Other iterable containers are not so clear, and of course even in a list you
could have cases of access to early items having side effects on upcoming items,
e.g., if the "keep" evaluation had side effects on deep data shared between
early
and later list items. But that would be nasty any which way ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
n't modify or delete an existing important
file until you know you have a new representation safely completed. I say
"new representation" since that also covers the possiblity of original plus
diff patch file as separate files, which could also be an option.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
clog up the digest with details and code snippets, does this sound
>familiar to anyone?
>
A snippet demonstrating a real bug would be helpful.
A snippet demonstrating a misunderstanding could be helpful.
What's the problem? ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>Another poster suggested a solution using struct. Here's my
>solution (which assume python integers are represented in 2's
>compliment binary):
>
>def ioctlValue(i):
>if i & 0x8000:
>i = -((i^0x)+1)
>return i
>
Do you think it's PEP-able, or should I quit being obnoxious ;-)
I think str.mod format like %x except %.b would make it
easy to write '0h%08b.16' % a_signed_integer and get something both
readable and inputtable as a constant. (0h. would be short
for 0b16.) BTW, %b (or %B for uppercase) could default to base 16.
The ouput would only be as wide as necessary, with the leading digit
guaranteed 0 or f (which is 0 or in the general case).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
thon interface, in which case an
interface object could have a suitable property to do the final
trimming or padding of bits. Or do you want to define some kind
of mathematical space? For specifying bits in literals see my
other post in this thread (I think ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
gt;'lucy':4,
>'sky':55,
>'diamonds':239843,
>'yesterday':4 }
>
>items = sorted( (v,k) for (k,v) in original.iteritems() )
>items.reverse() # depending on what order you want
>print items
>
>
>The result is:
>[(239843, '
(most recent call last):
> File "", line 1, in ?
>TypeError: float() takes at most 1 argument (2 given)
>
>So my question to you is: how can I change my code so I can pass two
>values to the WrapFloat constructor?
>
Float is an immutable, so you need to override __new__
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 17 Sep 2005 11:01:41 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> or tell sorted what to do ;-)
>>
>> >>> original= {
>> ... 'hello':135,
>> ... 'goodbye':30,
>> ... 'lucy':4,
in groupby(lines,
... lambda line:line.strip()!='') if k):
... print ''.join(t)
...
200501221530
John
*** long string here ***
200503130935
Jeremy
*** jeremy string here
200504151625
Clyde
*** clyde's long string here ***
>>>
If your source of line groups is not delimited by blank lines,
or has other non-blank lines, you will have to change the source
or change the lambda to some other key function that produces one
value for the lines to include (True if you want to use if k as above)
and another (False) for the ones to exclude.
HTH
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
mt.__new__:', mt.__new__
... something = mt.__new__(mt, cname, cbases, cdict)
... print 'something:', something
... return something
...
>>> class B(A): __metaclass__ = bar
...
cname, cbases: B (,)
cdict: {'__module__': '__main__', '__metaclass__': }
mt:
mt.mro(mt): [, ]
mt.__new__:
something:
>>>
And the something returned, whatever it is, if no checking is triggered by
normal use,
gets bound to the class name, e.g.,
>>> class C(A): __metaclass__ = lambda *a:('silly', 'result')
...
>>> C
('silly', 'result')
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
d act like if False
if 1 would act like if True
if 0.0would act like if False
if 5.0would act like if True
if '' would act like if False
if 'a'would act like if True
if [] would act like if False
if [1]would act like if True
if {} would act like if False
if {1: 2} would act like if True
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 19 Sep 2005 00:02:34 -0700, "malv" <[EMAIL PROTECTED]> wrote:
>Simple case:
>In this list, how to find all occurences of intervals of n adjacent
>indexes having at least one list-member with a value between given
>limits.
>Visualizing the list as a two-dimensional curve, this is like
>horizonta
On Mon, 19 Sep 2005 22:58:40 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On 19 Sep 2005 00:02:34 -0700, "malv" <[EMAIL PROTECTED]> wrote:
>
>>Simple case:
>>In this list, how to find all occurences of intervals of n adjacent
>>indexes having at least on
you can use other expressions than bool(x) to get the boolean
value, but you may have to think more about whether (x and 1) will
do it, or whether you should write (x!=0) or, in case x can be None,
perhaps settle on (x and 1 or 0) as an idiom to play safe.
Well, bool(x) is safe, and less typing ;-) OTOH, it's not a hammer for all
nails.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
D_ATTR3 (x)
anti-attribute, remove above byte code
51 BUILD_TUPLE 4
54 RETURN_VALUE
You might want to do the same for LOAD_GLOBAL/STORE_GLOBAL, and
STORE_DEREF/LOAD_DEREF, I don't know. But it wouldn't be a big deal
to get a hack working. Thorough testing is another matter,
not to mention justifying it ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
in all of this
>> pertains to files on Windows XP and Python 2.4
>
>Please clarify: is your question about identifying binary (non-ascii) files
>or about using os.walk?
>
>
I have a feeling it's about walking directories and identifying which files
to should be "cooked" (to normalize line endings when opened and read).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>> list(sd)
['f', 'o', 'o', '\n', '\x00']
You could make a de-escaping utility function, e.g.,
>>> def de_esc(s): return s.decode('string_escape')
...
>>> s
'foo\\n\\0'
>>> de_esc(s)
'foo\n\x00'
You might want to write a test to verify that it does what you
expect for the kind of escaped string you are using.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
# presets.py -- a decorator to preset function local variables without a
default-argument hack or closure
# also does currying, with adjustment of argument count, eliminating named
arguments from right.
# 20050310 09:22:15 -- alpha 0.01 release -- bokr
# Released to the public domain WITH
ce?
>
Are you the same person who posted re this format some time ago?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;a', 'b', 'c'])
>>> for list1_item, list2_item in zip(firstlist, secondlist):
... print list1_item, list2_item
...
1 a
2 b
3 c
Or if your lists are very long, you could use an iterator from itertools, e.g.,
>>> import itertools
&
t here to play 20-questions.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t;d['x']. Suppose d['x'] == 3:
>
> >>> 3 is not None
>True
> >>>
>
maybe (untested)
value = ('x' in d and [d['x']] or [bsf()])[0]
then there's always
if 'x' in d: value = d['x']
else: value = bsf()
or
try: value = d['x']
except KeyError: value = bsf()
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
6 LOAD_FAST0 (x)
9 LOAD_FAST1 (y)
12 BINARY_ADD
13 RETURN_VALUE
>>> inspect.getargspec(bar)
(['x', 'y'], None, None, None)
>>> dis.dis(bar)
1 0 LOAD_FAST0 (x)
3 LOAD_FAST1 (y)
6 BINARY_ADD
7 RETURN_VALUE
I don't know where this is leading. What was your goal again?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
gt;> printf('%03d %r %3d %5.2f %5d\n',1,'two', 0x3, 4.5, fn(6))
001 'two' 3 4.5064
>>
>> Best regards,
>> Marcin
>>
>You could think about teaching them the linelist.append(fn(x)) way,
>which then gives you the choice of
>
> "".join(linelist) - no gaps
> "\n".join(lienlist) - one item per line
> " ".join(linelist) - spaces between items.
>
IMO teachers should lead their students into contact with reality,
not insulate them from it with delusionary simplifications that
they will have to unlearn in order to progress.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
re-computing full
hashes would be optimal.
Compare to sort|uniq as a sieve. You wouldn't want to read through any files
any further than you had to.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
line 6, in __init__
ValueError: You are missing some env vars: ['unknown']
If you have spaces in your environment names (possible?) that would be nasty and
you would have to change the "required" __init__ parameter to split on
something other than spaces.
You could arrange for case-insensitivity if you liked. And if you really wanted
to have local or global bindings for your env names, you could easily do that
too,
but e.g., myenv.XXX seems like a readable way to group things together.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
tdefault(num, []).append(name)
if __name__ == '__main__':
phone = Twoway({'mike':10,'sue':8,'john':3, 'jack': 3, 'helen' : 10})
print 'jack:', phone['jack']
print 'same phone as jack:', phone[phone['jack']]
print 'deleting jack ...'; del phone['jack']
print 'john:', phone['john']
print phone
-
[13:05] C:\pywk\sovm>py24 twoway.py
jack: 3
same phone as jack: ['john', 'jack']
deleting jack ...
john: 3
{'mike': 10, 3: ['john'], 8: ['sue'], 10: ['mike', 'helen'], 'sue': 8, 'helen':
10, 'john': 3}
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t;__main__.A instance at 0x02EF142C>
or a different instance
>>> foo.__get__(None, A)(A())
<__main__.A instance at 0x02EF18CC>
If you don't pass the type, some things won't work fully, but the usual will
>>> foo.__get__(a)
>
As can be seen, the original function is in there in the bound method:
>>> foo.__get__(a, A).im_func
And you can call it as such if you like:
>>> foo.__get__(a, A).im_func('hi, via plain function')
hi, via plain function
Descriptors are a big deal in the new python. They are at the root
of much of the magic.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>> ... return obj
>> ...
>> py> myobj = Object()
>> py> fun(myobj, 2)
>> <__main__.Object object at 0x01162E30>
>> py> myobj.b
>> 2
>> py> obj = fun(1)
>> py> obj.b
>> 1
>>
>> This doesn't use any bytecode hacks, but I'm still not certain it's
>> really the way to go. What is it you're trying to write this way?
Yes, that is a good question ;-)
>
>OO doesnt work here,i have factored to classes with inheritance but it looks
>clumsy and it is clumsy to use, this things are in nature,functions.
>
>What i want is to declare in the decorator some code that is common to all
>these functions, so the functions assume that the decorator will be there
>and wont need to duplicate the code provided by it, and the functions are
>not known ahead of time, it has to be dynamic.
Still not sure what you mean by "the functions are not known ahead of time."
Please pretend things worked the way you want, and post an example. Maybe we can
make it work.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
rt time
>>> inst1 = InstProp()
>>> inst2 = InstProp()
>>> inst1.t = property(lambda self: time.ctime())
>>> inst2.p2 = property(lambda self: 'prop2')
>>> inst1.t
'Sat Mar 12 19:10:40 2005'
>>> inst2.p2
'prop2'
If you want robust writeable and/or deleteable properties, you will have
to do a little more work, but it can be done.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;",
'\\', 'x', '8', '3']
>>> len(r"C\x01\x02\x10'\x83")
18
>
>> That's 18 bytes. Is the command supposed to be the ASCII
>> characters \x01 or a single byte whose value is 1?
>
>For a start, according to the OP's code, the command ('C' a.k.a. 67) is
>first. The 1 is a meant to be a message number.
>
>Secondly, the hardware smells like it's got an 8080 or 6502 inside. The
>likelihood that it groks Python/C string representation is minimal.
>Folk just don't send 18 bytes at 9600 bps when 6 bytes will do.
>
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 13 Mar 2005 03:18:51 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On 12 Mar 2005 09:48:42 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote:
>
>>I'm trying to create some read-only instance specific properties, but
>>the following attempt
On Sat, 12 Mar 2005 23:09:58 -0400, vegetax <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
[...]
>> Please pretend things worked the way you want, and post an example. Maybe
>> we can make it work.
>>
>> Regards,
>> Bengt Richter
>
>Ok , the comp
On 12 Mar 2005 20:12:19 -0800, "John Machin" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
>> On 12 Mar 2005 17:35:50 -0800, "John Machin" <[EMAIL PROTECTED]>
>wrote:
>>
>> >
>> >[EMAIL PROTECTED] wrote:
>> >>
On Sun, 13 Mar 2005 10:46:52 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> Sorry for jumping in with a largely irrelevant comment. I didn't look
>> at the code, just sought to illustrate the 6/18 thing further, in a kneejerk
>> reactio
gt;raise NoSuchDomain, domainname
> return page
Careful with the above return's indentation after you fix the try/excepts.
>
>##
>##
>--
I've heard pychecker (http://pychecker.sourceforge.net/) catches a lot of stuff.
Maybe it would help you. Having lint-eyes, I haven't yet tried it, though it
would probably save me some time ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
equivalent, but note that it only works if everyone has a different
phone number.
>>> dict((v,k) for k,v in {'sue':3, 'bob':4}.items())
{3: 'sue', 4: 'bob'}
>>> dict((v,k) for k,v in {'sue':3, 'bob':4, 'mike':4}.items())
{3: 'sue', 4: 'bob'}
Surprised at who got left out?
>>> {'sue':3, 'bob':4, 'mike':4}.items()
[('sue', 3), ('mike', 4), ('bob', 4)]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 14 Mar 2005 01:19:23 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote:
>In answer to my question about instance properties not working, Bengt
>Richter suggest using:
>> > >>> class InstProp(object):
>> > ... def __getattribute__(self, at
>> print r2.status, r2.reason
>404 Not Found
>>>> data2 = r2.read()
>>>> conn.close()
>
>As far as I can understand, you can read() data only when you want
>to.
>
>Caveat:
>There's a warning that says "This module defines classes
aven't yet seen an answer to this,
>but it's a question for experimentation rather than theory.
ISTM 2(m-1) reads is not necessary, so "the question" to me doesn't involve
that ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 14 Mar 2005 13:07:29 -0800, "Martin Miller" <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote, in part:
>> On 14 Mar 2005 01:19:23 -0800, "Martin Miller"
><[EMAIL PROTECTED]>
>> wrote, in part:
>> >What still puzzles me, though, is why
at almost the entire industry has standardized on
>power-of-2 word sizes, octal is nearly useless but is still carried
>about for backwards compatibility.
>
Actually, octal was really handy for PDP-11/45 core dumps, even though
it had a power-of-2 (4 -> 16 bits) word size. The reason wa
differing in the arguments passed.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
self): return 'Hi'
...
>>> c=C()
>>> C.ordinary_method
>>> c.ordinary_method
>
>>> c.ordinary_method()
'Hi'
>>> C.ordinary_method
>>> C.ordinary_method(c)
'Hi'
Note the difference between ordinary and classmethod:
>>> type(c).ordinary_method
>>> type(finst).__getitem__
>
BTW, I see a class factory, but no "(meta)"class per se.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
__getitem__=classmethod(__getitem__)
...baz.lst = lst
...return baz
...
>>> f = foo([1,2,3])()
>>> type(f).__getitem__
>
>>> type(f).__getitem__(0)
1
Leaving out the classmethod:
>>> def foo(lst):
...class baz(object):
... def __getitem_
gt;... return self.vals[index]
>...
>py> lst = 'abcd'
>py> x = 'b'
>py> e1 = enum(lst)
>py> v = e1(x)
>py> (x in lst) and (e1[v] == x)
>True
For that, why not just
class enum(list):
def __call__(self, val): return self.index(val)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 15 Mar 2005 00:18:10 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
>> On Mon, 14 Mar 2005 14:48:25 -, "Alex Stapleton"
><[EMAIL PROTECTED]> wrote:
>>
>> >Whilst it might be able to do what I want I fee
On Tue, 15 Mar 2005 08:32:51 -0800, Ron Garret <[EMAIL PROTECTED]> wrote:
>In article <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] (Bengt Richter) wrote:
>
>> >Did you mean type(x).__getitem__(x,y)?
>> >
>> Not if x is a classmethod,
D'oh. I meant &qu
m(self): print 'method m called'
...x = 123
...
>>> obj = Sub()
Instance attributes work normally:
>>> obj.x
123
>>> obj.x = 456
>>> obj.x
456
>>> del obj.x
If not shadowed, the class var is found
>>> Sub.x
123
But it is read-only:
>>> Sub.x = 456
Traceback (most recent call last):
File "", line 1, in ?
File "", line 4, in __setattr__
AttributeError: setting 'x' to 456 not allowed
>>> Base.x = 456
Traceback (most recent call last):
File "", line 1, in ?
File "", line 4, in __setattr__
AttributeError: setting 'x' to 456 not allowed
>>> Sub.anything = 'something'
Traceback (most recent call last):
File "", line 1, in ?
File "", line 4, in __setattr__
AttributeError: setting 'anything' to 'something' not allowed
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
)))
>((= i 10))
>(vector-set! closures i (lambda (x) (+ x i
>((vector-ref closures 5) 1000))
>1005
>
>and what is perhaps surprising, Perl wins:
>
>$ perl -e '
> foreach my $i (0..9) {
> push @closures, sub {$_[0] + $i}
> }
> print $closures[5](1000), "\n"'
>1005
>
>
>If you think it's unlikely that one would want to keep a closure
>referring to a loop control variable longer than the loop iteration
>which has created it, think about the loop body spawning a thread.
>
Just do what you need to do. Python usually provides a way ;-)
Or do you just want what you want using your idea of the right spelling? ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
nuation object of some kind, that could optionally
be called
from the exception handler to effect as-if return to the point of an exception
and
continuation from there as if the exception hadn't happened (except maybe some
updated
binding in the local context that could be seen by the continuing
from a config file; I'll do it in my code as a
>default, and if users want any *other* behavior, they can config *that*.
>
To fish for yourself, go to google and put
RotatingFileHandler site:docs.python.org
in the search slot and click search.
The first hit is
http://docs.python.org
of it while still keeping the matched part.
>>
>>
>> Something like
>> re.sub(r'^([A-Z])', r'~\1', target)
>> should do it.
>>
>> Kent
>
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
mizations to the function-local namespace which prevent
>transparent re-binding of global names. And given that the
>function-local namespace is by far the most heavily used, and the
>relative utility (and wisdom) of using globals in this way, this is a
>case where the benefit of the special case is well worth the cost of
>its slight inconsistency.
The optimization argument goes away with x := something I think, since
the x search can be limited to looking in the lexical environment
exactly like looking for read-only outer scope names now, just with
different consequences for finding or not finding.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
;, 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['a', 'c']), set(['i',
'h', 'g'])]
[set(['a', 'c'])]
[set(['k', 'r', 'l']), set(['a', 'c']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['h', 'g']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b']), set(['a', 'e', 'd', 'f']),
set(['i', 'h'])]
[set(['a', 'e', 'd', 'f']), set(['a', 'c']), set(['i', 'h'])]
[set(['a', 'c']), set(['h', 'g']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['a', 'c'])]
[set(['a', 'e', 'd', 'f']), set(['i', 'h', 'g'])]
[set(['a', 'c', 'b']), set(['a', 'e', 'd', 'f']), set(['h', 'g']), set(['i',
'h'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['a', 'c']), set(['h',
'g'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['h', 'g']), set(['i',
'h'])]
[set(['a', 'e', 'd', 'f']), set(['a', 'c'])]
[set(['k', 'r', 'l']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'c']), set(['h', 'g']), set(['i', 'h'])]
[set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b']), set(['i', 'h'])]
[set(['a', 'c', 'b']), set(['i', 'h', 'g'])]
[set(['a', 'c', 'b']), set(['a', 'e', 'd', 'f']), set(['h', 'g'])]
[set(['a', 'c', 'b']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b']), set(['a', 'e', 'd', 'f']),
set(['h', 'g']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b']), set(['i', 'h', 'g'])]
[set(['a', 'c', 'b']), set(['i', 'h'])]
[set(['a', 'c']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'c']), set(['i', 'h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['a', 'c']), set(['h',
'g']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f'])]
[set(['a', 'c']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['i', 'h', 'g'])]
[set(['a', 'e', 'd', 'f']), set(['a', 'c']), set(['h', 'g'])]
[set(['a', 'e', 'd', 'f']), set(['h', 'g']), set(['i', 'h'])]
[set(['a', 'c']), set(['i', 'h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'c']), set(['i', 'h'])]
[set(['k', 'r', 'l']), set(['a', 'c'])]
[set(['a', 'e', 'd', 'f']), set(['h', 'g'])]
[set(['k', 'r', 'l']), set(['a', 'c', 'b']), set(['h', 'g']), set(['i', 'h'])]
[set(['a', 'e', 'd', 'f'])]
[set(['i', 'h', 'g'])]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;, 'd', 'f']),
set(['h', 'g']), set(['i', 'h'])]
5: [set(['k', 'r', 'l']), set(['a', 'e', 'd', 'f']), set(['a', 'c']),
set(['h',
the key should be emphasised more. Hence valadd or such?
>
>The appendlist() method is not as versatile as setdefault() which can be used
>with other object types (perhaps for creating dictionaries of dictionaries).
>However, most uses I've seen are with lists. For other uses, plain Python code
>suffices in terms of speed, clarity, and avoiding unnecessary instantiation of
>empty containers:
>
>if key not in d:
>d.key = {subkey:value}
>else:
>d[key][subkey] = value
>
Yes, but duck typing for any obj that supports "+" gets you a lot, ISTM at this
stage
of this BF ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 19 Mar 2005 03:14:07 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
[...]
>Yes, but duck typing for any obj that supports "+" gets you a lot, ISTM at
>this stage
>of this BF ;-)
Just in case, by "this BF," I meant to refer to my addval idea,
with no offens
def')]
?
I get:
0: []
6: [set(['a', 'c', 'b']), set(['e', 'd', 'f'])]
6: [set(['a', 'c', 'b', 'e', 'd', 'f'])]
Your code above:
>>> L = [set('abc'), set('def'), set('abcdef')]
>>> length=[len(s) for s in L]
>>> L2= sorted(zip(length,range(len(L
>>> Lnew=[L[j] for (i,j) in L2]
>>> Lnew.reverse()
>>> Lun=[Lnew[0]] # list with the result
>>> for s in Lnew[1:]:
... keep=True
... for i in range(len( Lun) ):
...if len(s)==len( s & Lun[i] ):
... keep=False
... break
... if keep==True:
...Lun.append( s )
...
>>> Lun
[set(['a', 'c', 'b', 'e', 'd', 'f'])]
But your successful set list is not unique in its success value (6) ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 19 Mar 2005 07:13:15 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> On Sat, 19 Mar 2005 01:24:57 GMT, "Raymond Hettinger" <[EMAIL PROTECTED]>
>> wrote:
>>
>>>I would like to get everyone's thoughts on
a),
>>> type(type(a)))['__getitem__'].__get__(
a,
type(a)).__call__
Which we can call with the index
>>> type(type(a)).__dict__['__dict__'].__get__(type(a),
>>> type(type(a)))['__getitem__'].__get__(
a,
type(a)).__call__(0)
0.5
Fortunately, we don't normally have to think about all that when we write
>>> a[0]
0.5
;-)
Caveat: this is not based on reading the code internals, so I could be
misinterpreting surface
appearances, but at least it ought to be clear that a[0] involves a lot of
dynamic decisions that
might ordinarlily not be taken, but which must be allowed for in looking for an
innocent method
like __getitem__ ;-)
[Hm, just looking in oubox: this apparently didn't go out the other day.]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
436346798089144038222112768000*x**4
-2718608642882609434610843144764478140416*x**3
+1533994355659295223664305312404777140224*x**2
-388225373807829537910251710026682204160*x
+23023948231698183889631576064000)
/274094621805930760590852096000
)(x)) for x in xrange(32)])
Not-ready-to-be-mytholo
1 (foo)
6 CALL_FUNCTION0
9 LOAD_GLOBAL 2 (Ellipsis)
12 COMPARE_OP 8 (is)
15 RETURN_VALUE
Disassembly of foo:
3 0 LOAD_FAST0 (self)
3 LOAD_CONST 1 (Ellipsis)
6 BINARY_SUBSCR
7 RETURN_VALUE
HTH
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
m.uniform(0,1))
-0.261249141864835
>>> math.log(1.0-random.uniform(0,1))
-0.99694366818547997
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>
>Untested:
>
>dict( (key,value) for (key,value) in row.iteritems() if key in cols )
If there's an overall why for doing it at all, why not just iterate through
keys of interest? I.e., (untested)
dict( (key, row[key]) for key in cols )
>
>Works in Py2.4
>
>Stefan
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 30 Nov 2004 21:54:46 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
[...]
>
>If there's an overall why for doing it at all, why not just iterate through
>keys of interest? I.e., (untested)
>
> dict( (key, row[key]) for key in cols )
>
Sorry Anton, I didn't se
501 - 600 of 974 matches
Mail list logo