You could use:
with open('data.txt', 'r') as file:
data = file.read().replace('\n', '')
Or if the file content is guaranteed to be one-line
with open('data.txt', 'r') as file:
data = file.read().rstrip()
More Related Contents:
- find all possible combinations of letters in a string in python [duplicate]
- How to understand regular expression with python?
- Unable to use convert strings into integers for a for loop
- How do I print curly-brace characters in a string while using .format?
- Remove specific characters from a string in Python
- How do I execute a string containing Python code in Python?
- How to un-escape a backslash-escaped string?
- How to check if type of a variable is string?
- Iterating each character in a string using Python
- Why are empty strings returned in split() results?
- Check if string ends with one of the strings from a list
- How to check if a string only contains letters?
- What is the max length of a Python string?
- str.startswith with a list of strings to test for
- How to split strings inside a list by whitespace characters
- Difference between using commas, concatenation, and string formatters in Python
- How can I extract keywords from a Python format string?
- Mutable strings in Python
- Python: find closest string (from a list) to another string
- Check presence of vowels in a string
- “TypeError: a bytes-like object is required, not ‘str'” when handling file content in Python 3
- Does R have function startswith or endswith like python? [closed]
- Remove Sub String by using Python
- How to get an expression between balanced parentheses
- How to Print “Pretty” String Output in Python
- How can I check if a string has a numeric value in it in Python? [duplicate]
- Python string operation, extract text between html tags
- get python dictionary from string containing key value pairs
- Mutable and Immutable Strings in python
- Detect whether a Python string is a number or a letter [duplicate]