473,508 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I am having a problem with shelve......

4 New Member
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.

Code:
Expand|Select|Wrap|Line Numbers
  1. import shelve
  2.  
  3.     high_space = 3000
  4.  
  5.     file_sizeh = file_size * week_selec
  6.     h_back = high_space - file_sizeh
  7.     db = shelve.open("netback.dat")
  8.     db['hremspace'] = h_back
  9.     db.close()
  10.     for h_back in hremspace != 3000 :
  11.         print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
  12.         print'after your backup of ',file_sizeh,' Mb\'s'
  13.         db['hremspace'] = h_back
  14.         db['netback'] = back_name
  15.         db['Highprofile'] = file_sizeh
  16.     else:
  17.         for h_back in db['hremspace'] > 0:
  18.             print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
  19.             print'after your backup of ',file_sizeh,' Mb\'s'
  20.             db['hremspace'] = h_back
  21.             db['netback'] = back_name
  22.             db['Highprofile'] = file_sizeh
  23.         else:
  24.             print'There is not enough space to save your backup.'
  25.             print'Please delete a backup and try again.'
File "C:\Users\------\Desktop\finalprojbac.py", line 112, in high_Priority
for h_back in hremspace != 3000 :
NameError: global name 'hremspace' is not defined
Aug 10 '10 #1
5 1489
bvdet
2,851 Recognized Expert Moderator Specialist
Line number 10 is the problem. The identifier hremspace has not been assigned to any value. The dictionary entry db['hremspace'] was assigned to h_back.

You have another problem on that line. Notice the TypeError:
Expand|Select|Wrap|Line Numbers
  1. >>> for item in (1,2,3,4,5) != 3000:
  2. ...     print item
  3. ...     
  4. Traceback (most recent call last):
  5.   File "<interactive input>", line 1, in ?
  6. TypeError: iteration over non-sequence
Maybe you need something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> for item in (1,2,3,4,5):
  2. ...     if item != 3000:
  3. ...         print item
  4. ...         
  5. 1
  6. 2
  7. 3
  8. 4
  9. 5
  10. >>> 
Aug 10 '10 #2
Fearx351
4 New Member
oh ok I guess I was trying to compare a value to a key? I am new to this so its still a big learning process for me . Basically I am trying to check the entry to make sure that value isnt 3000 . The reason being,is that If I didnt 3000 would be assigned everytime the function was executed. Like I said I am new to this and I really couldnt think of any other way around this.
Aug 10 '10 #3
dwblas
626 Recognized Expert Contributor
Try printing first to understand what the dictionary is.
Expand|Select|Wrap|Line Numbers
  1. db = shelve.open("netback.dat")
  2. print "hremspace value is", db['hremspace']
  3. db['hremspace'] = 1000
  4. print "hremspace value is now", db['hremspace'] 
  5. x = 100
  6. db['hremspace'] += x
  7. print "hremspace value is now", db['hremspace'] 
print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
print'after your backup of ',file_sizeh,' Mb\'s'
If you are trying to compute the size of the backup or space remaining please supply info on what you wish to do (and sample input data would help).
Aug 11 '10 #4
Fearx351
4 New Member
Basically what I want to do is have a set value(backup) and when the user inputs a specific backup. it will access the db and update and or subtract the necessary value.

I will post my current code just so you can get a better idea of what I am trying to do.

