default behavior

Nick Raptis airscorp at otenet.gr
Thu Jul 29 14:43:05 EDT 2010


On 07/29/2010 09:12 PM, wheres pythonmonks wrote:
> How do I build an "int1" type that has a default value of 1?
You mean something like:
 >>> x = int()
 >>> x
0
 >>> def myint(value=1):
...     return int(value)
...
 >>> myint()
1
 >>>

That's ugly on so many levels..

Anyway, basic types (and almost everything else) in Python are classes.
You can always subclass them to do whatever you like

> [Hopefully no speed penalty.]
> I am thinking about applications with collections.defaultdict.
> What if I want to make a defaultdict of defaultdicts of lists?  [I
> guess my Perl background is showing -- I miss auto-vivification.]
>
>
>    
Ah, python is no perl. Then again, perl is no python either.
----- Random pseudo-Confucius quote

Have fun,
Nick




More information about the Python-list mailing list