S
S
SideWest2019-05-10 10:26:38
Python
SideWest, 2019-05-10 10:26:38

Python. Import at the right time. Script modification. What should I do?

I have a hosted script, it works around the clock, but often I have to change the input data in it , and therefore I have to stop it, rewrite it and turn it on again, I got the idea to put them in a separate file and import them every time you go into the loop :

while True:
    time.sleep(10)
    from config import pay,people,dialogs

But such a miracle did not bring results, the program imports once at the first start and then works with the first values, then the idea came up to write it down in a notebook and do f.open()
every time But bad luck, my data is more complicated than a simple string, it is a dictionary type:
people = {
'Дима': (200003,'cb85e'),
'Паша': (2003,'cf8c3705'),
'Вест': (20013,'559108f0e06'),
'Вова': (2001,'6664c9'),
'Тома': (201,'a04d7')
}

Tell me how should I be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2019-05-10
@SideWest

1) you can reload the module: 3.4+ importlib.reload
2) you can run the script through subprocess with packing -> unpacking (for example, through pickle)
3) store it in json/hjson/json5/yaml, etc.

S
Sergey Gornostaev, 2019-05-10
@sergey-gornostaev

import json

with open('settings.json', encoding='utf-8') as fh:
    config = json.load(fh)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question