Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python and SQL mastery
#1
Good day, Dear Pythonistas

I have the following question:

I know that there are a lot of courses and materials about (Python + SQL) implementation, although most of them have very different approaches to learning (for example, some of them even include very deep concepts of Relational Algebra and so on). I understand that it is important and should not be ignored in the future, but I would like to gain first-hand experience.

Those of you who maybe work in the industry and apply these concepts regularly, could you please suggest courses/books/materials about SQL and Python+SQL (junior and middle level) or your professional approach.

It would be great to hear your story
Reply
#2
Maybe you are over-thinking this. It is not an arcane and esoteric mystery. If you can use SQL commands on the command line, or in say, phpMyAdmin, then you can use them in Python.

Think Nike: just do it!

I just do simple stuff, collecting homework or online classwork, but it works like this (and very fast):

import pymysql

# this 1 should get Monday's online class work, then Thursday's CW
def mysqlRemoteCW(clas, weeknr): 
    # To connect remote MySQL database 
    conn = pymysql.connect( 
        host='123.456.789.123',
        # listening on the default port, no need to set the server access port
        #port=123456,
        user='myuser',  
        password = 'mypassword', 
        db='mydbname', 
        )       
    cur = conn.cursor()   
    # Select query     
    sql = f"SELECT studentnr, score FROM allstudentsAnswers{clas}CW WHERE weeknr = %s"
    cur.execute(sql, (weeknr,))
    output = cur.fetchall()      
    # To close the connection 
    conn.close()
    return output

clas = input('Enter 20BE or 20EAP or 21BE  ')
weeknumber = input('Just enter a week number, like: Week1_M or Week4_M or Week11_T ')
results = mysqlRemoteCW(clas, weeknumber)
studentsScoresM = {}
# read the results in
for result in results:
    studentsScoresM[result[0]] = result[1]
# put the results in Excel
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020