Python3 Seventh Day (input and output)

Source: Internet
Author: User

How to output a value: 1, expression. The 2,print () function. 3, the Write () function of the file object

The STR () function returns a user-readable representation.

The repr () function returns the expression of the interpreter's late reading. Special characters in special strings can be escaped

Input () function: Enter, return the output object

Read and Write files:

Open (Filename,mode), returns a File object

FileName: File name, Mode: What pattern is open

Mode has the following modes:

r,rb,r+,rb+,w,wb,w+,wb+,a,ab,a+,ab+

R: Read-only mode open

B: Binary Open

W: Write-only mode open

+: Read/write mode

Pickle module:

Basic data serialization and deserialization implemented by pickle

Pickle.dump (Obj,file[,protocol])

Pickle.load (file)

File

file.close (); Close File

File.flush (); Output the in-memory file to a disk file

File.isatty (); Determine if the file is in the terminal

File.next (); Return to the next line

File.read ([size]); Returns the specified number of bytes read, if not specified or negative, all

File.readline ([size]); Read entire line

File.readlines ([sizeint]); Read Sizeint line

File.seek (Offset[,whence]); Set the current location of the file

File.tell (); Returns the current location of the file

File.write (str); write characters

File.writelines (sequence); write multiple lines

file.truncate ([size]); Truncates the file to a size character starting at the beginning of the first character of the file

Error handling

Try

....//To determine if there is a wrong statement

Except (Runtimeerror,typeerror,nameerror):

....//error code to execute

Else

....//code to execute without errors

Finally

....//The statements executed no matter what


Raise exception: Used to throw the specified exception, the exception that is thrown must be a subclass of exception


With expression: The file object in the//with statement block must be a normal way to clean up

....











Python3 Seventh Day (input and output)

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.