Search code examples
pythonfile-extension

Is there a Python 3 file extension that acts exactly like a *.py extension?


I am writing an open source project in python, and in order to make it easier for another developer to add to it, I would like to have all of my code to have another file extension, so that my installer/updater can tell the difference between my files and the other developers files (these would be unique to their computer).

What the installer would do is delete all of my program files, then download the latest ones and put them in the directory. In order to make these files combine, at the end of my main program, I would add in a few lines of code to check if any of the conditions in the other developers files occur.

I am making a digital assistant using the Chinese room thought experiment as a basis, so the main program is basically hundreds of if, elif, and else statements, pointing to modules telling the main program what to do.


Solution

  • "Is there a python 3 file extension that acts exactly like a *.py extension?"

    No, not that I know of. If you want to do "version control" by creating your own file extensions (?!), you can use the imp module like so:

    Python 3.4.3 interpreter output:

    >>> import imp
    >>> my_module = imp.load_source("My custom module", "my_module.some_extension")
    >>> my_module
    <module 'My custom module' from 'my_module.some_extension'>
    >>> dir(my_module)
    ['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'func']
    >>> my_module.func()
    my module says hi!
    >>> 
    

    my_module.some_extension:

    def func():
        print("my module says hi!")