1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import os
def create_package(path): if os.path.exists(path): raise Exception('%s 已经存在不可创建' % path) os.makedirs(path) init_path = os.path.join(path, '__init__.py') f = open(init_path, 'w') f.write("# coding:utf-8\n") f.close()
class Open(object): def __init__(self, path, mode='w', is_retern=True): self.path = path self.mode = mode self.is_retern = is_retern
def write(self, message): f = open(self.path, mode=self.mode) if self.is_retern: message = '%s\n' % message f.write(message) f.close()
if __name__ == '__main__': current_path = os.getcwd() open_path = os.path.join(current_path, 'b.txt') o = Open(open_path) o.write('你好 小慕')
|