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
-
2
votes1
answer442
views404 Error Python Django
That’s the mistake I’m having: As you can see in the URLS list the number 8 is equal to the "Current url" given below. My url list: from django.conf.urls import include, url from django.contrib…
-
2
votes1
answer71
viewsOauth v2 in Django 1.4
Friends, I am studying how to implement the Oauth v2 protocol in my application. I’ve done a lot of research here, and I haven’t found anything that could solve my problem. So far I have a database…
-
2
votes0
answers28
viewsHow to get additional information from "scipy.integrate.ode" solvers?
I am comparing different solvers ( dopri5, dop853, Vode, etc) of "scipy.integrate.ode" and I would like to know if there is any way to get information such as: number of iterations, number of steps…
-
2
votes2
answers258
viewsHow to save Django objects with quantity validation?
I’m still a beginner in Django and would like to know how I would do to save a certain amount of students in vacancies. Example: vagas = 5, how do I allow them only to be saved 5 students? class…
-
2
votes2
answers2038
viewsHow do one class that is inside another inherit an instantiated variable from the last one in python?
See the following python script: class a: def __init__(self,n): self.n=n class b: def __init__(self): ## o que botar aqui para receber a variável self.n ## def show(self): return self.n…
-
2
votes2
answers589
viewsLegacy of templates with Django
I’m having a bit of a problem applying template inheritance with Django. Apparently it’s all right but my html son is not rendered in the template html base. <!doctype html> {% load static %}…
-
2
votes2
answers2519
viewsHow to compress a folder with everything inside using python zipfile?
I am wanting to compress a file and a folder that has multiple files inside in a single file. zip using Python. The script is next p: from zipfile import ZipFile,ZIP_DEFLATED def zipar(lista): with…
-
2
votes1
answer430
viewsHow to run a Python Crawler with PHP
I made a Crawler with Python and run it by command line: python crawler.py As soon as I execute this command he asks me for the keyword that will be searched and start running. global keyword…
-
2
votes3
answers304
viewsWhat is the difference between the modules Math and cmath?
In Python we realize that there are the following modules: math and cmath, however I did not understand what difference between the two. See how they can be imported: import math import cmath What…
-
2
votes1
answer296
viewsError in month language Django
Good morning guys, Next, I have a very troublesome problem. When I try to use the date that was stored in the database, it comes with the month in English. py Settings.: LANGUAGE_CODE = 'pt-br'…
-
2
votes2
answers310
viewsProblem on condition when checking if user typed "n", "N", "s" or "S"
print("--------------------") print("CALCULADORA DE MÉDIA") print("--------------------") print() #Primeira nota v1 = float(input("Digite a primeira nota: ")) #Segunda nota v2 = float(input("Digite…
-
2
votes3
answers212
viewsGet source file from a Python module
How can I assign a method to a module in Python or even access its source file? I tried using the attribute __file__, as shown below, but returned me the error saying that the module does not have…
-
2
votes1
answer1093
viewsDifficulty in developing a little game
I’m implementing a game, against the computer, that follows this format: Be N the initial part number and M the maximum number of pieces that is possible withdraw in a round. To ensure that the…
-
2
votes1
answer783
viewsWhat is the problem with this code that takes the highest and lowest value?
I want to display the sum of the numbers typed as well as the largest and smallest number typed, only with while, if and else: contador = 1 maior = 0 menor = 0 S = 0 # 1º NÚMERO A SER SOMADO while…
-
2
votes1
answer53
viewsDisplaying certain values in Python
I need help with the following: I have a variable that generates random integer numbers from (0 to 400). In a given number of executions, I wish(m) to be displayed(s) the value(s) and the…
-
2
votes1
answer705
viewsAccess Dict within list
How do I access the dictionary containing the Portuguese language of the list below? To access the key: variavel.foreign_names, but I would like to take the values that are inside the dictionary…
-
2
votes1
answer880
viewsCreate a Python list copy so that they are independent
I have the following situation: I have the list 1 with the following values [10,20,30,40]. I want to create a copy of this list, but I need the list_2 not to change when I modify some value of the…
-
2
votes2
answers1916
viewsWhen generating a soup of letters with random letters how to place the words without matching?
I think I was explicit. It is given in a file. txt in the first line the grid size and then the words I should put in the generated letter soup. The problem is that when I get the soup the words…
-
2
votes1
answer86
viewsModule and hierarchies import - Python
Guys I’m having the following question. I am studying importing modules and grabbed the following problem, my directory is with the following configuration: Doubt 1 -> I want to import the…
-
2
votes1
answer138
viewsCheck index in Dict
I have a function that returns me 2 results, None or dict however I am trying to verify if a key specifies this in the result of this function. def get_language(card): if not card.foreign_names ==…
-
2
votes2
answers911
viewsHow can I use two methods in one line in python?
How could I order the methods of the last two lines of code with grandchildren, so that it works in this code: # É criada a hash 'pontuações' a qual ira armazenar e ao mesmo tempo linkar os nomes as…
-
2
votes1
answer671
viewsSpecify DNS server when resolving address
I would like to perform something like a "nslookup" to resolve a site address through my DNS servers, because in the example below, I get only through the DNS I have on my machine. How could I…
-
2
votes2
answers257
viewsstring formatting
I have the following string: JOSÉ CARLOS ALMEIDA (0-2) 1 need to remove text and spaces and leave (0-2) 1 this way I can deal with the trim, split etc... but this my string will not always be the…
pythonasked 8 years, 1 month ago Guilherme Lima 3,129 -
2
votes2
answers7292
viewsFilter elements from a Python list
Guys I want to remove all numbers equal to 1, but is giving this error list index out of range Follow the program lista= [2, 3, 1, 5, 1, 7, 8, 8, 9, 15, 1, 1] qtd = len(lista) for i in range(qtd):…
-
2
votes2
answers123
viewsDate to String to Pyhton conversion
I’m trying to get a date of this next select in python select MAX(PAYMENT_DATE) from fact_cashflow WHERE DOCUMENT_ID = 'SALDO FINAL' and PAYMENT_AMOUNT > 0 But my answer on the console is this…
-
2
votes2
answers1080
viewsHow to calculate the time from point A to B?
I need to do a time check that a truck takes from a factory X until a resale Y, in addition to calculating how long he was in this resale. I have GPS data and removed information that was relevant…
pythonasked 8 years, 3 months ago mrlucasrib 641 -
2
votes1
answer1445
viewspython (on/off key)
Hello. I am learning to code in python3, already some time ago. I am Ubuntu user. I’ve been creating a script for some time, now I want to improve it, I’ve looked for some modules and some examples…
-
2
votes1
answer1157
viewsDjango does not render static files that are in subfolders within /Static/
I am working on a Django project that has static files (css/js/imgs) according to the following structure: File Structure django_project | +apps | +django_project | +media | +static | +admin…
-
2
votes1
answer940
viewsHow to know which is the PID of a currently running Python script?
I have a certain Python script that I want to know what is the current PID of it, through the script itself. How can I do that? Through this too, I can determine that it be executed only once?…
-
2
votes2
answers513
viewsHow to open file by separating each line into an item from a list/tuple?
In PHP, we have a function called file which, when opening a file, causes each line to be placed in an item of a array. Example: hello.txt olá mundo php script file('hello.txt'); // array('olá',…
-
2
votes1
answer338
viewsRegistration error
Well, I’m a beginner in python, I was trying to make a basic registration/login system. However I had a problem creating accounts, the accounts are created in the database normally, but I can only…
-
2
votes1
answer2216
viewsPython function "repeat ... to <cond. >"
I wanted to know if there is the following function, written in pseudocode, in the Python language: repeat (commands) until (condition); Thank you.…
-
2
votes1
answer781
viewsUpload and view PDF’s Django admin
I wanted to ask a question, I am trying to upload a PDF file, on Jango, and I wanted to know if you like I view this pdf, I have the following code: py.models class Edital(models.Model): # ... class…
-
2
votes1
answer496
viewsPython - Problem printing inside a loop
I have the following code Python, representative of the game Pedra,Papel,Tesoura. import random listChoices = ["rock","paper","scissor"] print("Choose rock, paper or scissor to play or write exit to…
-
2
votes1
answer90
viewsDoubt Python, as a list is iterated in a repeat
Hello, the following algorithm relates people and friendship relationships between them. My doubt however refers to the block is indicated in the code. def not_the_same(user, other_user): return…
-
2
votes1
answer197
viewsWhy does '-1' have to be placed right after a variable?
Note: the code is from a book that teaches programming Code: def transação_salva(preço, cartão_de_crédito, descrição): arquivo = open("transactions.txt", "a") arquivo.write(" %s %16.2f \n %s %16s \n…
-
2
votes1
answer377
viewsHow to access data from a dynamic imput of a form with Django?
I am participating in a project in which we are using Django. I created a form with two initial fields and can add more dynamically using javascript. <div class="form-group"> <div…
-
2
votes2
answers323
viewsPython accumulator list
I am developing a function that takes 3 parameters fctn(Function, list, element) and that it has to return a list with the intermediate states of the accumulator, as in the example below:…
-
2
votes1
answer959
viewsPython Interpolate Txt
Good night, I recently started the program in python because of an elective I have at university, but my knowledge is still minimal. My teacher gave a job to do where I should create a code that…
-
2
votes1
answer123
viewsHow to extract the icon from a . exe file using python?
I simply came to need to have an image file . ico extracted from a file . exe and do not even know how to start. How can I do this?
-
2
votes1
answer555
viewsBacktracking in Python
I’m trying to find a subset, of size M, of binary strings of length n, where any string has a distance greater than 2 for any other string in the subset. Where the distance between two strings is…
-
2
votes2
answers831
viewsHow do I check if it’s uppercase, lowercase, or mixed with lowercase?
print('-----') print('TESTE') print('-----') print() lista = ['Joao', 'Joaozinho', 'Rafael'] print(lista) var = str(input('Digite algum dos nomes da lista:')) if var == 'Joao' or var == 'João' or…
-
2
votes1
answer562
viewsCalculation of Shannon entropy in network traffic (saved in CAP file) using Python
I have a dump file (CAP format) of a network traffic capture made with Ubuntu’s tcp dump. Until a certain time, it is a traffic free of attacks. Then, begin a series of attacks of type TCP SYN…
-
2
votes3
answers314
viewsHow to count the number of candidates on this page ? Python 3.6
Simple thing. I need to count how many candidates there are in the table of this page, for example : http://www.ufjf.br/cdara/sisu-2/sisu-2017-1a-edicao/lista-de-espera-sisu-3/?…
-
2
votes1
answer7728
viewsHow to write in a file without erasing old things?
Example: in my file has joao maria carla if I use: arq = open('nomes.txt') arq.write('jose') arq.write('\n') arq.close it will erase the previous ones that was Joao, maria,how do I write without…
-
2
votes1
answer546
viewsPython Pandas: regravando pd.read_table() with original comments
I have a tab-separated file in which the first lines are comments designated with '#'. I use the following code to pull the file without the comments... The file is something like: #comentario…
-
2
votes2
answers1898
viewsRegex to pick up text between <> in python?
I would like to extract the text contained between <> of a string. At first, I built the following expression: import re m=re.search(r'<(.*)>','abevbv envvrhwkv <eiwbv> ebvi…
-
2
votes1
answer949
viewsHow do I remove this warning?
Error: C: Python3 lib site-Packages flask_sqlalchemy__init__.py:839: Fsadeprecationwarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the Future.…
-
2
votes1
answer1025
viewsOrder form with Python and Django
I’m starting my studies with Python and Django. After creating several simple CRUDS, I tried to create a more complex form using several classes, but was unsuccessful. I want to create a screen for…
-
2
votes2
answers356
viewsChecking a Dos/Ddos attack (Denial of service) on a network dump (PCAP file)
from scapy.all import * import dpkt f1 = open("semAtaque.pcap") pcap = dpkt.pcap.Reader(f1) f1.close() f2 = open("Ataques.pcap") pcap = dpkt.pcap.Reader(f2) f2.close() I have two network traffic…