当前位置: 首页>>代码示例>>Python>>正文


Python State.load方法代码示例

本文整理汇总了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()
开发者ID:sarkian,项目名称:vicmd,代码行数:9,代码来源:backend.py

示例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)
开发者ID:GallagherCommaJack,项目名称:markets,代码行数:52,代码来源:server.py

示例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))
开发者ID:nicholasRutherford,项目名称:markets,代码行数:44,代码来源:server.py

示例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())
开发者ID:GallagherCommaJack,项目名称:markets,代码行数:5,代码来源:server.py

示例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())
开发者ID:GallagherCommaJack,项目名称:markets,代码行数:5,代码来源:server.py

示例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()))
开发者ID:orthonormal,项目名称:markets,代码行数:33,代码来源:main.py

示例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:
开发者ID:MaxAndersson,项目名称:openstackeon,代码行数:33,代码来源:go.py


注:本文中的state.State.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。