Python Forum

Full Version: 'module' object is not callable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,,

I'm a rookie with Python and as you can see from above I'm getting the following message. If I remove the xport line I receive no errors. Am I calling xport the wrong way?

Thanks

Error:
"module' object is not callable"
import pandas as pd
import pyodbc
import xport

# Trusted Connection to Named Instance
try:
    connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=laptop\MS_SQLEXPRESS;DATABASE=CheckData;Trusted_Connection=yes;')
except Exception as err:
    print('Exception occured while trying to create a connection ', err)
else:
    try:

        sql_query = pd.read_sql_query('''EXEC sp_Rtest''', connection) 
        # here, the 'connection' is the variable that contains your database connection information from step 2

        df = pd.DataFrame(sql_query)

        pd.set_option("display.max_columns", None)
        

        df.head()    

       with open("C:/Users/myfiles/my_file.xpt", "wb") as f:xport(df,f)


    except Exception as err:
       print('Exception occurred while fetching records ', err)
    else:
        print('')
    finally:
      print('')
finally:
    connection.close()
Please, post the full traceback you get, in error tags
(Nov-04-2021, 02:17 PM)Racer_x Wrote: [ -> ]Am I calling xport the wrong way?

It looks like that. Did you check the examples in the docs
They do import xport.v56 or import xport.v89
Then they use xport.v56.load() (or .loads()) and bind the return value to a name or xport.v56.dump() ( or .dumps()).

In your code you try to call xport() and you get the above error. Also even if it miraculously worked, you just throw away the return value.

Also note that for v89 only loads/dumps are implemented.
(Nov-04-2021, 02:44 PM)buran Wrote: [ -> ]Please, post the full traceback you get, in error tags
(Nov-04-2021, 02:17 PM)Racer_x Wrote: [ -> ]Am I calling xport the wrong way?

It looks like that. Did you check the examples in the docs
They do import xport.v56 or import xport.v89
Then they use xport.v56.load() (or .loads()) and bind the return value to a name or xport.v56.dump() ( or .dumps()).

In your code you try to call xport() and you get the above error. Also even if it miraculously worked, you just throw away the return value.

Also note that for v89 only loads/dumps are implemented.
Here's the full error:
Error:
PS C:\Users\Test Files> python -u "c:\Users\Test Files\xport.py" Exception occured while fethcing records 'module' object is not callable Exception occured while fethcing records 'module' object is not callable
There is one more problem - your own file is named xport.py and at the moment it try to import it, not the xport package. Rename your file to something else.
(Nov-04-2021, 03:15 PM)buran Wrote: [ -> ]There is one more problem - your own file is named xport.py and at the moment it try to import it, not the xport package. Rename your file to something else.

BAM!!!! You're a Genius!!! Thanks Buran!!! That was it, I'll continue to work on it but as soon as I changed the name certain attributes became available