Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Dick Moores
At 10:08 AM 8/2/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote BTW Kent, I'm going to take this opportunity to ask you about "System" in the IPython timing results. It's always zero for the code I time. What's an example of code that would have System be greater than zero? An

Re: [Tutor] locks and threads

2008-08-02 Thread Kent Johnson
On Sat, Aug 2, 2008 at 2:36 PM, James <[EMAIL PROTECTED]> wrote: > All, > > I'm trying to write a class that will acquire a lock before entering a > critical section, and then release it. Does this look like the right > way to go about accomplishing my goal? > > try: > grabLock = self.lock.acquire(

Re: [Tutor] Firstrade URL Authentication?

2008-08-02 Thread Kent Johnson
On Sat, Aug 2, 2008 at 11:17 AM, Federo <[EMAIL PROTECTED]> wrote: > There must be some sofisticated trick to login to www.Firstrade.com. Any Idea > what else can I try? You have to find out what it does in the browser using Firebug or other tools that will let you see the headers and data. Perhap

[Tutor] Firstrade URL Authentication?

2008-08-02 Thread Federo
Hi Kent Thanks for your reply. According to your instruction I have tried in Python interactive window the following (in my test I have used real username and password): >>> import urllib2 >>> import urllib >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) >>> urllib2.install_ope

[Tutor] Developing Macro: Is it possible in Python?

2008-08-02 Thread Federo
Hi Is it possible to do macro with Python? Macro should be able to click on given x,y screen location (one click, double click), drag scroll bar up / down etc.. Macro should be also able to extract data from predefined screen x,y location. I would use this to control desktop windows based progr

Re: [Tutor] Output never stops

2008-08-02 Thread Vivek Sant
Hi David, Simple explanation - you should use if instead of while. A while statement executes whatever is in that block again and again until the condition becomes false. So your code, the way you have it, first checks if the user's input is not -1. If you have typed Lary, it goes on to p

Re: [Tutor] Output never stops

2008-08-02 Thread David
David wrote: Very new to python and never programed before. Can not figure out why the output never stops when I run this in a terminal #!/usr/bin/python choice = raw_input("Enter the name Lary or Joan (-1 to quit): ") while choice != '-1': person = {'Lary': 43,'Joan': 24} if choi

[Tutor] Output never stops

2008-08-02 Thread David
Very new to python and never programed before. Can not figure out why the output never stops when I run this in a terminal #!/usr/bin/python choice = raw_input("Enter the name Lary or Joan (-1 to quit): ") while choice != '-1': person = {'Lary': 43,'Joan': 24} if choice == 'Lary':

Re: [Tutor] Classes in separate files

2008-08-02 Thread Alan Gauld
"James" <[EMAIL PROTECTED]> wrote Another question on classes in separate files... It could just as well be about functions. The issue is about visibility of names not classes. main.py instantiates a class called 'testClass' inside of a file temp.py. In main.py: t = temp.testClass() ...

Re: [Tutor] Why use lambda?

