Re: How to detect that a function argument is the default one

2014-12-11 Thread Ben Finney
Tony the Tiger writes: > radius='10', mass='1' > > if radius == '10' ... > > if mass == '1' ... This ignores the problem as stated: The OP wants to distinguish between a value that was explicitly set by the caller, versus a value that was set by default because the caller did not specify the par

Re: How to detect that a function argument is the default one

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 11:03 AM, Ian Kelly wrote: > > On Thu, Dec 11, 2014 at 3:02 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > > I would advise to remove the the mass parameter of your Sphere initialization. It could be inconsistent with the radius. > > To compute the mass you wo

Re: How to detect that a function argument is the default one

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 3:02 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > I would advise to remove the the mass parameter of your Sphere initialization. It could be inconsistent with the radius. > To compute the mass you would need the radius and the volumetric mass density. You a

Re: How to detect that a function argument is the default one

2014-12-11 Thread Jean-Michel Pichavant
- Original Message - > From: "ast" > > > >> Note : what is the mass of a circle ? > > > > In fact it's a ball moving in a plan. > I will change that name. I would advise to remove the the mass parameter of your Sphere initialization. It could be inconsistent with the radius. To compute

Re: How to detect that a function argument is the default one

2014-12-11 Thread Jean-Michel Pichavant
- Original Message - > From: "Chris Angelico" > > c1 = Circle((0,0), 10, None) > > print c1.mass > > 20 > > c1.radius = 20 > > print c1.mass > > 40 > > I think that juust might count as scope creep :) > ChrisA Here you go :p c1 = Circle((0,0), 10, None) print c1.mass 20 c1.gr

Re: How to detect that a function argument is the default one

2014-12-10 Thread ast
"Chris Angelico" a écrit dans le message de news:mailman.16814.1418228205.18130.python-l...@python.org... On Thu, Dec 11, 2014 at 3:10 AM, Jean-Michel Pichavant wrote: - Original Message - From: "ast" But there's an issue with that solution: self.mass being computed during the i

Re: How to detect that a function argument is the default one

2014-12-10 Thread Jussi Piitulainen
Jean-Michel Pichavant writes: > If you like one-liners, > > def __init__(self, center=(0,0), radius=10, mass=None): > self.center = center > self.radius = radius > self.mass = (mass is None and radius**2) or mass That's not a one-liner. That's a one-liner: def __init__(self, center=

Re: How to detect that a function argument is the default one

2014-12-10 Thread Marko Rauhamaa
Skip Montanaro : > On Wed, Dec 10, 2014 at 9:14 AM, ast wrote: >> I have the idea to write: >> >> def __init__(center=(0,0), radius=10, mass=None)): >> >>if mass == None:self.mass = radius**2 >>else: >>self.mass = mass >> >> but maybe Python provides something clever. > >

Re: How to detect that a function argument is the default one

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 9:10 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > If you like one-liners, > > def __init__(self, center=(0,0), radius=10, mass=None): > self.center = center > self.radius = radius > self.mass = (mass is None and radius**2) or mass If mass is None

Re: How to detect that a function argument is the default one

2014-12-10 Thread Ned Batchelder
On 12/10/14 11:10 AM, Jean-Michel Pichavant wrote: self.mass = (mass is None and radius**2) or mass When will this idiom die? We've had actual if-expressions for a while now: self.mass = radius**2 if mass is None else mass -- Ned Batchelder, http://nedbatchelder.com -- https://mail

Re: How to detect that a function argument is the default one

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 3:10 AM, Jean-Michel Pichavant wrote: > - Original Message - >> From: "ast" >> I have the idea to write: >> >> def __init__(center=(0,0), radius=10, mass=None)): >> >> if mass == None: >> self.mass = radius**2 >> else: >> self.mass = mass >

Re: How to detect that a function argument is the default one

2014-12-10 Thread Jean-Michel Pichavant
- Original Message - > From: "ast" > I have the idea to write: > > def __init__(center=(0,0), radius=10, mass=None)): > > if mass == None: > self.mass = radius**2 > else: > self.mass = mass > > but maybe Python provides something clever. > > Thx If you like on

Re: How to detect that a function argument is the default one

2014-12-10 Thread ast
"Skip Montanaro" a écrit dans le message de news:mailman.16809.1418225382.18130.python-l...@python.org... On Wed, Dec 10, 2014 at 9:14 AM, ast wrote: thx -- https://mail.python.org/mailman/listinfo/python-list

Re: How to detect that a function argument is the default one

2014-12-10 Thread Skip Montanaro
On Wed, Dec 10, 2014 at 9:14 AM, ast wrote: > I have the idea to write: > > def __init__(center=(0,0), radius=10, mass=None)): > >if mass == None:self.mass = radius**2 >else: >self.mass = mass > > but maybe Python provides something clever. This is almost the correct idio

How to detect that a function argument is the default one

2014-12-10 Thread ast
Hello Here is what I would like to implement class Circle: def __init__(center=(0,0), radius=10, mass=1)): self.center = center self.radius = radius if "mass is the default one": <- self.mass = radius**2 else: self.mass = mass I