PythonWin, python thread and PostQuitMessage?

2009-03-12 Thread arnaud
s by setting self.log to False. I wanted to do just: def run(self): print "Wkeylog run called" # Hook Keyboard self.hm.HookKeyboard() win32gui.PumpMessages() However I'm unable to stop this process. Can anyone shred al light here? Rg, Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: socket programming

2013-05-06 Thread Arnaud Delobelle
's a tradeoff. OTOH Twisted can handle much more than socket programming. On the third hand Twisted has its own learning curve as well... -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Arnaud Delobelle
nt ''.join(sorted(open(argv[1]), key=lambda l: -int(l.split('\t')[0]))[:10 if len(argv) < 3 else int(argv[2])]) Who said Python was readabl'y yours, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating valid identifiers

2012-07-26 Thread Arnaud Delobelle
it: namely the field name. Also it's hard to imagine a way to keep things readable when we don't know what the original identifiers look like :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Text editors

2012-07-29 Thread Arnaud Delobelle
seful to get feedback on unused imports / unused variables / undefined variables (which means you spot typos on variable names straight away). For instructions, see e.g. http://www.plope.com/Members/chrism/flymake-mode -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Arnaud Delobelle
r example: for i in range(100): for j in range(100): do_something((i + N)%100, (j + N)%100) Cheers, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
row, a "\uf701" gets inserted. I'm very inexperienced with Tkinter (I've never used it before). All I'm looking for is a workaround, i.e. a way to somehow suppress that output. Thanks in advance, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
On 31 August 2012 15:25, Kevin Walzer wrote: > On 8/31/12 6:18 AM, Arnaud Delobelle wrote: >> >> I'm very inexperienced with Tkinter (I've never used it before). All >> I'm looking for is a workaround, i.e. a way to somehow suppress that >> output. >

Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
On 31 August 2012 16:41, Alister wrote: > On Fri, 31 Aug 2012 11:21:14 -0400, Kevin Walzer wrote: > >> On 8/31/12 11:18 AM, Arnaud Delobelle wrote: >> >> >>> I'm not trying to do anything. When a user presses the UP or DOWN >>> arrow, then a stran

Re: Tkinter bug in Entry widgets on OS X

2012-09-01 Thread Arnaud Delobelle
the Entry widget input area. I've struggled to find good tkinter docs on the web. > caveat -- I've only written one simple form using Tkinter, so what > do I know... It's about as much as I've done! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter bug in Entry widgets on OS X

2012-09-01 Thread Arnaud Delobelle
On 1 September 2012 11:30, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: >> It would be good if I could intercept the key press event and cancel its >> action on the Entry widget. It's easy to intercept the key event, but I >> haven'

running Lua in Python

2012-09-02 Thread Arnaud Delobelle
s to be dormant. My requirements are stock OS X Python (which is 2.7) and Lua 5.2. I'm looking for either a way to make lunatic-python work or another tool that would do the job. Thanks in advance. -- Arnaud [1] http://labix.org/lunatic-python -- http://mail.python.org/mailman/listinfo/python-list

Re: running Lua in Python

2012-09-02 Thread Arnaud Delobelle
On 2 September 2012 10:39, Alec Taylor wrote: > Or you can use a module made for this task: > > http://labix.org/lunatic-python As I said in my original message, I couldn't get this to work. > http://pypi.python.org/pypi/lupa I'll check this out, thanks. -- Arnaud --

Re: running Lua in Python

2012-09-02 Thread Arnaud Delobelle
On 2 September 2012 10:49, Arnaud Delobelle wrote: > On 2 September 2012 10:39, Alec Taylor wrote: >> http://pypi.python.org/pypi/lupa > > I'll check this out, thanks. Mmh it seems to be lua 5.1 and more importantly it seems to require a custom build of Python, which I don&

Re: running Lua in Python

2012-09-02 Thread Arnaud Delobelle
On 2 September 2012 19:42, Stefan Behnel wrote: > Arnaud Delobelle, 02.09.2012 20:34: >> On 2 September 2012 10:49, Arnaud Delobelle wrote: >>> On 2 September 2012 10:39, Alec Taylor wrote: >>>> http://pypi.python.org/pypi/lupa >>> >>> I'll che

Re: Compairing filenames in a list

2012-09-30 Thread Arnaud Delobelle
itertools >>> filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"] >>> dict((key, tuple(val)) for key, val in itertools.groupby(sorted(filenames), >>> lambda f: os.path.splitext(f)[0])) {'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')} -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Obnoxious postings from Google Groups

2012-10-31 Thread Arnaud Delobelle
On 31 October 2012 22:33, Steven D'Aprano wrote: [...] > I don't killfile merely for posting from Gmail And we are humbly grateful. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: sort order for strings of digits

2012-10-31 Thread Arnaud Delobelle
t;> def prefix(s): ... return sum(1 for c in takewhile(str.isdigit, s)) or 1000, s ... >>> L = ['9', '1000', 'abc2', '55', '1', 'abc', '55a', '1a'] >>> sorted(L, key=prefix) ['1', '1a', '9', '55', '55a', '1000', 'abc', 'abc2'] Here's why it works: >>> map(prefix, L) [(1, '9'), (4, '1000'), (1000, 'abc2'), (2, '55'), (1, '1'), (1000, 'abc'), (2, '55a'), (1, '1a')] -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Retrieving an object from a set

2013-01-25 Thread Arnaud Delobelle
_eq__(self, other): equal = self.obj == other if equal: self.lastequal = other return equal >>> yfinder = FindEqual(x) >>> yfinder in S True >>> yfinder.lastequal is y True I've found y! I'm not happy with this as it really is a trick. Is there a cleaner solution? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Arnaud Delobelle
ly if you weren't interested in the first element of the list: from itertools import islice: for el in islice(mylist, 1): process2(el) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: 'class' named tuple

2012-01-31 Thread Arnaud Delobelle
tem__(self, index): return getattr(self, _attrs[index]) def __setitem__(self, index, value) setattr(self, _attrs[index], value) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Arnaud Delobelle
On 1 February 2012 08:11, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > The example should be > >> from itertools import islice: > > for el in islice(mylist, 1, None): >>     process2(el) Oops! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Generator problem: parent class not seen

2012-02-01 Thread Arnaud Delobelle
sions of your class hierarchies. You can check by printing the ids of your classes. You will get classes with the same name but different ids. Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Common LISP-style closures with Python

2012-02-04 Thread Arnaud Delobelle
re of Common-Lisp closures that Python closures share but other languages don't? I think what he is implying is that there is no such feature. Python closures are no more "Common-Lisp-style" than they are "Scheme-style" or "Smalltalk-like" or any other language-like. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: iterating over list with one mising value

2012-02-07 Thread Arnaud Delobelle
ou need your list to be of the form: wordFreq2 = [('with', 3), ('which', 1), ('were', 2), ('well', 1)] Then it will work. The quickest way to transform your list to the required form is something like this: def pairs(seq, fillvalue): it

Re: iterating over list with one mising value

