-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreycode.py
61 lines (42 loc) · 1.3 KB
/
greycode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
import sys
from pathlib import Path
symbols = [" ","_","-","","."]
name_of_script = sys.argv[0] #First argument as the name of script [greycode.py]
src_file=sys.argv[1] #Second argument as source file
new_file=sys.argv[2] #Third argument as a new file
#read = open(src_file, 'r')
def names():
again = open(src_file, 'r')
eol = len(again.readlines())
read = open(src_file, 'r')
for line in read:
new=open(new_file+".txt", 'a')
first = line.split()
eol -= 1
if eol == 0:
sys.exit()
for i in symbols:
comb1=first[0]+i+first[1]
comb2=first[1]+i+first[0]
#print(comb1)
#print(comb2)
comb1str=''.join(comb1)
comb2str=''.join(comb2)
new.writelines(comb1str+"\n")
new.writelines(comb2str+"\n")
src=Path(src_file)
if src.is_file():
#file exists
new = Path(new_file)
if new.is_file():
#new file exists
print("Error -- Error -- Error")
print("******Mentioned file is already exists******")
else:
#new file does not exist
names()
else:
#src file does not exist
print("Error -- Error -- Error")
print("The given file is not exists")