2

Below is my code, when printing the second file i create, i get an indent. Don't see why. Since I'm learning any other comments on my simple code are wellcome, and will be taken gladly. Thanks!

from sys import argv
script, file_name = argv
file_object = open(file_name)
print(file_object.read())
file_object.close()
second_file_name = input("Enter the second file name: \r\n>> ")
second_file_object = open(second_file_name + 'txt', 'w+')
second_file_object.write(input("Now write to your file: \r\n>> "))
second_file_object.seek(0)
print("printing the second file object: \r\n", second_file_object.read())  
# why is the file content indented when printed?
second_file_object.close()

1 Answer 1

4

print will add a single space between each argument by default.

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

If you change the separator, you can remove the space character you don't want.

print("printing the second file object:", second_file_object.read(), sep="\n")  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.