Created
April 2, 2009 14:08
-
-
Save cschamp/89201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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__' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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