Posts by Sidon • 6,563 points
288 posts
-
0
votes3
answers78
viewsA: Insert a list into a database made with Django
Italo’s response has a number of caveats, such as not working in many relationship to many. See in the documentation, then I put one more option: from <nome-do-pacote> import Usuario lista =…
-
2
votes3
answers516
viewsA: How to compare two JSON objects with the same elements in Python
If I understand correctly, the first thing you should do is make sure that the two return the same number of elements and that you have the keys that you want to compare, in a test using your own…
-
0
votes5
answers6866
viewsA: Indicate whether a character is a vowel or a consonant
To complement the answers already posted, I present three solutions, one that includes "pure" vowels the second, "accented" vowels, and the third returns if it is vowel or consonant, all consider…
-
2
votes3
answers354
viewsA: How to hide sensitive information in Django?
I don’t fully understand the question, for example: I can’t see Django’s relationship with Docker in this context, but I will try to answer. If I understand, what you want is to hide sensitive…
-
2
votes1
answer103
viewsA: Variable declaration in Python
In reality this "problem" is not related to the "declaring variables in python", it is just a kind of preciousness of pycharm, some time ago I found interesting this Feature, but after I joined a…
-
-1
votes1
answer234
viewsA: CSV file reading and vector line storage
TL;DR If I got it right, Voce can do using Dataframe pandas to read the file and then convert the values to type list python. I created an example to show this, as Voce did not exemplify csv, I…
-
1
votes1
answer135
viewsA: How does Django’s standard connection mechanism work?
Preambulo: Django tries to support as many resources as possible in all database backends. However, not all backends are equal and the solution was to make design decisions about what features…
-
2
votes1
answer282
viewsA: Deploy python Django project to Heroku. I’m having errors
See the end of the error message: EMAIL_PORT, EMAIL_USE_TLS ModuleNotFoundError: No module named 'mjsolutions.configs.configs' That is, Voce is calling a module that, although probably installed in…
-
1
votes2
answers85
viewsA: How to make the user re-enter the numbers at the beginning of the program?
Using your own code I made a change to do what you want, test: while True: print('''\033[4;33mOlá, Sr. Usuário!\033[m \033[4mDigite dois valores abaixo para fazer os cálculos:\033[m''') print('\n')…
-
1
votes1
answer190
viewsA: Normalizing values, what am I missing?
I’m not sure if the term for what you want is "normalize" by the terms used in the sklearn I believe the most appropriate term would be scale (or something similar), see the example: import numpy as…
-
1
votes1
answer62
viewsA: Receive user data from
TL;DR Your mistake is that you didn’t implement the second option, I’ll leave an example below, a little different from yours, but it’s just you adapt. To be simpler I’m not making consistences of…
-
2
votes1
answer593
viewsA: Formatting Django decimal number template
Add in Settings (considering your other settings, no need for humanize): THOUSAND_SEPARATOR='.', USE_THOUSAND_SEPARATOR=True In the template: {% load l10n %} ... {{valor | floatformat:2}} Example of…
-
0
votes2
answers253
viewsA: K-Means Algorithm
TL;DR Based on the simplicity of the question: Convert the data to numeric or create a new variable of the numeric type based on the categorical that you have, I do not know what you are using for…
-
0
votes1
answer705
viewsA: Last record of each Django object
As in Django there are several contexts, I will try to explain with your own example but in a Django console, if you want to try, enter a python console (in the environment and directory of your…
-
2
votes1
answer888
viewsA: Register different types of users in Django admin
TL;DR If I understood you do not need the inline, just register the Student and Teacher normally in admin, see if this is it: py.models: from django.db import models from django.contrib.auth.models…
-
0
votes2
answers6846
viewsA: How to cut string text in python by delimiting the initial substring to the final position?
Slicing in python Python has a very interesting and easy-to-use Feature called "slicing" which can be useful for getting sub-string from strings, before working directly with strings, let’s see how…
-
1
votes2
answers1430
viewsA: .get in Python 3
In this example,Mapa_De_Digitos is a dictionary type objetto, to see the type of an object use, type(): type(Mapa_De_Digitos) Out[7]: dict In case the get() is one of the methods of the class that…
-
0
votes2
answers978
viewsA: How to return a json to the same Django template?
After an exchange of information in the comments/chat, I understood the goal, what you want, essentially, is to run something in the back end return to the front end without the re-rendering of the…
-
3
votes3
answers991
viewsA: Showing only pairs in the list - Python
Thus: Using list comprehension: number = int(input('digite o numero: ')) lst= [n for n in range(number+1) if n%2==0] print('','list comprehension:',lst, sep='\n') Using the loop for: # usando for…
-
1
votes1
answer297
viewsA: Save a file using a view function on Django
I don’t know if there are errors in the back end (this is the problem of the Jango abstraction level, hard to detect errors without knowing the context), but something is missing in the front end.…
-
1
votes1
answer43
viewsA: Problem with case in script
As I recall the case does not recognize ranges, try so: if ((6<=$CORTE && $CORTE<=11)); then echo "Bom dia!" elif ((12<=$CORTE && $CORTE<=17)); then echo "Boa tarde!"…
-
2
votes2
answers335
viewsA: Operations sum and multiplication of integer numbers in Python list
Thus: elements = input("Enter only 5 numbers: ") list = elements.split() # Acresente essa linha list[1], list[4] = int(list[1])*3, int(list[4])+5 inverse_list = list[::-1] print (inverse_list)…
-
2
votes2
answers3821
viewsA: Python iloc[] function (Pandas)
Adapted from documentation: Dataframe.iloc Indexing purely localization-based integers for selection by position. iloc[] is basically based on placements represented by integers (from 0 to the axis…
-
1
votes2
answers138
viewsA: List in Python
Starting from the premise that the user will type the numbers separated by spaces, that is, since it has to be on the same line, it is not possible to check each typing (you could do the checking…
-
1
votes3
answers503
viewsA: Combination of values for sample selection
TL;DR A solution with pandas, I used the data of your example but added the brands to demonstrate the filtering, eliminating the lines with the brand "bar": import io import pandas as pd from…
-
1
votes1
answer439
viewsA: Filters in TXT file
TL;DR If I understand correctly, you want to read the file and then select lines in which a certain word appears in a certain column. I took a part of the text you put in the question I put the word…
-
2
votes1
answer14334
viewsA: Dataframe - Pandas. Creating new column after comparison between columns
TL;DR In the image of your example, there is no conicity between the columns LOCALIDADEand ds_cidade, so I created a DataFrame where one of the rows has these conicised columns, then I create a new…
-
0
votes1
answer80
viewsA: Error when using Getoldtweets3 filter for a certain period
TL;DR What’s going on is that depending on the period the line tweet = got.manager.TweetManager.getTweets(tweetCriteria) is bringing a number of tweets greater than what you set out to max_tweets…
-
2
votes2
answers883
viewsA: Decimal places in Django template
You can change this in your file settings.py, but note that for our system the "correct", is to separate decimal places with commas and not with point, the topic Format localization in the…
-
4
votes2
answers1897
viewsA: Django - Null and Blank Difference
If you define null=True (unlike NOT NULL) in a field of your template (a BD column), when entering empty values for types like DateTimeField and ForeignKey will be stored as NULL in your BD, this is…
-
6
votes2
answers1136
viewsA: What is the purpose of using "Else" together with Try/except in Python?
Clause else the misunderstood and despised. Always when we think about else associate immediately with blocks if, as Luciano Ramalho says in his book Python fluent, "The clause else is an underused…
-
0
votes2
answers60
viewsA: How to create variables dynamically (Speech_recognition)
From what I understand you know how many blocos of 30s are, if so, a way to do this would be, as suggested, to keep on a list, let’s say we know beforehand that there are 10 blocks: audios = [] with…
-
0
votes2
answers525
viewsA: Find and Extract a line or words from a source code with Python 3
A way to get what you want: import urllib.request url = "https://www.youtube.com/watch?v=2MpUj-Aua48" f = urllib.request.urlopen(url) alvo = None lines = f.readlines() for line in lines: if…
-
0
votes1
answer256
viewsA: Error when registering user in Django
I understand you need to just extend the User adding some fields, without necessarily changing anything in the auth, I mean, you’re not customizing the authentication, right? but I couldn’t…
-
3
votes4
answers461
viewsA: How can a group of parameters be required if at least one of them is informed?
TL;DR To specifically answer the question, go straight to the topic "Specifically answering the question." In Python we can call functions, sending "positional" and/or "named" arguments, to…
-
0
votes3
answers4376
viewsA: Current date and time in time zone timestamp format
Convert to Timezone, replace Timezone (:-)) with Z, add T. from datetime import datetime, timedelta current_time = (datetime.now()) print(print(str(current_time)[0:19].replace(' ','T'))) Saida (when…
-
2
votes1
answer514
viewsA: How to write a __init__ file in Python 3?
Up to python 3.3 the files __init__.py denote namespaces for python packages. PEP 420 makes explicit in its Abstract "namespaces are mechanisms for separating a python package into several…
-
1
votes4
answers361
viewsA: Python Code - Conditional Structure
TL;DR My suggestion consists of a function that can receive the percentages for the bonuses as optional parameters and returns a dictionary with the values informed by the user and the calculations…
-
2
votes1
answer1417
viewsA: Move python files to another folder in another directory
You can move and rename in a single command, both with the os.rename as with the shutil.move import os import shutil # Movendo e renomeando com os.rename os.rename('diretorio/origem/nome-arquivo',…
-
0
votes1
answer414
viewsA: Run Python code by calling for a Django form
TL;DR If I understand correctly, just check in the view if your request uses the POST method, if yes, do the necessary processing and return the resulated. In the example below I create a template…
-
1
votes3
answers11645
viewsA: Using Groupby in Pandas dataframe
TL;DR Edited Rereading the question I saw that the author of the question had achieved what he wanted but said that the result is an object and that the names become indices, or something similar. I…
-
0
votes2
answers470
viewsA: read the elements of an input matrix
TL;DR Just read it? The code below creates a list of dictionaries and stores the number 1, 11, 2 and 22 in the lists in each position of the matrix: dicts = [] for n_lst in range(len(matriz)): lst =…
-
1
votes1
answer769
viewsA: You can return the id of the last data registered with Django Model Form
You can take the id from the register you just registered, let’s say you have a model named after Item, with the fields descricao and quantidade atual, so you register an item and can already pick,…
-
0
votes1
answer68
viewsA: How to concatenate variables into a Django template
Use the filter add: {% block content %} {% for item in itens_lista %} <div class="post"> <h1><a href="">{{item.COD_ITEM | add:" - " | add:item.DESCR_ITEM}}</a></h1>…
-
1
votes1
answer103
viewsA: Remove a value from a list
In python you define a list like this: vet = [] To add elements in the list via inputs you can do for i in range(3): vet.append(int(input('Digite um valor: '))) Let’s say the user typed 10, 20, 30,…
-
0
votes1
answer413
viewsA: Automatic update of the related model through FK - Django
I do not see the need to use Signals, in fact when I see someone using always remember a phrase: "Signals is a powerful resource that should never be used". There are several ways to do what you…
-
1
votes2
answers1298
viewsA: How to create a dictionary through a string
Putting into practice the idea presented in the comments of the question: First let’s create a function that receives a list of dictionaries and a key, through the key the dictionary is returned:…
-
1
votes1
answer7196
viewsA: Modulenotfounderror: No module named 'authorizations'
See if it works like this: 1) Create the initial structure (Abaixos commands are for linux) $ mkdir -p gestao/aplicacao/autorizacoes 2) Create the files __init__.py $ touch gestao/__init__.py $…
-
2
votes2
answers370
viewsA: How to verify which numbers of a matrix are primes?
To make it easier, I will exemplify with pure lists of python and not matrices, but the solution can be easily adapted to matrices. First let’s create a function to check whether a number is prime…
-
0
votes1
answer269
viewsA: Python lib to convert PDF/EPUB to txt
I’ve used several libs for this, the one that gave me the best results, was Tika, to install: pip install tika Utilizing: from tika import parser file = 'path/to/file' # Fazendo parse data =…