Read a file line by line and check line separator,checkseparator,import sysif
Read a file line by line and check line separator,checkseparator,import sysif
import sysif __name__ == '__main__': if len(sys.argv) > 1: try: f = open(sys.argv[1], 'rb') except: print 'No file named %s exists!' % (sys.argv[1],) while 1: t = f.readline() if t == '': break if '\n' in t: t = t[:-1] if '\r' in t: t = t[:-1] sys.stdout.write(t + '\n') f.close()
- Looping Over Characters with read Writing the Loop Diffe
- Text files: iterating over the lines in the file,itera
- Reading the entire file at once,readingentire,print '\
- Creating a text file with the writelines() method.,cre
- Dates are easily constructed and formatted,,#Dates and
- Return the current working directory,workingdirectory,
热门文章:
相关内容
- Looping Over Characters with read Writing the Loop Differently,loop
- Text files: iterating over the lines in the file,iteratinglines,f =
- Reading the entire file at once,readingentire,print '\nRea
- Creating a text file with the writelines() method.,creatingwritelin
- Dates are easily constructed and formatted,,#Dates and T
- Return the current working directory,workingdirectory,import ospri
- String formatting: Right justify and Left justify,formattingjustify
- String format: Five digits after decimal in float,digitsdecimal,flo
- Print variables into a string,printvariables,x = 1234res
- Output float,outputfloat,x = 1.234567
评论关闭