Posts by jsbueno • 30,668 points
811 posts
-
3
votes5
answers286
viewsA: Regex to capture dimensions of a product with unit of measure
Regex can actually extract the three values "into a single line of code," but realize that this is an illusion - you are at a point where…
-
2
votes1
answer225
viewsA: Error reading file . xls
If you have an "XLS" file with in the issue title, it will not be able to be read with functions to read "CSV" files. They are fundamentally different files. (And CSV files usually won’t have bytes…
-
1
votes1
answer907
viewsA: Nameerror: name 'Y' is not defined
At last if its variable is Y uppercase. In Python, there are differences between uppercase and minuscule letters in variable names. That’s why he says that Y there is no - usey. Another thing wrong…
-
0
votes2
answers220
viewsA: Flask Sqlalcheny Typeerror: 'Fermentables' Object is not iterable
If you are going to add only one object to the database, use db.session.add, the method add_all is for an eternal object - in your case you must have copied the code from somewhere that added a…
-
6
votes2
answers323
viewsA: Python reserved word Yield
Briefly, this is the mechanism used for co-routines to return values in Python - details of how it works follow below: First: if the body of a function has the keyword yield, yield from or is…
-
4
votes1
answer198
viewsA: Python asynchronous generators
The best source of information about asynchronous generators is the PEP that describes their need, and their implementation - the PEP 525. To briefly describe asynchronous generators, let us briefly…
-
2
votes3
answers5999
viewsA: Inserted in a list of lists in python
The problem lies in its creation of lists. If you had created the list as you put it above, with all internal lists explicitly created, the problem would not happen - because each internal list is a…
-
2
votes2
answers514
viewsA: How to have two counters in the same loop?
In Python it is possible that a command for Sure go through multiple sequences at the same time. But before I say I’d better clarify a few things: (1) the for in Python is not, in general, used for…
-
1
votes1
answer175
viewsA: Problems to develop a Bricks Breaking-style game on Tkinter (collisions with objects)
Ok - I tweaked your code to get past the difficulty you encountered - but I didn’t hold back and wrote a little more code until it became playable. The main change made, and that has to do with the…
-
1
votes1
answer642
viewsA: Return the largest number in Python with recursion
You may have noticed that it is not the idea of this site that people solve the problem for you - but tips can be given. In the case of a recursive function, the idea is always: the function checks…
-
6
votes1
answer810
viewsA: How to run linux desktop application remotely via command?
There is how to set the environment variables in the destination, so that the program "find the screen" - in fact, it is only the variable "DISPLAY", since the user you use with SSH is the same as…
-
1
votes1
answer129
views -
2
votes1
answer112
views -
3
votes3
answers416
viewsA: How to Insert in a non-zero position in an empty list?
Python lists have the size equal to the number of elements they contain - they are different from "arrays" or "vectors" - although in some texts for beginners they are presented as "vectors". So…
-
3
votes1
answer296
viewsA: Hexagonal matrix in Python
As you can see, inside Python, you will not use a "hexagonal matrix" - you will use a two-dimensional structure. What you need is a way to (1) traverse the interesting coordinates for you (in this…
-
0
votes1
answer104
viewsA: How do I print Side using end=" with the included Time Module
To continue printing on the same line as it happens, in addition to changing the end line character with the parameter end, you also need to pass the parameter flush=True to synchronize the file…
-
14
votes1
answer137
viewsA: How can the search for an element in a set be O(1)?
The sets set are not "sequences" - neither in the internal organization of the data, nor in the interface they implement, since they do not guarantee any order. Sets actually have the implementation…
-
3
votes2
answers324
viewsA: Singleton pattern in Python
There are several ways to have a Singleton in Python - if you don’t mind using a specific method to get Singleton, it really can be one of the simplest approaches: i.e., "it’s possible" to create…
-
15
votes1
answer3091
viewsA: What is "await" for in Python?
The await Python is used so that it looks like a prefix for a function call that will be an asynchronous call. So, starting at the end - what we see in the code and its effect, and then…
-
3
votes1
answer331
viewsA: Save entire CSV file to mysql
Your call to cursor.execute is outside the block of for - simply idente the line correctly and the problem should be solved (but I haven’t checked if the rest of the program is correct) for row in…
-
1
votes1
answer136
views -
0
votes1
answer145
viewsA: Sort as typed (python)
It is really something quite artificial to impose an exercise of these and "probir to use lists" why "not yet arrived in this part of the matter". If you happen to have "as part of the subject", the…
-
3
votes1
answer71
views -
1
votes3
answers359
viewsA: Numbers over 32, 64 bits
Although the Python Random module is very practical, for encryption purposes the recommendation is to use the call os.urandom(), that has randomness most guaranteed by the operating system. On the…
-
0
votes2
answers260
viewsA: Python string prefix
The "prefix b" indicates that the object you have at hand is not a text string - but a set of bytes - In Python 3 the two things are fundamentally different, why you always need to know how the text…
-
2
votes1
answer34
viewsA: Recursions in closures
The code is right (with the only detail that makes no sense to keep the variable count alone in memoize - she should or should be inside the inner, or the cache should be out, along with her, but…
-
1
votes1
answer379
viewsA: Chained exceptions in Python
There’s not much mystery there: the "silencing" of an exception within an except is part of the way Python is made. One always has to keep in mind that unlike compiled code, where an error in the…
-
3
votes6
answers2884
viewsA: music does not play
The point is that the call pygame.event.wait() in almost all cases will return immediately: it returns whichever pygame event - including mouse drive, etc... If you want to run code in parallel with…
-
0
votes1
answer239
viewsA: How to get the origin of a form in cgi python?
Short answer - but read below!!! import os origin = os.environ.get("REMOTE_HOST") Some considerations: Pure CGI is not an interesting technology to be used in 2018. It was implemented in the…
-
2
votes4
answers365
viewsA: Repetition for calling variables
In Python, in general, when you want to use _names_das_variables as variables themselves, the recommendation is to use a dictionary. That is, instead of having "F1, F2, F3, F4", you could have a…
-
4
votes1
answer512
viewsA: Abstract classes in Python
"Provide cases of use" for this type of Feature is quite complicated - it is about functionalities placed in the core of the language to allow advanced class hierarchy handling and customization -…
-
3
votes1
answer119
viewsA: Library python asyncio
Recoding for development is using the latest Python - 3.6 - installing Python 3.6 on your server is a trivial problem compared to trying to create using asynchronous code for Python 2. But…
-
1
votes1
answer130
viewsA: Infinite wait per server response using python sockets
You order the program to receive 3 bytes in that socket, and they never arrive. In a system for production, you must set the socket timeout, for, if the answer does not arrive, the socket raise an…
-
1
votes1
answer65
viewsA: Is it a problem to use pygame.image.load() multiple times?
Yes - there’s a problem. Unlike the Python module import system, which uses a very complicated mechanic to read a disk file once, no matter how many times you do import, pygame.image.load…
-
1
votes2
answers1503
viewsA: Make server socket in Tkinter allow client input
The problem with this code is that although the function that creates a socket for the server is called, it does nothing else: creates a new server, connects it to the port, says it will listen to…
-
1
votes2
answers720
viewsA: Python 3 and Tkinter: progress bar does not update during script execution
The problem you are having is that Tkinter (as well as other graphical toolkits in various languages such as GTK, Qt, etc...) run in a single thread. A graphical program always has a main loop,…
-
2
votes2
answers180
viewsA: Problem with importing files into different directories
Your "deathash" as is a Python "package" (a collection of multiple modules). As a rule, what Python does to find packages is: It looks for the package name in the folder it is running in (where you…
-
1
votes1
answer64
viewsA: Python, Game of Life Implementation
The problem is that you use to count neighbors the same data structure that you are modifying for the next generation - When checking the neighbors of the cells in the line "2", the line "1" that…
-
1
votes1
answer1150
viewsA: How to configure Portuguese in kivy?
I did some tests here, including using a file . Kv, and everything works perfectly. but I’m on a Unix-like system and you’re probably on Windows. I assume you have made sure that your files - either…
-
1
votes1
answer1063
viewsA: python command to "grab" text from Qt Designer fields and save to sqlite
If your input field is a QtWidget.QLineEdit, you get text with the call to method .text(). If it’s a field like QtWidgets.QTextEdit, you first pick up a reference to QTextDocument associated, and…
-
0
votes1
answer447
viewsA: Import CSV to Pandas database without converting string to tuple
I couldn’t quite understand your problem - at least a whole row of the matrix would help - and understand if you want to optimize CSV coding - or just want the final reading as well. In this type of…
-
2
votes1
answer301
viewsA: Automatic condition for a variable.
There is, you just have to be using classes. You have virtually not put any code, but if it is ok, you access life in the code using self.life (or if it is outside the class’s own methods,…
-
5
votes3
answers337
viewsA: What’s wrong with allocating memory with new and then not erasing?
The "problem" is that each time the function is called, more memory is used. The problem is actually bigger if your program will work as a server or other type of long-term process, and run for…
-
0
votes1
answer49
viewsA: Check the relation of two objects in a list
padrao.sort(reverse=True) maior = padrao[0] if maior* 0.02 in padrao: maior = padrao[1] But as I wrote initially as a comment: This approach is very risky - especially if the documents are free…
-
2
votes1
answer896
viewsA: Read pairs of integer values using python tuples
The code you wrote will work well to read the data, and stop the input. The input must be integer, but the outputs of some of the requested items are decimal, so there is no problem in using the…
-
1
votes1
answer429
viewsA: Pyserial library problem (PYTHON)
This type of error is typical of when you think you imported one module and imported another: probably your project has another file serial.py. This file must be being imported instead of the serial…
-
0
votes2
answers293
viewsA: How do I display if I can ping a machine without displaying the textual ping pollution itself?
os.system is a direct method, but the crudest of all to execute an external command: it executes the command, but does not give you any control over what the command prints, asks the user,…
-
2
votes1
answer2179
viewsA: Automate printing of files within a folder
Your files are already in PDF - it’s the big difference to the answer on How to print a txt file in Python. but it gives a good basis of what is involved in printing and why Python or other…
-
2
votes1
answer684
viewsA: Randint does not generate random numbers the second time I use it
The problem is that you are not creating new matrices on each call to gerar_matriz() - what you do is add new numbers to the end of each existing line. And at the time of printing the lines, you…
-
4
votes1
answer1155
viewsA: Import python C++ modules
Modules in other languages are not directly usable from Python. The fact that the module is imported is why Python can import modules .so on Unix or .dll in Windows - but these modules have to have…