Questions tagged as 'python'

1
answer

Go through the dictionary in the template

I have the following view: from django.shortcuts import render def ini (request): dic = {"nombre" : "Mauro", "apellido" : "London", "sexo" : "M"} return render(request, "ini.html", dic ) and the ini.html: {% extends 'base.html' %...
asked by 11.10.2018 / 01:56
1
answer

How do I get the weight of a file with python?

I would like to know how you can get the size of a ".txt" file in Python, for example in bytes. I have been looking on the Internet and I can not find any method that is useful for this. Thank you very much.     
asked by 22.01.2018 / 20:55
1
answer

(Overloading) - Overload Operators in Python

How can I overload the (+, -, *, /, ... , //) operators on an object in python. Example: a = Vector(3, 5) b = Vector(2, 7) print(a + b) # Output: <Vector (5.000000, 12.000000)> print(b - a) # Output: <Vector (-1.000000,...
asked by 12.08.2018 / 02:38
1
answer

Consultation on 2 lists in python and mathematics

I have 2 lists lista1 = ["R1","R1","R2","R3","R4","R5","R6"] lista2 = ["Frase 1","Frase 2","Frase 3","Frase 4","Frase 5","Frase 6"] I would like ALL the 'Rx' in the list1 to be combined with ALL of the list2. Not sequentially, but randomly....
asked by 19.04.2016 / 17:50
3
answers

Compare two element-by-element vectors

I have two lists in Python: a = [1, 5, 5] b = [2, 10, 8] If 1 < 2 and 5 < 10 and 5 < 8 , that is, if each element of the list a is less than its corresponding element list b , then the variable c...
asked by 25.07.2017 / 09:33
1
answer

Change axes and a histogram units with matplotlib

Is it possible to change the units of the axis and of a histogram created with matplotlib (plt.hist), and that instead of counts represent a percentage (counts / total)? The code would be something like this: import matplotlib.pyplot as plt...
asked by 02.07.2017 / 22:15
3
answers

Classes in python

I know that this is basic, but we could say that I am a bit new in python and there are things that I do not know. I want to make a call for a function within another function, they are all within the same class. Example: Import ClassHeredada...
asked by 23.11.2016 / 00:43
2
answers

Why can not I delete an object from a list in python?

I present my code: numbers = list(range(0, 30, 2)) for i in range(0, 30): if numbers[i] % 2 == 0 and numbers[i] == 2: numbers[i] = 2 if numbers[i] % 2 == 0: numbers.remove(i) print(numbers)                Traceback...
asked by 26.12.2016 / 19:45
2
answers

Is there something like typeof in Python?

As the title says, is there a way to get the internal data type of a variable in Python 3? In C # I can compare it in the following way: var str = "Strings"; if (str.GetType() == typeof(string)) Debug.WriteLine("str es un string.");...
asked by 01.07.2016 / 18:19
1
answer

How to create a thread in Python?

I am writing a code but it has not worked as expected. A simplified version of the code is like this: from subprocess import call import time call([r"C:\Windows\System32\notepad.exe"]) time.sleep(5) call(["taskkill", "/im", "notepad.exe"])...
asked by 15.01.2016 / 18:35