Select to view content in your preferred language

How to use CSV module write to multiple lines.

13421
31
05-26-2016 11:57 AM
DevinUnderwood2
Regular Contributor

I have multiple lines but only one is written to the csv file. What am I missing from an except of my code.

s = (fullpath + lyr_source)
                    
                        with open('TEST.csv', 'w') as writeexcel:
                            a = csv.writer(writeexcel)
                            for line in :
                                a.writerow ([line])
0 Kudos
31 Replies
DevinUnderwood2
Regular Contributor

I broke the code apart into 2 separate parts.

Part 1) Looped the mxds and successfully printed the feature classes

Part 2) Using Search Cursor works fine on a shapefile but not a feature class.

The problem is accessing a feature class in an sde environment is what I conclude. It cannot open the feature class.

I will keep testing why is this the case, I may need to recheck how I set path using sde feature classes and their connection, may need special set up .

0 Kudos
BlakeTerhune
MVP Regular Contributor

First, there's a nice way of posting code in GeoNet.

As for your error, first make sure you're building your paths correctly and that the feature class you're after actually exists. Also, check that last line in the code. You want to write each row to the csv, not fields.