Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104258
| From | Roel Schroeven <roel@roelschroeven.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Struggeling with collections |
| Date | 2016-03-07 22:55 +0100 |
| Message-ID | <mailman.52.1457387777.10335.python-list@python.org> (permalink) |
| References | <241aeea9-2604-4fa4-bf06-822ba5be143b@googlegroups.com> |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Struggeling with collections Faling Dutchman <henriarends92@gmail.com> - 2016-03-07 00:24 -0800
Re: Struggeling with collections Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2016-03-07 09:39 +0100
Re: Struggeling with collections Faling Dutchman <henriarends92@gmail.com> - 2016-03-07 00:58 -0800
Re: Struggeling with collections Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-07 19:52 +1100
Re: Struggeling with collections Gary Herron <gherron@digipen.edu> - 2016-03-07 01:01 -0800
Re: Struggeling with collections Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-07 11:31 +0200
Re: Struggeling with collections Faling Dutchman <henriarends92@gmail.com> - 2016-03-07 01:43 -0800
Re: Struggeling with collections Roel Schroeven <roel@roelschroeven.net> - 2016-03-07 22:55 +0100
csiph-web