Re: Naming conventions for functions and methods

2014-07-08 Thread Arnaud Delobelle
On 8 July 2014 15:59, wrote: > > Looking for your opinions on how you name your functions and methods. > Example: I have a function that hashes a file. I could name this function > hash_file() or file_hash(). The 1st naming convention sounds more natural, > the 2nd naming convention allows one

Re: socket programming

2013-05-06 Thread Arnaud Delobelle
On 6 May 2013 17:05, Chris Angelico wrote: > I've never used Twisted, so I can't say how good it is. All I know is > that what I learned about socket programming in C on OS/2 is still > valid on Windows and on Linux, and in every language I've ever used > (bar JavaScript and ActionScript, which a

Re: My gui

2013-04-24 Thread Arnaud Delobelle
On 24 April 2013 18:53, Chris “Kwpolska” Warrick wrote: > On Wed, Apr 24, 2013 at 7:08 PM, Daniel Kersgaard > wrote: >> Today, being the last day of lectures at school, my instructor ran briefly >> through Tkninter and GUIs. I'd been looking forward to this particular >> lesson all semester, bu

Re: name lookup failure using metaclasses with unittests

2013-04-11 Thread Arnaud Delobelle
On 11 April 2013 07:43, Ulrich Eckhardt wrote: > The second question that came up was if there is a way to keep a metaclass > defined inside the class or if the only way is to provide it externally. Yes, using metaclasses! I wouldn't recommend it though. Here's a proof of concept: class MyTyp

Re: Unicode issue with Python v3.3

2013-04-10 Thread Arnaud Delobelle
On 10 April 2013 09:28, Steven D'Aprano wrote: > On Tue, 09 Apr 2013 23:04:35 -0700, rusi wrote: [...] > I think it is quite unfair of you to mischaracterise the entire community > response in this way. One person made a light-hearted, silly, unhelpful > response. (As sarcasm, I'm afraid it missed

Re: extract HTML table in a structured format

2013-04-10 Thread Arnaud Delobelle
On 10 April 2013 09:44, Jabba Laci wrote: > Hi, > > I wonder if there is a nice way to extract a whole HTML table and have the > result in a nice structured format. What I want is to have the lifetime > table at the bottom of this page: > http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then

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

2013-04-09 Thread Arnaud Delobelle
On 9 April 2013 16:25, wrote: > I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit > Arch Linux system) and am attempting to use pdb to debug it. I am getting > incorrect stack traces. I've made up a little 10-line program that > illustrates the problem and I attempted

Re: How to subclass a family

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 10:44, Antoon Pardon wrote: > Here is the idea. I have a number of classes with the same interface. > Something like the following: > > class Foo1: > def bar(self, ...): > work > def boo(self, ...): > do something > self.bar(...) > > What I want is t

Re: How to do a Lispy-esque read?

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 08:45, wrote: > Suppose I want to read an object from some stream. How do I do it? > > For example, if the input stream contained the text: > [1, # python should ignore this comment > 2] > > and I do a "read" on it, I should obtain the result > [1, 2] You might be interested in c

Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 17:20, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith wrote: >> I can't help point out, however, that if your initial implementation is to >> have your code return a constant, it's pretty likely to be an optimum >> solution in both time and space :-) > > Likel

Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 14:21, Roy Smith wrote: > For a while, I was rabidly(*) into TDD (Test Driven Development). The > cycle I was using was, "Write a specification of a behavior, write a > (failing) test for that behavior, then write the least possible amount > of code to make the test pass. Lather

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 way to get that > docstring or

Re: __doc__ string for getset members

