Posts by jsbueno • 30,668 points
811 posts
-
2
votes1
answer159
viewsA: How do I let the user decide which variable he wants to change in python?
Variables, whether variables in a module, class attributes, or instance attributes, can be changed in Python, having the variable name as a string, with the function setattr. So, let’s assume that I…
-
4
votes2
answers93
viewsA: How to print accents in Lua
It has to do with encoding - You can either create your Lua source file in the encoding used by the terminal - or use a terminal program that works with utf-8 in windows, one of the ways can be use…
-
3
votes2
answers136
viewsA: How to improve runtime
You call the function repetidos for each line of your dataframe, and this function in turn, looks again at all the lines of the dataframe. That is, if it has 10 lines, it will make 100 comparisons.…
-
2
votes1
answer1686
viewsA: How to run a python script from a directory inside another script that is in another directory?
Ideally, each directory or program that is made to be used by independent projects should be transformed into an installable package - for this, the most common method is to create a file setup.py…
-
0
votes1
answer48
viewsA: Base64 getting corrupted via post in flask
The problem is that CURL by default sends data emulating forms sent by a browser, with Content-Type as "application/x-www-form-urlencoded" - what Flask does when it sees this header is to translate…
-
0
votes1
answer92
viewsA: How to disregard keys inside a python formatted string
How @user140828 posted as comment: Just escape the keys by replacing the { por {{ e } by }}.
-
2
votes1
answer827
viewsA: How to run Python function every 1 minute, without using time.Leep()
How @Jassriver put it there - the module can be used sched from the standard library - but only this tip may not be enough, since "sched" is very low-level and flexible - so requires building a…
-
1
votes1
answer146
viewsA: Recover a branch in Git
When the message appears HEAD detached at 4bf36b5 nothing to commit, working tree clean you are free to create a new branch, at the point where you are - just give the command git branch…
-
2
votes2
answers437
viewsA: How to clear what has already been written on the moon terminal?
is almost the same problem I answer in this question by asking about the Python terminal How to clean the console in Python? - Reason: deleting the terminal is not a language problem - neither Lua,…
-
1
votes2
answers132
viewsA: Inherit boot modules and variables in a Python script for another Python script with Gtk3
Specifically about your doubt: If your program has several times the same import in different . py files, the Python does not load other copies of the imported module. Only the first import brings…
-
3
votes1
answer59
viewsA: Tkinter, open only graphical interface
Just save your file with the extension ". pyw" instead of ". py". (this is only on Windows - on other systems a Python program run by the graphical interface does not open a terminal automatically)…
-
3
votes2
answers197
viewsA: "List Comprehensions" is it worth it?
The use of List "Comprehensions" in Python is a good use? Yes, it’s a good use. The main idea has always been to let the most readable and concise things - so unless is a complex expression, which…
-
1
votes2
answers66
viewsA: object1 += object2 is different object1= object1 + object2 in python(3.8)?
Your real problem Your big problem there is that you’re using a list ([]) as a standard argument in the method __init__ - like the line def __init__(self,caixa=[]): is executed only once, this list…
-
2
votes1
answer84
viewsA: Create a python character chart
If you want to do this to learn, and as an exercise - it’s a pretty cool thing - and I’ll explain it here. If you need this as a requirement for a work/production application, my personal project in…
-
2
votes2
answers619
viewsA: Modifying a Python file without losing the current content
As the most efficient answer in this case is substantially different from the accepted answer, I will write a little. It has already been commented in the comments that this would not be by far the…
-
1
votes2
answers72
viewsA: Accept entry with only 1 digit
The line game = int(input("Choice a game between 1 and 3: ")) flame int and this immediately converts the typed value to an integer (and if it is not an integer, a Typeerror happens and the program…
-
4
votes1
answer44
viewsA: Do I lose commit history if I switch to remote branch?
No - when you move a branch up a remote, the entire commit history of that branch goes along. The only thing is that if you have multiple branches in a remote, you have to climb all the new remote…
-
4
votes1
answer622
viewsA: How to reverse git push --force?
If you haven’t ruined anyone’s work by pushing git --force - you don’t have to go back and do the other. If damaged, doing "force-with-Lease" doesn’t help either: he would only refuse to push. All…
-
1
votes1
answer442
viewsA: Set decimal numbers in a string list - Python
In fact, you’re doing it right already - There is only "number with two squares after the comma" or in the form of a string. A "number" is a "number" - a quantity: "1", "1.0", "1,000" is the same…
-
1
votes1
answer351
viewsA: I’m having trouble making the character move in python with pygame
You’re taking the image dynamically, but you’re always putting the drawing in the same position (300,400) on the main screen - You have to create variables (x and y, for example), to maintain the…
-
1
votes1
answer71
viewsA: Python: How to assign values in n arbitrary dimensions?
Come on - Numpy makes an interesting use of the syntax of objeto[ ...] Python, and can use it to address multidimensional indexes and even index ranges in each dimension - as well as other uses (as…
-
2
votes1
answer368
viewsA: How to update the Tkinter window?
For Tkinter to do something that is visible, you have to pass the control to it - after performing the functions and methods that build your window, add the initial data, etc, you do this by calling…
-
2
votes1
answer661
viewsA: Python sending multiple email with different attachments
you create the "email" object on the line mail = outlook.CreateItem(0) - just place this line and the following within the for - to create and send an email to each file. You didn’t say you need to…
-
1
votes1
answer243
viewsA: remove brackets from the values stored in a dictionary
The fact that your dictionary is like this: {'name': ['felipe'], 'birth': [Timestamp('1988-04-07 00:00:00')], 'gender': ['male']} indicates that each value in the dictionary is a list, with a single…
-
1
votes1
answer1991
viewsA: typeError: 'module' Object is not callable
It’s on the pygame.Surf line - that’s the name of the module - you should use pygame.Surface (with uppercase "S" - to create an instance of the Surface class. This is common in some medium to large…
-
2
votes1
answer56
viewsA: Problem with dictionaries
this is a complex problem, in the problem model presented in "programming marathons", and online problem servers in the SPOJ model - The most important thing is, before writing the code, to…
-
2
votes1
answer308
viewsA: Organizing code within __init__.py
Come on - in fact, what goes inside the __init__ might be a little wild. If the project is a library - with the idea of being imported and used by other projects, the best thing to do is to leave…
-
1
votes1
answer112
viewsA: Python parallelization slower than serial
I don’t know "joblib" - in particular I don’t know if it creates threads or processes - but the only call to sqrt Anyway it is very small near the job of serializing an integer (in Python, integers…
-
1
votes1
answer57
viewsA: Is it possible to create a virtual file in Python?
Yes - in Python 3, there is the module io - and within it, the classes BytesIO to create what you call "virtual file"(*) binary, and Stringio to do the same with a text file. Objects in this class…
-
2
votes1
answer303
viewsA: How to open a txt file that has a space in its python name?
The problem is not the spaces - the problem is the backslashes \ which are escape characters. Place an "r" prefix in the file name string r'c:\Users... or double each bar - as Python prints - to…
-
2
votes3
answers99
viewsA: Replace all arguments (of all strings) that exist in a Dict with . format
You can create a subclass of Dict, which has a substitution parameter, and do the .format directly on __getitem__ - Then the Python engine itself generates the formatting on each string you’re going…
-
1
votes1
answer150
viewsA: How to delete two related numpy array elements?
First of all: numpy "arrays" are different from Python "lists" - you can’t simply change their size: it doesn’t work del array[i] to delete the index element "i" from an array. As lists are part of…
-
0
votes2
answers766
viewsA: Load image in html from saved path in Django database
It works if noticia.imagem has a correct URL and that works for your image. Where are you storing the images? Is the app configured to serve static files from where they are? Just open the generated…
-
2
votes2
answers61
viewsA: Relation __dir__ method and __getattribute__method
This example of yours has fallen into some difficult ways to understand and explain. And the reason why is that you replace the __getattribute__ - this is a method very delicate, because it really…
-
2
votes1
answer524
views -
4
votes2
answers168
viewsA: Python 3: How to understand this string
Documentation: https://docs.python.org/3/reference/lexical_analysis.html#f-strings These are string formatting - the link above explains the options used with the 'format' method, which work the…
-
1
votes1
answer33
viewsA: Class mock without methods
Without you giving more details, all that is possible to advance is that you probably don’t need mock such a class. Simply let the code that will use this class use the original class. Why there are…
-
1
votes1
answer1518
viewsA: Unboundlocalerror: local variable 'ACE' referenced before assignment
The problem is that you want to use the "ACE" variable as global - but without explicitly marking it as global where you are using it, Python understands that it is local. So, to rotate just change:…
python-3.xanswered jsbueno 30,668 -
1
votes2
answers852
viewsA: Insert elements in the correct position in an ordered list
this program became much, much, more complicated than it was supposed to be. But it is not possible to "fix it" - better to write another one. You can read the comment above as a scolding - but it’s…
-
2
votes2
answers684
viewsA: Transform object to Dict in python
If you just need to create a dictionary, you can use the function zip Python to list your two lists - and you don’t need almost any code: novo_dict = {key: palavra for key, palavra in zip(keys,…
-
1
votes1
answer378
viewsA: (Tkinter) How to leave Labels, Buttons, and Frames with the tranparente background?
Tkinter does not support transparency - so unfortunately there is no such thing as. You can create themes with gradients, fake reflexes, do a lot of things - but it has neither text rotation nor…
-
3
votes1
answer6781
viewsA: Center text in python
Centralizing text requires the drawing api to know where centralize your text - and it is you who has to do this account. Many Apis have no function to automatically center text - in such cases, you…
-
3
votes2
answers742
viewsA: Python draw on the screen
You have to use a library that has the design features - and that intermediates with the operating system. To "black the screen" and you can draw everything from scratch, one of the easiest to use…
-
0
votes1
answer27
viewsA: Printable images with the Pillow library
You only have one instance of the image that is created the moment you call Image.open - If you simply move this line, and the line that creates the object texto into the for will work. But it’s a…
-
0
votes1
answer126
viewsA: Values are not converted to np.Nan
The call Series.apply Pandas, like most calls, doesn’t change the value "inplace" - will it return a new series (or dataframe - it’s hard to say, does it look like you called your variable "Series"?…
-
3
votes4
answers1516
viewsA: how it returns the indices of a python list
There is no method to retrieve the contents of a list, why these indexes are always sequential number, starting at zero. does not have "different indexes". If you need individual indexes, you can…
-
2
votes1
answer689
viewsA: Memory release in python dictionaries
Memory release on objects like dictionaries and lists is not automatic - after a data structure grows - it does not decrease in size - but keeps the internal size so it can grow to the maximum size…
-
6
votes1
answer482
viewsA: How to take the class name inside a python method
The class name of an object is available as self.__class__.__name__ Your mistake was that self.__name__ tries to take this attribute in the instance - has this extra step. Taking advantage of the…
python-3.xanswered jsbueno 30,668 -
1
votes1
answer149
viewsA: How to Decrease Complexity of a Function with Two Loops in Python
Comparing only 2 to 2 is not possible. But if it is a "real" algorithm and not something theoretical, you can, within the function itself, go building a list in parallel, this being ordered, and…
-
2
votes1
answer69
viewsA: Python - Error 34, Result Too large
By default, Python uses 64bit floating point numbers, which are the natives of most modern Cpus. These numbers are very flexible, but they have their limits - and if any operation breaks for a very…