Python,将SQLite转换为没有符号的txt文件

时间:2017-10-29 21:47:43

标签: python sqlite

我想知道如何将SQLite转换为易于阅读的.txt文件格式。我想知道如何做到这一点,因为当我尝试时,我遇到了一些错误,或者它会转换,但留下符号使得某人(不知道代码)更难阅读。

这是我目前的代码:

#Modules
import hashlib
import sqlite3
#Database setup
db = sqlite3.connect('users.db')
c = db.cursor()
#Creating the table and columns
c.execute(''' CREATE TABLE IF NOT EXISTS Users
            (ID INTEGER PRIMARY KEY AUTOINCREMENT,
             username TEXT, password TEXT)
            ''')

def register():
    username = input("Please create a username: ")
    realpass = input("Please create a password: ").encode('utf-8')
    hexpass = hashlib.sha256(realpass)
    password = hexpass.hexdigest()
    c.execute('''INSERT INTO  Users(username, password)
            VAlUES(?,?)''', (username, password)) 
    db.commit()#Saving the DB
    start()


def login():
    username = input("Please enter a username: ")
    realpass = input("Please enter a password: ").encode('utf-8')
    hexpass = hashlib.sha256(realpass)
    password = hexpass.hexdigest()
    finduser =('SELECT  FROM Users WHERE username = ? AND password =?')
    c.execute(finduser,[(username), (password)])
    results = c.fetchall()
    if results: 
        print("Welcome " +username)
        question()
    else: 
        print("Sorry wrong login details.")
        start()


def start():
    start1 = input("1.Register 2.Login: ")
    if start1 == "1":
        register()
    elif start1 == "2":
        login()
    else:
        print("Sorry invalid option")
        start()

start()

0 个答案:

没有答案