This file contains 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.cElementTree as ET | |
# Pyhton implementation: import xml.etree.ElementTree as ET | |
filename = 'myfile.xml' | |
tag = '' | |
text = '' | |
attrs = {} | |
# Document Tree XML parser (load the entire document into memory) | |
tree = ET.parse(filemane) |
This file contains 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
""" | |
MongoDB database installed on ~/Development/MongoDB/ | |
To run MongoDB just type: | |
mongod --dbpath ~/Development/MongoDB/db/ | |
cd <mongodb installation dir> | |
./bin/mongod --dbpath ~/Development/MongoDB/db/ | |
""" | |
from pymongo import MongoClient |
This file contains 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 csv | |
filename = 'file.csv' | |
# Read CSV | |
with open(filename, 'rb') as csvfile: | |
csvreader = csv.reader() # Common values -> delimiter=',' quotechar='"' | |
for row in reader: | |
pass | |
This file contains 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
# Count the number of lines within a file | |
num_lines = sum(1 for line in open('myfile.txt')) |
This file contains 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
DELETE FROM table_name | |
WHERE some_column=some_value; |
This file contains 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
# Aggregate functions | |
COUNT(column|*) | |
AVG(column) | |
MIN(column) | |
MAX(column) | |
SUM(column) | |
# Mathematical functions | |
ABS(number) | |
ROUND(number) |
This file contains 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 requests | |
url = 'http://...' | |
r = requests.get(url) | |
r.status_code | |
r.headers | |
r.enconding | |
html_s = r.text # content of the server’s response | |
json_data = json.loads(html_s) |
This file contains 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 xlrd | |
datafile = "my_file.xls" | |
workbook = xlrd.open_workbook(datafile) | |
sheet = workbook.sheet_by_index(0) | |
data = [[sheet.cell_value(r, col) | |
for col in range(sheet.ncols)] | |
for r in range(sheet.nrows)] |
This file contains 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 bs4 import BeautifulSoup | |
soup = BeautifulSoup(html_doc, 'html.parser') | |
print(soup.prettify()) | |
tag = soup.kind_of_tag # retrieve the element with kind_of_tag (the first occurrence I suppose) | |
tag.name # name of the tag | |
tag.string # text of the tag | |
tag.attrs # attributes of the tag as a dictionary | |
tag['attribute_name'] # access to an attribute |
This file contains 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
// cd <mongodb installation dir> | |
// ./bin/mongo | |
db // display database in use (default database: test) | |
show dbs // Show all databases | |
use <database> // select database to use | |
// Access a collection and use shell methods | |
show collections // show all collections for current database | |
db.<collection>.find() |