将dictonary值转换为字符串以放入文本文件?

时间:2016-01-13 06:25:31

标签: python python-3.x gps

我正在使用覆盆子pi B +和GPS模块将GPS详细信息输出到文本文件。

以下是一些了解正在使用的属性的链接:

http://python3-microstacknode.readthedocs.org/en/latest/example.html#l80-gps http://aprs.gids.nl/nmea/

这是我的代码:

<?php
$input = $_POST['userInput'];
$answer = $_POST['answer'];
$score = 0;
$counter = 0;

for ($counter = 0; $counter <=5; $counter++) {
    if ($input == $answer) {
        $score = $score + 1;
        header("location:game.php");
    } else {
    $score = $score;
}
}
?>

</html>

这是我的输出:

##Prints the latitude and longitude every second.
import time
import microstacknode.hardware.gps.l80gps

if __name__ == '__main__':
    gps = microstacknode.hardware.gps.l80gps.L80GPS()
    while True:
        data = gps.get_gpgga()
        print(data.values())
        text_file = open("/home/pi/fyp/gps.txt", "w")
        text_file.write(data.values())
        text_file.close()
        time.sleep(1)

如何将输出放入文本文件?

1 个答案:

答案 0 :(得分:0)

text_file.write(",".join(map(str,data.values())))

join

上做,