0317threading与字典函数使用

时间:2022-10-31 17:34:47

1)threading

def test():

    out=1

    return out

t=threading.Thread(target=test)

t1=threading.Thread(target=test()) #这个传进去为返回值

t.start ()# test在这执行

t1.start()#test函数在新建线程 已经执行,

2)字典函数

func_dic={}

# encoding: utf-8
import os
import sys

stack = []
class menu:
    def popit(self):
        if len(stack) == 0:
            print("stack is none ")
        else:
            print("remove",stack.pop())
        pass

    def pushit(self):

        stack.append(input("please append a new words:").strip())
        pass

    def viewStack(self):
        print(stack)

    CMDs={'o':popit,'u':pushit,'v':viewStack}

    def showMenu(self):
        pr="""
        P(U)sh
        p(O)p
        (V)iew
        (Q)uit

        enter choice"""

        while True:
            while True:
                try:
                    choise= input(pr).strip()[0].lower()
                    print(choise)
                except(EOFError,KeyboardInterrupt,IndexError):
                    choise = 'q'
                print('your input choise [%s]'%choise)

                if choise not in 'uvoq':
                    print("input error")
                else:
                    break
            if choise =='q':
                break
            self.CMDs[choise](self)
if __name__ == '__main__':
    m=menu()
    m.showMenu()