gleitz/howdoi — pull request #30 by anthonypt87 (2013-01-12 09:19:18+00:00)
Title: Allow multiple results when asking questions

The original functionality is exactly the same if the `number-of-results` flag is 1 (the default).

If you pass in --number-of-results > 1, you'll get more results now.

$ python howdoi.py print stack python
import traceback

def f():
g()

def g():
for line in traceback.format_stack():
print line.strip()

f()

# Prints:
# File "so-stack.py", line 10, in
# f()
# File "so-stack.py", line 4, in f
# g()
# File "so-stack.py", line 7, in g
# for line in traceback.format_stack():

$ python howdoi.py --number-of-results 2 print stack python

----------------------
Result 1

import traceback

def f():
g()

def g():
for line in traceback.format_stack():
print line.strip()

f()

# Prints:
# File "so-stack.py", line 10, in
# f()
# File "so-stack.py", line 4, in f
# g()
# File "so-stack.py", line 7, in g
# for line in traceback.format_stack():

----------------------
Result 2

>>> def f():
... def g():
... traceback.print_stack()
... g()
...
>>> f()
File "", line 1, in
File "", line 4, in f
File "", line 3, in g

$ python howdoi.py --number-of-results 2 -p 2 print stack python

----------------------
Result 2

>>> def f():
... def g():
... traceback.print_stack()
... g()
...
>>> f()
File "", line 1, in
File "", line 4, in f
File "", line 3, in g

----------------------
Result 3

def install_xxx():
print("Installing XXX... "),

install_xxx()
print "[DONE]"