Skip to content

Instantly share code, notes, and snippets.

@cschamp
Created April 2, 2009 14:08
Show Gist options
  • Save cschamp/89201 to your computer and use it in GitHub Desktop.
Save cschamp/89201 to your computer and use it in GitHub Desktop.
<type 'dict'>
<type 'instance'>
{'source': 'foo'}
Source is 'foo'
Traceback (most recent call last):
File "pyscope.py", line 21, in <module>
main()
File "pyscope.py", line 18, in main
print r"Source is '%(source)s'" % options
AttributeError: Values instance has no attribute '__getitem__'
#!/usr/bin/python
# Example:
# python pyscope.py -s foo
from optparse import OptionParser
def main():
options = {}
print type(options)
parser = OptionParser()
parser.add_option("-s", "--source", dest="source", type="string", action="store",
help="source file path")
(options, args) = parser.parse_args()
print type(options)
print options
print r"Source is '%s'" % options.source
print r"Source is '%(source)s'" % options
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment