packaging python code in zip file

2010-12-09 Thread mark jason
hi,
I have created a python app in eclipse pydev .The app is structured as
below..

mypackage
  |__ __init__.py
  |__ driver.py
  |__ helper.py
  |__ utils.py

The driver.py has the main program.I have added if
__name__=="__main__" block in  the

driver.py and pydev's run configuration has the following values,
Project : myproject
Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
 So,the app runs in pydev without any problems.

Then I thought of providing the modules as a zip file.So I created a
zip file containing
mypackage directory.The user should be able to unzip the zip file and
run the application from command line .

What bothers me is that ,the user will have to cd to mypackage folder
and run python driver.py..
This doesn't look like the proper way..
I also thought of  putting the driver,helper,utils modules in a folder
called mycode and zipping it without the __init__.py file .
I am not sure which is the correct way.
Can somebody advise me as to how I can package it better?

thanks,

mark
-- 
http://mail.python.org/mailman/listinfo/python-list


printing error message from an Exception

2010-12-09 Thread mark jason
hi
I was trying out some file operations and was trying to open a non
existing file as below

def do_work(filename):
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
print 'failed',e.message
finally:
f.close()
print 'closed'

if __name__=='__main__':
do_work("C:\code\misc.txt")   # there is no such file

I am getting an error and a warning

DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
  print 'failed',e.message

UnboundLocalError: local variable 'f' referenced before assignment

Is there a way to overcome the DeprecationWarning? I wanted to print
the error message from the IOError.How do I do this?
Also ,what should I do about the UnboundLocalError?

thanks and regards ,
mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: printing error message from an Exception

2010-12-10 Thread mark jason
On Dec 10, 11:55 am, Steven D'Aprano  wrote:
>     # By the way, IOError is not the only exception you could see.


thanks for the help Steven. Is it OK to catch Exception instead of
IOError ?
In some operation which can cause many errors ,can I use the
following?

try:
do_something()
except Exception,e:
display_message(e.args)
handle_exception(e)


thanks,
mark
-- 
http://mail.python.org/mailman/listinfo/python-list