[Tutor] Weird Try..Except Error

2011-11-25 Thread Nikunj.Badjatya

Hi All,

Please look at the snippet below.
When I am running my module its giving me following error.
Using : Python 2.7, windows Env.

{{{
# User defined modules
try:
from scripts import precheck
from scripts import input
from scripts import validate
from scripts import logsetup
from scripts.constants import *
except ImportError, err_msg:  == line 38
print(ERROR {0}.format(err_msg))
print(INFO  Please verify the presence of above module, and restart the 
installation)
sys.exit(1)

}}}

{{{
Output:

C:\ install.py -f input.xml
  File  C:\install.py, line 38
except ImportError, err_msg:
  ^
SyntaxError: invalid syntax
}}}

I checked the comma and spacing and didn't find any problem.

Any idea.?

Thanks
Nikunj
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Weird Try..Except Error

2011-11-25 Thread Nikunj.Badjatya
Hi All,

Thanks for the info.
I had Python27 and Python32 both installed togethar.
In Windows the PATH env variable, I had set Python27 exe and lib path.

But When I do
C:\ Python  [PressEnter]
I get 2.7

But when I run 
C:\ script.py  [PressEnter]
The script is running with Python3.2 , thts weird because I have set my Path 
variable with Pytho27 exe and lib.

Which was causing the problem.

Thanks
Nikunj

-Original Message-
From: tutor-bounces+nikunj.badjatya=emc@python.org 
[mailto:tutor-bounces+nikunj.badjatya=emc@python.org] On Behalf Of Peter 
Otten
Sent: Friday, November 25, 2011 5:28 PM
To: tutor@python.org
Subject: Re: [Tutor] Weird Try..Except Error

nikunj.badja...@emc.com wrote:

 Please look at the snippet below.
 When I am running my module its giving me following error.
 Using : Python 2.7, windows Env.
 
 {{{
 # User defined modules
 try:
 from scripts import precheck
 from scripts import input
 from scripts import validate
 from scripts import logsetup
 from scripts.constants import *
 except ImportError, err_msg:  == line 38
 print(ERROR {0}.format(err_msg))
 print(INFO  Please verify the presence of above module, and restart
 the installation) sys.exit(1)
 
 }}}
 
 {{{
 Output:
 
 C:\ install.py -f input.xml
   File  C:\install.py, line 38
 except ImportError, err_msg:
   ^
 SyntaxError: invalid syntax
 }}}
 
 I checked the comma and spacing and didn't find any problem.
 
 Any idea.?

You are likely mistaken about the Python version you are using. The above 
error will be triggered by Python 3.x which expects

try:
...
except ImportError as err_msg:
...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ProgressBar - Python and Powershell

2011-11-20 Thread Nikunj.Badjatya
Can anyone throw some light on this please. ! ?


From: tutor-bounces+nikunj.badjatya=emc@python.org 
[mailto:tutor-bounces+nikunj.badjatya=emc@python.org] On Behalf Of 
nikunj.badja...@emc.com
Sent: Thursday, November 17, 2011 4:21 PM
To: tutor@python.org
Subject: [Tutor] ProgressBar - Python and Powershell


Hi All,

I am using Python 2.7, windows Env.
I have an Installer written in Python(45%) and Powershell(55%) which is used to 
install Virtual Machines at specific locations. It is single threaded.
I am trying to implement a ProgressBar  for this installer. So that the user 
will come to know the progress of the installation.
I am using pypi progressbar module.
The top script is in python which inturns calls powershell scripts using 
subprocess.call() and proceeds with the installation.

I am taking a shared file between python and powershell, so that diff functions 
can update their %age completion level in to the file. Ex. Func1() updates it 
to 5%,  func2() will add its own 5% to it.. and so on.
At the start of the (main.py) script I am creating a thread whose sole purpose 
would be to keep READ a temp file for a new entry in it.
Based on this entry I can have my thread update the progressbar on the console.

My questions are:

1.   Can I have a better shared mechanism between python and powershell.?  
As I am using a file here. Reading + writing in python and writing only in 
powershell.  !

2.   Does this thread mechanism work.? I am yet to implement and test it.! 
:P What can be the possible shortfalls.?



Thanks

Nikunj
Bangalore - India

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ProgressBar - Python and Powershell

2011-11-20 Thread Nikunj.Badjatya
Thanks for the reply Steve.
I mean, the installer as a sole is single threaded.
They way to implement progressbar may turn it to multithreaded.

