I am trying to understand why a __main__.py
file could be run from shell issuing
python .
within the folder where said file is located.
How does this work? What does the .
stand for, and why is not the file name needed?
Where is the dot coming from?. Given a bash script, say
#!/bin/bash
#Dummy bash script
echo "This is a dummy bash script"
saved as dummy_bash_script
.
I could run it, opening a terminal from the folder where it is located, issuing
$ ./dummy_bash_script
providing hence an explicit path (./
). Are the two dots related? Does the dot in python .
indicate anything about the current directory? If yes, where is the backslash gone?
Another use for the .
(dot) in bash is as a shortcut for source
, but I fail to see any connection.
And why is not the file name needed, in python .
? I understand as a file is ran as a script "somewhere under the bonnet" it is assigned the name "main". That is, the special variable __name
gets an assignment, __name__ = "__main__"
.
But how does this exactly work as a __main__
file is executed as script using the dot, i.e. how can this file be ran with python .
, without file name?
Thanks