How to call methods inside a class?
Question: I have a test Python class named calc with two methods `add` and `sub`. How
can I run the methods from the python prompt? I am at the python command line
">>>" and typing `import calc`. Then I type `calc.add(5,3)` and get "No module
named 'calc'". File name is `calc.py`.

    
    
    class calc:
    
        def add(x,y):
            answer = x + y
            print(answer)
    
        def sub(x,y):
            answer = x - y
            print(answer)
    


Answer: `calc` is the module name _and_ a class in the module. Use `import calc` and
then refer to the class with `calc.calc`:

`calc.py`:

    
    
    class calc:
    
        def add(self, x, y): # note the use of "self"
            answer = x + y
            print(answer)
    
        def sub(self, x, y):
            answer = x - y
            print(answer)
    

Test script:

    
    
    import calc
    c = calc.calc()
    c.add(5, 3)
    

Several modules in the standard library exhibit this naming scheme, such as
`pprint`, `time`, and `datetime`.

