สำหรับผู้ใช้งาน Windows อย่าลืมกำหนดค่า path ให้กับ โฟลเลอร์python\Tools\Scripts ด้วยนะครับ
สำหรับผู้ใช้งาน Mac และลินุกซ์ ถ้าไม่พบไฟล์ reindent.py ใน /usr/share/doc/python3.X/examples/Tools/scripts/ แสดงว่ายังไม่ได้ติดตั้ง package “python3-examples” ครับ ให้ทำการติดตั้งด้วยครับ
การใช้งาน
reindent [-d][-r][-v] [ path ของไฟล์ py ที่ต้องการ ... ]
-d (--dryrun) คือ วิเคราะห์ แต่ไม่เปลี่ยน แฟ้ม
-r (--recurse) คือ ค้นหาทั้งหมด.py แฟ้มในไดเรกทอรีย่อยเกินไป
-n (--nobackup) คือ ไม่เก็บไฟล์เก่าก่อนแก้ไข indent
-v (--verbose) พิมพ์ข้อมูล msgs แล้วไม่แสดงผลออกมา
-h (--help)
หากไม่ได้กำหนด reindent จะทำการแก้ไข indent และทำการเก็บไฟล์เก่าก่อนแก้ไขโดยมีนามสกุล .bak ตามหลังครับ
ตัวอย่างเช่น
hello.py ก่อนแก้ไข
print("Test ...")เมื่อนำไปรัน
if __name__ == '__main__':
print("Hello :D")
input("Enter to exit")
>python hello.py File "hello.py", line 4 input("Enter to exit") ^ TabError: inconsistent use of tabs and spaces in indentation
พบกับ ปัญหา indent
ใช้คำสั่ง
reindent.py hello.py
hello.py หลังแก้ไข
print("Test ...")
if __name__ == '__main__':
print("Hello :D")
input("Enter to exit")
เมื่อนำไปรัน
>python hello.py Test ... Hello :D Enter to exit
จะเห็นได้ว่า ปัญหา indent ได้ถูกแก้ไขไปจากโค้ด python แล้วครับ
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ
0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)