python之函数用法execfile()

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之函数用法execfile()



#execfile()
#说明:用来执行一个文件,相对于双击的效果
'''
execfile(...)
    execfile(filename[, globals[, locals]])
    filename:文件名
    globals:全局变量--这里指绝对路径
    locals:本地变量--这里指相对路径
    
    Read and execute a Python script from a file.
    The globals and locals are dictionaries, defaulting to the current
    globals and locals.  If only globals is given, locals defaults to it.
'''


#案例
#import chardet
filename=r'my.py'
#print chardet.detect(filename)#ascii
#filename=r'my.py'.decode('ascii')
execfile(filename)
原文地址:https://www.cnblogs.com/dengyg200891/p/4945723.html