python之創建文件寫入內容


https://www.cnblogs.com/evablogs/p/7096686.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
#-*-conding-*-
#創建文件,並寫入數據:要求不能與現存系統文件重名
 
import  os
 
def  makefile(path,content):
     if  os.path.exists(path):
         if  os.path.isdir(path):
             =  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