Most voted "python-3.x" questions
Python 3 is the latest version of the Python programming language and was formally released on December 3, 2008.
Learn more…3,274 questions
Sort by count of
-
0
votes1
answer123
viewsProblems when encrypting text with matrices
Here comes the code: import numpy as np def invert(matrix): try: new = list(np.linalg.inv(matrix)) except np.linalg.LinAlgError: return "Matrix not inversible!" for i in range(len(new)): new[i] =…
python-3.xasked 6 years, 3 months ago nelson450 118 -
0
votes2
answers217
viewsDefault list replacement in regex
People need to turn a string into a list, in a peculiar way. I found in this post what I need to do. But I’m lost on the regex applied. I have numerous string in the following format: ["DECRETO Nº…
-
0
votes1
answer110
viewsRegex words in lowercase
I have a Regex that removes characters that are not letters or space for a Python application. Ex: var = re.sub('[^a-zA-Z \\\]', '', "abc Abc aBC cde123 def-ghi $?!123") Is returning: abc Abc aBC…
-
0
votes0
answers77
viewsCode runs on Jupyter and Error VSC
I run this code by Jupyter and it runs normally, but when I try to run this same code in Visual Studio Code it gives the following error: "File b'Salaries.csv' does not exist" says that the file…
-
0
votes1
answer1348
viewsHow to check parentheses of an algebraic expression?
I’m trying to solve a problem of a course I’m doing but I’m not able to imagine a way to solve. I need to create a program where the user type any expression that uses parentheses. My application…
python-3.xasked 6 years, 3 months ago Igor Pompeo 37 -
0
votes1
answer741
viewsError in pycharm
Good morning, everyone, In "file>Settings>project: ... > project interpreter" the environment has been configured: "/home/Brito/projetos/venv/saj_projects/bin/python" And I’m experiencing…
-
0
votes2
answers522
viewsRemove function in one list alters elements in another Python3
def almostIncreasingSequence(sequence): x = sequence for i in range(len(x)): sequence = x cont = 0 y = False sequence.remove(sequence[i]) for j in range(len(sequence)): try: if sequence[j] <…
-
0
votes1
answer915
viewsSave Json dictionary to txt
How can I save a. json dictionary of a requests in txt. I tried to do it this way but it didn’t work. import requests import json url = requests.…
-
0
votes1
answer224
viewsHow to save an xml string to a document?
I want to save my xml which is a str(return of an API) in a . xml file, but when I do this it does not fuciona anyone could help me? from xml.dom import minidom cont = minidom.parseString(xml)…
-
0
votes1
answer80
viewsBuy values from the list
I’m having a little problem with a list. I have a txt with some information (log failure of a system) and wanted python to print for me this flaw with their "translation" example: If cod_error ==…
-
0
votes1
answer1976
viewsCreate a mini CRUD (basic) in Python Tkinter
my name is Victor, I’ve researched the Treeview but I couldn’t do anything, but my goal is this one: I made an illustrated example follows the code: from tkinter import* class principal: def…
-
0
votes1
answer86
viewsFind a value in a given column in a.txt file
I am trying to search for a value at a certain position in the column of a text file and generating another file with these lines, but without success Follows the code: arquivo = open('arquivo.txt',…
-
0
votes0
answers35
viewsHow to change the password for an IP list?
How do I change the user and password of a large number of servers with different ips, rather than a single ip? Follows the code: # Copyright 2016 Hewlett Packard Enterprise Development LP # #…
-
0
votes1
answer549
viewsPandas: How to merge two data frames?
Good morning Everybody! I count on your help again. I have 2 CSV, as below: # f1.csv num ano 76971 1975 76969 1975 76968 1975 76966 1975 76964 1975 76963 1975 76960 1975 and # f2.csv num ano dou url…
-
0
votes1
answer103
viewsGenerate a random combination on each line
I made a number generator that looked like this: import random import math for i in range(10): c1 = (random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9])) c2 = (random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9])) c3…
-
0
votes1
answer183
viewsExplain template location in Django
I’m using Django for a project, but I came across a question. In my file settings.py I have the following configuration of templates: TEMPLATES = [ { 'BACKEND':…
-
0
votes1
answer2644
viewsDate calculation with Python
I have a script that needs to make a difference between 2 collected dates of some files In this case the script collects the date of a file. txt (dt_log) and the current Systema date (dt_sys) and my…
-
0
votes2
answers2500
viewsHow to use a function within another function in python3?
I wanted to take the result of the name function input and use inside the intro function, but the way I’m trying, I get just one error. code: def nome(): name = str(input('Poderia nos dizer seu…
-
0
votes0
answers81
viewshow I save variable values in a mysql database
I’m trying to create a facial recognition system using Opencv to record users' access to the school’s lab but the problem is that I’m not being able to save the access time information of each user…
-
0
votes0
answers108
viewshow to solve problems with "referenced before assignment"?
from tkinter import * from tkinter import messagebox jan = Tk() jan.title("Pontuacao") jan.geometry("200x200") pontos = 0 a = Label(jan, text="pontos") a.place(x=0,y=0) def aumentar_pontos(): pontos…
-
0
votes1
answer804
viewsHow to create a list of objects of variable size, and assign their attributes without listing them one by one?
I need to read a file and pass your information to a list of objects. The file is in format: "attribute 1", "attribute 2", "attribute 3", ...,"attribute" each row contains the information of a…
-
0
votes1
answer82
viewsHow do I write a tabular file in an instance of Azure Data Lake Store with the Python API?
Suppose I have an instance of Data Lake Store in my Azure inscription and I would like to create a Python script to write a tabular file with tab (CSV type or similar) in that instance. Without…
-
0
votes1
answer65
viewsHow to copy a. txt file that updates the name daily - Python
I need to copy a TXT file daily from one folder to another, but the file is renamed according to the date, the end after the "_" always changes with the date value. Ex: _20181205.txt, _20181206.txt,…
-
0
votes2
answers1150
viewsCheck if a file exists within a Python IF
Good afternoon, I’d like to make a check: If a file exists - delete If there is no following the flow of the program. I’m using Pycharm, you’re returning syntax error, But I’ve already put four…
-
0
votes1
answer1733
viewserror: (-215:Assertion failed) ! Empty() in Function 'detectMultiScale'
I’m totally layy on linux and I’m trying to use opencv version 3.4.2 with python 3.5.2 on linux Mint to run an example facial detection code. Below the code: import numpy as np import cv2…
-
0
votes0
answers30
viewsstart threads together python3
How to start threads together ? Context : I have a class that extends the Threading.Thread. However, when I start threads, it seems to me that they are running sequentially. Example : 1. Log in for;…
python-3.xasked 6 years, 2 months ago Rafael Anderson lobo 107 -
0
votes1
answer792
viewsHow to remove a dropdown from within a list
Good Afternoon, I have a problem with a job that is: I have a function that needs lists to organize various elements according to predefined characteristics. My question is how to remove a dropdown…
-
0
votes1
answer448
viewsFind the largest sequence using Python
I have the following code: import collections num = int(input('Digite um número inteiro: ')) #Inputar número inteiro binario = bin(num)[2:] #Cortar o 0b sequence = binario collection =…
-
0
votes1
answer47
viewsError sending package with scapy
Guys I’m taking the course Python for Hackers, but I came across a problem in the class about HOW TO CREATE YOUR FIRST PACKAGE. I can create the package, but I can’t send it through mr(), sr1(),…
python-3.xasked 6 years, 2 months ago Gustavo Luiz Bispo dos Santos 3 -
0
votes1
answer110
viewsPass a given sequence of times in Python 3
I have the following sequence: {1,4,12,28,45,22} I need a variable for example: seguinte = input(num('Insira um número: ')) According to the number given, he would pass the last item to the…
-
0
votes1
answer27
viewsunittest.mock: How can I use datetime.datetime.now with different calls in the same method?
How can I proceed with a mock test on datetime.datetime.now with different calls in the same method? In my test is returned the current date. Follow an example of the code, to facilitate help.…
-
0
votes2
answers135
viewsCompare Python index independent lists
Good afternoon, I need to compare 2 lists and when a certain value in the 'name' field of the list 1 does not exist in the 'name' field of the list 2 perform some function. The way I did is…
-
0
votes1
answer701
viewsCalculate the number of even numbers in a tuple recursively
I need help creating a recursive function that finds and adds the even elements of a tuple, I would really appreciate the help. def conta_pares(t): '''conta_pares : tuplo -> inteiro recebe tuplo…
-
0
votes1
answer112
viewsCommand that replaces Team.Leep?
I am making a program that detects colors and shapes of objects with a camera, when being recognized the format and the color configured, the program makes the control of the GPIOS in which I…
-
0
votes2
answers344
viewsname is not defined - name/variable undefined, Tkinter and slite3 help
I’m starting to study sqlite3 in Marra, and this being difficult, but I already got a few things, the problem is that when compiling the program appears the following error: "name 'adic' is not…
-
0
votes1
answer1391
viewsError installing python library
I’m having a problem trying to install the library pyaudio in Windows. The following result appears: Command "c: users digia appdata local Programs python python37-32 python.exe -u -c "import…
-
0
votes0
answers99
viewsI can’t use Schedule
I’ve already executed the command pip install schedule and the pip3 install schedule but when I try to import Schedule import schedule The following error appears: Modulenotfounderror: No module…
-
0
votes4
answers197
viewsRemove comment tag and your content in Beautifulsoup 4
How do I remove the comment tag along with its content with bs4 ? <div class="foo"> A Arara é um animal voador. <!-- <p>Animais Nome: Arara Idade: 12 anos e 9 meses Tempo de Vida: 15…
-
0
votes1
answer782
viewsPython asyncio and threading
I’m studying the module asyncio of Python and there is the function run_coroutine_threadsafe which should be executed in a different thread than the event loop. Follow my script: #!usr/bin/python3 #…
-
0
votes1
answer39
viewsPrint multiple lists each in a column
I have five lists that were extracted from an Excel table in CSV. I would like to know how I do to print them in the terminal next to each other, I believe it can be done with a loop for, but I…
python-3.xasked 5 years, 10 months ago Rodrigo Ferraz 309 -
0
votes2
answers1580
viewsHow to assign values to an undefined amount of python variables?
To assign values to multiple variables just follow this structure: a, b, c = 1, 2, 3; This I know, but what if for example I want to store several values that came from an input without knowing the…
-
0
votes3
answers51
viewssend temp_var_node value to Mysql database
I want to send the temperature value in OPCUA to the Mysql database, in this case the value of temp_var_node, my code is as follows: import sys sys.path.insert(0, "..") import time import datetime…
python-3.xasked 6 years, 2 months ago Sergio Nunes 351 -
0
votes2
answers1130
viewsProblems with using include in Django
I’m having trouble with the include function, according to the Django documentation, the syntax is include(module, namespace=None), include(pattern_list),include((pattern_list, app_namespace),…
-
0
votes1
answer50
viewssort list of dictionaries by key that contains None key
How can I sort a list of dictionaries by a certain key when within those dictionaries there is one with the key None? Example: mylist = [{'category': 'director'}, {'category': 'manager'},…
-
0
votes0
answers42
viewsHow to insert MOD 1000000007 into Python code
I understand that MOD 10 9 +7 is used when decimal values are extremely large. And to simplify is applied the: %10 9+7. However, I would like to understand the range of values in which MOD 10 9+7 is…
-
0
votes3
answers5205
viewsPython - Select 2 columns from a DF and sort them
I am new in the world of programming, and I am doing some studies with the aim of gaining knowledge in the area of Data Science. Come on... I have a Dataframe with a lot of information, among it…
python-3.xasked 6 years, 2 months ago Leandro Baruch 3 -
0
votes3
answers583
viewsMachine Learning Python
I started in the course of Machine Learning and in exercise I’m having difficulty because it is returning me a silly error that I can not find the solution. from sklearn.model_selection import…
-
0
votes1
answer455
viewsDjango Session, emite: Object of type '' is not JSON serializable
I am creating a student but when I try to save it within a session, returns me the following error: Object of type 'Student' is not JSON serializable In Settings.py: INSTALLED_APPS = […
-
0
votes1
answer100
viewsDoubt about Python methods and classes
I have the Login class and created an instance of it in the Main class, with the instance I am calling the start method, but in the start method when clicking the 'Log in' button the…
-
0
votes1
answer70
viewsI’m getting None in output
l = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] num = int(input(print("Choose a number: "))) new_list = [] for i in l: if i < num: new_list.append(i) print(new_list) I’m doing this exercise that asks…