Python Forum
I cannot able to see output of this code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I cannot able to see output of this code
#1
import sqlite3

conn = sqlite3.connect('emaildb.sqlite')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS Counts')
cur.execute('CREATE TABLE Counts(email TEXT, count INTEGER)')

filename = input("Enter file name: ")
if len(filename) < 1:
    filename = 'new.txt'

fh = open(filename, "r")

g = fh.read()

for line in g:
    if not line.startswith("From: "):
        continue
    pieces = line.split()
    email = pieces[1]
    cur.execute("SELECT count FROM Counts WHERE email = ?", (email,))
    row = cur.fetchone()
    if row is None:
        cur.execute('INSERT INTO Counts(email, count) VALUES (?, 1)', (email,))
    else:
        cur.execute('UPDATE Counts SET count = count + 1 WHERE email = ?', (email,))
    conn.commit()

sqlstr = 'SELECT email, count FROM Counts ORDER BY count DESC LIMIT 10'

for row in cur.execute(sqlstr):
    print(row[0], row[1])

cur.close()
Larz60+ write Feb-22-2023, 08:57 PM:
Please do not use attachments, instead post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I have done this for you this time, please use BBCode on future posts

Attached Files

Thumbnail(s)
   
Reply
#2
More details would be nice.

If nothing prints, that must mean that:
cur.execute('SELECT email, count FROM Counts ORDER BY count DESC LIMIT 10')
returns None. Is there anything in your Counts table?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 387 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  why I dont get any output from this code William369 2 1,138 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,182 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Why this code not getting desired output ? MDRI 2 2,544 Sep-18-2020, 02:11 AM
Last Post: MDRI
  I couldn't understand the output of the below code ravich129 1 1,936 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  Output of Python code hemal07yc 5 3,977 Sep-13-2019, 11:33 AM
Last Post: perfringo
  Output not following rules set in code. Escribblings 4 3,110 Apr-24-2019, 12:49 PM
Last Post: Escribblings
  What will the following code output? dukoolsharma 5 3,273 Dec-15-2018, 06:05 AM
Last Post: HarshaliPatel
  No output for the code to read emails avani9659 6 4,235 Aug-14-2018, 08:30 AM
Last Post: avani9659
  i need assistance on the output of a particular code sirvinprogramming 3 3,333 May-19-2018, 03:37 PM
Last Post: buran

Forum Jump:

User Panel Messages

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