Re: Insert comma in number?

2013-03-07 Thread John Posner
Peter Otten wrote: > Last not least there's the option to employ locale-aware formatting: Not quite last ... there's the mind-bending regular expression route: import re re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "12345678") # 12,345,678 re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "-54321")

Re: Re: PyQt QCalendarWidget events question

2012-07-16 Thread John Posner
On 7/16/2012 12:28 PM, tinn...@isbd.co.uk wrote: > tinn...@isbd.co.uk wrote: >> I am trying to use the PyQt4 calendar widget to perform some different >> actions on specific dates. There are three events available:- >> >> selectionChanged() >> activated(QDate) >> clicked(QDate) >> >> O

Re: Re: Python Gotcha's?

2012-04-05 Thread John Posner
On 4/4/2012 7:32 PM, Chris Angelico wrote: > Don't know if it's what's meant on that page by the += operator, Yes, it is. >> a=([1],) >> a[0].append(2) # This is fine [In the following, I use the term "name" rather loosely.] The append() method attempts to modify the object whose name is "a[0]"

Re: Formate a number with commas

2012-02-09 Thread John Posner
On 2:59 PM, noydb wrote: > How do you format a number to print with commas? I would readily admit that both the "locale" module and "format" method are preferable to this regular expression, which certainly violates the "readability counts" dictum: r"(?<=\d)(?=(\d\d\d)+$)" # python 2.6.6 imp

Re: Re: what is the difference between @property and method

2012-02-09 Thread John Posner
On 2:59 PM, Devin Jeanpierre wrote: > It is kind of funny that the docs don't ever explicitly say what a > property is. http://docs.python.org/library/functions.html#property -- > Devin Here's a writeup that does: http://wiki.python.org/moin/AlternativeDescriptionOfProperty -John -- http://m

Re: calling a simple PyQt application more than once

2012-01-29 Thread John Posner
Jabba Laci wrote: > Hi, Thanks for your reply. I forgot to mention that my first solution > created a headless browser, i.e. it didn't create any GUI. I would > like to keep it that way, thus I could scrape (AJAX-powered) webpages > in batch mode without any user interaction. No head, no problem.

Re: calling a simple PyQt application more than once

2012-01-27 Thread John Posner
Jabba Laci wrote: > Hi, > > I have a simple PyQt application that creates a webkit instance to > scrape AJAX web pages. It works well but I can't call it twice. I > think the application is not closed correctly, that's why the 2nd call > fails. Here is the code below. I also put it on pastebin: > h

Re: all() is slow?

2011-11-08 Thread John Posner
On 2:59 PM, Chris Angelico wrote: >>> So really, it's not "all() is slow" but "function calls are slow". >>> Maybe it'd be worthwhile making an all-factory: >> PLEASE say you're joking. If I saw code like that on any of our project, >> this would definitely qualify for a DailyWTF. > For the benefi

Re: testing if a list contains a sublist

2011-08-16 Thread John Posner
On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would req

Re: testing if a list contains a sublist

2011-08-16 Thread John Posner
On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would req

Re: how to separate a list into two lists?

2011-08-06 Thread John Posner
On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such > that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop

Re: how to separate a list into two lists?

2011-08-06 Thread John Posner
On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such > that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop

Re: Tkinter/py2exe with installer

2011-07-25 Thread John Posner
On 2:59 PM, Kevin Walzer wrote: > Can anyone point me in the direction of a Tkinter/Python app that has > been wrapped with py2exe and is deployed on Windows as a standalone > using one of the standard installer tools? (MSI, NSIS, Inno Setup, > etc.) I'm working on a Tkinter app for Windows and hav

Re: Tkinter/py2exe with installer

2011-07-25 Thread John Posner
On 2:59 PM, Kevin Walzer wrote: > Can anyone point me in the direction of a Tkinter/Python app that has > been wrapped with py2exe and is deployed on Windows as a standalone > using one of the standard installer tools? (MSI, NSIS, Inno Setup, > etc.) I'm working on a Tkinter app for Windows and hav

Re: Property setter and lambda question

2011-07-11 Thread John Posner
On 2:59 PM, Anthony Kong wrote: > So the question: is it possible to use lambda expression at all for > the setter? (As in the last, commented-out line) > > Python interpreter will throw an exception right there if I use the > last line ('SyntaxError: lambda cannot contain assignment'). I'd use >

