Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104196
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> |
| Newsgroups | comp.lang.python |
| Subject | Re: Struggeling with collections |
| Date | Mon, 7 Mar 2016 09:39:32 +0100 |
| Lines | 56 |
| Message-ID | <mailman.10.1457340581.10335.python-list@python.org> (permalink) |
| References | <241aeea9-2604-4fa4-bf06-822ba5be143b@googlegroups.com> |
| Reply-To | vincent.vandevyvre@oqapy.eu |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de 4FSPjd+OyeaLBIhDnK9R1g05ahq/WtimfDKwsUtnj4sQ== |
| Return-Path | <vincent.vande.vyvre@telenet.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'api.': 0.04; 'none,': 0.05; 'objects,': 0.07; 'option,': 0.07; 'dict': 0.09; 'item,': 0.09; 'python': 0.10; 'def': 0.13; '55,': 0.16; 'clear.': 0.16; 'dictionary,': 0.16; 'folks,': 0.16; 'from:name:vincent vande vyvre': 0.16; 'item:': 0.16; 'received:195.130': 0.16; 'received:195.130.137': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'received:telenet- ops.be': 0.16; '\xe9crit': 0.16; 'memory': 0.17; '>>>': 0.20; 'hey': 0.20; 'library': 0.20; 'java': 0.22; 'this:': 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'parameters': 0.27; 'least': 0.27; 'question': 0.27; 'data,': 0.27; 'found.': 0.27; 'objects': 0.29; 'classes': 0.30; 'connections': 0.30; 'received:be': 0.30; 'option': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; 'problem': 0.33; 'instances': 0.33; 'on,': 0.35; 'files,': 0.35; 'unknown': 0.35; 'knowledge': 0.35; 'item': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'starting': 0.37; 'files': 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'some': 0.40; 'easy': 0.60; 'hope': 0.61; 'show': 0.62; 'charset:windows-1252': 0.62; 'making': 0.62; 'more': 0.63; 'quantity': 0.66; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'address,': 0.77; 'alike': 0.84; 'amount.': 0.84; 'day"': 0.84; 'quantity,': 0.84; 'many,': 0.93 |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104196 |
Show key headers only | View raw
Le 07/03/2016 09:24, Faling Dutchman a écrit :
> Hey folks,
>
> I am just starting off in python, but have good knowledge of both Java and C#. Now is the problem that I need to have multiple instances of one dictionary, that is not a problem if you know how many, but now, it is an unknown amount.
>
> Some background info:
>
> I am making a library for an API. This library must be easy to use for the people who are going to use it. So I am making the models for the data, the connections and so on, so they just have to fill in the gaps. In C# and Java I did it with objects, but they do not work alike in python, or at least that is what I have found.
>
> If I do this:
>
> 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>
>
> So that is not usefull to me. There can be an infinite amount of objects of Item, and it needs to be easy accessable, just like
> for i in items
> print(i)
>
> and it has to show all the parameters of the class Item and not say "ive got an object at this memory address, have a nice day"
>
> I hope my question is clear.
>
The classes have a dict
Python 3.2.3 (default, Jun 18 2015, 21:46:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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
...
>>> i = Item(1,None,1,1,'asdf',{'asdf': 3, 'ads': 55},None)
>>> i.__dict__
{'files': 'asdf', 'option': {'ads': 55, 'asdf': 3}, 'pageCount': 1,
'metadata': None, 'productId': None, 'id': 1, 'quantity': 1}
>>>
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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