简体   繁体   中英

Changing directory every running python script

How can I change directory every launch programm?

For example, I need to ask directory before programm running:

     a = input()
     06
     os.chdir("C:\\Test\\a.2020") > os.chdir("C:\\Test\\06.2020")

You can pass the directory path as sys.argv while triggering the module.

    class FlatData:
        def __init__(self):
            # connection with elasticsearch at localhost
            self.es = elasticsearch.Elasticsearch([{'host': 'localhost', 'port': 9200}], http_auth=('XXXXX', 'XXXXX'), timeout=500)


        def activeCount(self, directoryPath):
            os.chdir(directoryPath)
            print("Current Working Directory ", os.getcwd())


    if __name__ == "__main__":
        fd = FlatData()
        fd.activeCount(sys.argv[1])

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