Home > Enterprise >  Python not accepting /n line breaks
Python not accepting /n line breaks

Time:11-12

Here is my code:

def main():
    opt = setup()
    if opt == 'Y' or opt == 'y':
        inst = ''
        instlist = []
        while not inst == 'end':
            inst = input('Enter codeline to execute, when done type "end"')
            if not inst == 'end':
                instlist.append(inst)
        exec('/n'.join(instlist))
    
        input()

It's supposed to read all of the lines you typed and execute them. I wanted to make it support things like if or try statements, on another question I saw that you can use '/n'.join(list) and the /n would add line breaks so python would understand. But when I run the code I get this traceback:

 File "", line 76, in <module>      
   main()
 File "", line 41, in main
   exec('/r/n'.join(instlist))
 File "<string>", line 1
   while True:/n    print('a')

What can I do to fix this?

CodePudding user response:

The escape character in python is a \ (backslash)
So, \n will be accepted by python as an escape sequence indicating new line.

  • Related