Print to a file
1 print 'hello', 'world'
To print to an output file, it's similar
1 f = open('out.txt','w') 2 print >>f, 'hello', 'world'
DZone Snippets > korakot > file
13480 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Korakot Chaovavanich http://korakot.stumbleupon.com
1 print 'hello', 'world'
1 f = open('out.txt','w') 2 print >>f, 'hello', 'world'
1 2 # Copy "c:\documents" folder/file to "c:\transferred" on host "w0001". 3 netcopy('w0001', 'c:\\documents', 'c:\\transferred') 4 5 # Move with account credentials. 6 netmove('w0001', 'c:\\documents', 'c:\\transferred', 'admin', 'adminpass') 7 8 # Delete with another account. 9 netdelete('w0001', 'c:\\transferred', 'testdom\\user1', 'user1pass')
1 2 from struct import unpack 3 f = open('data.bin', 'rb') 4 5 b = f.read(1) 6 b2 = f.read(2) 7 b4 = f.read(4) 8 9 n = ord(b) # from char to int 10 n4 = unpack('>L', b4) # big endian 11 n4 = unpack('<L', b4) # little endian 12 n = unpack('>h', b2) # big endian short
1 2 def post_multipart(host, selector, fields, files): 3 """ 4 Post fields and files to an http host as multipart/form-data. 5 fields is a sequence of (name, value) elements for regular form fields. 6 files is a sequence of (name, filename, value) elements for data to be uploaded as files 7 Return the server's response page. 8 """
1 2 import ftplib 3 s = ftplib.FTP('myserver.com','login','password') # Connect 4 5 f = open('todo.txt','rb') # file to send 6 s.storbinary('STOR todo.txt', f) # Send the file 7 8 f.close() # Close file and FTP 9 s.quit()