Re: List Problem

2012-09-23 Thread Steven D'Aprano
On Sun, 23 Sep 2012 14:31:48 -0700, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, Then you aren't making a copy. py> first_list = [1, 2, 3] py> second_list = first_list # THIS IS NOT A COPY py> second_list.append() py> print

Editing Inkscape SVG files with Python?

2012-09-23 Thread Steven D'Aprano
I have some SVG files generated with Inkscape containing many text blocks (over 100). I wish to programmatically modify those text blocks using Python. Is there a library I should be using, or any other guidelines or advice anyone can give me? Googling for "python inkscape" comes up with too ma

Re: For Counter Variable

2012-09-23 Thread Steven D'Aprano
On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >> Am I missing something obvious, or do I have to manually put in a >> counter in the for loops? That's a very basic request, but I couldn't >> find anything in the documentatio

Re: Java singletonMap in Python

2012-09-23 Thread Steven D'Aprano
On Mon, 24 Sep 2012 00:14:23 +0100, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web > for both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was > wondering how to c

Re: which a is used?

2012-09-24 Thread Steven D'Aprano
On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote: > Dear All, > > I have a simple code as follows: > > # Begin > a = 1 > > def f(): > print a > > def g(): > a = 20 > f() > > g() > #End > > I think the results should be 20, but it is 1. Would you please tell me > why? You are exp

Re: python file API

2012-09-24 Thread Steven D'Aprano
On Tue, 25 Sep 2012 08:14:01 +1000, Chris Angelico wrote: > Presumably the same way you reference a list element relative to > end-of-list: negative numbers. However, this starts to feel like magic > rather than attribute assignment - it's like manipulating the DOM in > JavaScript, you set an attr

Re: python file API

2012-09-24 Thread Steven D'Aprano
On Mon, 24 Sep 2012 15:36:20 -0700, zipher wrote: > You raise a valid point: that by abstracting the file pointer into a > position attribute you risk "de-coupling" the conceptual link between > the underlying file and your abstraction in the python interpreter I don't think this argument holds w

Re: keeping information about players around

2012-09-24 Thread Steven D'Aprano
On Tue, 25 Sep 2012 08:19:34 +1000, Chris Angelico wrote: > On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto > wrote: >> Also, If this is a browser app I'd go with phpmyadmin, and MySQL >> >> If a tkinter/wxpython/etc app, then maybe sqlite. > > Out of curiosity, why? MySQL isn't magically better f

Re: python file API

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:25:48 +0200, Thomas Rachel wrote: > Am 25.09.2012 04:28 schrieb Steven D'Aprano: > >> By the way, the implementation of this is probably trivial in Python >> 2.x. Untested: >> >> class MyFile(file): >> @property >>

Re: For Counter Variable

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:53:55 +0200, Thomas Rachel wrote: > When learning Python, it often happend me to re-inven the wheel. But as > soon as I saw the presence of something I re-wrote, I skipped my > re-written version and used the built-in. And me. Not just Python either. The very first piece o

Re: Who's laughing at my responses, and who's not?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 00:43:18 -0400, Dwight Hutto wrote: > It sounds pretentious, but over the past several days, I've been slammed > on every post almost. That's a gross exaggeration. Over the last few days you have gotten slammed because you mildly broke etiquette and then, instead of accepti

Re: For Counter Variable

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 11:16:40 +0100, Mark Lawrence wrote: > On 25/09/2012 10:53, Chris Rebert wrote: > > [snip] > >> Well, the PSU might, except they emphatically do not exist... > > I know that they exist You are delusional. The PSU certainly do not exist and it is a myth that they -- ht

Re: data attributes override method attributes?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 06:41:43 -0700, Jayden wrote: > Dear All, > > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name." > > But in my testing as follows: > > #Begin > class A: > i = 10 > def i(): > pr

