私は2つのpythonファイルを扱っています。私が行っていたら、私は別のから1を呼び出すために計画します。if __name__ == "__main__" on Imports
main.py
import os, re, time, logging, sys, subprocess, operator, datetime, pprint, dbfread, collections, calendar, xlwt, xlrd, errno, platform, stat
import subfile
# A long body of codes that does things
subfile.py
import os, re, time, logging, sys, subprocess, operator, datetime, pprint, dbfread, collections, calendar, xlwt, xlrd, errno, platform, stat
# Another long body of codes that does things
私はmain.pyを呼び出す場合、私はそれがまたsubfile.py
を実行することを期待します。場合によっては、私はsubfile.py
を別々に実行し、それ自体が正常に動作するようにしたいと考えています。今、subfile.py
に、if __name__ == "__main__"
の下にインポートコマンドをネストする必要がありますか?
subfile.py
if __name__ == "__main__":
import os, re, time, logging, sys, subprocess, operator, datetime, pprint, dbfread, collections, calendar, xlwt, xlrd, errno, platform, stat
# Another long body of codes that does things