Python Forum
Alternative to dynamic variable names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternative to dynamic variable names
#11
Why your results are different from my results? What I am doing wrong?
Reply
#12
Use https://docs.python.org/3/library/timeit.html instead of time
Reply
#13
Several things are wrong
  • The print() statement is very slow and its execution time varies. Don't include it in the test.
  • Here you want to compare the difference between vars()['foo'] and my['foo']. Don't include anything else in the test
  • Use the timeit module, which is much more precise because it runs the statements 1,000,000 times by default and uses a good timer.
Reply
#14
Thank you all!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  creating arbitrary local variable names Skaperen 9 1,823 Sep-07-2024, 12:12 AM
Last Post: Skaperen
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 2,196 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Use dynamic variable from parallel running python script Sicksym 0 2,351 May-15-2020, 02:52 PM
Last Post: Sicksym
  Can I use iteration to create variable names? Mark17 8 10,166 Oct-17-2019, 06:05 AM
Last Post: perfringo
  How do I create a Dynamic Variable? Nwb 1 3,299 Jun-10-2018, 11:50 AM
Last Post: volcano63
  2D Array/List OR using variables in other variable names? IAMK 4 5,015 Apr-16-2018, 09:09 PM
Last Post: IAMK
  Creating Dynamic Variable Names Dragonexpert 3 9,145 Oct-22-2016, 02:17 PM
Last Post: Dragonexpert

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020