Posts by jsbueno • 30,668 points
811 posts
-
0
votes1
answer58
viewsA: Pick numbers with decimals from a xlsx spreadsheet and convert in hours in python
When you do the math, you can see that the number "25.05555556" which corresponds to "601:20" hours is expressed in days. The class datetime.timedelta do Python can accept entry in days, such as…
-
0
votes1
answer66
viewsA: Unboundlocalerror: local variable 'res' referenced before assignment - raster image scanning error (like numpy array)
This error appears when trying to use a variable that has not yet been set. Looking at the code of your function, you can see that the "res" is assigned within a condition (if) - and its value is…
-
8
votes1
answer198
viewsA: How to put emoji in a string?
in Python from "3" - everything internally is Unicode. Unicode is translated by an "encoding' when data is sent to an API - in general they all work with "utf-8". Utf-8 is a specific encoding that…
-
5
votes2
answers202
viewsA: How to prevent a class from being instantiated in Python?
If for some reason you don’t want to put a simple comparison on __init__ how are you in reply from @jfaccioni , you can create a method __init_subclass__ in the base class that over-write an…
-
2
votes1
answer39
viewsA: How do I change the import location of the modules in python?
You have to learn about "virtual Nvironments": they are a resource used by the language for each project to have its own libraries, without any system conflict issues. So, if you have a game that…
-
1
votes1
answer45
viewsA: Unzip. corrupted zip with python
if you have another program that can open the zip, the best thing to do is to unpack elsewhere and recreate the zip; The work of investigating that broke with the Python zipfile when opening these…
-
1
votes1
answer47
viewsA: How to limit the number of lines writing CSV Python?
The function enumerate is applied to the iterator going to the last part of a command for - and what it does is, for each item, return not only the item, but its position in the iteration - so it…
-
0
votes1
answer50
viewsA: How to call a function by a parameter using argparse?
All Argparser does is read the command line parameters according to the specification you mount when calling the .add_argument and return an object that has the values of the past options, when you…
-
3
votes1
answer76
viewsA: How to print in the same line in python?
The terminal seen by Python and other languages is always a set of lines from top to bottom - so if you have information that will be distributed in multiple rows, in parallel with information that…
-
2
votes2
answers33
viewsA: How can I create update function in colab without restarting its kernel?
The "Reload" function of importlib can force the module to be re-executed, and then the Python process of your Kernel will have the new function. The problem is that importlib.reload alone always…
-
3
votes2
answers75
viewsA: Loop two functions at the same time
The initial idea of threading is very simple - and for what you want to do there: two unrelated I/O tasks, each in your thread, is perhaps one of the scenarios where it is simpler to maintain. In…
-
2
votes1
answer39
viewsA: Virtualenv python between Win/Linux machines
"virtualenv" should not be included in GIT versioned files. The libraries and modules that are installed for a project to work on virtualenv are always dependent on the operating system and…
-
0
votes1
answer116
viewsA: When I open the Python program directly on CMD, it simply closes
the point is that the program opens the cmd along with it. When it closes, the program ends, and the terminal where it was running ends together. The way to solve this is to include a input() blank…
-
0
votes3
answers84
viewsA: Dataframe Pandas - How to use a previous value other than NA for calculation
Not using "apply" is inefficient - basically you have to look at the cell-by-cell content of the column, going up from "3". You can use math.isnan to test if the value is nan. A function for this…
-
0
votes1
answer46
viewsA: i am not managing to inherit the client class with one of the two
To use with inheritance is as follows: its classes have to inherit from the common base class (client), and call the methods of the superclass, using the special call super() - in the if, the only…
-
2
votes1
answer52
viewsA: The . append() is not working in my dictionary - Python
Python dictionaries do not have .append: they always keep a key and a value, and this is independent of the insertion order - Given the key (in this case, the "name"), it will always take the same…
-
2
votes1
answer21
viewsA: Skipar an optional argument among several in Python
Either you call the function with the arguments in order, or you put the name of the arguments when calling. If you want to leave the defaul of lang and send pages, just do: FuncEx("politica",…
-
2
votes1
answer112
viewsA: How to shuffle all letters of words within a file . txt
There’s two little problems there: You confused the "with" command with a "for": "with", although it requires a code block, the block runs only once. So only the first line is read, and the program…
-
3
votes1
answer41
viewsA: Include a character in an excel python values
To transform from the string, before doing the as_type(int): df ['Vlor_Correto'] = df ['Vlor_Correto'].apply(lambda x: float(x[:-2] + "." + [-2:])) This form uses Python’s "slicing" syntax to take…
-
8
votes2
answers399
viewsA: How does Python structural matching (match declaration) work?
I followed from the first proposal and the various interactions of the development to the final proposal being implemented. How the Python match works? The idea of match is, from an object, or…
-
2
votes1
answer51
viewsA: Creating and installing my own packages
if you write a setup.py for your projects, even without putting the packages in public Pypi, or in a private repository, you can simply activate the virtualenv of another project, and type pip…
-
0
votes2
answers228
viewsA: Create shortcut with python
Doing a google search, this type of file really isn’t trivial to move around - it’s a binary format - and requires specialized code to respect the fields, etc... There is an opensource lib to bring…
-
2
votes1
answer98
viewsA: How do I use pipe when running python programs in the terminal, and what is it for?
The pipe, with the signal | is actually an operating system feature - provided by the shell (on Linux and Macos may be bash, among others, and on Windows to this day is "cmd"). What it does is…
-
0
votes1
answer70
viewsA: I’m having trouble with the smtplib
Sending email can be a bit tricky - with the "sendmail" method you are responsible for composing 100% of the body of your email, including the correct headers - you are putting the header "Subject"…
-
2
votes2
answers29
viewsA: What is the difference at the time of the return of these two forms?
return sendo() does the following: Python calls the function sendo, rotates your code, and the value it returns is in place of the expression sendo(). In this case, as the function sendo does not…
-
0
votes1
answer33
viewsA: I cannot run an audio player using Flask with Python3.7
Note that what goes in your variable {{music}} in the template is created pointing to the disk path of the mp3 file. This is created as a string (text) and it is this text that is placed in HTML.…
-
4
votes1
answer30
viewsA: How to check the Windows time zone in real time using Python?
That library localtz is not part of Python - it is open source, and its code is here: https://github.com/regebro/tzlocal Fortunately it is a fairly simple code, which only does the job of encoding…
-
3
votes1
answer157
viewsA: 'utf-8' codec can’t Decode byte 0xe1 in position in rendering html
Your template file is saved with "latin-1" encoding - Windows native, not 'utf-8' universal encoding, where it is more practical to write software projects. The accent encoding of the files depends…
-
1
votes1
answer82
viewsA: How to skip the line in python input?
By default, Python does not include very flexible tools for developing applications on the terminal: "Input" is pretty much the only option - for anyone on Unix (Linux or Mac OS), you can use the…
-
3
votes1
answer56
viewsA: Get the name of the Variable by which the function or class was called
It’s not possible for common variables when they call a function (ok, even "it’s possible," but it’s much more complicated, and it’s not the intention for something like this to be done). But for…
-
9
votes1
answer144
viewsA: What is the Join() function for in the threading module?
The .join simply pause the current thread (from where it was called) until the target thread (the thread it is attached to) ends. It is a way to re-sync the program, ensuring that no parallel…
-
2
votes1
answer151
viewsA: How to save a CSV in memory using Python?
"Creating a CSV in memory" doesn’t make much sense - A Pandas Dataframe is a data table in memory, but already with much more facilities than a CSV. A CSV is a convenient file type to port data back…
-
0
votes1
answer342
viewsA: Outlier Detection with python
You can use filter strategies to avoid spikes and points outside the curve, in various data domains (that is - data from various areas of knowledge: in health a value outside could identify an exam…
-
2
votes1
answer103
viewsA: How to allow input() to receive scientific notation in python 3?
The normal call to turn a string to decimal number - float, already converts any valid Python number to a "float" object that is treated as a number. And valid numbers include numbers with .…
-
1
votes2
answers167
viewsA: Python library installation error by cmd
The error may actually help more people - the problem is not the installation of pywhatkit - but yes, that Python did not find the bdist_wheel on the way. When this happens, you may need to install…
-
1
votes2
answers47
viewsA: How to remove dtype from dataframe line?
The problem is that your function creates a series with the data you need, and then you create a dataframe containing the series, in the line that has the "Return". In the answer the content of each…
-
1
votes2
answers331
viewsA: Problem of wget in python
this error you get is not from Python or wget - it’s from the site you’re downloading from. the error code is generated there: "403 Forbidden". Possibly the user has to be logged in to be able to…
-
4
votes1
answer41
viewsA: How do I create a variable with some columns of my data frame?
A Pandas dataframe allows you to create a "sub dataframe" - a view of the original dataframe, passing a list of the desired column names as an item within the brackets. That is, if your dataframe is…
-
1
votes1
answer64
viewsA: find a word in a random character list
it is easy to see with the account you are doing that - first, it does not take into account that the number of lets can change, second, if the input is "nnnnnnnnn" will result in "2". Try this: a…
-
1
votes1
answer714
viewsA: Writing a csv file on Google Drive using Colab
The call to "mount" makes google drive available to the program in Python as if it were in the "/drive" folder (under Unix, unlike Windows, directories do not have a drive letter before - "/"…
-
2
votes2
answers279
viewsA: Changing a key value in a Python dictionary
Your dictionary is "backwards". The correct is not to use a dictionary so that the values are lists and each position in the lists, in all values in the dictionary, corresponds to a record (that is:…
-
3
votes1
answer170
viewsA: Doubt about simple Python encryption script
The line makes some function calls and an "xor" operation, using the operator ^ - and concatenates the result into a string he calls "xored". we can unfold in parts to make it easier to understand:…
-
1
votes1
answer124
viewsA: How do I call an asynchronous corotine within a function that is initialized into a thread?
In general or you use asynchronous code for things in parallel, or uses multi-threaded code. You can mix the two together - and it’s common to have time-consuming tasks running on other threads, and…
-
1
votes1
answer177
viewsA: Python multiplication using recursion without interactions of type `while` and `for`
Clarified the doubts in the comment, you can write an answer that can be productive: Being able to perform tasks repetitively is possibly the most important feature of digital computing. For…
-
8
votes1
answer108
viewsA: What is the most efficient way to format code output to the user?
The string formatting mini-language used by "format" by the f-strings allows you to specify the output width of any string, and how to complete the missing spaces. So if I want any number to be…
-
0
votes2
answers210
viewsA: How to convert a value to float and int in python?
valor_float = float(valor) valor_int = int(valor)
-
0
votes1
answer33
viewsA: What alternative do I use to solve the problem of the get() function not working
Your mistake there is that the argument command in creating the function should be the function itself. How you put 'executar'between quotes, this is a string containing the name of the function.…
-
3
votes3
answers341
viewsA: Sort a list based on two different criteria using Sorted
The "key" parameter accepts any function, which will receive an element of the sequence that will be ordered, and must return an element that can be directly compared with ">" and "<" by…
-
6
votes2
answers2710
viewsA: Convert decimal to binary - python
The "bin" function gives the binary representation of a number as a string. Mse this representation as string is useful only to show the "0" and "1" on the screen, to be seen by people. Internally,…
-
0
votes1
answer117
viewsA: NASM SEGMENTATION FAILURE
I’m rusty, or I’d risk a more assertive response - but you see the mov si,[array+0] - this moves the Value found at the address "array + 0" to the register SI (the value "30") - and mov bl, [si] you…