Code - txt file generation from code, colab
Python Code to generate text files as from Output of code about “____will always be all-good for ____”.
____________________________
%%capture captured_number
import re
input_string = "Example 1, Example 2, Example 3"
input_string_2 = "Mehul, Ajay, Vijay"
# Split the input string into a list of words
words = [word.strip() for word in input_string.split(',')]
# Split the input string into a list of words
words_2 = [word.strip() for word in input_string_2.split(',')]
paragraph = "Thinking good will always be all-good for everyone."
for word in words:
modified_paragraph = re.sub(r'\bThinking good\b', word, paragraph) #replacing “Thinking good”
for word in words_2:
modified_paragraph_final = re.sub(r'\beveryone\b', word, modified_paragraph) # replacing “everyone”
print(f"{modified_paragraph_final}\n")
# Specify the file path
file_path = '/content/txt_file_name.txt'
# Save the captured output to the file
with open(file_path, 'w') as file:
file.write(captured_number.stdout)
# Print a message indicating the file has been saved
print(f"Output saved to: {file_path}")
Comments
Post a Comment