Re: helper function in a class' namespace

2008-01-31 Thread Arnaud Delobelle
On Jan 31, 8:05 pm, Stargaming <[EMAIL PROTECTED]> wrote: [...] > > class A(object): > >    def Helper(M) : > >      return 'H>'+M > >    def __init__(self,Msg) : > >      print Helper(Msg) > > > doesn't work since Python is looking for a global function Helper (why?) > > Because in the scope of th

Re: helper function in a class' namespace

2008-01-31 Thread Arnaud Delobelle
On Jan 31, 10:39 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Thu, 31 Jan 2008 20:05:44 +, Stargaming wrote: > > String concatenation is generally considered unpythonic, better use > > string interpolation:: > > >     'H> %s' % (M,) [...] > Also, the tuple above is tot

Re: helper function in a class' namespace

2008-01-31 Thread Steven D'Aprano
On Thu, 31 Jan 2008 20:05:44 +, Stargaming wrote: > String concatenation is generally considered unpythonic, better use > string interpolation:: > > 'H> %s' % (M,) String concatenation is significantly faster than string interpolation. >>> import timeit >>> timeit.Timer("'H> %s' % M", "

Re: helper function in a class' namespace

2008-01-31 Thread Stargaming
On Thu, 31 Jan 2008 20:51:23 +0100, Helmut Jarausch wrote: > Hi, > > the following code works fine > > def Helper(M) : >return 'H>'+M String concatenation is generally considered unpythonic, better use string interpolation:: 'H> %s' % (M,) > class A(object): >def __init__(self,Ms

helper function in a class' namespace

2008-01-31 Thread Helmut Jarausch
Hi, the following code works fine def Helper(M) : return 'H>'+M class A(object): def __init__(self,Msg) : print Helper(Msg) B=A('ZZ') but the Helper function is in the module's namespace. I'd like to put it into class A's namespace. Note, the Helper function doesn't need access to