Python Forum
how to connect mysql from txt 1 line goes good but not all lines in text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to connect mysql from txt 1 line goes good but not all lines in text
#1
hii once again i need help i'm taking courses but just need a little help.
I have a made script that opens a file with data stored to read the file and connect to the database from out that txt file with eval
but now it opens and and start checken and it opens connection at first 3 lines in txt but it connects and print the 4 database in text



filepath = 'Results/sorted.txt'
with open(filepath) as lijst:
    for line in lijst:
        cnt = 1
        while line:
            try:
                connection = eval('MySQLdb.connect({})'.format(line.strip()))
                print("Line {}: {}".format(cnt, connection, line.strip()))
                line = lijst.readline()
                cnt += 1
                while cnt == + 1:
                    connection(cnt, line)
            except Error as e:
                print(e) 
Error:
C:\Users\Gebruiker\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Gebruiker/Downloads/V1/test.py Line 1: <_mysql.connection open to 'first line' at 0000026EB9D29640> Line 2: <_mysql.connection open to 'second line' at 0000026EB9DB3FC0> Line 3: <_mysql.connection open to 'third line' at 0000026EB9D29640> (2002, "Can't connect to MySQL server on 'fourth line' (10060)") (2002, "Can't connect to MySQL server on 'fourth line ' (10060)") (2002, "Can't connect to MySQL server on 'fourth line' (10060)")
Reply


Messages In This Thread
how to connect mysql from txt 1 line goes good but not all lines in text - by kingceasarr - Mar-23-2021, 06:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Line graph with two superimposed lines sawtooth500 4 349 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  Mysql and mysql.connector error lostintime 2 691 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 833 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  Graphic line plot with matplotlib, text file in pytho khadija 2 1,396 Aug-15-2022, 12:00 PM
Last Post: khadija
  Editing text between two string from different lines Paqqno 1 1,323 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  Skipping line in text without Restarting Loop IdMineThat 4 1,499 Apr-05-2022, 04:23 AM
Last Post: deanhystad
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,042 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Find and delete above a certain line in text file cubangt 12 3,511 Mar-18-2022, 07:49 PM
Last Post: snippsat
  CSV to Text File and write a line in newline atomxkai 4 2,715 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,136 Feb-09-2022, 09:55 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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