Questions tagged as 'python'

3
answers

How to connect Python with Mysql?

I would like to know how I can make a simple Mysql connection through a Python script. For me to do this do I need to install some library? Or is there something that comes by default in Python (same as in PHP)?     
asked by 10.01.2017 / 19:07
2
answers

What makes join () be so superior compared to other concatenation techniques?

It's common to read that the concatenation method join() is much top other techniques in Python (such as + or += ). Starting from this point, I ask some questions: What does join() do so fast? Should I always...
asked by 17.09.2016 / 00:08
2
answers

Why should descriptor instances in Python be class attributes?

I'm studying descritores in Python and I found that they should be implemented as atributos de classe for example: class Descriptor: def __init__(self, obj): self.obj = obj def __get__(self, instance, owner=None...
asked by 23.10.2018 / 20:48
4
answers

How to create a directory in Python?

How can I use Python to create a particular directory? For example: app/ main.py How could you do to create a directory named temp within app through Python main.py ?     
asked by 09.12.2016 / 14:11
5
answers

How to create and read an XML with Python?

How to create and read an XML with the DOM component in Python? How to read an XML with the cElementTree component of Python?     
asked by 31.01.2014 / 17:46
3
answers

Measure the execution time of a function

How can I measure the runtime of a function in Python? In C #, I use the class Stopwatch() in this way var sw = new Stopwatch(); sw.Start(); AlgumaFuncao(); sw.Stop(); WriteLine(sw.ElapsedTicks);     
asked by 10.11.2015 / 14:41
1
answer

Is everything object in Python?

I am very confused about what is object and what can behave as an object, see the example I created to illustrate the situation: def subtrai(x,y): return (x - y) class OpeMatematica(object): def __init__(self, x, y): self.x =...
asked by 19.01.2016 / 15:16
1
answer

What do you use to format a string,%, or format?

Use "%" or "format" ? I think the latter is more recent, but is there any other aspect to be taken into account when deciding which one to use?     
asked by 11.12.2017 / 22:40
1
answer

How to make a "deep copy" in Python?

Let's say I have the following code: class Foo: pass foo_list = [Foo() for _ in range(10)] How can I proceed to create a copy of foo_list without references to both the list and the objects contained therein being passed to the...
asked by 19.10.2017 / 20:38
2
answers

How to subtract two dates using Python?

How do I know the difference of days between two dates using Python? For example, to know how many days there are between 11/22/213 and 3/25/2014 considering a possible leap year.     
asked by 29.01.2014 / 18:54