By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

Python Class Best Practice

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been doing python programming for about 2 years as a hobby and now
I'm finally able to use it at work in an enterprise environment. Since
I will be creating the base classes and libraries I wondering which why
is consider best when creating python classes:

1:
class Foo(object):
member1=''
member2=0

def __init__(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

2:
class Foo(object):
def __init(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2


- --
Rod
http://roddierod.homeunix.net:8080
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFHVeAscZAIaGStcnARAhRnAKCNFfjStOPGs/9tMI6bKuBQTPiJHQCdEMdY
OQPSSZlJWqkLxZvPwI2ctVs=
=CfvK
-----END PGP SIGNATURE-----
Dec 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Dec 5, 4:18 am, Rod Person <rodper...@verizon.netwrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been doing python programming for about 2 years as a hobby and now
I'm finally able to use it at work in an enterprise environment. Since
I will be creating the base classes and libraries I wondering which why
is consider best when creating python classes:

1:
class Foo(object):
member1=''
member2=0

def __init__(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

2:
class Foo(object):
def __init(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

- --
Rodhttp://roddierod.homeunix.net:8080
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFHVeAscZAIaGStcnARAhRnAKCNFfjStOPGs/9tMI6bKuBQTPiJHQCdEMdY
OQPSSZlJWqkLxZvPwI2ctVs=
=CfvK
-----END PGP SIGNATURE-----
It depends on what we try to achieve.

The first definition gets me class defined with two class and instance
variables of the names member1 and member2. Where as second definition
gets class with only instance variables member1 and member2.

Both the definitions would allow me, Foo().member1 and Foo().member2.
Where as first definition would also allow me Foo.member1 and
Foo.member2.
Dec 5 '07 #2

P: n/a
On Dec 5, 12:18 am, Rod Person <rodper...@verizon.netwrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been doing python programming for about 2 years as a hobby and now
I'm finally able to use it at work in an enterprise environment. Since
I will be creating the base classes and libraries I wondering which why
is consider best when creating python classes:

1:
class Foo(object):
member1=''
member2=0

def __init__(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

2:
class Foo(object):
def __init(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

The short answer : if 2 works, then stick with it.
Dec 5 '07 #3

P: n/a
cp*********@gmail.com a écrit :
On Dec 5, 12:18 am, Rod Person <rodper...@verizon.netwrote:
>-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been doing python programming for about 2 years as a hobby and now
I'm finally able to use it at work in an enterprise environment. Since
I will be creating the base classes and libraries I wondering which why
is consider best when creating python classes:

1:
class Foo(object):
member1=''
member2=0

def __init__(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

2:
class Foo(object):
def __init(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2


The short answer : if 2 works, then stick with it.
The yet-even-shorter-answer: 2

!-)
Dec 7 '07 #4

P: n/a
On 4 Dec, 23:18, Rod Person <rodper...@verizon.netwrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been doing python programming for about 2 years as a hobby and now
I'm finally able to use it at work in an enterprise environment. Since
I will be creating the base classes and libraries I wondering which why
is consider best when creating python classes:

1:
class Foo(object):
member1=''
member2=0

def __init__(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2

2:
class Foo(object):
def __init(self,member1='',member2=0):
self.member1 = member1
self.member2 = member2
Don't forget to call the base class __init__ function
Dec 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.