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

    1.导入模块

    import os
    import os.path
    from os import path
    from os.path import isdir, isfile

    2.动态导入模块

    try:
        from cStringIO import StringIO
    except ImportError:
        from StringIO import StringIO

    上述代码先尝试从cStringIO导入,如果失败了(比如cStringIO没有被安装),再尝试从StringIO导入。这样,如果cStringIO模块存在,则我们将获得更快的运行速度,如果cStringIO不存在,则顶多代码运行速度会变慢,但不会影响代码的正常执行。

    try 的作用是捕获错误,并在捕获到指定错误时执行 except 语句。

    3.使用__future__

    Python的新版本会引入新的功能,但是,实际上这些功能在上一个老版本中就已经存在了。要“试用”某一新的特性,就可以通过导入__future__模块的某些功能来实现。

    使用from __future__ import unicode_literals将把Python 3.x的unicode规则带入Python 2.7中。

    参考代码:

    from __future__ import unicode_literals
    s = 'am I an unicode?'
    print isinstance(s, unicode)

    4.安装第三方模块

     -easy_install

    -pip(内置到2.7.9)

    pip install web.py

  • 相关阅读:
    03-19总结
    JS-DOM
    难题汇总,浮动,伪元素(行级),
    bug汇总
    两栏布局
    表单 form
    a 、ul、 table 标签
    Bootstrap的基本使用(css、js文件的引入)
    6. CSS样式
    5 CSS
  • 原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/5674367.html
Copyright © 2011-2022 走看看