Python Forum

Full Version: Python on Windows 2012RC2 (with VS Code 1.22.2). Scripts not generating output.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm a relative newbie to Python.
I'm running Python on a VM with Windows 2012 RC2 installed.
I have Python 3.6.5 -x64 (from installer called python-3.6.5-amd64)
I've installed SQLAlchemy 1.2.6.
I'm just trying to run a simple script called 'sqlachemyver.py' with this in it:
#!/usr/bin/env python3
import sqlalchemy
sqlalchemy.__version__ 
Per this link and this one regarding the shebang

If I type python, it calls up the interpreter.
I can copy/paste the code and it spews out '1.2.6'

But I should be able to type 'python sqlachemyver.py' from the folder that contains the python, or 'sqlalchemy.py'

However the '1.2.6' is not directed as output.
If I type python sqlachemyver.py > out.txt, I get an empty file.

I can't get scripts to generate output when I run directly from the cmd shell

I'm also getting odd results in Visual Studio Code too (v1.22.2) when I try and run it:
Output:
C:\opt\tidalconversion>cd c:\opt\tidalconversion && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\opt\python\3.6.5-x64\python.exe C:\Users\administrator\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\PythonTools\visualstudio_py_launcher.py c:\opt\tidalconversion 61892 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput c:\opt\tidalconversion\sqlalchemyver.py "
I followed the VS Code instructions here.

Any pointers greatly appreciated.
Thanks.

Found answer myself...
#!/usr/bin/env python
import sys
import sqlalchemy
sys.stdout.write(sqlalchemy.__version__)
Per here
(Apr-24-2018, 06:39 PM)JGFMK Wrote: [ -> ]
#!/usr/bin/env python3
import sqlalchemy
sqlalchemy.__version__

In an interactive session, the result of any expression is printed out for you, to make quickly typing easier. That's why you get output in the interactive prompt. Any other time, calling print("some value") is how you get output in the terminal.
Right, so the version would be returned, just not output without print or the stdout.write. Thanks.