Writing: Python Good example of code style parsing

Source: Internet
Author: User
Tags function definition

The user input data into a file, the file must be non-existent

(1) Start line

(2) Module document string

(3) Import module

(4) Global variable declaration

(5) class definition

(6) Function definition

(7) Program body

#!/usr/bin/env python

Import OS//importing OS module

Content = []//define a list


#输入一个文件名, re-enter the prompt if present
While True:
fname = Raw_input ("FileName:")
If not os.path.exists (fname):
Break
Print "%s is already exists, Try again"% fname


#将用户输入的内容保存到一个列表当中
While True:
data = Raw_input ("Enter line (. To quit) > ")
if data = = ".":
Break
Content.append (data)


#将列表中的内容写入到文件中
Fobj = open (fname, ' W ')
Fobj.writelines (["%s\n"% x for x in content])
Fobj.close ()


This article is from the "Court of the Odd Tree" blog, please be sure to keep this source http://zhangdl.blog.51cto.com/11050780/1828784

Writing: Python Good example of code style parsing

Related Article

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.