How is new line denoted in Python?
<p>I have a list of special character:</p>

<pre><code>specialCharList=['`','~','!','@','#','$','%','^',
                         '&amp;','*','(',')','-','_','+','=',
                         '|','','{','}','[',']',';',':',
                         '"',',','.','&lt;','&gt;','/','?',"'",'\\',' ']
</code></pre>

<p>I need to include some sort of character notation for when the user presses the enter button for a new line. I've tried '\n' and that didn't work. Any ideas?</p>

<p>MORE INFO BELOW</p>

<p>Sorry, I should have specified. I'm making a basic encryption/decryption application. What it does is shifts the characters to the right 6 places and outputs that.</p>

<p>e.g. abc would output as ghi
e.g. 123 would output as 789</p>

<p>I've done the same using special characters. Use the list below to see how it works.</p>

<pre><code>specialCharList=['`','~','!','@','#','$','%','^',
                         '&amp;','*','(',')','-','_','+','=',
                         '|','','{','}','[',']',';',':',
                         '"',',','.','&lt;','&gt;','/','?',"'",'\\',' ']
</code></pre>

<p>e.g. ~! would output as ^&amp;</p>

<p>While everything works fine when someone inputs and combination of text,numbers, and special characters into the textbox to be encrypted, if someone inputs a new line (e.g. hits the enter key), I get an error.</p>

<pre><code>index=specialCharList.index(tbInput[i])
</code></pre>

<p>ValueError: u'\n' is not in list</p>

<p>Full code is below.</p>

<pre><code>import wx
import os
class mainForm(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Encryption Tool v2',size=(270,300))
        panel=wx.Panel(self)
        #Setting up controls
        wx.StaticText(panel,-1,'Enter Text Below',(10,10),(200,25))
        self.tbInput=wx.TextCtrl(panel,-1,'',(10,30),(250,220),wx.TE_MULTILINE)
        self.rdEncrypt=wx.RadioButton(panel,-1,'Encrypt',(10,250),(200,-1))
        self.rdDecrypt=wx.RadioButton(panel,-1,'Decrypt',(10,270),(200,-1))
        btnExecute=wx.Button(panel,-1,'Execute',(181,252),(80,-1))
        btnExecute.Bind(wx.EVT_BUTTON,self.encryptionDecryption)
    def encryptionDecryption(self,event):
        tbInput=self.tbInput.GetValue()
        rdEncrypt=self.rdEncrypt.GetValue()
        rdDecrypt=self.rdDecrypt.GetValue()
        if rdEncrypt==True and tbInput!='':
            #copy encryption code below
            encryptedStr=''
            alphabet=['X','M','y','B','e','f','N','D','i','Q',
                 'k','u','Z','J','s','A','q','Y','E','P','S',
                 'v','w','a','U','z','p','d','C','h','o','F',
                 'G','H','I','n','K','W','b','g','O','t','j',
                 'R','l','T','c','V','L','x','r','m']
            specialCharList=['`','~','!','@','#','$','%','^',
                             '&amp;','*','(',')','-','_','+','=',
                             '|','','{','}','[',']',';',':',
                             '"',',','.','&lt;','&gt;','/','?',"'",'\\',' ',]
            for i in range(0,len(tbInput)):
                if tbInput[i].isalpha():
                    index=alphabet.index(tbInput[i])
                    if index+6&gt;len(alphabet)-1:
                        index=5+(index-(len(alphabet)-1))
                        encryptedStr+=alphabet[index]
                    else:
                        encryptedStr+=alphabet[index+6]
                elif tbInput[i].isdigit():
                    if int(tbInput[i])+6&gt;9:
                        encryptedStr+=str(-1+(int(tbInput[i])+6)-9)
                    else:
                        encryptedStr+=str(int(tbInput[i])+6)
                else:
                    index=specialCharList.index(tbInput[i])
                    if index+6&gt;len(specialCharList)-1:
                        index=5+(index-(len(specialCharList)-1))
                        encryptedStr+=specialCharList[index]
                    else:
                        encryptedStr+=specialCharList[index+6]
            #print 'Encrypted Text: '+encryptedStr
            #text file here
            e=open('encryptedText.txt', 'w')
            e.write(encryptedStr)
            e.close()
            if os.name == 'nt':
                os.system('notepad ecryptedText.txt&amp;')
            elif os.name == 'posix':
                os.system('gedit decryptedText.txt&amp;')
            os.system('gedit encryptedText.txt&amp;')
        elif rdDecrypt==True and tbInput!='':
            #copy code for decryption below
            decryptedStr=''
            alphabet=['X','M','y','B','e','f','N','D','i','Q',
                 'k','u','Z','J','s','A','q','Y','E','P','S',
                 'v','w','a','U','z','p','d','C','h','o','F',
                 'G','H','I','n','K','W','b','g','O','t','j',
                 'R','l','T','c','V','L','x','r','m']
            specialCharList=['`','~','!','@','#','$','%','^',
                             '&amp;','*','(',')','-','_','+','=',
                             '|','','{','}','[',']',';',':',
                             '"',',','.','&lt;','&gt;','/','?',"'",'\\',' ']
            for i in range(0,len(tbInput)):
                if tbInput[i].isalpha():
                    index=alphabet.index(tbInput[i])
                    if index-6&gt;len(alphabet)-1:
                        index=5+(index-(len(alphabet)-1))
                        decryptedStr+=alphabet[index]
                    else:
                        decryptedStr+=alphabet[index-6]
                elif tbInput[i].isdigit():
                    if int(tbInput[i])-6&lt;0:
                        decryptedStr+=str(-1+(int(tbInput[i])-6)+11)
                    else:
                        decryptedStr+=str(int(tbInput[i])-6)
                else:
                    index=specialCharList.index(tbInput[i])
                    if index-6&gt;len(specialCharList)-1:
                        index=5+(index-(len(specialCharList)-1))
                        decryptedStr+=specialCharList[index]
                    else:
                        decryptedStr+=specialCharList[index-6]
            #print 'Decrypted Text: '+decryptedStr
            #text file here
            d=open('decryptedText.txt', 'w')
            d.write(decryptedStr)
            d.close()
            if os.name == 'nt':
                os.system('notepad ecryptedText.txt&amp;')
            elif os.name == 'posix':
                os.system('gedit decryptedText.txt&amp;')
            os.system('gedit encryptedText.txt&amp;')
        else:
            message=wx.MessageDialog(None, 'Please enter text for encryption/decryption','No Text Found',wx.OK|wx.ICON_INFORMATION)
            message.ShowModal()
            message.Destroy()
if __name__=='__main__':
    encryptionToolv2=wx.PySimpleApp()
    frame=mainForm(parent=None,id=-1)
    frame.Show()
    encryptionToolv2.MainLoop()
#usrInput=raw_input('Please enter your text.\n&gt; ')
#eOrD=raw_input('Do you want to encrypt or decrypt? (e or d)\n&gt; ')
#if eOrD=='e' or eOrD=='E':
#    encryption()
#elif eOrD=='d' or eOrD=='D':
#    decryption()
</code></pre>
