ForDictValues class¶
This page explains the ForDictValues
class.
Before reading on, maybe it is helpful to read the following page (the apysc uses this class for the same reason for each data type):
What class is this?¶
The ForDictValues
class is the for-loop class.
This interface returns Dictionary
’s value in a loop.
Basic usage¶
This class requires using the with
-statement.
The as
-keyword value becomes a Dictionary
’s value.
Also, this class requires the dict_value_type
argument to specify a type of Dictionary
’s value type.
This type only accepts an apysc type, such as the String
, Int
, or Rectangle
.
import apysc as ap
ap.Stage(
stage_width=250,
stage_height=150,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
dict_: ap.Dictionary[str, ap.Number] = ap.Dictionary(
{"a": ap.Number(50), "b": ap.Number(150)},
)
with ap.ForDictValues(dict_=dict_, dict_value_type=ap.Number) as value:
ap.Rectangle(
x=value,
y=50,
width=50,
height=50,
fill_color=ap.Color("#0af"),
)
ap.save_overall_html(dest_dir_path="for_dict_values_basic_usage_1/")
See also¶
Each branch instruction class’s scope variables reverting setting
Notes: This class also has the same arguments and behaves in the same way.
ForDictValues API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] __init__(self, dict_: apysc._type.dictionary.Dictionary[typing.Any, ~_DictValue], dict_value_type: Type[~_DictValue], *, locals_: Union[Dict[str, Any], NoneType] = None, globals_: Union[Dict[str, Any], NoneType] = None, variable_name_suffix: str = '') -> None
[Interface summary]
The loop implementation class for the ap.Dictionary
values.
[Parameters]
dict_
: Dictionary[Any, _DictValue]A dictionary to iterate.
dict_value_type
: Type[_DictValue]A dictionary value type. This interface accepts
InitializeWithBaseValueInterface
subclasses, such as theInt
,String
, orRectangle
.
locals_
: Optional[Dict[str, Any]], optionalCurrent scope’s local variables. Set locals() value to this argument. If specified, this interface reverts all local scope VariableNameMixIn variables (like Int, Sprite) at the end of a with-statement scope. This setting is useful when you don’t want to update each variable.
globals_
: Optional[Dict[str, Any]], optionalCurrent scope’s global variables. Set globals() value to this argument. This setting works the same way as the locals_ argument.
variable_name_suffix
: str, optionalA JavaScript variable name suffix string. This setting is sometimes useful for JavaScript debugging.