This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年02月04日 01:23 by arupchakrav, last changed 2022年04月11日 14:57 by admin.
| Messages (8) | |||
|---|---|---|---|
| msg210171 - (view) | Author: Arup Chakravarty (arupchakrav) | Date: 2014年02月04日 01:23 | |
Have a built-in mechanism to display all available import libraries within the interpreter. Like what is available through the built-in dir function. |
|||
| msg210172 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2014年02月04日 01:33 | |
>>> import sys >>> sys.modules.keys() ['google', 'copy_reg', 'sre_compile', '_sre', 'encodings', 'site', '__builtin__', 'sysconfig', '__main__', 'encodings.encodings', 'abc', 'posixpath', '_weakrefset', 'errno', 'encodings.codecs', 'sre_constants', 're', '_abcoll', 'types', '_codecs', 'encodings.__builtin__', '_warnings', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'warnings', 'UserDict', 'encodings.utf_8', 'sys', 'codecs', 'readline', 'os.path', 'signal', 'traceback', 'linecache', 'posix', 'encodings.aliases', 'exceptions', 'sre_parse', 'os', '_weakref'] |
|||
| msg210173 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年02月04日 03:04 | |
This is not what the OP asked, AFAICT. sys.modules is just the set of currently imported modules, not all potentially importable modules. |
|||
| msg210174 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2014年02月04日 03:26 | |
I guess I have no idea what the OP is asking for then. dir() certainly only gives immediately available builtins. |
|||
| msg210178 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2014年02月04日 06:06 | |
+1 for the OP's original idea (something like a dir_modules() function that lists out all possible imports). I think something like this must already be present in some of the Python front-ends such as ipython and bpython. That is how they support tab-completion for imports: In [1]: import co code codeop colorsys compileall contextlib copy codecs collections commands compiler cookielib copy_reg In [1]: import re re readline repr requests resource reverend rexec |
|||
| msg210238 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2014年02月04日 15:00 | |
The trick would be how to query finders to say "what could you find?" There is no API for that so either something pragmatic that won't work in the face of e.g. zipfiles would need to be used or a new optional API on finders to list what the tail name of modules it can find are (but without the package name as most finders just use fullname.rpartition('.')[-1] to figure out what they are looking for).
|
|||
| msg226682 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年09月10日 05:41 | |
I wrote some code that does something like this for a hacky custom readline completer. See the import_list() method at <https://github.com/vadmium/etc/blob/6ac333f/python/pythonstartup.py#L222>. It looks like I’m using a combination of "sys.builtin_module_names" and pkgutil.iter_modules(), with a whole lot of compatibility and bug workarounds. |
|||
| msg364554 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2020年03月18日 18:39 | |
When a replacement for pkgutil.walk_packages() is added to importlib to work appropriately with the import system then this should be doable. See https://bugs.python.org/issue19939 for work to replace pkgutil as appropriate. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:58 | admin | set | github: 64705 |
| 2020年03月18日 18:39:54 | brett.cannon | set | nosy:
- brett.cannon |
| 2020年03月18日 18:39:49 | brett.cannon | set | messages: + msg364554 |
| 2014年09月10日 05:41:44 | martin.panter | set | nosy:
+ martin.panter messages: + msg226682 |
| 2014年02月04日 15:00:54 | brett.cannon | set | messages: + msg210238 |
| 2014年02月04日 06:06:36 | rhettinger | set | status: closed -> open priority: normal -> low versions: + Python 3.5, - Python 2.7 nosy: + brett.cannon, rhettinger messages: + msg210178 resolution: rejected -> |
| 2014年02月04日 03:26:46 | benjamin.peterson | set | messages: + msg210174 |
| 2014年02月04日 03:04:56 | pitrou | set | nosy:
+ pitrou messages: + msg210173 |
| 2014年02月04日 01:33:20 | benjamin.peterson | set | status: open -> closed nosy: + benjamin.peterson messages: + msg210172 resolution: rejected |
| 2014年02月04日 01:23:14 | arupchakrav | create | |