python removing ' ' in string? -


this question has answer here:

i trying longtitude, latitude , altitude gps module on raspberry pi b+.

currently running code here:

## prints latitude , longitude every second. import time import microstacknode.hardware.gps.l80gps  if __name__ == '__main__':     gps = microstacknode.hardware.gps.l80gps.l80gps()     while true:         try:             data = gps.get_gpgga()         except microstacknode.hardware.gps.l80gps.nmeapacketnotfounderror:             continue         list = [list(data.values())[x] x in [7, 9, 12]]         string=str(list)         string = string[1:-1]         text_file = open("/home/pi/fyp/gps.txt","a")         text_file.write(string + "\n")         time.sleep(1) 

this output of said code:

0.0, 0.0, '10.2' 0.0, 0.0, '3.2' 0.0, 0.0, '10.1' 0.0, 0.0, '3.1' 0.0, 0.0, '4.5' 0.0, 0.0, '20.1' 0.0, 0.0, '3583.1232' 0.0, 0.0, '102.01' 0.0, 0.0, '32.131' 0.0, 0.0, '421.32' 0.0, 0.0, '12391.11' 0.0, 0.0, '323.411' 

is possible remove '' quotes in last section of output , leave number in first 2 sections of output?

because you're converting list string, shouldn't that. i'd suggest use ', '.join() instead:

list = [list(data.values())[x] x in [7, 9, 12]] string = ', '.join(map(str, list)) 

let's see what's wrong:

>>> l = ['123', 456] >>> str(l) "['123', 456]"  >>> print(str(l)) ['123', 456]  >>> ', '.join(map(str, l)) '123, 456'  >>> print(', '.join(map(str, l))) 123, 456 

because python use quotes says that: this object string.

and when convert object has string object within it, quotes still there instead of removed automatically.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -