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

  • SEARCH
  • Home
  • 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 6047225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:19:40+00:00 2026-05-23T07:19:40+00:00

I just made a fresh copy of eclipse and installed pydev. In my first

  • 0

I just made a fresh copy of eclipse and installed pydev.

In my first trial to use pydev with eclipse, I created 2 module under the src package(the default one)

FirstModule.py:

'''
Created on 18.06.2009

@author: Lars Vogel
'''
def add(a,b):
    return a+b

def addFixedValue(a):
    y = 5
    return y +a

print "123"

run.py:

'''
Created on Jun 20, 2011

@author: Raymond.Yeung
'''
from FirstModule import add

print add(1,2)
print "Helloword"

When I pull out the pull down menu of the run button, and click “ProjectName run.py”, here is the result:

123
3
Helloword

Apparantly both module ran, why? Is this the default setting?

  • 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-23T07:19:40+00:00Added an answer on May 23, 2026 at 7:19 am

    When you import a module, everything in it is “run”. This means that classes and function objects are created, global variables are set, and print statements are executed. *)

    It is common practice to enclose statements only meant to be executed when the module is run directly in an if-block such as this:

    if __name__ == "__main__":
        print "123"
    

    Now if you run the module as a script, __name__ is set to "__main__", so "123" will be printed. However, if you import the module from somewhere else __name__ will be "FirstModule" in your case, not "__main__", so whatever is in the block will not be executed.

    *) Note that if you import the same module again, it is not “run” again. Python keeps track of imported modules and just re-uses the already imported module the second time. This makes C/C++ tricks like enclosing header file bodies with IFNDEF statements to make sure the header is only imported once unnecessary in python.

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

Sidebar

Related Questions

I just made my first .net website. I'm trying to use the following line
I just made my first website , and I notice that the elements start
I'm using TortoiseSVN. I just made quite a few changes to my working copy
Hello C++ and/or ROS Experts I just made a fresh install of Ubuntu 12.04
I have just made a fresh install of rvm with rails on a fresh
I just made my first setup of RoR, and creating a new application works
I just made my first push into a Mercurial repository and now I am
I just made a browser using c# as one of my first projects of
I just made my first MVC3 app, and I thought it would be fun
I just made a transaction go through but not sure where there is a

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.