Re: [Tutor] Python debugger under Tiger?

2005-05-19 Thread Mike Hall
Great recommendation, thanks.-MHOn May 18, 2005, at 8:12 PM, Lee Cullens wrote:Mike,You may not be looking for a commercial IDE, but I am very happy with  WingIDE and using it with Tiger.Lee COn May 18, 2005, at 6:54 PM, Mike Hall wrote: I should of specified that I'm looking for an IDE with fulldebugging. Basically something like Xcode, but with Python support.On May 18, 2005, at 3:10 PM, [EMAIL PROTECTED] wrote: Quoting Mike Hall [EMAIL PROTECTED]: Does anyone know of a Python debugger that will run under OSX 10.4?The Eric debugger was looked at, but it's highly unstable underTiger. Thanks. pdb should work :-)-- John.___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python debugger under Tiger?

2005-05-18 Thread Mike Hall
Does anyone know of a Python debugger that will run under OSX 10.4? The Eric debugger was looked at, but it's highly unstable under Tiger. Thanks.-MH___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Launching a file browser

2005-03-31 Thread Mike Hall
Ah, so it has to do with access to the window manager. That answers a 
lot, thanks.

On Mar 31, 2005, at 4:09 PM, Max Noel wrote:
On Apr 1, 2005, at 00:14, Mike Hall wrote:
On Mar 31, 2005, at 12:21 AM, Max Noel wrote:
It's been too long since I used Python on MacOSX, but IIRC you 
can't just run a Python GUI program from the shell. Or something 
like that...you should ask this one on the python-mac SIG mailing 
list:
http://www.python.org/sigs/pythonmac-sig/

Kent
	You have to launch your script with pythonw, not with python.
I'm unclear on why a command like webbrowser.open() will comfortably 
launch your default web browser (in my case Safari), but something as 
ubiquitous to an OS as a file browser has special needs to launch. 
Perhaps each application has custom written their file browser, and 
I'm assuming they are each essentially doing system calls to the same 
thing...?
	No, the reason for that, IIRC, is that for the program to be able to 
interact with the window manager, it has to be launched with pythonw. 
When the program starts to display stuff elsewhere than in STDOUT or 
STDERR, an application launch is somehow triggered (icon appears in 
the Dock), which for some reason enables the user to interact with the 
program.
	Launching a web browser requires no interaction whatsoever with the 
WM, and can therefore be done with python.

	Yes, the python/pythonw distinction in Mac OS X is stupid, I'll give 
you that. I don't even know why it exists in the first place.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge 
a perfect, immortal machine?



-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Launching a file browser

2005-03-28 Thread Mike Hall
On Mar 28, 2005, at 4:24 PM, [EMAIL PROTECTED] wrote:
So, you are writing a GUI app and you want some kind of open file 
dialog?  Won't
this depend on what toolkit you are using for your GUI?

If you are using Tkinter (which should work on OS X, I think), try:
import tkFileDialog
f = tkFileDialog.askopenfilename()
Check dir(tkFileDialog) for other functions.
But other GUI toolkits will have their own functions.
I my case the gui will be comprised of html and javascript, talking to 
python through system calls. I basically want to know if there's an 
equivalent of the webbrowser() module (which launches my browser) for 
file dialogs. This is what EasyDialogs should do, but does not.

-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and Javascript

2005-03-25 Thread Mike Hall
I'm curious on whether or not JavaScript and Python can talk to each 
other. Specifically, can a python function be called from within a JS 
function? Admittedly this is probably more of a JavaScript than Python 
question, but I'd  love to know if anyone can at least point me in a 
direction to research this.

-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Javascript

2005-03-25 Thread Mike Hall
Ryan, I should clarify that what I'd like to do here is unrelated to 
the web. I'm actually just interested in using a local html page as a 
simple gui to launch python calls. So a JS event handler, say a button 
click, would then call a JS function which inside of it would call a 
Python function while handing it arguments (say a path that the JS 
queried from a field in the html page.) That kind of thing. It seems 
like it should be possible, and hopefully easy, but I have no 
experience in calling Python functions from other languages so I'm just 
looking for some input on that. Thanks,

-MH
On Mar 25, 2005, at 12:01 PM, Ryan Davis wrote:
Depends on your environment.
If your js is on a webpage, you can have it make http calls to a 
python web service.  Look for articles on XMLHttpRequest in
javascript to see some examples.

I don't know how else that could be done, but I imagine there are 
other ways.

