Repository navigation
Expand file tree
/
Copy pathpython_fundamentals.py
More file actions
94 lines (68 loc) · 2.23 KB
/
Copy pathpython_fundamentals.py
File metadata and controls
94 lines (68 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# def f():
# name = "deepak"
# print(name)
# age = 25
# print(age)
# profit = 4.8
# print(profit)
# is_active = True
# print(is_active)
# # array
# fruits = ["apple", "banana", "cherry"]
# print(fruits)
# # dictionary
# candidate = {"name":"deepak", "skills":"python", "last employer":"google"}
# print(candidate)
# # tuple
# numbers = (1, 2, 3, 4, 5)
# print(numbers)
# # set
# unique_ids = {22,12,22,22}
# print(unique_ids)
# print(3**2)
# f()
# results = [ i**2 if i % 2 == 0 else i**3 for i in range(5) ]
# # for i in range(5):
# # if(i%2==0):
# # results.append(i**2)
# print(results)
# # results1 = [i**2 for i in range(5) if i%2==0]
# # print(results1)
# # d =
# print([ i*3 for i in range(10) if i % 2 != 0 ])
# def build_api_uri(base_uri, version="v1", **kwargs):
# url = base_uri+'/'+version
# if kwargs:
# first = True
# for key, value in kwargs.items():
# if not first:
# url = f"{url}&{key}={value}"
# else:
# url = f"{url}?{key}={value}"
# first = False
# return url
# def build_api_uri(base_uri, version="v1", **kwargs):
# url = base_uri+'/'+version
# if kwargs:
# params = "&".join([f"{key}={value}" for key, value in kwargs.items()])
# url = f"{url}?{params}"
# return url
# print(build_api_uri('abc.com', page=1, pagesize=100, page1=1, pagesize1=100))
# class APIClient:
# def __init__(self, host, api_key="noapi"):
# self.host = host
# self.apiKey = api_key
# pass
# def get(self, path):
# if not path.startswith("/"):
# raise InternalError(f"Path must start with '/', got: '{path}'")
# url = f"{self.host}{path}"
# headers = {"Authorization": f"Bearer {self.apiKey}"}
# return {"url":url, "headers":headers}
# def __repr__(self):
# return f"APIClient({self.host})"
# class InternalError(ValueError):
# pass
# client = APIClient("https://api.noon.com", api_key="abc123")
# client.get("products") # Should raise ValueError
# client.get("/products") # Should work fine