LoginSignup
14
12

More than 5 years have passed since last update.

ファイルが直接呼び出された時にだけ実行するアレ Php/Ruby/Python

Posted at

PHP


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

Ruby


if __FILE__ == $0
  # コード
  some_code
end

Python


if __name__ == '__main__':
    # コード
    some_code()
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12