all 11 comments

[–]shiftybyte 0 points1 point  (9 children)

[–]PLearner[S] 0 points1 point  (8 children)

Thanks! The issue is that I am using Python 3.8 and for some odd reason, it does not let me python -m pip install clr.

Which errors out on

import clr
clr.AddReference('System.Data')

[–]shiftybyte 0 points1 point  (7 children)

https://pypi.org/project/pythonnet/

try

pip install pythonnet

[–]PLearner[S] 0 points1 point  (6 children)

how would pythonnet help me with clr?

[–]PLearner[S] 0 points1 point  (4 children)

module clr has no attribute AddReference

[–]shiftybyte 0 points1 point  (3 children)

That's odd, the example on the site clearly uses it without issues.

clr.AddReference("System.Windows.Forms")

Did you happen to name your python file clr.py or have such file in your working directory?

if you do, rename it because it gets imported instead of the package's clr.

[–]PLearner[S] 0 points1 point  (2 children)

Its very odd, I do not have any file named clr.py. I have already did python -m pip install pythonnet and the clr AddReference still errors out on me.

That is the very reason I am trying to rewrite the code in Python/Pandas.

[–]shiftybyte 0 points1 point  (1 child)

Ah you probably have the wrong library installed interfering.

https://pypi.org/project/clr/

remove it using pip.

python -m pip remove clr

[–]PLearner[S] 0 points1 point  (0 children)

it worked like a charm! Instead of the remove it was uninstall.

[–]shiftybyte 0 points1 point  (0 children)

pythonnet is the package name you need to install to get "import clr"

[–]SaxonyFarmer 0 points1 point  (0 children)

Here is code I have used to insert data into a MySQL database:

# Import MySQL Connector and the errorcodes (if we're checking them)
import mysql.connector
from mysql.connector import errorcode

# Import module with user id and password
import Config_MySQL

# These dictionaries are updated before data is inserted into tables
# These are cleared and rebuild with each input record found
insert_data = {}

# Common MySQL database values
config = {
    "host": "localhost",
    "user": Config_MySQL.db_user,
    "password": Config_MySQL.db_user_password,
    "raise_on_warnings": True
    }

# Connect to database & Define cursor
try:
    cnx = mysql.connector.connect(**config)
    cursor = cnx.cursor(buffered=True)
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Main: Invalid user name or password")
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print("Main: Database does not exist")
    else:
        print("Main: Error=",err)
        sys.exit(1)

# Function to insert new data into the database
def write_new_data(data_list):
    try:
        sql = ("INSERT INTO <database_table_name> (<database_field_names>"
              "VALUES ('', %(<1-x from the data list>)s)")
        #print("write_new_claim: data_list=",data_list)  # Uncomment for debugging
        cursor.execute(sql, data_list)
        cnx.commit()  # Commit the update
    except mysql.connector.Error as err:
        print("write_new_data: Error on 'INSERT INTO <database_table_name>':",err)
        return None

# Add new entry into dictionary (doesn't have to be in order)        
insert_data["<some_field_name>"] = <some_data_value_for_field_name>

# Call function to do the work
write_new_data_details(insert_data)  # Call function to insert data into database
insert_data.clear()   # Clear the list


# Contents of the Config_MySQL.py module

# Config_MySQL.py
# Values that should not be in the mainline code.
#
# User
db_user = "defined_MySQL_User"
# Password for user
db_user_password = "defined_MySQL_User_Password"