import os

nvcc_version_cmd = 'nvcc -V > output.txt'
os.system(nvcc_version_cmd)

with open('output.txt') as f:
    lines = f.readlines()
    for line in lines:
        if ", release" in line:
            start = line.index(', release') + 10
            end = line.index('.', start)
            result = line[start:end]
            print(result)
            quit()

import os

nvcc_version_cmd = 'nvcc -V > output.txt'
os.system(nvcc_version_cmd)

with open('output.txt') as f:
    lines = f.readlines()
    for line in lines:
        if ", release" in line:
            start = line.index(', release') + 10
            end = line.index('.', start)
            result = line[start:end]
            print(result)
            os.remove("output.txt")
            quit()

Remove output.txt file after done
Remove output.txt file after done

After we are done detecting nvcc version, let's delete the temporary output.txt file.
  import os
  
  nvcc_version_cmd = 'nvcc -V > output.txt'
  os.system(nvcc_version_cmd)
  
  with open('output.txt') as f:
      lines = f.readlines()
      for line in lines:
          if ", release" in line:
              start = line.index(', release') + 10
              end = line.index('.', start)
              result = line[start:end]
              print(result)
+             os.remove("output.txt")
              quit()
  
Remove output.txt file after done
## Code Before:
import os

nvcc_version_cmd = 'nvcc -V > output.txt'
os.system(nvcc_version_cmd)

with open('output.txt') as f:
    lines = f.readlines()
    for line in lines:
        if ", release" in line:
            start = line.index(', release') + 10
            end = line.index('.', start)
            result = line[start:end]
            print(result)
            quit()

## Instruction:
Remove output.txt file after done
## Code After:
import os

nvcc_version_cmd = 'nvcc -V > output.txt'
os.system(nvcc_version_cmd)

with open('output.txt') as f:
    lines = f.readlines()
    for line in lines:
        if ", release" in line:
            start = line.index(', release') + 10
            end = line.index('.', start)
            result = line[start:end]
            print(result)
            os.remove("output.txt")
            quit()
