Python导入Modules
首先更改当前路径:
1 >>>import sys
2 >>>sys.path.append("C:\\Users\\Leyond\\Desktop\\python")
2 >>>sys.path.append("C:\\Users\\Leyond\\Desktop\\python")
然后Check下,是否成功
>>>sys.path
打印出自定义目录
>>>import yourmodule
这里新建文件
fibo.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
>>>def fib(n):
>>> a, b = 0,1
>>> while b < n:
>>> print(b, end = ' ')
>>> a, b = b,a+b
>>> print()
>>>def fib2(n):
>>> result = []
>>> a,b = 0,1
>>> while b<n:
>>> result.append(b)
>>> a, b = b,a+b
>>> return result
>>> a, b = 0,1
>>> while b < n:
>>> print(b, end = ' ')
>>> a, b = b,a+b
>>> print()
>>>def fib2(n):
>>> result = []
>>> a,b = 0,1
>>> while b<n:
>>> result.append(b)
>>> a, b = b,a+b
>>> return result
调用:
>>>import fibo
>>> fibo.fib(100)
>>> fibo.fib(100)