I've just started a Python Scripting tutorial on QGIS. The problem arrives right at the end, when I have to use this script:

output_file = open('c:/Users/Ujaval/Desktop/airports.txt', 'w')
for f in layer.getFeatures():
  geom = f.geometry()
  line = '%s, %s, %f, %f\n' % (f['name'], f['iata_code'],
          geom.asPoint().y(), geom.asPoint().x())
  unicode_line = line.encode('utf-8')

Please note that the PATH used is another one, and that's my big problem as I tried several alternatives on how to write it, examples:

output_file = open('D:\ne_10m_airports', 'w')
IOError: [Errno 22] invalid mode ('w') or filename: 'D:\ne_10m_airports'

output_file = open('C://Users//Florin//Desktop//ne_10m_airports', 'w')
IOError: [Errno 13] Permission denied: 'C://Users//Florin//Desktop//ne_10m_airports'

output_file = open('C:/Users/Florin/Desktop/ne_10m_airports', 'w')

output_file = open('C:\Users\Florin\Desktop\ne_10m_airports', 'w')

I can't really seem to figure out why it's being denied permission. In any case, the error is either: permission denied, invalid mode or filename. (Tried it with double quotes as well).

  • 1
    I can see why it didn't worked...I didn't typed .txt file type. What a terrible mistake. No wonder it didn't work, however as I changed to Linux it could still be something else. – Geosphere May 21 '15 at 10:16
  • The error is telling you the problem, "invalid mode or filename". docs.python.org/2/tutorial/… – Matt May 21 '15 at 10:43


'D:\ne_10m_airports' as 'D:/ne_10m_airports' 

(change with uri formalism) or


(escaping) or


(r means raw string)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.