By using the .replace function, I was able to open a csv file and replace some text within the string, and re save the csv file as a txt file using python. I would now like to save this new txt file (or at leas the string that is in the txt file) as a .sql file.
Code: # Read in the file with open('Region.txt', 'r') as file : filedata = file.read()
# Replace the target strings
filedata = filedata.replace("America", "Europe")
filedata= filedata.replace("South America", "East Europe")
# Write the file out again
with open('MyDebt.txt', 'w') as file:
file.write(filedata)
file.close()
Text file: (Region.txt)
select country_name from abcd.d_organizations where region = 'America' and region2 = 'South America'
union all
select 'South America' country_name from dual
order by country_name asc
Region.txtand save it to a file, sayRegion.SQLand use that with a DBMS. You might need to add some other DDL to that file to make it do what you want.