zoukankan      html  css  js  c++  java
  • python小工具

    1:启动一个下载服务器:方便传输大量文件

    1:python2使用的模块
     ubuntu@ubuntu:~/share/python_Linux$ python2.7  -m SimpleHTTPServer
        
    2:python3使用的模块 
    ubuntu@ubuntu:~/share/python_Linux$ python3.7 -m http.server
    Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
    
    3:访问
    ubuntu@ubuntu:~$ ip addr show  #查看本机ip地址为192.168.43.97
    http://192.168.43.97:8000/   #浏览器中输入ip地址和端口号即可访问下载
    

    2:字符窜转换为JSON对象

    #底层服务的API一般以json的格式返回,为了方便debug,会将json转换为字符串记录到日志文件中,当需要分析问题时,就要将日志中的json字符串转换为json对象,以提高日志的可读性.
    '{"employees": [{"firstName": "Bill","lastName": "Gates"},{"firstName": "George","lastName": "Bush"},{"firstName": "Thomas","lastName": "Carter"}]}'
    
    
    ubuntu@ubuntu:~$ echo '{"employees": [{"firstName": "Bill","lastName": "Gates"},{"firstName": "George","lastName": "Bush"},{"firstName": "Thomas","lastName": "Carter"}]}' | python -m json.tool
    
    {
        "employees": [
            {
                "firstName": "Bill",
                "lastName": "Gates"
            },
            {
                "firstName": "George",ubuntu@ubuntu:~$ python
    Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45) 
    [GCC 9.2.1 20191008] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import json
    
                "lastName": "Bush"
            },
            {
                "firstName": "Thomas",
                "lastName": "Carter"
            }
        ]
    }
    
    

    3:检查第三方库是否已经安装

    ubuntu@ubuntu:~$ python3
    Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45) 
    [GCC 9.2.1 20191008] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path
    ['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']
    >>> 
    
    
    
    
    1:方法1:python交互终端import 库名
    ubuntu@ubuntu:~$ python
    Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45) 
    [GCC 9.2.1 20191008] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import json
    
    2:方法2:使用python解释器的-c参数快速执行import语句
    ubuntu@ubuntu:~/share/python_Linux$ python -c "import string"
    ubuntu@ubuntu:~/share/python_Linux$ python -c "import traceback" 
    #可以写脚本批量验证
    
    

    参考书籍:《Python Linux系统管理与运维》---赖明星

  • 相关阅读:
    CareerCup Questions List 职业杯题目列表
    [CareerCup] Guards in a museum 博物馆的警卫
    [LeetCode] 7. Reverse Integer 翻转整数
    Python笔记11------一个K-means聚类的小例子
    python笔记10-----便捷网络数据NLTK语料库
    Python笔记9-----不等长列表转化成DataFrame
    Python笔记8----DataFrame(二维)
    Python笔记7----Pandas中变长字典Series
    Python笔记6----数组
    Python笔记5----集合set
  • 原文地址:https://www.cnblogs.com/zhoujun007/p/11930078.html
Copyright © 2011-2022 走看看