RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread avi.e.gross
sibly non-pythonic topic and go read another book or a few hundred so when it comes up again ... -Original Message- From: Python-list On Behalf Of Thomas Passin Sent: Saturday, March 4, 2023 5:04 PM To: python-list@python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Weatherby,Gerard
Nope. No consensus. I’d use self.__class__ . Seems more explicit and direct to me. From: Python-list on behalf of Ian Pilcher Date: Thursday, March 2, 2023 at 4:17 PM To: python-list@python.org Subject: Which more Pythonic - self.__class__ or type(self)? *** Attention: This is an external

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Thomas Passin
y, March 4, 2023 1:09 PM To: python-list@python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 3/4/2023 2:47 AM, Peter J. Holzer wrote: Even before Python existed there was the adage "a real programmer can write FORTRAN in any language", indicating that idiomatic

RE: RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread avi.e.gross
it becomes an exotic addition to Python in a way that loosely melds, or if it becomes the PYTHONIC way ... -Original Message- From: Alan Gauld Sent: Saturday, March 4, 2023 1:38 PM To: avi.e.gr...@gmail.com; python-list@python.org Subject: Re: RE: Which more Pythonic - self.__class__ or

RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread avi.e.gross
native language(s). I am sure some books along these lines have already been written! Who wants to collaborate? -Original Message- From: Python-list On Behalf Of dn via Python-list Sent: Saturday, March 4, 2023 1:26 PM To: python-list@python.org Subject: Re: Which more Pythonic - self

RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread avi.e.gross
and found an expanding language with way too many ways to do anything and can choose. But I claim that too is pythonic! -Original Message- From: Python-list On Behalf Of Thomas Passin Sent: Saturday, March 4, 2023 1:09 PM To: python-list@python.org Subject: Re: Which more Pythonic - self.__class

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Peter J. Holzer
On 2023-03-04 12:38:22 -0500, avi.e.gr...@gmail.com wrote: > Of course each language has commonly used idioms as C with pointer > arithmetic and code like *p++=*q++ but my point is that although I live near > a seaway and from where C originated, I am not aware of words like "c-way" > or "scenic"

Re: RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Alan Gauld
On 04/03/2023 17:38, avi.e.gr...@gmail.com wrote: > > Of course each language has commonly used idioms > That's the point, the correct term is probably "idiomatic" rather than "pythonic" but it is a defacto standard that idiomatic Python has become known as Pythonic. I don't think that's a

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread dn via Python-list
On 04/03/2023 20.47, Peter J. Holzer wrote: On 2023-03-03 13:51:11 -0500, avi.e.gr...@gmail.com wrote: ... No. Even before Python existed there was the adage "a real programmer can write FORTRAN in any language", indicating that idiomatic usage of a language is not governed by syntax and

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Thomas Passin
On 3/4/2023 2:47 AM, Peter J. Holzer wrote: Even before Python existed there was the adage "a real programmer can write FORTRAN in any language", indicating that idiomatic usage of a language is not governed by syntax and library alone, but there is a cultural element: People writing code in a

RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread avi.e.gross
python-list@python.org Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 2023-03-03 13:51:11 -0500, avi.e.gr...@gmail.com wrote: > I do not buy into any concept about something being pythonic or not. > > Python has grown too vast and innovated quite a bit, but als

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Peter J. Holzer
On 2023-03-03 13:51:11 -0500, avi.e.gr...@gmail.com wrote: > I do not buy into any concept about something being pythonic or not. > > Python has grown too vast and innovated quite a bit, but also borrowed from > others and vice versa. > > There generally is no universally pythonic way nor

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Greg Ewing via Python-list
On 4/03/23 7:51 am, avi.e.gr...@gmail.com wrote: I leave you with the question of the day. Was Voldemort pythonic? Well, he was fluent in Parseltongue, which is not a good sign. I hope not, otherwise we'll have to rename Python to "The Language That Shall Not Be Named" and watch out for

RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread avi.e.gross
you should not care about efficiency! LOL! I leave you with the question of the day. Was Voldemort pythonic? Avi -Original Message- From: Python-list On Behalf Of Alan Gauld Sent: Friday, March 3, 2023 4:43 AM To: python-list@python.org Subject: Re: Which more Pythonic - self.__class__

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Ethan Furman
On 3/3/23 03:32, Chris Angelico wrote: > On Fri, 3 Mar 2023 at 20:44, Alan Gauld wrote: >> On 02/03/2023 20:54, Ian Pilcher wrote: >>> Seems like an FAQ, and I've found a few things on StackOverflow that >>> discuss the technical differences in edge cases, but I haven't found >>> anything that

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Chris Angelico
On Fri, 3 Mar 2023 at 20:44, Alan Gauld wrote: > > On 02/03/2023 20:54, Ian Pilcher wrote: > > Seems like an FAQ, and I've found a few things on StackOverflow that > > discuss the technical differences in edge cases, but I haven't found > > anything that talks about which form is considered to be

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Alan Gauld
On 02/03/2023 20:54, Ian Pilcher wrote: > Seems like an FAQ, and I've found a few things on StackOverflow that > discuss the technical differences in edge cases, but I haven't found > anything that talks about which form is considered to be more Pythonic > in those situations where there's no

RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-02 Thread avi.e.gross
Subject: Re: Which more Pythonic - self.__class__ or type(self)? On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote: > On 3/03/23 9:54 am, Ian Pilcher wrote: >> I haven't found >> anything that talks about which form is considered to be more Pythonic >> in those situations where

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-02 Thread Thomas Passin
On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote: On 3/03/23 9:54 am, Ian Pilcher wrote: I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional difference. In such cases I'd probably go for type(x), because

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-02 Thread Greg Ewing via Python-list
On 3/03/23 9:54 am, Ian Pilcher wrote: I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional difference. In such cases I'd probably go for type(x), because it looks less ugly. x.__class__ *might* be slightly more

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-02 Thread Thomas Passin
On 3/2/2023 3:54 PM, Ian Pilcher wrote: Seems like an FAQ, and I've found a few things on StackOverflow that discuss the technical differences in edge cases, but I haven't found anything that talks about which form is considered to be more Pythonic in those situations where there's no functional

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
Chris Angelico : > On Thu, Nov 24, 2016 at 10:14 PM, Marko Rauhamaa wrote: >> When you use threads, you call read(2) in the blocking mode. Then the >> read(2) operation will block "for ever." There's no clean way to >> cancel the system call. > > Signals will

Re: Is this pythonic?

2016-11-24 Thread Chris Angelico
On Thu, Nov 24, 2016 at 10:14 PM, Marko Rauhamaa wrote: > When you use threads, you call read(2) in the blocking mode. Then the > read(2) operation will block "for ever." There's no clean way to cancel > the system call. Signals will usually interrupt system calls, causing them

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
Chris Angelico : > On Thu, Nov 24, 2016 at 9:59 PM, Marko Rauhamaa wrote: >> Chris Angelico : >>> A coroutine can be abandoned at an await point, but the >>> currently-executed call is still going to complete (usually); >> >> I don't quite

Re: Is this pythonic?

2016-11-24 Thread Chris Angelico
On Thu, Nov 24, 2016 at 9:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote: >>> * Coroutines can be killed, threads cannot. >> >> Not strictly true. A coroutine can be abandoned at an

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
Chris Angelico : > On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote: >> * Coroutines can be killed, threads cannot. > > Not strictly true. A coroutine can be abandoned at an await point, but > the currently-executed call is still going to complete

Re: Is this pythonic?

2016-11-24 Thread Chris Angelico
On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote: > * Coroutines can be killed, threads cannot. > Not strictly true. A coroutine can be abandoned at an await point, but the currently-executed call is still going to complete (usually); a thread can be killed, but certain

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
"Frank Millman" : > "Steven D'Aprano" wrote in message > news:58368358$0$1513$c3e8da3$54964...@news.astraweb.com... >> I'm a newbie to asyncio, but if I were doing this using threads, [...] > > To me, the beauty of asyncio (or I suppose async in general) is that I > don't

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Steven D'Aprano" wrote in message news:58368358$0$1513$c3e8da3$54964...@news.astraweb.com... On Thursday 24 November 2016 15:55, Frank Millman wrote: > "Steve D'Aprano" wrote in message > news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com... > >> Even if the computation of the

Re: Is this pythonic?

