Bläddra i källkod

add print_arguments and save_arguments

quarrying 3 år sedan
förälder
incheckning
0ba060b29d
3 ändrade filer med 17 tillägg och 3 borttagningar
  1. 15 1
      khandy/utils_others.py
  2. 1 1
      khandy/version.py
  3. 1 1
      setup.py

+ 15 - 1
khandy/utils_others.py

@@ -1,6 +1,8 @@
 import time
+import json
 import socket
 import logging
+import argparse
 
 
 def print_with_no(obj):
@@ -102,4 +104,16 @@ def set_logger(filename, level=logging.INFO, logger_name=None):
     logger.addHandler(console_handler)
     return logger
 
-    
+
+def print_arguments(args):
+    assert isinstance(args, argparse.Namespace)
+    arg_list = sorted(vars(args).items())
+    for key, value in arg_list:
+        print('{}: {}'.format(key, value))
+
+
+def save_arguments(filename, args, sort=True):
+    assert isinstance(args, argparse.Namespace)
+    args = vars(args)
+    with open(filename, 'w') as f:
+        json.dump(args, f, indent=4, sort_keys=sort)

+ 1 - 1
khandy/version.py

@@ -1,3 +1,3 @@
-__version__ = '0.1.4'
+__version__ = '0.1.5'
 
 __all__ = ['__version__']

+ 1 - 1
setup.py

@@ -5,7 +5,7 @@ install_requires = ['numpy>=1.11.1', 'opencv-python', 'pillow']
 
 setup(
     name='KHandy',
-    version='0.1.4',
+    version='0.1.5',
     description='Handy Utilities for Computer Vision',
     long_description='Handy Utilities for Computer Vision',
     keywords='computer vision',