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)

 

posted @ 2015-11-07 17:14  Xiao|Deng  阅读(3062)  评论(0编辑  收藏  举报