Expand|Select|Wrap|Line Numbers
  1. ##Jeffrey Clark
  2. ##IT104
  3. ##Professor Brooker
  4. ##08/04/2010
  5. ##This program will create a network backup for user.
  6.  
  7. def main():
  8.     ##Main Function
  9.  
  10.     get_Command()
  11.  
  12. def get_Command():
  13.     ##Displays the Main Menu
  14.  
  15.     print'[]=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=[]'
  16.     print'[]This program will create a network backup routine for the user.[]'
  17.     print'[]=\=\=\=\=\=\=\=[]/=/=/=/=/=/=/=/=/=/=/=/=/=/=/[]=\=\=\=\=\=\=\=[]'                
  18.     print'                 []..........Main Menu..........[]'
  19.     print'                 []=\=\=\=\=\=\=\=\=\=\=\=\=\=\=[]'
  20.     print'                 []1.Create a New Backup        []'
  21.     print'                 []2.Remove a Backup Item       []'
  22.     print'                 []3.View Current Backups       []'
  23.     print'                 []4.Exit                       []'
  24.     print'                 []=/=/=/=/=/=/=/=/=/=/=/=/=/=/=[]'
  25.     get_Selection()
  26.  
  27. def get_Selection():
  28.     ##Gets the users selection from the Menu
  29.  
  30.     print
  31.     selection = input('Please make a selection from the Menu: ')
  32.  
  33.     if selection == 1:
  34.         new_Backup()
  35.     else:
  36.         if selection == 2:
  37.             rem_Backup()
  38.         else:
  39.             if selection == 3:
  40.                 readFile()
  41.             else:
  42.                 if selection == 4:
  43.                     exit_prog()
  44.                 else:
  45.                     print'You have chosen an invalid Option'
  46.                     get_Selection()
  47.  
  48. def new_Backup():
  49.  
  50.     global file_size
  51.     global back_name
  52.     ##Creates a new Backup for user
  53.  
  54.     back_name = raw_input('Please enter the name of the Backup: ')
  55.     file_size = input('Please enter the size of the file you wish to backup in MB\'s:')
  56.     net_week()
  57.  
  58. def net_week():
  59.     ##
  60.     global week_selec
  61.  
  62.     print''
  63.     print'[]How often will the backup be backed up?[]'
  64.     print'[]Make a selection 1-7'
  65.     print'[]'
  66.  
  67.     week_selec = input('Please make a selection from Menu:')
  68.     if week_selec <= 7:
  69.         week_selec = week_selec
  70.     else:
  71.         print'The number you have chosen is out of range'
  72.     file_Prior()
  73.  
  74. def file_Prior():
  75.     ##
  76.  
  77.  
  78.     print''
  79.     print'[]What is the priority level of Backup?[]'
  80.     print'[]1.High Priority'
  81.     print'[]2.Medium Priority'
  82.     print'[]3.Low Priority'
  83.     prior_selec = input('Please make a selection from Menu:')
  84.  
  85.     if prior_selec == 1:
  86.         high_Priority()
  87.     else:
  88.         if prior_selec == 2:
  89.             prior_selec =  m_prior
  90.             med_Priority()
  91.         else:
  92.             if prior_selec == 3:
  93.                 prior_selec =  l_prior
  94.                 low_Priority()
  95.             else:
  96.                 print'You have made an invalid selection'
  97.                 file_prior()
  98.  
  99. def high_Priority():
  100.     ##
  101.     global file_sizeh
  102.     print''
  103.     import shelve
  104.  
  105.  
  106.     high_space = 3000
  107.     file_sizeh = file_size * week_selec
  108.     h_back = high_space - file_sizeh
  109.     db = shelve.open('netback.dat')
  110.     db['hremspace'] = h_back
  111.     db['netback'] = back_name
  112.     db['Highprofile'] = file_sizeh
  113.     print db.keys()
  114.  
  115.     if db['hremspace'] != 3000:
  116.  
  117.         print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
  118.         print'after your backup name:',db['netback'],'of',file_sizeh,' Mb\'s'
  119.         db['hremspace'] = h_back
  120.         db['netback'] = back_name
  121.         db['Highprofile'] = file_sizeh
  122.  
  123.     else:
  124.         for h_back in back_name > 0:
  125.             print'There are ',db['hremspace'],' Mb\'s left in High priority storage'
  126.             print'after your backup of ',file_sizeh,' Mb\'s'
  127.             db['hremspace'] = h_back
  128.             db['netback'] = back_name
  129.             db['Highprofile'] = file_sizeh
  130.         else:
  131.             print'There is not enough space to save your backup.'
  132.             print'Please delete a backup and try again.'
  133.  
  134.  
  135. def med_Priority(file_sizem,):
  136.     ##
  137.     print''
  138.     med_space = 5000
  139.  
  140.     file_sizem = file_size * week_selec
  141.     m_back = med_space - file_sizem
  142.  
  143.     if m_back > 0 :
  144.          print'There are ',m_back,' Mb\'s left in Medium priority storage'
  145.          print'after your backup of ',file_sizem,' mb\s'
  146.          write_File()
  147.     else:
  148.         print'There is not enough space to save your backup.'
  149.         print'Please delete a backup and try again.'
  150.  
  151.     import shelve
  152.     ldb = shelve.open("netbackl.dat")
  153.     ldb['netback'] = back_name
  154.     ldb['Medprofile'] = file_sizem
  155.  
  156. def low_Priority(file_sizel,):
  157.     ##
  158.     print''
  159.     low_space = 9000
  160.  
  161.     file_sizel = file_size * week_selec
  162.     l_back = low_space - file_sizel
  163.  
  164.     if l_back > 0 :
  165.          print'There are ',l_back,' Mb\'s left in Low priority storage'
  166.          print'after your backup of ',file_sizel,' Mb\s'
  167.          write_File()
  168.     else:
  169.         print'There is not enough space to save your backup.'
  170.         print'Please delete a backup and try again.'
  171.  
  172.     import shelve
  173.     ldb = shelve.open("netbackl.dat")
  174.     ldb['netback'] = back_name
  175.     ldb['Lowprofile'] = file_sizel
  176.  
  177. def write_File():
  178.     ##
  179.  
  180.     import shelve
  181.     db = shelve.open("netback.dat")
  182.     db['netback'] = back_name
  183.     db['filesize'] = file_size
  184.     print db.keys()
  185.     try:
  186.         print db['netback']
  187.         print db['filesize']
  188.     finally:
  189.         db.close()
  190.  
  191. def readFile(db,):
  192.     ##Opens file to read
  193.     print'asd'
  194.     try:
  195.         print db['netback']
  196.         print db['filesize']
  197.     finally:
  198.         db.close()
  199. main()
  200.  
