I retrieved data from a sql query by using
bounds = cursor.fetchone()
And I get a tuple like:
(34.2424, -64.2344, 76.3534,
You can also use str.format() to produce any arbitrary formatting if you're willing to use *
magic. To handle the specific case of this question, with a single separator, is actually a little cumbersome:
>>> bounds = (34.2424, -64.2344, 76.3534, 45.2344)
>>> "{} {} {} {}".format(*bounds)
34.2424 -64.2344 76.3534 45.2344
A more robust version that handles any length, like join
, is:
>>> len(bounds)*"{} ".format(*bounds)
But the value added is that if you want to extend your formatting to something more involved you've got the option:
>>> "{} --> | {:>10} | {:>10} | {:>10} |".format(*bounds)
34.2424 --> | -64.2344 | 76.3534 | 45.2344 |
From here, your string formatting options are very diverse.