#Python class for dealing with files class myFile(): file_name= '' file_mode = '' def __init__(self,file_name,file_mode): print 'file_name' myFile.file_name = file_name myFile.file_mode = file_mode def read_lines(): file_handle = open(myFile.file_name,myFile.file_mode) self.file_lines = file_handle.readlines() return self.file_lines file = myFile('test.txt','r') print file.read_lines() import os file_list = [] file = open('C:/users/piyush/file_list.txt','w') for path, dirs, files in os.walk('c:/python27/ArcGIS10.2/Lib/test'): for f in files: if f.endswith('.txt'): line = os.path.join(path, f) file_list.append(line) file.write(line+'\n') print file_list file.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question