How to get the caller script name

后端 未结 4 1223
天命终不由人
天命终不由人 2020-12-19 14:44

I\'m using Python 2.7.6 and I have two scripts:

outer.py

import sys
import os

print \"Outer file launching...\"
os.system(\'inner.py\')
4条回答
  •  执念已碎
    2020-12-19 15:03

    If applicable to your situation you could also simply pass an argument that lets inner.py differentiate:

    import sys
    import os
    
    print "Outer file launching..."
    os.system('inner.py launcher')
    

    innter.py

    import sys
    import os
    
    try:
        if sys.argv[0] == 'launcher':
            print 'outer.py called us'
    except:
        pass
    

提交回复
热议问题