I have this code:
from sys import argv
import os
bold = "\033[1m"
reset = "\033[0;0m"
try:
argv[1]
except IndexError:
print("\nNo arguments! Add \"-h\" or \"--help\" for more info." + bold + "\n\nNow look what you've done!" + reset)
else:
pass
if argv[1] == "-h" or "--help":
print("\nxxxx, version 0.0.2")
print("xxxx is a simple tool for the command line used for quickly saving\n\
chunks of text, while providing more functionality than the traditional method\n\
(e.g. echo \"HELLO WORLD\" > hi.txt) used in bash.")
print("\nUsage: sans-sheriff [text] [directory] [options]")
print("\nOptions:\n\
-h, --help Display this help message and exit.\n\
-v, --verbose Output more verbosity.\n\
-e=utf8, --encoding Sets the encoding. Default is utf-8.\n\
utf16\n\
utf32\n\
ascii\n\
iso (8859-1)\n\
-text Sets the filetype. Default is \".txt\".\n\
html\n\
rtf\n\
tex\n\
-o, --open Open the file directly after.\n\
\n\
e.g. xxxx \"Hello World\" /home/user/Documents/myfile -e=utf32")
else:
try:
argv[2]
except IndexError:
print("No directory argument! Add \"-h\" or \"--help\" fopr mor info." + bold + "\n\nNow look what you've done!" + reset)
else:
pass
usrtxt = argv[1]
usrdir = argv[2]
usrtxt = open(usrdir, "w")
It is supposed to create text files based on a users' arguments, like this:
xxxx \"Hello World\" /home/user/Documents/myfile
But whenever it is launched like the example provided, it just loads the output that would have been produced when -h or --help is argued...
It doesn't seem logical why it would do this, and I'm quite a newbie to python as well, so any help would be greatly appreciated!