0

I have a Python function that asks for the input of a cluster name that in return will pull from a csv file and returns the columns as follows:

server10, xxxxxxxx1, yyyyyyyy1
server11, xxxxxxxx2, yyyyyyyy2
server12, xxxxxxxx3, yyyyyyyy3
server13, xxxxxxxx4, yyyyyyyy4
server14, xxxxxxxx5, yyyyyyyy5
server15, xxxxxxxx6, yyyyyyyy6
server16, xxxxxxxx7, yyyyyyyy7
server17, xxxxxxxx8, yyyyyyyy8
server18, xxxxxxxx9, yyyyyyyy9
server19, xxxxxxx10, yyyyyyy10

I'm using DictReader class from the csv module. How can I put each column into a list while retaining the information of the rows?

clarkus978
  • 574
  • 3
  • 10
  • 22
  • 1
    Are you using the [`csv`](https://docs.python.org/3/library/csv.html) module from the standard library? `csv.reader` does this automatically – Patrick Haugh Feb 23 '17 at 21:42
  • Yes - tell us a little more about what you want to do with this information. using `subprocess` almost certainly isn't necessary. – Jeremy Feb 23 '17 at 21:44
  • You may find this solves your problem: http://stackoverflow.com/questions/4937491/matrix-transpose-in-python – jooks Feb 23 '17 at 22:29

1 Answers1

0

Many thanks to Patrick Haugh for the hint. I was able to look back at my DictReader function and use hostname.append(col['hostname']) to put the columns into separate lists.

clarkus978
  • 574
  • 3
  • 10
  • 22