[Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)
Ivan Levkivskyi
levkivskyi at gmail.com
Wed May 17 13:43:26 EDT 2017
More information about the Python-ideas mailing list
Wed May 17 13:43:26 EDT 2017
- Previous message (by thread): [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)
- Next message (by thread): [Python-ideas] [semi-OT] NamedTuple from aenum library [was: JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 17 May 2017 at 19:40, Juancarlo AƱez <apalala at gmail.com> wrote: > > On Wed, May 17, 2017 at 12:48 PM, Ivan Levkivskyi <levkivskyi at gmail.com> > wrote: > >> class Foo(NamedTuple): >> """Foo is a very important class and >> you should totally use it. >> """ >> bar: int >> baz: int = 0 >> >> def grand_total(self): >> return self.bar + self.baz >> > > Really?! > > I didn't know that idiom existed. > > It is enough for many use cases, and I was just about to require typing > and pathlib on my 2.7-compatible projects. > > Unfortunately, this works _only_ in Python 3.6+. -- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170517/efb96098/attachment-0001.html>
- Previous message (by thread): [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)
- Next message (by thread): [Python-ideas] [semi-OT] NamedTuple from aenum library [was: JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list