Files and built-in functions open () file ()

Source: Internet
Author: User

---restore content starts---

Can you call it a function?

Open () function

How to open a file

Handle=open (file_name,access_mode= ' R ')

R Read

W Write

A add

+ Read/write

b binary Access

The default access_mode is R, read-only

If Open () succeeds, a file object handle is returned, and all subsequent file operations must be done through this file handle. When a file object is returned, we can access some of its methods, such as ReadLines () and close (). The method properties of a file object must also be accessed through the period property identifier.

Core notes: What are attributes, properties are data-related items, properties can be simple data values, or they can be execution objects such as functions and methods, and which objects have properties? Many objects, such as classes, modules, files, and complex numbers, have properties, how do we Access object properties? Use the period attribute to identify the method, which means to add a period (.) between the object name and the property name:

Object.attribute. Chinese Translation Objects-Properties

FileName =raw_input (' Enter file name ')

Fobj=open (filename, ' R ')

For Eachline in Fobj:

Print Eachline, #注意, this place has a comma, so there's no line break, but he automatically adds spaces.

Fobj.close ()

Files and built-in functions open () file ()

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.