[Beginner] - Hanging in the code, can't figure out what's wrong
BartC
bc at freeuk.com
Sun Apr 3 12:04:24 EDT 2016
On 03/04/2016 16:25, Rustom Mody wrote:
> On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote:
>> You can create the path manually outside of Python. Or look up the docs
>> to find out how to do that. A quick google suggested using os.makedirs
>> (to create multiple nested paths at the same time).
>> try:
>> os.stat(path)
>> except:
>> os.makedirs(path)
>>
>> print (name)
>>
>> try:
>> file=open(name,'w')
>> file.close()
>> except:
>
> If you dont want the vigilantes out in their squadrons please dont do it that way.
>
> More seriously you can do what you like but dont teach beginners to use bare excepts.
They're not mine (the first is from the first google hit, the second is
the OP's); if it was my choice I wouldn't use exceptions at all.
But the primary issue here is that file not being created. Once the code
works, it can be tweaked later and, if the path still needs creating
from the code, there are doubtless better ways of doing it, with or
without exceptions.
At the minute we don't even know if this was the problem.
--
Bartc
More information about the Python-list
mailing list