Results 1 to 2 of 2

Thread: อยากรู้ว่า เขียน python แบบไม่ได้เป็น interactive mode ทำยังไงครับ

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    1


    ผมอ่านหนังสือและอ่านเวป ผมหาไม่เจออ่ะครับ ส่วนใหญ่จะอธิบายเกี่ยวกับการเขียน python แบบ interactive mode เป็นหลัก แบบว่า เขียนเดี๋ยวนั้นแล้วแสดงผลเดี๋ยวนั้น แล้วถ้าเราจะเขียนแบบภาษา C เช่น

    >>> print 'hello'
    >>> print ' world'
    แล้วค่อยให้มันแสดงเป็น hello world

    เพราะถ้าตอนนี้ที่ผมทำมันจะเป็น

    >>> print 'hello'
    hello
    >>> print ' world'
    world

    อยากทราบว่า ทำยังไงอ่ะครับ เพิ่งศึกษาได้ไม่นาน ยังไงก็รบกวนด้วยนะครับ เพราะผมสนใจจะเอาไปทำ project จบในอนาคตเลยครับ

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


    สำหรับมือใหม่เอาแบบง่ายๆไปก่อนละกัน

    1. เริ่มต้นก็สร้างไฟล์นามสกุล .py จาก notepad หรืออะไรก็ได้ตามสะดวก
    2. คลิกขวาไฟล์ .py ที่สร้าง -> เลือก Edit with IDLE จะเข้าหน้าจอตัว editer ที่มีมาให้กับ python เวลาลง
    3. เขียนโปรแกรมไปตามปกติ
    4. เวลาจะคอมไพล์ก็กด F5

    เอาตัวอย่างง่ายๆไปใช้เป็นตัวอย่างใช้ในการทำงานต่อไปละกันเช่น

    ##GetPath.py

    import os
    import glob
    import string
    def GetAllPath(pathname):
    if pathname == []:
    return []
    else:
    templist = []
    for element in pathname:
    if os.path.isdir(element):
    index = pathname.index(element)
    if element[len(element)-1] != '\\':
    element=element+'\\\\'
    templist += GetAllPath(glob.glob(element+'*&#39)
    else:
    templist.append(element)
    return templist

    def main():
    pathlist = ['c:\\Python25\\DLLs']
    sizefile = []
    totalsize = 0
    print 'in progress...'
    pathlist = GetAllPath(pathlist)
    sizefile = map(os.path.getsize,pathlist)
    print 'success'
    for i in range(len(sizefile)):
    totalsize += sizefile[i]
    print string.rjust(pathlist[i]+'\t\t'+str(sizefile[i]),50)
    print 'total size = %d'%totalsize

    if __name__ == '__main__':
    main()

    วิธีทำก็สร้างไฟล์ GetPath.py แล้วเอาโค้ดนี้ไปใส่(ย่อหน้ามันออกจะเพี้ยนๆหน่อย จัดเองก็แล้วกัน) จากนั้นก็ save แล้วก็กด F5 ม้นจะรันเอาไฟล์ใน directory C:\Python25\DLLs ออกมาโชว์พร้อมแสดงขนาดไฟล์

Similar Threads

  1. Control of Interactive Robotic Interfaces
    By blackkitty in forum Robotics Education
    Replies: 0
    Last Post: 28-01-2008, 05:48 PM
  2. The Oxford Picture Dictionary Interactive CD-ROM
    By DaVinZi in forum Window Application
    Replies: 0
    Last Post: 12-09-2007, 10:31 PM
  3. โปรแกรม Interactive สอนประกอบคอมพิวเตอร์สำหรับมือใหม่
    By kipo in forum E-Book, Video หรือบทความทั่วไปด้าน Computer
    Replies: 0
    Last Post: 10-09-2007, 10:57 PM
  4. PyS60 เขียน Python บน Symbian 6.0
    By asylu3 in forum Python-Articles
    Replies: 1
    Last Post: 20-07-2007, 10:30 PM
  5. Replies: 1
    Last Post: 07-01-2005, 10:55 PM

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
  •