The use of with...as in 1.Python
This syntax is used instead of the traditional try...finally syntax.
With EXPRESSION [as VARIABLE] With-block
The basic idea is that the object with which the value is evaluated must have a __enter__ () method, a __exit__ () method.
Immediately after the statement that follows with is evaluated, the __enter__ () method of the returned object is called, and the return value of the method is assigned to the variable following the AS.
The __exit__ () method of the previous return object is called when all code blocks following the with are executed.
Ex
***********************************************************************************************
2.python if __name__ = = ' __main__ ': parsing
When you open a. py file, you will often see if __name__ = = ' __main__ ' at the bottom of the code: Now let's introduce its role.
The module is an object, and all modules have a built-in property of __name__. The value of the __name__ of a module depends on how you apply the module. If you import a module, the value of the module __name__ is usually the module file name, without the path or file extension. But you can also run the module directly like a standard program, in which case the __name__ value will be a special default "__main__".
***********************************************************************************************
Run the. py file directly in cmd, then the value of __name__ is ' __main__ ';
After import a. py file, the value of __name__ is not ' __main__ ';
Thus use if __name__ = = ' __main__ ' to determine whether the. py file is running directly
Such as:
#Test. Pyclass Test: def __init (self):p the F (self):p rint ' Hello, world! ' if __name__ = = ' __main__ ': Test (). f () #End you enter in cmd: C:>python test.pyhello, world! description: "__name__ = = ' __main__ '" is set up and you enter in cmd again: c:>python>>>import test>>>test.__name__ #Test模块的__name__ ' Test ' >> >__name__ #当前程序的__name__ ' __main__ ' no matter what, test.py in the "__name__ = = ' __main__ '" will not be set up! So, the next line of code will never run to!
***********************************************************************************************
Pycharm shortcut keys [Common]
Ctrl/
Comment (uncomment) the selected line
Shift + Enter
Start a new line
Ctrl + Enter
Smart Line Wrapping
TAB Shift+tab
Indent/Cancel Indent selected rows
Ctrl + Alt + I
Auto Shrink
Ctrl + Y
Delete the row where the current caret is located
Ctrl + D
Copy the current line, or block selected
Ctrl + Shift + J
Merge rows
Ctrl + Shift + V
Paste from the nearest buffer.
Ctrl + Delete
Delete to end of character
Ctrl + Backspace
Delete to start of character
Ctrl + numpad+/-
Expand or shrink a block of code
Ctrl + Shift + numpad+
Expand all blocks of code
Ctrl + Shift + numpad-
Shrink all blocks of code
Pycharm shortcut keys [Common] reference http://www.cnblogs.com/huangcong/archive/2013/03/25/2980102.html
Python Small Knowledge Point collection