The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Very New to Python :(
Discuss Very New to Python :( in the Python Programming forum on Dev Shed. Very New to Python :( Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 27th, 2003, 12:31 AM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
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!
|

November 27th, 2003, 02:46 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

November 27th, 2003, 03:08 AM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
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.
|

November 27th, 2003, 06:40 AM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
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.
|

November 27th, 2003, 06:45 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

November 27th, 2003, 12:31 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
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?
|

November 27th, 2003, 01:50 PM
|
 |
Wacky hack
|
|
Join Date: Apr 2001
Location: London, England
Posts: 513
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
|
|
|
'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
|

November 27th, 2003, 05:22 PM
|
|
Contributing User
|
|
Join Date: May 2003
Location: Norway
Posts: 41
Time spent in forums: 3 h 52 m 22 sec
Reputation Power: 11
|
|
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/
|

November 27th, 2003, 08:39 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
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.
|

November 27th, 2003, 08:51 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
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.
|

November 29th, 2003, 11:20 AM
|
|
Contributing User
|
|
Join Date: Nov 2003
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
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.
|

November 29th, 2003, 02:37 PM
|
|
|
|

November 30th, 2003, 02:52 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
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)
|

November 30th, 2003, 03:09 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

November 30th, 2003, 08:55 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: US
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Mark it still doesn't run on module. When I try to run it says "There's an error in your program: invalid syntax" it looks like this.
Code:
while password !=;Bob':
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)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|