0

Hi,

I don't understand how to write unix shell commands in python. I have this txt file were I want to delete duplicates. It looks something like this:

RTGR.txt
FRTO.txt
RTGR.txt
SDOP.txt
QWJL.txt
SDOP.txt
FRTO.txt
FRTO.txt
...etcetc...

I think I'm suppose to import os and then I want to use the following command line (which works in the shell but I don't know how to start when dealing with python):

sort f1 | uniq > f2

How do I as a start open the file in os system?

--Sofia

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by sofia85
0

How about

sorted(set(open('f1')))

Or even better

with open('f2', 'w') as f2:
    with open('f1') as f1:
        f2.writelines(sorted(set(f1)))

Edited by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.