Skip to content

Instantly share code, notes, and snippets.

>>> tp = ([1],[2],)
>>> tp[0] += [3,4]
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
tp[0] += [3,4]
TypeError: 'tuple' object does not support item assignment
>>> tp
([1, 3, 4], [2])
from lxml.html import fromstring
h = fromstring(open('/home/ddd/Hacker School.html').read())
links = set(h.xpath('//a[contains(@href, "github")]'))
for x in links:
t = x.attrib.get('href').rstrip('/')
if not t.endswith('.com'):
print t+'.atom'
<?xml version="1.0" encoding="utf-8" ?><opml version="1.1"><head> <title>Generated by FeedShow OMPLBuilder: Fri, 08 Jun 2012 17:49:24 +0200</title> <dateCreated>Fri, 08 Jun 2012 17:49:24 +0200</dateCreated></head><body><outline text="Main Folder"><outline title="github.com/brendannee.atom" text="github.com/brendannee.atom" type="rss" xmlUrl="http://github.com/brendannee.atom" />
<outline title="github.com/fiveplusone.atom" text="github.com/fiveplusone.atom" type="rss" xmlUrl="http://github.com/fiveplusone.atom" />
<outline title="github.com/j2labs.atom" text="github.com/j2labs.atom" type="rss" xmlUrl="http://github.com/j2labs.atom" />
<outline title="github.com/jconnolly.atom" text="github.com/jconnolly.atom" type="rss" xmlUrl="http://github.com/jconnolly.atom" />
<outline title="github.com/talos.atom" text="github.com/talos.atom" type="rss" xmlUrl="http://github.com/talos.atom" />
<outline title="github.com/shirmung.atom" text="github.com/shirmung.atom" type="rss" xmlUrl="http://github.com/shirmung.atom"
from lxml.html import fromstring
h = fromstring(open('/home/ddd/Hacker School.html').read())
links = set(h.xpath('//a[contains(@href, "github")]/@href'))
for x in links:
t = x.rstrip('/')
if not t.endswith('.com'):
print t+'.atom'
def a():
try:
return
finally:
print 'will always print'
if x:
return 1
return 2
#!/usr/bin/env python
import sys
import datetime
import requests
import dateutil.parser
from BeautifulSoup import BeautifulSoup
import time
import datetime
import sys
def call_me_maybe(decorator):
def inside(*args, **kwargs):
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
return decorator(args[0])
def decorate(actual_function):
return decorator(actual_function, *args, **kwargs)
return decorate
return inside