Posts by Sidon • 6,563 points
288 posts
-
2
votes1
answer638
viewsA: Difference between task and shared_task in Celery?
The decorator task, by default share tasks between apps: app1 = Celery() @app1.task def test_task(): pass app2 = Celery() print('test_task.name in app1.tasks.keys(): ' + str(test_task.name in…
-
3
votes2
answers61
viewsA: Pass X function as parameter to Y function, but only define X parameter within Y
TL;DR If I understand correctly, you have made 2 mistakes, the first is when Voce sends the function f_numbers for func2, instead of sending the object you are sending the execution and the second…
-
1
votes1
answer530
viewsA: Anaconda for Pycharm on Linux
Anaconda, besides being a python distribution, is also a virtual environment manager (venvs), that is, the ideal is that you create a virtual environment for each project you have to work on, so you…
-
0
votes1
answer53
viewsA: '<' not supported between instances of 'method' and 'method' Django 2.0
The message says that on the line where you make the comparison: if self.valortotal < self.valor_nota: You are comparing two instances of methods, so the message "< is not supported between…
-
-1
votes1
answer201
viewsA: Fill in field with "00-00-0000" when empty
Treat before building the query: data_exec_visita = '00-00-0000' if valores[1]=='' else valores[1] data_estado_format = '00-00-0000' if valores[2]=='' else valores[2] make a test before to see if…
-
3
votes1
answer678
viewsA: Bubblesort Complexity Calculation
It depends on what you mean by "complexity", I will try to demonstrate through notation Big O. Bubble Sort consists of going through a list and changing the positions of the elements in order to get…
-
0
votes1
answer103
viewsA: How to run a python script in Notepadqq?
In the image you put in the question there is a field for you to type a command, type the command to run the current script, in my case I would type: /usr/bin/python %path% When you confirm you will…
-
0
votes3
answers865
viewsA: Select with due dates
You did not inform which bank you are using and whether the command will be from a specific language/environment, I created an example with Mysql 5.6, although you also did not inform, I considered…
-
0
votes3
answers1736
viewsA: Find word in python txt file
According to the comments, what you need to do is just look for the word typed in the text and, if it exists, create the anagrams, for this I created an example simulating the reading of a text in a…
-
1
votes2
answers4333
viewsA: list, max/min in python
You can use pandas, I created an example with only 36 random numbers (3 rows of 12 columns) generated randomly to simulate your csv, I read this 'file' for a Dataframe pandas object and then present…
-
0
votes1
answer265
viewsA: Using groupby in a dataframe
For this problem I wouldn’t use the groupby, see my solution: I created an example where from the data you put in the question (I took only 6 lines of them) I create a DataFrame(df0) by doing Rt in…
-
0
votes1
answer445
viewsA: Communicate template with view
Comparing the code with the title of the question, it doesn’t seem to make much sense to me that I’m out of context, so I’ll try to answer myself by paying attention exclusively to the title of the…
-
2
votes2
answers422
viewsA: Finding students without a class - Python / Excel
In addition to importing the worksheet to a python structure, preferably a DataFrame, as Isaac suggests in his answer, it is also necessary to iterate the data to extract only the "students without…
-
0
votes1
answer45
viewsA: How to find only the distinct paths up to the specific directory?
Let’s say I know there’s a directory called vcf inside my /home, but I can’t remember where this one is and I want to find it: $ find ~/ -type d -name "vcf" Exit: /home/sidon/temp/vcf You can use it…
-
0
votes1
answer226
viewsA: Average frequency using dictionary
I don’t know if I understood it right, but if I had to count the words of a text I would use collections and, in the end, would mount the dictionary with the result, I will give an example…
-
0
votes1
answer151
viewsA: Pyvcf lib problem - Extract data from vcf files
scikit-allel "This package provides utilities for exploratory analysis of large-scale genetic variation data. It is based on scientific libraries Python numpy, scipy and others of general purpose."…
-
0
votes2
answers848
viewsA: Problem with balance of parentheses, in Python
In a free translation of that article in wikpedia (in English is strange) "Parentheses matching, Brace matching or Bracket matching refers to the feature called "syntax highlighting"that certain…
-
1
votes1
answer4919
viewsA: Comparing column values in dataframe pandas rows
The ideal would be that you show the content of the dataframes, it became difficult to understand the context, so I will try to give an example based on what I understood of your question, I will…
-
1
votes1
answer62
viewsA: Python3: Module csv has no Dictwriter Member
I made a small change to your code and it worked here, see below the versions I’m using: $ python --version Python 3.6.7 :: Anaconda, Inc. ~ $ python -c "import csv; print(csv.__version__)" 1.0 Now…
-
1
votes1
answer429
viewsA: Create a table with initial data in Django
You can create the table normally and then create a command to populate it at the time you want, as you said (in the comments) that the data will be "hardcoded", I’ll give a good example "simplão"…
-
0
votes1
answer515
viewsA: How to assign the PK of the logged-in user in Django to an FK in the model?
Although your question is not clear enough for me, I will try to answer with what I understand. You do not show your form definition, but what you need to do is delete the field usuario, so your…
-
1
votes1
answer286
viewsA: How to fire an automatic email through Django when you receive a new value in the database?
Use Django-model-utils pip install django-model-utils Add a field to make tracking in its model, and overrides the method save, your class would look like this: from model_utils import FieldTracker…
-
-2
votes3
answers2084
views -
1
votes1
answer355
viewsA: generate a pdf only with arguments passed by a Django form
You would have much more flexibility if you used the Forms of the own Django, ai Voce could continue using the templateview or even the formsviews, but I will consider in this answer what you are…
-
3
votes2
answers944
viewsA: How do I find a character pattern corresponding to a date in a text?
TL;DR Using regex: import re texto = ''' Data de fabricação: 20.02.2019 Validade: 30.12.2099 ''' print(re.findall('\d{2}\.\d{2}\.\d{4}',texto)) Output: ['20.02.2019', '30.12.2099'] See working on…
-
0
votes1
answer42
viewsA: How to show data in the template
In your example you are not treating the data that was sent to the template, based on your code I will create an example, but, to simplify, my data will be "hardcoded" instead of coming from a…
-
1
votes1
answer245
viewsA: Save . doc file in database with Django
Django provides the type Binaryfield to save binaries, Voce can set as follows: doc_file = models.BinaryField(blank=True) But watch carefully for what the documentation says (Highlighted part at…
-
0
votes2
answers2009
viewsA: PYTHON - FOR inside FOR
By the comments you need to "save" the Fields in variables for further treatment, so the suggestion is to store these Fields in a dictionary, actually in a list of dictionaries (a dictionary for…
-
0
votes2
answers766
viewsA: Iterate through multiple Xmls files with Python
Iterating on the structure of a path in your file system: import os path='/home/sidon/etc' for root, dirs, files in os.walk(path): for name in files: print(name) In the example above you are…
-
1
votes4
answers295
viewsA: Print null or non-null in Python array
Use Numpy You are constructing what you call the matrix through the lists of python, I have my doubts if Voce can call this matrix in the mathematical sense of the word. Using the numpy Voce you can…
-
2
votes2
answers1851
viewsA: How to assign a function to a button in Django Python
Since you are already programming in Django, you probably already know, but I’ll make it clear here: Django is called the MTV framework (Model-Template-View). The view (view) part usually inspects…
-
1
votes1
answer36
viewsA: How to leave Choices field with no default value
Alter MAO_DERROTA for: MAO_DERROTA = ( ('','..........'), ('Royal Flush', 'Royal Flush'), ('Straight Flush', 'Straight Flush'), ('Quadra', 'Quadra'), ('Full House', 'Full House'), ('Flush',…
-
1
votes1
answer34
viewsA: Django form for single key
I’m not sure I fully understood your context, but it seems that you already have the phones recorded in the bank and you want the user to type the phone as if it were a credential for entry into…
-
1
votes2
answers2545
viewsA: ORA-00907: right parenthesis not found
I don’t know Oracle, but his where has a right parentheses ')' that does not "house" with anyone, put in a terminal Qt-console (I think it works on ipython too) and navigate the line of code and the…
-
2
votes3
answers65
viewsA: How to join the score with the last word on the left?
Change the line: print("O percentual concluído até o momento é de:",(round((b*100),2)),"%") for: print("O percentual concluído até o momento é de:",str(round((b*100),2))+"%")…
-
2
votes3
answers2117
viewsA: Regular expression to return text between keys
TL;DR For this specific problem, you do not need regular expression, you can use find to build a Slice, see: print(str[str.find("{")+1:str.find(" }")]) dentro de uma string {dentro de outra} But if…
-
3
votes1
answer85
viewsA: Array always getting the same value [Loop in two matrices simultaneously]
From what I understand your "matrices" are common image matrices that have the format (n, n, 3) correct? and Oce wants to compare the occurrences of the RGB channels within them, right? Since you…
-
2
votes1
answer103
viewsA: Problem in python print
The split is the cause of the "problem", when using it Voce converts the string to a list, see an example: name = 'Foo' print(type(name)) <class 'str'> print(name) Foo name = name.split()…
-
3
votes1
answer213
viewsA: Code adaptation Fortran for python [Runtimewarning: overflow encountered in double_scalars]
Not a number (Nan) Your code is generating nan on the list you name x (I suggest you watch that video), and what is a nan? In a very objective and responsive way, Nan is the acronym for "Not a…
-
3
votes1
answer993
viewsA: Copy the value of a list variable to a python variable
In python when it comes to container variables (lists, dictionaries, etc) the idea is slightly different from other languages, when vc does var1 = [value1, value2..], var1 works as a kind of…
-
3
votes2
answers902
viewsA: Function Encode() and hash creation
Give "a few touches on the code" became vague, I will try to elucidate specifically your problem: the "b" in front of the object, indicates that this object is of type bytes, see the example below:…
-
0
votes2
answers69
viewsA: Find out if a timedelta object has any negative attribute
If I understand what you are asking I think your example does not work to detect if it has any negative "attribute", at least not in python3. Python converts everything to days and seconds, See the…
-
-1
votes2
answers379
viewsA: Recover List Written in Python File
TL;DL Use re.sub(), and split(), See the example below: import re ln = "['teste1', '27-12-18', '12/5/2015', 'Aberta']" # Removendo os caracteres indesejados ln = re.sub("\[|\]|'","",ln) #…
-
0
votes2
answers311
viewsA: Deploy Python project to Heroku with error
Interpreting the error message: You have the module: /app/djangosige/configs/__init__.py On line 3 of this file Voce makes an import from .settings import * That runs successfully, with the…
-
0
votes1
answer562
viewsA: Stacked dice. How to work this on pandas?
Use Groupby df = pd.DataFrame({'Time': ['Alpha', 'Alpha', 'Beta', 'Beta', 'Gama', 'Delta', 'Gama', 'Gama', 'Alpha', 'Delta', 'Delta', 'Alpha'], 'Rank': [2, 1, 3, 2, 3, 1, 4, 1, 2, 4, 1, 2], 'Ano':…
-
2
votes1
answer110
viewsA: Pass a given sequence of times in Python 3
Set is not manageable. In your question Voce uses the type set to define the sequence, in python this type is a data structure that represents a sequence denoting a mathematical set, i.e., Voce…
-
11
votes2
answers15237
viewsA: How to remove accent in Python?
Use unidecode: $ pip install unidecode from unidecode import unidecode print(unidecode('Arrepieí')) Arrepiei str1 = 'café' print(unidecode(str1)) cafe…
-
-1
votes3
answers122
viewsA: Iteration using "while"
TL;DR Try it like this: def count_f(registros): faltas, i = 0, 0 while i < len(registros): if registros[i] == 'f': faltas += 1 i += 1 return faltas while True: registros = input() if registros ==…
-
2
votes2
answers860
viewsA: Lambda in Python - Doubt
Lambda are one-line functions (usually called once). They are known as Anonimas functions in some languages. You may want to use both when you don’t need to use a function more than once in a…
-
0
votes2
answers70
viewsA: Override de Propriedade
[TL;DR] Look at this strategy: class Foo(object): def __init__(self): self._foo = None @property def foo(self): return self._foo @foo.setter def foo(self, value): self._foo = value class Bar(Foo):…