Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"python': 0.16; '*class': 0.16; 'attributes.': 0.16; 'least)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:object': 0.16; 'subject:simple': 0.16; 'subject:type': 0.16; '{})': 0.16; 'header :User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; '>>>>': 0.31; 'obscure': 0.31; 'writes:': 0.31; 'class': 0.32; 'could': 0.34; 'useful': 0.36; 'employee': 0.37; 'clear': 0.37; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name': 0.63; 'therefore': 0.72; 'as:': 0.81; 'received:89': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Akira Li <4kir4.1i@gmail.com> Subject: Re: Correct type for a simple "bag of attributes" namespace object Date: Sun, 03 Aug 2014 18:22:09 +0400 References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain X-Gmane-NNTP-Posting-Host: 89.169.229.68 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:Y+2hGRaMCUImWAmCbFmt659plJU= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407075742 news.xs4all.nl 2913 [2001:888:2000:d::a6]:40564 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75599 Albert-Jan Roskam writes: > I find the following obscure (to me at least) use of type() useful > exactly for this "bag of attributes" use case: >>>> employee = type("Employee", (object,), {}) >>>> employee.name = "John Doe" >>>> employee.position = "Python programmer" You could write it as: class Employee: name = "Johh Doe" position = "Python programmer" It also makes it clear that `type()` returns a *class Employee*, not its instance (Employee()) and therefore name, position are class attributes. -- Akira