I am sorry for the unorganized code I am a student and I am still learning.
Aug 24 '10 #5
Fearx351
4 New Member
bump....................
Aug 25 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2121
by: Chad | last post by:
I am trying to burn copies of our website on CDROM's and having problems because the ASP's cannot work without the existance of a server that supports ASP's. Does anyone have a suggestion or know...
1
1524
by: Dave Brown | last post by:
Hi All, Trying to get a simple query going using group by and order by I need to retrieve the latest record ordered by datetimestamp desc but grouped by my nodeID column... my data is thus;...
6
4777
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private...
8
1634
by: Vmz | last post by:
HI, I got two queues, I need to write void function that would check both queues and remove from first queue all nodes that matches second queue. Each node has two pointers that shows to previous...
0
1621
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops...
4
2597
by: jgill | last post by:
Having problem with the following HTML code in IE7, everything works fine in IE6: <option value='215001' label='250000,15,10,1'>215001 |A.J. Longo & Associates</option> In IE6 I see “215001 |A.J....
3
1220
by: sheena81 | last post by:
hi, im still having problem with sql server connection. my server is not at the same place, it's at other country. the command that i have used is as below : <% Set demoConn =...
2
998
by: shamaila | last post by:
i want to retrieve primary key of parent table and then send this key to child table,as they have one-one relationship i've written code int i; string id = "SELECT MAX(c_id) FROM call_history";...
1
1274
by: smartic | last post by:
Having problem with some characters like ( # , + , &) in my PHP page i can't see these characters in my database how can isolve this problem ?
1
1492
by: eishita | last post by:
Hi there I have created a server using Linux Mandriva 2010.0. but having problem while setting the database connectivity. Whenever I'm typing the command --- # mysqladmin -u root password...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.