Posts by Rafael Barros • 840 points
28 posts
-
2
votes1
answer1847
viewsA: Error reshaping an image | Valueerror: cannot reshape array of size 72000 into Shape (1.24000)
Your image array has 72000 positions and you want to turn it into a 200x120 array, which totals 24000 positions. But why 72000 positions, being that its image is 200x120? If your image has 200x120…
-
5
votes2
answers301
viewsA: Changing data types in a Python list
The error there is that there is no variable acs declared with an eternal object assigned to it. A tip on how to solve with fewer lines and well readable: Scroll through all the items in the list…
-
2
votes1
answer544
viewsA: How to configure Raspberry Pi to run only one Python application?
How can I set up Raspberry Pi for this purpose? An easy way to do this setup is to put a command to run your file .py in /etc/network/if-up.d/upstart. You need to open the file: sudo nano…
-
3
votes1
answer73
viewsA: scrape news portal comments
With this code you could not capture any comment because the comments are in a tag <p class="comment-text ng-binding ng-scope" [...]>. Soon, you beautiful girl from soup.find should be: v =…
pythonanswered Rafael Barros 840 -
2
votes2
answers91
viewsA: When changing the value of a variable, all objects in the same class are changing
Their variables image and rect are being defined as class variables. This means that every object created based on that class will have the same value as image and rect. To solve this using OOP, you…
-
1
votes1
answer21
viewsA: Command init and after_theme_support Wordpress
I believe you meant add_theme_support or after_setup_theme instead of after_theme_support. Well, there it goes: The add_theme_support is a function called usually in the functions.php to add theme…
wordpressanswered Rafael Barros 840 -
7
votes2
answers2073
viewsA: Find the largest and smallest element of a matrix
Your mistake is in saving type inputs str in the matrix and want to compare them as if they were the type int after. The value of '13', for example, it is not greater than '8', although 13 is…
-
3
votes1
answer3453
viewsA: Valueerror error: I/O Operation on closed file. when generating csv with python
This mistake happens because at the end of with: open(...) as csvfile: the open file is closed. Then soon after you enter a for who tries to write to this file that has already been closed. Put this…
pythonanswered Rafael Barros 840 -
3
votes3
answers243
viewsA: Use of functions in Python
The use of the functions is not only for repeated code. They can be used to encapsulate snippets of code and improve reading. Imagine a code that is dealing with the solution of a problem and in the…
-
1
votes1
answer1491
viewsA: Browse and count records from a JSON
Your iteration is not suitable for your output. When you count the output to put in d, will only have the result of the last iterated contract. Then we will make some modifications: output = [] for…
-
2
votes2
answers1609
viewsA: Python Mysql database connection
To begin with, you added the library pymysql, but is willing to use the pymysql.cursor. Do the right import: import pymysql.cursor Before calling cursor.execute() you have to set that will work with…
-
4
votes1
answer74
viewsA: Doubt in the book Python on a Crash Course
On the fifth and sixth line they declare self.question and self.responses. However, when referencing them later, on lines 10 and 19, they use question and responses. Just exchange them for…
-
1
votes1
answer1875
viewsA: Web scraping on page with login and password
First, you inserted a space after pre: [...].find("pre ", {"id": "code"}). text Correcting the code and removing this space, as below the error should be remedied: def getCode(self, id): return…
-
0
votes2
answers214
viewsA: syntax error in python
The error is not in the first line, but in the second. Its variable total_segs is misspelled in the second line. Is tota_segs. This error will be evidenced from the third line of code, when you make…
-
1
votes1
answer90
viewsA: How to read the contents of a "Generator Object" from the load_all method for yaml file?
Let’s focus on this part of the code, which is where the problem you’re facing is generated: with open('davros.yaml', 'r') as stream: yaml_config= yaml.load_all(stream) return yaml_config When you…
-
0
votes1
answer123
viewsA: Text.strip() Python
This is your td[1], where you apply the td[1].find('a').text.strip() to get the code and generate the index for the dictionary problems: <td> </td> That is, it has nothing. It is empty…
-
1
votes2
answers616
viewsA: Problem showing image in imshow
Your image img is the type uint8. The error that is happening is because your image gaussian is not of the same type as her. To solve this, instead of creating the gaussian of the kind int_, you…
-
1
votes1
answer1022
viewsA: How to calculate the similarity between two texts using word embedding in Python?
This similarity formula you are using is not suitable for the distance calculation that the library polyglot gives you. There is another formula of angle between vectors that is easier to apply and…
pythonanswered Rafael Barros 840 -
1
votes1
answer192
viewsA: Problem with C code
The complete, revised and tested solution: int main(void) { float dinheiro; scanf("%f",&dinheiro); // input do usuário dinheiro = dinheiro * 100; // multiplico por 100 para não trabalhar com…
-
0
votes2
answers2009
viewsA: PYTHON - FOR inside FOR
To get this result, write the iteration like this: for row in myresult: for fild in row: print (fild) Why? Your code gets every row contained in myresult and then in each row he catches a fild at a…
-
1
votes1
answer232
viewsA: Extracting information with Python
You can use the library platform to get this information from the system. >>> import platform >>> platform.machine() 'x86' >>> platform.version() '5.1.2600' >>>…
-
0
votes1
answer178
viewsQ: Create an empty set() object
I want to create an object of the type set empty. For this I am using the following expression: objeto = {} It turns out that when I do this, an object like dict. What I have to do to create an…
pythonasked Rafael Barros 840 -
0
votes1
answer529
viewsA: How to add a new dictionary inside another dictionary?
I believe you want to have it: {'MAIN': {'Nome': 'Jaque'}, 'NOVO_DICT': {}} #vígula antes de 'NOVO_DICT' If I’m right, so just add a new value to the entry NOVO_DICT of the variable ini. Thus:…
-
0
votes1
answer80
viewsA: Doubt Python Code and Opencv2
I want this code to send a text message, for example "Detected Person" every time it detects a face. You’re doing it right. By doing the check if len(facesDetectadas)>=1, you are checking if…
-
3
votes1
answer202
viewsA: Implement a blink counter in the face detection
One way you can solve your problem is by looking for a facial landmarks. You need to keep track of eye markings and calculate eye closure based on distance of markings. Below is a 2D representation…
-
1
votes2
answers82
viewsA: Returning Added Data in a Dictionary
You need to go through each of the positions of lista to then access the k and v of each of them. In practice, his last for end would look like this: for aluno in lista: for k,v in aluno.items():…
-
1
votes2
answers82
viewsA: Dictionary error
In fact, what you intend to create is a list of students within a dictionary. There was a small error in your code. You have the dictionary Dados with the item Alunos that keeps a list of students…
-
2
votes4
answers5739
viewsA: How to separate the letters of a string that are inserted into a list and place them in an array?
An easy way to separate letters in a string and allocate them in a list is by using the function list() python. Thus: palavras = ['teste','teste','teste','teste','teste'] matriz = [] for palavra in…