-1

I need to know how to do something like how in Lua you would use:

foo={
   x=7,
   y=5
}

and retrieve the variables with foo.x. Thank you!

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • I'm not familiar with Lua, but this looks like a dict. Have you considered that? The syntax would be `foo = {'x': 7, 'y': 5}; foo['x']` – wjandrea Dec 28 '20 at 15:51
  • I think this answer would help you: [How to use dot notation for dict in python?](https://stackoverflow.com/a/16279578/6030424) – Tom Myddeltyn Dec 28 '20 at 15:53
  • You're either looking to create a class or a dictionary with my lack of knowledge of Lua. Please explain more as to what this "collection" is to be used for and we can further help you. – Jab Dec 28 '20 at 15:56
  • You can use [**`types.SimpleNamespace`**](https://docs.python.org/3/library/types.html#types.SimpleNamespace) – Peter Wood Dec 28 '20 at 15:57
  • See [this answer](https://stackoverflow.com/a/49438171/1084416) – Peter Wood Dec 28 '20 at 15:58

2 Answers2

0

You're looking for a dictionary, where you're able to access key , value pairs.

foo={
   'x':7,
   'y':5
}

the semicolon is used to assign the key to the value

foo = { 
 'key':value
}
0

Use a python Dictionary type:

foo = {
    'x' : 7,
    'y': 5
}

Retrieve with: foo['x']

Here's the official documentation: https://docs.python.org/3/tutorial/datastructures.html#dictionaries

Ivy Allie
  • 43
  • 5