Re: [Tutor] random number generator

2007-10-04 Thread Andrew James
I need to start using the reply all button... Andrew James wrote: > while guess != number: >guess = float(raw_input("Make another guess: ")) >if guess > number: >print "Lower..." >elif guess < number: >print "Higher..." >tries += 1 > > You're asking people to change

Re: [Tutor] random number generator

2007-10-04 Thread Terry Carroll
On Thu, 4 Oct 2007, Jerry VanBrimmer wrote: > I'm no Python wizard, I'm still learning myself. But I think you need > another "if" statement to check if "guess" is equal to "number". > > if guess == number: > print "Congratulations!" No, he's got the equivalent function in his while statemen

Re: [Tutor] random number generator

2007-10-04 Thread Terry Carroll
On Thu, 4 Oct 2007, Jim Hutchinson wrote: > Any idea what I'm doing wrong? > while (guess != number): This is your problem. Like all^h^h^h most numbers in computing, floating point numbers are stored in binary. They only approximate the decimal values they print out as. Two numbers can prin

Re: [Tutor] random number generator

2007-10-04 Thread Jerry VanBrimmer
I'm no Python wizard, I'm still learning myself. But I think you need another "if" statement to check if "guess" is equal to "number". if guess == number: print "Congratulations!" Something like that. On 10/4/07, Jim Hutchinson <[EMAIL PROTECTED]> wrote: > Hello, > > I am writing a little

Re: [Tutor] using python to execute from Dir A in Dir B

