파이썬 추적을 켜면 파일 이름이 모듈과 소스 코드와 함께 제공됩니다.파이썬 추적에서 전체 경로 이름 찾기
파일 경로와 파일 이름을 표시 할 수 있습니까?
내가 사용하고 있습니다 : 예에서
-m trace -t
아래 다른 디렉토리에 두 개의 서로 다른
account_bank_statement.py 파일이 있습니다. 나를 위해 일하는 것이 추적 모듈을 해킹 포함 할
Tracing fIle path and line number
답변 :
17 --- modulename: account_bank_statement, funcname: button_create_invoice
18 account_bank_statement.py(329): if context is None:
19 account_bank_statement.py(333): currency = self.read(cr, uid, ids, ['currency'])[0]['currency']
20 --- modulename: account_bank_statement, funcname: _currency
21 account_bank_statement.py(107): res = {}
22 account_bank_statement.py(108): res_currency_obj = self.pool.get('res.currency')
이
이 (답) 질문의 중복입니다.편집
아래에 AlFe의 대답을 기반으로하는 솔루션. 그것 은 관입이지만, 내가 무엇을 찾고 있는지 않습니다. 나는 모듈 이름을 떠나고 또한 경로명을 추가했다. 나는 OpenERP와 함께 일하고 있으며 종종 여러 위치에 동일한 모듈 이름이 정의되어있다.
정말 Alfe의 해결책의 세련미이므로이 답변을 게시하지 않았습니다. 그렇다면 자신의 답변에 투표하십시오.
(2) 다음과 같이 편집 로컬 경로에(1) 복사 trace.py :
171 def modname(path):
172 """Return a plausible module name for the patch."""
173
174 base = os.path.basename(path)
175 filename, ext = os.path.splitext(base)
176 return filename
593 def globaltrace_lt(self, frame, why, arg):
594 """Handler for call events.
595
596 If the code block being entered is to be ignored, returns `None',
597 else returns self.localtrace.
598 """
599 if why == 'call':
600 code = frame.f_code
601 filename = frame.f_globals.get('__file__', None)
602 if filename:
603 # XXX modname() doesn't work right for packages, so
604 # the ignore support won't work right for packages
605 #modulename = fullmodname(filename)
606 modfile, ext = os.path.splitext(filename)
607 modulename = fullmodname(modfile)
608 if modulename is not None:
609 ignore_it = self.ignore.names(modfile, modulename)
610 if not ignore_it:
611 if self.trace:
612 print (" --- modulename: %s, funcname: %s, filename: %s"
613 % (modulename, code.co_name, filename))
614 return self.localtrace
615 else:
616 return None
샘플 출력
참고 다른 디렉토리에 포함 된 2 개 개의 다른 모듈 이름이있다 , 동일한 파일 이름으로. 이 수정 된 * trace.py **이 처리합니다.
2 --- modulename: register_accounting, funcname: button_create_invoice, filename: /home/sean/unifield/utp729/unifield-wm/register_accounting/account_bank_statement.pyc
3 account_bank_statement.py(329): if context is None:
4 account_bank_statement.py(333): currency = self.read(cr, uid, ids, ['currency'])[0]['currency']
5 --- modulename: account, funcname: _currency, filename: /home/sean/unifield/utp729/unifield-addons/account/account_bank_statement.pyc
6 account_bank_statement.py(107): res = {}
7 account_bank_statement.py(108): res_currency_obj = self.pool.get('res.currency')
관련 항목 : http://stackoverflow.com/questions/14492837/pythons-trace-module-and-filepaths – Evert
나는 중복 게시물에 답변했습니다. 잘하면 그것은 당신에게도 도움이 될 것입니다. – aquavitae