jan
July 30, 2021, 4:50pm
1
Hello,
I am currently on Section 9-17 (Running External Programs) from the Python course. I copied the code exactly as Mosh had, but mine shows an error, and I cannot seem to figure out how to fix it, or what my problem is. Could anyone help? I have attached an image to show my code as well as my error.
(Also, I am on Windows, I don’t know if that makes a difference)
Thank you!
2 Likes
I think ls -l
is a Mac/Unix thing. It’s used to list all the files in the directory. Windows has some other command.
You can try doing something like subprocess.run(["echo", "test"])
and see if python still works fine?
2 Likes
jan
July 31, 2021, 12:40am
3
Hmm, it doesn’t seem to be working. I’m not sure if I am doing something wrong. This is what I get when I run it:
Thanks for the help
Huh it might be because “echo” isn’t a file.
You can try adding shell=True?
subprocess.run(["echo", "test"], shell=True)
1 Like
jan
July 31, 2021, 4:03am
5
I tried that, and now when I run it in both the output and the terminal, I get: test. This doesn’t seem to be what Mosh gets, however.
Yes that’s okay, at least we know Python is working fine.
The closest you can get to what he has is if you use
subprocess.run(["dir"], shell=True)
It won’t look exactly the same since he is using a mac.
4 Likes
jan
August 1, 2021, 3:22am
7
I see. Thank you so much for your help!
Adad
August 6, 2021, 7:44pm
8
I’m using Mac too, but sometimes Mosh’s code don’t work for me too on VSC. Try yourself a PyCharm Community.
1 Like