|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Please help debug.
Hello!
Can anyone see any error in this piece of code? (It is not made by me, but I cannot get it to work. It yields ./install.py: line 5: syntax error near unexpected token `faile(c' ./install.py: line 5: `def faile(cmd):' when I utilize it. Below is the code. Thanks in advance, Ronny Mandal -- start -- # !/usr/bin/env python import os,sys,shutil,re def faile(cmd): print '%s: Running %s failed' % (sys.argv[0],cmd) sys.exit(1) if os.name=='posix': # unix? origdir=os.getcwd() dir='install' #if not os.path.isdir(dir): # os.mkdir(dir) os.chdir(dir) print 'Generating makefile using qmake.........' cmd='qmake' failure=os.system(cmd) if failure: faile(cmd) print 'Attempting make...' cmd='make' failure=os.system(cmd) if failure: faile(cmd) print 'Cleaning objekt files....' cmd='rm *.o Makefile' failure=os.system(cmd) if failure: faile(cmd) cmd='mv MuseSveis ../' failure=os.system(cmd) if failure: faile(cmd) os.chdir(origdir) print 'Run by typing MuseSveis' else: print 'Use linux!!\n' -- end -- |
|
#2
|
|||
|
|||
|
The first error is that the code has not been posted with [ CODE] tags, so the indentation is lost.
I can't find the second error until the first is fixed. Dave - The Developers' Coach |
|
#3
|
|||
|
|||
|
Quote:
-- Sorry, here it is again. Regards, RM Code:
# !/usr/bin/env python
import os,sys,shutil,re
def faile(cmd):
print '%s: Running %s failed' # (sys.argv[0],cmd)
sys.exit(1)
if os.name=='posix': # unix?
origdir=os.getcwd()
dir='install'
#if not os.path.isdir(dir):
# os.mkdir(dir)
os.chdir(dir)
print 'Generating makefile using qmake.........'
cmd='qmake'
failure=os.system(cmd)
if failure: faile(cmd)
print 'Attempting make...'
cmd='make'
failure=os.system(cmd)
if failure: faile(cmd)
print 'Cleaning objekt files....'
cmd='rm *.o Makefile'
failure=os.system(cmd)
if failure: faile(cmd)
cmd='mv MuseSveis ../'
failure=os.system(cmd)
if failure: faile(cmd)
os.chdir(origdir)
print 'Run by typing MuseSveis'
else:
print 'Use linux!!\n'
|
|
#4
|
||||
|
||||
|
First problem that comes to mind is that os.system() returns 0 if the command goes well - since to OS's 0 is true and none 0 is false, on the other hand, Python sees this a little differently. What this means to you?
Is you need to change lines like this.. Code:
failure = os.system(cmd) if failure: faile(cmd) into something like.. Code:
success = os.system(cmd) if not success: faile(cmd) I may be wrong, but that makes a lot of sence to me . Then i am a little odd .Hope this helps, Mark. |
|
#5
|
||||
|
||||
|
You might also want to loose re, and shutil from your import statment since they are not being used anywhere in the program as of yet
. This means that you have to waist time importing something your program never uses.Mark. |
|
#6
|
|||
|
|||
|
Thanks, but
thanks alot, but I still get the error message 'error near unexpected token..." as recently.
It seems like they've done a wrong declaration of the 'faile'. Or... Hmm.. I appreciate all help. Cheers! |
|
#7
|
|||
|
|||
|
That line looks ok, but is it possible that it is not using the regular ASCII character set? If it is has a character from the extended unicode char set in the line, then it may make Python choke. That is the only thing I can think of that would cause that error message.
Try examining the original file in hex. Dave - The Developers' Coach |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Please help debug. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|