diff --git a/README.md b/README.md index 5eb87f5..f4a5fc4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ -# lcNrD v1.6 +# lcNrD v1.7 lowercase AND remove Duplicates - A Very Simple Program; I find myself having to clean up data quite often & lose python scripts that I write for data cleaning. So I've decided to start this lcNrD project that is a but more of a permanent solution & I will add to its usefulness as I see fit. -## Disclaimer: -As it stands, this program works best with text listed using the '\n' delimiter. I plan to soon add more delimiter options - ## Current Functionality: +* Set input delimiter +* Set output delimiter * Lowercase the text of a file * Remove duplicates of a file * Copy all operations onto a new file @@ -25,7 +24,12 @@ As it stands, this program works best with text listed using the '\n' delimiter. treatment (default: None) -o OUT, --out OUT this is the file you want the lcNrD file to output as. Default = same name + _LcNrD (default: None) - -l, --lowercase add -l to set lowercase to true (default: False) + -id INPUT_DELIMITER, --input_delimiter INPUT_DELIMITER + this is the delimiter you want lcNrD to use for the + input file (default: \n) + -od OUTPUT_DELIMITER, --output_delimiter OUTPUT_DELIMITER + this is the delimiter you want lcNrD to use for the + output file. Default = input delimiter (default: None) -d, --duplicates add -d to remove duplicate elements (default: False) -s, --shuffle add -s to shuffle your list (default: False) -rf, --replace_file add -rf to replace the original file after lcnrd @@ -71,5 +75,3 @@ If you'd like to be able to access lcnrd from anywhere on your computer, add the 7. You should now from anywhere on your computer be able to type simply `lcnrd -h` from a terminal & it should work! ## Roadmap: -* Add input delimiter -* Add output delimiter diff --git a/lcNrD.py b/lcNrD.py index 918c285..bae2862 100644 --- a/lcNrD.py +++ b/lcNrD.py @@ -12,6 +12,10 @@ help='** this is the file you\'re targeting to get the lcNrD treatment') parser.add_argument("-o", "--out", type=str, help='this is the file you want the lcNrD file to output as. Default = same name + _LcNrD') +parser.add_argument("-id", "--input_delimiter", type=str, default='\\n', + help='this is the delimiter you want lcNrD to use for the input file') +parser.add_argument("-od", "--output_delimiter", type=str, + help='this is the delimiter you want lcNrD to use for the output file. Default = input delimiter') # store true or false so we can just be like 'if args.lowercase:' # so use true or false values instead of comparing strings @@ -41,6 +45,15 @@ help='add a -kae to add some text to the end of every line') args = parser.parse_args() +# check if input_delimiter is set to default & if so rectify escape character +# this escapse character is left in so that the default value displays correctly in -h +if(args.input_delimiter == "\\n"): + args.input_delimiter = "\n" + +# set output delimiter to input delimiter if output delimiter isn't set +if(args.output_delimiter == None): + args.output_delimiter = args.input_delimiter + print('Grabbing file contents...') # open the target file & grab its contents. Using `with` like this automatically @@ -49,7 +62,7 @@ text = fp.read() # let's create an array of the lines -lines = text.split("\n") +lines = text.split(args.input_delimiter) # Remove blank lines if args.blank_lines: @@ -251,6 +264,6 @@ # its creating a brand new one. This gets quickly gets slow with lots of text # so we wanna do this as little as possible. Using join on the list means # we just make all the string concatenation opertations in one go. - fp.write("\n".join(lines)) + fp.write(args.output_delimiter.join(lines)) print('...& DONE!')