Results 1 to 2 of 2

Thread: จะคอมไพล์ยังไงให้เป็น .pyo

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    14


    คือ จาก file.py จะคอมไพล์เป็น file.pyo ได้อย่างไร แล้ว file.pyc กับ file.pyo ต่างกันอย่างไร ใช้แทนกันได้หรือไม่ ขอความกรุณาด้วยครับ(ผมลองใช้ python -O file.py แล้วไม่เห็นออกเลย ผมสั่งผิดตรงไหนหรือเปล่า)

  2. #2
    Junior Member
    Join Date
    Oct 2006
    Posts
    14


    ง่า... ไม่มีใครตอบเราเลย

    เอาเถอะๆ เราหาคำตอบมาให้แล้ว (ถามเองตอบเองเสร็จ วู้ๆๆ)

    ก็ตอนแรกเข้า dos prompt แล้วย้ายไป directory ที่เก็บไฟล์ .py ก่อน
    จากนั้น ก็ใช้คำสั่ง
    python -O ก็จะเป็นการเข้าไปยัง python prompt แบบนี้

    C:\Project Python>python -O
    Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

    จากนั้นก็สั่ง import ตามปกติ

    >>> import file

    ถ้าไฟล์ไม่มี syntax error ที่ไหน ก็จะรันตามปกติ แล้วก็จะสร้างไฟล์ .pyo ให้แทน .pyc


    เพิ่มเติมอีกนิด คำสั่ง python มีอีกหลาย option ให้เลือกใช้ สามารถดูได้โดยใช้คำสั่ง

    python -h ที่หน้าจอ dos prompt มันก็จะแสดง option ต่างๆพร้อมคำอธิบายให้

    อย่างที่เคยถามไป pyo มันมีลักษณะอย่างไร ก็ประมาณเนี้ย

    -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)

    คือเป็นการทำ optimize code ให้รันได้ดีขึ้นนั่นเอง


    อย่างงี้สิ แม่ปลื้มมม.... จบ

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •