The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Please help debug.
Discuss Please help debug. in the Python Programming forum on Dev Shed. Please help debug. Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 18th, 2004, 09:35 AM
|
|
Registered User
|
|
Join Date: Sep 2003
Location: OSLO
Posts: 17
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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 --
|

June 18th, 2004, 09:44 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
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
|

June 18th, 2004, 10:56 AM
|
|
Registered User
|
|
Join Date: Sep 2003
Location: OSLO
Posts: 17
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DevCoach 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 |
--
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'
|

June 18th, 2004, 11:46 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
__________________
programming language development: www.netytan.com – Hula
|

June 18th, 2004, 11:48 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

June 18th, 2004, 02:24 PM
|
|
Registered User
|
|
Join Date: Sep 2003
Location: OSLO
Posts: 17
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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!
|

June 18th, 2004, 03:52 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|