__author__ = 'mare' print(1) print('hi, guyz') a = 'hello\n' print(a) #1 #hi, guyz #hello x=0.2 print(x) str(x) print( str(x) ) a = repr('hello\n') print(a) #0.2 #0.2 #hello\n print(x, 'test') print(a + 'this is test') #0.2 test #'hello\n'this is test import sys print("welcome","to","python", sep="~", end="!") #welcome~to~python! #print("welcome","to","python", sep="~", end="!", file=sys.stderr) #/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 /Users/mare/PycharmProjects/input_output/example.py #1 #welcome~to~python! ########### #alienment print('\n') for x in range(1, 6): print(x, '*', x, '=', x*x) #1 * 1 = 1 #2 * 2 = 4 #3 * 3 = 9 #4 * 4 = 16 #5 * 5 = 25 #using rjust for alienment for x in range(1, 6): print(x, '*', x, '=', str(x*x).rjust(4)) #1 * 1 = 1 #2 * 2 = 4 #3 * 3 = 9 #4 * 4 = 16 #5 * 5 = 25 #zfill example for x in range(1, 6): print(x, '*', x, '=', str(x*x).zfill(3)) #1 * 1 = 001 #2 * 2 = 004 #3 * 3 = 009 #4 * 4 = 016 #5 * 5 = 025 #### #formatting print( "{0} is {1}".format("apple", "red")) print("{0} is {1} or {2}".format("apple", "red", "green")) #apple is red #apple is red or green print("{item} is {color}".format(item="apple", color="red")) #apple is red dic = {"item":"apple", "color":"red"} print("{0[item]} is {0[color]}".format(dic)) #apple is red #using local variables item = "apple" color = "red" print("{0[item]} is {0[color]}".format(locals())) #apple is red print("{0:$=5}".format(10)) #$$$10 print("{0:$<5}".format(10)) print("{0:$>5}".format(10)) #10$$$ #$$$10 print("{0:q<5}".format(10)) print("{0:q>5}".format(10)) #10qqq #qqq10 print("{0:#<5}".format(10)) print("{0:#>5}".format(10)) #10### ####10 print("{0:#^6}".format(10)) ##10## print("{0:x}".format(10)) print("{0:b}".format(10)) print("{0:o}".format(10)) print("{0:c}".format(65)) #a #1010 #12 #A print("{0:#x}, {0:#o}, {0:#b}".format(10)) #0xa, 0o12, 0b1010 print("{0:e}".format(4/3)) #1.333333e+00 print("{0:f}".format(4/3)) print("{0:%}".format(4/3)) #1.333333 #133.333333% print("{0:.3f}".format(4/3)) #1.333 #input #a = input('insert any key:') #print(a) #insert any key:sadfsaf #sadfsaf #file input/output f= open('test.txt') print(f.read()) f.close() print( f.closed ) #binary mode and file copy f = open('Horse2.mp3', 'wb') f.write(open('Horse.mp3','rb').read()) f.close() f = open('test.txt') print( f.read() ) print( f.read() ) print( f.tell() ) #return position print( f.seek(0) ) #move to position print( f.read() ) #read again f.seek(0) print( f.readline() ) print( f.readline() ) print( f.readline() ) f.seek(0) print( f.readlines() ) f.close() """ I am boy Who are you Hello~ world I am boy Who are you Hello~ world ['I am boy\n', 'Who are you\n', 'Hello~ world\n'] """ with open('test.txt') as f: print(f.readlines()) print(f.closed) #not close print(f.closed) #closed because if use with keyword, when escape with block file is colsed automatically #['I am boy\n', 'Who are you\n', 'Hello~ world\n'] #False #True #### #pickle, save variables or class colors = ['red', 'green', 'black'] import pickle f = open('colors', 'wb') pickle.dump( colors, f) f.close() del colors f = open('colors', 'rb') #note! must read by binary colors = pickle.load(f) f.close() print( colors ) #['red', 'green', 'black']
2/07/2014
(python Study) input/output and file handle (example source code)
Subscribe to:
Post Comments (Atom)
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
As you can see in the following video, I created a class that stitching n cameras in real time. https://www.youtube.com/user/feelmare/sear...
-
fig 1. Left: set 4 points (Left Top, Right Top, Right Bottom, Left Bottom), right:warped image to (0,0) (300,0), (300,300), (0,300) Fi...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
* Introduction - The solution shows panorama image from multi images. The panorama images is processing by real-time stitching algorithm...
-
Created Date : 2011.10 Language : C/C++ Tool : Microsoft Visual C++ 2008 Library & Utilized : OpenCV 2.3 Reference : SIFT referenc...
-
In the YUV color format, Y is bright information, U is blue color area, V is red color area. Show the below picture. The picture is u-v col...
-
OpenCV has AdaBoost algorithm function. And gpu version also is provided. For using detection, we prepare the trained xml file. Although...
-
I once wrote the following article. http://study.marearts.com/2014/04/opencv-study-mat-point-access-method.html This article is a sample c...
-
Created Date : 2011.8 Language : Matlab Tool : Matlab 2010 Library & Utilized : - Reference : Multiple View Geometry (Hartly and Z...
No comments:
Post a Comment