python提升--running-python-code-contained-in-a-strin

先来俩连接:python

http://stackoverflow.com/questions/701802/how-do-i-execute-a-string-containing-python-code-in-python 
http://stackoverflow.com/questions/1015142/running-python-code-contained-in-a-string socket

而后 , 看文章吧spa

Be careful with exec and eval in Python

<http://lucumr.pocoo.org/2011/2/1/exec-in-python/>code


大概以下:utf-8

# -*- coding: utf-8 -*-

__author__ = 'lpe234'


x = """
import socket

def get_host():
    return socket.gethostname()

"""
ns = dict()
exec x in ns

print ns['get_host']()
相关文章
相关标签/搜索