Python 3: Store the contents of a file into one big string
Question: Suppose I have a textfile with this content:

> Hello World My name is Sam
>
> I am 12 years old and a boy
>
> I like Pizza

And I wanted to store it into one big string, no newlines, no spaces or
anything so it would read like this:

> HelloWorldMynameisSamIam12yearsoldandaboyIlikePizza

How would I do that? Google hasn't been much help.


Answer: You could use a regex, eg:

    
    
    import re
    
    with open('input') as fin:
        long_string = re.sub(r'\W', '', fin.read())
    # HelloWorldMynameisSamIam12yearsoldandaboyIlikePizza
    

Note that `\W` is equiv. to `[^a-zA-Z0-9_]` so you could change it to
`[^a-zA-Z0-9]` if you wanted to be explicit about anything that's a non ascii
letter/digit.

