Posts by jsbueno • 30,668 points
811 posts
-
5
votes3
answers326
viewsA: Doubt with variables
So - as it was repeated above, Python is dynamically typed. In language, this works because in fact, all in language is an object - and is an object derived from "Object". Now, over the years,…
-
3
votes1
answer95
viewsA: Parallelize with just one core?
As you yourself suspect, no, there will be no performance increase in this case. If the machine has hyperthreading - i.e.: two "visible" colors but only one physical core in that case, it would…
-
1
votes1
answer39
viewsA: Window processing of post-processing frame
The most practical way to get screenshots is with the "pyautogui package". Just install pyautogui in your Python environment and then: import pyautogui image = pyautogui.screenshot() This returns a…
-
6
votes1
answer1281
viewsA: How to delete an entry from a Python file without having to read the entire file?
Yes - you need to read the whole file, change what you want in memory, and save it again. This is the recommended practice. The main reason is that it is an unstructured text file: that is, each…
-
3
votes1
answer867
viewsA: Correct answer but Uri does not accept
The code looks good - if it works for examples you did, it should work for any case. The problem may be that although the statement says nothing, there may be large numbers that do not fit into a…
-
1
votes1
answer197
viewsA: Cassandra installation error - DRIVER in python
This is an encoding error - unfortunately, 25 years after the world has standardized an accents encoding that accepts characters from all over the world - utf-8, microsoft with windows continues to…
-
4
votes2
answers778
viewsA: Doubt about the Slice function
The call built-in slice Python is not really a function - like some other Python calls, it’s actually a class that creates the object slice. The chances of you needing to use slicedirectly are quite…
-
1
votes1
answer742
viewsA: Cannot import X
That’s right - it’s a classic case of "circular imports". Python tries to do the most intuitive thing possible with imports, but it has its limits. tl;dr: Your module main_server just needs the name…
-
0
votes2
answers630
viewsA: How can I create sequence and math series functions in python?
Are two forms: 1) the easiest - is not trying to use mathematical notation, and translate everything from mathematical notation to the language you are using, in this case Python (If you think about…
-
0
votes2
answers690
viewsA: Submit form in python
You have to send the post with the data to the destination page of the form, not to the page that generates the form in HTML. The URL for this page is in the "action" field of the tag form. In that…
-
4
votes1
answer9018
viewsA: How to leave code in language format within word
It has an interesting path, using unusual tools: The Python language follows one of the principles of the Unix philosophy where it is better to have several small tools that do one thing and do one…
-
1
votes1
answer1300
viewsA: Exchange of information between Python classes
A major problem with the above code is that it is not using "classes" - it is declaring functions in the body of a class - the way it is, they nay are "methods", are functions even, who know nothing…
-
3
votes2
answers394
viewsA: Meaning of these nomenclatures in Python and other languages, if the names are universal
The meanings of these terms are universal in computer science. Eventually some language may have other meanings for some of them, but it is still "allowed" to use them within the original form. The…
-
1
votes1
answer70
viewsA: How to pass Keywords Arguments in python in a simpler way?
Python is extremely flexible as the way of both passing and receiving function arguments. for what you want, the best thing seems to be to make the desired call (in the case of the example, the…
-
3
votes1
answer822
viewsA: Python CSV How to rewrite only one line of the file?
As I wrote in the comment - if you have a text file with data, and will want to keep changing this data, provavelemtne you are using the wrong solution. Using a "self-contained" database in Python…
-
3
votes2
answers9324
viewsA: Subtract days from an input date with javascript
tl;dr: The right thing is something like: inicial = new Date(ano, mes, dia); milissegundos_por_dia = 1000 * 60 * 60 * 24; data_final = new Date(inicial.getTime() + dias * milissegundos_por_dia);…
-
0
votes1
answer455
viewsA: Error: unhashable type: dict_keys, how to resolve?
With frozenset should work yes - the correct would be to do on these lines: chaves = envolvimentoNomesColunas.keys() valores = envolvimentoNomesColunas.values() moving on to chaves =…
-
1
votes3
answers229
viewsA: Import another debris module from another using Libreoffice macros
Wait - You did not get an error message on your import - maybe you’re just not familiar with Python The function of the other module will be available as Mod_B.getMovimentoGeral after a import…
-
0
votes2
answers111
viewsA: Separate input value and expected value in pytest.mark.parametrize
When you use paramtrize, the second parameter is a sequence (which can be a list), ond each element and another sequence containing an item for each function parameter. You want the sequence (1, 0,…
-
1
votes1
answer3056
viewsA: "list indices must be integers or Slices, not Nonetype"
The error message you have is very clear: when trying to access the list espaco, the variable jogada that you use as index contains None instead of a whole. So just follow where you call this…
-
1
votes3
answers1051
viewsA: Identify a numerical sequence in a text file
You can use regular expressions for this. A regular expression that finds all sequences that can contain digits, "-" and "." with at least 17 elements - it would be possible to refine the expression…
-
2
votes1
answer448
viewsA: python cannot use break
The break has limited utility for cases like these: it comes out of a single loop in the same function. You are creating the game with a good separation of what does what, but apparently the…
-
4
votes2
answers1259
viewsA: What are the function of each string prefix in Python?
So - come on - when I say Python, I’m talking about Python3; let’s assume that Python2 is a thing of the past. (I speak of the strings in Python2, but it is just one of the points where there has…
-
1
votes1
answer29
viewsA: Naïve Bayes execution error using Spark
The error message found indicates that within the library, a value was expected to contain ":" when it does not. (The message is not explicit, because really the code did not expect this, but look…
-
3
votes1
answer5801
viewsA: How to Create a communication between two clients via server using socket
this is the moment you find out because people don’t do that ordinarily. sending a test message via sockets is simple - with code like the above. have a complete implementation of a chat depends on…
-
3
votes2
answers1152
viewsA: Square Matrix in Python 3
The method rjust only exists to precisely insert spaces at the beginning of a line. And you’re calling the "strip", which removes spaces in an empty string, passed to the "end", which does nothing.…
-
1
votes1
answer1599
viewsA: List manipulation with dictionary inside a Python loop
Your algorithm would work. The problem there would be to just create your "new list" previously, with a list for each position in the original list (and hit the == in the if). But you have another…
-
0
votes2
answers1225
viewsA: How to check if the txt file has a blank space on the last line
A simple way, since you read all the previous files as a single string, is to use the method strip that removes all space characters from the beginning and the end of the string. With this, blank…
-
0
votes1
answer246
viewsA: Python binary search giving Wrong Answer in Moj
At first, the only problem I’m seeing there is that you don’t test if a number isn’t found - if the number doesn’t exist, it will recur every time. Your program will eventually print the "-1" on the…
-
21
votes1
answer1876
viewsA: What is Global Interpreter Lock (GIL)?
What exactly is GIL? Global Interpreter Lock is a flag that exists in the Python interpreter, and causes only one bytecode sequence in the Python VM to be executed at a time. The initial reason for…
-
0
votes2
answers335
viewsA: How to add multiple dictionaries using pickle to save to txt
If you don’t read the original file, it will always write a new dictionary. You have to, at the beginning of the execution of your program, read the file that is on the disk to a dictionary in…
-
2
votes2
answers875
viewsA: Decode data in Base64
About Base64 has nothing to do with "16 bits". As the name implies, your message is broken into 64-character representative pieces, i.e.: 6 bits. Using this subset of the 256-character (8-bit) total…
-
7
votes3
answers5645
viewsA: What is the purpose of declaring a function within a function?
It has some possible uses. The main ones are these two: function factory That might be the main use. Since functions are first-class objects in Python, each time a function containing others is…
-
2
votes2
answers2468
viewsA: Doubt about Keypress in Pygame
If you catch the KEYDOWN as it is doing, it will repeat yes, but not uniformly. The ideal is to use pygame.key.get_pressed() But before that - do you notice that you have some repeated code on your…
-
1
votes1
answer192
viewsA: How to suspend a command without disturbing active commands
So - "normal" programs, at this level of learning always run with one instruction after another. If you want one part of your code to do one thing, while another part of your code does another, you…
-
2
votes1
answer502
viewsA: How to organize pygame code correctly?
Boy What you need is object orientation. In the good way, not in the "mandatory" way that is Java, nor in the way "hidden under the semantics of prototyping" that is in Javascript. You need less:…
-
2
votes1
answer487
viewsA: Why make use of Python exceptions using raise?
Why climb an exception? This is identical to the last question, let’s contextualize things first. The programmer should not do everything so that an exception does not occur? Actually, no. The…
-
9
votes1
answer1010
viewsA: Use from module import* vs use import module in python 3
Never use from module import *. The "concision" in this case is an illusion. The * removes a level of determism to your code, making some static correction check features impossible (for example, if…
-
8
votes1
answer114
viewsA: Is it good practice to perform Imports within methods?
Let’s go in pieces. The style guide used by most people, the document called PEP-8, recommends that imports be in the module header. BUT you have to keep in mind that they are style recommendations…
-
14
votes3
answers883
viewsA: How to create operators in Python?
There are some factors involved there - in short: it may be "possible" to create some form of "++" and "-" - but they will have limitations, and this particular operator violates one of the…
-
0
votes1
answer93
viewsA: I am unable to use get_rect with Convert/convert_alpha and subsurface
If your problem is just height and width, simply create a rectangle with x and y = 0 and width and height = self. _tile_size - no need to create a rectangle based on the disk image read: self.rect =…
-
3
votes1
answer1550
viewsA: Communication between two programs in PYTHON
So - this can range from "easy" to "complicated" - especially if you’re going to put it into production and want to have some security of who calls what. I will try to list some options and give the…
-
3
votes1
answer37
viewsA: What class should the text class inherit?
There is no "recipe" from which class to inherit. You are the one who knows what your class will have to "know" do, and whether it is appropriate that she inherit from some other class or not. What…
-
0
votes2
answers1020
viewsA: How to pass an integer file to a C vector?
The problem of your question is caused by this line, within the main function: int p[qtd]; The point is that C cannot dynamically calculate the size of vectors - you have to put a fixed size to…
-
5
votes2
answers254
viewsA: "Deep Copy" without importing the "copy" module?
The copy module and its main functions copy.copy and copy.deepcopy are very useful, and should be used without restrictions whenever you need their functionalities. An interesting thing, both from…
-
4
votes2
answers461
viewsA: Do I need to import a module several times?
If you have in your file "classes.py" something like: import pygame class Classe1(...): ... and then in the main file: from classes import * Both the classes defined, and the "pygame" that was…
-
1
votes1
answer224
viewsA: Why does the variable x of the double type always print the same WRONG value in scientific notation?
So - as it is in the comments: these functions printf and scanf has not how to know what type of argument you are passing to them from the declared type of the variable. They just "guess" what kind…
-
1
votes2
answers920
viewsA: Turn string into operator
doing "right" is something that depends on how much functionality you want, and it’s something that, if you want to read parentheses for example, can get really complicated. But to keep it simple,…
-
3
votes2
answers943
viewsA: Use of if __name__=='__main__'. Why is the class not instantiated?
Split: Your block class with the class declaration creates the class yes - does not create a class instance. In Python this would be done using the class name as if it were a function call:…
-
3
votes1
answer266
viewsA: What would the conversion of this algorithm from C to Python look like
The algorithm is straightforward in Python, without any changes - however, the composition of the final value, which has to be binary, has to take some precautions. To start, of course, the buffer…