javaclass

runclass.py

122:bbadc235f0a8
2005-01-13 Paul Boddie Hopefully improved the clarity of the documentation, adding notes on running classes. Minor change to runclass.py, hopefully making it executable.
     1 #!/usr/bin/env python     2      3 "A program to run Java class files."     4      5 import classhook     6      7 def load_class(class_name):     8      9     "Load the class with the given 'class_name'."    10     11     class_name_parts = class_name.split(".")    12     if len(class_name_parts) == 1:    13         module = __import__("__this__", globals(), locals(), [class_name])    14         obj = getattr(module, class_name)    15     else:    16         class_module = ".".join(class_name_parts[:-1])    17         obj = __import__(class_module, globals(), locals())    18         for part in class_name_parts[1:]:    19             obj = getattr(obj, part)    20     21     return obj    22     23 def run_class(cls, args):    24     cls.main(args)    25     26 if __name__ == "__main__":    27     import sys    28     cls = load_class(sys.argv[1])    29     run_class(cls, sys.argv[2:])    30     31 # vim: tabstop=4 expandtab shiftwidth=4