From: Desai, R. <Rau...@an...> - 2007-01-18 16:44:11
|
Hi Guys=0D=0A=0D=0AIf I am reading a CSV file which has 2 columns and 10 re= cords, I can I=0D=0Acreate a 2D Array which will hold this data=3F. The 2D= array will be=0D=0Apopulated in a For loop which I have. Also how can acc= ess for example=0D=0Acertain values for a nth record=3F.=0D=0A=0D=0AI have= not been able to hold of much information on my problem. Any=0D=0Aassista= nce will be greatly appreciated.=0D=0A=0D=0ARegards=0D=0A=0D=0ARaul=0D=0A=0D= =0A------------------------------------------------------------------------= ------------------------=0D=0AThis message is for the designated recipient = only and may=0D=0Acontain privileged, proprietary, or otherwise private inf= ormation. =20=0D=0AIf you have received it in error, please notify the send= er=0D=0Aimmediately and delete the original. Any unauthorized use of=0D=0A= this email is prohibited.=0D=0A--------------------------------------------= ----------------------------------------------------=0D=0A[mf2]=0D=0A |
From: Leo U. <leo...@ya...> - 2007-01-18 17:16:35
|
You can probably just use list within a list: list = [[],[]] >>> a = [[],[]] >>> a [[], []] >>> for z in xrange(10): ... a[0].append(z) ... a[1].append(z) ... >>> a [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>> or maybe use jarray. Or you can use one list/array and calculate the index. leouser --- "Desai, Raul" <Rau...@an...> wrote: > Hi Guys > > If I am reading a CSV file which has 2 columns and > 10 records, I can I > create a 2D Array which will hold this data?. The > 2D array will be > populated in a For loop which I have. Also how can > access for example > certain values for a nth record?. > > I have not been able to hold of much information on > my problem. Any > assistance will be greatly appreciated. > > Regards > > Raul > > ------------------------------------------------------------------------------------------------ > This message is for the designated recipient only > and may > contain privileged, proprietary, or otherwise > private information. > If you have received it in error, please notify the > sender > immediately and delete the original. Any > unauthorized use of > this email is prohibited. > ------------------------------------------------------------------------------------------------ > [mf2] > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get > the chance to share your > opinions on IT & business topics through brief > surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > ____________________________________________________________________________________ It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. http://tools.search.yahoo.com/toolbar/features/mail/ |
From: Desai, R. <Rau...@an...> - 2007-01-18 18:35:06
|
Thanks for that.....however I still don't think what I is correct and I=0D=0A= can not figure it out.=0D=0A=0D=0AMy CSV looks likes this:=0D=0A=0D=0AAAAAA= ,BBBBB=0D=0AZZZZZ,XXXXX=0D=0A=0D=0AAnd my code as follow:=0D=0A=0D=0A user= File =3D open('test.csv', 'r')=0D=0A userFileLineCounter =3D 0=0D=0A user= FileLine =3D 'null'=20=0D=0A xdi =3D ''=0D=0A name =3D ''=0D=0A a =3D [[= ],[]]=0D=0A print 'grinder threads is %d' % (numGrinderThreads)=0D=0A=0D=0A= while (userFileLineCounter !=3D numGrinderThreads):=0D=0A userFileLines= =3D userFile.readlines()=0D=0A userFileLineCounter +=3D 1=0D=0A if (us= erFileLineCounter =3D=3D (grinder.threadID + 1)):=0D=0A for i in range(0= , len(userFileLines)):=0D=0A print 'Thread Data Line %d: %s' % (i, user= FileLines[i])=0D=0A # split the string into each individual data item=0D= =0A lineData =3D userFileLines[i].split(',')=0D=0A for j in range(0= , len(lineData)):=0D=0A print 'PK %d value: %s' % (j, lineData[j])=0D=0A= a[0].append(lineData[j])=0D=0A a[1].append(lineData[j])=0D=0A = break=0D=0A print a=0D=0A userFile.close()=0D=0A print 'file closed'=0D=0A=0D= =0AThe output is=0D=0A=0D=0Agrinder threads is 2=0D=0A[[], []]=0D=0Afile cl= osed=0D=0AThread Data Line 0: AAAAA,BBBBB=0D=0A=0D=0AXDI1 0 value: AAAAA=0D= =0AXDI1 1 value: BBBBB=0D=0A=0D=0AThread Data Line 1: ZZZZZ,XXXXX=0D=0AXDI1= 0 value: ZZZZZ=0D=0AXDI1 1 value: XXXXX=0D=0A[['AAAAA', 'BBBBB\n', 'ZZZZZ'= , 'XXXXX'], ['AAAAA', 'BBBBB\n', 'ZZZZZ',=0D=0A'XXXXX']] file closed=0D=0A=0D= =0A=0D=0AI would expect the List to look like:=0D=0A =20=0D=0A[[= 'AAAAA', 'BBBBB]['ZZZZZ', 'XXXXX']]=0D=0A=0D=0AAny suggestions=3F.=0D=0A=0D= =0ARegards=0D=0A=0D=0ARaul=20=0D=0A=0D=0A=0D=0A=0D=0A-----Original Message-= ----=0D=0AFrom: jyt...@li...=0D=0A[mailto:jyt= hon...@li...] On Behalf Of Leo=0D=0AUser=0D=0ASe= nt: 18 January 2007 17:16=0D=0ATo: jython users=0D=0ASubject: Re: [Jython-u= sers] 2D Arrays....=0D=0A=0D=0AYou can probably just use list within a list= :=0D=0Alist =3D [[],[]]=0D=0A>>> a =3D [[],[]]=0D=0A>>> a=0D=0A[[], []]=0D=0A= >>> for z in xrange(10):=0D=0A... a[0].append(z)=0D=0A... a[1].appe= nd(z)=0D=0A...=0D=0A>>> a=0D=0A[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3= , 4, 5, 6, 7, 8, 9]]=0D=0A>>>=0D=0A=0D=0Aor maybe use jarray.=0D=0A=0D=0AOr= you can use one list/array and calculate the index.=0D=0A=0D=0Aleouser=0D=0A=0D= =0A=0D=0A--- "Desai, Raul" <Rau...@an...> wrote:=0D=0A=0D=0A> Hi G= uys=0D=0A>=20=0D=0A> If I am reading a CSV file which has 2 columns and 10 = records, I can I=0D=0A=0D=0A> create a 2D Array which will hold this data=3F= =2E The 2D array will be=20=0D=0A> populated in a For loop which I have. = Also how can access for example=0D=0A=0D=0A> certain values for a nth reco= rd=3F.=0D=0A>=20=0D=0A> I have not been able to hold of much information on= my problem. Any=20=0D=0A> assistance will be greatly appreciated.=0D=0A> =0D= =0A> Regards=0D=0A>=20=0D=0A> Raul=0D=0A>=20=0D=0A>e.net/lists/listinfo/jyt= hon-users=0D=0A>=20=0D=0A=0D=0A=0D=0A-----Original Message-----=0D=0AFrom: = jyt...@li...=0D=0A[mailto:jython-users-bounce= s...@li...] On Behalf Of Leo=0D=0AUser=0D=0ASent: 18 January 2= 007 17:16=0D=0ATo: jython users=0D=0ASubject: Re: [Jython-users] 2D Arrays.= =2E..=0D=0A=0D=0AYou can probably just use list within a list:=0D=0Alist =3D= [[],[]]=0D=0A>>> a =3D [[],[]]=0D=0A>>> a=0D=0A[[], []]=0D=0A>>> for z in = xrange(10):=0D=0A... a[0].append(z)=0D=0A... a[1].append(z)=0D=0A..= =2E=0D=0A>>> a=0D=0A[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, = 7, 8, 9]]=0D=0A>>>=0D=0A=0D=0Aor maybe use jarray.=0D=0A=0D=0AOr you can us= e one list/array and calculate the index.=0D=0A=0D=0Aleouser=0D=0A=0D=0A=0D= =0A--- "Desai, Raul" <Rau...@an...> wrote:=0D=0A=0D=0A> Hi Guys=0D= =0A>=20=0D=0A> If I am reading a CSV file which has 2 columns and 10 record= s, I can I=0D=0A=0D=0A> create a 2D Array which will hold this data=3F. Th= e 2D array will be=20=0D=0A> populated in a For loop which I have. Also ho= w can access for example=0D=0A=0D=0A> certain values for a nth record=3F.=0D= =0A>=20=0D=0A> I have not been able to hold of much information on my probl= em. Any=20=0D=0A> assistance will be greatly appreciated.=0D=0A>=20=0D=0A>= Regards=0D=0A>=20=0D=0A> Raul=0D=0A>=20=0D=0A>=0D=0A----------------------= --------------------------------------------------=0D=0A-------------------= -----=0D=0A> This message is for the designated recipient only and may cont= ain=20=0D=0A> privileged, proprietary, or otherwise private information.=0D= =0A> If you have received it in error, please notify the sender immediately=0D= =0A=0D=0A> and delete the original. Any unauthorized use of this email is =0D= =0A> prohibited.=0D=0A>=0D=0A----------------------------------------------= --------------------------=0D=0A------------------------=0D=0A> [mf2]=0D=0A= > >=0D=0A------------------------------------------------------------------= ------=0D=0A-=0D=0A> Take Surveys. Earn Cash. Influence the Future of IT Jo= in=20=0D=0A> SourceForge.net's Techsay panel and you'll get the chance to s= hare=20=0D=0A> your opinions on IT & business topics through brief surveys = - and earn=0D=0A=0D=0A> cash=0D=0A>=0D=0Ahttp://www.techsay.com/default.php= =3Fpage=3Djoin.php&p=3Dsourceforge&CID=3DDEVDE=0D=0AV>=0D=0A_______________= ________________________________=0D=0A> Jython-users mailing list=0D=0A> Jy= tho...@li...=0D=0A>=0D=0Ahttps://lists.sourceforge.net/= lists/listinfo/jython-users=0D=0A>=20=0D=0A=0D=0A=0D=0A=0D=0A=20=0D=0A_____= ___________________________________________________________________=0D=0A__= __________=0D=0AIt's here! Your new message! =20=0D=0AGet new email alerts = with the free Yahoo! Toolbar.=0D=0Ahttp://tools.search.yahoo.com/toolbar/fe= atures/mail/=0D=0A=0D=0A---------------------------------------------------= ---------------------=0D=0A-=0D=0ATake Surveys. Earn Cash. Influence the Fu= ture of IT Join=0D=0ASourceForge.net's Techsay panel and you'll get the cha= nce to share your=0D=0Aopinions on IT & business topics through brief surve= ys - and earn cash=0D=0Ahttp://www.techsay.com/default.php=3Fpage=3Djoin.ph= p&p=3Dsourceforge&CID=3DDEVDE=0D=0AV=0D=0A_________________________________= ______________=0D=0AJython-users mailing list=0D=0AJ...@li...urc= eforge.net=0D=0Ahttps://lists.sourceforge.net/lists/listinfo/jython-users=0D= =0A=0D=0A------------------------------------------------------------------= ------------------------------=0D=0AThis message is for the designated reci= pient only and may=0D=0Acontain privileged, proprietary, or otherwise priva= te information. =20=0D=0AIf you have received it in error, please notify th= e sender=0D=0Aimmediately and delete the original. Any unauthorized use of=0D= =0Athis email is prohibited.=0D=0A-----------------------------------------= -------------------------------------------------------=0D=0A[mf2]=0D=0A |
From: Kent J. <ke...@td...> - 2007-01-18 18:53:38
|
Desai, Raul wrote: > Thanks for that.....however I still don't think what I is correct and I > can not figure it out. Your code is way more complicated than it needs to be. I'm not sure what you are doing with numGrinderThreads and userFileLineCounter - why do you open the same file repeatedly? - but to just read the file and split it into a list of lists you could do something as simple as userFile = open('test.csv', 'r') userFileLines = userFile.readlines() userFile.close() a = [ line.strip().split(',') for line in userFileLines ] If you are trying to skip lines at the beginning then use userFileLines = userFile.readlines()[numLinesToSkip:] Kent > > My CSV looks likes this: > > AAAAA,BBBBB > ZZZZZ,XXXXX > > And my code as follow: > > userFile = open('test.csv', 'r') > userFileLineCounter = 0 > userFileLine = 'null' > xdi = '' > name = '' > a = [[],[]] > print 'grinder threads is %d' % (numGrinderThreads) > > while (userFileLineCounter != numGrinderThreads): > userFileLines = userFile.readlines() > userFileLineCounter += 1 > if (userFileLineCounter == (grinder.threadID + 1)): > for i in range(0, len(userFileLines)): > print 'Thread Data Line %d: %s' % (i, userFileLines[i]) > # split the string into each individual data item > lineData = userFileLines[i].split(',') > for j in range(0, len(lineData)): > print 'PK %d value: %s' % (j, lineData[j]) > a[0].append(lineData[j]) > a[1].append(lineData[j]) > break > print a > userFile.close() > print 'file closed' > > The output is > > grinder threads is 2 > [[], []] > file closed > Thread Data Line 0: AAAAA,BBBBB > > XDI1 0 value: AAAAA > XDI1 1 value: BBBBB > > Thread Data Line 1: ZZZZZ,XXXXX > XDI1 0 value: ZZZZZ > XDI1 1 value: XXXXX > [['AAAAA', 'BBBBB\n', 'ZZZZZ', 'XXXXX'], ['AAAAA', 'BBBBB\n', 'ZZZZZ', > 'XXXXX']] file closed > > > I would expect the List to look like: > > [['AAAAA', 'BBBBB]['ZZZZZ', 'XXXXX']] > > Any suggestions?. > > Regards > > Raul > > > > -----Original Message----- > From: jyt...@li... > [mailto:jyt...@li...] On Behalf Of Leo > User > Sent: 18 January 2007 17:16 > To: jython users > Subject: Re: [Jython-users] 2D Arrays.... > > You can probably just use list within a list: > list = [[],[]] >>>> a = [[],[]] >>>> a > [[], []] >>>> for z in xrange(10): > ... a[0].append(z) > ... a[1].append(z) > ... >>>> a > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] > > or maybe use jarray. > > Or you can use one list/array and calculate the index. > > leouser > > > --- "Desai, Raul" <Rau...@an...> wrote: > >> Hi Guys >> >> If I am reading a CSV file which has 2 columns and 10 records, I can I > >> create a 2D Array which will hold this data?. The 2D array will be >> populated in a For loop which I have. Also how can access for example > >> certain values for a nth record?. >> >> I have not been able to hold of much information on my problem. Any >> assistance will be greatly appreciated. >> >> Regards >> >> Raul >> >> e.net/lists/listinfo/jython-users >> > > > -----Original Message----- > From: jyt...@li... > [mailto:jyt...@li...] On Behalf Of Leo > User > Sent: 18 January 2007 17:16 > To: jython users > Subject: Re: [Jython-users] 2D Arrays.... > > You can probably just use list within a list: > list = [[],[]] >>>> a = [[],[]] >>>> a > [[], []] >>>> for z in xrange(10): > ... a[0].append(z) > ... a[1].append(z) > ... >>>> a > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] > > or maybe use jarray. > > Or you can use one list/array and calculate the index. > > leouser > > > --- "Desai, Raul" <Rau...@an...> wrote: > >> Hi Guys >> >> If I am reading a CSV file which has 2 columns and 10 records, I can I > >> create a 2D Array which will hold this data?. The 2D array will be >> populated in a For loop which I have. Also how can access for example > >> certain values for a nth record?. >> >> I have not been able to hold of much information on my problem. Any >> assistance will be greatly appreciated. >> >> Regards >> >> Raul >> >> > ------------------------------------------------------------------------ > ------------------------ >> This message is for the designated recipient only and may contain >> privileged, proprietary, or otherwise private information. >> If you have received it in error, please notify the sender immediately > >> and delete the original. Any unauthorized use of this email is >> prohibited. >> > ------------------------------------------------------------------------ > ------------------------ >> [mf2] > ------------------------------------------------------------------------ > - >> Take Surveys. Earn Cash. Influence the Future of IT Join >> SourceForge.net's Techsay panel and you'll get the chance to share >> your opinions on IT & business topics through brief surveys - and earn > >> cash >> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE > V> > _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > > ________________________________________________________________________ > ____________ > It's here! Your new message! > Get new email alerts with the free Yahoo! Toolbar. > http://tools.search.yahoo.com/toolbar/features/mail/ > > ------------------------------------------------------------------------ > - > Take Surveys. Earn Cash. Influence the Future of IT Join > SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE > V > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > ------------------------------------------------------------------------------------------------ > This message is for the designated recipient only and may > contain privileged, proprietary, or otherwise private information. > If you have received it in error, please notify the sender > immediately and delete the original. Any unauthorized use of > this email is prohibited. > ------------------------------------------------------------------------------------------------ > [mf2] > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Desai, R. <Rau...@an...> - 2007-01-19 09:26:10
|
Hi=0D=0A=0D=0AThe reason why I am using numGrinderThreads is I need to wor= k out how=0D=0Amany threads my performance tool(Grinder) is using. So for = example=0D=0AThread 1 will record 1, thread record 2 and so on.=0D=0A=0D=0A= Given the code you gave me I go the following output. Why are there 2=0D=0A= copies of everything=3F. =20=0D=0A=0D=0Agrinder threads is 2=0D=0A[['AAAAA'= , 'BBBBB'], ['ZZZZZ', 'XXXXX']]=0D=0A[['AAAAA', 'BBBBB'], ['ZZZZZ', 'XXXXX'= ]]=20=0D=0A=0D=0A=0D=0AIdeally I want one copy of each record. Also, how w= ould I access values=0D=0Ain the this list=3F.=0D=0A=0D=0ARegards=0D=0A=0D=0A= Raul Desai=0D=0A=0D=0A=0D=0A=0D=0A-----Original Message-----=0D=0AFrom: Ken= t Johnson [mailto:ke...@td...]=20=0D=0ASent: 18 January 2007 18:53=0D=0A= To: Desai, Raul=0D=0ACc: jython users=0D=0ASubject: Re: [Jython-users] 2D A= rrays....=0D=0A=0D=0ADesai, Raul wrote:=0D=0A> Thanks for that.....however = I still don't think what I is correct and=20=0D=0A> I can not figure it out= =2E=0D=0A=0D=0AYour code is way more complicated than it needs to be. I'm n= ot sure what=0D=0Ayou are doing with numGrinderThreads and userFileLineCoun= ter - why do=0D=0Ayou open the same file repeatedly=3F - but to just read t= he file and split=0D=0Ait into a list of lists you could do something as si= mple as=0D=0A=0D=0AuserFile =3D open('test.csv', 'r')=0D=0AuserFileLines =3D= userFile.readlines()=0D=0AuserFile.close()=0D=0Aa =3D [ line.strip().split= (',') for line in userFileLines ]=0D=0A=0D=0AIf you are trying to skip line= s at the beginning then use userFileLines=0D=0A=3D userFile.readlines()[num= LinesToSkip:]=0D=0A=0D=0AKent=0D=0A>=20=0D=0A> My CSV looks likes this:=0D=0A= >=20=0D=0A> AAAAA,BBBBB=0D=0A> ZZZZZ,XXXXX=0D=0A>=20=0D=0A> And my code as = follow:=0D=0A>=20=0D=0A> userFile =3D open('test.csv', 'r')=0D=0A> user= FileLineCounter =3D 0=0D=0A> userFileLine =3D 'null'=20=0D=0A> xdi =3D = ''=0D=0A> name =3D ''=0D=0A> a =3D [[],[]]=0D=0A> print 'grinder thre= ads is %d' % (numGrinderThreads)=0D=0A>=20=0D=0A> while (userFileLineCoun= ter !=3D numGrinderThreads):=0D=0A> userFileLines =3D userFile.readlines= ()=0D=0A> userFileLineCounter +=3D 1=0D=0A> if (userFileLineCounter =3D= =3D (grinder.threadID + 1)):=0D=0A> for i in range(0, len(userFileLines= )):=0D=0A> print 'Thread Data Line %d: %s' % (i, userFileLines[i])=0D=0A= > # split the string into each individual data item=0D=0A> lineDa= ta =3D userFileLines[i].split(',')=0D=0A> for j in range(0, len(lineDa= ta)):=0D=0A> print 'PK %d value: %s' % (j, lineData[j])=0D=0A> = a[0].append(lineData[j])=0D=0A> a[1].append(lineData[j])=0D=0A> br= eak=0D=0A> print a=0D=0A> userFile.close()=0D=0A> print 'file closed'=0D= =0A>=20=0D=0A> The output is=0D=0A>=20=0D=0A> grinder threads is 2=0D=0A> [= [], []]=0D=0A> file closed=0D=0A> Thread Data Line 0: AAAAA,BBBBB=0D=0A> =0D= =0A> XDI1 0 value: AAAAA=0D=0A> XDI1 1 value: BBBBB=0D=0A>=20=0D=0A> Thread= Data Line 1: ZZZZZ,XXXXX=0D=0A> XDI1 0 value: ZZZZZ=0D=0A> XDI1 1 value: X= XXXX=0D=0A> [['AAAAA', 'BBBBB\n', 'ZZZZZ', 'XXXXX'], ['AAAAA', 'BBBBB\n', '= ZZZZZ',=0D=0A=0D=0A> 'XXXXX']] file closed=0D=0A>=20=0D=0A>=20=0D=0A> I wou= ld expect the List to look like:=0D=0A> =20=0D=0A> [['AAAAA', '= BBBBB]['ZZZZZ', 'XXXXX']]=0D=0A>=20=0D=0A> Any suggestions=3F.=0D=0A>=20=0D= =0A> Regards=0D=0A>=20=0D=0A> Raul=0D=0A>=20=0D=0A>=20=0D=0A>=20=0D=0A> ---= --Original Message-----=0D=0A> From: jyt...@li...urceforge= =2Enet=0D=0A> [mailto:jyt...@li...] On Behalf= Of Leo=20=0D=0A> User=0D=0A> Sent: 18 January 2007 17:16=0D=0A> To: jython= users=0D=0A> Subject: Re: [Jython-users] 2D Arrays....=0D=0A>=20=0D=0A> Yo= u can probably just use list within a list:=0D=0A> list =3D [[],[]]=0D=0A>>= >> a =3D [[],[]]=0D=0A>>>> a=0D=0A> [[], []]=0D=0A>>>> for z in xrange(10):=0D= =0A> ... a[0].append(z)=0D=0A> ... a[1].append(z)=0D=0A> ...=0D=0A>= >>> a=0D=0A> [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9= ]]=0D=0A>=20=0D=0A> or maybe use jarray.=0D=0A>=20=0D=0A> Or you can use on= e list/array and calculate the index.=0D=0A>=20=0D=0A> leouser=0D=0A>=20=0D= =0A>=20=0D=0A> --- "Desai, Raul" <Rau...@an...> wrote:=0D=0A>=20=0D= =0A>> Hi Guys=0D=0A>>=0D=0A>> If I am reading a CSV file which has 2 column= s and 10 records, I can=20=0D=0A>> I=0D=0A>=20=0D=0A>> create a 2D Array wh= ich will hold this data=3F. The 2D array will be=20=0D=0A>> populated in a= For loop which I have. Also how can access for=20=0D=0A>> example=0D=0A> =0D= =0A>> certain values for a nth record=3F.=0D=0A>>=0D=0A>> I have not been = able to hold of much information on my problem. Any=20=0D=0A>> assistance = will be greatly appreciated.=0D=0A>>=0D=0A>> Regards=0D=0A>>=0D=0A>> Raul=0D= =0A>>=0D=0A>> e.net/lists/listinfo/jython-users=0D=0A>>=0D=0A>=20=0D=0A> =0D= =0A> -----Original Message-----=0D=0A> From: jyt...@li...u= rceforge.net=0D=0A> [mailto:jyt...@li...] On = Behalf Of Leo=20=0D=0A> User=0D=0A> Sent: 18 January 2007 17:16=0D=0A> To: = jython users=0D=0A> Subject: Re: [Jython-users] 2D Arrays....=0D=0A>=20=0D=0A= > You can probably just use list within a list:=0D=0A> list =3D [[],[]]=0D=0A= >>>> a =3D [[],[]]=0D=0A>>>> a=0D=0A> [[], []]=0D=0A>>>> for z in xrange(10= ):=0D=0A> ... a[0].append(z)=0D=0A> ... a[1].append(z)=0D=0A> ...=0D= =0A>>>> a=0D=0A> [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, = 8, 9]]=0D=0A>=20=0D=0A> or maybe use jarray.=0D=0A>=20=0D=0A> Or you can us= e one list/array and calculate the index.=0D=0A>=20=0D=0A> leouser=0D=0A> =0D= =0A>=20=0D=0A> --- "Desai, Raul" <Rau...@an...> wrote:=0D=0A>=20=0D= =0A>> Hi Guys=0D=0A>>=0D=0A>> If I am reading a CSV file which has 2 column= s and 10 records, I can=20=0D=0A>> I=0D=0A>=20=0D=0A>> create a 2D Array wh= ich will hold this data=3F. The 2D array will be=20=0D=0A>> populated in a= For loop which I have. Also how can access for=20=0D=0A>> example=0D=0A> =0D= =0A>> certain values for a nth record=3F.=0D=0A>>=0D=0A>> I have not been = able to hold of much information on my problem. Any=20=0D=0A>> assistance = will be greatly appreciated.=0D=0A>>=0D=0A>> Regards=0D=0A>>=0D=0A>> Raul=0D= =0A>>=0D=0A>>=0D=0A> ------------------------------------------------------= ----------------=0D=0A> --=0D=0A> ------------------------=0D=0A>> This mes= sage is for the designated recipient only and may contain=20=0D=0A>> privil= eged, proprietary, or otherwise private information.=0D=0A>> If you have re= ceived it in error, please notify the sender=20=0D=0A>> immediately=0D=0A> =0D= =0A>> and delete the original. Any unauthorized use of this email is=20=0D= =0A>> prohibited.=0D=0A>>=0D=0A> ------------------------------------------= ----------------------------=0D=0A> --=0D=0A> ------------------------=0D=0A= >> [mf2]=0D=0A> -----------------------------------------------------------= -----------=0D=0A> --=0D=0A> -=0D=0A>> Take Surveys. Earn Cash. Influence t= he Future of IT Join=20=0D=0A>> SourceForge.net's Techsay panel and you'll = get the chance to share=20=0D=0A>> your opinions on IT & business topics th= rough brief surveys - and=20=0D=0A>> earn=0D=0A>=20=0D=0A>> cash=0D=0A>>=0D= =0A> http://www.techsay.com/default.php=3Fpage=3Djoin.php&p=3Dsourceforge&C= ID=3DDEV=0D=0A> DE=0D=0A> V>=0D=0A> _______________________________________= ________=0D=0A>> Jython-users mailing list=0D=0A>> Jyt...@li...urc= eforge.net=0D=0A>>=0D=0A> https://lists.sourceforge.net/lists/listinfo/jyth= on-users=0D=0A>=20=0D=0A>=20=0D=0A>=20=0D=0A> =20=0D=0A> __________________= ____________________________________________________=0D=0A> __=0D=0A> _____= _______=0D=0A> It's here! Your new message! =20=0D=0A> Get new email alerts= with the free Yahoo! Toolbar.=0D=0A> http://tools.search.yahoo.com/toolbar= /features/mail/=0D=0A>=20=0D=0A> ------------------------------------------= ----------------------------=0D=0A> --=0D=0A> -=0D=0A> Take Surveys. Earn C= ash. Influence the Future of IT Join=20=0D=0A> SourceForge.net's Techsay pa= nel and you'll get the chance to share=20=0D=0A> your opinions on IT & busi= ness topics through brief surveys - and earn=0D=0A=0D=0A> cash=20=0D=0A> ht= tp://www.techsay.com/default.php=3Fpage=3Djoin.php&p=3Dsourceforge&CID=3DDE= V=0D=0A> DE=0D=0A> V=0D=0A> _______________________________________________=0D= =0A> Jython-users mailing list=0D=0A> Jyt...@li...=0D= =0A> https://lists.sourceforge.net/lists/listinfo/jython-users=0D=0A>=20=0D= =0A> ----------------------------------------------------------------------=0D= =0A> -------------------------- This message is for the designated=20=0D=0A= > recipient only and may contain privileged, proprietary, or otherwise=20=0D= =0A> private information.=0D=0A> If you have received it in error, please n= otify the sender immediately=0D=0A=0D=0A> and delete the original. Any una= uthorized use of this email is=20=0D=0A> prohibited.=0D=0A> ---------------= -------------------------------------------------------=0D=0A> ------------= --------------=0D=0A> [mf2]=0D=0A>=20=0D=0A>=20=0D=0A> --------------------= --------------------------------------------------=0D=0A> --- Take Surveys.= Earn Cash. Influence the Future of IT Join=20=0D=0A> SourceForge.net's Tec= hsay panel and you'll get the chance to share=20=0D=0A> your opinions on IT= & business topics through brief surveys - and earn=0D=0A=0D=0A> cash=20=0D= =0A> http://www.techsay.com/default.php=3Fpage=3Djoin.php&p=3Dsourceforge&C= ID=3DDEV=0D=0A> DEV _______________________________________________=0D=0A> = Jython-users mailing list=0D=0A> Jyt...@li...=0D=0A> = https://lists.sourceforge.net/lists/listinfo/jython-users=0D=0A>=20=0D=0A> =0D= =0A=0D=0A=0D=0A=0D=0A------------------------------------------------------= ------------------------------------------=0D=0AThis message is for the des= ignated recipient only and may=0D=0Acontain privileged, proprietary, or oth= erwise private information. =20=0D=0AIf you have received it in error, plea= se notify the sender=0D=0Aimmediately and delete the original. Any unautho= rized use of=0D=0Athis email is prohibited.=0D=0A--------------------------= ----------------------------------------------------------------------=0D=0A= [mf2]=0D=0A |
From: Kent J. <ke...@td...> - 2007-01-19 11:02:09
|
Desai, Raul wrote: > Hi > > The reason why I am using numGrinderThreads is I need to work out how > many threads my performance tool(Grinder) is using. So for example > Thread 1 will record 1, thread record 2 and so on. > > Given the code you gave me I go the following output. Why are there 2 > copies of everything?. What is the code? It looks like you are printing the same (correct) list twice, not that one list has two copies of the data. The code you posted before had an outer loop that repeated everything, are you still doing that? > > grinder threads is 2 > [['AAAAA', 'BBBBB'], ['ZZZZZ', 'XXXXX']] > [['AAAAA', 'BBBBB'], ['ZZZZZ', 'XXXXX']] > > > Ideally I want one copy of each record. Also, how would I access values > in the this list?. In [1]: a=[['AAAAA', 'BBBBB'], ['ZZZZZ', 'XXXXX']] In [2]: a[0] Out[2]: ['AAAAA', 'BBBBB'] In [3]: a[0][0] Out[3]: 'AAAAA' In [4]: a[1][1] Out[4]: 'XXXXX' Kent |
From: Desai, R. <Rau...@an...> - 2007-01-19 14:57:50
|
Hi Guys,=0D=0A=0D=0AI managed to solve it. The code I had was way too comp= licated and=0D=0Aunnecessary. Many thanks for you help=20=0D=0A=0D=0ARaul=0D= =0A=0D=0A=0D=0A-----Original Message-----=0D=0AFrom: jython-users-bounces@l= ists.sourceforge.net=0D=0A[mailto:jyt...@li...= t] On Behalf Of Kent=0D=0AJohnson=0D=0ASent: 19 January 2007 11:02=0D=0ATo:= Desai, Raul=0D=0ACc: jython users=0D=0ASubject: Re: [Jython-users] 2D Arra= ys....=0D=0A=0D=0ADesai, Raul wrote:=0D=0A> Hi=0D=0A>=20=0D=0A> The reason = why I am using numGrinderThreads is I need to work out how=0D=0A=0D=0A> ma= ny threads my performance tool(Grinder) is using. So for example=20=0D=0A>= Thread 1 will record 1, thread record 2 and so on.=0D=0A>=20=0D=0A> Given = the code you gave me I go the following output. Why are there 2=0D=0A=0D=0A= > copies of everything=3F.=0D=0A=0D=0AWhat is the code=3F It looks like you= are printing the same (correct) list=0D=0Atwice, not that one list has two= copies of the data. The code you posted=0D=0Abefore had an outer loop that= repeated everything, are you still doing=0D=0Athat=3F=0D=0A>=20=0D=0A> gri= nder threads is 2=0D=0A> [['AAAAA', 'BBBBB'], ['ZZZZZ', 'XXXXX']] [['AAAAA'= , 'BBBBB'],=20=0D=0A> ['ZZZZZ', 'XXXXX']]=0D=0A>=20=0D=0A>=20=0D=0A> Ideall= y I want one copy of each record. Also, how would I access=20=0D=0A> value= s in the this list=3F.=0D=0A=0D=0AIn [1]: a=3D[['AAAAA', 'BBBBB'], ['ZZZZZ'= , 'XXXXX']]=0D=0A=0D=0AIn [2]: a[0]=0D=0AOut[2]: ['AAAAA', 'BBBBB']=0D=0A=0D= =0AIn [3]: a[0][0]=0D=0AOut[3]: 'AAAAA'=0D=0A=0D=0AIn [4]: a[1][1]=0D=0AOut= [4]: 'XXXXX'=0D=0A=0D=0AKent=0D=0A=0D=0A=0D=0A-----------------------------= -------------------------------------------=0D=0A-=0D=0ATake Surveys. Earn = Cash. Influence the Future of IT Join=0D=0ASourceForge.net's Techsay panel = and you'll get the chance to share your=0D=0Aopinions on IT & business topi= cs through brief surveys - and earn cash=0D=0Ahttp://www.techsay.com/defaul= t.php=3Fpage=3Djoin.php&p=3Dsourceforge&CID=3DDEVDE=0D=0AV=0D=0A___________= ____________________________________=0D=0AJython-users mailing list=0D=0AJy= tho...@li...=0D=0Ahttps://lists.sourceforge.net/lists/l= istinfo/jython-users=0D=0A=0D=0A-------------------------------------------= -----------------------------------------------------=0D=0AThis message is = for the designated recipient only and may=0D=0Acontain privileged, propriet= ary, or otherwise private information. =20=0D=0AIf you have received it in = error, please notify the sender=0D=0Aimmediately and delete the original. = Any unauthorized use of=0D=0Athis email is prohibited.=0D=0A---------------= ---------------------------------------------------------------------------= ------=0D=0A[mf2]=0D=0A |
From: Sidharth K. <sid...@gm...> - 2007-01-18 19:04:22
|
you could use list comprehensions here f = open('test.csv') data = f.readline() a = [l.split(",") for l in data] On 19-Jan-07, at 12:04 AM, Desai, Raul wrote: > Thanks for that.....however I still don't think what I is correct > and I > can not figure it out. > > My CSV looks likes this: > > AAAAA,BBBBB > ZZZZZ,XXXXX > > And my code as follow: > > userFile = open('test.csv', 'r') > userFileLineCounter = 0 > userFileLine = 'null' > xdi = '' > name = '' > a = [[],[]] > print 'grinder threads is %d' % (numGrinderThreads) > > while (userFileLineCounter != numGrinderThreads): > userFileLines = userFile.readlines() > userFileLineCounter += 1 > if (userFileLineCounter == (grinder.threadID + 1)): > for i in range(0, len(userFileLines)): > print 'Thread Data Line %d: %s' % (i, userFileLines[i]) > # split the string into each individual data item > lineData = userFileLines[i].split(',') > for j in range(0, len(lineData)): > print 'PK %d value: %s' % (j, lineData[j]) > a[0].append(lineData[j]) > a[1].append(lineData[j]) > break > print a > userFile.close() > print 'file closed' > > The output is > > grinder threads is 2 > [[], []] > file closed > Thread Data Line 0: AAAAA,BBBBB > > XDI1 0 value: AAAAA > XDI1 1 value: BBBBB > > Thread Data Line 1: ZZZZZ,XXXXX > XDI1 0 value: ZZZZZ > XDI1 1 value: XXXXX > [['AAAAA', 'BBBBB\n', 'ZZZZZ', 'XXXXX'], ['AAAAA', 'BBBBB\n', 'ZZZZZ', > 'XXXXX']] file closed > > > I would expect the List to look like: > > [['AAAAA', 'BBBBB]['ZZZZZ', 'XXXXX']] > > Any suggestions?. > > Regards > > Raul > > > > -----Original Message----- > From: jyt...@li... > [mailto:jyt...@li...] On Behalf Of Leo > User > Sent: 18 January 2007 17:16 > To: jython users > Subject: Re: [Jython-users] 2D Arrays.... > > You can probably just use list within a list: > list = [[],[]] >>>> a = [[],[]] >>>> a > [[], []] >>>> for z in xrange(10): > ... a[0].append(z) > ... a[1].append(z) > ... >>>> a > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>>> > > or maybe use jarray. > > Or you can use one list/array and calculate the index. > > leouser > > > --- "Desai, Raul" <Rau...@an...> wrote: > >> Hi Guys >> >> If I am reading a CSV file which has 2 columns and 10 records, I >> can I > >> create a 2D Array which will hold this data?. The 2D array will be >> populated in a For loop which I have. Also how can access for >> example > >> certain values for a nth record?. >> >> I have not been able to hold of much information on my problem. Any >> assistance will be greatly appreciated. >> >> Regards >> >> Raul >> >> e.net/lists/listinfo/jython-users >> > > > -----Original Message----- > From: jyt...@li... > [mailto:jyt...@li...] On Behalf Of Leo > User > Sent: 18 January 2007 17:16 > To: jython users > Subject: Re: [Jython-users] 2D Arrays.... > > You can probably just use list within a list: > list = [[],[]] >>>> a = [[],[]] >>>> a > [[], []] >>>> for z in xrange(10): > ... a[0].append(z) > ... a[1].append(z) > ... >>>> a > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>>> > > or maybe use jarray. > > Or you can use one list/array and calculate the index. > > leouser > > > --- "Desai, Raul" <Rau...@an...> wrote: > >> Hi Guys >> >> If I am reading a CSV file which has 2 columns and 10 records, I >> can I > >> create a 2D Array which will hold this data?. The 2D array will be >> populated in a For loop which I have. Also how can access for >> example > >> certain values for a nth record?. >> >> I have not been able to hold of much information on my problem. Any >> assistance will be greatly appreciated. >> >> Regards >> >> Raul >> >> > ---------------------------------------------------------------------- > -- > ------------------------ >> This message is for the designated recipient only and may contain >> privileged, proprietary, or otherwise private information. >> If you have received it in error, please notify the sender >> immediately > >> and delete the original. Any unauthorized use of this email is >> prohibited. >> > ---------------------------------------------------------------------- > -- > ------------------------ >> [mf2] >>> > ---------------------------------------------------------------------- > -- > - >> Take Surveys. Earn Cash. Influence the Future of IT Join >> SourceForge.net's Techsay panel and you'll get the chance to share >> your opinions on IT & business topics through brief surveys - and >> earn > >> cash >> > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDE > V> > _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> > https://lists.sourceforge.net/lists/listinfo/jython-users >> > > > > > ______________________________________________________________________ > __ > ____________ > It's here! Your new message! > Get new email alerts with the free Yahoo! Toolbar. > http://tools.search.yahoo.com/toolbar/features/mail/ > > ---------------------------------------------------------------------- > -- > - > Take Surveys. Earn Cash. Influence the Future of IT Join > SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDE > V > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > ---------------------------------------------------------------------- > -------------------------- > This message is for the designated recipient only and may > contain privileged, proprietary, or otherwise private information. > If you have received it in error, please notify the sender > immediately and delete the original. Any unauthorized use of > this email is prohibited. > ---------------------------------------------------------------------- > -------------------------- > [mf2] > > > ---------------------------------------------------------------------- > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |