简体   繁体   中英

Python cd in a folder without library

I have this script:

target = input("Choose your target: ")
... etc ...

When script runs, it creates a folder with target's value and inside it another .json file .

For example if target = Test , then I want to read: /Test/Test.json

I have found some commands to do it,but I need os library.

Is there any way to do it without library?

if you want create with os module then use this code

import os
target = input("Choose your target: ")
if target not in os.listdir():
    os.mkdir(target)
    os.system("touch {0}/{0}.json".format(target))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM