Dictionary or If statements, Jython

前端 未结 5 569
清酒与你
清酒与你 2021-01-06 06:04

I am writing a script at the moment that will grab certain information from HTML using dom4j.

Since Python/Jython does not have a native switch stat

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 06:24

    With your code you're running your functions all get called.

    handlers = {
    'extractTitle': extractTitle, 
    'extractMetaTags': extractMetaTags
    }
    
    handlers[type](dom)
    

    Would work like your original if code.

提交回复
热议问题