Re: Using decorators with argument in Python

2011-07-01 Thread John Posner
On 2:59 PM, Ethan Furman wrote: > def __call__(self, func=None): > if func is None: > return self._call() > self.func = func > return self > def _call(self): > print("\n" + self.char * 50) > self.func() > print(self.char * 50 +

Re: Using decorators with argument in Python

2011-06-29 Thread John Posner
On 2:59 PM, Lie Ryan wrote: >> Can any of you guys explain me advantages and disadvantages of >> using each of them > Simplicity is one, using @decor() means you have at least three-level > nested functions, which means the code is likely to be very huge and > perhaps unnecessarily. Bruce Eckel po

Re: Dynamic Zero Padding.

2011-06-07 Thread John Posner
Friedrich: >> I would be much obliged if someone can give me some tips on how to >> achieve a variably pad a number. > :) > > ('%%0%dd' % (pads,)) % (n,) > > Probably be good to wrap it in a function. It looks kind of obscure as it > is. You might want to try "new style" string formatting [1]

Re: Lambda question

2011-06-05 Thread John Posner
On 2:59 PM, Ian Kelly wrote: > On Sat, Jun 4, 2011 at 12:09 PM, Chris Angelico wrote: >> Python doesn't seem to have an inbuilt function to divide strings in >> this way. At least, I can't find it (except the special case where n >> is 1, which is simply 'list(string)'). Pike allows you to use the

Re: How best to convert a string "list" to a python list

2011-05-13 Thread John Posner
On 5/13/2011 3:38 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, No big deal that you weren't aware of the split() method for strings. Sin

Re: Py2exe problem with pyqt+matplotlib

2011-03-15 Thread John Posner
On 2:59 PM, Massi wrote: > I everyone, > > I'm trying to write a setup file for py2exe (0.6.9) to convert my > script into a windows (on win 7) executable. In my script (python2.6) > I use PyQt and matplotlib. Here is the setup.py file: > ImportError: No module named Tkinter > > Obviously Tkinter

Question on Django and Django Book

2010-11-13 Thread John Posner
I've started working, as a tech writer, for a Spanish software configuration management company. And I'm investigating the idea of releasing a user manual in the form of a wiki that supports paragraph-by-paragraph commenting. I looked at Django Book [1][2], but it's not clear to me how much of

Re: Dictionary of lists strange behaviour

2010-11-09 Thread John Posner
On 11/9/2010 1:43 PM, Terry Reedy wrote: ... List *is* useful as an initializer for collecitons.defaultdicts. And it was useful when several members of this forum helped me to develop a prime-number generator. See http://www.mail-archive.com/python-list@python.org/msg288128.html. (I meant t

Re: Why "flat is better than nested"?

2010-11-09 Thread John Posner
On 11/9/2010 3:44 PM, Gregory Ewing wrote: I don’t get it. I get it. Does that mean that I don't get it? Yes. As Dr. Feynman said about quantum mechanics. -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread John Posner
On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: It's clear but tedious to write: if 'monday" in days_off or "tuesday" in days_off: doSomething I currently am tending to write: if any([d for d in ['monday', 'tuesday'] if d in days_off]): doSomething Is there a better pythonic

Re: overriding a property

2010-10-20 Thread John Posner
On 10/20/2010 9:59 AM, Lucasm wrote: Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? Take a look at http://docs.python.org/reference/datamodel.html#descriptors The last paragraph of Sec

Re: overriding a property

2010-10-19 Thread John Posner
On 10/19/2010 9:39 AM, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. Is this the sort of thing

Re: processing input from multiple files

2010-10-15 Thread John Posner
On 10/15/2010 6:59 AM, Christopher Steele wrote: Thanks, The issue with the times is now sorted, however I'm running into a problem towards the end of the script: File "sortoutsynop2.py", line 131, in newline = message_type+c+str(station_id)+c+newtime+c+lat+c+lon+c+c+"-"+c+ "002"

Re: processing input from multiple files

2010-10-14 Thread John Posner
On 10/14/2010 10:44 AM, Christopher Steele wrote: The issue is that I need to be able to both, split the names of the files so that I can extract the relevant times, and open each individual file and process each line individually. Once I have achieved this I need to append the sorted files ont

Re: processing input from multiple files

2010-10-14 Thread John Posner
On 10/14/2010 6:08 AM, Christopher Steele wrote: Hi I've been trying to decode a series of observations from multiple files (each file is a different time) and put each type of observation into their own separate file. The script runs successfully for one file but whenever I try it for more they

Re: Class-level variables - a scoping issue

2010-10-11 Thread John Posner
On 10/10/2010 7:02 PM, Steven D'Aprano wrote: On Sun, 10 Oct 2010 18:14:33 -0400, John Posner wrote: Class attributes are often used as "class constants", so how about naming them with UPPERCASE names, like other constants? When you choose to override one of these const

Re: Class-level variables - a scoping issue

2010-10-10 Thread John Posner
eal(3) meal.Report()# "This meal includes 3 eggs." meal = SpamMeal() meal.EGGS = 4 meal.Report() # "This meal includes 4 eggs." # -John Posner -- http://mail.python.org/mailman/listinfo/python-list

Re: feature request: string.contains('...')

2010-09-24 Thread John Posner
On 9/24/2010 2:45 PM, Tim Chase wrote: On 09/24/10 13:01, Ethan Furman wrote: John Posner wrote: Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abcde') False I'm not aw

Re: feature request: string.contains('...')

2010-09-24 Thread John Posner
On 9/24/2010 4:21 AM, Peter Otten wrote: If you are not interested in the position of the substr use the "in" operator: if substr in s: print "found" else: print "not found" Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abc

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-18 Thread John Posner
On 8/18/2010 1:38 PM, cbr...@cbrownsystems.com wrote: To go the other way, if d = 1, then there exists integers (not neccessarily positive) such that a*x + b*y + c*z = 1 That fact is non-trivial, although the proof isn't *too* hard [1]. I found it interesting to demonstrate the simpler cas

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-16 Thread John Posner
On 8/16/2010 4:18 PM, Baba wrote: packages=[2,103,105] min_size=min(packages[0],packages[1],packages[2]) or: min_size = min(packages) -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Opposite of split

2010-08-16 Thread John Posner
On 8/16/2010 12:44 PM, Alex van der Spek wrote: Anybody catches any other ways to improve my program (attached), you are most welcome. 1. You don't need to separate out special characters (TABs, NEWLINEs, etc.) in a string. So: bt='-999.25'+'\t''-999.25'+'\t''-999.25'+'\t''-999.25'+'\t'+'

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-15 Thread John Posner
On 8/15/2010 11:38 AM, Baba wrote: In addition to the points that Emile and Ian made ... def diophantine_nuggets(x,y,z): cbc=0 #cbc=can_buy counter packages =[x,y,z] You can take advantage of a nifty "syntax convenience feature" here. Instead of loading all of the function's argumen

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-14 Thread John Posner
On 8/14/2010 10:52 AM, Baba wrote: for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[]

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-13 Thread John Posner
On 8/13/2010 6:25 AM, Roald de Vries wrote: On Aug 12, 2010, at 10:51 PM, John Posner wrote: On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force tgt = 120 # thanks, Dave Angel Anytime, but I'm not Dave

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread John Posner
On 8/12/2010 6:31 PM, News123 wrote: candidate_box_counts = product( xrange(target/box_sizes[0] + 1), xrange(target/box_sizes[1] + 1), xrange(target/box_sizes[2] + 1), ) Couldn't this be rewritten as: candidate_box_counts = product( * [ xrange

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread John Posner
On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force Dept of overkill, iterators/generators division ... -John #-- from itertools import imap, product, ifilter from operator import mul box_sizes =

Re: default behavior

2010-08-06 Thread John Posner
On 8/6/2010 6:24 PM, Wolfram Hinderer wrote: This is probably nitpicking, but the patch calls __missing__ a special method. However, unlike special methods, it is not invoked by "special syntax" but by the dict's __getitem__ method. (len() invokes __len__ on any object - you can't do something s

Re: default behavior

2010-08-06 Thread John Posner
On 8/2/2010 11:00 PM, John Posner wrote: On 7/31/2010 1:31 PM, John Posner wrote: Caveat -- there's another description of defaultdict here: http://docs.python.org/library/collections.html#collections.defaultdict ... and it's bogus. This other description claims that __missing__ i

Re: A useful, but painful, one-liner to edit money amounts

2010-08-05 Thread John Posner
On 8/5/2010 12:36 PM, MRAB wrote: You don't need to reverse the string: def thous_format(integer_string): """ add comma thousands separator(s) to an integer-valued string """ return re.sub(r"(?<=\d)(?=(?:\d\d\d)+$)", ",", integer_string) Nice! My first encounter with a look-behind

Re: A useful, but painful, one-liner to edit money amounts

2010-08-05 Thread John Posner
On 8/5/2010 12:33 AM, John Nagle wrote: There's got to be a better way to do this: def editmoney(n) : return((",".join(reduce(lambda lst, item : (lst + [item]) if item else lst, re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1]) Here's a more elegant variant, using regexp lookahead: def thous_

Re: default behavior

2010-08-03 Thread John Posner
On 8/3/2010 6:48 PM, Ethan Furman wrote: Christian Heimes wrote: I just went and read the entry that had the bogus claim -- personally, I didn't see any confusion. I would like to point out the __missing__ is *not* part of dicts (tested on 2.5 and 2.6 -- don't have 2.7 installed yet). I beg yo

Re: default behavior

2010-08-03 Thread John Posner
On 8/3/2010 5:47 PM, Christian Heimes wrote: So I'd rather not mention __missing__ in the first paragraph, which describes the functionality provided *by* the defaultdict class. How about adding this para at the end: defaultdict is defined using functionality that is available to *any* sub

Re: default behavior

2010-08-03 Thread John Posner
On 8/3/2010 12:54 PM, Ethan Furman wrote: I think mentioning how __missing__ plays into all this would be helpful. Perhaps in the first paragraph, after the colon: if a key does not currently exist in a defaultdict object, __missing__ will be called with that key, which in turn will call a "d

Re: default behavior

2010-08-02 Thread John Posner
On 7/31/2010 1:31 PM, John Posner wrote: Caveat -- there's another description of defaultdict here: http://docs.python.org/library/collections.html#collections.defaultdict ... and it's bogus. This other description claims that __missing__ is a method of defaultdict, not of dict.

Re: default behavior

2010-08-01 Thread John Posner
On 7/31/2010 2:00 PM, Christian Heimes wrote: Your answer is confusing even me. ;) Yeah, I get that a lot. :-) Let me try an easier to understand explanation. defaultdict *implements* __missing__() to provide the default dict behavior. In my experience, the word *implements* is commonly u

Re: default behavior

2010-07-31 Thread John Posner
On 7/31/2010 11:08 AM, Christian Heimes wrote: ... All you have to do is subclass dict and implement a __missing__ method. See http://docs.python.org/library/stdtypes.html?highlight=__missing__#mapping-types-dict Caveat -- there's another description of defaultdict here: http://docs.python.

Re: Easy questions from a python beginner

2010-07-14 Thread John Posner
On 7/14/2010 12:06 PM, Ethan Furman wrote: ... Have you tried this? --> def foo(): ... print locals() ... blah = 'interesting' ... print locals() ... --> foo() {} {'blah': 'interesting'} As can be clearly seen, blah does not exist before the assignment -- the *name* blah has not been *bound* t

Re: drag & drop in a python GUI application

2010-07-03 Thread John Posner
On 7/2/2010 11:20 AM, Michael Torrie wrote: On 07/01/2010 08:57 AM, Alan wrote: I know drag& drop is not possible with TK. Is this a Python Tk limitation or a Tk limitation in general? Google suggests that Tk itself supports some form of dnd. Which widget could I use for my python applicat

Re: Infinite prime number generator

2010-06-29 Thread John Posner
On 6/29/2010 12:51 PM, Thomas Jollans wrote: def rprimes(): def elim_mult(n): yield n for p in filter((lambda x:x%n != 0), elim_mult(n+1)): yield p yield 1 for p in elim_mult(2): yield p Thomas, take a look at the thread "Generators/iterators, Pythonicity, an

Re: Minor annoyances with properties

2010-05-27 Thread John Posner
On 5/27/2010 9:14 AM, Neil Cerutti wrote: On 2010-05-27, eb303 wrote: I've been using Python properties quite a lot lately and I've found a few things that are a bit annoying about them in some cases. I wondered if I missed something or if anybody else has this kind of problems too, and if ther

Re: function that counts...

2010-05-19 Thread John Posner
On 5/19/2010 5:51 PM, Steven D'Aprano wrote: On Wed, 19 May 2010 21:58:04 +0200, superpollo wrote: Rather than iterating over an index j = 0, 1, 2, ... and then fetching the jth character of the string, you can iterate over the characters directly. So the inner loop is better written: for c in

Re: how to cause a request for a missing class attribute cause its calculation

2010-05-19 Thread John Posner
On 5/18/2010 4:54 PM, Chris Rebert wrote: Suggested reading: http://docs.python.org/library/functions.html#property I've placed a revision to this official *property* documentation at: http://wiki.python.org/moin/AlternativeDescriptionOfProperty There's also a gentle (I hope) intro to t

Re: setting variables in pdb

2010-05-18 Thread John Posner
On 5/18/2010 4:15 PM, Art wrote: If I am in Pdb, I would like to set a temporary variable, for example: (Pdb) r = 1 The 'r' gets interpreted as 'return' by Pdb. Is there a Pdb instruction that guarantees the intended effect, like: (Pdb) let r = 1 I can usually avoid using such variable names

Re: How to automate accessor definition?

2010-03-22 Thread John Posner
On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote: Another (better IMHO) solution is to use a plain property, and store the computed value as an implementation attribute : @property def foo(self): cached = self.__dict__.get('_foo_cache') if cached is None: self._foo_cache = cached = self._some

Re: Method / Functions - What are the differences?

2010-03-21 Thread John Posner
On 3/21/2010 5:34 PM, Aahz wrote: In article, John Posner wrote: Bruno (and anyone else interested) -- As I promised/threatened, here's the *start* of a write-up on properties, aimed at non-advanced Python programmers: http://www.jjposner.net/media/python-properties-0310.pdf

Re: Method / Functions - What are the differences?

2010-03-18 Thread John Posner
On 3/10/2010 8:37 PM, Gabriel Genellina wrote: En Wed, 10 Mar 2010 11:45:38 -0300, John Posner escribió: As I promised/threatened, here's the *start* of a write-up on properties, aimed at non-advanced Python programmers: http://www.jjposner.net/media/python-properties-0310.pdf I&

Re: pivot() equivalent

2010-03-11 Thread John Posner
On 3/11/2010 6:16 PM, gundlach wrote: I *know* this already exists, but I can't remember where: def pivot(func, seq): # I know, a good implementation shouldn't call func() twice per item return ( (x for x in seq if func(x)), (x for x in seq if not func(x)) ) I feel like I read a thread in

Re: Method / Functions - What are the differences?

2010-03-10 Thread John Posner
[ cross-posting to edu-sig ] Bruno (and anyone else interested) -- As I promised/threatened, here's the *start* of a write-up on properties, aimed at non-advanced Python programmers: http://www.jjposner.net/media/python-properties-0310.pdf I'm interested in corrections, of course. But I'm

Re: imported var not being updated

2010-03-09 Thread John Posner
On 3/9/2010 9:48 AM, Bruno Desthuilliers wrote: John Posner a écrit : On 3/8/2010 11:55 PM, Gary Herron wrote: The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. What you can do, is not m

Re: imported var not being updated

2010-03-09 Thread John Posner
On 3/8/2010 11:55 PM, Gary Herron wrote: The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like

Re: related lists mean value

2010-03-08 Thread John Posner
On 3/8/2010 9:43 PM, John Posner wrote: On 3/8/2010 9:39 PM, John Posner wrote: obj.id = y[i] <--- statement redundant, remove it Sorry for the thrashing! It's more correct to say that the Tally class doesn't require an "id" attribute at all. So the code bec

Re: related lists mean value

2010-03-08 Thread John Posner
On 3/8/2010 9:39 PM, John Posner wrote: # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.id = y[i] <--- statement redundant, remove it obj.total += x[i] obj.count += 1 -John -- http://mail.python.org/mailman/listinfo/pyt

Re: related lists mean value

2010-03-08 Thread John Posner
On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] I have looke

Re: a simple def how-to

2010-03-07 Thread John Posner
On 3/7/2010 10:59 AM, vsoler wrote: Thank you for your help. Perhaps the solution you are suggesting is not exactly what I was looking for, but helped anyway. Oops, I was thinking list, not dict. Too fast, and not enough coffee! -John -- http://mail.python.org/mailman/listinfo/python-list

Re: a simple def how-to

2010-03-07 Thread John Posner
On 3/7/2010 10:05 AM, vsoler wrote: Hello, My script starts like this: book=readFromExcelRange('book') house=readFromExcelRange('house') table=readFromExcelRange('table') read=readFromExcelRange('read') ... But I would like to have something equivalent, like... ranges=['book','house','table',

Re: Method / Functions - What are the differences?

2010-03-05 Thread John Posner
On 3/5/2010 7:15 AM, Bruno Desthuilliers wrote: John Posner a écrit : On 3/3/2010 6:56 PM, John Posner wrote: ... I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll

Re: Method / Functions - What are the differences?

2010-03-04 Thread John Posner
On 3/3/2010 6:56 PM, John Posner wrote: ... I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll try to produce something over the next couple of days. Starting t

Re: Method / Functions - What are the differences?

2010-03-04 Thread John Posner
On 3/4/2010 5:59 AM, Bruno Desthuilliers wrote: I have two small ideas for improvement: - Swap the first two paragraphs. First say what it is, and then give the motivation. Mmm... As far as I'm concerned, I like it the way its. John ? I think it doesn't make very much difference. But in the

Re: Method / Functions - What are the differences?

2010-03-03 Thread John Posner
On 3/3/2010 6:33 PM, Eike Welk wrote: I have two small ideas for improvement: - Swap the first two paragraphs. First say what it is, and then give the motivation. No problem -- since this is a Wiki, you can perform the swap yourself! (If you haven't done it in a day or so, I'll do the deed.)

Re: Method / Functions - What are the differences?

2010-03-03 Thread John Posner
On 3/3/2010 10:48 AM, Bruno Desthuilliers wrote: I spotted this: http://www.python.org/doc/faq/programming/#what-is-a-method http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls Our text is probably a bit too long for a direct inclusion in t

Re: Method / Functions - What are the differences?

2010-03-03 Thread John Posner
On 3/3/2010 9:58 AM, John Posner wrote: Film at 11, John Done -- see http://wiki.python.org/moin/FromFunctionToMethod -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Method / Functions - What are the differences?

2010-03-03 Thread John Posner
On 3/3/2010 5:56 AM, Bruno Desthuilliers wrote: Eike Welk a écrit : John Posner wrote: I've updated the text at this location: > http://cl1p.net/bruno_0301.rst/ I think this is a very useful writeup! It would be perfect with a little bit of introduction that says: 1. - What it

Re: Adding to a module's __dict__?

2010-03-02 Thread John Posner
On 3/2/2010 10:19 AM, Roy Smith wrote: Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing the data out of that. Sigh. Here's an

Re: Method / Functions - What are the differences?

2010-03-02 Thread John Posner
thod object: in the call method, it should inject self.im_self as first arg, not self.im_func. This had been spotted by someone named John Posner, IIRC !-) Fixed (oops!). I've updated the text at this location: > http://cl1p.net/bruno_0301.rst/ I think the ball is back in your court,

Re: Method / Functions - What are the differences?

2010-03-01 Thread John Posner
On 3/1/2010 2:59 PM, Bruno Desthuilliers wrote: Answer here: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 I really have to put this in the wiki :-/ Bruno, I performed a light copy-edit of your writeup and put i

Re: Variable definition

2010-03-01 Thread John Posner
On 3/1/2010 1:07 PM, Raphael Mayoraz wrote: John Posner wrote: On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green':

Re: Variable definition

2010-02-26 Thread John Posner
On 2/26/2010 10:20 PM, Steven D'Aprano wrote: On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red

Re: Variable definition

2010-02-26 Thread John Posner
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value No trick, just swap a new ke

Re: loop through each line in a text file

2010-02-26 Thread John Posner
On 2/26/2010 4:21 PM, qtrimble wrote: fileIN = open(r"C:\testing.txt", "r") for line in fileIN: year = line[3:7] day = line[7:10] print year, day This is good since i can get the year and day of year into a variable but I haven't gotten any further. That's an excellent start.

Re: Docstrings considered too complicated

