• 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系统管理与运维》---赖明星

  • 相关阅读:
    c编写程序完成m名旅客和n辆汽车的同步程序代写
    [原]web服务器:SOAP,WSDL,UDDI
    用多进程同步方法演示“桔子-苹果”问题
    实验教学管理系统 c语言程序代写源码下载
    模拟游客一天的生活与旅游java程序代写源码
    Java作业代写
    快餐店运行模拟C++程序源码代写
    求可能组合VB源码代写
    深入源码分析Java线程池的实现原理
    ThreadLocal原理详解
  • 原文地址:https://www.cnblogs.com/zhoujun007/p/11930078.html
Copyright © 2020-2023  润新知