2008-08-02 Thread Alan Gauld
"bob gailer" <[EMAIL PROTECTED]> wrote In my Python Pipelines program for the Count stage I have: opts = { 'characters' : lambda rec, tot: tot + len(rec), 'words' : lambda rec, tot: tot + len(rec.split()), 'lines' : lambda rec, tot: tot + 1, 'minline' :lambda rec, tot: min(le

Re: [Tutor] Why use lambda?

2008-08-02 Thread bob gailer
desmond mansfield wrote: I've read some small tutorials on lambda, and how I can use it to define functions "on-the-fly". But what I don't understand, and cannot seem to find an answer to, is why I'd actually want to use it ? What can lambda do that normal function definitions cannot? Is it qu

Re: [Tutor] removing whole numbers from text

2008-08-02 Thread Benoit Thiell
Dear Dinesh, if you're using the regular expression only once, I would recommend: without_numbers = " ".join(re.split(" [0-9]+ ", phrase)) If not, compile the regular expression first and use the compiled version. Regards, Benoit Thiell. On Sat, 2 Aug 2008, Noufal Ibrahim wrote: Alan Gauld w

[Tutor] locks and threads

2008-08-02 Thread James
All, I'm trying to write a class that will acquire a lock before entering a critical section, and then release it. Does this look like the right way to go about accomplishing my goal? try: grabLock = self.lock.acquire( 0 ) if grabLock: print 'acquired lock successfully'

Re: [Tutor] removing whole numbers from text

2008-08-02 Thread Noufal Ibrahim
Alan Gauld wrote: "Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote I want to remove whole numbers from text but retain numbers attached to words. Is this a homework? If so we can only offer suggestions to direction but not give solutions. What is the best to do this using re? Yes, use re to d

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote BTW Kent, I'm going to take this opportunity to ask you about "System" in the IPython timing results. It's always zero for the code I time. What's an example of code that would have System be greater than zero? And what's the distinction between User and

Re: [Tutor] removing whole numbers from text

2008-08-02 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote I want to remove whole numbers from text but retain numbers attached to words. Is this a homework? If so we can only offer suggestions to direction but not give solutions. What is the best to do this using re? Yes, use re to define a pattern t

Re: [Tutor] Why use lambda?

2008-08-02 Thread Alan Gauld
"desmond mansfield" <[EMAIL PROTECTED]> wrote But what I don't understand, and cannot seem to find an answer to, is why I'd actually want to use it ? Its a matter of taste. There is nothing you can do with lambda that you cannot do with a function definition. But you might need an awful lot o

Re: [Tutor] Classes in separate files

2008-08-02 Thread Alan Gauld
"James" <[EMAIL PROTECTED]> wrote The issue is, however, that I'm not sure the "best" way to pass things into classes, and the "best" way to get something back. In an OOP syustem you don;t normally have to pass a lot into a method since most of the data should be internal to the object Often

Re: [Tutor] Why use lambda?

2008-08-02 Thread Danny Yoo
> What can lambda do that normal function definitions cannot? > Is it quicker to execute/less memory intensive? > Or is it just quicker to type and easier to think about? Notational convenience. Think about how, in arithmetic expressions, how we're not forced to give explicit names to all the sub

[Tutor] removing whole numbers from text

2008-08-02 Thread Dinesh B Vadhia
I want to remove whole numbers from text but retain numbers attached to words. All whole numbers to be removed have a leading and trailing space. For example, in "the cow jumped-20 feet high30er than the lazy 20 timing fox who couldn't keep up the 865 meter race." remove the whole numbers 20 an

Re: [Tutor] Why use lambda?

2008-08-02 Thread Shrutarshi Basu
>From what I've seen, Lambda is most useful if you're passing functions as arguments to other functions. You could use lambda to create a function on-the-fly, as you've said, and that will save you the trouble of having to write it separately. Try looking for examples on functional programming in P

Re: [Tutor] Classes in separate files

2008-08-02 Thread James
Another question on classes in separate files... main.py instantiates a class called 'testClass' inside of a file temp.py. In main.py: t = temp.testClass() So now I can access some of the variables inside of 't'. For example, let's say that in main.py, I do the following: # get a variable fr

[Tutor] Why use lambda?

2008-08-02 Thread desmond mansfield
I've read some small tutorials on lambda, and how I can use it to define functions "on-the-fly". But what I don't understand, and cannot seem to find an answer to, is why I'd actually want to use it ? What can lambda do that normal function definitions cannot? Is it quicker to execute/less memo

[Tutor] Classes in separate files

2008-08-02 Thread James
All, I've started tinkering (just a little) with classes, primarily because I have to. (I've never been a huge fan of OOP, but can tolerate it when used properly). I'll be the first to admit that I don't know much about how to program "correctly" when dealing with objects, however, so any thought

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Dick Moores
At 05:02 AM 8/2/2008, Kent Johnson wrote: On Sat, Aug 2, 2008 at 6:07 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm pretty new to Python's dictionaries, but I had a need for a function > that would find the values in a dict that have more than one key each. From your sample output it appears

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Kent Johnson
On Sat, Aug 2, 2008 at 6:07 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm pretty new to Python's dictionaries, but I had a need for a function > that would find the values in a dict that have more than one key each. >From your sample output it appears that you want not just the values, but a li

Re: [Tutor] Scan Directory for files

2008-08-02 Thread Kent Johnson
On Sat, Aug 2, 2008 at 1:41 AM, Fred @ Mac <[EMAIL PROTECTED]> wrote: > Hello, > > new to python, so please go easy on me! > > I am using > > for f in os.listdir(watch_dir): >tree = ET.parse(f) Should be ET.parse(os.path.join(watch_dir, f)) I think... >for shot in tree.findall('Sh

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Dick Moores
At 03:49 AM 8/2/2008, Dick Moores wrote: At 03:27 AM 8/2/2008, Andre Engels wrote: Content-Transfer-Encoding: base64Content-Disposition: inlineOn Sat, Aug 2, 2008 at 11:07 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm pretty new to Python's dictionaries, but I had a need for a function > th

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Dick Moores
At 03:27 AM 8/2/2008, Andre Engels wrote: Content-Transfer-Encoding: base64Content-Disposition: inlineOn Sat, Aug 2, 2008 at 11:07 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm pretty new to Python's dictionaries, but I had a need for a function > that would find the values in a dict that ha

Re: [Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Andre Engels
On Sat, Aug 2, 2008 at 11:07 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > I'm pretty new to Python's dictionaries, but I had a need for a function > that would find the values in a dict that have more than one key each. It > took me several hours to write. See >

[Tutor] I can't believe this needs to be this complex

2008-08-02 Thread Dick Moores
I'm pretty new to Python's dictionaries, but I had a need for a function that would find the values in a dict that have more than one key each. It took me several hours to write. See . Seems to do the job, both with the example shown, and with the dict

Re: [Tutor] Scan Directory for files

2008-08-02 Thread Alan Gauld
"Fred @ Mac" <[EMAIL PROTECTED]> wrote for f in os.listdir(watch_dir): tree = ET.parse(f) for shot in tree.findall('Shot'): ..do stuff.. But my script fails if, for example, a directory also exists in "watch_dir" Take a look at os.walk which allows recursive traversal of

Re: [Tutor] Scan Directory for files

2008-08-02 Thread Steve Poe
Fred, What is/are the exact error message(s)? You may want to look at the module glob. Steve Ar e you typing this in the python interpreter or On Aug 1, 2008, at 10:41 PM, Fred @ Mac wrote: Hello, new to python, so please go easy on me! I am using for f in os.listdir(watch_dir):