You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,63 +37,6 @@ The API comes with a copy of the `httplib2` inside the `shotgun_api3/lib` folder
37
37
38
38
where `vX.Y.Z` is a release found on `httplib2`'s [release page](https://github.com/httplib2/httplib2/releases).
39
39
40
-
## Maintaining Python 2 and 3 compatibility
41
-
42
-
python-api should remain compatible with both Python 2, and 3. To make this easier, we use [six](https://six.readthedocs.io/). When adding code that works with types that have changed between Python 2 and 3, notably strings and files, it's advisable to use the `six` types for casting and comparisons. Be sure to follow Python 2 and 3 compatible conventions in code, especially when raising or capturing exceptions and printing. While we don't use `future`, [this page](https://python-future.org/compatible_idioms.html) contains a fairly comprehensive list of Python 2/3 compatibility sticking points to look out for.
43
-
44
-
Additionally, the [python-modernize](https://python-modernize.readthedocs.io/en/latest/) tool can be helpful when updating Python 2 code for Python 3 compatibility.
45
-
46
-
### Examples:
47
-
48
-
#### Comparisons against changed types:
49
-
50
-
Python 2:
51
-
52
-
```
53
-
if isinstance(my_variable, str):
54
-
```
55
-
56
-
Python 2/3:
57
-
58
-
```
59
-
if isinstance(my_variable, six.string_types):
60
-
```
61
-
62
-
#### Catching exceptions
63
-
64
-
Python 2:
65
-
66
-
```
67
-
except SomeExceptionType, e:
68
-
print "I like to swallow exceptions!"
69
-
```
70
-
71
-
Python 2/3:
72
-
73
-
```
74
-
from __future__ import print_function
75
-
except SomeExceptionType as e:
76
-
print("I like to swallow exceptions!")
77
-
```
78
-
79
-
#### Print statements
80
-
81
-
Python 2:
82
-
83
-
```
84
-
print "My spoon is too big!"
85
-
```
86
-
87
-
Python 2/3:
88
-
89
-
```
90
-
from __future__ import print_function
91
-
print("My spoon is too big!")
92
-
```
93
-
94
-
95
-
Additionally, when testing locally, tests should be run for both python 2 and python 3 to ensure changes won't break cross-compatibility.
0 commit comments