<< Back to Programming Forum   Search

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

(deleted) 
Level 63
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: 2017-07-19 21:42:05

(deleted) 
Level 63
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