0

This is link to my older post in this connection cannot concatenate 'str' and 'file' objects : Python error

My code is now as below:

for src_filename, src_code in src_dict.iteritems():
try:
   if src_filename == "weigh_of_the_fruit.c":
      src_filepath = os.path.join(maindir, "folder/")
      filename = src_filename
      if not '/' in filename:
         filename = os.path.join(src_filepath, filename)
      a = open(filename, "r")
   src_dict[src_filename] = subprocess.check_output("unifdef" +'-D'+definedFlags + '-U' +undefinedFlags+ filename, shell = True)

except:
      subprocess.CalledProcessError, e:
      # code 

so I get an error on

src_dict[src_filename] = subprocess.check_output("unifdef" +'-D'+definedFlags + '-U' +undefinedFlags+ filename, shell = True)

I think this line doesn't detect the path - filename maindir is a path of repo and argument taken from command line.

P.S: I solved this problem. It was syntax error. I had to code space

Community
  • 1
  • 1
geek_xed
  • 165
  • 1
  • 8
  • 15
  • I followed a suggestion given by Charley in linked post. so basically filename is a path. – geek_xed Jul 10 '15 at 20:45
  • What exactly is the error? – khagler Jul 10 '15 at 20:47
  • it doesn't try src_dict statement and jumps to except and calls subprocess.CalledProcessError. it should not do so, if src_filename == 'weight_of_the_fruit.c". so I think it is not detecting filename. – geek_xed Jul 10 '15 at 20:51
  • moreover if I remove filename and put "/c/home/maindir/folder/"+src_filename, the code works fine. – geek_xed Jul 10 '15 at 20:53
  • This code won't run as written due to the indentation problems (which makes it hard to figure out if your problem is maybe just basic syntax). Can you ensure that you have posted a runnable sample? – larsks Jul 10 '15 at 20:58
  • this is part of very big code. but i have pasted the code as it is. – geek_xed Jul 10 '15 at 21:01

0 Answers0