Os.mkdir() is not exist

i have a python code in trinket and i tried to use os.mkdir() but it say AttributeError: ‘’ object has no attribute ‘mkdir’
i also tried os.makedirs()

Please show us your code. I assume there’s something wrong with the
object referenced by the name os, but without seeing the code we can’t

@milkor the linked code does not have “mkdir” anywhere in it. Did you mean to link something different? Regardless, it’s possible that an “online python service” might disable or remove the os module as a security consideration. Does your code run locally in a standard Python interpreter?

import os

    config_path = "c:\test"
    os.makedirs(config_path) if not os.path.exists(config_path) else None

or if you prefers

    config_path = "c:\test"
    if not os.path.exists(config_path):

u need to import os first

On Trinket the “os” module seems to be practically empty. You can check by calling

import os

I guess Trinket runs on the remote server, so it would have disabled any kind of direct OS/filesystem access. Instead of using Trinket, it may be easier to use an interactive python session on your local host.

thank you i will try somthing else

One thing to try is running Python on your local machine.

1 Like