LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2010)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 23 Jul 2010 08:14:18 -0700
Reply-To:     Albert-Jan Roskam <fomcl@yahoo.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Albert-Jan Roskam <fomcl@yahoo.com>
Subject:      Re: SOLVED: [SPSSX-L] Can Python read .sps files created by
              versions              16+?
Comments: To: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
In-Reply-To:  <SNT110-W44E47F4BC9BF3C166CD8F3FAA30@phx.gbl>
Content-Type: multipart/alternative;

Hi Ruben,

If you put a 'break' in the inner loop you might speed up your program a bit. The inner loop is terminated right when the first HOST command is found, ie no time wasted on the remainder of the file.

I probably doesn't matter much in this case, but still ;-)

Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Fri, 7/23/10, Ruben van den Berg <ruben_van_den_berg@hotmail.com> wrote:

From: Ruben van den Berg <ruben_van_den_berg@hotmail.com> Subject: [SPSSX-L] SOLVED: [SPSSX-L] Can Python read .sps files created by versions 16+? To: SPSSX-L@LISTSERV.UGA.EDU Date: Friday, July 23, 2010, 3:21 PM

Oh, I see! The problem is that   if "HOST".lower() in line:   should have been   if "host" in line.lower():   And now it indeed renders my V17 test file as well! Well, at least I seem to have a talent for looking in the wrong places when my code doesn't work...   Thanks a lot for helping out again! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: ruben.van.den.berg@tns-nipo.com Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com

  To: ruben_van_den_berg@hotmail.com CC: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: [SPSSX-L] Can Python read .sps files created by versions 16+? From: peck@us.ibm.com Date: Fri, 23 Jul 2010 06:54:38 -0600

V16 files are no different in format from earlier syntax files, although they could be in Unicode.  Unicode would not affect recognition of plain ascii text such as HOST, though.

But the code below lower cases "HOST" and then searches each line for "host".  I'd do it the other way around: lower case line and search for "host"

Also, note that os.walk is designed to return files one by one, so you could do the searching within the loop in the first program.

HTH,

Jon Peck SPSS, an IBM Company peck@us.ibm.com 312-651-3435

From: Ruben van den Berg <ruben_van_den_berg@hotmail.com> To: SPSSX-L@LISTSERV.UGA.EDU Date: 07/23/2010 03:24 AM Subject: [SPSSX-L] Can Python read .sps files created by versions 16+? Sent by: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>

Dear all,

I wanted to identify all .sps files in my folder and subfolders that contain any HOST command. My program does render a couple of .sps files which all contain at least one HOST command. However, it seems as if these are all syntax files created by version 15 or older (which are readable with notepad, whereas 16+ seems to require wordpad). For the sake of the experiment, I created a little syntax file with a HOST command in V17 and it was -indeed- not identified as an .sps file containing a HOST command.

Could anyone suggest how I could modify my program to include version 16+ syntax as well?

TIA!

Ruben van den Berg Consultant Models & Methods TNS NIPO Email: ruben.van.den.berg@tns-nipo.com Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com

begin program. import os def app(path):    paths = []    for dp, ds, fs in os.walk(path):        for f in fs:            paths.append(os.path.join(dp,f))    return paths end program.

begin program. paths=app('/Copy_Syn') targets=[] for path in paths:    file=open(path,"r")    for line in file:        if "HOST".lower() in line:            targets.append(path) print "\n".join(targets) end program.

New Windows 7: Find the right PC for you. Learn more.

New Windows 7: Find the right PC for you. Learn more.


[text/html]


Back to: Top of message | Previous page | Main SPSSX-L page