DictObjSys (DOS): Dictionary Objects System V.0.0.1 (2004 Oct 26)

R

RDJ

=== This is a AoooAoooA project (^_^) ===

DictObjSys (DOS): Dictionary Objects System V.0.0.1 (2004 Oct 26)

Copyright (C) 2004 RDJ

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


TABLE OF CONTENTS
*****************

_REFERENCES
_FILES
_RUN_DOS


_REFERENCES
************

Redirect: AoooAoooA.too.it
____Site: it.geocities.com/dawjde/AoooAoooA.html
___Email: (e-mail address removed) (OBJECT: [AoooAoooA] your object)


_FILES
******

DictObjSys/DOS.py...........library
DictObjSys/GNU_LGPL.txt.....GNU LIBRARY GENERAL PUBLIC LICENSE
DictObjSys/README.txt.......this file


_RUN_DOS
********

DOS is a library but you can run a test:

python DOS.py


Appear:

This is a test:
1-2
['three.a', 'three.b']
1-2-3b


It is OK! Now view the source code...

#
# Class
#

class DOS:
def __init__(self):
self.value = None
self.dict = {}

def get(self,path):
dos = self.getDOS(path)
if dos == None:
return None
else:
return dos.value

def getDOS(self,path):
pl = path.split('/')
dos_tmp = self
try:
for r in pl:
dos_tmp = dos_tmp.dict[r]
return dos_tmp
except KeyError:
return None

def keys(self):
return self.dict.keys()

def set(self,path,value):
pl = path.split('/')
dos_tmp = self
for r in pl:
if dos_tmp.dict.has_key(r) == False:
dos_tmp.dict[r] = DOS()
dos_tmp = dos_tmp.dict[r]
dos_tmp.value = value;
#
# Main
#

if __name__ == '__main__':
print 'This is a test:'
dos = DOS()
dos.set('one/two','1-2')
dos.set('one/two/three.a','1-2-3a')
dos.set('one/two/three.b','1-2-3b')
print dos.get('one/two')
print dos.getDOS('one/two').keys()
print dos.get('one/two/three.b')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top