Re: gracious responses

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 12:54:05 +0100, Mark Lawrence wrote: > Well thank goodness for that. Of course the person to whom you've > alluded has been defended over on the tutor mailing list, seriously, and > as I've said elsewhere after referring to my family as pigs!!! Since pigs are at least as inte

Re: Article on the future of Python

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 09:26:19 -0400, Kevin Walzer wrote: > On 9/25/12 4:15 AM, Mark Lawrence wrote: >> Hi all, >> >> I though this might be of interest. >> >> http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- >> python >> >> > Interesting article, but the comments of those who sa

Re: new-style class or old-style class?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote: > In learning Python, I found there are two types of classes? Which one > are widely used in new Python code? New-style classes. > Is the new-style much better than old-style? Yes. Always use new-style classes, unless you have some specific re

Re: Article on the future of Python

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 18:25:30 +, Grant Edwards wrote: > On 2012-09-25, Martin P. Hellwig wrote: >> On Tuesday, 25 September 2012 09:14:27 UTC+1, Mark Lawrence wrote: >>> Hi all, >>> >>> I though this might be of interest. >>> http://www.ironfroggy.com/software/i-am-worried-about-the-future-o

Re: Article on the future of Python

2012-09-26 Thread Steven D'Aprano
On Tue, 25 Sep 2012 23:35:39 -0700, wxjmfauth wrote: > Py 3.3 succeeded to somehow kill unicode and it has been transformed > into an "American" product for "American" users. For the first time in Python's history, Python on 32-bit systems handles strings containing Supplementary Multilingual Pl

Re: Article on the future of Python

2012-09-26 Thread Steven D'Aprano
On Wed, 26 Sep 2012 09:30:19 -0400, Kevin Walzer wrote: > On 9/25/12 11:35 AM, Steven D'Aprano wrote: >> IronPython in C#. Jython is written in Java. CLPython is written in >> Lisp. Berp and HoPe are written in Haskell. Nuitka is written in C++. >> Skulpt is writt

Re: Article on the future of Python

2012-09-26 Thread Steven D'Aprano
On Wed, 26 Sep 2012 10:01:11 +0100, Mark Lawrence wrote: > You remind me of the opening to the song Plaistow Patricia by Ian Dury > and the Blockheads. While I always appreciate a good reference to Ian Dury, please stop feeding D.H.'s ego by responding to his taunts. -- Steven -- http://mail

Re: Python 3.3 and .pyo files

2012-09-26 Thread Steven D'Aprano
On Fri, 21 Sep 2012 11:10:07 +0200, Marco wrote: > I was trying to import a pyo module in Python 3.3, but Python does not > find it: [...] Marco, this bug is apparently now fixed: http://bugs.python.org/issue16046 Please download the latest version of Python 3.3 and try again. (Folks, this is

Re: Article on the future of Python

2012-09-26 Thread Steven D'Aprano
On Thu, 27 Sep 2012 15:37:35 +1000, Chris Angelico wrote: > On Thu, Sep 27, 2012 at 10:44 AM, Steven D'Aprano > wrote: >> While PyPy is still a work in progress, and is not anywhere near as >> mature as (say) gcc or clang, it should be considered production-ready. > &

#python archives?

2012-09-26 Thread Steven D'Aprano
My google-foo is failing me. Is the #python chatroom on freenode archived anywhere on the web? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Article on the future of Python

2012-09-26 Thread Steven D'Aprano
On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: > Hi all, > > I though this might be of interest. > > http://www.ironfroggy.com/software/i-am-worried-about-the-future-of- python And a response: http://data.geek.nz/python-is-doing-just-fine -- Steven -- http://mail.python.org/mai

Re: Article on the future of Python

2012-09-27 Thread Steven D'Aprano
On Wed, 26 Sep 2012 08:45:30 -0700, wxjmfauth wrote: > Sorry guys, I'm "only" able to see this (with the Python versions an end > user can download): [snip timeit results] While you have been all doom and gloom and negativity that Python has "destroyed" Unicode, I've actually done some testing.

Re: Module baldy compiled to pyc?

2012-09-27 Thread Steven D'Aprano
On Thu, 27 Sep 2012 11:00:36 +0200, Laszlo Nagy wrote: > Today I had a strange experience. I have copied some updated py files > (modules) to a directory on a remote server, overwritting the old ones. > The pyc files on the server were older. Many programs are importing > these modules, and most o

Re: Article on the future of Python

2012-09-27 Thread Steven D'Aprano
On Thu, 27 Sep 2012 08:11:13 -0400, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano > wrote: >> On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >> response: >> >> http://data.geek.nz/python-is-doing-just-fine > >

Re: test

2012-09-27 Thread Steven D'Aprano
On Thu, 27 Sep 2012 17:36:57 -0400, Devin Jeanpierre wrote: > On Thu, Sep 27, 2012 at 5:28 PM, ForeverYoung wrote: >> Please ignore this post. >> I am testing to see if I can post successfully. > > Is there a reason you can't wait until you have something to say / ask > to see if it works? You'r

Re: Article on the future of Python

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 05:08:24 -0700, rusi wrote: > On Sep 27, 5:11 pm, Devin Jeanpierre wrote: >> On Thu, Sep 27, 2012 at 2:13 AM, Steven D'Aprano >> >> wrote: >> > On Tue, 25 Sep 2012 09:15:00 +0100, Mark Lawrence wrote: And a >> > response: >>

Re: creating an artificial "last element" in sort list

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 16:39:33 -0700, dave wrote: > a = ['a', 'b', x] > b = sorted(a) > > What does x need to be to always be last on an ascending sort no matter > what 'a' and 'b' are within reason... How about this? a = ['a', 'b'] b = sorted(a) + ['whatever you want'] You could also do thi

Re: Article on the future of Python

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 14:50:14 -0400, Devin Jeanpierre wrote: > I'm pretty sure nobody thinks Python is on a death march. Don't be so sure. There's always *someone* complaining about something, and they're usually convinced that (Language X) is on it's last legs because (feature Y) is missing or

Re: data attributes override method attributes?

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 18:02:04 +, Prasad, Ramit wrote: > Just to make sure I am following, if you call foo.__len__() it goes to > the instance code while if you do len(foo) it will go to > class.__len__()? If you call foo.__len__, the attribute lookup of __len__ will use the exact same search

Re: write a regex matches 800-555-1212, 555-1212, and also (800) 555-1212.

2012-09-28 Thread Steven D'Aprano
On Fri, 28 Sep 2012 21:25:35 -0600, Ian Kelly wrote: > Mine is simpler and faster. > > r = re.compile("") The OP doesn't say that you have to compile it, so just: '' wins. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Steven D'Aprano
On Sat, 29 Sep 2012 06:27:47 -0700, Ramchandra Apte wrote: > Should one always add super().__init__() to the __init__? The reason for > this is the possibility of changing base classes (and forgetting to > update the __init__). No. Only add code that works and that you need. Arbitrarily adding ca

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Steven D'Aprano
On Sat, 29 Sep 2012 20:14:10 -0700, Ramchandra Apte wrote: > I forgot something: > I meant super().__init__() or similar What about it? Please try to remember that we can't read your mind and don't know what you are thinking, we can only work from what you put in writing. There is no differenc

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Steven D'Aprano
On Sun, 30 Sep 2012 04:31:48 +1000, Chris Angelico wrote: > On Sun, Sep 30, 2012 at 3:17 AM, Steven D'Aprano > wrote: >> No. Only add code that works and that you need. Arbitrarily adding >> calls to the superclasses "just in case" may not work: >> &g

Re: Should one always add super().__init__() to the __init__?

2012-09-29 Thread Steven D'Aprano
On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: > It is not necesarily calling the parent class. It calls the initializer > of the next class in the MRO order and what class that is depends on the > actual multiple inheritance structure it is used in, which can depend on > subclasses t

