I think my title isn't clear so... I made this code which fetches top Dota TV games as an array of these match_ids and prints them in the end. STEAM_LGN
, STEAM_PSW
are steam login/password combination.
from steam.client import SteamClient
from dota2.client import Dota2Client
client = SteamClient()
dota = Dota2Client(client)
@client.on('logged_on')
def start_dota():
dota.launch()
match_ids = []
@dota.on('top_source_tv_games')
def response(result):
for match in result.game_list: # games
match_ids.append(match.match_id)
def request_matches():
dota.request_top_source_tv_games()
client.cli_login(username=STEAM_LGN, password=STEAM_PSW)
request_matches()
dota.on('top_source_tv_games', response)
print(match_ids)
The thing I'm having a problem with
When using Anaconda iPython Notebook -> when I run the cell for the first time -> it returns me
[]
but when I do it for the second time, it returns me a real data, for example
[5769568657, 5769554974, 5769555609, 5769572298, 5769543230, 5769561446, 5769562113, 5769552763, 5769550735, 5769563870]
So every time when I am playing in my ipython notebook sandbox -> I hit Shift+Enter
twice and get the data.
But now I need to tranfer this code to a bigger project. So for example let's say I save that code to dota2.info.py
file and have this code in another file referencing dota2.info.py
:
import subprocess
import time
### some code ###
while(True):
subprocess.call(['python', './dota2info.py'])
time.sleep(10)
And when running project code this always prints []
like it was doing on first Shift+Enter
cell-running in Anaconda ipython notebook.
[]
[]
[]
...
So my question is what should I do in this situation ? How can I solve this problem of (I don't know) ValvePython/dota2 code caching some important data in local unknown to me variables in ipython notebook?
Ideally I want the code immediately give me real data without having these []
.
question from:
https://stackoverflow.com/questions/65545768/how-do-i-make-code-save-local-variables-between-its-processes-in-python-like-ipy 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…