Hello and welcome to CertForums.co.uk, here we host free active certification forums with links to the best free resources for Microsoft's MCSA MCSE MCDBA Cisco's CCNA CCDA and CCNP, and CompTIA's A+ Network+ i-NET+ and Security+ certifications in the UK. If you wish to post or use other advanced features you will need to register first. Registration is absolutely free and takes only a few minutes to complete so sign up today!

If you have any problems with the registration process or your account login, please contact support

Go Back   CertForums > Computing Support Forums > Programming & Scripting
Home Forums Register Search Today's Posts Mark Forums Read

Python File I/O Assignment headache

Post New ThreadReply
 
Thread Tools Display Modes
  #16  
Old 13-Apr-2008, 07:20 PM
Mathematix's Avatar
Mathematix Mathematix is offline
Longterm Member
Posts: 839
Points: 1149 Mathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 points
Power: 24
None
Join Date: 09 Mar 2006
Location: London
Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
WIP: Not doing certs. Computer geek.
Hey Trip!

Found what the problem was immediately, but will leave you to read the code to deduce what it is. ;)


 
Reply With Quote
  #17  
Old 13-Apr-2008, 07:31 PM
tripwire45's Avatar
tripwire45 tripwire45 is offline
Administrator
Posts: 13,478
Points: 4044 tripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 points
Power: 184
None
Join Date: 29 Jun 2003
Location: Boise, ID, USA
Certifications: A+ and Network+
The problem with your code or mine?


You know, I wish my parents played Mozart when I slept because half the time I don't even know what the heck anyone's talking about!
 
Reply With Quote
  #18  
Old 13-Apr-2008, 08:35 PM
Mathematix's Avatar
Mathematix Mathematix is offline
Longterm Member
Posts: 839
Points: 1149 Mathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 points
Power: 24
None
Join Date: 09 Mar 2006
Location: London
Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
WIP: Not doing certs. Computer geek.
The error message for the code that I posted.


 
Reply With Quote
  #19  
Old 13-Apr-2008, 09:43 PM
tripwire45's Avatar
tripwire45 tripwire45 is offline
Administrator
Posts: 13,478
Points: 4044 tripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 points
Power: 184
None
Join Date: 29 Jun 2003
Location: Boise, ID, USA
Certifications: A+ and Network+
Quote:
Originally Posted by Mathematix View Post
The error message for the code that I posted.
Ok. Thanks. I'll let you know when I have it sorted.


You know, I wish my parents played Mozart when I slept because half the time I don't even know what the heck anyone's talking about!
 
Reply With Quote
  #20  
Old 13-Apr-2008, 11:31 PM
tripwire45's Avatar
tripwire45 tripwire45 is offline
Administrator
Posts: 13,478
Points: 4044 tripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 points
Power: 184
None
Join Date: 29 Jun 2003
Location: Boise, ID, USA
Certifications: A+ and Network+
The part of the program defining how option 4 should lookup an existing name and number should be written as follows:
Code:
def lookUpdetails(name):
    '''
    Retrieves details for 'name'
    if they exist.
    '''
    
    global number
    
    if not number.has_key(name):
        print "Key doesn't exist."
    else:
        print "Name: %s and Number: %s" % (name, number[name])
In the original program, the word number which I have bolded is actually written as key. I think you just looked at "if not number.has_key(name)" and focused on "key(name)".

I made the change and tested the program. It works now. I guess there's hope for me yet.


You know, I wish my parents played Mozart when I slept because half the time I don't even know what the heck anyone's talking about!
 
Reply With Quote
  #21  
Old 14-Apr-2008, 01:31 AM
tripwire45's Avatar
tripwire45 tripwire45 is offline
Administrator
Posts: 13,478
Points: 4044 tripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 points
Power: 184
None
Join Date: 29 Jun 2003
Location: Boise, ID, USA
Certifications: A+ and Network+
I'll just attach the program I'm working on right now (the I/O program) because it's pretty long. I'm posting the specific area that I'm trying to figure out here:
Code:
'''After print >> out_file, there must be a string listed...not a dictionary. What do I put there?'''

def save_grades():
    out_file = open(filename, "w")
    print >> out_file, '''what string goes here?'''
    out_file.close()
I'm attaching it as a txt file since the CF forum software won't recognize the .py extension.
Attached Files
File Type: txt 15-1exercise.txt (2.7 KB, 1 views)


You know, I wish my parents played Mozart when I slept because half the time I don't even know what the heck anyone's talking about!
 
Reply With Quote
  #22  
Old 14-Apr-2008, 08:56 PM
Mathematix's Avatar
Mathematix Mathematix is offline
Longterm Member
Posts: 839
Points: 1149 Mathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 points
Power: 24
None
Join Date: 09 Mar 2006
Location: London
Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
WIP: Not doing certs. Computer geek.
some ideas to investigate. your tutorial text should have provided some of these examples.


 
Reply With Quote
  #23  
Old 15-Apr-2008, 12:27 AM
tripwire45's Avatar
tripwire45 tripwire45 is offline
Administrator
Posts: 13,478
Points: 4044 tripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 pointstripwire45 has over 4000 points
Power: 184
None
Join Date: 29 Jun 2003
Location: Boise, ID, USA
Certifications: A+ and Network+
Quote:
Originally Posted by Mathematix View Post
some ideas to investigate. your tutorial text should have provided some of these examples.
Thanks. Kewl looking Python tutorial.


You know, I wish my parents played Mozart when I slept because half the time I don't even know what the heck anyone's talking about!
 
Reply With Quote
Post New ThreadReply Spread this thread: Submit this thread to digg Submit this thread to del.icio.us


Go Back   CertForums > Computing Support Forums > Programming & Scripting


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python to create UNIX command line tools tripwire45 News 1 21-Mar-2008 07:53 PM
Building a Home File Server tripwire45 News 7 18-Jan-2008 03:32 PM
Page File / Swap File / Virtual Memory oush Software 16 04-Jan-2008 08:30 AM
Moving winRAR file to external HDD Bambino1506 Software 25 27-Sep-2007 09:54 PM
Corrupt File Mailbox itdaddy Exchange Exams 3 21-Sep-2006 03:23 PM


All times are GMT. The time now is 11:40 PM.

Powered by vBulletin® Version 3.6.11
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
CertForums.co.uk (C) copyright 2003-2007 All Rights Reserved. Content published on CertForums.co.uk requires permission for reprint.
Hosted by Lunarpages