Quantcast
Channel: Planet Python
Viewing all 23953 articles
Browse latest View live

ItsMyCode: ModuleNotFoundError: No module named ‘absl’

$
0
0

In Python, ModuleNotFoundError: No module named ‘absl’ error occurs if we try to import the ‘absl-py‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the absl-py module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘absl’ error.  

What is ModuleNotFoundError: No module named ‘absl’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘absl’ error

  • Trying to use the modulewithout installing the absl-pypackage.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the absl-pymodule is not installed inside a virtual environment
  • Installing the absl-py package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(absl-py)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘absl’?

absl-py is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

The absl-py repository is a collection of Python library code for building Python applications. The code is collected from Google’s own Python code base and has been extensively tested and used in production.

We can fix the error by installing the absl-py‘ module by running the pip install absl-py command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: absl-py.

pip show absl-py

Output

Name: absl-py
Version: 1.2.0
Summary: Abseil Python Common Libraries, see https://github.com/abseil/abseil-py.
Home-page: https://github.com/abseil/abseil-py
Author: The Abseil Authors
Author-email:
License: Apache 2.0
Location: c:\personal\ijs\python_samples\venv\lib\site-packages

Solution 1 – Installing and using the absl module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the absl-py module.

# If you are using Python 2 (Windows)
pip install absl-py

# if you are using Python 3 (Windows)
pip3 install absl-py

# If the pip is not set as environment varibale PATH
python -m pip install absl-py

# If you are using Python 2 (Linux)
sudo pip install absl-py

# if you are using Python 3 (Linux)
sudo pip3 install absl-py

# In case if you have to easy_install
sudo easy_install -U absl-py

# On Centos
yum install absl-py

# On Ubuntu
sudo apt-get install absl-py

# If you are installing it in Anaconda 
conda install -c conda-forge absl-py

Once you have installed the absl-py module, we can now import it inside our code and use it as shown below.

from absl import app
from absl import flags

FLAGS = flags.FLAGS
flags.DEFINE_string("name", None, "Your name.")
flags.DEFINE_integer("num_times", 1,
                     "Number of times to print greeting.")

# Required flag.
flags.mark_flag_as_required("name")

def main(argv):
  del argv  # Unused.
  for i in range(0, FLAGS.num_times):
    print('Hello, %s!' % FLAGS.name)


if __name__ == '__main__':
  app.run(main)

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + P or ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1Python Interpreter

Solution 3 – Installing absl-py inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the absl-py module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install absl-py inside the virtual environment
pip install absl-py

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as absl-py.py as it may shadow the original absl-py module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘absl’ error occurs when we try to import the ‘absl-py‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the absl module by running the pip install absl-py command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.


ItsMyCode: ModuleNotFoundError: No module named ‘Bio’

$
0
0

In Python, ModuleNotFoundError: No module named ‘Bio’ error occurs if we try to import the ‘Bio‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the biopython module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘Bio’ error.  

What is ModuleNotFoundError: No module named ‘Bio’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘Bio’ error

  • Trying to use the modulewithout installing the biopython package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the biopython module is not installed inside a virtual environment
  • Installing the biopython package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(biopython)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘Bio’?

biopython is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.

Biopython is a set of freely available tools for biological computation written in Python by an international team of developers.

We can fix the error by installing the ‘biopython‘ module by running the pip install biopython command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: biopython.

pip show biopython

Output

Name: biopython
Version: 1.79
Summary: Freely available tools for computational molecular biology.
Home-page: https://biopython.org/
Author: The Biopython Contributors
Author-email: biopython@biopython.org
License: UNKNOWN
Location: c:\personal\ijs\python_samples\venv\lib\site-packages
Requires: numpy

Solution 1 – Installing and using the biopython module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the biopython module.

# If you are using Python 2 (Windows)
pip install biopython

# if you are using Python 3 (Windows)
pip3 install biopython

# If the pip is not set as environment varibale PATH
python -m pip install biopython

# If you are using Python 2 (Linux)
sudo pip install biopython

# if you are using Python 3 (Linux)
sudo pip3 install biopython

# In case if you have to easy_install
sudo easy_install -U biopython

# On Centos
yum install biopython

# On Ubuntu
sudo apt-get install biopython

# If you are installing it in Anaconda 
conda install -c conda-forge biopython

Once you have installed the biopython module, we can now import it inside our code and use it as shown below.

from Bio.Seq import Seq

my_seq = Seq("ITSMYCODE")
for index, letter in enumerate(my_seq):
    print("%i %s" % (index, letter))

Output

0 I
1 T
2 S
3 M
4 Y
5 C
6 O
7 D
8 E

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + P or ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1Python Interpreter

Solution 3 – Installing biopython inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the biopython module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install biopython inside the virtual environment
pip install biopython

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as bio.py as it may shadow the original biopython module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘Bio’ error occurs when we try to import the ‘biopython‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the biopython module by running the pip install biopython command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

ItsMyCode: ModuleNotFoundError: No module named ‘boto3’

$
0
0

In Python, ModuleNotFoundError: No module named ‘boto3’ error occurs if we try to import the ‘boto3‘ module without installing the package or if we have not installed it in the correct environment.

In this tutorial, let’s look at installing the boto3 module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘boto3’ error.  

What is ModuleNotFoundError: No module named ‘boto3’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘boto3’ error

  • Trying to use the modulewithout installing the boto3 package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the boto3 module is not installed inside a virtual environment
  • Installing the boto3 package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(boto3)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘boto3’?

boto3 is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2

We can fix the error by installing the ‘boto3‘ module by running the pip install boto3 command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: boto3.

pip show boto3

Output

Name: boto3
Version: 1.24.42
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: c:\personal\ijs\python_samples\venv\lib\site-packages
Requires: jmespath, s3transfer, botocore

Solution 1 – Installing and using the boto3 module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the boto3 module.

# If you are using Python 2 (Windows)
pip install boto3

# if you are using Python 3 (Windows)
pip3 install boto3

# If the pip is not set as environment varibale PATH
python -m pip install boto3

# If you are using Python 2 (Linux)
sudo pip install boto3

# if you are using Python 3 (Linux)
sudo pip3 install boto3

# In case if you have to easy_install
sudo easy_install -U boto3

# On Centos
yum install boto3

# On Ubuntu
sudo apt-get install boto3

# If you are installing it in Anaconda 
conda install -c conda-forge boto3

Once you have installed the boto3 module, we can now import it inside our code and use it as shown below.

import boto3

s3 = boto3.resource("s3")
for bucket in s3.buckets.all():
    print(bucket.name)

Output

ItsMyCode
ItsJavaScript

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + P or ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1Python Interpreter

Solution 3 – Installing boto3 inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the boto3 module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install boto3 inside the virtual environment
pip install boto3

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as boto3.py as it may shadow the original boto3 module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘boto3’ error occurs when we try to import the ‘boto3‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the boto3 module by running the pip install boto3 command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

ItsMyCode: ModuleNotFoundError: No module named ‘bs4’

$
0
0

In Python, ModuleNotFoundError: No module named ‘bs4’ error occurs if we try to import the ‘beautifulsoup4‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the beautifulsoup4 module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘bs4’ error.  

