By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,589 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,589 IT Pros & Developers. It's quick & easy.

Storing 50 Variables data

100+
P: 440
Hi ,

I will get the 50 values.Here I have tow scenarios.
Case -1 ) 50 Values may be same data types

10,20,30,50 .......

Case-2) Different data types

10.0,20.0,'Yes',1

How to store these values ?.Whether using a list is a better approach or create a class and 50 memeber variables to the class and use that variables.

Could anybody suggest the better approach to store the variable data.

Thanks
PSB
Aug 22 '07 #1
Share this Question
Share on Google+
5 Replies

ilikepython
Expert 100+
P: 844
Hi ,

I will get the 50 values.Here I have tow scenarios.
Case -1 ) 50 Values may be same data types

10,20,30,50 .......

Case-2) Different data types

10.0,20.0,'Yes',1

How to store these values ?.Whether using a list is a better approach or create a class and 50 memeber variables to the class and use that variables.

Could anybody suggest the better approach to store the variable data.

Thanks
PSB
I don't think it has to be so complicated:
Expand|Select|Wrap|Line Numbers
  1. myValues = [10, 0, 20, 'Yes', True, None, 3, 3.21]
  2. myValues.append(12)
  3. myValues.append("No")
  4. print myValues
  5.  
Is threre anything special you want to do with the data?
Aug 22 '07 #2

100+
P: 440
I don't think it has to be so complicated:
Expand|Select|Wrap|Line Numbers
  1. myValues = [10, 0, 20, 'Yes', True, None, 3, 3.21]
  2. myValues.append(12)
  3. myValues.append("No")
  4. print myValues
  5.  
Is threre anything special you want to do with the data?
Yes,I agree that it is very simple to add in the list .
But when retriving the data from the list,the developer has to remember which index of the list stands for what element.If the list is of 10 different values ,there are no issues,if it exceeds more than 10 different values,how we will remember which list index stands for what value.And while editing the values the developer has to edit at the right index,otherwise application will crash.

How to handle this situation?

Thanks
PSB
Aug 22 '07 #3

100+
P: 440
Yes,I agree that it is very simple to add in the list .
But when retriving the data from the list,the developer has to remember which index of the list stands for what element.If the list is of 10 different values ,there are no issues,if it exceeds more than 10 different values,how we will remember which list index stands for what value.And while editing the values the developer has to edit at the right index,otherwise application will crash.

How to handle this situation?

Thanks
PSB
When some maintins the code,how the developer understand ,which index value of the list stands for what value,untill unless the comments are mentioned for each index of the list.

Thanks
PSB
Aug 22 '07 #4

ilikepython
Expert 100+
P: 844
When some maintins the code,how the developer understand ,which index value of the list stands for what value,untill unless the comments are mentioned for each index of the list.

Thanks
PSB
Will it be possible to convert all the members to strings? When you use them you could use the string.isdigit() or string.isalpha(). How are you getting the data? How are you using it? A little more details, please.
Aug 22 '07 #5

bartonc
Expert 5K+
P: 6,596
When some maintins the code,how the developer understand ,which index value of the list stands for what value,untill unless the comments are mentioned for each index of the list.

Thanks
PSB
What's wrong with using a class to simulate a structure? You get named variables and all of the benefits of dynamic typing:
Expand|Select|Wrap|Line Numbers
  1. >>> class simulateStructure:
  2. ...     name = ""
  3. ...     age = 0
  4. ...     address = None
  5. ...     
  6. >>> simulateStructure.name = "Joe Blow"
  7. >>> simulateStructure.sibbling = "brother"
  8. >>> simulateStructure.sibbling
  9. 'brother'
  10. >>> 
Aug 23 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.