473,699 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accesibility of the namespace

In my code I have relatively wide dictionary definition (about 100
rows).

I would like to put it in to the different file (module) because of the
main code readability (say the name of the file will be
"my_dictionary. py")

In the dictionary I have strings formatted using % operator like:
lcd={2:"Your credit= %3d" % (credit)}

While I am trying to import my_dictionary in to the main code, I am
getting:

exception unhandled NameError
name "credit" is not defined

How can I organize my code so the "credit" variable will be "visible"
in the "my_diction ary" namespace?

Thanks

Petr Jakes

Mar 9 '06 #1
4 1006
On Thu, 09 Mar 2006 01:42:55 -0800, Petr Jakes wrote:
In my code I have relatively wide dictionary definition (about 100
rows).

I would like to put it in to the different file (module) because of the
main code readability (say the name of the file will be
"my_dictionary. py")

In the dictionary I have strings formatted using % operator like:
lcd={2:"Your credit= %3d" % (credit)}
The values in the dictionary (e.g. "Your credit= 9.99", or whatever value
credit actually has) are fixed at creation. I assume that means that
credit etc. are also fixed values.

While I am trying to import my_dictionary in to the main code, I am
getting:

exception unhandled NameError
name "credit" is not defined

How can I organize my code so the "credit" variable will be "visible"
in the "my_diction ary" namespace?


Put it in the same module as my_dictionary.

E.g.

# Module my_dictionary.p y
# which I hope will have a more sensible name before being used
# for production-code
credit = 27
foo = 15
lcd = {2: "Your credit= %3d" % credit}

On the other hand, if credit is a calculated value, this might not be
an easy thing to do. In that case, you can do this:
# Module calculatevalues .py
credit = some_function()
foo = some_other_func tion()

# Module my_dictionary.p y
import calculatevalues
lcd = {2: "Your credit= %3d" % calculatevalues .credit}

On the third hand, if the strings from the dictionary are supposed to be
changed at run-time (which sounds more sensible to me) then do this:

# Module my_dictionary.p y
lcd = {2: "Your credit= %3d"}
# main program
import my_dictionary
.... lots of code here
credit = 27
.... more code
print lcd[2] % credit


--
Steven.

Mar 9 '06 #2
Thanks Steven,
credit is mentioned to be a calculated value changed at run-time and
your "third hand" suggestion is exactly what I was looking for.

Petr Jakes

Mar 9 '06 #3
Ooooops. My keyboard (fingers) was faster than my mind :(
So....
There is more than one "run-time changed variable" in the dictionary
and not all strings in the dictionary are formatted using % operator.
Example:
lcd={
2:{2:(("Enter you choice"),("Your kredit= %3d" % (kredit)))},
4:{2:(("Your choice: %2s" % (keyboard)),("%-20s" % (actKeyboard))) }}

I do not know which variable(s) to use for the % operator in the time
of the call of the value (% formatted string) from the dictionary.

This is also the reason why the variable names are stored in the
dictionary with the strings.

Any other suggestions?
Thanks
Petr Jakes

Mar 9 '06 #4
Petr Jakes wrote:
Ooooops. My keyboard (fingers) was faster than my mind :(
So....
There is more than one "run-time changed variable" in the dictionary
and not all strings in the dictionary are formatted using % operator.
Example:
lcd={
2:{2:(("Enter you choice"),("Your kredit= %3d" % (kredit)))},
4:{2:(("Your choice: %2s" % (keyboard)),("%-20s" % (actKeyboard))) }}

I do not know which variable(s) to use for the % operator in the time
of the call of the value (% formatted string) from the dictionary.

This is also the reason why the variable names are stored in the
dictionary with the strings.

Any other suggestions?


So, use something like
lcd={ 2:{2:("Enter you choice","Your kredit= %(kredit)3d")},
4:{2:("Your choice: %(keyboard)2s" ,"%(actKeyboard )-20s")}} kredit = 7
keyboard = 'aa'
actKeyboard = 7654
lcd[2][2][-1] % vars() 'Your kredit= 7' lcd[2][2][0] % vars() 'Enter you choice' lcd[4][2][0] % vars() 'Your choice: aa' lcd[4][2][1] % vars() '7654 '


HTH
/MiO
Mar 9 '06 #5

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

Similar topics

1
2720
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
25
3079
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
3
10041
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
6
1966
by: Don Wash | last post by:
Hi There! I just need some advice on Namespace management for creating reusable VB.NET applications. I would like my applications to have this namespace structure... Namespace MyCompany Namespace MyApplication1
8
4911
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using namespace std;' unless the std namespace was declared first. This triggered my curiosity, and I tried to find out what the ANSI C++ standard had to say about this. I'm unable to find a conclusion, and hope someone here have a clue to spare. ...
10
1572
by: Monte Gardner | last post by:
I'm teaching a class on web authoring and html. I'm trying to find a good reading article on accesibility issues. I'm trying to keep the reading supplements to relatively light reading, so I don't want to just point my students to the W3C's Web Accessibilty Guidline articles (a little to heavy reading). Can any of you suggest an online article out there that will explain why you need to think about accesbility and some basic ideas on...
7
7433
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
14
3326
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
2
1533
by: petinboy | last post by:
Hi All! I am developing an accessibility keyboard application with Visual Studio 2005 Professional Edition and with C#. The application is a keyboard with buttons that interacts with any application on windows, such as Word, Messenger, IExplorer... The keyboard is on the bottom of the desktop and the other application is on the top of the desktop. The keyboard interacts with other applications using the SendKeys class. When I send...
0
8687
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8884
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.