python之创建文件写入内容


#!/usr/bin/python
#-*-conding-*-
#创建文件,并写入数据:要求不能与现存系统文件重名

import os

def makefile(path,content):
    if os.path.exists(path):
        if os.path.isdir(path):
            f = open('makefile_test.txt','w+')
            f.write(content)
            f.seek(0)
            read = f.readline()
            f.close()
            print(read)
        else:
            print('please input the dir name')
    else:
        print('the path is not exists')


path = str(input('the path:'))
content = str(input('please write the content into the new file:'))
makefile(path,content)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM