Re: more pythonic way

2019-02-16 Thread Grant Edwards
On 2019-02-16, Barry wrote: > On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote: > >>> The most pythonic way is to do this: >>> >>> def find_monthly_expenses(month=datetime.date.today().month, >> year=datetime.date.today().year): >>>... > > This has subtle bugs. > The default is calcul

Re: more pythonic way

2019-02-16 Thread Barry
On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote: >> The most pythonic way is to do this: >> >> def find_monthly_expenses(month=datetime.date.today().month, > year=datetime.date.today().year): >>... This has subtle bugs. The default is calculated at import time and not at function

Re: more pythonic way

2019-02-11 Thread Jimmy Girardet
The first one is used very often. Less verbose Le 11 févr. 2019 à 20:41, à 20:41, Felix Lazaro Carbonell a écrit: > > >Hello to everyone: > >Could you please tell me wich way of writing this method is more >pythonic: > > > >.. > >def find_monthly_expenses(month=None, year=None): > >

Re: more pythonic way

2019-02-11 Thread Peter Otten
Felix Lazaro Carbonell wrote: > Hello to everyone: > Could you please tell me wich way of writing this method is more pythonic: > def find_monthly_expenses(month=None, year=None): > > month = month or datetime.date.today() > Or it should better be: > if not month: >

Re: more pythonic way

2019-02-11 Thread Peter Otten
Grant Edwards wrote: > On 2019-02-11, Felix Lazaro Carbonell wrote: > >> Could you please tell me wich way of writing this method is more >> pythonic: >> >> def find_monthly_expenses(month=None, year=None): >> month = month or datetime.date.today() >> >> Or it should better be: >> >>

Re: more pythonic way

2019-02-11 Thread Sivan Grünberg
+1 with David Raymond, it's nice to use condensed style when it leaves things readable and logic. But if in doubt: "Explicit is better than implicit. Simple is better than complex." :) -Sivan On Mon, Feb 11, 2019 at 10:19 PM David Raymond wrote: > My non-expert vote is for > > if month is None

Re: more pythonic way

2019-02-11 Thread Terry Reedy
On 2/11/2019 2:46 PM, Felix Lazaro Carbonell wrote: def find_monthly_expenses(month=None, year=None): month = month or datetime.date.today().month Or it should better be: if not month: month = datetime.date.today().month As a 20+ year veteran, I would be

RE: more pythonic way

2019-02-11 Thread David Raymond
My non-expert vote is for if month is None: month = datetime.date.today().month Because you're checking for your default value, not whether the boolean version of what they did give you is True or False. It's explicit, it's not reliant on any __bool__() function implementations or overrides

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
-Mensaje original- De: Python-list [mailto:python-list-bounces+felix=epepm.cupet...@python.org] En nombre de Grant Edwards Enviado el: lunes, 11 de febrero de 2019 02:46 p.m. Para: python-list@python.org Asunto: Re: more pythonic way On 2019-02-11, Felix Lazaro Carbonell wrote

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
Sorry I meant .. def find_monthly_expenses(month=None, year=None): month = month or datetime.date.today().month .. Or it should better be: ... if not month: month = datetime.date.today().month .. Cheers, Felix. -- https://mail.python.org/mailman

Re: more pythonic way

2019-02-11 Thread Grant Edwards
On 2019-02-11, Felix Lazaro Carbonell wrote: > Could you please tell me wich way of writing this method is more pythonic: > > def find_monthly_expenses(month=None, year=None): > month = month or datetime.date.today() > > Or it should better be: > > if not month: >

Re: More Pythonic implementation

2014-08-19 Thread Ben Finney
Shubham Tomar writes: > Lets say I have a function poker(hands) that takes a list of hands and > returns the highest ranking hand, and another function hand_rank(hand) > that takes hand and return its rank. To make it clearer, I think you mean something like this:: def hand_rank(hand):

Re: More Pythonic implementation

2014-08-19 Thread Chris Kaynor
On Tue, Aug 19, 2014 at 10:09 AM, Shubham Tomar wrote: > Lets say I have a function poker(hands) that takes a list of hands and > returns the highest ranking hand, and another function hand_rank(hand) that > takes hand and return its rank. As in Poker > http://www.pokerstars.com/poker/games/rules

Re: more pythonic

2008-02-29 Thread Paul McGuire
On Feb 29, 5:57 pm, Alan Isaac <[EMAIL PROTECTED]> wrote: > Paul McGuire wrote: > > In general, whenever you have: > >     someNewList = [] > >     for smthg in someSequence: > >         if condition(smthg): > >             someNewList.append( elementDerivedFrom(smthg) ) > > replace it with: > >  

Re: more pythonic

2008-02-29 Thread Alan Isaac
Paul McGuire wrote: > In general, whenever you have: > someNewList = [] > for smthg in someSequence: > if condition(smthg): > someNewList.append( elementDerivedFrom(smthg) ) > replace it with: > someNewList = [ elementDerivedFrom(smthg) >

Re: more pythonic

2008-02-28 Thread Paul McGuire
On Feb 28, 8:58 am, Temoto <[EMAIL PROTECTED]> wrote: > On 28 ÆÅ×, 15:42, Paul McGuire <[EMAIL PROTECTED]> wrote: > > > > > > > On Feb 28, 5:40 am, Temoto <[EMAIL PROTECTED]> wrote: > > > > Hello. > > > > There is a Django application, i need to place all its data into > > > Access mdb file and sen

Re: more pythonic

2008-02-28 Thread Temoto
On 28 фев, 15:42, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Feb 28, 5:40 am, Temoto <[EMAIL PROTECTED]> wrote: > > > > > Hello. > > > There is a Django application, i need to place all its data into > > Access mdb file and send it to user. > > It seems to me that params filling for statement cou

Re: more pythonic

2008-02-28 Thread Paul McGuire
On Feb 28, 5:40 am, Temoto <[EMAIL PROTECTED]> wrote: > Hello. > > There is a Django application, i need to place all its data into > Access mdb file and send it to user. > It seems to me that params filling for statement could be expressed in > a more beautiful way. > Since i'm very new to Python,

Re: more pythonic

2008-02-28 Thread 7stud
On Feb 28, 4:48 am, 7stud <[EMAIL PROTECTED]> wrote: > > It's my understanding that the way you insert arguments into queries > has to be done in a db specific way.   > Rather: It's my understanding that the way you insert arguments into queries *should* be done in a db specific way.   -- http:/

Re: more pythonic

2008-02-28 Thread 7stud
On Feb 28, 4:40 am, Temoto <[EMAIL PROTECTED]> wrote: > Hello. > > There is a Django application, i need to place all its data into > Access mdb file and send it to user. > It seems to me that params filling for statement could be expressed in > a more beautiful way. > Since i'm very new to Python,

Re: More pythonic shell sort?

2006-06-12 Thread John Machin
On 11/06/2006 1:26 PM, [EMAIL PROTECTED] wrote: > Thanks for the critique. > > John Machin wrote: >> On 10/06/2006 7:00 AM, [EMAIL PROTECTED] wrote: [snip] >>> def sort(self,myList): >>> for gap in self.gapSeq: >>> for i in range(1,gap+1): >>> self.gapInsert

Re: More pythonic shell sort?

2006-06-10 Thread [EMAIL PROTECTED]
Thanks for the critique. John Machin wrote: > On 10/06/2006 7:00 AM, [EMAIL PROTECTED] wrote: > > Disclaimer - I recognize this is not a practical exercise. There are > > many implementations around that would do the job better, more > > efficiently (Meaning in C) or whatever. > > > > I caught so

Re: More pythonic shell sort?

2006-06-09 Thread John Machin
On 10/06/2006 7:00 AM, [EMAIL PROTECTED] wrote: > Disclaimer - I recognize this is not a practical exercise. There are > many implementations around that would do the job better, more > efficiently (Meaning in C) or whatever. > > I caught some thread about sorting and started thinking about shell

Re: More pythonic shell sort?

2006-06-09 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > An aside - can anyone tell me where the use += and -= is documented? > > http://docs.python.org/ref/augassign.html > http://pyref.infogami.com/assignments > > Thanks!!! -- http://mail.python.org/mailman/listinfo/python-list

Re: More pythonic shell sort?

2006-06-09 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > An aside - can anyone tell me where the use += and -= is documented? http://docs.python.org/ref/augassign.html http://pyref.infogami.com/assignments -- http://mail.python.org/mailman/listinfo/python-list

Re: More pythonic circle?

2006-04-09 Thread John Machin
[Pythor] Sure, I tested it. === I don't think that word means what you think it means :-) [Pythor] On the other hand, I'm not having any trouble producing a whole circle, while you seem to think I'm only producing half a circle. The code that limits itself to a 5x5 box is only expected to produce

Re: More pythonic circle?

2006-04-09 Thread Pythor
John Machin wrote: > [Michael Tobis] > Also, with this code, you are using radius for the dimensions of the > enclosing box, as well as the radius of the circle, so it's guaranteed > to not to actually produce a whole circle. Recall what python does with > negative indices! > > [Pythor] > I'm not s

Re: More pythonic circle?

2006-04-09 Thread Scott David Daniels
Pythor wrote: > I wrote the following code for a personal project. I need a function > that will plot a filled circle in a two dimensional array. I found > Bresenham's algorithm, and produced this code. Please tell me there's > a better way to do this. > > import numpy > > def circle(field=Non

Re: More pythonic circle?

2006-04-09 Thread John Machin
[Michael Tobis] Also, with this code, you are using radius for the dimensions of the enclosing box, as well as the radius of the circle, so it's guaranteed to not to actually produce a whole circle. Recall what python does with negative indices! [Pythor] I'm not sure what you mean here. It produc

Re: More pythonic circle?

2006-04-09 Thread John Machin
It's also possible to write microprocessor assembly language in any other language. The following code generates the OP's list of points with nothing more complicated than integer addition/subtraction inside the loop. It also does the right thing if the radius is not an integer, and avoids the OP's

Re: More pythonic circle?

2006-04-09 Thread Pythor
Fredrik Lundh wrote: > "Pythor" wrote: > > > > You aren't getting any benefit from numpy or python here. Are you > > > aiming for speed or legibility? > > > > > Speed will be a necessity, eventually. I was just really aiming for > > something that works, and that I am capable of writing. > > any

Re: More pythonic circle?

2006-04-09 Thread Fredrik Lundh
"Pythor" wrote: > > You aren't getting any benefit from numpy or python here. Are you > > aiming for speed or legibility? > > > Speed will be a necessity, eventually. I was just really aiming for > something that works, and that I am capable of writing. any special reason you cannot use an exis

Re: More pythonic circle?

2006-04-09 Thread Pythor
Steven D'Aprano wrote: > No, "minimum number of space characters" means "you don't use enough > spaces", not "your variable names are too short" *wink* > Hmm. Guess I can't read too well. > Within a single line, a good guideline is to leave a single space on > either side of pluses and minuses (

Re: More pythonic circle?

2006-04-09 Thread Pythor
Michael Tobis wrote: > Proving yet again that it's possible to write Fortran in any language. > Ouch... > You aren't getting any benefit from numpy or python here. Are you > aiming for speed or legibility? > Speed will be a necessity, eventually. I was just really aiming for something that work

Re: More pythonic circle?

2006-04-08 Thread Steven D'Aprano
On Sat, 08 Apr 2006 21:17:32 -0700, Pythor wrote: >> (3) legibility: there's no prize for the script with the absolutely >> minimum number of space characters :-) > True. I assume your saying I should make cx,cy,dx, and dy better > names. I probably will. Up to now I was just playing around wit

Re: More pythonic circle?

2006-04-08 Thread Michael Tobis
Proving yet again that it's possible to write Fortran in any language. You aren't getting any benefit from numpy or python here. Are you aiming for speed or legibility? Also, with this code, you are using radius for the dimensions of the enclosing box, as well as the radius of the circle, so it'

Re: More pythonic circle?

2006-04-08 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-08 às 21:17 -0700, Pythor escreveu: > John Machin wrote: > > (3) legibility: there's no prize for the script with the absolutely > > minimum number of space characters :-) > True. I assume your saying I should make cx,cy,dx, and dy better > names. I probably will. Up to now I was

Re: More pythonic circle?

2006-04-08 Thread Pythor
John Machin wrote: > OTTOMH, in a rush to go out: never mind Pythonic, following apply to > any language: > (1) accuracy: (a) sue me if I'm wrong, but I think you need range(dx+1) > so that the dx pixel is filled in Hmm. I think you're right. Thanks. > (b) a few more digits after 0.71 > might be

Re: More pythonic circle?

2006-04-08 Thread John Machin
OTTOMH, in a rush to go out: never mind Pythonic, following apply to any language: (1) accuracy: (a) sue me if I'm wrong, but I think you need range(dx+1) so that the dx pixel is filled in (b) a few more digits after 0.71 might be useful (2) efficiency: seems that range(dy, dx+1) would save some we