You can run Python in PowerShell the same way as from the command bar.
Run PowerShell Command as Admin
First, you have to start PowerShell as Admin. To do it, just click the magnifying glass on the Windows Toolbar and enter “powershell”.
Next, right-click the icon and run it as administrator.
Run Python code
Now, when you have the PowerShell window open, you can start the Python interpreter by typing “python”.
Run Python Script
In the previous section, you saw a simple text message that was executed in the python interpreter, using PowerShell.
To leave the Python interpreter, press Ctrl + Z and then Enter.
Navigate to the directory where your script is located and use this command:
It will run the script that is inside the script.py file.
print('Hello world from the script!')
You can also run a script without changing the current dictionary, by specifying an absolute path to a file. You can use both forward-slash (/) and backslash (\).
Run Script with Arguments
When you run Excel scripts, you can pass arguments from the command line. Take a look at this code from the sum.py file:
print("Your sum is",a+b)
It takes two numbers from the command line (sys.argv and sys.argv) and sum them returning text and the addition result. sys.argv is the first argument of our entry, which is the name of a script (sum.py).
When we develop applications, the problem we often face is a string to datetime conversion. We have to deal with different formats and time zones. Sometimes we need to convert dates and times to human-readable format, and vice versa.