偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Python實現(xiàn)tab文件操作相關應用方式解讀

開發(fā) 后端
Python實現(xiàn)tab文件操作在實際應用中是一個比較重要的操作技巧。那么,我們將會在這里通過一段代碼示例來為大家詳細介紹一下相關操作方法。

Python編程語言的應用范圍比較廣泛,可以在很多領域中來幫助開發(fā)人員實現(xiàn)一些特定的需求。比如在文件操作方面。我們今天就為大家詳細介紹一下有Python實現(xiàn)tab文件操作的一些具體操作技巧。

Python實現(xiàn)tab文件操作代碼示例:

  1. # -*- coding:gbk -*-  
  2. import os  
  3. class TABFILE:  
  4. def __init__(self, filename, dest_file = None):  
  5. self.filename = filename  
  6. if not dest_file:  
  7. self.dest_file = filename 
  8. else:  
  9. self.dest_file = dest_file  
  10. self.filehandle = None 
  11. self.content = []  
  12. self.initflag = False 
  13. self.column = 0 
  14. self.row = 0 
  15. self.data = []  
  16. def Init(self):  
  17. try:   
  18. self.filehandle = open(self.filename, 'r')  
  19. selfself.initflag = self._load_file()  
  20. except:   
  21. pass  
  22. else:  
  23. self.initflag = True 
  24. return self.initflag  
  25. def UnInit(self):  
  26. if self.initflag:  
  27. self.filehandle.close()  
  28. def _load_file(self):  
  29. if self.filehandle:  
  30. selfself.content = self.filehandle.readlines()  
  31. self.row = len(self.content) - 1  
  32. head = self.content[0].split('\t')  
  33. self.column = len(head)  
  34. for line in self.content:  
  35. #這里需要去掉末尾的換行  
  36. #lineline = line - '\n\r'  
  37. self.data.append(line.rstrip().split('\t'))  
  38. return True  
  39. else:  
  40. return False  
  41. def GetValue(self, row, column):  
  42. if 0 < row < self.row and 0 < column < self.column: 
  43. return self.data[row][column - 1]  
  44. else:  
  45. return None  
  46. def SetValue(self, row, column, value):  
  47. if 0 < row < self.row and 0 < column < self.column: 
  48. self.data[row][column] = value  
  49. else:  
  50. return False  
  51. def SaveToFile(self):  
  52. filewrite = open(self.dest_file, 'w')  
  53. if not filewrite:  
  54. return False  
  55. sep_char = '\t' 
  56. for line in self.data:  
  57. filewrite.write(sep_char.join(line)+'\n')  
  58. filewrite.close()  
  59. return True 

以上就是我們對Python實現(xiàn)tab文件操作的相關介紹。

【編輯推薦】

  1. Python實現(xiàn)ini文件操作基本操作方式分享
  2. Python構造列表基本應用語法詳解
  3. 利用PDB實現(xiàn)Python程序調試
  4. Python單元測試正確使用規(guī)則
  5. Python SQLITE數(shù)據(jù)庫操作簡便易用
責任編輯:曹凱 來源: 博客園
相關推薦

2010-03-03 13:45:08

Python查找重復文

2009-12-28 15:00:21

ADO操作

2010-03-04 15:57:23

Python實現(xiàn)ini

2010-03-04 11:36:02

Python提交表單

2010-03-03 14:30:05

Python set類

2024-10-11 12:00:00

Python批量文件操作

2009-12-16 13:33:28

Ruby輸出文件信息

2010-02-02 17:39:31

C++構造函數(shù)

2010-03-03 17:33:52

Python讀取XML

2010-02-05 16:46:58

C++ TinyXml

2009-12-22 10:15:17

ADO.NET規(guī)則

2010-03-03 15:17:46

Python調用MyS

2010-03-03 16:40:55

Python HTTP

2010-03-03 13:22:08

Python正則表達式

2010-02-26 13:26:55

WCF消息編碼器

2010-03-05 10:47:05

Python futu

2010-03-03 13:32:08

Python壓縮文件

2009-12-30 16:45:31

ADO操作

2011-08-22 14:12:48

iPhone開發(fā)NSTableView

2010-02-03 17:06:36

C++對象復制
點贊
收藏

51CTO技術棧公眾號