This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ftplib import FTP | |
f = FTP('localhost') | |
f.login('hudan') | |
fd = open('2003.pdf', 'wb') | |
f.retrbinary('RETR 2003.pdf', fd.write) | |
fd.close() | |
f.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ftplib import FTP | |
f = FTP('localhost') | |
print "Welcome:", f.getwelcome() | |
f.login('hudan') | |
print "Current working directory:", f.pwd() | |
names = f.nlst() | |
print 'List of directory: ', names | |
f.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import random | |
server_address = ('127.0.0.1', 5001) | |
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_socket.bind(server_address) | |
while True: | |
data, client_address = server_socket.recvfrom(1024) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
server_address = ('127.0.0.1', 5001) | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
client_socket.connect(server_address) | |
message = 'Hi ...' | |
delay = 1 | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write to file using with, no need to close file explicitly | |
with open('submission.html', 'w') as f: | |
f.write(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read file without close, with statement will close it for us :) | |
with open('submission.html', 'r') as f: | |
text = f.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.python.org/2/library/xmlrpclib.html | |
import xmlrpclib | |
proxy = xmlrpclib.ServerProxy("http://localhost:8000/") | |
print proxy.add(7,3) | |
print proxy.subtract(7,3) | |
print proxy.multiply(7,3) | |
print proxy.divide(7.0,3.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.python.org/2/library/xmlrpclib.html | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
def add(x,y): | |
return x+y | |
def subtract(x, y): | |
return x-y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.python.org/2/library/xmlrpclib.html | |
import xmlrpclib | |
import datetime | |
proxy = xmlrpclib.ServerProxy("http://localhost:8000/") | |
today = proxy.today() | |
# convert the ISO8601 string to a datetime object | |
converted = datetime.datetime.strptime(today.value, "%Y%m%dT%H:%M:%S") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.python.org/2/library/xmlrpclib.html | |
import datetime | |
from SimpleXMLRPCServer import SimpleXMLRPCServer | |
import xmlrpclib | |
def today(): | |
today = datetime.datetime.today() | |
return xmlrpclib.DateTime(today) |