Re: best python unit testing framwork

2008-11-12 Thread Timothy Grant
On Tue, Nov 11, 2008 at 2:59 PM, Brendan Miller [EMAIL PROTECTED] wrote:
 What would heavy python unit testers say is the best framework?

 I've seen a few mentions that maybe the built in unittest framework
 isn't that great. I've heard a couple of good things about py.test and
 nose. Are there other options? Is there any kind of concensus about
 the best, or at least how they stack up to each other?

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


I wanted to like unittest but couldn't. So I started using py.test. I
even wrote a plugin for TextMate to interface with py.test. If I had
known about Nose I would likely have used it instead because it is
built on top of the standard module. Now I have many thousands of
lines of py.test code so am not likely to make the change.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: best python unit testing framwork

2008-11-12 Thread Timothy Grant
On Wed, Nov 12, 2008 at 5:16 PM, Roy Smith [EMAIL PROTECTED] wrote:
 In article [EMAIL PROTECTED],
  Timothy Grant [EMAIL PROTECTED] wrote:

 I wanted to like unittest but couldn't. So I started using py.test. I
 even wrote a plugin for TextMate to interface with py.test. If I had
 known about Nose I would likely have used it instead because it is
 built on top of the standard module. Now I have many thousands of
 lines of py.test code so am not likely to make the change.

 A lot of people like or dislike various unit test frameworks for all sorts
 of reasons.  But, the bottom line is still that the best unit test
 framework is the one which gets you to use it every time you write a line
 of code.
 --
 http://mail.python.org/mailman/listinfo/python-list


When I first learned about Unit Testing seven years ago, I thought to
myself what a colossal waste of time. Now if I don't have tests I
really start to worry. I am a write the tests first kind-of-guy, and
my code and my ability to maintain my code have both improved
dramatically.


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: chomp?

2008-10-17 Thread Timothy Grant
On Fri, Oct 17, 2008 at 3:37 PM, Matt Herzog [EMAIL PROTECTED] wrote:
 Hey Pythons.

 This script works fine except I would like it to NOT print everything on a 
 newline.
 How can I tell print to chomp?

 Thanks.

 --- snip 
 -
 #!/usr/bin/python
 import time
 import sys

 def getload():
f = open('/proc/loadavg')
data = f.readline()
f.close()
(load1, load2, load3, extra) = data.split(' ',3)
return float(load1)

 done = False
 while not done:
while getload()  3:
print getload()
time.sleep(3)

# we left the loop!
print Ouch! My CPUs are roasting!
time.sleep(3)

 --
 'My country, right or wrong,' is a thing that no patriot would think of 
 saying. It is like saying, 'My mother, drunk or sober.'

 -- G.K. Chesterton
 --
 http://mail.python.org/mailman/listinfo/python-list



a ',' on the end of your print should suppress the newline.

 def x():
...print 'foo',
...print 'bar'
...
 x()
foo bar

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Selecting random elements from a list.

2008-10-13 Thread Timothy Grant
On Mon, Oct 13, 2008 at 2:29 PM, aditya shukla
[EMAIL PROTECTED] wrote:
 Hello folks,

 i have a list say list1=[a,b,c,...z] ie 26 elements i have to take 5
 elements from it randomly and save in another list.Please explain how to do
 this?


 Aditya

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




I would start here http://docs.python.org/library/random.html  you are
likely interested in choice or sample.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to set the time of a directory?

2008-10-10 Thread Timothy Grant
On Fri, Oct 10, 2008 at 10:16 PM, oyster [EMAIL PROTECTED] wrote:
 os.utime works only against files. so what to do for a directory?
 thanx

Not sure why you'd say that.

drwxr-xr-x  2 tjg  tjg   68 Oct 10 22:23 test
([EMAIL PROTECTED]) python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 import os
 help(os.utime)
Help on built-in function utime in module posix:

utime(...)
utime(path, (atime, mtime))
utime(path, None)

Set the access and modified time of the file to the given values.  If the
second form is used, set the access and modified times to the current time.

 os.utime('test', None)
 ^D
([EMAIL PROTECTED]) ls -ltr
drwxr-xr-x  2 tjg  tjg   68 Oct 10 22:24 test


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find the directory where python is installed ?

2008-10-02 Thread Timothy Grant
On Thu, Oct 2, 2008 at 12:16 PM, Stef Mientki [EMAIL PROTECTED] wrote:
 hello,

 how can I determine the location of the Python installation under winXP /
 Linux,
 with a Python program ?

 thanks,
 Stef Mientki

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


This what you're looking for?

([EMAIL PROTECTED]) python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 import sys
 sys.executable
'/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python'
 sys.path
['', '/Library/Python/2.5/site-packages/enum-0.4.3-py2.5.egg',
'/Library/Python/2.5/site-packages/mechanize-0.1.8-py2.5.egg',
'/Library/Python/2.5/site-packages/ClientForm-0.2.9-py2.5.egg',
'/Users/tjg/code/libs', '/Users/tjg/code/py-dist',
'/usr/local/lib/wxPython-unicode-2.8.8.0/lib/python2.5/site-packages',
'/usr/local/lib/wxPython-unicode-2.8.8.0/lib/python2.5/site-packages/wx-2.8-mac-unicode',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload',
'/Library/Python/2.5/site-packages',
'/usr/local/lib/wxPython-unicode-2.8.8.0/lib/python2.5',
'/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC']




-- 
Stand Fast,
tjg.  [Timothy Grant]

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


Re: PLEASE HELP ME WITH THIS ASSIGNMENT...PLEASE....

2008-09-11 Thread Timothy Grant
On Thu, Sep 11, 2008 at 12:02 PM, Daniel Fetchinson
[EMAIL PROTECTED] wrote:
 snip

 Thanking you,

 Ms. Vaidehi Pawar

 How much do you pay?

 How much do you ask for

 cheers
 Ms. Vaidehi

 I was just kidding. But if you seriously need people to do this kind
 of job it's better to post the amount you are willing to pay otherwise
 nobody will take it seriously.

 Cheers,
 Daniel
 --
 Psss, psss, put it down! - http://www.cafepress.com/putitdown
 --
 http://mail.python.org/mailman/listinfo/python-list


I find it impossible to take anyone asking others to do their school
work for them seriously no matter how or what they are willing to pay.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the pythonic way: why a.x = 1 is better than a.setX(1) ?

2008-09-04 Thread Timothy Grant
On Thu, Sep 4, 2008 at 4:09 AM, Marco Bizzarri [EMAIL PROTECTED] wrote:
 Sorry... pressed enter but really didn't want to.

 As I said, let's say I have a class

 class A:
def __init__(self):
 self.x = None



 Python makes the decision to allow the developers to directly access
 the attribute x,  so that they can directly write: a.x = 1, or
 whatever; this has for me the unfortunate side effect that if I write,
 for example a.y = 1, when I really wanted to write a.x = 1 no one
 cares about it, and I'm unable to spot this error until later.

 Of course, I know that while I'm fresh, I've a good knowledge of the
 code, and anything else, I will be able to avoid such stupid errors;
 however, I'm afraid of the times when I'm tired, when I have to put my
 hands on the code of someone else, and so on.

 Please, understand that I'm not stating that python is wrong... after
 all, if it is wrong, I can move to a language like Java, which has a
 different approach on it. I'm really very interested in reading past
 discussion on it, if they are available.

 Regards
 Marco

