Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I require a lot of help on reading and sorting files

symaticcsymaticc Posts: 2Member
And before I go posting away about my code, I was wondering if there is actually someone here who knows programming on python and is willing to help. Long story short, I am trying to write a code which reads a file and then sorts and and then writes it out to another file. I am give more details after if there is someone who is willing to help.

Thanks a lot in advance!

Comments

  • prgtutorprgtutor Posts: 1Member
    I haven't worked in Python recently, and I am far from an expert on it, but I do know that what you are trying to do is not that complicated in Python. I should be able to help you if you paste your code, or you can message it to me too.

    To start off, your program can be divided into a few steps, such as:

    i) read all the lines from the input file into a list of strings

    ii) sort the list using a simple one-line library function or in-built sort operator, as the case may be for Python

    iii) after you have sorted the file, you write out the sorted list to the new file.


    Apart from that, you also have to open the relevant files before reading and writing to them, and then close their handles after you are done with them.

    The above comment assumes you want to sort the file according to lines.






Sign In or Register to comment.