Python 运行程序时出错
您可能还有其他错误,但肯定没有声明Python 运行程序时出错,python,python-2.7,python-3.x,Python,Python 2.7,Python 3.x,您可能还有其他错误,但肯定没有声明name,所以 try: import sys # For Python 3.0 and later from urllib.request import urlopen except ImportError: # Fall back to Python 2's urllib2 import sys from urllib2 import urlopen def fetch_words(url): htm
name
,所以
try:
import sys
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
import sys
from urllib2 import urlopen
def fetch_words(url):
html = urlopen(url)
print(html.read())
story_words = []
for line in html:
line_words = line.decode('utf-8').split()
for word in line_words:
story_words.append(word)
return story_words
def print_items(items):
for item in items:
print(item)
def main():
url = sys.argv[1]
words = fetch_words(url)
print_items(words)
if name == '__main__'
main()
会给你带来一个错误。相反,它应该是
if name == 'main'
你需要将问题的格式编辑为代码。你能试一下代码并告诉我那是什么吗error@chichu你是谜语者吗?我是否应该将这些纯文本作为Python代码运行,这样我就可以找出您所遇到的错误?
if __name__ == '__main__'