Paip. Metadata-driven transformations-read file lines to a list idea uapi java PHP python summary
Source: Internet
Author: User
Paip. Metadata-driven transformations-read file lines to a list idea uapi java PHP python summary
#两个思路
1. The idea is as follows: Use File_get_contents () to get the contents of the TXT file, and then convert the obtained string into an array by explode (). Get array length You can use the count () function
2. Using the Read API by line
In the regular expression, there is a \ n is the meaning of newline, and a \ r is carriage return (that is, this led to the idiot Chinese translation "return") meaning. When working with a string or console output, it can be wrapped in any line.
#-----Python's problem is also to replace the line break with the ENTER key:
#todox read file lines to list (not arr, arr are tech word, but List was life word)
def file2list (file):
Rplc_list = [];
For line in open (F, encoding= "Utf-8"):
if (len (line)) ==0):
Break
#endif
#print (line)
Line=trim (line)
Line=line.replace ("\ n", ""); Line=line.replace ("\ R", "" ")
Rplc_list.append (line)
#end for
Return rplc_list
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.