2012-02-07 Thread Arnaud Delobelle
On 7 February 2012 22:57, Dennis Lee Bieber wrote: > On Tue, 7 Feb 2012 21:37:20 +0000, Arnaud Delobelle > wrote: > > >> >>Your list is flat so the unpacking fails.  For it to work, you need >>your list to be of the form: >> >>    wordFreq2 = [('w

Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Arnaud Delobelle
s? I am >> concerned about avoiding name clashes with standard modules and site >> packages. >> >> Thanks. >> > > This is not 100% an answer to the question, but you should read that : > http://www.python.org/dev/peps/pep-0008/ The OP mentions PEP 8 in th

Re: round down to nearest number

2012-02-10 Thread Arnaud Delobelle
n - n%k ... >>> # Round down with a positive k: ... round(167, 100) 100 >>> round(-233, 100 ... ) -300 >>> # Round up with a negative k: ... round(167, -100) 200 >>> round(-233, -100) -200 >>> # Edge cases ... round(500, -100) 500 >>> round(500, 100) 500 >>> # Floats ... round(100.5, -100) 200.0 >>> round(199.5, 100) 100.0 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Read-only attribute in module

2012-02-10 Thread Arnaud Delobelle
ropose that propery() work at module level, for module attributes, as > well as for class attributes. I think Steven would like something else: bare names that cannot be rebound. E.g. something like: >>> const a = 42 >>> a = 7 Would raise an exception. Is that right? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple namespaces within a single module?

2012-02-10 Thread Arnaud Delobelle
): x = "inside a" def fn1(): print(x) class b(Namespace): x = "inside b" def fn1(): print(x) def fn2(): print("hello") fn1() y = "inside main" a.fn1() b.fn1() b.fn2() print(x) print(y) marigold:junk arno$ python3 namespace.py inside a inside b hello inside b inside main inside main A bit more work would be needed to support nested functions and closures... -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: when to use import statements in the header, when to use import statements in the blocks where they are used?

2012-02-10 Thread Arnaud Delobelle
, importing within a function can avoid circularity problems (e.g. A imports B which tries itself to import A) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Arnaud Delobelle
tor to log taken by a method/function to complete it > execution and its working well. > > My requirement : log everything and figure out what bits are slow and > optimize them. > > What are your suggestions ?? Are you familiar with this? http://docs.python.org/library/profile.html

Re: How can I catch misnamed variables?

2012-02-10 Thread Arnaud Delobelle
crop up. > > Is there an automated way to catch errors like these?  I'm using the > compileall module to build my program and it does catch some errors > such as incorrect indentation, but not errors like the above. There's pychecker and pylint -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Arnaud Delobelle
trangely it was working fine the other day. Then while debugging a > script it suddenly started do this and now does this for every script How were you debugging? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: name of a sorting algorithm

2012-02-14 Thread Arnaud Delobelle
on't know what this sort is called, if it even has a name. It's a kind of Selection Sort, as each pass it looks for the minimum of the remaining unsorted items. But it ruffles the unsorted list each pass, seemingly to save using an extra register to store the current minumum (there

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-15 Thread Arnaud Delobelle
ht for all of us who have him in our killfiles. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Interactive keyword help

2012-02-15 Thread Arnaud Delobelle
e thought a couple of sentences here >> http://www.python.org/about/help/ would be justified, what do y'all think? >> > help() is a built-in function, not a keyword. I think he's referring to help *on* keywords, e.g. >>> help('yield') -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-16 Thread Arnaud Delobelle
quot;Both vulnerable", ] CONDITIONS = [ (DEALERS[j], VULNERABILITIES[(i + j)%4]) for i in range(4) for j in range(4) ] If you don't care about the order in which the conditions are listed, you could use CONDITIONS = itertools.product(DEALERS, VULNERABILITIES) (But maybe you do, I haven't looked at the code) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: TEST AN EXECUTABLE PYTHON SCRIPT SPEED UNDER A PYTHON SHELL

2012-02-16 Thread Arnaud Delobelle
ot? A lot of his/its > posts look too intelligent to be computer-generated - or maybe I'm > underestimating the quality of AI. > > I was wondering the exact same thing. I think it may be that what you are underestimating is your ability, as a human being, to create

Re: question about function pointer

2012-02-17 Thread Arnaud Delobelle
*() in python shell, error below happens > >  File "", line 1 >    *() >    ^ > SyntaxError: invalid syntax It's worth reading the Python tutorial. Here's the relevant section: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists You could read all of 4.7 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: HTTP logging

2012-02-20 Thread Arnaud Delobelle
wrapping all my logger.log() calls in try/except blocks, is > there a way to skip logging to the HTTPhandler if the HTTP server is > unavailable? Here's one: subclass HTTPHandler :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: sum() requires number, not simply __add__

2012-02-23 Thread Arnaud Delobelle
why should sum() not be able to > operate on that class? It can. You need to pass a second argument which will be the start value. Try help(sum) for details. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: sum() requires number, not simply __add__

2012-02-23 Thread Arnaud Delobelle
try: start = iterable.next() except StopIteration: return 0 for x in iterable: start += x return start del _sentinel -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: sum() requires number, not simply __add__

2012-02-23 Thread Arnaud Delobelle
On 23 February 2012 21:53, Chris Angelico wrote: > On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle wrote: >> _sentinel = object() >> >> def sum(iterable, start=_sentinel): >>    if start is _sentinel: >> >> del _sentinel > > Somewhat off-topic: Doe

Re: sum() requires number, not simply __add__

2012-02-23 Thread Arnaud Delobelle
On 23 February 2012 22:04, Chris Angelico wrote: > On Fri, Feb 24, 2012 at 8:59 AM, Arnaud Delobelle wrote: >> def sum(iterable, start=_sentinel, _sentinel=_sentinel): > > Is this a reason for Python to introduce a new syntax, such as: > > def foo(blah, optional=del): &g

Re: Does turtledemo in Python 3.2 actually work?

2012-02-24 Thread Arnaud Delobelle
n. > > Can anyone else confirm this as a bug? > > http://docs.python.org/py3k/library/turtle.html#demo-scripts Just tested with Python 3.2.1 on Mac OS X 10.6.8 and all seems fine. Perhaps if you say which platform it's failing on, others will be able to reproduce the fai

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-24 Thread Arnaud Delobelle
;for / break / else" rather than "for / else". -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-26 Thread Arnaud Delobelle
On 26 February 2012 13:38, Wolfgang Meiners wrote: >      do_it = (len(str) <= maxlength) if maxlength is not None else True That's a funny way to spell: do_it = maxlength is None or len(str) <= maxlength -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Listing children processes

2012-02-28 Thread Arnaud Delobelle
; http://code.google.com/p/psutil/ >> >> Cheers, >> Chris > Looked at that before.  psutil doesn't do children. > > --mihai Please don't top-post! Also, psutil.Process.get_children() looks to me like it "does" children. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: exec

2012-03-01 Thread Arnaud Delobelle
a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). I'm curious to know your motivation for doing this. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: decompilation

2012-03-02 Thread Arnaud Delobelle
;.join(patternList)) if '_ ' not in patternList: break if '_ ' not in patternList: print('SURELY you must be CHEATING, but you guessed my word in ' + str(i + 1) + ' tries!!!') else: bogusWord = pickWordFrom(L) print('You lose. The word was: ' + bogusWord) >>> I haven't actually checked if this code runs :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython callable. How?

