酸洗数据的问题

时间:2016-09-21 16:35:16

标签: python python-3.x pickle

import random
import pickle, shelve
import os
#import RPi.GPIO as GPIO | Raspberry pi only
import tkinter
import sys
import time

class Operator(object):
    global list_name
    def __init__(self):

        print("Welcome to Python OS 1.0")
        print("type 'help' to access help...") # ADD CODE OS.REMOVE("FILE")    
    def CheckDetails(self):
        if not os.path.isfile( 'details.dat' ) :
            data=[0]
            data[0] = input('Enter Your Name: ' )
            file= open( 'details.dat' , 'wb' )
            pickle.dump( data , file )
            file.close() 
        else :
            File = open( 'details.dat' , 'rb' )
            data = pickle.load( File )
            file.close()
            user = ""
            while user != data[0]:
                input("please enter your username...")
            print( 'Welcome Back To Python OS, '+ data[0])

    def Help(self):
        print("""
write(sentence) - Prints the typed sentence on the screen
open(file, mode) - Opens the file and mode such as 'r'
create(listName) - creates the list, listName
add(data, listName) - adds the data to listName
remove(data, listName) - removes the selected data from listName
              """)
    def write(self, sentence):
        print(sentence)

    @classmethod
    def create(self):
        list_name = input("Please enter the list name...")
        vars()[list_name] = []
        time.sleep(1)
        print("List (" + list_name + ") created")

    def add(self):
        data = input("Please specify the data to be added...")
        list_name += data

    def remove(self, data, list_name):
        remove_data = input("Plese specify the data to be removed...")
        list_name -=  data


def main():

    os = Operator()
    os.CheckDetails()
    ans = ""
    ans = ans.lower()
    while ans != "quit":
        ans = input()

        if ans == "write":
            os.write()
        elif ans == "help":
            os.Help()
        elif ans == "create":
            os.create()
        elif ans == "add":
            os.add()
        elif ans == "remove":
            os.remove()
        elif ans == "quit":
            break
        else:
            print("Sorry, that command does not exist or it will be added into a future update...")
    print("goodbye...")
main()

我正在尝试制作某种简化的python,但仅在CheckDetails()函数上出现错误。我正在腌制数据(这很好),但在让用户检查他或她的用户名时出错是正确的,我已经测试了它,即使我输入了正确的用户名,它还是在询问我的用户名。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

你有一个永远执行的while循环,因为你没有将你的用户变量分配给任何东西。     用户!=数据[0]:         user = input(“请输入您的用户名...”)         print('欢迎回到Python OS,'+ data [0])