zoukankan      html  css  js  c++  java
  • Python3 模块、包调用&路径

     1 '''
     2 以下代码均为讲解,不能实际操作
     3 '''
     4 '''
     5 博客园 Infi_chu
     6 '''
     7 '''
     8 模块的优点:
     9 1.高可维护性
    10 2.可以大大减少编写的代码量
    11 
    12 模块一共有三种:
    13 1.Python标准库
    14 2.第三方模块
    15 3.应用程序自定义模块
    16 '''
    17 # import example  # 调用example模块
    18 # from example import example # 调用example模块中的一个example方法
    19 '''
    20 博客园 Infi_chu
    21 '''
    22 
    23 
    24 '''
    25 包的特点:
    26 1.有__init__.py文件
    27 2.有很多模块组成
    28 '''
    29 
    30 # from test import example    # test为包名,example模块名,一层嵌套
    31 # from test.test1 import example  # test1、test2均为包名,test1在test中,example为模块名
    32 # from test.test1.func1 import example    # func1是example模块中的一个func1方法
    33 # import test     # test为包名,此命令相当于执行了__init__文件
    34 '''
    35 博客园 Infi_chu
    36 '''
    37 '''
    38 import 包 或 模块 的区别
    39 import 包 只是执行了一个__init__.py文件,并没有与其他模块产生联系,取值时需要加.调用
    40 import 模块 是直接调用模块
    41 '''
    42 
    43 '''
    44 路径解决
    45 '''
    46 # import sys,os
    47 # a = os.path.abspath(__file__)       # 得到绝对路径
    48 # print(a)
    49 # print(os.path.dirname(a))       # 得到上一层路径
    50 # base_dir = os.path.dirname(os.path.dirname(a))      # 得到上上一层路径
    51 # print(base_dir)
    52 # sys.path.append(base_dir)
    53 '''
    54 博客园 Infi_chu
    55 '''
  • 相关阅读:
    Mybatis+Spring整合
    java 线程详解
    java 异常处理
    java 日期 时间操作
    RandomAccessFile 详解
    js导入excel
    java 常见异常
    常用的java程序片段(算法)
    IO流详解
    json 详解
  • 原文地址:https://www.cnblogs.com/Infi-chu/p/7726319.html
Copyright © 2011-2022 走看看