Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'module' object has no attribute 'mkdirs'

While creating a nested directory in Python 3.6 received following error:

AttributeError: 'module' object has no attribute 'mkdirs'

Sample code:

def create_sample_data():
    os.mkdirs("/tmp/lambdadir/ProjectTemp/mynewtest")
    f=open("/tmp/lambdadir/ProjectTemp/mynewtest/my_copy.txt","w+")
    f.write("This is inside a directory")
    f.close()

Please help.

like image 782
Ash Avatar asked Dec 08 '18 22:12

Ash


2 Answers

There is no os.mkdirs. Perhaps you meant os.mkdir or os.makedirs instead?

like image 68
jwodder Avatar answered Nov 07 '22 13:11

jwodder


After googling a bit, found that, its a Python version issue.

I changed code from os.mkdirs() to os.makedirs() and it worked.

Details: os module documentation

Credits: buttscicles - Reddit

like image 6
Ash Avatar answered Nov 07 '22 12:11

Ash