Earlier quoted context omitted.
CGI scripts have much of PHPs simplicity. You can just drop in a executable file, and depending bit on server configuration, it will just run. With Python a basic hello world would look something like this: #!/usr/bin/python print "Content-type: text/plain" print "" print "Hello World!" So 3 lines of "boilerplate", and then you can do anything you want. No extra packages to install or languages to learn. No framework…
And therein lies the problem, in WSGI 99% of web sites are hosted in "shared hosting" services Now compare copying the .php files with configuring WSGI "No, but WSGI is easy blah blah blah" it doesn't beat copying files And no, settings WSGI is not easy Also, if you depend on IIS for example, PHP is almost plug'n'play WSGI on Windows is the definition of "bag of hurt". You can try fastcgi to run on windows, and then…
I only know PHP. How do I write a Web application in Python?
121–130 of 196 posts
Re: I only know PHP. How do I write a Web application in Python?
#122Is there any cheap & easy webhosting available for Python? Occasionally I get commisioned to build small websites ( I don't want the hassle/expense of having to setup and run VPS/AWS infastructure. I just want to give someone a bunch of files and say "sign up for some cheap webhosting, ask them to give you a DB called X and upload these". I usually end up just doing it in PHP, but it has always felt like a poor reaso…
Re: I only know PHP. How do I write a Web application in Python?
#123Earlier quoted context omitted.
Fair point. Correction: working with encodings sucks. Py3 isn't magnitudes better with Unicode; it's better about converting incoming bytes, and it makes literals into real strings. But the former isn't necessarily a good thing, and you can get the latter with a `__future__` import. Always dying on implicit conversions is definitely nice, though.
Working with encodings is indeed annoying in Python, but it’s not a “universal” problem.
Re: I only know PHP. How do I write a Web application in Python?
#124The idea is that a transaction starts when a request starts, and it’s automatically rolled back if there’s an exception. This is behavior you want from the start! It’s half (err, ¼) the point of using a database. I mostly agreed with the rest of the article but this strikes me as massive blooper. I can see no reason this would be considered good advise. It's the database equivalent of the GIL, can't figure out what y…
Updating a customer's winnings and recording a win are definitely things that should be together in a transaction - if one happened and not the other, that's a failure.
This is not the fault of using a transaction, this is the fault of not working with what is essentially a distributed transaction. Since you are relying on a message against a third party, you need to build distribution into this system, which is challenging. You might contact the third party after you've completed the internal processing, and you might use two-phase semantics even such that you can "PREPARE TRANSACTION" the work you've done locally, (nearly) guaranteeing that a commit will proceed, then work with your external messaging, then commit locally.
background at http://en.wikipedia.org/wiki/Two-phase_commit_protocol
Re: I only know PHP. How do I write a Web application in Python?
#125Earlier quoted context omitted.
What frameworks and platforms would you recommend for web development with java? I am writing my senior project at college in java (mainly because of the wide amount of image processing libraries available) and would love to add web capabilities.
I tend to prefer Python/Flask for Web dev to Python but if you are inclined to use Java there's only really one framework that doesn't make me want to tear my eyeballs out. That framework is Spring MVC. It is DI, adapters for vendor-specific libraries and utility. It's probably not the easiest thing to start with just because it is so flexible that it can be hard to know where to start. A good "Hello World" Spring MV…
Try http://blog.springsource.com/2011/01/04/green-beans-getting-...
Re: I only know PHP. How do I write a Web application in Python?
#126Earlier quoted context omitted.
CGI scripts have much of PHPs simplicity. You can just drop in a executable file, and depending bit on server configuration, it will just run. With Python a basic hello world would look something like this: #!/usr/bin/python print "Content-type: text/plain" print "" print "Hello World!" So 3 lines of "boilerplate", and then you can do anything you want. No extra packages to install or languages to learn. No framework…
Let's look at the PHP version: Hello World! One line. I didn't have to worry about Linux/Windows, knowing HTTP headers or the fact that I need two CRLFs after the last header[1]. I just wanted a page that says "Hello World!" and that's what I got. Don't get me wrong, I would never choose to write a web app in PHP over python. But it is brain dead simple to go from nothing to something in a few keystrokes. Which is pr…
Besides that, I don't think knowing HTTP headers or understanding significance of trailing newlines is required to write CGI scripts. You only need to know that you need those three 'magic' lines in the front of your scripts. Similarly like you need to know that in php you need around your script.
Re: I only know PHP. How do I write a Web application in Python?
#127Personally, I _like_ PHP because, at the core, it is a collection of utility functions to write webapps quickly. Here's a small set of those function that I would like to see somewhere else (like in Python for example): Save a file: file_put_contents() Load a file: file_get_contents() Trim whitespace: trim() Print a string (even numbers!): print $str Dump an array: print_r() Print the stack trace: print $e->getTraceA…
# Save a file
f.write(str)
# Read a file
f.read
# Trim whitespace
" foo ".strip
# Print anything
puts 1 # even numbers!
puts File.open("foo", "w+") # even file handles!
puts [1, 2, 3, 4] # even arrays!
puts [].class # even classes!
puts [].method(:size) # even functions!
# Dump an array (see above)
Python is similarly clear: # Save a file
f.write(str)
# Read a file
f.read()
# Trim whitespace
" foo ".strip()
# Print anything
print 1 # even numbers!
print open("foo", "w+") # even file handles!
print [1, 2, 3, 4] # even arrays!
print [].__class__ # even classes!
puts [].remove # even functions!
# Dump an array (see above)
Ruby and Python are extremely well documented. They have great standard libraries which wrap existing C functions too...and wrap them in a consistent fashion. They are also the second and third most popular language on Github, respectively...which means tons of great libraries to solve almost any problem you can think of.Ruby and Python are just as easy to use as PHP.
Re: I only know PHP. How do I write a Web application in Python?
#128Earlier quoted context omitted.
The transaction is internal to the database. It's essentially a list of operations to perform, if something goes wrong it provides a list of things to reverse. If the db transaction fails, then there would need to be some code to handle rolling back operations outside of the database. I don't think db transactions were to fault in your situation.
I'm not sure I really get what you are trying to say. I know what a transaction is, and I know it wasn't the fault of transactions. It was the fault of our poor use of transactions, in the same monolithic transaction pattern that the OP appears to be advocating.
The alternatives to transaction-per-request are autocommit, or explicit transactions required at all times. Autocommit is a terrible choice because now you've lost all atomicity and isolation for dependent operations (locking is also not much of an issue. If you're doing VB, then you're on SQL server, which has some of the worst locking behavior - turn on snapshot isolation to make it bearable). Explicit transactions required at all times is a terrible choice because now your app is littered with what is 90% of the time unnecessary boilerplate.
Re: I only know PHP. How do I write a Web application in Python?
#129I like java for web app development, simply because it has a well-structured api and a massive community of developers who have run in to the majority of the road blocks you will most likely encounter on the way to launching your app.
What frameworks and platforms would you recommend for web development with java? I am writing my senior project at college in java (mainly because of the wide amount of image processing libraries available) and would love to add web capabilities.
Re: I only know PHP. How do I write a Web application in Python?
#130Earlier quoted context omitted.
And therein lies the problem, in WSGI 99% of web sites are hosted in "shared hosting" services Now compare copying the .php files with configuring WSGI "No, but WSGI is easy blah blah blah" it doesn't beat copying files And no, settings WSGI is not easy Also, if you depend on IIS for example, PHP is almost plug'n'play WSGI on Windows is the definition of "bag of hurt". You can try fastcgi to run on windows, and then…
FastCGI works fairly well in my experience on shared Linux servers (that's how I host my personal projects). And for smaller scripts where I don't bother setting up FCGI, I just use plain CGI, which is just copying files .