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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:19:19+00:00 2026-05-20T08:19:19+00:00

Preface: So far I’ve used Python as a full scale programming language. Now I

  • 0

Preface:

So far I’ve used Python as a full scale programming language. Now I like to use it to write down some notes (comments) with some calculation (Python code) here and there (I’m actually using Emacs and send the current buffer again and again to a running IPython instance).

The problem: I like to reuse some common variable names like ‘A’ or ‘d’ multiple times within the same document without running into the problem that I accidentally forget to reassign the value to one of these variable names.

I so far abuse the class statement

# Topic one: bla bla
class _anon:
    d = 10
    A = d**2 * pi /4

# Topic two: bla bla
class _anon:
    A = d**2 * pi /4 # error is raised since d is missing

This works, since a class statement creates an execution frame which works as a variable scope, but I wonder if there is dedicated syntax for this use case.

  • 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-20T08:19:20+00:00Added an answer on May 20, 2026 at 8:19 am

    No. Only class and def blocks and modules (and in more recent versions, list comprehensions and generator expressions – not appliable here though) introduce a new scope. And only classes execute directly. So if you want to continue this debatable use of Python, you’ll have to stick with abusing class, or define functions and call them directly. Using a different file for each calculation is slightly less ugly at source code level, but propably not worth it if the calculations are always that small.

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

Sidebar

Related Questions

To preface I am using Borland C++ and the VCL. I need some sort
Let me preface this question by saying I use TextMate on Mac OSX for
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
I'll preface this question by mentioning that while I'm far from a regular expressions
To preface this, I love Moq. I wish I could use it in .NET
We are using WSS 3 SP2. I'd like to preface this by saying that
Just as a preface, I'm not very knowledgeable on T-SQL syntax. I'd like to
I will preface this question by saying, I do not think it is solvable.
Let me preface this by saying I'm a complete amateur when it comes to
I should preface this by saying I'm working on a pocket PC app and

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.