本文整理汇总了Python中state.State.load方法的典型用法代码示例。如果您正苦于以下问题:Python State.load方法的具体用法?Python State.load怎么用?Python State.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadState
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def loadState(self):
try:
state = State().fromFile(os.path.join(self.appdir, 'state.json'))
except IOError:
state = State().fromJSON(self.createDefaultState())
finally:
state.load()
示例2: test
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def test():
if request.method == 'GET':
return render_template('test.html')
else:
name = request.form['name']
code = request.form['code']
from main import run, loadBettingFunctions
bfs = loadBettingFunctions()
errors = []
def catchErrors(bf):
def bf2(*args):
try:
result = bf(*args)
if result is None or not isinstance(result, tuple) or len(result) != 2:
raise Exception("Bad value returned: %r" % result)
return result
except Exception as ex:
errors.append(ex)
raise ex
return bf2
from random import randint
filename = 'temp_test_%d.py' % randint(0,1000000)
with open(filename, 'w') as f:
f.write(code)
f.close()
try:
bfs[name] = catchErrors(__import__(filename[:-3]).bet)
from state import State
state = State.load()
bets, converged = run(state, bfs, max_iterations = 100)
if errors:
raise errors[0]
return render_template('test.html', name=name, code=code, run=True, bets=bets, converged=converged)
except Exception as ex:
print repr(ex)
return render_template('test.html', name=name, code=code, error=repr(ex))
finally:
import os
os.remove(filename)
示例3: test
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def test():
if request.method == 'GET':
return render_template('test.html')
else:
name = request.form['name']
code = request.form['code']
from main import run, loadBettingFunctions
bfs = loadBettingFunctions()
error = None
def catchErrors(bf):
def bf2(*args):
try:
return bf(*args)
except Exception as ex:
error = ex
raise ex
return bf2
try:
with open('temp_test.py', 'w') as f:
f.write(code)
f.close()
from temp_test import bet
bfs[name] = bet
from state import State
state = State.load()
bets, converged = run(state, bfs, max_iterations = 50)
if error:
raise error
return render_template('test.html', run=True, bets=bets, converged=converged)
except int as ex:
print repr(ex)
return render_template('test.html', error=repr(ex))
示例4: history
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def history():
from state import State
return render_template('history.html', state=State.load())
示例5: index
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def index():
from state import State
return render_template('index.html', state=State.load())
示例6: bfForPlayerName
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
def bfForPlayerName(name):
return getattr(__import__('players.%s' % name), name).bet
return dict((name, bfForPlayerName(name)) for name in playerNames)
def run(state, bfs, max_iterations = 10000):
from market import solve
return solve(bfs, dict((name, state.wealth.get(name, state.DEFAULT_WEALTH)) for name in bfs), state.rounds, max_iterations)
def main(state, outcome):
bets, converged = run(state, loadBettingFunctions())
return bets, converged, state.advance(bets, outcome)
if __name__ == "__main__":
from state import State
state = State.load()
outcome_exists = False
outcome = 0.5
from sys import argv
if len(argv) > 1:
try:
outcome = float(argv[1])
outcome_exists = True
except:
pass
bets, converged, newState = main(state, outcome)
formatBT = lambda bt: '\n'.join('%s: %0.1f, %0.1f' % thing for thing in sorted((k, t, f) for k, (t, f) in bt.items()))
示例7: xrange
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import load [as 别名]
#!/usr/bin/env python
from state import State
import os
import time
from kmc import kmc
import sys
s = State.load(sys.argv[1])
t = 0
time_i = 0
time_f = 0
nsteps = 0
for i in xrange(100000):
time_i = time.time()
s, dt = kmc(s)
time_f = time.time()
t+=dt
nsteps+=1
os.system('clear')
print s
print "energy:",s.energy
print "time:",t
print "dt:", dt
print "nsteps:", nsteps
print "nstates:", len(State.states)
if time_f - time_i > 0: