Questions tagged as 'python'

3
answers

Pythonic way of defining setters and getters

Searching the internet I see that it is highly recommended not to use Setter and Getters in Python classes, however, I can not determine a way to access private values without using them. There are several recommendations on using properties, bu...
asked by 28.02.2017 / 05:32
3
answers

How to check if a file exists using Python

How to check if a file exists, in Python, without using a block try: ?     
asked by 29.01.2014 / 18:37
3
answers

How to see the methods or attributes of an object in Python?

Given an object in Python, I can easily list what methods or attributes it has directly in the interactive interpreter?     
asked by 05.11.2015 / 23:55
4
answers

How to extract digits from a string in Python and add them together?

I need to decompose a string into Python, separating letter and numbers, and perform the sum of these numbers. For example: string ="96h11k" From this string I need to extract the numbers 9, 6, 1, 1 and add them: 9 + 6 + 1 + 1 = 17. Act...
asked by 28.11.2014 / 18:19
2
answers

Format String "28122016" for date "2016-12-28"

I know it's a simple question, but I've done a lot of research and I'm not finding a simple solution. I need to create a function that receives a date in "28122016" format and converts it to "2016-12-28" . How can I do this?     
asked by 24.01.2017 / 12:49
3
answers

How to ensure that a service is always running on CentOS?

I created a startup script for my application in CentOS, so I can use the following commands to initialize / stop the application: service django_app start service django_app stop How do I make sure this service is always running? For ex...
asked by 12.02.2014 / 18:09
3
answers

How do I prevent Django from finding IDs in the template?

I'm using Django 1.4 with location (L10N) enabled, which causes numeric values in the template to be formatted: 1.234,56 . The problem is that every time I put ID in the template, for example: data-id="{{ form.instance.id }...
asked by 11.12.2013 / 17:21
3
answers

Why do we have to use the self attribute as an argument in methods?

I watched a video lesson where it is said that every method is required to pass the self parameter in the method definition, as in the example below: class Complex(object): def __init__(self, real, imag): self._real = real...
asked by 10.01.2017 / 19:44
3
answers

How to calculate perfect numbers quickly?

I'm trying to perform an exercise to show the perfect numbers present within a given range, but I can only do this to the perfect fourth number. If I increase the range, it takes a long time and does not respond: def perfeito(n_max): lista...
asked by 24.09.2018 / 19:56
2
answers

What is the assert in Python?

@CiganoMorrisonMendez gave me a answer in a previously asked question about Python . And since I'm a beginner in% w / o%, I still do not know what the% w / w% that he indicated in the answer is. The excerpt from the code he indicated...
asked by 04.09.2015 / 15:08