lhl
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
  • python

    • Python 基础

      • 数据结构
      • 函数
      • 异常
      • 控制语句
      • 运算符
      • 模块
        • 使用模块
        • from..import 语句
        • 模块的 __name__
        • 一个简单 demo
      • 输入输出
      • json
    • Python 数据库

    • 面向对象

    • Python Web

    • Python 进阶

  • leetcode

  • 软件测试

  • Git

  • linux

  • 产品

  • MySql

  • docker

  • python
  • 基础
2023-04-28
目录

模块

#

# 使用模块


import sys

print('The command line arguments are:')
for i in sys.argv:
    print(i)

print('\n\n the pythonpath is', sys.path, '\n')
print('\n')

import sys当 Python 运行 import sys 这一语句时,它会开始寻找 sys 模块。 在这一案例中,由于其 是一个内置模块,因此 Python 知道应该在哪里找到 sys.argvsys 模块中的 argv 变量通过使用点号予以指明,也就是 sys.argv 这样的形式。 它清晰地 表明了这一名称是 sys 模块的一部分。 这一处理方式的另一个优点是这个名称不会与你程序 中的其它任何一个 argv 变量冲突。

# from..import语句

from math import sqrt 
print("Square root of 16 is", sqrt(16))

# 模块的 __name__


def fun_dect():
    if __name__ == '__main__':
        print('this program is run by itself')
    else:
        print('this module is imported by another module')


fun_dect()

# 一个简单 demo

def func_sayhi():
    print('sayhi')


__version__ = 0.1
## 1
import mymodule

mymodule.func_sayhi()
print('module version', mymodule.__version__)
## 2
from mymodule import func_sayhi, __version__
func_sayhi()
print('module version', __version__)
运算符
输入输出

← 运算符 输入输出→

最近更新
01
lhl learn notes
02
filter
06-09
03
decorator
06-09
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式