Posts by Woss • 73,416 points
1,476 posts
-
4
votes1
answer108
viewsA: Magical python methods in javascript
The closest you get to what you want is the method toString: class Vector { constructor(x, y) { this.x = x; this.y = y; } toString() { return `Vector(${this.x}, ${this.y})`; } } const v = new…
-
15
votes2
answers1147
viewsQ: What is Stencil JS?
Nowadays, much is said about the web Components and custom Elements, and along with big names like Angular, React, Vue and Polymer, the name has recently begun to appear Stencil JS. What is Stencil…
-
19
votes4
answers7124
viewsA: Accept only numerics in input
Just you treat the exception that is fired by int when the conversion fails: while True: try: nota = int(input("Informe a nota entre 0 e 10: ")) if not 0 <= nota <= 10: raise ValueError("Nota…
-
11
votes3
answers719
viewsA: Why static methods can be called through the "instance" of the Python 3 class?
This has, in a way, a relationship with the attributes of instance and class, along with the construction of the Python language, more precisely the decorators. Unlike other languages, the…
-
8
votes3
answers752
viewsA: String with JS Function Name
Function reference is available in the object window through the key equal to the function name. That is, to call the function, just do: const f = window[func]; f("parametro"); Take an example:…
javascriptanswered Woss 73,416 -
4
votes3
answers8207
viewsA: Separate each phrase word in an index from the python list
You have a list of lists with only one string. Semantically, this makes very little, if anything, sense, so maybe the way you’re creating these lists isn’t the best way. But if the intention is to…
-
6
votes2
answers654
viewsA: Syntax error in if Else
The indentation of else is wrong. It should be on the same level as the if: frase1 = str(input("Digite uma frase: ").strip()) frase2 = str(input("Digite uma frase: ").strip()) print("O tamanho da…
-
7
votes5
answers4681
viewsA: How to make a Rigger for a SEM jQuery event?
Natively this should be done through the method dispatchEvent of an object EventTarget. The parameter indicated in this method should be an object of the type Event. That is, first we need to create…
-
1
votes2
answers1134
viewsA: Browse HTML content and remove parts of HTML using PHP
As I said, the best way to manipulate HTML with PHP is by using the native classes of GIFT. In this case, I directly used the classes DOMDocument and DOMXPath. The code is commented when the steps…
-
3
votes1
answer1886
viewsA: Remove whitespace from the Python list
Just check when you generate the word list: lista_stopwords = [line.strip() for line in file_stopwords if line.strip() != ""] Notice the addition of the condition if line.strip() != "" at the end of…
-
0
votes4
answers5632
viewsA: Is there any way to use :Focus in div?
If the idea is to apply some style in div when one of the fields gets the focus, I would indicate using the event itself focus of input and access to div through the attribute parentElement. See…
-
1
votes1
answer574
viewsA: How to access objects of a class within an anonymous method?
If the anonymous function only has access to public elements, whether attributes or class methods, the code is basically what Guilherme described in the comments: a static method that creates a new…
-
9
votes3
answers353
viewsA: Is it possible to prevent one of the attributes of an object from being serialized in Javascript?
To simplify understanding, I will create an example closer to reality: const obj = { "name": "John Doe", "age": 34, "parents": [ { "name": "Derp", "age": 63, "gender": "male" }, { "name": "Derpina",…
-
10
votes2
answers262
viewsA: Check "in" return change the Python result
Yes, this behavior is what Python expected precisely by the way he will analyze the expression, but such behaviour has nothing to do with the order of precedence of the operators. What happens is…
-
1
votes3
answers12022
viewsA: Read 10 whole numbers and get the biggest one among them
Another way would be: # Define a função: def exercicio(): # Lista com os números lidos: numeros = [] # Lê o primeiro número, garantindo que não seja zero: numero = 0 while numero == 0: numero =…
-
13
votes2
answers262
viewsQ: Check "in" return change the Python result
It is known that to check whether a particular item does not belong to a list it is sufficient to use the operator in: values = [1, 2, 3, 4, 5] if 9 not in values: print("9 não pertence à lista.")…
-
2
votes2
answers6501
viewsA: Fatal error: Function name must be a string
The error itself occurs on the line: $nome = $_POST('$nome'); When using parentheses, PHP will parse $_POST as a function and try to execute its call by passing a parameter of type string; however,…
-
9
votes3
answers26954
viewsA: Python maximum and minimum
To title of curiosity, you can implement the function in a mathematical way. It is possible to demonstrate that: max{a, b} = 0.5 (a + b + |a - b|) and min{a, b} = 0.5 (a + b - |a - b|) So in Python,…
-
0
votes1
answer73
viewsA: Get the position of an Associative Array within another Array
The simplest way to solve the problem is to walk the array checking the name of each position and, when finding the desired name, return it. function getKeyFromName($array, $name) { foreach($array…
-
6
votes3
answers643
viewsA: How do I remove a "listener" that I added via addeventlistener?
A not very trivial way to perform the task is intercept function call addEventListener and keep the reference to the function in some way, because, as stated in the other responses, it would not be…
javascriptanswered Woss 73,416 -
2
votes1
answer1033
viewsA: What is and how to use array_walk?
The function array_walk is used to apply a certain function to all values of a array. It is easier to understand if, initially, we do not consider an anonymous function. So let’s consider a function…
-
2
votes1
answer449
viewsA: Send modal form over a normal form
The problem is that you are entering a form within another form and this is not allowed. I have already commented on this here: I have one form inside the other and I can’t get the most internal…
-
1
votes2
answers3488
viewsA: How to change the href of a link dynamically?
Some information is trivial to understand the problem and has been passed in the comments of the question: The page will be served by a C code embedded in some electronic device. This implies that…
-
3
votes1
answer138
viewsA: Always get the second read
Just apply the style using the selector nth-child(even) to select all even index elements (or odd for the odd). Take an example: ul { list-style: none; padding: 0; margin: 0; } li { float: left;…
-
8
votes1
answer254
viewsA: What is the real use of the pass in this case?
There is no use for this case. The only function of pass is to function as a placeholder in structures that require an expression, but that no logic should be executed. When a pass is executed,…
-
3
votes2
answers134
viewsA: How to merge several variables into one php and pass to Jquery in a link
Based on the question data, the result of your SQL query is as follows: $ResultadoLinkATV = [ (object) ["idVisita" => 33], (object) ["idVisita" => 34], (object) ["idVisita" => 37] ]; You…
-
1
votes1
answer461
viewsA: Store binary variable in list mode
It is not very clear whether you just want to display everything on the same line or store, in fact, in the same list, since you are overwriting the value of binario at each iteration. As, in my…
-
18
votes2
answers3744
viewsA: How does the "for" inline command work?
This form is called list comprehension, or in English list comprehensions. It is nothing more than a simplified way of writing a loop for. In this case I even used it inappropriately, because the…
-
3
votes2
answers265
viewsA: When is a default argument evaluated in Python?
Complementing the william’s response, in fact, what occurs is the evaluation of the arguments in time of method definition and how the objects in Python are treated as reference, in the method…
-
0
votes1
answer30
viewsA: Php does not want to write registration data to the database
There are at least two errors in your PHP code: Recover values in the superglobal $_POST without checking whether the request handled by the server is a POST. That is, when you access the page via…
-
1
votes1
answer479
viewsA: Send JS form to a PHP
It is. Through the attribute action of a form you define what will be the URL to which the form data will be sent. That is, when the form is submitted, the browser takes care of generating another…
-
10
votes2
answers11713
viewsA: How do I make python read line by line?
The most pythonic to accomplish this task is through a context manager with the with. with open("arquivo.txt") as file: for line in file: print line With the context manager, you don’t have to worry…
-
13
votes2
answers265
viewsQ: When is a default argument evaluated in Python?
Let us consider the following class: class Foo: def __init__(self, values = []): self.values = values Note that we are using an instance attribute and not a class attribute, but see the following…
-
3
votes2
answers787
viewsA: Syntax error problem in Else python
Syntax errors just read the message that will know what is wrong: the error points to line 41 and if there is something wrong with that line, see the line above. In this case, one of the parentheses…
python-2.7answered Woss 73,416 -
1
votes2
answers792
viewsA: login with Cpf or email in php
With regular expression, you can do something like: if (preg_match("/^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/", $valor)) { // É CPF } else { // É e-mail } Thus, the separator characters will be optional,…
-
8
votes2
answers1623
viewsA: Checking whether a string is empty in Javascript. Idiomatic or readable?
If the intention is really check whether the string is empty, then, yes, impairs the reading of the code and possibly the execution of it. The reason is that the comparison made in: if (!value) {…
-
4
votes4
answers846
viewsA: How to find numbers larger than X in a list
The logic is exactly the same to filter elements from a list: Filter elements from a Python list The simplest and most direct is to use list comprehension: B = len([i for i in N if i > 2]) In…
-
1
votes2
answers2057
viewsA: python vector input
Okay, I think I understand what you need, so I’m going to really focus on the problem: a loop of repetition that reads m lines in the format a b c d ..., Separate this line into values and convert…
-
30
votes8
answers4394
viewsA: How to identify "Capicua" numbers that have 5 digits?
Let us initially consider a positive 5-digit integer value that can be written as abcde. From the definition, we have that this value will be considered a Capicua if, and only if, abcde is equal to…
-
3
votes1
answer1243
viewsA: How to capture (GET) multiple values sent in the same variable (PHP)?
The official structure of the URL is defined by RFC 2986, Session 3.4 addressing the definition of query and even in it there is no "official" way to pass multiple values to the same parameter.…
-
3
votes1
answer297
viewsA: Concepts for the adoption of object orientation
In my view, the key words here are necessarily entail. Although simplicity is usually present in philosophy for the implementation of object orientation concepts, it is not a necessary requirement…
-
1
votes2
answers5665
viewsA: Doubt in While with two conditions
Taking advantage of all the commitment that Jefferson had to his reply, I propose a more mathematical analysis of the problem. As he commented, the statement itself in the problem does not…
-
2
votes1
answer1149
viewsA: Browse Python dictionary from the end
There is a way, but it is necessary to understand that it is not possible to order a dictionary. How to order a dictionary with a key Sort dictionary by Python value Sort dictionary by value and use…
-
1
votes5
answers1319
viewsA: Insert "X" value after some characters
Making a compilation of all the information I presented: The first, about using the jQuery library for such a trivial task. Is to significantly increase the payload application unnecessarily,…
-
1
votes1
answer948
viewsA: How to add up the values of an index?
The simplest way to do it is very similar to what you have now: lista = ['22659', '387685', '89546'] resultado = [] for sequencia in lista: soma = 0 for valor in sequencia: soma = soma + int(valor)…
-
1
votes2
answers71
views -
0
votes1
answer37
viewsA: Avoid Favicon Get in Flask
By my tests here, apparently if you set an image fake for favicon you will prevent the browser from making the default request. To do this, it would be something like: <link…
-
2
votes2
answers220
viewsA: How to send form but remove null fields
Just like the Caique commented, you can, with Javascript, add the property disabled at the time the form is submitted, so the browser will not include the blank fields: const form =…
-
1
votes1
answer1748
viewsA: How to implement a Python permutation algorithm?
The separation of text into groups can be done through a list understanding by accessing the positions i:i+key of the text, where i varies from 0 to the length of the text, with step equal to key.…
-
2
votes2
answers1613
views