Skip to content

Instantly share code, notes, and snippets.

@jaidevd
Last active August 29, 2015 14:19
Show Gist options
  • Save jaidevd/9b80e116d5b8a56f6a5a to your computer and use it in GitHub Desktop.
Save jaidevd/9b80e116d5b8a56f6a5a to your computer and use it in GitHub Desktop.
View Python docstrings through $EDITOR
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
"""
import sys
import tempfile
def main(funcpath):
namespace = funcpath.split('.')
base = namespace[-1]
expression = "from {0} import {1}".format(".".join(namespace[:-1]), base)
exec(expression)
docstring = eval("{}.__doc__".format(base))
with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(docstring)
print f.name
if __name__ == '__main__':
main(sys.argv[1])
#! /bin/bash
# pyds
function pyds {
DOCPATH=`python ~/src/pyds/pyds.py $1`
$EDITOR $DOCPATH
rm $DOCPATH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment