Posts by Woss • 73,416 points
1,476 posts
-
1
votes1
answer30
viewsA: Sum values from a column in the table where the date repeats, in a SUB-SELECT
Nor will I enter the merit of trying to understand what the tables are queuelog, asteriskcdrdb.cdr and cdrjuncao, because it is not clear what is their relationship with the problem. You did GROUP…
-
3
votes1
answer41
viewsA: Loop for with isinstance() command does not work as expected
To justify this behavior it will be necessary to comment on mutable and immutable objects. In short, mutable objects allow their value to be changed, while immutable. Its object b is the type int,…
-
3
votes1
answer53
viewsA: Why when I inform "1.93" gives error when converting to integer?
As you can see in official documentation: class int([x]) / class int(x, base=10) Return an integer Object constructed from a number or string x, or Return 0 if no Arguments are Given. If x defines…
-
2
votes3
answers119
viewsA: Python: How to find the current date
Your logic is correct, but there are strange things in your code. data_atual = calendar.day_name[my_date.weekday()] if data_atual == 'Monday': teste= 'true' else: teste= 'false' In the first line of…
-
0
votes1
answer45
viewsA: edit python function
As commented, you do not need edit function, just create a new one that does the proposed: def media_variavel_continua(func, ini, fim): return quad(lambda x: x*func(x), ini, fim)…
-
4
votes1
answer42
viewsA: How to use IDLE within a virtual environment?
No need to install. IDLE is actually a module that comes bundled with Python and, when created the virtual environment, is still available to you. To run it, simply create and activate your virtual…
-
2
votes6
answers491
viewsA: Optimize code in Python
From version 3.8 of Python you can use assignment Expression: while not (texto := input('Digite um texto todo em maiúsculas: ')).isupper(): print('Erro! Por favor, digite o texto com todas as letras…
-
3
votes0
answers32
viewsQ: What is it, Edgedb?
It’s quite common to see discussions like How to choose between Nosql and SQL? or even questions that question which bank is best. When reading more deeply we see that each type of bank seeks to…
-
1
votes1
answer33
viewsA: assync does not work in ajax
If using the await, doesn’t need the success or then within the function. You will need then only when it is not already in asynchronous scope. async function get_title(id) { const data = await…
-
0
votes1
answer59
viewsA: Gave error "list index out of range" and do not understand the reason
Your list has 5 elements, so len(notas) will return integer 5, being first position 0 and last 4. You defined a loop of repetition so that: for i in range(0,len(notas)+1): ... That is, your range…
-
1
votes1
answer35
viewsA: Program usually runs but has moments that stops in the middle of execution and does not leave the place
The problem lies in your logic not to repeat the values: num = randint(1, 60) if num not in lista[0]: lista[0].append(num) else: while num in lista[0]: num = randint(1, 60) lista[0].append(num) The…
-
3
votes2
answers56
viewsA: Solved - Save more than one array in Mysql
To join the values of the three arrays you can use the function array_map. It takes as its first argument a function that will be called for each array value and will return a new array with all…
-
5
votes2
answers112
viewsA: When is an Slice data copied?
Analyzing We can make some initial considerations to better understand what happens with the presented code. When you do sequence[start:stop:step], the part between square brackets will act as a…
-
1
votes2
answers44
viewsA: Print all if conditions
It is a simple matter of logic. If you want a code to be running when a = 1 or when a = 4, just make such a condition. Today you have: if a == 1: ... Just do: if a == 1 or a == 4: ... Or,…
-
3
votes2
answers55
viewsA: Python: Run class or element inside a class
I have to say that it’s a very confusing and very biased structure to be a XY problem. But by way of knowledge, by defining the method as static it will basically act as a normal function within the…
-
1
votes1
answer180
viewsA: Python with MYSQL - ERROR: 'Nonetype' Object is not subscriptable
The error happens when you are accessing the index of an object that is None. spam = None print(spam[0]) # TypeError: 'NoneType' object is not subscriptable Whereas in your code there is only…
-
2
votes2
answers99
viewsA: find intersections in two graphs in python
From mathematics, we know that the intersections of two curves can be defined by equalizing the generating functions. That is, if you have two functions, A(x) and B(x), then the intersection occurs…
-
7
votes2
answers217
viewsQ: What is the Mint language?
When dealing with Javascript frameworks we realize that there are a multitude of options, with new ones popping up all the time. Angular, Vue, React, Svelte, Stencil and others I can’t even…
-
1
votes1
answer60
viewsA: Problem when trying to solve a challenge
If your role receives ai and i as parameters, the least we can expect is that the expression that will define the next value depends on these two values. By the examples it is clearer that the…
-
2
votes1
answer1591
viewsA: Dicionario Python
Well, basically the problem is that you use the same dictionary and the same list to store the information of all students and it gets lost in the middle of your code. In the statement it is clear…
-
3
votes1
answer44
viewsA: How to generate a user-defined list?
lista = [] for i in range(n): lista += input("Informe o valor de x%d: " % (i+1)) When you do this you are summing up two sequences. Lists are sequences and strings are sequences. Like the return of…
-
4
votes3
answers72
viewsA: How to manipulate cells from a vector?
Just do what the statement asks: each value of the new will be the value added with the previous ones. def accumulate(iterable): accumulated = [] for value in iterable: accumulated.append(value +…
-
5
votes2
answers53
viewsA: Process command line arguments
As the documentation cites, the fact that you remove the hyphens from the argument name makes it a positional argument of your command and thus do not need to inform the name (read more about POSIX…
-
5
votes2
answers54
viewsA: Why does creating a list with the same generator only work the first time?
The way you did it, that’s the way it is. Internally, the function itertools.product work with generators and, by definition, a generator can only be consumed once. How Python handles the "Yield"…
-
3
votes1
answer59
viewsA: How to enable Virtualenv in Windows command prompt?
When you create Virtualenv from Windows, the created folder structure will be: D:\projeto\venv │ pyvenv.cfg │ ├───Include │ ... ├───Lib | ... └───Scripts activate activate.bat Activate.ps1…
-
3
votes1
answer90
viewsA: Error "mkdir: Missing operand"
The problem is in doing mkdir $i_txtfiles, because Bash is considering the variable $i_txtfiles, which does not exist, so the error says that the function argument is missing mkdir. To make the…
-
0
votes1
answer20
viewsA: I wish that when receiving an email after it passes 24hrs it shows the date and not the time ago as per the image
Just implement a condition that checks if the difference is greater than 24h. Something like this: $diff = \Carbon\Carbon::create($mail->created_at)->locale('pt'); if ($diff->diffInHours()…
-
3
votes1
answer63
viewsA: How can I extract multiple objects from within an Array
What you have is similar to this, quite summarized: function get_objects() { const array = []; for (let i = 0; i < 5; i++) { array.push({ id: i }); } return array; } console.log(get_objects());…
-
3
votes1
answer341
viewsA: What does this error mean and how to fix it: Eoferror: EOF when Reading a line?
Apparently you are not dealing with the exception of the entry. In the URI platform the exception is triggered EOFError when the program entry is completed. while True: try: #seu código entra aqui…
-
2
votes1
answer25
viewsA: PUT or PATCH, which one should I use in this scenario
The difference between PUT and PATCH is merely semantic. That is, the meaning of the request: its purpose. An interesting feature of the PUT method is that it updates an existing record, but creates…
-
1
votes2
answers48
viewsA: Help to sum days on a user-selected date
Changes: If you do not want the current date as a reference, do not use new Date(); instead, new Date(datainicio). Care that d.getMonth() returns the month starting at 0, then January is 0, February…
-
6
votes1
answer83
viewsA: How to establish a minimum and maximum amount of a value required by an input in a JS request?
You don’t need PHP for this. If you already make the request to get the value, just define it with Javascript even: const quantidade = document.getElementById("quantidade"); quantidade.min = 0…
-
0
votes1
answer38
viewsA: How to show only the posts of the logged-in user?
You can define a Local Scope: class Propuestas extends Model { public function user() { return $this->belongsTo(User::class); } ... /** * @param \Illuminate\Database\Eloquent\Builder $query *…
-
1
votes3
answers63
viewsA: How NOT to separate a number of two or more digits when adding to a Python list?
Instead of adding the character directly to the list, you can create a buffer variable to store the value while it is numeric and add the list only when you find a letter or finish the string: teste…
-
5
votes3
answers214
viewsA: Calculate increments so that 2 numbers become equal
The solution presented in this answer does not work for all situations. I will not analyze your code because you misunderstood the problem and the code does not reflect what is asked in the…
-
2
votes1
answer37
viewsA: Is there a way to assign values to symbolic variables after deriving them using sympy?
from sympy import diff, var r, h = var('r h') def derivadaVolume(): volume = 3.14*(r**2)*h return diff(volume, h) h = 3 r = 2 derivadaVolume() When you do that, you’re saying that h is worth 3…
-
2
votes2
answers40
viewsA: define the function
From basic mathematics, we remember that to invert the signal of an exponent, we can invert the fraction of the base. That is, x (-2) is the same as (1/x) 2, being the signal of potentiation. So we…
-
1
votes2
answers29
viewsA: What is the difference at the time of the return of these two forms?
Just make a simple table test. Assuming there is any function called spam, we can analyze both implementations. def spam(): """ Uma função qualquer """ ... In the first form we have: def…
-
2
votes1
answer52
viewsA: Break a list and create lists
Just go through your sequence looking for the value '1' and temporarily accumulating in an auxiliary variable. Whenever you find the value you returns the value of the temporary variable in its…
-
3
votes1
answer46
viewsA: Is it possible to create dictionaries using surreptitious ties?
Yes, it’s possible and your code already does that. However, as commented, because you always assign the same key in the dictionary, you will always be overwriting the old value. This way, your exit…
-
1
votes1
answer32
viewsA: I want to tweet every 240char but not recognized - Python(Tweepy)
You can use the function textwrap.wrap that will already return to you a list of substrings with the defined size. from textwrap import wrap ... booklines = wrap(bookfile.read(), width=240) for…
-
3
votes2
answers368
viewsA: Count occurrences of a letter in a string that repeats several times to a character limit
string_repetida = s * n_repetidos On this line you are creating a new string that will be the string s repeated n_repetidos. There’s no point in doing that, because if the idea is just to count the…
-
2
votes3
answers105
viewsA: Doubt about Python list
def verificar_lista(lista): itens = lista for i in range(len(itens)): if itens[i] not in itens: return False else: return True Doing the table test is easily shown that what your code does is: If…
-
8
votes3
answers171
viewsA: Does the function not return the minimum value?
The main problem is that you are passing a string as a parameter of your function: t = input("Digite sua lista: ") print(min_max(t)) The return of function input is always a string. When you call…
-
1
votes1
answer44
viewsA: Exchange vowels for "*"
That piece of code doesn’t make sense: for(n=0;n<=t_f;n++){ printf("Frase criptografada:%s",f[n]); } You’re going through the entire sentence to display character to character, but you put as…
-
2
votes3
answers415
viewsA: How do I timeout and replay a command line in Python?
As commented, you can use the reply of Timeout in Python input function along with a repeat loop, so re-run the function when timeout occurs. @timeout(seconds=5) def read_user_name(): name =…
-
3
votes1
answer347
viewsA: Calculate the average of a matrix
The problem is that len(matriz) returns the number of rows in the matrix, not the number of elements. Since you are going through the matrix, you can add in a variable the size of each row to get…
-
2
votes1
answer56
viewsA: Could you help me narrow the code?
You can create a dictionary in which the keys are the input characters and the value are the characters for which you want to "encrypt". Using the dict with zip the code becomes quite simple: def…
-
4
votes2
answers104
viewsA: Python - Declaration of a variable in Try
Your premise is wrong. The block try/except does not create a new context of variables, ie any variable you set within your block try will exist outside the block as well. See the example: try:…
-
9
votes2
answers287
viewsQ: What precautions should I take when naming a Python file?
It is quite common to see problems generated because the Python file was named after a library. # requests.py import requests response = requests.get(...) This code snippet would generate the error:…