Exemplo n.º 1
0
def func(arg):
    C.sm(arg)
    C().m(arg)
    f(arg)
    module.C.sm(arg)
    module.C().m(arg)
    module.f(arg)
Exemplo n.º 2
0
MODULE
ITERTOOLS
CSV
DECORATORS
NAMETUPLES
JSON
Flask
##################### CONCEPTS ######################

CLOSURES : Remembering a Function

DRY : Not To Repeate Yourself
MEMOIZATION : cashing to save computing time
COMPINATIONS : Order does not Matter 
PERMUTATIONS : Order Matter
IDEMPOTENCE : When f(x) = f(f(x)) example: GET, PUT, DELETE
STRING CONCATENATION : 'Name is ' + name
STRING INTERPOLATION : f'Name is {name}'
MUTABLE : lists
IMMUTABLE : strings
1st ClASS FUNCTION
##################### CLASSES ######################

def __repr__(self,str1): # __add__ , __len__	,__str__
	return f'Arg : {self.arg}{str1}'
# repr --> unambigous | str --> readable
__repr__ = function

@property
def fullname(self):
	return f'{self.first} {self.last}'
Exemplo n.º 3
0
#!/usr/bin/python3.6
#https://stackoverflow.com/questions/4385839/reimporting-a-single-function-in-python

import os
from module import f

f()

# changing f
command = "sed -i 's/hello/goodbye/' module.py"  # https://stackoverflow.com/a/53124215/1273751
os.system(command)

# reloading
import sys
import importlib

importlib.reload(sys.modules['module'])
from module import f

# calling the altered f
f()

# changing back to the original
command = "sed -i 's/goodbye/hello/' module.py"
os.system(command)

## if function is not from a module, do the following:


def g(x):
    return x + 1
Exemplo n.º 4
0
# 1. Import all the code from the file 'module.py'
import module
module.f()

# 2. Rename module in your own file
import module as m
m.f()

# 3. Import only specific functions of the module
from module import f
f()
Exemplo n.º 5
0
def test_if_f_is_invalid():
    assert f() == False
Exemplo n.º 6
0
def test_if_f_is_valid():
    assert f() == True