Questions tagged as 'python'

1
answer

In Python is there any debug function equivalent to PHP's "print_r" or "var_dump"?

In Python is there any debug function equivalent to print_r or var_dump of PHP? For example, in PHP: $valor = 'Hello'; var_dump($valor); string(5)'Hello' In Python would have some similar function for debug?     
asked by 10.01.2017 / 16:54
1
answer

time datetime.datetime.now ()

I'm doing a script where I measure the performance of a query in a database. The code is as follows: start = datetime.datetime.now() //CONSULTA AQUI end = datetime.datetime.now() print "Time taken: %s"%(end - start, ) The program returne...
asked by 12.01.2017 / 18:17
1
answer

Regex in Find () function in python

I need to use a regex in the Find() function in Python for example, if I use within a loop : arq = open("arquivo.txt","rb") var = arq.readline() a = var.find("abc.*def") It will be looking at the line "abc something (. *) de...
asked by 19.12.2016 / 19:19
1
answer

Open text file in Python package

I'm creating a Python package where one of my programs needs to open a text file to read some information. This file is in the same directory as my source. When I run the program in the interpreter I simply do with open("AtomProva.atp") as f:...
asked by 09.12.2016 / 14:35
3
answers

How to allow only one instance of a given class?

If we run the code below, a window with a button inside will be created, which whenever clicked will open another window (Window2). How can I make a second instance of Window2 not be allowed? I want to do this without using modal (). #!/usr/bi...
asked by 01.07.2014 / 19:42
1
answer

How to only allow one instance of a program made in Python?

Assuming I created a program in Python and it works perfectly, how do I only allow one instance of the program at a time? I searched Google and found a person saying they solved the question using PIDs, but it was not in Python and there were no...
asked by 08.07.2014 / 17:42
1
answer

Error installing polyglot package in Python by pip

I'm trying to install this package / module by pip and I can not find the solution. Follow Traceback : C:\Users\chris>pip install polyglot Collecting polyglot Using cached polyglot-16.7.4.tar.gz Complete output from command python se...
asked by 08.07.2016 / 21:48
1
answer

Checking and creating folders in python

Hello, I'm creating a code that should check if a folder exists, if it does not exist the code should create it and then proceed, otherwise just follow with the flow. I tried with If and While but I did not succeed. Most of the time it cre...
asked by 09.07.2016 / 05:48
1
answer

In Django why is the is_authenticated method always returns True?

I saw that in the documentation it indicates the is_authenticated method as being responsible for telling the templates if there is a logged in user. I also saw in the method code that it contains only the following: def is_authenticate...
asked by 19.02.2015 / 01:09
1
answer

List comprehension vs cycle for

I have the following code segments: def is_even(num): if(num % 2 == 0): return True return False 1. lista = range(50) pares = [i for i in lista if is_even(i)] # pares = [0, 2, 4, 6, 8...] 2. lista = range(50) pares =...
asked by 27.05.2016 / 20:07