1. 使用`import`语句:
```python
import hello_world
print(hello_world.helloWorldStr)
hello_world.HelloWorld()
2. 使用`from-import`语句:
```python
from hello_world import helloWorldStr, HelloWorld
print(helloWorldStr)
HelloWorld()
3. 使用`exec()`函数:
```python
with open('hello_world.py', 'r') as file:
exec(file.read())
print(helloWorldStr)
HelloWorld()
4. 使用`if __name__ == "__main__":`来执行源代码中的特定部分:
```python
hello_world.py
helloWorldStr = 'Hello, welcome to python world!'
def HelloWorld():
print('HelloWorld(): Hello, welcome to python world!')
if __name__ == "__main__":
print('hello_world.py: HelloWorld(): Hello, welcome to python world!')
5. 在PyCharm中导入Python项目:
打开PyCharm,选择`File > Open`,然后选择需要导入的文件夹。
配置项目对应的Python解释器。
在设置中选择`Project Interpreter`,然后点击`Add`,选择`Existing environment`或`New environment`,并指定Python解释器的路径。
以上是Python中常见的导入源代码的方法。