How do you write this in python

Alex Martelli aleaxit at
Sun Oct 3 10:37:12 CEST 2004

Ali <alikakakhel3 at> wrote:
> function PrintCard() {
> }
> function Card(name,email) {
> = name;
> = email;
>       this.PrintCard = PrintCard;
> }
> ali = new Card("Ali", "alik at");
> zainab = new Card("Zainab", "zainab at");
> The script in this page, has a function (Card) that is used to create
> an object with its own properties and methods (ali and zainab in this
> script). I was wondering if this was possible in python.

Sure, though we'd normally use a class statement instead:

class Card:
    def __init__(self, name, email): = name = email
    def PrintCard(self):
        ''' whatever... '''

ali = Card('Ali, 'alik at')
zainab = Card('Zainab', 'zainab at')

If for some weird reason you're keen to make Card a factory function
rather than a class, that can be arranged, too.  But the normal way in
Python is just to use and define classes.


More information about the Python-list mailing list