Re: [Tutor] RDT server for excel

2006-02-28 Thread János Juhász
Hi Danny, Hi Bob,

thanks your help.
RTD is really very win32 specific. The long name is RealTimeData service,
that is implemented as COM service.
It retrieves real-time data from a program that supports COM automation.

With this service an excel cell can hold the answer of this service called
by parameters given in the cell.
I just tried to implement it on our network, but it seems to be too handy.
Better to not use.
I wouldn't like to take care to register com services on every PCs. It
shouldn't not simplify but complicate this new possibility.
So I just solved the problem in excel with a user defined function. It
needn't any extra installation on the PCs.

I will use http://mail.python.org/mailman/listinfo/python-win32 next time.


I can write a python webserver easier, that can answer on the intranet for
this request
  http:\\www.dataserver.mycompany.com\balance?stockcode=soap&date=today
So the webquery seems to be more simple :)


Yours sincerely,
__
János Juhász





   
 Danny Yoo  
   
 <[EMAIL PROTECTED] 
   
 y.edu> To  
   
János Juhász <[EMAIL 
PROTECTED]>  
cc  
   
 2006.02.27 18:40   tutor@python.org
   
Subject 
   
Re: [Tutor] RDT server for 
excel   

   

   






On Mon, 27 Feb 2006, [ISO-8859-1] J?nos Juh?sz wrote:

> I would like to make a small RDT Server as COM Server in python that can
> be called from excel as =RDT("StockBalance.MyServer",,"17") I'v
> tried to use google, but with not too much success. I just would like a
> simple sample.

Hi Janos,

Unfortunately, I'm not sure if we can be of much help, since this is very
Windows specific.  You might want to ask about this on the win32 list; the
folks there have more expertise on writing COM servers, and I'm sure they
can give a few pointers.  Here's a link to their mailing list:

http://mail.python.org/mailman/listinfo/python-win32

Best of wishes to you!


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


Re: [Tutor] Telnet to cisco device

2006-02-28 Thread David Heiser
Title: Message



 
The 
following works with the Cisco switch that I have available. Cisco 4006 
with CatOS 6.2. It may not work with your model/OS or your switch may be 
configured differently. For instance, the default prompt terminates with 
"(enable)" so I used "tn.read_until(')')" instead of "tn.read_until(HOST + 
'#')".
 
--
import 
getpass ##import sys import telnetlib 
 
##HOST 
= 'switch_name'  # this is the hostname for device, to be changed to read 
from file when figure that out HOST = '10.216.1.223'  # this is the 
hostname for device, to be changed to read from file when figure that out 

 
##user 
= raw_input('Username: ')""" My switch does not require a username 
"""
 
##password = getpass.getpass()printloginpassword = 
getpass.getpass('Login password: ') """ The login password and enable 
password may not be the same """
 
tn = 
telnetlib.Telnet(HOST) #make less typing for me 
 
##tn.read_until('Username: ') #expected prompt after telnetting to the 
router ##tn.write(user + '\r\n')  #hopefully write username and pass 
character return ##raw_input('ENTER to continue') # just to see if it makes 
this far # this is where the program appears to hang 
 
##tn.read_until('Password: ') #expected prompt after putting in the 
username tn.read_until('password:')""" tn.read_until(':') may also work 
"""
 
##tn.write(password + '\r\n') tn.write(loginpassword + '\n') 

 
##tn.read_until(HOST + ">") #expected prompt is "hostname>" 
tn.read_until(">")""" The prompt may not contain the HOST name 
"""
 
tn.write('enable \n') # go to exec mode 
 
##tn.read_until('Password: ') #prompt to go to exec mode 
tn.read_until(':')
 
printenablepassword = getpass.getpass('Enable password: ') 
##tn.write(password + '\n') tn.write(enablepassword + '\n') 

 
##tn.read_until(HOST + '#')  #this should be the prompt after enable 
"hostname#" tn.read_until(')')  #this should be the prompt after enable 
"hostname#" 
 
