Re: return a ctypes object to C

2019-10-31 Thread Arnaud Loonstra
On 31-10-2019 14:44, Thomas Jollans wrote: On 31/10/2019 14.13, Arnaud Loonstra wrote: On 30-10-2019 09:32, Arnaud Loonstra wrote: Hi all, I'm trying to wrap my head around the ctypes API. I have a C structure I wish to create in Python and then return from python to C. So a python meth

Re: return a ctypes object to C

2019-11-07 Thread Arnaud Loonstra
On 31-10-2019 15:39, Arnaud Loonstra wrote: On 31-10-2019 14:44, Thomas Jollans wrote: On 31/10/2019 14.13, Arnaud Loonstra wrote: On 30-10-2019 09:32, Arnaud Loonstra wrote: Hi all, I'm trying to wrap my head around the ctypes API. I have a C structure I wish to create in Python and

"bad argument type for built-in operation"

2005-01-24 Thread Gilles Arnaud
Hello, I've got a nasty bug and no idea to deal with : here is the method : def denormer(self, var) : " denorme un vecteur d'entree " try: #a = map(self.decerner, self.param, var) #a = [self.decerner(x, y) for x, y in map(None, self.param, var)]

Dealing with ImportLock deadlock in Import Hooks

2013-08-02 Thread Arnaud Fontaine
ts, any thoughts about that? * Fix the code in ZODB to not avoid import but to me this seems like a dirty hack because it could happen again and I would prefer to fix this issue once and for all. Any thoughts or suggestion welcome, thanks! Regards, -- Arnaud Fontaine [0] http://bugs.python.o

Dealing with ImportLock deadlock in Import Hooks

2013-08-02 Thread Arnaud Fontaine
ts, any thoughts about that? * Fix the code in ZODB to not avoid import but to me this seems like a dirty hack because it could happen again and I would prefer to fix this issue once and for all. Any thoughts or suggestion welcome, thanks! Regards, -- Arnaud Fontaine [0] http://bugs.python.o

Re: Naming conventions for functions and methods

2014-07-08 Thread Arnaud Delobelle
;d still go for hashfile for the function name though. -- Arnaud -- https://mail.python.org/mailman/listinfo/python-list

ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-13 Thread Arnaud Delobelle
the same project name on google code. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-13 Thread Arnaud Delobelle
27;re using an old version of Python (before the with statement was introduced - 2.5?) >   File "unpyc3.py", line 96, in dec_module >     stream = open(pyc_path, "rb") > UnboundLocalError: local variable 'pyc_path' referenced before assignment > > change pyc_path to path Thanks, I've fixed that. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Arnaud Delobelle
On 14 September 2011 09:44, Vincent Vande Vyvre wrote: >   File "unpyc3.py", line 211, in __init__ >     for v in code_obj.co_cellvars + code_obj.co_freevars] > AttributeError: 'NoneType' object has no attribute 'co_cellvars' Could you show me what you do

Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Arnaud Delobelle
On 14 September 2011 11:03, Vincent Vande Vyvre wrote: > Le 14/09/11 11:31, Arnaud Delobelle a écrit : [...] > Could you show me what you do to get this error? Thank you, > [vincent@myhost unpyc3]$ python > Python 3.2.1 (default, Jul 11 2011, 12:37:47) > [GCC 4.6.1] on linu

How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
o_consts == ('foodoc',) But I can't find where in foo.__code__ is stored the information that the first constant in foo.__code__ is actually a docstring. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
On 15 September 2011 16:17, Ian Kelly wrote: > On Thu, Sep 15, 2011 at 5:10 AM, Arnaud Delobelle wrote: >> Hi all, >> >> You can do: >> >> def foo(): >>    "foodoc" >>    pass >> >> function = type(lambda:0) >> foo2 = fun

Re: cause __init__ to return a different class?

2011-09-15 Thread Arnaud Delobelle
on, I suggest you read Guido's essay on "new style classes" which were introduced in Python 2.2 (and are now a good 10 years old I think): http://www.python.org/download/releases/2.2.3/descrintro -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
out of it. My entry: >>> sum(map(int,str(2**1000))) 1366 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
On 16 September 2011 21:20, Ian Kelly wrote: > On Fri, Sep 16, 2011 at 2:17 PM, Arnaud Delobelle wrote: >> Ah go on, let's make a codegolf contest out of it. >> My entry: >> >>>>> sum(map(int,str(2**1000))) >> 1366 > > That is exactly what m

Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
er is 1 :) Hopefully-helpfully-but-not-so-sure'ly yours, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: way to calculate 2**1000 without expanding it?

2011-09-18 Thread Arnaud Delobelle
On Sep 18, 2011 1:20 PM, "Mark Dickinson" wrote: > > On Sep 16, 9:17 pm, Arnaud Delobelle wrote: > > Ah go on, let's make a codegolf contest out of it. > > My entry: > > > > >>> sum(map(int,str(2**1000))) > > You could save another

Re: Operator commutativity

2011-09-19 Thread Arnaud Delobelle
commutative. Then > > y = 123 + X() > > should have the same result. However, since it does not call __add__ on > an instance of X, but on the int 123, this fails: > > TypeError: unsupported operand type(s) for +: 'int' and 'X' > > How can

Re: Dynamically Cause A Function To Return

2011-09-20 Thread Arnaud Delobelle
# Simple example of 'pause' in action: >>> def g(x): ... b = 5 ... pause() ... >>> def f(x, y): ... z = 2 ... g(x) ... print "And we carry on..." ... >>> f('spam', [4, 2]) *** Entering pause mode (EOF to resume) pause> ? File "", line 3, in g . File "", line 3, in f .. File "", line 1, in pause> b (g) 5 pause> b+1 (g) 6 pause> .z (f) 2 pause> .y (f) [4, 2] pause> .x (f) 'spam' pause> ..len () pause> ^D *** Leaving pause mode And we carry on... >>> -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

About MAKE_FUNCTION opcode in Python 3

2011-09-20 Thread Arnaud Delobelle
r normal arguments is argc & 0xFF * the number of default values for keyword only arguments is argc >> 8 Can anyone confirm this? I can then open a ticket on bugs.python.org [1] http://docs.python.org/dev/library/dis.html#opcode-MAKE_FUNCTION -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: About MAKE_FUNCTION opcode in Python 3

2011-09-21 Thread Arnaud Delobelle
On 21 September 2011 04:09, Terry Reedy wrote: > I agree that doc should be updated for 3.x. Please suggest a new working if > you can, as well as copying the source snippet above. Add me terry.reedy as > nosy. Done: http://bugs.python.org/issue13026 -- Arnaud -- http://mail.p

Re: strange behavior from recursive generator

2011-09-23 Thread Arnaud Delobelle
m is now missing. If someone can shed light on why this is happening, I'd > be grateful. Line 46: for distribution_other in _balls_in_unlabeled_boxes( Should be: for distribution_other in _balls_in_labeled_boxes( HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: multinomial combinations

2011-09-24 Thread Arnaud Delobelle
(sorry about the top posting) Change yield c to yield (c,) HTH Arnaud PS: you could also change the if ... To If not ns: Yield ((),) Else: ... On Sep 24, 2011 8:06 AM, "Dr. Phillip M. Feldman" < [email protected]> wrote: > > I wrote a small generator

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Arnaud Delobelle
3, go half and half - generate the lower half by adding to the lower > bound, and the upper half by subtracting from the upper bound. Not #4 the barycentric approach. ((n-i)*a + i*b)/n for i in range(n+1) Gives you n+1 equally spaced values between a and b inclusive Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggested coding style

2011-09-24 Thread Arnaud Delobelle
The documentation says "New in version 2.2.2". But zfill has been in the string module for a lot longer. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Arnaud Delobelle
, 0.8, 1.1] >>> start, stop, n = -1, 1.1, 7 >>> [((n-i)*start + i*stop)/n for i in range(n+1)] [-1.0, -0.7001, -0.39997, -0.09996, 0.20004, 0.5, 0.8, 1.1] On these examples, using fractions is no better than what I suggested in my previous post. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating equally-spaced floats with least rounding error

2011-09-25 Thread Arnaud Delobelle
On 24 September 2011 23:10, Terry Reedy wrote: > On 9/24/2011 10:18 AM, Arnaud Delobelle wrote: >>      ((n-i)*a + i*b)/n for i in range(n+1) > >>>> ['%20.18f' % x for x in [((7-i)*0.0 + i*2.1)/7 for i in range(8)]] > ['0.00'

Re: Suggested coding style

2011-09-25 Thread Arnaud Delobelle
On Sep 25, 2011 10:49 PM, "Chris Angelico" wrote: > And if you're willing to learn, it's not uncommon to start off > complaining and end up appreciating. :) +1 QOTW -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting bits in large string / bit vector

2011-09-26 Thread Arnaud Delobelle
> len(bytes)*8 960 >>> sum(map(counts.__getitem__, bytes)) 480 Pretty fast as well. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python 2.6.7 on Windows

2011-09-27 Thread Arnaud Delobelle
ndows installer on the 2.6.7 page. Do I install > 2.6.6 first and then update to 2.6.7? I don't know if it would suite your needs but there's ActivePython - they provide an installer for 2.6.7 http://www.activestate.com/activepython/downloads HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: syntactic sugar for def?

2011-09-28 Thread Arnaud Delobelle
e a function object. The problem is that you need to provide a code object, and the easiest way to create a code object is to use a def statement :) HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: DRY functions with named attributes used as default arguments

2011-10-09 Thread Arnaud Delobelle
o_default = 42 def foo(arg1, arg2=foo_default): ... foo.DEFAULT = foo_default del foo_default ... Or get the default at function runtime: def foo(arg1, arg2=None): if arg2 is None: arg2 = foo.DEFAULT ... foo.DEFAULT = 42 ... But I'd probably simply go for foo_DEFAULT, foo_MONKEY and foo_SPECIAL. They're also quicker (1 dict lookup instead of 2) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: webapp development in pure python

2011-10-25 Thread Arnaud Delobelle
I've never used it, but I think it endeavours to be what you are looking for. HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: __dict__ attribute for built-in types

2011-10-27 Thread Arnaud Delobelle
bute '__dict__' >>>> Some built in types have a __dict__: >>> def foo(): pass ... >>> foo.__dict__ {} >>> import random >>> len(random.__dict__) 57 > > So, i was wondering : > > -- why this behaviour ? Performance reasons I guess. > -- where the official documentation refers to this point ? I don't know this one :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Use and usefulness of the as syntax

2011-11-12 Thread Arnaud Delobelle
> So what is the pragmatics of the as syntax ? It can also help when you want to import two different modules with the same name. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: else in try/except

2011-11-14 Thread Arnaud Delobelle
print("except") ... try except >>> try: ...print("try") ... except TypeError: ...print("except") ... else: ...f() ... try Traceback (most recent call last): File "", line 6, in File "", line 1, in f TypeError >>> HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: suppressing import errors

2011-11-15 Thread Arnaud Delobelle
nd, neither "quicker to execute" nor "more compact" equates > to "more Pythonic". It's idiomatic to write "x is None" when you want to know whether x is None. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: String splitting by spaces question

2011-11-23 Thread Arnaud Delobelle
#x27;" >>> [x for i, p in enumerate(s.split("'")) for x in ([p] if i%2 else p.split())] ['This', 'is', 'an', 'example string', 'with', 'quotes again'] -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-23 Thread Arnaud Delobelle
On 23 November 2011 17:38, W. eWatson wrote: [...] > It may be time to move on to c++. Good Luck. Bye! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: remove characters before last occurance of "."

2011-11-28 Thread Arnaud Delobelle
On 28 November 2011 20:45, Ethan Furman wrote: > [email protected] wrote: >> >> s = GIS.GIS.Cadastral\GIS.GIS.Citylimit >> NeededValue = Citylimit > > NeededValue = s.rsplit('.', 1)[1] Also: >>> s[s.rfind(".") + 1:] 'Citylim

Re: python 2.5 and ast

2011-11-29 Thread Arnaud Delobelle
itor except ImportError: from psi.devsonly.ast import parse, NodeVisitor -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Total newbie question: Best practice

2011-11-29 Thread Arnaud Delobelle
you come back to it in the future. As for the main() function, I don't think it is standard practice in Python. There is no requirement to have a main() function. You can use the idiom: if __name__ == "__main__": ... which will execute if you call the file as a sc

Re: How convert a list string to a real list

2011-11-29 Thread Arnaud Delobelle
On Nov 30, 2011 6:21 AM, "郭军权" wrote: > > Good after > I have a string liststr = '["","","ccc"]' ,and I need convert it to a list like list = ["","","ccc"],what can id do? > Thanks

Re: Clever hack or code abomination?

2011-12-01 Thread Arnaud Delobelle
> 2) If not, try "foo-1", "foo-2", and so on > > 3) If you reach "foo-20", give up. > > What would you say if you saw this: > > for suffix in [''] + [str(i) for i in xrange(-1, -20, -1)]: > It's a little obfuscated ;)

Re: Python 2 or 3

2011-12-03 Thread Arnaud Delobelle
valuable IMHO. There are some significant differences but if you have a good understanding of one, you will have no problem adapting very quickly to the other. And Python 2 is definitely not obsolete :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

How to generate java .properties files in python

2011-12-03 Thread Arnaud Delobelle
here a simple way to achieve this? I could do something like this: def encode(u): """encode a unicode string in .properties format""" return u"".join(u"\\u%04x" % ord(c) if ord(c) > 0xFF else c for c in u).encode("latin_1")

Re: How to generate java .properties files in python

2011-12-04 Thread Arnaud Delobelle
On 3 December 2011 23:51, Peter Otten <[email protected]> wrote: > Arnaud Delobelle wrote: > >> I need to generate some java .properties files in Python (2.6 / 2.7). >> It's a simple format to store key/value pairs e.g. >> >> blue=bleu >> green=ve

Re: How to generate java .properties files in python

2011-12-04 Thread Arnaud Delobelle
solution and this is it. FTR, the 'backslashreplace' argument tells the encoder to replace any character that it can't encode with a backslash escape sequence. Which is exactly what I needed, only I hadn't realised it. Thanks! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate java .properties files in python

2011-12-05 Thread Arnaud Delobelle
On 5 December 2011 20:05, Serhiy Storchaka wrote: > 03.12.11 23:34, Arnaud Delobelle написав(ла): > >> Is there a simple way to achieve this? I could do something like this: >> >> def encode(u): >>     """encode a unicode string in .properties format

Re: How to generate java .properties files in python

2011-12-05 Thread Arnaud Delobelle
On 5 December 2011 21:46, Serhiy Storchaka wrote: > 05.12.11 22:25, Arnaud Delobelle написав(ла): >> On 5 December 2011 20:05, Serhiy Storchaka  wrote: >>> You must also encode backslash ('\\'), whitespaces and control characters >>> (ord(c)<=32), '=&

Re: sending a variable to an imported module

2011-12-08 Thread Arnaud Delobelle
eed 'test', import settings and you will be able to access test. This is why singletons are often not needed in Python (just like most other design patterns). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: tracking variable value changes

2011-12-08 Thread Arnaud Delobelle
ainer object.  What you use as a container object > is up to you.  Some use a 1-element list, although I find that ugly. This kind of trick is not often necessary anyway. It may be a sign that there is a better approach to the problem that the OP is trying to solve. -- Arnaud -- http://mail.pyt

Re: Confusion about decorators

2011-12-12 Thread Arnaud Delobelle
ss _TypeCheckedFunction(): def __init__(self, decoratedfunction): self._decoratedfunction = decoratedfunction def __call__(self, *args, **kwargs): [...] Actual checking def __get__(self, obj, objtype): return partial(self, obj) (Untested) HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Confusion about decorators

2011-12-12 Thread Arnaud Delobelle
On 12 December 2011 13:52, Henrik Faber wrote: > On 12.12.2011 14:45, Arnaud Delobelle wrote: > >>> Can someone please enlighten me? >> >> You can (need to?) use the descriptor protocol to deal with methods. >> >> from functools import partial > [...

Re: Verbose and flexible args and kwargs syntax

2011-12-12 Thread Arnaud Delobelle
1,2,3,4,5 >>>> a,b,c > ([1, 2, 3], 4, 5) > >> I personally quite like them, but I would like them to be more general. > > > It already is. The *target can be anywhere in the sequence. > > -- > Terry Jan Reedy You can even have nested sequences! >>> a, (b, *c), *d = 1, "two", 3, 4 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Verbose and flexible args and kwargs syntax

2011-12-12 Thread Arnaud Delobelle
helped by > the fact that (a+b) % c == a%c + b%c You mean (a + b) % c == (a%c + b%c) % c :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Verbose and flexible args and kwargs syntax

2011-12-13 Thread Arnaud Delobelle
ed iterable using * will always > yield a list. That is, unless the construct appears inside a function > definition; then somehow a tuple is always the right choice' When you quote somebody (even yourself), it would be helpful if you attributed your quote. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]

2011-12-14 Thread Arnaud Delobelle
eas, to pursue them and to believe in them, but it would be foolish to think that they are superior to knowledge which has been accumulated over so many generations. You claim that mathematicians have a poor understanding of philosophy. It may be so for many of them, but how is this a problem? I

Re: % is not an operator [was Re: Verbose and flexible args and kwargs syntax]

2011-12-14 Thread Arnaud Delobelle
On 14 December 2011 12:33, Eelco wrote: > On 14 dec, 12:55, Arnaud Delobelle wrote: >> On 14 December 2011 07:49, Eelco wrote: >> > On Dec 14, 4:18 am, Steven D'Aprano > > [email protected]> wrote: >> >> > They might not be will

Re: Making the case for "typed" lists/iterators in python

2011-12-16 Thread Arnaud Delobelle
On 16 December 2011 18:25, Chris Angelico wrote: > tee = lambda func,arg: (func(arg),arg)[1] What a strange way to spell it! def tee(func, arg): func(arg) return arg -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Arnaud Delobelle
ble. How do I achieve that please? Well, you were almost there: pid = recs[19][8] Note: all caps is usually reserved for constants in Python. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
reates 4 intermediate strings, which is quite inefficient (I've got 10s of MB's worth of unicode strings to escape) I can think of another way using regular expressions: escape_ptn = re.compile(r"[\n\t\f\r\\]") # escape_map is defined above def escape_match(m, map=escape_map): return map[m.group(0)] def escape_text(text, sub=escape_match): return escape_ptn.sub(sub, text) Is there a better way? Thanks, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
On 20 December 2011 14:54, Tim Chase wrote: > On 12/20/11 08:02, Arnaud Delobelle wrote: >> >> Hi all, >> >> I've got to escape some unicode text according to the following map: >> >> escape_map = { >>     u'\n': u'\\n', >

Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
t; ...     u'\\': u'' > ... } >>>> escape_map = dict((ord(k), v) for k, v in escape_map.items()) >>>> print u"the quick\n brown\tfox > jumps\\over\\the\\lazy\\dog".translate(escape_map) > the quick\n brown\tfox jumps\\

Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python.

2011-12-21 Thread Arnaud Delobelle
already do: efoo2 = ["one", "two", "three", "four"] ["_".join(reversed((x.capitalize() + " little indian").split(" ")) * 2) for x in efoo2] Note 1: I've ignored the fact that reversed(...)*2 is erroneous Note 2: I wouldn't such code myself, in either form What's the advantage of your elementwise stuff? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How to check for single character change in a string?

2011-12-24 Thread Arnaud Delobelle
at Ian's counts matches and the OP asked > for non-matches, but that's an exercise for the reader :-) Here's a variation on the same theme: sum(map(str.__ne__, str1, str2)) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-25 Thread Arnaud Delobelle
nes of argument in this thread. The real kiss of death is when you find yourself on the same side of the "argument" as ranting Rick. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: mutually exclusive arguments to a constructor

2011-12-30 Thread Arnaud Delobelle
or b = Bearing("N24d30mE") Both methods are used for builtin types: >>> int('12') 12 >>> int(12.5) 12 >>> dict([(1, 2), (3, 4)]) {1: 2, 3: 4} >>> dict.fromkeys([1, 2]) {1: None, 2: None} HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Spamming PyPI with stupid packages

2012-01-04 Thread Arnaud Delobelle
l/python-list/2001-July/090659.html Did you change your mind, Terry? I too used to be against it :) I'll stop now. Cheers, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Arnaud Delobelle
t;        """ That's a clever trick! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing __dict__ with an OrderedDict

2012-01-06 Thread Arnaud Delobelle
ndering if I could somehow replace the dict with an > OrderedDict. No, you can't. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: "+=" does not work correct all alogn

2012-01-18 Thread Arnaud Delobelle
n lst += [a] and lst = lst + [a] The first one mutates the list object named 'lst' by appending 'a' at its end, whereas the second one creates a new list made of the items of lst with 'a' appended at the end. So your function conc1 does not mutate _list, whereas your function conc2 does. HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Is a with on open always necessary?

