Python Read and write files

Source: Internet
Author: User

reference 1: Http://zhidao.baidu.com/link?url=sqj6-1-peWnCAjTYU62i0X6qipUC6nVpfWd8eG0xo1YLj9Aaz_GioIJn_ 5i0oqiwlwfabhonggbwxlmj2uwzf5pgsoxzadyoj5uwtpzaitg

reference 2: http://younglibin.iteye.com/blog/1879377

(1) Read the file by line

(2) Select Remove \ n

To read floating-point data in a file in a regular format:

Http://www.jb51.net/article/49800.htm

http://www.thinksaas.cn/group/topic/92405/

Http://www.jb51.net/article/52077.htm

This indicates that Python reads and writes files as a string. that is, binary, also as a string to see. One character at a byte, enough to save it

Http://www.cnblogs.com/qq78292959/archive/2013/04/07/3003607.html

Summary: Every time learning a language is constantly tangled in this problem! It is a waste of time to hope that this question will not be repeated.

There are two types of stored data:

Method 1: like a C + +, you can press a small block of memory as a unit, the data structure (we do not understand, machine view, binary). Python is no good, there are no pointers, and there are no functions to allocate memory.

Method 2: stored as a string. and in string form. They are in advance to convert values into strings (including scanf,fscanf, printf. What is visible to us) as far as I know, some strategies are:

(1) one row per data

(2) Split by regular (for Python. And C/c++/matlab do not need, have fscanf, note: Read into the format is a person designed, not a bunch of random string. )

(3) As mentioned in reference 1, the use of the list is read by line, not pro-test.

So? The regular expression of the scripting language is to understand!

Python Read and write files

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.