Posts by jsbueno • 30,668 points
811 posts
-
0
votes1
answer181
viewsA: Empty columns of a spreadsheet when using pandas read()
On the spreadsheet - it logically contains some data in these columns - they can be simple blank characters in some cell (column 9, on row 3 seems to be an indiciative of one of these). Simply…
-
1
votes1
answer556
viewsA: How to add text to a Qplaintextedit(PYQT5)
The Widget PlainTextEdit has associated with it an object of the type QTextDocument - is this object that has the methods and attributes both to read the user’s typed content, or to change the…
-
1
votes1
answer389
viewsA: Read and write binary files using STRUCT
The struct module works well, but can be a bit boring sometimes. In particular, it expects a data formatting letter to each parameter that will write, has no arrays - that is, you need to pass, in…
-
2
votes1
answer797
viewsA: Attributeerror: 'module' Object has no attribute 'exceptions'
You should have a file, in your workbook, called "requests.py" - Python is finding this and trying to import it instead of the library requests installed with the PIP. The solution is to rename your…
-
1
votes1
answer1859
viewsA: doubt installing chatterbot in windows
The installer did not find a compiled binary version of one of the modules that is Chatterbot’s prerequisite, and was trying to compile it locally. At this point, he did not find the tools and…
-
1
votes1
answer546
viewsA: SQLITE query returning value outside of query rule
The logic problem you have is not Python, but SQL - your consultation is: SELECT * FROM porta WHERE qtd_ciclos = (SELECT MIN(qtd_ciclos) FROM porta WHERE tamanho='{}' AND habilitado='{}' AND…
-
1
votes2
answers750
viewsA: Convert a byte variable into a string?
In Python, the values that "are inside" the variables (technically "associated with names") are all objects - just as the literals typed directly in the program are also objects. Literals are, for…
-
4
votes1
answer1308
viewsA: python game of checkers
To know about threatened pieces, it has to be a check that looks, for each piece, all the diagonals in which it is, and if there are any "back" pieces. As you are taking into account the checkers,…
-
5
votes1
answer554
viewsA: What does the f = Fernet(key) code represent when using the cryptography.Fernet library?
Without looking at the library documentation you can already say that what it does is instantiate an object - in Python, as a rule, names in Camelcase are class names - if you "call" a class, create…
-
1
votes1
answer618
viewsA: How to assign a css class in Django forms
Well, you haven’t put any code from your templates there - if you want a CSS class in form of HTML, it is in the templates that you need to manually - the classes of django.forms even has rendering…
-
3
votes2
answers544
viewsA: Yellow comment on Pycharm when using the term "all"
This has nothing to do with the language - (source code has no "colors" is just text anyway) - and yes, with the tool you are using - in this case Pycharm. Pycharm is an IDE, and Ides provide…
-
2
votes1
answer737
viewsA: Plot function in PYTHON or MATLAB
"Functions" are one of the fundamental concepts of modern programming languages - and derive precisely from the concept of functions in mathematics. Python is a robust programming language that can…
-
3
votes2
answers39
viewsA: Dictionaries dependent on other dictionaries
This is a typical recursive problem - i.e., to each element to be explored, the key with the dependencies should be listed again, and for each new dependency, list the dependencies of the same. To…
-
4
votes1
answer44
viewsA: Django model mapping problem
The "Enterprise" class does not yet exist when the class body "Production" is processed - it is no "problem", it is simply logical. Django circumvents this by enabling Foreignkey classes to be…
-
0
votes2
answers2625
views -
3
votes1
answer562
viewsA: Undefined variable with import python
The problem will happen if it is like - and no matter if it is in the same file or not: import cls_usuario class Administrador(cls_usuario.Usuario): def __init__(self, id_administrador):…
python-3.xanswered jsbueno 30,668 -
1
votes1
answer404
viewsA: Python with socket communication between computers
There’s a reason why they invented HTTP over communication pr sockets, and then XMLRPC and JSONRPC over HTTP - sckets provide low-level communication - you have to worry about a lot of details,…
-
0
votes2
answers80
viewsA: exec with n does not work
Yes - when the Python compiler reads the string that goes inside the vailable a, he already plays the \n to be a line change - then the code exec will compile at that point: a = ''' open('test.txt',…
-
2
votes3
answers1730
viewsA: Remove quotes in lines from csv file
If your file is really asism, with quotes around the entire line, the file is incorrect - no ready function will be able to read the file - The correct for a CSV file is to have only the values,…
-
0
votes2
answers32
viewsA: Program performance in order of module loading
In fact, there is no absolute answer, and it depends on the profile of its application. Most often it is best to import at the beginning of the module - even by a language style convention. A Python…
-
4
votes1
answer168
viewsA: How to update some elements in SET in Python?
A set has the same question as dictionary keys, as I explained in your another issue - there is no atomic operation to exchange an element. In this case, you really need to call two methods: one to…
-
0
votes1
answer125
viewsA: Help with Python function
If you’re always going to compare values exact age and year, the simplest solution is to use a dictionary, where the keys are the values you want to compare, in the form of a tuple (simply separate…
-
9
votes2
answers2343
viewsA: How to change the value of the key in a Python dictionary?
There is no Rename, but it is possible to store the value in a new key and delete the old one in a single operation if the method is used pop of dictionaries: RE2["Data de Nascimento"] =…
-
3
votes5
answers842
viewsA: Find a file type within several folders and save the hierarchy
Starting from Python 3.5 there is a new package in the standard Python library called pathlib. In it, the class Path allows various types of operation with directories or files, including shortcuts…
-
0
votes2
answers452
viewsA: How to get a template that’s in another app on Django
Just inherit from "base.html" in another app, doing nothing else. All "template" folders of all Jango apps are consolidated into a single namespace. In other words - when it comes to importing,…
-
1
votes1
answer99
viewsA: How do you fix this code?
Yes, the event KeyPress is called whenever a key is pressed - and in general the operating system will have an automatic "auto-repeat": i.e., if the user does not release the key, several events of…
-
1
votes1
answer75
viewsA: How to use the Time module together with the Sys module
Instead of sys.stdout.write, simply use the command print, but pass the optional parameter flush with the value of True. For example: print(f'{cores["vermelho"]}JO{cores["fim"]}', end='',…
-
1
votes3
answers4131
viewsA: Join columns in python?
Rather than simply concatenating column data into a Python list, where you would have timestamps,. In this case, it is best to use the method apply - it can call a function row by row from your…
-
6
votes1
answer49
viewsA: What is the lifetime of a class instance and a "module instance"?
TL;DR: Classes and modules exist throughout the life of the process, from the moment the module is first imported (in the case of classes, the existing classes within the modules). The attributes of…
-
3
votes1
answer712
viewsA: Python Glossary, library synonymous with package? Module synonymous with class?
This terminology is not always used strictly everywhere - although they have a common meaning, there are differences: Class (class) - is the most distinct term from the others: class is a single…
-
2
votes1
answer173
viewsA: while (Cin >> str) An equivalent code in Python
In Python, the default entry is visible as an open text file in the object sys.stdin If the file was redirected from another, the end of file will be detected on sys.stdin - without redirecting, as…
-
1
votes1
answer34
viewsA: How to divide lines by lines of two different df and store in a third?
If you specify the columns you want to split (even if each dataframe has only one column), just use the operator / ). The result is a Pandas.Series, which can be used as a column in a dataframe: In…
-
2
votes1
answer50
viewsA: Why is it wrong for the file to be closed if in each iteration it should open again?
First: Opening and closing the file in each interaction is an incorrect way to use files anyway. Second, your problem is probably occurring because of the line you do arq.close() within the for -…
-
11
votes2
answers2537
viewsA: When should I use a Property instead of a Python attribute?
Yes - you should use a property only - and only if - access to the attribute involves something that will be computed live, and is more practical and readable to do this with an assignment (the…
-
1
votes1
answer30
viewsA: Spawn of midi python notes
just read the notes from a midi file - To do this without having to implement all the reading of an arqivo midi to extract the notes yourself, you need to have a midi library for this - The first…
-
1
votes1
answer363
viewsA: Error initializing PYGAME
Pygame is not meant to "chat" with Tkinter, where Turtle runs - its program is Frankish in its current state, creating the two interfaces - in theory, there should be no conflicts - Each library…
-
2
votes4
answers17442
views -
3
votes1
answer396
viewsA: How to calculate the factorial of a list of integers using thread?
Your program is well under way - the problem is, as you can see above, you didn’t bother to put the results of the function back together - you start the thread, and you don’t even try to get the…
-
0
votes1
answer871
viewsA: how to upload python files?
Normally you would use the requests.post - however, that’s the easy part. The point is that these pages in general do not simply have an HTML form, with a field of the type <input type="file"…
-
1
votes1
answer581
viewsA: Flash text on Tkinter / Side effect
The basic idea is correct - the way to keep something lively on Tkinter, even blinking text, is to have a function or method that is called by a timer like the one you do on janela.after. The…
-
3
votes3
answers69
viewsA: SQL syntax error in a Flask application
The fact that you can create a string of arbitrary size in Python, with """, mean that you can put as many SQL commands in there and have them executed as if they had been typed right into the…
-
2
votes1
answer192
viewsA: Run language file c in Python sricpt
Python’s ctypes module is a way of calling functions in native code - including functions written in C - from Python. Its use is not trivial, as is often the case with other Python features…
-
1
votes1
answer191
viewsA: Request Reverse Post Office API
Try a look at the wrapper of the Olist-maintained Post API - it’s a pretty cool design that uses a lot of mail stuff. If you don’t want to use the whole project, you can explore the code and see how…
-
1
votes1
answer902
viewsA: Pattern Recognition in Python
Pattern recognition is not something trivial - Unless the course is about this, and in this case you must be learning about classifiers, machine learning and the specific algorithms, there is no…
-
3
votes4
answers461
viewsA: How can a group of parameters be required if at least one of them is informed?
Of course the language has no way to bring ready all imaginable uses possible - either for the list of parameters, or for other things. But it includes enough mechanisms for you to implement it - in…
-
2
votes1
answer490
viewsA: Convert function arguments to string
If you have no need to distinguish between arguments, you can use the * in the declaration of the parameters of a function - this indicates that the function indicates a variable number of anonymous…
-
4
votes2
answers214
viewsA: How to create all possible combinations from a string?
You are doing something else wrong - although the number of combinations is large, in my system itertools.product generated the 400,000+ possible combinations in this case in less than 0.1 second.…
-
1
votes1
answer485
viewsA: How to capture parameters of the object that called an event in Tkinter?
A Tkinter "command" response call does not carry any information of what was clicked - the function is called without any parameter, and therefore has no information about how or why it was called.…
-
2
votes3
answers1736
viewsA: Find word in python txt file
The operator in Python has different behaviors if the second operand (which comes after the in) for a str or bytes, and if it’s another kind of sequence. In case you do a in b and both are strings,…
-
7
votes2
answers707
viewsA: Are class methods recreated for each instance in Python?
tl;dr: Methods are temporary objects - they are actually created each time they are accessed, with the aggregation of the attribute "self" the function that is declared in the class. That is: a…