還是有更好的方法來快速輸出數組的內容(多維或不是)。謝謝。python中print_r()的等價物是什麼?
64
A
回答
40
19
4
print
和pprint
非常適合定義合理對象表示的內置數據類型或類。如果你想要一個完整的任意對象轉儲,你將不得不推出自己的。這並不困難:只需創建一個遞歸函數,其基本情況是任何非容器內置數據類型,並且遞歸情況將函數應用於容器的每個項目或對象的每個屬性,可以獲得使用dir()
或inspect
模塊。
2
還有就是Python https://github.com/marcbelmont/python-print_r/wiki print_r的,但最好是使用標準的模塊
5
你要找的repr
bult的函數。
http://docs.python.org/2/library/functions.html#func-repr
print repr(variable)
2
+0
太好了,謝謝。 – 2017-07-17 12:42:24
3
from pprint import pprint
student = {'Student1': { 'Age':10, 'Roll':1 },
'Student2': { 'Age':12, 'Roll':2 },
'Student3': { 'Age':11, 'Roll':3 },
'Student4': { 'Age':13, 'Roll':4 },
'Student5': { 'Age':10, 'Roll':5 }
}
pprint(student)
0
如果要格式化variable
,你可以做一個字符串:
s = repr(variable)
它的作品無論是類型,並且不requiere任何進口。
如果你想用它的類型一起包括一個字符串對象的內容:
if hasattr(variable, "__dict__"):
s = "{}: {}".format(variable, vars(variable))
else:
s = repr(variable)
0
對於我使用的HttpResponse簡單的測試意見。從形式,變量,字符串ID測試的要求,而不是Object
def add_comment(request, id):
return HttpResponse(id)
相關問題
- 1. python中'gem'的等價物是什麼?
- 2. Python中imadjust的等價物是什麼?
- 3. 什麼是Python的os.walk的等價物?
- 4. 什麼是Python os.pathsep的等價物?
- 5. 什麼是Tomcat的Python等價物?
- 6. 什麼是java.util.zip.Inflater的Python等價物?
- 7. 什麼是VC7中的strtok_s等價物?
- 8. 什麼是Silverlight中的OnRender等價物?
- 9. C#中TreeBidiMap的等價物是什麼?
- 10. 什麼是C#中的vbNullChar等價物?
- 11. MySQL中'go'的等價物是什麼?
- 12. Bash中%%〜nxD的等價物是什麼?
- 13. C#中memset的等價物是什麼?
- 14. Monotouch中的CGPDFDocumentGetCatalog等價物是什麼?
- 15. C#中bigint的等價物是什麼?
- 16. 什麼是android中的dataWithContentsOfURL等價物?
- 17. jquery中Ajax.updater的等價物是什麼?
- 18. url中的「 - 」等價物是什麼?
- 19. TensorFlow中np.std()的等價物是什麼?
- 20. 什麼是Ruby中的「sys.stdout.write()」等價物?
- 21. wxWidgets中UpdateWindow()的等價物是什麼?
- 22. JQuery中innerHTML的等價物是什麼?
- 23. Bindingsource中EOF的等價物是什麼?
- 24. RDFlib中rdf:ID的等價物是什麼?
- 25. gcc中的#pragma等價物是什麼?
- 26. 節點JS中python中auth的等價物是什麼?
- 27. 什麼是Java中的close()的Python等價物?
- 28. Ruby中Python的itertools.product的等價物是什麼?
- 29. 什麼是Java中的StringEntity的Python等價物?
- 30. 在Fortran中Python的itertools.product的等價物是什麼?下面
應在問題來解釋,但是:http://php.net/print_r – 2010-02-02 21:28:34
馬克:這是一個PHP函數在屏幕上顯示任何變量的內容,包括數組或對象。 – 2010-02-02 21:28:55
print_r是PHP中的一項功能,它可以以顯示鍵和值的格式輸出任何維數組。 – 2010-02-02 21:29:25