Python Toolbox--text Read

Source: Internet
Author: User

1. Using open () BIF opens a disk file, creates an iterator to read data from a file, and reads one data row at a time.

2. The ReadLine () method reads a row of data from an open file.

3. The Seek () method can be used to "back" the file to the starting position.

4, Close () method closes a file that was previously opened.

5. The split () method can break a string into a list of strings.

6. A list of constants that cannot be changed in Python is called a tuple (tuple). Once the list data is assigned to a tuple, it can no longer be changed. The tuple is immutable.

7. ValueError will appear when the data does not conform to the desired format.

8. IOError will appear when data is inaccessible (for example, your data file may have been moved or renamed).

9. Help () BIF allows you to access Python documents in the Idel shell.

10. The find () method looks for a specific substring in a string.

11. The NOT keyword negates a condition.

12. The Try/except statement provides an exception handling mechanism that protects some lines of code that may cause run-time errors.

13, the pass statement is a Python empty statement or a null statement, it does nothing.

Note 1:

BIF (built-in functions) is a Python inline function.

In Python or the idle shell, we can type Dir (__builtins__) to see a list of Python's built-in methods ("Builtins" is preceded by two underscores).

NOTE 2:

Help ()

When viewing inline functions, direct help (Open)

When viewing a module, you need to import the module first. For example:

>>> Import String
>>> Help (String)

Help on module string:

NAME
String-a Collection of string operations (most is no longer used).

FILE
/usr/lib/python2.7/string.py

MODULE DOCS
Http://docs.python.org/library/string

DESCRIPTION
Warning:most of the code you see here isn ' t normally used nowadays.
Beginning with Python 1.6, many of these functions is implemented as
Methods on the standard string object. They used to being implemented by
A built-in module called Strop, but Strop was now obsolete itself.

......

Python Toolbox--text Read

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.