Live data from Hacker News

I only know PHP. How do I write a Web application in Python?

me.veekun.com

41–50 of 196 posts

Re: I only know PHP. How do I write a Web application in Python?

#41
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

Python 2 versus 3 isn't anything like PHP 4 versus 5.

The problem is that there are a few minor but backwards-incompatible changes to the syntax in py3. Libraries can't update until all their dependencies update. And web frameworks are some of the most complex software with the most dependencies, so they're updating last.

It's still pretty much the same language behaving in the same way, though. If you know Python 2 really well, it'll take all of five minutes to get accustomed to Python 3. Just don't worry about it and learn 2 until people stop telling you otherwise. :)

Re: I only know PHP. How do I write a Web application in Python?

#42
post #26

Earlier quoted context omitted.

While that's true (and I do love Flask), PHP comes installed on every discount web host. Deploying a PHP app is as easy as using FTP, deploying a Python app can be -- but doesn't have to be -- complex. I'd say this is the bigger sticking point than the framework. Obviously Heroku and other PAAS providers are changing the game as far as deployment ease. It should be to see what happens in the next few years on that fr…

It's a chicken-and-egg problem. Best I can do is encourage more people to write more Python software, so those crappy free hosts are more inclined to support running it. Until then, I don't think it's terribly unreasonable to pay twenty bucks a month for a server to play with. That's less than AT&T wants to charge me for sending a thousand 160-byte messages.

"crappy free hosts" ?

Re: I only know PHP. How do I write a Web application in Python?

#43

Earlier quoted context omitted.

All we need is to be able to drop an .erb file in a server and have it instantly rendered with the same magic of .php files. How hard would that be? Anyone here know how to write plugins for Apache?

You just described python cgi scripts

Ahh! So I was: http://wiki.dreamhost.com/ERB

Now all we need to do is make this a default .cgi in all apache installations and we're golden.

Re: I only know PHP. How do I write a Web application in Python?

#45
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

Python3 isn't much different from Python2. It's not like you have to re-learn Python when you switch from 2 to 3.

In a nutshell: print() has become a function instead of a statement. The standard library has been made more consistent. Built-in iterators are lazy by default. The two string types (str and unicode) are properly redefined as 'bytes' and 'strings'.

Re: I only know PHP. How do I write a Web application in Python?

#46
post #10

I'd say the necessity of this post is why PHP is as popular as it is. With PHP, there are no package managers I have to install; there is no template language to learn; there is often no version control; there is no "framework"; etc. You just drop in a .php file and, most likely, it will just run. If I need a quick dynamic page on my server, it's much easier to do this in PHP than in Python or Ruby. Until Python or R…

All we need is to be able to drop an .erb file in a server and have it instantly rendered with the same magic of .php files. How hard would that be? Anyone here know how to write plugins for Apache?

Install eruby binary (example given is ubuntu/apache):

  sudo apt-get install ruby libapache2-mod-ruby eruby
Set up your web server to serve it:

  AddHandler rubypage .erb .xhtml
  Action rubypage /cgi-bin/eruby
Start writing pages like this:

  The time is .
The first two steps could be completed by your web host, or done by you once. Obviously you might run into performance issues etc (no idea how well this would work on a live server), but that gets you up and running.

I would point out that most examples you can think of as trivial as that above could just be done with js anyway though, without any dynamic language server-side - the main reason to use a server-side language is to talk to a db or store data, at which point you probably want a framework anyway.

It's already a solved problem really, but people at that level are happy enough on PHP, which for the example above would be almost identical, and for anything more complex a framework is actually useful, and so there's no point in starting this way for many web projects.

Re: I only know PHP. How do I write a Web application in Python?

#47
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

In practice, for MOST developers, the changes between 2 and 3 are minimal. Offhand, print is a function, and there's no distinction between unicode strings and ascii strings anymore. If you do a lot of "low level" networking involving byte strings, you'll notice the difference, because you can't just jump between bytes and strings anymore.

It's this distinction that's delaying a lot of networking related libraries from porting to Python 3 - basically, it's going to be a long, buggy journey. Libraries such as Twisted, have very old codebases - old enough that some of the practices aren't the best, even for Python 2 code. Upgrading it to Python 3 will introduce quite a few breakages.

There's a lot more that I can't think of right now, but I'm sure someone else can cover off other differences.

There's no reason not to learn both - I use Python 3 for a few personal projects, and Python 2 for work.

Re: I only know PHP. How do I write a Web application in Python?

#48
post #36
post #32

Earlier quoted context omitted.

This is actually documented behavior: "The CHECK clause is parsed but ignored by all storage engines." From: http://dev.mysql.com/doc/refman/5.5/en/create-table.html I believe it was left to support certain migrations(?). You can create a trigger instead. I'm pretty certain many people will consider MySQL a good tool with which they produce good work. While it may have its quirks, it's present on virtually all shared…

So, you are telling me that it is a good thing, a normal behavior for a reliable tool to just ignore instructions I send to it and do nothing with it, not even a warning? So when I migrate a database, I have to carefully check each and every instructions (schema and data) and make sure MySQL did not "decide" it was not worth it and just silently threw it by the window? I have hard time to believe you are serious here…

I'm pretty certain when you migrate from a different database you're supposed to check your schema and data anyway, or do you just "decide" it should work without question?

I'm not saying this MySQL behavior is acceptable, I'm just saying that you should be aware of the limitations and quirks of the tools you work with.

Re: I only know PHP. How do I write a Web application in Python?

#49
post #35

I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages! Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language. I remember when this kinda happene…

Python 3 is not "really that new" and Python 2.6-2.7 is not "old" in any way.

In fact we have: pre-2.4 (really old, preinstalled on old Redhats), 2.4-2.7, 3.x

Python 3 is curing problem with variable visibility (and if you do not write in "pure" functional way - you will never see this problem) and unicode strings. Other differences is not so "revolutionary".

Re: I only know PHP. How do I write a Web application in Python?

#50
post #26

Earlier quoted context omitted.

While that's true (and I do love Flask), PHP comes installed on every discount web host. Deploying a PHP app is as easy as using FTP, deploying a Python app can be -- but doesn't have to be -- complex. I'd say this is the bigger sticking point than the framework. Obviously Heroku and other PAAS providers are changing the game as far as deployment ease. It should be to see what happens in the next few years on that fr…

It's a chicken-and-egg problem. Best I can do is encourage more people to write more Python software, so those crappy free hosts are more inclined to support running it. Until then, I don't think it's terribly unreasonable to pay twenty bucks a month for a server to play with. That's less than AT&T wants to charge me for sending a thousand 160-byte messages.

Don't mess with "crappy free hosts" -- just run it on a free Heroku dyno (http://www.heroku.com/pricing). Kenneth (http://kennethreitz.com) shows you can get good performance with Flask on the free dyno (http://flask.pocoo.org/mailinglist/archive/2012/2/22/flask-o...).
Post reply on HN