Page 48 - Python rat la co ban
P. 48

f2 = open('access_log', 'a+')

           f2.write('Attack detected')






          5.1.4. Đóng file đã mở





          Sau khi hoàn tất các thao tác đọc ghi file thì gọi phương

          thức  close()  để đóng file đã mở. Ví dụ:





           f1.close()

           f2.close()






          5.1.5. Đổi tên file





          Sử dụng phương thức  os.rename(old, new)  để đổi tên


          một file. Ví dụ:





           import os

           os.rename('test.txt', 'test_new.txt')






          5.1.6. Xóa file




          Sử dụng phương thức  os.remove(file)  để xóa một file
   43   44   45   46   47   48   49   50   51   52   53