(Dec-06-2018, 03:47 PM)saisankalpj Wrote: [ -> ]so if i create sitecustomize.py file and keep it in C:\Python37\Lib\site-packages,will even
pycharm recognize this as current working directory or it is only for command prompt?
Yes,but you have you make sure in
Configuring Python Interpreter that 3.7 is selected.
A package should be stand alone,and the use
import statement
to access files in it.
So the only requirement is that package folder is in
sys.path
,then will Python(3.7 in this case) find it.
Example:
my_pack\
|-- __init__.py
one\
|-- __init__.py
|-- sample_1.py
two\
|-- __init__.py
|-- sample_2.py
__init__.py:
the one under my_pack folder,other are empty.
from .one.sample_1 import power_of
from .two.sample_2 import upper_name
sample_1.py:
def power_of(arg):
return arg ** arg
sample_2.py:
def upper_name(name):
return name.upper()
Now can i test my package:
>>> import my_pack
>>> my_pack.power_of(5)
3125
>>> my_pack.upper_name('tom')
'TOM'
# Or can import like this
>>> from my_pack import power_of
>>> power_of(22)
341427877364219557396646723584
As you see i using the main
__init__.py
to lift sub modules up from folders.
This make it easier for users
my_pack.power_of(5)
insted of
my_pack.sample_1.power_of(5)
.
This is what i what i always do make
import
easier if other shall use my package.
So this package work stand alone,for Python to find it need to be in
sys.path
,so in my cases
E:\div_code\my_pack
Then it work from Editors or command line.