Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:31:29+00:00 2026-05-16T15:31:29+00:00

I am learning Python now, and today, I met a problem in http://docs.python.org/release/2.5.4/tut/node8.html 6.1.1

  • 0

I am learning Python now, and today, I met a problem
in
http://docs.python.org/release/2.5.4/tut/node8.html

6.1.1 Executing modules as scripts

When you run a Python module with

python fibo.py <arguments>

the code in the module will be executed, just as if you imported it, but with the
__name__ set to "__main__". That means that by adding this code at the end of
your module:

    if __name__ == "__main__":
        import sys
        fib(int(sys.argv[1]))

you can make the file usable as a script as well as
an importable module, because the code
that parses the command line only runs
if the module is executed as the
"main" file:

$ python fibo.py 50 1 1 2 3 5 8 13 21
34

but when i do this in shell, i got

File "<input>", line 1
python fibo.py 222
SyntaxError: invalid syntax

how to execute the script correctly?

fibo.py is:

    def fib(n):
        a,b=0,1
        while b<n:
            print b,
            a,b = b,a+b
            
            
    def fib2(n):
        result=[]
        a,b=0,1
        while b<n:
            result.append(b)
            a,b=b,a+b
        return result
    
    if __name__ =="__main__":
        import sys
        fib(int(sys.argv[1]))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:31:29+00:00Added an answer on May 16, 2026 at 3:31 pm

    What exactly did you do in the shell? What is the code you are running?

    It sounds like you made a mistake in your script – perhaps missing the colon or getting the indentation wrong. Without seeing the file you are running it is impossible to say more.

    edit:

    I have figured out what is going wrong. You are trying to run python fibo.py 222 in the python shell. I get the same error when I do that:

    [138] % python
    Python 2.6.1 (r261:67515, Apr  9 2009, 17:53:24)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> python fibo.py 222
      File "<stdin>", line 1
        python fibo.py 222
                  ^
    SyntaxError: invalid syntax
    >>>
    

    You need to run it from the operating system’s command line prompt NOT from within Python’s interactive shell.

    Make sure to change to Python home directory first. For example, from the Operating system’s command line, type: cd C:\Python33\ — depending on your python version. Mine is 3.3. And then type: python fibo.py 200 (for example)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do it using the scrollTop property of your… May 16, 2026 at 6:52 pm
  • Editorial Team
    Editorial Team added an answer It looks like you have an extra or missing k… May 16, 2026 at 6:52 pm
  • Editorial Team
    Editorial Team added an answer It's the built-in function buffer-file-name that gives you the full… May 16, 2026 at 6:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm learning python and PyGTK now, and have created a simple Music Organizer. http://pastebin.com/m2b596852
I've just started learning Python today. I've been reading a Byte of Python. Right
I'm learning Python now because of the Django framework. I have been a Perl
I'm learning Python now and I want to develop a screen capture tool in
I've started learning Python 3 - and now so far that I need some
I am learning Python for a class now, and we just covered tuples as
Hello Stack Overflow contributers, I'm a novice programmer learning Python right now, and I
I am just started out learning Python and also started looking into Django a
I'm learning Python (and it's my first programming language so don't be too intense
I'm just starting out learning python (for webapp usage) but I'm confused as to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.