Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Roel Schroeven Newsgroups: comp.lang.python Subject: Re: Struggeling with collections Date: Mon, 07 Mar 2016 22:55:54 +0100 Lines: 38 Message-ID: References: <241aeea9-2604-4fa4-bf06-822ba5be143b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de kQr5fA0PPbKi9Uz84WlYrQmeEUPVVd6kXrbS/IB4Q1DA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'none,': 0.05; 'none)': 0.07; 'option,': 0.07; 'collections': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; '55,': 0.16; 'item:': 0.16; 'need,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; '>>>': 0.20; 'aspect': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; "i'm": 0.30; 'received:be': 0.30; 'option': 0.31; 'skip:_ 10': 0.32; 'received:84': 0.32; 'class': 0.33; 'url:python': 0.33; 'skip:c 30': 0.35; 'files,': 0.35; 'knowledge': 0.35; 'item': 0.35; 'but': 0.36; 'url:org': 0.36; 'faster': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'files': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'url:3': 0.60; 'for:': 0.64; 'quantity': 0.66; 'life': 0.67; '100%': 0.72; 'isaac': 0.84; 'quantity,': 0.84; 'schreef': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: d54c57c9e.access.telenet.be User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) In-Reply-To: <241aeea9-2604-4fa4-bf06-822ba5be143b@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104258 Faling Dutchman schreef op 2016-03-07 09:24: > class Item: > def __init__(self, id, productId, quantity, pageCount, files, option, metadata): > self.id = id > self.productId = productId > self.quantity = quantity > self.pageCount = pageCount > self.files = files > self.option = option > self.metadata = metadata > > itm = Item(1,None,1,1,'asdf',{'asdf': 3, 'ads': 55},None) > print(itm) > > it prints: <__main__.Item object at 0x02EBF3B0> I'm not 100% sure exactly what you need, but namedtuple might be what you're looking for: >>> import collections >>> Item = collections.namedtuple('Item', 'id productId quantity pageCount files option metadata') >>> itm = Item(1, None, 1, 1, 'asdf', {'asdf': 3, 'ads': 55}, None) >>> print(itm) Item(id=1, productId=None, quantity=1, pageCount=1, files='asdf', option={'ads': 55, 'asdf': 3}, metadata=None) See https://docs.python.org/3/library/collections.html?highlight=namedtuple#collections.namedtuple -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven