diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-25 00:55:38 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-25 00:55:38 +0800 |
| commit | 965016c087f4691677f4255cdee11cdd9c85c3e9 (patch) | |
| tree | f487bffd7950c01de501486884c97cbb91adcda8 /main.py | |
| parent | 480972ff4cdbb93f93806342d469312fb33f069d (diff) | |
make it work with symlinks and imporved format
Diffstat (limited to 'main.py')
| -rwxr-xr-x[-rw-r--r--] | main.py | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -1,19 +1,30 @@ #!/usr/bin/env python from sys import argv, executable -from os import execv +from os import execv, path + +if path.islink(__file__): + from os import readlink + file = readlink(__file__) +else: + file = __file__ +cwd = path.dirname(path.abspath(file)) + +def write(): + execv(executable, ['python3', f'{cwd}/write.py']) +def read(): + execv(executable, ['python3', f'{cwd}/read.py']) if len(argv) > 1: if argv[1] == 'write': - print(' '.join(argv[2:])) - execv(executable, ['python3', 'write.py'] + argv[2:]) + write() elif argv[1] =='read': - execv(executable, ['python3','read.py']) + read() else: raise Exception("Unknown command\n\tAvailable commands: write, read") else: from simple_term_menu import TerminalMenu choice = TerminalMenu(['Write', 'Read']).show() if choice == 0: - execv(executable, ['python3', 'write.py']) + write() elif choice == 1: - execv(executable, ['python3','read.py'])
\ No newline at end of file + read() |
