I have these two functions:
JavaScript
x
19
19
1
def check_channel_number(self):
2
print "***************Channel Checker *********************"
3
print ''
4
user_channel_number = int(re.sub('D', '', raw_input("Enter a channel number, (3digit): "))[:3]);
5
channel = ("channelNr= '%d'") % (user_channel_number)
6
print channel
7
# channel_search = channel + str(user_channel_number)
8
datafile = file('output.txt')
9
10
found = False
11
for line in datafile:
12
if channel in line:
13
found = True
14
print 'The channel number you entered is correct and will be deleted'
15
return user_channel_number
16
17
print 'The channel number you entered is not on the planner'
18
return False
19
and
JavaScript
1
19
19
1
def delete_events(self):
2
if user_channel_number == True:
3
return 'The program number is correct and will be deleted'
4
5
# action = 'DeleteEvent'
6
menu_action = 'all'
7
book = 'RECYC:687869882'
8
arg_list = [('C:\Users\yke01\Documents\StormTest\Scripts\Completed'
9
'\Utils\UPNP_Client_Cmd_Line.py')]
10
arg_list.append(' --action=')
11
arg_list.append(action)
12
arg_list.append(' --ip=')
13
arg_list.append('10.10.8.89')
14
arg_list.append(' --objectId=')
15
arg_list.append(book)
16
subprocess.call(["python", arg_list])
17
18
print 'The program deleted successfully'
19
When I run my script, it says that user_channel_number
is not defined globally. How can I use user_channel_number
inside the delete_events
function?
Advertisement
Answer
Functions can not share their local variables. You can return the value from the first and pass it to the second:
JavaScript
1
8
1
def check_channel_number(self):
2
3
return user_channel_number
4
5
def delete_events(self):
6
user_channel_number = self.check_channel_number()
7
8
Or save value on the object:
JavaScript
1
9
1
def check_channel_number(self):
2
3
self.user_channel_number = user_channel_number
4
5
6
def delete_events(self):
7
if self.user_channel_number:
8
.
9