Python在返回变量值时遇到问题
当我运行第一个函数时,它会打印正确的URL。但是,当我运行第二部分时,它显示一个错误,表示未定义fullurl 有人能帮我吗 这是我的密码:Python在返回变量值时遇到问题,python,function,python-3.x,return,Python,Function,Python 3.x,Return,当我运行第一个函数时,它会打印正确的URL。但是,当我运行第二部分时,它显示一个错误,表示未定义fullurl 有人能帮我吗 这是我的密码: def urlmaker(format_mtg): fullurl = url + format_mtg.get() + "-constructed-league-" + date.get() #adds the users options to the url print(fullurl) return fullurl def
def urlmaker(format_mtg):
fullurl = url + format_mtg.get() + "-constructed-league-" + date.get() #adds the users options to the url
print(fullurl)
return fullurl
def htmltotxt(fullurl):
print(fullurl)
response = urllib.request.urlopen(fullurl) #requests the ability to open the website, which magic.wizards.com allows
html = response.read() #reads the html data from the open website
html = str(html) #saves the data as a string
make_lists(card_name_regex, card_number_regex, card_number_list, html)
您的代码没有注释,并且具有适当的缩进和间距:
def urlmaker(format_mtg):
fullurl = url + format_mtg.get() + "-constructed-league-" + date.get()
print(fullurl)
return fullurl
def htmltotxt(fullurl):
print(fullurl)
response = urllib.request.urlopen(fullurl)
html = response.read()
html = str(html)
make_lists(card_name_regex, card_number_regex, card_number_list, html)
urllib
url
,日期
,卡号\正则表达式
,卡号\正则表达式
,卡号\列表
<代码>日期甚至可能不是变量,而是导入的内容。定义它们的值或给出一个示例值,以便我们重现您的错误format\u mtg
和fullurl
参数的值。我可以推断,您使用的是第一个函数的结果作为第二个函数的参数,但仍然是format\u mtg
如果没有这四样东西,我们就找不到您的问题。请使用空格。Python不按字符收费。另外,显示实际的完整错误和回溯。您发布的代码中没有任何内容会给出该错误。您没有显示如何调用这些函数。请也包括在内。另外,请检查缩进。