Skip to content
Vital-jan edited this page May 2, 2020 · 3 revisions

Comand line:

python3
>>>
Ctrl+z for exit

sudo apt install python-pip // python packages manager


Python extension for Visual Studio Code:
python (Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.)

Type checking:

if value is None:
if value is not None:
value.isdigital (.isnumeric, .isdecimal) - returns true, if value is integer & if value > 0;
print (isinstance(s, (int, float)))
print (type(s) == str)
float(x)
int(x)
str(x)
Logical: and, or, not

Arrays

arr = [5,10,15]
try:
    i = arr.index (10)
    print ('arr[' + str(i) + '] = ' + str(arr[i]))
except ValueError:
    print ("Not found")
arr = {123: '=123=', 150: '=125='}
s = None
for key in arr:
    print (arr[key])
    if (key == 124): s = key
print (s)
if (s == None): print ("s=None")

JSON

 import json
 file = open (filename)
 text = file.read()
 file.close()
 my_dict = json.loads(text)
print ( len (my_dict))

var.2:

with open(filename) as file:
     try:
        urls_dict = json.load(file)
     except:
        urls_dict = {}

save JSON:

file = open (filename, "w")
file.write (json.dumps(my_dict))
file.close

Time interval:

d1 = time.time()
..........
..........
d2 = time.time()
print (d2-d1)

Clone this wiki locally