Re: Should one always add super().__init__() to the __init__?

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 00:08:03 -0600, Ian Kelly wrote: > On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano > wrote: >> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote: >> >>> It is not necesarily calling the parent class. It calls the >>> initi

Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote: > Hello! > > I'm still new to Python, so here's another easy one. After I save > something I've done as a .py file, how do I import it into something > else I work on? Every time I try to import something other than turtle > or math, I get

Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote: > Hello! > > I'm still new to Python, so here's another easy one. After I save > something I've done as a .py file, how do I import it into something > else I work on? Every time I try to import something other than turtle > or math, I get

Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:17:17 -0400, Roy Smith wrote: > In article > <4806a0b7-818a-4844-8286-f1b891a3c...@rj6g2000pbc.googlegroups.com>, > rusi wrote: > >> Here's a test to help you decide: How do you respond to the word >> 'magic'? If positive you will like Ruby, if not you may prefer Python.

Re: parse an environment file

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:11:09 -0600, Jason Friedman wrote: > $ crontab -l > * * * * * env > > This produces mail with the following contents: [snip] Yes, env returns the environment variables of the current environment. > On the other hand > > $ env > > produces about 100 entries, most of whi

Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > Thanks for trying to help, everybody. Sorry I didn't post the whole > error message. Now my problem is I just installed VPython and I'm trying > to run the very first example, bounce.py which I located. I opened it > and ran it in Idle. I

Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote: > Since I use Python 3.2.3 I've had trouble with programs and modules > designed for Python 2 and many programs don't work on my 64-bit system. While Python tries very hard to be backward compatible, the transition from the 2.x series to t

Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote: > Since I use Python 3.2.3 I've had trouble with programs and modules > designed for Python 2 and many programs don't work on my 64-bit system. While Python tries very hard to be backward compatible, the transition from the 2.x series to t

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Steven D'Aprano
On Tue, 02 Oct 2012 18:11:20 -0700, 8 Dihedral wrote: > Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: >> Oh, I'm convinced that it's a bot. >> The fact that Dihedral never responds to conversations about him/it is >> a give away: nearly all

Re: unit testing class hierarchies

2012-10-02 Thread Steven D'Aprano
On Wed, 03 Oct 2012 08:30:19 +1000, Ben Finney wrote: > Ulrich Eckhardt writes: > >> I want test_base() to be run as part of both TestD1 and TestD2, because >> it tests basic functions provided by both classes D1 and D2. > > It sounds, from your description so far, that you have identified a >

Re: Combinations of lists

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 16:26:43 +0200, Steen Lysgaard wrote: > Hi, > > I am looking for a clever way to compute all combinations of two lists. > Look at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m

Re: Help me abstract this (and stop me from using eval)

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 09:23:03 -0700, Daniel Klein wrote: > So ideally I would tell the script which language I'm currently > importing and based on that it would write to the appropriate text > fields. But I don't know how to abstract this: > > tempmes.polish = row[1] > > Well, I do. Like this: >

Emulating C++ namespaces with ChainMap and metaclass trickery

2012-10-03 Thread Steven D'Aprano
C++ namespaces are useful for encapsulating related objects within a single file, subdividing the global namespace without using classes. Python has modules, but they come in separate files. Using Python 3.3's ChainMap type, and some metaclass trickery, I abuse the class keyword to (almost) emu

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 18:30:24 -0400, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. [...] > There is either a neighbor, or a null value. I always know the (x,y) > pair to check the

Re: Why is pylaucher in Python 3.3 being installed in Windows folder?

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 14:13:10 -0700, Piotr Dobrogost wrote: > Why is pylauncher in Python 3.3 being installed in Windows folder and > not in Program Files folder? Installing into Windows folder was maybe > acceptable 10 years ago but not now... Read the PEP: http://www.python.org/dev/peps/pep-039

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-03 Thread Steven D'Aprano
On Thu, 04 Oct 2012 01:58:16 +, Steven D'Aprano wrote: > adict: 24712 > alist: 23127324 [...] > So in this situation, a list of lists uses about 100 times > more memory than a dict, but look-ups are about 6% faster. Correction: about 1000 times more memory. Sorry for the ty

Re: Can somebody give me an advice about what to learn?

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 21:47:33 -0700, Chris Rebert wrote: > On Wed, Oct 3, 2012 at 11:31 AM, Wolfgang Keller > wrote: >>> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new >>> programming language, because I learnt a bit of Perl though its OOP is >>> ugly. So, after searching a

Re: final question: logging to stdout and updating files

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 06:34:28 -0700, Ramchandra Apte wrote: > "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- Well, you've just added yourself into my list of people whose advice should always be ignored. That is *terrible* advice. But if you insist on following it, you ca

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote: > On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: >> How do you know that? >> >> No offence, but if you can't even work out whether lookups in a dict or >> a list are faster, I can't imagine why you think you can intuit what >

Re: final question: logging to stdout and updating files

2012-10-04 Thread Steven D'Aprano
On Wed, 03 Oct 2012 21:11:29 -0600, Littlefield, Tyler wrote: > I've seen frameworks like django reload files when it detects that > they've been changed; how hard would it be to make my engine reload > files that it detects were changed? Oh, about as hard as writing a program. What sort of fil

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 18:11:28 +0200, Thomas Rachel wrote: > Am 04.10.2012 03:58 schrieb Steven D'Aprano: >> alist = [[None]*2400 for i in range(2400)] from random import randrange >> for i in range(1000): >> x = randrange(2400) >> y = randrange(2400) &g

Re: instance.attribute lookup

2012-10-05 Thread Steven D'Aprano
On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman wrote: > There is a StackOverflow question [1] that points to this on-line book > [2] which has a five-step sequence for looking up attributes: > > > When retrieving an attribute from an object (print > > objectname.attrname) Python follows these

Re: try/except KeyError vs "if name in ..."

2012-10-06 Thread Steven D'Aprano
On Sat, 06 Oct 2012 08:27:25 +0200, Manuel Pégourié-Gonnard wrote: > Hi, > > I was looking at the example found here [1] which begins with: > > [1] http://docs.python.org/py3k/library/imp.html#examples > > def __import__(name, globals=None, locals=None, fromlist=None): > # Fast path: see if

Re: question on log as an instance method

2012-10-07 Thread Steven D'Aprano
On Sun, 07 Oct 2012 10:33:36 +0200, Franck Ditter wrote: > Question : I may consider + as an hidden instance method , as 1+2 is > equivalent to (1).__add__(2) ? I also consider __abs__ as an instance > method : (-2).__abs__() > 2 The short answer is, yes. The *correct* answer is, not quite

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 02:00:04 +1100, Chris Angelico wrote: > On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel wrote: >> import decimal >> a = decimal.Decimal(4.3) >> print(a) >> >> 5.0996447286321199499070644378662109375 > > Ah, the delights of copy-paste :) > >> The Decimal class has the

Re: Insert item before each element of a list

2012-10-09 Thread Steven D'Aprano
On Mon, 08 Oct 2012 19:34:26 -0700, rusi wrote: > How about a 2-paren version? > x = [1,2,3] reduce(operator.add, [['insert', a] for a in x]) > ['insert', 1, 'insert', 2, 'insert', 3] That works, but all those list additions are going to be slow. It will be an O(N**2) algorithm. If

Re: Creating a dictionary

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote: > below is the text file i have How to create Facility as a key and then > assign multiple values to it To use Facility as a key in a dict: d = {} d['Facility'] = 'ham' Note that keys are case-sensitive, so that 'Facility', 'facility', 'FACILIT

Re: Private methods

2012-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2012 11:08:13 -0600, Ian Kelly wrote: > On Tue, Oct 9, 2012 at 8:08 AM, Demian Brecht > wrote: >> A single underscore semantically means private. A double underscore >> will name mangle the function such that it's only accessible strictly >> by name through the class that it's defi

Re: Private methods

