r/pythonhelp • • Dec 08 '21

PYTHON ASSIGNMENT PLS SOMEONE LOL

Read in the included data file and write it to a file named sorted_data.txt with the same data, but order the columns in ascending alphabetical order.

https://www.dropbox.com/s/snhowdtcne6zuuf/MOCK_DATA-3.txt?dl=0

That is the link to the data file that is supposed to be initially read in.

1 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Dec 13 '21

Any chance you could edit that to show the indents correctly? Instructions are in the wiki, link in sidebar.

1

u/KeganBergi Dec 14 '21

from os import path

dataFileName = "pythonData.txt" outputFilename = "sorted_data.txt" HomeFolder = path.expanduser('~')

fullFileName = path.join(HomeFolder, "downloads", dataFileName)

userProfiles = {}

try: with open(dataFileName, 'r') as inputFile, open(outputFilename, 'w') as outputFile: NewList = [] fileHeader = inputFile.readline() for inputLine in inputFile.readlines(): cleanLine = inputLine.strip() id, first_name, last_name, email, gender, ip_address, favorite_color, ssn, buzzword, animal_name = cleanLine.split('\t') userProfiles = [animal_name, buzzword, email, favorite_color, first_name, gender, id, ip_address, last_name, ssn] print(userProfiles) outputFile.write('\t'.join(userProfiles) + '\n') pass except FileNotFoundError: print(f"ERROR: File {fullFileName} doesn't exist! ):")

1

u/KeganBergi Dec 14 '21

as you can see, it still likes to become a jumbled mess.

1

u/[deleted] Dec 16 '21 edited Dec 16 '21

You need to:

  • switch Reddit posting to markdown mode from fancy pants mode

  • create/edit a post/comment, write intro text followed by a blank line

  • switch to your Python code editor

  • select ALL the code in your editor and press tab to insert an additional 4 spaces in front of every line (assuming you've configured your editor to use spaces rather than tabs and use 4 spaces by default when tab key is used)

  • copy all the code in your editor and paste it into Reddit post/comment

  • add a blank line after the code block

  • don't forget to undo the additional indent in your code editor

Alternatively, use a paste service like pastebin.com.

I've tried to work out what your code says in the two comments, but can't figure it out.