2

I am able to download the file using wget and I can see the progress in the console, But how can we store this output into a python variable ?.

a sample code give below, I am excepting something like this.

output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf')
2

2 Answers 2

3

In general you can catch stdout of programs with subprocess

import subprocess

output = subprocess.check_output('ping localhost', stderr=subprocess.STDOUT, shell=True)
Sign up to request clarification or add additional context in comments.

1 Comment

@Arun That's an answer on the linked duplicate
1

I wouldn't recommend using wget, use urllib instead: https://docs.python.org/2/library/urllib.html.

If you must use wget just read the output file after wget writes it.

os.system('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf -O your_file_path')
print open('your_file_path').read()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.