import cannot find same file.Now,I have a,b,c files in folder A. File a read b&c ones.First,I wrote in file a like
import b
import c
・
・
・
x = b_method()
y = c_method()
But,error happens "No module named b".Next,I wrote in file a like
from A import b
from A import c
・
・
・
x = b_method()
y = c_method()
But,when I run this file,terminal said
ImportError: No module named 'A'
So,how can I read file b&c in file a? How can I fix this? I added
import os
import sys
file_dir = os.path.dirname(__file__)
sys.path.append(file_dir)
to file a,but it does not work.
My project structure is
test (parent app)
|--- A
|
---- a
---- b
---- c
Traceback says
Traceback (most recent call last):
File "a.py", line 10, in <module>
from A import b
ImportError: No module named 'A'
When i wrote import b
,
Traceback says
Traceback (most recent call last):
File "a.py", line 58, in <module>
xxx = b.parse(user, id)
NameError: name 'b' is not defined
Whole a.py is
import sys
import os
import b
import c
LOG_FILENAME = 'excel.log'
file_dir = os.path.dirname(__file__)
sys.path.append(file_dir)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(
LOG_FILENAME, maxBytes=2000000, backupCount=5, encoding='utf-8')
handler.setFormatter(
logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s'))
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
logger.addHandler(console)
# READ
def read_config():
f = codecs.open('config.json', 'r', 'utf-8')
text = f.read()
config = json.loads(text)
return config
try:
logger.debug('start.')
logger.info("--------------------------------")
logger.info("Excelファイル読込処理を開始します。")
logger.info("--------------------------------")
config = read_config()
output_dir = config['output_dir']
logger.info("クライアントのデータを読み込みます。")
book_name = config['client']['file_name']
regions = config['client']['regions']
#clientsが空だと、jsonがoutputされない
xxx = b.parse(user, id)
yyy = c.parse(name,mail)
logger.info("--------------------------------")
# ERROR
except:
logger.exception('exception occurred.')
print(input("error"))
sys.exit(-1)
logger.debug('end.')
print(input("finish"))
sys.exit(0)