Sunday, 15 August 2010

python - TypeError: cannot concatenate 'str' and 'NoneType' objects -



python - TypeError: cannot concatenate 'str' and 'NoneType' objects -

save = "/root/foo/" perf_path="/root/foobar/"

so, had variable save , perf_path in cmd. now, want substitute enhanced readability.

i wanted create folder variable app[a] stored.

direc = os.mkdir(save + + "-"+ j +"-" + k + "-" +l)

creating directory not seem problem. joining non-string value variable string seems problem.

cmd = "taskset -c %s" + perf_path + "perf2 stat -t %s e r4008387e1 -f -o" +save + direc + "%s.csv &" % (cpus_list[a],fpid[a],apps[a]) pro= subprocess.popen(cmd,shell=true, stdout=subprocess.pipe, preexec_fn=os.setsid)

typeerror: cannot concatenate 'str' , 'nonetype' objects

cmd = "taskset -c %s" + str(perf_path) + "perf2 stat -t %s e r4008387e1 -f -o" +str(save) + str(direc) + "%s.csv &" % (cpus_list[a],fpid[a],apps[a])

that wasn't of much help either.

any ideas how can solve this?

os.mkdir() not homecoming anything, direc set none.

do instead:

direc = save + + "-"+ j +"-" + k + "-" +l os.mkdir(direc)

you want utilize os.path.join() , string formatting build paths though, it'll lot easier read:

save = "/root/foo" perf_path="/root/foobar" direc = os.path.join(save, '-'.join((i, j, k, l))) os.mkdir(direc)

for subprocess.popen(), pass in list instead of string command , arguments, , leave shell default value of false, there no need have shell handle that:

cmd = ['taskset', '-c', cpus_list[a], perf_path, 'perf2', 'stat', '-t', fpid[a], 'e', 'r4008387e1', '-f', '-o', save, os.path.join(direc, "%s.csv" % apps[a]) ] pro = subprocess.popen(cmd, stdout=subprocess.pipe, preexec_fn=os.setsid)

python linux

No comments:

Post a Comment