?
Solved

ValueError: invalid literal for int() with base 10:

Posted on 2011-10-27
3
Medium Priority
?
1,553 Views
Last Modified: 2012-05-12
The problem I am having is when I capture my new starting incident number and write it to incident.txt if I then call  self.refresh which is the module I get the error below that I need to run to refresh the entire program ... in fact when I check the file there is nothing written to it.... but if I don't send it to refresh , (remove the call self.refresh) but shut it down and restart it ... everything works fine the information is written to the file... my question is why isn't it being written the way I have it written .... and is there a fix ?


Traceback (most recent call last):
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 846, in Newevent
    self.testforpassword()
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 857, in testforpassword
    self.archive()
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 875, in archive
    self.startinincidentnumber(self)
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 892, in startinincidentnumber
    self.databasesetup()
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 906, in databasesetup
    self.refresh()
  File "c:\Python26\sign\OCTOBER26_redo_new Event.py", line 470, in refresh
    self.Ic_num = int(self.incident)
ValueError: invalid literal for int() with base 10: ''

Open in new window






 def refresh(self):
	f =open("incident.txt")
        self.incident = f.readline() # reads the lines and returns their list including the final \n
        f.close()
	
        self.initContact = ''
        self.Inservice = ''
        self.Hospital1 = ''
        
        #load database contents'''
        conn = lite.connect("PermPatRecord.sqlite")
        c = conn.cursor()
        c.execute('select * from ptrecords')
        self.Ic_num = int(self.incident)
	
        a=0
        for i in c:
            self.Ic_num = int(i[1])
            self.statusbar.SetStatusText("Incident# %s" % str(self.Ic_num+1),1)
            a = 1
        if a==0:
            self.statusbar.SetStatusText("Incident# %s" % str(self.Ic_num),1)
        
        self.num_ptct = 0
       # self.Genrandomnumber()
        self.populate()

  def Newevent (self,event):
	
	self.newevent = wx.TextEntryDialog(self, 'Please Enter Your Password','Password',style=wx.OK |wx.CANCEL |wx.TE_PASSWORD)
	if self.newevent.ShowModal()==wx.ID_CANCEL:
	    self.newevent.Destroy()
	    return False
	else:
	    pass
	self.testforpassword()
    
    def testforpassword(self):
	w=open("password.txt", "r")
	self.passorig=(w.read()) 
	w.close()
	self.passwd=self.newevent.GetValue()
	h = hashlib.sha224(self.passwd)
	self.passwrd2011 = h.hexdigest()
	
	if str(self.passwrd2011)==str(self.passorig):
	    self.archive()
	    return True
	else:
	    dlg = wx.MessageDialog(self, "Incorrect Administrator Password !", caption = "Error Please Try Again" , style = wx.OK | wx.ICON_EXCLAMATION)
	    dlg.ShowModal()
	    dlg == wx.OK
	    dlg.Destroy() 
    def archive(self):
	try:
	    self.dirname=''
	    self.control=''
	    dlg = wx.FileDialog(self, "Save Existing Event", self.dirname, "", "Sqlite Files(*.sqlite)|*.sqlite", \
	    wx.SAVE | wx.OVERWRITE_PROMPT)
	    if dlg.ShowModal() == wx.ID_OK:		
		saveAs = r'%s' % dlg.GetPath().encode()		
		filename= "PermPatRecord.sqlite"
		shutil.copyfile(filename,saveAs)
		
		self.startinincidentnumber(self)
	except error:
	    dlg = wx.MessageDialog(self, "There Was a Problem Saving Your Event", caption = "Error Please Try Again Later " , style = wx.OK | wx.ICON_EXCLAMATION)
	    dlg.ShowModal()
	    dlg == wx.OK
	    dlg.Destroy() 
    def startinincidentnumber(self,event):
	self.newnumber = wx.TextEntryDialog(self, 'Enter Starting Incident Number','Text Entry')
	self.newnumber.ShowModal()
	startnum = self.newnumber.GetValue()
	number=open ("incident.txt","w")
	self.startnumber=startnum
	number.write(startnum)
	print number
	
	
	number.close
	self.databasesetup()
    def databasesetup(self):
	print  "here"
	w = open("incident.txt", "r")
        pd =(w.read())
        print "this is pd",pd
	print  pd
	w.close
	self.Ic_num=(self.incident)
	print self.Ic_num
	connect = sqlite3.connect("PermPatRecord.sqlite")
	connect.execute("delete from ptrecords")
	connect.commit()
	connect.close()
	self.refresh()
	self.populate()
	self.successfulnewevent()
    def successfulnewevent(self):
	dlg = wx.MessageDialog(self, "A New Event Has Been Created", caption = "Congratulation ! " , style = wx.OK | wx.ICON_EXCLAMATION)
	dlg.ShowModal()
	dlg == wx.OK
	dlg.Destroy()

Open in new window

0
Comment
Question by:dolamitejenkins
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
gelonida earned 2000 total points
ID: 37039908
Perhaps the problem is following:

You have to call the close function, which you tried to do in line 81.

However you forgot the parenthesis

number.close()

Thus the close function was never called.
0
 
LVL 17

Expert Comment

by:gelonida
ID: 37039966
You should look at pylint ( http://www.logilab.org/857 ) and regularly (or whenever you encounter a problem) run it at against  your code.

If you would run pylint against attached code snippet you would see a lot of output amongst which you would find.

C:  1: Missing docstring
C:  1: Invalid name "f" (should match (([A-Z
C:  2: Invalid name "data" (should match (([
W:  3: Statement seems to have no effect


The warning "Statement seems to have no effect" is the warning, which might have shown you that something is probably not as you intended it to be.


http://www.logilab.org/857


f = open('fname.txt')
data = f.read()
f.close

Open in new window

0
 

Author Closing Comment

by:dolamitejenkins
ID: 37039990
Thanks again .... your where absolutely right I forgot the ()
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question