in the same folder
calls the function:
A.py file:
def add(x,y):
print('和为:%d'%(x+y))
B.py file:
import A
A.add(1,2)
or
from A import add
add(1,2)
call class:
Amy polumbo y file: p>
class A:
def __init__(self,xx,yy):
self.x=xx
self.y=yy
def add(self):
print("x和y的和为:%d"%(self.x+self.y))
B.py file:
from A import A
a=A(2,3)
a.add()
or
import A
a=A.A(2,3)
a.add()
in different folders
The file path for the a.python file: E:\PythonProject\winycg
P. y file:
import sys
sys.path.append(r'E:\PythonProject\winycg')
'''python import模块时, 是在sys.path里按顺序查找的。
sys.path是一个列表,里面以字符串的形式存储了许多路径。
使用A.py文件中的函数需要先将他的文件路径放到sys.path中'''
import A
a=A.A(2,3)
a.add()
p>
div>
Read More:
- When Python Django creates a database, can’t open file ‘ manage.py ‘: [Errno 2] No such file or directory
- Fatal Python error: Py_Initialize: unable to load the file system codec.
- Ubuntu has solved the error of h5py installation: building wheel for h5py( setup.py )… or error: failed building wheel for h5py
- Install in Python 3. X web.py
- File “manage.py“, line 17 ) from exc ^ SyntaxError: invalid syntax
- Running Python 3.7 web.py Runtimeerror: generator raised stopiteration exception occurred during test
- PY3 install box2d PY
- About Python setup.py Install error
- Command “python setup.py egg_info” failed with error code 1 in /private/var/folders/14/4hz051qx0wqd3
- Mac install pycurl error: python setup.py egg_info" failed with error code 1”
- 53 Command “python setup.py egg_info“ failed with error
- ERROR: Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-zsbbp6ce/mysq
- Error encountered while executing PIP install: error: complete output from command Python setup.py egg_ info:
- Error: command error out with exit status 1: Python when installing mysqlclient in django2.0 setup.py egg_ info
- Error: command error out with exit status 1: Python when installing mysqlclient in centos7 setup.py egg_ info Check
- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full comm
- No code, a solution to the error in the path of reading CSV file by Python: filenotfounderror: [errno 2] no such file or directory: ‘XX. CSV‘
- Error: command error out with exit status 1: Python setup.py egg_ inf
- Command errored out with exit status 1: python setup.py egg_info Check the logs for full command ou
- python reads csv file is an error _csv.Error: iterator should return strings, not bytes (did you open the file in text)