Skip to content

Commit 77d9aa3

Browse files
committed
Made python2 compatible
1 parent 729bc4f commit 77d9aa3

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

py3nvml/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
from py3nvml import py3nvml
24
from py3nvml import nvidia_smi
35
from py3nvml.utils import grab_gpus

py3nvml/py3nvml.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ class struct_c_nvmlUnit_t(Structure):
381381
# Convert bytes objects to strings or leave untouched
382382
def bytes_to_str(s):
383383
if type(s) is bytes:
384-
return str(s, 'utf-8')
384+
try:
385+
return str(s, 'utf-8')
386+
except TypeError: # Can get this if running python 2
387+
return str(s)
385388
else:
386389
return s
387390

py3nvml/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import print_function
3+
from __future__ import division
34

45
import logging
56
import os

scripts/py3smi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#! /usr/bin/env python
2+
from __future__ import print_function
3+
from __future__ import division
4+
from __future__ import absolute_import
25

36
from py3nvml.py3nvml import *
47
from datetime import datetime

0 commit comments

Comments
 (0)