473,472 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Python Class Best Practice

-----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
4 2106
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
14
by: David MacQuigg | last post by:
I am starting a new thread so we can avoid some of the non-productive argument following my earlier post "What is good about Prothon". At Mr. Hahn's request, I will avoid using the name "Prothon"...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
3
by: Michael Sparks | last post by:
Hi, I'm posting a link to this since I hope it's of interest to people here :) I've written up the talk I gave at ACCU Python UK on the Kamaelia Framework, and it's been published as a BBC...
9
by: corey.coughlin | last post by:
Alright, so I've been following some of the arguments about enhancing parallelism in python, and I've kind of been struck by how hard things still are. It seems like what we really need is a more...
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.