ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] Re: Tutor Digest, Vol 5, Issue 39
by Alan Gauld other posts by this author
Dec 12 2003 8:15PM messages near this date
[Tutor] Re: Accessing hardware drivers written in "C"? | [Tutor] Python used in Data Acquisition systems?
>  If you pay attention you see the dictionary implicit inside of
module,
>  I use this to make a reference to the correct function declared
on end of
>  the code.

Maybe....

>  self_module = sys.modules[__name__]

This just gets you a reference to your own module.

>  def seed(XMLmodel, fontFile):
>    self_module.tecniquie = xpath.Evaluate('/layout/tecniquie',
> 
XMLmodel)[0].childNodes[0].nodeValue

And this creates a new module scope variable called tecniquie.
Which you could have done with an initialisation to None outside
(or by using the global specifier in the function).

>  class internode:
>    def __init__(self, node, data):
>      for child in node.childNodes:
>        self.data_list = getattr(self_module,
>                              'load_' + node.nodeName)(child,
data)

Now this bit is more interesting because here you are getting
one of two possible functions ddepending on the data.
However you could have domne that by declaring an explicit
dictionary:

loadFuncs = {
"load_group"  : load_group,
"load_dataSet" : load_dataSet
}

And then referencing the dictionary:
>        self.data_list = loadFuncs['load_' +
node.nodeName'](child, data)

>  def load_layout(node, data):
>    if self_module.tecniquie == u'layout':

And this just needs to be a variable reference, no need even
for the global qualifier.

>  def load_group(node, data):
>  def load_dataSet(node, data):

These would need to be defined before the dictionary.

At least I think that's how it would work. Its how I would try
coding it because I think its easier to see the intent.

Alan G.


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved