What Do You Think?

We welcome ideas, suggestions, feedback, and the occasional rant about the book. Did you find a topic confusing? Or did you find an error in the text or code? Did we omit a topic you would love to know more about? Drop us a line!

Your feedback really helps make this book an even better learning resource for Pythonistas around the globe.

Whatever the reason, good or bad, please send in your feedback at the link below:

realpython.com/python-basics/feedback

Avatar image for gearhorn

gearhorn on Sept. 16, 2019

there is a part in the 4.2 section where it has the code final_index = len(user_input) - 1 last_character = user_input[final_index] sorry for some reason when i put the last part in [ ] it underlined it, anyway that part gives the error user_input is not defined

Avatar image for Dan Bader

Dan Bader RP Team on Sept. 16, 2019

@gearhorn:

That’s because to make the example work you need to assign a value to user_input first:

For example, suppose a string input by a user is assigned to the variable user_input.

For example, you could do something like this:

user_input = input("Enter some text and press return: ")

Hope this helps you out :)

Avatar image for artuvil

artuvil on Sept. 30, 2019

I am excited to give it a try! I have read many hints in the open forum and now I’ll like to dig in.

Avatar image for hitoyano

hitoyano on March 21, 2020

Hello, I’m new to programming and to python. I’m using your latest version (feb. 2020) of the book to learn the basics but I’m not sure if it’s my lack of knowledge or a type-o. In section 12.6, the review exercise 2 says:

“2. Write a script that reads the numbers in the numbers.csv file from Exercise 1 into a list of lists of integers called numbers. Print the list of lists. Your output should like the following: [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]”

This is also related to an example on page 379. I even looked at the answer on your git.

It gives me this error: int_row = [int(num) for num in row] ValueError: invalid literal for int() with base 10: ‘[1, 2, 3, 4, 5]’

Is the answer correct on your git? Thanks

Avatar image for David Amos

David Amos on March 21, 2020

Hi @hitoyano!

Hmmm… I just double checked and the solution for that exercise does not produce that error for me.

The error message is telling you that the string '[1, 2, 3, 4, 5]' can’t be convert to an int, which tells me that the variable num is somehow assigned the string value '[1, 2, 3, 4, 5]'.

That must mean that row is assigned to a list of strings, or possibly even the file handler itself.

The solution on GitHub uses the csv.reader class to read rows from the CSV file made in Exercise 1 as lists of strings:

numbers = []

with file_path.open(mode="r", encoding="utf-8") as file:
    reader = csv.reader(file)
    for row in reader:  # <-- Each `row` is a list of strings, like ['1', '2', '3', '4', '5']
        int_row = [int(num) for num in row]
        numbers.append(int_row)

print(numbers)

When you execute that code (in conjunction with the code from the solution for Exercise 1), then no error is raised and the output displays a list of lists containing the numbers in the CSV file.

Does that code look the same as the code that produced the error for you?

Avatar image for hitoyano

hitoyano on March 21, 2020

Hello David Amos

I’ve executed exercise 1 successfully. I keep getting the same error for exercise 2 even if I use the solution found on git and above.

numb = []

with file_path.open(mode="r", encoding="utf-8") as file:
    reader = csv.reader(file)
    for row in reader:
        int_row = [int(num) for num in row]
        numb.append(int_row)
print(numb)

From the error I’ve deduced that for some reason the data cannot be converted to an integer. So, I suspect that it is already converted to int. I modified the code with the assumption that the numbers list is already an integer and therefore not having to convert it integer.

numb = []

with file_path.open(mode="r", encoding="utf-8") as file:
    reader = csv.reader(file)
    for row in reader:
        #int_row = [int(num) for num in row]
        numb.append(row)
print(numb)

The result is the following:

[[‘[1, 2, 3, 4, 5]’, ‘[6, 7, 8, 9, 10]’, ‘[11, 12, 13, 14, 15]’], []]

I´m not sure the reason why and if what I´ve done is correct I´m not sure why I seem to get an empty list at the end of the list. I´m still a bit confused.

I use windows 10 and I’m using python 3.8 idle to do these exercises if that matters.

Does that shed you any light as to what is happening or why I cannot get the same answer with your code.

Avatar image for David Amos

David Amos on March 25, 2020

Hey @hitoyano, are you on the Community Slack? If so, send me a DM there and I can try to help you out further. Thanks!

Avatar image for bob4kay7

bob4kay7 on March 30, 2020

Thanks for putting together this great book. I actually love every bit of the chapters I have read. Hopping to drop more comments as soon as I go through more chapters.

Avatar image for avalidzy

avalidzy on April 3, 2020

Where is my Python Basics book pdf? Paid for and downloaded and can’t find it. Been going through several loops ads for the book.

Avatar image for Dan Bader

Dan Bader RP Team on April 3, 2020

@avalidzy: The book files are available for download on the Download Book Files menu item listed at realpython.com/courses/python-basics-book/

Avatar image for JulioPDX

JulioPDX on April 30, 2020

Section 12.3, Missing pattern match when converting to list. Book

for path in new_dir.glob(".txt"):
    print(path)

list(new_dir.glob())

# should be
list(new_dir.glob("*.txt")
Avatar image for JulioPDX

JulioPDX on April 30, 2020

Correction

for path in new_dir.glob("*.txt"):
    print(path)
Avatar image for JulioPDX

JulioPDX on May 4, 2020

Section 12.6, Book states file_path = Path.home() / “temperatures.txt” “This creates a file called temperatures.csv in your home directory”

Should be file_path = Path.home() / “temperatures.csv”

Avatar image for JulioPDX

JulioPDX on May 4, 2020

12.6.1.1 Missing passing in the file object to csv.writer

Book

writer = csv.writer()

Should be

writer = csv.writer(file)
Avatar image for odunayo123

odunayo123 on July 18, 2020

Am trying learn more of python and automate with Python and be the best.

Avatar image for Dan Bader

Dan Bader RP Team on Nov. 7, 2023

Just to get some closure here – all of these issues have been corrected in the release version. Thanks to again everyone who submitted their “early access” feedback here, through the feedback form and links in the book, and Slack!

You must own this product to join the conversation.