Curious issue with simple code

2006-09-19 Thread codefire
Hi,

I have some simple code - which works...kind of..here's the code:

[code]
import os

def print_tree(start_dir):
for f in os.listdir(start_dir):
fp = os.path.join(start_dir, f)
print fp
if os.path.isfile(fp): # will return false if use f here!
if os.path.splitext(fp)[1] == '.html':
print 'html file found!'
if os.path.isdir(fp):
print_tree(fp)

print os.path
print_tree(r'c:\intent\docn')
[/code]

As above it all works as expected. However, on the marked line, if I
use f instead of fp then that condition returns false! Surely,
isfile(f) should return true, even if I just give a filename, rather
than the full path? 

If anyway can explain this I'd be grateful,

Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some tips to begin a simple project

2006-09-19 Thread codefire

dutche wrote:

> Now, that I know a bit of Python, I want to make some simple project, I
> thought something like a menu, just like "kxdocks" menu or something
> like that, with transparency and all with xml. But I dont know what
> things I have to know.
>

Start with some simple non-gui apps first. How about a text based
lottery number picker program - you can add a GUI later :)

Writing GUI apps takes a bit of experience - I have done it in other
languages but not Python (yet).

There are several good GUI toolkits TK as mentioned and also wxPython
is worth looking at.

Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curious issue with simple code

2006-09-19 Thread codefire
Ah of course, isfile(f) can only return true if it can find f! :)

I'm going to investigate those other functions too :)

Thanks a lot guys!
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curious issue with simple code

2006-09-19 Thread codefire
George Sakkis wrote:

> By the way, an easier way to deal with paths is the path.py module
> (http://www.jorendorff.com/articles/python/path/). Your example could
> be rewritten simply as:
>
> from path import path
> for html_file in path(start_dir).walkfiles('*.html'):
> print 'html file found!'
>

Thanks George,

I had played with it some more and ended up with the fairly succinct:

[code]
import os
import glob

for f in glob.glob('c:\\intent\\docn\\*\\*.html'):
print f
[/code]

It works quite nicely - I'm just twiddling - first time writing Python
(but like it) :)
I've bookmarked that site too for future ref.

Thanks again,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


I need some help with a regexp please

2006-09-21 Thread codefire
Hi,

I am trying to get a regexp to validate email addresses but can't get
it quite right. The problem is I can't quite find the regexp to deal
with ignoring the case [EMAIL PROTECTED], which is not valid. Here's
my attempt, neither of my regexps work quite how I want:

[code]
import os
import re

s = 'Hi [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] @@not
[EMAIL PROTECTED] partridge in a pear tree'
r = re.compile(r'[EMAIL PROTECTED]@\s]+\.\w+')
#r = re.compile(r'[EMAIL PROTECTED]')

addys = set()
for a in r.findall(s):
addys.add(a)

for a in sorted(addys):
print a
[/code]

This gives:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]   <-- shouldn't be here :(
[EMAIL PROTECTED]

Nearly there but no cigar :)

I can't see the wood for the trees now :) Can anyone suggest a fix
please?

Thanks,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some help with a regexp please

2006-09-21 Thread codefire
Hi,

thanks for the advice guys.

Well took the kids swimming, watched some TV, read your hints and
within a few minutes had this:

r = re.compile(r'[EMAIL PROTECTED]@\s]+\.\w+')

This works for me. That is if you have an invalid email such as
tony..bATblah.com it will reject it (note the double dots).

Anyway, now know a little more about regexps :)

Thanks again for the hints,

Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some help with a regexp please

2006-09-25 Thread codefire
Yes, I didn't make it clear in my original post - the purpose of the
code was to learn something about regexps (I only started coding Python
last week). In terms of learning "a little more" the example was
successful. However, creating a full email validator is way beyond me -
the rules are far too complex!! :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Talking to marketing people about Python

