Are Php / Ruby / Python that only runs when the file is called directly

PHP


if (realpath($argv[0]) == __FILE__) {
	#code
	some_code();    
}

Ruby


if __FILE__ == $0
  #code
  some_code
end

Python


if __name__ == '__main__':
    #code
    some_code()

Recommended Posts

Are Php / Ruby / Python that only runs when the file is called directly
[Beginners are worried] Which is better, Ruby, PHP or Python?
Import modules that are often used when starting the python interpreter
Workaround for the problem that sys.argv is not passed when executing a Python script with only the file name in Python2.7 on Windows
Avoiding the phenomenon that blank lines are inserted when outputting Python CSV
[Comparison of PHP, Ruby, and Python description] For those who are wondering how the description method is different.
When Selenium tells me that the Chrome driver version is different (Python)
Find out the name of the method that called it from the method that is python
[Python] Solution to the problem that elements are linked when copying a list
This is the only basic review of Python ~ 1 ~
This is the only basic review of Python ~ 2 ~
This is the only basic review of Python ~ 3 ~
There is a pattern that the program did not stop when using Python threading
The timing when the value of the default argument is evaluated is different between Ruby and Python.
Note that writing like this with ruby is writing like this with python
The Blender script (2.8) that erases only the skirt is completed
Find the part that is 575 from Wikipedia in Python
Embedding in datetime when only the time is known
Python program that looks for the same file name
PHP and Python samples that hit the ChatWork API
Use a macro that runs when saving python with vscode
How to deal with the problem that the current directory moves when Python is executed from Atom
Workaround for the problem that? Is displayed when checking the version when using non-standard perl | python with pkg version