Posts by Marcelo Theodoro • 366 points
10 posts
-
3
votes1
answer91
viewsA: Doubt def function with tuple mode input
There is a special syntax that allows you to receive a variable number of information in a function: >>> def tuplas(*args): ... return args[::2] ... >>> tuplas('Hello', 'World',…
-
0
votes2
answers742
viewsA: Is it possible to integrate Paypal into my website without the user logging in or creating an account?
This is called Checkout transparente. In the case of Paypal, this service is offered through Paypal Payment Pro. Besides Paypal, there are other companies that offer this service, such as Moip and…
-
1
votes2
answers11102
viewsA: How to import an xls file to Python?
A real example using xlrd: import xlrd def xls_parser(arquivo): tabela = xlrd.open_workbook(arquivo).sheet_by_index(0) qtd_linhas = tabela.nrows linhas = [] for i in range(1, qtd_linhas):…
-
1
votes1
answer950
viewsQ: How to return data from a select in sqlite3 as dictionaries instead of tuples in Python?
I’m using sqlite3 to record some data. However, by default, when a select is made, it returns the information as a list of tuples, which is considerably harder to work with than if they were…
-
2
votes1
answer950
viewsA: How to return data from a select in sqlite3 as dictionaries instead of tuples in Python?
This result can be achieved by changing the attribute row_factory cursor. This attribute should receive a callable, which accepts as arguments the cursor and the records (Rows), as in this adapted…
-
2
votes1
answer197
viewsA: Reportlab - Python - Doubt with date writing (date)
datetime.datetime object has no attribute 'decode' This error means that an object in the class datetime.datetime is being called, somewhere, with the attribute/method decode. The method decode, in…
-
0
votes2
answers856
viewsA: Sort lists in python dictionaries
If you only have a dictionary and want to sort a list within that dictionary, it can be used Sorted, as in the example below: >>> d = {'EstacaoCodigo' : ['1','2','3'] ,'NivelConsistencia' :…
-
1
votes1
answer71
viewsA: How do I get an argument in Web2py
Use the SQLFORM.Factory to do this, follows example: def apagar(): form = SQLFORM.factory(Field('id_deletar', label='Informe id...')) if form.process().accepted: id_deletar = form.vars.id_deletar…
-
3
votes4
answers9085
viewsA: NOT operator in python
Just to complement, a function where you just make a comparison and return only True or False, can be simplified this way: def tem_vaga(quantidade): return quantidade == 3 In the above case you will…
-
9
votes4
answers2266
viewsA: How to generate random numbers for Draw?
In Python you can use randint. Ex: from random import randint numero = randint(0, 99999) If you need to generate more than one number, and these are unique, you can loop and store these numbers in a…