python/응용
-
optparsepython/응용 2022. 5. 22. 00:10
import sys print(sys.argv) #################################################################### from optparse import OptionParser if __name__ == '__main__': usage = 'usage: %prog [options] arg1 arg2' parser = OptionParser(usage=usage) parser.add_option('-f', '--file', action='store', type='string', dest='filename', help='file name') # myprog.py -f input.txt parser.add_option('-n', '--num', actio..
-
yaml / configparserpython/응용 2022. 5. 21. 23:26
YAML config https://pypi.org/project/PyYAML/3.10/ Install config.yml DEFAULT: debug: true web_server: host: 127.0.0.1 port: 80 위의 config.yml 파일 생성하기 import yaml with open('config.yml', 'w') as yaml_file: yaml.dump({ 'DEFAULT': { 'debug': True }, 'web_server': { 'host': '127.0.0.1', 'port': 80 } }, yaml_file) 위의 config.yml 파일 읽기 import yaml with open('config.yml', 'r') as yaml_file: config = yaml..