Posts by Begnini • 1,681 points
46 posts
-
1
votes1
answer61
viewsA: Web Scraping iterator taking only elements with odd index
The problem is that you have 2 Divs with class nm-features-container for each element. The right one then would be for you to be more specific about which div you want. Looking at HTML, there is a…
-
2
votes1
answer35
viewsA: Graphic problem
The problem is that when you read the data, even though they are numbers in the file, they are strings, so Plot interprets them as if they were classes and not numerical values. To solve this just…
-
0
votes2
answers120
viewsA: Error in Python script
The problem is simple, you are passing the Angule in degrees and the function should receive the angle in radians. I refactored the code a little bit because I didn’t understand that sum of your…
python-3.xanswered Begnini 1,681 -
0
votes4
answers931
viewsA: Python columns excel csv
CSV (comma separated value) is a file where commas (,) delimit the columns. If Voce wants to create a file with the first blank column, Voce should put a comma in the first char of the string that…
-
0
votes3
answers155
viewsA: Why does print() print outputs one below the other and not the other?
The signature of the function print is the following: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) The third parameter, end, is what python will put after its string (line break…
-
3
votes1
answer48
viewsA: Setting an array element with a Sequence
Images in Opencv are arrays, Voce is forgetting to use the indices of the array to catch the color #auxCor em B, G, R auxCor = imgThresh[i, j] I don’t know if your job is just an exercise, but you…
-
1
votes1
answer62
viewsA: true giving problem(bug) in code
The problem is in the function func_get_args. It takes all arguments passed to its function, including the initial boolean. You have to remove this boolean from your array and then work alone with…
-
1
votes1
answer768
viewsA: PHP CURL Asynchronous
You are able to make this query using the functions curl_multi_init and curl_multi_add_handle. Imagine you have a function that creates a request, returning Curl Handler, as below: function…
-
2
votes1
answer46
viewsA: Difficulty removing Child, Python
Since you are using Beautifulsoup, you can use the method replace_with that each node contains. It allows you to swap the contents of the tag with a specific html. In case I swapped the contents for…
-
2
votes3
answers840
viewsA: Replace word list in text
I believe the simplest is for you to break every line in words, with the method split and see if that word is or is not a stopword. import csv import itertools with open('texto.txt', 'r') as file,…
-
0
votes1
answer239
viewsA: Download File via API + Lumen + Maatwebsite Excel
The problem is in the first parameter of the download method. ->download('xls', $headers); You’re telling the library to generate one xls, while throughout the rest of the code you are using CSV.…
-
2
votes1
answer438
viewsA: Compare 2 Text Files, and find equal words
As you have not specified the language, I will offer the simplest solution, in bash. $ grep -f arquivo1.txt arquivo2.txt > animal > fogo The -f parameter tells pro grep to pick up what will be…
-
12
votes2
answers1150
viewsA: How to count the objects present in the image with PHP?
If you can install an extension it is possible to do with php-opencv. First, with the image with name feijao.jpg sage, we can read it in shades of gray. $image = imread('feijao.jpg',…
-
1
votes1
answer264
viewsA: REGEX to remove websites, emails
The problems of these regular expressions are in the operator .*. The operator * is greedy, ie, it will try to match as many characters as possible of the string. The ideal is whenever possible, to…
-
0
votes1
answer127
viewsA: How to store a chained list
The difference is that a and b are pointers. When Voce does: a->ant = b->ant; a->prox = b->prox; a->dado = b->dado; a and b has the same values. But when you do: a = b a and b are…
-
1
votes1
answer1547
viewsA: multiple commands with python subprocess
The method Popen.communicate() has a parameter, called timeout that does exactly what you need, waits for n seconds and, if the process has not returned, kills it and triggers a Timeoutexpired…
-
8
votes1
answer101
viewsA: Get the least significant bit of an integer in Java
To get the least significant bit, just do the operation AND bit by bit of the integer you want to get the bit with the number 1. In binary (32 bits) 1 is represented by the first 31 bits 0 and the…
-
2
votes1
answer112
viewsA: Imports within Python functions
There are 2 reasons the developer does this: Performance - The import will happen only when the function is called, and if it is never called, the interpreter will not need to load the module.…
-
3
votes2
answers2513
viewsA: SQL - How to Get Last Day of the Previous Month Dynamically In This Situation
Postgresql has several functions to manipulate dates. First, with date_trunc, you truncate the date to have the current year and month. From the documentation: field selects to which Precision to…
-
2
votes3
answers191
viewsA: How to create a dictionary with a word and its adjacent from a string?
First you break the phrase into words: words = texto.lower().split() With this list of words, simply iterate over it by attaching the next word. So you don’t have much work, you can use the works…
-
2
votes1
answer217
viewsA: SQL JOIN multiple tables
First I will create the tables, in the same way that Voce mentioned ae, populating them: Client table postgres=# create table tabclientes (codcli int, nome varchar(10)); CREATE TABLE postgres=#…
-
0
votes2
answers47
viewsA: How to dynamically get specific day in a query
Postgresql has 2 methods to manipulate dates. First, with date_trunc, Voce truncates the date to have the current year and month. From the documentation: field selects to which Precision to truncate…
-
0
votes1
answer42
viewsA: Error in classifying text with a tree
You should only call the method fit_transform during training, in the test you should call only the method transform of your vectorizer. In your test, change the line: fwTexto =…
-
2
votes1
answer79
viewsA: Code is skipping lines - Python
The problem is the reading of words: palavras = arq.readlines() the method readlines returns a row, including with the n at the end. From the documentation: f. readline() reads a single line from…
-
1
votes1
answer3970
viewsA: Calculating minimum, maximum, mean and median in python
You cannot initialize min_trip with 0. By doing this, your code will never enter the condition: if int(t) <= int(min_trip): Initialize this value with a large, type value 9999999 or the first…
-
2
votes1
answer192
viewsA: Problems with __eq__, __lt__, etc. and the method removes from the list object
The problem is simple. The method list.remove searches the object you passed by parameter in the list and removes it. To know that it found the correct object, it uses the method __eq__ to compare…
-
2
votes1
answer363
viewsA: Script execution error in python in Laravel controller
Your webserver has different environment variables than your shell. To get an idea of what your environment’s PATH looks like, you can use the function getenv. For example: echo getenv('path'); To…
-
3
votes1
answer899
viewsA: Convert Days & Time (Hours x Minutes x Seconds) to Time only
The problem is that the %H of the datetime.strftime goes only up to 23. As per the documentation: %H - Hour (24-hour clock) as a zero-Padded decimal number. What you have to do is a function that…
-
0
votes2
answers770
viewsA: What is the difference between namedtuple and Namedtuple?
With typing.NamedTuple it is possible to put type in attributes, while with namedtuple no. Another difference is that with typing.NamedTuple it is possible to have default values for some of the…
-
1
votes2
answers187
viewsA: In which scenarios is Elasticsearch worth using?
Overall, for relatively simple searches Postgresql is good enough, which should probably be your case. Elasticsearch becomes really relevant when you need more complicated search engines, such as…
-
2
votes1
answer389
views -
2
votes1
answer226
viewsA: How to detect a click or other mouse event in win32gui’s Notifyicon?
The Win32 GUI API is controlled through messages, which are sent to a queue of process messages and wait there until they are processed. For a callback to be called, you need to consume the incoming…
-
3
votes1
answer1686
viewsA: sklearn’s classification_report and confusion_matrix: do the values not match?
I will try to explain step by step the analysis so that you can understand the problem or someone else with the same problem can understand how to solve these things. First, I’ll generate two…
-
1
votes1
answer249
viewsA: Update Cakephp Version to Newer
Cakephp has changed a lot from version 2.x to version 3.x. The code is incompatible, especially the data query (ORM) part of it. Cakephp developers made a tool to help -…
-
2
votes1
answer915
viewsA: Translate Captcha
Captcha breaking is not a very trivial problem, you need to know a little bit of image processing, even for simple cases. This captcha image is simple to break compared to most of the captcha that…
-
1
votes2
answers2255
viewsA: Where in a JSON Postgres Array
The tricky thing here is that filters is an array, so you can’t do the query directly, you have to scroll to each position of it. For this, you must use the function jsonb_array_elements(jsonb). It…
-
4
votes1
answer4268
viewsA: How to get any kind of cookie using Selenium?
This is a cookie HTTP(S) Only, that is, it cannot be accessed via javascript. To get it, you can access the HTTP headers of the request. I use the lib in python seleninum-requests, which is similar…
-
4
votes1
answer597
viewsA: How to calculate Shannon entropy based on HTTP header
I don’t know what the structure of your package returned by pyshark looks like, but I imagine it has 2 information, the IP address and the contents of the package. Imagining that you have these 2…
-
0
votes1
answer620
viewsA: Using glob in Python
All you have to do is make a if to see if the file starts with one or the other beginning. from zeep import Client from xml.dom import minidom import os import glob hasha =…
-
0
votes4
answers5300
viewsA: How to fix the number of numeric characters in a float?
Turn it into a string and then cut it out. If the number is smaller than the size you want, fill in with zeros on the left: def numero_sete(numero): numero = float(numero) numero = str(numero)…
-
1
votes2
answers541
viewsA: How to separate string in array?
You have to break into 2 parts, first break each field, as you are doing, then break each field into key / value and put into an array. created a function that does this, just pass the text that…
-
2
votes2
answers225
viewsA: Regexp extract value
You have to turn your template into a regex. As it has several characters that are special to a regular expression, you first need to escape them. Then just replace {SE} and {EP} by a group catching…
-
3
votes1
answer164
viewsA: Error in dictionary key
When you add a Dict to a list, you are only adding a reference, not a copy. For example: >>> professor = { >>> 'nome': 'Alan Turing' >>> } >>> print (professor)…
-
-2
votes2
answers65
viewsA: How to recover everything after the "?" in Rewriterule?
Is this the only rule that the URL passes? If I understand correctly, just deny the symbol ? in the rule and everything should work out as you want. RewriteRule ^chk-error/(^?.*)…
-
2
votes1
answer290
viewsA: Install PCNTL on Ubuntu 16.04 PHP7
If you install PHP via apt-get, it already comes with Ubuntu-enabled PCNTL. You don’t need to install anything. begnini@coffee-machine:~# php -i | grep pcntl pcntl pcntl support => enabled…
-
4
votes2
answers124
viewsA: Simple XML Reader: I can’t convert nodes to HTML or limit the number of items
The solution can be using simple xml, which already comes with PHP? The secret is to use the method position XPATH to filter the records you want. function parse($url, $offset = 1, $limit = -1) {…