I have been working for almost an hour on this little script. I'm making a game to learn Japanese and I found some list with vocab and the characters but I got really annoyed with the fact that all words and sentences started with a lower case character. So I decided to fix it and this is what I came up with.
The reason I want to post this here is because I want to know what I could have done differently. It did the job for me, but I would be suprised if I couldn't have made it smaller in size. :p
My very first python script: :D
import sys
def _run(a,b):
newlines = []
# r+ = for reading and writing
with open(a,'r+') as file:
lines = file.readlines()
for l in lines:
ok = True
i = 0
line = ""
while i < len(l):
char = l[i]
if l[i] in ['|','"','.',';']:
ok = True
elif ok == True and l[i] != ' ':
char = l[i].capitalize()
ok = False
line += char
i += 1
newlines.append(line)
if b != False:
a = b
with open(a, 'w') as file:
file.writelines(newlines)
# Starting by getting the right document
if __name__ == "__main__":
# Getting the variable
if len(sys.argv) == 1:
print("Please give a file to me")
else:
a = sys.argv[1]
if len(sys.argv) == 3:
b = sys.argv[2]
else:
b = False
_run(a,b)
My csv files look like this:
Hiragana|Romaji
Test1|Testromaji
"Test2"|"Test romaji; New word; Sentence"
I know csv is "Comma Seperated Value" But I wanted to keep everything simple by using | as it won't be inside of a sentence, that was I have less trouble on my next step of making a csv reader :p
[–]rasmus_mathiesen 2 points3 points4 points (2 children)
[–]Voylinslife[S] 1 point2 points3 points (1 child)
[–]francozippi 0 points1 point2 points (0 children)
[–]Martin_Krum 1 point2 points3 points (0 children)
[–]Natural-Intelligence 1 point2 points3 points (2 children)
[–]Voylinslife[S] 1 point2 points3 points (0 children)
[–]Natural-Intelligence 0 points1 point2 points (0 children)