-1

im querying my mysql database for user coordinates and feeding the output to a function. i intend to get map view from this user_location.

here is part of the code:

def map_view():
    u = conn.execute("select provider_point from providers where username = %s"% "'"+session["current_user"]+"'")
user = u.fetchone() 

print(user)
#gives ('-1.1477195,37.0630088',)
#converting to []  
start_coords = "["+(', '.join(user))+"]".replace("'","")
print(start_coords)
#gives which is what i want
[-1.1477195,37.0630088]

this gives me what i want but when i pass it to folium maps it recieves it as '[-1.1477195,37.0630088]' how do i get rid of the quotes(') ?

Pytbyte
  • 9
  • 4
  • 1
    please fix your indentation, we can't tell where the function definition ends (if it does). Also please add the part where you pass it to folium, I don't see that anywehre. – Z4-tier Feb 07 '20 at 09:48
  • can you please give me the type of user? is it a string? – Manali Kagathara Feb 07 '20 at 09:50

2 Answers2

0

As I can infer from the provided snippet, start_coords is of string type and undoubtedly, this is what you're getting. As it is a list of string, you can convert it to float before passing. Try

start_coords = start_coords.replace('[', '')
start_coords = start_coords.replace(']', '')
lis = start_coords.split(',')
lis = [float(i) for i in lis]

This outputs

[-1.1477195, 37.0630088]

where type(lis[0]) is float. So, lis is a list of float. Now, lis can be passed to folium maps.

Swati Srivastava
  • 1,102
  • 1
  • 12
  • 18
0

Looks like user is a tuple. You can pull out the first (and, by the looks of the example, only) item from the tuple with user[0] or simply loop over it.

for item in user:
    print("[{}]".format(item))

The parentheses and the quotes are not part of the value, it's how Python formats a tuple when you attempt to print it, just like it supplies [...] around a list, { and : and , and } to disambiguate a dict, etc.

>>> example = [1, 2, 3]
>>> print(example)
[1, 2, 3]

but [ is not part of the first value:

>>> print(example[0])
1
tripleee
  • 175,061
  • 34
  • 275
  • 318