2012-10-10 Thread Steven D'Aprano
On Wed, 10 Oct 2012 18:34:01 -0700, alex23 wrote: > On 10 Oct, 17:03, real-not-anti-spam-addr...@apple-juice.co.uk (D.M. > Procida) wrote: >> It certainly makes it quick to build a class with the attributes I >> need, but it does make tracing logic sometimes a pain in the neck. >> >> I don't know

Re: Is `wsample` a proper name for a function like this?

2012-10-10 Thread Steven D'Aprano
On Wed, 10 Oct 2012 20:33:16 -0700, Satoru Logic wrote: > I came across a function named `wsample` in a `utils` package of my > workplace recently. > > The "w" in `wsample` stands for `weighted`, and it randomly selects an > element from a container according to relative weights of all the > elem

Re: Insert item before each element of a list

2012-10-11 Thread Steven D'Aprano
On Fri, 12 Oct 2012 00:21:57 +0200, Hans Mulder wrote: > On 9/10/12 04:39:28, rusi wrote: >> On Oct 9, 7:34 am, rusi wrote: >>> How about a 2-paren version? >>> >> x = [1,2,3] >> reduce(operator.add, [['insert', a] for a in x]) >>> >>> ['insert', 1, 'insert', 2, 'insert', 3] >> >> Or if

Re: Is `wsample` a proper name for a function like this?

2012-10-11 Thread Steven D'Aprano
On Wed, 10 Oct 2012 23:44:42 -0700, suzaku wrote: > I think if a programmer has used the built-in `random` module before, he > would expect a function with "sample" in its name to return a population > sequence. I have used the random module for about fifteen years, and I still write random.samp

Re: How to use "while" within the command in -c option of python?

2012-10-12 Thread Steven D'Aprano
On Fri, 12 Oct 2012 19:04:20 -0400, Etienne Robillard wrote: > On Fri, 12 Oct 2012 15:51:19 -0700 > Herman wrote: > >> python -c "import os; while True: print('hello')" File "", >> line 1 >> import os; while True: print('hello') >> ^ >> SyntaxError: invalid syntax >> --

readline trick needed

2012-10-13 Thread Steven D'Aprano
I'm working with the readline module, and I'm trying to set a key combination to process the current command line by calling a known function, *and* enter the command line. Something along the lines of: * execute function spam() in some context where it can access the current command line as

Re: Feedback on my python framework I'm building.

2012-10-13 Thread Steven D'Aprano
On Sat, 13 Oct 2012 15:24:04 -0700, nbvfour wrote: > On Saturday, October 13, 2012 2:33:43 PM UTC-4, Chris Angelico wrote: >> >> Nice theory, but this is the bit that I fundamentally disagree with. >> Forcing programmers to work in one particular style is usually not the >> job of the language/fr

Re: Feedback on my python framework I'm building.

2012-10-13 Thread Steven D'Aprano
On Sun, 14 Oct 2012 05:33:40 +1100, Chris Angelico wrote: > Forcing programmers to work in one particular style is usually not the > job of the language/framework/library. Have you actually programmed before? *grin* I've never come across a language/framework/library that DOESN'T force progra

Re: python game develop:framework?

2012-10-14 Thread Steven D'Aprano
On Sun, 14 Oct 2012 01:58:57 -0700, nepaul wrote: > Something good framwork? http://duckduckgo.com/?q=python+%2Bgame+frameworks http://duckduckgo.com/?q=python+%2Bgame+libraries http://blekko.com/ws/?q=python%20game%20framework -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: pyw program not displaying unicode characters properly

2012-10-14 Thread Steven D'Aprano
On Sun, 14 Oct 2012 19:19:33 +0200, Alain Ketterlin wrote: > Usenet has no attachments. *snarfle* You almost owed me a new monitor. I nearly sprayed my breakfast all over it. "Usenet has no attachments" -- that's like saying that the Web has no advertisements. Maybe the websites you visit ha

