Every day we face many programming challenges that require advanced coding. You can’t solve these problems with simple basic Python syntax. In this article, I will share 13 advanced Python scripts that can become easy-to-use tools in your project. If you don’t currently use these scripts, you can add them to your favorites for retention.
This script will help you automate websites using Python. You can build a web robot that can control any website. Check out the code below. This script is very convenient in web crawling and web automation.
1 2 3 4 5 6 7 8 9 10 11
# pip install selenium import time from selenium import webdriver from selenium.webdriver.common.keys import Keysbot = webdriver.Chrome("chromedriver.exe") bot.get('http://www.google.com') search = bot.find_element_by_name('q') search.send_keys("@codedev101") search.send_keys(Keys.RETURN) time.sleep(5) bot.quit()
Enhance your photos with the Python Pillow library to make them look better. In the code below, I’ve implemented four ways to enhance any photo.
1 2 3 4 5 6 7 8 9 10 11
# pip install pillow from PIL import Image,ImageFilter from PIL import ImageEnhance im = Image.open('img.jpg') # Choose your filter # add Hastag at start if you don't want to any filter below en = ImageEnhance.Color(im) en = ImageEnhance.Contrast(im) en = ImageEnhance.Brightness(im) en = ImageEnhance.Sharpness(im)# result en.enhance(1.5).show("enhanced")
This advanced script will show you how to get lyrics from any song. First, you must get a free API key from the Lyricsgenius website, and then, you must follow the following code. This advanced script will show you how to get lyrics from any song. First, you must get a free API key from the Lyricsgenius website, and then, you must follow the following code.
1 2 3 4 5 6 7 8
# pip install lyricsgenius import lyricsgenius api_key = "xxxxxxxxxxxxxxxxxxxxx" genius = lyricsgenius.Genius(api_key) artist = genius.search_artist("Pop Smoke", max_songs=5,sort="title") song = artist.song("100k On a Coupe") print(song.lyrics)
Use the Python Pillow module to get the Exif data of any photo. Check out the code mentioned below. I provide two methods to extract the Exif data of photos.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Get Exif of Photo # Method 1 # pip install pillow import PIL.Image import PIL.ExifTags img = PIL.Image.open("Img.jpg") exif_data = { PIL.ExifTags.TAGS[i]: j for i, j in img._getexif().items() if i in PIL.ExifTags.TAGS } print(exif_data) # Method 2 # pip install ExifRead import exifread filename = open(path_name, 'rb') tags = exifread.process_file(filename) print(tags)
You can use Python to check if the website is running normally. Check the following code, it displays 200, which means the website is launched. If it displays 404, it means the website is closed.
OCR is a method of recognizing text from numbers and scanned docs. Many developers use it to read handwritten data, and the following Python code can convert scanned images to OCR text format.
Note: You must download tesseract.exe from Github .
1 2 3 4 5 6 7
# pip install pytesseract import pytesseract from PIL import Image pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' t=Image.open("img.png") text = pytesseract.image_to_string(t, config='') print(text)
Use the following code to convert all Pdf pages into images.
1 2 3 4 5 6 7
# PDF to Images import fitz pdf = 'sample_pdf.pdf' doc = fitz.open(pdf) for page in doc: pix = page.getPixmap(alpha=False) pix.writePNG('page-%i.png' % page.number)
# March 2024 Programming Language Ranking, the gap between Python and other languages has never been so big!
TIOBE’s March 2024 programming language rankings have been released, and the official title is: The gap between Python and the rest has never been that large.
The TIOBE index showed a relatively calm trend in February, but there were also some notable changes. According to TIOBE CEO Paul Jansen, the most noteworthy is that Python currently leads other language vendors by 4.5%, while Scratch returns to the top ten.
Meanwhile, Rust continues its upward trend.
Python, as a high-level programming language, has a wide range of applications and diverse advantages in today’s software development and data science fields.
Advantages of Python:
Easy to learn: Python syntax is concise and clear, similar to natural language, making it easy to learn and understand. This makes Python the preferred language for beginners, non-computer professionals, and education professionals.
Diverse Application Areas: Python can be used in various fields, including web development, data science, artificial intelligence, Machine Learning, scientific computing, natural language processing, network programming, etc. Its flexibility and versatility make Python a versatile programming language.
Python has a large and active community and ecosystem, supported by rich third-party libraries and tools such as NumPy, Pandas, TensorFlow, PyTorch, etc. These libraries can greatly simplify the development process and improve efficiency.
** Cross-platform: ** Python is a cross-platform language that can run on a variety of operating systems, including Windows, Linux, macOS, etc., which makes it easy for developers to deploy their applications in different environments.
Rapid development: Python has the characteristics of rapid development and iteration. By using features such as dynamic typing and automatic memory management, prototypes can be quickly built and iterative development can be carried out.
** Community support and rich documentation: ** Python has a large developer community with rich documentation, tutorials, and Q & A websites, such as Python official documentation, Stack Overflow, etc. Developers can easily obtain the help and resources they need.
** Extensive tool support: ** Python not only supports a variety of Integrated Development Environments (IDEs), such as PyCharm, Jupyter Notebook, etc., but also supports a variety of text editors, such as Sublime Text, VS Code, etc. Developers can choose the appropriate tool according to their preferences for development.
In terms of application scope, Python is almost ubiquitous.
Web Development: Python excels in building web applications through frameworks such as Django and Flask.
Data science and artificial intelligence: Python has a wide range of applications in the fields of Data Analysis, data lake visualization, Machine Learning, and artificial intelligence. Libraries such as Pandas, NumPy, Scikit-learn, and Matplotlib support the development of these fields.
** Scientific Computing: ** Python is also widely used in the fields of scientific computing and engineering. Libraries such as SciPy and SymPy provide rich scientific computing functions.
Python has strong capabilities in processing text data and natural language processing. Libraries such as NLTK and spaCy provide developers with rich tools and algorithms.
Historical rankings of major programming languages (1988–2024):
Programming Language “Celebrity List” (2003–2023):
TIOBE publishes a monthly ranking of programming languages based on the number of global technical engineers, courses, and third-party suppliers, including popular search engines and technical communities such as Google, Baidu, Wikipedia, Lingo, etc.
The data reflects the changing trend of mainstream programming languages, which can serve as a reference for our learning and work. However, each language has its own suitable application scenarios, so there is no need to pay too much attention to it. After all, the quality of a language depends on how it is used.
The following video shows the changing trends of programming languages in recent decades.
My personal official account often shares articles related to programming, as well as some side projects that I have already operated and can actually get started with. Welcome to follow!
A graphical User Interface (commonly referred to as a GUI) is the interactive environment that users encounter when opening an application or website. As an interactive visual component system of computer software, a graphical User Interface displays objects that convey information and represent user actions. These objects can dynamically change properties such as color, size, or visibility based on user interaction behavior. Icons, cursors, buttons, and other graphical elements (usually enhanced by visual effects such as sound or transparency) contribute to the entire graphical User Interface.
The quality of the graphical User Interface has a significant impact on the reputation and user base of the platform. The combination of these interactive elements plays a crucial role in shaping the User Experience of an application or website.
PyQt5 is developed by Riverbank Computing and is a popular Python framework for graphical User Interface (GUI). The framework is based on the Qt framework, which is a universal cross-platform tool widely used to create applications for various platforms.
PyQt5 has full cross-platform compatibility, allowing developers to seamlessly build applications on Mac, Windows, Linux, iOS and Android. The addition of QtGUI and QtDesigner modules makes it easy for users to integrate visual elements through a friendly drag-and-drop interface. In addition, developers can choose to manually code these elements, making it flexible to develop applications of all sizes, from small to large.
Tkinter is a well-known Python library for creating graphical User Interfaces (GUIs). This open-source library is known for its simplicity and is easily pre-installed in Python without additional installation work. Its user-friendliness makes it an excellent choice for beginners and intermediate programmers. However, it is worth noting that Tkinter may not be suitable for handling large projects. In plain language, it is okay to practice, but if you really want to do something, forget it.
In Tkinter, visual components are called widgets, and each component provides varying degrees of customization. The library provides various commonly used elements that developers may already be familiar with, including frameworks, buttons, check buttons, labels, file dialog boxes, and canvas.
Tkinter is already included in most Python installers, so it usually doesn’t need to be installed separately.
WxPython is another well-known Python library for GUI development, which provides Python developers with the ability to seamlessly build native User Interfaces without adding any additional overhead to the application. Similar to other libraries and frameworks, wxPython is compatible with various platforms, including Mac OS, Windows, Linux, and Unix-based systems.
One of the main features of wxPython is its extensive collection of small tools, which is a major advantage. In addition, the appearance of wxPython is attractive on all platforms and does not require a lot of custom modifications. However, it should be noted that compared with other frameworks such as Tkinter, the learning curve of wxPython is relatively steep.
PySimpleGUI was launched in 2018 and is designed to simplify GUI development for Python beginners. Many alternative frameworks involve more complex programs, but PySimpleGUI allows users to immediately get involved without having to deal with complex details related to other libraries.
PySimpleGUI utilizes four low-level graphical User Interface frameworks: Qt, Tkinter, wxPython, and Remi. By abstracting most of the low-level code, it greatly reduces the complexity of user usage. This method allows beginners to choose their favorite graphical User Interface framework and effortlessly access relevant visual elements, enabling them to easily create intuitive User Interfaces.
You can install PySimpleGUI using the pip command.
Libavg is a graphical User Interface framework that uses Python as a scripting language. Hardware accelerated with OpenGL and GPU shaders, it is one of the top libraries for User Interfaces tailored for modern touch devices. This Python library has various features, including camera support, animation capabilities, text alignment, GPU effects, and more. Its advanced screen layout engine includes techniques for rotating, scaling, Blend Mode, cropping, and various other operations on visual elements. Libavg is written in C++ and executes extremely quickly, thereby improving overall performance.
Libavg requires additional dependencies and build steps. For installation instructions, please refer to the official documentation, which will not be explained in detail here.
PyForms GUI framework is Python’s interpretation of Windows Forms, providing developers with the ability to design highly interactive interfaces in Windows GUI mode, web mode, and end point mode. This open-source cross-platform library simplifies the process of developing applications for various platforms with minimal code modifications. In addition, PyForms also integrates popular graphical center library instances such as PyQT and OpenGL.
The PyForms structure is divided into three different parts: PyForms-GUI, PyForms-Web, and PyForms-end point. Each layer is helpful for executing PyForms applications in Windows, Web, or end point environments.
Kivy is an acceleration framework supported by OpenGL ES 2, designed for creating innovative User Interfaces. It supports multiple platforms and is suitable for Windows, Mac, Linux, Android, and iOS. The toolkit of this open-source library includes more than 20 small tools and is a comprehensive resource library. Developed using a combination of Python and Cython, Kivy excels in creating intuitive User Interfaces, especially multi-touch applications. It helps to achieve natural User Interfaces (NUI), allowing users to effortlessly master various interactions that are usually hidden.
Kivy enables interface designers to code and deploy across platforms, and its built-in support for OpenGL ES 2 ensures the integration of modern graphics and technology.
PySide2, also known as QT for Python, is a well-known Python GUI library that provides official Python bindings for Qt. These bindings allow integration of Qt’s APIs into Python applications, while the binding generator tool facilitates C++ projects’ engagement with Python.
Qt is recognized as the gold standard for graphical User Interface design and the benchmark for evaluating other Python graphical User Interface frameworks. With PySide2, Python developers can use a powerful set of tools and libraries to quickly and flexibly create User Interfaces.
Wax is the wrapper of wxPython, which is the last part of our compile work. In addition to providing similar functionality to wxPython, Wax stands out with its particularly user-friendly User Interface. As an extension module of Python, Wax provides convenience for the development of cross-platform applications.
Wax is based on the efficient wxWindows platform, with the specific goal of simplifying GUI development for accessing Python elements and objects. This design choice ensures that Wax achieves commendable levels of efficiency and speed.
PyGUI is a simple and clear Application Programming Interface that enables developers to build User Interfaces with native elements for Python applications. This lightweight framework minimizes the code required between the application and the target platform, thereby improving overall efficiency.
PyGUI provides convenience for developing applications on various systems, including Windows machines, MacOS devices, and Unix-based systems. It is worth noting that the documentation for this library is written in Python, so there is no need to refer to other graphical User Interface libraries.
You can install PyGUI using the pip command.
1
pip install pygui
Python provides a rich library for developing graphical User Interfaces (GUIs), each with unique advantages and limitations. For beginners, Tkinter is known for its simplicity and user-friendly features, making it a great starting point. Meanwhile, PyQt5 and PySide2 offer advanced features and extensive customization options. Kivy provides convenience for cross-platform application development, while wxPython ensures a native look and feel on Windows, macOS, and Linux.
Python’s various graphical User Interface libraries provide developers with basic tools for designing visually appealing and interactive applications. Choosing the right library can simplify the development process and create high-quality software that meets user expectations.