import os
import sys

comment = "////////////////////////////////////////////////";
line_return = "\n"
line_break = "\r"
write_buffer = ""

test_list = ['test1', 'test2', 'test3', 'test4']

def create():

    fname = "template.v"

    open('my_file.txt', 'a').close()

    with open("header.txt") as f:
      with open("my_file.txt", "w") as f1:
        for line in f:
            f1.write(line)
    f.close()        
    
    
    #with open(fname, 'w') as f:

    write_buffer = comment + line_return
    f.write(write_buffer)

    write_buffer = "tartuffe" + line_return
    f.write(write_buffer)

    write_buffer = comment + line_return
    f.write(write_buffer)


    f.write(line_break)
    f.write(line_break)
    f.write(line_break)
    f.write(line_break)
    f.write(line_break)

    f.write("message \r\n")
    f.write("This is line \r\n")
    f.write("message \r\n")
    f.write("This is line \r\n")

    for item in test_list:
         f.write("%s \r\n" % item)

    f.close()
 
            

    #with open("header.txt", "r") as f1:
    #    t1 = f1.readlines()
    #with open("my_file.txt", "r") as f2:
    #    t2 = f2.readlines()
    #    t2.insert(20, t1)
    #with open("my_file.txt", "w") as f2:
    #    f2.writelines(t2)

    #f1 = open("header.txt", "r")
    #contents = f.readlines()
    #print(contents)
    #index = 0
    #contents.insert(index, contents)
    #f2 = open("path_to_file.txt", "w")
    #contents = "".join(contents)
    #f.write(contents)
    #f1.close()
    #f2.close()

   
    
    exists = os.path.isfile(fname)

    if exists:
         print("File exists , Warning !")    

    with open(fname, 'w') as f:

         write_buffer = comment + line_return
         f.write(write_buffer)

         write_buffer = "tartuffe" + line_return
         f.write(write_buffer)

         write_buffer = comment + line_return
         f.write(write_buffer)


         f.write(line_break)
         f.write(line_break)
         f.write(line_break)
         f.write(line_break)
         f.write(line_break)

        
         f.write("message \r\n")
         f.write("This is line \r\n")
         f.write("message \r\n")
         f.write("This is line \r\n")


         for item in test_list:
          f.write("%s \r\n" % item)

         f.close()

def main():
    create()
 
if __name__ == "__main__":
    status = main()
    sys.exit(status)
