I have a python question and I can't figure out why this is not firing. Below is the code:
import re
sfname='C:\python_Script\Testmain.txt'
i=0
Var1='AS'
Var2=''
Var3=''
with open("C:\python_Script\Testmain.txt") as file_in:
lines = []
for line in file_in:
lines.append(line)
if line.startswith('create view [dbo].'):
print (lines[i])
if not line.startswith('create view [dbo].'):
lines[i]=lines[i].replace("_"," ")
lines[i]= re.sub(r"\bid","key",lines[i])
Var2=lines[i]
Var2=re.sub(r"\bkey","Dimension",Var2)
if not line.endswith("Dimension"):
Var2='Fact Table'
Var3=lines[i] +" "+Var1+" "+Var2
print(Var3)
i+=1
the text file I'm reading from is relatively simple it has these attributes in it:
create view [dbo].Ignore_table
communication_channel_id
user_id
bounce_count
assignment_override_id
create view [dbo].test1
id
test1
basically I want to ignore anything with 'create view[dbo].' and create a print statement which replaces the word 'ID' with 'Key' adds an AS and then does 1 of 2 things: if) Var2 ends with 'Key' replace with the word 'Dimension'. if) var2 does not end with 'Key' then rename the whole thing 'Fact table'
but for some reason this second if the loop will fire even if it does not end with 'dimension' and it will always be 'Fact Table' Why?
if not line.startswith('create view [dbo].'):could just beelse: