Feeds
Acquia Developer Portal Blog: Changing to Drupal and Maintaining Search Engine Rankings
So you’ve decided to change to Drupal, or maybe you are making a major upgrade from a really old version of Drupal to a more modern one and you are concerned about your SEO.
Changing content management systems will impact your search engine optimization (SEO), but with careful consideration and planning this can be a positive change rather than a negative one.
What is SEOThere are many misconceptions about search engine optimization, and part of that is because the industry has often been cast in a negative light. Really SEO is the process of making sure your website meets certain guidelines and standards so search engines can understand its content, relevance, and value to users.
GUAC adopts license metadata from ClearlyDefined
The software supply chain just gained some transparency thanks to an integration of the Open Source Initiative (OSI) project, ClearlyDefined, into GUAC (Graph for Understanding Artifact Composition), an OpenSSF project from the Linux Foundation. GUAC provides a comprehensive mapping of software packages, dependencies, vulnerabilities, attestations, and more, allowing organizations to achieve better compliance and security of their software supply chain.
GUAC offers the full view of the supply chainSoftware supply chain attacks are on the rise. Many tools are available to help generate software bills of materials (SBOMs), signed attestations and vulnerability reports, but they stop there, leaving users to figure out how they all fit together. GUAC provides an aggregated, queryable view across the whole software supply chain, not just one SBOM at a time.
GUAC is for developers, operations and security practitioners who need to identify and address problems in their software supply chain, including proactively managing dependencies and responding to vulnerabilities. GUAC provides supply chain observability with a graph view of the software supply chain and tools for performing queries to gain actionable insights.
GUAC enhanced with ClearlyDefined integrationThe latest version of GUAC (v0.8.0) now provides support for ClearlyDefined. GUAC will query the ClearlyDefined license metadata store to discover license information for packages, even when the SBOM does not include that information.
A ClearlyDefined certifier will listen on collector-subscriber for any pkg/src strings, then convert to ClearlyDefined coordinates, then query the API service for the definition. The user agent will be the same as existing outgoing GUAC requests GUAC/<version> (e.g. GUAC/v0.1.0).
A CertifyLegal node will be created using the “licensed” “declared” field from the definition. The expression will be copied and any license identifiers found will result in linked License noun nodes, created if needed. Type will be “declared”. Justification will be “Retrieved from ClearlyDefined”. Time will be the current time the information was retrieved from the API.
Similarly a node will be created using the “licensed” “facets” “core” “discovered” “expressions” field. Multiple expressions will be “AND”ed together. Type will be “discovered”, and other fields the same (Time, Justification, License links, etc).
The “licensed” “facets” “core” “attribution” “parties” array will be concatenated and stored in the Attribution field on CertifyLegal.
Optionally, “described” “sourceLocation” can be used to create a HasSourceAt GUAC node.
Thanks to the communityAlthough licenses don’t directly impact security, they are an important part of understanding the software supply chain. We would like to thank Parth Patel (Kusari), Jeff Mendoza (Kusari), Ben Cotton (Kusari), and Qing Tomlinson (SAP) for their support to get this feature implemented in GUAC. The ClearlyDefined community looks forward to working together with the GUAC community to help organizations worldwide to better achieve compliance and security of their software supply chain.
The Drop Times: Resurrected with Resilience: Dallas Ramsden's Drupal Legacy
Drupal Association blog: Preparing for Drupal 7 End of Life: Key Steps to Take Now
As the end-of-life (EOL) for Drupal 7 approaches on 5 January 2025, site owners must adequately prepare to guarantee their websites' continued security, functionality, and compliance. Here, we outline the key steps to navigate this transition smoothly.
1. Conduct a Comprehensive Site AuditA thorough site audit is the first step in preparing for Drupal 7's EOL. This process involves:
-
Inventorying Content and Modules: List all content types, modules, themes, and custom code currently in use.
-
Assessing Module Usage: Identify which modules are essential and which can be replaced or eliminated.
-
Checking for Unsupported Modules: Determine if any modules are already unsupported and look for alternative solutions.
-
Evaluating Performance: Analyze site performance to identify any bottlenecks or issues that need addressing during the migration.
With a clear understanding of your site's current state, the next step is to plan your migration strategy. Key considerations include:
-
Choosing the Right Drupal Version: While Drupal 11 is the latest version, you may need to evaluate if an interim upgrade to Drupal 10 is more feasible.
-
Timeline and Budget: Estimate the time and resources required for the migration. Consider factors such as the complexity of your site, the number of custom modules, and the need for design changes.
-
Engaging Stakeholders: Communicate the migration plan with all relevant stakeholders, including developers, content creators, and business leaders, to ensure alignment and support.
-
Extended Long-Term Support: If your migration plan has an unsupported gap, consider utilizing HeroDevs Drupal 7 Never-Ending Support, a secure drop-in replacement for Drupal 7. HeroDevs’ service provides security, compliance, and compatibility updates as you plan your migration. As additional partners join the program, options will be listed in the Migration Resource Center.
Migrating from Drupal 7 to a newer version is a complex task that often requires professional assistance. Selecting a certified migration partner who will provide the expertise and experience needed to ensure a successful transition. Look for partners who:
-
Have Proven Experience: Check for case studies or references from similar migration projects.
-
Offer Comprehensive Services: Ensure they can handle all aspects of the migration, from planning and execution to post-migration support.
-
Understand Your Industry: Partners familiar with your industry can provide more tailored solutions and insights.
Ensure your hosting environment is ready for the new Drupal version. This may involve:
-
Upgrading PHP and MySQL Versions: Verify that your hosting provider supports the PHP and MySQL versions required by your new version of Drupal
-
Evaluating Server Performance: Ensure your server infrastructure can handle the new site's requirements, especially if you expect increased traffic or enhanced functionality.
-
Considering a New Hosting Provider: If your current provider doesn't meet the requirements, consider migrating to a provider specializing in hosting Drupal sites.
Before starting the migration, create a full backup of your site. This ensures you have a fallback option in case anything goes wrong. Additionally, set up a testing environment to:
-
Run Migration Tests: Perform a dry run of the migration process to identify and resolve potential issues.
-
Validate Functionality: Test all aspects of the site, including custom modules and integrations, to ensure everything works as expected post-migration.
-
User Acceptance Testing (UAT): Engage end-users to test the site and provide feedback on any usability or functionality issues.
With all preparations in place, proceed with the migration. Follow a phased approach to minimize disruption:
-
Migrate in Stages: Consider migrating in stages, starting with less critical sections of the site to ensure a smooth transition.
-
Monitor Progress: Continuously monitor the migration process to quickly address any issues that arise.
-
Communicate Changes: Keep all stakeholders informed about the migration progress and any potential downtime or changes.
After the migration, there are a few additional steps to ensure long-term success:
-
Conduct a Final Site Audit: Verify that all content, modules, and functionality have been successfully migrated and are working correctly.
-
Optimize Performance: Implement performance optimizations to ensure the new site runs efficiently.
-
Plan for Ongoing Maintenance: Establish a plan for regular updates, backups, and security monitoring to keep the site secure and up-to-date.
Preparing for Drupal 7's end-of-life requires careful planning and execution. By conducting a comprehensive site audit, planning your migration strategy, selecting a certified migration partner, updating your hosting environment, and following through with testing and execution, you can ensure a smooth transition to a more modern, secure, and efficient version of Drupal. Taking these steps now will help future-proof your website and provide a solid foundation for continued success.
Real Python: Interacting With REST APIs and Python
There’s an amazing amount of data available on the Web. Many web services, like YouTube and GitHub, make their data accessible to third-party applications through an application programming interface (API). One of the most popular ways to build APIs is the REST architecture style. Python provides some great tools not only to get data from REST APIs but also to build your own Python REST APIs.
In this video course, you’ll learn:
- What REST architecture is
- How REST APIs provide access to web data
- How to consume data from REST APIs using the requests library
- What steps to take to build a REST API
- What some popular Python tools are for building REST APIs
[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
FSF Events: Free Software Directory meeting on IRC: Friday, August 9, starting at 12:00 EDT (16:00 UTC)
Django Weblog: Django security releases issued: 5.0.8 and 4.2.15
In accordance with our security release policy, the Django team is issuing releases for Django 5.0.8 and Django 4.2.15. These releases address the security issues detailed below. We encourage all users of Django to upgrade as soon as possible.
CVE-2024-41989: Memory exhaustion in django.utils.numberformat.floatformat()The floatformat template filter is subject to significant memory consumption when given a string representation of a number in scientific notation with a large exponent.
Thanks to Elias Myllymäki for the report.
This issue has severity "moderate" according to the Django security policy.
CVE-2024-41990: Potential denial-of-service in django.utils.html.urlize()The urlize() and urlizetrunc() template filters are subject to a potential denial-of-service attack via very large inputs with a specific sequence of characters.
Thanks to MProgrammer for the report.
This issue has severity "moderate" according to the Django security policy.
CVE-2024-41991: Potential denial-of-service vulnerability in django.utils.html.urlize() and AdminURLFieldWidgetThe urlize and urlizetrunc template filters, and the AdminURLFieldWidget widget, are subject to a potential denial-of-service attack via certain inputs with a very large number of Unicode characters.
Thanks to Seokchan Yoon for the report.
This issue has severity "moderate" according to the Django security policy.
CVE-2024-42005: Potential SQL injection in QuerySet.values() and values_list()QuerySet.values() and values_list() methods on models with a JSONField are subject to SQL injection in column aliases via a crafted JSON object key as a passed *arg.
Thanks to Eyal Gabay of EyalSec for the report.
This issue has severity "moderate" according to the Django security policy.
Affected supported versions- Django main branch
- Django 5.1 (currently at release candidate status)
- Django 5.0
- Django 4.2
Patches to resolve the issue have been applied to Django's main, 5.1, 5.0, and 4.2 branches. The patches may be obtained from the following changesets.
CVE-2024-41989: Memory exhaustion in django.utils.numberformat.floatformat()- On the main branch
- On the 5.1 branch
- On the 5.0 branch
- On the 4.2 branch
- On the main branch
- On the 5.1 branch
- On the 5.0 branch
- On the 4.2 branch
- On the main branch
- On the 5.1 branch
- On the 5.0 branch
- On the 4.2 branch
- On the main branch
- On the 5.1 branch
- On the 5.0 branch
- On the 4.2 branch
- Django 5.0.8 (download Django 5.0.8 | 5.0.8 checksums)
- Django 4.2.15 (download Django 4.2.15 | 4.2.15 checksums)
The PGP key ID used for this release is Sarah Boyce: 3955B19851EA96EF
General notes regarding security reportingAs always, we ask that potential security issues be reported via private email to security@djangoproject.com, and not via Django's Trac instance, nor via the Django Forum, nor via the django-developers list. Please see our security policies for further information.
Stefanie Molin: Common Pre-Commit Errors and How to Solve Them
Daniel Roy Greenfeld: TIL: Parsing messy datetimes strings
How to convert inconsistent datetime strings into datetime objects.
Recently I've been working on yet another rewrite of my blog, this time to FastHTML. Thanks to the power and ease of that framework, that took about 45 minutes to replicate all the web pages of my blog. Wahoo!
Alas, the atom/rss feeds took quite a bit longer.
For the atom/rss feeds I chose to use the venerable Feedgen library. The challenge there is that Feedgen is rightfully particular about the datetime objects it accepts. And over the years as this site has had 650 posts added the timestamps have become rather inconsistent in their format. On that issue I fully blame the author, who unfortunately is me.
In any case, I wrote a little Python function that handles it in a timezone aware way using the dateutils.parser() functon that I learned.
# Python stdlib from datetime import datetime from dateutils import parser # You'll need to install the pytz dependency import pytz def convert_dtstr_to_dt(date_str: str) -> datetime: """ Convert a naive or non-naive date/datetime string to a datetime object. Naive datetime strings are assumed to be in GMT (UTC) timezone. """ try: dt = parser.parse(date_str) if dt.tzinfo is None: # If the datetime object is naive, set it to GMT (UTC) dt = dt.replace(tzinfo=pytz.UTC) return dt except (ValueError, TypeError) as e: Raise Exception(f"Error parsing date string: {e}")Original source code here.
Note: As of publishing, this article is still on my old blog. The DNS switchover to the FastHTML version of my blog happens later this week.
Specbee: How to split configurations across different sites in Drupal 10
Akansha Tech Journal: Inside the Codebase: A Deep Dive into Drupal Rag Integration
Python Bytes: #395 pythont compatible packages
Akademy 2024 T-shirt online orders now open & in-person extended
Orders for the Akademy 2024 T-shirt for those attending online are now open till 29th September, these will be shipped after Akademy. For those attending in person the order deadline has been extended till Sunday 11th
Full details are on the Akademy 2024 T-shirt page
Mockup of Akademy 2024 T-shirt by Jens ReuterbergMike Driscoll: Create Amazing Progress Bars in Python with alive-progress
Have you ever needed a progress bar in your Python command-line application? One great way of creating a progress bar is to use the alive-progress package created by Rogério Sampaio de Almeida! Alive progress provides multiple different types of progress bars in your terminal or IPython REPL session. The alive progress package will work with any iterable, from lists to querysets, and more.
Let’s spend a little time learning how the alive-progress package works!
InstallationInstalling the alive-progress package is easy using the pip installer utility. Here is the command you should use in your terminal:
python -m pip install alive-progressPip will install the package and any dependencies it needs. The pip tool shouldn’t take very long to install alive-progress.
Example UsageThe alive-progress package comes with a great demo that you can use to see all the different types of progress bars that the package supports. Open up a Python REPL and run the following code:
from alive_progress.styles import showtime showtime()When you run this code, you will see something similar to the following:
There is another alive-progress demo that is a little different from the one above. You don’t need to use a Python REPL to run it though. Instead, you can open up your terminal application and run the following command:
python -m alive_progress.tools.demoWhen you run this command, you will see something like this:
https://www.blog.pythonlibrary.org/wp-content/uploads/2024/08/alive_demo.mp4The alive-progress GitHub page also shows several different code examples that demonstrate how to use alive-progress in your code. Here is one of the examples:
from alive_progress import alive_bar import time for x in 1000, 1500, 700, 0: with alive_bar(x) as bar: for i in range(1000): time.sleep(.005) bar()Here you loop over four different integer values and create a progress bar for each of them. Then you loop over a range of one thousand and the progress bars will run through to completion.
When you run this code in your terminal, you will see this output:
Check out the GitHub repository for more fun examples!
Wrapping UpThe alive-progress package is lots of fun. You can add progress bars to any of your regular Python scripts and see them visually in your applications. This can be especially useful for command-line utilities that you create as they will show the user how far along they are in processing the data.
Download the package and start tinkering today!
The post Create Amazing Progress Bars in Python with alive-progress appeared first on Mouse Vs Python.
KDE Plasma 6.1.4, Bugfix Release for August
Tuesday, 6 August 2024. Today KDE releases a bugfix update to KDE Plasma 6, versioned 6.1.4.
Plasma 6.1 was released in June 2024 with many feature refinements and new modules to complete the desktop experience.
This release adds three weeks' worth of new translations and fixes from KDE's contributors. The bugfixes are typically small but important and include:
- DrKonqi: Use frameworks version number from kcrash. Commit.
- KWin: Fix sticky keys for AltGr. Commit. See bug #444335
- [kcms/access] Set range for visual bell duration selector. Commit.
Trey Hunner: Quickly find the right datetime format code for your date
I often find myself with a string representing a date and time and the need to create a format string that will parse this string into a datetime object.
I decided to make a tool that solves this problem for me: https://pym.dev/strptime
Finding the code to parse a date format with strptimeHere’s how I’m now using this new tool.
I find a date string in a random spreadsheet or log file that I need to parse. For example, the string 30-Jun-2024 20:09, which I recently found in a spreadsheet.
I then paste the string into the tool and watch the format appear:
Then I click on the date format to copy-paste it. That’s it!
This tool works by cycling through a number of common formats. It also works for dates without a time, like Jul 1, 2024.
This input field works great when you’re in need of a code for the datetime class’s strptime method (which parses dates). But what if you need a code for strftime (for formatting dates)?
Finding the code to format a date with strftimeIf you don’t have a date but instead want to construct a date in a specific common format, scroll down the page a bit.
This page includes a table of common formats.
Click on the format to copy it. That’s it.
Playing with format codesWhat if you have a date format already but you’re not sure what it represents?
Paste it in the box!
For example if you’re wondering what the %B in %B %d, %Y means, paste it in to see what that represent with the current date and time:
Other featuresThere are a few other hidden features in this tool:
- After a date or date format is pasted, if it corresponds to one of the formats listed in the table of common formats, that row will be highlighted
- Hitting the Enter key anywhere on the page will select the input field
- Clicking on a date within the format table will fill that date into the input box
- The bottom of the page includes links to other useful datetime formatting/parsing tools as well as a link to the relevant Python documentation
What do you think of this tool?
Is this something you’d bookmark and use often? Is this missing a key feature that you would need for it to be valuable for your use?
Are there date and time formats you’d like to see that don’t seem to be supported yet?
Comment or email me to let me know!
Talking Drupal: Talking Drupal #462 - DrupalCon Singapore
Today we are talking about DrupalCon Singapore, What you can expect, and What’s next for Drupal in Asia with guest Mike Richardson & Surabhi Gokte. We’ll also cover Filefield Paths as our module of the week.
For show notes visit: www.talkingDrupal.com/462
Topics- When is Drupalcon Asia
- The last one was in 2016, what did it take to reprise
- How do you handle language barriers
- What are your roles in the organizing committee
- Steering committee and Drupal South
- What can attendees expect
- Any special programming
- What kind of diversity is expected from attendees
- Driving from Mumbai to Singapore is 110 hours
- Will Dries be there
- Can we expect future Drupalcon Asia's
- Planning and logistics regarding coffee
- Starshot
- DrupalCon Singapore
- Droptimes
- Drupal camp Pune
- Steering committee for Drupal South
- Linux Australia Council
- DrupalCon Singapore Sponsorship
- Email events@drupalasia.org
- Park Royal Collection Marina Bay
- Singapore Wiki
- Singapore Visa
Mike Richardson - Singapore DrupalCon richo_au Surabhi Gokte - surabhi-gokte
HostsNic Laflin - nLighteneddevelopment.com nicxvan John Picozzi - epam.com johnpicozzi Josh Miller - joshmiller
MOTW CorrespondentMartin Anderson-Clutz - mandclu.com mandclu
- Brief description:
- Have you ever wanted to use a variety of tokens to customize the directory and file names of your uploaded files? There’s a module for that.
- Module name/project name:
- Brief history
- How old: created in July 2008 by Stuart Clark (Deciphered), though recent releases are by Oleh Vehera (voleger) of Golems GABB
- Versions available: 7.x-1.2 and 8.x-1.0-beta7, the latter of which supports Drupal 9.3 or newer, and Drupal 10
- Maintainership
- Seeking co-maintainers
- Security Coverage
- Opted in, but no coverage in practice for Drupal 9 or 10
- Test coverage
- Number of open issues: 131 open issues, 50 of which are bugs against the current branch
- Usage stats:
- 34,609 sites almost 35,000 sites
- Module features and usage
- This module allows you to customize file names and paths by leveraging a variety of entity-based tokens
- It also integrates with the Pathauto module, giving you options to clean up the tokens for example by removing slashes, filtering out words or punctuation, and so on
- It can also work with the Transliteration module to convert unicode characters into US-ASCII
- Filefield Paths has options to rename and move existing files, and can retroactively rename files, effectively bulk updating and moving all your existing files
- It can also work with the Redirect module to automatically create redirects from the old path and filename to the new location, when renaming
- I’d also like to give a tip of the cap to Jim Birch of Kanopi for suggesting this module, when I was talking to a customer who was looking to achieve pretty much exactly what this module does
Drupal Association blog: How did we get to Ripple Makers? The Evolution of the Drupal Membership Program
The Drupal Association’s individual membership program has always played a crucial role in supporting the Drupal community and ensuring the ongoing success of the Drupal project. The program was initially set up as a transactional vehicle: aside from the badge and voting rights, members received access to discounts from Drupal services providers.
The individual membership program stayed on autopilot during the turmoil of the Covid pandemic as we made the difficult decision to cancel DrupalCon North America 2020. During this time, our members and other Drupal community supporters donated unprecedented unrestricted funds using the hashtag #DrupalCares.
I joined the Drupal Association about two years ago as the Development & Membership Manager. My role split my time between Drupal Certified partners and the individual membership program, however it was clear from the beginning that the individual membership program would need a lot more attention.
The membership program underwent significant transformation from 2019 through May 2023, overcoming challenges and celebrating successes along the way. Initially, we faced a decline in numbers, but through consistent effort and unprecedented generosity, we've made remarkable strides. Today, we proudly recognize 1,747 members, with 70% of them providing recurring support.
Ripple Makers: Celebrating Changemakers in our CommunityThe individual membership program rebranded as Ripple Makers in 2024. With this new name, the Drupal Association increases focus on communication, transparency, and engagement within the community. The ‘new’ program encourages sustaining donors to make monthly recurring gifts, which provide a reliable source of funding. This financial support allows the Drupal Association to plan for the future, support essential projects, and foster a dynamic and responsive community.
Membership Programs, Sustainable Giving, and NonprofitsWhy does a nonprofit organization such as the Drupal Association need a sustaining giving program? This program is vital for the sustainability and growth of the Drupal Association, and the benefit it brings to the community. It provides a stable foundation of support, ensuring that we can continue to innovate and grow. In addition, unrestricted giving in particular allows nonprofits to allocate resources where they are needed most, supporting the overall health of the Drupal project. Importantly. It also opens up direct lines of communication with the community.
Positive Impact on the Drupal CommunityThe Drupal community thrives because of several factors: open source collaboration, supportive environment, diverse participation, commitment to quality, and others. In my opinion, a supportive environment is the most important one.
By becoming a Ripple Maker, you directly support a vibrant and inclusive community of people who care for the Drupal project. Your contributions empower us to foster a sustainable ecosystem for Drupal by harnessing the collective generosity and commitment to the future of Drupal. Learn more about the program and join the wave on our sign up page.
Thank you for your ongoing support and dedication. Let's make the next chapter of our sustainable giving program the best one yet!
Real Python: Functional Programming in Python: When and How to Use It
Functional programming is a programming paradigm in which the primary method of computation is the evaluation of functions. But how does Python support functional programming?
In this tutorial, you’ll learn:
- What the functional programming paradigm entails
- What it means to say that functions are first-class citizens in Python
- How to define anonymous functions with the lambda keyword
- How to implement functional code using map(), filter(), and reduce()
Functional programming typically plays a minor role in Python code, but it’s still good to be familiar with it. You’ll probably encounter it from time to time when reading code written by others. And you may even find situations where it’s advantageous to use Python’s functional programming capabilities in your own code.
Get Your Code: Click here to download the free sample code that shows you when and how to use functional programming in Python.
What Is Functional Programming?A pure function is a function whose output value follows solely from its input values without any observable side effects. In functional programming, a program consists primarily of the evaluation of pure functions. Computation proceeds by nested or composed function calls without changes to state or mutable data.
The functional paradigm is popular because it offers several advantages over other programming paradigms. Functional code is:
- High level: You describe the result you want rather than explicitly specifying the steps required to get there. Single statements tend to be concise but pack a lot of punch.
- Transparent: The behavior of a pure function can be described by its inputs and outputs, without intermediary values. This eliminates the possibility of side effects and facilitates debugging.
- Parallelizable: Routines that don’t cause side effects can more easily run in parallel with one another.
Many programming languages support some degree of functional programming. In some languages, virtually all code follows the functional paradigm. Haskell is one such example. Python, by contrast, does support functional programming but contains features of other programming models as well.
While it’s true that an in-depth description of functional programming is somewhat complex, the goal here isn’t to present a rigorous definition but to show you what you can do by way of functional programming in Python.
How Well Does Python Support Functional Programming?To support functional programming, it’s beneficial if a function in a given programming language can do these two things:
- Take another function as an argument
- Return another function to its caller
Python plays nicely in both respects. Everything in Python is an object, and all objects in Python have more or less equal stature. Functions are no exception.
In Python, functions are first-class citizens. This means that functions have the same characteristics as values like strings and numbers. Anything you would expect to be able to do with a string or number, you can also do with a function.
For example, you can assign a function to a variable. You can then use that variable the same way you would use the function itself:
Python 1>>> def func(): 2... print("I am function func()!") 3... 4 5>>> func() 6I am function func()! 7 8>>> another_name = func 9>>> another_name() 10I am function func()! Copied!The assignment another_name = func on line 8 creates a new reference to func() named another_name. You can then call the function by either of the two names, func or another_name, as shown on lines 5 and 9.
You can display a function to the console with print(), include it as an element in a composite data object like a list, or even use it as a dictionary key:
Python >>> def func(): ... print("I am function func()!") ... >>> print("cat", func, 42) cat <function func at 0x7f81b4d29bf8> 42 >>> objects = ["cat", func, 42] >>> objects[1] <function func at 0x7f81b4d29bf8> >>> objects[1]() I am function func()! >>> d = {"cat": 1, func: 2, 42: 3} >>> d[func] 2 Copied!In this example, func() appears in all the same contexts as the values "cat" and 42, and the interpreter handles it just fine.
Note: What you can or can’t do with an object in Python depends to some extent on context. Some operations work for certain object types but not for others.
For example, you can add two integer objects or concatenate two string objects with the plus operator (+), but the plus operator isn’t defined for function objects.
For present purposes, what matters is that functions in Python satisfy the two criteria beneficial for functional programming listed above. You can pass a function to another function as an argument:
Python 1>>> def inner(): 2... print("I am function inner()!") 3... 4 5>>> def outer(function): 6... function() 7... 8 9>>> outer(inner) 10I am function inner()! Copied! Read the full article at https://realpython.com/python-functional-programming/ »[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]