I am new to python and am actually using python as a result of taking a computer science class in college. I am writing a program to fit a hypothetical scenario. Well I have ran into a problem..Please help me!

the traceback and snippet are below.

def high_Priority():
    ##
    
    print''
    import shelve
    
    high_space = 3000

    file_sizeh = file_size * week_selec
    h_back = high_space - file_sizeh
    db = shelve.open("netback.dat")
    db['hremspace'] = h_back
    db.close()
    for h_back in hremspace != 3000 :
        print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
        print'after your backup of ',file_sizeh,' Mb\'s'
        db['hremspace'] = h_back
        db['netback'] = back_name
        db['Highprofile'] = file_sizeh
    else:
        for h_back in db['hremspace'] > 0:
            print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
            print'after your backup of ',file_sizeh,' Mb\'s'
            db['hremspace'] = h_back
            db['netback'] = back_name
            db['Highprofile'] = file_sizeh
        else:
            print'There is not enough space to save your backup.'
            print'Please delete a backup and try again.'

Traceback:
File "C:\Users\-----------\Desktop\finalprojbac.py", line 112, in high_Priority
for h_back in hremspace != 3000 :
NameError: global name 'hremspace' is not defined
>>>

I don't really understand the context but...

def high_Priority():
    ##
    
    print''
    import shelve

    file_sizeh = file_size * week_selec
    db = shelve.open("netback.dat")
    db['hremspace'] = h_back
    if h_back > 0:
        print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
        print'after your backup of ',file_sizeh,' Mb\'s'
        db['hremspace'] = h_back
        db['netback'] = back_name
        db['Highprofile'] = file_sizeh
    else:
        print'There is not enough space to save your backup.'
        print'Please delete a backup and try again.'
    db.close()

Cheers and Happy coding

Basically I am trying to store multiple values to a database. I want to be able to access that value from the db so that it doesnt just overwrite the value of the db everytime that function is executed(with the highspace being set to 3000). I want it to be able to store the seperate values a user inputs every time the program is executed, and the previous value not be effected by that set number.

If this helps this is what I am trying to do. My assignment is that I script a program that simulates a network backup basically the user will input its seperate backups with the backup limit being 3000mb. So if the user had 4 previous backups equaling 2700 if the user put a backup in for 4000 , the program wouldnt go through with storing the value.

>>> db = {}
>>> h_back = 50
>>> db['hremspace'] = h_back
>>> db
{'hremspace': 50}
>>> heremspace
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
NameError: name 'heremspace' is not defined
>>> #So you will get an NameError if hremspace only excit in a dictionary

If this line shall work.
for h_back in hremspace != 3000 :
Somewhere in your code hremspace has to be defined or do you mean to take value for hremspace out off dictionary.

>>> db['hremspace']
50

I mean to take the value out of the dictionary/db

ok so I got the code to work... But like I expected its not doing what I want it to . I just cant figure out how to get this to work.

file_sizeh = file_size * week_selec
    h_back = high_space - file_sizeh
    db = shelve.open('netback.dat')
    db['hremspace'] = h_back
    db['netback'] = back_name
    db['Highprofile'] = file_sizeh
    print db.keys()
                     
    if db['hremspace'] != 3000:
        print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
        print'after your backup of ',db['Highprofile'],' Mb\'s'
        db['hremspace'] = h_back
        db['netback'] = back_name
        db['Highprofile'] = file_sizeh

any suggestions on how to get this to basically take the value store it for next use and make it to where I can take the value held and subtract a variable from that value and store it again basically I want it to be sequential and not retain the same value everytime the function is executed. Sorry for not being able to explain this better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.