This was another example where a basic understanding of Python made transforming data simple and accurate. As you can see from the example, the second student has an acad_subplan represented in the 300 rows in the PeopleSoft-formatted output. Python reads an empty value as False, allowing you to use this type of syntax. The if statement on line 22 checks to make sure an acad_plan value was provided in the original file since it is optional. Lines 17-24 print the new comma-delimited format. I used Ole Zorn’s technique for assigning the acad_subplan and admit_term variables. Lines 9-15 iterate through each row in the file, saving the row’s fields in variables. Basically, cpp_list represents every row in the original file, and each row is itself a list. Line 7 creates a variable that contains a list of lists. I imported sys to read the filename from the command line and csv to parse the file based on tabs ( \t). class csv.unixdialect The unixdialect class defines the usual properties of a CSV file generated on UNIX systems, i.e. It is registered with the dialect name 'excel-tab'. Print the comma-delimited format using the appropriate variable valuesĬpp_list = list(csv.reader(f1, delimiter = "\t"))Īcad_subplan = "" if len(row) The good news: the majority of these fields have default values, which allowed me to quickly write a Python program to transform the tab-delimited file into the necessary comma-delimited format. Subplan = concentration (e.g., American Literature or Molecular Biology).Plan = area of study (e.g., English, Biology, or Economics).
![python write list to file tab delimited python write list to file tab delimited](https://freecontent.manning.com/wp-content/uploads/using-markup-for-languages-in-hugo_07.png)
![python write list to file tab delimited python write list to file tab delimited](https://files.realpython.com/media/Reading-and-Writing-Data-With-Pandas_Watermarked.435ef1c38466.jpg)
For those not familiar with PeopleSoft terminology, CPP data is the foundation of a student’s academic record.īasically, CPP consists of the following:
![python write list to file tab delimited python write list to file tab delimited](https://i.stack.imgur.com/TESvZ.png)
This week I was tasked with creating several thousand Career/Program/Plan records (CPP for short) to support enrollment conversion.