zoukankan      html  css  js  c++  java
  • Python-常用库

    import time
    print time.strftime('%y-%m-%d %H:%M:%S',time.localtime())
    19-04-21 13:03:08
    # coding:utf-8
    import os
    print u'当前文件的目录',os.path.dirname(__file__)
    print u'当前文件的上一级目录',os.path.dirname(os.path.dirname(__file__))
    base_dir = os.path.dirname(os.path.dirname(__file__))
    f = open(os.path.join(base_dir,'Days/login'),'r')
    print f.read()
    python执行路径搜索:
    程序根目录
    环境变量
    标准库目录
    第三方库的目录

    json字典的序列化与反序列化
    序列化:把python的数据类型转化为str的类型过程 dumps
    反序列化:str的类型转化为Python的数据结构 loads
    import json
    import requests
    r = requests.post(url = 'https://ecapi.parkingwang.com/v5/login',
    headers ={ 'Parkingwang-Client-Source':'ParkingWangAPIClientWeb',
    'Content-Type': 'application/json;charset=UTF-8'},
    data = json.dumps({"source":"common","password":""}))
    print r.status_code
    print r.text
    print json.loads(str(r.text))['msg']

    import json
    import requests
    r = requests.get(url = 'http://www.weather.com.cn/data/sk/101190408.html')
    '''文件的序列化与反序列化'''
    
    
    对文件的反序列化就是读取文件的内容
    文件反序列化后是unicode
    进行编码,把unicode转为str类型
    反序列化,把str转为字典类型

    dict1 = json.loads((json.load(open('weather.json','r'))).encode('utf-8'))
    print dict1['weatherinfo']['city']

    # coding:utf-8


    import json
    import requests
    r = requests.get(url = 'http://www.weather.com.cn/data/sk/101190408.html')
    # result = r.content.decode('utf-8')
    result = r.content
    print result
    r = json.dump(result,open('weather.json','w'))
    w = json.load(open('weather.json','r'))
    result1 = json.loads(w)
    print result1["weatherinfo"]["city"]
     
    
    
     
     






     
    
    
  • 相关阅读:
    cocos2dx CCSprite自动拉伸全屏
    linux 安装输入法
    linux jdk 配置
    Proguard.cfg 配置
    C++基本概念
    查看android keystore 别名
    view onTouch,onClick,onLongClick
    LiteDB V4.1.4版本 查询日期写法 C#
    解决Highcharts 5.0.7,IE8下bar类型图表无法显示的问题
    AspNetCore AmbiguousMatchException: The request matched multiple endpoints. Matches
  • 原文地址:https://www.cnblogs.com/hyzhang/p/10744895.html
Copyright © 2011-2022 走看看