Python Forum
Trying to figure how to continue my numbering for my "file 1:"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to figure how to continue my numbering for my "file 1:"
#4
imports are best placed on top of the file.
In line #9 you open file (only time in the code), and then in line #12 you close the file on every for iteration. Anyway, using context manager is a better to handle files. It will close the file automatically after you are done with the processing. Try something like this:

import os
import arcpy

def main():

    arcpy.env.workspace = "I:\\GEO5419_Python\\Lab2"
    path = r"I:\GEO5419_Python\Lab2"
    fcList = arcpy.ListFeatureClasses()
    with open(path + r'\listfeatures.txt', "w+") as file:
        for line in fcList:
            file.write("File 1:" + line)
            file.write("\n")  # writes next feature on seperate line

if __name__ == '__main__':
    main()
Reply


Messages In This Thread
RE: Trying to figure how to continue my numbering for my "file 1:" - by j.crater - Feb-03-2018, 03:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't seem to figure out how to delete several lines from a text file Cosmosso 9 6,720 Dec-10-2019, 11:09 PM
Last Post: Cosmosso

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020