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
__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_
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
differing in the arguments passed.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
>> 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
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
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
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
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
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 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 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
#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
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
>> ... 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
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
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
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
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
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
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
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
t here to play 20-questions.
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
&
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
# 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
>> 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
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
omeoffset+i*somefactor once you get past the limit checks for the virtual
slice. By the same token, transforming a few numbers of one virtual slice
into similar numbers for a a new virtual slice of that shouldn't be rocket
science.
And it wouldn't have to be done more than once. Don
uence gets larger. Of course, you can
>always use the standard
>C/C++ approach and pass the original sequence along with the (start,stop,step)
>indices of the slice,
>as Terry Reedy mentioned, but then you lose in expressiveness.
I didn't see the leadup to this, but what is the problem with just subclassing
tuple to
give you the views you want?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 25 Jan 2005 15:46:30 +, Stephen Kellett <[EMAIL PROTECTED]> wrote:
>In message <[EMAIL PROTECTED]>, Bengt Richter
><[EMAIL PROTECTED]> writes
>>I believe that is quite wrong as a general statement.
>
>Actually my initial statement should have been
to example,
>>> print list(x for i,x in enumerate(x for x in xrange(1, 996) if x % 2 ==0)
>>> if i<3 or iter([]).next())[2]
6
or in case you just want one item as result,
>>> print list(x for i,x in enumerate(x for x in xrange(1, 996) if x % 2 ==0)
>>> if i==2 or i==3 and iter([]).next())[0]
6
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 25 Jan 2005 11:46:04 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>>
>>>If you are after readability, you might prefer this...
>>>
>
in problem with a CPU clock based reading is that it's very stable unless
there's variable clock rate due to power management.
Why am I doing this? ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
s really that helpful?
def hamming():
def _hamming():
yield 1
for n in imerge(imap(lambda h: 2*h, iter(hg2)),
imerge(imap(lambda h: 3*h, iter(hg3)),
imap(lambda h: 5*h, iter(hg5:
yield n
hg2, hg3,
esponses in
>Windows is to write a kernel driver, and even then there are no guarantees.
>Windows is NOT a real-time system. If you have an environment where an
>unexpected delay of a millisecond or more is going to cause damage, then
>you need to redesign your application.
For sure. The big requirements picture is missing (not uncommon ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 24 Jan 2005 20:35:09 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
>>Bengt Richter wrote:
>>> So, e.g., for
>>>
>>> >>> presets = dict(a=1, b=2, deftime
4-1)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ut.finfo import finfo
>>> finfo(finfo)
('finfo', 'ut.finfo', 'c:\\pywk\\ut\\finfo.pyc', 1106641080)
>>> import time
>>> time.ctime(finfo(finfo)[-1])
'Tue Jan 25 00:18:00 2005'
HIH
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
:
"Kneeling, Cobb p
lanted a sturdy knee in the small of his back,")
funny that googling define:imbed gets nothing. Nor define:embed ??
I've had a number of misses in that kind of search. I wonder if it's
temporarily broken (or maybe it hit a licensing snag with the various
onl
nking XML are you??!! For this, definitely
ick ;-)
>
What you want to do will depend on the big picture, which is not apparent yet
;-)
>
>Please reply when you guyes can get a chance.
>Thanks,
Sorry to give nothing but untested suggestion, but I have to go, and I
will be off line mostly for a while.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> So, e.g., for
>>
>> >>> presets = dict(a=1, b=2, deftime=__import__('time').ctime())
>>
>> in the decorator args, the next version wi
On Sun, 23 Jan 2005 13:14:10 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> On Sat, 22 Jan 2005 16:22:33 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
>>
>>
[Steven Bethard]
>>>> > If you really want locals that d
On Sun, 23 Jan 2005 08:22:36 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>On Sun, 23 Jan 2005 15:43:43 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
>
>>aurora wrote:
>>> I am think more in the line of string.ljust(). So if we have a
>>> list.ljust(lengt
01:47:27)
[GCC 3.2.3 (mingw special 20030504-1)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(''.ljust)
Help on built-in function ljust:
ljust(...)
S.ljust(width[, fillchar]) -> string
3 (3)
21 STORE_FAST 1 (c)
6 24 LOAD_CONST 4 (3.1415926535897931)
27 STORE_FAST 4 (pi)
7 30 LOAD_CONST 5 ()
33 CALL_FUNCTION0
36 RETURN_VALUE
&
x27;.split(':'))
>>> print (a, b, c, d, e)
('a', 'b', 'c', None, None)
But then, might as well do:
>>> def bar(nreq, *args):
... if nreq <= len(args): return args[:nreq]
... return args+ (nreq-len(args))*(None,)
...
cted, nor did the y = 123 show at 4:
But the d['z'] showed up immediately, as you might expect ... but d['z'] also
in that last returned locals(), which you might not expect, since there was
no assignment to bare z. But they are apparently the same dict object, so you
would expect it. So maybe there is some kind of finalization at exit like
closure
building. Anyway, d = dict(locals()) would probably behave differently, but I'm
going to leave to someone else ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
provides fairly robust mechanism
>(called robustApply) for providing a set of possible arguments and using
>inspect to pick out which names match the parameters for a function in
>order to pass them in to the function/method/callable object. That
>said, doing this for __init__'s with attribute values from an object's
>dictionary doesn't really seem like the proper way to approach the problem.
Sounds like a workaround for parameter passing that maybe should have been
keyword-based?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
7:-1025:P 26:Q 27:10
-26:-Q-27:-R-28:-1026:Q 27:R 28:10
-27:-R-28:-S-29:-1027:R 28:S 29:10
-28:-S-29:-T-30:-1028:S 29:T 30:10
-29:-T-30:-U-31:-1029:T 30:U 31:10
-30:-U-31:-V-
m W3C a long time ago.
... I see the third edition at http://www.w3.org/TR/REC-xml/ is differently
styled,
(I guess new style sheets) but still pretty readable (glancing at it now).
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
c(C.__init__)
(['self', 'a', 'b', 'c'], None, None, (1, 'bee', 1.2))
that you want by looking at the unbound method C.__init__
(though im_func may be deprecated eventually?):
>>> C.__init__.im_func.func_code.co_varnames
('self', 'a', 'b', 'c')
>>> C.__init__.im_func.func_defaults
(1, 'bee', 1.2)
or by getting the __init__ function as such, by avoiding the attribute
access that makes it and unbound or bound method
>>> C.__dict__['__init__'].func_code.co_varnames
('self', 'a', 'b', 'c')
>>> C.__dict__['__init__'].func_defaults
(1, 'bee', 1.2)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
0 0101 0110 0111
1000 1001 1010 1011 1100 1101 1110
0001 00010001 00010010 00010011 00010100 00010101 00010110 00010111
[...snip stuff you can infer ...]
0111 01110001 01110010 01110011 01110100 01110101 01110110 01110111
0000 0001 0010 0011 0100 0101 0110 0111
Well, you get the idea.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
oblems internally, and accepts keys and values of any type without wrapping
or other modification -- or do you want a wrapper that can make any object
suitable for use as key or value in python's curent definition of dict?
Just DYFR please. You still haven't you know ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>> v][0]:]
>>> for s in newbar: print repr(s)
...
'str_1 and str_2 both in line two'
'three'
'four'
'str_1 and str_2 both in line five'
'last line'
Alternatively:
>>> newbar = list(dropwhile(lambda x: 'str_1' not in x or 'str_2' not in x,
>>> bars))
>>> for s in newbar: print repr(s)
...
'str_1 and str_2 both in line two'
'three'
'four'
'str_1 and str_2 both in line five'
'last line'
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ecursionlimit(n)
Set the maximum depth of the Python interpreter stack to n. This
limit prevents infinite recursion from causing an overflow of the C
stack and crashing Python. The highest possible limit is platform-
dependent.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
neral.
I can easily conceive of information that I'd rather not see publicized
without severe access controls. But in general I do believe in open sharing
of free information as the most productive for everyone.
>Exporting a machine gun is much different from publishing a
>description of one. Software is just a precise type of description.
Yeah, but ... ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 19 Jan 2005 04:55:53 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
>What am I missing? (this is from 2.4b1, so probably it has been fixed?)
>
I googled and found a bug report, but initial report kind of passes on it
saying nested sequences will probably be tuples, so no pan
like it expects to refer to the type,
not the arg
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 18 Jan 2005 17:38:20 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>> Which make me wonder what plans there are for providing a better
>> mechanism than default arguments as a way of initializing local function
>> variables. Nested def
s purity drives actual implementation, but purity issues
drive a lot of interesting, if not too practical, discussions. Of course, if
someone
has the energy to become champions of their ideas, and actually implement them
for testing and evaluation, more power to them. I don't think we shou
deftime=time.ctime()):
return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
Seem like a minor extension of the default-arg hack.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
ementation
>limitations is sold as a general principle.
People take short cuts in expressing themselves, just as you do.
E.g., you say "mutable key" when you really mean a value that will
remain constant while you are using it as a dictionary key. The "safe"
dictionary
that you are "thinking about" will apparently get its "safety" by ensuring that
the "mutable key" can't be "mutated" -- or do you want to discuss which copy
is the real "key" ;-) (I don't ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 17 Jan 2005 16:48:24 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> I can see postings on google, but my news service
>> is having a problem since sometime during the weekend.
>> Can get old stuff from other n.g., but no new.
>>
void )
>{
> int i, j;
> int ds;
> int u, v;
>
> /* setup rotor data */
> for (j=0;j<26;j++)
> data[4][j] = ((int)ref_rotor[j]-'A'+26)%26;
>
> for (i=1;i<4;i++)
> {
> step[i-1] = step_data[order[i-1]];
> for (j=0;j<26;j++)
> {
> data[i][j] = ((int)(rotor[order[i-1]][j])-'A' + 26) % 26;
> data[8-i][data[i][j]] = j;
> }
> }
>
>Now, do I need to start boning up on lists and how to use them or am I
>missing the bigger picture?? Again, for the complete code see
>http://home.earthlink.net/~lvraab. I'm not asking you to do it for me,
>just some pointers on going about this.
You are obviously not yet familiar with python, but a few hours with the
introduction and tutorials should help a lot. Then post something that
compiles. Or a snippet that does something you don't understand.
This is about all I have patience for this time. I really have other stuff to
do.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
I can see postings on google, but my news service
is having a problem since sometime during the weekend.
Can get old stuff from other n.g., but no new.
Wondering whether I'll see this via google.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 15 Jan 2005 11:00:36 -0800, Scott David Daniels <[EMAIL PROTECTED]>
wrote:
>G.Franzkowiak wrote:
>> Scott David Daniels schrieb:
>>
>>> franzkowiak wrote:
>>>
I've read some bytes from a file and just now I can't interpret 4
bytes in this dates like a real value. An extract f
ut once again ;-)
>>> lst = [1, 2, 3]
>>> i = 0
>>> for item in lst:
...if item !=2:
...lst[i] = item
...i += 1
...
>>> del lst[i:]
>>> lst
[1, 3]
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
nerally speaking you can ignore the overhead, and the
>flush() calls will be automatic as long as you don't mix file and string
>operations. The programming convenience is amazing.
That part does look good, but will scanning a large file with find
cause massive swapouts, or is there some smart prioritization or
hidden sequential windowing that limits mmap's impact?
>
>> --
>> I have come to kick ass, chew bubble gum and do the following:
>>
>> from __future__ import py3k
>>
>> And it doesn't work.
>
>So make it work :-)
>
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
import sys
try:
oldnew = __import__(sys.argv[3])
main(sys.argv[1], sys.argv[2], oldnew.old, oldnew.new)
except Exception, e:
print '%s:%s' %(e.__class__.__name__, e)
raise SystemExit, """
Usage: [python] binfupd.py infname outfname oldnewmodulename
where infname is read in binary, and outfname is written
in binary, replacing instances of old binary data with new
specified as python strings named old and new respectively
in a module named oldnewmodulename (without .py extension).
"""
---
REMEMBER: NO WARRANTY FOR ANY PURPOSE! USE AT YOUR OWN RISK!
And, if you know where to seek to, that seems like the best way ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;s as needed in a pool of partially complete
t's.
But your real requirements are not clear enough here, so you may get help
crossing
a stream, but no one will be able to say you are already on the side of the
stream
you want to be later, and there's an easy path without need of crossing twice
;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 14 Jan 2005 20:13:48 +0100, Reinhold Birkenfeld <[EMAIL PROTECTED]>
wrote:
>Bengt Richter wrote:
>> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
>>
>>>[EMAIL PROTECTED] wrote:
>>>> In Mythical Future P
g to list the variable names
># as strings in multiple places. It is enought to
># have them in the 'mapping'
># dictionary above
>
>t2 = Test(dictionary.get('a'), dictionary.get('b'),
>dictionary.get('c'))
>print t2
>
Why don't
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> BTW, I'm sure you could write a generator that would take a file name
>> and oldbinstring and newbinstring as arguments, and read and yield nice
>> os-file-s
On Thu, 13 Jan 2005 17:43:01 -0600, Jeff Epler <[EMAIL PROTECTED]> wrote:
>
>--LQksG6bCIzRHxTLp
>Content-Type: text/plain; charset=us-ascii
>Content-Disposition: inline
>Content-Transfer-Encoding: quoted-printable
>
>On Thu, Jan 13, 2005 at 11:04:21PM +, Bengt Rich
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> BTW, I'm sure you could write a generator that would take a file name
>> and oldbinstring and newbinstring as arguments, and read and yield nice
>> os-file-s
15], [16], [17], [18], [19]]
>>> for i in (x[0] for x in something): print i,
...
oops, that list() used it up ;-)
>>> something = [[x] for x in xrange(10,20)]
>>> for i in (x[0] for x in something): print i,
...
10 11 12 13 14 15 16 17 18 19
Really nice.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
g hex literals of negative numbers.
def __repr__(self): return '<%s object at %08.16b>' %(type(self).__name__,
id(self))
and you could write based literals in the above formats with e.g., with
'16x%.16b' % number
or
'2x%.2b' % number
etc.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
has justified the fact that an
>assignment does not return any value, and therefore cannot be used as a
>component of an expression.
>
Hm, that makes me wonder, is there an intermediate "returning of value" in
x = y = z = 123
?
>Mea culpa, but I'm not going to *pl
27;s let(x, y, ...): spec.
It provides a new way of factoring. As well as things no one has thought of yet
;-)
The other thing to think about is that the let suite could be strictly
def-time, which would
provide the opportunity to avoid re-calculating things in functions without
abusing default args,
and using the easy closure-variable creation instead. E.g.,
let(foo):
preset = big_calc()
in:
def foo(x):
return x * preset
(This "in:" has no "in xxx:" name, so the effect is immediate execution of the
anonymously
defined function, which writes through to foo with the def, as permitted by
let(foo):).
Problems? (Besides NIH, which I struggle with regularly, and had to overcome to
accept Tim's
starting point in this ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
... inner()
... print 4, locals()
...
>>> foo()
1 {'a': 1, 'b': 2}
2 {'a': 2, 'c': 3, 'b': 2} and b: 2
4 {'a': 1, 'b': 2, 'inner': }
of course a difference using the new syntax is that 'inner' is not bound to a
persistent name.
>
>otherwise that would be impossible to do calculations based on scope
>variables and "using:" would be useless =), consider example of usage:
>
>current_position = 1
>current_environment # = ...
>current_a_lot_of_other_parameters # = ...
>scores = [count_score(move) for move in aviable_moves] using:
> def count_score(move):
> #walking through current_environment
> return score
No worry, UIAM.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
fout = open('mynewbinfile', 'wb')
for buf in updated_file_stream('myoldbinfile','rb', oldbinstring,
newbinstring):
fout.write(buf)
fout.close()
(left as an exercise ;-)
(modifying a file "in place" is another exercise)
(doing the latter with defined maximum memory buffer usage
even when mods increase the length of the file is another ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
gt;> def MC(*a): print a; return type(*a)
...
>>> class F:
... __metaclass__ = MC
... pass
...
('F', (), {'__module__': '__main__', '__metaclass__': })
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 13 Jan 2005 12:19:06 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote:
>On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote:
>> extensiondict = dict(
>> php = 'application/x-php',
>> cpp = 'tex
ATTCTCAAAGGAATAGACGG
>>CW127_A03
>TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
>TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
>GCATTAAACATTCCGCCTGGG
>...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
u set baud rates and handshaking etc. I would
think.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
#x27;: 10, 'c': 3}]
>
It's kind of a strange list comp, but I guess you're just illustrating
something.
But for this case you could just write
>>> [d.update({'c':3}) or d for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]]
[{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}]
taking advantage of normal d.update() returning None and so forcing the 'or'
term.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
(map(totallen, x))
> return 1
Since the requirement is to _count_, not flatten, ISTM your solution is best so
far ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
deas?
>
I think I would refactor along these lines: (untested)
extensiondict = dict(
php = 'application/x-php',
cpp = 'text/x-c-src',
# etcetera
xsl = 'test/xsl'
)
def detectMimeType(filename):
extension = os.path.splitext(filename)[1].replace('.', '')
try: return extensiondict[extension]
except KeyError:
basename = os.path.basename(filename)
if "Makefile" in basename: return 'text/x-makefile' # XXX case
sensitivity?
raise NoMimeError
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
/www.tbray.org/ongoing/When/200x/2004/12/08/-big/IMG_3061.jpg
>>
>>
>> LOL, he is working on linux, isn't he?
>>
>> So it was about bloody time.
>
>Guido Van Rossum is now working on linux??
Are they both left-handed? Hm, sinister ...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
On 11 Jan 2005 07:51:35 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote:
>[EMAIL PROTECTED] (Bengt Richter) wrote in message news:<[EMAIL PROTECTED]>...
>> On 9 Jan 2005 14:13:28 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote:
>>
>> >Hi,
>> >
urn preset # return now legal
...
print foo()
The combination would work like:
let(rebindable):
factor = 10
in bar:
rebindable *= factor
rebindable = 2
bar()
print rebindable # => 20
rebindable += 5
bar()
print rebindable # => 250
You can see this could be used nicely in case functionality, with a dict of
named in-functions.
What do you think?
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>[cut]
>
> The reason I went for sets instead of lists is the speed,
>availability of unique, common and other methods.
>What would you propose as an elegant solution?
>Actually, even those nested for loops take ages. :(
If you will explain a little what you are doing with these set "items"
perhaps someone will think of another way to represent and use your data.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
hand with redundant information that will accomplish the effect
of masking and shifting and adjusting sign.
If you need this speed, volunteers will magically appear. Maybe even if you
don't ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
>eliminating the need to move the lips (which reduces effort and stops
>flies getting in).
>
>Tim C
>Sydney, Australia
LOL. Thanks, needed that ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
al-time
stuff, but I haven't used it. (I just seem to remember reading something about
that in the MSDN docs,
but I am not sure. And too lazy to go back and look ;-)
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
tements, too.
>
>if someregexp.match(s) as m:
> # blah using m
>elif someotherregexp.match(s) as m:
> # blah using m
>
If 'where: ...' were an expression suite ISTM you could write
if m where: m = someregexp.match(s) # same-line format
blah(m)
eli
801 - 900 of 974 matches
Mail list logo