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 8761703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:21:07+00:00 2026-06-13T15:21:07+00:00

def nearbin(): parser = argparse.ArgumentParser(description = choose near bin) parser.add_argument(-bin, type=int,action = store, default

  • 0
def nearbin():
    parser = argparse.ArgumentParser(description = "choose near bin")
    parser.add_argument("-bin",  type=int,action = "store", default = "10", help="bin number")   
    args = parser.parse_args()   
    bin = args.bin 
    print bin
    return f(bin)


if __name__ == "__main__":
    nearbin()        

In command line, I can use “python test.py -bin 10” to run the program

If I want to import test in another python script and use function nearbin(bin) in another script, how can I do this?

  • 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-06-13T15:21:09+00:00Added an answer on June 13, 2026 at 3:21 pm

    My usual approach:

    def nearbin(bin):
        ...
    
    def main(args):
        parser = argparse.ArgumentParser(...)
        ...
        args = parser.parse_args(args)
    
        nearbin(args.bin)
    
    if __name__ == '__main__':
        sys.exit(main(sys.argv[1:]))
    

    This lets you support direct command-line invocation (./script.py -bin 20), invocation with command line args (main("-bin 20".split())), and programmatic invocation (nearbin(20)).

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

Sidebar

Related Questions

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
def withPositionalArgs(*args): print args, type(args) def withTupleAsArgument(tupleArg): print tupleArg, type(tupleArg) a=1 b=2 c=[10,20] print
def comb(c: Int, r: Int): Int = { if(r == 1) c else if(r
def funct(): x = 4 action = (lambda n: x ** n) return action
def login debugger LOGIN::authenticate(params) end When it hits the line with debugger, I type
def get_type x = [{:type=>'A', :patterns=>['foo.*']}, {:type=>'B', :patterns=>['bar.*']}] name = 'foo.txt' result = x.each
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def self.jq_column_models COLUMN_NAME.collect {|x| {:name => x.to_s, :width => 80, :format => 'integer' if
def On_Instrumentation_StartAnimation(): Syntax : On_Instrumentation_StartAnimation() Purpose : Fired if the animation is started Parameters

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.