Posts by Carlos H Marques • 437 points
23 posts
-
0
votes1
answer377
viewsQ: in Sqlalchemy what is the difference between filter and filter_by
Is there any difference between the function filter and filter_by in Sqlalchemy? If it exists, when should I use each of them properly?
-
1
votes1
answer173
viewsA: sum the database values and display the result in the flask-sqlalchemy template
You can do it this way from sqlalchemy.sql import func @app.route('/') def index(): va = Registro.query(func.sum(Registro.valores)).all() return render_template('index.html', va=va) in the…
-
0
votes3
answers243
viewsA: How to save file without overwriting the previous python?
To stay in a more dynamic and organized way, you can put the date and time in the file name, for example from datetime import datetime data = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") nome1 =…
-
8
votes1
answer1176
viewsQ: What are and what are .js.map files for?
I downloaded the latest version of Boostrap (4.3.1 today). and I noticed that in the js folder, came several files with the end . map js/bootstrap.bundle.js js/bootstrap.bundle.js.map…
-
0
votes1
answer146
viewsA: Arithmetic calculations (sum) in the Flask-Sqlalchemy database
You can use datetime.timedelta for this from datetime import timedelta hh = 0 mm = 0 for post in posts: h, m = post.hora.split(':') hh += int(h) mm += int(m) hora = timedelta(hours=hh) +…
-
0
votes1
answer269
viewsA: Select from and Insert into another database with Python
Maursb, from what I saw in your code, there’s an error in the FOR change line 20 so it looks like this rows = cursor.fetchone()
-
0
votes1
answer45
viewsA: Updating a JSON-like column in Postgres with Python and Psychopg2
If this snippet of code you posted is the same as in the program, there is an error in this part of the code json.dumps({'v1':'a','v2:'b'}), id_game) ^ deveria ter um ' aqui` try replacing with…
-
-1
votes2
answers344
viewsA: How to make a text generator according to the possibilities I put in it
Place the options inside a tuple, shuffle with the Random.shuffle method, and take the first position. from random import shuffle op1 = ['Olá', 'Oi', 'Boa tarde'] shuffle(op1) op2 = ['o seu dia está…
pythonanswered Carlos H Marques 437 -
2
votes3
answers1463
viewsA: For with python time
You can do this simply using the Sleep method of the time module see an example of code that runs every 1 hour. from time import sleep from datetime import datetime hora = 3600 while True: print…
pythonanswered Carlos H Marques 437 -
4
votes2
answers87
viewsQ: Updating OS packages from a Database container
I am redoing a Zabbix server here at the company, where I will upgrade from version 3.2 to 4.0 I’m thinking of using Docker to make life easier, since Dockerhub has images for Zabbix-Server, for…
-
0
votes2
answers130
viewsA: Local variable declaration in a PYTHON function
Take a look at Rafael. When you do a, b = a, a+b variable A and variable B receive the value at the same time, so when B receives a+b A still has the value of the previous loop the previous value.…
-
1
votes2
answers171
viewsA: Coding problems
In this case, as you use output a system terminal, in case you use linux, it can be solved as follows # -*- coding: utf-8 -*- import sys reload(sys) sys.setdefaultencoding('utf8') # aqui você seta a…
-
1
votes1
answer150
viewsA: Flask Sqlalchemy : Keyerror
You are specifying the Category class and the Author class field Alter author =db.relationship('Category', backref=db.backref('article',lazy=True)) To make you like author =db.relationship('Author',…
-
3
votes2
answers206
viewsA: Replace words between two files
Another way that would keep the " n" in the text is like the code below, which is even simpler than yours. import csv with open ("arquivo1.txt", "r") as f, open("arquivo2.csv", "r") as f1: text =…
-
1
votes2
answers206
viewsA: Replace words between two files
I think it would be something like # coding=utf-8 import csv aa = "" with open ("arquivo1.txt", "r") as f, open("arquivo2.csv", "r") as f1: text = f.read().split('\n') text_csv = csv.reader(f1,…
-
0
votes2
answers220
viewsA: Flask Sqlalcheny Typeerror: 'Fermentables' Object is not iterable
I managed to solve the problem as follows Popular the database: malte_cevada = FermentableTypes(name='Malte de cevada') malte_trigo = FermentableTypes(name='Malte de trigo')…
-
-6
votes2
answers52286
viewsA: Which operator is equivalent to different in Python?
In Python you could use Different "!=" or Not "is not" if "Foo" != "Bar": return "Diferente" if "Foo" is not "Bar": return "Diferente"
-
0
votes3
answers840
viewsA: DIV Bootstrap Alignment
Probably the problem is that you are not respecting the 12 columns. 8 + 1 + 2 = 11 try to put 1 more somewhere like 9 + 1 + 2, or 8 + 1 + 3 that should solve
-
-2
votes4
answers6679
viewsA: How to force numeric keyboard display on the smartphone when clicking an input?
HTML5 added new type types to the input field <input type="number"> To add ZIP type mask by editing the date-Mask as below <input class="form-control" placeholder="Ex.: 00000-000"…
-
2
votes1
answer141
viewsA: Python - How to keep decimal places from list item to variable?
I tested here with Python 2.7 and 3.6 and the result was the same >>> lista = [0.123456789101112, 0.987654321012345] >>> a=lista[0] >>> lista[0] 0.123456789101112…
-
1
votes1
answer46
viewsA: Exception XML-RPC class (Python)
Server register_function should look like server.register_function(Animal, "Animal") server.register_function(Sheep, "Sheep") And in the Customer change the line 8 to be as with…
pythonanswered Carlos H Marques 437 -
1
votes2
answers220
viewsQ: Flask Sqlalcheny Typeerror: 'Fermentables' Object is not iterable
In the model FermentableTypes: class FermentableTypes(db.Model): __tablename__ = "fermentable_types" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) desc =…
-
0
votes2
answers300
viewsA: How to insert checkbox dynamically from Python/Flask code?
The easiest way is to do this directly on Jinja2 {% for d in dirs %} <input id="{{d}}" name="{{d}}" type="checkbox"> {% endfor %}