mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-09 10:40:34 -05:00
New Post
This commit is contained in:
parent
35c0da53a0
commit
ea9471f9fa
1 changed files with 23 additions and 0 deletions
23
content/blog/detectpythonversion.md
Normal file
23
content/blog/detectpythonversion.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: "Detect Python Version"
|
||||
date: 2021-03-15T18:09:38-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
---
|
||||
|
||||
I was working on a distribution recently where `python` was mapped to `python2`. It mixed me up for a bit since I was writing a script for `python3` but it ran partially under `python2`. To lower confusion in the future, I think it's a great idea to check the python version and exit if it isn't the version you expect.
|
||||
|
||||
```python
|
||||
from sys import version_info, exit
|
||||
|
||||
if version_info.major != 3:
|
||||
print("This script only supports Python 3")
|
||||
print("Curent version: " + \
|
||||
str(version_info.major) + "." + \
|
||||
str(version_info.minor) + "." + \
|
||||
str(version_info.micro)
|
||||
)
|
||||
print("Exiting...")
|
||||
exit(1)
|
||||
```
|
||||
|
Loading…
Reference in a new issue