This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/664118/whats-the-difference-between-dict-and | |
>>> from timeit import timeit | |
>>> timeit("a = {'a': 1, 'b': 2}") | |
0.424... | |
>>> timeit("a = dict(a = 1, b = 2)") | |
0.889... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/6130768/return-none-if-dictionary-key-is-not-available | |
You can use dict.get() | |
value = d.get(key) | |
which will return None if key is not in d. You can also provide a different default value that will be returned instead of None: | |
value = d.get(key, "empty") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
myOrderedDict = OrderedDict() | |
myOrderedDict['a'] = 1 | |
myOrderedDict['b'] = 2 | |
myOrderedDict.popitem(last = False) # Setting last to False signals you wanted to remove the first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
That being said, conforming your Python code to PEP 8 is generally a good idea and helps make code more consistent when working on projects with other developers. There is a command-line program, pycodestyle (previously known as pep8), that can check your code for conformance. Install it by running the following command in your terminal: | |
$ pip install pycodestyle | |
Then run it on a file or series of files to get a report of any violations. | |
$ pycodestyle optparse.py | |
optparse.py:69:11: E401 multiple imports on one line | |
optparse.py:77:1: E302 expected 2 blank lines, found 1 | |
optparse.py:88:5: E301 expected 1 blank line, found 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The program autopep8 can be used to automatically reformat code in the PEP 8 style. Install the program with: | |
$ pip install autopep8 | |
Use it to format a file in-place with: | |
$ autopep8 --in-place optparse.py | |
Excluding the --in-place flag will cause the program to output the modified code directly to the console for review. The --aggressive flag will perform more substantial changes and can be applied multiple times for greater effect. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python 要用 pip install numpy | |
python3 要用 pip3 install numpy | |
想一想也是很合理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://color.firefox.com/?theme=XQAAAAIVAQAAAAAAAABBqYhm849SCia2CaaEGccwS-xNKlhW9r_vLXIlVnuJdAic7eRjUc7NRneKMRgQIDK-eQWrkV64LlDNDxf_eMByAZRY7cQeDk2YcCQuge8iz6wsuNPluyBJiPNe5xIoZzicTFzQ6DMdJYDEw-AeRyNROrGJ4T-DeBLGg-1Vj7VZ3d9k5NxuR_XDp27McA_KR92FIt5YLJrt4-wN1xy00G2UBvBL10ttWMmb3Fj4oR16M_W9K9p__-NlUeA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wine regedit | |
Search for "LogPixels" there. You will see something like this: | |
"LogPixels"=dword:00000060 | |
Change 60 to something more suitable. For example this is what I use with my | |
two displays (one with resolution 1680x1050 and another one with 1280x1024): | |
"LogPixels"=dword:00000095 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.geeksforgeeks.org/global-keyword-in-python/ | |
To access a global variable inside a function there is no need to use global keyword. | |
If we need to assign a new value to a global variable then we can do that by declaring the variable as global. | |
This output is an error because we are trying to assign a value to a variable in an outer scope. This can be done with the use of global variable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.vpnusers.com/viewtopic.php?t=2861 | |
==== | |
You can connect all VPN Gate server by following settings. | |
HostName: Please get from this page http://www.vpngate.net/en/ | |
UserName: vpn | |
Password: vpn | |
Pre-shared key: vpn |
OlderNewer