Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old November 27th, 2003, 12:31 AM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old November 27th, 2003, 02:46 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 27th, 2003, 03:08 AM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old November 27th, 2003, 06:40 AM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 43 sec
Reputation Power: 5
Send a message via ICQ to SolarBear Send a message via MSN to SolarBear
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...")
to stop it from closing too soon.

Also, for your Hello world example, be totally sure you're using the correct syntax:
Code:
print "Hello world!"
Copy & paste this if need be.

Reply With Quote
  #5  
Old November 27th, 2003, 06:45 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #6  
Old November 27th, 2003, 12:31 PM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #7  
Old November 27th, 2003, 01:50 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
'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

Reply With Quote
  #8  
Old November 27th, 2003, 05:22 PM
ilves ilves is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Norway
Posts: 41 ilves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 22 sec
Reputation Power: 6
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/
__________________
Good web hosting info - articles about web hosting
hb's web dev blog

Reply With Quote
  #9  
Old November 27th, 2003, 08:39 PM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #10  
Old November 27th, 2003, 08:51 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #11  
Old November 29th, 2003, 11:20 AM
oxygenthief oxygenthief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 35 oxygenthief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Quote:
Originally posted by Beast4rmDaEast
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?

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.

Reply With Quote
  #12  
Old November 29th, 2003, 02:37 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 42 m 24 sec
Reputation Power: 9
This is quite a nice online tutorial as well;

http://www.ibiblio.org/obp/thinkCSpy/

Reply With Quote
  #13  
Old November 30th, 2003, 02:52 PM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #14  
Old November 30th, 2003, 03:09 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #15  
Old November 30th, 2003, 08:55 PM
Beast4rmDaEast Beast4rmDaEast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 12 Beast4rmDaEast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: