Play
Multi-Player
Coins
Community
Settings
Help
Community   Maps   Forum   Mail   Tournaments   Ladders   Clans   Recent Games
Sign In | Sign Up
<< Back to Programming Forum   

Posts 1 - 2 of 2   
How do you translate JS property lists to Py 2.7: 7/19/2017 17:32:04

DanWL 
Level 62
Report
I want to translate this JS code to Python 2.7:
var players =
{
	one:
	{
		name: 'Player One',
		money: 1500
	},
	two:
	{
		name: 'Player Two',
		money: 1400
	}
}


Accessing player one's name should return 'Player One'.
Accessing one's money should return 1500.
Accessing player two's name should return 'Player Two'.
Accessing two's money should return 1400.

Edit:
Can you also show how you'd be able to access player 1 and player 2 in the Python translation?

Thanks in advance.

Edited 7/19/2017 21:09:36
How do you translate JS property lists to Py 2.7: 7/19/2017 21:42:05

DanWL 
Level 62
Report
Just figured it out 2 mins ago :)

class players:
    class one:
        name = 'Player One'
        money = 1500
    class two:
        name = 'Player Two'
        money = 1400

>>> players.one.name
>>> players.one.money
>>> players.two.name
>>> players.two.money
Posts 1 - 2 of 2   

Contact | About WarLight | Play Risk Online | Multiplayer Strategy Game | Skill Game | Terms of Service