How can I execute the below simple script called foo.py from the (bash) command line?
def hello():
return 'Hi :)'
I tried the following and got an error.
$ python -c 'import foo; print foo.hello()'
File "<string>", line 1
import foo; print foo.hello()
^
SyntaxError: invalid syntax
I'm able to execute the following but just receive no output.
$ python foo.py
$
CodePudding user response:
print foo.hello()
Is this Python2?
remove that print before function call:
$ python -c 'import foo; foo.hello()'
Or make it like python3 syntax:
$ python -c 'import foo; print(foo.hello())'
CodePudding user response:
If you're using python 2.x, use:
import foo; print foo.hello()
However, on python 3.x brackets are required:
import foo; print(foo.hello())
CodePudding user response:
maybe your Python version is 3.x
On Python3 print should have "()"
you can try
print(foo.hello())