##tn.write('sh int status' '\r\n') #run this command, read this from file 
when i figure out how tn.write('sh int\n')""" This command works on a 
Cisco 4006 with CatOS 6.2 """
 
##tn.read_until(HOST + '#') #prompt once above command has finished 
running, useful when reading multiple commandsprintprint 
tn.read_until(')')
 
##tn.write('exit' '\R\N') #disconnect from the session tn.write('exit 
\n')
 
##print tn.read_all() #prints out something, maybe needs to be prior to 
"exit" command 
 
##tn.close()""" I don't think you need this """
 
 

  
  -Original Message-From: 
  [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of 
  STREET Gideon (SPARQ)Sent: Monday, February 27, 2006 11:36 
  PMTo: tutor@python.orgSubject: [Tutor] Telnet to cisco 
  device
  Hi all, 
  I'm trying to get a script together to automate 
  adding a couple of commands across a lot of cisco switches.  Thought I'd 
  try to get the script working correctly on one switch first.  I've been 
  reading a few online tutorials and have managed to kludge up the following 
  (which fails where commented).  Anyone able to advise where I may be 
  going wrong?
  I'm sitting on a windows box here at work, 
  otherwise I'd see what I could get expect to do. 
  Thanks Gideon 
   import getpass import sys 
  import telnetlib 
  HOST = 'switch_name'  # this is the hostname 
  for device, to be changed to read from file when figure that out 
  user = raw_input('Username: ') password = getpass.getpass() 
  tn = telnetlib.Telnet(HOST) #make less typing for 
  me 
  tn.read_until('Username: ') #expected prompt after 
  telnetting to the router tn.write(user + 
  '\r\n')  #hopefully write username and pass character return 
  raw_input('ENTER to continue') # just to see if it 
  makes this far 
  # this is where the program appears to hang 
  
  tn.read_until('Password: ') #expected prompt after 
  putting in the username tn.write(password + 
  '\r\n') 
  tn.read_until(HOST + ">") #expected prompt is 
  "hostname>" tn.write('enable \n') # go 
  to exec mode 
  tn.read_until('Password: ') #prompt to go to exec 
  mode tn.write(password + '\n') 
  
  tn.read_until(HOST + '#')  #this should be the 
  prompt after enable "hostname#" tn.write('sh int status' '\r\n') #run this command, read this from file 
  when i figure out how 
  tn.read_until(HOST + '#') #prompt once above 
  command has finished running, useful when reading multiple commands 

  tn.write('exit' '\R\N') #disconnect from the 
  session 
  print tn.read_all() #prints out something, maybe 
  needs to be prior to "exit" command 
  tn.close()   
  


  This e-mail (including any 
attachments) may contain confidential orprivileged information and 
is intended for the sole use of the person(s) towhom it is 
addressed. If you are not the intended recipient, or the 
personresponsible for delivering this message to the intended 
recipient, pleasenotify the sender of the message

Re: [Tutor] Telnet to cisco device

2006-02-28 Thread Python
On Tue, 2006-02-28 at 16:36 +1000, STREET Gideon (SPARQ) wrote:
> tn.read_until('Username: ') #expected prompt after telnetting to the
> router 
> tn.write(user + '\r\n')  #hopefully write username and pass character
> return
> 
Sending both \r and \n may be confusing things.

I'd recommend using tcpwatch.py
http://hathawaymix.org/Software/TCPWatch
to monitor a telnet session that works.  That way you will have a
collection of exact prompts available to build your script.

-- 
Lloyd Kvam
Venix Corp

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


[Tutor] switch-case in python

2006-02-28 Thread 铁石

  I know this may seem to be stupid.
but as I found that there's no 
switch-case control flow in python,
an I just can't remember( or know) any 
method to make such a control flow.


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


Re: [Tutor] switch-case in python

2006-02-28 Thread Bob Gailer
铁石 wrote:
>   I know this may seem to be stupid.
> but as I found that there's no 
> switch-case control flow in python,
> an I just can't remember( or know) any 
> method to make such a control flow.
>   
if cond1:
stmts
elif cond2:
stmts
...
else:
stmts

No need for break.
>
>   
> 
>
> ___
> 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] switch-case in python

