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
votes2
answers5301
viewsDelete value from a Python dictionary
I need to delete a key from a dictionary if a certain situation arises. I have this code: for i in dict.keys(dataClean): dataClean[i] = dataClean[i] - 1 if dataClean[i] == 0: del…
-
0
votes1
answer661
viewsDefine the execution period of an application
I developed a Python application that registers in the database accessing an email and reading each of the records, generating an Index per record. I need this application to run on the server…
-
0
votes1
answer594
viewsInsert documents into Mongodb via pymongo
Good evening. I am using python for the first time in order to run a Crawler. I’ve been able to rotate and take the acquisitions and I want to save them on Mongodb via pymongo. I tried to follow the…
pythonasked 6 years, 4 months ago user119916 -
0
votes1
answer240
viewsHow to correctly read a multi-level JSON?
In Python3 this code reads the Senate API to create a dataframe of one-year propositions import requests import pandas as pd headers = {"Accept" : "application/json"} proposals = [] url =…
-
0
votes1
answer633
viewsParse txt file and return to another file - Python
Good night! There is a file with numbers, save in txt format, each number separated by space, with a list with about 50 values in each line of the txt file (and more than 10,000 lines in the file):…
-
0
votes1
answer1126
viewsDjango datetimefield as text
I am creating an application on Jango where I will have a form to create scheduling queries, my model is like this: class Agenda(models.Model): """Criação da agenda de consultas da Clinica"""…
-
0
votes1
answer211
viewsPyinstaller generating error to import numpy library
Good afternoon, I am creating a python project, and need to get a executable . exe to run in any windows without having python installed. However, what happens is that when I open the generated…
-
0
votes1
answer30
viewsPython - Replace x lines above and below the searched text
Good, I needed to do something that in a document filled in for example as: linha1 bla bla linha2 bla bla linha3 bla bla linha4 bla bla linha5 bla bla linha6 bla blax linha7 bla bla linha8 bla bla…
-
0
votes2
answers470
viewsMatch Checking Python Hangman game
I’m finishing the Python hangman game. But I’m having trouble with the final check when the player hits the word, I’m not able to create a check to validate if the player hit the word, could help…
pythonasked 6 years, 4 months ago Maycon Willian Alves da Silva 75 -
0
votes1
answer994
viewsIntelbrass cameras with python
I wonder if it is possible to take images of an intelbrass camera through ip by python, I searched a lot and found nothing, the code that came closest was this one: import cv2 cap =…
-
0
votes1
answer363
viewsPython error In Flask framework import
after installing python and declaring environment variables, creating a page and trying to run by Command Prompt sends the following error : Traceback (most recent call last): File "app.py", line 1,…
-
0
votes1
answer31
viewsHow to create a class instantiation using variables from a function return in Python 3?
Hello, I wish I could instantiate the class Sala below using as arguments the return of the function choose_sala(): The ideal would be to call the class initialization when the function returns…
pythonasked 6 years, 4 months ago George Bueno 23 -
0
votes2
answers137
viewsVery slow python code?? Access to Access database with pyodbc
I need to get some data from a huge access database (two, actually, depending on the input I have). I have a function that calls this bank by Chunks (if I try a fetchall gives memory problem). This…
-
0
votes1
answer70
viewsI’m getting None in output
l = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] num = int(input(print("Choose a number: "))) new_list = [] for i in l: if i < num: new_list.append(i) print(new_list) I’m doing this exercise that asks…
-
0
votes1
answer534
viewsCalculate Roc curve (sensitivity and specificity) with scklear
Hello. How do I calculate the Roc curve in python? I already have part of the code: Is a dataset of tweets that are classified into insecure and others. I am working with cross validation because…
pythonasked 6 years, 4 months ago André Nascimento 1,258 -
0
votes3
answers347
viewsReturn the oldest person from a list with tuples
The question is this: ; Consider that a person has the format Tuplo - (name, year of birth, city). Create a senior function that receives a list of people and returns the oldest person in the group.…
-
0
votes1
answer583
viewsImport CSV into Django database
I have a CSV database and wanted to import to my models from Django, CSV has this structure: NAME,CLUB,LEAGUE,POSITION,RATING,PACE,SHOOTING,PASSING,DRIBBLING,DEFENDING,PHYSICAL,LOADDATE Tore…
-
0
votes1
answer183
viewsExplain template location in Django
I’m using Django for a project, but I came across a question. In my file settings.py I have the following configuration of templates: TEMPLATES = [ { 'BACKEND':…
-
0
votes2
answers1939
viewsVS Code: Unable to initialize the PRN device (Python 3.7.2)
Hello! I’m having a problem configuring Python in VS Code. When you execute the command print('Olá Mundo!'), the terminal returns: Unable to initialize PRN device. The VS Code version is: 1.30.2…
-
0
votes1
answer2644
viewsDate calculation with Python
I have a script that needs to make a difference between 2 collected dates of some files In this case the script collects the date of a file. txt (dt_log) and the current Systema date (dt_sys) and my…
-
0
votes2
answers925
viewsHow to generate break condition of a repeat loop in Python during its execution?
I’m trying to make a program in Python that during the execution of a loop, some command is waiting for an input condition while the loop is executed. For example, a program that prints numbers in…
-
0
votes3
answers892
viewsRequired field modification if checkbox is selected in Django
I need to check if a "checkbox" button, called yes_no, was selected in my html page and modify the "name" field to mandatory when this checkbox is triggered. My code is this: In the models.py file:…
-
0
votes1
answer2054
viewsAccessing an element in pandas dataframes
I would like to access the first element of the pandas dataframe. import pandas as pd data = [['2019', '0000', 'protocolo'], ['2020', '1111', 'pedido']] df = pd.DataFrame(data) Trying: df =…
-
0
votes1
answer157
viewsReuse function variables
I have a script in Python divided into functions and need to access a function variable in another example function: import glob, os, time, datetime, sys, platform from datetime import datetime from…
pythonasked 6 years, 3 months ago user68537 -
0
votes1
answer325
viewsDoubt with Django 2.0 views and urls
How best to do these functions in the views.py, or it has to be that way? from django.shortcuts import render def index(request): return render(request, 'contas/index.html') def cadastro(request):…
-
0
votes1
answer336
viewsDoes Python have a way to natively drip an IP?
Is there any way to drip an IP natively into python, or a library? For example, I do so: import os ips = ["192.168.0.1","192.168.0.2","192.168.0.3"] cmd = "ping -n 3 " for ip in ips:…
-
0
votes3
answers90
viewsProblem editing a list in Python 3
I do not understand what is happening with this excerpt of code. What was expected was that when imprint the list at the end he the elements of her split, but is returning the list as if nothing had…
-
0
votes0
answers75
viewsHow do I create a neural network file . config from . json, . H5 or . pb files?
Good afternoon, I’m on a convolutional neural network project and I’d like someone to help me with how I can create a file type for the neural network that calls. config I haven’t found much result…
-
0
votes1
answer75
viewsSet a css class and render the form in Django
I created the following class: from django import forms class FormDefault(forms.Form): def __init__(self, *args, **kwargs): super(FormDefault, self).__init__(*args, **kwargs) for field_name, field…
-
0
votes1
answer3133
viewssqlite3.Operationalerror: near " ": syntax error
you know what that mistake means? Error: sqlite3.OperationalError: near “ ”: syntax error Code: def alterturma(self): bancoturmas = Bancoturmas() #try: c = bancoturmas.conexao.cursor()…
-
0
votes1
answer122
viewsDúvidas Array Python
I have a script that takes all the Windows Services and filters only those that have MSSQL and then take the name of the services as image below: But I need to take the values of the Array and…
pythonasked 6 years, 3 months ago user68537 -
0
votes1
answer178
viewsCreate an empty set() object
I want to create an object of the type set empty. For this I am using the following expression: objeto = {} It turns out that when I do this, an object like dict. What I have to do to create an…
pythonasked 5 years, 9 months ago Rafael Barros 840 -
0
votes1
answer733
viewsScrapy for login
I took this code from the internet and changed it a little, to log in to the cpfl site, but when I use the command scrapt crawl myproject nothing happens and the command scrapy runspider items.py of…
-
0
votes1
answer177
viewsHow to dynamically change an image in a kivy label
I want to dynamically change an image on a kivy label. every time the variable increases a number the label should change the image in python def mudaimagem(self): erros = self.qtd_erros if erros ==…
-
0
votes2
answers1609
viewsPython Mysql database connection
Trying to make the connection to my database, but is returning me the following error! Exception has occurred: Attributeerror 'Connection' Object has no attribute 'execute' Exception has occurred:…
-
0
votes2
answers468
viewsConcatenation of multiple lists with Python
Good afternoon! I have a problem and need help, I am working with 3 distinct lists that should be added to a dictionary, but so I can capture all values without one overwriting the other, I need to…
-
0
votes2
answers135
viewsCompare Python index independent lists
Good afternoon, I need to compare 2 lists and when a certain value in the 'name' field of the list 1 does not exist in the 'name' field of the list 2 perform some function. The way I did is…
-
0
votes0
answers98
viewsHow to add values of a request:
Example: request = requests.get('https://api.amountofsomething.com') quantidade = requisição.json()['amount'] This request returns the quantity, for example: {[{25}{120}{158}{0}{2}{10}]} I need to…
-
0
votes2
answers344
viewsname is not defined - name/variable undefined, Tkinter and slite3 help
I’m starting to study sqlite3 in Marra, and this being difficult, but I already got a few things, the problem is that when compiling the program appears the following error: "name 'adic' is not…
-
0
votes3
answers340
viewsHow to add values of a json request in python?
Example: request = requests.get('https://api.amountofsomething.com') amount = request.json()['amount'] This request returns values like these: [{"amount": 0.1}, {"amount": 2},{"amount":…
pythonasked 6 years, 3 months ago Eliezer Borges 1 -
0
votes1
answer224
viewsApplication of linear regression
I have two lists print(lista) [970084.4148727012, 983104.7719906792, 996164.0, 1006426.5111488493, 1016687.0370821969, 1026941.5758164332, 1037185.9604590479, 1047415.8544247652, 1057626.746645888,…
pythonasked 6 years, 3 months ago user9080886 21 -
0
votes1
answer678
viewsHow to print PDF’S with python by checking if the print was successful?
Is there any way to implement a python printing routine where it is possible to verify that the file has been printed successfully? I’ve tried using java with PDFBOX, but I couldn’t find a way to do…
-
0
votes0
answers67
viewsProblem with git stash save --Keep-index and git pull
I’m trying to git pull on a server but it asks me to save the files and even using the "git stash save --Keep-index" command (it always worked) it doesn’t let me run git pull
-
0
votes1
answer55
viewsBest way to perform print command
I’ve been studying about Python for a short time and I’ve learned to display a print value in three ways: % '{}'.format(exemplo) f' {exemplo} ' There is one more way pythonic or each form is…
-
0
votes2
answers159
viewsIndexing error when separating line information
import pandas as pd import numpy as np import matplotlib as plt df = pd.read_csv('dito_julho.csv') df.head() campanha valor 1 Prospect | 5 dias | Com crédito 2 2 Prospect | 5 dias | Com crédito 5 3…
-
0
votes1
answer52
viewsBlank graph
The program is running normal, however, the position graphs, line 339 and 345 are blank, others are normal. I would like to know what to do to solve? Follows code: # -*- coding: utf-8 -*- """…
-
0
votes0
answers65
viewsHow to process data without the kernel dying?
I want to process the data into one unsupervised.py notebook. However, every time I start, my computer almost freezes and it looks like the kernel dies. It seems to be generated because of a memory…
-
0
votes2
answers362
viewsIs adding more than one element to Append possible?
I can add more than one element to the function append? For example: convite.append("Carlos", "Junior") convite["Alberto", "Eduardo"]
-
0
votes1
answer50
viewsProblem with pyinstaller+ os.getcwd() on MAC OS
After numerous problems with Tkinter and Pyinstaller, I finally managed to make a Unix executable application work normally on MAC High Sierra. But inside my application folder, there is a folder…
-
0
votes1
answer35
viewsConnect a button with a pyqt4 lcd screen
Good afternoon, everyone! I need to develop a calculator in pyqt 4, but I don’t know how to connect the number/operations buttons to the virtual lcd display. I have already researched, but I haven’t…