Re: [Tutor] Traversing Excel Columns

2006-09-12 Thread John Fouhy
On 12/09/06, Chris Hengge [EMAIL PROTECTED] wrote:
 I don't suppose that anyone has a fix for me eh? I've tried about all I
 can think of and I'd like to be able to give this program a trial
 tomorrow when I get back to work.. sure would save me some time :]

Will there be internal blanks?  You could just scan for Cells(row,
col).Value in (None, '').

Otherwise, run makepy.py (if you haven't already) on Excel, and then
look through the code it generates.  It will show you all the methods
you can call, and what arguments they expect.  Something may leap out
at you.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib

2006-09-12 Thread Kent Johnson
Patricia wrote:
 Hi,
 
 I have used urllib and urllib2 to post data like the following:
 
 dict = {}
 dict['data'] = info
 dict['system'] = aname
 
 data = urllib.urlencode(dict)
 req = urllib2.Request(url)
 
 And to get the data, I emulated a web page with a submit button:   
 s = htmlbody
 s += form  action='a_method' method='POST'
 s += textarea cols='80' rows='200' name='data'/textarea
 s += input type='text' name='system'
 s += input type='submit' value='Submit'
 s += /form/body/html
 
 
 I would like to know how to send a file. It's a text file that will be 
 gzipped before being posted. I'm using python version 2.2.3.

There are some old examples hereA
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

I think the modern way uses email.MIMEMultipart but I don't have an 
example handy.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Traversing Excel Columns

2006-09-12 Thread Etrade Griffiths
Chris

are you looking for something like this?

xlSht=xlApp.Worksheets(Sheet1)

irow=1
XL_row_has_data=1

while XL_row_has_data:
 xlRng=xlSht.Range(xlSht.Cells(irow,1),xlSht.Cells(irow,256))
 ncell=xlApp.WorksheetFunction.CountA(xlRng)

 if ncell ==0:
 # Cells in current row are all empty
 XL_row_has_data=0
 else:
 # Look in next row
 irow=irow+1

print first row with empty cells is row +str(irow)

HTH

Alun Griffiths


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help needed for etherealXML parsing

2006-09-12 Thread Kent Johnson
Akanksha Govil wrote:
 Hi,
 
 I have downloaded an add on python script etherealXML.py for parsing 
 the ethereal captured packets.
 
 This script runs fine on python 2.3 but on python 2.4 it gives error.\

What is the error?

 
 Has any one tried porting this script?

This might give a clue:
http://www.python.org/doc/2.4.3/whatsnew/node15.html
 
 Also I found the SAX parser earlier used to return a call back function 
 which is no longer the case, so how do we modify the script according to 
 the new SAX parser?

Which parser? Which callback was returned? From what call?

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] HTML page status

2006-09-12 Thread Johan Geldenhuys

Hi all,

I looked a little bit at the urllib and it all looks fairly easy.
What I didn't see, if it is there, was how to know or identify if a page 
was successfully downloaded. I want to do tests to see if a connection 
to a webpage was successful by parsing whatever came back.

Will this be the easiest way of doing this or is there a different way 
of testing the availability of webpages? Let's say I can connect to a 
webpage, but it failed to upload 100%, how will I know that the 
connection was not 100% successful? I'm not very familiar with url 
parsing and HTML to know if there are other indicators to notify me if a 
page or any web access is possible.

Once this was done, can I add features to say how fast the page was 
downloaded?

Thanks

Johan


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTML page status

2006-09-12 Thread Luke Paireepinart
Johan Geldenhuys wrote:
 Hi all,

 I looked a little bit at the urllib and it all looks fairly easy.
 What I didn't see, if it is there, was how to know or identify if a page 
 was successfully downloaded. I want to do tests to see if a connection 
 to a webpage was successful by parsing whatever came back.

 Will this be the easiest way of doing this or is there a different way 
 of testing the availability of webpages? Let's say I can connect to a 
 webpage, but it failed to upload 100%, how will I know that the 
 connection was not 100% successful? I'm not very familiar with url 
 parsing and HTML to know if there are other indicators to notify me if a 
 page or any web access is possible.

 Once this was done, can I add features to say how fast the page was 
 downloaded?

   
