zoukankan      html  css  js  c++  java
  • python模块

    安装模块,使用模块

    The Python Package Index is a repository of software for the Python programming language. There are currently 84841 packages here.

    https://pypi.python.org/pypi

    https://pypi.python.org/pypi/ez_setup

    https://pypi.python.org/pypi/pip

    sudo apt install python-setuptools

    easy_install pip
    pip install django

    pip比easy_install有更好的输出

    下面这个命令可以查询当前所有已安装的模块

    >>> help('modules')

    以下是在ipython中的输入与输出,下面这个命令可以查询相应模块的版本号

    In [3]: import django
    In [4]: django.__version__
    Out[4]: '1.10rc1'
    In [5]: import MySQLdb
    In [6]: MySQLdb.__version__
    Out[6]: '1.2.4b5'

    os模块
    /usr/lib64/python2.7/os.py
    re模块
    pickle模块
    pkg_resources模块
    /usr/lib/python2.7/site-packages/pkg_resources.py

    socket

    SocketServer是对上面的封装实现

    httplib

    urllib2是对上面的封装实现

    import urllib2
    op=urllib2.build_opener()
    f=op.open("http://www.fltdz.com/index.html")
    f.read()

    import MySQLdb

    yum安装MySQLdb模块
    yum install python-devel mysql-devel
    yum install MySQL-python

    源码安装MySQLdb模块

    yum install python-devel mysql-devel
    wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4b5.tar.gz#md5=2d760ee948aff4f50d01afdf8afff48c
    tar zxvf MySQL-python-1.2.4b5.tar.gz
    cd MySQL-python-1.2.4b5
    python setup.py build
    python setup.py install


    [root@103-c7 first]# python con.py
    (('5.1.73',),)
    [root@103-c7 first]# cat con.py
    import MySQLdb
    #db=MySQLdb.connect(host='192.168.10.104',user='root',password='123456',db='mysql')
    db=MySQLdb.connect('192.168.10.104','root','123456','mysql')
    cursor=db.cursor()
    cursor.execute('select host,user,password from user')
    result=cursor.fetchall()

    for row in result:
            host=row[0]
            user=row[1]
            password=row[2]
            print 'user=%s,host=%s,password=%s' %(user,host,password)

    #print result cursor.close() db.close()

    http://www.cnblogs.com/ccdc/p/4069112.html
    yum install python-devel
    yum install libjpeg libjpeg-devel zlib zlib-devel freetype freetype-devel lcms lcms-devel
    yum install python-imaging

    当您希望与 Web 页面中找到的内容进行某种比较复杂的交互时,您需要使用 mechanize 库
    
    [root@kvm1 python]# easy_install mechanize
    Searching for mechanize
    Reading https://pypi.python.org/simple/mechanize/
    Best match: mechanize 0.2.5
    Downloading https://pypi.python.org/packages/ca/fd/edbcc1abd5bbfc0e19fb3a8d3eebfd11d7d1ce9c8f24c0f54e8db09956b3/mechanize-0.2.5.zip#md5=a497ad4e875f7506ffcf8ad3ada4c2fc
    Processing mechanize-0.2.5.zip
    Writing /tmp/easy_install-F_4XQm/mechanize-0.2.5/setup.cfg
    Running mechanize-0.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-F_4XQm/mechanize-0.2.5/egg-dist-tmp-ZkMUJd
    Adding mechanize 0.2.5 to easy-install.pth file
    
    Installed /usr/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg
    Processing dependencies for mechanize
    Finished processing dependencies for mechanize
    
    
    /usr/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg/mechanize/__init__.py
    
    
    
  • 相关阅读:
    2016-2017-2 20155325实验二《Java面向对象程序设计》实验报告
    20155325 2016-2017-2 《Java程序设计》第8周学习总结
    20155325《Java程序设计》实验一(Java开发环境的熟悉)实验报告
    20155323 2016-2017-2《Java程序设计》课程总结
    20155323 第五次实验 网络编程与安全
    20155323课堂实践20170531
    20155323课堂实践20170524
    20155323 第四次实验 Android程序设计实验报告
    20155323课堂实践20170517
    20155323课堂实践20170510
  • 原文地址:https://www.cnblogs.com/createyuan/p/5692556.html
Copyright © 2011-2022 走看看