开发者

How to detect in Iron Python what the script is being called from?

开发者 https://www.devze.com 2023-03-10 04:47 出处:网络
I have a ipy script that can be called either from an embedded console in a larger application or directly from the command line and I\'m looking for a quick way to determine at run time which has occ

I have a ipy script that can be called either from an embedded console in a larger application or directly from the command line and I'm looking for a quick way to determine at run time which has occurred without ha开发者_运维技巧ving to pass an argument to differentiate the events.

Additionally the script has to run on both mono/linux and .net/windows.

Thanks in advance for any assistance.


You could use System.AppDomain.CurrentDomain.GetAssemblies() (assuming you don't use AppDomain isolation, of course) and see if that contains an assembly that would only be preset when your application is running.


It might depend on the way you run the embedded code, but the common way to check if a script is run from command line is:

if __name__=='__main__': ....

That should work also in your case. Regarding the platform check sys.platform.

0

精彩评论

暂无评论...
验证码 换一张
取 消