2012-01-20 Thread Arnaud Delobelle
; So maybe doing a > > with open(filename) as f: >     contents = f.readlines() That's what I do, unless I'm in an interactive session. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird Loop Behaviour

2012-01-20 Thread Arnaud Delobelle
like black = 0, 0, 0 white = 255, 255, 255 for color, wait in (black, 3), (white, 2), (black, 3): screen.fill(color) pygame.display.update() time.sleep(wait) pygame.quit() -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a file from specific column content

2012-01-22 Thread Arnaud Delobelle
[ ("3", "section_1") ("5", "section_2") ("\xFF", "section_3") ] with open(input_path) as input_file: lines = iter(input_file) for end, path in sections: with open(path, "w") as output_file: for line in lines: if line >= end: break output_file.write(line) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a file from specific column content

2012-01-22 Thread Arnaud Delobelle
On 22 January 2012 16:09, MRAB wrote: > On 22/01/2012 15:39, Arnaud Delobelle wrote: [...] >> Or more succintly (but not tested): >> >> >> sections = [ >>     ("3", "section_1") >>     ("5", "section_2") >>  

A way to write properties

2012-01-23 Thread Arnaud Delobelle
gt;> a = A() >>> b = B() >>> a.x 0 >>> a.x_plus_one 1 >>> b.x_plus_one 3 I don't know why one would want to do this though :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

tkinter: invisible PanedWindow "sashes" on OS X

2013-03-21 Thread Arnaud Delobelle
="top pane") m.add(top) bottom = Label(m, text="bottom pane") m.add(bottom) mainloop() -- I can see two panes alright, but no handle to resize them (or 'sash' as they seem to be called in tkinter). Is there something else that I should be doing? TIA, -- A

Re: tkinter: invisible PanedWindow "sashes" on OS X

2013-03-21 Thread Arnaud Delobelle
On 21 March 2013 18:42, Christian Gollwitzer wrote: > Am 21.03.13 15:37, schrieb Arnaud Delobelle: > >> Hi Python List, >> >> I'm trying to use PanedWindow on OS X (10.8.3). I've started with the >> effbot docs example (http://effbot.org

Re: Processing user input as it's entered

2013-03-26 Thread Arnaud Delobelle
yping. The entered text will also > need to be captured once the user has finished typing. > > This is a gui-less CLI tool for python 2.7 > > I've seen some information on tty.setraw but I'm not sure how you'd go about > wiring that up. Can you use curses (http:/

Re: Splitting a list into even size chunks in python?

2013-03-27 Thread Arnaud Delobelle
tools import islice >>> items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> n = 3 >>> list(iter(lambda i=iter(items):list(islice(i, n)),[])) [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] Not too readable though :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorator help

2013-03-27 Thread Arnaud Delobelle
elf.var_a = > > @MyDecorator(...) > def meth_one(self, in_data): > ... I don't really understand what you are trying to do. It would be easier if you had some code that tried to do something (even if it doesn't quite work). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: how do you make a loop run in reverse?

2013-03-27 Thread Arnaud Delobelle
d(lines): ... yield line ... >>> print_pattern(mirror_pattern(generate_pretty_pattern())) * ** *** * *** ** * Here's another example: >>> print_pattern(mirror_pattern(''.join(mirror_pattern("*".ljust(i).rjust(15))) >>> for i in range(1,16,2))) * * * * * * * * * * * * * * * * * * * * * * * * * * * * -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Doing both regex match and assignment within a If loop?

2013-03-29 Thread Arnaud Delobelle
can name these alternatives ( '(?Ppattern)'). Then you can do if m.group('case1'): ... elif m.group('case2'): ... -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Sudoku

2013-03-31 Thread Arnaud Delobelle
where you'd expect it (exit is a constant, not a function): http://docs.python.org/2/library/constants.html#constants-added-by-the-site-module As for the behaviour when you pass a string, it's documented here: http://docs.python.org/2/library/exceptions.html#exceptions.SystemExi

Re: extending class static members and inheritance

2013-04-02 Thread Arnaud Delobelle
return sum((getattr(p, 'mybits', []) for p in cls.mro()[::-1]), []) class Derived(Base): mybits = ["value3", "value4"] class FurtherDerived(Derived): mybits = ["value5"] >>> Derived.mylist() ['value1', 'value2', 'value3', 'value4'] >>> FurtherDerived.mylist() ['value1', 'value2', 'value3', 'value4', 'value5'] HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: is operator versus id() function

