Re: assign class variable in __init__

2010-06-08 Thread James Mills
On Wed, Jun 9, 2010 at 6:36 AM, Mark Lawrence wrote: > Yes alright bloody Aussies  ** n * sodit * *wink*.  Not sure if this is a > syntax error, but too lazy too test at an interactive prompt. I resent that remark :) --James -- http://mail.python.org/mailman/listinfo/python-list

Re: assign class variable in __init__

2010-06-08 Thread Mark Lawrence
On 08/06/2010 17:55, Steven D'Aprano wrote: On Tue, 08 Jun 2010 17:24:55 +0100, Mark Lawrence wrote: On 08/06/2010 17:04, Ross Williamson wrote: Hi Everyone, Just a quick question - Is it possible to assign class variables in the __init__() - i.e. somthing like: They're instance variables,

Re: assign class variable in __init__

2010-06-08 Thread danieldelay
you can also use : >>> class A(object): def __init__(self, **args): self.__dict__.update(args) >>> a=A(source='test', length=2) >>> a.source 'test' but this is to be used carefully because mispelling your args somewhere in your program will not raise any error : >>> A(

Re: assign class variable in __init__

2010-06-08 Thread Peter Otten
Jean-Michel Pichavant wrote: > def __init__(self, source="test", length=1): > self.source = source > self.length = length > > is the way to go. OP's original idea is a bad idea :). D'accord. > Could be a problem with hundreds of parameters, but who write > constructors with hundreds of paramete

Re: assign class variable in __init__

2010-06-08 Thread Jean-Michel Pichavant
Peter Otten wrote: Jason Scheirer wrote: On Jun 8, 9:37 am, Peter Otten <__pete...@web.de> wrote: Ross Williamson wrote: Hi Everyone, Just a quick question - Is it possible to assign class variables in the __init__() - i.e. somthing like: def __init__(self,se

Re: assign class variable in __init__

2010-06-08 Thread Peter Otten
Jason Scheirer wrote: > On Jun 8, 9:37 am, Peter Otten <__pete...@web.de> wrote: >> Ross Williamson wrote: >> > Hi Everyone, >> >> > Just a quick question - Is it possible to assign class variables in >> > the __init__() - i.e. somthing like: >> >> > def __init__(self,self.source = "test", self.le

Re: assign class variable in __init__

2010-06-08 Thread Jason Scheirer
On Jun 8, 9:37 am, Peter Otten <__pete...@web.de> wrote: > Ross Williamson wrote: > > Hi Everyone, > > > Just a quick question - Is it possible to assign class variables in > > the __init__() - i.e. somthing like: > > > def __init__(self,self.source = "test", self.length = 1) > > > rather than > >

Re: assign class variable in __init__

2010-06-08 Thread Steven D'Aprano
On Tue, 08 Jun 2010 17:24:55 +0100, Mark Lawrence wrote: > On 08/06/2010 17:04, Ross Williamson wrote: >> Hi Everyone, >> >> Just a quick question - Is it possible to assign class variables in the >> __init__() - i.e. somthing like: > > They're instance variables, not class variables. In the usua

Re: assign class variable in __init__

2010-06-08 Thread Peter Otten
Ross Williamson wrote: > Hi Everyone, > > Just a quick question - Is it possible to assign class variables in > the __init__() - i.e. somthing like: > > def __init__(self,self.source = "test", self.length = 1) > > rather than > > def __init__(self,source = "test", length = 1): No. If you are

Re: assign class variable in __init__

2010-06-08 Thread Mark Lawrence
On 08/06/2010 17:04, Ross Williamson wrote: Hi Everyone, Just a quick question - Is it possible to assign class variables in the __init__() - i.e. somthing like: They're instance variables, not class variables. def __init__(self,self.source = "test", self.length = 1) No. rather than def _

assign class variable in __init__

2010-06-08 Thread Ross Williamson
Hi Everyone, Just a quick question - Is it possible to assign class variables in the __init__() - i.e. somthing like: def __init__(self,self.source = "test", self.length = 1) rather than def __init__(self,source = "test", length = 1): -- Ross Williamson University of Chicago Department of As