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 json | |
import sqlite3 | |
conn = sqlite3.connect('rosterdb.sqlite') | |
cur = conn.cursor() | |
# Do some setup | |
cur.executescript(''' | |
DROP TABLE IF EXISTS User; | |
DROP TABLE IF EXISTS Member; |
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 xml.etree.ElementTree as ET | |
import sqlite3 | |
conn = sqlite3.connect('trackdb.sqlite') | |
cur = conn.cursor() | |
# Make some fresh tables using executescript() | |
cur.executescript(''' | |
DROP TABLE IF EXISTS Artist; | |
DROP TABLE IF EXISTS Genre; |
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 re | |
import sqlite3 | |
conn = sqlite3.connect('emaildb.sqlite') | |
cur = conn.cursor() | |
cur.execute(''' | |
DROP TABLE IF EXISTS Counts''') |
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 urllib | |
import json | |
serviceurl = 'http://python-data.dr-chuck.net/geojson?' | |
while True: | |
address = raw_input('Enter location: ') | |
if len(address) < 1 : break |
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 urllib #importing urllib | |
import json #importing json | |
#requesting a json file url | |
url = raw_input("Enter the URL:") | |
#load json file as list -info | |
info = json.loads(urllib.urlopen(url).read()) | |
x = 0 | |
#loop through each item in list comments |
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 urllib #importing urllib | |
import xml.etree.ElementTree as ET #importing xml library | |
url = raw_input("Enter the URL:") #requesting a xml file | |
#read the file and get the comment tag | |
data = urllib.urlopen(url).read() | |
tree = ET.fromstring(data) | |
lst = tree.findall('.//comment') |
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
"""The program will use urllib to read the HTML from the data files below, | |
extract the href= vaues from the anchor tags, | |
scan for a tag that is in a particular position from the top and follow that link, | |
repeat the process a number of times, and report the last name you find.""" | |
import re | |
import urllib | |
from BeautifulSoup import * | |
url = raw_input('Enter URL:') |
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 urllib | |
from BeautifulSoup import * | |
url = raw_input("Enter the URL:") | |
html = urllib.urlopen(url).read() | |
soup = BeautifulSoup(html) | |
tags=soup('span') | |
x = list() |
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 | |
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
mysock.connect(('www.pythonlearn.com', 80)) | |
mysock.send('GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n') | |
while True: | |
data = mysock.recv(512) | |
if ( len(data) < 1 ) : | |
break |
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 re #using regular expressions | |
print sum(map(int, re.findall('[0-9]+',open('RegexSum289081.txt').read()))) | |
#Outline-read the file, look for integers using the re.findall(),converting the extracted strings to integers and summing up the integers. |
NewerOlder