Questions tagged as 'python-3.x'

1
answer

Doubt with sorted when sorting list of integers in the form of strings

I have this list A : A = ['-1', '-2', '-2', '1', '1', '10', '100', '20', '4'] If I put sorted(A) I get this ['1', '1', '-1', '20', '4', '-2', '-2', '10', '100'] I tried this list: lista = ['3', '2', '5', '6', '7'] and...
asked by 31.01.2018 / 05:30
2
answers

Open file from another location by relative path

I need to open a file that is in another directory that is being worked on, I tried with: open("../carpeta/subcarpeta1/subcarpeta2/archivo.log") but when I run the script I get:    FileNotFoundError: [Errno 2] No such file or directory:...
asked by 30.01.2018 / 05:27
2
answers

execute javascript in python

When accessing a web via python, is there a way to show the response code of a javascript? what the user sees I have this: import mechanicalsoup browser = mechanicalsoup.StatefulBrowser() print(browser.open("https://www.web.com/")) print(br...
asked by 31.01.2018 / 23:07
1
answer

Problem with the use of python classes

When I run my program it gives me this error:    new = colony.Colonia (self .__ tasks, self .__ times)   UnboundLocalError: local variable 'colony' referenced before assignment my class is the following: import tareas import hormiga imp...
asked by 30.01.2018 / 20:35
1
answer

How can I pass a string of bytes to PDF with Python?

I am connecting to an API in which you return a PDF in bytes format and I want to know if there is any simple way to format it in PDF to be able to download it. My problem is that it returns a string of data in this format: b'%PDF-1.7 \n%\x...
asked by 22.02.2018 / 09:38
3
answers

How to capture keyboard or key combination in python3?

Hi, I would like to know how I can capture key combinations in python3 , for example by pressing Ctrl + A execute a method in a class. It's for a console program and this is what I've found so far of information. #! /usr/bin/env python3...
asked by 18.05.2017 / 16:34
1
answer

Inheritance in the classes

I have a question about the classes, is it about if having two classes (a father and another daughter) could get a list (global) that is in the father and join new elements from the daughter? And if that is how I could do it, then I have mana...
asked by 30.12.2018 / 20:49
1
answer

How to generate a json of an object that comes from forms.ModelForm

Hi, I would like to create and save an object in the database which has arguments args and kwargs . the arguments args and kwargs must obey the format JSON , I have the following: class ProgramarActividadForm(f...
asked by 20.01.2016 / 14:28
1
answer

Sort treeview columns

I have a thread in which I asked how to generate a treeview from a panda dataframe in python. The thread is this: How to use Tkinter ProgressBar My problem now is that I do not know how to implement a function that orders each column whe...
asked by 13.09.2018 / 11:29
1
answer

DataFrame cleanup

I have a dataframe where there is an index and several columns, in the columns there are empty rows (my idea is not to eliminate them, but to fill them, since I do not want to lose so much data) I know a lot of the information of that column (wi...
asked by 29.08.2018 / 15:52