I think the most obvious solution to the problem is effective unit
tests. If you type a.y =1 and have a test that asserts a.x == 1 then
you would quite quickly discover that you made a typo.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax error in .py file and globals variable values not available.

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 12:48 AM, Alexis Boutillier
[EMAIL PROTECTED] wrote:
 Timothy Grant a écrit :

 On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
 [EMAIL PROTECTED] wrote:

 Timothy Grant a écrit :

 On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
 [EMAIL PROTECTED] wrote:

 Hi,

 I have a strange behaviour of python with pdb and import statement.
 Here is the example code :

 file my1.py:
 import my2

 file my2.py:
 a=5
 toto

 I intentionnaly put a syntax error in file my2.py.

 If I run python -i my2.py and run pdb I got :
 NameError: name 'toto' is not defined

 import pdb
 pdb.pm()

 - toto

 print a

 5

 If I run python -i my1.py and run pdb I got :
 NameError: name 'toto' is not defined

 import pdb
 pdb.pm()

 - toto

 print a

 None

 Why can't I get access to variable a in pdb when the process generating
 the
 error came from an import statement ?

 With python 2.3.5, it works fine and in the two cases I get the correct
 value of 5 for variable a.
 with python 2.43,2.5.1,2.5.2, it doesn't work and I get None value
 for
 variable a.

 Somebody can explain me this behaviour ?


 Thanks.
 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list


 Because of the syntax error the module wasn't loaded.

 What kind of behaviour would you expect on code that has been flagged
 as not executable?

 I got the same behaviour with :
 file my2.py:
 a=5
 raise SystemError,

 In pdb, I can't have the value of attribute a.
 So this is not linked to the fact that it is a SyntaxError or a
 SystemError.

 I expect to be able to have the value of all attributes that have been
 used
 before the error occured.
 This is problematic because in a more complicated code, you can't have
 the
 value of the attribute that was used before the error occured.
 Python know that this attribute exist, it only don't have its value.
 other
 attribute affected are : __name__,__doc__,__file__.

 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list


 So if you were writing C code and the file failed to compile you would
 still expect to have a working executable that just worked up until
 the point of the syntax error?

 I'm not sure why you just don't fix the syntax error and move on.



 As you can see in my last response, this problem is not linked to the type
 of error, If I raise a SystemError instead of creating a SyntaxError I
 still can't access variable defined before the error.


 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list


http://docs.python.org/ref/import.html

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ensure only single application instance.

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 6:51 AM, Heston James [EMAIL PROTECTED] wrote:
 Good afternoon all.

 I have an application/script which is launched by crontab on a regular
 basis. I need an effective and accurate way to ensure that only one instance
 of the script is running at any one time.

 After a short look around the internet I found a couple of examples, such as
 this one (http://code.activestate.com/recipes/474070/), however they both
 seem to be focused on a windows based environment.

 Can anyone offer their advice on how best to do this on a linux based
 system?

 I have been contemplating the idea of creating a pidfile which is destroyed
 at the end of the script, will this suffice? is it fool proof? My only
 concern with this is that if the script crashes or is stopped halfway
 through processing for whatever reason, I'll be left with a dead pidfile on
 the system and no successive runs will work.

 I'm really interested to get your ideas guys, Thanks.

 Heston

 
 Get Hotmail on your mobile from Vodafone Try it Now!
 --
 http://mail.python.org/mailman/listinfo/python-list


Why not look at the process list, and if you find two entries kill the
one that is just starting?


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Command lime code

2008-08-29 Thread Timothy Grant
On Fri, Aug 29, 2008 at 3:38 PM,  [EMAIL PROTECTED] wrote:
Seriously, did you think we've hacked your computer and are spying on
your web browsing? How would we know what web page you have visited?

 I was hoping someone would give me a page add where such code could be
 found.
 Thanks for the helpful reply.
 --
 http://mail.python.org/mailman/listinfo/python-list


If you asked a more helpful question you may get more helpful replies.
None of us here have experienced your experiences, or seen the code
you're working on, so expecting us to divine what you're looking for
based on next-to-no content in your question is a bit much.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wild Card String Comparison

2008-08-28 Thread Timothy Grant
On Wed, Aug 27, 2008 at 10:00 PM, W. eWatson [EMAIL PROTECTED] wrote:
 Timothy Grant wrote:

 On Wed, Aug 27, 2008 at 8:49 PM, W. eWatson [EMAIL PROTECTED]
 wrote:

 Is it possible to do a search for a wild card string in another string.
 For
 example, I'd like to find v*.dat in a string called bingo. v must be
 matched against only the first character in bingo, and not simply found
 somewhere in bingo, as might be the case for *v*.dat.
 --
  Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
 Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

   Web Page: www.speckledwithstars.net/
 --
 http://mail.python.org/mailman/listinfo/python-list

 Is this what you're looking for?

 What's this?
 -

 Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
 [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
 Type help, copyright, credits or license for more information.

 x = 'the quick brown fox'

 --

 'the' in x

 True

 'qui' in x

 True

 'jumped' in x

 False

 If that doesn't meet  your needs you may want to look at the re
 module. But if you can avoid re's your likely better off.

 re module??


 There are no wild cards in your examples. * is one wild card symbol?
 begin*end means find begin followed by any string of characters until it
 find the three letters end.

 begin here now but end it should find begin here now but end
 beginning of the end is the title of a book should find beginning of the
 end
 b egin but end this now should find nothing.


 --
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/
 --
 http://mail.python.org/mailman/listinfo/python-list


you definitely need the re module then.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax error in .py file and globals variable values not available.

2008-08-28 Thread Timothy Grant
On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier
[EMAIL PROTECTED] wrote:
 Timothy Grant a écrit :

 On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
 [EMAIL PROTECTED] wrote:

 Hi,

 I have a strange behaviour of python with pdb and import statement.
 Here is the example code :

 file my1.py:
 import my2

 file my2.py:
 a=5
 toto

 I intentionnaly put a syntax error in file my2.py.

 If I run python -i my2.py and run pdb I got :
 NameError: name 'toto' is not defined

 import pdb
 pdb.pm()

 - toto

 print a

 5

 If I run python -i my1.py and run pdb I got :
 NameError: name 'toto' is not defined

 import pdb
 pdb.pm()

 - toto

 print a

 None

 Why can't I get access to variable a in pdb when the process generating
 the
 error came from an import statement ?

 With python 2.3.5, it works fine and in the two cases I get the correct
 value of 5 for variable a.
 with python 2.43,2.5.1,2.5.2, it doesn't work and I get None value for
 variable a.

 Somebody can explain me this behaviour ?


 Thanks.
 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list



 Because of the syntax error the module wasn't loaded.

 What kind of behaviour would you expect on code that has been flagged
 as not executable?

 I got the same behaviour with :
 file my2.py:
 a=5
 raise SystemError,

 In pdb, I can't have the value of attribute a.
 So this is not linked to the fact that it is a SyntaxError or a SystemError.

 I expect to be able to have the value of all attributes that have been used
 before the error occured.
 This is problematic because in a more complicated code, you can't have the
 value of the attribute that was used before the error occured.
 Python know that this attribute exist, it only don't have its value. other
 attribute affected are : __name__,__doc__,__file__.

 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list


So if you were writing C code and the file failed to compile you would
still expect to have a working executable that just worked up until
the point of the syntax error?

I'm not sure why you just don't fix the syntax error and move on.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting references to obect instances into a list

2008-08-27 Thread Timothy Grant
On Wed, Aug 27, 2008 at 8:32 AM, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Thanks for your reply Simon.

 I will read the article you told me to but first, please, have a look
 at this snippet:

 m = [2,3,4]
 p = ['a','b','c']
 q = [m,p]
 q
 [[2, 3, 4, 'a', 'b', 'c'], ['a', 'b', 'c']]
 del p
 q
 [[2, 3, 4, 'a', 'b', 'c'], ['a', 'b', 'c']]



 How come q is not updated after I deleted p?

 This is my point.
 --
 http://mail.python.org/mailman/listinfo/python-list


Because the list still has a reference to the object formerly known as p.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax error in .py file and globals variable values not available.

2008-08-27 Thread Timothy Grant
On Wed, Aug 27, 2008 at 2:49 AM, Alexis Boutillier
[EMAIL PROTECTED] wrote:
 Hi,

 I have a strange behaviour of python with pdb and import statement.
 Here is the example code :

 file my1.py:
 import my2

 file my2.py:
 a=5
 toto

 I intentionnaly put a syntax error in file my2.py.

 If I run python -i my2.py and run pdb I got :
 NameError: name 'toto' is not defined
 import pdb
 pdb.pm()
 - toto
 print a
 5

 If I run python -i my1.py and run pdb I got :
 NameError: name 'toto' is not defined
 import pdb
 pdb.pm()
 - toto
 print a
 None

 Why can't I get access to variable a in pdb when the process generating the
 error came from an import statement ?

 With python 2.3.5, it works fine and in the two cases I get the correct
 value of 5 for variable a.
 with python 2.43,2.5.1,2.5.2, it doesn't work and I get None value for
 variable a.

 Somebody can explain me this behaviour ?


 Thanks.
 --
 Boutillier Alexis
 Methodology engineer

 Arteris SA
 The Network-on-Chip Company TM
 www.arteris.net

 6 par Ariane Immeuble Mercure
 78284 Guyancourt Cedex
 France
 Office: (+33) 1 61 37 38 71
 Fax:(+33) 1 61 37 38 41
 [EMAIL PROTECTED]
 --
 http://mail.python.org/mailman/listinfo/python-list



Because of the syntax error the module wasn't loaded.

What kind of behaviour would you expect on code that has been flagged
as not executable?

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: no string.downer() ?

2008-08-27 Thread Timothy Grant
On Wed, Aug 27, 2008 at 5:28 PM, John Machin [EMAIL PROTECTED] wrote:
 On Aug 28, 9:53 am, Terry Reedy [EMAIL PROTECTED] wrote:
 ssecorp wrote:
  if i want to make a string downcase, is upper().swapcase() the onyl
  choice? there is no downer() ?

 If you are not being a troll, there are two easy ways to answer such a
 question.


 [snip]

 Reading the manual backwards as the OP seems to have done (upper,
 swapcase, ...) one finds:

 
 swapcase( )

 Return a copy of the string with uppercase characters converted to
 lowercase and vice versa.
 

 Out of the possible diagnoses (trolling, incredible stupidity, feeble
 joke attempt) of the cause of the ensuing upper/downer question, I'm
 going with the third.

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


I was going to go with not particularly strong in English. To someone
not familiar with English, downer() could very well be the obvious
converse of upper().

I'm usually quick to think troll but this time I didn't. Maybe I'm just naive.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wild Card String Comparison

2008-08-27 Thread Timothy Grant
On Wed, Aug 27, 2008 at 8:49 PM, W. eWatson [EMAIL PROTECTED] wrote:
 Is it possible to do a search for a wild card string in another string. For
 example, I'd like to find v*.dat in a string called bingo. v must be
 matched against only the first character in bingo, and not simply found
 somewhere in bingo, as might be the case for *v*.dat.
 --
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/
 --
 http://mail.python.org/mailman/listinfo/python-list

Is this what you're looking for?

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 x = 'the quick brown fox'
 'the' in x
True
 'qui' in x
True
 'jumped' in x
False


If that doesn't meet  your needs you may want to look at the re
module. But if you can avoid re's your likely better off.


-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Could anyone point me to a good site for pearl compiler download

2008-08-21 Thread Timothy Grant
On Thu, Aug 21, 2008 at 12:19 PM, Mike Driscoll [EMAIL PROTECTED] wrote:
 On Aug 21, 1:51 pm, Gabriel Genellina [EMAIL PROTECTED]
 wrote:
 En Thu, 21 Aug 2008 15:01:16 -0300, rich murphy
 [EMAIL PROTECTED] escribió:

  Could anyone point me to a good site for pearl compiler download.

 Would be better to ask for it in a Perl group, don't you think?

 --
 Gabriel Genellina

 Maybe he wants to know how a pearl is compiled from a clam! I would
 read the dubious Wikipedia article:

 http://en.wikipedia.org/wiki/Pearl

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


Maybe he meant Pearl Jam compilation download.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Query: Related to locking a resource in a multithreaded environment

2008-08-19 Thread Timothy Grant
On Mon, Aug 18, 2008 at 10:58 PM, tarun [EMAIL PROTECTED] wrote:
 Hello All,

 I've a configuration.ini file. This particular can be accessed by several
 threads of my application. Each thread can read/write configuration
 parameters from/to the configuration.ini file. I am using threading (Rlock)
 to lock the resource (configuration.ini file) while accessing it from any
 thread. I use the file available at
 http://www.voidspace.org.uk/python/configobj.html for read/write.

 I did the following in one of my files:

 import threading
 class Synchronization:
   def __init__(self):
 self.mutex = threading.RLock()

 Now this I can create instances of the class Synchronization and use
 acquire/release to work on the shared resource. But every thread would need
 to import this class and hence each thread would create a separate instance
 of the class. This means several lock variables. But I think we need a
 global lock flag that is accessible across all the threads.

 How do i do this?

 Please let me know ASAP.

 Thanks In Advance,
 Tarun
 --
 http://mail.python.org/mailman/listinfo/python-list


Does making it a class level instead of instance level variable not work?

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Blackberry mobile phones

2008-08-11 Thread Timothy Grant
On Sun, Aug 10, 2008 at 9:54 PM,  [EMAIL PROTECTED] wrote:
 I'm looking for a version of Python for Blackberry mobile phones - has
 anyone heard of such a thing? I've been googling this topic without success.

 Thanks,
 Malcolm

My understanding is that the BB's run Java, so there *may* be some
chance that it might be possible to get Jython running on it.


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wildcards for regexps?

2008-08-11 Thread Timothy Grant
On Sun, Aug 10, 2008 at 9:10 PM, ssecorp [EMAIL PROTECTED] wrote:
 If I have an expression like bob marley and I want to match
 everything with one letter wrong, how would I do?
 so bob narely and vob marley should match etc.

At one point I needed something like this so did a straight port of
the double-metaphone code to python.

It's horrible, it's ugly, it's non-pythonic in ways that make me
cringe, it has no unit tests, but it does work.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically creating html code with python...

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 10:05 AM,  [EMAIL PROTECTED] wrote:
 Hi,

 Thanks for your patience.

 I got the text displayed in the web browser with the following code:

 [CODE]
 f=StringIO.StringIO()
 f.write('htmlheadtitledata analysis site/title/headbody')
 f.write(pThis is a trial test/p)
 f.write(/body/html)

 print Content-type: text/html\n
 print f.getvalue()
 f.close()
 [/CODE]

 Now I am trying to put both the image and the text together, but the 
 following lines do not create the text with the chart that I expected.

 [CODE]
 f=StringIO.StringIO()
 f.write('htmlheadtitledata analysis site/title/headbody')
 f.write(pThis is a trial test/p)
 f.write(urllib.urlopen(http://localhost/myLibs/ChartLib.py,urllib.urlencode(TheData)))
 f.write(/body/html)

 print Content-type: text/html\n
 print f.getvalue()
 f.close()
 [/CODE]

 I am wondering if urllib.urlopen is the command I need to revise.

 Thanks for the pointers as well. I will look into them.




 Jerry Hill [EMAIL PROTECTED] wrote :

 On Mon, Aug 11, 2008 at 12:26 PM,  [EMAIL PROTECTED] wrote:
  I have tried calling a script containing the code below from a web browser 
  and it did not get the text.

 You quoted my post that answered this question, but did not implement
 either of the two solutions I suggested.  I continue to suggest that
 you either: f.seek(0) before you f.read(), or that you replace
 f.read() with f.getvalue().

 Also, you may want to read the docs on
 StringIO - http://docs.python.org/lib/module-StringIO.html
 File objects - http://docs.python.org/lib/bltin-file-objects.html

 --
 Jerry


It looks to me like you are opening the url, but never retrieving the
content of the url.

I think you may have better luck with urllib2 which has a read() method.

http://docs.python.org/lib/urllib2-examples.html

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: for x,y in word1, word2 ?

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 8:44 AM, Casey [EMAIL PROTECTED] wrote:
 My first thought is that you should be looking at implementations of
 Hamming Distance.  If you are actually looking for something like
 SOUNDEX you might also want to look at the double metaphor algorithm,
 which is significantly harder to implement but provides better
 matching and is less susceptible to differences based on name origins.
 --
 http://mail.python.org/mailman/listinfo/python-list


I responded in the thread of the poster's original message on this
subject, but will do the same here. I have a horribly ugly version of
the double-metaphone algorithm in python that does work, and may be of
some use in solving this problem.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: for x,y in word1, word2 ?

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 12:13 PM, Dave Webster [EMAIL PROTECTED] wrote:
 Thanks, Timothy.  I'm pretty sure that there is no such thing as a beautiful
 implementation of double-metaphone but I would personally like to have a copy
 of your python implementation.  I have a fairly elegant version of the 
 original
 metaphone algorithm I wrote myself (in PERL, many years ago) but I've
 never found
 the time to reverse-engineer the original C++ code for double-metaphone and
 pythonize it.

 On Mon, Aug 11, 2008 at 2:08 PM, Timothy Grant [EMAIL PROTECTED] wrote:
 On Mon, Aug 11, 2008 at 8:44 AM, Casey [EMAIL PROTECTED] wrote:
 My first thought is that you should be looking at implementations of
 Hamming Distance.  If you are actually looking for something like
 SOUNDEX you might also want to look at the double metaphor algorithm,
 which is significantly harder to implement but provides better
 matching and is less susceptible to differences based on name origins.
 --
 http://mail.python.org/mailman/listinfo/python-list


 I responded in the thread of the poster's original message on this
 subject, but will do the same here. I have a horribly ugly version of
 the double-metaphone algorithm in python that does work, and may be of
 some use in solving this problem.

 --
 Stand Fast,
 tjg. [Timothy Grant]


This is truly cringe-worthy, and pretty much a direct port of the C++
code. It need unit tests (which are on my to-do someday list) but
even though it's ugly it does work and I have managed to do real work
with it.


-- 
Stand Fast,
tjg. [Timothy Grant]
#
# DMetaph.py
#
# Copyright 2006 by Timothy (rhacer) Grant
#
# Based on an algorithm and code by Lawrence Philips
# 
# This code is licensed under the terms of the GNU Public License v2
#

import re

DEBUG = False

class DMetaph(str):

DMetaph(word) creates a Double Metaphone encoding of the word passed in.



def __init__(self, s):
self.s = s.upper() + ' '  # Padding allows safe indexing beyond the end
self.length = len(s)
self.last = self.length - 1

self.current = 0
self.primary = 
self.secondary = 
self.alternate = False

if self.StringAt(0, 2, 'GN', 'KN', 'PN', 'WR', 'PS'):
self.current += 1

if self.s[0] == 'X':
self.MetaphAdd('S')
self.current += 1

while len(self.primary)  4 or len(self.secondary)  4:
if DEBUG: print processing character: %s current: %s length: %s % (
self.s[self.current], self.current, self.length)

if self.current = self.length:
break

self.ProcessString()

self.metaph = self.primary
self.metaph2 = ''
if len(self.metaph)  4:
self.metaph = self.metaph[:4]

if self.alternate:
self.metaph2 = self.secondary
if len(self.metaph2)  4:
self.metaph2 = self.metaph2[:4]


def SlavoGermanic(self):
if ('W' in self.s or 'K' in self.s 
or 'CZ' in self.s or 'WITZ' in self.s):
return True
return False

def MetaphAdd(self, main, alt=None):
if main:
self.primary += main

if alt:
self.alternate = True

if (alt[0]  ' '):
self.secondary += alt
else:
if (main[0]  ' '):
self.secondary += main

def IsVowel(self, at):
if (at  0) or (at  self.length):
return False

if self.s[at] in 'AEIOUY':
return True

return False

def StringAt(self, start, length, *sub_strings):
if self.s[start:start + length] in sub_strings:
return True

return False

def print_diags(self, section):
printsection: %s current: %s % (section, self.current)

def ProcessString(self):
if self.IsVowel(self.current):
if DEBUG: self.print_diags('VOWEL')

if self.current == 0:
self.MetaphAdd('A')

self.current += 1
return

elif self.s[self.current] == 'B':
if DEBUG: self.print_diags('B')

self.MetaphAdd('P')

if self.s[self.current + 1] == 'B':
self.current += 2
else:
self.current += 1

return

elif self.s[self.current] == 'C':
if DEBUG: self.print_diags('C')

if (self.current  1
and not self.IsVowel(self.current - 2)
and self.StringAt(self.current - 1, 3, 'ACH')
and self.s[self.current + 2]  'I' 
and self.s[self.current + 2]  'E'
or self.StringAt

Re: some kind of trace facility ?

2008-08-09 Thread Timothy Grant
n Sat, Aug 9, 2008 at 4:14 PM, Stef Mientki [EMAIL PROTECTED] wrote:
 hello,

 I want to investigate on a regular base the flow of my Python (most of them
 using wxPython) programs.
 So I want to have some log facilty, that logs things like
 - every time a function / method is called
 - the time spent in that function / method (or even better start / finish
 time)
 - in case the function / method has some predefined variables, the values of
 these variables
 - the caller

 As an extra condition, I'm only interested in my own program modules
 (located in a specific subdirectory).

 Is there a module available that can perform such a task ?
 Any hints to get started ?

 thanks,
 Stef Mientki

As is often the case, I have never used this technique, but have read about it:

You may want to investigate a logging decorator. Python's Decorator
module has a decorator factory that should allow you to log at least
the calls. I'm not sure it would help you much with the time the
method took, but I could very well be wrong about that.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Access individual fields in csv using python

2008-08-07 Thread Timothy Grant
On Thu, Aug 7, 2008 at 9:23 AM, Krishna [EMAIL PROTECTED] wrote:
 How do I access individual fields in csv using python? Please let me
 know ASAP as its real urgent for me.

 Thanks for your help

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

I'd likely use the csv module.

http://docs.python.org/lib/module-csv.html


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython pop--up (could not retrieve information...)

2008-08-07 Thread Timothy Grant
On Thu, Aug 7, 2008 at 11:36 AM, mistersulu [EMAIL PROTECTED] wrote:
 Hi all:

 I'm using a wx.ListView object with a multi-threaded wxPython app.
 The list is dynamically generated and accessed across two or more
 threads.  In spite of the fact that I have checks to see if an item at
 a given index is in the list and the entire set of logic is contained
 within a try: except: block I periodically get pop-up windows stating
 Could not retrieve information for list control item X when I try to
 change or access the list items.

 I searched the web and groups for similar posts but can't find any
 solutions.

 My question is:

 Is there a setting somewhere in wxPython to either disable these pop-
 up messages or a semaphore or event locking method to enable cross-
 thread access to a listview object?

 Thanks in advance,
 sulu

I haven't done any threaded apps, but my understanding is that the you
should not manipulate the GUI outside of the main application thread.


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: A question about string and float number

2008-08-07 Thread Timothy Grant
That's because s IS a string. It's not been converted to a float.

In [1]: s = '3.1415'
In [2]: n = float(s)
In [3]: type(s)
Out[3]: type 'str'
In [4]: type(n)
Out[4]: type 'float'

Why are you avoiding the very simple try:/except: solution to this problem?

On Thu, Aug 7, 2008 at 1:28 PM, Wei Guo [EMAIL PROTECTED] wrote:
 Hi I tried the first type method but it seens that it doesn't work. Could
 anyone help me about it?

 s = '3.145'
 type(s) == type(float())
 False
 type(s)
 type 'str'
 type(float())
 type 'float'


 Best regards,

 Wei


 On 8/7/08, Wei Guo [EMAIL PROTECTED] wrote:

 Hi Thanks for Tyler and Edwin's help.

 For my questions, I need to import some xml file and there are floating
 number and strings in it. I need to process string and number differently.
 This is reason that I am asking question here. Is this background
 information we need for this quesions.

 Btw, which way is better? type or with exception ValueError?

 Thanks,

 Wei


 On 8/6/08, Tyler Breisacher [EMAIL PROTECTED] wrote:

 It's generally a bad idea to use except without naming a specific
 exception. The exception you might expect in this case is ValueError. Any
 other exception *should* be uncaught if it happens. By the way, this method
 will return true for integers as well as floats. For example, isFloat('3')
 will return 3.0. So make sure this is what you want, since it wasn't 100%
 clear from the original message.


 Wei Guo wrote:

 #this is a better way of testing a string for float
 def isFloat(s):
try:
s = float(s)
except:
return False
return True


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



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




-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Print statement isn't showing up?

2008-08-05 Thread Timothy Grant
On Tue, Aug 5, 2008 at 9:09 AM, Robert Dailey [EMAIL PROTECTED] wrote:
 Hi,

 I have the following code:


 def ReplaceExternalWithCopy( localDir, remoteDir ):
 print Removing external local directory:, localDir
 rmdirs( localDir )
 vfxrepo.copy( remoteDir, localDir )

 I noticed that the print statement above does not show up before
 vfxrepo.copy() is called. the copy() function (as well as the rmdirs()
 function) are very long file-system calls that take up to 5 minutes. I
 should see a print statement before these are executed, but I do not.
 Instead it shows up *after* the last 2 lines of code have completed. Is
 there something broken about this?

My guess is that the output is getting buffered and the buffer doesn't
get flushed until sometime after the function executes.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding IP address of localhost via socket API (or other API)

2008-08-05 Thread Timothy Grant
On Tue, Aug 5, 2008 at 2:50 PM, David York [EMAIL PROTECTED] wrote:
 Does anybody know how to find the real IP address (e.g.: address visible to
 internet) of a machine via Python?  In other words I have a machine with an
 IP address something like 192.168.1.5, an address given to me by a router.
 The router's address (and thus my machine's address) to the outside world is
 something realistic, 123.156.123.156 or whatever.  How do I get that
 number?  I've tried socket.getaddrinfo('localhost', None) but all I get is
 127.0.0.1 as expected.

 How do I find out my machine's IP address as visible to the outside world?
 Thanks a lot.

David

I'm not sure what you are trying to accomplish. The machine I'm typing
this on has a 192.168.x.x number. The router that gave it to me also
has a 192.168.x.x number. However, I know that that is not the IP that
the world sees when my packets finally leave the building.

What if your machine has multiple interface cards in it?

What are you trying to accomplish?


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding IP address of localhost via socket API (or other API)

2008-08-05 Thread Timothy Grant
On Tue, Aug 5, 2008 at 4:39 PM, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 Sorry for replying to the replier (Timothy) instead of the OP (David),
 but the original post seems to have been eaten by my ISP.

 On Tue, 05 Aug 2008 15:48:26 -0700, Timothy Grant wrote:

 On Tue, Aug 5, 2008 at 2:50 PM, David York [EMAIL PROTECTED] wrote:
 Does anybody know how to find the real IP address (e.g.: address
 visible to internet) of a machine via Python?  In other words I have a
 machine with an IP address something like 192.168.1.5, an address given
 to me by a router. The router's address (and thus my machine's address)
 to the outside world is something realistic, 123.156.123.156 or
 whatever.  How do I get that number?  I've tried
 socket.getaddrinfo('localhost', None) but all I get is 127.0.0.1 as
 expected.

 How do I find out my machine's IP address as visible to the outside
 world? Thanks a lot.

David

 I'm not sure what you are trying to accomplish. The machine I'm typing
 this on has a 192.168.x.x number. The router that gave it to me also has
 a 192.168.x.x number. However, I know that that is not the IP that the
 world sees when my packets finally leave the building.

 That's the IP address the OP probably wants. At least, when I've asked
 this exact same question, that's what I meant.

 The only way I know of is to query an external server that will tell you.
 There's a few of them out there. Here's a few:

 http://checkip.dyndns.org/
 http://www.showmyip.com
 http://www.showmyip.com/simple/
 http://whatismyip.org/

 The basic algorithm is to connect to one of those sites and fetch the
 data it returns, then parse it appropriately. Some of them return a
 simple IP address, some a complicated bunch of text, some a nicely
 formatted XML document. Some of them only allow you to query the server a
 limited number of times. I don't remember which is which.

 To get you started, here's an untested piece of code:

 import urllib2
 import re
 data = urllib2.urlopen(site).read()
 matcher = re.compile(r\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
 ip_address = matcher.search(data).group()



 --
 Steven

Now that is a cool solution to the problem. It even works in my work
environment where I have three routers between me and the front door.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: [unittest] Run setUp only once

2008-08-04 Thread Timothy Grant
On Sun, Aug 3, 2008 at 1:56 PM, Jorgen Grahn [EMAIL PROTECTED] wrote:
 On Tue, 29 Jul 2008 20:12:14 +0200, Nikolaus Rath [EMAIL PROTECTED] wrote:
 Jean-Paul Calderone [EMAIL PROTECTED] writes:
 On Tue, 29 Jul 2008 19:26:09 +0200, Nikolaus Rath [EMAIL PROTECTED] wrote:
Jean-Paul Calderone [EMAIL PROTECTED] writes:
 On Tue, 29 Jul 2008 16:35:55 +0200, Nikolaus Rath [EMAIL PROTECTED] 
 wrote:
Hello,

I have a number of conceptually separate tests that nevertheless need
a common, complicated and expensive setup.

Unfortunately, unittest runs the setUp method once for each defined
test, even if they're part of the same class as in

 ...

 Yeah, well, I guess that would work. But to me this looks really more
 like a nasty hack.. isn't there a proper solution?

 [Someone described elsewhere in the thread how it's xUnit's philosophy
 to have one environment per executed test.]

 One option is to look into other unit test tools. People sometimes
 mention py.test as being superior.  I haven't tried it -- I'm just a
 slightly dissatisfied unittest user.

  http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#Python

 /Jorgen

 --
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
 \X/ snipabacken.se  R'lyeh wgah'nagl fhtagn!
 --
 http://mail.python.org/mailman/listinfo/python-list


py.test supports setup/teardown_module, setup/teardown_class and
setup_teardown_method.

I've never needed to use the first, the second comes in very handy
especially when writing acceptance tests.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Python questions

2008-08-04 Thread Timothy Grant
On Mon, Aug 4, 2008 at 1:27 PM, LessPaul [EMAIL PROTECTED] wrote:
 On Aug 2, 3:07 pm, Tim Roberts [EMAIL PROTECTED] wrote:
 binaryjesus [EMAIL PROTECTED] wrote:

 One great open source GUI package that you left out is GTK ie. pygtk.
 i cant compare it with wx as i have never used it but isay its much
 better than QT.

 Anyway for ur q if u want to compair qt n wx. QT should be faster coz
 it has a better documentation.

 Holy moly, did you send this from your cell phone?
 --
 Tim Roberts, [EMAIL PROTECTED]
 Providenza  Boekelheide, Inc.

 Thanks much to all the replies. At this point I believe I'm going to
 start with wx and go from there. I probably will build a small test
 app or two and try the various packages. It doesn't sound like the
 APIs are going to be too tough to grasp. And yes, I've about 10 years
 work in Windows using an event-driven model (LabWindows).
 --
 http://mail.python.org/mailman/listinfo/python-list


Make sure to subscribe to the wxPython list the people there have
helped me immensely in the past.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't import work?

2008-08-04 Thread Timothy Grant
On Mon, Aug 4, 2008 at 3:34 PM, ssecorp [EMAIL PROTECTED] wrote:
 I have in Lib/site-packages a module named pdfminer. when I do import
 pdfminer it complains:

 import pdfminer

 Traceback (most recent call last):
  File pyshell#3, line 1, in module
import pdfminer
 ImportError: No module named pdfminer


 I created a file pdfminer.py and put it in site-packages and that
 works.

 so I apparently can't import a directory pdfminer. In the directory
 pdfminer there are 3 other directoriees and inside them python-files.

 how would I import them?
 --
 http://mail.python.org/mailman/listinfo/python-list


set your PYTHONPATH environment to include the directory where your module is.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module re, extract on string match

2008-08-04 Thread Timothy Grant
On Mon, Aug 4, 2008 at 4:54 PM, Sriram Rajan [EMAIL PROTECTED] wrote:
 I am wondering if I can use re.search to extract from a particular
 location in a string.
 Example:
  string1='/Users/sriram/folder1/folder2/folder3/folder4/folder5/file'
  re.search ('folder3,string1)

  Extract /folder3/folder4/folder5/file

 Thanks,

 Sriram

Something like below?

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 import re
 s = '/Users/sriram/folder1/folder2/folder3/folder4/folder5/file'
 y = re.search('folder3.*', s)
 y.group()
'folder3/folder4/folder5/file'



-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Timothy Grant
On Sun, Aug 3, 2008 at 12:37 AM, Avi [EMAIL PROTECTED] wrote:
 Apart from the initial installation of Python itself, I
 never use an installer to install a Python package if I
 can avoid it. I wouldn't trust it to install into the right
 Python version.

 On that: how would I go about updating the system Python, then?  Or is
 that going to be stuck at whatever it is, and Mac users are expected
 to run two simultaneous Python installations?  I'm not entirely
 comfortable with having a separate MacPython (I used to do so, but it
 caused so many issues with installing new packages that I gave up on
 it) and would prefer to just update system Python.

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


You will likely cause more problems updating the system python than
managing the two separate installations. OSX relies on the version of
python they ship. While there are likely cases where it could be
replaced completely safely the risks of having to re-install your OS
at some point because it has the wrong version of python are not worth
it.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teething troubles with Python on a Mac

2008-08-03 Thread Timothy Grant
On Sun, Aug 3, 2008 at 10:44 AM, Avinash Vora [EMAIL PROTECTED] wrote:
 You will likely cause more problems updating the system python than
 managing the two separate installations.

 That's sadly worrying.

 OSX relies on the version of python they ship.

 I think that helps my point--there *are* bug fixes between major versions
 despite the new language changes, and that can really only be a good thing.

 While there are likely cases where it could be
 replaced completely safely the risks of having to re-install your OS
 at some point because it has the wrong version of python are not worth
 it.


 I haven't been a Mac user long enough to see a major version change (I was
 on Linux/XP/Vista for most of 2.4 and switched distributions right after 2.5
 came out, and then XP before that), so I've never seen a version change, but
 is this the sort of thing that will be upgraded in Software Update?

 - Avinash

I haven't paid enough attention to the system python in my four years
as an Apple user to know. I simply installed the python I wanted and
went from there.

I honestly don't think it is a cause for concern though. The situation
is very similar to on Linux (Red Hat has their version of python) you
simply install what you want and use it.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function editing with Vim throws IndentError

2008-07-25 Thread Timothy Grant
On Thu, Jul 24, 2008 at 9:32 PM, Lawrence D'Oliveiro
[EMAIL PROTECTED] wrote:

 In message
 [EMAIL PROTECTED],
 Matimus
 wrote:

  On Jul 24, 2:54 am, Lawrence D'Oliveiro [EMAIL PROTECTED]
  central.gen.new_zealand wrote:
  In message
  [EMAIL PROTECTED],
 
  Matimus wrote:
   That isn't the standard. With that setup tabs will show up as 4
   spaces, and still confuse you.
 
  Why should that be confusing? The most common tab-stop setting is 4
  columns.
 
  A tab character is specified as 8 spaces.

 Specified by whom? The most common setting these days is 4 columns.
 --
 http://mail.python.org/mailman/listinfo/python-list


A tab-stop has historically been 8 spaces. Most terminals, printers and
other devices understand the tab as 8 characters.

Smart editors have made it easy to make tabs APPEAR as four spaces, but they
are almost universally interpreted elsewhere as 8 characters.

http://en.wikipedia.org/wiki/Tab_key

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: POP3 - Using poplib only shows the first few hundred messages in the mailbox

2008-07-25 Thread Timothy Grant
On Fri, Jul 25, 2008 at 5:18 AM, SteveC [EMAIL PROTECTED] wrote:

 Hello,

 I am trying to use POP3_SSL class of the poplib module to read email
 from my gmail account.  I can connect just fine using the example here
 http://www.python.org/doc/lib/pop3-example.html

 import getpass, poplib

 M = poplib.POP3('localhost')
 M.user(getpass.getuser())
 M.pass_(getpass.getpass())
 numMessages = len(M.list()[1])
 for i in range(numMessages):
for j in M.retr(i+1)[1]:
print j


 That is the above sample code from the python doc.  While everything
 works fine, the problem is that when I use the list() function it only
 returns about 400 messages starting from the beginning of my inbox.  I
 have probably 10,000 emails in my gmail account.  I don't see any pop3
 object functions to move around the inbox or anything of the like.

 Could someone point me in the right direction?  I'm sure there must be
 something simple I am missing.

 Thanks,
 Steve
 --
 http://mail.python.org/mailman/listinfo/python-list


The GroupWise popper where I work only allows access to the first  100
messages. To access the next 100 you have to retrieve the first 100.

My guess is that gmail is doing something similar.

If you retrieve the first 400, do you get a new list the next time?

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: Function editing with Vim throws IndentError

2008-07-22 Thread Timothy Grant
On Tue, Jul 22, 2008 at 2:02 PM, ptn [EMAIL PROTECTED] wrote:

 Hi everybody,

 I have a weird problem.  Say I have a .py file with some functions in
 it, like this:

# (...)
def foo():
print(bar)

 When I open it and add a line to one of the functions,

# (...)
def foo():
troz = bar
print(troz)

 I get the following traceback from the interpreter:

Traceback (most recent call last):
  File SOMEWHERE/example.py, line ??
troz = bar
  ^
IndentationError: unindent does not match any outer indentation
 level

 And so I'm forced to rewrite the function entirely just to add the new
 line.

 I thought that my problem was the w option from formatoptions, so I
 changed my .vimrc file to this:

augroup filetype
  autocmd BufNewFile,BufRead *.txt set filetype=human
augroup END
autocmd FileType human setlocal formatoptions+=ta2w
autocmd FileType lisp,scheme,python,c,java,vim setlocal
 formatoptions-=ta2w

 But the problem didn't go away.  I don't think this has anything to
 do
 with the tabs and spaces, because I have them set up like this:

set tabstop=4 shiftwidth=4 expandtab

 which is the standard way to handle them.

 The scripts I load are: qbuf, TagList, indent/python.vim and a reduced
 version of the standard python.vim

 Could someone provide some pointers?

 Thanks,

 Pablo Torres N.
 --
 http://mail.python.org/mailman/listinfo/python-list


Are you editing someone else's code? If you are, my guess is that the file
uses tabs for indentation.

You may want to do :set list within Vim to test that theory. That should
show you what all the whitespace characters are.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: How do I compare files?

2008-07-22 Thread Timothy Grant
On Tue, Jul 22, 2008 at 4:27 PM, Clay Hobbs [EMAIL PROTECTED] wrote:

 I am making a program that (with urllib) that downloads two jpeg files
 and, if they are different, displays the new one.  I need to find a way
 to compare two files in Python.  How is this done?

 -- Ratfink

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


I'd start with file sizes.

If that's not enough you might look at the md5 library and check the md5
values for the files.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: Testing for connection to a website

2008-07-15 Thread Timothy Grant
On Tue, Jul 15, 2008 at 3:48 PM, Alexnb [EMAIL PROTECTED] wrote:




 Alexnb wrote:
 
  Okay, I already made this post, but it kinda got lost. So anyway I need
 to
  figure out how to test if the user is able to connect to a specific
  website. Last time I got pointed to the urllib2 page, but if I do
  urlopen() and and am not connected, the program stops. So I don't know if
  that was what you guys wanted me to do, but I don't think so, you guys
 are
  smarter than that. So, how can I test for connection to a website.
 

 Just for anyone looking this up later here is code that works :)

 from urllib2 import *
 import urllib2
 e = ''

 req = urllib2.Request('http://www.dictionary.com')
 try:
response = urlopen(req)

 except HTTPError, e:
print e.code
 except URLError, e:
print e.reason

 if e == '':
print good to go
 --
 View this message in context:
 http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18476597.html
 Sent from the Python - python-list mailing list archive at Nabble.com.

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


I'm glad to see you found the old post and implemented the code suggested
there.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: One step up from str.split()

2008-07-14 Thread Timothy Grant
On Mon, Jul 14, 2008 at 6:33 PM, Joel Koltner [EMAIL PROTECTED]
wrote:

 I normally use str.split() for simple splitting of command line arguments,
 but
 I would like to support, e.g., long file names which-- under windows -- are
 typically provided as simple quoted string.  E.g.,

 myapp --dosomething --loadthis my file name.fil

 ...and I'd like to get back a list wherein ListEntry[3]=my file name.fil
 ,
 but just running str.split() on the above string creates:

  ListEntry='myapp --dosomething --loadthis my file name.fil'
  ListEntry.split()
 ['myapp', '--dosomething', '--loadthis', 'my', 'file', 'name.fil']

 Is there an easy way to provide just this one small additional feature
 (keeping quoted names as a single entry) rather than going to a full-blown
 command-line argument parsing tool?  Even regular expressions seem like
 they'd
 probably be overkill here?  Or no?

 Thanks,
 ---Joel



I've found that anytime I have more than one option on the command line,
optparse  is the way to go. It works very very well for every circumstance
I've been able to throw at it.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list

Re: Creating a TCP/IP connection on already-networked computers

2008-06-14 Thread Timothy Grant
On Sat, Jun 14, 2008 at 11:54 AM, John Salerno [EMAIL PROTECTED]
wrote:

 John Salerno wrote:

  -
 #!/usr/bin/env python

 from socket import *
 from time import ctime

 HOST = '192.168.1.100'



  -
 #!/usr/bin/env python

 from socket import *

 HOST = '192.168.1.100'


 A question about this. Is the HOST referring to the IP address of the
 server computer in both of these cases? Because when I ran the program and
 got to the part where it says connected from: on the server side, it shows
 this same IP address. Shouldn't it be something different, since the
 requests are coming from a different computer than the server computer?

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


John,

It looks to me as if you're running both client and server on the same box,
and in effect conecting to yourself.

You asked in an earlier message if a friend on a different network could
connect to you using your client programme and that depends on a LOT of
things. Your friend certainly wouldn't be able to using the 192.168.x.x
address as that is an unroutable address. But you would likely have a bit of
work to do to get it to work through you and your friend's firewalls (that
is likely a conversation for a later time though.


-- 
Stand Fast,
tjg.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Write to file and see content on screen

2008-06-10 Thread Timothy Grant
On Mon, Jun 9, 2008 at 6:01 PM, [EMAIL PROTECTED] wrote:

 Hello all,

 New user to python.   I can write to a file, however, I would like to
 do both...whatever I do on the screen, I'd like to write it to a file.

 any pointers on where I can find this info.

 thanks,


This code has one really significant problem in that it opens the file each
time it is called but it gives a bit of an idea about what you can do.

[EMAIL PROTECTED]) python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type help, copyright, credits or license for more information.
 def myprintandwrite(outstr):
... f = open('out.txt', 'w')
... f.write(outstr)
... print outstr
...
 myprintandwrite('this is a test')
this is a test
 ^D
([EMAIL PROTECTED]) cat out.txt
this is a
test
([EMAIL PROTECTED])

-- 
Stand Fast,
tjg.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Q re documentation Python style

2008-06-08 Thread Timothy Grant
On Sun, Jun 8, 2008 at 2:17 PM, kj [EMAIL PROTECTED] wrote:



 I'm a Perlhead trying to learn the Way of Python.  I like Python
 overall, but every once in a while I find myself trying to figure
 out why Python does some things the way it does.  At the moment
 I'm scratching my head over Python's docstrings.  As far as I
 understand this is the standard way to document Python code.  I
 think that's fine for simple functions, but I have some functions
 that require a very long docstring to document, and somehow I find
 it a bit disconcerting to stick a few screenfuls of text between
 the top line of a function definition and its body.  I guess I'm
 still a lot more comfortable with Perl's POD, which allows more
 flexibility on the placement of the documentation relative to the
 source code.

 I expect that the reply to this quibble about very long docstrings
 will be something like: if your function requires several screenfuls
 of text to document, then it is too complex or it is doing too
 much; refactor it into a collection of simpler functions that will
 have shorter docstrings.

 Fair enough.  In general I agree with this sentiment, except that
 I think that sometimes even simple functions require a lot of
 documentation.  For example, I want to document a function that
 takes a dictionary as argument, and this dictionary is expected to
 have 5 keys.  (When the number of mandatory arguments gets above
 4, I find that it's too difficult to remember their order, so I
 resort to using a dictionary as the single argument.)  The semantics
 for each of these keys needs to be described.  Plus, of course, I
 need to describe what the function returns.  That's a few screenfuls
 right there...

 I guess this is a rambling way to ask: are docstrings *it* as far
 Python documentation goes?  Or is there a second, more flexible
 system?

 Then again, I suppose that Python's relative formal rigidity is
 considered by many to be a strength.  Which means that, to be
 comfortable with Python, one has to learn to like this (relatively)
 rigid structure...

 But I thought I'd ask.  :)

 Kynn

 --
 NOTE: In my address everything before the first period is backwards;
 and the last period, and everything after it, should be discarded.
 --
 http://mail.python.org/mailman/listinfo/python-list


If you use named parameters in your functions and methods, order is not so
important...

 def foo(a=None, b=None, c=None):
...print a,b,c
...
 b(c=1, a=2, b=3)
2 3 1


-- 
Stand Fast,
tjg.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Re: Good script editor for Python on Mac OS 10.3

2006-11-29 Thread Timothy Grant
On 11/29/06, Lou Pecora [EMAIL PROTECTED] wrote:
 In article [EMAIL PROTECTED],
  Scott_Davies [EMAIL PROTECTED] wrote:

  Hi,
 
  I have an old Mac with OS X Panther installed.  I also have the Python
  language download file, but I haven't got a text/script editor to use
  for it.  Does anyone have a recommendation for a good Python text
  editor in OS 10.3?
 
  Thanks,
 
  Scott D.
 

 Try TextWrangler.  It's free.  I use it's big brother BBEdit and like it.

 -- Lou Pecora  (my views are my own) REMOVE THIS to email me.
 --
 http://mail.python.org/mailman/listinfo/python-list


As a long-time Vim user I still vote for shelling out the Euros for TextMate.

Fabulous editor...
fabulous support...
fabulous community.





-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question - leading zeros

2006-10-13 Thread Timothy Grant
On 10/13/06, eldorado [EMAIL PROTECTED] wrote:
 I have looked around and cannot seem to find a way to strip leading zeros
 off of values in a dictionary. Basically, I am looking to do a for loop
 and any value that has one or more leading zeros would be stripped. Any
 pointers would be appreciated. Thanks


Do you really want to be storing the string representation of the int?

int('123') will convert the string representation to the number.

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Leave the putdowns in the Perl community, the Python world does not need them

2006-09-25 Thread Timothy Grant
On 25 Sep 2006 07:35:45 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Metaperl,

 Steve makes a good point. Fredrik is one of the most important
 contributors of Python code, tools, etc and as far as I am concerned,
 that is so important that it gives him the right to be cranky from tiem
 to time.

 If somebody like me were to get cranky and negative, on the other hand,
 that would be unacceptable.

 Actual production of useful code is of paramount importance ;-))

 Ron Stephens

I just checked google groups and my first post to this newsgroup was
back in April of 98. I'd been lurking for likely a year prior to that.

That little bit of introduction is simply to say something I'm sure
Fredrik will hate to hear

He's mellowed over the years.

Steve is 100% correct, if Fredrik says your wrong (even if he says it
not very nicely) You ought to stop and reconsider your opinion.

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: DMetaph.py An implementation of the Double Metaphone algorithm

2006-08-25 Thread Timothy Grant
Hello everyone,

I recently had a need to do some work with fuzzy matches, so I ported
Lawrence Philips DMetaph class from C++ to Python.

This is currently pretty much a line for line port of his his C++
code. It is not very pythonic at all.

Because it is SO ugly, I'm not yet making it available for download,
but am making it available on request.

I hope to clean it up significantly and make it far more pythonic in
the near future.


-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what are you using python language for?

2006-06-06 Thread Timothy Grant
On 6/4/06, hacker1017 [EMAIL PROTECTED] wrote:
 im just asking out of curiosity.

My current gig is perl only, but I still use python for personal stuff

1) +Twisted for a couple of IRC Bots
2) an interface between TextMate and py.test
3) a soccer management game (wxPython + PyGame)


-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python Editor

2006-05-31 Thread Timothy Grant
On 5/31/06, Manoj Kumar P [EMAIL PROTECTED] wrote:

 Hi,

 Can anyone tell me a good python editor/IDE?
 It would be great if you can provide the download link also.

 Thank You,
 -Manoj-


 SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 
 2005 conducted by the BUSINESS TODAY - Mercer - TNS India

SASKEN BUSINESS DISCLAIMER
 This message may contain confidential, proprietary or legally Privileged 
 information. In case you are not the original intended Recipient of the 
 message, you must not, directly or indirectly, use, Disclose, distribute, 
 print, or copy any part of this message and you are requested to delete it 
 and inform the sender. Any views expressed in this message are those of the 
 individual sender unless otherwise stated. Nothing contained in this message 
 shall be construed as an offer or acceptance of any offer by Sasken 
 Communication Technologies Limited (Sasken) unless sent with that express 
 intent and with due authority of Sasken. Sasken has taken enough precautions 
 to prevent the spread of viruses. However the company accepts no liability 
 for any damage caused by any virus transmitted by this email
 --
 http://mail.python.org/mailman/listinfo/python-list


If you're on OSX you might take a look at both TextMate or
TextWrangler or BBEdit.

Best advice I can give is find one that works for you.



-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Test professionalism (was: count items in generator)

2006-05-15 Thread Timothy Grant
On 5/15/06, Cameron Laird [EMAIL PROTECTED] wrote:
 In article [EMAIL PROTECTED],
 Delaney, Timothy (Tim) [EMAIL PROTECTED] wrote:
 .
 .
 .
 That's exactly my point. Assuming your test coverage is good, such an
 error would be caught by the MemoryError. An infinite loop should also
 be caught by timing out the tests, but that's much more dependent on the
 test harness.
 
 Tim Delaney

 Gulp.  OK, you've got me curious:  how many people habitually frame
 their unit tests with resource constraints?  I think I take testing
 seriously, and certainly also am involved with resource limits often,
 but I confess I've never aimed to write all my tests in terms of
 bounds on time (and presumably memory and ...).  You've got me
 thinking, Tim.
 --
 http://mail.python.org/mailman/listinfo/python-list


