Several lines of code to call functions in the unix pipeline style, and several lines of unix
After using linux, you basically know its pipeline, which is to use the output of a program or command as the input of another program or command.
To put it bluntly, let's look at how python can be used to call functions in the unix pipeline style.
#coding=utf-8class Pipe: def __init__(self, func): self.func = func def __ror__(self, other): return self.func(other)@Pipedef add(args): return sum(args)@Pipedef incr(arg): return arg + 1print [1, 2, 3] | add | incr
The principle is that the decorator + operator is overloaded. (For more information about the decorator, see <the essence of the python decorator>)
Here, the magic method _ ror _ overload operator |
It's really simple and rude. My life is short. I use python!
How to view the function interfaces called by executable files in Unix/Linux
There is no good tool to achieve the effect you have mentioned. The strings command can be seen, but you have to analyze it carefully. The usage is as follows:
Strings program name | more
Or input the result to a file, such:
Strings program name> input file name
Then vi enters the file name to see the corresponding content.
In unix, I used vi to edit the c file. How can I quickly jump to the declaration of the referenced function?
You should press Esc to enter the command mode, and then enter "? "And"/"keys can both enter the baseline mode.
Add a string to it to search.
/Find and match the string function. The system will automatically find and highlight all the words found in the "/string" command mode.
String, and then go to the first string. If you want to continue searching, you can press the "F" key. Press the "N" key to continue searching;
? You can also use "? String "searches for a specific string. It is similar to"/string ", but it is a forward query string.