Apr-18-2019, 08:47 PM
Hello,
First post, but have spent hours online trying to get first usable program other than "Hello World" to work. All posted solutions found to have bugs on my setup - different Python versions(?).
Very simple for...next type algorithm with all "Basic" progs, VB, PowerBasic or batch file, but examples online don't work, so far. My first attempt to try out Python, due to all of the hoopla about its power etc.
Running Python 3.7.2 .py file from Win 10 "Desktop," I open a text file with several one line entries of credit card names. Some end with "VisaRen" indicating that I need to renew or update them.
I want an output text file of just those "Visa" flagged files. After a fairly exhaustive search, I found only one program that gives me 1 (one) result (one line of text) in an output file. I want all lines that match a search criterium.
Here is my attempt, admittedly copied from an online "expert's" example with double backslashes used instead of single backslashes as he recommended:
Any help appreciated. About to give up on Python!
First post, but have spent hours online trying to get first usable program other than "Hello World" to work. All posted solutions found to have bugs on my setup - different Python versions(?).
Very simple for...next type algorithm with all "Basic" progs, VB, PowerBasic or batch file, but examples online don't work, so far. My first attempt to try out Python, due to all of the hoopla about its power etc.
Running Python 3.7.2 .py file from Win 10 "Desktop," I open a text file with several one line entries of credit card names. Some end with "VisaRen" indicating that I need to renew or update them.
I want an output text file of just those "Visa" flagged files. After a fairly exhaustive search, I found only one program that gives me 1 (one) result (one line of text) in an output file. I want all lines that match a search criterium.
Here is my attempt, admittedly copied from an online "expert's" example with double backslashes used instead of single backslashes as he recommended:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
stringToMatch = 'VisaRen' matchedLine = '' #get line # NOTE to self - " and \\ used for Python 3.7 instead of ' and \ with open ( "C:\\Users\\John\Desktop\\StuffIn.txt" , "r" ) as file : for line in file : if stringToMatch in line: matchedLine = line break #and write it to the file with open ( "C:\\Users\\John\Desktop\\StuffOut.txt" , "w" ) as file : file .write(line) #Above was (matchedLine) # f = close() - ?? |