What is ModuleNotFoundError: No module named ‘bs4’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘bs4’ error

  • Trying to use the modulewithout installing the beautifulsoup4 package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the beautifulsoup4module is not installed inside a virtual environment
  • Installing the beautifulsoup4 package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(beautifulsoup4)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘bs4’?

beautifulsoup4 is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.

Beautiful Soup is a library that makes it easy to scrape information from web pages. It sits atop an HTML or XML parser, providing Pythonic idioms for iterating, searching, and modifying the parse tree.

We can fix the error by installing the beautifulsoup4‘ module by running the pip install beautifulsoup4command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: beautifulsoup4.

pip show beautifulsoup4

Output

Name: beautifulsoup4
Version: 4.11.1
Summary: Screen-scraping library
Home-page: https://www.crummy.com/software/BeautifulSoup/bs4/
Author: Leonard Richardson
Author-email: leonardr@segfault.org
License: MIT
Location: c:\personal\ijs\python_samples\venv\lib\site-packages
Requires: soupsieve

Solution 1 – Installing and using the beautifulsoup4 module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the beautifulsoup4 module.

# If you are using Python 2 (Windows)
pip install beautifulsoup4

# if you are using Python 3 (Windows)
pip3 install beautifulsoup4

# If the pip is not set as environment varibale PATH
python -m pip install beautifulsoup4

# If you are using Python 2 (Linux)
sudo pip install beautifulsoup4

# if you are using Python 3 (Linux)
sudo pip3 install beautifulsoup4

# In case if you have to easy_install
sudo easy_install -U beautifulsoup4

# On Centos
yum install beautifulsoup4

# On Ubuntu
sudo apt-get install beautifulsoup4

# If you are installing it in Anaconda 
conda install -c conda-forge beautifulsoup4

Once you have installed the beautifulsoup4 module, we can now import it inside our code and use it as shown below.

In the below example we will take a look at how to fetch all the links(href) in the Metrics ConverterHome Page using BeautifulSoup and urllib libraries

from bs4 import BeautifulSoup
import urllib.request

soup = BeautifulSoup(
    "<html><body><h1>Welcome to Python Tutorial</h1></body></html>", "html.parser"
)
print(soup.prettify())


parser = "html.parser"  # or 'lxml' (preferred) or 'html5lib', if installed
resp = urllib.request.urlopen("https://www.metricsconverter.com")
soup = BeautifulSoup(resp, parser, from_encoding=resp.info().get_param("charset"))

for link in soup.find_all("a", href=True):
    print(link["href"])

Output

<html><body><h1>
   Welcome to Python Tutorial
  </h1></body></html>

/
/static/privacy-policy/
/static/cookie-policy/
/static/contact-us/
/length/
/volume/
/area/
/energy/
/force/
/speed/
/weight-and-mass/
/time/

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + P or ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1Python Interpreter

Solution 3 – Installing beautifulsoup4 inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the beautifulsoup4 module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install beautifulsoup4 inside the virtual environment
pip install beautifulsoup4

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as bs4.py as it may shadow the original beautifulsoup4 module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘bs4’ error occurs when we try to import the ‘beautifulsoup4‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the beautifulsoup4 module by running the pip install beautifulsoup4 command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

"Morphex's Blogologue": An eventful coding week for Simple TCP proxy

$
0
0
I've been mailing a bit on the python-users mailing list about STP this week, and there were some discussions there that were unfruitful - but I got some useful tips in the process:

https://mail.python.org/pipermail/python-list/2022-July/9070...

This TCP proxy needs to scale and perform reasonably well, so the last thing I worked on was making sure that downloading large files via the proxy works reasonably well, in these commits:

https://github.com/morphex/stp/commit/3328a45d5314040abd37fa...

https://github.com/morphex/stp/commit/5e477bf5756e2763db799c...

In was interesting, and relieving to see that I could speed up the download process 3-4x by multiplying the "transfer buffer" by 8. A local download of the test.tar file was around 1.3 GB/s via lighttpd, and 122 MB/s via STP. After the buffer change, the speed increased to 449 MB/s. Which is more than what a gigabit connection to the internet can handle.

So, so far so good, and good enough.

The previous commit:

https://github.com/morphex/stp/commit/5e477bf5756e2763db799c...

I got a tip for, and reduced the thread stack size to the minimum, which is from what I gather, necessary to ensure that it will run reliably on different platforms - as Linux has a rather big thread size and that could break on others if you're reliant on it.

I also implemented a "fall through", so that the thread sending data back and forth doesn't stop and wait for .N number of seconds, if data has just been sent back and forth.

And in the commit before that, I adjusted the sleep time for threads "polling" on whether or not they have become active:

https://github.com/morphex/stp/commit/9910ca8c80e9d150222b68...

which also increased the speed at which STP could deal with the connection queue.

There has been some questions on the Python list as to exactly what I'm building and why, but I think a fair description would be that it is a simple to understand, and run, TCP proxy which does some useful things out of the box.

Coming from the web development and hosting world, I'm tempted to add some HTTP protocol features as well, but that's something that belongs in another project, maybe using STP as the frame which it plugs into.

Podcast.__init__: The Benefits Of Python And Django For Going From Zero To MVP At Speed

$
0
0
Every startup begins with an idea, but that won't get you very far without testing the feasibility of that idea. A common practice is to build a Minimum Viable Product (MVP) that addresses the problem that you are trying to solve and working with early customers as they engage with that MVP. In this episode Tony Pavlovych shares his thoughts on Python's strengths when building and launching that MVP and some of the potential pitfalls that businesses can run into on that path.

Summary

Every startup begins with an idea, but that won’t get you very far without testing the feasibility of that idea. A common practice is to build a Minimum Viable Product (MVP) that addresses the problem that you are trying to solve and working with early customers as they engage with that MVP. In this episode Tony Pavlovych shares his thoughts on Python’s strengths when building and launching that MVP and some of the potential pitfalls that businesses can run into on that path.

Announcements

  • Hello and welcome to Podcast.__init__, the podcast about Python’s role in data and science.
  • When you’re ready to launch your next app or want to try a project you hear about on the show, you’ll need somewhere to deploy it, so take a look at our friends over at Linode. With their managed Kubernetes platform it’s easy to get started with the next generation of deployment and scaling, powered by the battle tested Linode platform, including simple pricing, node balancers, 40Gbit networking, dedicated CPU and GPU instances, and worldwide data centers. And now you can launch a managed MySQL, Postgres, or Mongo database cluster in minutes to keep your critical data safe with automated backups and failover. Go to pythonpodcast.com/linode and get a $100 credit to try out a Kubernetes cluster of your own. And don’t forget to thank them for their continued support of this show!
  • Your host as usual is Tobias Macey and today I’m interviewing Tony Pavlovych about Python’s strengths for startups and the steps to building an MVP (minimum viable product)

Interview

  • Introductions
  • How did you get introduced to Python?
  • Can you describe what PLANEKS is and the story behind it?
  • One of the services that you offer is building an MVP. What are the goals and outcomes associated with an MVP?
    • What is the process for identifying the product focus and feature scope?
  • What are some of the common misconceptions about building and launching MVPs that you have dealt with in your work with customers?
    • What are the common pitfalls that companies encounter when building and validating an MVP?
  • Can you describe the set of tools and frameworks (e.g. Django, Poetry, cookiecutter, etc.) that you have invested in to reduce the overhead of starting and maintaining velocity on multiple projects?
    • What are the configurations that are most critical to keep constant across projects to maintain familiarity and sanity for your developers? (e.g. linting rules, build toolchains, etc.)
  • What are the architectural patterns that you have found most useful to make MVPs flexible for adaptation and extension?
  • Once the MVP is built and launched, what are the next steps to validate the product and determine priorities?
  • What benefits do you get from choosing Python as your language for building an MVP/launching a startup?
    • What are the challenges/risks involved in that choice?
  • What are the most interesting, unexpected, or challenging lessons that you have learned while working on MVPs for your clients at PLANEKS?
  • When is an MVP the wrong choice?
  • What are the developments in the Python and broader software ecosystem that you are most interested in for the work you are doing for your team and clients?

Keep In Touch

Picks

Closing Announcements

  • Thank you for listening! Don’t forget to check out our other shows. The Data Engineering Podcast covers the latest on modern data management. The Machine Learning Podcast helps you go from idea to production with machine learning.
  • Visit the site to subscribe to the show, sign up for the mailing list, and read the show notes.
  • If you’ve learned something or tried out a project from the show then tell us about it! Email hosts@podcastinit.com) with your story.
  • To help other people find the show please leave a review on iTunes and tell your friends and co-workers

Links

The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA

IslandT: Move a simple circle up and down with Pygame

$
0
0

In this article I will show you how to move a circle up and down within the display panel of Pygame, the code is basically the modification of the previous code which I have written to add a circle to the display screen of the panel!

The concept behind this is really simple, the program will move the circle from the top left corner to the bottom right corner and will reverse direction once the circle has hit the wall!

# Import and initialize the pygame library
import pygame
pygame.display.init()

# set the caption on the panel
pygame.display.set_caption("Draw Some Drawing")

# windows height and width
windowwidth = 600
windowheight = 600

# Print this line on output panel if the initialize process is successful
if(pygame.display.get_init() == True):
    print("Success initialize the game!")

# Initialize a window or screen for display
screen = pygame.display.set_mode([windowwidth, windowheight])

# Print the x, y size of the game display window

print("The windows size is " + str(pygame.display.get_window_size()))

_x = 0.5 # small increment in x and y direction
_y = 0.5
circle_center_x = 60 # set the circle initial coordinates, set its radius as well
circle_center_y = 60
circle_radius = 60

# Run the game until the user asks to quit
running = True
while running:

    # If the user clicks on the 'x' button on pygame display window then set running to false
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Fill the rectangles with blue color
    screen.fill((0,0,255))

    pygame.draw.circle(screen, pygame.Color(0,0,0), (circle_center_y, circle_center_y), circle_radius) # Draw black circle at the middle of screen
    #pygame.draw.rect(screen, pygame.Color(225, 225, 225), pygame.Rect(x,y,rectangle_width,rectangle_height)) # Draw rectangle on screen
    #pygame.draw.line(screen, pygame.Color(255, 25, 255), (250, 300), (300,300), width=3) # Draw line on screen
    #pygame.draw.arc(screen, pygame.Color(255, 255, 255), pygame.Rect(400,30,100,100), 25.0, 30.0, width=3) # Draw arc on screen
    #pygame.draw.polygon(screen, pygame.Color(200, 125, 205), [(100,100), (150, 150), (200,250), (220, 270), (500, 300), (50, 160)], width=5) # Draw polygon on screen

    circle_center_x+=_x # increase the center x and center y coordinates of the circle
    circle_center_y+=_y

    # switch the _x or _y value if the circle hits the wall
    if(circle_center_x+circle_radius >= windowwidth):
        _x= -0.5
    elif(circle_center_x - circle_radius <= 0):
        _x= 0.5

    if (circle_center_y + circle_radius >= windowwidth):
        _y = -0.5
    elif (circle_center_y - circle_radius <= 0):
        _y = 0.5

    # update the drawing and display screen
    pygame.display.flip()

# Quit the game
pygame.display.quit()

The circle will get trapped within a loop and will continue moving up and down…now it is your turn to modify this program to make the circle moves in four directions, do let me know about the outcome in the comment box below this post if possible!

ItsMyCode: ModuleNotFoundError: No module named ‘click’

$
0
0

In Python, ModuleNotFoundError: No module named ‘click’ error occurs if we try to import the ‘click‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the click module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘click’ error.  

What is ModuleNotFoundError: No module named ‘click’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘click’ error

  • Trying to use the module- without installing the click package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the click module is not installed inside a virtual environment
  • Installing the click package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(click)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘click’?

click is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with sensible defaults out of the box.

We can fix the error by installing the ‘click‘ module by running the pip install click command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: click.

pip show click

Output

Name: click
Version: 8.1.3
Summary: Composable command line interface toolkit
Home-page: https://palletsprojects.com/p/click/   
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD-3-Clause
Location: c:\personal\ijs\python_samples\venv\lib\site-packages
Requires: colorama
Required-by: black

Solution 1 – Installing and using the click module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the click module.

# If you are using Python 2 (Windows)
pip install click

# if you are using Python 3 (Windows)
pip3 install click

# If the pip is not set as environment varibale PATH
python -m pip install click

# If you are using Python 2 (Linux)
sudo pip install click

# if you are using Python 3 (Linux)
sudo pip3 install click

# In case if you have to easy_install
sudo easy_install -U click

# On Centos
yum install click

# On Ubuntu
sudo apt-get install click

# If you are installing it in Anaconda 
conda install -c conda-forge click

Once you have installed the click module, we can now import it inside our code and use it as shown below.

import click

@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        click.echo(f"Hello, {name}!")

if __name__ == '__main__':
    hello()

Output

$ python hello.py --count=3
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1

Python Interpreter

Solution 3 – Installing click inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the click module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install click inside the virtual environment
pip install click

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as click.py as it may shadow the original click module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘click’ error occurs when we try to import the ‘click‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the click module by running the pip install click command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.


ItsMyCode: ModuleNotFoundError: No module named ‘colorama’

$
0
0

In Python, ModuleNotFoundError: No module named ‘colorama’ error occurs if we try to import the ‘colorama‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the colorama module correctly in different operating systems and solve ModuleNotFoundError: No module named ‘colorama’ error.  

What is ModuleNotFoundError: No module named ‘colorama’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘colorama’ error

  • Trying to use the module- without installing the colorama package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the colorama module is not installed inside a virtual environment
  • Installing the colorama package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(colorama)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘colorama’?

colorama is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

colorama is a Python package

Colorama is a Python package that makes ANSI escape character sequences (for producing colored terminal text and cursor positioning) work under MS Windows.

We can fix the error by installing the ‘colorama‘ module by running the pip install colorama command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: colorama.

pip show colorama

Output

Name: colorama
Version: 0.4.5
Summary: Cross-platform colored terminal text.
Home-page: https://github.com/tartley/colorama
Author: Jonathan Hartley
Author-email: tartley@tartley.com
License: BSD
Location: c:\personal\ijs\python_samples\venv\lib\site-packages
Requires:
Required-by: click

Solution 1 – Installing and using the colorama module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the colorama module.

# If you are using Python 2 (Windows)
pip install colorama

# if you are using Python 3 (Windows)
pip3 install colorama

# If the pip is not set as environment varibale PATH
python -m pip install colorama

# If you are using Python 2 (Linux)
sudo pip install colorama

# if you are using Python 3 (Linux)
sudo pip3 install colorama

# In case if you have to easy_install
sudo easy_install -U colorama

# On Centos
yum install colorama

# On Ubuntu
sudo apt-get install colorama

# If you are installing it in Anaconda 
conda install -c anaconda colorama

Once you have installed the colorama module, we can now import it inside our code and use it as shown below.

from colorama import Fore, Back, Style

print(Fore.RED + "some red text")
print(Back.GREEN + "and with a green background")
print(Style.DIM + "and in dim text")
print(Style.RESET_ALL)
print("back to normal now")

Output

imageModuleNotFoundError: No module named 'colorama' 4

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1

Python Interpreter

Solution 3 – Installing colorama inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the colorama module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install colorama inside the virtual environment
pip install colorama

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as colorama.py as it may shadow the original colorama module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘colorama’ error occurs when we try to import the ‘colorama‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the colorama module by running the pip install colorama command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

ItsMyCode: ModuleNotFoundError: No module named ‘Crypto’

$
0
0

In Python, ModuleNotFoundError: No module named ‘Crypto’ error occurs if we try to import the ‘pycryptodome‘ module without installing the package or if you have not installed it in the correct environment.

In this tutorial, let’s look at installing the pycryptodomemodule correctly in different operating systems and solve ModuleNotFoundError: No module named ‘Crypto’ error.  

What is ModuleNotFoundError: No module named ‘Crypto’?

There are various reasons why we get the ModuleNotFoundError: No module named ‘Crypto’ error

  • Trying to use the module without installing the pycryptodome package.
  • If the IDE is set to the incorrect version of the Python/Python interpreter.
  • You are using the virtual environment and the pycryptodome module is not installed inside a virtual environment
  • Installing the pycryptodome package in a different version of Python than the one which is used currently.
  • Declaring a variable name as the module name(pycryptodome)

If you are getting an error installing pip, checkout pip: command not found to resolve the issue.

How to fix ModuleNotFoundError: No module named ‘Crypto’?

pycryptodome is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.  

PyCryptodome is a self-contained Python package of low-level cryptographic primitives. All modules are installed under the Crypto package.

We can fix the error by installing the ‘pycryptodome‘ module by running the pip install pycryptodome command in your terminal/shell.

We can verify if the package is installed correctly by running the following command in the terminal/shell.

This will provide the details of the package installed, including the version number, license, and the path it is installed. If the module is not installed, you will get a warning message in the terminal stating WARNING: Package(s) not found: pycryptodome.

pip show pycryptodome

Output

Name: pycryptodome
Version: 3.15.0
Summary: Cryptographic library for Python
Home-page: https://www.pycryptodome.org
Author: Helder Eijs
Author-email: helderijs@gmail.com
License: BSD, Public Domain
Location: c:\personal\ijs\python_samples\venv\lib\site-packages

Solution 1 – Installing and using the pycryptodome module in a proper way

Based on the Python version and the operating system you are running, run the relevant command to install the pycryptodome module.

# If you are using Python 2 (Windows)
pip install pycryptodome

# if you are using Python 3 (Windows)
pip3 install pycryptodome

# If the pip is not set as environment varibale PATH
python -m pip install pycryptodome

# If you are using Python 2 (Linux)
sudo pip install pycryptodome

# if you are using Python 3 (Linux)
sudo pip3 install pycryptodome

# In case if you have to easy_install
sudo easy_install -U pycryptodome

# On Centos
yum install pycryptodome

# On Ubuntu
sudo apt-get install pycryptodome

# If you are installing it in Anaconda 
conda install -c conda-forge pycryptodome

Once you have installed the pycryptodome module, we can now import it inside our code and use it as shown below.

from Crypto.PublicKey import RSA

secret_code = "Unguessable"
key = RSA.generate(2048)
encrypted_key = key.export_key(passphrase=secret_code, pkcs=8,
                              protection="scryptAndAES128-CBC")

file_out = open("rsa_key.bin", "wb")
file_out.write(encrypted_key)
file_out.close()

print(key.publickey().export_key())

Output

b'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv4cPMmtVy3RLUVI3+Hqe\nd2Mcl4WR0BjOXQ1Vf+B5wX0RIcZwCEjemUMnglA/cQl4Ink5Z/CAHMCWmzUPkNGe\nBG+Zadt+u9Q+3syNH0YRFGv+jBqm6DQaA4Eiz+PEBy/sVBoX7fLulpCPJ/G9U/f9\nrWGVF0ysSL8BWN0QcF6RcqP+6jNnexDWEyzFS85+WJoTwGZ1lJFPCN18I1FPPuRj\nEV/tVaqedutXZ8Lq2pIS9urbNPawlK1PxBc6SmdqE46F6JU0sCDoijUFMD0fZz69\n0XCemO7GKrd9f4/cLZ0+R/K5qTp1JtSRISOtAr+/TeeEZ1DcA6Z+GS2854V8m1KC\nVQIDAQAB\n-----END PUBLIC KEY-----'

Solution 2 – Verify if the IDE is set to use the correct Python version

If you are still getting the same error even after installing the package, you can verify if the IDE you are using is configured with the correct version of the Python interpreter.

For Eg:- In the case of Visual Studio Code, we can set the Python version by pressing CTRL + Shift + Por ( + Shift + P on Mac) to open the command palette.

Once the command palette opens, select the Python interpreter and select the correct version of Python and also the virtual environment(if configured) as shown below.

image 1

Python Interpreter

Solution 3 – Installing pycryptodome inside the virtual environment

Many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm often install their own virtual environment of Python to keep things clean and separated from your global Python.

If you are using VS Code, then you can also create a virtual environment, as shown below.

In the case of virtual environments, you need to ensure that the pycryptodome module needs to be installed inside the virtual environment and not globally.

Step 1: Create a Virtual Environment. If you have already created a virtual environment, then proceed to step 2.

Step 2: Activate the Virtual Environment

Step 3: Install the required module using the pip install command

# Create a virtual Environment
py -3 -m venv venv

# Activate the virtual environment (windows command)
venv\Scripts\activate.bat

# Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1

# Activate the virtual environment (Linux)
source venv/bin/activate

# Install pycryptodome inside the virtual environment
pip install pycryptodome

Solution 4 – Ensure that a module name is not declared name a variable name.

Last but not least, you may need to cross-check and ensure that you haven’t declared a variable with the same name as the module name.

You should check if you haven’t named any files as Crypto.py as it may shadow the original pycryptodome module.

If the issue is still not solved, you can try removing the package and installing it once again, restart the IDE, and check the paths to ensure that packages are installed in the correct environment path and Python version.

Conclusion

The ModuleNotFoundError: No module named ‘Crypto’ error occurs when we try to import the ‘pycryptodome‘ module without installing the package or if you have not installed it in the correct environment.

We can resolve the issue by installing the pycryptodome module by running the pip install pycryptodome command. Also, ensure that the module is installed in the proper environment in case you use any virtual environments, and the Python version is appropriately set in the IDE that you are running the code.

Tryton News: Newsletter August 2022

$
0
0

The summer did not stop the Tryton developments, here are the new features that landed:

Changes for the User

Saved CSV exports now also set the header in the same way as when run from the wizard.

The account chart reports now use a context form instead of a setup wizard. This allows the report configuration to be instantly changed instead of needing to close and re-open it.

