Posts by Giovanni Nunes • 2,638 points
141 posts
- 
		1 votes1 answer29 viewsA: Relationship 1:N mongoDBOops! Well, I don’t have an exact idea about how you’re thinking about modeling but according to the Mongodb* people the recommendation for 1:N relationships is embedding rather than referencing,… 
- 
		0 votes2 answers289 viewsA: Django create paging using AjaxDjango even has a pager that can be used but it will not do as you want, so the tip is to use Django REST Framework along with some solution in JS, for example Datatables (in this case it is… 
- 
		1 votes2 answers142 viewsA: BUILD FAILED (Ubuntu 20.04 using ruby-build 20210420) - Ruby year install error using asdfYou don’t have the GNU Make installed, at least the script configuration, the configure, stopped at this point. Install it with: sudo apt install make And as you are compiled something for Ruby I… rubyanswered Giovanni Nunes 2,638
- 
		0 votes1 answer56 viewsA: Insert edge into graphBased on the description of the CSV you have passed and considering that I do not know what will be done after edges and vertices are defined, I opted for an approach with a smaller number of… 
- 
		1 votes1 answer51 viewsA: Sqlite database conflict when merging into gitThe Git is trying to versioning the database file, a binary, and then generating a conflict that it cannot solve easily (and much less securely) and for this, and other reasons, should not be… 
- 
		0 votes1 answer28 viewsA: You’re not saving the picture on the wayThe field ImageField requires the installation of the library Pillow so that it can validate the image but if you do not want/can install it replace the ImageField for FileField on the model: ...… 
- 
		2 votes1 answer56 viewsA: What is export for FLASK_APP and FLASK_ENV?These are environment variables that help Flask understand how to behave. The first,FLASK_APP can be left empty and then it will search for "app" or "wsgi" (with or without the ".py" at the end, ie… 
- 
		2 votes1 answer76 viewsA: How to receive user data and return function value using flask?Your "problem" is not right in Python but in HTML. It turns out that the attribute action does not exist in <button> (<button>: The Button element) and yes in <form>, then your… 
- 
		0 votes1 answer28 viewsA: How to treat a function value as an existing variable?The ideal solution would be to create an object to store the position and other attributes of the balls, for example: VERMELHO = (255, 0, 0,) class Bola: def __init__(self, x, y, tamanho, cor):… 
- 
		1 votes1 answer172 viewsA: How to sort a dictionary list alphabetically and generate new dictionaries with if condition with Python?Oops! There is a problem in the design of your program because you are not storing name, age and phone in a dictionary and yes, storing names, ages and phones not related to each other. I mean,… pythonanswered Giovanni Nunes 2,638
- 
		2 votes1 answer44 viewsA: I can’t understand that kind of importThe first import will load the module pygame within the scope (namespace) of your file/module while the second will only load the class "Sprite" in it. Actually the second import is there as a… 
- 
		7 votes3 answers228 viewsA: Compare two lists in python and return matchesThe simplest way is by using a comprehensilist on. uma_lista = [1, 2, 3, 4,] outra_lista = [3, 4, 5, 6,] iguais = [elemento for elemento in uma_lista if elemento in outra_lista] This command will… 
- 
		11 votes3 answers171 viewsA: Does the function not return the minimum value?In fact the problem is not in its function but in how the list of numbers is being passed to it: t = input("Digite sua lista: ") print(min_max(t)) This is sending a string and not a list, so your… 
- 
		1 votes1 answer38 viewsA: Compare two lists element by element:How would you do it manually? That is, you would compare the list item by item. If the item of the same index of the first list is equal to the one of the second you notify that they are equal,… 
- 
		2 votes2 answers53 viewsA: Browse and collect data from dictionaries within a listYou can do it in several ways, for example you could package this data in a class but as you said already have separate functions a simple way to do it is like this: meus_dados = [ {'sexo': 'M',… 
- 
		2 votes1 answer54 viewsA: Removing strings from within a listIt is that so you are creating a list of XLRD objects, do this way to recover only the values: lista = list() for i in range(1,worksheet.nrows): lista.append( [j.value for j in worksheet.row(i)] )… 
- 
		1 votes2 answers409 viewsA: Save Date and Time File in Python NameYou’re using the bar ("/") in the file name and if you are using Linux, macOS or some UNIX derivative your date will be considered as part of the file path and not its name. And in Windows NTFS the… 
- 
		2 votes1 answer87 viewsA: Python rest_framework how to change URL?In "views.py" in the class definition it should be something like CreatureViewSet() you must put the attribute lookup_field with the value of the field you want to use: class CreatureViewSet(...):… 
- 
		3 votes1 answer208 viewsA: How to use a global variable in a python function?You do not need to use global variables (which is not good practice) but correctly define the class you built: from main import player from random import randint p1 = player class Item: # # -->… 
- 
		6 votes2 answers74 viewsA: What it really means "from modulox import *"You don’t matter twice. Using the asterisk does not necessarily mean that you will import all available classes, functions or variables within a module. Then we have two cases... The variable was… 
- 
		0 votes1 answer40 viewsA: Nested structure giving errorSimplify logic, remember that knowing if you are "person" or "people" during the loop is irrelevant since this information will change with each loop execution for. It’s information that only… 
- 
		0 votes2 answers196 viewsA: How to display object name in Django template?Add to the class Editora the method__str__(), something like that: class Editora(models.Model): ... def __str__(self): return self.nome_editora This will make the Django learn how to correctly… 
- 
		0 votes2 answers1733 viewsA: Function that returns all combinations of a stringSpecifically in the case of Python you can use the itertools.: from itertools import combinations all_combinations = set() my_string = "pernambuco" # <- já não tem repetições de caracteres for i… pythonanswered Giovanni Nunes 2,638
- 
		2 votes1 answer131 viewsA: How to write a python module from a test?It is possible to obtain this result in several ways, this one is one of them. Starting with the class design, or better, classes: """ GoogleDriver.py """ class GoogleDriver: """ The GoogleDriver… 
- 
		2 votes2 answers405 viewsA: Ignoring a line from a txt fileIssue of order of commands, you are transforming the string read in a list and then comparing but as the lists do not have the method .find() you get an error message. Based on your function a step… 
- 
		1 votes1 answer904 viewsA: Error NoreversematchYou are sending parameters on template and also receiving them in view but there is no route at urls which satisfies this condition, thus adding the parameters to it. url(… 
- 
		2 votes1 answer156 viewsA: None return problem in pythonIn fact you were printing the return of the function main() (the print(main(...))), but this function writes several things but returns no value. There is no return in the end passing values to… pythonanswered Giovanni Nunes 2,638
- 
		0 votes1 answer70 viewsA: How to return an attribute from a class based on the minimum and maximum of other attributes of the array?Your modeling won’t help you much to differentiate one element from the other, they’re all elements within a list, you can use the attribute index() to find out the position of the value you… 
- 
		1 votes2 answers52 viewsA: How I write in Python documents on ForJust improving the answer already given, some tips. You can use the with when defining the file Handler in a proper scope and so need not close it from the arquivo.close() in the end. with… pythonanswered Giovanni Nunes 2,638
- 
		4 votes3 answers472 viewsA: How to add a new key to a dictionary?You can leave the dictionary empty and keep adding the keys as needed, something like this: def contabiliza_letras(string): dict = {} for letra in string: if not letra == " ": dict[letra] =… pythonanswered Giovanni Nunes 2,638
- 
		3 votes1 answer598 viewsA: Django request.GETThe simplest way is: id_parada = request.GET.get("id_parada", "") In this case you are using the method .get() to retrieve the contents of the key id_parada in request.GET and, if it does not exist,… 
- 
		1 votes1 answer53 viewsA: Dates in pythonBut Time is a variable (by the way, python variables, by convention, should use lower case letters), hence its content will always have the same value (in this case always the same string defined at… 
- 
		0 votes1 answer328 viewsA: Keyerror: 'A secret key is required to use CSRF.'You need to put {{ form.csrf_token }} to include the token, he needs to stay inside the tags <FORM>...</FORM> of your form. By the way, both are missing from the example you published.… 
- 
		2 votes1 answer350 viewsA: Update in a specific field in Django 2.0What you did was change the method You need to load the desired record, for example the ID 3: minha_venda = Venda.objects.get(id=3) From there, you can change the fields you want:… 
- 
		0 votes1 answer57 viewsA: Error creating Django filterAccording to the documentation of Django REST Framework, you must pass the parameters inside a tuple instead of a list, i.e.: filter_backends = (SearchFilter,) search_fields =… 
- 
		0 votes2 answers123 viewsA: How to make an associative matrix in python 3?You can work directly with a dictionary, ie: matriz_assoc = { "a": [ 1, 2, 3, ], "b": [ 4, 5, 6, ], "c": [ 7, 8, 9, ] } And to access your content you will use: print(matriz_assoc["a"][0]) 1 Of… 
- 
		0 votes1 answer5140 viewsA: Update version of PythonIn Windows Python is a program that is installed in part, not being part of the operating system as it happens in the Linux, BSD, etc distributions -- something similar happens with macOS X --, so… python-3.xanswered Giovanni Nunes 2,638
- 
		0 votes1 answer48 viewsA: Save log to application folderHow you just set the file as Log.txt it will save you the directory where you started the application, the simplest way to solve the problem is from os import path # ... log_file =… pythonanswered Giovanni Nunes 2,638
- 
		-1 votes2 answers50 viewsA: Error in Python method call (list)I reformatted your code and created a routine to use your class: cost = CloudCost() for mes in range(1,12): print(cost.month(10, mes)) And everything worked normally and the method was invoked:… pythonanswered Giovanni Nunes 2,638
- 
		2 votes1 answer1442 viewsA: Pick a select value in DjangoFrom the point of view of good data modeling you should have defined in Models an association between Aparelho and Fabricante (since an appliance is produced by a manufacturer) but the little that… 
- 
		1 votes1 answer178 viewsA: How to indent a yaml file using regular expression?Notice that the spaces are just inside your string: yaml_content = """ MAIN : PROD : {} LOCATION : {} EXTRA : LOLO : {} """.format(PROD, LOCATION, LOLO) And the easiest way to solve this would be to… 
- 
		1 votes1 answer37 viewsA: Heroku python file deployment failedCurrently the Heroku supports only versions 2.7.17, 3.7.2 and 3.6.8 of Python, the latter being 3.6.8, defined by default and you can only use these versions. You can find more details on… 
- 
		3 votes2 answers124 viewsA: How to read the Git help manual?Actually, Andre, the git as a tool is much more complex than this preview of what can be done demonstrates. To use the tool you will initially need to understand some basic concepts like:… 
- 
		0 votes1 answer133 viewsA: Create dialog in DjangoYour form is not invoking the view, then it does not perform the task. You forgot to put the action="{% url 'remover_cliente' %}" within the tag form.… 
- 
		1 votes1 answer47 viewsA: Invalid block tagAs tags {% ... %} are unique to the templates system commands Django (whatever comes embedded in it, whether using the Jinja2). To create a new variable within the template, use the tag {% with ...… 
- 
		2 votes1 answer121 viewsA: Problem passing argument via Python command lineSpecifically in this case, the interpreter is understanding that the program is a shell script and not a program in Python. Add the shabang -- Be the #!/usr/bin/python or #!/usr/bin/env pythom -- at… 
- 
		2 votes2 answers82 viewsA: Instantiate class by passing only a few parameters in Python 3If you have many arguments that need to be passed to a class, or even a function, it is recommended that you take another approach than positional arguments. Maybe keep nome as a positional (and… 
- 
		2 votes1 answer1137 viewsA: Remove character in Shell ScriptThere are several ways to do this and one of them, using the cut, would be: echo "OrclLog,1: Number of rows inserted on the current node: 66." |\ cut -d":" -f3 | cut -d"." -f1 And the result would… 
- 
		7 votes1 answer812 viewsA: Is it possible to have a split() with two or more conditions in Python?You can use the regex.split() that uses a regular expression to mount the separator. For example: import re a = "a,b.c|d" re.split("[,\.|-]",a) That will return the list: ['a', 'b', 'c', 'd']… 
- 
		3 votes1 answer76 viewsA: When I hit the word, an input still appears at the endThe error is related to how you mounted the loop while: # Programa--------------------------- while True: mostra_palavra() if erros > 7 or "_" not in palavra_a_mostrar: break resposta =…