python__00013__Python中类似C中的include方式

python__00013__类似C中的include方式

一、python的include方式

在C或者C++中有时候会用到#include指令包含某个文件,但是杂python中却没有这样的指令,python提供了import指令

二、代码如下
  1. d:\hello.py:
import os

def print_hello():
  print('hello')
  
hello_str = 'hello_str'
  1. e:\call.py:
import os
import sys
sys.path.append('d:')
from hello import *

print_hello()
print(hello_str)
  1. 输出结果如下:
E:\>python call.py
hello
hello_str