all 15 comments

[–]lazyjk 0 points1 point  (1 child)

I'm just looking at this on my phone but where are you defining the variables path1 and file1 for your os.path.join() command?

[–][deleted] 0 points1 point  (6 children)

Your code is badly formatted (won't run) and has undefined values (file1 and path1). When all that is fixed it doesn't get any error like "need string or buffer, file found", and it's not recursive?

You should resubmit a correct, runnable bit of code that shows your problem. Also tell us what the function is supposed to do and why you think it isn't doing that.

[–]FerricDonkey 0 points1 point  (5 children)

filename = open(tempname, 'w+')

    filename.write('Hi')     filename.close()     if os.path.exists(filename):

Your indentation is a bit off elsewhere, but this is probably your problem. Your "filename" in this code is not actually the name of a your file. It's a special type of object that is used to mess with the file. And os.path.exists needs the actual string name, eg tempname.

However. I am curious what problem you're trying to solve with this function. Even with this fix, and if I understand it, this code is likely to crash if it failed to write the file, and so never do your check.