New TXT file additions and print out

Source: Internet
Author: User

#!/usr/bin/python

Import OS

File1=open ("C:\Python34\ceshi.txt", "A +"); #a + Open a file for reading and writing. If the file already exists, the file pointer will be placed at the end of the file. The file opens with an append mode. If the file does not exist, create a new file to read and write.

St1=input (' Please enter character: '); #键盘输入内容

File1.write (ST1); #把键盘输入的内容能够保存到txt文件中

Guangbiao=file1.seek (0,0); #光标位置设置在首位 (This is set to read the file after it is fully read, if not set may cause some content to be unreadable)

Qrgb=file1.tell (); #获取光标位置

Print (QRGB) #打印出光标位置

Ai=file1.read (100); Read File contents

Print (AI); #打印出文件内容

File1.close () #关闭文件

Os.rename ("Ceshi.txt", "12.txt") #修改文件名
Os.remove ("12.txt") #删除文件

New TXT file additions and print out

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.