Posts by Giovanni Nunes • 2,638 points
141 posts
-
2
votes2
answers143
viewsA: Conditional structure does not work
Another alternative to this problem, and also much more scalable, is to use the language’s own data structures to solve the problem: ITEMS = 3 precos = [] for item in range(1, ITEMS + 1):…
-
0
votes3
answers1463
viewsA: For with python time
From what I understand you just want to increment the values, so use the object timedelta together with the datetime to increase or decrease variables with date and time: from datetime import…
pythonanswered Giovanni Nunes 2,638 -
1
votes1
answer2467
viewsA: How to put a background image on Jumbotron? Bootstrap 4
The best way to do this is to create a new file to store CSS customizations, a "style.css" or "custom.css" etc and define the new attributes for "Jumbotron": .jumbotron-with-background {…
twitter-bootstrapanswered Giovanni Nunes 2,638 -
3
votes1
answer153
viewsA: How to let the negative operator after using diff() in php
The result of the comparison is always the number of days but there is an attribute in the object returned by date_diff() called invert indicating whether the value is positive or negative (zero for…
-
1
votes1
answer43
viewsA: How to use t (tabulation) on EOF outputs?
The cat does not interpret the escape codes but there are several ways to do it, one of them is to use the echo: echo -e "alias\tVARIABLE = command" That will return the sequence alias VARIABLE =…
-
1
votes3
answers563
viewsA: Problem keeping quotation marks
Adding a third option, you can use sequences """ ... """ or ''' ... ''' to delimit the strings without the need to escape the quotes and apostrophes within it: >>> a = '''Disse ele: "era…
-
1
votes1
answer38
viewsA: Return only the file name in the view
Use the function basename module os.path: >>> from os import path >>> a='/usr/local/share/pixmaps/sample_image.png' >>>> path.basename(a) 'sample_image.png' You can…
-
2
votes2
answers1740
viewsA: Comparing datetime with minutes interval
If you just want to compare two dates with a certain time tolerance between them the best alternative is to work with them in seconds and not with human format with day, month, year, hour, minute…
-
2
votes2
answers493
viewsA: Typeerror: 'datetime.datetime' Object is not callable
You are calling the variable seven_days_ago as if it were a function (hence the error saying that the object datetime.datetime cannot be called), remove the parentheses and it will work. And…
pythonanswered Giovanni Nunes 2,638 -
1
votes1
answer1092
viewsA: Sqlite3 - unrecognized token
You are creating a table that starts with a number, 5w2h, in addition to the name of one of the fields, Where, is reserved word within SQL. One way to solve is to put them all in quotes: sqlite>…
sqlite3answered Giovanni Nunes 2,638 -
1
votes2
answers46
viewsA: How do I print the smallest height ever read?
Unless you consider a smaller value with a very large number at startup, which may not be a good idea for some cases, the best thing is to start the variable to a lower height with the first height…
canswered Giovanni Nunes 2,638 -
1
votes2
answers1675
viewsA: Tooltip Bootstrap 4 does not work
I used the tooltips in a project and configured them like this: $(document).ready(function() { // ... $(function () { $('[data-toggle="tooltip"]').tooltip() }) // function() // ... }) And HTML is…
-
1
votes1
answer92
viewsA: Error when recognizing Ubuntu SSH?
This account [email protected] is to be used by the customer of the git and not for remote access: $ ssh -T [email protected] logged in as XXXXXXXXXX. You can use git or hg to connect to Bitbucket.…
-
0
votes2
answers77
viewsA: How to "reimport" an object from a Python module?
If you’re using the jupyter, just press «Shift»+«Enter» on the cell, you will see that its number in brackets will increase, this means that the function has been "relined" and is now available with…
-
5
votes1
answer280
viewsA: Push in Bitbucket
It’s actually Git itself that’s blocking you, not Bitbucket, because you don’t have user and email properly configured, just do it: git config --local user.name "Henrique Mendes" Or whatever name…
-
3
votes3
answers3774
viewsA: Write text to Shell Script
There are several ways, one is using the command cat and a delimiter: cat >'arquivo.txt' <<EOT aí você coloca um monte de texto e só precisa terminar com o a mesma string usada no…
-
3
votes2
answers424
viewsA: How do I calculate the average running time of a function?
You can place the snippet of code you are measuring execution within a loop: import time REPETICOES = 10 tempos = [] for vezes in range(0, REPETICOES): inicio = time.time() # ... o código a medir…
pythonanswered Giovanni Nunes 2,638 -
0
votes2
answers131
viewsA: Regex to extract string content
In your case you will need to use groups in regex to delimit and also identify what you want to search/extract, groups are identified by using elements in parentheses. This program uses the samples…
-
2
votes1
answer34
viewsA: Next element of the loop
In the case of the loop for you will not be able to catch the next element from the list but it is possible to use the loop while and the command shift to do so: show_commits(){ first_tag=${1} while…
-
1
votes1
answer89
viewsA: Date validation composed of three integers in Django
Do you want to check whether the date entered is valid or not? Use the module datetime who knows how to do it properly: # -*- coding: utf-8 -*- from __future__ import print_function from datetime…
-
0
votes1
answer223
viewsA: Error: Deploy Python Heroku - Runtime (python-3.4.0) is not available
According to the documentation of Heroku they only support versions 3.7.1, 3.6.7 and 2.7.15 of Python. You are trying to use versions that are no longer available, so modify your project to use…
-
0
votes1
answer487
viewsA: No module named - Python
You also installed version 2 of Mailchimp after installation of version 3, remove it with pip uninstall mailchimp and reinstall version 3.
-
0
votes1
answer285
viewsA: Mask using flask does not load
Are you using the jQuery Mask which is not an integral part of jQuery and therefore needs to be loaded as well. By the way, is that "_=" correct? This example using pure HTML worked: <html>…
-
4
votes3
answers98
viewsA: Doubt in my code is not printing correctly
You’re treating the notes like strings, then when you sort Python puts "1", "10", in front of "2", "4" etc. In this case the best solution is to work with them as a numerical format. # ... for item…
pythonanswered Giovanni Nunes 2,638 -
0
votes4
answers658
viewsA: Debug showing variable name and value?
They’re inside the module logging: import logging from random import randint logging.basicConfig(level=logging.DEBUG) logging.info('Iniciando o programa') for i in range(0, 5): x = randint(0, 100) y…
-
1
votes2
answers249
viewsA: Dashboards of users logged in using Django admin user
It is an asynchronous method, you can register in a template both the login as to the logout user, saving this information before calling the functions login() (records that the user has entered)…
-
5
votes1
answer836
viewsA: Export a dictionary to file . txt
If you are working only with the default data types of the language, that is, "int", "float", "str" and "bool" you can export and import the dictionary as a JSON file: #!/usr/bin/env python from…
-
0
votes2
answers275
viewsA: Foreign key FK, is each identification number on a table?
The foreign key (Foreign Key) is when a key of a table (some call index, or ID) is used within another table to reference it, then it exists to relate them, ie it does not exist alone. In your…
-
1
votes1
answer68
viewsA: Print Mongodb BSON with several different structures
Both JSON and its "brother", BSON, do not preserve the order of the keys inside the document. The simplest solution is to store them inside a array, something like this: { "_id" : { ... }, "media":…
-
1
votes1
answer239
viewsA: Python processes
This condition causes the Pool is started only if the program is called directly, as the module multiprocessing will also call this program to run the function f() for each instance of pool this…
-
2
votes3
answers12436
viewsA: What are recorders and what is their basic functioning?
The registers are a "space" within the (micro)processor where it is possible to store certain values. These can be an arbitrary value, the result of a logical/arithmetic operation, flags status or…
assemblyanswered Giovanni Nunes 2,638 -
1
votes2
answers1874
viewsA: Problem importing a class from another folder and using it. (Python)
Within the classes directory create a file called "__init__.py" with the following content: from classPrint import printar This will identify to Python that the classes directory has a module…
-
0
votes2
answers294
viewsA: upload with ajax and formdata displays error
Sending and receiving data in AJAX is usually done using strings and you are sending the data as Object, use the function JSON.stringify() to convert the data before sending. // ... $.ajax({ type:…
-
0
votes2
answers254
viewsA: Intensive python course by Eric Matthes ex8.10
I do not know the book but as I understood the exercise tells you to create a new function and not modify the existing one, so you need to create this second function, the make_great() to return the…
-
-1
votes2
answers52
viewsA: Problem with Vagrant up - Homestead-7 already exists
Use vagrant global-status to view all the virtual machines you have configured and the status of each of them: $ vagrant global-status id name provider state directory…
-
2
votes3
answers783
viewsA: How to input() stop after space instead of line break in Python3
Really the question is confusing but if the list is "infinite", just read an entire line and then separate the elements: #!/usr/bin/python3 # recebe cada número de uma só vez. print('Digite a lista…
-
1
votes1
answer38
viewsA: Import packages inside tests with python
Since I don’t know how is the structure of your project the simplest solution is you put its directory in the path of Python. You can do it in two ways. The first is by the environment variable…
pythonanswered Giovanni Nunes 2,638 -
1
votes1
answer571
viewsA: Python Class Method Call
You noticed that method getRank() was spelled as getRankeado()? After the correction your program starts working correctly: import random class Card(object): def __init__(self, rank, suit):…
pythonanswered Giovanni Nunes 2,638 -
0
votes1
answer1779
viewsA: How to grab and save many data entries in python?
Variables of the same type can be aggregated into a list (I will use the terminology of Python), for example: animais=['cachorro', 'gato', 'galinha'] print(animais) ['cachorro', 'gato', 'galinha']…
-
0
votes2
answers1096
viewsA: Error formatting string for python datetime
If it makes no difference to you, add the parameter ignoretz=True when calling the method parse(): from datetime import datetime from dateutil.parser import parse data =…
-
1
votes1
answer1151
viewsA: How to create a registration form with Django
Your form is not associated with the template, hence it has not inherited the "save" attribute anywhere. Here you have two ways to fix this, in the first remove the sub-class Meta form (it is not…
-
0
votes1
answer172
viewsA: Create functions in Python
This example will receive a list (of lists) of any size, associate to variables nome, uf and idade and add up the values of uf: def conta_ufs(pessoas): ufs = {} for pessoa in pessoas: nome, uf,…
-
0
votes1
answer41
viewsA: how to take out data and add to an existing Python function
Do so, rename the function aposta() for get_aposta(), then you can call her that: aposta = get_aposta(fichas) And when it’s time to call the function jogarDados(), this will have read access to the…
-
1
votes1
answer155
viewsA: How to print on screen or console, a string array in php
What you want is to individually check each element of the array. I mean, it would be something like this: for ($i=(int)0; $i<count($remetenteArray); $i++){ print ">".$remetenteArray[$i]."<…
-
0
votes2
answers343
viewsA: String occurrence calculation in list - Python
Basically you should go through each item of the list checking whether the position relative to the profession contains "Doctor" or else "Teacher" and incrementing the respective counter. Something…
-
1
votes1
answer1839
viewsA: Python - Error in using import, module --- has in attribute
I noticed in the repository that the file __init__.py inside "Events" is empty. It is he who coordinates the loading of modules inside the directory. In your case it should be something like: from…
-
1
votes1
answer60
viewsA: My site does not get responsive is just text
I believe that what you want to do is this (considering only the excerpt presented): <div class="container"> <div class="row"> <div class="col-sm-12 col-md-6 col-lg-4"> <h1…
-
1
votes2
answers875
viewsA: Is it possible to replace the Javascript language with Python in web development?
It is possible to use "interpreters" such as Javascriphton to translate your Python code to JS or even solutions like Coffescript or Typescript to program in a cleaner version of the language.…
-
0
votes2
answers623
viewsA: Regular expression for dynamic URL
Considering that the variable part will be composed of letters, number and the hyphen, replace the (.*) for [a-z0-9\-]+ that must resolve.
-
0
votes2
answers37
viewsA: Table does not want to be vertical
For each table row you must also have your own TR (Row table): {% for i in range(200) %} {% if "IFATC" in data[i]['DisplayName'] %} <tr> <td align=middle…