Disassembling strings and turning them into function parameters
Hi, 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.. thanks for answers, munin -- http://mail.python.org/mailman/listinfo/python-list
Re: Disassembling strings and turning them into function parameters
Hey, that's exactly what I need! Thanks for your help, the others too of course :) Didn't expect to get answers so quickly.. -- http://mail.python.org/mailman/listinfo/python-list
Problem with loading textfiles into dictionaries.
Hello, I want to do the following: def do_load(self, arg): sitefile = file('sitelist', 'r+', 1) while True: siteline = sitefile.readline() site_rawlist = siteline.split() sitelist[site_rawlist[0]] = site_rawlist[1:] if len(siteline) == 0: break I want to load a textfile into a dictionaries and use the first word on a line as the key for the list, then take the remaining words of the line and make them values of the key. This doesn't work: File "ftp.py", line 57, in do_load sitelist[site_rawlist[0]] = site_rawlist[1:] IndexError: list index out of range However, it works flawlessy in another function, where I have: def do_add(self, arg): sitefile = file('sitelist', 'r+', 1) act_addlist = arg.split() sitelist[act_addlist[0]] = act_addlist[1:] sitefile.seek(0,2) sitefile.write(arg + "\n") print "Written to database." Anyone knows why it doesn't work in the first function? Help very much appreciated. munin -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with loading textfiles into dictionaries.
Yeah I kind of want to 'reinvent' the pickle and I am aware of that. The problem for me is that the output that pickle dumps to a file is too 'cryptic' as I want the ability to edit the corresponding textfile directly and easily, so I'm going for an own way. But yes, Kartic and you were basically right about the line length and checking it first. Didn't really think about it, maybe I was too tired... :) Thanks again! Hope I'm not bothering you all with my extremely newbie questions. munin -- http://mail.python.org/mailman/listinfo/python-list