AKTU B.
Tech Second Year
PYTHON PROGRAMMING
Unit 5
Python file operations
LEC-3
Today’s Target
PYTHON WITH IDE
AKTU PYQs
By
Pragya Rajvanshi
1
Syllabus
Python packages: Simple programs using the built-in functions of packages matplotlib,
numpy, pandas etc. GUI Programming: Tkinter introduction, Tkinter and
PythonProgramming, Tk Widgets, Tkinter examples. Python programming with IDE.
2
Python Features:
Python is a high-level,
Easy to Learn and Use: Simple syntax like plain English.
interpreted programming
Cross-Platform: Works on Windows, macOS, Linux, etc.
language known for its
Large Library: Ready-to-use tools for tasks like math, web, and
simplicity and readability
data.
You can use it to create
Dynamic Typing: No need to define variable types explicitly.
websites, analyze data,
Community Support: Lots of resources and help available
automate tasks, or build apps.
online.
It’s beginner-friendly and lets
you write code that’s easy to
read and understand.
3
How python is interpreted? The interpreter reads the code line by line.
Python is interpreted because its code is 3.Bytecode Conversion:
executed line by line by the Python interpreter. The interpreter translates your source code
Here's how it works: into an intermediate form called bytecode.
1.Source Code: Bytecode is a simplified version of your code
You write Python code in a file (e.g., that is easier for the computer to understand.
example.py). This bytecode is stored temporarily in memory
This is the human-readable version of your or as a .pyc file (if caching is enabled).
program. .
2.Python Interpreter:
When you run the code (e.g., using python
example.py), the Python interpreter starts
working. 4
4.Python Virtual Machine (PVM): Static analysis
The bytecode is executed by the Python It is the process of analyzing code without executing
Virtual Machine. it. It checks for bugs, errors, security vulnerabilities,
The PVM takes each instruction from and code quality issues by examining the source code
the bytecode and executes it on your or bytecode.
computer. Key Points:
5.Output: How it works: Tools analyze the code structure,
The interpreter runs the code step by syntax, and logic to detect potential problems.
step, producing results as it goes. Purpose: To catch errors early in the development
If there’s an error in your code, Python process before the code is run or tested.
stops and shows an error message. Examples: Finding unused variables, type
mismatches, or missing imports.
5
Tools that help to find bugs or Features of PyLint:
perform static analysis 1.Code Quality Checks:
PyLint is a popular Python Detects issues like unused variables, undefined variables,
tool for analyzing code to and unreachable code.
ensure it adheres to coding Ensures your code follows the Python style guide (PEP 8).
standards, finds errors, and 2.Coding Standards:
improves code quality. Highlights deviations from best practices.
It performs static code Enforces consistent naming conventions for variables,
analysis and provides classes, and methods.
suggestions for 3. Error Detection:
improvement. Finds common errors like missing imports, syntax issues, or
potential bugs.
6
Code Refactoring: PyChecker
Provides suggestions to It is a static analysis tool for Python that helps find bugs, errors,
refactor and simplify and inconsistencies in code.
code to make it cleaner It was one of the earlier tools for Python linting, though it is
and more readable. less commonly used today compared to tools like PyLint.
Custom Rules: Features:
Allows users to define 1.Bug Detection:
custom rules for Identifies syntax errors and logical mistakes in code.
analysis or disable Flags unused variables, modules, or imports.
specific checks as
2.Error Analysis:
needed.
Detects type mismatches and missing function arguments.
Highlights potential runtime errors.
7
3. Code Warnings: Python decorators
Issues warnings for
A decorator is a special type of function in Python that allows
deprecated Python features
you to modify or enhance the behavior of other functions or
or bad practices.
methods without changing their code.
4.Cross-Version Compatibility:
Decorators are often used to add functionality like logging,
Checks for compatibility
timing, or access control to functions.
issues across different
Python versions.
8
9
What is IDE? 1.Code Editor: A text editor with features like syntax highlighting,
An IDE (Integrated autocomplete, and code formatting.
Development Environment) 2.Debugger:Helps identify and fix errors in your code by running
is a software application it step by step.
that provides tools to help 3.Compiler/Interpreter: Converts your source code into
programmers write, debug, executable code (or interprets it for languages like Python).
and manage code efficiently. 4.Project Management: Allows you to organize files and folders
It integrates several features within a project.
into one interface, making 5.Integrated Tools: Includes tools for version control (e.g., Git),
the development process testing, and deployment.
easier and faster. .
10
SOME OF IDE Key features :
1. PyCharm 1.Code Editor:
It is a popular Integrated Smart code completion and suggestions.
Development Environment Syntax highlighting and formatting.
(IDE) specifically designed 2.Debugger:
for Python development. Powerful tools to identify and fix errors in Python code.
It is developed by JetBrains 3.Code Analysis:
and provides many features Highlights coding issues and suggests improvements.
to help developers write, 4.Project Management:
debug, and manage Python Helps organize files and dependencies in large projects.
projects efficiently. 5.Support for Web Development:
Includes frameworks like Django and Flask.
11
6.Testing Tools: 2. VS Code
Includes support for VS Code (Visual Studio Code) is a lightweight, powerful, and
running unit tests directly free code editor developed by Microsoft.
from the IDE. It is widely used for writing, debugging, and managing code
Why Use PyCharm? in multiple programming languages, including Python,
JavaScript, C++ etc.
Simplifies Python
Why Use VS Code?
development with smart tools.
Free: Fully free and open-source.
Boosts productivity with
Lightweight: Ideal for both small scripts and large projects.
features like code analysis and
Customizable: Extensions let you tailor it to your needs.
debugging.
Community: Huge user base with plenty of tutorials and
Ideal for both beginners and
resources.
experienced developers.
12
Key Features of VS Code: 3.Debugger:
1.Lightweight and Fast:
Debug code with breakpoints, variable inspection, and call
Designed to be minimalistic
stack analysis.
and run efficiently on most
4.Cross-Platform:
systems.
Available for Windows, macOS, and Linux.
2.Code Editor:
Syntax highlighting, 5.Customizable:
autocompletion, and Personalize the editor with themes, fonts, and keyboard
IntelliSense (smart code shortcuts.
suggestions) 6.Multi-Language Support:
Supports many languages (Python, Java, JavaScript, C#, etc.)
with extensions.
13
3.Eclipse Key Features of Eclipse:
It is a powerful, 1.Java-Focused:
open-source Integrated Built specifically for Java development with tools like
Development auto-completion, debugging, and refactoring.
Environment (IDE) 2.Project Management:
primarily used for Organize large projects easily with a structured interface.
developing Java 3.Integrated Debugger:
applications. Set breakpoints, inspect variables, and step through your code for
It is also versatile and debugging.
supports other 4.Cross-Platform:
programming languages. Available for Windows, macOS, and Linux.
5.Version Control:
Built-in support for Git and other version control systems.
14
4.Spyder Key features of spyder
Spyder (Scientific Python 1.Data Visualization:
Development Environment) Supports inline plotting using libraries like Matplotlib and
Seaborn.
is an open-source Integrated
2.Integrated Debugger:
Development Environment
Step through your code to debug and fix errors.
(IDE) specifically designed
3.Project Management:
for data science and
Organize multiple scripts and files in a structured manner.
scientific computing in
4.Code Analysis:
Python. Includes tools like Pylint to detect errors and enforce coding
It is widely used for tasks standards.
like data analysis, machine 5.Support for Scientific Libraries:
learning, and visualization. Seamless integration with NumPy, Pandas, SciPy, and Matplotlib.
15
Programming Cycle for python .
The development cycle of Python is
considerably shorter than that of
traditional tools.
There is no compilation or linking steps
in Python.
Python programs simply import
modules at runtime and use the objects
they contain. Because of this, Python
programs run immediately after
changes are made.
16
17
What is PEP 8? Why Follow PEP 8?
PEP 8 (Python Readability: Makes code easier to read and understand.
Enhancement Proposal Consistency: Helps teams maintain a uniform coding style.
8) is the official style Best Practices: Encourages efficient code.
guide for Python code.
Key Guidelines of PEP 8:
It provides guidelines
1.Indentation:
and best practices to
Use 4 spaces per indentation level.
help developers write
2. Line length
clean, readable, and
PEP 8 recommends limiting each line of code to a maximum of 79
consistent Python code.
characters and comments or docstrings to 72 characters.
18
Spaces Comments
Use spaces around Write meaningful comments to explain why something is done.
operators and after Use # and keep comments short and clear python.
commas. Functions
Don’t add spaces inside Keep your functions small and focused on one
parentheses or Name them clearly to show what they do.
brackets.
Imports
Put imports at the top
of the file.
Import one library per
line.
19
AKTU QUESTIONS
Q.1 What is python? How python is interpreted? What are the tools AKTU 2019-20
that help to find bugs or perform static analysis? What are AKTU 2020-21
python decorators? AKTU 2022-23
Q.2 Describe how to generate random number using numpy. write AKTU 2023-24
a python m program to create an array of 5 random number
integer between 10 and 50
Q.3 Explain the dataFrame in pandas. Write a python program to AKTU 2023-24
create an dataFrame from dictionary and print it
20