Search code examples
pythondatabasepyodbcfilemaker

Using python, I'm trying to access text from a database, but I'm getting different results when I do just print vs a foreach loop


Using python, I'm trying to access text from a database (FileMaker Pro) using a pyodbc connection. When I use a foreach loop, for some reason the text prints. But, when I just straight away print it then I think it prints the location or something. The following code explains it better:

 import pyodbc
 connectString = "DSN=FMODBC32;UID=...;PWD=..." 
 connection = pyodbc.connect(connectString)
 cursor = connection.cursor()

 param = cursor.execute("select Parameters from Info")
       ## Parameters = fieldName in the database, Info = tableName in database

 print(param)
       ## This prints: <pyodbc.Cursor object at 0x08930C20>  (Is this the location?)

 for info in param:
     print(info) 
       ## This prints the actual text I need, not the location

I want to just do print(param) and not a whole foreach loop to get the text I need. Any advice?


Solution

  • print(param)
    

    only prints you the param object.

    You should add

    cursor = connection.cursor()
    cursor.execute("select Parameters from Info")
    param = cursor.fetchall()
    

    and print(param) should be ok.