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 |