Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
0
votes1
answer63
viewsA function that does the opposite of an addition mod 2³²
def mod_2to32sub1(x): s = 0 # the sum while x > 0: # get the digits s += x & (2**32-1) x >>= 32 if s > 2**32-1: return mod_2to32sub1(s) elif s == 2**32-1: return 0 else: return s…
-
0
votes3
answers42
viewsHow to simplify these two methods?
Well, in my class there are two magical methods, add and sub: def __add__(self, other): if other.__m == self.__m and other.__n == self.__n: result = [] for i in range(other.__m): lst = [] for j in…
-
0
votes2
answers81
viewsPython: Return a list in 2D format
I want to use the __str__ to receive a list and returns it in the form of a matrix. Example: list_exemplo = [[0,1], [2,3]]would return as: [[0, 1], [2, 3]] How do I do it in the method __str__?…
-
0
votes1
answer70
viewsDoes the kivy use native resources?
I wonder if the kivy uses native Android system features.
-
0
votes1
answer58
viewsSyntaxerror without apparent errors
import sys entrada = input("DLL Nome: ") saida = entrada+"_output.txt" file = bytearray(open(entrada, 'rb').read()) with open(saida, 'w') as output: for count, byte in enumerate(file, 1):…
-
0
votes2
answers528
viewsSwap String Values from a Dataset to'Float' values
Good afternoon guys!!! I have a little problem to perform a work of a college subject. I’m picking up a ready dataset from another article that was held. Dataset goes something like this:…
pythonasked 5 years, 11 months ago Arthur Abitante 439 -
0
votes3
answers5733
viewsHow to save the output result of a Python script to a txt file?
Script showing saved wifi passwords: import subprocess data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors="backslashreplace").split('\n') profiles =…
-
0
votes1
answer593
viewsInserting a JSON object into a JSON field in Postgresql with Python
Good morning, everyone, I have the following problem, I made a Crawler and it receives the information, but at the time of formatting it in json format and insert in the database presents error.…
-
0
votes3
answers211
viewsCompare the widget with the rest of the Python list
I need to create a program where in the given list, if the name is repeated it puts a numbering. For example: names = [maria, Joao, maria] the result should be result = [maria, Joao, maria1] Other…
-
0
votes2
answers50
views"List" remains null after using Python append
I would like to understand why t2 is null after assignment of t1+append. t1=[1,2] t2=t1.append(3) print(t2)
pythonasked 5 years, 3 months ago Vitor Gonçalves 552 -
0
votes4
answers1240
viewsI want to take only the first digit after the point of a number that in python 3.7.4
I want to take only the number after the dot, type in the number 3.76443 I want to print only the 7, how do I do? how will I also make to print it? I have to create a variable for it?
-
0
votes1
answer33
viewsAccess Tag via beautifulsoup
Hello, I’m having difficulty accessing the price that is in the third line of the code via beautifulsoup. Does anyone have any idea how to access? <span id="ctl00_Conteudo_ctl01_spanPrecoPor"…
-
0
votes1
answer321
viewsSwitch Windows Screen with Python
Good Afternoon! Guys, I’m writing a Python script using the Pyautogui library. At some point, this script "needs to navigate between screens", example, my script is working a report within my TMS…
-
0
votes0
answers41
viewsHow to work elements of a python web page
I’ve been studying python for a while and I’ve created an application, now I’d just like to create a page where the data that’s stored in a variable is displayed in that html element, sort of like…
-
0
votes0
answers14
viewsHelp with the while loop in a Python quiz
The intention is if the answer is s he executes that completed the registration successfully, but if it is n or other than s prints the message: registration canceled or thank you and come back…
-
0
votes2
answers969
viewspython & Selenium - wait download finish to close the browser
How can I just close the webdriver when my download is finished. Time Sleep didn’t help me much because times vary a lot. follows my code: ExportCSV = WebDriverWait(driver, 10).until(…
-
0
votes1
answer142
viewsHow to create an Array within the other
I need to create an array that has Indice and values page_links receives the links of a page all_links_main = [] for link in page_links: all_links_main.append(link.get('href')) produto = [] for…
-
0
votes2
answers52
viewsHow I write in Python documents on For
arquivo = open('escala.txt', 'w') for i in range(0, 101): var = (i * 2000)/100 arquivo.white('Temperature is:',i ,'°C converted is:', var) arquivo2.close() That’s not possible I’d like to know how…
pythonasked 5 years, 3 months ago Eric Levinski Kirsten 15 -
0
votes1
answer714
viewsMenu in the Tkinter Python module
Hello, I have a screen that was made in Tkinter and I have a menu with cascade submenus, what I need to do is show the different information of the submenus without having to create several other…
-
0
votes1
answer58
viewsReplace words in a text that must be formed of letters and numbers
I am trying to replace words in a text that are formed, obligatorily, formed of letters and numbers. I tried that: def passwords(): df['C'] = df['C'].str.replace(r'[a-zA-Z0-9]', '<password>')…
-
0
votes1
answer188
viewsHow can I impute values with Sublime text
How can I pass values to Sublime Text Exp: I created this simple program to make a basic account! Note: there is no box to pass value, I believe you need to use the terminal but I do not know very…
-
0
votes1
answer35
viewsFlask application deploy error
I am trying to deploy a flask application in the same way I do when using python2.7, but in this case I am using python3 and an error is returned in wsgi. Below follows the first line of apache2…
-
0
votes1
answer405
viewsPython - Retrieve BD information by column name
Dear, How to retrieve database information by column names and not by indexes? cursor.execute('SELECT * FROM [AutomacaoCampanhasDashboard].[dbo].[TBL_GCCP2]') row = cursor.fetchall() nome =…
-
0
votes1
answer187
viewsHow to create a file-based JSON map
Hello, I have a problem that is the following I have a map with the following format and I need to create a script that converts this map to a specific JSON model in python: Map template: TELEFONIA…
-
0
votes2
answers70
viewsOverride de Propriedade
According to some examples I found I’m trying to implement an override of a property, but the override does not work. I think this is a theme still a little obscure with few examples and little…
-
0
votes1
answer354
viewsImporting values from other codes in Tkinter - python
Hello, I’m doing a large program and wanted to divide the screens into other codes, I can import the screens, but I need to get some values from other screens, but I can’t do it. First screen: from…
-
0
votes2
answers219
viewsHow do I make some command to go from one option panel to another in python
Like I was doing a deal that had a panel of options that you pick the number and then it goes and runs like Fazer oque: 1: ir ao mercado 2: ficar em casa 1 (pra ir ao mercado) then after I chose to…
pythonasked 5 years, 11 months ago Cavernosa Spider 187 -
0
votes1
answer99
viewsHow to schedule a schedule with kivy
I want to make an event happen for 2 seconds at the speed of 29/30, after 5 seconds passed since the beginning of the program, with the following code: from kivy.app import App from…
-
0
votes1
answer515
viewsRecursive function that returns the sum of the divisors of a number
As an exercise I had to create a recursive function that returns the sum of the divisors of a number. I made the following code, but is giving maximum recursion error: def somadiv(n, i = 1, s= 0):…
-
0
votes1
answer234
viewsError creating function in Python 3.7.0
I cannot execute this code, it should receive an image in format .BMP and return to the list of pixels, do not know what can be wrong: from struct import pack from struct import unpack def…
-
0
votes1
answer244
viewsStore the contents of a file in another - python file
I’m trying to read information from a file and save it in a new file, after passing all information to lowercase and removing punctuation characters. For this I created a Readfile() function that…
-
0
votes2
answers59
viewsBeginner - Unexpected Behavior in a Variable
I’m trying to create a Python code that calculates the remaining value in my VR and alerts me if the average per day drops from 25. It is an attempt to better understand while and break. I created a…
pythonasked 5 years, 11 months ago Eduardo Mergener 21 -
0
votes0
answers259
viewsCalling functions by shell
Write the function maior_primo that takes an integer greater than or equal to 2 as a parameter and returns the largest prime number less than or equal to the number passed to the function. Examples…
pythonasked 5 years, 11 months ago Gabriel Fonseca 1 -
0
votes2
answers414
viewsStore a dictionary in a Python file
I have a function that counts how many times the words appear: def countWordExact(dataClean): count = {} dataFreq = [] for word in dataClean.split(" "): if word in count: count[word] += 1 else:…
-
0
votes1
answer634
views -
0
votes1
answer61
viewsI need relationship one for many between 3 tables
Hello I have the table People, Vehicles and Messengers who are the users who pay per month the precise staging that each person can have more than one vehicle, but when registering in the monthly…
-
0
votes0
answers222
viewsFord-Fulkerson Python algorithm
I’m doing a college paper where I need to implement the Ford-Fulkerson algorithm in Python. However, I am having difficulty finding an augmenting path in the residual graph (path function). I don’t…
-
0
votes2
answers93
viewsManipulating Python Lists with a mathematical formula
I have to make a certain calculation with real numbers generated randomly in Pyton. In my case, there will be 10 randomly generated numbers, and after that, I need each number on my list to be…
pythonasked 5 years, 2 months ago Rômulo Pinheiro 1 -
0
votes0
answers57
viewsI need some help on batteries
I need to create a new list with the values of a string, without repeating the previous digit. If it were only not to put duplicate values, it would be easier, but the rule is not to repeat the…
-
0
votes1
answer115
viewsProblem using if and Elif Python
I have a problem using the if and the elif to create an extract table taking information from the bank. If in the bank the transaction category is deposit, I want it print in a way, but after he…
-
0
votes1
answer370
viewsGet method error in Python Requests library
I’m trying to learn how to use the library Requests in python, but there is an error that I do not know how to solve, in several tutorials creates the variable r =…
-
0
votes0
answers99
viewsError Recording audio using pyaudio - Ioerror: [Errno -9997]
I’m trying to record an audio from a script I developed with python using pyaudio but I’m encountering a strange error, below follows the script that was saved with the name rec.py: import pyaudio…
-
0
votes2
answers311
viewsDeploy Python project to Heroku with error
I’m trying to deploy a Python project using Django on Heroku. deploy is fine, but when trying to do heroku run python manage.py migrate the following error occurs. Traceback (most recent call last):…
-
0
votes1
answer151
viewsProblems with python utf8 encoding
Error I get when running the script: I get this bug by its name ~ which returns from the mysql table. If the table ~ in the name does not give error, if you put the ~ get this error. my script: #!…
-
0
votes1
answer34
viewsPython - Problem with df.apply(Function)
beauty? Can I get a little help? Just call. I have a dataframe with some string information and wanted to change them to text. To simplify, imagine that the table contains information of the…
-
0
votes1
answer54
viewsfunction for not repeating loop
deze = [] df["1_Dezena"][0:10] for a in (df["1_Dezena"][0:10]): deze.append(int(a)) print(deze) Upshot: [41] [41, 9] [41, 9, 36] [41, 9, 36, 6] [41, 9, 36, 6, 1] [41, 9, 36, 6, 1, 19] [41, 9, 36, 6,…
pythonasked 5 years, 2 months ago Franklin R Moura 1 -
0
votes1
answer1272
viewsRename files with Python by dynamically adding numbering
I have a directory with many pdf lists, and want to rename the files dynamically. Ex: ~/teste/ |__ProjMed-Química-Físico.Química-quimica_propriedades_coligativas_exercicios.pdf…
-
0
votes0
answers25
viewsUpdate item value inside python dictonary
SCRIPT for row in result_psql: if row in lds_data: print(lds_data[row]['status']) else: continue OUTPUT NO GOAL I would like to update the value IN THE for YES STRUCTURE OF THE DICT lds_data =…
pythonasked 5 years, 2 months ago Luis Henrique 697 -
0
votes1
answer926
viewsSelect higher value per row of two columns (Python)
I have a dataframe with several columns, the last two are where I sum and multiply the other columns, at the end I create a column that should select the highest value between these two columns, for…
-
0
votes1
answer213
viewspython Count of different words with only one counter?
I have this code: palavras = dataClean.split() count = 1 for palavra, frequencia in palavras: aleatorio = random.uniform(0.0, 1.0) if aleatorio < 0.5: count += 1 contProb[palavra] = count count =…