Skip to content
Advertisement

Call a function from the console as an argument

I have a file1.py:

JavaScript

Now I want to call file1.battery() from the linux console with python file1.py battery.

But I get the error:

JavaScript

Advertisement

Answer

You can use eval for compiling string like code or use globals and locals:

JavaScript

Also, the module can import itself:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement