Python 3 Programming Tutorial - Subprocess module

preview_player
Показать описание


Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

Wow this saved my (brain) life! The best tutorial after countless hours of trying to understand subprocess. Even my paid online course couldn't have done a better job. Thank you so much! You have a new subscriber.

JV-jcci
Автор

I have recently started with Python and have been reading and watching videos. This is by far the best and easiest to understand explanation and I now understand it. Thank you!

alexp
Автор

Very helpful indeed. I've used this info to create 2 simple executable scripts on my Linux VPS. These scripts use sudo chown to change the owner of the 'wp-content' folder to 'www-data' in order to be able to update Worpress from the dashboard. Then I use the second script to change back the owner to my user name. Thanks for all your efforts Harrison, I very much enjoy this series and the one on Pandas.

lalu
Автор

Hi there, I'm not sure whether you're aware or not, but if you put: universal_newlines=True within subprocess.check_output(), or most of the other functions within subprocess, then instead of receiving a binary stream, it is interpreted with new lines, so that stdout will look just as pretty as in the shell.

jonathanbrooks
Автор

Great video. Gotta appreciate tutorials that show germane examples and explain in terms you can grasp.

jeffg
Автор

I like how you showed how to do both versions, great video man!

meltedcheese
Автор

a little advice: never use shell=True unless you really have to call the command through shell, and this video does not talk about exception handling such as zombie command running forever

kylewood
Автор

The subprocess call will be shown in pycharm and sublime tex how it should be. Maybe the IDE you mentioned was an exception ;)

Pterryreal
Автор

i just found the most underrated channel on youtube.

comicks
Автор

On the subprocess.check_output wouldn't you just decode the output?


output = subprocess.check_output('ls', shell=True)
print(output.decode("utf-8"))


This will turn it into a string that would print the \n characters as new lines, giving you clean output

chunchunmaru
Автор

You don't need replaces to fix the output @5:08(unless you meant using a regex to pull data out of the result which is different, you did say 'parse' but I'll comment anyways since it's some extra information for other people and info is _nearly_ always good right?).
ex:
output = b'Hello\r\n'
print(output) # gives b'hello\r\n' in 3.x, the expected 'hello'+newline in 2.x
print(output.decode('ascii')) # gives the desired 'hello'+newline in 3.x and 2.x
print(output.decode('utf-8')) # also gives the desired 'hello'+newline in 3.x and 2.x

@11:30 you mention you think 'r is for return and n for newline'. Actually 'r' is for carriage return (so, close) and 'n' is for 'line feed', which are old terms carried over from typewriters, a 'carriage return' would return the carriage (the part that held and moved the paper as you typed) back to the beginning of the line and a 'line feed' would advance ('feed') the paper one 'line' down. Thus you'd be at the start of a new line ready to continue typing.

FreeER
Автор

Around 10:00 when you are flailing a bit, I think you could have done \' to escape those single quotes.  Of course your final workaround was a better idea.

GonsalvoDeCordova
Автор

Please make a tutorial on pipes thanks!

zbzb-icsr
Автор

all your videos are awesome while I want to know about the piping so please upload the video on it and also changing windows directory using popen

kapil-pjld
Автор

Hey Harrison! I am looking for a good example code using sys and subprocess modules to communicate between python and non-python programs. I don't know any other programming language, but I feel like these two modules can open the door to other languages so I want to dig into examples and see how other programming languages allow to do that.
Where do good examples hide on the net? :)

fredyharter
Автор

the fix to where your using subprocess to call systut.py would probably be:
subprocess.call("python systut.py \"check this out\" ", shell=true)

alexcohen
Автор

If you already made a video-tutorial on PIPEs, please post a link here.

ashketchum
Автор

How can I use login credentials??? I'm trying connect to linux from Windows... pexpect doesn't work for windows... So I can use only Subprocess.. Pls show me example how can I use login credentials.. Thanks..

armanavetisyan
Автор

Can we terminate a process that is running in terminal using python, just quit the process and not totally killing the command prompt itself?

suryameda
Автор

Im using python 3.7.0 and "Check this out!" is not printing. It only shows me 0.

akeemlouigarde
welcome to shbcf.ru