Last active
November 12, 2021 10:07
-
-
Save wsgzao/04d28ab11109c704880fe53dc8eeae52 to your computer and use it in GitHub Desktop.
read a text file into a string variable and strip newlines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Input: | |
192.168.0.1 | |
192.168.0.2 | |
192.168.0.3 | |
Output: | |
192.168.0.1,192.168.0.2,192.168.0.3, | |
''' | |
with open('list.txt', 'r') as file: | |
data = file.read().replace('\n', ',') | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment