0

I have an issue with an open file. First I need to design the name of my file, then it supposed to create a file in a block note with format .txt. Also, I have to use %less in order to print the file.

This is my code:

    def file():
       name=str(input("write the name of your file: ")) 
       content=str(input("write : "))

       with open(name+".txt" , "w") as newfile:
         newfile.write(content)
       %less name.txt

    file()
    leer_libro("name.txt") #it counts my letters of each line
4
  • What problem are you having? Your code should work if you answer name. Commented Dec 21, 2020 at 23:53
  • it doesn't work Commented Dec 22, 2020 at 0:06
  • That's not detailed enough. Commented Dec 22, 2020 at 0:13
  • You should probably end the file with a newline if you want to use normal Unix tools. Commented Dec 22, 2020 at 0:14

1 Answer 1

1

You must pass on an absolute path to with. Example:

with open("D:/PYTHON/03_Coding_Rule/name.txt", "a") as fi:

Please enter an absolute path

Are you having this problem?

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.