Re: [Zope] python help needed

2010-01-19 Thread Garry Saddington
Andrew Milton wrote:
> +---[ Garry Saddington ]--
> | I am trying to upload a csv file (called data) using the following script:
> | 
> | i=0
> | d=data.readlines()
> | for row in d:
> |  i+=1
> |  a=row.split(',')
> |  if i > 1:
> |  subjectid=a[0]
> |  entry=a[1]
> |  type=a[2]
> |  studentid=a[3]
> |  try:
> |  
> |  
> | 
> context.insertestimatesandtargets(subjectid=subjectid,entry=entry,type=type,studentid=studentid)
> |  except:
> |  continue
> | return "something good"
> | 
> | (email editor messed up indentation)
> | 
> | insertestimatesandtargets() is a ZSQLmethod. When the call to this 
> | method results in an error the script stops and not all data is 
> | inserted. Without an error all the data is inserted.
> | So how can I make this script skip over errors and continue? The reason 
> | is that there may already be some data in the database table that I want 
> | to preserve.
> 
> The try/except block should prevent the script from failing when calling
> the ZSQL method (assuming your indenting *is* correct in the python
> script [look for mixed tabs/spaces, since in the email some of your
> indents are 8 and some are 4]).
No all correct - Thunderbird not allowing me to edit the text.
> 
> Your other option is to do transaction sub-commits manually (there's
> plenty of google links for how to do this).
> 
> You probably can't do this directly from a python script, you'll have to
> setup an External Method to do it (or alter the security for the
> transaction machinery).
> 
Yes, thanks I thought that was the problem. I've already sorted it with 
external methods.
Garry
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] python help needed

2010-01-19 Thread Andrew Milton
+---[ Garry Saddington ]--
| I am trying to upload a csv file (called data) using the following script:
| 
| i=0
| d=data.readlines()
| for row in d:
|  i+=1
|  a=row.split(',')
|  if i > 1:
|  subjectid=a[0]
|  entry=a[1]
|  type=a[2]
|  studentid=a[3]
|  try:
|  
|  
| 
context.insertestimatesandtargets(subjectid=subjectid,entry=entry,type=type,studentid=studentid)
|  except:
|  continue
| return "something good"
| 
| (email editor messed up indentation)
| 
| insertestimatesandtargets() is a ZSQLmethod. When the call to this 
| method results in an error the script stops and not all data is 
| inserted. Without an error all the data is inserted.
| So how can I make this script skip over errors and continue? The reason 
| is that there may already be some data in the database table that I want 
| to preserve.

The try/except block should prevent the script from failing when calling
the ZSQL method (assuming your indenting *is* correct in the python
script [look for mixed tabs/spaces, since in the email some of your
indents are 8 and some are 4]).

Your other option is to do transaction sub-commits manually (there's
plenty of google links for how to do this).

You probably can't do this directly from a python script, you'll have to
setup an External Method to do it (or alter the security for the
transaction machinery).

-- 
Andrew Milton
a...@theinternet.com.au
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] python help needed

2010-01-19 Thread Garry Saddington
I am trying to upload a csv file (called data) using the following script:

i=0
d=data.readlines()
for row in d:
 i+=1
 a=row.split(',')
 if i > 1:
 subjectid=a[0]
 entry=a[1]
 type=a[2]
 studentid=a[3]
 try:
 
 
context.insertestimatesandtargets(subjectid=subjectid,entry=entry,type=type,studentid=studentid)
 except:
 continue
return "something good"

(email editor messed up indentation)

insertestimatesandtargets() is a ZSQLmethod. When the call to this 
method results in an error the script stops and not all data is 
inserted. Without an error all the data is inserted.
So how can I make this script skip over errors and continue? The reason 
is that there may already be some data in the database table that I want 
to preserve.

regards
Garry
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )