Most voted "python-2.7" questions
In the 2.x series of the Python programming language, version 2.7 is last and the latest. Use this tag only if the problem is specific to this version. Also use the [python] tag in your question.
Learn more…477 questions
Sort by count of
-
0
votes1
answer913
viewsLists of dictionaries
I have a list of dictionaries like the following and I want to get for a list the ages of the animals of each owner, for example, the animals of ana have on average x years ... However I am not…
python-2.7asked 9 years ago André Fonseca 1 -
0
votes1
answer85
viewsDoubt while loop
I have the following code: # -*- coding: utf-8 -*- def soma(lista): soma_num = 0 while soma_num <= lista: soma_num += a return soma() a = [1, 2, 3, 4] print(soma(a)) I know it will give error on…
-
0
votes0
answers138
viewsPython - Pygame
People in python when I write the following command import pygame to import pygame the following error appears: Traceback (most recent call last): File "<pyshell#0>", line 1, in <module>…
python-2.7asked 8 years, 10 months ago Ricardo0303 25 -
0
votes1
answer533
viewsHow to print page
I want to create a template for printing data but I’m a little lost on how to do this, I have a print name button, the same is found in a table that contains the customer name, telephone address etc…
-
0
votes1
answer74
viewsThrough a panel of 2 lists make a chart
I have 1 table with 2 lists as for example the following ones , where the first one contains dates in the YYYYMMDD format and the second one contains the number of times a crime happened that day.…
-
0
votes2
answers560
viewsList indexes in python
Good afternoon! I have the list: a=[4,3, 1, 2, 3] and the list: sub_ind_novo=[96, 7, 97, 23, 18] And I needed to link the lists by getting the result: no97. G1 #when sub_ind_novo is 97, the…
-
0
votes0
answers77
viewsContinuous division - Indexerror: list index out of range
for i in lista: lista.append(X) X = X * 0.5 for i in range(100): print 'N[%d] = %.4f' %(i, lista[i]) This mistake always happens: Indexerror: list index out of range…
-
0
votes1
answer105
viewsDjango does not create admin.py file in new app
I’m following some video lessons about Django to make some changes to a project started some time by someone else. However, when starting a new app in this project with the command django-admin…
-
0
votes1
answer100
viewsPython Random.getstate function
I need your help in the following situation: I have a loop that generates a random value from 0 to 400. I need my function to return at which time the loop generated the number X. (For example, loop…
-
0
votes1
answer141
viewsSave contents of a Listbox to mysql database
Good morning, I have a listbox and I’m having a hard time storing the contents of that list in the Mysql database. Someone could help me. I followed code and error below: def SaveVariosCodBr(self):…
-
0
votes1
answer46
viewsHow to make the execution of the synthesizer not be interrupted?
I’m trying to make a program that when I press a key, it reads which key was pressed. For example: press the key "a" returns: "Normal Key A" (audio) press "b" key returns: "Normal Key B" (audio)…
python-2.7asked 8 years, 5 months ago Isabela da Silva 1 -
0
votes1
answer34
viewsDjango 1.10 + Django Restless 0.0.10 and Empty Request
I’m using Django Restless views to build some REST interfaces and in all posts the request.POST and request.params are empty. In case I run: print request print request.POST I have the following…
-
0
votes1
answer322
viewsHow to filter PCAP file with Python?
The PCAP file was generated on 12/21/2016 and is 5 GB so it is impractical to try to open it with wireshark (graphical user interface) I installed tshark on Ubuntu and while reading the manual, I…
-
0
votes1
answer83
viewsIgnore certain indices in a Python list
I have the following situation: I have a list of 64 items and I want the first two values to be displayed and all the other ones after 2. An example would be: lista =…
-
0
votes1
answer503
viewsImport attributes from models classes from another app
Good afternoon guys, I’m good a doubt! I am using 2 Apps in Django admin App1 = Registrations App2 = Controlling Fellows I imported into "Stock Changers" (App2) the app1 model, the "Person" class in…
-
0
votes1
answer750
viewsTypeerror: 'float' Object is not iterable in 2D CHOICE function
I have the code below and I can’t make it work. For, I need an array from my 2D list to be chosen randomly with the CHOICE function and perform the sum of values that are less than 85.0 and subtract…
-
0
votes3
answers331
viewsAvoiding code duplication without the use of switch/case in the Python language
Friends, I have the following code in Python: data_hoje = time.strftime("%d %b %Y", time.gmtime() ) #data de hoje data_desejada = time.strftime("%d %b %Y", time.gmtime(time.time() + (3600 * 24 *…
-
0
votes1
answer187
viewsWriting IP addresses to file, each IP on a different line using Python
from scapy.all import * pkts = rdpcap("lalalao.pcap") for p in pkts: ## print p.time if IP in p: #if packet has IP layer src_ip = p[IP].src dest_ip = p[IP].dst print src_ip f = open('IP_src.txt',…
-
0
votes1
answer106
viewsTraversing a file and splitting its contents into other separate files using Python
from scapy.all import * pkts = rdpcap("lalalao2.pcap") #time slice de t em segundos : 10 minutos t = 600 somaMin = pkts[0].time + t valores=[] for p in pkts: if p<=somaMin: valores.append(p)…
-
0
votes1
answer36
viewsInteracting all items on a list
I have the following situation: I have 4 numerical lists ranging from 1 to 30. Ex.: AP_X = [1,2,3,4,5...30] AP_Y = [1,2,3,4,5...30] demanda_X = [1,2,3,4,5...30] demanda_Y = [1,2,3,4,5...30] I have…
-
0
votes2
answers82
viewsXHR in javascript for Python displays three times the return
I recently deployed Python to my IIS server, and started testing some requests. First I created the javascript code, as you can see below: sendRequest = function() { var http = new XMLHttpRequest();…
-
0
votes1
answer207
viewsTransform varchar to float
I made a code that takes data from the comic to generate a graph with the matplotlib, but the data in the comic is as varchar and for the creation of the data it must be in the format float. How can…
-
0
votes2
answers52
viewsTransform long/varchar data to string
# -*- coding: utf-8 -*- import MySQLdb as mdb import matplotlib.pyplot as plt print(plt) con = mdb.connect('localhost', 'root', '123456', 'testdb'); null = None with con: cur = con.cursor() d =…
-
0
votes1
answer69
viewsHow to include Labels in matplotlib
I have the following code: import matplotlib.pyplot as plt AP_X = [10,20,30,40] AP_Y = [50,60,70,80] plt.scatter(AP_X, AP_Y, color="green") plt.ylim(0, 100) plt.xlim(0, 100) plt.show() It displays a…
-
0
votes2
answers1885
viewsHow to create a board of user-determined size and present it as text using python?
I am trying to create a program in Python 3.6.1 that creates a board according to the size typed by the end user and prints the result in the shell. It needs to be presented as text, and cannot use…
-
0
votes1
answer973
viewsConnect via SSH to another machine and run script
I am automating tasks and I am new in Python, so I would like your help because I need to run a Shell script on another machine and this command I need to give inside a Python code. I thought I’d…
-
0
votes1
answer2324
viewsLocating values in a python array and assigning specific values
I have the following vector: posicao = [47, 62, 24, 18, 47, 62, 63, 78, 68, 87, 24, 18, 68, 87, 63, 78] I need to search in this vector the values [24, 18]. After locating them all, I need to assign…
-
0
votes3
answers50
viewsDetermine the indices of a vector to be subtracted
I have the following vector: a = [10, 20, 30, 40, 50, 60...] I need to create a new list that is the subtraction of the later index by the previous one. For example: b = [indice[0] - indice[1],…
-
0
votes0
answers734
viewsHow can I plot a spectrogram in real time by reading data from an ADC such as the "MCP3008" connected to the Raspberry GPIO?
My idea will be to read data from an ADC such as the MCP3008 connected to Rasperry’s GPIO, from the readings plot a real-time graphics of the signal processed by a FFT(fast Fourrier transform) or…
-
0
votes1
answer476
viewsTraverse a vector to a given number of indexes and form a list of values
I have the following vector: a = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20] I need every five indexes to form a list of these elements. You’d look like this: b = [(10, 10, 10, 10, 10), (20, 20, 20,…
-
0
votes1
answer666
viewsWord processing in csv file
I have a database with over a thousand opinions (text) in a csv file, however I need only texts that contain more than 5 words to stay in my file. The problem is to make a code that goes through the…
-
0
votes0
answers25
viewsconversion of Unittest Python2 to Python3
I have some free time and am updating in Python3. I came across a problem in the execution of the unittest, and I believe you can help me. Error: File…
-
0
votes1
answer845
viewsAutomate reading multiple text files in a Python script
I have a Python script that counts the number of connections contained in a text file and that is working perfectly: with open('1zao.txt') as f: linhas = f.readlines() soma = 0 for linha in linhas:…
-
0
votes1
answer55
viewsIdentify repeated indices and exchange only one of them
I have the following vector: a = [1, 2, 3, 4, 1, 3] I need to go through this vector and identify which values are repeated. After identifying them, I need only one of them to be exchanged for a…
-
0
votes0
answers486
viewsOpen files through the relative directory
How do I read the relative file path that is in a different python file directory and then open that file? For example: For archive1 in the name_project/files/file1.txt directory and the python code…
-
0
votes0
answers35
viewsI need to access the sdados of this list and save to a txt file line by line
From matricula import Aluno class repasse_matricula(Aluno): def __init__(self): arq = open('Alunos Matriculados.txt', 'r') self.alunos_matriculados = [] for k in arq: if…
python-2.7asked 7 years, 9 months ago Gustavo Bonifácio 1 -
0
votes1
answer172
viewsAdd 0 after the comma
I have a string str(owner.Vr_real).replace('.',',') which receives values of the type: 2045.5 3040,45 4042,05 Note that the first number does not complete with 0 (ex: 2045.50). What function could I…
python-2.7asked 7 years, 7 months ago user2287892 57 -
0
votes1
answer253
viewsInsert Data Tuple into same database cell
I have the following script: import pymysql cobertura = (10, 20) base_de_dados = pymysql.connect("localhost", "root", "senha", "base_de_dados") cursor = base_de_dados.cursor()…
-
0
votes1
answer340
viewsCorrelating vectors through the Python indexes
I have the following vectors: posicao_1 = [4, 62, 24, 18, 47, 62, 63, 78, 68, 87, 24, 18, 6, 8, 12, 17] posicao_2 = [43, 61, 21, 19, 46, 63, 68, 72, 66, 89, 29, 10, 8, 7, 6, 15] I need to search the…
-
0
votes1
answer44
viewsCorrelate vectors through the index and assign different values
I have the following vectors: posicao_1 = [4, 62, 24, 18, 47, 62, 63, 78, 68, 87, 24, 18, 6, 8, 12, 17] posicao_2 = [43, 61, 21, 19, 46, 63, 68, 72, 66, 89, 29, 10, 8, 7, 6, 15] I need to search the…
python-2.7asked 7 years, 9 months ago Danilo 447 -
0
votes2
answers240
viewsConcatenate items into a vector
I have the following vector, which I obtain after consulting a database: a = ['[[10, 20], 10]'] When I try to access their values through the indexes, I can’t. For example, if you type:…
-
0
votes1
answer1335
viewsConvert word(DOC) document to pdf using python
I would like to convert a word(doc) document to pdf using the python 2.7. I have this script, but I didn’t understand anything about it. import sys import os import comtypes.client wdFormatPDF = 17…
-
0
votes0
answers319
viewsHow to stop a progressibar in Tkinter
I have always developed in JS to half lost here in Python, if you can help me... I wanted to let the button close without an event until the progress bar is finished, and the progress bar at the end…
-
0
votes1
answer200
viewsIndexerror: image index out of range using PIL
I’m starting to work with image processing and need to do a simple exercise to double the size of a. I have the following script: from PIL import Image imagem = Image.open("local_da_Imagem", "r")…
-
0
votes1
answer94
viewsImport: No module named manages.alert.views
I am trying to use the following function defined in gerencia/alert/views.py def maLogger(level, message, node=None): aux=0 if level=='Critical_client': aux=2 date = datetime.datetime.now() log =…
-
0
votes1
answer123
viewsUnidentified session in some logins on Django
I am doing a maintenance on a Django app version 1.5 with DRF 2.3. This app features off-the-shelf user authentication that works well. See a summary below: Accounts/views.py class…
python django python-2.7 django-admin django-rest-frameworkasked 7 years, 8 months ago Kaio Cesar 305 -
0
votes1
answer32
viewsVerificaciones periodicas Django
How could I create a loop, thread or anything that my webapp periodically checks every 5 minutes the database and deletes entries that are "expired". I did some research, but I couldn’t find…
-
0
votes1
answer304
viewsWeb Application for Script Monitoring
What is the best way to monitor the execution of a script? I have a.py script that needs to be running "endlessly", and I would like to know if it is running or not. I would like a web application…
-
0
votes1
answer239
viewsPython2.7 with Opencv 3.3.0 - Videocapture problem
I’m running Opencv 3.3.0. with Python 2.7 on a Windows 7 Professional x64 machine, and when I run the code below, falls in the prints "Something went wrong" and "Finished ..." import cv2 capture =…
-
0
votes1
answer1394
viewsHow to improve a bar graph whose values are very close in Python?
I am drawing the bar graph using the following Python code: # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y…