Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
9 years ago

facing an runtime python error "int object has no attribute split "

Hi All, Am trying to save the extracted data from the DB to a list but am facing the python runtime error "int  object has no attribute split"

 

 
def TestProc():
   AConnection = ADO.CreateADOConnection()
   AConnection.ConnectionString = "Provider=MSDASQL.1;" + \
  "Data Source=teachersDB";
   AConnection.LoginPrompt = False
  AConnection.Open()
  RecSet = AConnection.Execute_('select empno from emptable')
  RecSet.MoveFirst();
  while not RecSet.EOF:  
    rows = RecSet.Fields.Item["empno "].Value
    rows=  rows.split(",")
    Log.Message(rows)
    RecSet.MoveNext()
  AConnection.Close()
 
  

    

When am trying to convert from int to list or string to list also its not working Can anybody help me out

  • baxatob's avatar
    baxatob
    9 years ago

    Try to update your code:

     

    ...

    data_container = [] # create an empty list while not RecSet.EOF: rows = RecSet.Fields.Item["empno "].Value data_container.append(rows) # add retrieved value to the list RecSet.MoveNext()
    ...

    After the while loop will be completed, data_container list should contain all requested values from your table.

  • baxatob's avatar
    baxatob
    9 years ago

    Try this:

     

    Log.Message(str(data_container))

    That is not the best solution, but it should help you to understand the output using Log.Message() method.

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    Please clarify, what do you expect from your function.

     

    Why you have call the split() method within each iteration of the while loop? What type of data returns from the data base?

     

    split() is a string's method, but your table contains integers.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      1) Expectation of my function is to extract the data from the database

      2)i was able to extract the data but the data was coming in the column format but i want them in a list so i was trying to split the column wise value and assassin that into a List so that i can compare two Lists

      • baxatob's avatar
        baxatob
        Community Hero

        Try to update your code:

         

        ...

        data_container = [] # create an empty list while not RecSet.EOF: rows = RecSet.Fields.Item["empno "].Value data_container.append(rows) # add retrieved value to the list RecSet.MoveNext()
        ...

        After the while loop will be completed, data_container list should contain all requested values from your table.