2016-11-23 Thread Steven D'Aprano
On Thursday 24 November 2016 15:55, Frank Millman wrote: > "Steve D'Aprano" wrote in message > news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com... > >> Even if the computation of the memoised value is done asynchronously, you >> can easily split the computation off to a separate method

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Steve D'Aprano" wrote in message news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com... Even if the computation of the memoised value is done asynchronously, you can easily split the computation off to a separate method (as you already talked about doing!) and make getval() block until

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
On Wed, 23 Nov 2016 10:11 pm, Frank Millman wrote: > Gah! The law of unintended consequences strikes again! > > As I mentioned, the class in question represents a database column. Yes, you mentioned that. > A > separate class represents a database row. I have a __str__() method on the >

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
On Wed, 23 Nov 2016 11:27 pm, Frank Millman wrote: > It is a bit like quantum theory. I have no way of telling whether the > computation has been carried out without looking at it, but the act of > looking at it triggers the computation. I can tell, of course, by looking > at the underlying

Re: Is this pythonic?

2016-11-23 Thread Gregory Ewing
Frank Millman wrote: For the time being I will use 'print(await obj.__str__())', as this is a good compromise. It seems more like a very *bad* compromise to me. I can't see how this gains you anything over just doing print(await obj.getvalue()), and you lose the ability to do anything that

Re: Is this pythonic?

2016-11-23 Thread Tim Chase
On 2016-11-23 22:15, Steve D'Aprano wrote: > On Wed, 23 Nov 2016 08:10 pm, Frank Millman wrote: > > The class has a getval() method to return the current value. > > > > Usually the value is stored in the instance, and can be returned > > immediately, but sometimes it has to be computed, incurring

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Chris Angelico" wrote in message news:CAPTjJmqGEwHPVyrR+Ti9bV=S5MsLt3nquF4TvE=xpees188...@mail.gmail.com... On Wed, Nov 23, 2016 at 11:27 PM, Frank Millman wrote: > > @Chris >> >> This strongly suggests that str(x) is the wrong way to get the >> information. You

Re: Is this pythonic?

2016-11-23 Thread Chris Angelico
On Wed, Nov 23, 2016 at 11:27 PM, Frank Millman wrote: > > @Chris >> >> This strongly suggests that str(x) is the wrong way to get the >> information. You shouldn't be doing database requests inside __str__ >> or __repr__. > > > I guess you are right, but still it is a pity.

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Frank Millman" wrote in message news:o13meh$p2g$1...@blaine.gmane.org... 3. When instantiating an object, check if it would need computation - if computation_required: self.getval = self._getval_with_comp else: self.getval = self._getval 4. In _getval_with_comp,

Re: Is this pythonic?

2016-11-23 Thread Peter Otten
Frank Millman wrote: > Hi all > > Sometimes I write something that I think is quite clever, but later on I > look at it and ask 'What was I thinking?'. > > I have just come up with a 'clever' solution to a problem. Would this > cause raised eyebrows if you were reviewing this? > > I have a

Re: Is this pythonic?

2016-11-23 Thread Chris Angelico
On Wed, Nov 23, 2016 at 10:11 PM, Frank Millman wrote: > Gah! The law of unintended consequences strikes again! > > As I mentioned, the class in question represents a database column. A > separate class represents a database row. I have a __str__() method on the > 'row' class

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
On Wed, 23 Nov 2016 08:10 pm, Frank Millman wrote: [...] > The class has a getval() method to return the current value. > > Usually the value is stored in the instance, and can be returned > immediately, but sometimes it has to be computed, incurring further > database lookups. This is called

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Marko Rauhamaa" wrote in message news:87inrer0dl@elektro.pacujo.net... "Frank Millman" : > 3. When instantiating an object, check if it would need computation - >if computation_required: >self.getval = self._getval_with_comp >else: >self.getval

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Marko Rauhamaa" wrote in message news:87inrer0dl@elektro.pacujo.net... "Frank Millman" : > What is the verdict? -1, 0, or +1? Perfectly cromulent, run-of-the-mill Python code. A new word to add to my vocabulary - thanks :-) Frank --

Re: Is this pythonic?

2016-11-23 Thread Marko Rauhamaa
"Frank Millman" : > 3. When instantiating an object, check if it would need computation - >if computation_required: >self.getval = self._getval_with_comp >else: >self.getval = self._getval > > 4. In _getval_with_comp, perform the computation, then add

