0

I'm using Python 3.4. Any idea why my code isn't creating the files in the created location? The code is:

from sys import argv

from fpdf import FPDF import json import csv

def write_cover_letter(cover_letter, skills):

# open csv file and read input
with open(skills) as skills_csv:

    for row in reader:

        pdf = FPDF('P', 'mm', 'A4')  # portrait mode, mm , A4 size paper
        pdf.add_page()  # new blank page
        pdf.set_font('Arial', '', 12)  # font, Style (B,U,I) , fontsize in pt.

        #ignore the header row
        if rownum == 0:
            pass

        else:
            model_cover_letter = open(cover_letter, 'r')

            for line in model_cover_letter:

                line = line.replace('#website', row[0])
                line = line.replace('#inserttools', ','.join(row[1].split('#')))  # skills are seperated by '#' split and join them
                line = line.replace('#toolproficient', row[2])
                line = line.replace('#toolyr', row[3])
                line = line.replace('#company', row[4])

                pdf.write(6, line)

            pdf.output('C:\Python34/cover_letters/Cover Letter - ' + row[4] + '.pdf', 'F')
            pdf.close()

        rownum = rownum + 1

if name == "main":

coverletter = argv[1]
skillset = argv[2]

# just use the right file names or modify the ones provided
write_cover_letter(coverletter, skillset)

It goes through the command prompt with no errors but doesn't create a file on the designated location. Any idea why?

coverletter.txt

Phone: 123-456-7890 Email:

Dear Hiring Manager,

I am interested in the position you listed on #website . I belive my skills are a good match to be working with you and your team. I am familiar with the tools (#inserttools) that you require for the job. I have worked in #toolproficient for over #toolyr years.

I am presently getting a Masters degree in Computer Science from New York University. Also I work part-time with a startup providing them solutions to make better software products. My latest product required me to gather data from web scraping, APIs or other sources and rank them according to a keyword based algorithm. I learned it requires dedication to be working in a small team and to understand the end user. I also got to interact with the best developers who guided me in developing my software skills in an Agile environment. I am constantly looking forward to upgrade my skills while developing software applications.

I hope my resume helps you understand the application stack I have worked on and also helps you find a better fit for the position you have to offer at #company.

Thank You

Sincerely,

skills.csv

skills.csv

bsayles15
  • 19
  • 4
  • There are many things wrong with your code so it is hard to tell what the specific cause of the failure is. Please post the full error message. – Kapocsi May 05 '20 at 01:11
  • 1
    I see a couple of problems, but the one that's causing the error you're getting is the `eval()`. You don't want to do that. Just a wild guess, but I think you mean to `split()` the contents of `line`. – Rusty Widebottom May 05 '20 at 01:12
  • I changed it to split but it still getting the error code. Anything else that could be creating it? – bsayles15 May 05 '20 at 01:39
  • C:\Python34>python coverletter.py '.' is not recognized as an internal or external command, operable program or batch file. that's the full error message – bsayles15 May 05 '20 at 01:39
  • Add your data files to your question (skills.csv, cover_letter.txt) and I will take a look. – Rusty Widebottom May 05 '20 at 01:46
  • I added both files at the end of the post. Thanks for your help. – bsayles15 May 05 '20 at 02:00
  • What are you trying to achieve with the `args = eval(line.strip())` line? As said in an other comment, this is the cause of your problem. And if you think you need `eval`, you probably do not understand it. Plus `eval` is generally risky in python. – Keldorn May 05 '20 at 02:22
  • What are you trying to accomplish in the second `for` loop? – Rusty Widebottom May 05 '20 at 02:23
  • The second for loop creates the new document by taking the rows from the csv file and inserting them into the pdf file. – bsayles15 May 06 '20 at 00:38
  • I updated the code to a split () from eval from the other comment but it still gives me the error – bsayles15 May 06 '20 at 00:40

0 Answers0