您的位置:首页 > 运维架构 > Shell

python中shell调用py文件的内容

2011-03-10 15:36 567 查看
python中想在shell中调用一个test.py文件里面的方法。

test.py文件里面的内容如下:

def ListFea():
print "this is myself"

def ListFeaT(fea):
print "this is:", fea

def ListFeaR(fee, fea):
print "this is:", fee, "add", fea

class simpleTest(object):
"simple test"
def runone():
print "runone"
def runtwo(self):
print "this has:",self
def runthree(self,value):
print "this is:",value


如何在shell中调用py中的内容呢。

其实主要加几行就够了:

import sys #引入sys库体
sys.path.append("C://myPython") #往系统路径中加入自己存放py文件的地址


然后就可以开始通过import的方法导入相关的方法和内容了

from test import * #从test.py文件中加载所有的内容。


顺带提一下python文件进行编译的方法:

import py_compile #导入编译库
py_compile.compile("C://myPython//test.py") #对test.py文件进行编译


因为也是刚开始学习,所以可能一些名词用的不是很准确,大家包涵了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: