Storing 50 Variables data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    Storing 50 Variables data

    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
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by psbasha
    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:
    [code=python]
    myValues = [10, 0, 20, 'Yes', True, None, 3, 3.21]
    myValues.append (12)
    myValues.append ("No")
    print myValues
    [/code]
    Is threre anything special you want to do with the data?

    Comment

    • psbasha
      Contributor
      • Feb 2007
      • 440

      #3
      Originally posted by ilikepython
      I don't think it has to be so complicated:
      [code=python]
      myValues = [10, 0, 20, 'Yes', True, None, 3, 3.21]
      myValues.append (12)
      myValues.append ("No")
      print myValues
      [/code]
      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

      Comment

      • psbasha
        Contributor
        • Feb 2007
        • 440

        #4
        Originally posted by psbasha
        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

        Comment

        • ilikepython
          Recognized Expert Contributor
          • Feb 2007
          • 844

          #5
          Originally posted by psbasha
          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.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by psbasha
            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:[CODE=python]
            >>> class simulateStructu re:
            ... name = ""
            ... age = 0
            ... address = None
            ...
            >>> simulateStructu re.name = "Joe Blow"
            >>> simulateStructu re.sibbling = "brother"
            >>> simulateStructu re.sibbling
            'brother'
            >>> [/CODE]

            Comment

            Working...