0

I have just read some of posts on how to save a kml file on macos desktop in Python but i couldn't find the answer.I try to locate the file path but it doesn't work. my code is:

import pathlib
import simplekml

longitude = input("Enter longitude: ")
latitude = input("Enter longitude: ")

kml = simplekml.Kml()
kml.newpoint(name="Sample", coords=[(longitude, latitude)])
kml.save("~/Desktop/bura/Points.kml")

The problem starts with kml.save("~/Desktop/bura/Points.kml") it doesn't find the path and doesn't save the file.

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
Barish Ahsen
  • 100
  • 1
  • 1
  • 4

1 Answers1

2

kml probably does not expand ~, but you can do it explicitly:

import os
...
kml.save(os.path.expanduser("~/Desktop/bura/Points.kml"))
AChampion
  • 29,683
  • 4
  • 59
  • 75