Reputation: 317
I am trying to call a single column from my SQL server and then split it at each "," so I have a list of all the fields in this column
I currently have this code:
for element in tagall:
parts = element.split(',')
print (parts)
but this returns that
'pyodbc.row has no attribute 'split'
Is there any way to split the row into separate lines?
Thanks in advance
Upvotes: 1
Views: 6624
Reputation: 9946
yes, you are trying to split the row object, which is kinda like a list. so if you're only getting one column back you need to do something like:
row[0].split(',')
Upvotes: 0
Reputation: 7806
It seems you want to print this out as a big string instead of keeping the items separate.
for that you can do:
for element in tagall:
print(",".join(element))
if you wanted to split it in to separate lines you could do
for element in tagall:
for item in element:
print(item) #but this doesn't need a comma because they are on separate lines
Upvotes: 2