Skip to content

Commit

Permalink
Sample adjusted for Python3 (google#7819)
Browse files Browse the repository at this point in the history
Co-authored-by: chrismue <[email protected]>
Co-authored-by: Derek Bailey <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2023
1 parent 535ead8 commit 6af83a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions samples/sample_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ def main():
# Note: We did not set the `Mana` field explicitly, so we get a default value.
assert monster.Mana() == 150
assert monster.Hp() == 300
assert monster.Name() == 'Orc'
assert monster.Name() == b'Orc'
assert monster.Color() == MyGame.Sample.Color.Color().Red
assert monster.Pos().X() == 1.0
assert monster.Pos().Y() == 2.0
assert monster.Pos().Z() == 3.0

# Get and test the `inventory` FlatBuffer `vector`.
for i in xrange(monster.InventoryLength()):
for i in range(monster.InventoryLength()):
assert monster.Inventory(i) == i

# Get and test the `weapons` FlatBuffer `vector` of `table`s.
expected_weapon_names = ['Sword', 'Axe']
expected_weapon_names = [b'Sword', b'Axe']
expected_weapon_damages = [3, 5]
for i in xrange(monster.WeaponsLength()):
for i in range(monster.WeaponsLength()):
assert monster.Weapons(i).Name() == expected_weapon_names[i]
assert monster.Weapons(i).Damage() == expected_weapon_damages[i]

Expand All @@ -128,10 +128,10 @@ def main():
union_weapon = MyGame.Sample.Weapon.Weapon()
union_weapon.Init(monster.Equipped().Bytes, monster.Equipped().Pos)

assert union_weapon.Name() == "Axe"
assert union_weapon.Name() == b"Axe"
assert union_weapon.Damage() == 5

print 'The FlatBuffer was successfully created and verified!'
print('The FlatBuffer was successfully created and verified!')

if __name__ == '__main__':
main()

0 comments on commit 6af83a7

Please sign in to comment.