program with raw_input prompt behaves differently after compile

T

tim

I want to write a program that looks into a given folder, groups files
that have a certain part of the filename in common and then copy those
groups one at a time to another place, using the raw_input prompt to
continue or break.

here's what I have:

###########
def makegroepen():
global p
import os
from longestcommonprefix import longestcommonprefix
p = raw_input('path')
l = os.listdir(p)
l.sort()
groepen=[]
groep=[]
basenames=[]
for r in l:
if r.find('_poly16.mp3'):
baselist = r.split('_')
mopobasename = baselist[0]
if mpbasename not in basenames:

basenames.append(mpbasename)
for s in l:

if
longestcommonprefix([s,mpbasename])==mpbasename:
print mpbasename
if s not in groep:
groep.append(s)
if len(groep)==6:
groepen.append(groep)
groep=[]
print groepen
return groepen
def movegr():
global p, groepen
for t in groepen:
contprompt=raw_input('continue? (n to stop)')
if contprompt=='n':
break
for curr in t:
if os.path.isfile(p+'\\'+curr):
tempfile = open(p+'\\'+curr, 'rb')
tempfile.seek(0)
tempfilecont = tempfile.read()
dircondition = os.path.exists('c:\\content\\workfolder')
if dircondition == False:
os.makedirs('c:\\content\\workfolder')
destfile = open('c:\\content\\workfolder\\'+curr, 'wb')
destfile.write(tempfilecont)
destfile.close()
if __name__=='__main__':
global groepen
groepen = makegroepen()
movegr()

########
(I renamed 'commonprefix' to 'longestcommonprefix', it is actually just
the 'binary search version' I found at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252177 )

It works fine when I run this from PythonWin IDE, but after compiling an
executable from it (py2exe) it exits whatever I type in the 'continue?'
prompt.
What am I doing wrong?
Thanks,
Tim
 
H

Hans Nowak

tim said:
I want to write a program that looks into a given folder, groups files
that have a certain part of the filename in common and then copy those
groups one at a time to another place, using the raw_input prompt to
continue or break.

> [...]

It works fine when I run this from PythonWin IDE, but after compiling an
executable from it (py2exe) it exits whatever I type in the 'continue?'
prompt.
What am I doing wrong?

Maybe this helps:

http://forums.devshed.com/python-pr...h-raw-input-from-a-exe-text-color-187633.html

The solution described here was to compile the program as a console app,
rather than a Windows app.
 
T

tim

It was kindof a stupid mistake on my part: I had to put 'import os' at
the very beginning, and not only in one of my two function definitions.
Thanks anyway, thanks to your link I also found how to change the colour
of the console...neat :p !
Tim

Hans said:
tim wrote:


I want to write a program that looks into a given folder, groups files
that have a certain part of the filename in common and then copy those
groups one at a time to another place, using the raw_input prompt to
continue or break.



[...]

It works fine when I run this from PythonWin IDE, but after compiling an
executable from it (py2exe) it exits whatever I type in the 'continue?'
prompt.
What am I doing wrong?

Maybe this helps:

http://forums.devshed.com/python-pr...h-raw-input-from-a-exe-text-color-187633.html

The solution described here was to compile the program as a console app,
rather than a Windows app.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,991
Messages
2,570,217
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top