
You don't usually think of Microsoft and Python in the same sentence. But now, in Visual Studio 2017, you can develop applications in Python, making Visual Studio probably the best Python IDE around (at least on Windows). This isn't just for the Pro or Enterprise versions of Visual Studio; it includes the free Community edition. (There are license restrictions on the Community edition, of course, but individual developers can nonetheless use it to create free or paid applications. Organizations are expected to buy the Pro/Enterprise edition unless it's for academic research or contributing to open source.)
Is Python Installed?
Visual Studio is component-based, and gives you the choice of installing specific workloads and components. Typical Workloads include ASP.NET and web development, .NET desktop development, and, in this case, Python development. The default for the Python development workload is Python 3 64-bit, but in the VS 2017 Installer components tab, you can download Python 2 and either (or both) Python 2/ 3 in 32-bit. Other components installed by the Python development workload include Python language support and Python web support. There's also optional Python IoT support and Anaconda 2 or 3 (again in 32- or 64-bit); you just tick the relevant boxes to have it downloaded and installed. After you've done that, you’ll have a Python entry in the New Project screen, with choices of Web projects (Bottle, Flask, Jade and Django), normal Python and Iron Python, PyGame and Pyvot projects. You’ll also have some machine learning projects, including Classifier, Clustering and Regression.Debugging in Visual Studio
To be honest, debugging in Visual Studio is no different than debugging in C++, C#, and so on. You run the program with F5, press F10 to step over functions, and F11 to step into them. Just click in the left gutter to add a breakpoint, and execution will stop there. You have access to all local variables in a debug window; the intermediate window acts as a REPL. Type in the name of a variable to see its value, or a function to call it. Plus, there's no need to use the traceback module to view a stack trace; it's there for you anytime in the Call Stack window, and looks like this when it hits the breakpoint on the t = (t * n) line:> pi in Example1 line 13 Python inner in D:\devstuff\devstuff\dice.com\2018\August2018\VisualStudio-python\Python\Example1\Example1\ line 6 Python Timer.timeit in timeit line 176 Python timeit in timeit line 232 Python Example1 module line 19 PythonJust to test it, I timed this program to calculate the first 1,000 digits of Pi. It took just over a second to do it 100 times:
import decimal import timeit def pi(): decimal.getcontext().prec += 2 three = decimal.Decimal(3) lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24 while s != lasts: lasts = s n, na = n + na, na + 8 d, da = d + da, da + 32 t = (t * n) / d s += t decimal.getcontext().prec -= 2 return +s decimal.getcontext().prec = 1000 print(timeit.timeit(pi,number=10)) print(pi())In addition to the Intermediate Window, which only exists while stepping, there's also a full interactive REPL window that is closer to the standard python REPL. It's not displayed by default, but can be found on the View/Other Windows menu. You can specify that your applications run under it.