简体   繁体   English

将整数添加到文本文件中一行上的特定数字

[英]adding an integer to a specific number on a line in a text file

The file includes a username surname year membership status nights booked and points 该文件包括用户名姓氏年份,会员资格预订天数和积分

members usernames consist of the first three letters of their surname, plus a three-digit number, followed by the last two digits of the current year 成员用户名由其姓氏的前三个字母加上一个三位数字组成,后跟本年的后两位数字

We're currently struggling to find a way to add points to a specific user on a text file. 当前,我们正在努力寻找一种方法,可以在文本文件中为特定用户添加点。

Booking = int(input('How many nights do you want to book:    '))
if Booking <= 14:
    Users = str(input('Have you already signed up as a user:    '))
    if Users == 'yes' or 'Yes':
        Login = str(input('Enter given username    '))
        datafile = open('Users2.txt')
        for line in datafile:
            if Login in line:
                points = Booking * 2500
                NewUser = Login
            else:

You can use sqlite which is very user friendly under python. 您可以使用在python下非常用户友好的sqlite。

import sqlite3
conn = sqlite3.connect('Users2.db') #this takes place of Users2.txt

c = conn.cursor()
# THIS ONLY FIRST TIME, JUST EXAMPLE
c.execute('''CREATE TABLE users
             (id int PRIMARY KEY NOT NULL,username text, surname text, year text, membership text)''') 
# you can create your structure here

c.execute("INSERT INTO users(id,username) VALUES (1,'farbiondriven')")


conn.commit()
Booking = int(input('How many nights do you want to book:    '))
if Booking <= 14:
    Users = str(input('Have you already signed up as a user:    '))
    if Users == 'yes' or 'Yes':
        Login = str(input('Enter given username    '))

        c.execute('SELECT * FROM users WHERE username=?', Login)
        outputQuery = c.fetchone()
        if(len(outputQuery)>0):
           ....do your stuff...




conn.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM