Questions tagged as 'python'

1
answer

Count how many times a word in a file appears in another file

I would like to count how many times a list of words (file1) appears in another list of words (file2) with open("corpus.txt", "r") as f1, open("lexico.txt", "r") as f2: file1 = f1.read() file2 = f2.read() corpus1 = file1.split(" "...
asked by 26.09.2017 / 12:04
2
answers

How to fill in the leading zeros in Python?

In php, I know we can fill a number with zeros through printf Example: printf('%04s', 4); // Imprime: "0004" How could I do this in Python ? When I try to do this in the above way, the result is not as expected: print '...
asked by 13.08.2015 / 21:39
2
answers

Where is the class constructor in Python?

Definition of Wikipedia.    The builder is a method   which is generally responsible for allocating the necessary resources to the   of the object beyond the initial definition of the variables of   status (attributes). In Python the...
asked by 23.01.2016 / 01:26
3
answers

How to transform a String made up of numbers into a list of integers?

I have a list with a string: a = ["1, 2, 3, 4"] I want to get every number within that list, turn them into integers, and return the largest and smallest value in that list. I've already tried doing this with FOR IN like this: def...
asked by 12.12.2015 / 18:59
1
answer

Why use two server-side languages on the same system?

Why do I see many systems with two, up to three programming languages? When I see a system that migrates from one language to another, I even understand, but why do many maintain two or three programming languages? For example, I've seen...
asked by 07.01.2017 / 14:41
1
answer

Function of .pyc files in Python

If the Python language is interpreted, why are there .pyc files that are compiled bytecodes?     
asked by 25.05.2017 / 07:14
2
answers

Syntax error on another machine

I have a machine in which Python 2.6.6 is installed, in a certain part of a script I make the following command: with open('saida1.txt') as saida: for line in saida: if "]L" in saida: print line In which I search t...
asked by 16.12.2016 / 13:50
2
answers

Abstract Class in Python, how to choose implementation

I'm learning python and trying to do a program where I have an abstract class and two subclasses that implement such. I need to make another class that will choose which implementation to use depending on the user, but I can not do that. If some...
asked by 25.07.2016 / 21:39
1
answer

Function to return the source code name itself in python

Is there any function to return the source file name itself? The intent would be to create a log file, which one of the data would have the name of the source that is generating that log. If you have an error, it is easier to go directly to t...
asked by 08.05.2018 / 16:30
3
answers

Why in Python can we define an index of a Dict as a Tuple?

I noticed that in Python, we can add values of type tuple as index of a dict (dictionary). Example: test = {} test[(1, 2, 3)] = ("um", "dois", "tres") print test // {(1, 2, 3): ('um', 'dois', 'tres')} And after the defini...
asked by 17.06.2015 / 17:17