Re: [Tutor] system call

2007-10-27 Thread Eric Walker
Alan, The problem is that I have another tool that has an initialization period when you start it up. I want to see how long it takes for it to start up or initialize. So, I set up the tool to startup and after it finishes the init stage, load up a file which has a custom procedure. Then run thi

Re: [Tutor] position

2007-10-27 Thread linda.s
On 10/27/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "linda.s" <[EMAIL PROTECTED]> wrote > > >I have a string a= "qq,eee,rrr". > a.index(",") > > 2 > > It is the position of the first "," in a. > > Is that possible to find the Nth "," in a if a is a very long string > > and I need know the p

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Dick Moores
At 04:06 PM 10/27/2007, Alan Gauld wrote: >"Dick Moores" <[EMAIL PROTECTED]> wrote > > >> Hence if type(n) is already long it does not have to get converted > >> to int to accommodate something small. > > > > And that's not a bug? > >No its expected behaviour. >If you start with a float and add an

Re: [Tutor] underlying C/C++ object has been deleted

2007-10-27 Thread David Boddie
On Thu Oct 25 06:45:38 CEST 2007, Lawrence Shafer wrote: > I am trying to convert a program with hand coded QT over to using UI > files from QT Designer. I am getting the error below and do not > understand what's going on. This error occurs when an object referred to by Python and Qt is delete

Re: [Tutor] question re type()

2007-10-27 Thread Dick Moores
At 11:34 AM 10/27/2007, Dave Kuhlman wrote: >On Sat, Oct 27, 2007 at 01:03:18PM +0100, Alan Gauld wrote: > > > if type(n) == int > > > > Or just use an instance of the same type: > > > > if type(n) == type(42) > >Calling type(n) for any integer seems to return the same object. >I checked with id().

Re: [Tutor] about Tix

2007-10-27 Thread ALAN GAULD
> This looks to me like the Tix DLL hasn't been installed or it's > installed in a folder where it can''t be found. The Tix module > is just a wrapper round the Tix DLL so you need both. > > I wonder where should I install Tix DLL I'd look for the other DLLs in the Python tree or alternatively p

Re: [Tutor] position

2007-10-27 Thread Alan Gauld
"linda.s" <[EMAIL PROTECTED]> wrote >I have a string a= "qq,eee,rrr". a.index(",") > 2 > It is the position of the first "," in a. > Is that possible to find the Nth "," in a if a is a very long string > and I need know the position of the Nth ","? Yes but not directly. index takes a couple

Re: [Tutor] system call

2007-10-27 Thread Alan Gauld
"John" <[EMAIL PROTECTED]> wrote > for i in attempts: #attempts holds strings of shellscripts >cmd="%s which runs many different shell scripts and takes > about an > hour" % (i) >os.system(cmd) >#debugging >print "Finished with %s" % (i) >raw_input("More

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote >> Hence if type(n) is already long it does not have to get converted >> to int to accommodate something small. > > And that's not a bug? No its expected behaviour. If you start with a float and add an integer the result is a float. Why should long act any

Re: [Tutor] system call

2007-10-27 Thread Alan Gauld
"Eric Walker" <[EMAIL PROTECTED]> wrote > I am trying to run a timing script but I need the python program > to stop and wait for the executable to finish. Does anyone have > any examples of doing this? There are several ways to do it depending on what exactly you are trying to do. We need a

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > n = 100 You start with n as a long. > print type(n) > while True: > if type(n) == long: > n -= 100 A long minus an int gives a long: >>> n = long(42) >>> n 42L >>> n - 3 39L So n never changes into an int even though it is wit

Re: [Tutor] question re type()

2007-10-27 Thread Alan Gauld
"Dave Kuhlman" <[EMAIL PROTECTED]> wrote > Calling type(n) for any integer seems to return the same object. > I checked with id(). I would hope so since they are all of the same type. It thus makes sense that they all return a reference to the same type object. > So, should we be using: > >

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Alan Gauld
"John" <[EMAIL PROTECTED]> wrote >I have a file sitelocations: > > STN_id[1]=AAA > STNlat[1]=58.80 > STNlon[1]=17.40 > STNelv[1]=20 > STN_id[2]=BBB > STNlat[2]=42.45 > STNlon[2]=25.58 > STNelv[2]=2925 > > which in shell scripts I can simple 'source'. > In Python I have to: >

Re: [Tutor] system call

2007-10-27 Thread Ricardo Aráoz
John wrote: > I have the exact same situation, but system doesn't seem to wait. Here > is my pseudo code: > > for i in attempts: #attempts holds strings of shellscripts > cmd="%s which runs many different shell scripts and takes about > an hour" % (i) > os.system(cmd) > #d

Re: [Tutor] system call

2007-10-27 Thread James
How about using subprocess.Popen( ... ).wait()? I believe subprocess.call() will wait until the process is finished, too. The subprocess module is meant to replace spawn, popen2, os.system() etc. if I'm not mistaken. Take a look at this excellent resource I've used numerous times: http://ww

Re: [Tutor] system call

2007-10-27 Thread John
I have the exact same situation, but system doesn't seem to wait. Here is my pseudo code: for i in attempts: #attempts holds strings of shellscripts cmd="%s which runs many different shell scripts and takes about an hour" % (i) os.system(cmd) #debugging print "Fini

[Tutor] position

2007-10-27 Thread linda.s
I have a string a= "qq,eee,rrr". >>> a.index(",") 2 It is the position of the first "," in a. Is that possible to find the Nth "," in a if a is a very long string and I need know the position of the Nth ","? Thanks, Linda ___ Tutor maillist - Tutor@pyth

Re: [Tutor] about Tix

2007-10-27 Thread linda.s
On 10/26/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > Linda, > > >I run the following code in Python 2.5 and got the error (when I do > > "import Tix", no error). > > Congratulations I think this might just be the first Tix question > on the tutor list! :-) > > > Traceback (most recent call last): >

Re: [Tutor] question re type()

2007-10-27 Thread Dave Kuhlman
On Sat, Oct 27, 2007 at 01:03:18PM +0100, Alan Gauld wrote: > > "Dick Moores" <[EMAIL PROTECTED]> wrote > > > if type(n) == 'int' or type(n) == 'long': > > do something > > don't use strings > > if type(n) == int > > Or just use an instance of the same type: > > if type(n) == type(42) Call

Re: [Tutor] system call

2007-10-27 Thread Eric Walker
disregard this one. I found the answer. I was using spawn instead of os.system. Thanks. - Original Message From: Eric Walker <[EMAIL PROTECTED]> To: tutor@python.org Sent: Saturday, October 27, 2007 9:55:05 AM Subject: [Tutor] system call Hello, I am trying to run a timing script but

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
Thanks, it's strange, it works within a script defined at the top, but if I try to import it from a module it fails: NameError: name 'files' is not defined On 10/27/07, Aditya Lal <[EMAIL PROTECTED]> wrote: > > > > On 10/27/07, John <[EMAIL PROTECTED]> wrote: > > > > Note, i need the ns+1 beca

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Dick Moores
At 10:27 AM 10/27/2007, Jeff Younker wrote: >On Oct 27, 2007, at 12:52 PM, Dick Moores wrote: >>At 08:39 AM 10/27/2007, Aditya Lal wrote: >>> Hence if type(n) is already long it does not have to get converted >>>to int to accommodate something small. >> >>And that's not a bug? > >There is no need

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Jeff Younker
On Oct 27, 2007, at 12:52 PM, Dick Moores wrote: > At 08:39 AM 10/27/2007, Aditya Lal wrote: >> Hence if type(n) is already long it does not have to get converted >> to int to accommodate something small. > > And that's not a bug? There is no need for a type change to represent zero, so, no, that

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Aditya Lal
On 10/27/07, John <[EMAIL PROTECTED]> wrote: > > Note, i need the ns+1 because the 'source files are not zero indexed. > > On 10/27/07, John <[EMAIL PROTECTED] > wrote: > > > > Here's where I am: > > > > > > def source(filename, vList): > > """ takes a file object and a list of variables as input

[Tutor] system call

2007-10-27 Thread Eric Walker
Hello, I am trying to run a timing script but I need the python program to stop and wait for the executable to finish. Does anyone have any examples of doing this? Thanks Python Newbie __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best s

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Dick Moores
At 08:39 AM 10/27/2007, Aditya Lal wrote: >I would expect that a type change will happen if there is a need. Hey, I HAD a need! OK, a made-up one. > Hence if type(n) is already long it does not have to get converted > to int to accommodate something small. And that's not a bug? >I changed you

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
Note, i need the ns+1 because the 'source files are not zero indexed. On 10/27/07, John <[EMAIL PROTECTED]> wrote: > > Here's where I am: > > > def source(filename, vList): > """ takes a file object and a list of variables as input """ > import re > # Read the file > fid=open(filename,'r') >

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
Here's where I am: def source(filename, vList): """ takes a file object and a list of variables as input """ import re # Read the file fid=open(filename,'r') lines = fid.readlines() fid.close() #how many variables ns=len(lines)/len(vList) #predefine the varibles for v in vList: exec(

Re: [Tutor] More type() puzzlement

2007-10-27 Thread Aditya Lal
On 10/27/07, Dick Moores <[EMAIL PROTECTED]> wrote: > > Win XP, Python 2.5.1 > > > #!/usr/bin/env python > #coding=utf-8 > > n = 100 # 10 billion > print "type of 10 billion is", type(n) > n = 10 # 1 billion > print "type of 1 billion is", type(n) > > raw_in

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Aditya Lal
On 10/27/07, John <[EMAIL PROTECTED]> wrote: > > The problem is the infies are also being used in a shell scripted > environment, they are frequently updated and cannot be changed. > > So ideadly I could just define a function which sourced the file, assuming > the variable names passed in the *arg

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
The problem is the infies are also being used in a shell scripted environment, they are frequently updated and cannot be changed. So ideadly I could just define a function which sourced the file, assuming the variable names passed in the *args list. So, yes, I know the names, they just haven't bee

[Tutor] More type() puzzlement

2007-10-27 Thread Dick Moores
Win XP, Python 2.5.1 #!/usr/bin/env python #coding=utf-8 n = 100 # 10 billion print "type of 10 billion is", type(n) n = 10 # 1 billion print "type of 1 billion is", type(n) raw_input("press enter to continue") n = 100 print type(n) while True:

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Aditya Lal
On 10/27/07, John <[EMAIL PROTECTED]> wrote: > > Ok, so trying to convert it to a function: > > def source(ifile, *args): > """ takes a file object and a list of variables as input. > assumes, source file has variables in format: > VAR[i]=variable """ > > imp

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
Ok, so trying to convert it to a function: def source(ifile, *args): """ takes a file object and a list of variables as input. assumes, source file has variables in format: VAR[i]=variable """ import re # Read the file lines = fd.readlines()

Re: [Tutor] question re type()

2007-10-27 Thread Aditya Lal
On 10/27/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > "Dick Moores" <[EMAIL PROTECTED]> wrote > > > if type(n) == 'int' or type(n) == 'long': > > do something > > don't use strings > > if type(n) == int > > Or just use an instance of the same type: > > if type(n) == type(42) > > Alan G. > > __

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
Thanks! This is helpful.. I like the RE approach as it's conceivable to write a function... On 10/27/07, Aditya Lal <[EMAIL PROTECTED]> wrote: > > You can source the file in python provided that you make it python > friendly:- > > STN_id[1]='AAA' instead of STN_id[1]=AAA > ... > > > --- >

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Aditya Lal
You can source the file in python provided that you make it python friendly:- STN_id[1]='AAA' instead of STN_id[1]=AAA ... --- import re # Read the file fd = open('sitelocations') lines = fd.readlines() fd.close() # Make it python friendly: put all values in 'single quotes' cmd = '\n'.joi

Re: [Tutor] 'source' in python or preloading variables

2007-10-27 Thread Ricardo Aráoz
John wrote: > I have a file sitelocations: > > STN_id[1]=AAA > STNlat[1]=58.80 > STNlon[1]=17.40 > STNelv[1]=20 > STN_id[2]=BBB > STNlat[2]=42.45 > STNlon[2]=25.58 > STNelv[2]=2925 > > which in shell scripts I can simple 'source'. In Python I have to: > sitesFile=file('sitelocat

[Tutor] 'source' in python or preloading variables

2007-10-27 Thread John
I have a file sitelocations: STN_id[1]=AAA STNlat[1]=58.80 STNlon[1]=17.40 STNelv[1]=20 STN_id[2]=BBB STNlat[2]=42.45 STNlon[2]=25.58 STNelv[2]=2925 which in shell scripts I can simple 'source'. In Python I have to: sitesFile=file('sitelocations','r') sites=sitesFile.readlines() i

Re: [Tutor] how to run function only for a pre-defined time

2007-10-27 Thread Alan Gauld
"Vinu Vikram" <[EMAIL PROTECTED]> wrote > Could anybody try to tell me whether it is possible to run a > function only > for a particular time period. In my python script I call some third > party > function which some time won't give results. I would like to write > the > script in such a way

Re: [Tutor] question re type()

2007-10-27 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > if type(n) == 'int' or type(n) == 'long': > do something don't use strings if type(n) == int Or just use an instance of the same type: if type(n) == type(42) Alan G. ___ Tutor maillist - Tutor@python.o

[Tutor] how to run function only for a pre-defined time

2007-10-27 Thread Vinu Vikram
Hi All Could anybody try to tell me whether it is possible to run a function only for a particular time period. In my python script I call some third party function which some time won't give results. I would like to write the script in such a way that, it will wait for the result from this functio

Re: [Tutor] question re type()

2007-10-27 Thread Dick Moores
At 04:34 AM 10/27/2007, Ricardo Aráoz wrote: >Just take the quotes off : > >if type(n) == int or type(n) == long : Thanks. I tried a lot of things, but not that one! Dick >HTH Oh, yeah! ___ Tutor maillist - Tutor@python.org http://mail.python.org/

Re: [Tutor] question re type()

2007-10-27 Thread Ricardo Aráoz
Dick Moores wrote: > I can't figure out how to test a variable n for its type. > > An example that is the wrong syntax, but shows what I want to do: > > if type(n) == 'int' or type(n) == 'long': >do something > > elif type(n) == 'float': >do something else > > elif type(n) == 'str': >

[Tutor] question re type()

2007-10-27 Thread Dick Moores
I can't figure out how to test a variable n for its type. An example that is the wrong syntax, but shows what I want to do: if type(n) == 'int' or type(n) == 'long': do something elif type(n) == 'float': do something else elif type(n) == 'str': do something different What's the correc

Re: [Tutor] Looking for suggestions for improving chessTimer.py code

2007-10-27 Thread Dick Moores
At 01:13 AM 10/27/2007, Alan Gauld wrote: >"Dick Moores" <[EMAIL PROTECTED]> wrote > > > OK, here's a short script, which runs fine on Windows. What do I add > > to have it run on unix as well? > >Take a look at my Event Driven programming topic. It contains a >simple key echo program using msvcrt

Re: [Tutor] Error 403 when accessing wikipedia articles?

2007-10-27 Thread Alan Gauld
"Alex Ryu" <[EMAIL PROTECTED]> wrote > I'm trying to use python to automatically download and process a > (small) > number of wikipedia articles. However, I keep getting a 403 > (Forbidden > Error), when using urllib2: FWIW I had a similar problem in trying to use Google to illustrate the use

Re: [Tutor] Looking for suggestions for improving chessTimer.py code

2007-10-27 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > OK, here's a short script, which runs fine on Windows. What do I add > to have it run on unix as well? Take a look at my Event Driven programming topic. It contains a simple key echo program using msvcrt and instructions for Linux users to convert it to