2007-10-04 Thread Andre Walker-Loud
Thank you everyone for the help. I have two solutions, but I would love one that uses the subprocess.Popen() - I have no experience with this module.class - if someone with more experience would feel inclined to provide an example, I would be very much appreciative. SOLUTION 1 (my brute for

Re: [Tutor] another quickie

2007-10-04 Thread bhaaluu
On 10/4/07, max baseman <[EMAIL PROTECTED]> wrote: > hello all, im sorry but i might be asking a lot of Tkinter questions > for a bit. > im still working on my first GUI, it is very simple all i want it to > do is open a text file, write to it, than save it. so far i have a > GUI with the ability t

[Tutor] random number generator

2007-10-04 Thread Jim Hutchinson
Hello, I am writing a little program to test a theory and as part of teaching myself Python. I've only been at this about a week now. I have a program that "should" work but doesn't. It generates a random number between 1 and 2 out to 10 decimal places. I think there is something wrong with how my

Re: [Tutor] matching a street address with regular expressions

2007-10-04 Thread Ricardo Aráoz
Christopher Spears wrote: > One of the exercises in Core Python Programming is to > create a regular expression that will match a street > address. Here is one of my attempts. > street = "1180 Bordeaux Drive" patt = "\d+ \w+" import re m = re.match(patt, street) if m is

[Tutor] another quickie

2007-10-04 Thread max baseman
hello all, im sorry but i might be asking a lot of Tkinter questions for a bit. im still working on my first GUI, it is very simple all i want it to do is open a text file, write to it, than save it. so far i have a GUI with the ability to right text (nothing amazing), but i don't know how

Re: [Tutor] using python to execute from Dir A in Dir B

2007-10-04 Thread Alan Gauld
"Andre Walker-Loud" <[EMAIL PROTECTED]> wrote > If I were using CSH, I could do all this very simply by having these > lines in my script > > ### .csh file > > cd /scratch > my_exe.csh The best answer is to use subprocess as Kent suggested but you can also use os.chdir(path) before using os.syste

Re: [Tutor] How to do histogram

2007-10-04 Thread Kent Johnson
Fangwen Lu wrote: > Dear all- > > I want to get a histogram. And I did the following. > from pylab import * > x=(1,1,2,2,2,2,3,4) > hist(x) > > Then I get > (array([2, 0, 0, 4, 0, 0, 1, 0, 0, 1]), array([ 1. , 1.3, 1.6, 1.9, > 2.2, 2.5, 2.8, 3.1, 3.4, 3.7]), ) > > But actually I wan

Re: [Tutor] How to do histogram

2007-10-04 Thread Rikard Bosnjakovic
On 04/10/2007, Fangwen Lu <[EMAIL PROTECTED]> wrote: > What's the problem? We have no idea. Perhaps you could give us some info of what errors the Python-process returns. Things will be easier to help out that way. -- - Rikard - http://bos.hack.org/cv/ _

[Tutor] How to do histogram

2007-10-04 Thread Fangwen Lu
Dear all- I want to get a histogram. And I did the following. from pylab import * x=(1,1,2,2,2,2,3,4) hist(x) Then I get (array([2, 0, 0, 4, 0, 0, 1, 0, 0, 1]), array([ 1. , 1.3, 1.6, 1.9, 2.2, 2.5, 2.8, 3.1, 3.4, 3.7]), ) But actually I want to get a picture. What

Re: [Tutor] using python to execute from Dir A in Dir B

2007-10-04 Thread Tiago Saboga
On Thu, Oct 04, 2007 at 03:15:41PM -0400, Andre Walker-Loud wrote: > what I need to do is have my python script run another executable, > but it must do it from a directory different from the one I am in, it > needs to run in the /scratch/ directory (again not my choice) > > Is this possible,

Re: [Tutor] using python to execute from Dir A in Dir B

2007-10-04 Thread Kent Johnson
Andre Walker-Loud wrote: > Hi All, > > lets say I am in Dir A (out of my control because I have submitted a > job to a queuing system) > > and I have a python script which is running in this directory - the > one I submitted to the queue > > what I need to do is have my python script run ano

[Tutor] using python to execute from Dir A in Dir B

2007-10-04 Thread Andre Walker-Loud
Hi All, lets say I am in Dir A (out of my control because I have submitted a job to a queuing system) and I have a python script which is running in this directory - the one I submitted to the queue what I need to do is have my python script run another executable, but it must do it from a

Re: [Tutor] Timers in Python

2007-10-04 Thread Noufal Ibrahim
Kent Johnson wrote: > Kamal wrote: >> hello everyone, >> >> Is there a method in Python which does what >> setInterval('someFunction()',5000) does in Javascript. >> >> Basically, I want to call functionOne() every x minutes, and wondering >> whats the best way to do it. You can also look at the sc

Re: [Tutor] getting a result from an if condition

2007-10-04 Thread Kent Johnson
Tino Dai wrote: > Hi Everybody, > > I'm having some problems with get an if block to work. > > import re > > regex=re.compile('(some expression)') > > # What I'm trying to get to work > if (m=regex.search('some long string')): > print m.groups() > > - The thing that isn't working is

[Tutor] getting a result from an if condition

2007-10-04 Thread Tino Dai
Hi Everybody, I'm having some problems with get an if block to work. import re regex=re.compile('(some expression)') # What I'm trying to get to work if (m=regex.search('some long string')): print m.groups() - The thing that isn't working is the m=regex in the if line. Is this

Re: [Tutor] Timers in Python

2007-10-04 Thread Rikard Bosnjakovic
On 04/10/2007, Kamal <[EMAIL PROTECTED]> wrote: > Basically, I want to call functionOne() every x minutes, and wondering > whats the best way to do it. If you need to run the functions concurrently, use threads. Else you can setup a simple signal-handler for SIGALRM and set the time accordingly:

Re: [Tutor] Timers in Python

2007-10-04 Thread Kent Johnson
Alan Gauld wrote: > If its within a GUI context then I think both Tkinter and wxPython > have timer facilities although I've never used them. Tkinter: http://www.pythonware.com/library/tkinter/introduction/x9507-alarm-handlers-and-other.htm ___ Tutor ma

Re: [Tutor] Timers in Python

2007-10-04 Thread Kent Johnson
Kamal wrote: > hello everyone, > > Is there a method in Python which does what > setInterval('someFunction()',5000) does in Javascript. > > Basically, I want to call functionOne() every x minutes, and wondering > whats the best way to do it. http://aspn.activestate.com/ASPN/Cookbook/Python/Recip

Re: [Tutor] Timers in Python

2007-10-04 Thread Alan Gauld
"Rob Andrews" <[EMAIL PROTECTED]> wrote >> Is there a method in Python which does what >> setInterval('someFunction()',5000) does in Javascript. >> >> Basically, I want to call functionOne() every x minutes, and >> wondering >> whats the best way to do it. > > Yes, the time module in the standar

Re: [Tutor] Timers in Python

2007-10-04 Thread Rob Andrews
On 10/4/07, Kamal <[EMAIL PROTECTED]> wrote: > Is there a method in Python which does what > setInterval('someFunction()',5000) does in Javascript. > > Basically, I want to call functionOne() every x minutes, and wondering > whats the best way to do it. Yes, the time module in the standard library

Re: [Tutor] matching a street address with regular expressions

2007-10-04 Thread Alan Gauld
"Christopher Spears" <[EMAIL PROTECTED]> wrote > create a regular expression that will match a street > address. Here is one of my attempts. > > Obviously, I can just create a pattern "\d+ \w+ \w+". > However, the pattern would be useless if I had a > street name like 3120 De la Cruz Boulevard

Re: [Tutor] Controlling MS Windows programs?

2007-10-04 Thread Alan Gauld
"Fast Primes" <[EMAIL PROTECTED]> wrote > I am looking for ways to control multiple Windows programs > from Python, such that I can enter data via Python and have > that data passed to an underlying third party program's GUI > screen, ... > Is it possible to come at this in a more straight fo

Re: [Tutor] creating the equivalent of string.strip()

2007-10-04 Thread Alan Gauld
"Christopher Spears" <[EMAIL PROTECTED]> wrote > I decided to post a solution to this problem that uses > regular expressions. > > def my_strip(s): >remove_leading = re.sub(r'^\s+','',s) >remove_trailing = > re.sub(r'\s+$','',remove_leading) >new_s = remove_trailing >return new_s