Python learning files Create a write program

Source: Internet
Author: User

#!/usr/bin/env python
Import OS#导入功能模块
url = "/tmp/"#变量定义
def check ():#函数定义
whileTrue:#一直循环 prompt the user to enter the correct file name to create
Os.system ("cd/tmp")
d_com=raw_input ("please input filename")#将用户输入的值赋给变量做判断
if os.path.exists (url+d_com) = = True:#调用功能模块判断文件是否存在
print "error!! File had existed "#输出判断结果
Continue#存在时重新输入文件名
Else:
While True:
#当要创建的文件不存在
M = open (url+d_com, ' a ')# Prompt the user to enter content into the created file
A = raw_input ("Piease input what ' s want Add")
m.write (A)#将内容写入创建的文件
M.flush
M.close ()
if A = = "":

exit ()#当输入为空时代表输入结束, exit the function.

Check ()

Python learning files Create a write program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.