<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -28,6 +28,4 @@ def geocode(s, api_key='', geocoder='google', list_geocoders=False):
     name, (lat, lon) =  mod.geocoder(api_key)(s)
     print '%s\t%s\t%s' % (name, lat, lon)
 
-if __name__ == '__main__':
-    optfunc.run(geocode)
-        
\ No newline at end of file
+optfunc.main(geocode)</diff>
      <filename>geocode.py</filename>
    </modified>
    <modified>
      <diff>@@ -129,6 +129,11 @@ def run(func, argv=None, stderr=sys.stderr):
             stderr.write('%s: ' % func.__name__)
         stderr.write(&quot;%s\n&quot; % '\n'.join(errors))
 
+def main(*args, **kwargs):
+    prev_frame = inspect.stack()[-1][0]
+    if inspect.getmodule(prev_frame).__name__ == '__main__':
+        run(*args, **kwargs)
+
 # Decorators
 def notstrict(fn):
     fn.optfunc_notstrict = True</diff>
      <filename>optfunc.py</filename>
    </modified>
    <modified>
      <diff>@@ -10,5 +10,4 @@ def two(arg):
 def three(arg):
     print &quot;Three: %s&quot; % arg
 
-if __name__ == '__main__':
-    optfunc.run([one, two, three])
+optfunc.main([one, two, three])</diff>
      <filename>subcommands_demo.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2bc96ec80fded47eda9b4ff8ae99c4e5c9f826dd</id>
    </parent>
  </parents>
  <author>
    <name>Simon Willison</name>
    <email>simon@simonwillison.net</email>
  </author>
  <url>http://github.com/simonw/optfunc/commit/f7ba9965e4e7f4028b336053887ffbcbb47d898f</url>
  <id>f7ba9965e4e7f4028b336053887ffbcbb47d898f</id>
  <committed-date>2009-05-29T05:38:54-07:00</committed-date>
  <authored-date>2009-05-29T05:38:54-07:00</authored-date>
  <message>optfunc.main() - like optfunc.run(), but it peeks at the stack and uses it to decide if __name__ == '__main__', saving you from having to type that idiom yourself</message>
  <tree>815b98c2f2868a11648832600a88012ed0134367</tree>
  <committer>
    <name>Simon Willison</name>
    <email>simon@simonwillison.net</email>
  </committer>
</commit>
