Search code examples
pythonpython-3.xtextcopy-paste

How to copy code from a text file to a .py file?


I am making a hardcoded voice assistant and I want others to be able to use it as I do i.e. open applications and other stuff but the paths have my username in them so I am thinking I should create a txt file with all the voice commands (in python syntax) and make a script that copies the contents of txt file to a py file, so that others can copy paste and add more commands simply by editing the txt file.

How do I do it? Or is there a simpler way to do this?


Solution

  • with open("filetowrite.py","wb") as fout:
        with open("filetoread.txt","rb") as fin:
             fout.write(fin.read())
    

    I guess ... seems like a strange method to use to me though