runtime-import | 前端资源(js & css)运行时加载工具 | Plugin library
kandi X-RAY | runtime-import Summary
kandi X-RAY | runtime-import Summary
前端资源(js & css)运行时加载工具.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of runtime-import
runtime-import Key Features
runtime-import Examples and Code Snippets
Community Discussions
Trending Discussions on runtime-import
QUESTION
When I enable an interpreter feature in Python 2 with a from __future__ import X
statement (e.g. from __future__ import unicode_literals
), the interpreter behavior changes from there on out.
Is there a way, at runtime, to determine what __future__
pragmas have been enabled at a given point in execution?
The reason I want to do this is that some legacy code I maintain conditionally enables some __future__
pragmas before eval
ing/runtime-importing other arbitrary code. When debugging behavior issues in that code, I want to check whether it's because some of those conditional __future__
imports have been triggered or not. I know that conditionally importing __future__
(or importing it at anything other than the top of an entry point) is an antipattern and have no plans of spreading it; I just want to debug code that does this.
I've tried checking sys.modules
, and using that I can tell that something from __future__
has been imported because the __future__
module shows up in the already-imported list. However, that's just the __future__
module, and the interpreter-behavior changes are not implemented as submodules, so I can't see which have been enabled or not.
ANSWER
Answered 2018-Sep-10 at 15:51You can just look at the top of the file, because __future__
imports are defined there, they can't be anywhere else.
Also the interpreter is not changed globally as you imply. The __future__
changes are only for the modules that have the actual __future__
import in them. So if you have two .py
files in your project, and only one of them has the from __future__ import unicode_literals
, then only that file will have unicode literals. The other file will still have normal literals.
The test below has been executed in python 2.7:
file1.py:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install runtime-import
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page