I'm a huge proponent of unittest and believe I take them very
seriously also. I try never to write a line of code unless I have a
test to prove I need it.

I have written tests that take into account resource constraints, but
ONLY when I've written code that, while passing all tests, shows
resource consumption problems.

Creating resource contstraint tests out of the gate *may* fall into
the category of premature optimization.

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


py.test munging strings in asserts?

2006-04-20 Thread Timothy Grant
I'm playing around with py.test and writing a parser for it's output
for use in TextMate.

I've run into what appears to be a strange phenomenon, but which is
likely me doing something wrong.

I'm writing a test to test some HTML output and the test fails for
several reasons, all of which I understand but one.

Here's the output (I've surrounded the problem area with *** to make
it a little more visible.


def test_error_summary():
text = '''html
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titlePyTestMate/title

style type=text/css
.error {color : #FF}
/style

/head
body
pError in a
href=txmt://open/?url=file:///Users/tjg/code/textmate/test_pytestmate.pyline=17/Users/tjg/code/textmate/test_pytestmate.py/a
at line 17/p
pre
[/Users/tjg/code/textmate/test_pytestmate.py:17]
/pre
/body
/html'''

assert pytestmate.create_output(
['[/Users/tjg/code/textmate/test_pytestmate.py:17]']
E   ) == text
   assert 'html\nhead\nmeta http-equiv=Content-Type 
 content=text/html; charset=utf-8 
 /\ntitlePyTestMate/title\n\n***...mate/test_pytestmate.py***/a at 
 line 
 17br/pre[/Users/tjg/code/textmate/test_pytestmate.py:17]/pre/body\n/html'
  == 'html\nhead\nmeta http-equiv=Content-Type content=text/html; 
 charset=utf-8 
 /\ntitlePyTestMate/title\n\n***...st_pytestmate.py***/a at line 
 17/p\npre\n[/Users/tjg/code/textmate/test_pytestmate.py:17]\n/pre\n/body\n/html'
 +  where 'html\nhead\nmeta http-equiv=Content-Type
content=text/html; charset=utf-8
/\ntitlePyTestMate/title\n\n...mate/test_pytestmate.py/a at
line 
17br/pre[/Users/tjg/code/textmate/test_pytestmate.py:17]/pre/body\n/html'
= function create_output at
0x42e870(['[/Users/tjg/code/textmate/test_pytestmate.py:17]'])
 +where function create_output at 0x42e870 =
pytestmate.create_output

[/Users/tjg/code/textmate/test_pytestmate.py:55]
===

granted the left side of that equality could be messed up due to
create_output() NOT doing the right thing. But the right side is
simply the contents of the variable text so WHY is the first part of
the path being substituted with ...?

Any insight greatly appreciated.

--
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib authentication required error

2006-03-31 Thread Timothy Grant
On 31 Mar 2006 18:20:27 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 In using a simple smtp routine:

 # begin example
  import smtplib
  server = smtplib.SMTP('outgoing.verizon.net')
  server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]',
 To: [EMAIL PROTECTED]
 From: [EMAIL PROTECTED]
 Subject: Shakespeare Quote

 Tis like the breath of an unfeed lawyer...
 )
  server.quit()
 # end example

 I find the following error:

raise SMTPSenderRefused(code, resp, from_addr)
 smtplib.SMTPSenderRefused: (550, '5.7.1 Authentication Required',
 '[EMAIL PROTECTED]')


 I have attempted to incorporate into the interactive session:

 server.login = ('userid', 'password')   # the same ones I use in my
 email program

