本文整理汇总了Python中state.State.create方法的典型用法代码示例。如果您正苦于以下问题:Python State.create方法的具体用法?Python State.create怎么用?Python State.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_state
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import create [as 别名]
def add_state(self, state_name):
"""Adds a new state, and returns it."""
if self._has_state_named(state_name):
raise Exception('Duplicate state name %s' % state_name)
state = State.create(self, state_name)
self.states.append(state.key)
self.put()
return state
示例2: create
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import create [as 别名]
def create(cls, user, title, category, exploration_id=None,
init_state_name='Activity 1', image_id=None):
"""Creates and returns a new exploration."""
# Generate a new exploration id, if one wasn't passed in.
exploration_id = exploration_id or cls.get_new_id(title)
# Temporarily create a fake initial state key.
state_id = State.get_new_id(init_state_name)
fake_state_key = ndb.Key(Exploration, exploration_id, State, state_id)
# Note that demo explorations do not have owners, so user may be None.
exploration = cls(
id=exploration_id, title=title, init_state=fake_state_key,
category=category, image_id=image_id, states=[fake_state_key],
editors=[user] if user else [])
exploration.put()
# Finally, create the initial state and check that it has the right key.
new_init_state = State.create(
exploration, init_state_name, state_id=state_id)
assert fake_state_key == new_init_state.key
return exploration