Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

printing output with command

how to print output with command in python. i am getting output in python but not getting idea to print that output in text file.
how to compare that output file with user defined text file????? help me please 😭
I'm not quite sure what your question is

To print to console
Code
print("Hello world")

To print to file:
https://docs.python.org/3/tutorial/input...ting-files
Code
file_name = "test.txt"
with open(file_name, "w") as f:
    f.write("Hello world!")

To compare files the simplest way is:
Code
user_file = input("Please enter a file name: ")
with open(user_file, "r") as f:
    f1_data = f.read()
with open("test.txt", "r") as f:
    f2_data = f.read()
if(f1_data == f2_data):
    print("File contents is equal")
else:
    print("Files do not match")
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Will PattersonSep 25, 2021 10:42 PM 4 168 Sep 25, 2021 10:42 PM
Last Post: Able.
[Java] by severosJun 5, 2021 06:30 PM 4 350 Jun 5, 2021 06:30 PM
Last Post: GenericSkid
[Python] by HardStoNJul 14, 2020 08:10 AM 5 319 Jul 14, 2020 08:10 AM
Last Post: Anxuein