Skip to content

Commit 2412a44

Browse files
committed
Some Python 3 compatibility fixes; still need to fix coordinate_to_string
1 parent 1873740 commit 2412a44

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

pyexcelerate/DataTypes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from . import six
23

34
class DataTypes(object):
45
BOOLEAN = 0
@@ -18,21 +19,21 @@ def to_enumeration_value(index):
1819
@staticmethod
1920
def get_type(value):
2021
# Using value.__class__ over isinstance for speed
21-
if value.__class__ == str:
22+
if value.__class__ in six.string_types:
2223
if len(value) > 0 and value[0] == '=':
2324
return DataTypes.FORMULA
2425
else:
2526
return DataTypes.INLINE_STRING
2627
# not using in (int, float, long, complex) for speed
27-
elif value.__class__ == int or value.__class__ == float or value.__class__ == long or value.__class__ == complex:
28+
elif value.__class__ in six.integer_types + (float, complex):
2829
return DataTypes.NUMBER
2930
# fall back to the slower isinstance
30-
elif isinstance(value, basestring):
31+
elif isinstance(value, six.string_types):
3132
if len(value) > 0 and value[0] == '=':
3233
return DataTypes.FORMULA
3334
else:
3435
return DataTypes.INLINE_STRING
35-
elif isinstance(value, (int, float, long, complex)):
36+
elif isinstance(value, six.integer_types + (float, complex)):
3637
return DataTypes.NUMBER
3738
elif isinstance(value, datetime):
3839
return DataTypes.DATE

pyexcelerate/Range.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . import DataTypes
2+
from . import six
23

34
class Range(object):
45
A = ord('A')
@@ -174,7 +175,7 @@ def coordinate_to_string(coord):
174175

175176
@staticmethod
176177
def to_coordinate(value):
177-
if isinstance(value, basestring):
178+
if isinstance(value, six.string_types):
178179
value = Range.string_to_coordinate(value)
179180
if (value[0] < 1 or value[0] > 65536) and value[1] != float('inf'):
180181
raise Exception("Row index out of bounds")

pyexcelerate/tests/benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def run_pyexcelerate():
1212
stime = time.clock()
1313
ws = wb.new_sheet("Test 1", data=testData)
1414
wb.save("test_pyexcelerate.xlsx")
15-
print "pyexcelerate, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime)
15+
print("pyexcelerate, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime))
1616

1717
def run_openpyxl():
1818
stime = time.clock()
@@ -22,7 +22,7 @@ def run_openpyxl():
2222
for row in testData:
2323
ws.append(row)
2424
wb.save("test_openpyxl.xlsx")
25-
print "openpyxl, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime)
25+
print("openpyxl, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime))
2626

2727
def run_xlsxwriter():
2828
stime = time.clock()
@@ -32,7 +32,7 @@ def run_xlsxwriter():
3232
for col in range(COLUMNS):
3333
ws.write_number(row, col, 1)
3434
wb.close()
35-
print "xlsxwriter, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime)
35+
print("xlsxwriter, %s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime))
3636

3737
def test_all():
3838
run_pyexcelerate()

pyexcelerate/tests/python_benchmarks.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import time
22

3-
43
def test_benchmark():
54
TRIALS = range(1000000)
65

@@ -16,7 +15,7 @@ def test_benchmark():
1615
if not answer:
1716
print "failed test"
1817
break
19-
print "isinstance, %s" % (time.clock() - stime)
18+
print("isinstance, %s" % (time.clock() - stime))
2019

2120
# attempt __class__
2221

@@ -26,13 +25,13 @@ def test_benchmark():
2625
if not answer:
2726
print "failed test"
2827
break
29-
print "__class__, set, %s" % (time.clock() - stime)
28+
print("__class__, set, %s" % (time.clock() - stime))
3029

3130
stime = time.clock()
3231
for i in TRIALS:
3332
answer = (integer.__class__ == int or integer.__class__ == float or integer.__class__ == long or integer.__class__ == complex)
3433
if not answer:
3534
print "failed test"
3635
break
37-
print "__class__, or, %s" % (time.clock() - stime)
38-
36+
print("__class__, or, %s" % (time.clock() - stime))
37+

pyexcelerate/tests/test_Workbook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from ..Workbook import Workbook
2-
import cStringIO as StringIO
32
import time
43
import numpy
54
from datetime import datetime
@@ -21,7 +20,7 @@ def test_save():
2120
stime = time.clock()
2221
ws = wb.new_sheet("Test 1", data=testData)
2322
wb.save("test.xlsx")
24-
print "%s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime)
23+
print("%s, %s, %s" % (ROWS, COLUMNS, time.clock() - stime))
2524

2625
def test_formulas():
2726
wb = Workbook()

0 commit comments

Comments
 (0)