2012-03-04 Thread Arnaud Delobelle
On Mar 4, 2012 9:04 AM, "Sirotin Roman" wrote: > > Hi. > How exactly jython decides is object callable or not? I defined > __call__ method but interpreter says it's still not callable. > BTW, my code works in cpython It will help if you show us the code. -- Arn

Re: Fast file data retrieval?

2012-03-12 Thread Arnaud Delobelle
http://docs.python.org/library/dbm.html) - it would be very easy to do. Or you could have your own custom solution where you scan the file and build a dictionary mapping keys to file offsets, then when requesting a dataset you can seek directly to the correct position. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Style question (Poll)

2012-03-14 Thread Arnaud Delobelle
hey don't do the same thing :) I suspect you meant: for value in list:   if not value is another_value:    value.do_something()  break I always feel uncomfortable with this because it's misleading: a loop that never loops. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Style question (Poll)

2012-03-14 Thread Arnaud Delobelle
On 14 March 2012 22:15, Prasad, Ramit wrote: > Only use 'is' if you are looking for objects like True, > False, None or something that MUST be exactly the same object. I've rarely seen valid uses of 'is True' or 'is False'. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is readable

2012-03-14 Thread Arnaud Delobelle
2): return [x1 + x2 for x1, x2 in zip(list1, list2)] Or in Python 2.X: from itertools import izip def pairwise_sum(list1, list2): return [x1 + x2 for x1, x2 in izip(list1, list2)] Or even: from operator import add def pairwise_sum(list1, list2): return map(add, list1, list2) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is readable

2012-03-15 Thread Arnaud Delobelle
On 15 March 2012 00:27, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: >> I don't know this book and there may be a pedagogical reason for the >> implementation you quote, but pairwise_sum is probably better >> implemented i

Re: Python is readable

2012-03-15 Thread Arnaud Delobelle
at span more than one line. If the worst comes to the worst, I would write: aptly_named_condition = ( very long condition that goes over plenty of lines ) if aptly_named_condition: do stuff -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Currying in Python