2013-04-05 Thread Arnaud Delobelle
lse You've fallen victim to the fact that CPython is very quick to collect garbage. More precisely, when Python interprets `id(A.f) == id(a.f)`, it does the following: 1. Create a new unbound method (A.f) 2. Calculate its id 3. Now the refcount of A.f is down to 0, so it's garbage co

Re: new.instancemethod - how to port to Python3

2013-04-07 Thread Arnaud Delobelle
l it manually > return apply(self.to_binary, varargs, keys) > [...] -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie to python. Very newbie question

2013-04-07 Thread Arnaud Delobelle
t;>> sum(takewhile((100).__gt__, filter((2).__rmod__, map((2).__rpow__, >>> count(1) 165 :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: __doc__ string for getset members

2013-04-07 Thread Arnaud Delobelle
Python works. You won't be able to get the docstring of a descriptor this way. You need to do it from the class. The behaviour you observe is normal and cannot be overriden. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: __doc__ string for getset members

2013-04-07 Thread Arnaud Delobelle
On 7 April 2013 21:38, Nick Gnedin wrote: > > Arnaud, > > Thanks for the answer. I understand that I cannot access the docstring as an > attribute of a getter, but what did you mean when you said "You need to do > it from the class"? I am still confused - is there a wa

Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
also not the best in terms of time or space complexity. Does this mean you have to write tests for time and space complexity as well? That's interesting, but I don't know of tools to help do that (time complexity seems easy enough, but space complexity seems tougher to me). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
hich outputs the song "99 bottles of beer": http://codegolf.com/99-bottles-of-beer Cheers, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do a Lispy-esque read?

2013-04-08 Thread Arnaud Delobelle
[1, 2] You might be interested in code.compile_command() (http://docs.python.org/2/library/code.html) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How to subclass a family

2013-04-08 Thread Arnaud Delobelle
;>> foo.boo(1) Foo1.boo 1 Foo1.bar >>> far = Far1() >>> far.bar() Foo1.bar >>> far.boo(0) DifferentBoo.boo 0 Foo1.boo 0 Foo1.bar >>> far.boo(1) DifferentBoo.boo 1 Foo1.bar HTH, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Python pdb bug, followed by bug in bugs.python.org

2013-04-09 Thread Arnaud Delobelle
ou come in contact with. Therefore, my suggestion is that you stay clear of any computer equipment from now on, as you may cause hazards for yourself and others. Others may be able to elaborate further. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: extract HTML table in a structured format

2013-04-10 Thread Arnaud Delobelle
'colspan="2" {{Version |o |13 April 2007}}', '2.6.12'], ['[[Ubuntu 6.06|6.06 LTS]]', 'Dapper Drake', '1 June 2006', '{{Version |o | 14 July 2009}}', '{{Version |o | 1 June 2011}}', '2.6.15'], ['[[Ubuntu 6.10|6.10]]', 'Edgy Eft', '26 October 2006', 'colspan="2" {{Version |o | 25 April 2008}}', '2.6.17'], [...] ] >>> That should give you the info you need (until the wiki page changes too much!) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode issue with Python v3.3

2013-04-10 Thread Arnaud Delobelle
on this list was answered by Alex Martelli and nowadays I get most excellent and concise tips from Peter Otten - thanks, Peter! If there's one person on this list I don't want to offend, it's you! So here's to lots more good and bad humour on this list, and the occasional slightly un-pc remark even! Cheers, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Arnaud Delobelle
MyObject(metaclass=MyType): pass >>> class Test(MyObject): ... def __metaclass__(name, bases, attrs): ... print("Test metaclass") ... return MyType(name, bases, attrs) ... Test metaclass -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: My gui

2013-04-24 Thread Arnaud Delobelle
o ' + str(miles) + 'miles.') >> >> poop = MyGui() >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > poop? Seriously? You aren’t serious about that copying, right? > > Your code seems to be missing a lot of important stuff. You don’t > inherit from tkinter.Frame. Compare your program to the sample “Hello > world!” program: His class is not a frame, it's just a container for the tkinter code. It's a bit unusual but it looks correct to me (apart from the single underscores in __init__() as spotted by Ned Batchelder). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

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