Re: portable unicode literals

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 15:05:01 +0200, Ulrich Eckhardt wrote: > Hi! > > I need a little nudge in the right direction, as I'm misunderstanding > something concerning string literals in Python 2 and 3. In Python 2.7, > b'' and '' are byte strings, while u'' is a unicode literal. In Python > 3.2, b'' i

Re: how to insert random error in a programming

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 19:25:38 +0530, Debashish Saha wrote: > how to insert random error in a programming? While editing the source code, have your cat walk across the keyboard. I really think you need to explain your question better. -- Steven -- http://mail.python.org/mailman/listinfo/pytho

Re: Exception Messages

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 09:00:15 -0700, Wanderer wrote: > How do you get Exceptions to print messages? I have an exception defined > like this > > class PvCamError(Exception): > def __init__(self, msg): > self.msg = msg Please don't invent yet another interface for exception messages. E

Re: how to insert random error in a programming

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 18:21:55 -0700, alex23 wrote: > On Oct 16, 5:52 am, Chris Angelico wrote: >> Surely there's a shorter way to rot13 a piece of text? CODE GOLF! > > In Python2: "a piece of string".encode('rot13') :) And in Python 3, unfortunately there has been a right-royal mess made of the

Re: [on topic] Re: readline trick needed

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> I'm working with the readline module, and I'm trying to set a key >> combination to process the current command line by calling a known >> function, *and* enter the command

Re: [on topic] Re: readline trick needed

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 13:20:24 +0100, Robert Kern wrote: > On 10/16/12 12:27 PM, Steven D'Aprano wrote: >> Well, I was hoping for a pure Python solution, rather than having to >> troll through who knows how many thousands of lines of code in a >> language I can barely re

Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks: > The best advise is to ignore such posts and encourage others to do the > same. If you ignore such posts, how will the poster know they are unacceptable? How should somebody distinguish between "I am being shunned for actin

Re: OT Questions

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 21:06:24 -0400, David Hutto wrote: > I'm working on toning down the smack talk, I'm just used to a little > witty back and forth with some seriously cruel individuals. Thank you David, that is appreciated. I see that you have changed your signature to match your preferred nam

Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 14:10:17 -0700, rurpy wrote: > On 10/16/2012 10:49 AM, Steven D'Aprano wrote: >> > On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and >> > dicks: > > No, I wrote about trolls. "dicks" is a highly emotive and almost

Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Wed, 17 Oct 2012 02:45:04 +, Steven D'Aprano wrote: > Dwight "call me David, but I can't be bothered changing my signature" > Hutto's behaviour. I withdraw this dig at David Hutto. It was unnecessary, and it turns out, wrong as he has now changed his s

Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 21:25:38 -0700, alex23 wrote: > I really don't get people who feel they need to share their opinion when > that opinion is that other people shouldn't share theirs. +1 QOTW It makes me laugh when newcomers to this group stick their head up to chastise us for arguing about th

Re: OT Questions

2012-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2012 18:05:12 -0400, Dwight Hutto wrote: > On Wed, Oct 17, 2012 at 5:31 AM, Chris Angelico > wrote: >> On Wed, Oct 17, 2012 at 5:27 PM, Dwight Hutto >> wrote: >>> On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht >>> wrote: I can't ascertain what your strengths are as I don't w

Re: Script for finding words of any size that do NOT contain vowels with acute diacritic marks?

2012-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2012 13:16:43 -0400, David Robinow wrote: > On Wed, Oct 17, 2012 at 1:07 PM, Ian Kelly > wrote: >> "return len(w) != len(w_decomposed)" is all you need. > > Thanks for helping, but I already knew that. David, Ian was directly responding to wxjmfa...@gmail.com, whose suggestion i

Re: Aggressive language on python-list

2012-10-17 Thread Steven D'Aprano
On Wed, 17 Oct 2012 14:10:34 -0700, rurpy wrote: > On 10/17/2012 02:28 PM, Oscar Benjamin wrote:> On 17 October 2012 19:16, > Chris Angelico wrote: >>> On Thu, Oct 18, 2012 at 3:48 AM, wrote: >>>>On 10/16/2012 08:45 PM, Steven D'Aprano wrote: >>>&g

