Removing newline characters not working
Question: Im trying to remove the `\n` from a list created in a function. My code for
removing it doesnt seem to be working. Im not getting an error either??

**CODE**

    
    
    #!/usr/bin/python
    
    """
    Description:
    
    Basic Domain bruteforcer
    
    Usage:
      your_script.py (-f <file>) (-d <domain>) [-t 10] [-v]
      your_script.py -h | --help
    
    Arguments:
      -f --file File to read potential Sub-domains from. (Required)
      -d --domain Domain to bruteforce. (Required)
    Options:
      -h --help     Show this screen.
      -p --proxy    Proxy address and port. [default: http://127.0.0.1:8080] (Optional)
      -t --thread   Thread count. (Optional)
      -v --verbose  Turn debug on. (Optional)
    """
    from docopt import docopt
    
    
    def fread(dwords, *args):
            flist = open(dwords).readlines()
            #print current list
            print flist
            nlist = flist
            for i in nlist:
              i.rstrip('\n')
              return nlist
    
    if __name__ == "__main__":
            arguments = docopt(__doc__, version='0.1a')
            # print new list with removed \n
            print fread(arguments['--file'])
    


Answer: Strings are not mutable, `i.rstrip('\n')` _returns_ a new string.

Use a list comprehension:

    
    
    def fread(dwords):
        flist = open(dwords).readlines()
        return [s.rstrip('\n') for s in flist]
    

or, since you are reading the whole file into memory anyway,
`str.splitlines()`:

    
    
    def fread(dwords):
        return open(dwords).read().splitlines()
    