Thanks,
Ryan
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On 
Behalf Of Mike Hall
Sent: Friday, March 25, 2005 2:18 PM
To: tutor@python.org
Subject: [Tutor] Python and Javascript

I'm curious on whether or not JavaScript and Python can talk to each
other. Specifically, can a python function be called from within a JS
function? Admittedly this is probably more of a JavaScript than Python
question, but I'd  love to know if anyone can at least point me in a
direction to research this.
-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Javascript

2005-03-25 Thread Mike Hall
On Mar 25, 2005, at 12:41 PM, Alan Gauld wrote:
If you are using WSH on Windows and have the Python active scripting
installed then yes. Similarly if you use IE as web browser then it
can be done in a web page too.

I'm on OSX, and would be doing this through Safari most likely.
-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Javascript

2005-03-25 Thread Mike Hall
On Mar 25, 2005, at 4:53 PM, Alan Gauld wrote:
intrigued by Dashboard, which will be in the next OSX release. It
allows you to create widgets which are essentially little html
pages
There is an API for Dashboard and I'm pretty sure MacPython will
support it - it covers most of the cocoa type stuff. You might be
better checking out the Apple developer site for the Dashboard
hooks and loooking at MacPythons options.
Alan G.

Alan, thanks for pointing me towards a few good approaches to look at. 
Going through some of the developer information I've come across 
mention of JS extensions which allow for system calls within a JS 
function, which should pretty much do what I want. Thanks,

-MH
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Mike Hall

Liam, rU worked like a charm. My previous syntax where the lines were condensing was:

fOpen = file(f, r)
fRead = fTmp.readlines()

In this instance the size of fRead would not correspond to my line numbers. With  fOpen = file(f, rU) it now does. Thanks :) 


On Mar 22, 2005, at 7:15 PM, Liam Clarke wrote:

From the docs - 

In addition to the standard fopen() values mode  may be 'U' or 'rU'.
If Python is built with universal newline support (the default) the
file is opened as a text file, but lines may be terminated by any of
'\n', the Unix end-of-line convention, '\r', the Macintosh convention
or '\r\n', the Windows convention. All of these external
representations are seen as '\n'  by the Python program. If Python is
built without universal newline support mode 'U' is the same as normal
text mode. Note that file objects so opened also have an attribute
called newlines which has a value of None (if no newlines have yet
been seen), '\n', '\r', '\r\n', or a tuple containing all the newline
types seen.


So, try 

x = file(myFile, 'rU').readlines()

Or try:

x = file(myFile, 'rU')
for line in x:
#do stuff

Let us know how that goes. 

Regards, 

Liam Clarke

PS 

Worse come to worse, you could always do - 
x = file(myFile, 'r').read()
listX = x.split('\r')



On Tue, 22 Mar 2005 17:10:43 -0800, Mike Hall
[EMAIL PROTECTED]> wrote:
Unless I'm mistaken .readlines() is supposed to return a list, where
each index is a line from the file that was handed to it. Well I'm
finding that it's putting more than one line of my file into a single
list entry, and separating them with \r. Surely there's a way to have a
one to one correlation between len(list) and the lines in the file the
list was derived from...?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Mike Hall
On Mar 23, 2005, at 3:17 AM, Kent Johnson wrote:
Anyway, Mike, it seems clear that your file has line endings in it 
which are not consistent with the default for your OS. If reading with 
universal newlines doesn't solve the problem, please let us know what 
OS you are running under and give more details about the data.
Kent, reading universal did indeed solve my problem, but for the record 
I'm on OSX, and was reading from a standard plain text file.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] .readlines() condensing multiple lines

2005-03-22 Thread Mike Hall
Unless I'm mistaken .readlines() is supposed to return a list, where 
each index is a line from the file that was handed to it. Well I'm 
finding that it's putting more than one line of my file into a single 
list entry, and separating them with \r. Surely there's a way to have a 
one to one correlation between len(list) and the lines in the file the 
list was derived from...? 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-18 Thread Mike Hall
On Mar 18, 2005, at 1:02 PM, Christopher Weimann wrote:
On 03/18/2005-10:35AM, Mike Hall wrote:
A caret as the first charachter in a class is a negation.
So this [^\s]+ means match one or more of any char that
isn't whitespace.
Ok, so the context of metas change within a class. That makes sense,
but I'm unclear on the discrepancy below.
The ^ means begining of line EXCEPT inside a charachter class. There it
means NOT for the entire class and it only means that if it is the very
first charachter. I suppose you could consider that the there are two
separate types of char classes. One is started with [ and the other is
started with [^.
Got it, thanks.


That would be \
Here's where I'm confused. From the Python docs:
Special characters are not active inside sets. For example, [akm$] 
will
match any of the characters a, k, m, or $

And the next paragraphs says...
  You can match the characters not within a range by complementing the
  set. This is indicated by including a ^ as the first character of 
the
  class; ^ elsewhere will simply match the ^ character. For 
example,
  [^5] will match any character except 5.


The sad thing is I have read that paragraph before (but obviously 
hadn't absorbed the significance). I'm new to this, it'll sink in. 
Thanks.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
applause Very nice sir. I'm interested in what you're doing here with 
the caret metacharacter. For one thing, why enclose it and the 
whitespace flag within a character class? Does this not traditionally 
mean you want to strip a metacharacter of it's special meaning?

On Mar 16, 2005, at 8:00 PM, Christopher Weimann wrote:
On 03/16/2005-12:12PM, Mike Hall wrote:
I'm having trouble getting re to stop matching after it's consumed
what I want it to.  Using this string as an example, the goal is to
match CAPS:
s = only the word in CAPS should be matched

jet% python
Python 2.4 (#2, Jan  5 2005, 15:59:52)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type help, copyright, credits or license for more information.
import re
s = only the word in CAPS should be matched
x=re.compile(r\bin ([^\s]+))
x.findall(s)
['CAPS']


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote:
in (.*?)\b will match against in  because you use .* which will 
match an empty string. Try in (.+?)\b (or (?=\bin)..+?\b )to 
require one character after the space.

Another working example, excellent. I'm not too clear on why the back 
to back .. in (?=\bin)..+?\b ) makes the regex work, but it does.

You can't import it, you have to run it from the command line. I don't 
know if it is installed under Mac OSX though. You might be interested 
in RegexPlor:
http://python.net/~gherman/RegexPlor.html

RegexPlor looks fantastic, will be downloading. Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
I don't have that script on my system, but I may put pythoncard on here 
and run it through that:

http://pythoncard.sourceforge.net/samples/redemo.html
Although regexPlor looks like it has the same functionality, so I may 
just go with that. Thanks.

On Mar 17, 2005, at 1:31 AM, Michael Dunn wrote:
As Kent said, redemo.py is a script that you run (e.g. from the
command line), rather than something to import into the python
interpretor. On my OSX machine it's located in the directory:
/Applications/MacPython-2.3/Extras/Tools/scripts
Cheers, Michael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote:
The first one matches the space after 'in'. Without it the .+? will 
match the single space, then \b matches the *start* of the next word.
I think I understand. Basically the first dot advances the pattern 
forward in order to perform a non-greedy match on the following 
word.(?) Very nice.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
I'm having trouble getting re to stop matching after it's consumed what I want it to.  Using this string as an example, the goal is to match CAPS:

>>> s = only the word in CAPS should be matched

So let's say I want to specify when to begin my pattern by using a lookbehind:

>>> x = re.compile(r(?=\bin)) #this will simply match the spot in front of in

So that's straight forward, but let's say I don't want to use a lookahead to specify the end of my pattern, I simply want it to stop after it has combed over the word following in. I would expect this to work, but it doesn't:

>>> x=re.compile(r(?=\bin).+\b) #this will consume everything past in all the way to the end of the string

In the above example I would think that the word boundary flag \b would indicate a stopping point. Is .+\b not saying, keep matching characters until a word boundary has been reached?

Even stranger are the results I get from:

>>> x=re.compile(r(?=\bin).+\s) #keep matching characters until a whitespace has been reached(?)
>>> r = x.sub([EMAIL PROTECTED], s)
>>> print r
only the word [EMAIL PROTECTED]

For some reason there it's decided to consume three words instead of one. 

My question is simply this:  after specifying a start point,  how do I make a match stop after it has found one word, and one word only? As always, all help is appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
Liam, re.compile(in (.*?)\b) will not find any match in the example 
string I provided. I have had little luck with these non-greedy 
matchers.

I don't appear to have redemo.py on my system (on OSX), as an import 
returns an error. I will look into finding this module, thanks for 
pointing me towards it :)

On Mar 16, 2005, at 2:36 PM, Liam Clarke wrote:
x=re.compile(r(?=\bin).+\b)
Try
x = re.compile(in (.*?)\b)
.*? is a non-greedy matcher I believe.
Are you using python24/tools/scripts/redemo.py? Use that to test 
regexes.

Regards,
Liam Clarke
On Wed, 16 Mar 2005 12:12:32 -0800, Mike Hall
[EMAIL PROTECTED] wrote:
I'm having trouble getting re to stop matching after it's consumed 
what
I want it to.  Using this string as an example, the goal is to match
CAPS:

s = only the word in CAPS should be matched
So let's say I want to specify when to begin my pattern by using a
lookbehind:
x = re.compile(r(?=\bin)) #this will simply match the spot in
front of in
So that's straight forward, but let's say I don't want to use a
lookahead to specify the end of my pattern, I simply want it to stop
after it has combed over the word following in. I would expect this
to work, but it doesn't:
x=re.compile(r(?=\bin).+\b) #this will consume everything past
in all the way to the end of the string
In the above example I would think that the word boundary flag \b
would indicate a stopping point. Is .+\b not saying, keep matching
characters until a word boundary has been reached?
Even stranger are the results I get from:
x=re.compile(r(?=\bin).+\s) #keep matching characters until a
whitespace has been reached(?)
r = x.sub([EMAIL PROTECTED], s)
print r
only the word [EMAIL PROTECTED]
For some reason there it's decided to consume three words instead of
one.
My question is simply this:  after specifying a start point,  how do I
make a match stop after it has found one word, and one word only? As
always, all help is appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


--
'There is only one basic human right, and that is to do as you damn 
well please.
And with it comes the only basic human duty, to take the consequences.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
On Mar 16, 2005, at 5:32 PM, Sean Perry wrote:
I know this does not directly help, but I have never successfully used 
\b in my regexs. I always end up writing something like foo\s+bar or 
something more intense.
I've had luck with the boundary flag in relation to lookbehinds. For 
example, if I wanted to only match after int (and not print) 
(?=\bint) seems to work fine. I'm a bit frustrated at not being able 
to find a simple way to have a  search stop after eating up one word. 
You'd think the \b would do it, but nope.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
But I only want to ignore B if A is a match. If A is not a match, 
I'd like it to advance on to B.

On Mar 9, 2005, at 12:07 PM, Marcos Mendonça wrote:
Hi
Not and regexp expert. But it seems to me that if you want to ignora
B then it should be
(A) | (^B)
Hope it helps!
On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall
[EMAIL PROTECTED] wrote:
I'm having some strange results using the or operator.  In every 
test
I do I'm matching both sides of the | metacharacter, not one or the
other as all documentation says it should be (the parser supposedly
scans left to right, using the first match it finds and ignoring the
rest). It should only go beyond the | if there was no match found
before it, no?

Correct me if I'm wrong, but your regex is saying match dog, unless
it's followed by cat. if it is followed by cat there is no match on
this side of the | at which point we advance past it and look at the
alternative expression which says to match in front of cat.
However, if I run a .sub using your regex on a string contain both dog
and cat, both will be replaced.
A simple example will show what I mean:
import re
x = re.compile(r(A) | (B))
s = X R A Y B E
r = x.sub(13, s)
print r
X R 13Y13 E
...so unless I'm understanding it wrong, B is supposed to be ignored
if A is matched, yet I get both matched.  I get the same result if I
put A and B within the same group.
On Mar 8, 2005, at 6:47 PM, Danny Yoo wrote:

Regular expressions are a little evil at times; here's what I think
you're
thinking of:
###
import re
pattern = re.compile(rdog(?!cat)
...| (?=dogcat), re.VERBOSE)
pattern.match('dogman').start()
0
pattern.search('dogcatcher').start()

Hi Mike,
Gaaah, bad copy-and-paste.  The example with 'dogcatcher' actually 
does
come up with a result:

###
pattern.search('dogcatcher').start()
6
###
Sorry about that!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
but yeah, it
seems you're expecting it to examine the string as a whole.
I guess I was, good point.

On Mar 9, 2005, at 12:28 PM, Liam Clarke wrote:
Actually, you should get that anyway...

|
Alternation, or the ``or'' operator. If A and B are regular
expressions, A|B will match any string that matches either A or B.
| has very low precedence in order to make it work reasonably when
you're alternating multi-character strings. Crow|Servo will match
either Crow or Servo, not Cro, a w or an S, and ervo.

So, for each letter in that string, it's checking to see if any letter
matches 'A' or 'B' ...
the engine steps through one character at a time.
sorta like -
for letter in s:
 if letter == 'A':
#Do some string stuff
 elif letter == 'B':
#do some string stuff
i.e.
k = ['A','B', 'C', 'B']
for i in range(len(k)):
if k[i] == 'A' or k[i]=='B':
   k[i]==13
print k
[13, 13, 'C', 13]
You can limit substitutions using an optional argument, but yeah, it
seems you're expecting it to examine the string as a whole.
Check out the example here -
http://www.amk.ca/python/howto/regex/ 
regex.html#SECTION00032

Also
http://www.regular-expressions.info/alternation.html
Regards,
Liam Clarke
On Thu, 10 Mar 2005 09:09:13 +1300, Liam Clarke [EMAIL PROTECTED]  
wrote:
Hi Mike,
Do you get the same results for a search pattern of 'A|B'?
On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall
[EMAIL PROTECTED] wrote:
I'm having some strange results using the or operator.  In every  
test
I do I'm matching both sides of the | metacharacter, not one or the
other as all documentation says it should be (the parser supposedly
scans left to right, using the first match it finds and ignoring the
rest). It should only go beyond the | if there was no match found
before it, no?

Correct me if I'm wrong, but your regex is saying match dog, unless
it's followed by cat. if it is followed by cat there is no match on
this side of the | at which point we advance past it and look at  
the
alternative expression which says to match in front of cat.

However, if I run a .sub using your regex on a string contain both  
dog
and cat, both will be replaced.

A simple example will show what I mean:
import re
x = re.compile(r(A) | (B))
s = X R A Y B E
r = x.sub(13, s)
print r
X R 13Y13 E
...so unless I'm understanding it wrong, B is supposed to be  
ignored
if A is matched, yet I get both matched.  I get the same result if  
I
put A and B within the same group.

On Mar 8, 2005, at 6:47 PM, Danny Yoo wrote:

Regular expressions are a little evil at times; here's what I think
you're
thinking of:
###
import re
pattern = re.compile(rdog(?!cat)
...| (?=dogcat), re.VERBOSE)
pattern.match('dogman').start()
0
pattern.search('dogcatcher').start()

Hi Mike,
Gaaah, bad copy-and-paste.  The example with 'dogcatcher' actually  
does
come up with a result:

###
pattern.search('dogcatcher').start()
6
###
Sorry about that!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
--
'There is only one basic human right, and that is to do as you damn  
well please.
And with it comes the only basic human duty, to take the consequences.


--
'There is only one basic human right, and that is to do as you damn  
well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regular expression question

2005-03-08 Thread Mike Hall
I'd like to get a match for a position in a string preceded by a specified word (let's call it Dog), unless that spot in the string (after Dog) is directly followed by a specific word(let's say Cat), in which case I want my match to occur directly after Cat, and not Dog.

I can easily get the spot after Dog, and I can also get it to ignore this spot if Dog is followed by Cat. But what I'm having trouble with is how to match the spot after Cat if this word does indeed exist in the string.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

2005-03-08 Thread Mike Hall
First, thanks for the response. Using your re:
my_re = re.compile(r'(dog)(cat)?')
...I seem to simply be matching the pattern Dog.  Example:
 str1 = The dog chased the car
 str2 = The dog cat parade was under way
 x1 = re.compile(r'(dog)(cat)?')
 rep1 = x1.sub(REPLACE, str1)
 rep2 = x2.sub(REPLACE, str2)
 print rep1
The REPLACE chased the car
 print rep2
The REPLACE cat parade was under way
...what I'm looking for is a match for the position in front of Cat, 
should it exist.


On Mar 8, 2005, at 5:54 PM, Sean Perry wrote:
Mike Hall wrote:
I'd like to get a match for a position in a string preceded by a 
specified word (let's call it Dog), unless that spot in the string 
(after Dog) is directly followed by a specific word(let's say 
Cat), in which case I want my match to occur directly after Cat, 
and not Dog.
I can easily get the spot after Dog, and I can also get it to 
ignore this spot if Dog is followed by Cat. But what I'm having 
trouble with is how to match the spot after Cat if this word does 
indeed exist in the string.
.  import re
.  my_re = re.compile(r'(dog)(cat)?') # the ? means find one or 
zero of these, in other words cat is optional.
.  m = my_re.search(This is a nice dog is it not?)
.  dir(m)
['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict', 
'groups', 'span', 'start']
.  m.span()
(15, 18)
.  m = my_re.search(This is a nice dogcat is it not?)
.  m.span()
(15, 21)

If m is None then no match was found. span returns the locations in 
the string where the match occured. So in the dogcat sentence the last 
char is 21.

.  This is a nice dogcat is it not?[21:]
' is it not?'
Hope that helps.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

2005-03-08 Thread Mike Hall
This will match the position in front of dog:
(?=dog)
This will match the position in front of cat:
(?=cat)
This will not match in front of dog if dog is followed by cat:
(?=dog)\b (?!cat)
Now my question is how to get this:
(?=cat)
...but ONLY if cat is following dog. If dog does not have cat  
following it, then I simply want this:

(?=dog)

...if that makes sense :) thanks.

On Mar 8, 2005, at 6:05 PM, Danny Yoo wrote:

On Tue, 8 Mar 2005, Mike Hall wrote:
I'd like to get a match for a position in a string preceded by a
specified word (let's call it Dog), unless that spot in the string
(after Dog) is directly followed by a specific word(let's say  
Cat),
in which case I want my match to occur directly after Cat, and not
Dog.
Hi Mike,
You may want to look at lookahead assertions.  These are patterns of  
the
form '(?=...)' or '(?!...).  The documentation mentions them here:

   http://www.python.org/doc/lib/re-syntax.html
and AMK's excellent Regular Expression HOWTO covers how one might use
them:
http://www.amk.ca/python/howto/regex/ 
regex.html#SECTION00054

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] newbie OSX module path question

2005-02-14 Thread Mike Hall
I'm on OS X, and I cannot get Python to import modules I've saved. I 
have created the the environment.plist file and appended it with my 
desired module path. If I print sys.path from the interpreter, my new 
path does indeed show up as the first listing, yet any attempt at 
importing modules from this directory fails with ImportError. What am I 
doing wrong?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie OSX module path question

2005-02-14 Thread Mike Hall
Hm, so if I import glob, and then execute this line:
print glob.glob('/Local_HD/Users/mike/Documents/pythonModules/*.py')
I simply get brackets returned:
[]
...not sure what this means. Thanks again.


On Feb 14, 2005, at 5:41 PM, Danny Yoo wrote:

On Mon, 14 Feb 2005, Mike Hall wrote:
Can you show us what your sys.path looks like?  Just do a
cut-and-paste so we can quickly validate it for you.
Thanks for the response. Here's a paste of what sys.path returns. The
first listing is the path inside of environment.plist:
['', '/Local_HD/Users/mike/Documents/pythonModules',
'/Users/tempmike/Documents/pythonModules',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python23.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages']
Can you show us the exact thing you're typing, as well as the literal
error that Python shows?
I will attempt to import using 'import' followed by file name. 
Example:

import module1
The error returned will be:
ImportError: No module named module1

[Meta: Please keep python-tutor in CC, so that all of us on the mailing
list can help you.]
Hi Mike,
Ok, can you do this at the Python prompt?
###
import glob
print glob.glob('/Local_HD/Users/mike/Documents/pythonModules/*.py')
###
Copy and paste the output you see.
If things go wrong, then we will have a good focus point to debug the
problem.  But if things go right --- if you see a bunch of Python 
module
files --- then I will be stuck and will have to think of something 
else.
*grin*


Do you have problems doing an import if your modules's directory is
the current working directory?
Funny you should mention that. After posting to this list, I tried
cd'ing over to the dir I created for modules, and then launched 
Python.
My modules can indeed be imported using this method.  But I'm still
curious as to why I cannot get a successful import (when I'm not 
within
my work dir) when the path is visibly defined within the sys.path
variable? Thanks very much.
Ok, so there appears to be nothing wrong with the modules themselves or
with importing them when they're in the current working directory. We
should then focus on sys.path itself, since that's the mechanism Python
uses to lookup modules that aren't in the current directory.
For the moment, I'll assume that there's something funky with the
pathname.  As mentioned earlier, it could be as subtle as a
case-sensitivity issue.  The glob statement above will help us check to
see if Python can see those files, at least.
Best of wishes to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie OSX module path question

2005-02-14 Thread Mike Hall
Ok, I've got it working. The environment.plist file wants a path 
beginning with /Users, not /Local_HD. So simple!  Thanks everyone.

On Feb 14, 2005, at 6:26 PM, David Rock wrote:
* Mike Hall [EMAIL PROTECTED] [2005-02-14 18:22]:
Hm, so if I import glob, and then execute this line:
print glob.glob('/Local_HD/Users/mike/Documents/pythonModules/*.py')
I simply get brackets returned:
[]
...not sure what this means. Thanks again.
It means it didn't find anything that matches that pattern, which
suggests that the directory does not contain *.py files. That might be 
a
problem. ;-)

--
David Rock
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor