From 44583d6929d6e4b0bab528f3ccf625af6364f617 Mon Sep 17 00:00:00 2001 From: justjcurtis Date: Fri, 5 Jul 2019 11:58:32 +0100 Subject: [PATCH 1/6] added -id option for setting input delimiter --- lcNrD.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lcNrD.py b/lcNrD.py index 918c285..a6d6cec 100644 --- a/lcNrD.py +++ b/lcNrD.py @@ -12,6 +12,8 @@ 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') # 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 +43,11 @@ 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" + print('Grabbing file contents...') # open the target file & grab its contents. Using `with` like this automatically @@ -49,7 +56,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: From 976b840a9729df6fdf65013fec60d0566635021f Mon Sep 17 00:00:00 2001 From: justjcurtis Date: Fri, 5 Jul 2019 12:15:51 +0100 Subject: [PATCH 2/6] added updates to Readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5eb87f5..d5a4eea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lcNrD v1.6 +# lcNrD v1.6.5 lowercase AND remove Duplicates - A Very Simple Program; @@ -8,6 +8,7 @@ I find myself having to clean up data quite often & lose python scripts that I w 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 * Lowercase the text of a file * Remove duplicates of a file * Copy all operations onto a new file @@ -25,6 +26,8 @@ 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) + -id INPUT_DELIMITER, --input_delimiter INPUT_DELIMITER + this is the delimiter you want lcNrD to use for the -l, --lowercase add -l to set lowercase to true (default: False) -d, --duplicates add -d to remove duplicate elements (default: False) -s, --shuffle add -s to shuffle your list (default: False) @@ -71,5 +74,4 @@ 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 From a8b980058b25fcb3d2bb3ea8b75a9a486ab27b37 Mon Sep 17 00:00:00 2001 From: Jacson Curtis Date: Fri, 5 Jul 2019 12:24:02 +0100 Subject: [PATCH 3/6] Update README.md added missing text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5a4eea..2c57b14 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ As it stands, this program works best with text listed using the '\n' delimiter. Default = same name + _LcNrD (default: None) -id INPUT_DELIMITER, --input_delimiter INPUT_DELIMITER this is the delimiter you want lcNrD to use for the - -l, --lowercase add -l to set lowercase to true (default: False) + input file (default: \n) -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 From b7fa2149d3a646bb7044eadde0c12c3239929ccc Mon Sep 17 00:00:00 2001 From: justjcurtis Date: Fri, 5 Jul 2019 12:27:40 +0100 Subject: [PATCH 4/6] added -od option to set output delimiter --- README.md | 7 +++++-- lcNrD.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c57b14..806fffa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lcNrD v1.6.5 +# lcNrD v1.7 lowercase AND remove Duplicates - A Very Simple Program; @@ -9,6 +9,7 @@ As it stands, this program works best with text listed using the '\n' delimiter. ## 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 @@ -29,6 +30,9 @@ As it stands, this program works best with text listed using the '\n' delimiter. -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 @@ -74,4 +78,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 output delimiter diff --git a/lcNrD.py b/lcNrD.py index a6d6cec..7e0ecfb 100644 --- a/lcNrD.py +++ b/lcNrD.py @@ -14,6 +14,8 @@ 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 @@ -48,6 +50,10 @@ 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 From f710a57c850c38acdae726e1db92582643d71809 Mon Sep 17 00:00:00 2001 From: justjcurtis Date: Fri, 5 Jul 2019 12:35:03 +0100 Subject: [PATCH 5/6] removed unnecessary disclaimer about delimiters --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 806fffa..f4a5fc4 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,6 @@ 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 From ce7cf852cce9cf19b8ea0f82e45ea5dd3779a176 Mon Sep 17 00:00:00 2001 From: justjcurtis Date: Fri, 5 Jul 2019 16:26:11 +0100 Subject: [PATCH 6/6] changed join statement to use given output delimiter --- lcNrD.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcNrD.py b/lcNrD.py index 7e0ecfb..bae2862 100644 --- a/lcNrD.py +++ b/lcNrD.py @@ -264,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!')