2006-09-25 Thread codefire
Might be handy to point out that the Python version will be easier (and
therefore cheaper) to maintain compared to the Perl version. As someone
said there are numerous success stories at python.org.

You could also point him at :

http://www.tiobe.com/tpci.htm

Although Perl is higher than Python (by one place) you will noticed
that Perl activity is in sharp decline in contrast to Python's steady
growth.

I think Google also gives a pretty big endorsement of Python (as you
wanted the marketing angle).

Cheers,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Surprise using the 'is' operator

2006-09-26 Thread codefire
I thought the 'is' operator was used to identify identical objects,
whereas the '==' operator checked equality. Well, I got a surprise
here:

IDLE 1.1.3
>>> a = 10
>>> b = a
>>> a is b
True
>>> a == b
True
>>> c = 10
>>> a == c
True
>>> a is c
True
>>>

I was NOT expecting the last statement to return True!

What am I missing?

Thanks
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Talking to marketing people about Python

2006-09-26 Thread codefire

Dennis Lee Bieber wrote:

>   Unfortunately, if management goes further down the page, they find
> Ruby and "D" (when did that get out) both rated so many up arrows they
> had to use shorthand notation to represent 14 arrows...

Yes, there is no doubt Ruby is gaining traction - mostly due to the
success of Ruby on Rails. I was in the Ruby community in the very early
days and it was like being in a quiet backwater. As soon as ROR came on
the scene the whole thing just exploded.

I chose Python over Ruby because it has more maturity and stability (in
terms of the product). Python does the job and does it well and is
steadily growing and improving.

D has been around for several years at least. It doesn't really compete
with Python though. But not sure if it would be suitable for the
product mentioned at the start of this thread.

Cheers,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Surprise using the 'is' operator

2006-09-26 Thread codefire
Haha!

OK thanks guys.

I was just trying to check if objects were the same (object), didn't
know Integers were a special case.

Thanks,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


where are isinstance types documented?

2006-09-26 Thread codefire
Hi,

I'm using the isinstance built-in function. I've found the docs for it,
but there are no docs on the supported types.

For example isinstance(a, int) works fine but isinstance(s, string)
doesn't - because 'string is not known'.

I do know how to import the types module and then use defined types
such as 'types.StringType' - but the documentation says that from 2.2
this is not the preferred way.

So, where's the documentation for types I can use with isinstance, such
as 'int'?

Many thanks,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Surprise using the 'is' operator

2006-09-26 Thread codefire
Thanks for that Fredrik, that's clear. That's actually a pretty nice
feature as it's nicely optimised.

>>> a = 10
>>> c = 10
>>> a is c
True
>>> c = c +1
>>> a is c
False
>>> 

Cheers,
Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where are isinstance types documented?

2006-09-26 Thread codefire

OK Simon, thanks for that link, I think I can ferret out the common
types from there. 

Tony

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some help with a regexp please

2006-09-26 Thread codefire
> for dense guys like myself, regular expressions work best if you use
> them as simple tokenizers, and they suck pretty badly if you're trying
> to use them as parsers.

:) Well, I'm with you on that one Fredrik! :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some help with a regexp please

2006-09-26 Thread codefire

> I still don't touch regular expressions... They may be fast, but to
> me they are just as much line noise as PERL... I can usually code a
> partial "parser" faster than try to figure out an RE.

Yes, it seems to me that REs are a bit "hit and miss" - the only way to
tell if you've got a RE "right" is by testing exhaustively - but you
can never be sure They are fine for simple pattern matching though.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does anybody earn a living programming in python?

2006-09-27 Thread codefire

Mike C. Fletcher wrote:
> Job security and easy availability is not the be-all and end-all of
> happiness in life.  That said, if you know anyone who "just wants a
> job", please, push them at Java, someone has to spend the next 30
> years maintaining the Struts and J*EE sites people are putting
> together today in all those big institutions.
> 

Absolutely spot on Mike! :)

Tony

-- 
http://mail.python.org/mailman/listinfo/python-list