main

In Python, can I call the main() of an imported module?

In Python, can I call the main() of an imported module? Question: In Python I have a module myModule.py where I define a few functions and a main(), which takes a few command line arguments. I usually call this main() from a bash script. Now, I would like to put everything into a small package, …

Total answers: 7

Running a python package

Running a python package Question: Running Python 2.6.1 on OSX, will deploy to CentOS. Would like to have a package to be invoked from a command line like this: python [-m] tst For that, here is the directory structure made: $PYTHONPATH/ tst/ __init__.py # empty __main__.py # below dep.py # below The following is in …

Total answers: 1

Using module's own objects in __main__.py

Using module's own objects in __main__.py Question: I’m trying to access a module’s data from inside its __main__.py. The structure is as follows: mymod/ __init__.py __main__.py Now, if I expose a variable in __init__.py like this: __all__ = [‘foo’] foo = {‘bar’: ‘baz’} How can I access foo from __main__.py? Asked By: sharvey || Source …

Total answers: 6

PHP equivalent of Python's __name__ == "__main__"?

PHP equivalent of Python's __name__ == "__main__"? Question: As per the title, is there PHP equivalent of __name__ == “__main__”? Is there something that would work for both scripts executed through the command line and through a web request, or would a custom function be needed? For those unfamiliar with Python, __name__ == “__main__” allows …

Total answers: 4

`if __name__ == '__main__'` equivalent in Ruby

`if __name__ == '__main__'` equivalent in Ruby Question: I am new to Ruby. I’m looking to import functions from a module that contains a tool I want to continue using separately. In Python I would simply do this: def a(): … def b(): … if __name__ == ‘__main__’: a() b() This allows me to run …

Total answers: 3

What does if __name__ == "__main__": do?

What does if __name__ == "__main__": do? Question: What does this do, and why should one include the if statement? if __name__ == "__main__": print("Hello, World!") If you are trying to close a question where someone should be using this idiom and isn’t, consider closing as a duplicate of Why is Python running my module …

Total answers: 47