How Do You Troubleshoot the pip Message ‘sys.stderr.write(f”ERROR: {exc}”)’?

Problem scenario
You run a pip command (e.g., pip –version), but ou get an error like this:

Traceback (most recent call last):
File “/home/mike/.local/bin/pip”, line 7, in
from pip._internal.cli.main import main
File “/home/mike/.local/lib/python3.*/site-packages/pip/_internal/cli/main.py” , line 60
sys.stderr.write(f”ERROR: {exc}”)

You no longer want to use Python 2 in on the server. What should you do?

Solution

1.a.

How Do You Use a Class in Python to Test The __init__ Constructor’s Default Settings?

Problem scenario
You want to instantiate a class with default values if the class was called to create an object without all the settings. You want to verify you know how to code this basic object-oriented programming feature. You want to print out specific member variables of an object. How do you do this?

Solution
Use this program:

#!/bin/python3

class Computer(object):
def __init__(self, …

How Do You Troubleshoot the Python Error “built-in method strip of str object at 0x7fc87bf4a0f0”?

Problem scenario
You are running a Python program with the “strip” string manipulation method. You get this problem:

<built-in method strip of str object at 0x7fc87bf4a0f0>

What should you do?

Solution
Did you remember to use the parentheses “()” with your strip call?

print(x.strip) can return “<built-in method strip of str object at 0x7fc87bf4a0f0>”

print(x.strip()) will return the intended value. …

Why Do Some Job Descriptions Emphasize Object-oriented Programming?

Question
Why do some job descriptions emphasize object-oriented programming as opposed to procedural programming, scripting or other alternatives?

Background
Some people think that OOP is overused in certain contexts (page 379 of Python 3 Object-Oriented Programming and page 1303 of Programming Python by Mark Lutz). For example OOP may not be ideal for something like regexing (or matching string patterns per page 247 of Python 3 Object-Oriented Programming).

How Do You Troubleshoot Maven Giving You an Error Such as “java.lang.OutOfMemoryError java heap space”?

Problem scenario
You are getting an error such as “java.lang.OutOfMemoryError java heap space”

You have plenty of swap space available, but this error persists. The problem is as if nothing is using swap space you know exists. Why won’t your Java program or Maven build utilize the swap space that is available to it?

Possible solution #1 (for Maven builds)
Run a command like one of these (but uncomment the second one if you want to commit roughly 5 GB of memory to the maven build):

export MAVEN_OPTS=-Xmx512m
# export MAVEN_OPTS=-Xmx5120m

Now retry your mvn command.

How Do You Use the Bisect Module in Python?

Problem scenario
You want to use bisect in Python. How do you do this?

Solution

# This program was adapted from code found
# https://docs.python.org/3/library/bisect.html

import bisect
def grade(score, breakpoints=[60, 70, 80, 90], grades=’FDCBA’):
i = bisect.bisect(breakpoints, score)
return grades[i]

x = [grade(score) for score in [71, 88, 94]]
print(x)

import bisect
def whether(temperature, breakpoints=[38, 70, 80, 100], descriptors=[”cold”, “cool”, “warm”, …

How Do You Troubleshoot “java.io.IOException: Stream closed at java.base/java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:442)”?

Problem scenario
You are trying to run a Hadoop job. You get this error:
“java.io.IOException: Stream closed at java.base/java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:442)”

What should you do?

Solution
Is the “python” command recognized as such? You may need to install Python or link the python3 binary to be in a typical location where env variables would look for it (e.g., /usr/bin/python).

Here are commands that could help you:

whereis python3
sudo ln -s python3 /bin/python

If you need help installing Python,

How Do You Solve the MacOS Command Line Error “No Java runtime present…”?

Problem scenario
Using a MacOS, you are trying to run a command (e.g., a “java” command) from the Terminal utility (character prompt). You get the message “No Java runtime present”, and the command fails. What should you do?

Solution
Using the GUI, download the .dmg file from here.

Once it is downloaded, double click it. Follow the menu steps (Continue ->

How Do You Iterate Through Two Lists of Unequal Length in Python?

Problem scenario
You want to iterate through two lists and perform some operation. The lists are not equal length. You want to iterate through them in some type of step-by-step fashion despite their lack of equality. What should you do?

Solution
Use this as an example:

list_a = [1, 2, 3]
list_b = [”dog”, “cat”, “rat”, “chicken”]

i = 0
j = 0

while (i < …