Hi everybody! I want automatically create many folders with the python files inside. Those python files I want to fill in with the text, which is python code. So I want to insert that code as a text. The problem is that the code contains commands which are not recognizable as a text. Can you tell me, please, how to force python to consider code as a text.
Thanks in advance.
Here is my code:
import os import shutil
beginh=0 beginm=0 begink=0
hr=3 # h mr=4 # death increment due to foraging kr=5 # perturbation max and min range difference
directory_name = 'foodPert' for h in range(beginh, beginh+hr): if h == 0: d = 100 if h == 1: d = 500 if h == 2: d = 1000 for m in range(beginm, beginm+mr): if m == 0: df = 0 if m == 1: df = 0.1 if m == 2: df = 0.2 if m == 3: df = 0.3 for k in range(begink, begink+kr): if k == 0: fp = 2 if k == 1: fp = 4 if k == 2: fp = 6 if k == 3: fp = 8 if k == 4: fp = 10 dirName = directory_name+'_h_'+ str(d) + '_df_' + str(df) + '_fp_' + str(fp) os.mkdir(dirName)
#make compile.py file c = open('/compile.py','w') c.close()
c = open('/compile.py','w') # this information I'll put inside the file l = [' import os import shutil seeds=5 beginrep=0 cpp_name = 'FoodPerturbation.cpp' myprogram = directory_name+'_h_'+ str(d) + '_df_' + str(df) + '_fp_' + str(fp)
#if directory is not there yet, create it if not (os.path.isdir('./' + dirName + '/')): os.mkdir(dirName) #copy necessary files shutil.copyfile('random.h',dirName+'/random.h') shutil.copyfile('SocialColony.h',dirName+'/SocialColony.h') shutil.copyfile('SocialPopulation.h',dirName+'/SocialPopulation.h') shutil.copyfile('Individual.h',dirName+'/Individual.h') shutil.copyfile(cpp_name, dirName + '/' + cpp_name) #change to the subdirectory os.chdir(dirName) #compile within subdirectory, creating the executable within subdirectory os.popen('g++ -g ' + cpp_name + ' -o ' + myprogram) #change back to higher directory os.chdir('../') #make job description files (handy if they have a keyword that distinguishes them, like 'job') job_name='job_' + myprogram +'_s'+str(k+1)