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: -
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.'
File "C:\Users\------\Desktop\finalprojbac.py", line 112, in high_Priority
for h_back in hremspace != 3000 :
NameError: global name 'hremspace' is not defined
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: - >>> for item in (1,2,3,4,5) != 3000:
-
... print item
-
...
-
Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
TypeError: iteration over non-sequence
Maybe you need something like this: - >>> for item in (1,2,3,4,5):
-
... if item != 3000:
-
... print item
-
...
-
1
-
2
-
3
-
4
-
5
-
>>>
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.
dwblas 626
Recognized Expert Contributor
Try printing first to understand what the dictionary is. - db = shelve.open("netback.dat")
-
print "hremspace value is", db['hremspace']
-
db['hremspace'] = 1000
-
print "hremspace value is now", db['hremspace']
-
x = 100
-
db['hremspace'] += x
-
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).
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. -
##Jeffrey Clark
-
##IT104
-
##Professor Brooker
-
##08/04/2010
-
##This program will create a network backup for user.
-
-
def main():
-
##Main Function
-
-
get_Command()
-
-
def get_Command():
-
##Displays the Main Menu
-
-
print'[]=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=[]'
-
print'[]This program will create a network backup routine for the user.[]'
-
print'[]=\=\=\=\=\=\=\=[]/=/=/=/=/=/=/=/=/=/=/=/=/=/=/[]=\=\=\=\=\=\=\=[]'
-
print' []..........Main Menu..........[]'
-
print' []=\=\=\=\=\=\=\=\=\=\=\=\=\=\=[]'
-
print' []1.Create a New Backup []'
-
print' []2.Remove a Backup Item []'
-
print' []3.View Current Backups []'
-
print' []4.Exit []'
-
print' []=/=/=/=/=/=/=/=/=/=/=/=/=/=/=[]'
-
get_Selection()
-
-
def get_Selection():
-
##Gets the users selection from the Menu
-
-
print
-
selection = input('Please make a selection from the Menu: ')
-
-
if selection == 1:
-
new_Backup()
-
else:
-
if selection == 2:
-
rem_Backup()
-
else:
-
if selection == 3:
-
readFile()
-
else:
-
if selection == 4:
-
exit_prog()
-
else:
-
print'You have chosen an invalid Option'
-
get_Selection()
-
-
def new_Backup():
-
-
global file_size
-
global back_name
-
##Creates a new Backup for user
-
-
back_name = raw_input('Please enter the name of the Backup: ')
-
file_size = input('Please enter the size of the file you wish to backup in MB\'s:')
-
net_week()
-
-
def net_week():
-
##
-
global week_selec
-
-
print''
-
print'[]How often will the backup be backed up?[]'
-
print'[]Make a selection 1-7'
-
print'[]'
-
-
week_selec = input('Please make a selection from Menu:')
-
if week_selec <= 7:
-
week_selec = week_selec
-
else:
-
print'The number you have chosen is out of range'
-
file_Prior()
-
-
def file_Prior():
-
##
-
-
-
print''
-
print'[]What is the priority level of Backup?[]'
-
print'[]1.High Priority'
-
print'[]2.Medium Priority'
-
print'[]3.Low Priority'
-
prior_selec = input('Please make a selection from Menu:')
-
-
if prior_selec == 1:
-
high_Priority()
-
else:
-
if prior_selec == 2:
-
prior_selec = m_prior
-
med_Priority()
-
else:
-
if prior_selec == 3:
-
prior_selec = l_prior
-
low_Priority()
-
else:
-
print'You have made an invalid selection'
-
file_prior()
-
-
def high_Priority():
-
##
-
global file_sizeh
-
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['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 name:',db['netback'],'of',file_sizeh,' Mb\'s'
-
db['hremspace'] = h_back
-
db['netback'] = back_name
-
db['Highprofile'] = file_sizeh
-
-
else:
-
for h_back in back_name > 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.'
-
-
-
def med_Priority(file_sizem,):
-
##
-
print''
-
med_space = 5000
-
-
file_sizem = file_size * week_selec
-
m_back = med_space - file_sizem
-
-
if m_back > 0 :
-
print'There are ',m_back,' Mb\'s left in Medium priority storage'
-
print'after your backup of ',file_sizem,' mb\s'
-
write_File()
-
else:
-
print'There is not enough space to save your backup.'
-
print'Please delete a backup and try again.'
-
-
import shelve
-
ldb = shelve.open("netbackl.dat")
-
ldb['netback'] = back_name
-
ldb['Medprofile'] = file_sizem
-
-
def low_Priority(file_sizel,):
-
##
-
print''
-
low_space = 9000
-
-
file_sizel = file_size * week_selec
-
l_back = low_space - file_sizel
-
-
if l_back > 0 :
-
print'There are ',l_back,' Mb\'s left in Low priority storage'
-
print'after your backup of ',file_sizel,' Mb\s'
-
write_File()
-
else:
-
print'There is not enough space to save your backup.'
-
print'Please delete a backup and try again.'
-
-
import shelve
-
ldb = shelve.open("netbackl.dat")
-
ldb['netback'] = back_name
-
ldb['Lowprofile'] = file_sizel
-
-
def write_File():
-
##
-
-
import shelve
-
db = shelve.open("netback.dat")
-
db['netback'] = back_name
-
db['filesize'] = file_size
-
print db.keys()
-
try:
-
print db['netback']
-
print db['filesize']
-
finally:
-
db.close()
-
-
def readFile(db,):
-
##Opens file to read
-
print'asd'
-
try:
-
print db['netback']
-
print db['filesize']
-
finally:
-
db.close()
-
main()
-
I am sorry for the unorganized code I am a student and I am still learning.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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;...
|
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...
|
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...
|
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...
| |
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....
|
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 =...
|
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";...
|
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 ?
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |