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

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: 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

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-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 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 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

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: 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

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-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

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

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

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

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: 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: 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

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: 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: 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: 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: 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: 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: 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: 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: __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: __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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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

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

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: 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

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: 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: 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: 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 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 --

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: 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'

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-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-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. >

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: 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

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: 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: 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: 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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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
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
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: 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: 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: 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: 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: 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: 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: 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

  1   2   3   4   5   6   7   8   9   10   >