Anyways, I have posted the problem in pyhton-list ml.

Thanks
Nikunj

-Original Message-
From: tutor-bounces+nikunj.badjatya=emc@python.org 
[mailto:tutor-bounces+nikunj.badjatya=emc@python.org] On Behalf Of Steven 
D'Aprano
Sent: Sunday, November 20, 2011 8:46 PM
To: tutor@python.org
Subject: Re: [Tutor] ProgressBar - Python and Powershell

nikunj.badja...@emc.com wrote:
 Can anyone throw some light on this please. ! ?

This is a list for beginners learning Python. Your question is quite 
advanced for this list, as it involves both threads and subprocesses. It 
also uses a third-party module, progressbar, and a Windows-only 
application Powershell. You might get lucky and find somebody here that 
knows all of these technologies, but I think you're asking in the wrong 
place. Perhaps you should try in the main Python mailing list, 
python-l...@python.org, also available on Usenet as comp.lang.python.

By the way, you say that your application is single-threaded, but then 
describe using threads. That means it isn't single-threaded at all.

Good luck.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to get module name from ImportError

2011-11-20 Thread Nikunj.Badjatya
Hi All,

Please look at the following snippet.
{{{

# User defined modules
try:
from scripts import precheck
from scripts import validate
from scripts import constants
except ImportError:
print(ERROR: One of the modules (..scripts/precheck.py, validate.py, 
constants) is not present.)
print(INFO : Please verify the above modules, and restart the 
installation)
sys.exit(1)

}}}

See the red line.
I want to get the name of the particular module which is not available and 
hence causing ImportError.
One of the ways can be to get the STDERR and process it using re. !?

Is there a better alternate available .?

Thanks
Nikunj
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get module name from ImportError

2011-11-20 Thread Nikunj.Badjatya
Exactly !
Thanks a lot.

From: Christian Witts [mailto:cwi...@compuscan.co.za]
Sent: Monday, November 21, 2011 11:36 AM
To: Badjatya, Nikunj
Cc: tutor@python.org
Subject: Re: [Tutor] How to get module name from ImportError

On 2011/11/21 07:54 AM, nikunj.badja...@emc.commailto:nikunj.badja...@emc.com 
wrote:
Hi All,

Please look at the following snippet.
{{{

# User defined modules
try:
from scripts import precheck
from scripts import validate
from scripts import constants
except ImportError:
print(ERROR: One of the modules (..scripts/precheck.py, validate.py, 
constants) is not present.)
print(INFO : Please verify the above modules, and restart the 
installation)
sys.exit(1)

}}}

See the red line.
I want to get the name of the particular module which is not available and 
hence causing ImportError.
One of the ways can be to get the STDERR and process it using re. !?

Is there a better alternate available .?

Thanks
Nikunj




___

Tutor maillist  -  Tutor@python.orgmailto:Tutor@python.org

To unsubscribe or change subscription options:

http://mail.python.org/mailman/listinfo/tutor
 try:
... import nothing
... except ImportError, err_msg:
... print err_msg
...
No module named nothing

Hope that helps.
--

Christian Witts
Python Developer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ProgressBar - Python and Powershell

2011-11-17 Thread Nikunj.Badjatya

Hi All,

I am using Python 2.7, windows Env.
I have an Installer written in Python(45%) and Powershell(55%) which is used to 
install Virtual Machines at specific locations. It is single threaded.
I am trying to implement a ProgressBar  for this installer. So that the user 
will come to know the progress of the installation.
I am using pypi progressbar module.
The top script is in python which inturns calls powershell scripts using 
subprocess.call() and proceeds with the installation.

I am taking a shared file between python and powershell, so that diff functions 
can update their %age completion level in to the file. Ex. Func1() updates it 
to 5%,  func2() will add its own 5% to it.. and so on.
At the start of the (main.py) script I am creating a thread whose sole purpose 
would be to keep READ a temp file for a new entry in it.
Based on this entry I can have my thread update the progressbar on the console.

My questions are:

1.   Can I have a better shared mechanism between python and powershell.?  
As I am using a file here. Reading + writing in python and writing only in 
powershell.  !

2.   Does this thread mechanism work.? I am yet to implement and test it.! 
:P What can be the possible shortfalls.?



Thanks

Nikunj
Bangalore - India

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor