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
answer65
viewsHow to copy a. txt file that updates the name daily - Python
I need to copy a TXT file daily from one folder to another, but the file is renamed according to the date, the end after the "_" always changes with the date value. Ex: _20181205.txt, _20181206.txt,…
-
0
votes0
answers70
viewsParameter and variable multiplication with different index numbers
Good night, I’m doing an implementation of a mathematical model of optimization in Python 3.4. I need to multiply a parameter "Lambda" indexed in i,j,tt and a variable "x" indexed in i,t. The…
-
0
votes1
answer46
viewsException XML-RPC class (Python)
I’m trying to create an XML-RPC class, but it’s giving an Exception, but I don’t understand why. It’s just a simple example: server.py from xmlrpc.server import SimpleXMLRPCServer import pickle…
-
0
votes2
answers1150
viewsCheck if a file exists within a Python IF
Good afternoon, I’d like to make a check: If a file exists - delete If there is no following the flow of the program. I’m using Pycharm, you’re returning syntax error, But I’ve already put four…
-
0
votes1
answer466
viewsDjango: Local Postgresql and Heroku?
I would like to use Postgresql locally and on Heroku. How I set up mine settings.py to know which configuration to use? I’ve tried putting it as an environment variable, but I haven’t been able to.…
-
0
votes1
answer302
viewsList_display in Django/Python
sXDw.png My Models class is like this class Produto(models.Model): NomeRazao = models.CharField('Nome',max_length=50,unique=False,blank=False) CpfCnpj = models.IntegerField('Quantidade',blank=False)…
-
0
votes1
answer164
viewsSave fields back to python variables
I made a query in mysql with python and show the result: cursor = db.cursor() cursor.execute("SELECT Dias, HoraConsulta, HoraSaida, nome, Consulta, centrodb.LocalConsulta.Descricao, Contato FROM…
-
0
votes2
answers1214
viewsLevels in the game of old
I am working on an old game in Python, and I have 3-level codes (easy, medium and hard) distinct, as it could implement an initial "menu" where the user could choose one of the levels and be…
pythonasked 6 years, 5 months ago Renato Silva 33 -
0
votes1
answer143
viewsSelecting different ranges on a giant dataframe in Rstudio
I have a CSV much large with multiple stock dates and their closing prices, impossible to use Excel. The action name is in the same date column and only appears at the beginning of the series, as…
-
0
votes1
answer826
viewsStack several txt files using pandas
I wanted to make a routine that accumulates the data I extract from google Analytics every day, but my code shows an error that I can not solve: import pandas as pd import os import glob my_dir =…
-
0
votes0
answers135
viewsI cannot run the code because Pycharm says that the App class was not created
Pycharm says the App class has not been set, but it doesn’t make any sense since I created the App class. from tkinter import * class App: def __init__(self,master): frame = Frame(master)…
-
0
votes4
answers685
viewsOnly put the correct message print once
I’m doing this show: Develop a program that requires typing of a CPF number in format xxx.xxx.xxx-xx and indicate if it is a valid or invalid number via validation of check digits and formatting…
-
0
votes1
answer448
viewsFind the largest sequence using Python
I have the following code: import collections num = int(input('Digite um número inteiro: ')) #Inputar número inteiro binario = bin(num)[2:] #Cortar o 0b sequence = binario collection =…
-
0
votes1
answer590
viewsCode evaluation: Logistic regression with K fold validation. Is that correct?
The code below is an attempt to make a logistic regression with k fold cross validation. The idea is to take the confusion matrices generated in each fold and then generate an average confounding…
-
0
votes0
answers353
viewsAttributeerror: 'numpy.ndarray' Object has no attribute 'pop'
I am trying to run this code nhttps://colab.research.google.com and gives this error. # Preprocessing function #n está funcionando :( def preprocess(data, columns_to_ignore): # Sort by descending id…
pythonasked 5 years, 11 months ago Raul Nascimento 103 -
0
votes1
answer110
viewsPass a given sequence of times in Python 3
I have the following sequence: {1,4,12,28,45,22} I need a variable for example: seguinte = input(num('Insira um número: ')) According to the number given, he would pass the last item to the…
-
0
votes1
answer225
viewsError reading file . xls
I have some files to read in Python, I’m using the following structure: df = pd.read_csv(path, Sep=' t') And this generated the following error: Unicodedecodeerror: 'utf-8' codec can’t Decode byte…
pythonasked 6 years, 5 months ago Matheus Rocha 86 -
0
votes3
answers563
viewsProblem keeping quotation marks
famous_person = "Dalai Lama disse:\n" message = "\Se quer viver uma vida feliz, amarre-se a uma meta, não a pessoas nem a coisas\" print(famous_person + message) I have tried everything (including…
-
0
votes2
answers108
viewsOrder dictionary and display 20 first
I have a dictionary with words and their frequency. Of the kind: dic = {walt: 2, disney: 1, ola: 5, ...} To sort the dictionary I did so: aux = sorted(dicionario, key=dicionario.get, reverse=True)…
-
0
votes1
answer701
viewsCalculate the number of even numbers in a tuple recursively
I need help creating a recursive function that finds and adds the even elements of a tuple, I would really appreciate the help. def conta_pares(t): '''conta_pares : tuplo -> inteiro recebe tuplo…
-
0
votes0
answers110
viewsCollision problems in Tkinter (game)
I’m learning Tkinter developing a little game but I’m in trouble to erase objects collided with find.overlapping from tkinter import * from constantes import * import random class Jogo(): def…
-
0
votes1
answer2333
viewsPython utf-8 encoding error
Good afternoon to all I am beginner to Python programming, I am creating a program that reads the information of a text and transcribes elsewhere. Apparently the text was working normally on the…
-
0
votes1
answer87
viewsProblem with Python script
Guys, I have a slight problem with a script I created in Python. print("Agora eu vou dizer algo para você.") idade = int(input("Me diga sua idade.")) if idade < 18 print("Me desculpe, você não…
-
0
votes2
answers259
viewsI’m trying to do Bhaskara in Python and even with the highlighted if programming says I can’t turn a Complex into float
a = float(input("A = ")) b = float(input("B = ")) c = float(input("C = ")) delta = float(b**2-4*a*c) raiz = (delta ** 0.5) if raiz is float or int: raiz = float(delta **…
pythonasked 5 years, 11 months ago Lucas Batista 1 -
0
votes1
answer2655
viewsPandas iterrows, how to make the second looping using index
for index, row in candles.iterrows(): if (row['Twintower'] == 1): I would like to make a second looping from the moment he finds this condition, ie from this index down, or Row down, tried several…
-
0
votes1
answer615
viewsMean between vectors within functions (python)
Good afternoon guys, I have the following code: def Ler_vetor(): VET= []*10 for i in range(0,10): VET.append(int(input('Digite um número: '))) return VET def Escreva_vetor(VET): print('Dentro do…
-
0
votes1
answer226
viewsExample of Python service from Post method
Any example of a Python Post method service? I don’t know how to do this with the database connection. I know how to do Get and I’ll leave an example below. @route('/dadosBloqueios', method = "GET")…
-
0
votes1
answer40
viewsInsert only if date is not duplicated - Python
Good afternoon, you guys! Today I am making an Internet that does not check if such record has already been entered in the database. Through the variables: name, date and number an Index is…
-
0
votes1
answer701
viewsUsing Tkinter together with a database
I am doing a program of registration of people with interface (still very basic, just to do tests) and I am with several difficulties: I’m extracting the data using the .get(), however, I can only…
-
0
votes4
answers197
viewsRemove comment tag and your content in Beautifulsoup 4
How do I remove the comment tag along with its content with bs4 ? <div class="foo"> A Arara é um animal voador. <!-- <p>Animais Nome: Arara Idade: 12 anos e 9 meses Tempo de Vida: 15…
-
0
votes1
answer500
viewsJson by python URL?
good afternoon! I have a python script that I need to pass a Json via URL to an application, which validates through the mac address. With several researches, I have been testing the code below,…
-
0
votes2
answers2891
viewsPython and Access
Please help, my class does not connect in Access at all.. I’m using: Pycharm, win10 (x64), office 2007 and 2016, python 3.6(x86). Thank you for your attention. follows example of the class: class…
-
0
votes2
answers110
viewsOutput not expected in CSV Python (infinite loop) file
Bom, I’m trying to save the distance and time, result of the difference in the sending/arrival time of the ultrasonic sound, this through the sensor for Raspberry Pi 3 HC-SR04! After obtaining these…
-
0
votes1
answer1277
viewsMulti-value dictionary creation for a key
I’m trying to create a code for registration by input, as an exercise. dic = {} ... def cadastrar(): nome = input('Nome: ') variavel1 = input('variavel 1,: ') variavel2 = input('Variavel 2: ')…
-
0
votes1
answer2628
viewsHow to generate random numbers but with some restrictions in python?
import random v=[1,7,15] x=random.choice(v) How do I generate more numbers "1" than "15"? At 10000 times, choose 1 number and at the end: number 1 must have left about 40%. number 7 must have left…
-
0
votes2
answers1580
viewsHow to assign values to an undefined amount of python variables?
To assign values to multiple variables just follow this structure: a, b, c = 1, 2, 3; This I know, but what if for example I want to store several values that came from an input without knowing the…
-
0
votes2
answers618
viewsCompare Hash of two files in Python
I need to compare the hash of the files a.txt and b.txt using a python3 native library. I tried to do so: import hashlib file_0 = 'a.txt' file_1 = 'b.txt' hash_0 = hashlib.new('ripemd160')…
-
0
votes2
answers171
viewsCoding problems
I’m having codage problem that I can’t solve. I’ve tried several suggested things but none works: Script: # -*- coding: utf-8 -*- import sys line = ["Oi tudo bem com você","eu GOSTO de café", "esta…
-
0
votes1
answer741
viewsError in pycharm
Good morning, everyone, In "file>Settings>project: ... > project interpreter" the environment has been configured: "/home/Brito/projetos/venv/saj_projects/bin/python" And I’m experiencing…
-
0
votes2
answers522
viewsRemove function in one list alters elements in another Python3
def almostIncreasingSequence(sequence): x = sequence for i in range(len(x)): sequence = x cont = 0 y = False sequence.remove(sequence[i]) for j in range(len(sequence)): try: if sequence[j] <…
-
0
votes1
answer414
viewsPython - Tkinter - Dynamic Checkbutton does not take the value of the variable when referenced from another file/screen
I’m having the following problem: I can get the value of a dynamic variable (checkbutton) when the whole program is in one file with only one function: import string from tkinter import * import…
-
0
votes1
answer50
viewssort list of dictionaries by key that contains None key
How can I sort a list of dictionaries by a certain key when within those dictionaries there is one with the key None? Example: mylist = [{'category': 'director'}, {'category': 'manager'},…
-
0
votes1
answer175
viewsHow to open . csv file containing "ç" in column label with Python
I’m starting at the Python and I have a problem: I need to open a file .csv in the Python, but in the column header contains a ç. When I try to open it presents the following error:…
-
0
votes1
answer80
viewsBuy values from the list
I’m having a little problem with a list. I have a txt with some information (log failure of a system) and wanted python to print for me this flaw with their "translation" example: If cod_error ==…
-
0
votes0
answers35
viewsHow to change the password for an IP list?
How do I change the user and password of a large number of servers with different ips, rather than a single ip? Follows the code: # Copyright 2016 Hewlett Packard Enterprise Development LP # #…
-
0
votes1
answer1152
viewsPython webdriver Selenium does not find the item on the page after loading
I am having a problem when searching for an item inside a page, this item is loaded after loading the page via ajax or iframe, there is some way to create a condition for the script to wait until…
-
0
votes1
answer906
viewsHow to perform calculations on top of a CSV file with Python 2.7?
I am learning some commands for analyzing data extracted from a CSV file and locked in the following situation: I want to use as a basis this CSV to realize the average of the room: Nome;P1;P2;P3…
-
0
votes2
answers1874
viewsProblem importing a class from another folder and using it. (Python)
I’m going crazy here. I’m facing a problem that should have been solved by logic already. The problem is this: I have two folders: Novapasta/ Novafolder/classes In the first folder there is a file:…
-
0
votes3
answers280
viewsHow Django URL works
I’m developing a Jango website. Where I own these two structures main from django.contrib import admin from django.urls import path, include from post import views urlpatterns = [ path('admin/',…
-
0
votes1
answer566
viewsOperationalerror: near "?": syntax error python sqlite3
Good night. I’m trying to put a dynamic column with the function class db(): def __init__(self,coluna): self.coluna = coluna def inserir_coluna_tabela1(self): import sqlite3 as sql conn =…