Posts by jsbueno • 30,668 points
811 posts
-
0
votes3
answers131
viewsA: Html, icon respecting page background color
This case has nothing to do with HTML - you need to edit the image so it has a transparent background. If you treat the image in GIMP, you can open the file, go to Camada->Adicionar canal alfa,…
-
1
votes3
answers7146
viewsA: How to run the method inside a.py file by linux terminal
It is best to write your program in Python so that it implements the parameters you need in the syntax most used in command-line programs. Then, you mark your Python file as executable, and you can…
-
0
votes1
answer1701
viewsA: Delete certain lines from a python . csv
The idea of how to delete lines from CSV file itself is more or less easy to understand - but you used your CSV file in such a different way than the most appropriate way of using it, which - at…
-
1
votes1
answer504
viewsA: How to use joblib in Python for parallelism?
Threads create a "parallel processing line" within your program - but they don’t work magic: they all use resources and do exactly as you say. Ensure that a given program does not create more than…
-
2
votes2
answers1008
viewsA: What is " x" in the Python strings?
The `" Xhh" inside a string indicates that the next two characters (initialized by "H") will be interpreted as hexadecimal digits, and therefore is a way to represent any arbitrary byte inside a…
-
4
votes1
answer962
viewsA: Web Scraping - convert HTML table to python Dict
Beautifullsoup is being used redundantly there - you just find the beginning of the table, and then use "brute force" to separate all the elements by "; ", and then treat the result as plain text.…
-
3
votes3
answers2710
viewsA: get the 3 largest numbers from a python list
You have two problems there. One of them is precisely that you are limiting the data of the list twice: when calling the function, you must pass its complete list, out of order -and it will return…
-
6
votes2
answers12076
viewsA: How to use Python comma instead of a dot
Quick, dirty approach - "str.replace": Python’s string handling facilities allow you to turn the number into a string, and replace the "." character with the ",". Just do something like:…
-
8
votes1
answer1237
viewsA: Does the type annotation in a function not guarantee the type in Python 3?
Yes - this is the expected and desired behavior of a Python function. Possible typing tips with syntax def x(a: int, b: int)->int: - are just that: tips. There are some programs that check…
-
1
votes1
answer2840
viewsA: Sending files through sockets - Python
You have to open the file in binary mode - mainly if you are using Python 3.x - this is done by placing the letter "b" after "w": fyle = open(flname,'wb') (Also no "+" is required if you will only…
-
1
votes2
answers629
viewsA: How to implement a priority queue that still meets other requirements?
I can think of some ways to solve this - but it’s complicated: a professional development task - it would be pretty long to answer here. And - suddenly time would be better engaged in creating a…
-
5
votes2
answers876
viewsA: Is it possible for me to create a runtime class in Python?
In Python, it is trivial to create runtime classes - and with some work and care, you can even create instrumented classes with ORM (Relational Object Mapping) functionalities that work well. Your…
-
1
votes1
answer365
viewsA: How to create an SQL function that calls a script in python?
If your database is Postgresql you can put a PL/Python function right inside the database - the documentation is here: https://www.postgresql.org/docs/9.0/static/plpython.html I don’t know if Python…
-
3
votes2
answers1130
viewsA: How to replace 1 bit of an integer without changing the other neighboring bits?
The C language even allows us to use structand union to be able to direct the value of one or more bits with the operator =. This functionality is rarely used - and anyway, requires you to define a…
-
1
votes1
answer39
viewsA: Error compiling Caffe/Pycaffe
Yes - you did not isntalou the packages with the headers of these libraries on the system, so you can compile something with them. Whenever you build a package - and sometimes a clean Python "Pip…
-
5
votes2
answers441
viewsA: Python dot notation ( methods )
Python dot notation is used to retrieve object attributes. In particular in Python, there is no distinction at the moment when you use the point between an "attribute" and a "method" - as in Python…
-
1
votes3
answers281
viewsA: Problem with pointer and recursive function
The compiler does no magic - if you want to return the value that the recursive call to search find for the function that called search for the first time, explicitly place this Return in the code.…
-
2
votes1
answer2487
viewsA: Reading a bitmap image
Ok - basically, let the "fscanf" go - it’s a penada auxiliary function mainly to read files cuj content be text, and in this case can more mess than help. This answer gives a general outline with…
-
18
votes11
answers38715
viewsA: How to check if the variable string value is number?
Python strings have an "isdigit method": case.isdigit() - that returns True or False. This method is enough if you want only positive integers - however, if you want to validate also entering…
-
2
votes2
answers52
viewsA: Transform long/varchar data to string
If that was your problem, you’d just do len(str(e)) - but it wouldn’t solve anything - you would just print out the number number number number "and" (that is, if 400 records had been read, this…
-
4
votes2
answers324
viewsA: How do I use the same argument/parameter in two different functions?
Don’t try to do everything in a single row - simply assign variables to your parameters typed with input: def seno1(x, n): ... def cos1(x,n): ... # e mais abaixo no seu código ponha o trecho: x =…
-
3
votes2
answers2822
viewsA: How to print an integer vector by removing the last comma in Python 3?
Python has this idea of having a way that is the obvious way to solve things - but not always the obvious is so obvious at first glance. This problem always gets ugly in other languages, just…
-
4
votes2
answers342
viewsA: Doubts about the realloc function
In C the space you reserve for the dasdos and how you effectively use this data are two separate things. Since sizeof(char) is always 1, you in fact, when calling realloc left only 3 bytes reserved…
-
0
votes2
answers495
viewsA: Python takes the first column value instead of the last one
Python’s SQL calls, in any driver, are made in two parts: in one you call the cursor’s "run" method, as you do - this call only returns the number of results found, not the results themselves - so…
-
9
votes3
answers68693
viewsA: How to create a python array
Python does not have, despite having several native types, a "matrix" type neither native, nor in its standard library. numpy For any serious work involving matrices (that is, you have a problem…
-
1
votes1
answer96
viewsA: Average True Range Calculation
Without you saying how much the difference is, it is impossible to answer this question with certainty - but most likely the difference is due to the natural error arising from how we represent the…
-
4
votes1
answer213
viewsA: How to make the elements of a tuple to be the arguments of a python function?
Taking your first example, just do: tupla=(arg1,arg2,arg3) def f(*args): for i in args: print(i) f(*tupla) The operator * as a parameter prefix, or element of a sequence or iterator, "unfolds" the…
-
2
votes1
answer986
viewsA: How do I use the find function to find an entry in a Python dictionary (json)?
It’s not that simple: when JSON is still a string, i.e., srialized - you can use find (it’s a Python string method), and find the position of the characters you want - but that way you don’t know…
-
1
votes1
answer2433
viewsA: Graph using python-igraph with attributes per node and edges
I didn’t know this igraph - apparently it is to library for working with Python graphs. So, taking a look at the documentation and experimenting with the interactive Python prompt (This is the…
-
3
votes1
answer64
viewsA: Assemble structure with hexadecimal data
You don’t say what types of data the variables will be - assuming they are always integers without signal, this answer works - by the way, there are no "hexadecimal data" - there are data that are…
-
5
votes1
answer45
viewsA: Relationship Database
Yes, "N:N". Simply a table with 3 fields: id, id_question, id_answer - and preferably everything should be an index, so you can do the two-way search. Depending on how you are using, you will not…
-
7
votes3
answers16319
views -
5
votes2
answers8828
viewsA: After all, what is the function Repr in python for?
The repr calls for the internal method __repr__ object. Its idea is to return a string representation of any object - but thinking more about the programmer than the end user of the program. Above…
-
1
votes1
answer194
viewsA: Scraping in Python. Mounting an Insert
Starting from the beginning - in general we would use the requests and beautifulsoup modules to read the content of a web page - but it is also possible to do yes. We have another problem that these…
-
0
votes1
answer39
viewsA: Build Java code using Python
String a string "Wont cut it" - you will have to create a minimalist parser - possibly even make a regular expression - that reads the file, find the method statements, start and end lines (for…
-
0
votes1
answer45
viewsA: There is Binding of data in Python
It doesn’t exist in the standard library - but it’s something relatively easy to do by placing the code for it in your base class - and calling the constructor of that class. Unfortunately this…
-
1
votes1
answer4423
viewsA: CSV file reading and data storage in a vector
dados = {} with open("arquivo.CSV") as arquivocsv: ler = csv.DictReader(arquivocsv, delimiter=",") for linha in ler: for chave, valor in linha.items(): if chave not in dados: dados[chave] = []…
-
4
votes2
answers534
viewsA: How to run a loop until the lines of a given.txt file end
In Python, the object itself representing an open file is made to work directly with a loop as you speak. For example, a program to print each row of a file is simply: nome = input("Digite o nome do…
-
26
votes3
answers22473
viewsA: What is "with" in Python for?
The command with serves to facilitate the writing of any code block that involves resources that need to be "finalized" (i.e., restored, released, closed, etc... ) after the block is terminated -…
-
2
votes1
answer3084
viewsA: What are the ascii codes of the arrow keys on the keyboard?
These keys do not have "ASCII" code. The ASCII table consists of 128 characters, send 32 control and 96 printable - and the control ones contain only "digitable" keys - type "enter", "tab" - and…
-
11
votes2
answers94597
viewsA: How to break the line?
Just put the line break character where you want the break. This character is typed by escaping the letter "n" with a backslash - the famous sequence " n" - when the Python parser finds this…
-
1
votes1
answer2606
viewsA: How to format float and range input in Python 2?
You should use the "while" construction to keep asking while the input is not good, and the "if" command with conditions to check this. Another good practice, to avoid duplication of code is to use…
-
1
votes1
answer540
viewsA: Insert in Tree B with a large number C/C++
The problem with this code is that you don’t understand how strings work in C, and how they are represented in memory. You can’t just do something like: char *a = "teste"; int b = (int) a; As I…
-
2
votes1
answer167
viewsA: Socket-python syntax error
This Except syntax is not valid in Python 3- this is the old Python 2 syntax, and even in new code made to run in Python 2 it is still recommended to use the new style: try: ... except NomeDoErro as…
-
2
votes2
answers12290
viewsA: python - covery game/college project
Answering specific questions of the implementation in the question, about the game of the hedge Ok - I’ll leave the other answer as a reference for anyone who wants to implement the Python Cover…
-
5
votes2
answers12290
viewsA: python - covery game/college project
Creating a snake game in the terminal, from scratch Reviewing your question - I didn’t really answer you need - it’s a college exercise reconstructing the steps of the covering from the direction -…
-
5
votes1
answer1356
viewsA: Python serial vs multiprocessing vs threading code
So - the problem is that your above programs are not parallel - they are serial. The question of parallelizing a code is not so trivial, for some problems it can be quite difficult, and above all,…
-
3
votes1
answer2731
viewsA: Accent error while saving Python file
So - the biggest problem there is that you have at hand an object list, returned by the "Reader" iteration - and is trying to write this list directly in an output text file, converging it in string…
-
5
votes1
answer3970
viewsA: What are built-in functions? And what is your difference from reserved words?
Very good question - let’s put it this way: Python seeks to be an elegant language. In this sense, the key words of the language are what enable its mechanics: conditional with "if", "Elif" and…
-
5
votes2
answers15896
viewsA: How to stop an execution in Python?
Use the "input" function - it waits until the user type enter (it can type more text before pressing enter, but if you are not going to do anything with this text, it is indifferent):…