Tag: Python

How to add a ‘b’ prefix to a variable name in Python?

Strings with a ‘b’ prefix in Python Consider the following example: byte_string = b'test string' print(byte_string) These two strings will print: b'test string' Strings with a ‘b’ prefix are a sequence of bytes, i.e. a special type of data (such as strings, numbers, lists, etc.). Suppose we want to do something like this: variable_string = "test string" byte_string = b'variable_string'...

How to run a program from Python: how to run a system command or another Python script (complete guide)

Table of Contents 1. The subprocess module in Python 2. How to pass arguments to a program in subprocess.run 3. Getting the result of command execution (standard output, stdout)) 4. Working with the standard error (stderr) 5. Automatic command splitting into a list of arguments 6. How to run a command with wildcards 7. Calling a command without breaking it...

How to clear a List in Python. Why clearing a List deletes copies of it in other variables

Why clearing a List in Python deletes copies of it in other variables Clearing a list in Python can be done in a number of ways, some of which can lead to unexpected results if you don't know the differences and what's going on under the hood. Let's look at a very simple script that doesn't do anything meaningful, but...

How to find the third root in Linux. How to extract a root of any degree in Linux

Table of contents 1. How to extract a cube root in Linux 2. How to find a cube root in the Linux calculator (GNOME Scientific calculator) 3. How to find a root of any degree in the Linux calculator (GNOME Scientific calculator) 4. How to extract a root of any degree in the command line 4.1 Extracting cube roots using...

Error “ModuleNotFoundError: No module named ‘manimpango’” (SOLVED)

When starting one of the programs the following error occurred: Traceback (most recent call last): File "/usr/bin/emote", line 33, in <module> sys.exit(load_entry_point('Emote==0.0.0', 'gui_scripts', 'emote')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/bin/emote", line 25, in importlib_load_entry_point return next(matches).load() ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 202, in load module = import_module(match.group('module')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1206,...

How to get data from a web page using GET and POST methods in a Python script on Windows

Python programs and scripts can make requests to and receive data from websites and web services using the GET and POST methods (as well as other HTTP methods: PUT, PATCH and DELETE). But what if you want to pass data from a web page to a Python script? This can be done in several ways. How to get data from...

How to get data from a web page using GET and POST methods in a Python script

Python programs and scripts can make requests to and receive data from websites and web services using the GET and POST methods (as well as other HTTP methods: PUT, PATCH and DELETE). But what if you want to pass data from a web page to a Python script? This can be done in several ways. How to get data from...

How to install Python as a CGI module in Apache on Linux

Table of contents 1. How to run a Python script on a web server 2. How to set up Python as a CGI module in Apache on Debian (Ubuntu, Linux Mint, Kali Linux) 2.1 Setting up Python CGI for a single directory 2.2 Setting up Python CGI for the entire web server 3. How to set up Python as a...

How to set up Python as a CGI module in Apache on Arch Linux (Manjaro, BlackArch)

Setting up Python CGI for a single directory Create a directory /srv/http/cgi-bin/ - this is where the Python scripts will be located: sudo mkdir /srv/http/cgi-bin/ Open the /etc/httpd/conf/httpd.conf file – the web server configuration file: sudo gedit /etc/httpd/conf/httpd.conf Find a group of lines: <Directory "/srv/http/cgi-bin"> AllowOverride None Options None Require all granted </Directory> And replace it with: <Directory "/srv/http/cgi-bin"> AllowOverride...

How to set up Python as a CGI module in Apache on Debian (Ubuntu, Linux Mint)

Setting up Python CGI for a single directory Run the command to enable the CGI module: sudo a2enmod cgi Restart the web server for the changes to take effect: sudo systemctl restart apache2 Create file /usr/lib/cgi-bin/test.py: sudo gedit /usr/lib/cgi-bin/test.py Copy the following content to this file: #!/usr/bin/python3 print ("Content-type: text/html") print ("") print ("") print ("<html><head>") print ("") print ("</head><body>")...
Loading...
X