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.
# ----- 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
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.