Skip to main content

No more if else code

Project description

No more if else code

  • 示例一
from NoIf import handle_base


@handle_base.register('strategy_test')
def strategy_1():
    print('strategy_1')


@handle_base.register('strategy_test')
def strategy_2():
    print('strategy_2')

if __name__ == '__main__':
    strategy = handle_base.invoke('strategy_test', 'strategy_1')
    strategy()

  • 示例二
from NoIf import handle_base


class Strategy(object):
    pass


@handle_base.register(Strategy)
class Strategy1(Strategy):

    def test(self):
        print('strategy_1')


@handle_base.register(Strategy)
class Strategy2(Strategy):

    def test(self):
        print('strategy_2')


if __name__ == '__main__':
    strategy_handle = handle_base.invoke(Strategy, 'Strategy1')
    handle = strategy_handle()
    handle.test()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NoIf-0.5.0.tar.gz (2.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page