3

I have some functions that have huge inputs (some of them has 28 etc), I have to print those variables by same sequence with inputs. I'm getting those variables with locals() functions. However this function gives me a dictionary which has totally different sequence.

So, how can I get these variables without changing their sequence ?

iva123
  • 3,395
  • 10
  • 47
  • 68
  • 2
    This is why Python offers keyword parameters. Why aren't you using keyword parameters? Why are you using large numbers of position parameters? – S.Lott Dec 16 '10 at 12:47
  • Why do you have to print them in the same order? This sounds like the wrong solution. – Lennart Regebro Dec 16 '10 at 13:29
  • Could you post a sample code, so we could see what do you mean? From what you've written it sounds like you're creating this problem in the first place. What problem you are trying to solve in your program? – Paweł Prażak Dec 16 '10 at 14:12
  • Since 3.7 (released in 2018), dictionaries are now ordered. Does anyone know if locals() returns in order for Python >= 3.7? – michen00 Aug 31 '22 at 05:44

1 Answers1

3

Give a look at this other SO question. They suggest several ways of doing what you want. The easiest one seems to be using inspect instead of locals.

Community
  • 1
  • 1
kikito
  • 51,734
  • 32
  • 149
  • 189