Python Forum
Appending to a text string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Appending to a text string
#11
(May-03-2020, 09:44 AM)syno7878 Wrote: I tried your code and I got the following error message. I'm using Python 2.7:
Stop using Python 2.7 is not supported anymore,will not be maintained at all past 2020.
f-string that i use was new in Python 3.6 -->

For python 2 use .format
f = open("password.txt", "r")
s = f.read()
f_out = open("password2.txt", "wt")

for count in range(1900,2021):
    f_out.write('{}{}\n'.format(s, count))
f_out.close()
Output:
password1900 password1901 password1902 password1903 password1904 password1905 .....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split string into 160-character chunks while adding text to each part iambobbiekings 9 9,607 Jan-27-2021, 08:15 AM
Last Post: iambobbiekings
  Reading a text until matched string and print it as a single line cananb 1 2,023 Nov-29-2020, 01:38 PM
Last Post: DPaul
  Using an integer to manipulate a string/text variable rexyboy2121 1 1,748 Apr-22-2020, 01:37 AM
Last Post: michael1789
  Trying to extract Only the capitol letters from a string of text Jaethan 2 2,179 Feb-27-2020, 11:19 PM
Last Post: Marbelous
  program that search string in text file and do something alon30 1 3,252 Aug-04-2017, 08:10 AM
Last Post: buran
  How to find exact matching string from the text desul 5 4,106 Apr-17-2017, 04:31 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020