Sunday, May 30, 2021

Python Pool: Know Everything About PythonWin IDE

PythonWin is the name of the IDE (Interactive Development Environment) for the Windows extension. It gets installed by default whenever you install Python for windows extension.

Thus, for all the python programs running on the Windows operating system, PythonWin acts as a graphical user interface for running the programs. In addition, it has several features in its environment, which makes debugging and editing python code an easier task.

What is an IDE?

IDE stands for Interactive Development Environment. Since PythonWin is an IDE, it is essential to know first what exactly is an IDE. An IDE is a single software that contains all the features for building applications.

The features contained inside an IDE are code editor, debugger, building tools, and compiler. By using an IDE, we don’t have to configure each tool separately. Thus, enabling us to develop applications at a faster rate.

Apart from PythonWin, python has different IDEs such as PyCharm, Visual Studio Code, Jupyter Notebook, Google Colab, Sublime Text, etc.

Installing PythonWin

To install PythonWin on a windows computer, you need to download ‘Python for Windows Extensions‘ from SourceForge.

The link for the download is : https://sourceforge.net/projects/pywin32/

The SourceForge page would appear something like this:

Downlon pythonwin

Click on the Download option and select the latest suitable version for your computer. First, you need to ensure that the PythonWin version is compatible with the version of the python software downloaded on your computer.

After that, the download will start right away.

After installing, a window will appear for the PythonWin setup. Click on Next.

pythonwin installation-1

Then, it will ask for the location of the directory in which the Python software is installed. If you have already installed it, it will find the location by default. Again click on Next.

pythonwin 2

The installation will start.

installing pythonwin third step

Now, click on Finish.

Finishing the installation of pythonwin

Now if you will search for PythonWin on the windows start menu, you can see that it has been installed on your local computer.

searching for the ide

Opening PythonWin

After installing the software, when you will open the PythonWin application, it would look something like this:

opening pythonwin

As you can see, the software’s toolbar and menu bar are visible on the top of the screen. The interactive window is where we will type the python commands and run them. The three arrows (>>>) here indicate the command prompt.

Executing a Code

We will try to execute running a print statement in PythonWin. We will print the statement “Programming in PythonWin“. For that, you have to type:

print(“Programming in PythonWin”) next to the ‘>>>’ symbol. The statement will be printed as the output.

pythonwin executing code

Creating a New script

To create a new script, go to the ‘File‘ option present in the toolbar. Then, click on the first option – ‘New‘ or you can press the control key + N.

A window will appear. Click on ‘Python Script‘ from the given options and select ‘OK.’

A new window titled ‘Script1‘ will appear as the new script.

pythonwin creating script

Let us try to run some code in this new script.

We will try to perform simple addition of two numbers. We will take two numbers ‘a’ and ‘b’ from the user and print their addition.

wring code

Now, to execute the code, we will have to first save the script. To save the script, click on File from the toolbar. Click on the ‘Save’ option or press the control key + S. A window pops up.

Give the script a name and click on the ‘Save‘ button. Here, we have given it the name ‘Script1‘ with the .py‘ extension.

Running the New Script

To run that script, click on the ‘Run‘ icon present on the top. A window named ‘Run Script‘ will appear.

The window will mention the location of the script file. It has two other fields: ‘ Arguments‘ and ‘Debugging.’ By default, the debugging field will be set to ‘No debugging.’ Click on ‘OK.’

Now, since the above code accepts input from the user, it will first ask for the user to Enter first number. Enter an input number and click on OK.

pythonwin running script

Then, enter the second number and click on OK.

pythonwin executing script

In the interactive window, the output will be printed. In this case, the output is

'Their summation is : 15'. 
pythonwin running script

To open a given file, you can either press ‘ctrl + O” or go to ‘File‘ and select ‘Open.’ Now, select the location of the script file from the window pop up and click on ‘Open‘. The script file will open.

Debugging with PythonWin

PythonWin is known for its debugging features which help in writing a code efficiently. Debugging refers to the process of finding and removing errors and bugs from a code.

PythonWin has several debugging tools which help in identifying and resolving errors. Debugging shall execute our code line by line for any error.

PythonWin has a check option that will find any syntax errors if present in the code. At the bottom of the window, it will list the syntax error along with the line in which it occurred.

For example, in the ‘Script1’ program, we will remove one parenthesis from the first input statement. Then, on using the check tool, it will display ‘Syntax Error‘ at the bottom of the window.

debugging in IDE
The error says 'Invalid Syntax'. 

In case of multiple errors, it will show one error at a time, line by line. After typing the missing parenthesis, the error will be resolved. At the bottom, it will show the message that it was successfully able to check the file.

Now, we will see the debugging tools available in PythonWin. From the ‘View‘ option in the toolbar, click on tools. There, check on the ‘Debugging‘ option.

pythhonwin debugging

You will see an entire toolbar containing debugging tools appears.

pythonwin Menu Bar

‘Watch’ tool: It helps in keeping track of the changes occurring in the variables.

‘Step’ tools: These three tools step through the list by debugging one line at a time.

‘Breakpoint’ tool: Used to set a breakpoint to fulfil a condition.

FAQ’s

What is ArcGIS in reference to PythonWin?

ArcGIS is a library in python containing a powerful set of tools for analysis and visualization. We can use the PythonWin IDE for ArcGIS.
To use PythonWin on ArcGIS, go to ArcGIS Pro Python’s command prompt. Type the ‘idle’ in the command prompt, and this would load the graphical user interface of the PythonWin idle.

What is the difference between PythonWin and IDLE?

PythonWin is an IDE. IDLE stands for Integrated development and learning environment.
PythonWin is a software development package containing tools such as Debugger, editor, compiler, and building tools.
At the same time, IDLE consists of basic packages and concepts of an IDE. The purpose of IDLE is for learning and education.


That sums up PythonWin. If you have any questions, let us know in the comments below.

Till then, Happy Learning!

The post Know Everything About PythonWin IDE appeared first on Python Pool.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...