Python Forum
is it pythonic to add a name 'attribute' to an existing variable?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is it pythonic to add a name 'attribute' to an existing variable?
#1
I have several variables in a list: - they are the result of ana analysis run using another library in python

vars = [run1, run2, run3, run4]
I now need to run one more analysis in a for loop and save the objects within the for loop. For this reason, during the save, i want to add a name attribute to the variables so that I can have a convenient filename for each.

Is it valid to do the following before the for loop in python? I know that attributes are set explicitly in classes, but for something minor like a string, is it valid to add a name attribute which is just a string descriptor to a variable?

vars[0].name = 'name1'
-- etc

thank you
Reply


Messages In This Thread
is it pythonic to add a name 'attribute' to an existing variable? - by amjass12 - Oct-04-2021, 08:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create new variable dependent on two existing variables JoeOpdenaker 6 3,123 Oct-25-2020, 02:15 PM
Last Post: jefsummers
  Assignment of non-existing class variable is accepted - Why? DrZ 6 4,339 Jul-13-2020, 03:53 PM
Last Post: deanhystad
  which is "better" (or more Pythonic)? Skaperen 2 2,087 Feb-01-2020, 03:10 PM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 7 3,273 Feb-01-2020, 03:51 AM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 8 3,420 Nov-16-2019, 06:46 PM
Last Post: Skaperen
  which is more Pythonic? Skaperen 5 2,917 Jul-16-2019, 01:00 AM
Last Post: Skaperen
  Function Attribute / Global Variable Confusion digitalmatic7 1 5,414 Feb-13-2018, 09:54 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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