Posts by Woss • 73,416 points
1,476 posts
-
23
votes2
answers905
viewsQ: How does PHP foreach work?
To clarify, this question is not about when the foreach is used or differs from it to other loops of repetition, but about the functioning of foreach in itself. In the documentation, little is said…
-
9
votes4
answers2878
viewsA: Two "Return" in a function
Your example has no purpose, so there’s no way to give too many details. If you need to return more than one function value, you can return a sequence such as a list, tuple, set, etc. def função():…
-
10
votes1
answer729
viewsQ: When should an ordered list actually be an ordered list in HTML?
In HTML there are two basic elements to define a list: <ol>, representing an ordered list; <ul>, which represents a disorderly list; But when, in fact, it makes sense to represent an…
-
8
votes4
answers13602
viewsA: Check that the array() is empty with PHP
A lot of things don’t make sense in your code. At least considering only the part you posted in the question, it will be up to you to evaluate at the end since only you have access to the rest of…
-
1
votes1
answer269
viewsA: Convert jQuery to Typescript
addTourOverlay2() { // (1) if (document.querySelectorAll('#tour-overlay').length === 0) { let newDiv = document.createElement('div'); newDiv.id = 'tour-overlay'; let body =…
-
6
votes1
answer249
viewsA: How to inform parameters to the parent class initializer with Python?
One of the precepts of language is: Explicit is better than implicit. So don’t expect anything magical python. You have defined the method B.__init__ two-parameter, self and c, then when to…
-
3
votes1
answer141
viewsA: Why doesn’t this factor function work?
Returns nothing because you called the function main within itself; but as the function is never called from without, it will not be performed. Apparently it was an error in the indentation of the…
-
9
votes1
answer690
viewsA: What is the difference between classes initialized with (and without) __init___
They are not the same. In your example it was almost mere coincidence. Just do not instantiate the class c who will see what happens. This is because classes are only a scope limiter in Python. You…
-
5
votes3
answers412
viewsA: How to make a DIV with a crossed text. Type a text passing through a DIV
This form reproduces the Open English logo, but not exactly a text passing through the square, requiring changes¹ for this. One way that comes very close is to apply the style to the element :before…
-
9
votes1
answer66
viewsA: Why does (a < x < b) produce a result other than ((a < x) and (x < b))?
It turns out that SQL will run something different than you think with the syntax you used: WHERE a < x < b This expression could be written as (a < x) < b producing the same result, but…
-
15
votes2
answers2035
viewsA: What is the Python semicolon function?
In the example, for nothing. It can be used, obligatorily, to separate expressions in the same line and, optionally, at the end of it: a = 1; b = 2 print(a+b) # 3 See working on Repl.it But this…
-
3
votes1
answer839
viewsA: How can I improve my hangman game code?
Displaying the word on the screen First, let’s do the function that displays the word on the screen, along with the underscores in the letters that should not be displayed. For this, we can do: def…
-
10
votes2
answers680
viewsA: In HTML what is an Undetermined Checkbox and how to use this status along with CSS?
In fact, there is no property indeterminate that makes the checkbox enter the undetermined state, that because it’s not a state. The indeterminate is merely visual. The possible states of a checkbox…
-
3
votes2
answers57
viewsA: Convert string "11092018" to date format "11-09-2018"?
Using the function date_parse_from_format $data = date_parse_from_format('dmY', '11092018'); $data['month'] = str_pad($data['month'], 2, 0, STR_PAD_LEFT); $data['day'] = str_pad($data['day'], 2, 0,…
-
4
votes2
answers446
viewsA: How to take 2 PHP arrays and join in 1 string
You have: $arr = [ ['0', '1'], ['a', 'b'] ]; First, we need to associate the values of the first array with the values of the second. You can do this with the function array_map: $pares =…
-
2
votes2
answers295
viewsA: What’s the difference between using Return and print in this recursive function that calculates the sum of numbers?
If the function should return the sum of a set of integers, we can mathematically define the problem. Let us consider that the interval is defined by a and b: [a, b], being b greater than or equal…
-
2
votes1
answer136
viewsA: error in the path to bank connection
The path seems to be correct, but it is not. The backslash is the escape sequence within a string, then \U are not two characters, but only one. Or you escape the inverted bars path =…
-
1
votes1
answer36
viewsA: Header collapse with pure javascript
As documented in the MDN, the function window.scroll receives two parameters, x and y, not a function callback, as you did. I believe what you want to do is listen to the event of scroll and execute…
-
4
votes2
answers6030
viewsA: Compare dates in Python
Taking advantage of the logic demonstrated in response of the fernandosavio and integrating with the my other answer on how to list recent files from a directory, you can do something like: import…
-
6
votes2
answers679
viewsA: What determines a variable as a Python array?
In Python the type defines nothing. What you define is the object contract with the function you will perform. For example, when you do obj[x], regardless of what obj or x is, the Python interpreter…
-
3
votes2
answers396
viewsA: Convert date string to ISO 8601 format (with "T" and "Z")
Yeah, to define an object of the date type, there’s not much to do. Since your date is not in any ISO format, you need to set it manually, as you did. date = datetime.strptime('15/03/2018 13:00:40',…
-
1
votes5
answers11566
viewsA: How to find the type of a variable given by the user?
Another simple way is to use the ast.literal_eval. Eval vs Ast.literal_eval: what are the differences? Thus, you do not open security loopholes using the function eval, or need to predict all input…
-
5
votes1
answer174
viewsA: String search with character "|"
The problem is that the character | is reserved in regular expression. What is happening is that you are seeking the word "END" or the number "2" or empty. Empty will always be found. To solve the…
-
1
votes1
answer49
viewsA: Referenced method is not found in Subject class in PHPSTORM
You did: $conn = require 'connection.php'; But the file connection.php has no return, so its variable $conn will not be what you expect to be. Ideally, in my view, is you correctly set the return on…
-
2
votes1
answer262
viewsA: Constructor method in inheritance classes
You have a valuable problem on your hands. That question is what we call diamond problem and occurs in multiple inheritance when a class inherits from two classes that inherit from the same class.…
-
1
votes1
answer218
viewsA: Avoid Duplicity in PHP+Mysqli Registration
If you want a column to be unique, use the Unique constrain. Just that, just that. create table pessoas ( id int not null auto_increment, nome varchar(255), email varchar(255) unique ); In this…
-
8
votes2
answers523
viewsQ: Eval vs Ast.literal_eval: what are the differences?
In Python it is common to read that ast.literal_eval is an alternative to eval. Are the functions equivalent? Everything one does to another also does? In security matters, there is priority in…
-
4
votes4
answers232
viewsA: Transform a numeric string into a list of python numbers
You can work with JSON, since the values you have are sequences in JSON as well. >>> json.loads('[1, 2, 3]') # [1, 2, 3] And, to join the lists, you can use the function…
-
3
votes5
answers34006
viewsA: How to return the last record of an array with Javascript or jQuery?
If it is something recurring in the project, you can extend the Array by implementing a method for it: Array.prototype.get = function(index) { return this[index < 0 ? this.length + index :…
-
2
votes3
answers733
viewsA: Display only words that have an even number of vowels within a sentence
Your code is, by very little, almost working. The first problem, and the main one, is that you do not restart the vowel count with each word. As you did, the count will accumulate; so, instead of…
-
5
votes1
answer145
viewsA: Is <label> semantic or allowed to use which elements inside?
In accordance with W3C and WHATWG, the permitted content is any element characterized as phrasing content, which is the same as permitted for the element <p>. What are the allowed elements…
-
7
votes2
answers890
viewsA: Can I use header/footer tags inside the main/Section tag?
Yes, it is allowed. According to the W3C specification, both the element <section> as to the <main> allow as content the elements classified as flow content, which include the elements…
-
3
votes2
answers454
viewsA: How to clone a list with Python 3?
The main problem is that you have a list of mutable objects - in this case, a list of lists. So just making a shallow copy won’t be enough. To copy the mutable objects from your list, so they don’t…
-
9
votes2
answers138
viewsA: Is it necessary to use semicolons at the end of a "single expression" in PHP?
Documentation: Separation of instructions The closing tag of a block of PHP code automatically implies a semicolon; you don’t need to have a semicolon ending the last line of a PHP block. The block…
-
4
votes3
answers1422
viewsA: Convert string with HTML tags into an array
With the same idea presented by hkotsubo, you can insert the contents of your string in a virtual element and scroll through the child elements. If it is an instance of Text, effectuates the split,…
javascriptanswered Woss 73,416 -
0
votes2
answers621
viewsA: Removing unnecessary question mark from a String
To add also at the end of string which does not have the question mark, you can use the regular expression: (\?+|$) Which basically captures any sequence of one or more question marks or the end of…
-
1
votes2
answers2728
viewsA: How to separate only the first word of each string from a list?
To complement, by using the split to separate the strings in the blanks, it is not necessary to strip before when the separator is not defined as a parameter. See what the documentation says:…
-
3
votes2
answers169
viewsA: How do I delete empty lists from my list?
Bacco’s answer explains well what the problem was, but I would like to add some comments. The function readlines will read the entire contents of the file at once, placing each line of the file in a…
-
18
votes1
answer281
viewsQ: What is Python Assignment Expressions 3.8?
As assignment Expressions are defined in the PEP 572 which has been approved to be implemented in version 3.8 of Python. But what are the assignment Expressions and when they should be used? What…
-
1
votes1
answer295
viewsA: You can’t specify target table 'pessoa' for update in FROM clause
As described in the documentation of Mysql: You cannot delete from a table and select from the same table in a subquery. That is, you cannot delete records from the same table you used in a…
-
4
votes1
answer261
viewsA: Code sum error starting with 0; Problem inserting data into.txt file
The variable codigo will be global and is imported into the scope of the function as read-only. If you need to modify the value of it, you need to use the term global to import it as written as…
-
7
votes1
answer663
viewsA: What would be the best HTTP response to inform the client that it cannot delete a single record?
I understand two plausible answers: 200 or 409. Why? Today, the HTTP protocol provides for five response groups: Group 1xx: informative answers; Group 2xx: successful responses; Group 3xx: redirect…
-
2
votes1
answer45
viewsA: Am I required to call a Parameter if I determine it in a function?
You are not required to pass it, but the function needs to be handled in case the parameter is not set, otherwise it makes no sense to do so. For example, we assume a function that displays a…
javascriptanswered Woss 73,416 -
4
votes1
answer48
viewsA: "NOT IN" behavior affecting NULL column display
As discussed in Why NULL values are not selected?, NULL is not a value, so there is no way to compare it with other values - including itself. For example, even if you did select id, preco,…
-
2
votes2
answers63
viewsA: Not all arguments were converted during string formatting. What does that mean?
As Pedro said, its syntax has several errors. The error quoted is because you used the operator % in string, which is used for formatting, but its string does not have any template to be replaced.…
-
1
votes1
answer133
viewsA: How to pass variable to PHP file in Shell Script
There will be a variable $argv that will be a array with values passed via CLI, but not the way you did. Just pass the value as argument from script: $ php -f complete.php teste Thus, if you value…
-
0
votes1
answer242
viewsA: Write to csv file
In the question, you quote that the function returns you: ['x' - 'y', 'z', ['a', 'b', 'c', 'd', 'e', 'f']] But in the function you returned: csvLinha = linha[0] + " - " + proxima[0] + "," +…
-
6
votes1
answer280
viewsA: How do I intersect each position on my list?
The point is that your object A is a list of lists. It is only possible to generate the object set from types hashables, but since the list is a changeable type, it is not hashable, as the error…
-
1
votes1
answer39
viewsA: Nameerror when entering the value read by the input function
The problem is that you are using the function input in the Python 2.7 without knowing, apparently, how it works. In this version, the function input will evaluate the entry as a Python code. If you…
-
5
votes2
answers320
viewsA: Why can’t f-strings be used as docstring?
Because the f-string ceases to be literal and by definition ceases to be a candidate to be docstring. Also by the fact that the docstring is generated at compile time, when generated the byte-code…