I have this code in myname.py
:
# myname.py
def get_name():
return "Jim"
and this in hello.py
:
# hello.py
import myname
name = myname.get_name()
print("hello {}".format(name))
When I try to execute hello.py
in the MINGW64 shell, this error happens:
b2b@DESKTOP-5QEK604 MINGW64 ~/Desktop/Python moje projekty/Dev/apiarena_django/git (master)
$ ./hello.py
./hello.py: line 2: import: command not found
./hello.py: line 4: syntax error near unexpected token `('
./hello.py: line 4: `name = m.get_name()'
How do I fix the problem?
To run a Python script as a command, without using the "python" command, your first line has to tell the system what interpreter to use. This is called a "she-bang" line. You can either type "python hello.py" or replace the first line with:
#! /usr/bin/env python
As it is, the system is trying to run your command as a bash script. There is no "import" command in bash.