我在java方面有相当的背景,正在尝试学习python。当其他类位于不同的文件中时,我在理解如何访问其他类的方法时遇到了问题。我不断收到模块对象不可调用。
我做了一个简单的函数来查找一个文件的列表中的最大和最小整数,并希望在另一个文件的另一个类中访问这些函数。
任何帮助表示赞赏,谢谢。
class findTheRange():
def findLargest(self, _list):
candidate = _list[0]
for i in _list:
if i > candidate:
candidate = i
return candidate
def findSmallest(self, _list):
candidate = _list[0]
for i in _list:
if i < candidate:
candidate = i
return candidate
import random
import findTheRange
class Driver():
numberOne = random.randint(0, 100)
numberTwo = random.randint(0,100)
numberThree = random.randint(0,100)
numberFour = random.randint(0,100)
numberFive = random.randint(0,100)
randomList = [numberOne, numberTwo, numberThree, numberFour, numberFive]
operator = findTheRange()
largestInList = findTheRange.findLargest(operator, randomList)
smallestInList = findTheRange.findSmallest(operator, randomList)
print(largestInList, 'is the largest number in the list', smallestInList, 'is the smallest number in the list' )