The cost allocation for a shipment and landed cost is now shown before and after posting. This enhances understanding and can help prevent mistakes.

New Modules

The Sale Promotion Coupon Payment Module includes the same parties as the payments to allow the usage to be counted per party.

Changes for the System Administrator

The logging messages now include the duration spent processing the request or task.

The logging messages containing the request parameters are now truncated at 80 chars.

Changes for the Developer

The payment modules link together the same parties that have used the same payment methods.

A promotion coupon can now count together identical parties.

Tryton now uses an implicit join clause on sub-queries when searching on Many2One fields. This allows the database engine to use a better SubPlan, reducing the complexity from O(n²) to O(n log(n)) by using the index on the primary key.

1 post - 1 participant

Read full topic

Matt Layman: Announcing django-denied

$
0
0
I have paranoia when it comes to my Django app. I run a homeschool scheduling service called School Desk. My Software as a Service (SaaS) lets families plan their homeschool activities. Since the app deals with data about students (including my kids!), it’s important to me that every user’s data is protected, so that users can only view their own information. When I designed the system, I picked a shared Postgres schema (i.

Mike Driscoll: PyDev of the Week: Stefanie Molin

$
0
0

This week we welcome Stefanie Molin (@StefanieMolin) as our PyDev of the Week! Stefanie is the author of Hands-On Data Analysis with Pandas. You can learn more about Stefanie by visiting her website or checking out Stefanie's GitHub profile.

Stefanie Molin

Let's take a few moments to get to know Stefanie better!

Can you tell us a little about yourself (hobbies, education, etc.)

I am a software engineer and data scientist at Bloomberg in New York City. I work at the intersection of information security and data science. A lot of my time revolves around data wrangling and visualization, building tools for gathering data and providing context, and knowledge sharing. I am also the author of "Hands-On Data Analysis with Pandas," which is currently in its second edition.

I graduated from Columbia University's Fu Foundation School of Engineering and Applied Science with a bachelor’s degree in operations research, and I am currently pursuing a master’s degree in computer science, with a specialization in machine learning, from Georgia Tech. In my free time, I enjoy traveling the world, reading, inventing new recipes, and learning new languages spoken among both people and computers.

Why did you start using Python?

In a previous job, I wanted to improve a model for an alerting system my team had built, but we didn't have any labeled data. I decided to build a web app to make it possible for users to provide feedback on alerts they received, as well as ones that others received. I was coding in R at that point, so building a Shiny app was an option; however, a teammate suggested I use Python since it would be easier to set up on our server. I spent the next three weeks building out an initial version as a Flask app. Python was easy to learn and more compatible with our infrastructure – it helped to have other coders on the team using the same language.

What other programming languages do you know and which is your favorite?

Other than Python, I currently use React, JavaScript (both vanilla and D3), as well as some Bash and Arduino (C++). I also have prior experience with R and Java, but those are a bit rusty now. Python is definitely my favorite language for most projects, but I like React for front-end web development. Once you get over the (steep) learning curve, there is so much you can do quickly, and it makes it much easier to create an aesthetically pleasing web app when you use a framework.

What projects are you working on now?

I'm in the homestretch of my master's program in computer science. Other than that, I've been working on a pandas workshop and another on data visualization in Python – both of which I’ve been presenting at conferences like ODSC and PyCon.

I’ve also recently dipped my toes into open source contributions. I fixed multiple data visualization bugs for the pandas 1.5.0 release, and I added a new functionality for adding reference lines to JointGrid and FacetGrid plots (which seems to be a crowd favorite) in the Seaborn 0.11.2 release. I love to open my data visualization in Python workshop by telling everyone that after the first section they will know enough to have made that Seaborn contribution. While I was in the process of building the workshop, I was also able to fix a bug in the anatomy of a figure page in Matplotlib’s documentation just before the release candidate at the time became the final release.

Which Python libraries are your favorite (core or 3rd party)?

From the standard library, I'm a huge fan of itertools (so much so that it's almost a signature of my code), calendar, and collections– the standard library is packed with useful functionality waiting to be discovered.

As far as third-party libraries, my favorites are pandas (of course), matplotlib (people love to hate it, but you can do so much if you take the time to understand the API – check out the first section of my data visualization in Python workshop for help with that), and flask.

How did you decide to be a book author?

I took a couple of Java courses during my undergraduate studies, but it wasn't until I was in the workforce that I discovered my interest in the intersection of data science and software engineering. I did a lot of self-study to move my career in that direction. Part of this involved reading several data science and programming books. At the time, I felt that writing a book myself would be a good way to package up all that knowledge, kind of like a thesis.

Personally, when I'm new to something, I like to see meaningful examples, not just made-up data. This helps me understand why you would do something, as well as recognize it when I see a use case for it; this was my value proposition for the book I wanted to write.

I never actually thought of a subject for the book. One day, my publisher (Packt) reached out to me looking for an author for a book on data analysis using pandas. The timing was right, so I went for it – and about a year later, "Hands-On Data Analysis with Pandas" was published.

What are the top 3 things you learned while writing a book?

While writing the first few drafts, I quickly learned that just having an outline of the book and a list of 3-5 main concepts for each chapter wasn't enough to contend with writer's block – and sometimes, to even get started. It was worth the extra time to break down each of the concepts into another couple of levels until I had a detailed outline for each chapter, along with personal deadlines for each part. This approach helped keep me on track for the chapter deadlines I had set with my publisher. Breaking big projects down into much smaller pieces is how I code, but I learned that this approach also generally lends itself well to large projects.

I was fortunate enough to have a small group of friends and colleagues who provided me with constructive criticism throughout the process. It was a bit of a trial by fire, but I learned how to accept such feedback and used it to improve the final product, while not taking it personally. After that initial round of review, I ended up rewriting more than half of the content in some of the chapters – it was hard to throw out so much content that I had labored over, but taking their feedback into account really made for a better product.

I can be very hard on myself and that translates to perfectionism, so I also had to learn that it's really more of an optimization problem (of time, quality, being happy with the final product, etc.). I was never going to be able to make sure the draft was 100% free of typos (after all, the book is nearly 800 pages!), but I could control the overall quality of the content and whether it was something that I could be proud of.

Is there anything else you'd like to say?

Push yourself; do things that scare you (within reason) – you only grow by going outside of your comfort zone, and you will be surprised at what you are capable of achieving.

Thanks so much for doing the interview, Stefanie!

The post PyDev of the Week: Stefanie Molin appeared first on Mouse Vs Python.

Python for Beginners: Remove Quotes From a String in Python

$
0
0

Due to the availability of various modules, Python is one of the most used programming languages for natural language processing and text analytics. We use strings in python to analyze text data. Single quotes or double quotes enclose each string in Python. However, the input string may contain quotes in between. This article discusses different ways to remove quotes from a string in Python.

Remove Quotes From a String in Python Using For loop

In Python, we use for loop to iterate over an iterable object like a string or list. To remove quotes from a string using a for loop, we will use the following steps.

  • First, we will create a list named quotes to store the single quote and double quote characters.
  • Then, we will create an empty string named newStr to store the output string.
  • Now, we will use the for loop to iterate through the characters in the input string.
  • While iteration, if we find characters other than a single quote or double quotes, we will append the characters to newStr using the string concatenation operator. To check if a character is a single or double quote, we will use the membership operator.
  • If we find a single quote or double quote character in the string, we will skip it.
  • After execution of the for loop, we will get the output string in the variable newStr.

You can observe the entire process in the following example.

input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
quotes = ["'", '"']
newStr = ""
for character in input_string:
    if character not in quotes:
        newStr += character
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Instead of using the list named quotes and the membership operator, we can directly compare the characters for the presence of single quotes and double quotes in the string. For this, we will compare the characters using the equality operator in the if statement. The rest of the processes remain the same as above.

input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
newStr = ""
for character in input_string:
    if character == "'" or character == '"':
        continue
    else:
        newStr += character
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Here, you can see that we haven’t used the list and membership operator. Instead, we have directly compared the characters in the if statement using the equality operator.

Using the filter() Function and the join() Method to Remove Quotes From a String in Python

The filter() function is used to exclude elements from an iterable object. The syntax of the filter() function is as follows.

filter(input_function,iterable_object)

Here,

  • The iterable_object is the python object from which we need to exclude the elements.
  • The input_function is a function that takes an element of the iterable_object and returns True or False.

After execution, the filter() function returns a filter object. A filter object is an iterable object that contains all the elements of iterable_object for which the input_function returns True.

The join() method is used to create a string from a given iterable object. When invoked on a separator string, the join() method takes an iterable object as its input argument.

After execution, it returns a string in which all the elements of the iterable object are separated by the separator.
To remove quotes from a string in Python using the join() method and filter() function, we will use the following steps.

  • First, we will create a function isNotQuotes() that takes a character as its input argument. If the character is a single quote or double quotes character, it returns False. Otherwise, it returns True.
  • After this, we will use the filter() function to exclude quotes from the string. For this, we will pass the isNotQuotes function as the first input argument and the input string as the second argument to the filter function. After execution of the filter() function, we will get a filter object containing all the characters of the input string except quotes.
  • Now, we will use the join() method to obtain the output string. For this, we will use an empty string as a separator. We will invoke the join() method on the separator by passing the filter object as its input argument.

After execution of the join() method, we will get the output string without any quotes. You can observe this in the following example.

def isNotQuotes(character):
    if character == '"':
        return False
    if character == "'":
        return False
    return True


input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
filter_object=filter(isNotQuotes,input_string)
newStr = "".join(filter_object)
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Remove Quotes From a String in Python Using List Comprehension

List comprehension is used to create a new list from existing iterable objects. We can use list comprehension and the join() method to remove quotes from a string in Python. For this, we will use the following steps.

  • First, we will create a list named quotes to store the single quote and double quote characters.
  • Then, we will use list comprehension to get a list of characters from the input string excluding quotes.
  • Once we obtain the list of characters, we will invoke the join() method on an empty string and pass the list of characters as an input argument to it.
  • After execution of the join() method, we will get the desired string. You can observe this in the following example.
input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
quotes = ["'", '"']
myList = [character for character in input_string if character not in quotes]
newStr = "".join(myList)
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Using the replace() Method to Remove Quotes From a String in Python

The replace() method is used to replace one character with another in a string. When invoked on a string, the replace() method takes the element that needs to be replaced as the first input argument and the new character as its second argument. After execution, it returns the modified string.
To remove quotes from a string in Python using the replace() method, we will use the following steps.

  • First, we will invoke the replace() method on the input string. Here, we will pass the single quote character as the first input argument and an empty string as the second input argument to the replace() method. The replace() method will return a string say tempStr as its output.
  • Again, we will invoke the replace() method on tempStr. This time, we will pass the double quote characters as the first input argument and an empty string as the second input argument to the replace() method.

After the second execution of the replace method, we will get the desired output string with no quote characters in it. You can observe this in the following example.

input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
tempStr = input_string.replace("'", "")
newStr = tempStr.replace('"', "")
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Remove Quotes From a String in Python Using re.sub() Function

Regular expressions provide us with various functions for string manipulation. We can use the re.sub() function to remove quotes from a string in Python.
The re.sub() function has the following syntax.

re.sub(old_character, new_character, input_string)

Here,

  • The input_string is the string from which we have to replace or remove characters.
  • The old_character is the character that needs to be removed from input_string.
  • The new_character is the character that will be inserted into the input_string in place of the old_character.

To remove quotes from a given string in python using the re.sub() function, we will use the single quote and double quotes characters as old_character and an empty string as the new_character.

  • First, we will pass a single quote as the first input argument, an empty string as the second input argument, and the given string as the third input argument to the re.sub() function. After execution, the sub() function will return a string. We will name it tempStr.
  • Now, we will pass double quotes as the first input argument, an empty string as the second input argument, and tempStr as the third input argument to the re.sub() function.

After execution, the re.sub() function will return the desired string having no quotation marks. You can observe this in the following code.

import re

input_string = "Pythonf'orb''eginn'er's"
print("The input string is:", input_string)
tempStr = re.sub("'", "", input_string)
newStr = re.sub('"', "", tempStr)
print("The output string is:", newStr)

Output:

The input string is: Pythonf'orb''eginn'er's
The output string is: Pythonforbeginners

Remove First and Last Quote characters From a Python String

If we have a string having quote characters only at the start and end as in "'Aditya'" or '"Aditya"', we can use the following approaches to remove quotes from the string.

Using the ast module to Remove First and Last Quote characters From a String

The ast module provides us with the literal_eval() function to evaluate an expression written in the form of a string. The literal_eval() function takes a string as its input argument, evaluates it, and returns the output.
As we pass the string '"Aditya"' or "'Aditya'"to the literal_eval() function, it considers the input string as expression and "Aditya" or 'Aditya' as the corresponding values. You can observe this in the following example.

import ast

input_string = "'Aditya'"
newStr=ast.literal_eval(input_string)
print("The input string is:", input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Aditya'
The output string is: Aditya

This approach won’t work if the input string contains extra quotes at a position different than the first and last positions. If you try to remove quotes from such an input string using the literal_eval() function, the program will run into the SyntaxError as shown in the following example.

import ast

input_string = "'Adity'a'"
print("The input string is:", input_string)
newStr=ast.literal_eval(input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Adity'a'
Traceback (most recent call last):
  File "/home/aditya1117/PycharmProjects/pythonProject/string12.py", line 5, in <module>
    newStr=ast.literal_eval(input_string)
  File "/usr/lib/python3.8/ast.py", line 59, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    'Adity'a'
           ^
SyntaxError: invalid syntax

In this approach, the input string must contain quote characters at both the first and last positions.

If we have a quote character at the first position and not at the last position, the program will run into the SyntaxError . Similarly, If we have a quote character at the last position and not at the first position, the program will again run into a SyntaxError.
You can observe this in the following example.

import ast

input_string = "'Aditya"
print("The input string is:", input_string)
newStr=ast.literal_eval(input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Aditya
Traceback (most recent call last):
  File "/home/aditya1117/PycharmProjects/pythonProject/string12.py", line 5, in <module>
    newStr=ast.literal_eval(input_string)
  File "/usr/lib/python3.8/ast.py", line 59, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    'Aditya
          ^
SyntaxError: EOL while scanning string literal

Another condition to keep in mind is that the quote characters at both the start and end of the string should be the same. If there is a single quote at the start and double quotes at the end of the string or vice versa, the program will again run into the SyntaxError as shown below.

import ast

input_string = "'Aditya\""
print("The input string is:", input_string)
newStr=ast.literal_eval(input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Aditya"
Traceback (most recent call last):
  File "/home/aditya1117/PycharmProjects/pythonProject/string12.py", line 5, in <module>
    newStr=ast.literal_eval(input_string)
  File "/usr/lib/python3.8/ast.py", line 59, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    'Aditya"
           ^
SyntaxError: EOL while scanning string literal

The program will run into a ValueError exception if the input string doesn’t contain quote characters at the start and end. You can observe this in the following example.

import ast

input_string = "Aditya"
print("The input string is:", input_string)
newStr = ast.literal_eval(input_string)
print("The output string is:", newStr)

Output:

The input string is: Aditya
Traceback (most recent call last):
  File "/home/aditya1117/PycharmProjects/pythonProject/string12.py", line 5, in <module>
    newStr = ast.literal_eval(input_string)
  File "/usr/lib/python3.8/ast.py", line 99, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python3.8/ast.py", line 98, in _convert
    return _convert_signed_num(node)
  File "/usr/lib/python3.8/ast.py", line 75, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib/python3.8/ast.py", line 66, in _convert_num
    _raise_malformed_node(node)
  File "/usr/lib/python3.8/ast.py", line 63, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <_ast.Name object at 0x7ffbe7ec60d0>

Hence, you should keep in mind that you can use the literal_eval() function only if the string contains quote characters only at the start and end.

Remove First and Last Quote characters From a String Using the eval() function

The eval() function works in a similar manner to the literal_eval() function. It also takes a string expression as an input argument, evaluates the expression, and returns the resultant value.
You can remove the first and last quotes from a string using the eval() function as shown below.

input_string = "'Aditya'"
print("The input string is:", input_string)
newStr = eval(input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Aditya'
The output string is: Aditya

All the conditions mentioned for the string_eval() function are true for the eval() function. Hence, you should keep in mind that you cannot use the eval() function for every string.

Using the json module to Remove First and Last Quote characters From a String

A python string enclosed in double quotes is a valid json object. Therefore, we can use the json module to remove quotes from the first and last position of an input string.
The loads() function in the json module takes a json object as its input argument and returns a python string corresponding to the json object.
As our string contains extra quotes at the first and the last position. It will be considered a valid json object. Hence, we can pass it to the loads() function to obtain the output string as shown below.

import json
input_string = '"Aditya"'
print("The input string is:", input_string)
newStr = json.loads(input_string)
print("The output string is:", newStr)

Output:

The input string is: "Aditya"
The output string is: Aditya

Here, you should keep in mind that the string with single quotes is not a valid json string. Hence, if you try to remove single quotes from a given string using the json module, the program will run into error as shown in the following example.

import json
input_string = "'Aditya'"
print("The input string is:", input_string)
newStr = json.loads(input_string)
print("The output string is:", newStr)

Output:

The input string is: 'Aditya'
Traceback (most recent call last):
  File "/home/aditya1117/PycharmProjects/pythonProject/string12.py", line 4, in <module>
    newStr = json.loads(input_string)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In all the other situations except the extra double quotes, the approach using the json module will run into error if you try to remove the quotes from the string. Hence, you should keep in mind that you can use this approach in only one case.

Remove First and Last Quote characters From a String Using the strip() Function

Using the ast module, the json module, or the eval() function to remove quotes from the start and end of a string have many restrictions. It is highly possible that your program will run into an exception while using these approaches. Instead of the above approaches, we can use the strip() method to remove quotes from the start and end of a string.
The strip() method, when invoked on a string, takes a character as its input argument. After execution, it removes all the occurrences of the character from the start and the end of the string and returns a new string.
To remove quotes from the start and end of the string, we will use the following approach.

  • First, we will declare a string temp1, and initialize it to the input string.
  • Now, we will use a while loop to remove the quote characters. Inside the while loop, we will use the following steps.
  • First, we will declare a temporary string named temp2 and initialize it to temp1.
  • Now, we will invoke the strip() method on temp1. Here, we will pass a single quote character as an input argument to the strip() method. We will store the return value of the strip() method in temp3.
  • Again, we will invoke the strip() method on temp3. This time, we will pass double quotes as an input argument to the strip() method. We will store the output in temp4.
  • Now, we will check if temp4 is equal to temp2. If yes, all the quotes have been removed from the string as no change has occurred to the string in the current iteration. Hence, we will move out of the while loop using a break statement.
  • If temp2 is not equal to temp4, the string still contains quotes at the start and the end. Hence we need another iteration. For this, we will assign temp4 to temp1.

After execution of the while loop, we will get the desired string with quotes removed from its start and end. You can observe this in the following code.

input_string = "'Pythonforbeginners'"
print("The input string is:", input_string)
temp1 = input_string
while True:
    temp2 = temp1
    tem3 = temp2.strip("'")
    temp4 = tem3.strip('"')
    if temp4 == temp2:
        newStr = temp2
        print("The output string is:", newStr)
        break
    else:
        temp1 = temp4

Output:

The input string is: 'Pythonforbeginners'
The output string is: Pythonforbeginners

This approach removes the quotes successfully in the cases where the literal_eval() method and the eval() function fails. Therefore, you can use this approach freely. For instance, look at the following example.

input_string = "'''''''Pythonforbeginners'\""
print("The input string is:", input_string)
temp1 = input_string
while True:
    temp2 = temp1
    tem3 = temp2.strip("'")
    temp4 = tem3.strip('"')
    if temp4 == temp2:
        newStr = temp2
        print("The output string is:", newStr)
        break
    else:
        temp1 = temp4

Output:

The input string is: '''''''Pythonforbeginners'"
The output string is: Pythonforbeginners

In the above example, you can observe that we have used an input string that contains seven single quotes at its left and a single quote with double quotes at its right. Even in this asymmetrical situation, the program works correctly and doesn’t run into any Error.

Conclusion

In this article, we have discussed various approaches to remove quotes from a string in Python. Out of all these approaches, I will suggest you use the replace() method and the re.sub() function. The approaches using these functions are the most efficient.
I hope you enjoyed reading this article. To know more about python programming, you can read this article on dictionary comprehension in Python. You might also like this article on regression in machine learning.

The post Remove Quotes From a String in Python appeared first on PythonForBeginners.com.

Real Python: Asynchronous Tasks With Django and Celery

$
0
0

You’ve built a shiny Django app and want to release it to the public, but you’re worried about time-intensive tasks that are part of your app’s workflow. You don’t want your users to have a negative experience navigating your app. You can integrate Celery to help with that.

Celery is a distributed task queue for UNIX systems. It allows you to offload work from your Python app. Once you integrate Celery into your app, you can send time-intensive tasks to Celery’s task queue. That way, your web app can continue to respond quickly to users while Celery completes expensive operations asynchronously in the background.

In this tutorial, you’ll learn how to:

  • Recognize effective use cases for Celery
  • Differentiate between Celery beat and Celery workers
  • Integrate Celery and Redis in a Django project
  • Set up asynchronous tasks that run independently of your Django app
  • Refactor Django code to run a task with Celery instead

If you’ve never used Celery in a Django app before, or if you’ve peeked into Celery’s documentation but couldn’t find your way around, then you’re in the right place. You’ll learn all you need to start running asynchronous tasks with Django and Celery.

You’ll integrate Celery into an existing Django app. Go ahead and download the code for that app so you can follow along:

Source Code:Click here to download the source code you’ll use to integrate Celery into your Django app.

Python Celery Basics

Celery is a distributed task queue that can collect, record, schedule, and perform tasks outside of your main program.

Note: Celery dropped support for Windows in version 4, so while you may still be able to get it to work on Windows, you’re better off using a different task queue, such as huey or Dramatiq, instead.

In this tutorial, you’ll focus on using Celery on UNIX systems, so if you’re trying to set up a distributed task queue on Windows, then this might not be the right tutorial for you.

To receive tasks from your program and send results to a back end, Celery requires a message broker for communication. Redis and RabbitMQ are two message brokers that developers often use together with Celery.

In this tutorial, you’ll use Redis as the message broker. To challenge yourself, you can stray from the instructions and use RabbitMQ as a message broker instead.

If you want to keep track of the results of your task runs, then you also need to set up a results back end database.

Note: Connecting Celery to a results back end is optional. Once you instruct Celery to run a task, it’ll do its duty whether you keep track of the task result or not.

However, keeping a record of all task results is often helpful, especially if you’re distributing tasks to multiple queues. To persist information about task results, you need a database back end.

You can use many different databases to keep track of Celery task results. In this tutorial, you’ll work with Redis both as a message broker and as a results back end. By using Redis, you limit the dependencies that you need to install because it can take on both roles.

You won’t do any work with the recorded task results in the scope of this tutorial. However, as a next step, you could inspect the results with the Redis command-line interface (CLI) or pull information into a dedicated page in your Django project.

Why Use Celery?

There are two main reasons why most developers want to start using Celery:

  1. Offloading work from your app to distributed processes that can run independently of your app
  2. Scheduling task execution at a specific time, sometimes as recurring events

Celery is an excellent choice for both of these use cases. It defines itself as “a task queue with focus on real-time processing, while also supporting task scheduling” (Source).

Even though both of these functionalities are part of Celery, they’re often addressed separately:

  1. Celery workers are worker processes that run tasks independently from one another and outside the context of your main service.
  2. Celery beat is a scheduler that orchestrates when to run tasks. You can use it to schedule periodic tasks as well.

Celery workers are the backbone of Celery. Even if you aim to schedule recurring tasks using Celery beat, a Celery worker will pick up your instructions and handle them at the scheduled time. What Celery beat adds to the mix is a time-based scheduler for Celery workers.

In this tutorial, you’ll learn how to integrate Celery with Django to perform operations asynchronously from the main execution thread of your app using Celery workers.

You won’t tackle task scheduling with Celery beat in this tutorial, but once you understand the basics of Celery tasks, you’ll be well equipped to set up periodic tasks with Celery beat.

Read the full article at https://realpython.com/asynchronous-tasks-with-django-and-celery/ »


[ 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 ]


TestDriven.io: Class-based vs Function-based Views in Django

$
0
0
This article looks at the differences between Django's class-based views (CBV) and function-based views (FBV).

Python⇒Speed: The best way to find performance bottlenecks: observing production

$
0
0

Your customers are complainin’, your monitors are alertin’, your thumbs are a-twiddlin’—whatever the symptom, the problem is that your application is too slow. And you want to find out why, so you can fix it.

You could spin up your application on your laptop, do some benchmarking, and try to find the bottleneck. Sometimes, that’s all it takes, but quite often, local testing tells you nothing useful. For many performance bottlenecks, the only way to identify the problem is to measure in production.

To understand why, we’ll need to go over all the many ways production might differ from your laptop. In this article, we’ll be focusing on server-based applications where your organization has set up the production environment (including cloud hosting); applications run by third-parties involve even more difficulties.

Some of the differences between development and production that we’ll mention include:

  • CPU, memory, and disk speeds.
  • Network latency.
  • Data inputs.
  • Database contents and configuration.
  • Just a hint of the complexities involved with cloud services, and more.
  • Software versions.
Read more...

Nikola: Nikola v8.2.3 is out!

$
0
0

On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v8.2.3. This is a bugfix release, which fixes compatibility with python-markdown and two more minor bugs.

What is Nikola?

Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn Jupyter Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed).

Find out more at the website: https://getnikola.com/

Downloads

Install using pip install Nikola.

Changes

  • Compatibility with Markdown 3.4.0 (Issue #3635)

  • Find substring in string instead of using contains in utils

  • Don't add semicolon in docinfo fields via CSS (caused duplicated semicolons)

Nikola now requires Python 3.7 or newer.

Python Insider: Python 3.10.6 is available

$
0
0

Here you have a nice package of 200 commits of bugfixes and documentation improvements freshly made for Python 3.10. Go and download it when is still hot:

https://www.python.org/downloads/release/python-3106/

This is the sixth maintenance release of Python 3.10

Python 3.10.6 is the newest major release of the Python programming language, and it contains many new features and optimizations.

Major new features of the 3.10 series, compared to 3.9

Among the new major new features and changes so far:

  • PEP 623 – Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.
  • PEP 604 – Allow writing union types as X | Y
  • PEP 612 – Parameter Specification Variables
  • PEP 626 – Precise line numbers for debugging and other tools.
  • PEP 618 – Add Optional Length-Checking To zip.
  • bpo-12782: Parenthesized context managers are now officially allowed.
  • PEP 634 – Structural Pattern Matching: Specification
  • PEP 635 – Structural Pattern Matching: Motivation and Rationale
  • PEP 636 – Structural Pattern Matching: Tutorial

More resources

bpo-38605from __future__ import annotations (PEP 563) used to be on this list in previous pre-releases but it has been postponed to Python 3.11 due to some compatibility concerns. You can read the Steering Council communication about it here to learn more.

And now for something completely different

A pentaquark is a human-made subatomic particle, consisting of four quarks and one antiquark bound together; they are not known to occur naturally or exist outside of experiments to create them. As quarks have a baryon number of (+1/3), and antiquarks of (−1/3), the pentaquark would have a total baryon number of 1 and thus would be a baryon. Further, because it has five quarks instead of the usual three found in regular baryons (a.k.a. ‘triquarks’), it is classified as an exotic baryon. The name pentaquark was coined by Claude Gignoux et al. (1987) and Harry J. Lipkin in 1987; however, the possibility of five-quark particles was identified as early as 1964 when Murray Gell-Mann first postulated the existence of quarks. Although predicted for decades, pentaquarks proved surprisingly tricky to discover and some physicists were beginning to suspect that an unknown law of nature prevented their production.

We hope you enjoy the new releases!

Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation.

Real Python: Python Basics: Finding and Fixing Code Bugs

$
0
0

Everyone makes mistakes—even seasoned professional developers!

IDLE is pretty good at catching mistakes like syntax errors and run-time errors, but there’s a third type of error that you may have already experienced. Logic errors occur when an otherwise valid program doesn’t do what was intended.

Logic errors cause unexpected behaviors called bugs. Removing bugs is called debugging, and a debugger is a tool that helps you hunt down bugs and understand why they’re happening.

Knowing how to find and fix bugs in your code is a skill that you will use for your entire coding career!

In this Python Basics video course, you’ll:

  • Learn how to use IDLE’s Debug Control window
  • Practice debugging on a buggy function
  • Learn alternative methods for debugging your code

[ 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 ]

Viewing all 23953 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>