So I’m trying to create a flood fill algorithm and I keep getting a recursion error with this. The algorithm seems to have infinite recursion and I cannot pinpoint why. I have looked all over the internet and I cannot find a solution as it seems like my program is correct according to most sources. Ther…
Tag: python
PyCharm shows unresolved references error for valid code
I am using PyCharm to work on a project. The project is opened and configured with an interpreter, and can run successfully. The remote interpreter paths are mapped properly. This seems to be the correct configuration, but PyCharm is highlighting my valid code with “unresolved reference” errors, e…
Why do up and down arrow commands not work in the Python command line interpreter?
I am using a VT100 terminal emulator on Linux. In bash, up and down arrows scroll through the last commands executed; they work as expected. Previous (up arrow) and next (down arrow) commands are not interpreted in the Python command line interpreter. What kind of key mappings do I need to make this work? Tha…
Print series of prime numbers in python
I was having issues in printing a series of prime numbers from one to hundred. I can’t figure our what’s wrong with my code. Here’s what I wrote; it prints all the odd numbers instead of primes: Answer You need to check all numbers from 2 to n-1 (to sqrt(n) actually, but ok, let it be n). If…
Allowing resizing window pyGame
I am trying to allow resizing for this app, I put the RESIZABLE flag, but when I try to resize, it messes up! Try my code. It is a grid program, when the window resizes I want the grid to also resize/shrink. Please tell me whats wrong, thanks. Answer You are not updating your width, height, or size when the
Install psycopg2 on Ubuntu
I’m trying to get the python postgres client module installed on Ubuntu 12.04. The guidance is to do the following: However, apt says that the package can’t be located. I’m keen to install this through apt. Is this part of another package that I can install? Answer Using Ubuntu 12.04 it appe…
Sending data from HTML form to a Python script in Flask
I have the code below in my Python script: Also, I have an HTML form in init.html: How can I pass the user input from “projectFilepath” when a user clicks “spotButton” on a variable in my python script? I’m new in Python and Flask, so forgive me if I make any mistakes. Answer The…
Why do we need the “finally” clause in Python?
I am not sure why we need finally in try…except…finally statements. In my opinion, this code block is the same with this one using finally: Am I missing something? Answer It makes a difference if you return early: Compare to this: Other situations that can cause differences: If an exception is thr…
Adding an attribute to a Python dictionary from the standard library
I was wondering if you could add an attribute to a Python dictionary? Is there anyway to quickly add my description attribute without having to copy the dict class and overloading the constructor. I thought it would be simple, but I guess I was wrong. Answer Just derive from dict: Instances of MyDict behave l…
How to use multiprocessing queue in Python?
I’m having much trouble trying to understand just how the multiprocessing queue works on python and how to implement it. Lets say I have two python modules that access data from a shared file, let’s call these two modules a writer and a reader. My plan is to have both the reader and writer put req…