Skip to content

Tag: python

Replacing character in string doesn’t do anything

I have a list like this, Expected output: Removing the brackets is easy by using .replace(), but I don’t want to remove the brackets from strings (#) and (##). my code: but this doesn’t remove the brackets from the words. Answer You can use re.sub. In particular, note that it can take a function a…

How to import API data using Pandas?

I am trying to pull some data from EIA API, below is what I tried but I’m getting the error on the first line of code: AttributeError: ‘str’ object has no attribute ‘text’ Any help would be much appreciated! Answer You haven’t requested anything from the API. Look carefully…

Django Rendering Form in HTML Issue

I’m attempting to render a form, in html and have tried the normal {{ form }}. However when I go to the site set up by: python manage.py runserver. I get the following where the form should go (highlighted section on screen-capture) webpage This is the code for the form in question. forms.py This is the…

Creating a word length frequency table in python

I have the following code: Without importing anything else, how would I make a table which prints the length and then the frequency. For example: In a file with the text of “a blah ba ba” it would print: What confuses me about this is how to add all the length of the words together, should I be ma…

django FieldError: Cannot resolve keyword ‘category_name_contains’ into field. Choices are: category, description, id, image, name, order, price

I want to build a food delivering app, but facing this error. “FieldError: Cannot resolve keyword ‘category_name_contains’ into field. Choices are: catego ry, description, id, image, name, order, price”. This is the query.py: This is the views.py This is my models.py: Here’s the …

Best way of getting Qt pushbuttons Icons information in python?

Im developing a PyQt application which modifies buttons icons dynamically. The icons are created with QStyle, stored as class parameters and then put into the buttons with the setIcon() method. Since the icons are modified dynamically, i want an elegant way of checking what is the current button icon. The ori…