Should a class's constructor be documented in the class's docstring or
__init__'s docstring? For instance:
class Foo(object):
"""This class represents mating lizards. Constructor requires one
argument, the lizard this lizard is mating with."""
def __init__(self, other):
pass
# or
class Bar(object):
""This class represents mating lizards."""
def __init__(self, other):
"""Initiate the object. Requires one argument, "other", which is the
lizard this lizard is mating with."""
pass 2 1316
Leif K-Brooks wrote: Should a class's constructor be documented in the class's docstring or __init__'s docstring? For instance:
class Foo(object): """This class represents mating lizards. Constructor requires one argument, the lizard this lizard is mating with.""" def __init__(self, other): pass
# or
class Bar(object): ""This class represents mating lizards.""" def __init__(self, other): """Initiate the object. Requires one argument, "other", which is the lizard this lizard is mating with.""" pass
Think as a user of your library: Where will you look at if you do not
know how to use a class ?
--
Yermat
Leif K-Brooks wrote: Should a class's constructor be documented in the class's docstring or __init__'s docstring? For instance:
class Foo(object): """This class represents mating lizards. Constructor requires one argument, the lizard this lizard is mating with.""" def __init__(self, other): pass
# or
class Bar(object): ""This class represents mating lizards.""" def __init__(self, other): """Initiate the object. Requires one argument, "other", which is the lizard this lizard is mating with.""" pass
It's probably a matter of taste, but
I'd prefer the style like in class Bar, because
information about the constructor is technically
nearer to the constructor.
Please don't write "Initiate the object." That's
what a constructor is (almost) always supposed to do.
Regards,
Holger This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sergey Krushinsky |
last post by:
Hello all,
Is there a common way to emulate constructor overloading in Python class?
For instanse, I have 3 classes:
1/ Polar - to hold polar coordinates;
2/ Cartesian - to hold cartesian...
|
by: Edward Diener |
last post by:
Is there a way in Python to have the constructor of a class "return" another
instance of the same class ? I am well aware of the fact that __init__ does
not return anything, but I would love to do...
|
by: Christian Dieterich |
last post by:
Hi,
I need to create many instances of a class D that inherits from a class
B. Since the constructor of B is expensive I'd like to execute it only
if it's really unavoidable. Below is an example...
|
by: scott |
last post by:
hi people,
can someone tell me, how to use a class like that* (or "simulate" more
than 1 constructor) :
#--
class myPointClass:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def...
|
by: Simon Morgan |
last post by:
Hi,
Can somebody please explain to me why:
class SomeClass:
def __init__(self, contents=):
self.contents = contents
def add(self, element):
self.contents.append(element)
|
by: Alfonso Morra |
last post by:
Hi,
I have some code from an example, that I want to retrofit into my
project. The code from the example has the following line:
SharedAppenderPtr myAppender( new...
|
by: GiBo |
last post by:
Hi all,
I have a class URI and a bunch of derived sub-classes for example
HttpURI, FtpURI, HttpsURI, etc. (this is an example, I know there is
module urllib & friends, however my actual problem...
|
by: inline |
last post by:
Hello!
I want to assign self to object of parent class in constructor, like
def my_func():
...
return ParentClass()
class MyClass (ParentClass):
def __init__(self):
self = my_func()
|
by: Joel Koltner |
last post by:
I have a generic (do nothing) exception class that's coded like this:
class MyError(exceptions.Exception):
def __init__(self,args=None):
self.args = args
When I attempt to raise this...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |