Posts by jsbueno • 30,668 points
811 posts
-
0
votes1
answer282
viewsA: Generate XML file of more than 1 Mi of records with Xml.etree.elementtree in python
So - the way you’re doing, there are two things that need all the records in memory at the same time - one of them is Pandas - it will read all your database records and create a dataframe with all…
-
7
votes2
answers242
viewsA: What is In[]: and Out[]:?
The In[]: is how some interactive environments put the prompt for you to type a Python expression. It is in place of the >>>, that you see when you call "Python" or "Idle". Already the…
-
1
votes1
answer90
viewsA: Pygame is not drawing an object
You haven’t put all the mainloop code - but most likely the only problem is that you’re using a "global" variable for Bullet, but in the wrong way. When there is a need for a global variable, it…
-
4
votes2
answers573
viewsA: Python / Pandas - error reading Arq. csv ( path)
Trade in all your "\" for "\\", or by "/". the problem is that the character " " is used in programming languages, such as C or Python to indicate a special character in a string, and only if the…
-
2
votes2
answers214
viewsA: Why does the value always return 0?
In C, the program at the time of execution does not "know" anything about variable size - with some luck the compiler does not let your program compile. The printf and scanf although very used, are…
-
0
votes2
answers400
viewsA: Global variable for Python directory storage
Variables in a module, as well as functions and classes, can be imported in Python. So if your project has a "config.py" file that has a "data_path" variable, anywhere you want to use it, just do…
-
5
votes1
answer122
viewsA: Need to use @classmethod in __new__
The special methods, with names between two __ as __new__ and __init__ are special for a reason: they are part of the language specification - so the rules for these methods are at least as good as…
-
1
votes2
answers1918
viewsA: What is the best database for Python 3?
The question will probably be closed because it is not directly linked to programming, and every question related to "what is the best..." involves subjective criteria. However, there is an answer…
-
0
votes1
answer136
viewsA: When running two Django projects at the same time, one of the two users is dropped
By default, as it is in Giovanni’s comment, user login and session information is stored in the database by Django’s Session middleware. As they are the same database, and without any additional…
-
10
votes1
answer408
viewsA: What is a virtual subclass in Python and what are its advantages?
TL;DR: - updating - The main motivation for creating this language functionality (not the call to .register, and yes, the whole concept and mechanism of "virtual subclassing") was almost certainly…
-
2
votes2
answers376
viewsA: python search
Let’s go in pieces... First, if your goal is just to return True if the element is found, you shouldn’t be using the test: if alvo in lista: in your code: this is the way normal Python to search for…
-
2
votes1
answer85
viewsA: Is it possible to use python’s LIB socket to make communications as a websocket?
Answering only the question "Is it possible to use python’s LIB socket to make communications as a websocket?" Yes - is it possible to. After all, websockets are a higher-level protocol, which use…
-
3
votes1
answer90
viewsA: Threads do not run - Python
Probably the thread is started, and its surprise comes from the fact that its variable _limites will be the even object within each thread. You’re passing a list to a thread - the other threads will…
-
0
votes1
answer259
viewsA: Python - stack - - balancing
You have a problem in the first "if" already - "if i is different from "(" OR other than "[" ..." - ra, I cannot be EQUAL to "(" AND "[" at the same time - so the condition will always be true - and…
-
5
votes1
answer97
viewsA: List exiting order while looping
The problem is that you are trying to insert your text data directly into the query, and you are using the equivalent of an 'SQL Injection" there - simply one of the text strings you are putting…
-
7
votes4
answers138
viewsA: Count inside an array with values from another array
You don’t need two for unless you are going to count 'manually' - without using the menu .count. The correct thing is to call the method .count of array1, passing each word you want to tell there…
-
2
votes2
answers81
views -
1
votes2
answers112
viewsA: Separate a string into blocks according to similarity
The problem with your code is that it counts all occurrences of a given letter in the string, regardless of its position (the value returned by the method count) - and does not take into account…
-
3
votes2
answers327
viewsA: Delete Root Directory in Python
The function os.rmdir directly calls the OS Api equivalent to this call, and traditionally this call only erases even an empty directory. However, the Python language includes, in addition to these…
-
0
votes1
answer34
viewsA: Python+HTML+Sqlalchemy error
Setting parameters like you created in the view requires the parameter ("doc") to be passed in the path part of the URL, not as given from a GET. That is, this configuration is expecting something…
-
2
votes1
answer55
viewsA: my python file is not being written
You call the method write of the open file passing strange arguments. The method write of file type objects accepts a single argument, no name, with the text that must be written in the file.…
-
1
votes2
answers717
viewsA: Read a.dat file and assign names to its columns using Pandas
The "dataframe" in Pandas, which is the data structure that binds columns with name to the data itself accepts, to be constructed, precisely, a "two-dimensional sequence" with the data as an…
-
1
votes1
answer119
viewsA: 2 decorators in a Python method
Precisely. In one method, the self will be inserted as first argument in the call. In your check you check the type of all the past arguments - and the type of the first will always be equal to the…
-
4
votes1
answer351
viewsA: Compression and Reading of CSV file with large-scale rows x columns via Pandas
If you have a file . csv want to view its contents, the best option is to open it in a spreadsheet, such as Libreoffice or Excel. If the number of lines exceeds what your spreadsheet program can…
-
5
votes3
answers2034
viewsA: Handle cmd files using python
Yes, in Python it would be easy to create a program to manage other scripts . bat, and create them and describe them according to IP. But it would be even easier, and more maintainable, to exchange…
-
2
votes1
answer267
viewsA: Serialize Python Objects in JSON
TL;DR: Unless you need to pass the data to a program written in another language, or edit manually as a text file, use pickle instead of json to save object states. Then the excerpt crucial that was…
-
5
votes1
answer1389
viewsA: Problem to convert ANSI to UTF-8 in Python 3
What is "not staying right"? If you don’t show what’s wrong, there’s no way to say right. In fact, "ANSI encoding" isn’t even a standard - in Python, it’s only valid on Windows, and gives error on…
-
1
votes1
answer40
viewsA: Function that returns a new instance of a class
look - your whole project - does some strange things to manipulate objects - and the code is not all there, I went to see in github, because of the contact we had in another question -…
-
1
votes1
answer454
viewsA: Insert values to a 3D numpy array
A simple way seems to be to create a dictionary, where each pair of coordinates x, y taken from the X and Y arrays is the key, and the value of z is the corresponding value. After the operations to…
-
1
votes1
answer198
viewsA: Maintaining the relationship between vector elements after a Python sorting
The simplest way is to associate the X and Y elements in pairs, and then sort those pairs - you can disassociate the pairs into new X1 and Y1 vectors later. If you are not using numpy, the easiest…
-
2
votes1
answer603
viewsA: How to extract information from a 'cnab' file using python?
It’s a file type with fixed field sizes - you read a line, and use Python’s slice syntax to extract the value from each field - For example, for the line: 39900000 2957742120001329999999999…
-
1
votes1
answer190
views -
2
votes1
answer47
viewsA: Python Virtualenv showing computer libs
Good - the main problem is that virtualenv never should be bundled with the other versioned files in GIT. What needs to be in git is the file that lists the dependencies - in general the…
-
7
votes2
answers312
viewsA: Optimizing Imports in python
The ideal thing is to have a schema to make a dynamic import of files in the same folder. This code can run in the file __init__ from a folder - and as soon as you import that folder as a package,…
-
2
votes1
answer276
viewsA: How to use print in the graphical interface?
The Python 3 print is just a function - although widely used, which converts the parameters passed in sequence to strings, and writes these strings to the file sys.stdout by default. When we use a…
-
3
votes2
answers962
viewsA: Search Only the numbers of a String using Regex in python
import re proc = " 5080847-62.2018.4.04.7100 033/2.17.0001000-7" numeros = "".join(re.findall("\d+", proc)) print(numeros) Parts of a regular expression find "blocks" of the text you want to use…
-
4
votes1
answer762
viewsA: Implement Thread in Python
Threading would work in this case - since the longest delay is the latency and response time of the twitter API. Threading does not work well in Python in almost no other scenario due to a number of…
-
4
votes1
answer191
viewsA: P2P sharing with PHP?
PHP is a language that has been created with a focus on generating dynamic HTML pages, and although it has evolved into a general-purpose language, it has not incorporated the best choice of tools…
-
2
votes1
answer1417
viewsA: Mount SQL query in Python3 from data in a dictionary
In Python there are several ways to manipulate strings and interpolate variables, and concatenate several strings with + is the worst of them. Your error is that the string representation of a list…
-
1
votes1
answer403
viewsA: ftplib and pyftpdlib communication
Look at - I can understand where the problem is, but I don’t know how to give you the solution. In the FTP protocol, and other protocols on TCP (such as HTTP itself), when the first connection is…
-
5
votes2
answers462
viewsA: Assignment of Boolean within a ternary operator
TL;DR: The ternary operator in Python is written in the form: resultado_pro_caso_verdadeito if condicao else resultado_pro_caso_falso With the keywords if...else separating the 3 terms. In Python,…
-
5
votes1
answer602
viewsA: Try & Except, correct way
First thing is to never use one except with nothing - in Python 3 (which is what you should be using - Python 2 is incompatible and is a language at the line-out limit -use Python 3), empty "except"…
-
2
votes1
answer149
viewsA: Is it possible to receive real-time information from Chrome in Python?
There is no "proxy embedded" in Chrome. If you’re seeing a menu or proxy options in your Chrome developer tool interface, it’s because you have some proxy extension installed in your browser. What…
-
0
votes1
answer209
viewsA: Check if there is object in instantancy
Whether the call can return an object or None, you compare by checking if the returned object is None with the operator is: select_me = User.select_me(request) if select_me is None: me, random,…
-
9
votes1
answer83
viewsA: Is it possible to use logical operators within "Cout"? - C++
What happens is that operators >> and << which are "shift right" and "shift left" are reset to the "Cout" object and work to "channel" the objects you want to put in the standard output.…
-
6
votes1
answer799
viewsA: How to export classes, methods or constants in a Python module
Inside the folder "models" your Python modules will see only the files and folders inside, and whatever is on PYTHONPATH. Then, you use either the full name of the "Domain" folder, including the…
-
5
votes1
answer196
viewsA: Class within class, is it possible? (Python)
It’s possible, but it has limited usefulness: it only serves when you want to use the inner class as a "namespace", and you’ll never want to create an instance of it. Only correct. For example, when…
-
0
votes1
answer59
viewsA: What does offset mean in Pillow?
"offset" means "offset" - The method .getoffset of objects of type "Font" inside the module ImageFont requires a text string - and returns the position, in pixels, from which it would begin to draw…
-
2
votes1
answer26
viewsA: I cannot use functions and search for class attribute of an object
The prblema is that in your code, at no point do you create a new object from class character - You gather information from the fields in a dictionary called info, and ignore this questionnaire, and…
-
0
votes1
answer34
viewsA: Error while getting Bytearray from.3gp file on Android/Java
This is normal - not all data types are created to have a textual representation. In this case, you are dealing with a binary file type - any value can have a value of 0 up to 255, which does not…