Created
July 31, 2019 15:32
-
-
Save metasim/6c487e5cc9f85d3821ef738fa445aa0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_dims(parts): | |
assert(len(parts) is 2, "Expected dimensions specification to have exactly two components") | |
assert(all([isinstance(p, int) and p > 0 for p in parts]), | |
"Expected all components in dimensions to be positive integers") | |
options.update({ | |
"imageWidth": parts[0], | |
"imageHeight": parts[1] | |
}) | |
if raster_dimensions is not None: | |
if isinstance(raster_dimensions, tuple): | |
set_dims(raster_dimensions) | |
elif isinstance(raster_dimensions, str): | |
p = list(map(lambda s: int(s), raster_dimensions.split(','))) | |
set_dims(p) |
At line 2 I would probably prefer an equality test rather than is. Not exactly sure why.
I honestly don't know the difference.
IDK but maybe this seems correct
is
will return True if two variables point to the same object,==
if the objects referred to by the variables are equal.
And as I recall there is some interesting things like if i say a=2
and b=2
then a is b
is true because both objects will point ot the same underlying object. I think.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At line 2 I would probably prefer an equality test rather than
is
. Not exactly sure why.at line 3 we could also attempt coercion to
int
.At line 10 also check for
list
:if isinstance(raster_dimensions, (list, tuple))
If you take my suggestion above about doing int coercion within
set_dims
function then you don't need to do it at 14. If you still want to do it, i think more readable to do anotehr list comprehension at 14 instead oflist(map(...)
. say[int(s) for s in raster_dimensions.split(',')]