首页 > 文章列表 > python创建模块的注意点

python创建模块的注意点

python模块
141 2022-08-07

说明

1、模块名称应遵循Python变量命名规范,不得使用中文或特殊字符;

2、不要与系统模块名冲突,最好先检查系统是否已经存在该模块。

检查方法是在Python交互环境中执行importabc,如果成功,则说明该模块存在于系统中。

实例

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
' a test module '
 
__author__ = 'Michael Liao'
 
import sys
 
def test():
    args = sys.argv
    if len(args)==1:
        print('Hello, world!')
    elif len(args)==2:
        print('Hello, %s!' % args[1])
    else:
        print('Too many arguments!')
 
if __name__=='__main__':
    test()

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。