Posts by Woss • 73,416 points
1,476 posts
-
6
votes2
answers107
viewsA: Random within a Random
What you want is to draw an element from the list with different weights. There is an explanation for this in the question below and it is not worth replicating here: Random draw, but with different…
-
3
votes2
answers959
viewsA: Searching word within text of PHP Array
First tip is to avoid the use of the unset unless necessary, as you lose the original value of your variable and this can complicate the debugging process during maintenance - you cannot compare…
-
2
votes1
answer71
viewsA: Multidimensional php array error
The difference between array_diff and array_diff_assoc is that the second compares the index as well. In your case, how are two arrays numerical index (sometimes called sequential) where apparently…
-
1
votes2
answers87
viewsA: Hosting and favicon error 404
This is a particularity of the hosting you are using. Every time someone makes a request on this server the existence of the cookie is checked __test - and possibly validated the value of it (we…
-
1
votes3
answers463
viewsA: How to list files in a folder with size
As of Python version 3.4, you have no reason to use the package os. A new package has been added, pathlib, to deal with directories and files that abstract much in a more organized way the functions…
-
4
votes1
answer133
viewsA: Python - Brute Force - Memory Error
You can get the lowercase letters of the alphabet with: from string import ascii_lowercase If you want all letters, including uppercase, string.ascii_letters, or only capital letters,…
-
1
votes1
answer131
viewsA: How to convert a jQuery object to html?
You really don’t need to do this, let alone use the document.write; just use the function append jQuery: function criarBotaoDownload(){ var botao = $("<a>"); botao.attr("download",…
-
2
votes2
answers230
viewsA: What is the best tool to perform a Javascript integration with Mysql?
First some concepts need to be consolidated. What you do in the frontend does not influence what you do in the backend and vice versa. Both parties communicate through a protocol that they both…
-
2
votes2
answers132
viewsA: What is the correct linear-gradient (CSS) syntax in Javascript?
The syntax is exactly the same as the one you used in CSS, because the HTMLElement.style work with the same syntax used by the styles inline element. The detail is that you should not pass the…
javascriptanswered Woss 73,416 -
4
votes1
answer2507
viewsA: Too Many values to unpack (expected 2) no Django
You used the method dict.keys, that returns an eternal object with only dictionary keys and error occurs by deconstructing tuple of a value into two variables. for key, value in defaults.keys():…
-
4
votes2
answers51
viewsA: Why doesn’t Event exist inside the lower block?
These are different events. The first is the click event, the second is the timeout; the second does not possess a target, only the first. What you’re doing is what we call closure, where a function…
-
7
votes2
answers194
viewsA: Raising fraction to power
You can use fractions to deal with fractions: from fractions import Fraction base = Fraction(1, 2) exponent = 3 result = base**exponent print(result) # 1/8 If the idea is to accept as user input…
-
6
votes2
answers283
viewsA: Use of empty "print()" in place of " n" before conditions
In fact there is no problem. Another alternative would be you just set the value of a variable with its conditions and call the function print just once. That would be another application of what…
-
4
votes2
answers343
viewsA: select Count within select
You don’t need to make multiple selections for this, just make the selection of all the data, group by instance and add the records by month: SELECT instancia, SUM(CASE WHEN MONTH(ura_data) = 1 THEN…
-
4
votes4
answers1262
viewsA: Take array value
As I have shown in Mount two-dimensional PHP array, the function array_map already makes this association for you: $dados= [ ['Teste 8', 'Teste B'], ['avaria_20190614005447368417.jpg',…
-
2
votes1
answer24
viewsA: How to obtain the name of the protected properties of an object without the asterisks?
Since the idea is to inspect an object, do it correctly with the classes of Reflection: $reflect = new ReflectionObject($person); $protected =…
-
3
votes2
answers35
viewsA: How to not show junk value when pulling a data from a null PHP database
Checking whether the value of $row['DT_FATURAMENTO'] is empty before passing it to the function strtotime. You tried to do this: strtotime($row['DT_FATURAMENTO'] ?? '') But: Used the null…
-
4
votes1
answer73
viewsA: Input does not take the file type
In accordance with the W3C, the attribute is expected to type is empty when the browser is unable to determine the MIME of the file in question. That is, being empty is not a problem and should be…
-
3
votes1
answer183
viewsQ: Is it possible to define async as the initializer method of a Python class?
Let’s say I have a class where I need to initialize a field with the return of a corotina: import asyncio class Server: def __init__(self): self.connection = await self.connect() async def…
-
5
votes3
answers141
viewsA: Amounts of games in a betting code and their random numbers in ascending order in Python
A practical alternative to this is to use functions that the library random already offers you: from random import sample def loteria() -> list: return sorted(sample(range(1, 61), 6))…
-
2
votes2
answers716
viewsA: Attributeerror: str Object has no attribute 'Confidence'
The problem is that you store a Python object in the form of string in the file, later read it also as string and use it as if it were the same initial object. At the moment you save the object as…
-
1
votes1
answer219
viewsA: How to escape the "{" character in a formatted string?
You need to duplicate the keys. Instead of just {, utilize {{: interface = "alguma" s = "{INTERFACE} {{".format(INTERFACE=interface) print(s) # alguma { If you are using version 3.6 or higher of…
-
1
votes1
answer491
viewsA: Assign Linux environment variable in python
The module os has a dictionary with environment variables that can be accessed by os.environ. If your environment has the variable PATH and you want to access it via Python just do: import os PATH =…
-
0
votes1
answer51
viewsA: Creating several Snippets
As specified in documentation, just you set the source only once: ################################################ # JS ################################################ '.source.js': 'Console log':…
-
0
votes1
answer116
viewsA: Access out-of-loop variable for
Your code: cookies = [] for i in get_cookies(url): cookies = '='.join(i) + '; ' print(cookies) You defined cookies as a list, but wants the result to be a string; within the repeat loop you are…
-
18
votes1
answer155
viewsQ: What justified adding the syntax for positional-only parameters to Python version 3.8?
As stated in What’s New In Python 3.8 to PEP 570, that defines the syntax for only positional parameters, has been implemented. According to PEP 570 it will be possible to use the bar in defining…
-
2
votes1
answer28
viewsA: How I remove the typeahead autocomplete and leave only the suggestions below
Just a matter of consulting the official documentation: Options hint – If false, the typeahead will not show a hint. Defaults to true. I mean, just do: $('.typeahead_oque').typeahead( { minLength:…
-
3
votes3
answers233
viewsA: Error using append after merging two lists into one
There are many things that should be considered in your code. In short: The indentation is wrong, which would result in syntax error in this case; Uses unnecessary repeat loops; Makes wrong…
-
0
votes1
answer45
viewsA: Error trying to set the value of a class property
You are defining infinite recursion in the two methods of your property. def get_name(self): if self._name != "": return self.name else: print("The name is not registred") You did return self.name,…
-
0
votes1
answer100
viewsA: POO in PHP classes ( reuse methods and attributes from other inherited classes)
One way would be to implement the method in a generic way trait: trait FindAll { public function findAllWhere($where) { try { $data = $this->repository->findWhere($where)->all(); return […
-
2
votes1
answer543
viewsA: Configure HTML table using python’s Django for structure
As already mentioned, the easiest method is to use get_html_string of PrettyTable, because it already returns, as string, all the HTML code of your table. However, by default, Django escapes the…
-
8
votes4
answers1053
viewsA: Python Queue Code - How to check if there is an element with a specific name in the queue and its index position?
Given the implementation, I would say that a list would already solve your problem well enough, not needing to implement a chained list for it, but considering that the chained list is part of the…
-
3
votes1
answer971
viewsA: Error "Indexerror: list assignment index out of range" when setting "l[0] ="
You’re doing an assignment in a position that doesn’t exist on the list. As you started the list as empty, there will be no position 0 and therefore you will not be able to do the assignment. If the…
-
7
votes1
answer611
viewsA: Read large (80gb) php file
Of course I do. You don’t need to store all the file contents in memory if you can process each line separately, just have in memory only one line at a time. $handle = fopen('arquivo.txt', 'r') if…
-
4
votes1
answer1062
viewsA: How to convert a string to Date with the month name in English
There is an error and a potential problem in its application. The error is that the formatting set by %B awaits the full name of the month, while in the value to be treated you have only the reduced…
-
5
votes1
answer2163
viewsA: How to compare elements of the same index in a list
You don’t need to convert the strings for lists. In Python, the strings are also eternal. The simplest way for you to make this comparison is to create a zip between the two strings and compare…
-
24
votes1
answer228
viewsA: When and why to use range 1xx status?
Status 1xx are obsolete? Not, there is a translation error in the excerpt you quoted from Wikipedia. The original passage is: Since HTTP/1.0 Did not define any 1xx status codes, Servers MUST NOT…
-
2
votes1
answer121
viewsA: tuple Parameter unpacking is not supported in python 3
You have a list of tuples, then in your lambda expression, which you defined in the parameter key, you will also receive a tuple as parameter. IE, is passed to the lambda a tuple with 2 positions…
-
1
votes2
answers1152
viewsA: How to pass data from an HTML form to a php object
First, the problem in the constructor method of its class: public function __construct() { $this->nome = $nome; $this->idade = $idade; $this->sexo = $sexo; $this->qualidade = $qualidade;…
-
6
votes4
answers2928
viewsA: Uppercase HTML vs CSS
There are differences, they are very important and it is recommended to use what makes sense for their purpose; they are not equivalent. Something You Need at all times has in mind: CSS applies…
-
7
votes3
answers315
viewsA: Would it be possible to list Enum from a table field through a query?
The very documentation quote: To determine all possible values for an ENUM column, use SHOW COLUMNS FROM tbl_name LIKE 'enum_col' and parse the ENUM Definition in the Type column of the output. Free…
-
2
votes1
answer58
viewsA: Conversion Farenheit Celsius
When dividing an integer by an integer, the result will also be an integer. That is, if you divide 5 by 9, being both integers, you will have 0 as the whole part of the actual result. Thus,…
-
4
votes2
answers237
viewsA: How to get the name of the python function parent
You can use the module inpect for that. With it you can get the stack up to its function add_log and, from it, find out who called the function. For this, we use the function inpect.stack, that…
-
20
votes2
answers264
viewsQ: How does PHP handle type declaration?
Still in PHP 5 it was already possible to make the declaration of types in arguments of function. Type statements Type declarations allow functions to require parameters to be of certain types when…
-
1
votes3
answers104
viewsA: How to mix elements of two arrays?
Just implement a function for this: function array_zip(...$arrays) { for ($i = 0; $i < count($arrays[0]); $i++) { foreach ($arrays as $array) { yield $array[$i]; } } } So if you do: $array_1 =…
-
5
votes2
answers10307
viewsA: Calling modal by javascript
It’s all about reading the documentation. function abreModal() { $("#myModal").modal({ show: true }); } setTimeout(abreModal, 1000); <script…
-
1
votes1
answer96
viewsA: Class does not connect with PDO to the database and another class in the same path yes
The error is simple: in the method Conexao::obtemConexao, if self::$instancia is defined, the method has no return, so in the first call, when it is not set, it returns correctly, but in the next…
-
0
votes1
answer60
viewsA: PDO - Showing bank information
Stick to the "Uncaught Pdoexception". Just capture the exception thrown in this case and treat it the way you want. try { $pdo = new PDO(...); } catch (PDOException $e) { die('Em manutenção!'); }…
-
5
votes4
answers388
viewsA: How can I add a hyphen between all even numbers of a value?
Regular Expressions You can do this with regular expressions: ([02468]{2,}) Captures any sequence formed by the numbers 0, 2, 4, 6 or 8 with two or more of size. After capturing the sequences of…
-
6
votes4
answers2181
viewsA: Check file extensions in Python
You can use the library pathlib to go through the directory and get the suffix of each file: from pathlib import Path path = Path('Pasta') for filename in path.glob('*'): print(filename.suffix) See…