|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Very New to Python :(
Hey guys, I'm new here so be nice. I have intermediate experience in html and I am trying to learn python for programming. What books do you guys recommend for starters with no programming experience, oh also one more thing before I leave. I was following a very basic online Tutorial to write :
"print "Hello, World!" First save the program. Go to File then Save. Save it as hello.py. (If you want you can save it to some other directory than the default.) Now that it is saved it can be run. Next run the program by going to Run then Run Module (or if you have a older version of IDLE use Edit then Run script). This will output Hello, World! on the *Python Shell* window. " Problem is i have version 2.3 and I think the tutorial is out of date because there is no "Run" or anything I can run it with. Help! Uber Noob in need of help! |
|
#2
|
||||
|
||||
|
he first drawback of the new IDLE
..First, you don't need IDLE to run a program, all you have to do is save the Python file and (.py) and double click too run it on windows (sorry Uber, assuming your a windows user like me) In IDLE though simply go Run -> Run Module.. or pressing F5 should work. I think we agreed that "O'really's Learning Python" was a good place to start, and the second edition was just released so that should be even better! Mark |
|
#3
|
|||
|
|||
|
Thanks mark, i tried the f5 thing and it says " there's an error in your program : invaild syntax" i checked it over and over again I don't know why its not even working. Yeah I have windows too
, but when I click on the .py a black box appears ( noobies term for ms-dos ) and quits instanly. |
|
#4
|
||||
|
||||
|
The problem with Windows is that it opens a DOS box, prints your progra's output and then closes. Add
Code:
raw_input("Press any key...")
Also, for your Hello world example, be totally sure you're using the correct syntax: Code:
print "Hello world!" |
|
#5
|
||||
|
||||
|
The thing about Python is if theres an error in the code, it exits emediatly. And when a Python program exits/finishes the Python window is closed.. we can stop a program exiting by adding raw_input() to the end, which forces the program wait for the user to press ENTER before finishing.
However if we have an error the program exits before reaching the raw_input(). The best way too do this would be to run the program from the command line (in this case DOS) i.e. Code:
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Mark>cd D:\python D:\python>python C:\hello.py Hello world Give that a try, you could also post your code here and i'll take a look for you.. Mark. |
|
#6
|
|||
|
|||
|
wow thanks that helped me a lot, finally figured out how to save and to make dos from disapering.
I found out my mistake I was copy-pasting : "hello, world" hello, world when I removed the bottom hello,world it worked perfectly. Do you guys know which books by O'Reily should I buy for python? there is one called Python in a Nutshell, is it good for starters? |
|
#7
|
||||
|
||||
|
'Learning Python' is the one you want.
All O'Reilly books follow this naming convention: Learning x - for beginners Programming x - for the experienced X in a nutshell - handy reference for experienced X cookbook - tips and tricks for x |
|
#8
|
|||
|
|||
|
Just wait a few weeks for the second edition* of "Learning Python", it's still not here yet! The first edition is four years old and was made for Python version 1.5.2.
If we trust the Amazon.com reviews, "Python for the absolute beginner" and "Practical Python" can also be recommended, although they're not published buy O'reilly- *http://www.oreilly.com/catalog/lpython2/ |
|
#9
|
|||
|
|||
|
What am I doing wrong, I was playing with variables and strings. Heres my code.
s = raw_input("Whats your first name?") d = raw_input ("Whats your last name?") e = raw_input ("Where you from?") print "Hows",e,"Mr."s, d I want it to say for example: Hows US, Mr.Joe Smith. |
|
#10
|
||||
|
||||
|
You need another comma (or plus) between "Mr." and s.. the differance being that using a comma inserts a space between the two strings while the plus operator doesnt!
first = raw_input('Whats your first name?') last = raw_input ('Whats your last name?') from = raw_input ('Where you from?') print 'Hows', from + ', Mr.' + first, last You should really use string formatting here, especially if your worried about preformance (which your not but hey) first = raw_input('Whats your first name?') last = raw_input ('Whats your last name?') from = raw_input ('Where you from?') print 'Hows %s, Mr.%s %s' % (from, first, last) Mark. |
|
#11
|
|||
|
|||
|
Quote:
The first book I started out with was Learn to Program Using Python by ALan Gauld. The book or at least some of the content is available online as well (http://www.freenetpages.co.uk/hp/alan.gauld/). I've still got it (might even have the CD somewhere). It covers programming basics, and how to program using Python. According to the link I posted, there is a second version of the book out. The first version of the book was written around Python 1.5.2 but many of the basics covered still apply. I remember I was able to complete many (if not all) of the examples using Python 2.1 still. As far as O'Reilly books, I have (and have read) quite a few--Learning Python is probably the best beginner book (as telex4 said), though the Python Cookbook has some great examples in it once you learn the basics. I don't have a need for the Learn to Program book anymore, if you're interested in it PM me and we can work something out. The book has been read but is gently used with no marks inside and all pages intact. |
|
#12
|
|||
|
|||
|
|
|
#13
|
|||
|
|||
|
Thanks for the links. I am having trouble on this code can someone help me here it is.
print "Welcome to Blah" s = raw_input('name?') d = raw_input('Who told you about Blah?') f = raw_input ('State the last trip you have been to') while password !="Bob": password = raw_input("Password:") print " 'Welcome %s, how was %s. By the way say hi to %s for me.'% ( s, d, f) |
|
#14
|
||||
|
||||
|
If your gonna post code try and put it between code tags ([ CODE ]code here[ /CODE ] without the spaces), as Scorp said in other languages it makes things easier to read, but in Python indentation makes the differance
anyway this should work!Code:
#!/usr/bin/env python
password = ''
print 'Welcome to Blah'
s = raw_input('name? ')
d = raw_input('Who told you about Blah? ')
f = raw_input ('State the last trip you have been to? ')
while password != 'Bob':
password = raw_input('Password:')
print 'Welcome %s, how was %s. By the way say hi to %s for me.' % (s, d, f)
Your script was bailing because it was trying to compare password, and password wasn't defined ![]() Edit: fixed the stupid typo, why did they have to put ; next to ' on the keyboard ![]() Mark. Last edited by netytan : December 1st, 2003 at 01:38 AM. |
|
#15
|
|||
|