473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

program with raw_input prompt behaves differently after compile

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/Coo.../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

Dec 24 '05 #1
2 1469
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-pro...or-187633.html

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

--
Hans Nowak
http://zephyrfalcon.org/
Dec 24 '05 #2
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 Nowak wrote:
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-pro...or-187633.html

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

Dec 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Helmut Jarausch | last post by:
Hi when using an interactive Python script, I'd like the prompt given by raw_input to go to stderr since stdout is redirected to a file. How can I change this (and suggest making this the...
5
by: Thomas Philips | last post by:
I'd like to stop a program (i.e. terminate its execution) without raising an exception if some condition is met, e.g answer = " " while answer not in "yn": answer = raw_input("y for yes, n for...
2
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
0
by: biganimal | last post by:
I have a program and I want the program to be able to save question/answers so the program actually gets smarter without getting amnesia everytime its started. Can anyone help??? # questor.py ...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
0
by: Nick Stinemates | last post by:
On Tue, Apr 15, 2008 at 07:24:05AM -0700, shawn s wrote: I love that you call the users of your app retards :) That rocks! ping runs forever. tracert doesnt. try: -- Nick Stinemates...
5
by: jamitwidme | last post by:
Is there any way to type into a Tkinter frame window? I want to use raw_input() within a Tkinter frame.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.