Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98807

Persist objects in a LIST

Newsgroups comp.lang.python
Date 2015-11-14 06:26 -0800
Message-ID <0cb1bcda-54d5-4cc7-bd23-f86f7f10ee28@googlegroups.com> (permalink)
Subject Persist objects in a LIST
From John Zhao <johnzzhao@gmail.com>

Show all headers | View raw


I am new to Python, and just learned that Python list is just a container of object reference.   

In the example below,  bDict needs to be just a temporary object, constructed at run time and then be added to aList.       At the end, aList will contain n objects.    

Is there a clean way to do that?

Many thanks, 

John

$ ipython
WARNING: IPython History requires SQLite, your history will not be saved
WARNING: Readline services not available or not loaded.
WARNING: The auto-indent feature requires the readline library
Python 2.7.9 (default, Sep  5 2015, 07:20:36)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
In [1]: aList = []
In [2]: bDict = {}
In [3]: bDict['instance_name']='SERVER_TIER'
In [4]: aList.append(bDict)
In [5]: print aList
[{'instance_name': 'SERVER_TIER'}]
In [6]: bDict.clear()
In [7]: print aList
[{}]

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Persist objects in a  LIST John Zhao <johnzzhao@gmail.com> - 2015-11-14 06:26 -0800
  Re: Persist objects in a  LIST John Zhao <johnzzhao@gmail.com> - 2015-11-14 07:02 -0800
    Re: Persist objects in a  LIST Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-14 10:39 -0500
    Re: Persist objects in a LIST Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2015-11-14 17:33 +0100

csiph-web