美文网首页欢哥带你玩编程Python日常
Python学习记录-判断字符串为空

Python学习记录-判断字符串为空

作者: 听风轻咛 | 来源:发表于2019-01-02 10:43 被阅读0次

基本库

  1. 判断字符串为空

    s=' '
    if s.strip()=='':
        print 's is null'
    # 或者
    if not s.strip():
        print 's is null'
    
  2. plt

    # 显示图像
    plt.show()
    
    # 暂停
    plt.pause(10) # second
    
    # 关闭图像
    plt.close()
    
  3. json文件保存与读取

    model={} #数据
    with open("./hmm.json",'w',encoding='utf-8') as json_file:
        json.dump(model,json_file,ensure_ascii=False)
    
    model={} #存放读取的数据
    with open("./hmm.json",'r',encoding='utf-8') as json_file:
        model=json.load(json_file)
    

    解决读取出来数据为unicode的问题方法:

    def byteify(input, encoding='utf-8'):
        if isinstance(input, dict):
            return {byteify(key): byteify(value) for key, value in input.iteritems()}
        elif isinstance(input, list):
            return [byteify(element) for element in input]
        elif isinstance(input, unicode):
            return input.encode(encoding)
        else:
            return input
            
    dic = json.load(jsonfile)
    dic = byteify(dic)
    

tkinter

  • 主框架

    import Tkinter
    top = Tkinter.Tk()
    # 进入消息循环
    top.mainloop()
    
    image_1cvnj5g7jt4s6qv1n7676914949.png-13.9kBimage_1cvnj5g7jt4s6qv1n7676914949.png-13.9kB

说明

元旦放假出去玩了,新的一年新的生活,祝大家新年快乐哦!

相关文章

网友评论

    本文标题:Python学习记录-判断字符串为空

    本文链接:https://www.haomeiwen.com/subject/pnnalqtx.html