
Feb. 21, 2023
6:15 p.m.
On 2023-02-21 11:26, Steven D'Aprano wrote: [snip]
If your code blocks are a single statement, you can write:
try: import windows_module except ImportError: import unix_module
but most people will say that is ugly and be spread out:
try: import windows_module except ImportError: import unix_module
I can think of one use-case. Suppose this: try: import windows_module as module except ImportError: import unix_module as module could be shortened to this: import windows_module else unix_module as module Not that I'm in favour of it, because it occurs too rarely to be worth a special syntax. [snip]