I know that F Strings were introduce in Python 3.6. For that I was getting error: "Invalid Syntax"
DATA_FILENAME = 'data.json'
def load_data(apps, schema_editor):
Shop = apps.get_model('shops', 'Shop')
jsonfile = Path(__file__).parents[2] / DATA_FILENAME
with open(str(jsonfile)) as datafile:
objects = json.load(datafile)
for obj in objects['elements']:
try:
objType = obj['type']
if objType == 'node':
tags = obj['tags']
name = tags.get('name','no-name')
longitude = obj.get('lon', 0)
latitude = obj.get('lat', 0)
location = fromstr(F'POINT({longitude} {latitude})', srid=4326)
Shop(name=name, location = location).save()
except KeyError:
pass
Error:
location = (F'POINT({longitude} {latitude})', srid=4326)
^
SyntaxError: invalid syntax
So I used:
fromstr('POINT({} {})'.format(longitude, latitude), srid=4326)
The error was removed and it worked for me. Then I found this library future-fstrings. Should I use it. Which will remove the above "Invalid Error"?