Learning Python And Already Stuck?

I am trying to learn Python and in the first chapter of this book it tells me to make a module file by opening my favorite text editor (i assumed this meant something like Notepad) and type:
Import sys
Import sys.argv
and save it as spam.py
then it told me to run it by listing the filename as an argument on a python command in the operating system shell:
% python spam.py -i eggs -o bacon
I did all of this and i get an error stating invaild syntax
how could i be stuck in the first chapter, this is not good
HELP!!!

Tags: , , ,

5 Responses to “Learning Python And Already Stuck?”

  1. Zeus says:

    I have try many ways to achieve your so called “invalid syntax”
    The first word should be import, first letter is “i” in “invalid”, not “l” in “letter”
    import sys
    print sys.argv
    Try again and u should have this output:
    ['spam.py', '-i', 'eggs', '-o', 'bacon']
    :) Typo error is the first lesson for your python class !!

  2. John K says:

    Did you pick Python for any particular reason? It hasn’t overwhelmed the industry like people thought it would. I paid $30 for a book and didn’t get past the first chapter. I never even wrote a line of code. Unless you have a very specific reason for wanting to learn Python, I’d have to suggest you take a serious look at a more popular language. Other than that, I can’t help, as if you hadn’t already guessed!

  3. Homework Help says:

    May be you could contact a python expert to help you learn python fast. Check websites like http://getafreelnacer.com/

  4. Lain Lain says:

    First of all, use a better text editor. Try TextPad. It’s free for evaluation version.
    Are two the only two lines you have in spam.py? Then it is not going to work. If you have some other code, please post as well.
    And also mention the line number where you are getting the error.

  5. csanon says:

    The code works fine. If the second line is print sys.argv instead of import, it’s OK, so I’m not sure what is wrong on your side. Here’s a question from me, sorry if it sounds silly, but when you type in the command in shell, you don’t actually type in the % sign, right?
    If you really do get an error, can you post the error message here? What does it say on the commandline?
    And one more thing, don’t actually use Notepad for a text editor. It works, but barely. There’s plenty of high quality and free text editors out there to use, so use them.

Leave a Reply