[Twisted-Python] Passing revieved rata and erroring out bad passowrds

Jean-Paul Calderone exarkun at divmod.com
Tue Oct 28 11:19:55 EDT 2008

On Tue, 28 Oct 2008 10:42:49 -0400 (EDT), Brian Levin <b.levin at hvcc.edu> wrote:
>I apologizes if these are simple questions.  I am a complete newb when it comes to python and twisted.  I am trying to pass a command via ssh to a server.  I am having 2 problems.  I am hoping that someone can help me.  I have been unable to find answers in "the google".
>Problem 1: I am unable to pass the received data to a variable without creating a global.  As a general rule it is my understanding that the use of globals in python should be avoided.  If there is a better method for passing the data variable out of the dataReceived method I would prefer to use it.

I'm not sure what you mean by "pass the received data to a variable".  In
general, I think that it only makes sense to pass objects to functions.
What you do to variables is set them.  From looking at your code, I'm not
sure what you want to accomplish.  Your code sets a global variable and
later, when your program is done and about to exit, prints the value.  If
that's all you want to do, you could just print the value instead of setting
a variable to it.  I suspect you want to do something else, but I don't
know what.  Whatever it is, it will probably involve calling a function or
method of some object, probably passing the data you received (or some
transformation of it) as an argument.

>Problem 2:  A bad password or username causes and infinite loop.  I need to find a way to cause an error or return a false value when the password or username is bad.

I'm not sure about this one.


More information about the Twisted-Python mailing list