Most voted "python-3.x" questions
Python 3 is the latest version of the Python programming language and was formally released on December 3, 2008.
Learn more…3,274 questions
Sort by count of
-
2
votes0
answers182
viewsProblem with success_url in Django
In views I have the following classes class AdicionarPessoaView(CustomCreateView): template_name = "cadastro/adicionar.html" form_class = PessoaForm model = Pessoa obj = Pessoa.objects.all().count()…
-
2
votes1
answer44
viewsDjango model mapping problem
The relationship between the classes in the Models.py file does not work because of the order of the classes (I think it has more to do with the interpreter) follows the problem: class…
-
2
votes1
answer109
viewsChange configuration file by configparser remove_section
How to save the configuration file (.ini) after deleting an option or section? I’m doing it this way: test ini. [LOCAL] url = 'http://localhost:8080/' username = 'usuario' password = 'SECRET'…
-
2
votes1
answer1308
viewspython game of checkers
i have an array of a checkers game state, how can I know which pieces are threatened on the board? X5 is the threatened black parts and X6 is the threatened red parts, ie I want to know how to…
-
2
votes1
answer389
viewsRead and write binary files using STRUCT
I have an array valores = [16, -25, 34, 2, 199, 45, 67, 90]and need to save them in a binary file using struct. Then I need to read the binary file with struct. To read, I’m using the following…
-
2
votes2
answers580
viewsHow to collect data in web Crapping in Python?
Within of this URL, has several links , I have to take the links for the month of June 2017, download them and create a dataframe with all the files in one. But I stopped here at this part, how can…
-
2
votes2
answers98
viewsHow to pass a Dict within a function, to be used in any case if necessary?
Good afternoon, I have a big keyError problem, because in my program that makes use of Dict will perform several processes, and if at some point he does not find an item in which he looks, will…
-
2
votes3
answers208
viewsHow to configure Settings.py to use Django-tenant-schema?
I need to configure my Django to run llb django-tenant-schema My project does not create schemas and soon I cannot synchronize my bank with the project. I’m having trouble understanding how you are…
-
2
votes2
answers74
viewsHow do I know if a Shader is working?
Is my code right? I’m using Python and Pyglet, as I know if Shader is running, why did I get Shader’s code on the internet: import pyglet from pyglet.gl import * import pyshaders as ps t =…
-
2
votes2
answers2710
viewsConvert decimal to binary - python
Hello guys I’m new in python my code below displays the values of the ASCII table for a typed string. How can I take these values and convert to binary valor = input("Insira o valor a ser…
-
2
votes1
answer55
viewsRead file with list comprehension only works the first time
fhand = open('text.txt', mode = 'r') txtfile = [item.split()[0] for item in fhand] txtfile2 = [item.split()[1] for item in fhand] print(txtfile) print(txtfile2) Why the second comprehensilist on is…
-
2
votes1
answer971
viewsError "Indexerror: list assignment index out of range" when setting "l[0] ="
I’m having a problem in my class in function __init__() class Lutador(): __nome = "null" __nacionalidade = 'null' __idade = 0 __altura = 0.0 __peso = 0.0 __categoria = 'null' __vitorias = 0…
-
2
votes2
answers62
viewsRemove numbers and special characters from a text, but not within a word
I would like to remove numbers and/or special characters from a text, but not within a word. Example: texto = "ol@ mundo, eu bebo H20 e nao fumo cig@rro !#& 123" The result should be: ol@ mundo,…
-
2
votes2
answers329
viewsFunction that returns uppercase consonants
the function receives a sentence as input and returns the sentence with all its consonants in uppercase. def teste(frase): i=0 while i<len(frase): if frase[i]in 'bcdfghjklmnpqrstvxwyz':…
-
2
votes1
answer126
viewsHow does the life cycle and visibility of the Flask object work. g?
In Flask there’s an object called g or Flask.g that according to the documentation is used for data storage. And this object is used when assigning something to it. For example: def get_db(): if…
-
2
votes3
answers114
viewsHow to remove only spaces between words/letters?
Supposing I have a string: str = ' p s i c ó l o g o '. Note that the string has a space before the letters, a space between the letters and a space after the letters. What I want is for the spaces…
-
2
votes4
answers82
viewsHow do I create a list for possible answers in python?
Well... I wanted to make a list for possible user responses to input, for example: nom = str(input('Você gosta de mim? ')) lista = ['sim','claro','obvio'] if nom == lista: print('obrigado, bom…
-
2
votes1
answer1184
viewsManipulating 3 GB Dataset with Pandas using Chunks
Hello! I’m trying to work with a *.csv file using Pandas in Python3 embedded in a Googlecloud VM. This VM has 16GB of memory and even so gave Memoryerror. To solve this problem I used the attribute…
-
2
votes1
answer52
viewsIn a list list, how to sum each item of each list with the item of its respective position?
For ex my list is: x = [[1,2,3,4,5],[6,7,8,9]] How can I create a new list so that its elements are the sums of the corresponding elements in each list? y = [1+6,2+7,3+8,4+9,5+0]…
-
2
votes1
answer133
viewsPython - Brute Force - Memory Error
I am working on this code that generates sequences with all the possibilities of the characters entered(your_list) your_list = 'abcdefghijklmnopqrstuvwxyz' complete_list = [] for current in…
-
2
votes1
answer67
viewsHow to create a loss function in Keras that uses opencv?
I am developing a machine Learning model using the Keras library and realize that the available loss functions are not giving the best results in my test suite. I’m using an Unet architecture, where…
-
2
votes1
answer50
viewsIndex 3D arrays with Numpy
I have an array in three dimensions (x, y and z) and an address vector. This vector has a size equal to the x dimension of the array, and its objective is for each x to point a y bringing their…
-
2
votes1
answer991
viewsPython: remove double quotes from a list
Gentlemen(as), I need remove double quotes from each index in the list and, would like to remove each empty space, as well as remove that ' n' from the end of the list. lista = ['"11/07/2019"',…
python-3.xasked 5 years, 3 months ago Wilson Junior 182 -
2
votes1
answer1417
viewsMount SQL query in Python3 from data in a dictionary
I’m trying to format a query and leave it this way: INSERT INTO users('username', 'password') VALUES ('meuusuario', 'minhasenha') But you’re returning me with []: INSERT INTO users(['username',…
-
2
votes1
answer99
viewsTake an element from a list and search in another list
I am having a problem related to lists, I have some files to access and pass them to lists (3 files to 3 lists). Basically one of the files would have technical data of IBGE, and I need to take this…
-
2
votes1
answer479
viewsHow to format datetime in a Flask application?
How can I make it show only dd/mm/yy and take the hours and seconds in my database or templates? Database: class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True)…
-
2
votes1
answer353
viewsSumming numeric values in text files with Python
I am writing a small Python project that consists of an application that adds expenses, storing the name and value of expenses in a text file and printing on the command line, and at the end…
-
2
votes2
answers2065
viewsDisplay the sum of each row of a randomly generated matrix
I have the following program that generates a random matrix according to the number of rows and columns desired. In it is also located and displayed the highest value of the elements, and their…
-
2
votes1
answer217
viewsCalculating numerical integrals from numpy arrays
I have the triple integral of the figure. I used the documentation of the scipy to solve her. Now I want to exchange the values of the upper limits of x, y and z, which in this problem are the…
-
2
votes1
answer380
viewsDjango does not validate changed fields in the client by JS
My project has a form that one of the fields is object list (Courses), but these objects are being passed from another list (Courses of the area) through Javascript, only that the values allocated…
-
2
votes1
answer88
viewsdifficulty making vowels uppercase
I was making a script and her goal was to get the characters to move forward. But it was only the alphabetic characters that walked a position. And finally she should turn lowercase vowels into…
python-3.xasked 5 years ago user147847 -
2
votes1
answer740
viewsPython arithmetic progression with decimal numbers
I was doing some exercises on the Internet and I came across the following: create a program that reads the first term and the reason and calculate the umpteenth term of this P.A. I did the program…
python-3.xasked 5 years ago Ricardo Passos 149 -
2
votes2
answers1157
viewsPrint the open range between two numbers in descending order
In the code below, I can make it not show variable value a, but the variable b ends up in the print. The expected response would be the open interval ]A..B[. Ex: variable a = 10 and variable b = 5.…
-
2
votes0
answers44
viewsPython - Count values with separation
I need to create a barplot with counting items within a column: 0 DevFullStack,CientistadeDados,blockChain,DEVOPS 1 Java 2 Java;.Net 3 Salesforce;SAP;ArquiteturadeDados 4…
python-3.xasked 5 years ago Phillipe Savelkoul 21 -
2
votes0
answers144
viewsI need to fix my Python Graph class to simulate a dictionary
Hello, I am trying to fix my graph class to use as a dictionary further forward, but from what I understand it is only accessing the memory location instead of the data, in the example below I will…
-
2
votes1
answer59
viewsReturn to category the RGB difference is smaller
I’m having a doubt, that I’m probably trying to "reinvent the wheel", but I couldn’t come up with a result. I have a color matrix (in RGB): { "muito-clara": [248,299,218], "clara": [243,209,180],…
-
2
votes4
answers620
viewsHow to delete files and folders recursively safely with Python?
Guys, I’m trying to create a script to delete my files and folders in a safe way, just like it does the shred, srm, etc...but I would like to do this with Python script. I was able to find a…
-
2
votes1
answer83
viewsHow can I run a function when user registers Django
I am developing a server using Django and wanted when a user registers to run a function that would create a directory with the user name. The folder with the new user name will be stored in…
-
2
votes1
answer49
viewsRegex checking if there is no character on a line
I’m having trouble putting together a Regex that checks if there isn’t a character at any point in a row after a pattern. I have the following log: 3/9/18, 17:47 - Pessoa 1: Oi gente! 3/10/18, 22:59…
-
2
votes3
answers344
viewsHow to read a text file and generate a dictionary?
Write the function símbolo() who accepts a string (the name of a file: Nasdaq.txt) as input. The archive will have company names and stock symbols. In this file, a company name will occupy a line…
-
2
votes1
answer454
viewsCreating a covariance program with Python
I’m working out a little bit with the lists and trying to create statistical operations with them and I’m having a hard time calculating the covariance Basically I’m trying to create separate…
-
2
votes0
answers67
viewsWhat may cause the error in JSON conversion?
I’m making a Crawler, which will take the GIFS from 9gag. The code is this: In [11]: import requests In [12]: t = requests.get('https://9gag.com/v1/group-posts/group/gif/type/hot?') In [13]:…
-
2
votes3
answers614
viewsAccept user input without pressing enter
Hello, in the menu(self) method I need to accept a user input without having to press the Enter key, only pressing a number to choose an option. I’m new and I’m learning, sorry for the mess! class…
python-3.xasked 4 years, 9 months ago Gustavo Henrique 33 -
2
votes2
answers250
viewsReferencing Python Variables
I’m learning programming on my own and no matter how I look online, I can’t understand exactly why the following reference doesn’t work as I imagine it would work. Let’s say I created a function to…
-
2
votes2
answers343
viewsGetting maximum value of each grouping with groupby pandas
Hello, i have the DF below which I would like to group by 'country' and get the maximum population value: df = pd.DataFrame({'pais': ['Brasil', 'Brasil' , 'EUA', 'EUA'], 'cidade': ['Santos', 'São…
-
2
votes2
answers215
viewsHow to access the lines of a file read by readlines()?
I’m trying to use the readlines, but it makes a mistake that I don’t understand the reason, see: arquivo = open("cadastros.txt", "r") loginarquivo = arquivo.readlines()[0] senhaarquivo =…
-
2
votes1
answer76
viewsCorrect use of lambda with filter()
Here is a practical example of a script that simulates a seller’s sales days and extracts only the days when the seller hit the day’s quota. The list represents the month (I entered only 3 days for…
-
2
votes2
answers181
viewsReading and processing XML file from a CVE (Common Vulnerabilities and Exposures) database with Python
By using the Annexes lista.txt and cve.xml develop a Python script that: open and read the ". xml" extension file made available at the end; search the file for all occurrences of CVE ID in the…
-
2
votes1
answer540
viewsWhy does Python consider an empty string ('or "") to be present in a simple variable with characters, but not in a composite one?
When doing basic programs asking for user input, and testing if it is empty with in because of another variable that defines possible inputs, I come across the following: if '' in 'abc': print('not…
-
2
votes1
answer27
viewsRecord an index-specific value and treat the values
The number of Likes is cumulative, that is, if the post has 0 Likes and receives 5 Likes, it will have 0 + 5 =5 Likes. If soon, this same post receives 7 Likes, will have 5 + 7 = 12 Likes. If the…