2016-09-21 70 views
0
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()函数上发生错误。我正在酸洗数据(这很好),但在让用户检查他或她的用户名时发生错误是正确的,我已经测试了它,即使我输入了正确的用户名,它也会询问我的用户名。任何人都可以帮忙吗?酸洗数据问题

+0

你并没有使用在while循环中输入到你的'user'变量 – bunji

回答

0

你有一个while循环会永久执行,因为你没有把你的用户变量赋值给任何东西。 ! 而用户=数据[0]: 用户=输入( “请输入您的用户名...”) 打印( '欢迎回到Python的OS,' +数据[0])

+0

WOW,我很愚蠢,谢谢你发现错误 –