Paip. metadata-driven conversion-read a file row to a list concept uapijavaphppython summary

Source: Internet
Author: User
Paip. metadata-driven conversion-read a file row to a list concept uapijavaphppython summary paip. metadata-driven conversion-read a file row to a list concept uapi java php python summary

# Two ideas
1. The idea is as follows: use file_get_contents () to get the content of the txt file, and then convert the obtained string to an array through explode. You can use the count () function to obtain the array length.
2. read api by line

In a regular expression, \ n indicates newline, and \ r indicates carriage return (that is, this leads to an idiot Chinese translation "press enter. When processing String or console output, line breaks can be applied to any String or console output.

Author old Wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax

# --- Uapi file2list ()

# ----- The problem with python is that you need to replace the line break and the carriage return key ..
# Todox read file lines to list (not arr, arr is tech word, but list is life word)
Def file2list (file ):
Rplc_list = [];

For line in open (f, encoding = "UTF-8 "):
If (len (trim (line) = 0 ):
Break
# Endif
# Print (line)
Line = trim (line)
Line = line. replace ("\ n", ""); line = line. replace ("\ r ","")
Rplc_list.append (line)
# End
Return rplc_list

# ------ Java
# ------- Php

$ File = '2010-12-15.txt ';
$ Content = file_get_contents ($ file );
// Echo $ content;

$ Array = explode ("\ r \ n", $ content );
// Print_r ($ array );

For ($ I = 0; $ I <count ($ array); $ I ++)
{
Echo $ array [$ I]. '<br/> /〉';
}

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.