Using Functions from Other .py Files
Question: So I'm very new to Python and programming in general. I've run into an issue
with my text game. I'm trying to create a function (pretty sure 'def (name) is
a function, right?)in a .py called 'locationMenu' and use it in my main game
file. Here is the start of my locationMenu.py (the rest is simply prints and
if/elif/else statements.

    
    
    from main import Engine, Hallway, Canteen, Bedroom, Room
    
    class locationsMenu():
        def locationMenu(self):
    

and here is the place in my main game file where I am trying to use the
'locationMenu' function that I just created.

    
    
        locationMenu()
    

That is just one line after I made a choice with input, etc. but now I would
like to skip to the locationMenu that is in the other file.

Any help much appreciated. Please don't use "big words" because as I said I'm
still very new to programming in general.


Answer: `locationMenu()` is an instance method of the `locationsMenu()` class, so
you'd need to create an instance and call the method on it, something like:

    
    
    from locationMenu import locationsMenu
    
    my_menu = locationsMenu()       #  Create a new object
    my_menu.locationMenu()          #  Call its instance method
    

If you were to just try `locationsMenu.locationMenu()` then you'd get
something like this error:

    
    
    Traceback (most recent call last):
      File "./prog.py", line 3, in <module>
        locationsMenu.locationMenu()
    TypeError: locationMenu() missing 1 required positional argument: 'self'
    

because `locationMenu()` is not a class method, and you're trying to call it
in the absence of a `locationsMenu` object.

If you don't want it inside a class at all, then make it a regular function,
and do:

`locationMenu.py`:

    
    
    from main import Engine, Hallway, Canteen, Bedroom, Room
    
    def locationMenu():
        print("In function locationMenu()")
    

`prog.py`:

    
    
    from locationMenu import locationMenu
    
    locationMenu()
    

