I need to edit a few .pyt files, which are python code but specific to ESRI ArcGIS software.

Is there a variable that lists the file ending that python formatting is applied to that I could add .pyt to in order to have those files formatted?


  • 1
    Do you mean you want python-mode (or whatever) to turn on when you edit one of those files? If so, you can adjust auto-mode-alist.
    – Dan
    Aug 20, 2020 at 14:28
  • got it, currently the python-mode is applied as: ("\\.py[iw]?\\'" . python-mode) there's probably a way to change that regex but (add-to-list 'auto-mode-alist '("\\.pyt\\'" . python-mode)) in my init.el did the trick. Aug 20, 2020 at 14:34
  • 1
    ("\\.py[iwt]?\\'" . python-mode) should do it then.
    – NickD
    Aug 20, 2020 at 15:55
  • thanks @NickD, The way I'm currently doing it with add-to-list, I just update the variable each time emacs each time it's opened. Any thoughts about how to edit the variable in a way that it will persist across sessions? Like how is the rest of the list built and can I edit that? Maybe it's better to keep all of this custom stuff inside init.el. Aug 21, 2020 at 12:53
  • 1
    It is better to keep it inside init.el: isn't that where you put the add-to-list? What I meant was to find the place in your init.el where python-mode is set for .pyi and .pyw files and add the t there. But if somebody else is doing that setting, then it's not worth worrying about it: the add-to-list method is fine.
    – NickD
    Aug 21, 2020 at 13:36

1 Answer 1


view auto-mode-alist using:

M-x describe-variable RET auto-mode-alist

Then edit the list by adding to your init file:

(add-to-list 'auto-mode-alist '("\\.pyt\\'" . python-mode))

Per the docs here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.