2012-03-20 Thread Arnaud Delobelle
On 19 March 2012 23:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! > > On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm > wrote: >> Here we go. >> >> ---> >> def genCur(f, unique = True, minArgs = -1): > > It is customary in Python for unsupplied arguments with no default to >

Re: Odd strip behavior

2012-03-22 Thread Arnaud Delobelle
gt; if __name__ == '__main__': >main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? Try help(ste.strip) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Odd strip behavior

2012-03-22 Thread Arnaud Delobelle
On 22 March 2012 20:04, Rodrick Brown wrote: > > On Mar 22, 2012, at 3:53 PM, Arnaud Delobelle wrote: > Try help(ste.strip) > > It clearly states "if chars is given and not None, remove characters in > chars instead. > > Does it mean remove only the first occurrence

Re: Python Gotcha's?

2012-04-05 Thread Arnaud Delobelle
On 5 April 2012 21:06, Emile van Sebille wrote: > Kind of begs for a contains method that returns the appropriate boolean: > > if text.contains('bob') It's already there: text.__contains__('bob') It's usually spelt otherwise though: 'bob

Re: Zipping a dictionary whose values are lists

2012-04-14 Thread Arnaud Delobelle
On 13 April 2012 17:35, Kiuhnm wrote: > On 4/13/2012 17:58, Alexander Blinne wrote: >> >> zip(*[x[1] for x in sorted(d.items(), key=lambda y: y[0])]) > > Or >  zip(*[d[k] for k in sorted(d.keys())]) .keys() is superfluous here: zip(*(d[k] for k in sorted(d

Re: Making helper methods more concise

2012-04-16 Thread Arnaud Delobelle
object): def __init__(self): self.listing = [] # This method does the work. def append_text(self, text, style): self.listing.append((text, style)) # The rest of the methods are just helpers. for style in 'paragraph', 'header', 'title': exec """def append_%s(self, text): self.append_text(text, "%s")""" % (style, style.capitalize()) del style -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Making helper methods more concise

2012-04-16 Thread Arnaud Delobelle
On 16 April 2012 13:29, Arnaud Delobelle wrote: > You can do this (untested), but no doubt it won't be to everybody's taste: > > class A(object): >   def __init__(self): >       self.listing = [] > >   # This method does the work. >  

Re: Framework for a beginner

2012-04-17 Thread Arnaud Delobelle
On 17 April 2012 09:54, Bryan wrote: > Django has emphasized backwards compatibility with the > down-side that, last I heard, there was no plan to move to Python 3. Not quite: https://www.djangoproject.com/weblog/2012/mar/13/py3k/ -- Arnaud -- http://mail.python.org/mailman/listinfo/

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Arnaud Delobelle
#x27;ve learnt a lot from your posts on this list over the years, but too often you spoil it with your compulsion to have the last word on every argument you get involved in at any cost. Some arguments aren't worth winning... -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: confusing doc: mutable and hashable

2012-04-28 Thread Arnaud Delobelle
s long as __eq__ only relies on immutable state (and then so should __hash__ of course). A typical example would be an object that does some caching. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax for code blocks

2012-05-01 Thread Arnaud Delobelle
Perhaps you would have better luck if you either post the actual code > you want people to critique, or posted a link to that code. He did post a link to a blog post describing his module and also a link to the actual code, on bitbucket IIRC. Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: return respective values when mutiple keys are passed in dictionary

2012-05-07 Thread Arnaud Delobelle
e','boy','cat'    ### Output i want > # 1. You can use a list comprehension >>> [mydict[k] for k in 'a', 'b', 'c'] ['apple', 'boy', 'cat'] 2. You can use map (for python 3.X, you need to wrap this in list(...)) >>> map(mydict.__getitem__, ['a', 'b', 'c']) ['apple', 'boy', 'cat'] 3. You can use operator.itemgetter >>> from operator import itemgetter >>> itemgetter('a', 'b', 'c')(mydict) ('apple', 'boy', 'cat') -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Good data structure for finding date intervals including a given date

2012-05-13 Thread Arnaud Delobelle
. I can't access it but it seems to me it's not about self sorted data structures, which is what the OP is looking for. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Carbon Event Manager (Carbon.CarbonEvt module) - working?

2012-05-15 Thread Arnaud Delobelle
rsistently.  Another > way that should work for any OS X universal Python 2.7.x: > >    arch -i386 python2.7 This is what I have with system python 2.6: $ cat ~/bin/python_32 #! /bin/bash export VERSIONER_PYTHON_PREFER_32_BIT=yes /usr/bin/python "$@" I use it for wxpython, which only seems to work in 32 bit mode. I can't remember where I found it. Maybe I read the man page? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate only rotationally-unique permutations?

2012-05-19 Thread Arnaud Delobelle
s me think of Lyndon words. A Lyndon word is a word which is the only lexicographical minimum of all its rotations. There is a very effective way of generating Lyndon words of length <= n. It may be possible to adapt it to what you want (obviously as Lyndon words are aperiodic you'd have t

Re: Help doing it the "python way"

2012-05-29 Thread Arnaud Delobelle
yet effective: new_list = [(x, y + i) for x, y in coord_list for i in (-1, 1)] IMHO these list comprehensions are often overlooked too quickly in favour of itertools (in this case chain.from_iterable). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: python3 raw strings and \u escapes

2012-05-30 Thread Arnaud Delobelle
On 30 May 2012 12:54, Thomas Rachel wrote: > There is a 3rd one: use   r'[ ' + '\u3000' + ']'. Not very nice to read, but > should do the trick... You could even take advantage of string literal concatenation:) r'[' '\u3000' r&#x

Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-10 Thread Arnaud Delobelle
s :) This article makes me feel more positive about my inability to feel comfortable in an IDE. Thanks for the link! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with ImapLib and subject in French

2012-06-18 Thread Arnaud Delobelle
up_Les_Gr=E8ves?= > > But the search function doesn't find my email, and I don't know why, even if > I try with the entire string of the subject. Can you post the code that doesn't work? It's hard to debug "search function doesn't find my email". It would

Getting a module's code object

2011-08-25 Thread Arnaud Delobelle
is marshalled into the .pyc file - so there may be a way to unmarshal it - but I can't easily find information about how to do this. Is this a good lead, or is there another way to obtained a module's code object? Thanks -- Arnaud [1] http://docs.python.org/py3k/library/marshal.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Run time default arguments

2011-08-25 Thread Arnaud Delobelle
27;debug' : false } > def doSomething (debug = None): >     debug = debug if debug != None else defaults['debug'] >     # blah blah blah You're close to the usual idiom: def doSomething(debug=None): if debug is None: debug = defaults['debug'] ..

Re: Getting a module's code object

2011-08-25 Thread Arnaud Delobelle
On 25 August 2011 16:07, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > >> In Python 3, a function f's code object can be accessed via f.__code__. >> >> I'm interested in getting a module's code object, [...] > > Taken from

The RAISE_VARARGS opcode in Python 3

2011-08-26 Thread Arnaud Delobelle
ARGS's argument can only be 0 or 1 in Python 3, whereas it could be up to 3 in Python 2. Can anyone confirm that this is the case? In this case, I guess the dis docs need to be updated. Thank you, Arnaud [1] http://docs.python.org/py3k/library/dis.html#opcode-RAISE_VARARGS [2] http://www.python.org/dev/peps/pep-3109/#grammar-changes -- http://mail.python.org/mailman/listinfo/python-list

Re: The RAISE_VARARGS opcode in Python 3

2011-08-27 Thread Arnaud Delobelle
On 27 August 2011 07:49, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > >> Here is an extract from the dis module doc [1] >> >> """ >> RAISE_VARARGS(argc) >> Raises an exception. argc indicates the number of parameters to

how to format long if conditions

2011-08-27 Thread Arnaud Delobelle
e) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) What would you do? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: how to format long if conditions

2011-08-27 Thread Arnaud Delobelle
On 27 August 2011 08:24, Steven D'Aprano wrote: > Arnaud Delobelle wrote: > >> Hi all, >> >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to <80 colums) >> >> Here's a

Re: Returning a value from exec or a better solution

2011-08-29 Thread Arnaud Delobelle
be > more than just the one function in there (though I suppose I may be able to > work around that). Hi Jack, Here is a possible solution for your problem (Python 3): >>> class CapturingDict(dict): ... def __setitem__(self, key, val): ... self.key, self.val = key, val ... dict.__setitem__(self, key, val) ... >>> c = CapturingDict() >>> exec("def myfunction(x): return 1", c) >>> c.key 'myfunction' >>> c.val HTH, -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: killing a script

2011-08-29 Thread Arnaud Delobelle
t if I am not mistaken, that will require me to put a line or > two after each os.system call. That's almost like whack-a-mole at the > code level rather than the Control-C level. OK, not a huge deal for > one script, but I was hoping for something simpler. I was hoping I > could put

Re: Returning a value from exec or a better solution

2011-08-30 Thread Arnaud Delobelle
uot;works flawlessly" post.  In addition to > your issue, there is also the problem that supplying an empty environment > does not allow the user to call necessary functions (like scheme_eval). You could simply prepend the function definition string with whatever imports are needed. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning a value from exec or a better solution

2011-08-30 Thread Arnaud Delobelle
On 30 August 2011 22:48, Rob Williscroft wrote: > Arnaud Delobelle wrote in > news:CAJ6cK1YVi3NQgdZOUdhAESf133pUkdazM1PkSP=p6xfayvo...@mail.gmail.com in > gmane.comp.python.general: > >> On 30 August 2011 13:31, Jack Trades wrote: >>> >>> >>> On

Re: Closures and Partial Function Application

2011-08-31 Thread Arnaud Delobelle
hieving this in Python? Would it look something like this: > > def foo(x, y): >    return x + y > > xFoo = lambda y: foo(10, y) from functools import partial foo10 = partial(foo, 10) HTH Arnaud -- http://mail.python.org/mailman/listinfo/python-list

PyGILState_Release called twice in embedded application

2023-03-23 Thread Arnaud Loonstra
e_Release is called again. (7) while I've already called it (126). I can make the crash go away by adding import warnings warnings.simplefilter("ignore", ResourceWarning) to my python code. But I'd rather prevent this from happening in the first place. Any suggestion ver

Re: PyGILState_Release called twice in embedded application

2023-03-23 Thread Arnaud Loonstra
On 23-03-2023 13:33, Barry Scott wrote: On 23 Mar 2023, at 08:46, Arnaud Loonstra wrote: Hi all, I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release. I'm running Python in a native thread (so a thread cr

Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
onactor.c862 0x5568e472 19 pythonactor_handlerpythonactor.c828 0x5568e2e2 20 sphactor_actor_run sphactor_actor.c 855 0x558cb268 ... Any pointer really appreciated. Rg, Arnaud -- https://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 13:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understanding of CPython limits me here. I'm creating a Tuple in

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understanding of CPython limits me here

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running int

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got P

Re: Embedding Python crash on PyTuple_New

2021-11-24 Thread Arnaud Loonstra
On 24-11-2021 01:46, MRAB wrote: On 2021-11-23 20:25, Arnaud Loonstra wrote: On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB

Embedding Python (3.7) on OSX crash on Py_Initialize when run as bundle

2019-02-28 Thread Arnaud Loonstra
Python is build with the following flags: ./configure --prefix $HOME/openFrameworks/apps/devApps/$APPNAME/bin/python --disable-shared --with-openssl=$(brew --prefix openssl); Anybody any pointers or advice? Rg, Arnaud -- https://mail.python.org/mailman/listinfo/python-list

return a ctypes object to C

2019-10-30 Thread Arnaud Loonstra
;" [super class] "" [meta type] "" ob_refcnt 1 Py_ssize_t However how I can I get it back to the original C type (zmsg_t *) Any help really appreciated. Rg, Arnaud -- https://mail.python.org/mailman/listinfo/python-list

Re: return a ctypes object to C

2019-10-31 Thread Arnaud Loonstra
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 method is called from C and needs to return an object which we then process in C again

  1   2   3   4   5   6   7   8   9   10   >