I had some trouble with this not too long ago. I don't know what kind
of authentication your mail server requires, but to send through gmail
I had to do the following.

s = smtplib.SMTP('smtp.gmail.com')
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.ehlo()
s.login('foo', 'bar')
s.sendmail(from_address, to_addresses, msg)
s.close()

Hope that helps.

--
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A little request about spam

2005-04-14 Thread Timothy Grant
On 4/14/05, mark hellewell [EMAIL PROTECTED] wrote:
 On 4/14/05, BJörn Lindqvist [EMAIL PROTECTED] wrote:
  Please do not reply to spam. Replying to spam makes it much harder for
  spam filters to catch all the spam or will produce very many false
  positives. Atleast that's how gmail's filter works. And if you must
  reply, please change the subject line.
 
 Is anybody else finding that Gmails spam filter has started
 labelling a lot of python-list emails as spam? About 20
 python-list emails a day end up getting caught by their
 filter and I'm having to manually go in and mark them
 as Not spam.

Absolutely! I didn't know if it were just me or what but starting a
couple of weeks ago, The filter went from near perfect to trapping 20+
good emails per day.

Very annoying.

-- 
Stand Fast,
tjg.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to script DOS app that doesn't use stdout

2005-03-08 Thread Timothy Grant
On Sun, 06 Mar 2005 13:41:57 GMT, Gregor [EMAIL PROTECTED] wrote:
 There's a DOS console application I am trying to script (in Python), but it
 doesn't seem to use stdout or stderr... For example, if I redirect output
 to a file (cmd  file.txt), the output still appears on screen.
 Similarly, the output pipes returned by popen* don't catch the app's
 output. How might this app be generating its output? Any thoughts on how it
 could be captured (perhaps with something in the win32 extensions)?
 
 Thanks,
 
 Greg.

I've had to do this a couple of times but never in recent years. I
don't know your exact needs, but the best tool I ever found for this
sort of job was called Phantom of the Keyboard.

I ran into a couple of apps that I needed data out of and couldn't get
it. They'd only output to screen, never to disk. I used Phantom to
automate the app to dump data to screen and then capture the screen to
disk.

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


More newbie macosx user questions

2005-02-24 Thread Timothy Grant
I think I'm mis-understanding something about how PYTHONPATH works (at
least on OSX I didn't have this trouble on Linux).

I have a directory where I store libraries that I'm playing around
with. However, for some reason python can't find the library. Since
I'm using PyQt, I use pythonw, but the results are identical with
python. It doesn't look like my PYTHONPATH is getting prepended to the
library path.

Can anyone tell me what I'm doing wrong?

([EMAIL PROTECTED]) echo $PYTHONPATH 
/Users/timothygrant/code/lib
([EMAIL PROTECTED]) ls $PYTHONPATH
NJB.pyNJB.pyc   _njb_c.so njb_c.py  njb_c.pyc
([EMAIL PROTECTED]) pythonw
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type help, copyright, credits or license for more information.
 import NJB
Traceback (most recent call last):
  File stdin, line 1, in ?
ImportError: No module named NJB
 import sys
 for p in sys.path:
... print p
... 

/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
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-libnjb on macosx

2005-02-10 Thread Timothy Grant
I was working on some things that use Glenn Strong's excellent libnjb
wrapper on my Linux box. I have since bought a PowerBook and have been
trying to get everything working correctly under OS/X.

This morning I got Python-libnjb to build without errors using the
following command:

ld -dynamic -dylib -L/sw/lib -L/sw/lib/python2.3/config njb_c_wrap.o
-o _njb_c.dylib -lpython2.3 -lnjb -lSystem -framework IOKit -ldylib1.o

However, when I try and import NJB.py I get the following:

([EMAIL PROTECTED]) pythonw NJB.py  
Traceback (most recent call last):
  File NJB.py, line 2, in ?
import njb_c, sys, os, os.path, stat
  File /Users/timothygrant/src/Python-libnjb/njb_c.py, line 5, in ?
import _njb_c
ImportError: Inappropriate file type for dynamic loading

I'm guessing this means that while I got the library to build, I
didn't get it to build correctly. However, I'm enough of an OS/X
neophyte that I don't know which direction to turn.

Any suggestions?


-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding user's home dir

2005-02-02 Thread Timothy Grant
On Wed, 02 Feb 2005 11:30:34 -0800 (PST), Nemesis
[EMAIL PROTECTED] wrote:
 Hi all, I'm trying to write a multiplatform function that tries to
 return the actual user home directory. I saw that
 os.path.expanduser(~) works on Linux but on Windows2000 (at least on
 the win I used) it returns %USERPROFILE%, so I tried os.environ[HOME]
 and it gave me the same results. So I ended up with
 os.environ[USERPROFILE], it doesn't work on Linux but (at least) on
 Windows2000 it returns the correct information
 
 I googled a little bit and it seems that there is no general solution,
 so I tried to merge what I found, and I wrote this little function:
 
 def getHomeDir():
 ''' Try to find user's home directory, otherwise return current 
 directory.'''
 try:
 path1=os.path.expanduser(~)
 except:
 path1=
 try:
 path2=os.environ[HOME]
 except:
 path2=
 try:
 path3=os.environ[USERPROFILE]
 except:
 path3=
 
 if not os.path.exists(path1):
 if not os.path.exists(path2):
 if not os.path.exists(path3):
 return os.getcwd()
 else: return path3
 else: return path2
 else: return path1
 
 Please, could you test it on your systems and tell me what you got?
 I'd like to know what it returns on different operating systems because
 I'm developing a multiplatform software.
 
 Thank you all.
 --
 Unauthorized amphibians will be toad away.
 
  |\ |   |HomePage   : http://nem01.altervista.org
  | \|emesis |XPN (my nr): http://xpn.altervista.org
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 

Works beautifully on my PowerBook running Mac OSX 10.3.7

/Users/timothygrant

-- 
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list