import sys from mymod import test, countChars, countLines print test('test') import mymod print mymod.test('test')
def countLines(name): file = open(name, "r") data = file.readlines() n = len(data) file.close() return n def countChars(name): file = open(name, "r") data = file.read() n = len(data) file.close() return n def test(name): print "countLines:", countLines(name) print "countChars:", countChars(name) if __name__ == "__main__": import mymod mymod.test("mymod.py")
#!/python #-*- coding:utf8-*- from mymod import test #import mymod if __name__ =='__main__': test('')
# Module "mymod" is fully imported import mymod print(mymod.countLines('mymod.py')) print(mymod.countChars('mymod.py')) print(mymod.test('mymod.py')) # Functions are imported from the module from mymod import countLines, countChars, test print(countLines('mymod.py')) print(countChars('mymod.py')) print(test('mymod.py'))
import mymod mymod.test('E:\Leanrning-Python-4th-solution\第五部分\TEST.txt') from mymod import * #都可以,然后我懒得打印,你自己慢慢打印 #上面路径问题,你自己根据你自己的本地地址调,具体怎么搞成通用的,我还不会,见谅
from mymod import test if __name__ == '__main__': dante = "dante\ndante\n" test(dante)
import mymod mymod.test('myclient1.py')
''' myclient1.py - imports mymod.py and check its operation. ''' from mymod import test, countChars, countChars1, countLines, countLines1 text = 'test.txt' file = open(text) print(test(text), test(file)) print(countChars(text), countChars1(file)) print(countLines(text), countLines1(file)) print('\nedited again version')