The output of a python script - python

So I am trying to debug some Python code that I am running, because for some reason when I run the code in a command line it works perfectly, but when I make it a .py file and run it that way it fails.
The output is in a Windows Commander window, and it disappears before I can read it.
Is there a way to see what this output is?

Open a windows commander, and then go to the dir where a.py is, run "python a.py", it will not disappear!

Related

Run "open" in elgato streamdeck without opening console

I'm trying to run a python script from an elgato streamdeck, the code works properly but everytime i run it through my streamdeck it breifly opens a CMD window.
my goal is to run the script "silently"
I already changed the .py to a .pyw, which should run it without a window opening, but the problem seems to come from the elgato app
Any thoughts on how i could do that ?
runing my python script from a .bat file seems to have fix the issue, thx OneCricketeer :)

How to display clear output in terminal (VScode Python)

When I’m executing a highlighted python code in VScode I see the output in terminal along with actual code. Is there a way to make the terminal display output only and not all lines of code associated with it?
No, because it executes the selected code in interactive mode.
In order to get clean output you need to write your code to a .py file and execute it.
You could creat a new .py file and put the code into this file.
For example, I have a .py file namde Helloworld.py and one line in it.
Then you could run this file by click "Run python file"
Here is the terminal shows:
If the above does not work, I think there may be a problem with your default terminal settings.

python `os.system("xdg-open test.pdf")` doesn't open file

I'm trying to run the xdg-open test.pdf command from within a python script, but nothing happens when I execute os.system("xdg-open test.pdf") even though it outputs code 0, and even though after executing os.system("ls") it does show the file test.pdf. I've also tried subprocess.run("xdg-open test.pdf", shell=True) and subprocess.call(["xdg-open", "test.pdf"]). On the other hand, if I run xdg-open test.pdf from the terminal (I'm on Ubuntu), it does open the pdf. What explains this problem and how can I fix it?

How do force or change my terminal to run python executable file in python 3 just by opening the file?

My terminal is running python 2 so when I run my python file the program fails.
So basically I am new to programming and trying to create a small python script to help me auto create folders. I also want to give the script to colleges so that they can use it on their systems too.
I know that I can run my file in terminal by using "python3 myfile.py" and it will work, but that's too much off a mission to do for my colleges and as my colleges are not familiar with code or terminal for that matter, I wanted to create an executable file so that they just click to open type a few answers to the promoted question and boom folders created.
This is where I run into a problem, I have "#!/usr/bin/env python3" at the top of my file but when I run the script IDLE opens up and it just shows the code I have written but doesn't seem to run the actual script I wrote. Am I doing something wrong?
I also then though perhaps I could just use the terminal to run the file as it is now executable, so I go into terminal and enter "myfile.py" and the program runs but in python 2 so my script fails as it is in python3. So another question would be is there a way to code into my python file, when running this file make sure you use python3? as I would want this to work on all colleges system without them having to write out anything in terminal?
Sorry for the long explanation but any advice would be greatly appreciated.
Thank you in advance
When you are on windows you can just create a .bat file where you write: python3 myfile.py in it.
Both files have to be in the same directory.
If you want to have a .exe you can also use py2exe.
You could also try just #!/usr/bin/python3 without env.
More here.

A python 3.5 script not printing results in windows command shell or powershell, only in the interpreter

I'm trying out some data science tutorials with python and can't get print to, well, print! when I run a .py in windows command shell or powershell. Print does work when I use the interpreter, but I have to type it in line by line (I'm not seeing how to run a .py as a file in the interpreter). I'm attaching snips of the file, and a snip of me running in the interpreter. I tried to attach snips of what happens when I run in command shell and powershell, but apparently I need at least 10 reputation points before I can post more than 2 links. Admittedly, those snips weren't interesting; there is no error and nothing printed. It just runs and returns to the prompt.
Also, as a test, I saved a .py file that simply does print ("Hello") and it does print correctly in windows command prompt and powershell.
Thanks in advance for any help!
Casie
PY script
Snip From Python Shell
Is that image from the IDLE console? To run the script you are editing, use menu Run > Run Module, or F5. Every python GUIs has an equivalent feature.
To run an arbitrary script from inside the commandline interpreter, say mywork.py: As long as it's in the working directory that you were in when you started the interpreter, you run it (once) by typing import mywork. (As you can see, its name must be a python identifier.)
Edit: You'd get to the bottom of this a lot quicker if you'd put print("Hello, world") in a script by itself and run it. From over here it looks like it would print just fine, proving there's nothing wrong with your python interpreter.
Your script has a bug, though: As soon as you enter the function random_kid(), you leave it again since you return a value on the first line. All those print statements are never executed. Why you think it works differently with %run I can't say, but for sure this function cannot print any output.

Categories

Resources