Posts by Miguel • 29,306 points
758 posts
-
4
votes1
answer1889
viewsA: Print in ascending order the natural first n which are multiples of i or j or both
If all you need is a list of n numbers because the overhead of adding more and then removing them unnecessarily? You can use a while cycle and module to see if any of the nums i and j is multiplied…
-
1
votes1
answer139
viewsA: Error while working with date formatting in Laravel
Laravel is doing internally the next: isset($usuario->data_nascimento->format('d/m/Y')) ? $usuario->data_nascimento->format('d/m/Y') : old('data_nascimento'); Case format false ("Returns…
-
1
votes1
answer400
viewsA: Plotting file . xls with matplotlib and openpyxl
From what I understand I think you might be popular with axle values x and y as follows: ... y_vals, x_names = [], [] for c1, c2 in celulas: x_names.append(c1.value) y_vals.append(c2.value) You can…
-
9
votes2
answers160
viewsA: Little Python Combat Game
Basically you have 3 major problems: a=randint(1,6) This Line only happens once before the while cycle, so the value of a will not change, it seems to me that it should be within the cycle and it is…
-
0
votes1
answer857
viewsA: How to skip first line of csv file
You can do the following to remove the first array item, array_shift(): ... $Dados = file($tempFile); array_shift($Dados); // remover primeira linha, primeiro elemento do array ... DEMONSTRATION…
-
5
votes1
answer39
viewsA: Python c/ swapcaser problem
There appears a None because you’re not returning anything in your function, you’re just printing, change to: def swap_case(s): for x in s: if x.isupper()==True: return x.lower() else: return…
-
3
votes1
answer72
viewsA: It is possible to name a python module using the __import__function
As you have in question is not, but you can assign the return of __import__ to a var, ex: mod_alias = __import__('string') The equivalent of: import string as mod_alias In this case mod_alias is…
-
1
votes1
answer102
viewsA: How to save inline style in a variable?
Of course, just save the value of the property you want before any change, using the version getter of the method css(): var original_val = $('.box').css('top'); // <-- acrescentar isto…
-
3
votes1
answer1071
viewsA: How to create a dictionary and auto increment values?
You can do it using setdefault, and yes, it is unnecessary to use two cycles: t = [[1,2],[2,1],[3,1],[4,1],[1,1],[2,2],[1,2]] dicionario = {} for k, v in t: # unpacking dos valores de cada sublista…
-
1
votes1
answer2667
viewsA: How to avoid Max retries exceeded error in scraping in Python?
I ran the program down in response, it took almost 2 hours (even with 100 threads), but the data is here: https://we.tl/kAUuAeW9gR (won’t be for long) I can’t effectively answer the question of the…
-
0
votes1
answer366
viewsA: Passing href address on a datalist
You can do as follows, as the event to delegate should be the input: var href; function myfunction(){ $('form').on('submit', function(e) { e.preventDefault(); href = $('datalist option[value="'…
-
5
votes3
answers324
viewsA: How can I take each selected checkbox and put it inside an input?
Taking advantage of what you were doing, here’s what you can do: var vals; $('#bt-ok').click(function() { vals = []; $("input[type='checkbox']:checked").each(function(){…
javascriptanswered Miguel 29,306 -
1
votes1
answer106
viewsA: Application for login on another site (Facebook), error "Invalidsubmiterror"
Place the parameter submit with the corresponding button: ... browser.submit_form(form, submit=form['login']) ... Thus remaining: import robobrowser import re url = 'https://m.facebook.com'…
-
0
votes1
answer366
viewsA: Access prop in Vuejs method
Access a prop exactly as you’re doing, this.orders, ex: ... methods: { get_orders: function() { return this.orders; } }, ... As per comment I realized that these items came from an ajax request,…
-
0
votes2
answers68
viewsA: Exercise list ordering
No mistake, you simply did not order the list after removing duplicates: def remove(lista): return sorted(set(lista)) # <--- ordena lista DOCS…
-
2
votes2
answers457
viewsA: How to join texts in a file?
To write to files (this part you already have): from random import sample from string import ascii_lowercase print('\n'.join('teste' for _ in range(100)), file=open('1.txt', 'w'))…
python-3.xanswered Miguel 29,306 -
2
votes1
answer59
viewsA: How to find out which line is any CSV data
Here’s what you can do: $CPF_user = $_POST['CPF']; // receber cpf do user $lines = file('file.csv'); // array com as linhas do file.csv foreach($lines as $l) { // percorrer as linhas $params =…
-
2
votes3
answers2778
viewsA: Separate data from a txt file
Assuming each line will always have the same formatting, number of digits etc... I don’t think it’s a good idea to separate by spaces, since the column names have spaces, in this case I’ll separate…
-
2
votes1
answer1254
viewsA: Add spaces to the end of the field - python
You can use ljust: print('7513200870410'.ljust(13)) # '7513200870410' print('181420'.ljust(13)) # '181420 ' Or format (python3.x): print('{:<13}'.format(7513200870410)) # '7513200870410'…
-
2
votes1
answer131
viewsA: Migrate: Is it possible to change a table to add a column and already pass some value to it (excluding the nullable() option)?
Yes you can add a default: Schema::table('estudantes', function (Blueprint $table) { $table->string('genero')->default('M'); }); This way if you do not say otherwise when inserting a new row…
-
3
votes1
answer161
viewsA: Like php mysqli
What you want is a relationship between Nxn tables (many to many), a user can like several posts, and a post can be liked by several users. The most conventional is to create a pivot table, e.g.:…
-
1
votes1
answer25
viewsA: Can you ignore a page in the apache log?
Based on the DOCS, in the "Conditional Logs" section we can see: # Não incluir nos logs caso a requisição venha do ip abaixo SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog # Não incluir nos logs o…
-
3
votes2
answers1715
viewsA: python list problems
Depending on the data you present you can do the calculations all at once (in the same cycle), as well as you can popular the two lists also in the same cycle: listaCarro = [] listaConsumo = []…
-
4
votes1
answer2368
viewsA: How to go back days on datetime, python?
Here’s what you can do, datetime.timedelta: import datetime date_now = datetime.datetime.now() seven_days_ago = date_now - datetime.timedelta(days=7) print('now:', date_now.strftime("%d/%m/%y")) #…
-
2
votes2
answers787
viewsA: How to add up several numbers that were typed in the output?
You’re overwriting the value of n when you do n = int(input()), does before: total = 0 for _ in range(3): n = int(input()) total += n print(total) DEMONSTRATION Or with fewer lines/variables: total…
-
1
votes1
answer53
viewsA: Search using model
In reality it’s all right, but incomplete. At this time: $model = MinhaModel::where( 'campo1', $codigo ); You just get the Builder, you are not yet extracting the results, for that you just need to…
-
15
votes1
answer4493
viewsA: How to make a "deep copy" in Python?
What you’re doing is just one Shallow copy (surface copy). DOCS: The Difference between Shallow and deep copying is only Relevant for compound Objects (Objects that contain other Objects, like lists…
-
4
votes1
answer48
viewsA: Write Dice from one list to another list
Taking advantage of what you have you can do like this: def acoes(T): listaAction=[] for idx, i in enumerate(T): if(i==0): listaAction.append(idx) return listaAction T = [0,0,0,1,0,0,0,-1,0]…
-
4
votes1
answer5780
viewsA: Error: "Maximum recursion Depth exceeded while Calling a Python Object"
The mistake is because you’re settar a property that bears the same name as yours setter, and its method: @x.setter def x(self, valor): self.x = valor # valor de x muda aqui Whenever this value…
-
1
votes3
answers3451
viewsA: How to count the records of a csv in python?
To count the lines/lists that have "Feminine", you can do so: import csv l_feminino = [] with open('teste.csv', 'r') as arquivo: delimitador = csv.Sniffer().sniff(arquivo.read(1024), delimiters=";")…
-
4
votes3
answers1523
viewsA: How to print Javascript variable value in HTML tag?
You can do it like this: var data = new Date(); var dia = data.getDate(); var mes = data.getMonth(); var ano4 = data.getFullYear(); var str_data = ano4 + '-' + (mes+1) + '-' + dia; inp =…
-
4
votes2
answers885
viewsA: How to add an animation button to go back to the top of the page using the easings library?
To apply easing you can do as follows: $('button').on('click', function() { $('html, body').animate({ scrollTop: $($(this).data('target')).offset().top }, 800, 'easeOutBounce'); // o easing que…
-
3
votes2
answers81
viewsA: Fix incorrect module return
The 'problem' not only in python, happens in many other languages, some do not 'demonstrate' because they soon treat the result internally. This has been the subject of early computing, and has to…
-
3
votes2
answers4478
viewsA: List of objects in Python
If the goal is just to show the class name, you can do so: class Foo: pass print(Foo().__class__.__name__) # Foo DEMONSTRATION But if you want something more personalized for each object (class…
-
2
votes2
answers407
viewsA: How to correlate files from two txt files in Python
To see the elements in common between two files (word lists) makes the intersection between your sets: with open('arquivo1.txt') as f1, open('arquivo2.txt') as f2: content1 = f1.read().split() #…
-
2
votes1
answer3550
viewsA: count how many times the word loaded from the txt file appears python
To tell a word you can do so: palavra = 'casa' with open('arquivo.txt') as f: ocorrencias = f.read().count(palavra) print(ocorrencias) # num de vezes que a palavra aparece Done this, if you want to…
-
1
votes2
answers4032
viewsA: Remove specific Python characters
Another way to do it is by using Translate, that: lista = [["de carlos,"],["des.dd carlossd,"],["Peixe, texto!"]] lista_separados = ['.',',',':','"','?','!',';'] trans = {ord(i): '' for i in…
-
5
votes3
answers1281
viewsA: Python dictionary
From what I understand I think you can do the following: d = {'olá': 'hello', 'como':'how', 'estás':'are', 'tu':'you'} frase = 'olá como estás tu' # aqui seria o teu input('frase') words =…
-
7
votes1
answer1498
viewsA: Count how many times a word of a file appears in another file
Here’s what you can do: count = {} with open('corpus.txt') as f1, open('lexico.txt') as f2: corpus = f1.read().split() # texto for word in f2: # palavras a quantificar no texto w_strp = word.strip()…
-
10
votes1
answer564
viewsA: Is there any way to delete the auto space that appears after the python comma?
In that exact way, print('exemplo',zero), nay. But the way (only available in python3.x) more like this, in which space is taken out is: zero = 0 print('exemplo', zero, sep='') # exemplo0 DOCS Here…
python-3.xanswered Miguel 29,306 -
2
votes1
answer1377
viewsA: Selecting row information in an HTML table
In a simple way you can look for the <td> with Indice 1 (eq(1)) within the line to which the button that was clicked belongs. var clicado = null, nome = null; $('.clicado').click(function(){…
-
5
votes1
answer1958
viewsA: Associate two lists in python
The condition <= 5 is wrong, because if the lists have 5 elements only have between 0 and 4 indices (because these start at 0), try this version of the code while n < 5, or better, while n…
-
3
votes1
answer277
viewsA: "rank" array in Python
Let’s start by sorting the list: lista = [['segundo', 1], ['evidenciaram', 3],['Palavras', 4], ['apresentado', 2], ['tratados', 1], ['realizada', 1], ['mostraram', 2]] l_sorted = sorted(lista,…
-
4
votes2
answers43
viewsA: List creation problem in Vue.js
In the for cycle you must specify that you are traversing in order to have access to the corresponding Dice, try this: <li v-for="(element, index) in elements"> {{ element.title }} <a…
-
1
votes2
answers233
viewsA: How to extract all td names in order?
What is the order you want? Alphabetical or in the order in which they were found? Below I do to cover both scenarios: from bs4 import BeautifulSoup as bs from urllib.request import urlopen req =…
-
5
votes5
answers7921
viewsA: How to properly format CPF in Python?
If it is really this format always, then I agree with @Maniero in comment, it does not need a class for this at all, you can do so: teste = input("CPF: ") # 12345678900 cpf =…
-
2
votes1
answer242
viewsA: How to allow the user to add a new option in a <select>?
You can do it like this, I’ll check if there’s anything typed in here so you don’t add a <option> text-less: var input_ele = document.getElementById('new-opt'); var add_btn =…
-
1
votes4
answers94
viewsA: Putting elements in lists
If it is as constant as shown in your example you can do: lista = ['banana [amarela]\n', 'uva [vinho]\n', 'laranja [laranjado]\n', 'kiwi [verde]\n', 'framboesa [vermelho]\n', 'coco [marrom]\n']…
-
1
votes1
answer59
viewsA: Command finddo Matlab in python?
The find de Matlab returns the position of the elements that satisfy a particular condition. A simple way to implement it would be: vals = [1,2,5,64,33,2,4,-1,3,-54,21] vals_find = [idx for idx, val…
python-3.xanswered Miguel 29,306 -
5
votes1
answer705
viewsA: Refresh page when user is missing and there are no videos on page
Only with php/html you can’t do this, but here’s an example of doing with javascript/jquery: <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script> var…