Posts by jsbueno • 30,668 points
811 posts
-
3
votes1
answer180
viewsA: Does using "from x import y" in python reduce the size of the application?
It makes no difference in the final application size. When something is read from a Python module, even if it is only a module variable, it is executed (like any .py file) - the functions, classes…
-
1
votes1
answer84
viewsA: Why is the text label not changed?
In fact, it’s surprising that the label changes the way the code is, if you call the function escreve_texto from within interface_grafica. A "process" is something independent at the level of the…
-
1
votes1
answer1977
viewsA: Path to a python character
Congratulations on the initiative! So here we go: The "easy to start and hard to continue" way of doing this kind of thing is to use sequences within sequences. Anyway, you’re defining your maze as…
-
1
votes1
answer58
viewsA: Is it worth doing exercises that teach not very optimized ways of doing a program?
In fact, if you already understand what the code would look like, and you can imagine it in your mind, you don’t have to. In particular, if you can’t use loop structures, I recommend not to do it -…
-
1
votes1
answer617
viewsA: Does query with date in sql include the day in question?
Your answer: The "between" operator is inclusive - both the maximum and minimum value are included in the search range. Now - this is not the best way to do a data search - are some points you can…
-
2
votes1
answer721
viewsA: Error installing psycopg2 in a pypy virtualenv environment
A search for the packages reveals that psycopg2 is not compatible with pypy (this will happen with several Python packages that have native code together, that is, using the cPython-specific API).…
-
9
votes2
answers2973
viewsA: What’s the difference between socket and port?
Socket is an operating system resource that is connected to a port. A port is a number defined in the network protocol - usually with 16 bits. A socket is a connection in a given port, and always…
-
3
votes1
answer684
viewsA: Syntax of the Lambda function
lambda in Python is not a function. It is a keyword that allows defining a function as an expression, or part of an expression. When you use the lambda, we say that you have created a new function,…
-
3
votes1
answer74
viewsA: How to "launch" a new programming language
A project that starts with a person, the best way is to put as open project, and try to join a community. You create a repository on Github for your language project - put in the code, and the…
language-designanswered jsbueno 30,668 -
0
votes1
answer125
viewsA: Python/ Selenium is not filling the tilde (~)
It may be because send_keys sends keys through a layer before the system keyboard driver. As your keyboard has the Brazilian layout, the "~" is a silent key. Try simply sending the "~" twice,…
-
1
votes1
answer889
viewsA: Python - Access a function above outside a class
There is no gain or reason to define classes within Python classes. (Ok, there’s actually a very minor reason: you might want to use your classes as namespaces to maintain values) But in this case,…
-
2
votes1
answer160
viewsA: Access variable via exec
There are many, many snags with the way you are doing this program - but, this is part of the things we write when we’re understanding how to program. The main thing is that its control structures…
-
6
votes3
answers15464
viewsA: For increment in Python
As people put in the other answers, what happens is that the for in the languages that inherited the syntax of C is just one while incremented. In Python it is rare to actually use a for numerical…
-
1
votes1
answer147
viewsA: How to disable text cursor?
I don’t know if it’s possible - In the documentation there is no method related to this. And although GTK3+ supports CSS style configuration, some attempts I made here did not modify the cursor. In…
-
2
votes3
answers1236
viewsA: Is it possible to know which website my link was clicked on?
For now yes - if the user clicks a link that leads to your page, with some restrictions, the URL of the previous page is sent to your server in the HTTP header. And in this case, the contents of…
-
-1
votes2
answers66
viewsA: Price calculation algorithm does not display the result correctly
You must not be running the same program that compiles. As noted in the comments, we are missing one ) in the first case - printf("Voce vai pagar R$ %.2f", valor-((10/100)*valor)); Open 3…
-
4
votes4
answers3471
viewsA: Matrix generator in Python
The problem is that in your bond you create one list and assign it to the row variable - and then, you assign that same list to each position in your matrix. If you create a new list on each line,…
-
1
votes2
answers1583
viewsA: Python - Assign the value of an entry to a variable
def enviar(): texto = mensagem.get() print(texto) When you use a variable associated with an Entry, you must make the calls to get and set for the variable. Kinter ("message") as the name of a local…
-
4
votes1
answer73
viewsA: Why is the source not changed in Raspberry Pi?
The problem seems more complicated than it should be. Apparently one of the developers of the Raspberry UI decided that it’s not for people to exchange fonts - see this post here:…
-
2
votes1
answer854
viewsA: PYTHON - how to use a loop without stopping Tkinter
The program runs on a single thread - then either it runs the Tkinter loop, responsible for receiving and executing mouse events, keyboard, etc... or it stays in your while...time.sleep(1.5). This…
-
0
votes1
answer71
viewsA: How to make a window stand above all?
has a legal answer in the English S.O. here: https://stackoverflow.com/questions/1892339/how-to-make-a-tkinter-window-jump-to-the-front Basically it’s calling the method .attributes from your…
-
2
votes1
answer895
viewsA: Convert fraction of hour to hh:mm:ss
This error is happening because the divmod that you are calling does not return a number - to have a split rest in Python, simply use the operator % . Divmod returns the entire part and the rest of…
-
2
votes1
answer2970
viewsA: How to manipulate docx files using python?
The point is that documents like . docx, the old . doc, or the libreoffice . odt are orders of magnitude more complex than a normal . txt file. Although it is easy to understand how they work (the .…
-
4
votes2
answers778
viewsA: Empty if declaration in function
Not as you imagine - any command that ends with : in Python creates a block - and this block has to have expressions and commands, otherwise it is a syntax error. Updating: pass functions as…
-
2
votes1
answer2885
viewsA: How to open a Python file selection window with GTK?
The GTK framework has the "Filechooserdialog" which is a complete window to browse the file system, and allows either the choice of an existing file (or directory) ("open" action), or the user to…
-
3
votes2
answers1943
viewsA: How to link to download html file?
Neither Django, nor any maintained Python framework has an automatic match between file paths on the server and Urls - this is something of static HTML that comes from the pre-1.0 Web - and it’s…
-
1
votes1
answer270
viewsA: Apply color palette to raw image
You can use the GIMP. It has options for this right in the color menus - but if interactive use isn’t enough for you, the program exposes hundreds of calls to your internal API (called "PDB" -…
-
2
votes2
answers2075
viewsA: Change color and border size Tkinter Menu
The menu edge color is given by the background color (background) of the menu. If you want the border color to be different from the menu background color, you have to set the background color of…
-
1
votes1
answer850
viewsA: How to integrate an Android application with a Python+DB server?
Yes - As you may have already understood, your Python application will be on a cloud server. Several frameworks for android allow you to make an application that will fetch results in the cloud…
-
8
votes2
answers13897
viewsA: How to remove specific position characters from a string?
Python strings, as in many other languages, are not changeable: that is, for any modification, Voce must create a new string (in general it is ok to associate the new string with the same variable).…
-
1
votes3
answers2037
viewsA: Regex to validate certain date format
While it is possible to do this through regular expressions, I do not believe it is the best way in any programming language. (I don’t know why I answered the question thinking it was Python’s too -…
-
3
votes1
answer8329
viewsA: Formatting two decimal places using list (Python)
As you may have noticed, the ideal is to keep the numbers as numbers while the program is running - and only worry about formatting the presentation when it is or printing the result, or saving it…
-
3
votes2
answers367
viewsA: How to optimize my access to the Python dictionary?
As in the comments and the other answer, Python dictionaries are a hash table, with search time O(1) - and the information about it is here:…
-
1
votes1
answer47
viewsA: What problem can occur when retouching a value without having a variable to receive (Python)?
No problem at all. Although it is not a typical Python language design, where it is common to have functions without a return value, it is possible that a function always returns the object on which…
-
2
votes1
answer182
viewsA: differences between for...in JS and in Python
Python has a for that since the beginning of language, in the 90s was a construct to traverse a sequence. A block that in other programming languages, or in generic terms, we call for each or for…
-
4
votes3
answers5349
viewsA: Python3: How to calculate the number of working days between two dates?
then, as it is in Diego’s answer, to know the number of days between two dates, just subtract two objects of the type date and take the attribute days. Now, regarding working days: - counting…
python-3.xanswered jsbueno 30,668 -
1
votes1
answer1949
viewsA: Program a Python function to always run on the last Friday of the month
So - the Schedule library does not support this. So the simplest way will be to simply schedule the task for every Friday, and put a filter code in the function entry: if the current date is not the…
-
6
votes2
answers1153
viewsA: How to transform integers into byte in the Python language?
In Python 3 the built-in "bytes" itself does this: >>> bytes([40,10,20,30]) b'(\n\x14\x1e' In Python 2, what today are "bytes" was the equivalent of strings. However in Python 3 they have…
-
2
votes1
answer509
viewsA: How to save value of a function that returns a char pointer in a string array
So - what you need to have there in your main function is a pointer vector for strings: each position in the array will actually contain the address of a string. Thus, each position in its vector…
-
0
votes1
answer160
viewsA: Why if I rename the folder the files inside it change?
You haven’t created your rename function so it’s reversible - it’s no surprise that running twice the same functionality won’t restore the original names. The use of regular expressions, and subs…
-
5
votes1
answer400
viewsA: Is it possible to make connections with Python without using the language packages?
"Without the modules, "in Python, you can use all the functions that are built in (builtin): in the case of Python this means that you can still communicate with the world using print, input, and…
-
1
votes1
answer779
viewsA: Indentation in Python
you have more to worry about in the code than the spacing of lines. Code is about having functions - and if it’s applied to the problem, having classes and methods - a "program" played without even…
-
1
votes2
answers602
viewsA: Object orientation in python
This has very little to do with object orientation, and much more to do with Tkinter. I myself find very bad the inherited design of the classes of the application of Tkinter classes. Since the…
-
2
votes3
answers16701
viewsA: The ' ' (SPACE) character, counts in the string in the C language?
In C, space is a normal character, like any other. What you’re seeing as odd there, is that in fact the function scanf uses space as an input value separator by default. If you instead of scanf use…
-
1
votes1
answer47
viewsA: Extract '_id' from load_response object
You have, serialized as a byte string, another JSON object, which is the key content _content. It is easy to see this because you have the structure of a dictionary, and other typical JSON format…
-
1
votes1
answer82
viewsA: I didn’t understand how the (self) value works in "city.state = self " within the add_city() function
The self in Python is equivalent to this existing in Javascript, Java, C++ and others - and concerns the object itself. In case, you’re seeing the self within a state class method - so the self is…
-
1
votes1
answer98
viewsA: What signal to use for firing methods from a pygtk thread?
The correct is to call the functions GObject.idle_add or GObject.timeout_add from the other thread. This way the function will be called directly by GTK, without relying on signal processing.…
-
1
votes1
answer466
viewsA: Shortcut by initial letter Optionmenu in Python Tkinter
Tkinter, although it caters well for basic needs, has very few active developers, and sometimes the best documentation is to look directly into the source code (in addition to the semi-official…
-
2
votes2
answers11769
viewsA: Problem when calculating percentage (result is always "0")
Your error in the original program is on this line: porcentagem = int(ingressos / vagas) * 100 Well, tickets / vacancies, will always give a number between 0 and 1. This transformed into whole will…
-
2
votes1
answer1927
viewsA: Exercicio calculo maior numero python
in your check from 1 to 1, you are looking for splitters up to the given maximum number(k), not up to the smallest number you are checking (n): if all(n%x!=0 for x in range(2,k)): Exchange for: if…