Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex


14.3.2.7 Printing a version string

Similar to the brief usage string,optparse can also print a version stringfor your program. You have to supply the string as theversionargument to OptionParser:

parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 1.0")

"%prog" is expanded just like it is inusage. Apartfrom that,version can contain anything you like. When you supplyit,optparse automatically adds a--version option to your parser.If it encounters this option on the command line, it expands yourversion string (by replacing"%prog"), prints it to stdout, andexits.

For example, if your script is called/usr/bin/foo:

$ /usr/bin/foo --versionfoo 1.0


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp