Привет!
Подскажите, пожалуйста, как можна кусок кода позначить как текст? Заранее спасибо!
П.С. Кавычки не работают.
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)
directory_name = directory_name+'_h_'+ str(d) + '_df_' + str(df) + '_fp_' + str(fp)
for k in range(beginrep,beginrep+seeds):
dirName = directory_name+str(k+1)
#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)
f=open(job_name,'w')
f.write('#PBS -N dynamics'+'_rep'+str(k+1)+'\n')
f.write('#PBS -l walltime=100:00:00\n')
f.write('#PBS -l ncpus=2\n')
f.write('#PBS -j oe\n')
f.write('cd '+ directory_name + '/' + dirName+ '\n')
f.write('./' + myprogram + ' ' + str(k+1) + '\n')
f.close'
]
for i in l:
c.write(i)
c.close
#make submit.py file
s = open('/submit.py','w')
s.close()
s = open('/compile.py','w')
# this information I'll put inside the file
j = ['
import os
seeds=5
beginrep=0
for k in range(beginrep,beginrep+seeds):
job_name='deathPert_h500_df_0_pr_0.015_per_0.5'+'_s'+str(k+1)
os.popen('qsub '+'job_'+job_name)
os.chdir('..')
'
]
for i in j:
s.write(i)
s.close
Alex IvanovТакая ошибка обычно говорит об отсутствии прав либо на создание файла либо на его запись, выставьте права.
Верно!
Но мне пока не удается создать файлы в папках. Мне выдает ошибку Permission denied ‘/compile.py’
Alex IvanovРешил я детально посмотреть ваш код.
У меня есть права администратора, если вы это имеете ввиду.
#make compile.py file
c = open('/compile.py','w')
c.close()
#make submit.py file
s = open('/submit.py','w')
s.close()