我对python不太了解。我想开始研究项目,设置说明说:
pip install -r requirements-dev.txt
简单的恩赐。问题是我得到了这个:
Downloading/unpacking gunicorn==0.13.4 (from -r requirements.txt (line 7))
Running setup.py egg_info for package gunicorn
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-root/gunicorn/setup.py", line 18, in <module>
long_description = file(
NameError: name 'file' is not defined
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-root/gunicorn/setup.py", line 18, in <module>
long_description = file(
NameError: name 'file' is not defined
我不明白这个问题。也许有人可以帮忙吗?
我在Arch Linux上运行它,python默认为python 3,项目不是python 3,但我不确定是不是这样。
感谢。
答案 0 :(得分:115)
file()
改用open()
;见Built-in Functions - open()。
答案 1 :(得分:6)
您的项目似乎是用Python编写的&lt; 3.这是因为file()
内置函数is removed in Python 3。尝试使用Python 2to3 tool或edit the erroneous file yourself。
Gunicorn需要Python 2.x&gt; = 2.5。 计划使用Python 3.x支持。
答案 2 :(得分:3)
文件未在Python3中定义,您显然正在使用它。您正在安装的软件包不适合Python 3,相反,您应该安装Python 2.7并重试。
请参阅:http://docs.python.org/release/3.0/whatsnew/3.0.html#builtins
答案 3 :(得分:0)
要解决此错误,只需添加import sys
students = {}
polling_active = True
while polling_active:
name = input("enter your name: ")
score = int(input("enter your score: "))
students[name] = score
repeat = input("would you like to add another student?" "(yes/no)")
if repeat == 'no':
polling_active = False
print ("-------RESULT-------")
#We will use totalScore for keeping all students score summation.
#Initaly total score is 0.
totalScore = 0
#For getting lowest score student name, we need lowest score first.
#Initaly we don't know the lowest score. So we are assuming lowest score is maximum Int value
lowestScore = sys.maxsize
#We also need to store student name. We can use lowestScoreStudentName variable for storing student name with lowest score
#Initaly we don't know the student name. So we initialize it as an empty student list.
lowestScoreStudentName = []
#For getting maximum score student name, we need maximum score first.
#Initaly we don't know the maximum score. So we are assuming lowest score is minimum Int value
maximumScore = -sys.maxsize - 1
#We also need to store student name. We can use maximumScoreStudentName variable for storing student name with maximum score
#Initaly we don't know the student name. So we initialize it as an empty student list.
maximumScoreStudentName = []
for name, score in students.items():
totalScore = totalScore + score
print(name, "your score is: ", score )
if lowestScore > score:
lowestScore = score
#Making student list empty, since score is lower than before
lowestScoreStudentName = []
lowestScoreStudentName.append(name)
elif lowestScore == score:
#keeping all students in the list who gets lowest score
lowestScoreStudentName.append(name)
if maximumScore < score:
maximumScore = score
#Making student list empty, since score is higher than before
maximumScoreStudentName = []
maximumScoreStudentName.append(name)
elif maximumScore == score:
#keeping all students in the list who gets highest score
maximumScoreStudentName.append(name)
total_sum = sum(list(students.values()))
average_sum = totalScore/len(students)
print("Average score : " + str(average_sum))
print("Lowest Score holder students name: " + str(lowestScoreStudentName))
print("Highest score holder students name: " + str(maximumScoreStudentName))
在您的代码中!