[python] 'module' object is not callable - calling method in another file

I have a fair background in java, trying to learn python. I'm running into a problem understanding how to access methods from other classes when they're in different files. I keep getting module object is not callable.

I made a simple function to find the largest and smallest integer in a list in one file, and want to access those functions in another class in another file.

Any help is appreciated, thanks.

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' )

This question is related to python import module

The answer is


  • from a directory_of_modules, you can import a specific_module.py
  • this specific_module.py, can contain a Class with some_methods() or just functions()
  • from a specific_module.py, you can instantiate a Class or call functions()
  • from this Class, you can execute some_method()

Example:

#!/usr/bin/python3
from directory_of_modules import specific_module
instance = specific_module.DbConnect("username","password")
instance.login()

Excerpts from PEP 8 - Style Guide for Python Code:

Modules should have short and all-lowercase names.

Notice: Underscores can be used in the module name if it improves readability.

A Python module is simply a source file(*.py), which can expose:

  • Class: names using the "CapWords" convention.

  • Function: names in lowercase, words separated by underscores.

  • Global Variables: the conventions are about the same as those for Functions.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to import

Import functions from another js file. Javascript The difference between "require(x)" and "import x" pytest cannot import module while python can How to import an Excel file into SQL Server? When should I use curly braces for ES6 import? How to import a JSON file in ECMAScript 6? Python: Importing urllib.quote importing external ".txt" file in python beyond top level package error in relative import Reading tab-delimited file with Pandas - works on Windows, but not on Mac

Examples related to module

How to fix: fatal error: openssl/opensslv.h: No such file or directory in RedHat 7 How to import functions from different js file in a Vue+webpack+vue-loader project Typescript ReferenceError: exports is not defined ImportError: No module named tensorflow ModuleNotFoundError: What does it mean __main__ is not a package? ES6 modules in the browser: Uncaught SyntaxError: Unexpected token import module.exports vs. export default in Node.js and ES6 What's the difference between an Angular component and module Export multiple classes in ES6 modules Python - Module Not Found