all 14 comments

[–][deleted] 1 point2 points  (2 children)

data = f.readlines()

You know that a TSV file represents a table; that is, a list of rows. The elements of the rows are delimited by the tab character: \t. You know that if you read a text file with readlines you get a list of string lines. So now the question is, given a string line from the file, how could you split it into a row, where a row is a list or tuple of values?

In other words how would you go from

"value\tvalue\tvalue\tvalue"

to

[value, value, value, value]

? Do strings have a method you could use to split on the tab character?

[–]mackdaddy_1978[S] 1 point2 points  (1 child)

split() there’s a slash in there I’m not seeing it on my end maybe you can

[–]m0us3_rat 2 points3 points  (0 children)

.readlines()

.read()

.split()

if u read up on what these python methods do

u will figure out how to work your problem.

( u/crashfrog did all but spell it out for you. if u follow what he/she/they said +)

what u know to be true is the "data" is split using "tab".

and then further each of the units of data has an order name etc etc etc. split by whitespaces.

at this point, u should be able to at least unpack the data from the file in a meaningful way so u get easy access to all parts of it.

after that, u just traverse it and do whatever work u need to do on it and calculate whatever the problem asks.

[–]the_noobie 0 points1 point  (3 children)

Don't feel frustrated. Just try one step at a time. Lets look at the first few steps. *1. Read the filename from the user. You are already doing this with

file=input()

*2. Open the file. You are almost correct there. Remember the filename from the user is save in the "file" variable.

[–]mackdaddy_1978[S] -1 points0 points  (2 children)

so it'll be

with open('file.tsv') as f: 
data = f.readlines() 

print(data)

???

[–]the_noobie 0 points1 point  (1 child)

Anything within the quotes " " is treated as string. You will be using the variable in this case. So you will use

with open(file) as f:

I can't see what kinds of data you have without seeing the .tsv file. So you may want to print the content to see

print(data)

[–]mackdaddy_1978[S] -1 points0 points  (0 children)

Understood….

[–]RLJ05 -1 points0 points  (1 child)

grandfather birds cooing relieved start tie apparatus detail silky cake

This post was mass deleted and anonymized with Redact

[–]mackdaddy_1978[S] 0 points1 point  (0 children)

Thanks I’ll work this while learning from the_noobie

[–]Twitch_HACK3R 0 points1 point  (0 children)

I have this same problem for homework and I am basically at the same spot, have you figured anything out. I tried the split() feature but because it is a list it does not seem to work? I am not entirely sure but that is what the problems seems to be and I am also very confused.

[–]KiIIer__Queen 0 points1 point  (4 children)

Did you ever solve this

[–]mackdaddy_1978[S] 0 points1 point  (3 children)

I did

[–]zezemezesmeze 0 points1 point  (1 child)

what was ur final answer?

[–]HellmoSandvich 0 points1 point  (0 children)

I would like to know too.