python - Creating a folder and set as working directory for saving stdout files and images -


in code, create textfile stdout , save several .png images , .mat matrices - when code finishes running there lot of files inside directory

i want code able create new directory inside folder code running, , save .txt file output .png , .mat newly created folder.

i have figured out create new directory should do:

import os os.mkdir('folder') 

and create output file , set stdout there is

import sys filename = open('filename.txt','w') sys.stdout = filename 

i tried using open('folder/filename.txt','w') error: ioerror: [errno 2] no such file or directory

thank you!

if understand right, want create file 'filename.txt' inside folder made ('folder')?

given that's case, use os.path.join()

import sys filename = open(os.path.join('folder','filename.txt'),'w') sys.stdout = filename 

now sys.stdout points file inside new folder


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -