Furious Python-conclusion-I/O and python

Source: Internet
Author: User
Tags mathematical functions

Furious Python-conclusion-I/O and python

Well, I didn't expect it to be so fast. I just finished reading the entry in just two days. Of course, it's just an entry. If I want to use it later, I will summarize the details of each type. For example:Mathematical functions,Or summarize the applications of some frameworks, suchScarpy(The crawler framework is very excited. Many people know it, but they have never used it ......), after writing this article, I will watch a movie and go back to school.

PythonScreen I/O:For interactive programming, it is good to input directly. It is used only in script-based programming. The methods used are input and raw_input. The following example is provided.

#! /Usr/bin/pythonprint raw_input () # both methods read the entire row of strings, and the raw_input method returns the read string print input () # input considers the string to be read as a valid python expression and returns the value of the operation # If two strings are also input "1 + 2", the first one prints "1 + 2 ", the second one will print the result "3"

PythonFile I/O:Processing files is the most convenient method. It is too slow to process files. The following is an example of how to process files.

Suppose there is a file named test in the current directory. The content is as follows:

I like python.

The following is an example of code for processing this file.

#! /Usr/bin/pythonpf = open ("test", "r +") # open method, used to open a file # Where pf is a file Pointer a bit like C ++ # test is the file name # r + is the open mode, which will be shown later

Str = pf. read (14) # read method. For example, if I pass 14, it will read 14 characters. If I do not write a parameter, it will read as many characters as possible, which may make the entire text pf. write ('\ n' + str +' \ n') # write method to write a string. The passed parameter is the print pf string. tell () # The tell method tells us the current position of the file print pf. seek (0, 0) # seek method. The first parameter is offset, and the second parameter has three possibilities: 0 (starting from the file), 1 (current location), and 2 (end of the file) import OS # OS is the operating system module. Some methods are used to manage the OS of files. rename ('test', 'T') # rename the object. Here we name 'test' as 'T' OS. remove ('T') # The remove method is to delete a file directly. The input parameter is the deleted file name.

Here the simple entry will be happy to end, I feel that learning language is probably want to know this thing, and then use the time to go to the official website to check it, give the official site address: https://docs.python.org/2/


I/O warning prompt appears in python. How can I solve Chinese garbled characters?

Add # _ * _ coding: UTF-8 _ * _ to the first line.

I/O Error

We recommend that you check whether the disk space is sufficient. If it is sufficient, we recommend that you check the disk space of the mobile phone storage and use the chkdsk command or Windows disk for diagnosis. If there is no error, the file system may be incompatible or virus.

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.