python-exec

Import python module over the internet/multiple protocols or dynamically create module

梦想的初衷 提交于 2019-12-18 16:50:38
问题 Is it possible to import a Python module from over the internet using the http ( s ), ftp , smb or any other protocol? If so, how? If not, why? I guess it's about making Python use more the one protocol(reading the filesystem) and enabling it to use others as well. Yes I agree it would be many folds slower, but some optimization and larger future bandwidths would certainly balance it out. E.g.: import site site.addsitedir("https://bitbucket.org/zzzeek/sqlalchemy/src

Python: Is exec always bad practice and if so why not deprecated [closed]

浪尽此生 提交于 2019-12-12 14:38:32
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Can someone think of an example with good practice that uses exec? If there is always a more efficient and secure way to replace exec, why python doesn't deprecate exec? 回答1: No, eval and related tools are not always bad by any measure. There are a number of things that only

Import python module over the internet/multiple protocols or dynamically create module

泪湿孤枕 提交于 2019-11-30 13:50:10
Is it possible to import a Python module from over the internet using the http ( s ), ftp , smb or any other protocol? If so, how? If not, why? I guess it's about making Python use more the one protocol(reading the filesystem) and enabling it to use others as well. Yes I agree it would be many folds slower, but some optimization and larger future bandwidths would certainly balance it out. E.g.: import site site.addsitedir("https://bitbucket.org/zzzeek/sqlalchemy/src/e8167548429b9d4937caaa09740ffe9bdab1ef61/lib") import sqlalchemy import sqlalchemy.engine In principle, yes, but all of the tools

Why does Python 3 exec() fail when specifying locals?

拜拜、爱过 提交于 2019-11-27 07:38:16
问题 The following executes without an error in Python 3: code = """ import math def func(x): return math.sin(x) func(10) """ _globals = {} exec(code, _globals) But if I try to capture the local variable dict as well, it fails with a NameError : >>> _globals, _locals = {}, {} >>> exec(code, _globals, _locals) --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-aeda81bf0af1> in <module>() ----> 1 exec(code, {}, {})