Python筆記(七)

來源:互聯網
上載者:User

標籤:i/o   mon   sts   getc   參照物   str   處理   擷取檔案   基本   

# -*-coding:utf-8-*-# Python 檔案I/O    # 列印到螢幕#print 1234567    # 讀取螢幕輸入#input_str=raw_input("Please:")  # 同時輸入2*3#print "your input is :",input_str # 輸出 2*3#input_str=input("Please:") # 同時輸入2*3#print "Your input is :",input_str # 輸出 6,input和raw_input基本類似,但是input可以接受python運算式,並運算出結果返回    # 開啟關閉檔案file=open("log.txt","w+")file.write("Hello")print file.readline(10)    # 檔案定位file.tell() # 擷取檔案內的當前未知。file.seek(0,0) # 用於改變當前檔案的位置,第一個參數表示位移量,即移動多少,第二個參數表示參照物,即從什麼位置開始移動,0表示從檔案開頭開始移動,1表示從當前位置開始移動,如果設定為2表示從檔案末尾開始移動file.close() # close() 方法關閉檔案是一個很好的習慣    # 重新命名和刪除檔案import os # python的os模組提供了檔案處理的操作方法os.rename("log.txt","new_log.txt")os.remove("new_log.txt")if os.path.exists("test"):    os.rmdir("test")os.mkdir("test") # os.chdir("newdir") 這裡不再示範print os.getcwd() # 顯示當前工作目錄
 

Python筆記(七)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.