0
我試圖從同一個文件中的另一個對象獲取最大值和最小值。但它一直返回「對象沒有屬性'max_value'」。有人能告訴我如何獲得對象的每個實例的變量嗎?以下是完整代碼:如何從一個對象的實例獲取變量到同一文件中的另一個對象?
from math import *
from graphics import *
def compute_min_and_max(expression):
#Various constants
print("Evaluating ", expression)
min_value = 1e200
max_value = -1e200
#Gets maximum and minimum for x between 0 and 10
for i in range(0, 1001):
try:
x = i/100.0
y = eval(expression)
min_value = min(y, min_value)
max_value = max(y, max_value)
except Exception:
print("For ", x, " the expression is invalid")
pass
print("Your min and max numbers are *drum roll*...")
return(min_value, max_value)
def compute_min_and_max_for_file(filename):
global_min = 1e200
global_max = -1e200
opened_function_file = open(filename, 'r')
#Gets global max and min
for line in opened_function_file:
compute_min_and_max(line)
global_max = max(compute_min_and_max(line).max_value, global_max)
global_min = min(compute_min_and_max(line).min_value, global_min)
#Closes file, and returns the values
opened_function_file.close()
return (global_min, global_max)
啊,當然。我很累,我看不到那些:P – user7628