Using Python Functions in Terminal
Question: I'm just starting to learn Python and I'm having a hard time testing things
out in the terminal. What I want to do is simply run a pre-written Python
method in the Python interpreter. (I know how to run it by doing python
file_name.py, but I want to run it in the interpreter itself).

So if I for example had the file "exampleModule.py":

    
    
    def exampleFunc(data):
        print(data)
    

Then in the terminal I run Python and do:

    
    
    Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import exampleModule
    >>> exampleFunc('Hello')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'exampleFunc' is not defined
    

The thing that I don't get about this is that if I run the module in the
Python IDLE, I can access the exampleFunc, but not in the terminal
interpreter.

Thanks!


Answer: When you do

    
    
    import exampleModule
    

you have to write the full name of its functions. According to the
[Docs](https://docs.python.org/2/tutorial/modules.html)*,

> This does not enter the names of the functions defined in **exampleModule**
> directly in the current symbol table; it only enters the module name
> **exampleModule** there. Using the module name you can access the functions

If you want to write only the function name, do

    
    
    from exampleModule import *
    

As, according to the [Docs](https://docs.python.org/2/tutorial/modules.html)*

> This does not introduce the module name from which the imports are taken in
> the local symbol table (so in the example, **exampleModule** is not
> defined).

**changed the function name to yours for better understading.*

