-1

i am trying to write a python script to get all the content in one file to be written to another file . but i am getting the below error . the code i am using is :

#!/user/bin/env python

with open('log.txt', 'r') as file:

line = file.read()

with open('/etc/snort/rules/test.rules' , 'w') as f2:

f2.write(line)

the error i get is :

in line 7

with open('/etc/snort/rules/test.rules' , 'w') as f2:

***IndentationError : expected an indented block***
3
  • Python is indentation sensitive, everythng in your with statement should have a one-level indentation Commented Aug 11, 2018 at 23:41
  • Then you should indent the line f2.write(line) as well as line = file.read(). Indentation is usually 4 spaces per level of (Hint: if a line ends in a colon :, then at least one line underneath it needs to be indented). Commented Aug 11, 2018 at 23:42
  • Hi , i am new in using python , i am not sure what should i do to fix the error? Commented Aug 11, 2018 at 23:44

1 Answer 1

1
#!/user/bin/env python

with open('log.txt', 'r') as file:
    line = file.read()
#### <-- the line above has 4 spaces worth of indentation.  
with open('/etc/snort/rules/test.rules' , 'w') as f2:
    f2.write(line)

I indented the lines under the 'with' statements by 4 spaces

Sign up to request clarification or add additional context in comments.

1 Comment

@Sara mark this answer as correct if it has solved your issue. It makes the solution clearer to others and gives @N Chauhan credit for helping. Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.