Feb-14-2023, 02:29 AM
Greetings!
I'm trying to shorten my code and I'd like to use OneLiners.
I Googled it and it is not that clear how to use it.
Here is the code I'm trying to write in a one-liner and it is not working.
Thank you!
I'm trying to shorten my code and I'd like to use OneLiners.
I Googled it and it is not that clear how to use it.
Here is the code I'm trying to write in a one-liner and it is not working.
w = open('c:/01/oneLiner.txt','w') with open('c:/01/mytext-2.txt','r') as f : for i in f : i=i.strip() if "PG" in i : print(i) w.write(f"{i}\n") w.close()OneLiner
w = open('c:/01/oneLiner.txt','w') with open('c:/01/mytext-2.txt','r') as f : w.write(f"{i}\n") i=i.strip() for i in f if "PG" in i w.close()Here is the error:
w.write(f"{i}\n") i=i.strip() for i in f if "PG" in i ^ SyntaxError: invalid syntaxAll help is appreciated!
Thank you!