0

the default path appears to be the project folder I am working in, but I cannot find any documentation that shows how to specify where the csv is saved to on the machine, I am currently using shutil to move the file to my desired path but this is not a robust solution because this application will be used by many users and this may cause problems.

length = len(list1)

#convert job name to csv name
jobname = jobname + ".csv"


with open (jobname, 'w', newline='') as f:
    thewriter = csv.writer(f)

    thewriter.writerow(column_header_list)
    
    i = 0
    for x in range(length):
        thewriter.writerow([list1[i],0,0,0,0,0,0,0,0,0,0])
        i += 1

#create a path for the newly made file
original_path = r'C:\Users\Scott\OneDrive\Documents\DL\Main Application MRL'
original_path = (original_path + '\\') #concat to add backslash to path 
original_path = original_path + jobname #add jobname to path 

target_path = r'C:\Users\Scott\OneDrive\Documents\DL\JobData'

shutil.move(original_path,target_path)
  • 1
    The first arg to open is the path to the file. It's saving to your current directory because the path you are specifying is a relative path. – jordanm Dec 28 '20 at 19:23
  • change jobname to jobname = 'C:\Users\Scott\OneDrive\Documents\DL\JobData\' +jobname+'.csv' – Rajat Mishra Dec 28 '20 at 19:24
  • Saving in the user's current working directory is *not* unusual or surprising. Hardcoding long paths which probably don't exist on new users' systems is much more inconvenient and inflexible. – tripleee Dec 28 '20 at 19:26
  • Perhaps see also [Difference between `./` and `~/`](https://stackoverflow.com/a/55342466/874188) – tripleee Dec 28 '20 at 19:48

0 Answers0