python - How to offer platform-specific implementations of a module? -
I need to create a function in a module platform - without changing any of the files importing it, many By implementing it. The following tasks:
do_it = getattr (__ import __ (__name__), "do_on_" + sys.platform)
... but if module Breaks are put in a package.
There will be an option if do_it () with hard work calls for other alihaff others.
Anything better?
use globals () ['do_on_' + forum] < Call code> getattr instead, and your original idea should work whether it is inside the package or not.
Comments
Post a Comment