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

How about

sorted(set(open('f1')))
commented: nice +13

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)))

great thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.