Python

常用命令

无网环境包迁移

  1. pip freeze >requirements.txt //列出所有需要的包
  2. pip download -rrequirements.txt //打包到文件夹
  3. pip install --no-index --find-links=/xxx/xxx/sites -r /xxx/xxx/sites.requirements.txt //复制到新环境下安装      

查看已安装插件

pip list

安装插件

pip install 包名

指定python版本安装插件

python3 -m pip install 包名

语法总结:冒号和缩进需要注意

list,dic声明

  array= list() #链表
  array.append(data) //添加到结尾
  array.pop(1) //删除第1个
  ''.join(array)//拼接字符串

  dic = { key:value } #字典
  dic[key] = value //添加

三目运算

   "大于" if 1>0  else "小于"    

字符串包含

   "Hello" in "Hello World"

字符串构造

  "{}你好,我是{}".format("老师","学生")

for循环

  for item in Array:    
        print(item)
  > 冒号要加

While循环

  while 0<1:
        print("Hello World")
  > 冒号要加

Json字符串解析

   str1 = [{
        "UID": "D6F0218714002508",
        "Device": "HHHLT",
        "Product": "CLT-AL00",
        "Status": False,
        "IP":"172.0.0.1",
        "PlatForm":"WIN7"
    }]
   mesg = json.dumps(str1)
   #json.dumps(str1)将python对象转换为str
   #json.loads(str1)将str转换为python对象

控制台内容清空

  os.system('cls')

request post get

  import requests,json,os
  r =requests.post(url,{"msg":mesg})  #mesg为json格式
  r =requests.get(url)
  result = json.loads(r.text)
  items = result.items()
原文地址:https://www.cnblogs.com/tangpeng97/p/13343769.html