Shinyshell Community Forums > Coding > Python? |
||||||
Sign Up | Member List | New Posts | Help |
[1]
May 04 02009, 21:19 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
There's already a ton of Python threads in here already lol. But uhm, I was wondering if anybody knew a good Python tutorial? Because the links here are broken. :[
I know PHP well enough to code little stuff. I'm lost when it comes to MySQL. But I want to learn Python. But (correct me if I'm wrong) there are several different kinds. Which should I learn/begin with. Thanks! |
May 05 02009, 06:40 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Those threads all be mine.
The Python tutorial I've found so far would actually be a pdf-book named "Think Python". Try Googling it, but I do have a copy on my hard-drive so I can send you that if you can't find it. I think there is only one kind of Python, however Python can be run though an interpreter (command line) or be used in scripts. If you're intending to use it for the web, then you're obviously looking at using scripts. The Python syntax is all the same, just some of the stuff needs to be treated differently, but seeing as you know PHP already that should come naturally (as it did to me). The first things you need to know when coding python for the web is that: 1. All files need to have UNIX (/n) file endings. If you've got a Mac or Linux, this is the default, however if you haven't you'll have to change the settings somewhere. 2. All files need to be CHMOD'd to '755' in order for the script to run, otherwise you get a big white '500 Internal Server' error. Now I'll just wait for leccy to post and tell you that something I said was wrong, because I'm such a noob. Good luck with Python, though. ______________________________ Lazurane |
May 05 02009, 22:06 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
"1. All files need to have UNIX (/n) file endings. If you've got a Mac or Linux, this is the default, however if you haven't you'll have to change the settings somewhere."
How do you mean? |
May 06 02009, 07:36 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
It's like a file setting, that you can't see, but it's there in the file encoding. It's hard for me to explain.
______________________________ Lazurane |
May 06 02009, 13:13 GMT | ||||
Kthar Krme jedno bezglavo Location: kroatie Post count: 106 |
Yeah, Nick's got it pretty good. And when he says it's hard to explain, you've got to understand him. It's always hard for pros to explain as they're used to do things not tutor. They understand them because they've developed their own perception, a mental image odf the matter, that's why the manuals are so expensive. Just look at Yngwie's Arpeggios from Hell. They're very hard to explain.
|
May 06 02009, 14:15 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
What Nick's trying to say is that every file uses certain characters for new lines (when you're writing a script and press the enter key, it actually inserts a newline character. This just shows up as an actual "new line" in your editor)
However, this character isn't the same across all operating systems. For example, on Windows, 2 characters are actually used, "\r\n". On UNIX-based systems, this is merely "\n". So, in case you want to run a python script on a server (which is often a Linux system) you'll have to convert all "\r\n"s into "\n"s. You don't have to do this with PHP, which is why Nick warned you about it. Most better editors can do this for you. Also, there is only one Python. All python scripts go through the interpreter (that's the only thing that can actually understand Python code), only Python on the server-side sends it's output to the HTTP server, and it ends up in your browser, whereas a Python script you would run on the desktop typically outputs to the shell (that's the Command Prompt window). I hope that helps you. Oh yeah - don't worry about Kthar. He's cool with Ingmar Bergman now. |
May 06 02009, 22:17 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
So how do I set it so it will use '\n' instead of '\r\n'?
Goodness, maybe I should reinstall Linux on my computer. Also, if I just write the code in the file editor of my CP, will I still have to change it? SO MANY QUESTIONS. Number three: I'm having some problems with getting my Python to execute on my site. ;D http://z-design.jenviousity.com/test/python/index.py I've also tried running it as a .CGI file, as I did with my old host. Still didn't work. .HTACCESS file: said PYTHON file: said Although I'm actually not sure if it should be said in the beginning instead of that. I don't know where I got the second one. @_@ Peter has become confused! Peter hurt itself in its confusion! EDIT: Oh, and my files are CHMODded to 755. :] |
May 07 02009, 09:47 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
I use Komodo Edit (the free version) for editing Python, Perl and Ruby. It can colour code in a vast amount of languages, though. If you want to download it, you can do so here.
It has a option for specifying file line endings: open a Python script in it, and go to Edit > Current File Settings and in the "File settings" section, select UNIX (\n) as the line ending, and uncheck the "Preserve existing line endings" checkbox. Click Ok, and you will have changed the line endings. Another thing: #!/usr/bin/python The #!/usr/bin/python is usually alright (should be ok on your server too) - except after you print the header (that's the Content-type part) you need to print a newline: #!/usr/bin/python This should then work. |
May 07 02009, 14:01 GMT | ||||
Kthar Krme jedno bezglavo Location: kroatie Post count: 106 |
Lec, something must be wrong with this forum. My post got deleted. I sense it was of great importance and relevance to the topic so sould you be so kind and put it back. It meant much to me.
|
May 07 02009, 22:40 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
<3 IT WORKED. Thanks!
So now I'm off. Well, later I will be. I'm on my dad's computer now. And thanks, Nick, for all your posts earlier. I'll use the MySQL one for reference later. EDIT: Electron, for some reason, the Komodo thing thinks the third line is wrong? #!/usr/bin/python print "Content-Type: text/html\n" print "Hello World!" |
May 10 02009, 21:38 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
There's no error, but Komodo sometimes has trouble with indentation. If the line between "#!/usr/bin/python" and the rest of the code has a tab or space, it might consider the lines that follow it bad.
|
May 12 02009, 16:43 GMT | ||||
Kthar Krme jedno bezglavo Location: kroatie Post count: 106 |
I have problems with a very particular dent as well. When will you get that vaccum machine?
|
[1]
Forum Information |
||||||||||
|