How do I use a back slash as a delimiter, python wont recognize it.
ofile = open('MapServicesInfo.csv', "w")
writer = csv.writer(ofile, delimiter = '\', quotechar='"', quoting=csv.QUOTE_ALL)
This is an example of a row I need to write to csv file by delimiting the slash.
Write each section within the slashes to separate rows .
I guess I need to know how to make it not recognize as a escape character ?
... \Sewer\ControlValve
Here is the process
>>> a = "Sewer\ControlValve" >>> b = a.split("\\") >>> b ['Sewer', 'ControlValve'] >>> c = ("{}\n"*len(b)).format(*b) >>> c 'Sewer\nControlValve\n' >>> print(c) Sewer ControlValve
Now that can be simplified of course
Interesting I just added .split ("\\)
writer.writerow([fullpath.split("\\")])
I get the following which correctly splits it at the slashes and yields commas.
['Sewer', 'ControlValve']
So, I only need to write to different rows where it is has a comma.
I handled that in my example
see line 5
if you have to do this, all it does is determine the length of the list (hence the len(b)) and multiplies the format designator {} the correct number of times, then adds a newline
hence.... line 5
this is equivalent to
use my c syntax
for i in c:
writer.writerow(i)
and you are done
Thanks for the help
I put the following and results in vertical rather than horizontal and each letter is written to a different cell.
b = fullpath.split("\\")
c = ("{}\n" * len(b)).format(*b)
for i in c:
writer.writerow (i )
simpler still... use b if you have to write one row at a time
for i in b: print(i)
...
Sewer
ControlValve
b = fullpath.split('\\')
c = ("{}\n" * len(b)).format(*b)
for i in b:
writer.writerow(i)
This is one step closer. Yet writing into single cells and vertically.
S\"E"\"W"...
C\"O"\"N"...
grief... it obviously don't write the newline
so try to add it
writer.writerow( i + "\n" )