Skip to content

Instantly share code, notes, and snippets.

@wsgzao
Last active November 12, 2021 10:07
Show Gist options
  • Save wsgzao/04d28ab11109c704880fe53dc8eeae52 to your computer and use it in GitHub Desktop.
Save wsgzao/04d28ab11109c704880fe53dc8eeae52 to your computer and use it in GitHub Desktop.
read a text file into a string variable and strip newlines
'''
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