简体   繁体   中英

Running a Python script from the command prompt isn't working correctly

In my Python course, we've been asked to output the results of our script to a text file before we submit. This is a simple task and is something I've been doing all semester. However, it doesn't seem to be working today.

Normally I would open a command prompt, CD to the directory with my script and then enter the following:

car_test.py > car_test.txt

Now when I do this, it's opening Visual Studio 2019 (which is what I'm using as my IDE for Python). I've gone back to other scripts that I have done this with previously and the same thing is happening with those. Oddly enough, it creates a text file, but it's blank. Again, this is happening with previously known working scripts as well.

Any thoughts on what might be going on here?

EDITED ANSWER:

It happened to me again today and I figured out what caused it. Instead of having the default program set to Python for.py files, it had somehow changed to Visual Studio 2019. Once I changed it back to Python, it is now working as I had described below and in the OP.

OLD ANSWER:

After posting this question I walked away to take a break. I can't explain why, but it's working now.

C:\Users%USERNAME%\source\repos\car_test\car_test>car_test.py > car_test.txt

Output file car_test.txt is showing the following: Car is accelerating: Current speed: 5 Current speed: 10 Current speed: 15 Current speed: 20 Current speed: 25

Car is braking: Current speed: 20 Current speed: 15 Current speed: 10 Current speed: 5 Current speed: 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM