1

I am able to compile the code but I cannot locate my csv file so I do not think it is being generated.

The method should create and write to a csv file. What I do know is where is it being created and how to I define where I want it to be created if it is working.

def generateCSVfile(fileName,fileDescription,fileLocation,md5Hash):
    with open('deploymentTemplate.csv', 'w') as csvfile:
        createRow = csv.writer(csvfile, delimiter=' ',
                                quotechar='|', quoting=csv.QUOTE_MINIMAL)
        createRow.writerow([fileName,' ', fileDescription,' ', fileLocation,' ', md5Hash])

2 Answers 2

2

To find the absolute path of your csv file (i.e., where in the file system it is saved), and to check that it was saved correctly:

import os
print("Output is located at " + os.path.abspath('deploymentTemplate.csv'))
print("File exists? " + str(os.path.exists('deploymentTemplate.csv')))

Possible output:

Output is located at C:\deploymentTemplate.csv
File exists? True

Sign up to request clarification or add additional context in comments.

Comments

1

'deploymentTemplate.csv' is a relative path, so the file will be created in whatever the working directory of your script is. When run from a terminal, the working directory of your script will be the same as that of the terminal.

Working directory can be changed using os.chdir() and obtained using os.getcwd() (after import os).

You may also provide an absolute path, e.g. r'C:\deploymentTemplate.csv on Windows or '/home/drew/deploymentTemplate.csv' on Linux to indicate the exact path to your file.

Please, read about relative paths, absolute paths and working directory on Wikipedia.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.