开发者

Is this the preferred way to detect if the unicode or non-unicode version of cx_oracle was installed?

I have a custom module that's basically a thin wrapper around a database connection with cx_Oracle. I'd like to re-use this module on computers with both the unicode version of cx_Oracle installed, and with the non-unicode version.

To do this, I need to "detect" the version installed. I could "try" making a connection using a string connection descriptor; and if I get a TypeError back, then assume it's the unicode 开发者_如何转开发version installed. This just seems a bit kludgy.

Is there a better/preferred way of doing this?

Thanks.


Using try ... except is a perfectly suitable way to do this kind of detection. The same technique is used to write portable apps using SQLITE that will work on newer 2.7 Python with SQLITE in the library and older 2.4 where SQLITE was an addon module with a more cryptic name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