-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
36 lines (31 loc) · 1012 Bytes
/
functions.py
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
# Define functions for writing variables
def writevar(name): # For user input
import config
command = "config." + name
try:
exec(command)
except (NameError, AttributeError):
var_written = False
while not var_written:
print("Enter value of \'" + name + "\":")
try:
user_input = int(input())
var_written = True
except ValueError:
var_written = False
print("ERROR! Invalid entry . . .")
with open("config.py", "a") as f:
f.write("\n" + name + " = " + str(user_input))
def writevar(name, value): # For predefined values
import config
command = "config." + name
try:
exec(command)
except (NameError, AttributeError):
with open("config.py", "a") as f:
f.write("\n" + name + " = " + str(value))
# Reloading config file
def reload_config():
import importlib
import config
importlib.reload(config)