Python

    版本為 20:32, 20 Nov 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    Python Samples

    基本語法

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)

    字串(String)與列表(List)處理

    #字串切割(Slice)
    print s[i]    #取字串的第i個字元
    print s[i:j]  #取字串的第i個開始到第j-1個字元
    print s[-1]   #取字串的最後一個字元
    print s[:j]   #取字串的第一個開始到第j-1個字元
    print s[i:]   #取字串的第i個開始的所有字元
    

    查詢模組的使用方法

    python
    
    >>>help(str) 
    >>>exit()
    

    內建的 http server

    http://effbot.org/librarybook/simplehttpserver.htm

    # File: simplehttpserver-example-1.py
    
    import SimpleHTTPServer
    import SocketServer
    
    # minimal web server.  serves files relative to the
    # current directory.
    
    PORT = 8000
    
    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
    
    httpd = SocketServer.TCPServer(("", PORT), Handler)
    
    print "serving at port", PORT
    httpd.serve_forever()
    

    建立一個檔案上傳的 Web-UI
    需要檔案: droppy.py
    假設要上傳檔案的儲存路徑為 ~/upload

    cd ~/upload
    python ~/bin/droopy.py -m "Hi, it's me Bob. You can send me a file."

    - h 可以顯示更多參數

    取得 eth0 IP 位址

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)

    播放 IP 位址的語音

    reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)

     

    Powered by MindTouch Core