From: Updike, C. <Cla...@jh...> - 2004-04-07 19:10:50
|
I can't tell why your csv module gives errors without seeing it, but here is how you would do this just using straight jython: >>> f = open("c:/temp/users.csv") >>> try: ... for line in f.readlines(): ... if line.strip().startswith("#"): continue ... else: ... items = line.split(",") ... items = [item.strip() for item in items] ... if len(items) != 4: print "Bad line: %s" % line ... else: (user, password, group, desc) = items ... print "user=%s, password=%s, group=%s, desc=%s" % (user, password, group, desc) ... finally: ... f and f.close() ... user=tom, password=apple, group=admin, desc=asfdasdf user=dick, password=quince, group=user, desc=aslkdjfd user=harry, password=banana, group=guest, desc=asdfasdf >>> where users.csv is: # user password group desc tom, apple, admin, asfdasdf dick, quince, user, aslkdjfd harry, banana, guest, asdfasdf -Clark -----Original Message----- From: Tim [mailto:hob...@ya...] Sent: Wednesday, April 07, 2004 11:42 AM To: jyt...@li... Subject: [Jython-users] Creating new WebLogic users from a csv in Jython I have been tasked with writing a script in jython to create X number of new users (from a csv file) for weblogic 8.1. I have spent the better part of 2 days trying to find documentation on reading csv's in jython. I have found the docs on using it with python and i can get it to read them but i can't do anything with the rows once i return them. Can anyone point me in the right directions. Here is what i have so far (using python)... import csv user = csv.parser() <-- gives me an error reader = csv.reader(file("c:\users.cvs")) for row in reader: user.parse(row) <-- also give me an error -- this code hasn't been tested since i can't get past the errors above -- o = ObjectName("Security:/typeless/myrealmDefaultAuthenticator") p = proxy(o) p.createUser(user, password, descr) p.userExists() p.addMemberToGroup(group, user) p.isMemeber(group, user, true) thanks for any input tim ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |