33

What is the difference (if any) between ".pyc" and ".py[cod]" notation in ignoring files. I am noticing I have both on my git ignore file. Thanks

justhalf
  • 8,960
  • 3
  • 47
  • 74
BluePython
  • 1,635
  • 3
  • 24
  • 35
  • 4
    @CarlNorum: The OP is not asking about what those extensions mean, just if the pattern `.py[cod]` covers ignoring `.pyc` already. It's a `git` question, not a Python question. – Martijn Pieters Sep 10 '13 at 22:40
  • 2
    It says "What is the difference (if any) between .pyc and .py[cod] files". – Carl Norum Sep 10 '13 at 22:46
  • 1
    It's ambiguous. It appears to ask about the difference between the .py{c,o,d} file extensions, but may really be a Git question about gitignore patterns, since that sparked the question. – T Percival Sep 10 '13 at 22:53

1 Answers1

50

You are safe to remove the .pyc entry from your .gitignore, since .py[cod] will cover it. The square brackets are for matching any one of the characters, so it matches .pyc, .pyo and .pyd.

Since they are all generated from the .py source, they should not be stored in source control.

T Percival
  • 8,526
  • 3
  • 43
  • 43
  • 3
    .pyd files are windows dlls and are not generated by .py files. They are typically compiled from C or C++ source and should be ignored by git much like generated .exe are ignored. If, however, somebody decided to check .pyd files into the repo, you would want to remove the [d] from the ignore file. – tdelaney Sep 10 '13 at 22:33
  • so .pyd files are Python file generated from C or C++ ? – BluePython Sep 12 '13 at 06:05
  • The source for a `.pyd` module may be written in any language, but the `.pyd` file itself is a binary file containing executable code. – T Percival Sep 12 '13 at 18:02