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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:57:06+00:00 2026-06-17T17:57:06+00:00

A few weeks ago I started learning Python, and I figured the best way

  • 0

A few weeks ago I started learning Python, and I figured the best way to get the hang of it was to jump straight in by making a simple (?) text-based game with the option to save your progress and reload your saved game to continue later.

Since I need it to write a saved object containing several nested lists and dictionaries (rather than a simple string), I went with Pickle.

What’s going wrong is this: The save() function works fine on its own, but I later need to access two of the variables within it. For some reason, no matter what I do, save() won’t return savePath and saveName; it throws a NameError: savePath/saveName is not defined. I am sure it’s something really stupid and obvious that I’m missing, but I can’t see what.

P.S. I apologize for the messiness of my code—I haven’t really learned how to code efficiently yet.

For this I’ve cut out the working functions and simplified the classes, but in essence everything else is the same.

http://pastebin.com/x7UPYe5T

Any ideas would be greatly appreciated. I just know I’m going to be kicking myself when I see what the problem is …

  • 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-17T17:57:07+00:00Added an answer on June 17, 2026 at 5:57 pm

    Fundamentally, your problem is that you’re expecting savePath and saveName to be in global scope, where they are only available in the function save(). Your immediate problem will likely be addressed just by including the line:

    global saveName, savePath
    

    at the top of the save() function.

    This is a good blog post explaining some the differences in variable scope. See also docs to Python global.

    That said: global variables are often a sign of problematic design. Especially since you’re taking the trouble to return savePath and saveName, a better solution would be to make sure you actually save these values when you return them:

    (savePath, saveName) = save()
    

    Here again, you’re saving global scope — but when you wrap that outer level of code in a function, you’ll have better encapsulation.

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

Sidebar

Related Questions

I started learning ruby on rails few weeks ago. I don't completely understand metaprogramming
A few weeks ago I started making a change in my SVN repository's trunk
I've started learning Objective-C a few weeks ago and I still don't understand how
I've just started learning Java (about a week ago) and the last few days
I have started programming a few weeks ago in java/android. I want to write
I started a github project a few weeks ago. I was able to push
we started a paper on Haskell a few weeks ago and just received our
Few weeks ago I started using VS 2008 (Professional) with Windows 7 (Enterprise). When
a few weeks ago I started to use xsd.exe for create classes for serialization/deserialization
I started working with C# a few weeks ago and I'm now in 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.