Python Forum
python import module or namespace from namepsace variable ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python import module or namespace from namepsace variable ?
#11
(May-23-2017, 01:45 PM)harun2525 Wrote: @volcano63

can you write a function like function (get_module_from_name_psace) in my first reply

Took me about 5 minutes to figure out -
In [1]: import importlib

In [2]: import robot

In [3]: importlib.import_module('robot.errors')
Out[3]: <module 'robot.errors' from '/usr/local/lib/python3.4/dist-packages/robot/errors.py'>

In [4]: robot.__name__
Out[4]: 'robot'
you most probably don't have robot package, but the principle applies, errors is a module of the robot package
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#12
Importlib is one of the most complicated (if not the most complicated)
if you wish to explore, here's a video by the guy that rewrote it http://pyvideo.org/pycon-us-2013/how-import-works.html
It is complicated by necessity, and was worse before the rewrite.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 432 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,434 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 723 Aug-06-2023, 01:09 AM
Last Post: aupres
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,892 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  import module error tantony 5 3,457 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,082 Sep-21-2022, 01:34 PM
Last Post: snippsat
Question How can I import a variable from another script without executing it ThomasFab 12 7,827 May-06-2022, 03:21 PM
Last Post: bowlofred
  Import a module for use in type hint? Milosz 0 1,489 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,812 Oct-27-2021, 03:32 AM
Last Post: Tek
  'namespace' shorthand for function arguments? shadowphile 5 2,602 Aug-11-2021, 09:02 PM
Last Post: shadowphile

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020