Home / Companies / Pybites / Blog / December 2016

December 2016 Summaries

13 posts from Pybites

Filter
Month: Year:
Post Summaries Back to Blog
Python 3.6 introduces several new features and improvements, making it a significant release for developers. Notable enhancements include the introduction of f-strings for more concise string formatting, improved readability of large numbers using underscores, and expanded type hinting capabilities, allowing documentation of variable intent. The release also stabilizes the asyncio module, providing a consistent API for asynchronous programming. Additionally, there's a new dictionary implementation that reduces memory usage, though its order-preserving nature is considered an implementation detail. The secrets module is introduced to securely generate cryptographically strong pseudo-random values, emphasizing that the random module is unsuitable for security purposes. The pyvenv script is deprecated in favor of python3 -m venv for virtual environments. With Python 2.x no longer actively developed, transitioning to Python 3.x is advisable to benefit from these updates.
Dec 31, 2016 581 words in the original blog post.
Python's reliance on indentation is a fundamental aspect of the language that differentiates it from others, which typically use curly braces to define code blocks. This feature, while contributing to Python's elegance and simplicity, can also lead to errors if not handled with care, as inconsistent indentation can cause the code to malfunction. Proper indentation involves using four spaces per indentation level, as recommended by the official Python Style Guide, rather than tabs, to ensure consistency and readability. For those using Vim, configuring the editor to automatically adhere to Python's indentation standards can help mitigate common pitfalls. Despite its potential complexity, mastering indentation in Python is crucial for writing clean, error-free code, and adhering to best practices can prevent common errors and facilitate collaboration.
Dec 30, 2016 869 words in the original blog post.
A Python enthusiast describes how they adapted a Twitter bot script to automatically tweet new blog posts and updates from selected Python-related RSS feeds. The project involves obtaining necessary Twitter API credentials, selecting feeds to follow, and using Python libraries such as feedparser and tweepy to parse and post relevant content to Twitter. The script, developed in a virtual environment, comprises 67 lines of code and is designed for daily deployment via a cronjob. The author highlights the efficiency of using PyPI packages to streamline the development process and mentions plans to incorporate testing with pytest.
Dec 29, 2016 665 words in the original blog post.
Mike Pirnat's ebook, "How to Make Mistakes in Python," offers a collection of useful tips to help Python programmers improve their coding practices. It emphasizes the importance of using virtual environments like virtualenv or pyvenv to isolate projects, and suggests using IPython or Jupyter Notebooks instead of the default REPL for efficiency. The guide advises adhering to PEP 8, Python's style guide, and highlights the significance of meaningful variable names and avoiding overly complex constructs such as excessive nesting in lambdas, list comprehensions, and decorators. It recommends replacing long if/elif blocks with classes or dictionaries and using Enums, and suggests using properties instead of extensive getters and setters. The book also warns against the global scope, encourages explicit imports, and advises against using mutable default argument values in functions. It stresses the importance of testing, recommends using frameworks like pytest, and underscores the utility of logging. Pirnat's insights are shared in a concise 80-page ebook, celebrating the ethos of "Keep Calm and Code in Python."
Dec 28, 2016 378 words in the original blog post.
Julian shares his enthusiasm for the book "Automate the Boring Stuff" by Al Sweigart, which he found engaging and effective in teaching Python through practical projects like web scrapers and image resizing scripts. The book starts with basic programming concepts and quickly advances to more complex topics, complemented by exercises and challenges, making it a memorable learning resource. Despite some differences in variable naming conventions compared to current Python standards, Julian highly recommends the book for both beginners and experienced programmers, emphasizing its practical utility and Al's relatable teaching style. The book is available for free online, making it accessible to a broad audience interested in automating everyday tasks with Python.
Dec 26, 2016 589 words in the original blog post.
The author explores methods to efficiently organize Kindle highlights, initially attempting to parse the Kindle's My Clippings.txt file but finding it cumbersome due to limited success with existing PyPi modules. They discover a more efficient solution using Amazon's Kindle cloud for books purchased via Amazon, which allows for filtering and exporting highlights using the Bookcision JS bookmarklet. This bookmarklet, when used in Chrome, enables downloading highlights in JSON format, which the author then converts into a static HTML page using a custom Python script. The script involves converting JSON data into HTML by substituting template strings with values from a JSON dictionary, employing Python's generator feature for memory efficiency. The author details the process of batch processing JSON files to create HTML files for easy blog integration, emphasizing the elegance of using generators despite not needing their memory efficiency in this context.
Dec 26, 2016 409 words in the original blog post.
The text provides a detailed guide on packaging and distributing Python scripts as executable zip files, a process made easier with the introduction of the zipapp module in Python version 3.5. The author demonstrates this method using a script that generates a weekly digest from a Pelican blog, showcasing step-by-step instructions for cloning the relevant code, managing dependencies, and modifying the script to utilize locally installed packages. The process involves creating a zip file containing the script and its dependencies, which can then be executed without requiring users to install additional packages. Although this packaging approach may not be suitable for larger projects due to limited debugging capabilities, it offers a convenient way to share smaller scripts without needing consumers to perform any pre-setup or dependency management.
Dec 25, 2016 492 words in the original blog post.
A blog post discusses the process of creating an RSS feed for a blog built with Pelican and details the use of Python tools to automate a weekly email digest of blog posts. By adding a specific line to the pelicanconf.py file, an RSS feed is generated, and a Python script with the help of the PyPI feedparser library is used to parse the feed into a usable data structure. The script processes articles from the feed, incorporating timestamp calculations to filter entries from the past week. The blog post also outlines how to set up a cron job to send out the weekly digest via email using sendmail, with options for both HTML and plain text formats, and includes instructions for ensuring Python is set up correctly on shared hosting environments. Finally, it encourages readers to subscribe to the blog or join a Facebook group to receive these updates.
Dec 24, 2016 286 words in the original blog post.
A Python virtual environment, or virtualenv, is a sandboxed, independent Python instance that allows developers to isolate their coding projects from the main system environment, preventing clutter and conflicts with installed modules. By creating and activating a virtualenv within a project, programmers can work with a clean slate, installing only the necessary modules specific to that project without affecting the primary Python environment. The process involves creating a virtualenv using a simple command and activating it, which is indicated by the environment's name appearing in the shell prompt. While Python 3 comes with virtualenvs by default, Python 2.7 requires manual installation through pip. Once activated, users can install and manage modules within the virtualenv, ensuring all changes remain contained and do not impact the main environment. Exiting the virtualenv is straightforward, and all modifications are preserved within the virtualenv itself, making it a useful tool for developers to experiment and develop code without risking their primary setup.
Dec 22, 2016 435 words in the original blog post.
The text provides an overview of various Python-related projects and learning experiences, ranging from writing more Pythonic code to developing simple applications. It highlights practical exercises, such as a code kata for web scraping with collections.Counter, and shares the author's journey of creating a Twitter bot for fun. The text also mentions the author's initiation into Flask development through an existing project and their exploration of data analysis using Pandas and matplotlib, particularly focusing on Brexit data. It notes the recognition of a Spanish-translated article on Pybonacci and emphasizes the author's learning journey through influential books such as "Fluent Python," "Powerful Python," "Mastering Python," and "The Hitchhiker’s Guide to Python."
Dec 22, 2016 138 words in the original blog post.
The text discusses the process of setting up and managing a Pelican-based blog for PyBites, highlighting that Pelican now supports having a single repository for both source files and generated HTML, eliminating the need for separate repositories. It outlines the steps for cloning the repository, setting up the environment, and installing dependencies, as well as creating and pushing new blog content. The text also mentions the challenges of having two repositories in the past and the decision to manually push changes due to conflicts and unnecessary work when automating the process. Additionally, it briefly touches on using git hooks to streamline the workflow.
Dec 20, 2016 275 words in the original blog post.
Deques, as outlined in the Python standard library documentation, offer efficient, thread-safe operations for appending and popping elements from either end with O(1) complexity, making them more efficient than lists, especially for operations involving both ends. The text explores an example of rotating letters in a string, initially approached with a custom function using lists, but later optimized using the native rotate method of a deque, highlighting that deques also allow rotation to the left or right with a simple method call. The author emphasizes the importance of exploring standard library documentation and asking questions to enhance one's programming skills, noting that even casual exploration can lead to discovering more efficient methods and practices, such as the faster lookup times in sets or dictionaries compared to lists.
Dec 20, 2016 360 words in the original blog post.
The PyBites blog, created by Julian and Bob, is a platform dedicated to sharing their journey and experiences with Python programming. Readers can explore how the blog originated and find contact information for the founders. The blog encourages a calm and enjoyable approach to coding in Python.
Dec 19, 2016 33 words in the original blog post.