2016-09-21 4 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

вы не назначая вход в переменную 'user' в цикле while – bunji

ответ

0

У вас есть цикл while, который будет выполняться вечно, потому что вы не назначаете свою пользовательскую переменную ни на что. ! пока пользователь = данные [0]: пользователя = вход ("Пожалуйста, введите ваше имя пользователя ...") печати ('Добро пожаловать в Python OS,' + данные [0])

+0

WOW, я настолько глуп, спасибо, что нашел ошибку –

Смежные вопросы