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

The Archive Base Latest Questions

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

In a script I’m trying to import the main module from another script with

  • 0

In a script I’m trying to import the main module from another script with an argument.

I get the error message “NameError: global name ‘model’ is not defined”.

If someone sees the mistake, I’d be grateful !

My code :

script1

#!/usr/bin/python

import sys
import getopt
import pdb
import shelve

class Car:
    """ class representing a car object """
    def __init__(self, model):
        self.model = model

class Porsche(Car):
    """ class representing a Porsche """
    def __init__(self, model):       
        Car.__init__(self, model)
        print "I have a Porsche but no driving licence : too bad !"

# Main
def main(argv):

    settings = shelve.open('mySettings')
    global model
    try:
        opts, args = getopt.getopt(argv, "m:", ["model="])
    except getopt.GetoptError, err:
           print " wrong argument, exiting "
           sys.exit()
    for opt, arg in opts:
        if opt in ("-m", "--model"):
            model = arg

    def choose_car(model):
        """ Creates the car"""
        my_Porsche = Porsche(model)     

    choose_car(model)

if __name__ == "__main__":
   main(sys.argv[1:]) 

script2

#!/usr/bin/python

import os
import sample
import sys

def main(argv):
        script1.main("-m Carrera")

# Main program
if __name__ == '__main__':
    main(sys.argv[1:])

rgds,

  • 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:53:02+00:00Added an answer on May 16, 2026 at 3:53 pm

    argv is a list. Therefore you should call script1.main as

    script1.main(['-m', 'Carrera'])
    

    or, equivalently,

    script1.main('-m Carrera'.split())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • 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 Queries are queued, so if the SELECT occurs before the… May 16, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer Yes, pass an array of the object and the method… May 16, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer AFAIK, what you are calling a class level variable in… May 16, 2026 at 11:33 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

Script: http://keith-wood.name/countdown.htm Daily json response: items: { fajr: '5:23 am', sharooq: '7:23 am', dhur:
script/generate acts_as_taggable_on_migration rake db:migrate causes Mysql::Error: Specified key was too long; max key length
The script I am trying to run via shell_exec in PHP requires an environmental
The script will be called from a URL like example.com/photo.php?id=123 or example.com/photos/123 depending on
My script is supposed to find all related posts from the current posts categories
Script test.sh: #!/bin/bash if [[ $# -eq 0 ]]; then echo no arg else
Script Example: @SET APPLY_ORA=YES @REM ... IF %APPLY_ORA%==YES ( @ECHO Doing Oracle CALL %SOME_ORACLE_SPECIFIC_COMMAND%
Script adds id for block, gives: <div id=some>Text</div> After that page should jump for
Script replaces rel attributes to class . Full code - http://jsbin.com/efozi3/8/ It doesn't work
A script is misbehaving. I need to know who calls that script, and who

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.