Re: Aggressive language on python-list

2012-10-17 Thread Steven D'Aprano
David, While I acknowledge and appreciate your efforts to be less aggressive on this list, I think you have crossed a line by forwarding the contents of an obviously personal email containing CLEARLY PRIVATE MATTERS to a public list without permission, without even anonymising it. Not cool mat

Re: A desperate lunge for on-topic-ness

2012-10-17 Thread Steven D'Aprano
On Thu, 18 Oct 2012 02:06:19 -0400, Zero Piraeus wrote: > What are people's preferred strategies for dealing with lines that go > over 79 characters? A few I can think of off the bat: > > 1. Say "screw it" and go past 79, PEP8 be damned. I've been burnt enough by word-wrapping in editors that do

Re: unittest for system testing

2012-10-18 Thread Steven D'Aprano
Sorry for breaking threading, but the original post has not come through to me. > On 18/10/2012 01:22, Rita wrote: > Hi, > > Currently, I use a shell script to test how my system behaves before I > deploy an application. For instance, I check if fileA, fileB, and fileC > exist and if they do I go

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2012 12:47:48 -0400, Dave Angel wrote: > I never use the backslash at end-of-line to continue a statement to the > next. Not only is it a readability problem, but if your editor doesn't > have visible spaces, you can accidentally have whitespace after the > backslash, and wonder wh

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2012 15:59:18 +0200, Jean-Michel Pichavant wrote: > - Original Message - >> On 2012-10-18, Zero Piraeus wrote: >> >> > What are people's preferred strategies for dealing with lines that go >> > over 79 characters? A few I can think of off the bat: >> >> I try to do what's

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2012 17:36:57 -0400, Zero Piraeus wrote: > The accepted rule in print is that lines of prose should be between 45 > and 90 characters, with 66 being ideal for readability. Code is not > prose, and the combination of fixed-width and much more variable line > length aids readability,

Re: Add if...else... switch to doctest?

2012-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2012 17:08:37 -0700, David wrote: > Hello, how to add if...else... switch to doctest? Step 1): Write your doctest with the switch. Don't forget to test both branches: >>> global_var = True >>> if global_var: ... function() ... else: ... function()

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2012 20:35:20 -0700, rusi wrote: (extracting the text without the ASCII-art) > > “When I get new information, I change my position. What, sir, > > do you do with new information?” —John Maynard Keynes > > “Anyone who believes exponential growth can go on forever in a > > finite wor

Re: section with in a section config file and reading that config file

2012-10-19 Thread Steven D'Aprano
On Fri, 19 Oct 2012 12:09:53 +0200, Tarek Ziadé wrote: > On 10/19/12 11:51 AM, kampy wrote: >> hi all, >> my requirement is to have section with in a section in config >> parameters ex: >> [AAA] >> [BBB] >> a=1 >> b=1 >> [CCC] >> a=1 >> b=2 >> Any one help me in

Re: Python does not take up available physical memory

2012-10-19 Thread Steven D'Aprano
On Fri, 19 Oct 2012 14:04:21 -0500, Pradipto Banerjee wrote: > I have a 32-bit machine. Can I install a 64-bit build even if my PC is > 32-bit? No. Well, you could try, and if the installer did no error checking it might even install the 64-bit exe onto your computer, but it would crash when yo

Re: Python does not take up available physical memory

2012-10-19 Thread Steven D'Aprano
On Fri, 19 Oct 2012 14:03:37 -0500, Pradipto Banerjee wrote: > Thanks, I tried that. Still got MemoryError, but at least this time > python tried to use the physical memory. What I noticed is that before > it gave me the error it used up to 1.5GB (of the 2.23 GB originally > showed as available) -

<    4   5   6   7   8   9   10   11   12   13   >