Skip to content

Instantly share code, notes, and snippets.

@realFranco
Created August 3, 2021 19:15
Show Gist options
  • Select an option

  • Save realFranco/6680bfe560403fe11517af55e1e2c428 to your computer and use it in GitHub Desktop.

Select an option

Save realFranco/6680bfe560403fe11517af55e1e2c428 to your computer and use it in GitHub Desktop.
Script to compose a csv file.
"""
Description: Compose a CSV object.
Example execution:
python3 python_pipeline.py > output.csv
"""
import csv
def return_csv():
out = ''
keys = 'name, country, hobby'
values = [
['Jhon Doe', 'Belgium', 'Ping Pong'],
['Jhane Doe', 'Italy', 'Dancing'],
['Jack Doe', 'UK', 'Soccer']
]
for row in values:
out += ', '.join(row) + '\n'
out = out[:-1] # Avoid the last blank line
out = keys + '\n' + out
# print(f'[DEBUG] CSV output: {out}\n')
return out
if __name__ == '__main__':
csv_data = return_csv()
print(csv_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment