Created
August 3, 2021 19:15
-
-
Save realFranco/6680bfe560403fe11517af55e1e2c428 to your computer and use it in GitHub Desktop.
Script to compose a csv file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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