Skip to content

Commit 1c693b6

Browse files
committed
Python note: check module existence
1 parent 0ae8486 commit 1c693b6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ import uuid
237237
print(base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes))
238238
----
239239

240+
=== Determining if a module exists
241+
242+
[source,python,linenums]
243+
----
244+
try:
245+
__import__("libcloud")
246+
print("A module")
247+
except ImportError:
248+
print("Not a module")
249+
----
250+
240251
== FAQs
241252

242253
=== Why global interpreter lock (GIL) in CPython?

0 commit comments

Comments
 (0)