我有兩個函數中的返回值。請參閱下面的功能;使用其他功能
def check_channel_number(self):
print "***************Channel Checker *********************"
print ''
user_channel_number = int(re.sub('\D', '', raw_input("Enter a channel number, (3digit): "))[:3]);
channel = ("channelNr= '%d'") % (user_channel_number)
print channel
# channel_search = channel + str(user_channel_number)
datafile = file('output.txt')
found = False
for line in datafile:
if channel in line:
found = True
print 'The channel number you entered is correct and will be deleted'
return user_channel_number
print 'The channel number you entered is not on the planner'
return False
只是想在下面的函數中使用(user_channel_number)的返回值。
def delete_events(self):
if user_channel_number == True:
return 'The program number is correct and will be deleted'
# action = 'DeleteEvent'
menu_action = 'all'
book = 'RECYC:687869882'
arg_list = [('C:\\Users\\yke01\\Documents\\StormTest\\Scripts\\Completed'
'\\Utils\\UPNP_Client_Cmd_Line.py')]
arg_list.append(' --action=')
arg_list.append(action)
arg_list.append(' --ip=')
arg_list.append('10.10.8.89')
arg_list.append(' --objectId=')
arg_list.append(book)
subprocess.call(["python", arg_list])
print 'The program deleted successfully'
當我運行我的腳本時,它說user_channel_number
沒有全局定義?如何在delete_events()
函數中調用user_channel_number
?
1.類型強制轉換'user_channel_number'到'int',然後嘗試把它比作'真'。 2.「check_channel_number」總是返回false。 3.您的'delete_events'中的return語句會在運行之後停止所有代碼。看起來你在上課?您可以定義'self.user_channel_number'使其可以訪問您所在類中的所有方法。 – Signal