0

I'm trying to copy & paste a company address into a python script to automate my cover letter. when I paste the address it shows up in a single line in the created word document. I want it to be in the number of lines as I copied it.

from docxtpl import DocxTemplate
import datetime
import sys

company_name = input("Enter name of the Company : ") 

position_name = input("Enter name of the Position: ")

hiring_person = input("Enter name of the Hiring Person: ")

company_address = input("Enter the company address: ").splitlines()

today_date = datetime.datetime.today().strftime('%m/%d/%Y')

context = {'today_date': today_date, 
           'company_name' : company_name, 
           'hiring_person' : hiring_person,
           'position_name' : position_name,
           'company_address' : company_address}

doc = DocxTemplate("master_cover_letter.docx")
doc.render(context)
doc.save('Cover_letter_'+company_name+'_'+position_name+'.docx')

This is what I had in the "master_cover_letter.docx"

{{today_date}}

{{hiring_person}}

{{company_address}}

Re: Job Application - {{position_name}}

Dear {{hiring_person}},

I am writing to express my interest in the position of {{position_name}}. Having in-depth knowledge in a wide range of relevant technologies and etc.

consider the following as the company address which is in 4 lines.

Tesla Automation GmbH,

Rudolf-Diesel-Strasse 14,

54595 Prüm,

Germany.

macropod
  • 12,757
  • 2
  • 9
  • 21
ABJesary
  • 9
  • 2
  • Does this answer your question? [Store multi-line input into a String (Python)](https://stackoverflow.com/questions/10426699/store-multi-line-input-into-a-string-python) – Jan Wilamowski Feb 02 '22 at 01:45
  • @JanWilamowski not really. the output still came as a single line output. i used the following code instead. i just made sure the address i copy has a delimiter at the end of the line. `company_address = input("Enter the company address: ").replace(',',',\n')` – ABJesary Feb 03 '22 at 02:45
  • Have you read the answers to the question I linked? Do no use `input()` because it will only accept a single line. Use one of the other suggestions made there. – Jan Wilamowski Feb 03 '22 at 03:16
  • @JanWilamowski Thanks. I did understand it. I use jupyter notebook and it returns a blank and I couldn't key in anything after running the line when I use `sys.stdin.readlines()`. would appreciate a find? Ty. – ABJesary Feb 04 '22 at 20:13
  • I'm not sure if stdin works in Jupyter. You could try reading in a text file instead. – Jan Wilamowski Feb 05 '22 at 00:45
  • Did you figure this out? One idea would be to breakup the `company_address` variable into multiple variables with their own prompts, e.g. `company_street_number`, `company_street_name`, `company_city`, etc – p_sutherland Apr 08 '22 at 17:10

0 Answers0