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

Related Questions

This script saves the files as /home/name/main/all my files and stuff . I want
my script is using utf8_general_ci and im trying to transfer to another script that
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
My script below generates a url if the $.post() response has an error. I
This script seems to get hung up when it hits the series of if
The script below loops through to create tabs and name the tab then it
Script below is not working. Not getting any php error messages. Had asked a
The script below applies random colours from an array to a div id, and
Script: #!/bin/bash vpct=5.3 echo $((vpct*15)) Error: ./abc.sh: line 5: 5.3: syntax error: invalid arithmetic

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.