Skip to content

Instantly share code, notes, and snippets.

@ErinCall
ErinCall / gist:2872479
Created June 5, 2012 03:41
Do these look functionally equivalent
#python 2.7
with warnings.catch_warnings(record=False) as w:
soup = BeautifulStoneSoup("<b />")
self.assertEqual(u"<b/>", unicode(soup.b))
#python 2.5
warnings_manager = warnings.catch_warnings(record=True)
w = warnings_manager.__enter__()
try:
soup = BeautifulStoneSoup("<b />")
I have two parsers: one looks at sys.argv while the other looks at some of the tokens the first slurped up. So from argparse's perspective, it does seem like there should just be one parser. I assert that isn't appropriate for my purposes, though:
The first parser is looking at general lay-of-the-land-type stuff: "username to use when calling that API", etc.
The second is looking at specific what-to-do stuff: "what you should do with that API."
I want the settings for the first part to be configurable in a couple different ways: config file, env vars, command-line arguments. For that, I really want my various "configuration getters" to live together. The "what to do" parser has no business in that domain, though; I want it at the top-level script where it can determine a dispatch to some library function. So I have two parsers.
All I'm trying to get argparse to do is "if you are displaying a usage message, display the message for the general script and also the one describing the various subparsers." sys.e
>> require 'some_class'
=> true
>> foo = SomeClass.new
=> #<SomeClass:0x100a23900>
>> foo.doit
SomeClass=> nil
class SomeThing(object):
def doathing(self):
pass
class OtherThing(SomeThing):
make_it_happen_capn(self):
doathing()
>>> def do_something():
... print 'here'
... for x in xrange(0, 8):
... yield x
...
>>> do_something()
<generator object do_something at 0x100428aa0>
>>> foo = do_something()
>>> foo
<generator object do_something at 0x100428b40>
§ echo "
.
.
.
"
.
.
.
module SomeModule
@foo = 1234
def self.some_method
@foo
end
end
class SomeClass
def bar
@ErinCall
ErinCall / gist:4568976
Created January 18, 2013 21:53
ha ha ha what the heck
>> a, a, b = [1, 2, 3]
=> [1, 2, 3]
>> a
=> 2
>> _, _, b = [1, 2, 3]
=> [1, 2, 3]
>> _
=> [1, 2, 3]
>> a
=> 2
@ErinCall
ErinCall / gist:5490199
Created April 30, 2013 17:11
catsnap tests fail to tear down on postgresql 9.2
§ nosetests
..........................................................................................................................E
======================================================================
ERROR: test suite for <module 'tests' from '/Users/andrew/code/catsnap/tests/__init__.pyc'>
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andrew/Envs/catsnap/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/suite.py", line 227, in run
self.tearDown()
File "/Users/andrew/Envs/catsnap/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/suite.py", line 350, in tearDown
self.teardownContext(ancestor)
var auth, querystring, sha1, sign, strftime, test_auth;
strftime = require('strftime');
querystring = require('querystring');
sha1 = require('sha1');
module.exports = function(robot) {
return robot.respond(/test/, function(msg) {