Posts by Woss • 73,416 points
1,476 posts
-
0
votes2
answers295
viewsA: Nesting a flat PHP array to generate an HTML menu and submenus
Your structure is recursive, so why don’t you solve it using recursiveness? And you don’t need to restructure your array, just filter the items you want to display from the value of id_parent.…
-
8
votes1
answer73
viewsA: Limiting the number of regex Matches with Python
Whenever working with iterators, remember the package itertools. You can use the function itertools.islice to limit the iterator returned by re.finditer. For example: from itertools import islice #…
-
2
votes1
answer37
viewsA: Definitions and their use in classes
Depends. In Python you will notice that for instance methods (which are not static or class), the first parameter will always be called¹ self. This object is a reference to the very instance you are…
-
1
votes2
answers96
viewsA: What is the mistake in logic?
Three things: You overwrite the value of soma every iteration of the loop; You define soma as a whole; You must first multiply the fat, then add up; To correct (1), you will need to change soma =…
-
7
votes2
answers1563
viewsA: In HTML and CSS should I use Single Quotes or Double Quotes? Is there any recommendation?
No, no, yes, yes. There is no established good practice, use the one that suits you best. There is no difference for the browser since the way to use it does not break the HTML syntax and generate…
-
5
votes1
answer640
viewsA: How to remove the question mark "?" at the end of the URL of a request?
They commented, but no one answered. You are using a form to create navigation between pages. When you submit a GET form, you are expected to send parameters to generate a query that will define the…
-
4
votes2
answers179
viewsA: Why should we import Messagebox explicitly into Tkinter even if it matters with the asterisk?
That’s because unlike what some think the asterisk doesn’t matter all necessarily. When you do: from X import * If X for a module, the interpreter will search for X.__all__, if X is a package, will…
-
2
votes1
answer513
viewsA: Object counter by an infrared sensor on Raspberry with Python
whereas sensor turn to 1 when there is no object in front of the sensor, you can make a loop that waits for the object to pass; something like: from functools import partial sensor_ir =…
-
7
votes2
answers144
viewsA: When using method in a string, it is not including parentheses "()"
That’s what we call interpolation of strings and only works in PHP if used double quotes or heredoc. The PHP interpreter, when it finds a string double quotation marks or heredoc, will try to…
-
0
votes2
answers54
viewsA: Because you may be causing error when comparing two dates in php
You do not need to do all this that was presented in the other reply. If it were to compare the timestamps just wouldn’t need to use the class DateTime. $expira = strtotime("2019-02-16 18:18:48");…
-
2
votes1
answer76
viewsA: How to check more than one level of an object without the code being visually ugly?
You can create a function for this: function get(obj, path) { const attributes = path.split('.'); for (let attribute of attributes) { if (!obj.hasOwnProperty(attribute)) { return null; } obj =…
-
4
votes1
answer237
viewsA: Subtract php hours
Don’t confuse timetable with amount of hours. What you have are amounts of hours and minutes, separated by two points, which will induce you to think it’s a time. And to subtract quantities, you…
-
1
votes1
answer103
viewsA: Why does $fat start with 1 in factor calculation?
It is what we call the neutral element of the operation. That value, $fat = 1, will always be there regardless of what the input value is, that is, whether we are calculating the factorial of 5 or…
-
1
votes1
answer53
viewsA: Doubt attribute declaration in PHP 7
First, do: spl_autoload_register($nomeDaClasse) { ... } It’s wrong and it doesn’t make any sense. The function spl_autoload_register is native to PHP and aims to record functions for the autoload.…
-
4
votes1
answer235
viewsA: Word repetition
An object of the type string, in Python, allows it to be multiplied by an integer generating a new string being the first repeated several times. See: >>> 'incomodam ' * 3 incomodam…
-
2
votes2
answers136
viewsA: How to group array that has the same value
Just you set a array that will group the values, using the matter as key array, storing the values in the keys according to the subject of each item. $gabarito =…
-
6
votes3
answers2192
views -
1
votes1
answer912
viewsA: Formatting a python stored text
Just add the line break when writing to the file: arquivo.write(str(lista1) + '\n') Incidentally, lista1 is already a string, then call str is unnecessary. arquivo.write(lista1 + '\n') You also put…
-
8
votes1
answer482
viewsA: Algorithm for Helicopter Escape Solution
Just analyze mathematically (equate) and see which one is nearest. Let’s say the fugitive has to walk p positions to reach the police and h positions to reach the helicopter. So: P = F + D*p H = F +…
-
3
votes1
answer66
viewsA: Mysql query returning empty
I recommend that you at all times read the documentation of the functions before using them. Otherwise you will program on trial and error basis, getting frustrated and wasting time.…
-
3
votes1
answer397
viewsA: Size of tuple lists in a df
As discussed in: Check that all items in a string are different? Removing duplicate elements in a python list How not to repeat values in a Python list? You can use the type set Python which, by…
-
7
votes2
answers13516
viewsA: Could not convert string to float. Why?
This exception is made when the string that you are trying to convert is not in a valid format. This happens when you use the comma as decimal separator, when the string is empty or has non-numeric…
-
2
votes1
answer5197
viewsA: Request Python form/data
You are setting the header Content-Type as multipart/form-data, but you do not send the data in this way. Do not complicate what is simple. Just inform the data via data, headroom: face_response =…
-
2
votes1
answer149
viewsA: Pycharm complaining about the local variable
Just you position the mouse about the notification that the message will appear that the IDE has missed: In free translation, the name cor may not be defined. This is a warning, not a error. The…
-
3
votes1
answer4917
viewsA: <? php echo $_SERVER["PHP_SELF"];? > what is the function?
Yes, $_SERVER["PHP_SELF"] is the path to the file itself in question. This way, when submitting the form, the POST request will be sent to itself. However, it is not recommended that you do this. If…
-
4
votes1
answer1116
viewsA: Working with time in pandas and python
There is no difference between times. It makes no sense. If I ask you what the difference is between 11:00:00 and 10:00:00 you may even get attack to reply that it is 1 hour, but it is wrong,…
-
2
votes1
answer50
viewsA: sort list of dictionaries by key that contains None key
The idea is to always compare data of the same type. The easiest (and clearest) way is to map the values you have to integer values and sort the list according to these numbers. PRIORIDADE = {…
-
1
votes1
answer185
viewsA: PHP 7 typed and difference between argument numbers and parameters
What you need is not Operator spread, the ..., then there is no way to use it to do what you wish. The Operator spread groups all parameters passed to function within one array. If you use it in the…
-
3
votes1
answer297
viewsA: Tkinter library not recognized by Pycharm
Your flame file tkinter.py. When you do from tkinter import *, you will import all objects from your own archive. In order of priority, the interpreter will search for the module first in the…
-
3
votes3
answers387
viewsA: I created a Python function, but it is not executed
The error that causes your code to not run is that you have never called the function you declared. Add to end of file to resolve: if __name__ == "__main__": jokenpo() See more about function…
-
2
votes1
answer30
views -
6
votes2
answers2479
viewsA: How to quote a javascript string
The easiest is for you to use strings template: xmlRowString += `<imagem class="${r}"></imagem>`; Template String in Javascript Template strings on MDN The fact of using the grave accent…
javascriptanswered Woss 73,416 -
8
votes1
answer295
viewsA: Why does Fractions.Fraction(1/3) not return "1/3"?
1/3 is a periodic tithe; that is, the amount of 3 after the comma is infinite, which makes it impossible to represent it computationally. When you store the value in memory, the value will be…
-
12
votes1
answer161
viewsQ: Why does 2*i*i tend to be faster than 2*(i*i) when i is integer?
The two multiplications, 2*i*i and 2*(i*i), are equal and must generate the same result, what changes is only the order that the multiplications are made, but apparently are treated differently by…
-
2
votes1
answer26
viewsA: Automatically add as typed
The problem is that as long as the field has no value, the attribute value will be undefined. If you try to add any value with undefined the result will be NaN. The solution is for you to consider…
javascriptanswered Woss 73,416 -
4
votes1
answer2628
viewsA: How to generate random numbers but with some restrictions in python?
As of version 3.6, the package random has the function choices that allows you to define the weights of each value within a population. from random import choices population = [1, 7, 15] weights =…
-
8
votes1
answer173
viewsA: Difficulties with using IF
The construction of your condition is wrong: if sit[i] == "aprovado\n" or "aprovado": ... But before we begin, we need to know that a string not empty is considered as a true value in Python (Truthy…
-
3
votes1
answer189
viewsA: Why Button inside Label does not work. Button does not work as expected not to activate Checkbox
The problem is that the <label> has only one interactive child and, by default, the interaction with these elements should not activate the <label>. See the excerpt from HTML Standard:…
-
23
votes2
answers293
viewsQ: Should different states of an HTML element be represented in different properties?
Let’s start with a problem-example: visually replace the element <input type="checkbox"> by images. In this case, three states have been defined for the element: Natural, getting the gray…
-
2
votes4
answers197
viewsA: Remove comment tag and your content in Beautifulsoup 4
Based on the answers to the question Beautifulsoup 4: Remove comment tag and its content, you can use the method extract to remove an item from the tree. To know if the item is a comment, simply…
-
6
votes2
answers379
viewsA: Recover List Written in Python File
As commented, the way you used to write to the file is not the ideal one to recover the data later. You just converted the list into a string before writing to the file, but this process is not…
-
7
votes1
answer98
viewsA: input:checked does not change border as prompted in css
You are improperly using CSS selectors according to your HTML structure. input:checked + li { border: solid rgba(37,205,61,1.00); } This will select the element <li> which is adjacent to the…
-
1
votes1
answer33
viewsA: Check and list files from a PHP directory
You can use the function glob to list files from a regular expression: $id = 11; $imagens = glob("imagens\/noticias\/noticia_{$id}(_\d+)?\.jpg"); foreach ($imagens as $imagem) { // ... }…
-
4
votes2
answers344
viewsA: How to make a text generator according to the possibilities I put in it
Python has a native function for this: random.choice. from random import choice saudacoes = ('Olá', 'Oi', 'Boa tarde') saudacao = choice(saudacoes) print(f'{saudacao}, como vai você?') This way,…
-
5
votes2
answers2798
viewsA: Validation of CEP Javascript
First, the function definition is wrong. In Javascript we do not declare the function return type, we always use function whether there will be a return or not. Second, its object cep will be the…
-
4
votes2
answers240
viewsA: col-Md-6 occupying all space
Instead of placing the two columns col-md-6 within a column col-md-12, why not put inside a row? The row occupies the 12 columns and does not have the spacings that a column has, which breaks its…
-
1
votes1
answer603
viewsA: check whether a string exists in an array that is inside another array
Just you go through your array and call the function in_array for each value: function has_value($neddle, $arr) { foreach ($arr as $value) { if (in_array($neddle, $value) { return true; } } return…
-
1
votes2
answers65
viewsA: Insert in Postgres with Python is not working
Missed you calling conn.commit(). By default, the library psycopg2 will start a transaction before executing the first SQL. If the function commitis not called, the transaction will be ignored and…
-
1
votes3
answers96
viewsA: Show the user his test position
An alternative is to create a dynamic column with the position of each student within the ordering and then select it. Considering a simplified table: create table notas( id int not null…
-
8
votes3
answers194
viewsA: "break" does not finish execution as it should
No, it’s not a bug in Pycharm, much less it works on your colleague’s computer. It doesn’t work because the code is wrong. First, indentation. Indentation defines the code blocks in Python and is…