Updating Python on Mac

The default Python on OS X shouldn’t be messed with as it’s used by the OS itself. If your default is 2.6.1 then you must have Snow Leopard. If you just install from the standard 3.1 disk image then you can invoke it using python3.1 from the terminal (you don’t have to do any extra steps for this to … Read more

Python Error: AttributeError: __enter__ [duplicate]

More code would be appreciated (specifically the ParamExample implementation), but I’m assuming you’re missing the __enter__ (and probably __exit__) method on that class. When you use a with block in python, the object in the with statement gets its __enter__ method called, the block inside the with runs, and then the __exit__ gets called (optionally with exception info if one was raised). Thus, if you don’t have an __enter__ defined … Read more

What are type hints in Python 3.5?

I would suggest reading PEP 483 and PEP 484 and watching this presentation by Guido on type hinting. In a nutshell: Type hinting is literally what the words mean. You hint the type of the object(s) you’re using. Due to the dynamic nature of Python, inferring or checking the type of an object being used is especially hard. This fact makes it hard for developers to understand what … Read more

How to print like printf in Python3?

In Python2, print was a keyword which introduced a statement: In Python3, print is a function which may be invoked: In both versions, % is an operator which requires a string on the left-hand side and a value or a tuple of values or a mapping object (like dict) on the right-hand side. So, your … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)