Removing the "&" from the command in python under Visual Studio

I’m trying to run my python script under Visual Studio and it gives an “&” sign in the command line, which I don’t understand as this prevented me from running the program. I’ll be grateful to know how I can resolve this error


Thanks in advance…

Appears to be a VSCode issue, relating to your workspace settings.

Your terminal is using PowerShell, which uses the & character to run a command with spaces in it (and the path to your Python contains spaces). The generated command looks correct. Are you sure that there is an issue with the script running? Does your script actually have any print statements or something else that would show it running?

Hello Chris,

I’ve attached the file and we’ll be grateful if you can run it to see what it generates. I provided results when I ran it some time ago, but it’s now providing this & message, which I can’t seem to resolve.

I apologize for any inconvenience caused, but I would appreciate any further suggestion to resolve the issue.

Thanks in advance.

Regards,

  1. Kayode Coker

(Attachment Design of Steam Ejector.py is missing)

E-mail attachments don’t work here. Paste your code directly on the forum page, using a code block (start with ```python and end with ```)

Hello Chris,

I’ve just run the code under cmd and it generated the results shown below. It seems that the problems lie with the Visual Studio.

Regards,

  1. Kayode Coker

{
… “Motive steam flow rate (kg/s)”: W_motive,
… “Nozzle throat area (m²)”: A_throat,
… “Motive steam exit velocity (m/s)”: V_exit,
… “Mixing chamber area (m²)”: A_mix,
… “Diffuser exit area (m²)”: A_exit_new,
… “Discharge pressure ¶”: P_discharge_new,
… “Discharge pressure (bar)”: P_discharge_new / 100000,
… }
{‘Motive steam flow rate (kg/s)’: 0.8333333333333334, ‘Nozzle throat area (m²)’: 0.32130584192439865, ‘Motive steam exit velocity (m/s)’: 684.1052550594828, ‘Mixing chamber area (m²)’: 0.0016622222222222225, ‘Diffuser exit area (m²)’: 0.027777777777777783, ‘Discharge pressure ¶’: 106069.51871657754, ‘Discharge pressure (bar)’: 1.0606951871657755}

Hello Moosemaimer,

I ran the script under cmd and it generated the results as shown below. It seems that the problems lie with VS environment creating &. I don’t know how to resolve this at the moment and the link you provided didn’t provide concrete advice to resolve the problem.

Regards,

A.Kayode Coker

{
… “Motive steam flow rate (kg/s)”: W_motive,
… “Nozzle throat area (m²)”: A_throat,
… “Motive steam exit velocity (m/s)”: V_exit,
… “Mixing chamber area (m²)”: A_mix,
… “Diffuser exit area (m²)”: A_exit_new,
… “Discharge pressure ¶”: P_discharge_new,
… “Discharge pressure (bar)”: P_discharge_new / 100000,
… }
{‘Motive steam flow rate (kg/s)’: 0.8333333333333334, ‘Nozzle throat area (m²)’: 0.32130584192439865, ‘Motive steam exit velocity (m/s)’: 684.1052550594828, ‘Mixing chamber area (m²)’: 0.0016622222222222225, ‘Diffuser exit area (m²)’: 0.027777777777777783, ‘Discharge pressure ¶’: 106069.51871657754, ‘Discharge pressure (bar)’: 1.0606951871657755}

That looks like VS Code and not Visual Studio (I know the names can be confusing). You can ask for help or file a bug at GitHub - microsoft/vscode-python: Python extension for Visual Studio Code .

Your snippet looks like a REPL session transcript, not running a script.

If you type something at a REPL, it is echoed back:

>>> {"a": 2 + 2}
{"a": 4}

But when running a .py script, it is not. You need to print() data you want to display.

Hello Chris,

The script only shows the print statements and previously had given results in Visual Studio. How can I get rid of the “&” sign as I can’t recollect installing PowerShell into Visual Studio, unless it’s installed with the Python software that I downloaded. This is preventing me from generating the results from the script, which is o.k. As it works under cmd environment. Alternatively, how can I remove PowerShell so that the script runs only in Visual Studio without generating the & sign, thus preventing it to run?

Regards,

  1. Kayode Coker

PowerShell is a part of Windows.

The & is not a problem. Your script never outputs anything. You need to print() things if you want to show them on the terminal from a script. This is different from when you type code in the interactive interpreter.