473,616 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

global name is not defined

I'm getting an error msg I don't understand, "global name EMR_globals
is not defined", and could use some help.

I've separated the application I'm building into several modules. One
of the modules holds variables I need to pass from one module to
another and is called 'EMR_globals'. Several other modules hold
functions or user menus and then 'EMR_main' controls the initial user
interaction. I'm using MySQL to hold the data.

The initial connection to the database is done by 'EMR_main'.
Functions then define and close a cursor for various queries. The
connection variable, 'conn', is defined 'conn = "" ' in EMR_globals
and then used in EMR_main. Unfortunately when a module.function
attempts to use it I get the error msg.

Here is the source of the error, module 'name_lookup':

def name_find(namef rag):

cursor = EMR_globals.con n.cursor(MySQLd b.cursors.DictC ursor)
cursor.execute( "SELECT patient_ID, firstname, lastname FROM
demographics WHERE lastname LIKE '%s%%'" % (namefrag))

results = cursor.fetchall ()

for index, row in enumerate(resul ts):
print "%d %s %s %s" % (index, row["patient_ID "],
row["firstname"], row["lastname"])

indx = int(raw_input(" Select the record you want: "))
results_list = list(results)
a = str(results_lis t[indx]['patient_ID'])
print 'You have chosen patient ID # ' + a

cursor.execute( "SELECT * FROM demographics WHERE patient_ID = %s"
% (a,))
selected_pt = cursor.fetchall ()
# if this query returns more than one record the following code will
fail I think
print menus.menu_demo graphics(select ed_pt['firstname'],
selected_pt['lastname'],
selected_pt['address'],
selected_pt['city'],
selected_pt['state'],
selected_pt['zipcode'],
selected_pt['phonenumber'])
print menus.menu_pt_r ecord

cursor.close()
Thanks for any help. Mike

Nov 6 '07 #1
3 11502
En Tue, 06 Nov 2007 18:57:12 -0300, barronmo <ba******@gmail .comescribió:
I'm getting an error msg I don't understand, "global name EMR_globals
is not defined", and could use some help.

I've separated the application I'm building into several modules. One
of the modules holds variables I need to pass from one module to
another and is called 'EMR_globals'. Several other modules hold
functions or user menus and then 'EMR_main' controls the initial user
interaction. I'm using MySQL to hold the data.
Global variables usually are not a good design decision, but that's not
your current problem.
The initial connection to the database is done by 'EMR_main'.
Functions then define and close a cursor for various queries. The
connection variable, 'conn', is defined 'conn = "" ' in EMR_globals
and then used in EMR_main. Unfortunately when a module.function
attempts to use it I get the error msg.
In Python, "global" means "global to the module". If conn is defined in
EMR_globals, when you want to use it elsewhere, you can:

a)
from EMR_globals import conn
....
cursor = conn.cursor(... )

b)
import EMR_globals
....
cursor = EMR_globals.con n.cursor(...)

Usually those import statements are placed at the top of the module.
cursor.execute( "SELECT * FROM demographics WHERE patient_ID = %s"
% (a,))
selected_pt = cursor.fetchall ()
# if this query returns more than one record the following code will
fail I think
print menus.menu_demo graphics(select ed_pt['firstname'],
selected_pt['lastname'], ...
I think it will fail even with one record, because fetchall() returns a
list of rows. Try using fetchone(). Anyway, if patient_ID is the primary
key, you should always get a single row.

--
Gabriel Genellina

Nov 6 '07 #2
Looks like you forgot to import EMR_globals, EMR_main, etc.
-----Original Message-----
From: py************* *************** *************@p ython.org
[mailto:py****** *************** *************** *****@python.or g
] On Behalf Of barronmo
Sent: Tuesday, November 06, 2007 2:57 PM
To: py*********@pyt hon.org
Subject: global name is not defined

I'm getting an error msg I don't understand, "global name EMR_globals
is not defined", and could use some help.

I've separated the application I'm building into several modules. One
of the modules holds variables I need to pass from one module to
another and is called 'EMR_globals'. Several other modules hold
functions or user menus and then 'EMR_main' controls the initial user
interaction. I'm using MySQL to hold the data.

The initial connection to the database is done by 'EMR_main'.
Functions then define and close a cursor for various queries. The
connection variable, 'conn', is defined 'conn = "" ' in EMR_globals
and then used in EMR_main. Unfortunately when a module.function
attempts to use it I get the error msg.

Here is the source of the error, module 'name_lookup':

def name_find(namef rag):

cursor = EMR_globals.con n.cursor(MySQLd b.cursors.DictC ursor)
cursor.execute( "SELECT patient_ID, firstname, lastname FROM
demographics WHERE lastname LIKE '%s%%'" % (namefrag))

results = cursor.fetchall ()

for index, row in enumerate(resul ts):
print "%d %s %s %s" % (index, row["patient_ID "],
row["firstname"], row["lastname"])

indx = int(raw_input(" Select the record you want: "))
results_list = list(results)
a = str(results_lis t[indx]['patient_ID'])
print 'You have chosen patient ID # ' + a

cursor.execute( "SELECT * FROM demographics WHERE patient_ID = %s"
% (a,))
selected_pt = cursor.fetchall ()
# if this query returns more than one record the following code will
fail I think
print menus.menu_demo graphics(select ed_pt['firstname'],
selected_pt['lastname'],
selected_pt['address'],
selected_pt['city'],
selected_pt['state'],
selected_pt['zipcode'],
selected_pt['phonenumber'])
print menus.menu_pt_r ecord

cursor.close()
Thanks for any help. Mike

--
http://mail.python.org/mailman/listinfo/python-list
Nov 6 '07 #3
Thanks, seems to be fixed with importing MySQLdb, menus, EMR_main, etc
in the Name_find module. Is there a better way to do things? I
thought I was avoiding using global variables by putting the shared
ones in their own module.

Thanks for the help.

Mike

Nov 7 '07 #4

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

Similar topics

3
6430
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the point of declaration of this variable, correct?): static const char * g_application_name = "Tiny, class-based MDI Example"; In another source file, I'm including the header globals.hpp and I'm using the variable g_application_name. I do,...
11
2547
by: Capstar | last post by:
Hi, I am working on an application, which will run embedded without an OS. The app is build up out of a couple of well defined parts. At first I wanted to keep those parts seperated and use opaque data types to transfer information in between them. At some stage I was stuck and needed to make a variable global, and I also needed to make the struct declaration public to some other parts. Looking through the code I found out that lots...
3
7132
by: Anjali Lourda | last post by:
Hi, I have defined a function in global.asax file. Could somebody please tell me how i am supposed to call that function from the other files of the same project. Global.asax public function getName() as String dim name as string name = "Abc" return name end function
12
2213
by: a | last post by:
def fn(): for i in range(l) global count count= .... how do i declare count to be global if it is an array subsequently i should access or define count as an array error:
8
13189
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
1
29337
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
2
23744
by: pythonnewb | last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was planning to then create a program to detect input and use this module, but I am hung up. I have constructed the code that I thought would work (though there may be a better way) and I got this error message. Traceback (most recent call last): File...
0
1435
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no* program wide globals. There are only module wide globals. Also, the "global isglobal" is absolutely meaningless as anything declared there is a (module level) global by definition.
4
5988
by: RgeeK | last post by:
I have a main module doStuff.py and another module utility.py. At the start of doStuff.py I call import utility.py Then I also proceed to initiallize some global variables sName = "" Then I create a class, some methods etc. In one of the methods I assign
0
8199
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
8642
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
8592
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
8448
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
7118
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
6097
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
4060
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2576
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
0
1439
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.