if you use httplib you can capture the returned headers and look at the 
error code.
404 if the page wasn't found,etc etc.
I'm really bad at using it so I won't attempt to give you an example.
GIYF I guess :)
-Luke
 Thanks

 Johan


 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] foreach loops

2006-09-12 Thread Alan Gauld
 Does python have foreach loops?  I don't see any
 mention of them in the docs.  Am I going to have to
 use Perl (gasp!) if I want my beloved foreach loop?

Its called a for loop in Python...

Or is there some extra magic in the Perl version that I'm missing?

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] foreach loops

2006-09-12 Thread Alan Gauld
 I was thinking more along the lines of this:
 
 A C++ for loop:

This is exactly NOT a foreach loop, its a vanilla for loop.

 
 #include iostream
 
 using std::cout;
 
 int main() {
 
 for (int i = 0; i  10; i++) {
 cout  i  \n;
 }

for i in range(10): print i

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTML page status

2006-09-12 Thread Michael P. Reilly
On 9/12/06, Johan Geldenhuys [EMAIL PROTECTED] wrote:
Hi all,I looked a little bit at the urllib and it all looks fairly easy.What I didn't see, if it is there, was how to know or identify if a pagewas successfully downloaded. I want to do tests to see if a connection
to a webpage was successful by parsing whatever came back.Will this be the easiest way of doing this or is there a different wayof testing the availability of webpages? Let's say I can connect to awebpage, but it failed to upload 100%, how will I know that the
connection was not 100% successful? I'm not very familiar with urlparsing and HTML to know if there are other indicators to notify me if apage or any web access is possible.Once this was done, can I add features to say how fast the page was
downloaded?ThanksJohanI've just finished writing a smoke test engine after releasing new webpages. I use httplib.HTTPConnection classes.Here is an example:
import urlparse, httplibclass SiteCheck: reqtype = 'POST' def __init__(self, url): self.url
 = ""> pieces = urlparse.urlparse(url) self.hostname = pieces[1] self.conn = httplib.HTTPConnection(self.hostname) def run(self): self.conn.request(self.reqtype, self.url
) response = self.conn.getresponse() method_name = 'response_%d' % response.status try: method = getattr(self, method_name) except AttributeError: 
self.response_default(response) else: method(response) def response_default(self, response): self.result = '%d %s' % (response.status, response.reason) def response_200(self, response):
 self.result = response.reason # OK def response_302(self, response): self.result = response.msg['Location'] # 302 redirectHopefully this will give you some ideas.
 -Arcege-- There's so many different worlds,So many different suns.And we have just one world,But we live in different ones.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTML page status

2006-09-12 Thread Johan Geldenhuys




I don't know if this will work in all cases. I tried it with a internet
connection and could get a 'OK' response. Then I tried it withoput a
internet connection and received a Traceback error, which is not what I
want.

It gave me some idea what is possible.

Johan

Michael P. Reilly wrote:
On 9/12/06, Johan Geldenhuys
[EMAIL PROTECTED]
wrote:
  
  
Hi all,

I looked a little bit at the urllib and it all looks fairly easy.
What I didn't see, if it is there, was how to know or identify if a page
was successfully downloaded. I want to do tests to see if a connection

to a webpage was successful by parsing whatever came back.

Will this be the easiest way of doing this or is there a different way
of testing the availability of webpages? Let's say I can connect to a
webpage, but it failed to upload 100%, how will I know that the

connection was not 100% successful? I'm not very familiar with url
parsing and HTML to know if there are other indicators to notify me if a
page or any web access is possible.

Once this was done, can I add features to say how fast the page was

downloaded?

Thanks

Johan
  
  
  
I've just finished writing a smoke test engine after releasing new
webpages. I use httplib.HTTPConnection classes.
  
Here is an example:
  
  import urlparse,
httplib
  class SiteCheck:
 reqtype = 'POST'
 def __init__(self, url):
 self.url = "">
 pieces = urlparse.urlparse(url)
 self.hostname = pieces[1]
 self.conn = httplib.HTTPConnection(self.hostname)
 def run(self):
 self.conn.request(self.reqtype, self.url
)
 response = self.conn.getresponse()
 method_name = 'response_%d' % response.status
 try:
 method = getattr(self, method_name)
 except AttributeError:
 self.response_default(response)
 else:
 method(response)
 def response_default(self, response):
 self.result = '%d %s' % (response.status, response.reason)
 def response_200(self, response):
  
 self.result = response.reason # "OK"
 def response_302(self, response):
 self.result = response.msg['Location'] # 302 redirect
  
  Hopefully this will give you some ideas.
 -Arcege
-- 
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] man pages parsing (still)

2006-09-12 Thread Tiago Saboga
Em Segunda 11 Setembro 2006 19:45, Kent Johnson escreveu:
 Tiago Saboga wrote:
  Ok, the guilty line (279) has a copy; that was probably defined in the
  dtd, but as it doesn't know what is the right dtd... But wait... How does
  python read the dtd? It fetches it from the net? I tried it
  (disconnected) and the answer is yes, it fetches it from the net. So
  that's the problem!
 
  But how do I avoid it? I'll search. But if you can spare me some time,
  you'll make me a little happier.
 
  [1] - The line is as follows:
  !DOCTYPE refentry PUBLIC -//OASIS//DTD DocBook XML V4.1.2//EN

  http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd;

 I'm just guessing, but I think if you find the right combination of
 handlers and feature settings you can at least make it just pass through
 the external entities without looking up the DTDs.

I got it! I just set the feature_external_ges to false and it doesn't fetch 
the dtd any more. Thanks!!! ;-)


 Take a look at these pages for some hints:
 http://www.cafeconleche.org/books/xmljava/chapters/ch07s02.html#d0e10350
 http://www.cafeconleche.org/books/xmljava/chapters/ch06s11.html

It looks very interesting, and it was exactly what I needed. But I couldn't 
grab it at first, I need some more time to understand it all.

Thanks again!!!

Tiago.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Traversing Excel Columns

2006-09-12 Thread Chris Hengge
I got it working!

try:#Attempt to record the fields from the excel file. row = 10 #Set the row in excel. #While the cell isn't 'None', keep looping. #Excel (row,col) for navigation while xlSht.Cells(row,1).Value != None:
 print  file, '%s', % xlSht.Cells(row,1).Value, row = 1 + row

This does exactly what I want. Now perhaps, is there a prettier way to write it?
I can get file.write('%s',) % xlSht.Cells(row,1).Value to work..

I'm just taking all the values from the cells and dumping them into a text file with single quotes and a comma (sorta like comma seperated values) that need to be on long line(like I've got it above in my working code).


Also, why doesn't 'xlSht.Cells(row + 1, 1).Value' work for this loop, but it did for the previous loop I posted to tutor?
On 9/12/06, John Fouhy [EMAIL PROTECTED] wrote:
On 12/09/06, Chris Hengge [EMAIL PROTECTED] wrote: I'm not sure what internal blanks means.. but I'll take a stab and say
 no, there are going to be NO blanks once I start reading the column unless there are no more values to read... null or  would be fine for a stopping point.Well, basically, I'm thinking you could say something like:
for i in itertools.count(1): if xlSht.Cells(1, i).Value in (None, ''): maxCol = i breakThis should start at (1,1) (the top-left cell), and move right, untilit hits a blank cell, at which point it aborts.
You could do the same thing, but changing row instead of column, tofind the maximum column.So, by internal blanks, I meant blank cells with non-blank cells tothe right, or below.
Also, if the first row is not necessarily the longest, you would needa bit more trickery. also, what is makepy.py? I'm still working through a couple books on python, so I haven't got all the tricks yet :]
makepy.py is a utility that comes with pythonwin. Basically it buildspython libraries corresponding to COM objects.If you do this(one-time only), your code should run faster.Also, you will getmeaningful help(), and you can look at the code it produces to get a
quick list of all the available methods, and what arguments theyexpect.You can run it from the command line, or you can run it from the menuof the pythonwin IDE.--John.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor