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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:15+00:00 2026-05-26T09:05:15+00:00

I am programming in python and need to access the name I have given

  • 0

I am programming in python and need to access the name I have given to an object so as to be able to pass this as a string (concatenated with another string).

The reason I need to do this is that the program I am using forces me to create a global (which in my case is a dictionary) and I am writing a function to work in general with several different objects (which each have similar sets of properties, eg. object 1 is of length 2 (signifying in my case 2 neurons) labelled 0 and 1 and each of these has 4 properties a,b,c,d. I want to create a “dictionary filetree” of these properties but both object1 and object 2 are 2 instances of the same class, therefore I need to change the first level keys to being ‘NAME1_0, ‘NAME1_1’, ‘NAME2_0’, ‘NAME2_1’).

def Init(neuron,input):
#Initialises the neuron group, arguements are neuron (neurongroup) and input (neurongroup)
global dict
dict={}
for x in range(0,len(neuron)):
    neuron[x].L=0
    neuron[x].G=0
    neuron[x].ron=1/period
    neuron[x].roff=1/period
    dict[x]={'tau_on':0.5,
             'Non_off':neuron[x].roff*0.5,
             'Non_off':neuron[x].ron*0.5,
             'Ni_on':ones(len(input))*qon*0.5,
             'Ni':ones(len(input))*qoff*0.5+ones(len(input))*qon*0.5,
             'p_current':0,
             'p_previous':0,
             'my_tau_on':[],
             'my_Non_off':[],
             'my_Noff_on':[],
             'my_Ni_on':[],
             'my_Ni':[],
             'my_p_on':[],
             'my_ron':[],
             'my_roff':[],
             'my_theta':[],
             'my_weights':[],
             'my_record_times':[]}
     dict['%s' % x, neuron]=dict.pop(x)

does not work as it does not give the name assigned to the object but merely the name of the object itself. for a more minimal case of my problem

NAME1=4
def func(x):    #creates string of 'NAME1'
    print 'x'

func(NAME1)
#output='NAME1'
  • 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-26T09:05:16+00:00Added an answer on May 26, 2026 at 9:05 am

    Your could do a reverse lookup of the names in globals():

    >>> NAME1 = 4
    >>> def name_of(value):
            for k, v in globals().items():
                if v is value:
                    return k
            raise KeyError('did not find a name for %s' % value)
    
    >>> name_of(NAME1)
    'NAME1'
    

    If the same object has been assigned to more than one name, only one name will be returned.

    If you want to search more broadly than just globals, look for the dicts in gc.get_referrers(value) and capture all matches:

    >>> def names_of(value):
            'Find all names for the value'
            result = []
            for d in gc.get_referrers(value):
                if isinstance(d, dict):
                    for k, v in d.items():
                        if v is value:
                            result.append(k)
            return result
    
    >>> import math
    >>> pie = math.pi
    >>> names_of(pie)
    ['pie', '_pi', 'pi', 'pi']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python programming. I have this problem: I have a list of
I have been programming in Python, PHP, Java and C for a couple or
I need to have an at-home project now that I'm working on Python/Django at
I am new to network programming but old to Python. I have a simple
I have a question about righteous way of programming in Python... Maybe there can
I'm reading Tutorial on Network Programming with Python , and in this document the
Im new to python programming and need some help with some basic file I/O
I'm been programming with Python in AppEngine for the last months, and I need
I have never done Python programming before but I have done a lot of
I have been doing python programming for my project and I have just started.

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.