Python Forum

Full Version: [Solved] Import syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

on https://docs.python.org/3/library/concur...or-example

we can see import concurrent.futures

is that exactly the same as from concurrent import futures

or there a difference beside the syntax ? (speed, security, options availables etc.. ?)

Thanks.
(Dec-28-2022, 06:46 AM)SpongeB0B Wrote: [ -> ]is that exactly the same
The only difference is that after import concurrent.futures, the name 'concurrent' will be in the current namespace, while after from concurrent import futures, it is the name 'futures' that appears in the current namespace.
Type "help", "copyright", "credits" or "license" for more information.
>>> import concurrent.futures
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'concurrent']
>>> 
vs
Type "help", "copyright", "credits" or "license" for more information.
>>> from concurrent import futures
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'futures']
>>>