-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElement.py
More file actions
38 lines (27 loc) · 759 Bytes
/
Element.py
File metadata and controls
38 lines (27 loc) · 759 Bytes
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
import json
class Element:
def __init__(self,Name):
#do things
#print("Element Created")
self.Name = Name
self.Valence = 1#not needed abs(self.FindValenceFromName(self.Name))
def __str__(self):
if(self.Valence ==1 ):
return self.Name
else:
return self.Name + str(self.Valence)
def GetJsonOfElements(self):
with open('valence.json') as data_file:
data = json.load(data_file)
return data
def FindValenceFromName(self,name):
if(self.CheckIfValidElement(name)):
return self.GetJsonOfElements()[name]
else:
return 1
def CheckIfValidElement(self,name):
data = self.GetJsonOfElements()
return data.has_key(name)
if __name__ == "__main__":
H = Element("H")
print(H.Name + " with Valence " + str(H.Valence))