Posts by nosklo • 5,801 points
236 posts
-
3
votes1
answer428
viewsA: Python pandas very slow
The pandas loads the entire file into memory, and this can be slow in case of very large files. Try not to load the entire file. The code below does the same as yours, but without using pandas and…
-
0
votes1
answer2007
viewsA: Problem click python botan Selenium
It seems that when you try to click on the object, it still does not exist on the screen, it is not visible or clickable at the time. Dynamic pages often create the elements before enabling them, or…
-
1
votes1
answer459
viewsA: How to create python module and make available for any application
Create the following folder structure: MeuCodigo\ README LICENSE setup.py meucodigo\ __init__.py meucodigo.py Inside setup.py put the following: from distutils.core import setup…
-
0
votes1
answer100
viewsA: Parse file . txt using Pandas from external rules in a JSON
def extrai_txt(arquivo, layout): for linha in arquivo: yield {c['codigo']: linha[c['inicio']-1:c['inicio']-1+c['tamanho']] for c in layout} Form of use: with open('seu_arquivo.txt') as f: for reg in…
-
4
votes2
answers1460
viewsA: Calculate the sum of a range of numbers entered by the user
When using somatorio = 0 within the repeating structure for, your somatorio will always be reset as 0 before adding up the next number. Remove this initialization from within the repeat structure as…
-
1
votes1
answer339
viewsA: Abort a specific Thread
Unfortunately, unable to interrupt threads. The only way a thread ends is to let her code run to the end. What you can do, if your thread has a loop, is establish a communication channel with the…
-
-1
votes1
answer172
views -
0
votes1
answer220
viewsA: Select column item in Python
Don’t use the os.popen. To run subprocesses in python always use the module subprocess, as recommended in the documentation of popen. Always pass the execution parameters as list, so you avoid…
-
0
votes1
answer151
viewsA: How to recover text from a Tkinter widget created with the Guis PAGE generator?
Your question is incomplete, failed to put the code where you try to access the self.Text1 and the error that is generating. You say the method get() does not return anything, but that is not…
-
0
votes1
answer1287
viewsA: Return from a sub menu to the main menu of a Python function
The problem is that your main menu is not inside the while, but in the scope of the main module, so it does not repeat itself! after it finishes the program is over! Just indent it correctly. I…
-
0
votes1
answer136
viewsA: Read XML and Print Data in Word or PDF with Python
Using the excellent library lxml: >>> doc = lxml.etree.parse(seu_arquivo_xml) >>> print(doc.xpath('//@name')) #localiza elementos com atributo `name` ['AZUL', 'DIREx',…
-
1
votes1
answer51
viewsA: Is it possible to write all the paragraphs that the user only put after the loop in sequence? and in a justified way?
You asked two questions in one. You can write all the paragraphs that the user put only after the loop in sequence? From what I understand, you only want to write after the loop is finished, so you…
-
8
votes1
answer53
viewsA: How can I make the word not break in half? And leave at most 40 characters per line?
Use the module textwrap that comes in python: import textwrap for linha in textwrap.wrap(valor, 40): print(linha) Upshot: In the beginning God created the heavens and the earth. Now the earth was…
-
1
votes2
answers176
viewsA: Chrome bot error - ERROR:platform_sensor_reader_win.cc
The error is caused by this line of code: https://chromium.googlesource.com/chromium/src/+/master/services/device/generic_sensor/platform_sensor_reader_win.cc#242 It occurs when the page tries to…
-
1
votes1
answer107
viewsA: Text Mining python or r
PDF files may have special fields to store this data, as author and date, but I opened the PDF you sent and in it these fields are not filled: So there is no magic, you will need to parse the text…
-
1
votes3
answers152
viewsA: Separate the result that appears in os.getcwd() to be able to display only c:
Use the functions of os.path! Assuming you have a variable d with the directory you want (you can use os.getcwd() to get the current directory, but in the example below I will use the same directory…
-
0
votes1
answer37
viewsA: Ioerror: [Errno socket error] [Errno 8] _ssl. c:504: EOF occurred in Violation of Protocol
The problem is you’re trying to use https and not http, and for that, you need several encryption libs installed and updated. python 2.7.3 is elder (was released more than 6 years ago) and much has…
-
1
votes1
answer57
views -
0
votes1
answer548
viewsA: Variable check if the field is not typed in Python?
You printed the message print("\n\033[47m\033[30mEspaço vazio! Digite um nome...\033[0;0m") But the code keeps running and inserts the empty name anyway! You can only enter the name if it is filled…
-
0
votes1
answer204
viewsA: Use of Class in Kivy
That its function def build(self): return ComboPotenciaConsumo() return ComboPotenciaPainel() Has two return - but when python finds return it closes the function, therefore, the second return will…
-
0
votes1
answer245
viewsA: Movements in the python Tkinter
Do not use time.sleep() because its interface becomes irresponsible. Instead, create a function to refresh the ball’s position, and use tela.after() to schedule the execution of this function from…
-
1
votes2
answers1576
viewsA: Use {%for %} and {%if %} in Django template
{%if video.is_visible == False%} Should be {%if not video.is_visible %} or better, simply use {% else %}…
-
0
votes1
answer363
viewsA: How do I animate an object on canvas with a bind with an animation already "running"
You need a rewrite in your code. When firing the shot, you can’t animate the shot completely to the end. Instead, you must create an object that stores the position of the shot, you can use a class…
-
2
votes2
answers65
viewsA: How to do the inversion of what is received with comma addition?
The code you passed has almost nothing to do with the question - it just reads the names and adds in a list! This example takes a name that is in the variable nome and applies what you did.…
-
1
votes1
answer38
viewsA: tranformative
def eR(k, x): result = 1 for kp in range(2, k + 1): result = (x ** kp) / result * kp return result Com while: def eR(k, x): kp = result = 1 while kp < k: kp += 1 result = (x ** kp) / result * kp…
-
1
votes1
answer270
viewsA: Pass URL list to Scrapy function
You asked two questions in one: would like to pass a list of URL. Looks like you don’t have to do anything, just pass the list. Maybe rename your parameter url for urls just to be consistent? args =…
-
1
votes1
answer353
viewsA: How to capture events in Python?
self.KeyUp += self.TeclaClicada Or self.KeyDown or self.KeyPress... depends on the key you want to capture, some go to an event, others to another... Its function TeclaClicada has to have that…
-
2
votes1
answer668
viewsA: Integrate Rdstation with Django + Python p/ lead submission
Using requests: import requests requests.post( 'https://www.rdstation.com.br/api/1.3/conversions', json={ 'email': '[email protected]', 'name': 'raphael melo de lima', 'identificador':…
-
0
votes1
answer101
viewsA: How to capture multiple HTML values with Django Forms
No Django there’s no need use [] after the field name, you can remove this from your HTML. The problem is that the MultipleChoicesField requires a parameter choices that has to be informed so that…
-
10
votes8
answers4052
viewsA: How to generate 200,000 primes as fast as possible in Python?
I arrived late in answering. However, I will contribute an implementation that is very interesting and useful, because it NO LIMIT NEEDED. It uses the 'Erastóthenes' sieve algorithm, but in a…
-
9
votes3
answers4852
viewsA: How to remove accents with regular expressions in Python?
A simple mode that uses the module unicodedata, included in python, to decompose each Unicode accent into its original Codepoint + combination Codepoint, then filter the combination codepoints to…
-
2
votes1
answer738
viewsA: Python script via PHP
php is not allowed to turn off the computer. It runs with an internal service user, (usually www-data), and this user is not allowed to run the sudo. When you run with your user, on the terminal, it…
-
1
votes1
answer400
viewsA: Fix Encoding Problem while exporting to csv from a scrapy file
You are encoding your strings in utf-8, but it seems that you are using a spreadsheet program to read them that you are not recognizing this encoding. If you are using excel, when importing to…
-
4
votes2
answers1690
viewsA: Change Python string
First of all, remember that python has much more efficient sorting algorithms already implemented in the language, simply calling a function to sort: entrada = ''.join(sorted(entrada)) But to answer…
-
1
votes2
answers107
viewsA: How do you inherit a pygame class?
You can’t create a child class from a module. The inheritance system only works from class to class, and modules are not classes. They are objects, instances of the class module. What you said you…
-
5
votes1
answer3835
viewsA: Read specific line of a txt file
No, text files are sequential byte files, and since each line can have a different number of bytes, there is no direct way to get to a certain line without knowing its position first. To know where…
-
2
votes3
answers2247
viewsA: Typeerror: Object of type 'Nonetype' has no Len()
The problem is that the function display_topics does not have a clause return nor yield, soon she will always return None every time. topics = display_topics(nmf, tfidf_feature_names, no_top_words)…
-
2
votes3
answers836
viewsA: Lists count total amount and higher repeat
Use the collections.Counter: >>> import collections >>> vetor = [1,2,3,4,5,6,7,8,8,8] >>> c = collections.Counter(vetor) >>> print(c) Counter({8: 3, 1: 1, 2: 1,…
-
2
votes1
answer169
viewsA: How to build a basic parse to treat a sentence and extract an action contained in it that will be executed?
A simple way to read commands and call the correct function, is to use the module cmd which comes with python. For example: comando> ajuda Comandos disponíveis: ===================== ajuda andar…
-
3
votes1
answer3175
viewsA: Number of rows and columns of a python matrix
depends on what you mean by "matrix": The pure python language itself does not have a matrix-specific structure. You can use lists inside lists, but there is no way to determine the size without…
-
1
votes2
answers724
viewsA: Flask MVC - doubts
You have defined a Folder template with the name of template here: template_folder='template' However through the image it is possible to verify that the folder you created is called templates…
-
1
votes2
answers824
viewsA: Read a csv file and add your data into a dictionary
Your code didn’t work because you are trying to repeat reading the file: for u in header: # ... for line in reader: The first time will work, but the second time, reader has already been consumed.…
-
2
votes2
answers106
viewsA: Python - libraries without import "*"
When importing the other module with import nome_da_biblioteca it runs and its namespace is added to the current module in a module type object with the same name as the module. So, just use…
-
2
votes1
answer441
viewsA: How to get the index comparing two lists of different lengths in Python?
As you have not provided any code, I will invent here in a simple way: lista1 = [ 'ARS-BFGL-BAC-10919', 'ARS-BFGL-BAC-10975', 'ARS-BFGL-BAC-11000', 'ARS-BFGL-BAC-11003', 'ARS-BFGL-BAC-11025',…
-
0
votes1
answer137
viewsA: How to run this script in a more sophisticated way?
You don’t have to make it so complicated ip as a parameter of __init__ of its original class even, without creating more sublevels: #!/usr/bin/python from paramiko import SSHClient import paramiko…
-
0
votes1
answer25
viewsA: Organize tabs in pyqt4
QT doesn’t have that object, so you’d have to do manually: Create a vertical layout, place one QStackedWidget and several QTabBars. You will have to manually define methods to ensure that only one…
-
1
votes1
answer225
viewsA: Return HD size and free space to client-server
There’s a problem here: lista = pickle.loads(dest) dest is a tuple, so there’s no way you can decode using pickle. I imagine you want to receive data from the socket using recv or recvfrom first,…
-
1
votes1
answer272
viewsA: How to replace a certain sentence of a Python string? Using re.sub()
>>> import re >>> tentativa = 'Olá td bem? *:palavra_proibida*985 td otimo' >>> resultado = re.sub(r'\*:\S+', '', tentativa) >>> print(resultado) Olá td bem? td…
-
2
votes2
answers408
viewsA: Django + Python update and do not insert
form.save() saves the form, and not the student. Since the form has all the data, it tries to create a new record. Try to change the line student = form.save() for student.save()…
-
11
votes2
answers523
viewsA: Eval vs Ast.literal_eval: what are the differences?
The two functions compile the code, but ast.literal_eval only executes the code if it is a literal of a basic object: strings, bytes, numbers, True, False and None. In addition, tuples, lists,…