1
A
回答
4
使用追蹤模塊:
#!/usr/bin/env python
import traceback
def asdf():
(filename,line_number,function_name,text)=traceback.extract_stack()[-1]
print function_name
asdf()
8
您需要指定爲了您的用例,我們給你更好的答案。 你爲什麼想這樣做?
您可以通過使用__name__
得到一個函數的名稱的字符串:
def asdf():
print asdf.__name__
"asdf"
但是,會是什麼呢?在這種情況下,您可以直接打印名稱。
在這種情況下會發生什麼?
def asdf():
print __method__
foo = asdf
foo()
打印"foo"
或"asdf"
?
相關問題
- 1. Ruby等價於Python的DictWriter?
- 2. python等價於ruby的`map.with_index`?
- 3. python等價於ruby的StringScanner?
- 4. Python等價於Ruby的包函數
- 5. Python中的「require」(Ruby)等價於什麼?
- 6. Ruby的等價的Python setattr()
- 7. Elixir的Ruby的__method__相當於什麼?
- 8. Ruby ::等價於Tie :: FIle?
- 9. PL/Ruby等價於MySQL
- 10. Python等價於ignoreboth:erasedups
- 11. Python等價於Mathematica的ArrayPlot?
- 12. PHP等價於Python的requests.get
- 13. Python等價於Mathematica的「LaguerreL」
- 14. C#等價於python的struct.pack
- 15. C++等價於Python的doctests?
- 16. C#等價於Python的os.path.exists()?
- 17. 等價於python「dir」的Java?
- 18. Python的延續與Ruby的等價物
- 19. Python的等價物Ruby的each_slice(count)
- 20. Ruby的watchr在Python中等價嗎?
- 21. 是否有「python -i」的ruby等價物?
- 22. Ruby的等價於PHP的ucfirst()函數
- 23. Ruby的等價於C#的??運營商
- 24. Ruby的等價於PHP的「get_defined_vars」函數?
- 25. Ruby等於Python的幫助()?
- 26. Python等效於Ruby的#each_cons?
- 27. Ruby的等價於Python的多處理模塊是什麼?
- 28. Ruby中的Java CLASSPATH等價於什麼?
- 29. 比較對象等價於Ruby的
- 30. 有沒有C#等價於Ruby的`respond_to?`?