Lpthw stupid way to learn Python Chapter 16

Source: Internet
Author: User

Some extensions are made according to the content of chapter 16.

For example, if a file exists, it is appended to the file and created if it does not exist.

It also draws on a method similar to the cat <<eof > test in the shell command, prompting the user to enter a trailing character.

Now there is a small pit, how to use Python to read a file of the number of rows, the original Os.system ("Wc-l filename") is OK, but how to operate under Windows? Fill it back.

#!/usr/bin/env python#-*-coding:utf-8-*-from sys import argvfrom OS import pathscript, filename = argvif path.exists (fi Lename):    print "we ' re going to erase%r."% filename    t_module = "A" Else:    print "We'll create%r."% filename    t_module = "W" end_eof = raw_input ("Please give me an EOF string") with open (Filename,t_module) as fo:    Line_Count = 1 while    True:        line_content = raw_input ("Please input%d line string:\n"% line_count)        if line_content = = End_e Of:            break        Else:            fo.write (line_content)            fo.write ("\ n")

  

Lpthw stupid way to learn Python Chapter 16

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.