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
-
0
votes2
answers1691
viewsAlgorithm to determine prime numbers between 2 and N. What is wrong?
n = int(input("Digite N: ")) lista =[] divisores =[] for i in range(2, n+1): for j in range(1,n+1): if i>=j: if i%j ==0: divisores.append(j) print("divisores",divisores) if len(divisores) ==2:…
-
0
votes1
answer668
viewsApproximation of the cosine function using the first n terms of a series
Data x real and n natural, calculate an approximation to cos x through n first terms of the following series: cos x = 1/1 - (x**2)/2! + (x**4)/4! - (x**6)/6! + ... + ((-1)**k)*(x**2k)/((2k)!) My…
-
0
votes2
answers16086
viewsunboundlocalerror problem: local variable 'num' referenced before assignment
def fnum_aleatorio(a, b, m, semente=None): if semente != None: num=semente num_aleatorio = (num*a+b)%m if num_aleatorio <= a//2: return 0 else: return 1 I’m trying to make a function that has a 0…
-
0
votes1
answer1641
viewsMatplotlib python normalize y-axis
I’m trying to normalize the y axis of this Plot,when I speak normalize and leave on the same scale import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec import numpy as np from…
-
0
votes0
answers93
viewsThe best way to use getters and setters
I started to study programming a short time ago and the chosen language was Python. And I’m finding it very difficult to enter the use of getters, setters and properties. In my internet browsing, I…
-
0
votes2
answers78
viewsI want to queue numbers. Python 3.6
I want to show the output of the data in queue form, for how many times the user wants. def ex1(): valo = int (input("Insira o numero")) for t in range (1,valo+1): print((int(valo))*1) print (ex1())…
python-3.xasked 6 years, 7 months ago ZeroCold 43 -
0
votes1
answer47
viewsExtract '_id' from load_response object
After post, I get an object load_response, in Dict format, with the following structure: {'_content':…
-
0
votes1
answer70
viewsHow to check if there is a repeated string in a list?
I would like to learn an easier way to check all items on a list and search for repeated strings. I’m currently doing it this way: elif "azul" in fios[0] and fios[1] or "azul" in fios[1] and fios[2]…
python-3.xasked 6 years, 7 months ago TulioBRK 5 -
0
votes1
answer82
viewsI didn’t understand how the (self) value works in "city.state = self " within the add_city() function
class Estado: def __init__(self, nome, sigla): self.nome = nome self.sigla = sigla self.cidades = [] def adiciona_cidade(self, cidade): #essa linha abaixo que eu não entendi o que significa…
-
0
votes2
answers457
viewsHow to join texts in a file?
I’m trying to develop a program, which does the following: From 1 to 100, he writes in a text file the word "test". And after that, I want him to join the word "test" OF EACH LINE with the…
python-3.xasked 6 years, 9 months ago BRKappa 41 -
0
votes0
answers91
viewsHow do I install the Discord.py library in the unbutu terminal?
How do I install the Discord.py library in the unbutu terminal? Discord is already installed, I want to install the library now, through the terminal.
-
0
votes2
answers65
viewsWhy can’t variables from the same instance be read in different processes? (Python)
I have two processes going on and I have a class containing a method that modifies a value, as you can see in the code below. The Eventoboton function represents a click to modify a value. But the…
-
0
votes0
answers41
viewsI understand a parallel execution using _thread. Is there any more pythonic way to write the same code?
import _thread def filho(tid): print('Ola da thread', tid) def pai(): i = 0 while True: i += 1 _thread.start_new_thread(filho, (i,)) if input() == 'q': break pai() Is there any more pythonic way to…
-
0
votes1
answer75
viewsInformation from an API in your web application - Flask Python
I’m a beginner in python and I’m venturing into flask because I thought learning better than Django. So excuse my ignorance of what I’m going to ask or if my code is wrong, more like I do to take…
-
0
votes2
answers829
viewsHow to pick only numbers between parentheses in Python with regular expression
Texto = "54 oz (163 g)" I want the result to be only 163
-
0
votes1
answer77
viewsHow to detect specific text in a string
I want to make a program that detects if it has a specific "text" in the input typed by the user. In this example, the "text": 100 I want it to detect this 100 (position independent) in the input.…
python-3.xasked 6 years, 9 months ago BRKappa 41 -
0
votes1
answer517
viewsPython import file from variable
If I set a variable as the directory from which I will import a file, such as: a = 'C:\\Users\\Windows 7\\Desktop\\Program10.py If I try from a import foo, me is given Modulenotfounderror: No module…
-
0
votes0
answers85
viewsPython iterators, asynchronous context managers
I’m studying the asyncio module and there are some implementations of some other services that I understand but I found myself in some doubts, that would be iterators and asynchronous context…
python-3.xasked 6 years, 6 months ago ThiagoO 2,022 -
0
votes1
answer508
viewsHow do I focus on Toplevel open Tkinter?
In the Help menu, I’m opening as many windows as I click to open, this wasn’t supposed to happen. I tried to adapt something of this post: Tkinter focus a window ignoring the back? , but I couldn’t,…
-
0
votes1
answer793
viewsNoreversematch error in Django
Hello! Studying on Django and developing in this framework, I came across the following error: Noreversematch at / Reverse for 'displayURL' with Arguments '('',)' not found. 1 Pattern(s) tried:…
python python-3.x web-application django django-templatesasked 6 years, 9 months ago Thiago Benine 95 -
0
votes1
answer100
viewsWriting code with python 3
Good guys are... I am currently working on a project, where in one of the functions the script has to write a certain code that was generated from parameters chosen by the user, but after generating…
-
0
votes2
answers302
viewsUsing variable in chdir function (module OS)
It would be possible to use the informed data in a variable in some other function other than the chdir() module AS python? I realized that it is not possible to use variables in the exchange of…
-
0
votes0
answers85
viewsReplace a list with another list in a file
I’m having trouble doing step 4, I want to create a code takes links in a file and replaces by others in an HTML already pre-formatted with variables @link1@, @link2@..., but it returns the error:…
python-3.xasked 6 years, 6 months ago Takashi 1 -
0
votes1
answer191
viewsprint("...") is running several times
I made a program to check if the reported CPF is valid, but a bug is happening: When I type a valid CPF immediately, the "Cpf..." message is printed once. When I type a wrong number and then enter…
-
0
votes2
answers1526
viewsIgnore any white space in the middle of a string
I am trying to create a regex that is able to find a string in a text even if there is some white space in the middle of the words. For example, I look in the text for the following excerpts…
-
0
votes1
answer27
viewsDjango 2 Template missing
In my project I have a project with 2 apps. The first app is learning_logs which has a template, base.html The second app is users, I’m trying to use the learning_logs template on users as follows:…
-
0
votes0
answers35
viewsPython - CTR class does not register in DB
Good night. Application developed in Python 3.x Database: sqlalchemy. I’m trying to develop a simple product registration system in an SQL database. For this, I am trying to develop from the MVC…
-
0
votes0
answers54
viewsHow to increase the performance of a search with for
Basically the program I did does this same procedure, but with more data. I need to increase search performance, of course this can be done with libraries if it’s better. No matter how you improve…
-
0
votes2
answers322
viewsHow to implement Fibonacci more efficiently using dictionaries?
One recursive Fibonacci implementation is: def F(n): if n == 0: return 0 elif n == 1: return 1 else: return F(n-1)+F(n-2) The problem is that it is somewhat inefficient, since, for example, to…
-
0
votes1
answer36
viewsError when searching for a string
Hey, how you doing? I’m having a problem executing this code. From the second "While True" the program can not find the written product. It was registered right above. I checked this code from tail…
-
0
votes1
answer278
viewsTransfer list to Python binary file
Good morning programmers. Need to put a list in a binary file but is showing error. lista = [-1, 333.0, -1, 333.0, 10, 8.0, 45, -66.5999984741211, 12, -44.70000076293945] Code: open("saida.bin",…
python-3.xasked 6 years, 6 months ago Bruno 383 -
0
votes1
answer46
viewsTransforming this readable code to Python 3
Hi I wanted to know how I transform this legible code to Python 3` import urllib proxy = {'http': 'http://myproxy:port'} print ("Using HTTP proxy %s" % proxy['http'])…
-
0
votes1
answer170
viewsReceiving Nan (not a number) when reading a file. CSV with numpy
Using python 3.6.5 import numpy as np valores = np.genfromtxt("arquivo.csv",delimiter = ";",skip_header = 1) print(valores) CSV file.: Valores1,Valores2,Valores3 10,20,30 40,50,60 70,80,90 34,54,23…
-
0
votes1
answer160
viewsAccess variable via exec
I was trying to create a "shell" to be able to communicate with a python program during its execution, so far I have the following (this code is just an example): import sys, pygame from threading…
-
0
votes1
answer440
viewsHow to fix ipykernel_launcher.py: error: unrecognized Arguments in jupyter?
I’m following this one tutorial tensorflow after two days preparing the environment in Anaconda I finally managed to perform premade_estimator.py using the cmd but when I try to run the same code in…
-
0
votes0
answers605
viewsExport mysql data to csv
I am trying to export specific data from a client database to csv, I searched the internet and said I would achieve using the code below. SELECT * FROM escola INTO OUTFILE…
-
0
votes1
answer402
viewsPython - print list elements that have 5 letters
Boas, Having the following list:: lista_nomes =['Manuel', 'Laura', 'Antonio', 'Jasmim', 'Maria','Silvia', 'Lu', 'Pancrácio', 'Diogo', 'Ricardo', 'Miguel', 'Andre',] I want to print the list elements…
-
0
votes1
answer930
viewsFor Python, what is the difference between Pip x Conda x anaconda
I’m learning python and saw that always appears tutorials for the tools: Pip Conda anaconda And I wondered what the practical difference was between them?…
-
0
votes0
answers282
viewsWhat simple way can I run python programs?
My question is quite beginner level, excuse me. I use pycharm but I am open to other better suggestions according to my problem. I would like to run the code on the interpreter himself, but…
python-3.xasked 6 years, 8 months ago Allan Belem 61 -
0
votes1
answer38
viewsWork with two cursors on the same connection
I need to read two tables in the database in order to compare them later, the code I did this giving error, because I am going through two queries in the same connection how could I be correcting…
python-3.xasked 6 years, 6 months ago aguch 39 -
0
votes1
answer268
viewsGet data from a specific column in CSV
I have a question in an exercise. I have a table where I need to get results from only one column. the data are as follows: ['2017-01-01 00:27:45', '2017-01-01 00:31:13', '208', 'Damen Ave &…
-
0
votes1
answer699
viewsTkinter, how to update label on canvas?
Hello, I am trying to build a dynamic table that updates the values automatically but I am not able to update the Labels, I am using the following code: import tkinter as tk def populate(frame):…
-
0
votes1
answer84
viewsWhy is the text label not changed?
I have a screen class, which contains a label of text, the code loads an xml containing the objects. py screen.: #!/usr/bin/python3 import gi import modulo_arquivos import os…
-
0
votes1
answer53
viewsParse Xpath from Int
I have a scrapy running the for to bring the day and link to something. Ex: t_day = div.xpath('.//a/text()').extract_first() a_day = div.xpath('.//a/@href').extract_first() day = int(t_day) if day…
-
0
votes1
answer45
viewsDisplaying full Fractions result
I am generating number simplifications through the Fractions package. All right until you find numbers where the simplification goes to the maximum, ie reducing one of the terms to "1". When this…
python-3.xasked 6 years, 8 months ago Evilmaax 2,613 -
0
votes1
answer565
viewsPython and pymysql connection
I’m creating a login system and user records. I created a model to do the insertion and controller, validating the information and step for the model to save, however, my model is not working. Here…
-
0
votes0
answers45
viewsIDE Pycharm on Windows
I already have a habit of using Pycharm over GNU/Linux, and by force majeure I will have to use it over Windows. The problem is this: When running the python script from the IDE, a python Crawler,…
-
0
votes1
answer50
viewsIteration with variable of type 'TIME'
I am doing a project in which I need to perform a loop that increases minute by minute of a variable from two times informed. I thought of logic as follows: vHoraInicial = '13:30' vHoraFinal =…
-
0
votes2
answers977
viewsPython - Find a tuple odd
I’m new in this area and recently, for a college job I couldn’t turn this line of code into tuple. function code: def encontra_impares(lista): lis = [] if len(lista) > 0: numero = lista.pop(0) if…
-
0
votes1
answer49
viewsCheck the relation of two objects in a list
I need to extract from a pure text the full value of an agreement. I have hundreds of documents with some figures, and I realized that generally the highest value is also the total value of the…