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
answer180
viewsSlow matplotlib (Python) to plot a 2-D graph?
Lately I came up with the need to use Python for plotting graphics with more than 3600 coordinates, but I realized that time can be a problem, but I’m not sure if the code I did has any performance…
-
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
answer127
viewsDoes Command Project Standard have no Python purpose?
The Command Project Pattern provides a way to decouple two objects, one that invokes an action of the one who knows how to execute it, but my question is : In python and other languages that…
-
0
votes2
answers4733
viewsOpen and close multiple tabs in Python browser
Hi, I need some help. I need this script I have (Python and JS) to open a certain number of tabs and after a time interval close and reopen the same tabs again. However, to not close the browser, I…
-
0
votes1
answer663
viewsLogin information validation does not work
Doubts are throughout the program import string alphabet = list(string.ascii_lowercase) n = range(0, 10) name = input('Digite seu nome de usuário:') if name in n: while True: print('Apenas letras…
-
0
votes1
answer1245
viewsCopy entire directory with python
Hello, I would like to copy a whole directory using python, because I have a site base ready and every time I will create a new project I have to keep moving the files to a new folder. I would do…
-
0
votes1
answer143
viewsRegular Expressions in python
How can I read a python file looking for words that fit into a regular expression, for example: search dates(dd/mm/yyyy)?
-
0
votes1
answer1846
viewsWhat is the function of "use_aliases=True" in emoji.emojize?
I am following a course of Python and it was explained how to import libraries and such, and to use this library (as example) was told to use this command print(emoji.emojize('Python is :thumbsup:',…
pythonasked 6 years, 8 months ago Darlley Brito 37 -
0
votes1
answer374
viewsSend html file to FTP - Python 3.6
Forgive me for asking the layman, but I’ve searched everywhere without finding a way out. I have the code below and I am trying to send the files directly to FTP (initially I wanted to do this…
pythonasked 6 years, 11 months ago Alexandre Perali 1 -
0
votes0
answers723
viewsCheck neighbor in a matrix
I have the following problem: I have a large matrix [10x10 for example] It has values from 1 to 9. I must check whether a vector [1, 2, 3, 4, 5] (for example) is contained in this matrix. When…
-
0
votes1
answer547
viewsPython to turn a number into an integer
import math x=9 raiz=math.sqrt(x) print raiz for i in range (raiz,9): #Problema aqui i=i**2 print i I need to create a for with the root of an operation (always whole. 2, 3,4,5...) but when I try to…
-
0
votes1
answer51
viewsMultilingual site
I’m trying to put a site made in Python/Django as multilingual, but I could not understand how to actually do with the documentation or what I found on the Internet, I even found one here in…
-
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
votes0
answers47
viewsCall error of a Python application (+Opencv) in Visual Studio 17 (C#)
I’m trying to make a "control panel" that each button will call a Python application(+Opencv) but when I run it through the Pycharm IDE, or straight from the folder, it runs perfectly, but when I…
-
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
answer165
viewsError in python indentation
I already program in c, I’m mdc in Python but I’m struggling with indentation, because in c we don’t care about it, someone could help me, my code below numero = int(input()) for i in range(): x =…
pythonasked 6 years, 7 months ago rafael marques 939 -
0
votes2
answers776
viewsCompare values in a list of tuples
lista = [('Maria', 28, 7.0), ('Ana', 30, 9.0), ('Thiago', 30, 9.0)] resultado = [] for i in lista: if i[2]<i[2]+1: resultado.append(i[0]) print(resultado) Correct exit: Ana, Thiago, Maria My way…
-
0
votes1
answer123
viewsCron job that runs a bash script (which runs a python script) behaving differently than when executed manually
Hello.. I have a python script that plots two different graphs and that needs to be run daily to update these graphs on a website The data that is used by this script, is in a certain directory in…
-
0
votes1
answer26
viewsGet content from email
I’m using the following: import imaplib import email m = imaplib.IMAP4_SSL("imap.gmail.com", 993) m.login("myemail","mypass") m.select("Inbox") result, data = m.uid('search', None, "ALL") # search…
-
0
votes1
answer89
viewsExtract data from a website and play in your Flask web application
Which module could I use in flask to get data from an API and play in my web application in the HTML part
-
0
votes1
answer535
viewsFind a specific element in a list with sub-lists (Python)
I’m tweaking a Pathfindig code based on A*, I need to check and modify an element within a list with several sub-lists, but I have doubts if I use a repeat loop, or if there is already a function…
-
0
votes1
answer33
viewsGet variable declared in function outside of developer
I tried with the module inspect but I couldn’t get the result. The concept is: "scan" a file through a decorator. Stages Capture variable file before function read_file be called "Scan" filing…
-
0
votes1
answer586
viewsHow to install a Python module
Hello, I have a script here in python that needs a lib: pypxlib But I don’t know how to install this blessed because I’ve never worked with python. I’m using python 3.5 on Sabayon Linux. someone has…
-
0
votes1
answer679
viewsReturn the smallest value - Python
from collections import OrderedDict #Pra poder acessar os elementos igual listas e tuplas. v v v lista_aberta = {(1,3): [1,2,3,4], (1,4): [2,3,4,9], (1,5): [3,4,1,7]} I need to check all the…
-
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
answers53
viewsCreate Function Looping Script
I am very beginner in Python. I am with a project to create an UDP chat in Python. I want to solve an Issue to create an Online message. I typed the code, only it’s wrong. #! /usr/bin/env python…
-
0
votes1
answer213
viewsCache Session in Python
I have a script Python running a Tornado application. Inside the onmessage I have several variables that will keep an equal value always, so there is no need to fill them in whenever a new message…
-
0
votes0
answers267
viewsRandom Python Monte Carlo function
I need to generate random numbers. An amount of numbers in the range of 10 5 and 10 6 random numbers. The randint function of the Random library seems to me that it does not have a good degree of…
-
0
votes1
answer2140
viewsHow to define the tangent function in python?
I would like someone to help me define the tangent function using python with constraints at points where the function does not exist (pi/2 + k*pi(k integer). Thanks in advance.
-
0
votes0
answers41
viewsQuestions about Django MTV
I’m having a hard time understanding the concept of Django. Please check that my conception is correct: MTV refers to Model Template View. Model would be my database. Template would be the interface…
-
0
votes1
answer149
viewsshapefile to raster conversion using Python and GDAL library
I’m doing a file conversion shapefile for crawl, using a Python script and the GDAL library. For this I use two functions: The function gdal.rasterizeOptions (put the output options of my die in…
pythonasked 6 years, 11 months ago Lilian Guimarães 13 -
0
votes1
answer208
viewsCharacters repeating in String discovery [Python]
The goal here is to discover the passwords, in trial and error even, and ta everything going well while the letters, but when they reach the numbers, they repeat themselves for a reason I really…
pythonasked 6 years, 11 months ago Caio Roberto 29 -
0
votes1
answer208
viewsSelect with pyodbc
I am trying to use the string I get from an Entry and Optionmenu to perform the Sqlserver search but from the following error: TypeError: not enough arguments for format string Here is the code of…
-
0
votes1
answer82
viewsHow to start Python code correctly
I’m still learning Python and once I saw a guy starting a Python code with something ____init___, with a if ___init___ ... == True. I asked him why he started the code in such a way, he told me that…
pythonasked 6 years, 7 months ago Lucca Gontijo 9 -
0
votes1
answer56
viewsHow to simulate a click on Linkedin with Selenium. Problem: dynamic id / uses Ember
Good morning, I’m trying to click the 'Show more' button in the field of skills but without any success. Xpath is dynamic, and by class also does not work. The button seems to be hidden somehow. I…
-
0
votes1
answer136
views -
0
votes1
answer145
viewsSort as typed (python)
with a problem that would be the following, the problem asks to order the numbers in the order you typed them and then do in reverse order, someone can give me a light, the code is more or less…
-
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
answer635
viewsPython: Error translating text with the Translate api
I’m trying to do a translation with the Googletrans api(https://pypi.org/project/googletrans/). Code: # -*- coding: utf-8 -*- from googletrans import Translator translator = Translator() print…
-
0
votes1
answer94
viewsHow do I register several records
I want to do multiple contact records, I wanted it to be more dynamic, for example, the person has a number of phones or cell phones or emails and while on the site, she can click on a summation…
-
0
votes1
answer407
viewsJoining two frames by axes
I’m a beginner in the study of programming and I have a question: I need to merge two dataframes into the date column. A data frame shows information about a bike rental company and other weather…
-
0
votes1
answer80
viewsWhat does this -J8 mean?
I am learning how to set up a server and came across this command -J8. I have not found anywhere an explanation of why this command. Could someone help me understand what he does? Thanks in advance…
-
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
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
votes1
answer247
viewsCreate date condition in UNIX format Timestamp - Django
I have a table in the database that the date fields are of type Biginteger, in which receives a date in Timestamp format. How do I make one SELECT in the table with the following conditions: SELECT…
-
0
votes1
answer88
viewsMechanicalsoup Proxy in python
Regarding Python requests using mechanicalsoup, how do I open the site using a proxy. import mechanicalsoup br = mechanicalsoup.StatefulBrowser() site = 'www.exemplo.com.br' open = br.open(site)…
pythonasked 6 years, 7 months ago Jhoony Fr0id 1 -
0
votes1
answer77
viewsDoubt the use of If, While or for
I’m new to python programming. I have a vector with values ranging from 0 to 200 randomly and I want to do a routine to eliminate (remove) values that are below 30 and above 160, and create a new…
-
0
votes2
answers333
viewsPython - Detectives and Assassins
I’m having difficulty understanding what this exercise in the link below is requesting: http://www.ic.unicamp.br/~mc102/Labs/roteiro-lab06.html What I’ve understood so far is that I should build an…