python: use different function depending on os

前端 未结 2 1049
孤城傲影
孤城傲影 2021-01-21 05:17

I want to write a script that will execute on Linux and Solaris. Most of the logic will be identical on both OS, therefore I write just one script. But because some deployed str

2条回答
  •  醉酒成梦
    2021-01-21 06:05

    You can do it like this:

    if 'linux' in sys.platform:
        def do_stuff():
            result = # do linux stuff
            more_stuff(result)
    elif 'sun' in sys.platform:
        def do_stuff():
            result = # do solaris stuff
            more_stuff(result)
    

    And then simply call do_stuff().

提交回复
热议问题