SlideShare a Scribd company logo
(PYTHON) Running into output errors: file, Traceback, and OSError: [Errno 22]
import sqlite3
import json
import matplotlib.pyplot as plt
import tkinter as tk
import socket
import csv
import pandas as pd
class User_Layer:
def __init__(self, root):
self.root = root
self.root.title("Country Selection")
self.country_label = tk.Label(self.root, text="Select a country:")
self.country_label.pack()
self.country_list = tk.Listbox(self.root)
self.country_list.pack()
self.countries = pd.read_csv('"C:UsersnhiiDownloadsUSAStates2020.csv"') ['Country'].unique()
#only works with double and copied file path from folders
for country in self.countries:
self.country_list.insert(tk.END, country)
self.submit_button = tk.Button(self.root, text="Submit", command=self.submit)
self.submit_button.pack()
def submit(self):
selected_country = self.country_list.get(self.country_list.curselection())
business_layer = BusinessLayer()
business_layer.get_data(selected_country)
class BusinessLayer:
def __init__(self):
self.server_host = 'localhost'
self.server_port = 9999
def get_data(self, country):
sql_query = f"SELECT Year, Population FROM USAStates2020 WHERE Country = '{country}'
AND Year BETWEEN 1970 AND 2020"
data_layer = DataLayer(self.server_host, self.server_port)
data = data_layer.send_query(sql_query)
graphic_layer = GraphicLayer()
graphic_layer.plot(json.loads(data))
class DataLayer:
def __init__(self, host, port):
self.host = host
self.port = port
def send_query(self, query):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((self.host, self.port))
s.sendall(query.encode())
data = s.recv(1024).decode()
return data
class GraphicLayer:
def plot(self, data):
df = pd.DataFrame(data)
df['Year'] = pd.to_datetime(df['Year'], format='%Y')
plt.plot(df['Year'], df['Population'])
plt.title('Population vs Year')
plt.xlabel('Year')
plt.ylabel('Population')
plt.show()
class ServerLayer:
def __init__(self, host, port):
self.host = host
self.port = port
def start(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((self.host, self.port))
s.listen()
print(f"Server listening on {self.host}:{self.port}")
while True:
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
query = conn.recv(1024).decode()
conn.execute(query)
results = conn.fetchall()
json_data = json.dumps(results)
conn.sendall(json_data.encode())
if __name__ == "__main__":
root = tk.Tk()
User_Layer = User_Layer(root)
root.mainloop()
#output should have tkinter window allowing user to input selected country and print out
C02 graph from file
#file: https://1drv.ms/x/s!AhPNdK2Zw23UgTUllZBA6oB13pEc?e=Q6f5wV

More Related Content

Similar to PYTHON Running into output errors file Traceback and OS.pdf

Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Groupsapdocs. info
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCIS321
 
PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)Ange Albertini
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1saydin_soft
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016Mir Mahmood
 
A multi submission importer for easyform
A multi submission importer for easyformA multi submission importer for easyform
A multi submission importer for easyformAnnette Lewis
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAVRohit malav
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVRohit malav
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET componentsBình Trọng Án
 
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...Grafana Labs
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
Sq lite python tutorial sqlite programming in python
Sq lite python tutorial   sqlite programming in pythonSq lite python tutorial   sqlite programming in python
Sq lite python tutorial sqlite programming in pythonMartin Soria
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySqlkamal kotecha
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxamit657720
 

Similar to PYTHON Running into output errors file Traceback and OS.pdf (20)

Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Group
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
A multi submission importer for easyform
A multi submission importer for easyformA multi submission importer for easyform
A multi submission importer for easyform
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...
[PromCon2018] Prometheus Monitoring Mixins: Using Jsonnet to Package Together...
 
Apps1
Apps1Apps1
Apps1
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
Sq lite python tutorial sqlite programming in python
Sq lite python tutorial   sqlite programming in pythonSq lite python tutorial   sqlite programming in python
Sq lite python tutorial sqlite programming in python
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
srgoc
srgocsrgoc
srgoc
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 

More from onlineseller570

Why is formal training of workers so important to most emplo.pdf
Why is formal training of workers so important to most emplo.pdfWhy is formal training of workers so important to most emplo.pdf
Why is formal training of workers so important to most emplo.pdfonlineseller570
 
Which of the following isare true about phosphorus as a min.pdf
Which of the following isare true about phosphorus as a min.pdfWhich of the following isare true about phosphorus as a min.pdf
Which of the following isare true about phosphorus as a min.pdfonlineseller570
 
Ying Import has several bond issues outstanding each making.pdf
Ying Import has several bond issues outstanding each making.pdfYing Import has several bond issues outstanding each making.pdf
Ying Import has several bond issues outstanding each making.pdfonlineseller570
 
Which of the following would block a cells ability to migra.pdf
Which of the following would block a cells ability to migra.pdfWhich of the following would block a cells ability to migra.pdf
Which of the following would block a cells ability to migra.pdfonlineseller570
 
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdf
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdfUn pedazo de tierra fue despejado de rboles hace muchos ao.pdf
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdfonlineseller570
 
Una mujer de 50 aos acude al mdico con su marido por una h.pdf
Una mujer de 50 aos acude al mdico con su marido por una h.pdfUna mujer de 50 aos acude al mdico con su marido por una h.pdf
Una mujer de 50 aos acude al mdico con su marido por una h.pdfonlineseller570
 
Team Deliverable 3 Succession Planning Part Two Hide Assi.pdf
Team Deliverable 3  Succession Planning Part Two Hide Assi.pdfTeam Deliverable 3  Succession Planning Part Two Hide Assi.pdf
Team Deliverable 3 Succession Planning Part Two Hide Assi.pdfonlineseller570
 
A bar chart to represent the data below You shou.pdf
A bar chart to represent the data  below      You shou.pdfA bar chart to represent the data  below      You shou.pdf
A bar chart to represent the data below You shou.pdfonlineseller570
 
18 Consider the 3 alternative allocation methods from the p.pdf
18 Consider the 3 alternative allocation methods from the p.pdf18 Consider the 3 alternative allocation methods from the p.pdf
18 Consider the 3 alternative allocation methods from the p.pdfonlineseller570
 
2 Wine menu Your twelve 12 wine selections will include .pdf
2 Wine menu Your twelve 12 wine selections will include .pdf2 Wine menu Your twelve 12 wine selections will include .pdf
2 Wine menu Your twelve 12 wine selections will include .pdfonlineseller570
 
Como miembros de la facultad se les ha pedido que diseen u.pdf
Como miembros de la facultad se les ha pedido que diseen u.pdfComo miembros de la facultad se les ha pedido que diseen u.pdf
Como miembros de la facultad se les ha pedido que diseen u.pdfonlineseller570
 
3 Lets do two pedigree problems one thats straight forwa.pdf
3 Lets do two pedigree problems one thats straight forwa.pdf3 Lets do two pedigree problems one thats straight forwa.pdf
3 Lets do two pedigree problems one thats straight forwa.pdfonlineseller570
 
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdf
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdfQu estrategia buscaba implementar el nuevo CEO de JCPenney.pdf
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdfonlineseller570
 
11 Green Industries has 50 million shares outstanding and a.pdf
11 Green Industries has 50 million shares outstanding and a.pdf11 Green Industries has 50 million shares outstanding and a.pdf
11 Green Industries has 50 million shares outstanding and a.pdfonlineseller570
 
Table National Income Accounts Use Table National Income.pdf
Table National Income Accounts Use Table National Income.pdfTable National Income Accounts Use Table National Income.pdf
Table National Income Accounts Use Table National Income.pdfonlineseller570
 
Analyse the scenario provided by examining the relevant soci.pdf
Analyse the scenario provided by examining the relevant soci.pdfAnalyse the scenario provided by examining the relevant soci.pdf
Analyse the scenario provided by examining the relevant soci.pdfonlineseller570
 
5 Two random variables have the joint density fXYxyx.pdf
5 Two random variables have the joint density fXYxyx.pdf5 Two random variables have the joint density fXYxyx.pdf
5 Two random variables have the joint density fXYxyx.pdfonlineseller570
 
a The operation of DNA ligase is only possible in the 3 to.pdf
a The operation of DNA ligase is only possible in the 3 to.pdfa The operation of DNA ligase is only possible in the 3 to.pdf
a The operation of DNA ligase is only possible in the 3 to.pdfonlineseller570
 
8 Create a simple table in MS Word that shows similarities .pdf
8 Create a simple table in MS Word that shows similarities .pdf8 Create a simple table in MS Word that shows similarities .pdf
8 Create a simple table in MS Word that shows similarities .pdfonlineseller570
 
31 Which of the following best ifulrates miztanabichy A c.pdf
31 Which of the following best ifulrates miztanabichy A c.pdf31 Which of the following best ifulrates miztanabichy A c.pdf
31 Which of the following best ifulrates miztanabichy A c.pdfonlineseller570
 

More from onlineseller570 (20)

Why is formal training of workers so important to most emplo.pdf
Why is formal training of workers so important to most emplo.pdfWhy is formal training of workers so important to most emplo.pdf
Why is formal training of workers so important to most emplo.pdf
 
Which of the following isare true about phosphorus as a min.pdf
Which of the following isare true about phosphorus as a min.pdfWhich of the following isare true about phosphorus as a min.pdf
Which of the following isare true about phosphorus as a min.pdf
 
Ying Import has several bond issues outstanding each making.pdf
Ying Import has several bond issues outstanding each making.pdfYing Import has several bond issues outstanding each making.pdf
Ying Import has several bond issues outstanding each making.pdf
 
Which of the following would block a cells ability to migra.pdf
Which of the following would block a cells ability to migra.pdfWhich of the following would block a cells ability to migra.pdf
Which of the following would block a cells ability to migra.pdf
 
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdf
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdfUn pedazo de tierra fue despejado de rboles hace muchos ao.pdf
Un pedazo de tierra fue despejado de rboles hace muchos ao.pdf
 
Una mujer de 50 aos acude al mdico con su marido por una h.pdf
Una mujer de 50 aos acude al mdico con su marido por una h.pdfUna mujer de 50 aos acude al mdico con su marido por una h.pdf
Una mujer de 50 aos acude al mdico con su marido por una h.pdf
 
Team Deliverable 3 Succession Planning Part Two Hide Assi.pdf
Team Deliverable 3  Succession Planning Part Two Hide Assi.pdfTeam Deliverable 3  Succession Planning Part Two Hide Assi.pdf
Team Deliverable 3 Succession Planning Part Two Hide Assi.pdf
 
A bar chart to represent the data below You shou.pdf
A bar chart to represent the data  below      You shou.pdfA bar chart to represent the data  below      You shou.pdf
A bar chart to represent the data below You shou.pdf
 
18 Consider the 3 alternative allocation methods from the p.pdf
18 Consider the 3 alternative allocation methods from the p.pdf18 Consider the 3 alternative allocation methods from the p.pdf
18 Consider the 3 alternative allocation methods from the p.pdf
 
2 Wine menu Your twelve 12 wine selections will include .pdf
2 Wine menu Your twelve 12 wine selections will include .pdf2 Wine menu Your twelve 12 wine selections will include .pdf
2 Wine menu Your twelve 12 wine selections will include .pdf
 
Como miembros de la facultad se les ha pedido que diseen u.pdf
Como miembros de la facultad se les ha pedido que diseen u.pdfComo miembros de la facultad se les ha pedido que diseen u.pdf
Como miembros de la facultad se les ha pedido que diseen u.pdf
 
3 Lets do two pedigree problems one thats straight forwa.pdf
3 Lets do two pedigree problems one thats straight forwa.pdf3 Lets do two pedigree problems one thats straight forwa.pdf
3 Lets do two pedigree problems one thats straight forwa.pdf
 
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdf
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdfQu estrategia buscaba implementar el nuevo CEO de JCPenney.pdf
Qu estrategia buscaba implementar el nuevo CEO de JCPenney.pdf
 
11 Green Industries has 50 million shares outstanding and a.pdf
11 Green Industries has 50 million shares outstanding and a.pdf11 Green Industries has 50 million shares outstanding and a.pdf
11 Green Industries has 50 million shares outstanding and a.pdf
 
Table National Income Accounts Use Table National Income.pdf
Table National Income Accounts Use Table National Income.pdfTable National Income Accounts Use Table National Income.pdf
Table National Income Accounts Use Table National Income.pdf
 
Analyse the scenario provided by examining the relevant soci.pdf
Analyse the scenario provided by examining the relevant soci.pdfAnalyse the scenario provided by examining the relevant soci.pdf
Analyse the scenario provided by examining the relevant soci.pdf
 
5 Two random variables have the joint density fXYxyx.pdf
5 Two random variables have the joint density fXYxyx.pdf5 Two random variables have the joint density fXYxyx.pdf
5 Two random variables have the joint density fXYxyx.pdf
 
a The operation of DNA ligase is only possible in the 3 to.pdf
a The operation of DNA ligase is only possible in the 3 to.pdfa The operation of DNA ligase is only possible in the 3 to.pdf
a The operation of DNA ligase is only possible in the 3 to.pdf
 
8 Create a simple table in MS Word that shows similarities .pdf
8 Create a simple table in MS Word that shows similarities .pdf8 Create a simple table in MS Word that shows similarities .pdf
8 Create a simple table in MS Word that shows similarities .pdf
 
31 Which of the following best ifulrates miztanabichy A c.pdf
31 Which of the following best ifulrates miztanabichy A c.pdf31 Which of the following best ifulrates miztanabichy A c.pdf
31 Which of the following best ifulrates miztanabichy A c.pdf
 

Recently uploaded

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 

Recently uploaded (20)

Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

PYTHON Running into output errors file Traceback and OS.pdf

  • 1. (PYTHON) Running into output errors: file, Traceback, and OSError: [Errno 22] import sqlite3 import json import matplotlib.pyplot as plt import tkinter as tk import socket import csv import pandas as pd class User_Layer: def __init__(self, root): self.root = root self.root.title("Country Selection") self.country_label = tk.Label(self.root, text="Select a country:") self.country_label.pack() self.country_list = tk.Listbox(self.root) self.country_list.pack() self.countries = pd.read_csv('"C:UsersnhiiDownloadsUSAStates2020.csv"') ['Country'].unique() #only works with double and copied file path from folders for country in self.countries: self.country_list.insert(tk.END, country) self.submit_button = tk.Button(self.root, text="Submit", command=self.submit) self.submit_button.pack() def submit(self): selected_country = self.country_list.get(self.country_list.curselection()) business_layer = BusinessLayer() business_layer.get_data(selected_country) class BusinessLayer: def __init__(self): self.server_host = 'localhost' self.server_port = 9999 def get_data(self, country): sql_query = f"SELECT Year, Population FROM USAStates2020 WHERE Country = '{country}' AND Year BETWEEN 1970 AND 2020" data_layer = DataLayer(self.server_host, self.server_port) data = data_layer.send_query(sql_query) graphic_layer = GraphicLayer() graphic_layer.plot(json.loads(data)) class DataLayer: def __init__(self, host, port): self.host = host self.port = port
  • 2. def send_query(self, query): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((self.host, self.port)) s.sendall(query.encode()) data = s.recv(1024).decode() return data class GraphicLayer: def plot(self, data): df = pd.DataFrame(data) df['Year'] = pd.to_datetime(df['Year'], format='%Y') plt.plot(df['Year'], df['Population']) plt.title('Population vs Year') plt.xlabel('Year') plt.ylabel('Population') plt.show() class ServerLayer: def __init__(self, host, port): self.host = host self.port = port def start(self): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((self.host, self.port)) s.listen() print(f"Server listening on {self.host}:{self.port}") while True: conn, addr = s.accept() with conn: print(f"Connected by {addr}") query = conn.recv(1024).decode() conn.execute(query) results = conn.fetchall() json_data = json.dumps(results) conn.sendall(json_data.encode()) if __name__ == "__main__": root = tk.Tk() User_Layer = User_Layer(root) root.mainloop() #output should have tkinter window allowing user to input selected country and print out C02 graph from file #file: https://1drv.ms/x/s!AhPNdK2Zw23UgTUllZBA6oB13pEc?e=Q6f5wV