Python Forum
Do I have to pass 85 variables to function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I have to pass 85 variables to function?
#9
(Sep-26-2020, 01:28 PM)Milfredo Wrote:
            'dist_yards1' : line[315],
            'dist_yards2' : line[316],
            'dist_yards3' : line[317],
            'dist_yards4' : line[318],
            'dist_yards5' : line[319],
            'dist_yards6' : line[320],
            'dist_yards7' : line[321],
            'dist_yards8' : line[322],
            'dist_yards9' : line[323],
            'dist_yards10' : line[324],

One thing you might consider, for runs like this that always have the same number of data points, is to keep the dictionary element as a single list of N values. So,
h["dist_yards"] = [ line[315], line[316], .... line[324] ]

# Which, if they're all adjacent in the source data,
# you can even assign using a list slice:

h["dist_yards"] = line[315:324]
And so on for the other multi-value parameters. Then you'd just access them as,
h["dist_yards"][0] through h["dist_yards"][9]. (Or in any combinations, again using slices if appropriate:

first_three_dist_yards = h["dist_yards"][0:2]

Correction: I screwed up my slice syntax, as usual.

# Make that
h["dist_yards"] = line[315:325]  # Yes, one higher than the last element

# And
first_three_dist_yards = h["dist_yards"][0:3]
Reply


Messages In This Thread
RE: Do I have to pass 85 variables to function? - by ferdnyc - Sep-26-2020, 08:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 887 Jul-27-2023, 12:40 AM
Last Post: tester_V
  How to print variables in function? samuelbachorik 3 929 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  User-defined function to reset variables? Mark17 3 1,688 May-25-2022, 07:22 PM
Last Post: Gribouillis
  How to pass variables from one class to another hobbyist 18 10,879 Oct-01-2021, 05:54 PM
Last Post: deanhystad
  Regex - Pass Flags as a function argument? muzikman 6 3,650 Sep-06-2021, 03:43 PM
Last Post: muzikman
  Possible to dynamically pass arguments to a function? grimm1111 2 2,222 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,577 Sep-07-2020, 08:02 AM
Last Post: perfringo
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,516 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Pass integers to datetime.date function florian 3 2,744 Jul-18-2020, 04:43 AM
Last Post: scidam
  How to pass multiple arguments into function Mekala 4 2,480 Jul-11-2020, 07:03 AM
Last Post: Mekala

Forum Jump:

User Panel Messages

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