-1
text_file = open("BIGBLUE.txt", "r")
lines = text_file.readlines()
target = open ("function_1.txt", "a+")
counter = 1

for line in lines :
    if line[0:29] == "(* @NESTEDCOMMENTS := 'Yes' *)":
        target = open("function_" + str(counter) + ".txt", "a+")
        counter++
    print(line)
    target.write(line)

My goal is to split up a huge text file into multiple ones using (* @NESTEDCOMMENTS := 'Yes' *) as the string delimiter.

My intention is to: Open the file Read Line at a time in the for loop if the first 30 characters are (* @NESTEDCOMMENTS := 'Yes' *), I want to create a new file called function_#.txt. Then copy the entire line to the target file.

Only creating new files when it encounters the key string, and copying all lines to that file until it encounters another key string.

It's currently bugging out on

target = open("function_" + str(counter) + ".txt", "a+")

Compiler is saying "inconsistent use of tabs and spaces"

Any pointers?

1 Answers1

0

The issue you are facing is more related to code format. You have tabs and spaces in your script. according to python.org reference

  • Tabs should be used solely to remain consistent with code that is already indented with tabs.
  • Python 3 disallows mixing the use of tabs and spaces for indentation.
  • Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

please check this Possible mixed indentation in Python??

hope this helps

toheedNiaz
  • 1,435
  • 1
  • 10
  • 14