473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: About __init__ and default arguments

Nathan Duran wrote:
>
On Apr 11, 2008, at 11:35 AM, py*****************@python.org wrote:
>I'd like to assign the value of an attribute in __init__ as the default
value of an argument in a method. See below:
Why not just do

def franklin(self, keyword):
if not keyword: keyword = self.default
return "A %s in time saves nine." % (keyword)
Several things are false (for example: '', 0, False, [], ...)
If you can get along with the code you have suggested, I'd
think about using:

def franklin(self, keyword):
return "A %s in time saves nine." % (keyword or self.default)

-Scott David Daniels
Sc***********@Acm.Org
Jun 27 '08 #1
0 872

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John M. Gabriele | last post by:
I know that Python doesn't do method overloading like C++ and Java do, but how am I supposed to do something like this: --------------------- incorrect ------------------------...
13
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...
3
by: Daniel Schüle | last post by:
Hello Ng, I was playing around with pymedia module and I succeeded when I used complementation instead of inheritance .. but then I was forced to wrap simple methods of sound.Output like...
7
by: Kent Johnson | last post by:
Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? The super() method only works correctly in multiple...
4
by: Noah | last post by:
Am I the only one that finds the super function to be confusing? I have a base class that inherits from object. In other words new style class: class foo (object): def __init__ (self, arg_A,...
1
by: Daniel Klein | last post by:
I've have a program that is using both of the methods below (in different classes of course) for initializing the class. The example below shows a class with the 2 methods with one commented out. ...
19
by: dickinsm | last post by:
Here's an example of a problem that I've recently come up against for the umpteenth time. It's not difficult to solve, but my previous solutions have never seemed quite right, so I'm writing to...
4
by: Steven D'Aprano | last post by:
When you call a new-style class, the __new__ method is called with the user-supplied arguments, followed by the __init__ method with the same arguments. I would like to modify the arguments...
25
by: Erik Lind | last post by:
I'm new to Python, and OOP. I've read most of Mark Lutz's book and more online and can write simple modules, but I still don't get when __init__ needs to be used as opposed to creating a class...
43
by: kenneth | last post by:
Dear all, I have encountered this weird problem. I have a class definition with an __init__ argument 'd' which defaults to {}. This argument is put in the 'self.d' attribute at initialization...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
marktang
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,...
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,...

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.