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
-
1
votes1
answer393
viewsHow to remove null, false and true values from Json file?
I have a JSON file with this data: { "in_reply_to_screen_name": null, "favorited": false, "id_str": "92", "entities": { "user_mentions": [], "symbols": [], "urls": [], "hashtags": [ { "indices":…
-
1
votes1
answer502
viewsHow to organize pygame code correctly?
I came from Javascript which is a little simpler than Python, there I didn’t need to worry too much about scope (almost everything was global) and not about code organization. But in Python even if…
-
1
votes1
answer363
viewsCreate a python function that returns a number that is the amount of equal values of two columns
I am trying to create a function that returns me a number that is the amount of equal values in two columns. (I am new to programming) I tried the following (I don’t know how wrong it is): e = 0…
pythonasked 6 years, 10 months ago Victor Boscaro 33 -
1
votes2
answers1545
viewsHow to increment the value of a variable according to the user’s response?
I would like to ask the user a question to answer "yes" or "no". If the answer is "yes" add 10 weights to the variable peso and if "no", do not add. I have a question about how to convert the string…
-
1
votes1
answer33
viewsDictionary running all keys instead of just one
I have in the following code I have a function that performs certain operation according to the parameters passed. Then I have a dictionary serving as switch case, which will serve to define which…
-
1
votes2
answers2468
viewsDoubt about Keypress in Pygame
I have a question related to Pygame. I’m starting to move and I found a problem here. When I press the button A(left) I make the image walk to the left, until then everything ok. But if I hold down…
-
1
votes1
answer2885
viewsHow to open a Python file selection window with GTK?
I have a Python application using GTK graphical user interface. This interface consists of a screen with data input a button, the goal of the program is to save data in spreadsheets in a specific…
-
1
votes0
answers140
viewsTask Bag (Bag of Tasks) for Matrix Multiplication
I would like the help of you to do this work, I have little practice in programming and I need to do in Python that I am still learning. The work is as follows: This work consists of dividing the…
pythonasked 7 years ago André Salgueiro 11 -
1
votes1
answer2290
viewsHow to use python round
When I use the python round it converts 1.5 to 2, but with 2.5 it leaves 2. How do I make it round 2.5 to 3 ? Where any number other than the number 2
-
1
votes1
answer2970
viewsHow to manipulate docx files using python?
I created two files docx but I can’t write to them (using python) but I can do it with txt files. The question is I could create a file docx and write in it using a python script?…
pythonasked 6 years, 9 months ago Arthur Peixoto Ramos 13 -
1
votes1
answer336
viewsPython - How to add add values between row and column in ndarray
Hello, I am having the following difficulty, this because I am working with numpy now, I am inexperienced... Well my problem is this, I have a tuple (w, t), and the t repeats itself, so that I want…
-
1
votes1
answer860
viewsBeautifulsoup - True href links
I was studying about Webscraping with Python and started using the bs4 bilioteca (Beautifulsoup). When I started picking up the tags a and the attribute href, I realized that I could not access the…
-
1
votes1
answer604
viewsHow to integrate and make queries with pymongo?
I am learning to integrate Python and Mongodb and, because of that, I proposed a challenge: create a small program to register football players. My program has two modules, info_player and…
-
1
votes0
answers468
viewsInterpolation Spline in python?
What is the best method to interpolate Spline second-order Python? I’ve used interp1d, but not quite what I intend. Example of what is intended. from scipy.interpolate import interp1d import…
-
1
votes1
answer1914
viewsPassing a list of objects to a python dictionary
I have a list of objects: lista_objetos = ['acarreta', 'afeta', 'alavancagem', 'apropriadas', 'arvore', 'avaliacao'] each object stores information, among that information the word itself, Ex:…
-
1
votes2
answers289
viewsDjango create paging using Ajax
I want to upload the pagination without refresh using ajax I have a table where shows 5 items per page the goal is to change page not refresh the page to switch to the following In the views: In the…
-
1
votes1
answer83
viewsHow to load only one line and modify it
I want to modify just one line of a file, something like that with open('arquivo.txt', 'r+') as f: for line in f.readlines(): if line == algumacoisa: line.write('textoaqui'); break f.close() I saw…
-
1
votes2
answers4838
viewsChanging a value with the pandas library
I’m opening a file. csv with the pandas library, but I am informed at the time of opening this file that a given column presents values of different types. I know that the character "/" was used in…
-
1
votes1
answer246
viewsPython binary search giving Wrong Answer in Moj
def busca(num, a, primeiro, ultimo): meio = int((primeiro + ultimo) / 2) if num == a[meio]: return meio elif num < a[meio]: return busca(num, a, primeiro, meio) else: return busca(num, a, meio+1,…
pythonasked 7 years ago João Pedro Ache Virgili 111 -
1
votes1
answer1599
viewsList manipulation with dictionary inside a Python loop
I have a list of lists, in which the internal lists contain words and each internal list represents the words of each different file. lista = [['carro','barco'],['moto','aviao'],['bike','skate']] ie…
-
1
votes1
answer75
viewsPython language format function in C#
int varvalor; int var01 = varvalor * 1; Console.Write("Digite um número para ser multiplicado: "); var01 = Convert.ToInt32 (Console.ReadLine()); Console.WriteLine(); I wanted to write on…
-
1
votes1
answer715
viewsHelp in Python! Guessing game!
I need some help in this little game. The point is this, the game I’ve made and it’s working perfectly, what I need actually is the loop with the While. I can not find the error, while the user does…
pythonasked 7 years ago GratefullyDead 373 -
1
votes0
answers2543
viewsGenerate custom report with Python
someone has worked or seen someone develop custom python reports? For example, in Java we can easily create a report with iReport that features sample templates and new templates with drag-and-drop…
-
1
votes2
answers1152
viewsSquare Matrix in Python 3
My code is printing spaces at the beginning and end of the line, and is giving presentation error (URI issue 1557) Does anyone have a good tip? "Matrix values should be formatted in a…
-
1
votes1
answer1183
viewsHow to Separate Data in Dictionary from a . txt (Python)
I have a text file (attachment.txt), which I have to store in a dictionary, with Name as key and phone, value. the file has the following information: --- nome telefone --- Ailton-1197765445…
-
1
votes1
answer54
viewsHow to allow only the creation of valid objects in Python?
class Linha(object): def __init__(self, x, y): self.x = x self.y = y @property def x(self): return self._x @x.setter def x(self, valor): if valor >= 0: self._x = valor @property def y(self):…
-
1
votes0
answers72
viewsHow to update the position of the text when changing the position of the button?
I have a boot class that is a Sprite and has as attribute text that is also a Sprite. I was wondering how to change the position of the text when I change the position of the boot rectum? import…
-
1
votes1
answer58
viewsError creating Python object
class Linha(object): def __init__(self, x, y): self.x = x self.y = y @property def x(self): return self._x @x.setter def x(self, valor): valor = int(valor) if valor >= 0: self._x = valor else:…
-
1
votes1
answer305
viewsGenerate pdf file from a pdf Object
I’m interested in making a crawler to work with pdf, but hit me a doubt here. I need to download files pdf of a python url, when it has a .pdf it’s easy and no problem, but when she’s a objeto pdf I…
-
1
votes1
answer2590
viewsCheck the highest prime number - using while and if only
I’m having trouble solving an exercise in logic, I think I’m thinking wrong: What I need: Given a number N show the largest prime number up to N. The code I’ve made so far is this: def…
-
1
votes1
answer448
viewspython cannot use break
This is a little game that simulates a race. However, when a player reaches level 3 I want him to stop loop and reset all data, but I can’t use the break so that when the level of one of the players…
pythonasked 7 years ago Marcos Vinícius 21 -
1
votes0
answers359
viewsSelenium works with Firefox, but not with Chrome
I was normally using Firefox on Selenium with Python, but I wanted to do some testing using Google Chrome, so I made the following change: self.driver = webdriver.Firefox() To self.driver =…
-
1
votes1
answer655
viewsConditional upon Bhaskara’s calculation
I’m trying to add a if to show the order of the increasing numbers in Bhaskara’s formula, however it shows error message if the root is negative or there are no roots. How can I adjust? import math…
-
1
votes1
answer3056
views"list indices must be integers or Slices, not Nonetype"
I’m trying to develop an old game in python, which gets a user who will play against the computer, the output should say the winner of the game or got old. Almost everything is correct except when…
-
1
votes1
answer180
viewsDoes using "from x import y" in python reduce the size of the application?
If I make an imposition in the form "from X import Y" instead of "import Y" I am saving on the size of the final application or it makes no difference? Let’s say within Y has thousands of functions…
-
1
votes0
answers53
viewsProgram in Python 3
I’m a beginner in Python 3. I’m using Pycharm v.2017.3.3 and would like to know how to finish my project "Hello World" for a friend to run on your Windows. Someone could help me? Grateful.…
pythonasked 6 years, 9 months ago Fernando Barros 39 -
1
votes1
answer27
views: column in front of variable
Oops, coming back with the column question before the variable. Example I’m seeing in python in neural recurring. arr = arr[:n_batches * batches_size] what the :n_batches ?…
pythonasked 6 years, 9 months ago Cassio Kawakita 11 -
1
votes2
answers173
viewsWhat is the logic of python for i 'in'
I’d like to know the logic of for i in vogais, as in the example. Doubt, it carries the entire typed word in a list in memory and already sorts according to our classification,or it reads character…
-
1
votes0
answers56
viewsHow to check connected tty ports in Python?
I have a device that is connected to the computer and I need to verify which devices are connected and information about the device, to then take the name of the port and initiate a communication.…
-
1
votes1
answer167
views"If(a == b):" or "if a==b:" in Python, which is correct?
I’ve seen two ways to express conditional in python, using or not (). With (): if(a): print('x') Without (): if a: print('x') Which of the two ways would be the most correct to use?…
pythonasked 6 years, 8 months ago Lucas Stern 43 -
1
votes3
answers2049
viewsHow to start full screen window with Tkinter?
from caixaimport import * # Variables # Tkinter Variables win_width, win_height = 1280, 1024 windows = Tk() # start a variable Tk windows.geometry(f'{win_width}x{win_height}') windows.title('SCH…
-
1
votes1
answer301
viewsAutomatic condition for a variable.
I created a character for a game using a class and within that class I placed the attribute life = 10. During the course of this character, he receives some damage from enemy damage attacks which I…
pythonasked 6 years, 8 months ago Pedro Henrique Santos 19 -
1
votes1
answer1063
viewspython command to "grab" text from Qt Designer fields and save to sqlite
Good afternoon. I’m enthusiastic and I’m starting in python. With Tkinter I can send the text of the fields to the database with the function "get()", in gtk, if I’m not mistaken, with "get_text()".…
-
1
votes3
answers2116
viewsCreate table csv in python
I’m trying to build a table from information collected on a website. The problem is that although the print comes out as expected, at the time of saving in csv file is going only the last record.…
-
1
votes1
answer71
viewsWhat is the right way to do the template in Django/python?
This has been my first contact with the framework and with mvc/mvt, and I’m in doubt, as a matter of good practices and tals, should I make a template for each of the views or should I just make a…
-
1
votes0
answers55
viewsDjango Channels Routing not working
I wanted people to access my URL normally like before (install Channels) localhost/home/minha-slug and detected the socket messages within that route. I want to create Groups so I don’t keep sending…
-
1
votes0
answers24
viewsFilling a series of images from data in a table
I need to make portfolios for about 500 people, I have a table with the name and image attached and I want to know how to put this data in the portfolio template.
-
1
votes1
answer666
viewsPoint of Intersection between two lines using Geoplades
Good morning to you all. I’m making a code and I came across a problem. I am using Geopandas and I need to find the intersection between two lines (Linestring Z) and the respective elevation values…
pythonasked 6 years, 12 months ago Vinicius Nogueira 11 -
1
votes1
answer7390
viewsBubble Sort Algorithm in Python
def bubble_sort(lista): elementos = len(lista)-1 ordenado = False while not ordenado: ordenado = True for i in range(elementos): if lista[i] > lista[i+1]: lista[i], lista[i+1] =…
-
1
votes0
answers95
viewsHow to read comma-separated numbers in a text file?
Hey, guys, hey, hey, hey, guys!. Next,I have an archive where I have several comma separated values.I need to turn these values in a list,and even then it’s quiet. The point is that using the python…
pythonasked 6 years, 12 months ago GratefullyDead 373