I am using urllib to get a string of html from a website and need to put each word in the html document into a list. Here is the code I have so far. I keep getting an error. I have also copied the error below. Here is the error. Answer str.replace is the wrong function for what you want
Tag: python
cvtcolor in Cv2 – no attribute
I’m writing a program to collect a series of images from a USB microscope and generate an average as a way of denoising. I’m having to convert the image into a numpy array, sum the pixels then divide before converting back to an image. Somewhere along the line the channels get mixed so my output i…
Module dependency graph in Python 3
How do I graph module dependencies in Python 3? I found snakefood, but it seems to only work with Python 2. Answer I built a tool based on pydeps here.
Python unittest not recognizing tests
I’m trying to learn how to use the unittest framework in python. I keep getting the message below when I run my file containing the tests. I’ve searched here and elsewhere and can’t figure out why it is not recognizing the tests. Each test starts with test and the other portions of the unitt…
Django REST Framework and FileField absolute url
I’ve defined a simple Django app that includes the following model: (Technically yes, that could have been an ImageField.) In a template, it’s easy enough to include the MEDIA_URL value (duly coded in settings.py) as a prefix to the thumbnail URL. The following works fine: Using DRF, I’ve de…
Force NumPy ndarray to take ownership of its memory in Cython
Following this answer to “Can I force a numpy ndarray to take ownership of its memory?” I attempted to use the Python C API function PyArray_ENABLEFLAGS through Cython’s NumPy wrapper and found it is not exposed. The following attempt to expose it manually (this is just a minimum example rep…
Problems with decoding from command prompt [python]
I have the following problem. I have a german text saved in .txt UTF-8 format, and I’d like to print it out with python. Here’s my code: It works perfectly in IDLE, but when I save my code and run it from the command prompt, it raises error, specifically: In my particular case, the text is “…
Antialiasing shapes in Pygame
I’m using Pygame to draw some things. The problem is that they have a lot of aliased edges: I want to make them softer, like this: My idea so far was to draw the shape in double size, and then use to shrink it to the size I want. Unfortunately if I’m drawing my shapes on a transparent surface, the
Python quicksort – one list – swaps
**I need to make a quicksort algorithm but so that it uses only one list and does swaps inside of it. I managed to make it “sort” or position the first element but now i don’t know how to implement the recursion. The biggest problem I’m having is how to recursively work on a part of th…
Can I change the title bar in Tkinter?
I’m using Tkinter as GUI for my program, but as I see, many programs don’t have standard look as Tkinter does. By standard look I mean standard title bar, borders, etc. For example, Tkinter’s title bar: vs GitHub’s title bar: See how they have their own custom exit, resize and minimize…