2010-02-24 Thread John Posner
On 2/24/2010 4:54 PM, Jonathan Gardner wrote: On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger wrote: Hi all, a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: """Function that does stuff""

Re: Noob raw_input question

2010-02-24 Thread John Posner
On 2/24/2010 12:39 PM, Abigail wrote: Yesterday I downloaded and installed Python 3.1 and working through some examples but I have hit a problem a = raw_input("Enter a number" ) Traceback (most recent call last): File "", line 1, in a = raw_input("Enter a number" ) NameError: name 'raw

Re: How to make an empty generator?

2010-02-24 Thread John Posner
generator An iterator produced by a generator function or a generator expression. -John +1. Can someone submit a documentation patch, please? Will do. -John [sorry if this is a dup] Done: #8012 "Revise generator-related Glossary entries" -John -- http://mail.python.org/mailman/listinfo/

Re: How to make an empty generator?

2010-02-24 Thread John Posner
On 2/24/2010 9:07 AM, Steve Holden wrote: John Posner wrote: Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms to Terry's definitions above in most places. But the Glossary says: generator A function which returns an iterator.<... more ...>

Re: Signature-based Function Overloading in Python

2010-02-23 Thread John Posner
On 2/23/2010 1:25 PM, Michael Rudolf wrote: Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceback (most recent call last): File "", lin

Re: Efficiently building ordered dict

2010-02-22 Thread John Posner
On 2/22/2010 4:29 PM, Bryan wrote: Sorry about the sorted != ordered mix up. I want to end up with a *sorted* dict from an unordered list. *Sorting the list is not practical in this case.* I am using python 2.5, with an ActiveState recipe for an OrderedDict. Have you looked at this: htt

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-19 Thread John Posner
On 2/19/2010 3:02 PM, MRAB wrote: Is this any better? def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] for row in reader: if '[MASKS]' in row: break data.append(row) As noted in another thread recently, you

Re: How to make an empty generator?

2010-02-19 Thread John Posner
On 2/19/2010 2:25 PM, Terry Reedy wrote: On 2/19/2010 12:44 PM, Stephen Hansen wrote: Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here retu

Re: Why this doesn't work?

2010-02-18 Thread John Posner
On 2/18/2010 12:28 PM, mk wrote: Sorry to bother everyone again, but I have this problem bugging me: #!/usr/bin/python -i class Foo(object): def nostat(self,val): print val nostat.__orig_get__ = nostat.__get__ @staticmethod def nostatget(*args, **kwargs): print 'args:', args, 'kwargs:', kwa

Re: Referring to class methods in class attributes

2010-02-17 Thread John Posner
On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. Very nice writeup, Bruno -- thanks! class method(ob

Re: Traversing through variable-sized lists

2010-02-17 Thread John Posner
On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: Hi, I couldn't figure out a better description for the Subject line, but anyway, I have the following: _num_frames = 32 _frames = range(0, _num_frames) # This is a list of actual objects, I'm just pseudocoding here. _values = [0, 1, 2, 3, 4] I want

Re: Modifying Class Object

2010-02-15 Thread John Posner
On 2/15/2010 6:09 PM, Steven D'Aprano wrote: On Mon, 15 Feb 2010 21:25:23 +, Arnaud Delobelle wrote: John Posner writes: [...] x = s[0] [...] assigns the name *x* to the object that *s[0]* refers to s[0] does not refer to an object, it *is* an object (once evaluated of c

Re: Modifying Class Object

2010-02-15 Thread John Posner
Alf said (2/13/2010 8:34 PM): Names in Python refer to objects. Those references can be copied via assignment. That's (almost) all. And it provides a very short and neat way to describe pass by sharing. Alf also said (2/13/2010 8:43 PM): * Steve Howell: > This thread is interesting on man

Re: Executing a command from within python using the subprocess module

2010-02-15 Thread John Posner
On 2/15/2010 7:35 AM, R (Chandra) Chandrasekhar wrote: Dear Folks, I want to execute a command from within python using the subprocess module. Coming from a Perl background, I thought I could use variable interpolation in strings, but found that this is neither supported Yes, it is: see the u

Re: Please help with MemoryError

2010-02-12 Thread John Posner
On 2/12/2010 12:14 PM, Steven D'Aprano wrote: On Fri, 12 Feb 2010 06:45:31 -0800, Jeremy wrote: You also confirmed what I thought was true that all variables are passed "by reference" so I don't need to worry about the data being copied (unless I do that explicitly). No, but yes. No, variabl

  1   2   3   >