473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Re: Global dictionary or class variables

On Fri, Oct 24, 2008 at 1:44 PM, Mr. SpOOn <mr********@gmail.comwrote:
Hi,
in an application I have to use some variables with fixed valuse.

For example, I'm working with musical notes, so I have a global
dictionary like this:

natural_notes = {'C': 0, 'D': 2, 'E': 4 ....}

This actually works fine. I was just thinking if it wasn't better to
use class variables.

Since I have a class Note, I could write:

class Note:
C = 0
D = 2
...

Which style maybe better? Are both bad practices?
Depends. Does your program use the note values as named constants, or
does it lookup the values dynamically based on the note name?
If the former, then the class is marginally better, though putting the
assignments in a (possibly separate) module would probably be best. If
the latter, than the dictionary is fine.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Oct 24 '08 #1
0 732

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

Similar topics

8
by: alex | last post by:
Hi, is it possible to create 'global' variables that can be seen in all other classes? Alex
0
by: Joe Blow via DotNetMonster.com | last post by:
Hello, I have a design problem involving class instances as global variables. To give you my background, I've programmed lots in Java, and most of it has been large class structures. I'm...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
1
by: Crutcher | last post by:
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program,...
4
by: DaveM | last post by:
Although I've programmed for fun - on and off - since the mid 70's, I'm definitely an OO (and specifically Python) beginner. My first question is about global variables. Are they, as I'm starting...
7
bvdet
by: bvdet | last post by:
I provide shop drawings to structural steel fabricators with SDS/2 software (http://sds2.com) by Design Data (DD). I am not a programmer by education or trade and started writing scripts about 5...
18
by: Donn Ingle | last post by:
Hi, I'm getting myself really confused. I have three classes. Two of them need to reference the third, like so: Canvas ---Stack <--- Thing I am doing this right now: s = Stack()
4
by: icarus | last post by:
global_vars.py has the global variables set_var.py changes one of the values on the global variables (don't close it or terminate) get_var.py retrieves the recently value changed (triggered right...
3
by: Mr.SpOOn | last post by:
Hi, in an application I have to use some variables with fixed valuse. For example, I'm working with musical notes, so I have a global dictionary like this: natural_notes = {'C': 0, 'D': 2,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.