I have been coding using Python for almost 2 weeks now and I think I have a good handle on the basic stuff, i.e the basic syntax, declaring variables, printing them, playing around with the lists, dictionaries and that kind of stuff, pretty basic.
Now I am pretty good at PHP and by that what I mean is that PHP is the language I know better than other languages and that I use for most of my work, but due to it's popularity in various Dev forums and also due to my curiosity as a developer I came to the conclusion that I would be better off knowing some Python and if it grows on me, I could actually start doing some projects with it.
So when I set up the environment and was ready to start my python coding adventure, when I had obtained sufficient understanding of the language to now start doing some database scripting tests i.e.. connecting to the DB, querying the DB and that kind of stuff, I ran into some errors, and long story short those errors had to do with the mysql-connector module that I had imported in my script vis-a-vis the version of Python in my system (I run Python3.6 on Ubuntu). The most stable release as I found out is Python2.7 and is actually the default Python environment in my OS, so when I run my little DB connecting script, it runs perfectly.
I hopped back to the online forums to find a work-around for my situation and apparently I would have had an easier time just using Python2.7 in my DB test. The dilemma is that I actually want to write Python in its most progressive version which right now is 3.6, probably 3.7. It's like I'm stuck in ver 2.7 for now, and I'm not so sure about that.
Comparing PHP to Python where the most fundamental code is really the same (at least as far as DB connection is concerned for me), I cannot help but be frustrated by all this, if anyone out there knows some good starting points for me, please feel free to share your pointers.
Thanks. :)
Top comments (4)
I had a long list of complaints with Python 2.x. I thought the language was okay, but awkward, and had unsurmountable problems.
When Python 3.0 came out, I was amazed that every single one of my negatives points against Python 2.x had been rectified in Python 3.0. Wow! That must have been a very painful bandage to rip off.
Since you are coming from PHP, I presume your problem domain is one for which PHP is a good choice for solving those problems. Perhaps the best choice in that domain. Python by itself does not really compete in that domain.
But Python with Django does compete in that space, at least to some extent. (Another more popular alternative is Ruby on Rails ... I've found Ruby not to my liking, and I've found Python to appeal to my sense of code aesthetics. But that's all a subjective matter of one's personal taste.)
Python 2 is actually deprecated - it was intended to be End Of Life in 2015, but then that was pushed out until 2020. However, there is a freeze on new features, it is purely maintenance releases and there will never be a Python 2.8. The reason 2.7 is already installed on your system is that quite a few operating systems have dependencies on it.
As you're just starting out, you definitely want to be using Python 3, but this does mean checking whether the packages you're aiming to pull in are actually compatible.
Note that you can have multiple Python versions installed - do not attempt to upgrade your system installation manually or you could do some serious damage to system dependencies.
In terms of general package management/dev workflow, I'd highly recommend checking out Pipenv - it's the officially recommended solution, and from personal use, it's absolutely fantastic too.
I don't mean to sound harsh, but this is 2018. If 2/3 compatibility is giving you trouble, you are using wrong packages to begin with.
Have you considered using an ORM to access the database? It may be total overkill for simple CRUD, but is worth learning nevertheless. There are many options, eg. SQLAlchemy is pretty cool and powerful, PonyORM is arguably somewhat simpler.
Hi,
you may try mysqlclient package to access MySQL server on Python 3.x .
github.com/PyMySQL/mysqlclient-python