2006-02-28 Thread Hugo González Monteverde
Yep, it is an often mentioned thing.

Using:

---
if condition:
action
elif condition2:
action2
else:
defaultaction
---

is pythonic.

Also using a dictionary and indexing using the case is very fast and
useful when there are many options. This approach is described here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410692

Hope that helps,

Hugo

铁石 wrote:
>   I know this may seem to be stupid.
> but as I found that there's no 
> switch-case control flow in python,
> an I just can't remember( or know) any 
> method to make such a control flow.
> 
> 
> 
> 
> 
> 
> ___
> 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] switch-case in python

2006-02-28 Thread Ewald Ertl
Hi!

Have a look to the Python-Cookbook at ActiveState.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410692

This is a recipe for simulating a switch.

HTH Ewald

铁石 wrote:
>   I know this may seem to be stupid.
> but as I found that there's no 
> switch-case control flow in python,
> an I just can't remember( or know) any 
> method to make such a control flow.
> 
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] Unexpected Behavior in unittest

2006-02-28 Thread Carroll, Barry
Greetings:

This is a fairly long-winded question.  I beg your indulgence.  

I am writing unit tests for our bar code scanner test software, and I have 
encountered some results that I cannot explain nor get around.  Here is the 
scenario.

Our program implements a generator class for creating 'label' objects.  Leaving 
out a lot of detail, the generator converts a text string into a list of floats 
(txtlst), along with other attributes.  My unit tests verify that the 'label' 
has been constructed correctly.  

One of the generator class's attributes is the character separator (cs), a 
float which is inserted between the individual character representations in the 
label's txtlst.  This value is set when the generator object is created 
(default is 1.0), and can be changed by a simple assignment at any time before 
the label object is generated.  One of my tests verifies that, when cs is 
changed, the new value appears in the txtlst attribute for labels created after 
the change.  

To test this, I do the following:

 1. create a generator object
 2. check the cs value
 3. create a label
 4. check the cs values in txtlst
 5. change the generator's cs value
 6. check the new cs value
 7. create a new label
 8. check the cs values in the new txtlst


The first code excerpt implements these steps outside the unittest framework.   
 
###
#!/usr/bin/python2.3
from lblgen import *

lg = lblgen(t = 'Any string here')
print '\n\nlg.cs: %.1f' % lg.cs
assert(1.0 == lg.cs)
lbl = lg.generate()
for x in lbl.txtlst[lbl.chlen::lbl.chlen]:
assert(1.0 == x)
lg.cs = 2.5
print '\n\nlg.cs: %.1f' % lg.cs
assert(2.5 == lg.cs)
lbl = lg.generate()
for x in lbl.txtlst[lbl.chlen::lbl.chlen]:
assert(2.5 == x)
###

As the output shows, the assignment to lg.cs succeeded and the proper value was 
found in txtlst (no exceptions thrown by the assert statements).  
>>


lg.cs: 1.0


lg.cs: 2.5
>>

The next excerpt does the same steps inside the unittest framework.
###
#!/usr/bin/python2.3
from lblgen import *
import unittest

class cs_tryout(unittest.TestCase):

def test_cs(self):
lg = lblgen(t = 'Any string here')
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' % 
   (1.0, lg.cs))
self.assertEqual(1.0, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(1.0, got, msg % (ndx, 1.0, got))

lg.cs = 2.5
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' % 
   (2.5, lg.cs))
self.assertEqual(2.5, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(2.5, got, msg % (ndx, 2.5, got))


if __name__=='__main__':
unittest.main( )
 ###

In this case, the assignment to lg.cs failed.  
>>
F
==
FAIL: test_cs (__main__.cs_tryout)
--
Traceback (most recent call last):
  File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in test_cs
self.assertEqual(expect, lg.cs, msg)
  File "C:\PROGRA~1\Python23\lib\unittest.py", line 302, in failUnlessEqual
raise self.failureException, \
AssertionError: Generator cs is incorrect.
Expected 2.5; got 1.0

--
Ran 1 test in 0.000s

FAILED (failures=1)
>>

Can anyone tell me why it should fail here and succeed when unittest is not 
involved?  I need to be able to verify that this and other attributes can be 
changed, and I don't want to abandon the unittest framework if I can avoid it.  

Thanks in advance for your help.  
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.
-Quarry worker's creed


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


Re: [Tutor] Unexpected Behavior in unittest

2006-02-28 Thread Danny Yoo

> In this case, the assignment to lg.cs failed.
> >>
> F
> ==
> FAIL: test_cs (__main__.cs_tryout)
> --
> Traceback (most recent call last):
>   File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in 
> test_cs
> self.assertEqual(expect, lg.cs, msg)
>   File "C:\PROGRA~1\Python23\lib\unittest.py", line 302, in failUnlessEqual
> raise self.failureException, \
> AssertionError: Generator cs is incorrect.
> Expected 2.5; got 1.0
>

Hi Barry,

I think the bug here is less glamorous than you might expect.  I'd
recommend rerunning the unit test again, and watch carefully about what
exactly you're running.

It's strongly possible that you may be running the wrong test program: I
see a reference to a 'test3.py' there in the error message that dies on
the line:

self.assertEqual(expect, lg.cs, msg)

But, hunting through the class that you've shown us, I see no such line.
*grin*

The simplest explanation is that you're not running the test program that
you think you're running.  Double check that you mean to run 'test3.py',
as opposed to some other 'test*' program in your working directory.


Good luck!



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


Re: [Tutor] Unexpected Behavior in unittest

2006-02-28 Thread Carroll, Barry
Danny:

I wish it were that simple.  'test3.py' is the name of the file
containing the test case class.  I left the invocation out of my output
excerpt.  It should look like this:


J:\My Documents\Projects\Mongoose\symgen\test3.py
F
==
FAIL: test_cs (__main__.cs_tryout)
--
Traceback (most recent call last):
  File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in
test_cs

<<>>

FAILED (failures=1)


BTW the other code excerpt was from a file named 'test1.py' in the same
directory. 

Regards,
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed

> -Original Message-
> From: Danny Yoo [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 28, 2006 2:08 PM
> To: Carroll, Barry
> Cc: tutor@python.org
> Subject: Re: [Tutor] Unexpected Behavior in unittest
> 
> 
> > In this case, the assignment to lg.cs failed.
> > >>
> > F
> >
==
> > FAIL: test_cs (__main__.cs_tryout)
> >
--
> > Traceback (most recent call last):
> >   File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25,
in
> test_cs
> > self.assertEqual(expect, lg.cs, msg)
> >   File "C:\PROGRA~1\Python23\lib\unittest.py", line 302, in
> failUnlessEqual
> > raise self.failureException, \
> > AssertionError: Generator cs is incorrect.
> > Expected 2.5; got 1.0
> >
> 
> Hi Barry,
> 
> I think the bug here is less glamorous than you might expect.  I'd
> recommend rerunning the unit test again, and watch carefully about
what
> exactly you're running.
> 
> It's strongly possible that you may be running the wrong test program:
I
> see a reference to a 'test3.py' there in the error message that dies
on
> the line:
> 
> self.assertEqual(expect, lg.cs, msg)
> 
> But, hunting through the class that you've shown us, I see no such
line.
> *grin*
> 
> The simplest explanation is that you're not running the test program
that
> you think you're running.  Double check that you mean to run
'test3.py',
> as opposed to some other 'test*' program in your working directory.
> 
> 
> Good luck!
> 
> 
> 


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


Re: [Tutor] Unexpected Behavior in unittest

2006-02-28 Thread Danny Yoo


> I wish it were that simple.  'test3.py' is the name of the file
> containing the test case class.  I left the invocation out of my output
> excerpt.  It should look like this:

Hi Barry,


Ok.

But still go back and make sure you're running the right file.  The error
message says that:

> Traceback (most recent call last):
>   File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in
> test_cs

So Python's running a program that has at least 25 lines in it.


But the test3.py file you've shown us at the bottom of:

 http://mail.python.org/pipermail/tutor/2006-February/045423.html

just simply doesn't have that many lines.  Let's look again at the program
you're showing us as 'test3.py':

###
#!/usr/bin/python2.3
from lblgen import *
import unittest

class cs_tryout(unittest.TestCase):

def test_cs(self):
lg = lblgen(t = 'Any string here')
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' %
   (1.0, lg.cs))
self.assertEqual(1.0, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(1.0, got, msg % (ndx, 1.0, got))

lg.cs = 2.5
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' %
   (2.5, lg.cs))
self.assertEqual(2.5, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(2.5, got, msg % (ndx, 2.5, got))


if __name__=='__main__':
unittest.main( )
###


What you're showing us above --- what you think is test3.py --- and what
the error message is saying here:

#
Traceback (most recent call last):
  File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in
test_cs
self.assertEqual(expect, lg.cs, msg)
  File "C:\PROGRA~1\Python23\lib\unittest.py", line 302, in
failUnlessEqual
raise self.failureException, \
#

presents two inconsistent views of what should be the same exact program.


We can look at this more closely: the error message has a reference to an
'expect' variable name, but this doesn't exist in the program you're
showing us.  Python isn't magical, so I have to assume that some program,
different than the one you've shown us, is being executed.


Does this make sense?

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


Re: [Tutor] Telnet to cisco device

2006-02-28 Thread STREET Gideon (SPARQ)

Thanks all for the replies.

I got tcpwatch up and running and where the program was hanging is
actually a page prompt, so now I just need to get the script to pass a
space whenever that prompt comes up I'm surprised it worked and got
to that point (that's a testament to the online tutorials).

Fun and games :)

-Original Message-
From: Python [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 28 February 2006 11:05 PM
To: STREET Gideon (SPARQ)
Cc: Tutor Python
Subject: Re: [Tutor] Telnet to cisco device

On Tue, 2006-02-28 at 16:36 +1000, STREET Gideon (SPARQ) wrote:
> tn.read_until('Username: ') #expected prompt after telnetting to the
> router tn.write(user + '\r\n')  #hopefully write username and pass
> character return
>
Sending both \r and \n may be confusing things.

I'd recommend using tcpwatch.py
http://hathawaymix.org/Software/TCPWatch
to monitor a telnet session that works.  That way you will have a
collection of exact prompts available to build your script.

--
Lloyd Kvam
Venix Corp




This e-mail (including any attachments) may contain confidential or
privileged information and is intended for the sole use of the person(s) to
whom it is addressed. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, please
notify the sender of the message or send an e-mail to
mailto:[EMAIL PROTECTED] immediately, and delete all copies. Any
unauthorised review, use, alteration, disclosure or distribution of this
e-mail by an unintended recipient is prohibited. Ergon Energy accepts no
responsibility for the content of any e-mail sent by an employee which is of
a personal nature.

Ergon Energy Corporation Limited  ABN 50 087 646 062
Ergon Energy Pty Ltd  ABN 66 078 875 902
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Problem wxPython

2006-02-28 Thread Prabhakar K
Hai to all,
 
    I installed ActivePython-2.4.1-247-win32-ix86 and wxPython2.6-win32-ansi-2.6.2.1-py2 in my system. When i Run a wxPython example.. geeting an Errors
 
Traceback (most recent call last):  File "E:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript    exec codeObject in __main__.__dict__  File "F:\python\wx.py", line 1, in ? 
    from wxPython.wx import *  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\__init__.py", line 10, in ?    import _wx  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_wx.py
 ", line 3, in ?    from _core import *  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_core.py", line 15, in ?    import wx._core  File "F:\python\wx.py", line 1, in ? 
    from wxPython.wx import *ImportError: No module named wx
 
 
Program Code:
 

from wxPython.wx import *
class MyApp(wxApp):    def OnInit(self):    frame = wxFrame(NULL, -1, "Hello from wxPython")    frame.Show(true)    self.SetTopWindow(frame)    return true
app = MyApp(0)app.MainLoop()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor