Closed zkwurst closed 7 years ago
I am not quite sure what is the problem. I don't see a need to use nested quotes in "'img{0}_13.img'", otherwise you would have to show me the error.
Regarding the hardcoded name, can't you loop through the zip archive and find the file with img extension and use that name directly?
The nested quotes were my attempt to get .format to work with the string literal when I concatenated them later.
product_format_string = "'img{0}_13.img'"
imgName = product_format_string.format(zipSplit)
So that it would work like this:
imgName = 'img{0}_13.img'.format(zipSplit)
But it didn't work. So I figured I'd have to to .format the .format, and that's when I realized I was probably doing something that didn't need doing.
If you happen to know what I was doing wrong, I'd be curious, but it's definitely not important.
Looping through the zip will work if there's just one .img file in the zip. I was thinking there were two because of the thumbnail, but that's .jpg. I'll check the zip and implement that today.
imgName = product_format_string + ".format({0})".format(zipSplit)
is what I meant to type.
imgName = product_format_string.format(zipSplit)
That's obviously not how any of this works.
Is this what you needed?
In [1]: a = "Hello {0}!"
In [2]: a
Out[2]: 'Hello {0}!'
In [3]: a.format('Zeke')
Out[3]: 'Hello Zeke!'
This is the dictionary I made for NED:
In this entry:
"file_string": "'img{0}_13.img'",
I want to insert the zip archive name using .format later on in the script. THe zip archive name is coming from the zip download URL.
zipSplit
is the string I want to insert into"'img{0}_13.img'"
which i've assigned toproduct_format_string
But this gets caught in one of the timeout errors. I don't remember which.
imgName = product_format_string.format(zipSplit)
I have it hardcoded like this and it works, but only for NED IMG files from 2013. I don't know if other datasets use a similar naming convention.
I didn't want to waste much time on it, but I feel like I'm completely missing something obvious and more pythonic.
A future move to vsizip/vsicurl would solve this anyway.