On Sun, 23 Apr 2006 22:12:01 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
[...]
>(IMO the proper way to indicate the you don't have a tuple is to use None or
>some other sentinel,
>not abuse a perfectly legal tuple value).
>
> >>> dis.dis(compile('class X:p
t; with compatibility of existing code IMHO.
>
>It's mostly a good way to add inconsistency and confusion to a situation
>that's already confusing enough for newbies.
I don't agree with your idea of inconsistency.
IMO it would be better to explain that a legal basetuple value (empty tuple) is
currently
being abused as a logical flag to call types.ClassType(clsname, basestuple,
clsdict)
instead of type(clsname, basestuple, clsdict), and explain that it will be
corrected, so that
class X():pass will now call the latter, consistent with class X(bases):pass.
Bottom line: IMO class C():pass should create a new-style class,
and the parens serve well as a reminder of which kind it is, whether empty or
not,
until py3k.
I.e., make it easy for newbies: parens means new-style, no parens means
old-style, until py3k.
Pontificating pushes my counter-pontificating button; that's the only
explanation
I have for doing this. I was going to stop wasting time, but find myself
unable as yet fully to abandon scanning clp and python-dev ;-/
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
Personally, I'd always use (depending on guesses regarding lengths of
>lists) [x for x in l1 if x in l2] or the setified equivalent, of course.
>
Perhaps newbies should be advised that
[x for x in l1 if x in set(l2)]
is not a (well) setified equivalent? I could see them being tempted.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
large
else:
large,also
but that reads gawdawfully. (So, I imagine, does about any code hitting the
offset limit ;-)
If it's a matter of too many elifs, the OP could break that more readably, e.g.
(untested)
done=True
if cond:
bla
elif c2:
bla 2
s module().
OTOH, I could see wanting to define properties, and access module.latest_foo
and have it choose dynamically from versioned stuff, or something like that.
Of course you can write module.get_latest_foo() as an ordinary function, and
not be bothered with subclassing and jimmying sys.module
On Tue, 07 Feb 2006 18:10:05 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
[...]
>< ernesto.py >-
[...]
Just noticed:
>substrings = line.split()
>if substrings and isinstance(substrings, list) and substrings
s
>that if I just assign to the list variable it just modifies the local
>(to the function) name space, and that those changes aren't reflected
>in the list in the original name space.
>
>I believe there are some ways around this, but I haven't found one that
>would not require any special handling in either the code calling the
>client stub or the original functions. I want to maintain transparency.
>
>etv
>
Good luck ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
106 SocialSecurity: 123456789'
[Person('David'), Person('Ernesto')]
ssdict keys: [123456789, 476892771999L]
Name: David Age: 108 SS: 476892771999
Name: Ernesto Age: 25 SS: 123456789
if you want to try this on a file, (we'll use the source itself here
since it includes valid example data lines), do something like:
>>> import ernesto
>>> info = ernesto.extract_info(open('ernesto.py'))
AssertionError: Bad second line after "Name: Ernesto" line:
'Age: 44 Brithdy: 040106 SocialSecurity: 123456789\n'
>>> info
[Person('David'), Person('Ernesto')]
tweak to taste ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
(s)
>>> binascii.unhexlify(h)
'\x00\x01\x02\x03ABCD0123'
>>> b64 = binascii.b2a_base64(s)
>>> binascii.a2b_base64(b64)
'\x00\x01\x02\x03ABCD0123'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
at if '\n' *doesn't* signify a line break on the Mac,
>then it may exist in the body of the text - and trigger ``ending =
>'\n'`` prematurely ?
>
Are you guaranteed that text bodies don't contain escape or quoting
mechanisms for binary data where it would be a mistake to convert
or delete an '\r' ? (E.g., I think XML CDATA might be an example).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
cant fraction of the total execution time. There is little or no
>point in avoiding generators due to a misplaced and foolish attempt to
>optimise your code.
>
I show an advantage favoring generator resumption vs function call:
>>> from time import clock
>>> def f(): return clock()
...
>>> def g(): yield clock(); yield clock()
...
>>> max(f()-f() for x in xrange(1))
-9.2190462142316409e-006
>>> max(f()-f() for x in xrange(1))
-9.2190462139818408e-006
>>> max(float.__sub__(*g()) for x in xrange(1))
-7.5428559682677587e-006
>>> max(float.__sub__(*g()) for x in xrange(1))
-7.5428559682677587e-006
>>> max(float.__sub__(*g()) for x in xrange(1))
-7.5428559682677587e-006
(It'll probably go ten times faster on a recent box ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
oo
...
popdir
log,file,c:\temp\foo\log.txt
log,on
...
log,off
etc. etc)
Of course, you can jigger an INI file to contain any info you want also,
even using the windows
{Get,Write}PrivateProfile{String,Int,Section,SectionNames}
API functions, which like many MS APIs IME of yore seem to work simply if you
conform to
their usage preconceptions, but punish you with info discovery hell otherwise
;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ree:
(S (NP (NP The horse)
(VP raced
(PP past
(NP the barn
(VP fell)
.)
IIUC, that's the way I parse it too ;-)
(I.e., "The horse [being] raced past the barn fell.")
BTW, the online response has some clickable elements in the diagram
to get to definitions of the terms.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
n just permit only the
>http: protocol?
>
How about finding the browser via .html association and then letting that
handle the url? E.g., slong the lines of
>>> import os
>>> ft = os.popen('assoc .html').read().split('=',1)[1].strip()
>>> ft
'MozillaHTML'
>>> os.popen('ftype %s'%ft).read().split('=',1)[1].strip()
'D:\\MOZ\\MOZILL~1\\MOZILL~1.EXE -url "%1"'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
te" virtual blocks when it gets real
zero blocks to write from a user, or even with file system copy utils?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
; print "%(key)s" % d
'key'
test
>>> print "%((1,2))s" % d
'(1,2)'
(1, 2)
Right
>>> d[123] = 'onetwothree'
>>> print "%(123)s" % d
'123'
123
onetwothree
Note recursive printing of convert
ilias_lazaridis.py
peter 16
anton 21
name=peter, age=16,
name=anton, age=21,
(the first for user in users loop presumes knowledge of the field names name
and age.
The second gets them automatically from the names loaded in the load method from
the first line of the text file. The second l
o get the data and then prints the message. E.g.,
program1.print_the_message('John')
instead of
program1.inst.John()
No class needed.
OTOH, if you are going to use a class, you might want to name it
capitalized (more conventional) and derive from object, or subclass
from something else if it makes sense. I.e. class Klass(object): ...
What kind of "database" are you accessing? An RDBMS? A CSV text file?
A directory full of named single-line files (ugh), or?
How often will you access the data? Are you the only one?
Requirements, requirements ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
val(((8, PLUS, 6), TIMES, (MINUS, 2)))
PLUS(8, 6)
MINUS(2, None)
TIMES(14, -2)
-28
>>> seqeval((MINUS, (8, PLUS, 6), TIMES, (MINUS, 2)))
PLUS(8, 6)
MINUS(14, None)
MINUS(2, None)
TIMES(-14, -2)
28
>>> list(seqeval((i, TIMES, j, PLUS, k)) for i in (2,3) for j in (10,100) for
>>> k in (5,7))
TIMES(2, 10)
PLUS(20, 5)
TIMES(2, 10)
PLUS(20, 7)
TIMES(2, 100)
PLUS(200, 5)
TIMES(2, 100)
PLUS(200, 7)
TIMES(3, 10)
PLUS(30, 5)
TIMES(3, 10)
PLUS(30, 7)
TIMES(3, 100)
PLUS(300, 5)
TIMES(3, 100)
PLUS(300, 7)
[25, 27, 205, 207, 35, 37, 305, 307]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
of LatInt might work, since it's a string (so is Latitude))
>TypeError: cannot add type "int" to string
^^ ^^^ ^^
This is not lying ;-)
>
>
>I tried print repr(filename) and it returned the actual filename:
>'n16w099.asc' , 'n17w062.asc' , etc.
So you can see Latitude would be '16' '17' etc. right?
On to the next traceback ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
(vars(x))
>>> type(x.__dict__)
>>> vars(x)['?']
'THIS ITEM NOT AVAILABLE'
>>> type(x)
>>> type(x).__dict__
>>> type(x).__dict__['__dict__']
>>> type(x).__dict__['__dict__'].__get__
nt call last):
> File "", line 1, in
>TypeError: expected 0 arguments, got 1
>
>>> def square(xbox):
... while True: yield xbox[0]*xbox[0]
...
>>> xbox = [3]
>>> g = square(xbox)
>>> g.next()
9
>>> xbox[0]=4
>
and yielding that to tell the world the latest. Since
only attributes
are being modified, the original state binding could be used and the
generator's yielded
value could be ignored, but it could be handy if the generator is passed around
IWT.
The world could also feed info in as attributes of state. And other generators
could share
the same external state variable and all kinds of weird things could be built
;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
And
all
that in the face of the fact that much of the problem will be engineering
consensus,
not engineering technical solutions. So are you excited? Good luck ;-)
Probably the best anyone with any excitement to spare could do is ask Martin
what he could use help with, if anything. He'd probably not like muddying any
existing clear visions and plans with impractical ramblings though ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ems of
a generator from the outside, e.g.,
def gfoo(x, y):
while True:
yield x**2 + y**2
ifoo = gfoo('dummy','dummy') # or first pair
for ifoo.x, ifoo.y in pairs: print ifoo.next()
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
dict__
>>> X.__dict__['__dict__']
and
>>> class Y(object):
... def _getdict(self): print '_getdict'; return self._dict
... __dict__=property(_getdict)
... def __init__( self ):
... self._dict = CustomDict( foo = 'bar' )
...
>>> y = Y()
>>> y.__dict__
_getdict
{'foo': 'bar'}
>>> y._dict
{'foo': 'bar'}
>>> y.foo
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'Y' object has no attribute 'foo'
>>> def ga(self, attr): print '__getattr__(%s)'%attr; return
>>> self.__dict__[attr]
...
>>> Y.__getattr__ = ga
>>> y.foo
__getattr__(foo)
_getdict
'bar'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
= str(Latitude)
you probably won't need a print repr(LatString) here if you see the above print
>LatInt = int(LatString)
>radians = LatInt * 0.0174532925
>zFactor = 1/(113200 * (cos(radians)))
>
BTW, capitalizing the first letter of python variable names is counter to usual
convention.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 23 Jan 2006 04:00:40 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
>
[...]
>> It wouldn't be shadowing, but I suppose you could replace sys.stdout with
>> a custom object whose methods check where they were called from.
>&g
e classes, functions are functions.
classes seem to be classobjs, designed to implement classic class behavior
but using the new machinery to achieve compatible integration.
>
>Admittedly I still confused between the various flavours of functions
>(function, bound method, unbound method, class method, static method...)
>*wink* but the difference between types and functions is fairly clear.
>
>Just don't ask about the difference between type and class... *wink*
>
Why not? ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 23 Jan 2006 08:53:59 +1300, Carl Cerecke <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> On Thu, 19 Jan 2006 23:16:57 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
>
>> How about something like
>>
>> >>> actions = dict(
&
alled from.
Then you could give the object initialization parameters as to which namespace
you want to have the effect in, and/or methods to control the action or turn
it on or off etc. BTW, how about stderr?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 21 Jan 2006 14:28:20 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Fri, 20 Jan 2006 04:25:01 +, Bengt Richter wrote:
>
>> On Thu, 19 Jan 2006 12:16:22 +0100, =?ISO-8859-1?Q?Gerhard_H=E4ring?=
>> <[EMAIL PROTECTED]> wrote:
>> [...]
&g
be looking into Pysco or Pyrex and avoid making your
>code really unreadable.
>
How about something like
>>> actions = dict(
...a=compile('print "A"; state="b"','','exec'),
...b=compile('print "B"; state="
represented as a float. So is 1.5 and so are more other values
than
you can count with an ordinary int ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
on that does not recompute the
>whole list each time. Any ideas?
>
Make a custom class factory that makes a class with a1..aN and can be
instantiated
with x, producing an object that behaves like L
So the question in my mind is, how are you actually going to use these "L"
things?
you mention that "=" is not "==" in python?
I too would resist the idea that
assert a*2.5e-8 == x
"should be written as"
x = a*2.5e-8
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 18 Jan 2006 04:19:37 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
>> Typos happen to all of us, but in case you hadn't realized what "it's"
>> is a contraction for ("it is"), now you do, and you can save
uot; or it's first letter is "i" ? ;-)
And how many "it"s (?) are there in the previous sentence?
I wonder if "Eats Leaves and Shoots" (a book on punctuation) has something on
that.
(vs, "Eats, Leaves, and Shoots" -- panda vs gunslinger).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ath.floor( 5.5)) => 5
Which ISTM is the way some other int conversions have worked, but I can't
recall the context ATM.
I.e., just trim the fractional bits from the theoretical fixed point twos
complement number, which
always subtracts those positive-value fractional bits algebraically.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
;test from c"
...
>>> c = C(True)
>>> c.test()
Traceback (most recent call last):
File "", line 1, in ?
File "", line 5, in _null
Exception: not allowed to access
>>> c2 = C(False)
>>> c2.test()
test from c
>>> vars(c)
{'test': >}
>>> vars(c2)
{}
>>> R._restrict
['test']
Still don't know what real application problem this is solving, but that's ok
;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
on is
defined within a factory function).
This can be used to advantage sometimes, but needs good documentation to be
clear for the next code maintainer ;-)
I guess I should re-read your original requirements that led to thes design
ideas.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Mon, 16 Jan 2006 10:34:40 +, Bengt Richter wrote:
>
>> >>> class A:
>> ... def __getattr__(self, attr): print 'A().%s'%attr; raise
>> AttributeErro
On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>On Mon, 16 Jan 2006 10:34:40 +, Bengt Richter wrote:
>
>> >>> class A:
>> ... def __getattr__(self, attr): print 'A().%s'%attr; raise
>> AttributeErro
x27;%attr; raise AttributeError
...
>>> class B:
... def __getattr__(self, attr): print 'B().%s'%attr; raise AttributeError
...
>>> A()==B()
A().__eq__
B().__eq__
B().__eq__
A().__eq__
A().__coerce__
B().__coerce__
A().__cmp__
B().__cmp__
False
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
print 'Inside Parent.__init__()'
...
>>> class Child( Parent ):
... def __init__( self ):
... sup = simple_super(self)
... sup.__init__()
... self.sup = sup
... print "Inside Child.__init__()"
...
>>> c = Child()
Inside Parent.__init__()
Inside Child.__init__()
>>> c.sup
<__main__.simple_super object at 0x02EF80EC>
>>> c.sup.__init__
>
>>> c.sup.__init__()
Inside Parent.__init__()
I don't know if this helps ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t;for chunk in iter(f.read, '', (blocksize,)): ...
>
Whatever "Which" refers to got snipped or may be in a post that hasn't
become visible for me yet, but I assume Jean-Paul was referring to lambda use
as in e.g. (untested):
for chunk in iter(lambda frd=open(
bject has no attribute 'x'
>--- /output -
>
>Why isn't this inherited method call working right?
The method call is working fine. It's just that as before
Child.__init__ overrides Parent.__init__ without calling
Parent.__init__ or set
On Sun, 15 Jan 2006 08:08:16 -0500, "Roger Upole" <[EMAIL PROTECTED]> wrote:
>
>"Bengt Richter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>> On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <[EMAIL PROTECTED]> wrote:
if os.popen('dir %s:\\xxx'%c).read()]
...
>>> fakeGetLogicalDriveStrings()
['C:', 'D:', 'E:', 'V:', 'W:']
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
way of genera modular definition
http://www.adaic.org/standards/95lrm/html/RM-3-5-4.html
and here is the fixed point
http://www.adaic.org/standards/95lrm/html/RM-3-5-9.html
Whoo, I haven't been into that stuff almost since Ada was "green" ;-)
Makes me wonder if generators could usefully have rendezvous('?, es?) ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
'Soiltypes', 'parent':'Soil'}
]
children = {}
for d in source_list:
children.setdefault(d['parent'], []).append(d['title'])
def get_progeny(title, d=children):
if title in d: return [title] + [get_progeny(child) for child in d[title]]
else: return title
source = ['result_list = [']
result_list = []
for child in children['root']:
source.append('# %s'%child)
source.append('%r,'% get_progeny(child))
result_list.append(get_progeny(child))
source.append(']')
result_list_source = '\n'.join(source)
print result_list_source
print result_list
[18:20] C:\pywk\clp>py24 david_pratt.py
result_list = [
# Project
['Project', ['Geometries', ['Geometry', 'Points', 'Layers', 'Water']],
'Verticals'],
# Soil
['Soil', 'Soiltypes'],
]
[['Project', ['Geometries', ['Geometry', 'Points', 'Layers', 'Water']],
'Verticals'], ['Soil', '
Soiltypes']]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
e hardware can't entirely
optimize out
with smart buffering etc. Not to mention possible interactions with all the
other things
an OS may be doing "simultaneously" switching between things that it accounts
for as real/user/sys.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
i) for i in xrange(5)), SI('start:'))
Traceback (most recent call last):
File "", line 1, in ?
TypeError: sum() can't sum strings [use ''.join(seq) instead]
vs
>>> reduce(operator.__add__, (SI(i) for i in xrange(5)), SI('start:'))
'start:01234'
Which seems to boil down to incomplete restrictions on duck typing.
Maybe Guido will want to complete it, but ISTM your original implementation
delegating string addition implementation to ''.join was reasonable.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
overridden
(or instance is of an old-style class as mentioned above).
I suspect these then implement the check for __getattr__, which can be user
defined
to intercept attribute access on particular objects in the search chain, after
higher-priority stuff fails.
[... Can't ... keep .. eyes ... open ... for ... rest ...]
(not the fault of your prose, had a beer ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
r() values.
>
You are right, but OTOH the OP speaks of a "flagging" the dict as modified.
If she made e.g., "modified" a property of the dict subclass, then
retrieving the the "modified" "flag" could dynamically check current state repr
vs some prior state rep
x27;t belong into the test source.
>
Perhaps in a config file that can specify special conditions re running
identified tests? E.g., don't run vs run and report (warn/fail/info)
changed result (e.g. from cached result) vs run and report if pass etc.
Then if code change unexpectedly makes a test work, the config file can just
be updated, not the test.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
t. And sum, if you want a one-liner.
Hint2: try 4/7 and 4.0/7 interactively
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ass DervAugit(AugiterBase):
... def _gen(self, d):
... for k, self._v in d.items(): yield k
... def value(self): return self._v
...
>>> it = DervAugit(dict(enumerate('abcd')))
>>> for i in it:
... if i%2: print i, it.value()
...
1 b
3 d
>>> for i in it:
... print i, it.value()
...
>>> it = DervAugit(dict(enumerate('abcd')))
>>> for i in it:
... print i, it.value()
...
0 a
1 b
2 c
3 d
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>>> for i in it:
... if i%2: print i, it.value
...
1 b
3 d
You could of course store self._value and def value(self):return self._value to
be closer to your syntax)
>So my question is: Can you think of an easy way to write something that
>looks like a generator (using yield), but can also incorporate methods other
>than next?
>
See above.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 10 Jan 2006 00:47:36 -0800, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
>[Bengt Richter]
>> What about some semantics like my izip2 in
>>
>> http://groups.google.com/group/comp.lang.python/msg/3e9eb63a1ddb1f46?hl=en
>>
>> (which doe
abstract value, which is always an interpretation of some concrete
representation.
I suspect that describing things in terms of abstract graphs and their
transformations
would be useful. E.g., starting with python's objects (in the abstract) as
nodes,
and "references" as directed arcs.
More on this later, perhaps, but I have to go now ...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
iteration? Is this a fundamental looping construct or just a
>theoretical wish-list item? IOW, does Python really need
>itertools.izip_longest() or would that just become a distracting piece
>of cruft?
Even if there is little use for continuing in correct code, IWT getting
at the state of the iterator in an erroroneous situation would be a benefit.
Being able to see the result of the last attempt at gathering tuple elements
could help. (I can see reasons for wanting variations of trying all streams
vs shortcutting on the first to exhaust though).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 9 Jan 2006 08:19:21 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>Op 2006-01-05, Bengt Richter schreef <[EMAIL PROTECTED]>:
>> On 5 Jan 2006 15:48:26 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
[...]
>> But you can fix that (only test is what you see
meet my need?
>
Narrowly interpreting your requirements (only quotes are with
double quotes (never containing escaped same) and strip quotes off)
and tested only as you see ;-)
>>> import re
>>> rx = re.compile(r'"([^"]*)"|(\w+)')
>>> s = '
ystem. You don't need readlines either. Try
(untested)
# open f and w as before [1]
for line in f:
if line.strip(): w.write(line) # write only non-blank lines
[1] BTW, I didn't see the 't' mode in
http://docs.python.org/lib/built-in-funcs.html
description of open/file, but I have a nagging doubt about saying it's not
valid.
Where did you see it?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ith.
>
OTOH, he's probably just trying to get someone to remember zip-abuse for him.
Hope it's not homework ;-)
>>> sq = [[r+c for c in 'abc'] for r in '123']
>>> for r in sq: print r
...
['1a', '1b', '1c']
[
ss
...
>>> foo()
started at Sun Jan 08 14:13:55 2006
ended at Sun Jan 08 14:13:55 2006
diff = 0.00 sec
>>> foo()
started at Sun Jan 08 14:14:02 2006
ended at Sun Jan 08 14:14:02 2006
diff = 0.00 sec
>>> @timelogger() # stdout
... def foo(dt): time.sleep(d
A_MAP.get(source.read(2), DEFAULT)
>
Much better than my version, since you went beyond the OP's code to what he said
he was trying to do ("look at two-byte pairs coming from a machine ... over the
serial cable").
I just went for a direct translation of the code, which is nearly a
x27; %((byte1,byte2), pairvalues.get((byte1,byte2),
'DEFAULT ??'))
...
(66, 32) => 0.16701
(32, 1) => 5
(36, 32) => 'natural'
(32, 32) => 0
(20, 20) => 'DEFAULT ??'
HTH
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ciation with the distribution of digital generic products to make them
distinguishable for any business purpose whatever. IP principles established
with
corn flakes and decoder rings are thought to translate perfectly to the digital
domain of FOSS distros including anything toy-like.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
xcept binary?
Want to give a clue as to output format? Gapped? Ascii at the right?
Bit numbers or hex byte offsets at the left?
Do you need a one-liner solution?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
'.__mod__, bitsof(3**100, 8))[::-1])
'005A4653CA673768565B41F775D6947D55CF3813D1'
>>> ''.join(map('%02X'.__mod__, bitsof(-3**100, 8))[::-1])
'FFA5B9AC3598C897A9A4BE088A296B82AA30C7EC2F'
>>> hex(-3**100)
'-0x5A4653CA673768565B41F775D6947D55CF3813D1L'
(I leave it to your judgement as to how useful our current hex() representation
of negative numebers is ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 5 Jan 2006 14:34:39 -0800, [EMAIL PROTECTED] wrote:
>
>Bengt Richter wrote:
>> On 5 Jan 2006 15:48:26 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>
>> >On 2006-01-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> >><[EMAIL
On Thu, 05 Jan 2006 07:42:25 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On 4 Jan 2006 15:20:43 -0800, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
>
[ ... 5 options enumerated ... ]
>>
>>
>6. Could modify izip so that one could write
>
>from it
and izip will never stop.
But you can fix that (only test is what you see ;-) :
>>> from itertools import repeat, chain, izip
>>> it = iter(lambda z=izip(chain([3,5,8],repeat("Bye")),
>>> chain([11,22],repeat("Bye"))):z.next(), ("Bye","Bye"))
>>> for t in it: print t
...
(3, 11)
(5, 22)
(8, 'Bye')
(Feel free to generalize ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 05 Jan 2006 09:47:02 -0600, Robert Kern <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> On 4 Jan 2006 12:46:47 -0800, "Raven" <[EMAIL PROTECTED]> wrote:
>
>>>The problem with Stirling's approximation is that I need to calculate
>&
pable
of alternative, non-C
implementation of the python semantics. So I thought I'd try this as a possible
terminology, to see if
it makes it any easier for anyone ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ined inline functions in
mymod.py
to have been inlined in the code of mymod.
I've been meaning to do a proof of concept, but I've hinted at these things
before,
and no one seems much interested. And besides it's really a distraction from
more radical
stuff I'd like to try ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ing until but not including (sentinel,)*len(seqs)
This would seem backwards compatible, and also potentially allow you to use the
rest mode
from the start, as in
for tup in izip(*seqs).rest(sentinel):
# process tup and notice sentinel for yourself
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
culate
>the hypergeometric hence the factorial for numbers within a large range
>e.g. choose(14000,170) or choose(5,2)
>
It seems you are hinting at some accuracy requirements that you haven't
yet explained. I'm curious how you use the values, and how that affects your
judgement of S
On 3 Jan 2006 17:42:44 -0800, "KraftDiner" <[EMAIL PROTECTED]> wrote:
>I'm porting a routing from C++ to python.
>There is a complex for loop that I don't know how to code in python
>
>for (i = nPoints-1, j = 0; j < nPoints; i = j, j++)
>
Perhaps most directly comparable semantics (untested):
i =
ong_Factorial_Integer)
ISTM you wouldn't get zero if you scaled by 10**significant_digits (however many
you require) before dividing. E.g., expected hits per trillion (or septillion
or whatever)
expresses probability too. Perhaps that could work in your calculation?
Regards,
Bengt Richter
-
28] C:\pywk\clp\seven\pycontest_01>wc -lc seven_seg.py
2136 seven_seg.py
2 lines, 136 chars including unix-style lineseps (is that cheating on windows?)
No imports.
Guess I'll have to try another tack ;-/
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
How did you go from the PATHEXT "clue" to the set command you specify and decide
not to set pathext, e.g., by something like
set PATHEXT=%PATHEXT%;.py
Does your set do the pathext and assoc and ftype all in one swell foop?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 25 Dec 2005 16:39:47 +0100, Simon Hengel <[EMAIL PROTECTED]> wrote:
>Hello,
>we are hosting a python coding contest an we even managed to provide a
>price for the winner...
^
>
How much are you going to sell him or her for? ;-)
Regards,
Bengt Richter
--
http
f not __debug__: return f
... def wrap(*args, **kw):
... print 'before entering function "%s" ...'%f.func_name
... result = f(*args, **kw)
... print 'after returning from function "%s" ...'%f.func_name
... return result
... wrap.func_name = f.func_name # make it look the same if desired
... return wrap
...
>>> @debugdeco
... def foo(something): print something; return 'whatever'
...
>>> foo('hello')
hello
'whatever'
You could still do stuff unconditionally of course, and also inside foo.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
> It's like having James Bond as your very own personal body guard ;)
>
>That is such a nice quote that I am going to put it in my email
>signature ! :)
>
>-Anand
>
Maybe look into fixing the above problem while you're at it?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 22 Dec 2005 12:42:36 -0800, "planetthoughtful" <[EMAIL PROTECTED]> wrote:
>
>Bengt Richter wrote:
>> On 22 Dec 2005 08:55:17 -0800, "planetthoughtful" <[EMAIL PROTECTED]> wrote:
>>
>
>> >I would like to include the ability to edit
e "(1==1)" and "(1==0)".
>
You may want to upgrade to a newer version.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
.items(): print '%10s: %.2f'%(name,price)
...
yoghurt: 1.19
banana: 0.79
apple: 1.23
I'm not suggesting this as a pattern to follow, just to illustrate what you can
do
with raw_input. IOW, it's about how you build the prompt string, and what you do
with the user response input string that solves your problem.
Voluminous prompts get old fast, so you might e.g. want to accept a '?' to get
extra
context-sensitive info instead, followed by retry.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
did;-).
>
So is google about to determine how many luminaries can fit on the head of a
project? ;-)
Seriously, if you heavies do sometimes work on the same project, it would be
interesting to know what modes of co-operation you tend to adopt.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
gt;> len(amounts)
26
is the total number of numbers
So if you choose with uniform probability, you'd expect
>>> 19./26
0.73076923076923073
to be the fraction satisfying pick<10
With a larger sample, the fraction should show better, e.g.,
>>> sum(random.choice(amounts)<10 for _ in xrange(100))
730983
Does that help?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 21 Dec 2005 18:30:03 -0700 (MST), Jim Benson <[EMAIL PROTECTED]> wrote:
>On Thu, 22 Dec 2005, Bengt Richter wrote:
>
>> >>
>> >> For Americans: 15 meters is roughly 50 feet.
>> >
>> >Google can do that too, of course.
>> &g
On Wed, 21 Dec 2005 21:47:29 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>[roughly "an inch is not exactly 25.4mm"]
>> At least according to my dusty 37th Edition Handbook of Chemistry and
>> Physics (c) 1955.
>> Maybe things
Appears to be the google number
But the official conversion
>>> 1000/39.37
25.400050800101603
is not _exactly_ 25.4 mm/inch
so the distance from Martellibot to BDFL should
more exactly be
>>> 15*39.37/12
49.2124999
Send bug report to google ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
e')
h = ''
import g or (h or g) or h as mod # (h or g) is a string expression =>
'gname' here
Also, a bare 'and' could make its predecessor term be treated like an ordinary
expression (even if
a bare name), allowing bare guard condition expressions, e.g.,
import cond and name or alternate as mod # <==> import (cond and 'name') or
alternate as mod
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
-1: ''
0: ''
1: ';'
2: ';;'
3: ''
I.e.,
Zeile += ';'*(42-Zeile.count(';'))
should work, since a string is a sequence type and
http://docs.python.org/lib/typesseq.html
Says
"""
Operation ResultNotes
...
s * n , n * s n shallow copies of s concatenated(2)
...
(2)
Values of n less than 0 are treated as 0 (which yields an empty sequence of
the same type as s). ...
"""
I guess it might be nice to mention this in help(str) also, to publish a useful
fact better.
Maybe under str.__mul__ ?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
x27;:-24
>}
>
>def myfloat(str):
>try:
>exp = SI_prefixes[str[-1]]
>return float(str[:-1]) * 10**exp
>except KeyError:
>return float(str)
>
>?
Nit: why not move 10** out of myfloat into SI_prefixes
(i.e., just retrieve precalculated factors)?
Nit_2: No twinge of conscience shadowing str? ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ation: New York
[15:20] C:\pywk\clp>md xd
[15:20] C:\pywk\clp>py24 extractfilesegs.py -tf xd (Jimmy)
Files created:
"xd\jimmy.txt"
< xd\jimmy.txt >
Jimmy
Current Location: Denver
Next Location: Chicago
[15:21] C:\pywk\clp>py24 extractfilesegs.py -tf xd "Person: (Sarah)"
Files created:
"xd\sarah.txt"
< xd\sarah.txt >
Person: Sarah
Current Location: San Diego
Next Location: Miami
Next Location: New York
[15:22] C:\pywk\clp>py24 extractfilesegs.py -tf xd "^(irrelevant)"
Files created:
"xd\irrelevant.txt"
< xd\irrelevant.txt >
irrelevant
trailing stuff ...
HTH, NO WARRANTIES ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
e ValueError, "%r may not be overridden" % name
ValueError: 'securityLevel' may not be overridden
Quoting command line arg to make a single arg with embedded spaces:
[ 9:54] C:\pywk\ut>py24 clvalues.py -added "should be string"
decode: 0
securityLevel: 3
1 - 100 of 974 matches
Mail list logo