# author: Roy.G
'''
print("all====>",all([0,-1,1]))
print("any====>",any([0,0,1]))
print("-----ascii------")
a=ascii([0,0,1,"罗伊"])
print("ascii====>",[a],type(a))
print("bin(%s)===>"%(20),bin(20))
print("bool===>",bool(3))
print("---bytearray---")
b=bytearray("abcdefg",encoding="utf-8")
print(b[1])
print("callable==>",callable(bytearray))
print("chr===>",chr(b[3]))
print("ord===>",ord("a"))
#compile a code to module
code='''
# print("i am roy")
'''
py_obj= compile(code,"err.log","exec")
exec(py_obj)
exec(code)
print("dir===>",dir(b))
print(divmod(5,2)) #return result and remainder
#eval=e value,means conver a str to code and run the code
x=1
code="x+20"
print(eval(code))
lm=lambda x:print(x)
lm(4)
print("-------filter--------")
result = filter(lambda n:n>3 and n<5,range(100)) # filter lamda from range()
count=0
for i in result:
count+=1
print(i)
print(count)
print("-------map--------")
result_1 = map(lambda n:n*n,range(10)) # independent variable from range() map though the function lambda
count = 0
for i in result_1:
count+=1
print(i)
print("count=",count)
print(type(result_1))
print("-------reduce--------")
import functools
result_2 = functools.reduce(lambda x,y:x*y,range(2,5)) #
print(result_2)
print(type(result_2))
print("-------frozenset--------")
fs=frozenset([1,2,3,4,4,3,2,1])
print(fs,type(fs))
print("-------globals()--------")
print(globals())
glb=globals()
print(glb['__name__'])
print("---------hash----------")
print(hash("郭艳华"))
print(hash("a"))
'''
print("------json------")
import json
code={"a":1,"b":2,"c":3}
print(code)
print("type code dict",type(code))
# cd=str(code)
f=open("code_1.txt","w")
(json.dump(code,f))
f.close()
#f.write(json.dumps(code))
# fr=open("code_1.txt","r")
# print(type(fr))
# fr.close()
with open("code_1.txt") as fr:
print(type(fr))
data_1=json.load(fr)
print(data_1,type(data_1))
print(data_1["a"])
# dump load for handle ,dunps loads for string ;jsonfile need to be closed for loading