2013-04-07 Thread Arnaud Delobelle
On 7 April 2013 19:02, Nick Gnedin wrote: > > Folks, > > I am writing an extension where I follow the guide on the web > (http://docs.python.org/3.3/extending/newtypes.html#generic-attribute-management). > I have an object declared, > > struct Object > { > PyObject_HEAD > }; > > and a member s

Re: Newbie to python. Very newbie question

2013-04-07 Thread Arnaud Delobelle
On 7 April 2013 20:23, Ian Foote wrote: > I'm surprised no one has suggested: > import math sum( x*x for x in range(1, int(math.sqrt(100)), 2)) Yeah! And I'm surprised no one came up with: >>> from itertools import count, takewhile >>> sum(takewhile((100).__gt__, filter((2).__rmod__, m

Re: new.instancemethod - how to port to Python3

2013-04-07 Thread Arnaud Delobelle
On 7 April 2013 10:50, Helmut Jarausch wrote: > Hi, > > I'm trying to port a class to Python3.3 which contains > > class Foo : > > def to_binary(self, *varargs, **keys): > > > > self.to_binary = new.instancemethod(to_binary, self, self.__class__) `self` isn'

Re: is operator versus id() function

2013-04-05 Thread Arnaud Delobelle
On 5 April 2013 14:49, Candide Dandide wrote: > Until now, I was quite sure that the is operator acts the same as the id > builtin function, or, to be more formal, that o1 is o2 to be exactly > equivalent to id(o1) == id(o2). This equivalence is reported in many books, > for instance Martelli's

Re: extending class static members and inheritance

2013-04-02 Thread Arnaud Delobelle
On 2 April 2013 14:27, Fabian PyDEV wrote: > Hi All, > > I have a question. > > Let says I have the following two classes: > > class Base(object): > __mylist__ = ["value1", "value2"] > > def somemethod(self): > pass > > > class Derived(Base): > __mylist__ =

Re: Sudoku

2013-03-31 Thread Arnaud Delobelle
On 31 March 2013 23:34, Dave Angel wrote: >[...] With my Python > 2.7.2, exit(something) with something being a string prints the string and > then exits. Nowhere have I seen that documented, and I thought it either > took an int or nothing. It is documented, just not exactly where you'd expect

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

2013-03-29 Thread Arnaud Delobelle
On Friday, 29 March 2013, Alain Ketterlin wrote: > Victor Hooi > writes: > > > expression1 = re.compile(r'') > > expression2 = re.compile(r'') > [...] > > Just a quick remark: regular expressions are pretty powerful at > representing alternatives. You could just stick everything in

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

2013-03-27 Thread Arnaud Delobelle
On 26 March 2013 23:59, wrote: > So i have a set of for loops that create this : > > *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** >*** *** *** *** *** *** *** >*** *** *** *** *** *** **

Re: Decorator help

2013-03-27 Thread Arnaud Delobelle
On 27 March 2013 19:49, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that are > passed in data > and do work referencing the class vars. > > > I want to decorate these methods, the decorator needs access to the class > vars, so I thought > about ma

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

2013-03-27 Thread Arnaud Delobelle
On 27 March 2013 08:27, Peter Otten <__pete...@web.de> wrote: > Look again, for the grouper() recipe. For lists you can also use slicing: > items > ['a', 'b', 'c', 'd', 'e', 'f', 'g'] n = 3 [items[start:start+n] for start in range(0, len(items), n)] > [['a', 'b', 'c'], ['d', 'e', 'f

Re: Processing user input as it's entered

2013-03-26 Thread Arnaud Delobelle
On 26 March 2013 10:07, Sven wrote: > Hello, > > Is there a way (ideally cross platform but a *nix OS solution would be > great) to process user input as they type? > What I aim to achieve is to count the number of characters a user has > entered and display it while they are typing. The entered t

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
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/tkinterbook/panedwindow.htm), namely: -- from Tkinter import * m = PanedWindow(orient=VERTICAL) m.pack(fill=BOTH, expand=1) top = Label(m, text="top pane") m.add

Retrieving an object from a set

2013-01-25 Thread Arnaud Delobelle
Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to ret

Re: sort order for strings of digits

2012-10-31 Thread Arnaud Delobelle
On 31 October 2012 23:09, Steven D'Aprano wrote: > The trick is to take each string and split it into a leading number and a > trailing alphanumeric string. Either part may be "empty". Here's a pure > Python solution: > > from sys import maxsize # use maxint in Python 2 > def split(s): > for

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
On 30 September 2012 02:27, Kevin Anthony wrote: > I have a list of filenames, and i need to find files with the same name, > different extensions, and split that into tuples. does anyone have any > suggestions on an easy way to do this that isn't O(n^2)? >>> import os, itertools >>> filenames =

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 -- http://mail.python.org/m

running Lua in Python

2012-09-02 Thread Arnaud Delobelle
Hi all, I'm looking for a way to run Lua scripts in Python, and also send and receive data between the two. Something like lunatic-python [1] would be ideal. However, so far I haven't been able to build it on the machines it's supposed to run on (macs with OS X Lion) and it seems to be dormant.

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
On Friday, 31 August 2012, Dennis Lee Bieber wrote: > On Fri, 31 Aug 2012 15:41:01 GMT, Alister > > > > declaimed the following in gmane.comp.python.general: > > > I agree that it is unexpected in a single line entry box but isn't the > 1st > > rule of user interface design to assume the user is

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
Hi all, I'm writing a small GUI on OS X (v. 10.7.4) using Tkinter. I'm using stock Python. It mostly works fine but there is a bug in Entry widgets: if and Entry widget has focus and I press the UP arrow, a "\uf700" gets inserted in the widget. If I press the DOWN arrow, a "\uf701" gets inserte

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

2012-08-06 Thread Arnaud Delobelle
On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some > other values i = N and j = M, and I want to iterate through a

Re: OT: Text editors

2012-07-29 Thread Arnaud Delobelle
On 29 July 2012 06:36, rusi wrote: > Just curious about your emacs+python usage. > Do you use the emacs builtin python mode or the separate python-mode? > Do you use pdb? > Any other special setups? One thing that I find very useful is to configure flymake to use pyflakes. Very useful to get fee

Re: Generating valid identifiers

2012-07-26 Thread Arnaud Delobelle
On 26 July 2012 13:26, Laszlo Nagy wrote: [...] > I do not want this program to generate very long identifiers. It would > increase SQL parsing time, and don't look good. Let's just say that the > limit should be 32 characters. But I also want to recognize the identifiers > when I look at their mo

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Arnaud Delobelle
On 17 July 2012 13:01, Lipska the Kat wrote: > Well I've set myself a task. > I have a text file containing a list of stock items > each line contains the number in stock followed by a tab followed by the > name of the item. I need to implement something that reads in the text file > and outputs

Re: Problem with ImapLib and subject in French

2012-06-18 Thread Arnaud Delobelle
On 18 June 2012 12:31, Valentin Mercier wrote: > Hi, > > I'm trying to search some mails with SUBJECT criteria, but the problem is > the encoding, I'm trying to search french terms (impalib and python V2.7) > > I've tried few things, but I think the encoding is the problem, in my mail > header I h

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

2012-06-10 Thread Arnaud Delobelle
On 10 June 2012 07:16, rusi wrote: > This is worth a read in this context: http://osteele.com/archives/2004/11/ides Interesting! I definitely fall nicely at one extreme of this dichotomy. Every time I've tried to use an IDE, it's made me feel inadequate and I've quickly retreated to my comfort

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']' -- Arnaud -- http://mail.python.org/mailman/listinfo/python

Re: Help doing it the "python way"

2012-05-29 Thread Arnaud Delobelle
On 24 May 2012 21:22, Scott Siegler wrote: > Hello, > > I am an experienced programmer but a beginner to python.  As such, I can > figure out a way to code most algorithms using more "C" style syntax. > > I am doing something now that I am sure is a more python way but i can't > quite get it rig

Re: How to generate only rotationally-unique permutations?

2012-05-19 Thread Arnaud Delobelle
On 19 May 2012 06:23, John O'Hagan wrote: > To revisit a question which I'm sure none of you remember from when I posted > it > a year or so ago - there were no takers at the time - I'd like to try again > with > a more concise statement of the problem: > > How to generate only the distinct perm

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

2012-05-15 Thread Arnaud Delobelle
On 15 May 2012 20:55, Ned Deily wrote: > In article > , >  msmucr wrote: >> i would like to ask you for some information regarding Carbon Event >> Manager ( Carbon.CarbonEvt ) library in Python. >> I need to recieve and work with few Carbon events in my program. I've >> followed some examples on

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

2012-05-13 Thread Arnaud Delobelle
On 13 May 2012 13:29, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. I don't think that'll help the OP. Python's OrderedDict keeps track of the order in which the keys were inserted into the dictionary (a bit like a list), it doesn't keep the keys sor

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

2012-05-07 Thread Arnaud Delobelle
On 7 May 2012 12:31, Nikhil Verma wrote: > HI All > > I was clearing my concepts on dictionary and stuck in this problem. > I have a dictionary which i have formed by using zip function on two list so > that one list (which i have hardcoded) becomes the keys and the other list > becomes its values

Re: syntax for code blocks

2012-05-01 Thread Arnaud Delobelle
(sent from my phone) On May 1, 2012 6:42 PM, "Jerry Hill" wrote: > > On Tue, May 1, 2012 at 1:07 PM, Kiuhnm > wrote: > > If you had read the module's docstring you would know that the public > > version uses > > Are you aware that you've never posted a link to your module, nor it's > docstrings?

Re: confusing doc: mutable and hashable

2012-04-28 Thread Arnaud Delobelle
(sent from my phone) On Apr 28, 2012 7:36 PM, "Chris Rebert" wrote: > Correct. Pedantically, you can define __hash__() on mutable objects; > it's just not very useful or sensible, so people generally don't. I find it's fine to define __hash__ on mutable objects as long as __eq__ only relies on im

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

2012-04-26 Thread Arnaud Delobelle
On 26 April 2012 12:42, Adam Skutt wrote: > On Apr 26, 5:10 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Wed, 25 Apr 2012 20:50:21 -0700, Adam Skutt wrote: >> > On Apr 25, 8:01 pm, Steven D'Aprano > > +comp.lang.pyt...@pearwood.info> wrote: >> >> On Wed, 25 Apr 2012 13:49:24

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/python-li

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
On 16 April 2012 13:01, Alan Ristow wrote: > Hi all, > > I have defined a class that includes a number of helper methods that > are useful to me, but pretty redundant. Something like so, where I > maintain a list of tuples: > > class A(object): >    def __init__(self): >        self.listing = [] >

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))) -- Arnaud -- http://mail.pyth

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' in text -- Arnaud -- http://mail.python.org/

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
On Mar 22, 2012 7:49 PM, "Rodrick Brown" wrote: > > #!/usr/bin/python > > def main(): > >str1='this is a test' >str2='t' > >print "".join([ c for c in str1 if c not in str2 ]) >print(str1.strip(str2)) > > if __name__ == '__main__': >main() > > ./remove_str.py > his is a es > hi

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
On 15 March 2012 22:35, Ben Finney wrote: > Kiuhnm writes: > >> Moreover, I think that >>   if ( >>       >>       ): >>       >>       >>       >> is not very readable anyway. > > I agree, and am glad PEP 8 has been upda

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
On 14 March 2012 23:34, Kiuhnm wrote: > I've just started to read >  The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { >    my($arg1, $arg2) = @_; >    my(@result) = (); >    @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
On 14 March 2012 20:37, Croepha wrote: > Which is preferred: > > for value in list: >  if not value is another_value: >    value.do_something() >    break > > --or-- > > if list and not list[0] is another_value: >  list[0].do_something() Hard to say, since they don't do the same thing :) I suspe

Re: Fast file data retrieval?

2012-03-12 Thread Arnaud Delobelle
On 12 March 2012 19:39, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data

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. -- Arnaud -- http://mail.python.org/mai

Re: decompilation

2012-03-02 Thread Arnaud Delobelle
On 2 March 2012 18:52, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Aha, a customer! I've written a module for this: unpyc3 (http://code.google.com/p/unpyc3/) Here it is in action: Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53) [GCC 4.2

Re: exec

2012-03-01 Thread Arnaud Delobelle
On 1 March 2012 13:07, Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: >    def __init__(self): >        cmd = "def sqr(self, x):\n    return x**2\nself.sqr = sqr\n" >        exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sq

Re: Listing children processes

2012-02-28 Thread Arnaud Delobelle
On 28 February 2012 21:39, Mihai Badoiu wrote: > On Tue, Feb 28, 2012 at 4:35 PM, Chris Rebert wrote: >> >> On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: >> > I'm trying to compute the total CPU load of an external process and it's >> > children.  (so I cannot use resource.getrusage)  Fo

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
On 24 February 2012 14:54, Steven D'Aprano wrote: > for...else is a very useful construct, but the name is misleading. It > took me a long time to stop thinking that the else clause executes when > the for loop was empty. This is why I think we should call this construct "for / break / else" rat

Re: Does turtledemo in Python 3.2 actually work?

2012-02-24 Thread Arnaud Delobelle
On 24 February 2012 12:25, Steven D'Aprano wrote: > Python 3.2 includes turtledemo, a demonstration program for the turtle > module. > > When I run it, I can load the turtle scripts, and the GUI application > says "Press the start button", but there is no start button. > > Can anyone else confirm

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
On 23 February 2012 21:23, Buck Golemon wrote: > def sum(values, > base=0): >      values = > iter(values) > >      try: >          result = values.next() >      except StopIteration: >          return base > >      for value in values: >          result += value >      return result This is defi

Re: sum() requires number, not simply __add__

2012-02-23 Thread Arnaud Delobelle
On 23 February 2012 21:19, Buck Golemon wrote: > I feel like the design of sum() is inconsistent with other language > features of python. Often python doesn't require a specific type, only > that the type implement certain methods. > > Given a class that implements __add__ why should sum() not be

Re: HTTP logging

2012-02-20 Thread Arnaud Delobelle
On 20 February 2012 16:03, Jason Friedman wrote: > I am logging to HTTP: > > logger.addHandler(logging.handlers.HTTPHandler(host, url)) > > Works great, except if my HTTP server happens to be unavailable: > > socket.error: [Errno 111] Connection refused > > Other than wrapping all my logger.log()

Re: question about function pointer

2012-02-17 Thread Arnaud Delobelle
On 17 February 2012 07:53, Zheng Li wrote: > def method1(a = None): >        print a > > i can call it by > method1(*(), **{'a' : 1}) > > I am just curious why it works and how it works? > and what do *() and **{'a' : 1} mean? > > when I type *() in python shell, error below happens > >  File "",

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

2012-02-16 Thread Arnaud Delobelle
On 16 February 2012 21:10, Prasad, Ramit wrote: >>> When you reply to a known bot, please include some indication of the >>> fact, so we know your message can be ignored as well. > >>Sometimes I wonder about 8. Is there a real person there, as well as the >>bot? A lot of his/its > posts look

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

2012-02-16 Thread Arnaud Delobelle
On 16 February 2012 05:03, Ian Kelly wrote: > On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster > wrote: >> As to your first suggestion though, I am having some difficulty. Note >> that the vulnerability rotates; i.e. CONDITIONS[4] is not the same as >> CONDITIONS[0]. >> Is there a better way of doi

Re: Interactive keyword help

2012-02-15 Thread Arnaud Delobelle
On 15 February 2012 17:23, Andrew Berg wrote: > On 2/15/2012 10:04 AM, Mark Lawrence wrote: >> I didn't realise that this was available until today.  It doesn't appear >> to be prominent in the official docs or have I missed something? >> Certainly I'd have thought a couple of sentences here >> ht

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

2012-02-15 Thread Arnaud Delobelle
On 15 February 2012 09:47, Duncan Booth wrote: > Rick Johnson wrote: [...] Perhaps it's a bit presumptuous of me but... It's tempting to react to his inflammatory posts, but after all Rick is a troll and experience shows that trolls are best left alone. Also, please spare a thought for all of u

Re: name of a sorting algorithm

2012-02-14 Thread Arnaud Delobelle
On 14 February 2012 15:31, Dennis Lee Bieber wrote: > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci > wrote: > >>Could someone please tell me what the following sorting algorithm is called? >> >>Let an array contain the elements a_1, a_2, ..., a_N. Then: >> >>for i = 1 to N-1: >>    for j = i+1

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Arnaud Delobelle
On 13 February 2012 19:50, waylan wrote: > When I try running any Python Script on the command line with Python > 3.2 I get this weird behavior. The cursor dances around the command > line window and nothing ever happens. Pressing Ctr+C does nothing. > When I close the window (mouse click on X in

Re: How can I catch misnamed variables?

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 21:06, John Gordon wrote: > Recently I was been bitten by some stupid errors in my code, and I'm > wondering if there's a simple way to catch them. > > One error was of the form: > >  my_object.some_function() > > .. when I hadn't declared an object named "my_object". > > The o

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

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 12:30, sajuptpm wrote: > Hi, > > I want to log time taken to complete database requests inside a method/ > function using decorator .  is it possible > I think, i have to inject log code inside the method/fuctions or > modify it. > I wrote a decorator to log taken by a met

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
On 8 February 2012 01:48, Lei Cheng wrote: > Hi all, > >    In a py file, when to use import statements in the header, when to use > import statements in the blocks where they are used? >    What are the best practices? >    Thanks! Aside from other answers: in some rare cases, importing within a

Re: multiple namespaces within a single module?

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 00:05, Ethan Furman wrote: > Ethan Furman wrote: >> >> Hrm -- and functions/classes/etc would have to refer to each other that >> way as well inside the namespace... not sure I'm in love with that... > > > > Not sure I hate it, either.  ;) > > Slightly more sophisticated code:

Re: Read-only attribute in module

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 03:27, Terry Reedy wrote: > On 2/9/2012 8:04 PM, Steven D'Aprano wrote: > >> Python happily violates "consenting adults" all over the place. We have >> properties, which can easily create read-only and write-once attributes. > > > So propose that propery() work at module level,

Re: round down to nearest number

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 06:21, Ian Kelly wrote: > (3219 + 99) // 100 * 100 >> 3300 > (3289 + 99) // 100 * 100 >> 3300 > (328678 + 99) // 100 * 100 >> 328700 > (328 + 99) // 100 * 100 >> 400 >> >> Those are all rounded up to the nearest 100 correctly. > > One thing to be aware of though

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

2012-02-09 Thread Arnaud Delobelle
On 9 February 2012 14:00, Laurent Claessens wrote: > >> Here is my question: I would like to start an in-house library of small >> modules to import, for things like error handling/logging. That's easy >> enough, but is there a recommended way of naming such modules? I am >> concerned about avoidi

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: iterating over list with one mising value

2012-02-07 Thread Arnaud Delobelle
On 7 February 2012 20:23, Sammy Danso wrote: > > Hi Expert, > Thanks for your responses and help. thought I should provide more information > for clarity. Please don't top-post. > Please find the error message below for more information > >    for (key, value) in wordFreq2: > ValueError: need m

Re: Common LISP-style closures with Python

2012-02-04 Thread Arnaud Delobelle
On 4 February 2012 10:14, Antti J Ylikoski wrote: > On 4.2.2012 4:47, Chris Rebert wrote: >> Out of curiosity, what would be non-Common-Lisp-style closures? >> >> Cheers, >> Chris > > > I understand that a "closure" is something which is typical of functional > programming languages.  -- Scheme-st

Re: Generator problem: parent class not seen

2012-02-01 Thread Arnaud Delobelle
On Feb 1, 2012 9:01 PM, "Russell E. Owen" wrote: > > I have an odd and very intermittent problem in Python script. > Occasionally it fails with this error: > > Traceback (most recent call last): > File > "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas > eFocusScript.py",

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: 'class' named tuple

2012-01-31 Thread Arnaud Delobelle
On 1 February 2012 00:54, Emmanuel Mayssat wrote: > I have the following program. > I am trying to have index the attributes of an object using __getitem__. > Reading them this way works great, but assigning them a value doesn't > Is there a way to do such a thing? > (Almost like a named tuple, bu

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Arnaud Delobelle
On 1 February 2012 03:16, Paulo da Silva wrote: > Em 01-02-2012 01:39, Paulo da Silva escreveu: >> Hi! >> >> What is the best way to iterate thru a huge list having the 1st element >> a different process? I.e.: >> >> process1(mylist[0]) >> for el in mylist[1:]: >>       process2(el) >> >> This way

  1   2   3   4   5   6   7   8   9   10   >