Disassembling strings and turning them into function parameters
Fredrik Lundh
fredrik at pythonware.com
Sun Jan 30 13:15:15 EST 2005
<mercuryprey at gmail.com> wrote:
> I'm pretty new to Python, to programming overall...so how would I make
> something where the user inputs multiple words in a string - like
> "connect 123.123.123.123 21 user password" or similar, and then I can
> split this string up to pass these arguments to a function like
> ftp_connect(ip, port, user, pw) etc...? I have no idea how to "break"
> the string up so I can get these out of it..
you can use the split() method to split on whitespace:
>>> s = "connect 123.123.123.123 21 user password"
>>> s.split()
['connect', '123.123.123.123', '21', 'user', 'password']
btw, the cmd module might be useful for your project:
http://effbot.org/librarybook/cmd.htm
http://docs.python.org/lib/module-cmd.html
</F>
More information about the Python-list
mailing list