Questions tagged as 'python-2.7'

1
answer

Python: Error translating text with api translate

I'm trying to do a translation with the api GoogleTrans ( link ). Code: # -*- coding: utf-8 -*- from googletrans import Translator translator = Translator() print translator.translate('hello', dest='pt') I get the error: UnicodeEncodeErr...
asked by 23.04.2018 / 18:15
1
answer

Sorting a list of strings in python

I need to sort a list inside it is another list containing exactly one string and a number, the problem is that I'm not getting the desired result, let's put an example if I have the list below a = [ ['c2sp1s5', 0], ['c2sp1s10', 1],...
asked by 13.12.2017 / 21:47
2
answers

using the 'any' function in python

I have 2 lists with multiple landline / cellular numbers. Example: Lista 1: ['0169924233316','01687665544','01978553322']<br> Lista 2:: ['0169924233316', '01788226541']<br> Within a for, I compare the 2 lists to find if there i...
asked by 16.10.2017 / 13:16
1
answer

Reading an XML file and printing specific fields using the Python language

I have the following XML file (actually it's just a piece of the file): <!DOCTYPE sysstat PUBLIC "DTD v2.19 sysstat //EN" "http://pagesperso-orange.fr/sebastien.godard/sysstat-2.19.dtd"> <sysstat> <sy...
asked by 02.08.2017 / 02:01
1
answer

Identify repeated indices and exchange only one of them

I have the following vector: a = [1, 2, 3, 4, 1, 3] I need to go through this vector and identify the repeated values. After identifying them, I need only one of them to be changed by a random value between 1 and 11. For example: T...
asked by 13.09.2017 / 03:07
1
answer

TypeError: POST data should be bytes, an iterable of bytes, or a file object. It can not be of type str

I'm trying to translate a code from Python 2.7 to 3.6 Code 2.7 works perfectly: from urllib2 import Request, urlopen values = """ { "exchange_code": "PLNX", "exchange_market": "BTC/USDT" } """ headers = { 'Content-Type': 'ap...
asked by 21.03.2017 / 00:23
1
answer

Doubt while while

I have the following code: # -*- coding: utf-8 -*- def soma(lista): soma_num = 0 while soma_num <= lista: soma_num += a return soma() a = [1, 2, 3, 4] print(soma(a)) I know that it will give error in line 7 and 10, s...
asked by 22.06.2016 / 07:13
1
answer

Through a tuple of 2 lists make a graph

I have 1 tuple with 2 ready lists like for example the following ones, in which the first contains dates in the format YYYYMMDD and the second contains the number of times a crime happened that day. tuplo= (['20160130', '20160230', '20160330',...
asked by 26.05.2016 / 16:34
1
answer

Error: "no module named xxxx"

I have Python installed in my pcs (Windows 7 and 8) but I can not execute any script that contains import . The error message always appears:    import error: no module named xxxx.     
asked by 12.11.2015 / 11:59
1
answer

For x in range (y) does not return right

I have a problem with a def x () in python. the Problem is "inside" it. Even though I put it right, it returns the else, no matter. I've tried everything but I could not tell because it does not return right. Here's the code. def filters...
asked by 20.05.2015 / 01:30