Posts by jsbueno • 30,668 points
811 posts
-
1
votes1
answer1245
viewsA: How to create a CSV file via Python by keeping the decimal separator in the same place?
Your biggest problem in the case is Excel and has nothing to do with Python - he is assuming that the "locality" (localization) of his CSV is in "Brazilian Portuguese", and, in that locality, the…
-
4
votes1
answer74
viewsA: Mosaicing in Python or C++?
Doing it in C++ won’t make it much faster. This is because although Python is rather a slow language, all the calls that actually consume resources in this algorithm (and other similar ones), are…
-
0
votes2
answers258
viewsA: if statement - use of parentheses
There is no gain or loss in using extra parentheses in expressions like if and while. They are not mandatory in the language precisely to simplify the reading of the expressions. o : at the end of…
-
3
votes3
answers1053
viewsA: Problems in Try (Python)
It is not possible try continue on the next line, after an error, for the simple reason that the language has no way of guessing what to do after an error. The programmer describes the behavior…
-
4
votes1
answer3049
viewsA: Increases font size in python and how does the number of decimals decrease?
font size Increasing the font size is not possible for terminal output programs (with print): This is part of your terminal settings - which is a program that your Python program, and the Python…
-
5
votes1
answer704
viewsA: How does Python handle common functions and internal Python functions?
Both types of function are identical and treated in the same way: After created in memory of the Python application, that is, since the code that creates the function - tando one with def as one…
-
4
votes1
answer162
viewsA: Doubts Python Matrices
The problem is that Python doesn’t have native types of "matrix" - in general, in small programs, people invent a kind of matrix - and programs that will do stuff muting with matrices, can use the…
-
2
votes1
answer832
viewsA: How to update lines with open() in python?
The very call to the method write can update text files - what happens is that if the file content is "text", it is virtually impossible to change its content in a way that is useful - it is best to…
-
2
votes1
answer78
viewsA: program that puts people on a list
One list (list) in Python does not work as the vectors or "arrays" are used in C and other languages. In particular, it is created empty (or from another sequence) - and you add new elements as you…
-
17
votes2
answers653
viewsA: How does Python treat the "Yield" command internally?
Understanding what’s going on The yield internally does a lot of things: For starters: the fact of a function had the keyword yield anywhere in her body causes her to be treated differently by…
-
7
votes2
answers987
viewsA: How to use one Model Class values in another in Django?
This is a legal case to use a property - when for the code that will use its instances, there will be simply reading the attribute, but in the class, a method is executed automatically. Note that…
-
3
votes1
answer678
viewsA: How to print PDF’S with python by checking if the print was successful?
As it is in my answer on How to print a txt file in Python , printing is not a feature of any language, and yes, it depends on interaction with the operating system. I think a good way, regardless…
-
4
votes1
answer995
viewsA: How to make Python 3.7 recognize the libraries installed in Python 3.6?
You cannot use the same libraries - the ones that are compiled for Python 3.6 will only work in that version. However, it is easy to install the same libraries again for Python 3.7 - You didn’t say…
-
13
votes1
answer4099
viewsA: Definition and use of @Property
A little context before: traditionally, scholarly texts on object orientation talk about which attributes and methods have to be separated into "public" and "private" (and, some languages put a few…
-
3
votes2
answers214
viewsA: syntax error in python
You didn’t write a Python program. You copied everything that was on the interactive interpreter screen, and you’re trying to run it like a program. Although the windows are similar, they are…
-
0
votes1
answer85
viewsA: Error running Python test 3.6.7
Are you sure this test failure is from this test function? Why doesn’t she compare this - and the assert error message actually shows a list populated with the names read - which should be the…
-
5
votes1
answer511
viewsA: how to import classes referencing each other in python?
First - you are confusing "class" with "modules". In Java, there is a language specificity and public classes must be the only public class in a file of the same name. This has nothing to do with…
-
3
votes2
answers334
viewsA: Return the index of a row with the min function in Python
The for in Python is always a for each: that is, it will always go through the elements of a sequence, in case its facesDetectadas, and not, as is necessary in most other languages, for which will…
-
5
votes1
answer5223
viewsA: How to manipulate CSV data in python?
CSV files are always read line by line. However, unless they are really too large, the data fits all in memory (if it doesn’t fit, a specialized system is required - even the Pandas library depends…
-
7
votes5
answers9012
viewsA: How to replace more than one character in the replace method in Python 3?
TL;DR: import re ... novo_texto = re.sub(r"\W", texto_original, "") Full answer: The "replace" can only exchange a single string of text for another. For more complex text operations, the so-called…
-
6
votes2
answers5035
viewsA: What is the range() function in Python for?
In Python 3, range, despite being used as a function, including the initial examples of tutorials in Python, is not a function. It is a class: In [1]: teste = range(10) In [2]: type(teste) Out[2]:…
-
1
votes2
answers204
viewsA: Is there any way to nest one for N times?
Usually, if you have an algorithm that will actually need an arbitrary number of loops inside each other, you use just recursive functions. You place a single loop in the recursive function - and,…
-
3
votes2
answers432
viewsA: How to compare two identical`strings, but different encoded strings?
Strings are not "equal" - if one is with all non-ASCII characters encoded with "%XX", it has to be decoded before. The standard library has the function urllib.parse.unquote which can transform…
-
8
votes1
answer1815
viewsA: Differences between list, tuple and set
There are three different data structures - at both the use and implementation level - and each of them can serve a better purpose. (Note - in the text below I end up using alternately the names in…
-
2
votes2
answers323
viewsA: Python-based web Scrapping does not provide complete html page information
Page information is populated by Javascript code that runs after the key is loaded. This code makes the requests in real time to the various servers, and etc... With normal web-Scrapping…
-
2
votes1
answer187
viewsA: Different global variables that when one is changed change the value at all
You’re missing some concepts of data structures there, and your program gets confused. I’ll try to give you some tips, but it’s important that you take a break and digest it well - preferably by…
-
3
votes1
answer1861
viewsA: How to solve the None problem in PYTHON
"None" only appears because you, in the last line, call the function bissexto, and prints the return value of the same. Since she doesn’t have a command return explicit, it returns None, and its…
-
2
votes1
answer139
viewsA: Error with date time
Whenever the mistake TypeError ... object is not subscriptable appears is why the code is trying to use the operator [ ] on an object that is not a sequence or a map. And in your case, on the line…
-
5
votes2
answers63
viewsA: Function of free() in abstract types
I believe there are more problems in this code - without seeing the function regAluno you can’t tell exactly what (all of a sudden it works). But about the function free: she brand name the memory…
-
1
votes5
answers714
viewsA: I want to turn a text into a list of dictionaries
You saved the Python text representation of your objects in the file. It is not a recommended format, because not always the representation (repr) of an object will be able to reconstruct it. In the…
-
1
votes1
answer95
viewsA: Run Videos with parameters
Will call her os.startfile has exactly the same effect as you clicking the file through the graphical interface. That is: the operating system will open the associated program first with that type…
-
1
votes2
answers552
viewsA: Changing character values in C
This is because you are just "going forward" - your code has no prediction to go back to the letter 'a' after passing the 'z'. For the C language, characters and numbers between -128 and +127 are…
-
0
votes3
answers606
views -
5
votes3
answers275
viewsA: How to configure pygame in English?
If the symbols appear as ? it simply means the source file you are using - smbfont.ttf does not include these -symbols and they are replaced by "?". This is a very common problem with low quality…
-
5
votes1
answer62
viewsA: This is the iteration of a nested loop
I would like to get only the desired iteration without having to generate from start to the necessary point If you need this, then you don’t need a loop, or generators, or anything - just a…
-
4
votes1
answer104
viewsA: Function . split() buging the output of the string in python2, how to solve?
Your code is not making very conventional calls, and there are more consistent and short ways to do what you want. The problem you are having is that you are using the method .strip strings, to…
-
3
votes1
answer229
viewsA: How to enable Basic Authentication in Nginx for an Angular path?
You do not have to do this way. The part of the Urls after the character # is never passed to the server. - This is in the specification of the Urls themselves. Angular uses this feature precisely…
-
0
votes1
answer63
viewsA: Strange error in C
As you can see in the video itself, the value of i is overwritten with garbage before the line with the if that you put in question - and yes in the very line that contains if(fgets(c, 250,…
-
1
votes2
answers162
viewsA: Identify zero sequences in a csv file using python
The first thing to keep in mind is that: a CSV file is not "modifiable" - your program will have to generate another CSV file, with the same template, and the most entered data. In your example it…
-
6
votes3
answers1193
viewsA: Python 3 number rounding
suggestion 1 a good practice in such cases, if the accuracy is not too critical is to let Python store the value of the accounts as they are made, without worrying about that value - and, just at…
python-3.xanswered jsbueno 30,668 -
2
votes1
answer341
viewsA: Set timestamp field to accept value 0000-00-00 00:00:00
Well - that’s not a valid timestamp, is it? There’s no year 0 in our calendar - it’s 1A.C and then year 1 D.C. - the date and time representations in this format don’t account for those dates. The…
-
3
votes1
answer273
viewsA: Cancel button on a timer
Tem como fazer o timer continuar - "Having how, has". Only this ceases to be a simple program like what you are doing, and above all, violates the expected way of running programs through the…
-
2
votes1
answer77
viewsA: separate special characters
Yeah, but it’s not "split" related. It is possible to convert the whole string to lower case, and use the normalize function of the module unicodedata, as you used, to separate accents and letters…
-
2
votes2
answers856
viewsA: Sort lists in python dictionaries
It has - but it has to understand the possible steps before it can do something like this. The method sort of the lists (or the function sorted) accept as an optional parameter a "sort key"…
-
3
votes3
answers2117
viewsA: Regular expression to return text between keys
Although it’s probably possible to do this with regular expressions, maybe it’s not the best way to do it - Regular expressions are a language part of the "host" language - and are actually…
-
7
votes2
answers618
viewsA: Compare Hash of two files in Python
First - you are comparing file names - the call to update in Hashlib classes does not open files alone - it expects objects of type "bytes" (and that is the reason for the error message, you are…
-
6
votes1
answer161
viewsA: Why does 2*i*i tend to be faster than 2*(i*i) when i is integer?
"You already know, but it doesn’t hurt to repeat" if you think you need optimizations at this level in a chunk of Python code, you are writing this chunk of code in the language wrong (or any other…
-
4
votes2
answers1580
viewsA: How to assign values to an undefined amount of python variables?
In general, if you don’t have exactly one value for each variable, that is, if the variables will have the same functionality and save elements of a sequence, then the best thing is to do this: save…
-
1
votes1
answer1818
viewsA: Error presented in vscode when trying to run a Python code
This type of error happens when the operating system is trying to directly run a Python file, but does not have an indicator that it is a Python file. Under Unix and Linux, unlike Windows, the file…
-
1
votes1
answer48
viewsA: Pass Descriptor by parameter to another Descriptor
The instance of a Descriptor is a property of the class of the object that uses the Descriptors. This means that if you are creating a Descriptor to store an individual value in each instance, that…