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
-
4
votes1
answer1443
viewsWhat is the difference between dump and dumps from the Pickle module in Python?
I have read the documentation of Python and also of Pickle himself, but I could not assimilate the content (lack of examples). On the Web I only found information about using "dump + load" and…
-
4
votes1
answer1262
viewsHow to get out of a loop with hotkeys
I have an app that runs in the background in an infinite loop. How do I stop the loop using hotkeys (Ctrl+F1~F12)?
-
4
votes1
answer651
viewsHow to copy the path of a selected file in Window Explorer?
How to copy the full path containing the file name to the Clipboard using the "shortcut" CTRL-C? For example: Inside windows explorer select a file (teste.py) using the CTRL-C and then the CTRL-V in…
-
4
votes1
answer683
viewsSort lists with two sort criteria
If I have a list of lists like this: lista = [['ana','1'], ['joao', '3'], ['rita','2'], ['alice','2']] I first want to sort the list according to the numbers, to look like this: lista =…
python-2.7asked 9 years, 5 months ago CSAnimor 731 -
4
votes1
answer202
viewsUnexpected Error using parse_args() function of the Argumentparser object in Python
In a simple code I’m doing in Python, I get the exception below, when I call the function parser_args() on the type object ArgumentParser: Unexpected error: (<type 'exceptions.SystemExit'>,…
-
4
votes3
answers23189
viewsRecursive and iterative function that calculates the factorial from 1 to n
Good people, wanted help with an exercise: It asks to create a function that calculates the factorial of the numbers from 1 to n. I already have the recursive part, but I don’t know how to make it…
-
4
votes1
answer13184
viewsassignment list index out of range
Part of my Python program is: dt=1 maxt=3600*2 t=range(0,maxt,dt) r=len(t) Tsup_i=20 for i in range(1,r): Tsup[0]=Tsup_i P[i]=((I_dc)**2) * R20 * (1 + a * (Tsup[i] - (20+K))) And the error is…
-
4
votes3
answers1388
viewsMinimum search from a list ignoring zero values
I have a list of values with zero elements and elements other than zero and I wanted to return the lowest value of the list and its Index, but ignoring the zeroes, that is, the fact that there are…
-
4
votes1
answer86
viewsHow to get an end list for the start?
Opening lists: B_I = ['Cab', 'Bou', 'Bou', 'RFF', 'RF1', 'Rf2', 'Cor'] Ba_F = ['Bou', 'Zez1', 'Zez2', 'Praca', 'Sro', 'Sro', 'Falag'] Then I did ........ Final=[] #lista com todos os barramentos sem…
-
4
votes1
answer266
viewsHow to execute arbitrary code in Python?
I use an xbase language that has macro substitution as in the original Clipper. Is there anything equivalent in Python? We use a lot of command line assembly via menus at runtime. For example,…
-
4
votes1
answer2424
viewsrunning split() to form a list within another list
have the following list: [['a:/, b:/, w:/, g:/, f:/, d:/Downloads/Torrent/End, x:/files.2t, y:/files.1t'], ['d:/Dropbox/project/rato_bat'], ['data']] however I would like it to be a list within…
-
4
votes2
answers337
viewsData entry without echoing on screen
entrada = input("digite a senha") If I use the function input, what the user keystrokes will be echoed on the screen. How to do so so that nothing is shown on the screen?…
-
4
votes1
answer260
viewsHow to install Python 3
I’m new to Ubuntu and I’m learning Python. I have installed on my pc Pyhton 2.7.12 and would like to know how I do to upgrade to version 3. I’m taking a course where I need to use a lib. import…
-
4
votes1
answer859
viewsHow to repeat a function call every X seconds in Pyqt?
I am developing a small application in Pyqt4 where I need to upload the data to a table coming from a Webservice. This I managed to do quietly. However, now, I need that every 1 minute, these data…
-
4
votes1
answer77
viewsList being modified without implementation
I’m having a problem where the list I’m working on is being modified even though there’s no value passing to it. from random import * from numpy import * m=2 lista_inicial=[[1, 2], [0, 2], [0, 1]]…
-
4
votes1
answer114
viewsRobo_feed routine of checking if loop giving dick in python
Robo_feed I’m new to python, I was looking to develop a robot that would take the last post of some news portals here in my region, With a survey I came to the conclusion that it would be easier to…
-
4
votes2
answers57
viewsWhat function do I use to return or show all the equal numbers in a list of 20 numbers?
n = [] for i in range(20): n.append(int(input("Digite o número: ")))
-
4
votes1
answer438
viewsPython remover() list index out of range
def gera_huffman(simbolosOriginal, probabilidadesOriginal): # gera_huffman(['a', 'b','c', 'd'], [5, 2, 1, 2]) simbolos = simbolosOriginal probabilidades = probabilidadesOriginal lista = [] while…
-
4
votes1
answer135
viewsDoubt: how to use python scripts for web?
I want to make a web application that will read colors in RGB logos and create suggestions of color scales for websites. The algorithm will be in python, using Opencv. The client moves the image…
-
4
votes3
answers9942
viewsRemove non-numeric characters from a Python string
Let’s say, I have: a = "0LÁM@UN@D0 I would like something to remove all letters (A-Z) and other characters, I just want to get the numbers, in the example, would be only 0 and 0 b = "A1B2C3"…
-
4
votes1
answer202
viewsImplement a blink counter in the face detection
As q do to display the amount of flashes of people detected at the time. The code below detects face with Haar Cascade, where it displays a face counter. from __future__ import print_function…
-
3
votes1
answer146
viewsDjango - How does Developer @login_required work in views from another app?
I have a project in Django and only an application where I do registration, searches, login to the system, etc. I was reading an article about the creation of projects and saw that for the sake of…
-
3
votes1
answer694
viewsHow to build a url in Django?
I am learning Django, but one thing I have not understood so far is, how to build a url, I know it uses regular expression, but someone there has how to explain to me, or indicate me a material that…
-
3
votes2
answers221
viewsPython error access is denied
This gives this error when trying to run the project: before that I had installed python 2.6 on the machine ... but it already had python 2.7 will have caused the error ? [Error 5] Access is denied:…
python-2.7asked 10 years, 8 months ago Wisner Oliveira 473 -
3
votes1
answer479
viewsHow to simulate a form action=POST with urllib2
I want to create a program that reads my college notes and display on the screen , for this I am using urllib2 to receive the web page where my notes are presented but to receive I need to log in.…
-
3
votes1
answer230
viewsPython subprocess.check_output command
I am calling a program in Java via command subprocess.check_output python. It is not working. In this command I pass a file as parameter. There’s something wrong with the command below? import…
-
3
votes1
answer112
viewsAttraction of objects in python
I’m writing a code where one image goes toward another only for some reason it’s not working. I take the distance between them calculate the gravitational force Fg = G*M1*M2/D^2 of attraction…
-
3
votes1
answer84
viewsEditing of python files
I intend to insert in files .py the stretch below: -*- encoding: utf-8 -*- needs to be in specific line, and in large amount of files. Is there any Unix/linux tool that can perform this task?…
-
3
votes3
answers9505
viewsDifference between dates/times in Python
I need to calculate the difference between two dates in python, but always some error. >>> from datetime import datetime >>> data1 = datetime(2015, 8, 5, 8, 12, 23) >>>…
-
3
votes1
answer169
viewsHave two versions of Python in OSX, no overwrite
Is there any way to install version 3.x of Python without overwriting the pre-installed (essential) version of OSX? I already know the virtualenv but I would like to avoid it, because I only use…
-
3
votes3
answers1652
viewsHow to start a Django project using virtualenv?
I have searched and found several different ways and conventions to create a project in Django using virtual environment (virtualenv). Is there a pattern to this? Someone helps me with a correct…
-
3
votes2
answers1883
viewsHow to remove spaces at the beginning and end of an XLS output
I have the code below, for him to open a spreadsheet on XLS and show me the header. however I would like the left and right spaces to be removed and the internal spaces to be replaced by underline…
-
3
votes1
answer169
viewsHow to change the width of columns in the Admin listing in Django?
How do I specify the width for the columns that are displayed in the Admin listing, more precisely the ones I specify in list_display in admin.py. Researching I found similar question here, where I…
django python-3.x python-2.7 django-templates django-1.8asked 9 years, 3 months ago Marcio Luís 1,061 -
3
votes3
answers479
viewsMaximum occurrences in a python dictionary
If I have the dictionary: meu_dic = {A:3, B:5, C:0, D:10, E:2} resulting from: meu_dic = {i:lista.count(i) for i in lista} I know that To appears 3 times in the list, B 5 times, etc.. How can I…
-
3
votes1
answer1218
viewsFind out if a point is within a circle on a Cartesian plane
I was doing the task Target shooting of the 2013 Brazilian Computer Olympiad (OBI) at Programming level 2, which can be found here, and I was able to do it without great difficulty. The task was to…
-
3
votes2
answers591
viewsStart a command line tool in Python
How can I create a command line tool in Python that works like ls linux or dir windows? How would I start one script like the one that will later be compiled as an executable?…
-
3
votes2
answers2075
viewsChange color and border size Tkinter Menu
Can someone help me with this question?…
-
3
votes1
answer415
viewsHow do I set a Tray Icon (tray icon) in a Pyqt application?
I’m still a beginner in Pyqt and would like to clarify a question: Is there any way to define a Tray Icon (Tray Icon) in a Pyqt application? If so, how can I do it? I need to set some options on…
-
3
votes1
answer498
viewsError with scrapy requests
I have a csv file with some urls that need to be accessed. http://www.icarros.com.br/Audi, Audi http://www.icarros.com.br/Fiat, Fiat http://www.icarros.com.br/Chevrolet, Chevrolet I’ve got an Spider…
-
3
votes1
answer340
viewsImport Mysql data to Excel
To want to import data from Mysql to excel using Python, when I try to make it from an error of tuple. Someone with more experience can help me? I followed the code and the error: # coding=utf-8…
-
3
votes2
answers202
viewsDisplaying certain vectors in a 2D Python list
I have the following situation: - I have a variable called (vector_distances). This variable receives a 2D list with several vectors. - I wish it to be displayed, only vectors whose sum of their…
-
3
votes1
answer229
viewsTypeerror: a float is required
This is my code: ### BIBLIOTECAS import scipy.special as sps import numpy as np import matplotlib.pyplot as plt import pandas as pd import scipy as sp from scipy.stats import norm from scipy.stats…
-
3
votes2
answers599
viewsList of square roots
How can I make a function that takes a parameter n, return a list of the first n square roots, using higher-order functions, in Python. As shown below: [sqrt(1), sqrt(1)+sqrt(2),…
-
3
votes1
answer113
viewsHow to do this regular expression in python 3.6
I need to do a regular expression to extract the links from this string : links…
-
3
votes2
answers1109
viewsNumber divided by a divisor greater than it returns zero?
I went to do a calculation on Python 2.7 and got scared when I saw the result: val = 1 / 16 print(val); # 0 Example in IDEONE That is, when we make a division where the divided number is less than…
-
3
votes2
answers6824
viewsAutomatically create vector in Python
I’m new to Python and need help with the following: I have a variable (x) that takes an integer value. I want this variable to be used to create a vector with 1 row and (x) columns. This vector must…
-
3
votes1
answer393
viewsWhy does input work in Python 3.x and not 2.7?
I ran this same code with just a few minor differences in syntax to suit the right mode of script in Python version 2.7.9 and also in Python 3.4.2 Script I ran in Python 2: name=input("tell me your…
-
3
votes1
answer649
viewsOpen multiple files with "with open"
It is possible to open more than one file in a program with with open("meutexto.txt", "r") as f: I didn’t find anything about it (or didn’t look hard enough). I know it’s possible to do otherwise:…
-
3
votes1
answer1093
viewsRemove repeated words using python
I have a text file with many repeated words. I need every word in the file to appear only once. import codecs wordList = codecs.open('Arquivo.txt' , 'r') wordList2 = codecs.open('Arquivo2.txt', 'w')…
-
3
votes2
answers95
viewsDoubt about importing libraries
Let’s say, there’s folder A. In this folder A there is the lib folder. In this lib folder, there is a library called example.py. How do I stop importing the.py example? I see it’s possible to import…