Python Forum

Full Version: Text editing with python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a *.txt 3d scan file in the form of x,y,z...

-43.9017 58.4327 8.0448 0.5321
-43.9031 58.4574 8.0457 0.4800
-43.9247 58.4600 8.0505 0.5794
-43.8825 58.4828 8.0390 0.5164

The problem is that the file is way too big and needs some culling ... ie it has about 2055 million point and in order for a program to read it it needs to be less than 2000 million or even less. I am a beginner in python and it shouldn't be hard but the idea is to open the file through python, delete every 50th row and save in another location. In another situation i would have sat it through and solved it myself but because it critical for my job i don't have the luxury of time.

Thanks in advance for your help.
You can read it and process it line by line:

with open('big_file.txt', 'r') as f:
    for line in f:
        # do something