0

I have a text file with very specific formatting (it is message policy for a program and the syntax has to be exact). I need to write a python program that can replicate all of the text and formatting in this file (not simply opening and modifying an existing file).

For example, the first few lines in this text file are laid out like so:

SYNTAX_VERSION 5



LOGFILE "FILENAME"

If I were to get Python to replicate this I would have to manually enter into python:

policy = open('D-HFLinux_HDX_Messages.templ.txt','w')
policy.write('SYNTAX_VERSION 5\n\n\n\nLOGFILE "FILENAME"\n        DESCRIPTION "DESCRIPTION GOES HERE"')
policy.close()

The problem is the text file is several hundred lines long and manual entry is not an option. Is there some way to import the text file into Python, which would then automatically write a script so when I run that script, Python creates an exact copy of the file?

david_10001
  • 492
  • 1
  • 6
  • 22
  • If you mean to copy the file: https://stackoverflow.com/a/123212 – yang5 Oct 05 '17 at 04:47
  • No I need to import the file into a python script, like above. I then need to the modify part of that script with data from CSV files (i.e. errors). – david_10001 Oct 05 '17 at 04:54
  • Just normally opening the file in read mode will maintain the newlines/tabs. Not much you have to do yourself. – Wiggy A. Oct 06 '17 at 02:43

1 Answers1

0

This just needed the text to be copied from the text file and pasted into the script, but with multiline quotations i.e

'''SYNTAX_VERSION 5



LOGFILE "FILENAME"'''
david_10001
  • 492
  • 1
  • 6
  • 22