One: Cause
(1) The shift in attitudes and ideas is important: The reason for learning Python is also tortuous enough-to learn about Python and the Perl language, to learn about it, and to have the motivation to study it. Finally, learning about Python is the result of learning "machine learning" and foreign teaching videos. , and the foreign machine learning API are used in the Python language, their first sledgehammer, the sense of efficiency is high, slowly the concept of change.
(2) the shift in attitudes and ideas is important: learning a new technology or language is the same as the law of people's understanding of things-the first reaction is repulsive and opposed (where it feels awkward) when new things are approached; after a few days (and maybe a few weeks later, there is no contact with PS: aside, After a few months to learn), then there will be a honeymoon period (feeling the efficiency of what is very high, very good PS: Not enough), began to wonder how ugly and stupid language before learning, began to resist the original learning, and even began to suspect life (PS: maybe there); Honeymoon period, The basic knowledge of the new knowledge, and began to touch advanced applications, but because of the advanced complex application API is not very understanding, always out of such or so inexplicable mistakes, and began to doubt life ...
(3) To avoid the above-mentioned strange way, is to make friends, especially the technical Daniel-When you learn a new technology, have Daniel to give you guidance, will certainly bring you a lot of fun, but also harvest the friendship; technical blog of Technology Daniel (CSDN or Github)
(4) That's how I started, my short learning python journey.
Two: Text processing comparison
(1) Java language:
/ * * @function: Read file contents * @input: Enter filename * @output: Full contents of File * /public static string ReadFile (string File) throws FileNotFoundException, IOException { //stringbuffer sb = new StringBuffer (); FileInputStream FileInputStream = new FileInputStream (file) BufferedReader BufferedReader = new BufferedReader (new InputStreamReader (FileInputStream, "GBK")); String line = Bufferedreader.readline (); while (line! = null) {String [] words = Line.split (regex);//or Replace and so on (word in words) {System.out.println (word);} //sb.append (line) append ("\ r \ n");//newline character in Windows system lines = Bufferedreader.readline (); } Bufferedreader.close (); return sb.tostring ();//It is impossible to put an article in it.
(2) C + + language:
C + + language implementation of C + + does not implement the function of Split function, below the C + + STL in some of the functions of simulation to realize the split function. #include <iostream> #include <string> #include <vector> #include <fstream>using namespace std;/ * @in, SRC: string to be split @in, Delim: Delimiter string @in_out, Dest: Save each string after splitting */void split (const string& SRC, const string& Delim, vector<string>& dest) {string str = Src;string::size_type start = 0, index;string substr;index = Str.find_first_ Of (Delim, start);//Find the first occurrence of any character in Str (start: Start) Delim while (index! = string::npos) {substr = Str.substr (Start, Index-start);d est.push_back (substr); start = Str.find_first_not_of (Delim, index);//Find in STR (start: Index) The first character that does not belong to Delim appears if (start = = String::npos) Return;index = str.find_first_of (Delim, start);}} int main () {Ifstream infile ("Test.txt", ios::in);vector<string> results;string word;string Delim (""); string Textline;if (Infile.good ()) {while (!infile.fail ()) {getline (infile, Textline); split (Textline, Delim, results);}} Infile.close (); Vector<string>::iterator iter = ResULts.begin (); while (iter! = Results.end ()) {Cout<<*iter++<<endl;} return 0;}
(3) Python language:
In Python there is a special function split () to split the string to achieve a simpler myfile = open (' Test.txt ', ' r ') allwords = []line = Myfile.readline () while Line:list = Line.split (") for word in list:if word[-1]== ' \ n ': Allwords.append (word[:-1]) #去掉行末的 ' \ n ' else:allWords.append (word) line = Myfile.readline () myfile.close () print Allwords
(4) Summary: In comparison, (aside from running efficiency does not say), development efficiency is better than Python, followed by Java, and finally C + +, (but once C + + These methods are packaged in advance, it is also very good).
Python Text processing and JAVA/C