Re: Creating A Pythonic API Binding

2016-06-08 Thread Steven D'Aprano
On Wednesday 08 June 2016 12:31, Lawrence D’Oliveiro wrote: > The wrong way: [...] > The right way : That's quite good. A few minor issues: I don't understand why you have a method that returns files called "get_children". And I would expect that if you passed a

Re: to be pythonic: should caller or callee log?

2013-09-06 Thread Gildor Oronar
El 04/09/13 20:14, Xaxa Urtiz escribió: and what about something like that : class AbsctractAccount(): def transaction(self, amount, target): logging.info(Start transaction of %s to %s % (amount, target)) self.DoTransaction(amount,target) def

Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Gildor Oronar
El 04/09/13 10:26, Ethan Furman escribió: I would say it is not really the caller's or the callee's job to do the logging, even though it should be done. What would be really handy is a function that sat in between the caller and callee that logged for you -- you know, a decorator: Thanks a

Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Gildor Oronar
Thanks: El 04/09/13 05:01, Terry Reedy escribió: I would expect that every account class has a transaction method. * If so, just call it, but assertIsNot(DebitAccount.transaction, AbstractAccount.transaction) for every subclass in your test suite. * If not, perhaps you need an abstract

Re: to be pythonic: should caller or callee log?

2013-09-04 Thread Xaxa Urtiz
Le mercredi 4 septembre 2013 09:44:27 UTC+2, Gildor Oronar a écrit : Thanks: El 04/09/13 05:01, Terry Reedy escribió: I would expect that every account class has a transaction method. * If so, just call it, but assertIsNot(DebitAccount.transaction,

Re: to be pythonic: should caller or callee log?

2013-09-03 Thread Terry Reedy
On 9/3/2013 12:07 PM, Gildor Oronar wrote: What would you choose? Do you put logging routine into caller or callee? My intuitive answer is callee does the logging, because that's where action takes place, like this: class Account(): def transaction(self, amount, target):

Re: to be pythonic: should caller or callee log?

2013-09-03 Thread Ethan Furman
On 09/03/2013 09:07 AM, Gildor Oronar wrote: What would you choose? Do you put logging routine into caller or callee? My intuitive answer is callee does the logging, because that's where action takes place, like this: class Account(): def transaction(self, amount, target):

Re: Designing a Pythonic search DSL for SQL and NoSQL databases

2013-07-19 Thread Roy Smith
In article mailman.4864.1374236715.3114.python-l...@python.org, Alec Taylor alec.tayl...@gmail.com wrote: Dear Python community, I am analysing designing an abstraction layer over a select few NoSQL and SQL databases. Specifically: - Redis, Neo4j, MongoDB, CouchDB - PostgreSQL This

Re: Designing a Pythonic search DSL for SQL and NoSQL databases

2013-07-19 Thread Alec Taylor
Hmm, looking at the capabilities of Redis; you're likely right. Would welcome discussion on the implementability and usefulness of a central search abstraction to the other stores mentioned. One thing could be that using the paradigm the database was made for is better than any advantages

Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Terry Reedy
On 5/24/2010 12:56 PM, Nathan Rice wrote: I'm trying to do some fairly deep introspection and instrumentation of instances and classes at runtime, and in order for everything to be properly behaved I need to have radically different behavior in the event that the thing passed to me is a wrapped

Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Duncan Booth
Terry Reedy tjre...@udel.edu wrote: Builtin classes, named or not, do not have dotted names 1 .__class__ class 'int' class C: pass I believe all others do, including C-coded extension classes. C().__class__ class '__main__.C' Not quite all. Classes created by calling the type

Re: Most reliable/pythonic way to tell if an instance comes from a class implemented in C/etc?

2010-05-24 Thread Carl Banks
[Following up to Terry Reedy's post since I don't see the original] On May 24, 11:30 am, Terry Reedy tjre...@udel.edu wrote: On 5/24/2010 12:56 PM, Nathan Rice wrote: I'm trying to do some fairly deep introspection and instrumentation of instances and classes at runtime, and in order for

Re: [ANN] regobj - Pythonic object-based access to the Windows Registry

2009-05-04 Thread Glenn Linderman
On approximately 5/3/2009 7:35 AM, came the following characters from the keyboard of Ryan Kelly: Hi All, I've just released the results of a nice Sunday's coding, inspired by one too many turns at futzing around with the _winreg module. The regobj module brings a convenient and clean

Re: [ANN] regobj - Pythonic object-based access to the Windows Registry

2009-05-04 Thread Ryan Kelly
I've just released the results of a nice Sunday's coding, inspired by one too many turns at futzing around with the _winreg module. The regobj module brings a convenient and clean object-based API for accessing the Windows Registry. Sounds very interesting, Ryan. Just a couple

Re: Definition of Pythonic?

2009-04-19 Thread Lawrence D'Oliveiro
In message 49e30ac0$0$6828$5fc3...@news.tiscali.it, Francesco Bochicchio wrote: Which is pretty sensible, since good engineering is often based more on choosing the right trade-off rather than choosing the One Right Thing to do. Yes, but remember that, too, is a tradeoff. Moderation is fine,

Re: Definition of Pythonic?

2009-04-13 Thread Francesco Bochicchio
John Yeung ha scritto: On Apr 11, 10:08 am, Emmanuel Surleau emmanuel.surl...@gmail.com wrote: Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. A couple of others have already mentioned the Zen of Python, available

Re: Definition of Pythonic?

2009-04-12 Thread Lawrence D'Oliveiro
Pythonic--an acid, capable of reacting with bases to form pythanates? Would it be an organic or inorganic acid? Deprive it of a bit of oxygen, and it becomes pythonous, reacting to form pythonites. What do you mean, the fume cupboard's broken down? Honestly I feel fine... --

Re: Recommendations on Pythonic tree data structure design techniques

2009-04-12 Thread Gabriel Genellina
En Thu, 09 Apr 2009 13:18:27 -0300, pyt...@bdurham.com escribió: Any recommendations on Python based tree data structures that I can study? I'm working on an application that will model a basic outline structure (simple tree) and am looking for ideas on Pythonic implementation techniques. I'd

Re: Definition of Pythonic?

2009-04-12 Thread Gabriel Genellina
En Sun, 12 Apr 2009 08:16:19 -0300, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand escribió: Pythonic--an acid, capable of reacting with bases to form pythanates? Would it be an organic or inorganic acid? Deprive it of a bit of oxygen, and it becomes pythonous, reacting to form

Re: Definition of Pythonic?

2009-04-11 Thread Tim Chase
Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. Judging from Python, it seems to exclude (mostly) magical variables like '$.'. Is this right? What else would you include in this definition? At the python

Re: Definition of Pythonic?

2009-04-11 Thread skip
Emm Having written a few trivial scripts in Python, I'm curious as to Emm how you would sum up the Pythonic philosophy of development. Try import this at your friendly, neighborhood Python prompt. -- Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/ XML sucks,

Re: Definition of Pythonic?

2009-04-11 Thread Aahz
In article mailman.3700.1239458914.11746.python-l...@python.org, Emmanuel Surleau emmanuel.surl...@gmail.com wrote: Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. Judging from Python, it seems to exclude (mostly)

Re: Definition of Pythonic?

2009-04-11 Thread John Yeung
On Apr 11, 10:08 am, Emmanuel Surleau emmanuel.surl...@gmail.com wrote: Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. A couple of others have already mentioned the Zen of Python, available at the Python command

Re: Definition of Pythonic?

2009-04-11 Thread MRAB
John Yeung wrote: On Apr 11, 10:08 am, Emmanuel Surleau emmanuel.surl...@gmail.com wrote: Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. A couple of others have already mentioned the Zen of Python, available at

Re: Definition of Pythonic?

2009-04-11 Thread Emmanuel Surleau
On Saturday 11 April 2009 18:00:58 John Yeung wrote: On Apr 11, 10:08 am, Emmanuel Surleau emmanuel.surl...@gmail.com wrote: Having written a few trivial scripts in Python, I'm curious as to how you would sum up the Pythonic philosophy of development. A couple of others have already

Re: Definition of Pythonic?

2009-04-11 Thread Mark Wooding
John Yeung gallium.arsen...@gmail.com writes: A couple of others have already mentioned the Zen of Python, available at the Python command prompt. I would agree with that, but also add the caveat that none of the principles expressed there are hard-and- fast rules. Indeed, I'd suggest that

Re: Recommendations on Pythonic tree data structure design techniques

2009-04-09 Thread Daniel Fetchinson
Any recommendations on Python based tree data structures that I can study? I'm working on an application that will model a basic outline structure (simple tree) and am looking for ideas on Pythonic implementation techniques. By outline I mean a traditional hierarchical document outline

Re: Recommendations on Pythonic tree data structure design techniques

2009-04-09 Thread CTO
I'm writing a Python graph library (called Graphine) that's pretty easy to use and does what you want. It is pre-alpha right now, but if you're interested please let me know- I'm very interested in hearing outside opinions. -- http://mail.python.org/mailman/listinfo/python-list

Re: Recommendations on Pythonic tree data structure design techniques

2009-04-09 Thread andrew cooke
pyt...@bdurham.com wrote: Any recommendations on Python based tree data structures that I can study? I'm working on an application that will model a basic outline structure (simple tree) and am looking for ideas on Pythonic implementation techniques. By outline I mean a traditional

Re: Is this pythonic?

2009-01-27 Thread Baby Coder
On 18 déc 2008, 13:51, Jason Scheirer jason.schei...@gmail.com wrote: I'd say it's fine but breaking up the statement once or twice is a good idea just because if one of the function calls in this nested thing throws an exception, a smaller statement with fewer calls makes for a far more

Re: is this pythonic?

2009-01-22 Thread Peter Otten
TP wrote: Hi, Is the following code pythonic: l=[{title:to, value:2},{title:ti,value:coucou}] dict = [ dict for dict in l if dict['title']=='ti'] l.remove(*dict) l [{'title': 'to', 'value': 2}] Precision: I have stored data in the list of dictionaries l, because in my application I

Re: is this pythonic?

2009-01-22 Thread TP
Peter Otten wrote: If you can change the rest of your program to work smoothly with a dictionary I would suggest the following: [snip] from collections import defaultdict [snip] Thanks a lot. I didn't know defaultdict. It is powerful. I begin to understand that people prefer using

Re: is this pythonic?

2009-01-22 Thread pruebauno
On Jan 21, 4:23 pm, Scott David Daniels scott.dani...@acm.org wrote: prueba...@latinmail.com wrote: ... If you have duplicates this will not work. You will have to do something like this instead: o=[] i=0 ln=len(l) while iln:    if l[i]['title']=='ti':            

Re: is this pythonic?

2009-01-22 Thread pruebauno
On Jan 21, 4:23 pm, Scott David Daniels scott.dani...@acm.org wrote: prueba...@latinmail.com wrote: ... If you have duplicates this will not work. You will have to do something like this instead: o=[] i=0 ln=len(l) while iln:    if l[i]['title']=='ti':            

Re: is this pythonic?

2009-01-21 Thread Peter Pearson
On Wed, 21 Jan 2009 16:16:32 +0100, TP wrote: Is the following code pythonic: l=[{title:to, value:2},{title:ti,value:coucou}] dict = [ dict for dict in l if dict['title']=='ti'] l.remove(*dict) l [{'title': 'to', 'value': 2}] Precision: I have stored data in the list of dictionaries l,

Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 1:16 am, TP tribulati...@paralleles.invalid wrote: Is the following code pythonic: l=[{title:to, value:2},{title:ti,value:coucou}] dict = [ dict for dict in l if dict['title']=='ti'] l.remove(*dict) l [{'title': 'to', 'value': 2}] Try not to use 'dict' or the name of any of

Re: is this pythonic?

2009-01-21 Thread MRAB
alex23 wrote: On Jan 22, 1:16 am, TP tribulati...@paralleles.invalid wrote: Is the following code pythonic: l=[{title:to, value:2},{title:ti,value:coucou}] dict = [ dict for dict in l if dict['title']=='ti'] l.remove(*dict) l [{'title': 'to', 'value': 2}] Try not to use 'dict' or the name

Re: is this pythonic?

2009-01-21 Thread TP
alex23 wrote: Try not to use 'dict' or the name of any of the other built-in types as labels. Ops... Moreover I know it... You're stepping through an entire list just to pass another list to l.remove to step through and remove items from...in fact, given that list.remove deletes the

Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:27 am, MRAB goo...@mrabarnett.plus.com wrote: FYI, you shouldn't modify a list you're iterating over. But I'm not. I'm building a new list and binding it to the same name as the original, which works perfectly fine (unless I'm missing something): l = range(100) l = [d for d in l

Re: is this pythonic?

2009-01-21 Thread MRAB
alex23 wrote: On Jan 22, 3:27 am, MRAB goo...@mrabarnett.plus.com wrote: FYI, you shouldn't modify a list you're iterating over. But I'm not. I'm building a new list and binding it to the same name as the original, which works perfectly fine (unless I'm missing something): [snip] I was

Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:34 am, TP tribulati...@paralleles.invalid wrote:     for index, record in enumerate(l):         if record['title'] == 'ti':             l.pop(index) Ok, I will use this solution. But it is less pythonic than list comprehensions. Are you asking if it's less pythonic, or

Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:56 am, MRAB goo...@mrabarnett.plus.com wrote: I was referring to the code:      for index, record in enumerate(l):          if record['title'] == 'ti':              l.pop(index) where you are enumerating and iterating over 'l', but also modifying 'l' with 'l.pop(index)'. Ack,

Re: is this pythonic?

2009-01-21 Thread pruebauno
On Jan 21, 12:34 pm, TP tribulati...@paralleles.invalid wrote: alex23 wrote: Try not to use 'dict' or the name of any of the other built-in types So my list is rather: l=[{title:to, color:blue, value:2} {title:ti, color:red, value:coucou}] So, I will rather use your solution: for index,

Re: is this pythonic?

2009-01-21 Thread Scott David Daniels
prueba...@latinmail.com wrote: ... If you have duplicates this will not work. You will have to do something like this instead: o=[] i=0 ln=len(l) while iln: if l[i]['title']=='ti': o.append(l.pop(i)) ln-=1 else: i+=1 Or the

Re: Is this pythonic?

2008-12-18 Thread Bruno Desthuilliers
ipyt...@gmail.com a écrit : x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? functional programming addicts might say yes. But as far as I'm concerned, I find it a bit too nested... --

Re: Is this pythonic?

2008-12-18 Thread Laszlo Nagy
ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? You should try LISP. :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this pythonic?

2008-12-18 Thread pruebauno
On Dec 18, 11:08 am, ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? Lisp and Scheme programmers love that style. You can tell by the number of parentheses :-). In Python people

Re: Is this pythonic?

2008-12-18 Thread Jason Scheirer
On Dec 18, 8:45 am, prueba...@latinmail.com wrote: On Dec 18, 11:08 am, ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? Lisp and Scheme programmers love that style. You

Re: Is this pythonic?

2008-12-18 Thread Russ P.
On Dec 18, 8:08 am, ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? I hope you're kidding. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this pythonic?

2008-12-18 Thread Hendrik van Rooyen
Bruno Desthuilliers bru.@websiteburo.invalid wrote: ipyt...@gmail.com a écrit : x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? functional programming addicts might say yes. But as far as I'm

Re: A more pythonic way of writting

2008-12-05 Thread Mark Tolonen
eric [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False, UNICODE=False, VERBOSE=False): vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE] filtered = map( lambda m:m[1],filter( lambda m: m[0],

Re: A more pythonic way of writting

2008-12-05 Thread Gerard flanagan
eric wrote: Hi, I've got this two pieces of code that works together, and fine def testit(): for vals in [[imask==mask for mask in [1j for j in range(6)] ] for i in range(16)]: print vals, '-', flag(*vals) def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False,

Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 5, 3:44 pm, Mark Tolonen [EMAIL PROTECTED] wrote: eric [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False, UNICODE=False, VERBOSE=False):    vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE,

Re: A more pythonic way of writting

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote: I like to believe that the less the 'debug pointer' stands in the python code, the fastest the code is (or is potentially) What's a debug pointer? Pre-mature optimization is the root of evil in programming. Unless you have actually *measured*

Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 6, 12:19 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote: I like to believe that the less the 'debug pointer' stands in the python code, the fastest the code is (or is potentially) What's a debug pointer? Pre-mature

Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-05 Thread Terry Reedy
Marco Bizzarri wrote: I understand that Python is a balance between different forces (like any software object around the world) and I'm simply asking some pointers to the discussion leading to this balance. The original decisions by Guido were nearly 20 years ago and other discussions are

  1   2   >