Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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.
  6. #4
  7. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    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.
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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?
  12. #7
  13. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    '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
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Norway
    Posts
    41
    Rep Power
    12
    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
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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.
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    35
    Rep Power
    12
    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.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    This is quite a nice online tutorial as well;

    http://www.ibiblio.org/obp/thinkCSpy/
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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)
  26. #14
  27. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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 02:38 AM.
    programming language development: www.netytan.com Hula

  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    US
    Posts
    12
    Rep 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)
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo