473,543 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class Rhash proposal

Writing software in Python for me it means work with dictionaries.
They are next to humans head.They make no assumption on the names of
variables ,mainly they leave the user
to set his program with the names he like.They track me next to the

Not to bore I ask opinions abuot a very simple new class Rhash :
The name to read as ErHash means recursive hash:

Its implementation:

class Rhash(dict):
def __getitem__(rha sh,key):
if key not in rhash:
return dict.__getitem_ _(key)

Rhash lets us say:



I['like']['mixing'][('smoking','thi nking')]=True
and have no Key Error and don't use the unreadable .setdefault(key ,{})
which anyway oblige us to
program the depth in advance.

Would it be nice to have it to help directly dict?

Thanks for comments Paolino

.....lotta dura per la verdura

Jul 18 '05 #1
2 1297
paolo veronelli <pa************ *@yahoo.it> wrote:
class Rhash(dict):
def __getitem__(rha sh,key):
if key not in rhash:
return dict.__getitem_ _(key)

Rhash lets us say:



I['like']['mixing'][('smoking','thi nking')]=True

You could simply write the indices into a sequence (tuple),
instead of stacking multiple dimensions of indices:

Human = {}
I = {}

Human[('isKindOf', 'beast')] = None

I[('like', 'mixing', ('smoking', 'thinking'))] = True

That would be easier and more efficient. Can you provide
a real-world example where your Rhash approach offers a
real advantage?

Best regards

Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany

``All that we see or seem is just a dream within a dream.''
(E. A. Poe)
Jul 18 '05 #2

The strenght of dictionaries is the key research (obviously)
The possibility of transparent nesting given by Rhashes pays off in
building tree of orederd informations.Or dered so that you can easily find
and store informations in it.

It's nothing more than a simple but useful database which you dedicate to
your views of the world you are trying to simulate.

The focus point in using dictionaries is that we want to deal with complex
informations which cannot be simplified in a record (an instance of a
It looks like every python object is nothing more than a dictionary,whic h
has constraints on nestings.This paradigma can be broken by using Rhashes
which have no constraints.

The other side of the story,is that keys have no specific meanings and the
code has to take in account some topological propreties of the Rhash
layout to work with it.

Particularly,th e meaning of every level of nesting has to be known to the

In my latest job the Rhash 'world' has the resources as first level,the
name of the resources.
The second is the predicate level,so querying it gives all the predicates
applicable to the resource choosen.
The other levels,are polymorphic and parseable only by pieces of code
binded to the predicate level......

Naturally using nested dictionaries is not very useful if the code
performs mere calculations,wh ere the input is primitive.

But if we deal with large and polimorphic informations which want to drive
the code and we are reading __metaclass__ looking for light,they can help.
The RDF reasoner I'm buiding has only 3 classes all derived from Rhash
with some other Rhashes inside.It works and,mostly ,the code is readable


print m
{'Lerat': {'isa': {'walker': None, 'human': None}, 'likes': {'music':
{'blues': None, 'ambient': None}}, 'sleeps': None}}
This is a better example maybe.
Thanks for comments Paolino

.....lotta dura per la verdura

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something with potential to be useful, but I would like to hear more opinions first. If this is deemed to be useful, I *may* try to write a PEP for it. This...
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
by: jygoh3 | last post by:
by: Coco | last post by:
Hi, I am wondering if this can be done. Well i have a class that take any object, and the class will get string from text file which is value need to be retrieved from this object. For example the property called Name of the class Proposal. what i need is my class to be able to read the string "Proposal.Name" and get the value Name from the...
by: JTL | last post by:
I have learnt java before and now begin to learn c++ what puzzle me is that seem that different SDKs(c++builder, vs.net, gcc..) has its own class library we know that in java there are only one uniform class library so that the codes I written in JBuilder can just copy to JCreator or Eclipse and they all run well does c++ have such an...
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add signed/unsigned modifier to class declarations to next revision of C++ programming language
by: Ben Voigt [C++ MVP] | last post by:
I'm trying to construct a compelling example of the need for a language feature, with full support for generics, to introduce all static members and nested classes of another type into the current name search scope. i.e. a very simple application would be class ManyComputations { calling System.Math;
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under 6.4.2(2) : case constant-expression : I propose that the case expression of the switch statement be changed from "integral constant-expression" to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.