Re: list index()

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Wed, 29 Aug 2007 23:44:33 -0700, zzbbaadd wrote:

> What's with the index() function of lists throwing an exception on not
> found? Let's hope this is rectified in Python 3. If nothing else, add
> a function that doesn't throw an exception. There are a million
> situations where you can have an item not be in a list and it is not
> an exception situation.

Write such a function yourself, it is quite easy after all.  I very seldom
use the `list.index()` method.  What do your millions situations look like?
Maybe there is a better data structure than lists for those situations!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Ben Finney
[EMAIL PROTECTED] writes:

> What's with the index() function of lists throwing an exception on not
> found?

It's letting you know that the item isn't in the list. There's no
sensible return value from an "index" function in that condition.

> Let's hope this is rectified in Python 3. If nothing else, add a
> function that doesn't throw an exception.

You can easily create one:

def get_an_index_even_if_not_found(the_list, the_item):
bogus_index_value = object()
try:
index = the_list.index(the_value)
except ValueError:
index = bogus_index_value
return index

It's up to you to figure out what bogus_index_value you want to
use. The rest of us will continue to catch the exception where needed.

-- 
 \  "Reichel's Law: A body on vacation tends to remain on vacation |
  `\ unless acted upon by an outside force."  -- Carol Reichel |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: We need PIGs :)

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 07:10:47 +0200, Martin Marcher wrote:

> Does that sound like a good idea or would that be over formalization?

Sounds like over engineering/formalization to me.

You are aware of the Python Enhancement Proposals (PEPs)?

Is something like the `Python Database API Specification v2.0`_ or `API
for Block Encryption Algorithms v1.0`_ what you are looking for?

.. _API for Block Encryption Algorithms v1.0:
http://www.python.org/dev/peps/pep-0272/
.. _Python Database API Specification v2.0:
http://www.python.org/dev/peps/pep-0249/

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: We need PIGs :)

2007-08-30 Thread Carl Banks
On Thu, 30 Aug 2007 07:10:47 +0200, Martin Marcher wrote:
> My idea was to define "Python Implementation Guidelines" (PIGs) that
> specify a problem formalize it enough so that implementations are
> interchangeable (in this example create a module that has an
> "authenticate(username, password)" method so that one could easily take
> that module for any given app and then authenticate against postgres,
> and also against my plaintext file (which was the original - quite
> useless - implementation).
> 
> Does that sound like a good idea or would that be over formalization?

The Python community already did something for web applications (WSGI, I 
think).  Not sure how well that's working out.

Doing this kind of thing is not, of course, something that can be done in 
general for all problems.  It would only help if there's enough demand 
for interoperability that developers make the effort to adhere to the 
guidelines (which are rarely ideal for any particular situation).  
Although there are some informal standards that Python programmers often 
observe (for example, the interface of file-like objects), there isn't 
too much demand to standardize them.

I believe the Python language itself makes formal guidelines less 
helpful, because its dynamicism (among other things) makes is so good at 
interfacing.  That is, if you have two pieces of code that don't work 
together, it's easy to connect them.  Many people often call Python a 
good "glue" language for this reason.  And when you have a good "glue" 
language, formal interface guidelines aren't so important.



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


Re: replacing xml elements with other elements using lxml

2007-08-30 Thread Stefan Behnel
Ultrus wrote:
> Ah! I figured it out. I forgot that the tree is treated like a list.
> The solution was to replace the  element with the first 
> child, then use Python's insert(i,x) function to insert elements after
> the first one.

You could also use slicing, something like:

parent[2:3] = child[1:5]

should work.


> lxml rocks!

I know, but it feels good to read it once in a while. :)

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


Re: Python molecular viewer

2007-08-30 Thread Paul McGuire
On Aug 29, 8:31 am, Andy Cheesman <[EMAIL PROTECTED]> wrote:
> Dear People,
>
> I was wondering if people could recommend a simple molecular viewing
> package written in python. I'm working in Theoretical chemistry and I'm
> not after an all-singing dancing molecular rendering package(pymol does
> that rather well) but a program which reads XYZ files and displays
> simple structures which can be rotated in 3D
>
> Thanks
>
> Andy

slut is an OpenGL wrapper that I found to be very intuitive to use,
and comes with some simple "moving ball" animations, but the
animations also can be panned, zoomed, and rotated.  In your case, you
wouldn't need to do the animation, just plot the balls in 3D and then
pan and zoom to your heart's content.

Here is a simple program that plots a series of points on a sphere:

from slut import *

# points on a sphere
data = [
(1.0, 0.0, 0.0),
 (0.945, 0.0, -0.325),
 (0.789, 0.0, -0.613),
 (0.547, 0.0, -0.836),
 (0.246, 0.0, -0.968),
 (-0.083, 0.0, -0.997),
 (-0.402, 0.0, -0.916),
 (-0.677, 0.0, -0.735),
...
 (-0.078, 0.027, 0.997),
 (0.232, -0.080, 0.968),
 (0.517, -0.177, 0.836),
 (0.746, -0.256, 0.613),
 (0.895, -0.307, 0.325),
 (0.945, -0.325, 0.0) ]

from slut import *

class SphereViewer(World):
def onSetup(self):
self.width = 400
self.height = 400
self.name = "Points on a Sphere"

def onDraw(self):
# draw translucent sphere
glColor4f(0.7, 0.7, 0.7, 0.5)
sphere(0, 0, 0, 1.0)
glColor4f(0.3, 0.3, 0.4, 1.0)

# plot points on surface
glPointSize(4)
for d in data:
point(*d)

# connect points with path
glLineWidth(1.5)
lastd = data[-1]
for d in data:
line( *(lastd + d) )
lastd = d

viewer = SphereViewer()
viewer.run()

And here is a short Wink video showing me working with a simplified
version of this sphere: http://www.geocities.com/ptmcg/python/sphere1.htm.

If you have your molecules' 3D coordinates, you should be able to just
plot them, and then use slut to view the molecule.

-- Paul

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


Re: list index()

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote:

> [EMAIL PROTECTED] writes:
> 
>> What's with the index() function of lists throwing an exception on not
>> found?
> 
> It's letting you know that the item isn't in the list. There's no
> sensible return value from an "index" function in that condition.

What about -1?  C programmers do this all the time.  :-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> What's with the index() function of lists throwing an exception on not
> found? Let's hope this is rectified in Python 3. If nothing else, add
> a function that doesn't throw an exception. There are a million
> situations where you can have an item not be in a list and it is not
> an exception situation.

What's with using your brain instead of whining ?

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


Re: Embedding the python interpreter

2007-08-30 Thread Tom Gur
On Aug 28, 4:03 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-08-28, Tom Gur <[EMAIL PROTECTED]> wrote:
>
> > Hey,
>
> > Do you know an easy way to embed the python interpreter in a python
> > program (so a non-technical user, which has no idea how to install the
> > python interpreter would be able to run the script as an executable) ?
>
> Hey,
>
> This question is asked at least once a week.  I'm surprised you
> didn't see the threads.  [It probably should be int he FAQ, but
> isn't.]
>
> http://www.py2exe.org/http://sourceforge.net/projects/cx-freeze/http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgihttp://cheeseshop.python.org/pypi/py2app/
>
> --
> Grant Edwards   grante Yow! Could I have a drug
>   at   overdose?
>visi.com

Thanks a lot !

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


Re: Creating a multi-tier client/server application

2007-08-30 Thread Paul Rubin
Jeff <[EMAIL PROTECTED]> writes:
> I was really hoping to avoid an entirely web-based app, for a few
> reasons, not the least of which is that I've been working almost
> entirely on web apps for the past few years, and I am getting mighty
> sick of it.

If you've done any gui programming, you'll know that it's even more
tedious and time-consuming than web programming.  At least the way I
do web stuff, I'm a back-end coder so I slap together a usable
interface with crude html (the only kind I know), then let a real web
designer handle making it look nice (that person doesn't have to be a
programmer).  It's relatively easier to get someone like that involved
in a project than someone who can do good visual stuff AND write code,
as is (to some extent) needed for a client side GUI.

> But I'd really like to try something different.

A year-long mission critical project is not the time or place to try
something different.  Better start with something easier.

> Some reasons for them would be (in no particular order): 1) More
> responsive and user-friendly interfaces, 2) Much better ability to
> sort, export, import, and print data (very important), 3) Easier to
> "lock down" who's using the program by only installing it on certain machines.

1) is true in principle and but a heck of a lot of apps don't really
use the capability.  There's tons of crappy gui apps out there that
could be done just as well with no client installation.  

2) I don't understand this part.  Sort = server side.
Export/import/printing: upload and download files?  Depending on your
requirements a little bit of browser scripting may be enough to handle
this.  3) I don't agree with this at all, and if you were trying to
pitch your project to me I'd be asking you a lot of questions about
security, in particular whether you're up to integrating SSL into both
your server and client, as well as they're already integrated into
existing browsers and http servers, which were written by experts and
have had tons of review and testing, yet problems still occasionally
turn up with them.  (Hmm, maybe you could use something like stunnel,
yet another client install.)  Since you're handling personal and
financial info maybe you should be using multi-factor authentication
(hardware tokens with client certificates) and browsers already handle
the client side of that (Windows CAPI in Explorer or PKCS#11 plugin
for Firefox).

> usability of a desktop app is rather frightening.  I've done plenty of
> stuff with AJAX, and it certainly has its purpose, but it gets
> incredibly bloated and fragile *very* quickly.

Yes I agree with this.  There are multiple judgement calls as to 1)
when the maintenance tradeoff starts tilting towards a thick client vs
AJAX when you need certain interface features that can be done either
way; and 2) whether you REALLY need those features.  Again, if you
were trying to pitch this project to me, I'd want to see some sample
screen designs with a persuasive argument that their functions
couldn't be done as effectively in html, if necessary using a small
java applet or embedded browser plug-in to handle stuff like file i/o
or whatever.

> My manager even wants use cases (if you've never had to deal with
> use cases, consider yourself a lucky, lucky person) which I am going
> to attempt to argue as that is even going *too* far.

You definitely need use cases.  You should also put together some
sample screens to figure out the user interactions.  You won't be
surprised to hear that I usually do those in html.

> So, long story short (too late), no Extreme Programming for me.

I'm not a real adherent of Extreme Programming (abbreviated XP, not to
be confused with Windows XP) like some folks on this newsgroup are,
but some of its ideas are worth studying.  In particular, doing
bite-sized incremental development with very frequent interaction with
the customer, letting them try out new code as the implementation
progresses, can save you from surprises.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Ben Finney
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:

> On Thu, 30 Aug 2007 17:09:36 +1000, Ben Finney wrote:
> > It's letting you know that the item isn't in the list. There's no
> > sensible return value from an "index" function in that condition.
> 
> What about -1?  C programmers do this all the time.  :-)

I don't believe you've contradicted me :-)

-- 
 \"If you ever drop your keys into a river of molten lava, let |
  `\  'em go, because, man, they're gone."  -- Jack Handey |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Ben Finney
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> What's with using your brain instead of whining ?

Now now, no need for snappiness. If you don't feel a constructive
response is merited, please ignore.

-- 
 \   "A lot of people are afraid of heights. Not me, I'm afraid of |
  `\widths."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Ben Finney
Ben Finney <[EMAIL PROTECTED]> writes:

> def get_an_index_even_if_not_found(the_list, the_item):

Bah. Should be "…(the_list, the_value):".

-- 
 \"Don't worry about people stealing your ideas. If your ideas |
  `\are any good, you'll have to ram them down people's throats."  |
_o__)  -- Howard Aiken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Python doesn't see the directories I create

2007-08-30 Thread mr_gadget
When I create a subfolder, python is not seeing it. Can someone please 
explain this behaviour ? I just started with python, read the tutorial over 
the weekend and am writing my very first script. So I may not be seeing 
something. Both os.path and glob.glob seem not to see a folder I created. 
Other sibling folders seem to work fine. On a whim I tried paths with \\ 
double slashes and that worked. But why should single slashes work for some 
folders and not for others ??

What I need is to match a bunch of files in a folder with 
glob.glob(C:\enhancement\rawfiles\*.bin.gz) and send them to a function that 
unzips them. But I always get []. Yes the folder does have my files, and I 
checked all permissions etc, everything looks identical to the other folders 
which python IS seeing. Same problem on my vista pc too.

Behaviour reproduced below.

C:\Enhancement>dir /ad

 Volume in drive C has no label.

 Volume Serial Number is 8056-41E7

 Directory of C:\Enhancement

08/28/2007  06:15 PM  .

08/28/2007  06:15 PM  ..

08/28/2007  06:07 PM  BSA Documentation

08/28/2007  05:56 PM  output

08/29/2007  07:08 PM  rawfiles

08/23/2007  04:38 PM  SnapCell2.3.2

08/28/2007  06:15 PM  test

   0 File(s)  0 bytes

   7 Dir(s)  35,703,283,712 bytes free

C:\>python -V

Python 2.5.1

C:\>python -c "import os; print os.path.exists('C:\enhancement\output')"

True

C:\>python -c "import os; print os.path.exists('C:\enhancement\rawfiles')"

False

C:\>python -c "import os; print os.path.exists('C:\\enhancement\\rawfiles')"

True

C:\>python -c "import glob; print glob.glob('C:\enhancement\rawfiles\*')"

[]

C:\>python -c "import os; print os.path.exists('C:\enhancement\test')"

False

C:\>python -c "import os; print 
os.path.exists('C:\enhancement\snapcell2.3.2')"

True


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


Re: list index()

2007-08-30 Thread Bruno Desthuilliers
Ben Finney a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
>> What's with using your brain instead of whining ?
> 
> Now now, no need for snappiness. If you don't feel a constructive
> response is merited, please ignore.

Yes, you're right. Sorry.

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Bruno Desthuilliers
mr_gadget a écrit :
> When I create a subfolder, python is not seeing it. Can someone please 
> explain this behaviour ? I just started with python, read the tutorial over 
> the weekend and am writing my very first script. So I may not be seeing 
> something. Both os.path and glob.glob seem not to see a folder I created. 
> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
> double slashes and that worked. But why should single slashes work for some 
> folders and not for others ??

s/slash/antislash/g

It's a very well known gotcha due to MS's choice to use the antislash as 
path separator. In most languages - Python included - the antislash is 
used for escape sequences (non-printable characters). '\r' is the escape 
sequence for CR (carriage return). Doubling the antislash prevents 
escaping.

You can avoid all escaping by using raw strings:

mypath = r"C:\enhancement\rawfiles\"

Also and IIRC, using slash instead should also work, ie:

mypath = r"C:/enhancement/rawfiles/"

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Diez B. Roggisch
mr_gadget schrieb:
> When I create a subfolder, python is not seeing it. Can someone please 
> explain this behaviour ? I just started with python, read the tutorial over 
> the weekend and am writing my very first script. So I may not be seeing 
> something. Both os.path and glob.glob seem not to see a folder I created. 
> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
> double slashes and that worked. But why should single slashes work for some 
> folders and not for others ??
> 
> What I need is to match a bunch of files in a folder with 
> glob.glob(C:\enhancement\rawfiles\*.bin.gz) and send them to a function that 
> unzips them. But I always get []. Yes the folder does have my files, and I 
> checked all permissions etc, everything looks identical to the other folders 
> which python IS seeing. Same problem on my vista pc too.
> 
> Behaviour reproduced below.
> 
> C:\Enhancement>dir /ad
> 
>  Volume in drive C has no label.
> 
>  Volume Serial Number is 8056-41E7
> 
>  Directory of C:\Enhancement
> 
> 08/28/2007  06:15 PM  .
> 
> 08/28/2007  06:15 PM  ..
> 
> 08/28/2007  06:07 PM  BSA Documentation
> 
> 08/28/2007  05:56 PM  output
> 
> 08/29/2007  07:08 PM  rawfiles
> 
> 08/23/2007  04:38 PM  SnapCell2.3.2
> 
> 08/28/2007  06:15 PM  test
> 
>0 File(s)  0 bytes
> 
>7 Dir(s)  35,703,283,712 bytes free
> 
> C:\>python -V
> 
> Python 2.5.1
> 
> C:\>python -c "import os; print os.path.exists('C:\enhancement\output')"
> 
> True
> 
> C:\>python -c "import os; print os.path.exists('C:\enhancement\rawfiles')"
> 
> False
> 
> C:\>python -c "import os; print os.path.exists('C:\\enhancement\\rawfiles')"
> 
> True
> 
> C:\>python -c "import glob; print glob.glob('C:\enhancement\rawfiles\*')"
> 
> []
> 
> C:\>python -c "import os; print os.path.exists('C:\enhancement\test')"
> 
> False
> 
> C:\>python -c "import os; print 
> os.path.exists('C:\enhancement\snapcell2.3.2')"

I'm pretty sure it's a missing backslash escape thingy. Either use \\ 
for a backslash in paths, or just the forward slash, it works as well.

And case-sensitivity might be an issue as well.
Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python doesn't see the directories I create

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 04:30:50 -0400, mr_gadget wrote:

> C:\>python -c "import os; print os.path.exists('C:\enhancement\rawfiles')"
> 
> False
> 
> C:\>python -c "import os; print os.path.exists('C:\\enhancement\\rawfiles')"
> 
> True

The backward slash has a special meaning in string literals.  It is used
to escape special character.  One such sequence is '\r' which is *one*
character, namely the return character.  To insert *one* backslash it has
to be protected by another backslash or the string literal may be prefixed
by an 'r' to tell the compiler that backslashes have no special meaning in
that raw string literal.

In [23]: len('\r')
Out[23]: 1

In [24]: len('\\')
Out[24]: 1

In [25]: len(r'\r')
Out[25]: 2

In [26]: len(r'\\')
Out[26]: 2

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python doesn't see the directories I create

2007-08-30 Thread lupino
Ciao mr_gadget,

> When I create a subfolder, python is not seeing it. Can someone please 
> explain this behaviour ? I just started with python, read the tutorial over 
> the weekend and am writing my very first script. So I may not be seeing 
> something. Both os.path and glob.glob seem not to see a folder I created. 
> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
> double slashes and that worked. But why should single slashes work for some 
> folders and not for others ??

Instead of relying on your own error-prone ability of using forward and back
slashes as path separators, try to get as much as possible from python. ;)

You can use os.sep as a cross-platform path separator, instead of forward
slashes or escaped back slashes.

Moreover you can use the os.path.join function to let python take care of your
problem. :)

>>> os.path.join("C:", "Programs", "MySubFolder")
'C:/Programs/MySubFolder'

HTH,

-- 
[ Andrea Spadaccini - a.k.a. lupino3 - GLUGCT - from Catania - ICQ : 91528290 ]
[ GPG ID: 5D41ABF0 - key on keyservers - Debian GNU / Linux - Kernel 2.6.18.4 ]
[ Linux Registered User 313388 - a(dot)spadaccini(at)catania(dot)linux(dot)it ]
[   Computers are high-speed idiots, programmed by low-speed idiots   ]
-- 
http://mail.python.org/mailman/listinfo/python-list


gc.garbage

2007-08-30 Thread 7stud
gc.garbage returns an empty list even though the command:

 gc.set_debug(gc.DEBUG_LEAK)

produces the following output:

gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 

I expected all those objects to be in the list returned by
gc.garbage.  Here's the code:

import gc

class Cat(object):
def __del__():
pass

class Dog(object):
def __del__():
pass

def some_func():
the_dog = Dog()
the_cat = Cat()
the_dog.cat = the_cat
the_cat.dog = the_dog

some_func()

gc.set_debug(gc.DEBUG_LEAK)
print gc.garbage

--output:--
[]
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 

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


Re: gc.garbage

2007-08-30 Thread Martin v. Löwis
> gc.set_debug(gc.DEBUG_LEAK)
> print gc.garbage
> 
> --output:--
> []
> gc: uncollectable 
> gc: uncollectable 
> gc: uncollectable 
> gc: uncollectable 

gc.garbage is filled only after these messages
are printed, not before. You need to add an explicit
call to gc.collect() if you want to see what
uncollectable garbage you have.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-30 Thread Ali
On Aug 21, 11:00 am, Joel Andres Granados <[EMAIL PROTECTED]>
wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also found http://pida.co.uk/main as a possible solution.  Anyone
> tried it yet?

PIDA (http://pida.co.uk/), in my humble opinion, is the One True IDE*.

It will embed the editor of your choice, use the version control
system of your choice, and integrate the tools of your choice. In
short, it integrates your development tools into a single environment.
Hence the tag: "One True IDE".

Ali

* Emacs is pretty good at this, but since PIDA can embed Emacs anyway,
and adds features to it...

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


problem with SQLObject + mysql

2007-08-30 Thread Guillermo Heizenreder
Hi list I'm new whit SQLObjet. 
I'm study the tutorial:Connecting databases to Python with SQLObjet[1]

My problem is:
>>>from sqlobject.mysql import builder
>>>con=builder()(user='dbuser',passwd='dbpassword',host='localhost',db='garbanzo')
Traceback (most recent call last):
  File "", line 1, in 
  File
"/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/mysql/mysqlconnection.py",
 line 51, in __init__
DBAPI.__init__(self, **kw)
  File
"/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/dbconnection.py",
 line 249, in __init__
DBConnection.__init__(self, **kw)
TypeError: __init__() got an unexpected keyword argument 'passwd'


First i creating the user mysql:
 [EMAIL PROTECTED]:~$ mysql -u root
 mysql> use mysql;
 Database changed
 mysql> create database garbanzo;
 Query OK, 1 row affected (0.02 sec)
 mysql> grant all privileges on garbanzo to 'dbuser'@'localhost'
identified by 'dbpassword';
 Query OK, 0 rows affected (0.10 sec)
 mysql> flush privileges;
 Query OK, 0 rows affected (0.09 sec)


So... how i do to connect?. how create de password correctly? 

Thanks and kind regards from Argentina.
P/D: my English it to bad, I'm a novice, :P.

[1]http://www-128.ibm.com/developerworks/library/os-pythonsqlo/index.html?ca=drs#resources
-- 
Heizenreder Guillermo
http://code.google.com/u/gheize/

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Steve Holden
Bruno Desthuilliers wrote:
> mr_gadget a écrit :
>> When I create a subfolder, python is not seeing it. Can someone please 
>> explain this behaviour ? I just started with python, read the tutorial over 
>> the weekend and am writing my very first script. So I may not be seeing 
>> something. Both os.path and glob.glob seem not to see a folder I created. 
>> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
>> double slashes and that worked. But why should single slashes work for some 
>> folders and not for others ??
> 
Note you *didn't* try paths with double slashes, you merely correctly 
represented the paths with single slashes :-)

> s/slash/antislash/g
> 
> It's a very well known gotcha due to MS's choice to use the antislash as 
> path separator. In most languages - Python included - the antislash is 
> used for escape sequences (non-printable characters). '\r' is the escape 
> sequence for CR (carriage return). Doubling the antislash prevents 
> escaping.
> 
> You can avoid all escaping by using raw strings:
> 
> mypath = r"C:\enhancement\rawfiles\"
> 
Please note that the above is a well-known syntax error. A string 
literal cannot end with a single backslash, as it escapes the closing quote.

 >>> mypath = r"C:\enhancement\rawfiles\"
   File "", line 1
 mypath = r"C:\enhancement\rawfiles\"
^
SyntaxError: EOL while scanning single-quoted string
 >>>

> Also and IIRC, using slash instead should also work, ie:
> 
> mypath = r"C:/enhancement/rawfiles/"
> 
That does indeed work in most situations, but ideally (i.e. for maximum 
code portability) paths should be constructed using os.path.join(), or 
collected from the environment somehow.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Unzip: Memory Error

2007-08-30 Thread mcl
On 29 Aug, 21:18, David Bolen <[EMAIL PROTECTED]> wrote:
> mcl <[EMAIL PROTECTED]> writes:
> > I am trying to unzip an 18mb zip containing just a single 200mb file
> > and I get a Memory Error.  When I run the code on a smaller file 1mb
> > zip, 11mb file, it works fine.
> (...)
> > def unzip_file_into_dir(file, dir):
> >#os.mkdir(dir, 0777)
> >zfobj = zipfile.ZipFile(file)
> >for name in zfobj.namelist():
> >if name.endswith('/'):
> >os.mkdir(os.path.join(dir, name))
> >else:
> >outfile = open(os.path.join(dir, name), 'wb')
> >outfile.write(zfobj.read(name))
> >outfile.close()
>
> The "zfobj.read(name)" call is reading the entire file out of the zip
> into a string in memory.  It sounds like it's exceeding the resources
> you have available (whether overall or because the Apache runtime
> environment has stricter limits).
>
> You may want to peek at a recent message from me in the "Unable to
> read large files from zip" thread, as the suggestion there may also be
> suitable for your purposes.
>
> http://groups.google.com/group/comp.lang.python/msg/de04105c170fc805?...
> -- David

David,

Thank you. I read your post and I basically understood the concept,
butI could not get my head around the code, I need to write for my
solution. (Newbie and a bit long in the tooth)

To solve my problem, I think my best approach would be to read my
zipped file / files from the zip archive when I need them.  Max three
users, occasional use.  So no big overloading of host's server.

pseudo code

zfhdl = zopen(zip,filename)  # Open File in Zip Archive for
Reading

while True:
ln = zfhdl.readline()# Get nextline of file
if not ln:   # if EOF file
  break
dealwithline(ln) # do whatever is necessary with
file
zfhdl.close

That is probably over simplified, and probably wrong but you may get
the idea of what I am trying to achieve.

Richard

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Bruno Desthuilliers
Steve Holden a écrit :
> Bruno Desthuilliers wrote:
(snip)
>> You can avoid all escaping by using raw strings:
>>
>> mypath = r"C:\enhancement\rawfiles\"
>>
> Please note that the above is a well-known syntax error. A string 
> literal cannot end with a single backslash, as it escapes the closing 
> quote.

oops ! My bad :(
Thanks for the correction...

(snip)
>> Also and IIRC, using slash instead should also work, ie:
>>
>> mypath = r"C:/enhancement/rawfiles/"
>>
> That does indeed work in most situations, but ideally (i.e. for maximum 
> code portability) paths should be constructed using os.path.join(), or 
> collected from the environment somehow.

Indeed. But I doubt a path starting with 'C:' will work fine on a 
unix-like environment anyway !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python + gcov

2007-08-30 Thread labrach
Some precisions :
I've forced the configuration options with the followings flags in the
Makefile.pre :
  OPT='-Wall -fprofile-arcs -ftest-coverage -pg'
  BASECFLAGS='-Wall -fprofile-arcs -ftest-coverage -pg'
  LDFLAGS='-Wall -fprofile-arcs -ftest-coverage -pg'
  XLINKER='-Wall -fprofile-arcs -ftest-coverage -pg'

But, the coverage files are not produced by a simple : python -c
'print "Hello"'
while the gmon.out is produced

Another questions is:
the wrapped c++ module is also compile with -pg flags (and -fprofile-
arcs -ftest-coverage  as well) but the profile information does not
appear in the gmon.out
Do I need to make a static extension of my imported module to profile
it ?

thanks anyone ...

laurent


On 29 août, 18:22, [EMAIL PROTECTED] wrote:
> Hi
> I want to profile (and analyse coverage) some  c++ code imported as 
> apythonmodule
> I've compiledpython(2.4.2) with gcc 3.4.3 and flags=-Wall -fprofile-
> arcs -ftest-coverage in order to usegcov. However, thepythonbinary
> does not generate any coverage file (such than *.gcno, gcda) during
> execution.
> any tips ?
> or may be another method to profile c++ wrapped modules withinpython?
>
> thanks
>
> laurent


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

Re: Python doesn't see the directories I create

2007-08-30 Thread Steve Holden
Bruno Desthuilliers wrote:
> Steve Holden a écrit :
>> Bruno Desthuilliers wrote:
[...]
>> That does indeed work in most situations, but ideally (i.e. for maximum 
>> code portability) paths should be constructed using os.path.join(), or 
>> collected from the environment somehow.
> 
> Indeed. But I doubt a path starting with 'C:' will work fine on a 
> unix-like environment anyway !-)

Just to be contrarian:

[EMAIL PROTECTED] ~/Projects/python.org/build
$ ls C:/Steve/
Apache  SANSsecurityOverview.pdf
Apache2 SQLServer.txt
 ...
Resume.odt  todo.txt
Resume.pdf  untitled-1.py

[EMAIL PROTECTED] ~/Projects/python.org/build

That's Cygwin, of course. Is that sufficiently "unix-like"? Though I 
have to admit that the different utilities all take different approaches 
to the use of Windows paths, and some just won't take them at all.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Pablo Rey
Dear Colleagues,

I am getting the following error with a XML page:

>   File "/home/prey/RAL-CESGA/bin/voms2users/voms2users.py", line 69, in 
> getItems
> d = minidom.parseString(xml.read())
>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py", line 967, 
> in parseString
> return _doparse(pulldom.parseString, args, kwargs)
>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py", line 954, 
> in _doparse
> toktype, rootNode = events.getEvent()
>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py", line 265, 
> in getEvent
> self.parser.feed(buf)
>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py", line 
> 208, in feed
> self._err_handler.fatalError(exc)
>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/handler.py", line 38, 
> in fatalError
> raise exception
> xml.sax._exceptions.SAXParseException: :553:48: not well-formed 
> (invalid token)


> def getItems(page):
> opener =urllib.URLopener(key_file=HOSTKEY,cert_file=HOSTCERT) ;
> try:
>xml = opener.open(page)
> except:
>return []
> 
> d = minidom.parseString(xml.read())
> items = d.getElementsByTagName('item')
> data = []
> for i in items:
>data.append(getText(i.childNodes))
> 
> return data

The page is 
https://lcg-voms.cern.ch:8443/voms/cms/services/VOMSCompatibility?method=getGridmapUsers
 
and the line with the invalid character is (the invalid character is the 
final é of Université):

/C=BE/O=BEGRID/OU=Physique/OU=Univesité Catholique de 
Louvain/CN=Roberfroid


I have tried several options but I am not able to avoid this problem. 
Any idea?.

I am starting to work with Python so I am sorry if this problem is 
trivial.

Thanks for your time.
Pablo Rey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Carsten Haese
On Wed, 2007-08-29 at 23:44 -0700, [EMAIL PROTECTED] wrote:
> What's with the index() function of lists throwing an exception on not
> found? Let's hope this is rectified in Python 3.

You're assuming that this behavior is a mistake. It's not, and
consequently, it won't be "rectified".

>  If nothing else, add
> a function that doesn't throw an exception. There are a million
> situations where you can have an item not be in a list and it is not
> an exception situation.

How could it not be an exception, in the plain English sense of the
word? Most certainly you're asking for the index because you want to do
something with the index. If the item is not found, you have no index,
so that's a special case that must be handled separately. There is no
logical difference between handling that special case in an except
clause versus handling it with an if-branch.

Is the Pythonic way

try:
i = somelist.index(thing)
# Do something with i
except IndexError:
# Do something if thing not found

really that much worse than the theoretical alternative

i = somelist.index_that_returns_an_indicator(thing)
if i!=ThingNotFoundIndicator:
# Do something with i
else:
# Do something if thing not found

?

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


logging.config.fileConfig disables existing loggers

2007-08-30 Thread Robert
Hi

I have been grappling today with some unexpected behaviour from
logging.config.fileConfig.

I am using the following config file:
[loggers]
keys=root

[handlers]
keys=console

[formatters]
keys=form01

[logger_root]
level=DEBUG
handlers=console

[handler_console]
class=StreamHandler
level=NOTSET
formatter=form01
args=(sys.stdout,)

[formatter_form01]
format="%(asctime)s - %(name)s - %(filename)s:%(lineno)s - %
(levelname)s - %(message)s"
datefmt=

As you can see, it sets the root logger level to be DEBUG. I would
expect this to have the same effect as calling logger.basicConfig with
a level = DEBUG. What instead happens is that all my loggers become
disabled. One might argue that the loggers should only be created
after configuring the logger, but what about using the listening
method to configure again later...

While I can understand that the application of a new config file is
not incremental, ie should override any previous configuration
completely, it does not appear right that only loggers explicitly
named in the config file are enabled. I would expect that if I enabled
a particular logger then all child loggers should be enabled too.
Alternatively one needs to know the names of all loggers a-priori in
order to be able to monitor them.

So I took the liberty to try to discern what is going on. The culprit
(from my perspective) was the logging.config._install_loggers method,
particularly the last two lines which disable any logger not mentioned
in the config file. If those lines are deleted and a new loop is
created at the top of the function which resets all existing loggers
to their default status, then we see the desired behaviour. This seems
quite simple and sensible. Below is a patch file for applying the
change. What do people think?

Robert

--- config.py.old   2007-08-30 13:42:39.0 +0200
+++ config.py   2007-08-30 13:53:15.0 +0200
@@ -173,6 +173,14 @@
 def _install_loggers(cp, handlers):
 """Create and install loggers"""

+# reset all existing loggers so that they can inherit new
configuration
+for log in logging.root.manager.loggerDict.keys():
+logger = logging.root.manager.loggerDict[log]
+logger.level = logging.NOTSET
+logger.propagate = 1
+logger.handlers = []
+logger.disabled = 0
+
 # configure the root first
 llist = cp.get("loggers", "keys")
 llist = string.split(llist, ",")
@@ -192,16 +200,6 @@
 for hand in hlist:
 log.addHandler(handlers[hand])

-#and now the others...
-#we don't want to lose the existing loggers,
-#since other threads may have pointers to them.
-#existing is set to contain all existing loggers,
-#and as we go through the new configuration we
-#remove any which are configured. At the end,
-#what's left in existing is the set of loggers
-#which were in the previous configuration but
-#which are not in the new configuration.
-existing = root.manager.loggerDict.keys()
 #now set up the new ones...
 for log in llist:
 sectname = "logger_%s" % log
@@ -212,8 +210,6 @@
 else:
 propagate = 1
 logger = logging.getLogger(qn)
-if qn in existing:
-existing.remove(qn)
 if "level" in opts:
 level = cp.get(sectname, "level")
 logger.setLevel(logging._levelNames[level])
@@ -227,12 +223,6 @@
 for hand in hlist:
 logger.addHandler(handlers[hand])

-#Disable any old loggers. There's no point deleting
-#them as other threads may continue to hold references
-#and by disabling them, you stop them doing any logging.
-for log in existing:
-root.manager.loggerDict[log].disabled = 1
-

 def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
 """

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


Important Research Project

2007-08-30 Thread E.D.G.
Important Research Project  (Related to computer programming)

Posted by E.D.G. on August 30, 2007 [EMAIL PROTECTED]

This report is being posted to a number of Internet Newsgroups to see if
there are any experienced computer programmers who would like to provide
some assistance with an effort to develop a Perl language computer program.

Interested parties can try contacting me by e-mail or by posting a
response note to the comp.lang.perl.misc newsgroup.  They would need to
download a recent (free) MSI copy of Perl from the ActiveState Web site and
get it running on a Windows XP or Vista system.

http://www.activestate.com

I am presently using Perl 5.8.8 but plan to upgrade to the latest
version as soon as possible.  People can use Windows 98 if that is the only
operating system available.  Perl also runs on other operating systems.  But
at this time I specifically need help with the Windows version.

The goal is to have a single Perl program (or modules) perform functions
that have been done by a sizeable collection of other language programs in
the past.

Help is presently needed with learning how to get Perl to generate
charts and also produce standalone .exe copies of itself.  The plan is to
then make those .exe copies available to other scientific researchers around
the world for free use along with free use updates when they become
available.  If other researchers wish to get Perl running on their own
computers then they will probably also be given the source code for the
original program for free use so that they can do their own development
work.

Perl was originally chosen because it is quite versatile, is a free
download, and is supported both by ActiveState and quite a few independent
programmers.  So other researchers could get their own versions running
without having to worry about viruses or cost.

So far the work is fairly advanced.  The effort has been underway for at
least a decade.  The core data generation program was formally copyrighted
several years ago.  My present version of Perl will send data to Windows as
if it were being manually typed into the keyboard (important for controlling
other programs).  And it can directed to respond to most keystrokes even
when another program is the active one.  Unfortunately, Windows also
presently responds to those keystrokes.  And that complicates things a bit.

Not being a professional computer programmer I have been finding it
difficult to get new features such as a chart generating ability merged with
and running with Perl.  And the entire research project is now being slowed
as a result.  One of my colleagues has done an extensive amount of work with
Basic.  And I even offered to pay him to help with the Perl development
effort.  But after he downloaded a copy of Perl and examined it he decided
that this would involve too much effort.  I have to agree with him.

Once it is possible to create charts and .exe versions the plan is for
researchers around the world to develop Perl modules for generating a
variety of data related to sun, moon, planet, ocean tide crest and trough,
and Solid Earth Tide locations.  Most of those data can already be generated
with other programs.  Some of the data are not yet available anywhere as far
as I am aware.  If the effort is unusually successful the Perl program (or
modules) might eventually be converted to CGI programs that will run at one
or more Internet Web sites.



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


Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 13:46:47 +0200, Pablo Rey wrote:

>   The page is 
> https://lcg-voms.cern.ch:8443/voms/cms/services/VOMSCompatibility?method=getGridmapUsers
>  
> and the line with the invalid character is (the invalid character is the 
> final é of Université):

The URL doesn't work for me in a browser.  (Could not connect…)

Maybe you can download that XML file and use `xmllint` to check if it is
well formed XML!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Stefan Behnel
Pablo Rey wrote:
> I am getting the following error with a XML page:
> 
>>   File "/home/prey/RAL-CESGA/bin/voms2users/voms2users.py", line 69,
>> in getItems
>> d = minidom.parseString(xml.read())
>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py",
>> line 967, in parseString
>> return _doparse(pulldom.parseString, args, kwargs)
>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py",
>> line 954, in _doparse
>> toktype, rootNode = events.getEvent()
>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py",
>> line 265, in getEvent
>> self.parser.feed(buf)
>>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
>> line 208, in feed
>> self._err_handler.fatalError(exc)
>>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/handler.py",
>> line 38, in fatalError
>> raise exception
>> xml.sax._exceptions.SAXParseException: :553:48: not
>> well-formed (invalid token)
> 
> 
>> def getItems(page):
>> opener =urllib.URLopener(key_file=HOSTKEY,cert_file=HOSTCERT) ;
>> try:
>>xml = opener.open(page)
>> except:
>>return []
>>
>> d = minidom.parseString(xml.read())
>> items = d.getElementsByTagName('item')
>> data = []
>> for i in items:
>>data.append(getText(i.childNodes))
>>
>> return data
> 
> The page is
> https://lcg-voms.cern.ch:8443/voms/cms/services/VOMSCompatibility?method=getGridmapUsers
> and the line with the invalid character is (the invalid character is the
> final é of Université):
> 
> /C=BE/O=BEGRID/OU=Physique/OU=Univesité Catholique de
> Louvain/CN=Roberfroid
> 
> 
> I have tried several options but I am not able to avoid this
> problem. Any idea?.

Looks like the page is not well-formed XML (i.e. not XML at all). If it
doesn't specify an encoding (), you can try recoding the
input, possibly decoding it from latin-1 and re-encoding it as UTF-8 before
passing it to the SAX parser.

Alternatively, tell the page authors to fix their page.

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 07:28:52 -0400, Steve Holden wrote:

> Bruno Desthuilliers wrote:
>> Steve Holden a écrit :
>> Indeed. But I doubt a path starting with 'C:' will work fine on a 
>> unix-like environment anyway !-)
> 
> Just to be contrarian:
> 
> [EMAIL PROTECTED] ~/Projects/python.org/build
> $ ls C:/Steve/
> Apache  SANSsecurityOverview.pdf
> Apache2 SQLServer.txt
>  ...
> Resume.odt  todo.txt
> Resume.pdf  untitled-1.py
> 
> [EMAIL PROTECTED] ~/Projects/python.org/build
> 
> That's Cygwin, of course. Is that sufficiently "unix-like"? Though I 
> have to admit that the different utilities all take different approaches 
> to the use of Windows paths, and some just won't take them at all.

Even on Unix it shouldn't be a problem on most file systems to create a
directory named 'C:'

[EMAIL PROTECTED]:~$ mkdir C:
[EMAIL PROTECTED]:~$ touch C:/test.txt
[EMAIL PROTECTED]:~$ ls -l C:
total 0
-rw-r--r-- 1 bj bj 0 2007-08-30 14:38 test.txt

:-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: problem with SQLObject + mysql

2007-08-30 Thread Guillermo Heizenreder
El jue, 30-08-2007 a las 07:33 -0300, Guillermo Heizenreder escribió:
> Hi list I'm new whit SQLObjet. 
> I'm study the tutorial:Connecting databases to Python with SQLObjet[1]
> 
> My problem is:
> >>>from sqlobject.mysql import builder
> >>>con=builder()(user='dbuser',passwd='dbpassword',host='localhost',db='garbanzo')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/mysql/mysqlconnection.py",
>  line 51, in __init__
> DBAPI.__init__(self, **kw)
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/dbconnection.py",
>  line 249, in __init__
> DBConnection.__init__(self, **kw)
> TypeError: __init__() got an unexpected keyword argument 'passwd'

__ini__() got an keyword argument 'password' not 'passwd'

> 
> First i creating the user mysql:
>  [EMAIL PROTECTED]:~$ mysql -u root
>  mysql> use mysql;
>  Database changed
>  mysql> create database garbanzo;
>  Query OK, 1 row affected (0.02 sec)
>  mysql> grant all privileges on garbanzo to 'dbuser'@'localhost'
> identified by 'dbpassword';
>  Query OK, 0 rows affected (0.10 sec)
>  mysql> flush privileges;
>  Query OK, 0 rows affected (0.09 sec)
> 
> 
> So... how i do to connect?. how create de password correctly? 

> Thanks and kind regards from Argentina.
> P/D: my English it to bad, I'm a novice, :P.
> 
> [1]http://www-128.ibm.com/developerworks/library/os-pythonsqlo/index.html?ca=drs#resources

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

Re: Creating a multi-tier client/server application

2007-08-30 Thread vanrpeterson
We totally agree with your software engineering goals.  Relying on
wxPython and minimizing web reliance brings sanity to the enterprise.
We too love PostgreSQL and avoid XML whether cleaned by SOAP at all
costs.  We have found the object-relationship managers to be bloated
and unruly.   What are you building and how many hours per month are
you willing to spend supporting it?

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


Re: Creating a multi-tier client/server application

2007-08-30 Thread vanrpeterson
We totally agree with your software engineering goals.  Relying on
wxPython and minimizing web reliance brings sanity to the enterprise.
We too love PostgreSQL and avoid XML whether cleaned by SOAP at all
costs.  We have found the object-relationship managers to be bloated
and unruly.   What are you building and how many hours per month are
you willing to spend supporting it?

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


Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Pablo Rey
Hi Stefan,

The xml has specified an encoding ().

About the possibility that you mention to recoding the input, could you 
let me know how to do it?. I am sorry I am starting with Python and I 
don't know how to do it.

Thanks by your help.
Pablo



On 30/08/2007 14:37, Stefan Behnel wrote:
> Pablo Rey wrote:
>> I am getting the following error with a XML page:
>>
>>>   File "/home/prey/RAL-CESGA/bin/voms2users/voms2users.py", line 69,
>>> in getItems
>>> d = minidom.parseString(xml.read())
>>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py",
>>> line 967, in parseString
>>> return _doparse(pulldom.parseString, args, kwargs)
>>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py",
>>> line 954, in _doparse
>>> toktype, rootNode = events.getEvent()
>>>   File "/usr/lib/python2.2/site-packages/_xmlplus/dom/pulldom.py",
>>> line 265, in getEvent
>>> self.parser.feed(buf)
>>>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
>>> line 208, in feed
>>> self._err_handler.fatalError(exc)
>>>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/handler.py",
>>> line 38, in fatalError
>>> raise exception
>>> xml.sax._exceptions.SAXParseException: :553:48: not
>>> well-formed (invalid token)
>>
>>> def getItems(page):
>>> opener =urllib.URLopener(key_file=HOSTKEY,cert_file=HOSTCERT) ;
>>> try:
>>>xml = opener.open(page)
>>> except:
>>>return []
>>>
>>> d = minidom.parseString(xml.read())
>>> items = d.getElementsByTagName('item')
>>> data = []
>>> for i in items:
>>>data.append(getText(i.childNodes))
>>>
>>> return data
>> The page is
>> https://lcg-voms.cern.ch:8443/voms/cms/services/VOMSCompatibility?method=getGridmapUsers
>> and the line with the invalid character is (the invalid character is the
>> final é of Université):
>>
>> /C=BE/O=BEGRID/OU=Physique/OU=Univesité Catholique de
>> Louvain/CN=Roberfroid
>>
>>
>> I have tried several options but I am not able to avoid this
>> problem. Any idea?.
> 
> Looks like the page is not well-formed XML (i.e. not XML at all). If it
> doesn't specify an encoding (), you can try recoding the
> input, possibly decoding it from latin-1 and re-encoding it as UTF-8 before
> passing it to the SAX parser.
> 
> Alternatively, tell the page authors to fix their page.
> 
> Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asking all python programmers.

2007-08-30 Thread Hyuga
On Aug 29, 11:09 am, "sjpiii" <[EMAIL PROTECTED]> wrote:
> You mean use correct spelling and grammar?  But what about all the time
> we've spent creating cutesy little non-words like "l8er?"
>
> Actually, I'm less tolerant of those than of normal spelling and grammar
> errors because of the number of posters here for whom english is not their
> native language.

What I find worst of all, however, are people for whom English is not
their first language, *and* they write in lazy, slangy AOL-speak.
Making mistakes is fine, and even being completely incomprehensible is
bearable if it looks like an effort was made to use the language
correctly.  I don't know about anyone else, but when I'm learning a
new language, spoken or programming, I try my best to use it is
correctly as possible given my level of experience with it.  Using
slang and shorthand correctly really requires you to know what you're
doing--sort of like optimizing.

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Neil Cerutti
On 2007-08-30, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> mr_gadget a écrit :
>> When I create a subfolder, python is not seeing it. Can someone please 
>> explain this behaviour ? I just started with python, read the tutorial over 
>> the weekend and am writing my very first script. So I may not be seeing 
>> something. Both os.path and glob.glob seem not to see a folder I created. 
>> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
>> double slashes and that worked. But why should single slashes work for some 
>> folders and not for others ??
>
> s/slash/antislash/g
>
> It's a very well known gotcha due to MS's choice to use the
> antislash as path separator. In most languages - Python
> included - the antislash is used for escape sequences
> (non-printable characters). 

Keeping in mind which came first, isn't it at least as accurate
to attribute this problem to Python's choice of escape character?
There were probably advantages to adopting the same escape
character as other well-known languages/codes, but the choice has
caused some trouble over the years. 

To me, Python's collection of special-purpose string literal
notations is one of its little warts.

Of course, I'm not smart enough to have delivered the ONE TRUE
string literal notation either, but I do have a computer and an
internet connection, so there you are.

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


Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 15:31:58 +0200, Pablo Rey wrote:

> On 30/08/2007 14:35, Marc 'BlackJack' Rintsch wrote:
>
>> Maybe you can download that XML file and use `xmllint` to check if it
>> is well formed XML!?
> 
>   This is the output of the xmllint command:
> 
> [EMAIL PROTECTED] voms2users]$ xmllint cms.xml cms.xml:553: error: Input is 
> not
> proper UTF-8, indicate encoding !
> /C=BE/O=BEGRID/OU=Physique/OU=Univesité Catholique de
> Louvain/CN=Roberfroi
>  ^
> cms.xml:553: error: Bytes: 0xE9 0x20 0x43 0x61
> /C=BE/O=BEGRID/OU=Physique/OU=Univesité Catholique de
> Louvain/CN=Roberfroi
> 
> […]
> 
>  

So the XML says it is encoded in UTF-8 but it contains at least one
character that seems to be encoded in ISO-8859-1.

Tell the authors/creators of that document there XML is broken.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 15:20 +0200, Pablo Rey wrote:
>   Hi Stefan,
> 
>   The xml has specified an encoding ( ?>).

It's possible that the encoding specification is incorrect:

>>> u = u"\N{LATIN SMALL LETTER E WITH ACUTE}"
>>> print repr(u.encode("latin-1"))
'\xe9'
>>> print repr(u.encode("utf-8"))
'\xc3\xa9'

If your input string contains the byte 0xe9 where your accented e is,
the file is actually latin-1 encoded. If it contains the byte sequence
0xc3,0xa9 it is UTF-8 encoded.

If the string is encoded in latin-1, you can transcode it to utf-8 like
this:

contents = contents.decode("latin-1").encode("utf-8")

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: list index()

2007-08-30 Thread Marshall T. Vandegrift
[EMAIL PROTECTED] writes:

> What's with the index() function of lists throwing an exception on not
> found? Let's hope this is rectified in Python 3. If nothing else, add
> a function that doesn't throw an exception. There are a million
> situations where you can have an item not be in a list and it is not
> an exception situation.

The Python string types have both the method `index()` which throws an
exception and the method `find()` which implements the same behavior but
returns -1 for not-found substrings.  I would naively have assumed the
`list` type to provide both as well, but it provides only `index()`.

Anyone know the reason for this lack of parallelism?

-Marshall

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


Re: Sorting a list of Unicode strings?

2007-08-30 Thread koen . vanleemput
Wikipedia in Suomi lists it at the bottom ;-)

http://sv.wikipedia.org/wiki/Lista_%C3%B6ver_l%C3%A4nder#.C3.85

Cheers
~K

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


Re: Important Research Project

2007-08-30 Thread Paul McGuire
On Aug 30, 8:12 am, "E.D.G." <[EMAIL PROTECTED]> wrote:
> Important Research Project  (Related to computer programming)
>
> Posted by E.D.G. on August 30, 2007 [EMAIL PROTECTED]
>
> This report is being posted to a number of Internet Newsgroups

Always the hallmark of a considerate poster.

> to see if
> there are any experienced computer programmers who would like to provide
> some assistance with an effort to develop a Perl language computer program.
>
> Interested parties can try contacting me by e-mail or by posting a
> response note to the comp.lang.perl.misc newsgroup.  They would need to
> download a recent (free) MSI copy of Perl from the ActiveState Web site and
> get it running on a Windows XP or Vista system.
>
> http://www.activestate.com
>

This is a little backwards, one usually presents their research topic
*first* and their contact info *last*.  The reason?  SO PEOPLE KNOW
WHAT THE @#$(&#!@ YOU ARE WORKING ON!  Ok, I'll bite, keep reading...

> I am presently using Perl 5.8.8

Whoop-de-doo for you.

> but plan to upgrade to the latest
> version as soon as possible.  People can use Windows 98 if that is the only
> operating system available.  Perl also runs on other operating systems.  But
> at this time I specifically need help with the Windows version.
>

I suspect Perl is largely the same Perl on all those platforms.  Win
98?  Is this a zombie spam from the turn of the century?

> The goal is to have a single Perl program (or modules) perform functions
> that have been done by a sizeable collection of other language programs in
> the past.
>

Doing what!?  Grrr..., keep reading, there's gotta be a punch line...

> Help is presently needed with learning how to get Perl to generate
> charts and also produce standalone .exe copies of itself.  The plan is to
> then make those .exe copies available to other scientific researchers around
> the world for free use along with free use updates when they become
> available.  If other researchers wish to get Perl running on their own
> computers then they will probably also be given the source code for the
> original program for free use so that they can do their own development
> work.
>

Ohmigod, is Google broken?  Or has Perl gone this long and this far
without support for creating charts and graphs?  Sounds like about 10
minutes of research.

> Perl was originally chosen because it is quite versatile, is a free
> download, and is supported both by ActiveState and quite a few independent
> programmers.  So other researchers could get their own versions running
> without having to worry about viruses or cost.
>

(Why is this posted on all these non-Perl newsgroups, then?  I've
*seen* Perl already, and never want to again!)

> So far the work is fairly advanced.  The effort has been underway for at
> least a decade.  

... and we are just getting around to plotting some data.

> The core data generation program was formally copyrighted
> several years ago.  

Red flag #37 - "formally copyrighted", wooo-h

> My present version of Perl will send data to Windows as
> if it were being manually typed into the keyboard (important for controlling
> other programs).  And it can directed to respond to most keystrokes even
> when another program is the active one.  Unfortunately, Windows also
> presently responds to those keystrokes.  And that complicates things a bit.
>

... and has for the past decade, and I still haven't figured it out.

> Not being a professional computer programmer I have been finding it
> difficult to get new features such as a chart generating ability merged with
> and running with Perl.  And the entire research project is now being slowed
> as a result.  One of my colleagues has done an extensive amount of work with
> Basic.  And I even offered to pay him to help with the Perl development
> effort.  But after he downloaded a copy of Perl and examined it he decided
> that this would involve too much effort.  I have to agree with him.
>

Maybe that up-front language choice could stand a review...

> Once it is possible to create charts and .exe versions the plan is for
> researchers around the world to develop Perl modules for generating a
> variety of data related to sun, moon, planet, ocean tide crest and trough,
> and Solid Earth Tide locations.  Most of those data can already be generated
> with other programs.  Some of the data are not yet available anywhere as far
> as I am aware.  If the effort is unusually successful the Perl program (or
> modules) might eventually be converted to CGI programs that will run at one
> or more Internet Web sites.

AHHH!  The "research", I almost forgot!  Why is it left to the end of
the message?  And do we still know what the @#(*&$ this "variety of
data" is for?  I'm going to take a wild guess here - earthquake
prediction?  perpetual motion?  picking guaranteed-to-win lottery
numbers?

After a pitch like that, who could not be tempted at the prospect of
"gen

Re: SAXParseException: not well-formed (invalid token)

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 15:20 +0200, Pablo Rey wrote:
>   About the possibility that you mention to recoding the input, could you 
> let me know how to do it?. I am sorry I am starting with Python and I 
> don't know how to do it.

While I answered this question in my previous reply, I wanted to add
that you might find the following How-To helpful in demystifying
Unicode:

http://www.amk.ca/python/howto/unicode

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


strings (dollar.cents) into floats

2007-08-30 Thread luca bertini
Hi,

i have strings which look like money values (ie 34.45)
is there a way to convert them into float variables?
everytime i try I get this error: "numb = float(my_line) ValueError:  
empty string for float()"
"
here's the code



import sys
import re

for line in sys.stdin.readlines():
my_line = line.rstrip()
numb = float(my_line)
print numb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strings (dollar.cents) into floats

2007-08-30 Thread Marshall T. Vandegrift
luca bertini <[EMAIL PROTECTED]> writes:

> i have strings which look like money values (ie 34.45)
> is there a way to convert them into float variables?
> everytime i try I get this error: "numb = float(my_line) ValueError:  
> empty string for float()"
> "

You actually have problems here -- the immediate, and the one which will
get you later :-).  First, that error message indicates that you passed
an empty string to `float()`:

>>> float("")
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: empty string for float()

Second, if you the values your script is handling are actually monetary
values, you really don't want to represent them with `float`s anyway:

>>> float("34.45")
34.453

Binary floating point values are necessarily inexact.  I'm not 100% sure
what the best-practices are for representing monetary values in Python,
but the `decimal` module is probably a good start.

HTH,

-Marshall

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


Re: strings (dollar.cents) into floats

2007-08-30 Thread Gary Herron
luca bertini wrote:
> Hi,
>
> i have strings which look like money values (ie 34.45)
> is there a way to convert them into float variables?
> everytime i try I get this error: "numb = float(my_line) ValueError:  
> empty string for float()"
> "
> here's the code
>
> 
>
> import sys
> import re
>
> for line in sys.stdin.readlines():
>   my_line = line.rstrip()
>   numb = float(my_line)
>   print numb
>   
The clue "empty string for float" must mean that the value of my_line is
an empty string.  And that would seem to mean you have an empty line in
your input. 

So...  Either remove the empty lines, or test my_line before calling
float on it.

Gary Herron

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


Re: list index()

2007-08-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Aug 2007 09:53:53 -0400, Marshall T. Vandegrift wrote:

> The Python string types have both the method `index()` which throws an
> exception and the method `find()` which implements the same behavior but
> returns -1 for not-found substrings.  I would naively have assumed the
> `list` type to provide both as well, but it provides only `index()`.
> 
> Anyone know the reason for this lack of parallelism?

Historical reasons and IIRC the `find()` method on strings will go away in
Python 3.0.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

SOCKS5 + python = pain in you-know-where ?

2007-08-30 Thread Valery
Hi all

just googled both the web and groups. Who could believe in that:
nothing simple, helpful and working concerning SOCKS5 support in
python.

Anyone got success here?

Regards,

Valery.

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


Re: We need PIGs :)

2007-08-30 Thread Martin Marcher
Hello,

On 30 Aug 2007 07:14:25 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Thu, 30 Aug 2007 07:10:47 +0200, Martin Marcher wrote:
>
> > Does that sound like a good idea or would that be over formalization?
>
> Sounds like over engineering/formalization to me.
> You are aware of the Python Enhancement Proposals (PEPs)?

Yes I am thought I mentioned the wsgi pep in the mail...

> Is something like the `Python Database API Specification v2.0`_ or `API
> for Block Encryption Algorithms v1.0`_ what you are looking for?

http://en.wikipedia.org/wiki/Java_Authentication_and_Authorization_Service
http://en.wikipedia.org/wiki/Content_repository_API_for_Java
http://jcp.org/en/jsr/all

But since python is much more open in these terms these hints should
guide developers thru solutions so that they know they can use other
modules/classes without any effort if such a specificaton exists. In
Java it is more like not implementing any of these things is

>
> .. _API for Block Encryption Algorithms v1.0:
> http://www.python.org/dev/peps/pep-0272/
> .. _Python Database API Specification v2.0:
> http://www.python.org/dev/peps/pep-0249/

Indeed i wasn't aware of these (I know the wsgi spec) but I was more
thinking about guidelines where you can be quite sure that because of
not being able to provide an implementation that is so general that it
could be incorporated in the standard library.

Think of

* object relational mappers (probably a bad example - but would be still nice)
* service registries
* service repositories
* 

that use the same interface so that you can swap them effordlessly.
I'm thinking big here so that generalization has to be applied to the
problems but also that you can keep to well known interface to
implement so that it will work out for the majority of situations in
these fields.

I do know the WSGI spec but I do think that (otherwise I wouldn't have
had the idea) that PEPs are the wrong place for that. To me PEPs are
(better should be) about the plain stock standard library and how to
work with it (coding guidelines, docstring, iterators, generators -
specification of the language) PIGs (given the name is arguable - I
just like it it removes a bit of the necessary formal taste it has)
should define:

* problem
* solution
* expected behaviour
* interface

(probably even prepare unit tests if the interface is stabilized)

but should by itself not implement anything as for example the DBAPI
does. and given the nature of the field (spezialized for a task but
still applies to a lot of people) an general purpose implementation
wouldn't be useful

hope that explains it well enough. I've been in a couple of projects
where problems where common to all those projects but the
specification made up by individual (project) managers made it
impossible to reuse parts of other apps (and I guess with some
"official" backup one could point back on proven recipies - that's
probably the term that describes it best)

greetings (always wondered is that a formal or informal closing part
in english letters?)
martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strings (dollar.cents) into floats

2007-08-30 Thread J. Cliff Dyer

Gary Herron wrote:

luca bertini wrote:
  

Hi,

i have strings which look like money values (ie 34.45)
is there a way to convert them into float variables?
everytime i try I get this error: "numb = float(my_line) ValueError:  
empty string for float()"

"
here's the code



import sys
import re

for line in sys.stdin.readlines():
my_line = line.rstrip()
numb = float(my_line)
print numb
  


The clue "empty string for float" must mean that the value of my_line is
an empty string.  And that would seem to mean you have an empty line in
your input. 


So...  Either remove the empty lines, or test my_line before calling
float on it.

Gary Herron

  

Or let the exception get raised, and handle it.

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

Please assist- Python Consultant needed for 3-6 month project

2007-08-30 Thread Kelley McNeillie
I am contacting you from a company called Software Specialists, an IT Placement 
Firm based in Pittsburgh, PA.  We are prepared to make a donation to your 
organization if you could please help us out with a referral.  We are looking 
for a python developer with  web-based application experience.  If you know of 
anyone, or if you would be able to post this opportunity on your site, I would 
greatly appreciate it.  I am finding this skill pretty much impossible to 
identify locally, and I really would like to be able to assist my client with 
this position.   I am just trying to be creative in my search, I hope I am 
reaching the right person with this request.  If not, I apologize. Thank you in 
advance for any assistance you may be able to provide.

Best Regards,


Kelley McNeillie
Software Specialists, Inc.
357 Northgate Drive
Suite 10
Warrendale, PA 15086
724 933 6100 x 1105
724 933 6106 (F)
[EMAIL PROTECTED]
www.softwarespecialists.com

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


Re: list index()

2007-08-30 Thread zzbbaadd
On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] writes:
> > What's with the index() function of lists throwing an exception on not
> > found?
>
> It's letting you know that the item isn't in the list. There's no
> sensible return value from an "index" function in that condition.

for str:

find(   sub[, start[, end]])
Return the lowest index in the string where substring sub is
found, such that sub is contained in the range [start, end]. Optional
arguments start and end are interpreted as in slice notation. Return
-1 if sub is not found.

-1 is used in other languages as well.

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


Python threading

2007-08-30 Thread Robert . R . Emmel
Hello,

I am using the threading module and the Queue module in python to to
send out shipment tracking URL requests.

Is there a way to timeout a thread within a Queue?

I think the way I have it now the thread will wait until something is
returned and will basically wait forever for that something.

Between the waiting for something to be returned and the timeouts on
the database connections, the program appears to just hang like it has
stopped working. Any suggestions?

Here is a sample of code I am using (left out some of the code for
brevity):

import urllib
from HTMLParser import HTMLParser
import threading
import Queue

NTHREADS = 100

...

def Web_Retrieve(inpque, outqueue):
N = 1
try:
connection = MySQLdb.connect(host="hostname", port=3306,
user="username", passwd="password", db="Mydatabase")
print "t" + str(N)+ " - Database Connection Established !!"
cursor = connection.cursor()
except MySQLdb.OperationalError, message:
errorMessage = "t" + str(N)+ " -Error %d:\n%s" % (message[0],
message[1])
else:

DBRow = inpque.get()
while not (DBRow[0] == ''):
PNum = DBRow[1]
PNum = RemoveHyphens(RemoveSpaces(PNum))
print "t" + str(N)+ " -PNum : " + PNum
...
# Setup URL to retrieve status web page depending on
Carrier SCAC
if SCAC == "RDWY":
pURL = "http://www.quiktrak.roadway.com/cgi-
bin/quiktrak?"
bURL = "&pro0=" + PNum

if DEBUG > 90 or (DEBUG > 30 and DEBUG < 40):
print "t" + str(N)+ " -URL: ", pURL +
bURL
WURL = pURL + bURL

# Retrieve status web page, assign it to a
variable and close connection
try:
f = urllib.urlopen(pURL+bURL)
s = f.read()
f.close()
except IOError, e:
print 't' + str(N)+ ' -I/O Error:
',e.strerror
 ##   continue

...

outqueue.put((PR, s, WURL, s12))
DBRow = inpque.get()
N = N+ 1
outqueue.put(None)
cursor.close()
connection.commit()
connection.close()
print "t" + str(N)+ " -Database Closed"

## Main processing file.
def WebProcess(Mode):
## Get file listing from the proper directory depending on mode
if Mode == 'B':
IFilenames = os.listdir(os.curdir+os.sep+'Input')
NTHREADS = 100
...

# Open connection to MySql
try:
connection = MySQLdb.connect(host="hostname", port=3306,
user="username", passwd="password", db="mydatabase")
print "Database Connection Established !!"
cursor = connection.cursor()
except MySQLdb.OperationalError, message:
errorMessage = "Error %d:\n%s" % (message[0], message[1])
else:


inputs = Queue.Queue(0)
results = Queue.Queue(0)
thread_pool = []

for ii in range(NTHREADS):
thread = threading.Thread(target=Web_Retrieve,
args=(inputs, results))
thread.start()
thread_pool.append(thread)

## Retrieve BOL's from Database for web retrieval
print "Current Mode is : ", Mode
print "Length of Mode string is : ", len(Mode)
Mode_results = cursor.execute( "Select * from bol_table where
Mode = %s and (Expired IS NULL or Expired IS False);", (Mode.strip()))
print "Mode Query Results: ", Mode_results
if Mode_results > 0:
print " Do Web Page lookups !!! "
DBRows = cursor.fetchall()
for DBRow in DBRows:
inputs.put(DBRow)

for ii in range(len(DBRows)):
PR, s, WURL, s12 = results.get()
##print "PR is : "+PR+" S's first 100 char's are
"+s[0:100]+" WURL is : "+WURL
print
"+-+"
print "PR is : " + PR
print "s is (First 100) : " + s[0:100]
print "WURL is : " + WURL
print "s12 is : " + s12
print
"+-+"



## Clear out thread pool

for thread in thread_pool:
inputs.put(('',''))




For the times I have run into the "" on web pages I take
the f.read() string s and pass it to this function:

## fix webpages that have the 'scr' + 'ipt' split on them.
def fixscript(x):
SQ = 0
EQ = 0
##if DEBUG > 90:
##print "fixscript length of x: ", len(x)
while True:
SQ = x.find('scr" + "ipt', SQ + 12)
##if DEBUG > 90:
##print "SQ : ", SQ
if SQ <= 0:
break
x = x[0:SQ + 3] + x[SQ + 8:]
return x

Just passing this along to those who have run into this proble

Re: Python doesn't see the directories I create

2007-08-30 Thread Steve Holden
Neil Cerutti wrote:
> On 2007-08-30, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
>> mr_gadget a écrit :
>>> When I create a subfolder, python is not seeing it. Can someone please 
>>> explain this behaviour ? I just started with python, read the tutorial over 
>>> the weekend and am writing my very first script. So I may not be seeing 
>>> something. Both os.path and glob.glob seem not to see a folder I created. 
>>> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
>>> double slashes and that worked. But why should single slashes work for some 
>>> folders and not for others ??
>> s/slash/antislash/g
>>
>> It's a very well known gotcha due to MS's choice to use the
>> antislash as path separator. In most languages - Python
>> included - the antislash is used for escape sequences
>> (non-printable characters). 
> 
> Keeping in mind which came first, isn't it at least as accurate
> to attribute this problem to Python's choice of escape character?
> There were probably advantages to adopting the same escape
> character as other well-known languages/codes, but the choice has
> caused some trouble over the years. 
> 
> To me, Python's collection of special-purpose string literal
> notations is one of its little warts.
> 
> Of course, I'm not smart enough to have delivered the ONE TRUE
> string literal notation either, but I do have a computer and an
> internet connection, so there you are.
> 
Well, it's a wart that's shared with many other languages - including, 
interestingly enough, Microsoft's very own C#, from whose documentation 
the following examples are taken:

string a = "hello, world";  // hello, world
string b = @"hello, world"; // hello, world
string c = "hello \t world";// hello world
string d = @"hello \t world";   // hello \t world
string e = "Joe said \"Hello\" to me";  // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me
string g = "server\\share\\file.txt";   // \\server\share\file.txt
string h = @"\\server\share\file.txt";  // \\server\share\file.txt
string i = "one\r\ntwo\r\nthree";

The fact is that some strings are always going to cause trouble. 
Unfortunately programming itself is a task that requires a little more 
knowledge to be applied to the task. Just learn the rules and move on.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Python threading

2007-08-30 Thread Chris Mellon
On 8/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am using the threading module and the Queue module in python to to
> send out shipment tracking URL requests.
>
> Is there a way to timeout a thread within a Queue?
>
> I think the way I have it now the thread will wait until something is
> returned and will basically wait forever for that something.
>
> Between the waiting for something to be returned and the timeouts on
> the database connections, the program appears to just hang like it has
> stopped working. Any suggestions?
>
> Here is a sample of code I am using (left out some of the code for
> brevity):
>



The two possible implementations:

a) Use a timeout in your get() call to allow to check for thread termination
b) push a sentinel object into the Queue that means "please exit now".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please assist- Python Consultant needed for 3-6 month project

2007-08-30 Thread Steve Holden
Kelley McNeillie wrote:
> I am contacting you from a company called Software Specialists, an IT 
> Placement Firm based in Pittsburgh, PA.  We are prepared to make a donation 
> to your organization if you could please help us out with a referral.  We are 
> looking for a python developer with  web-based application experience.  If 
> you know of anyone, or if you would be able to post this opportunity on your 
> site, I would greatly appreciate it.  I am finding this skill pretty much 
> impossible to identify locally, and I really would like to be able to assist 
> my client with this position.   I am just trying to be creative in my search, 
> I hope I am reaching the right person with this request.  If not, I 
> apologize. Thank you in advance for any assistance you may be able to provide.
> 
Kelley:

Please see

   http://www.python.org/community/jobs/

(which, by the way, is the first non-sponsored result for a Google 
search on "python jobs") and in particular

   http://www.python.org/community/jobs/howto/

which explains how you can submit jobs for inclusion on the Job Board. 
There is no fee for this service, though naturally donations to the 
Python Software Foundation are always gratefully received:

   http://www.python.org/psf/donations/

Good luck with your search.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: How to use os.putenv() ?

2007-08-30 Thread T
On Aug 29, 9:50 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Aug 30, 11:21 am, [EMAIL PROTECTED] wrote:
>
>
>
> > >>> import os
>
> > >>> os.environ['PATH']
>
> > 'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
> > \system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>
> > >>> os.putenv('PATH', 'C:\\WINNT\\system32')
>
> > >>> os.environ['PATH']
>
> > 'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
> > \system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>
> > What am I doing wrong?  How do I change the value of an environment
> > variable?
>
> What you are missing is that os.environ is only populated from the
> global process environment at process startup.
>
> If you update os.environ the changes will be pushed into the global
> process environment as well. But if you use os.putenv() instead,
> bypassing os.environ, the changes will not show in os.environ.
>
> To confirm that the global process environment is being updated, use
> os.getenv().
>
> Graham

Can you tell me what I am still missing please?

>>> import os
>>>
>>> os.getenv('PATH')
'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
\system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>>>
>>> os.putenv('PATH', 'C:\\WINNT\\system32')
>>>
>>> os.getenv('PATH')
'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
\system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>>>

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


Simple elementtree question

2007-08-30 Thread IamIan
This is in Python 2.3.5. I've had success with elementtree and other
RSS feeds, but I can't get it to work with this format:

http://www.w3.org/1999/02/22-rdf-syntax-ns#";
 xmlns:dc="http://purl.org/dc/elements/1.1/";
 xmlns:fr="http://ASPRSS.com/fr.html";
 xmlns:pa="http://ASPRSS.com/pa.html";
 xmlns="http://purl.org/rss/1.0/";>
http://www.sample.com";>
Example feed
http://www.sample.com
Sample News Agency - News Feed
http://www.sample.com/img/new.gif"; />


http://www.sample.com/news/2/news.htm"; />
http://www.sample.com/news/20001/news.htm"; />


http://www.sample.com/img/about.gif";>
Our News Feed
http://www.sample.com/img/title.gif
http://www.sample.com

http://www.sample.com/news/2/
news.htm">First story
30 August, 2007 : - - First description including unicode
characters
http://www.sample.com/news/2/news.htm

http://www.sample.com/news/20001/
news.htm">Second story
30 August, 2007 : - - Second description including
unicode characters
http://www.sample.com/news/20001/news.htm



What I want to extract is the text in the title and link tags for each
item (eg. First story and http://www.sample.com/
news/2/news.htm). Starting with the title, my test script
is:

import sys
from urllib import urlopen

sys.path.append("/home/me/lib/python")
import elementtree.ElementTree as ET

news = urlopen("http://www.sample.com/rss/rss.xml";)
nTree = ET.parse(news)
for item in nTree.getiterator("title"):
  print item.text

Whether I try this for title or link, nothing is printed. There are
also unicode characters in the  tags, I'm not sure if that
could affect the output like this. In case it did I passed an encoding
argument to ET.parse (which I'd seen in other posts) but it said
encoding was an unexpected argument...

Printing all subelements does work:
print nTree.getiterator()

[http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDF at
40436d2c>,
http://purl.org/rss/1.0/}channel at 40436b2c>,
http://purl.org/rss/ 1.0/}title at 40436dcc>,
http://purl.org/rss/1.0/}link at 40436d6c>,
< Element {http://purl.org/rss/1.0/}description at 40436e0c>,
http://pur l.org/rss/1.0/}image at 40436e6c>,
http://purl.org/rss/1.0/}items at 4 0436f2c>, http://www.w3.org/1999/02/22-rdf-syntax-ns#}Seq at 40436f6c> ,
http://www.w3.org/1999/02/22-rdf-syntax-ns#}li at
40436f0c>,
http://www.w3.org/1999/02/22-rdf-syntax-ns#}li at
40436fec>,
http://purl.org/rss /1.0/}item at 4044624c>,
http://purl.org/rss/1.0/}title at 4044626c>,
http://purl.org/rss/1.0/}description at 4044614c>,
http://purl.org/rss/1.0/}link at 4044630c>,
http://purl.org/rss/1.0/}item at 40 4463ac>,
http://purl.org/rss/1.0/}title at 404463cc>,
,
http://purl.org/rss/1.0/} link at 4044640c>]

Any ideas are greatly appreciated.

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


Re: Is LOAD_GLOBAL really that slow?

2007-08-30 Thread Rhamphoryncus
On Aug 29, 8:33 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Wed, 2007-08-29 at 19:23 -0600, Adam Olsen wrote:
> > It seems a common opinion that global access is much slower than local
> > variable access.  However, my benchmarks show a relatively small
> > difference:
>
> > ./python -m timeit -r 10 -v -s 'x = [None] * 1
> > def foo():
> >   for i in x:
> > list; list; list; list; list; list; list; list; list; list' 'foo()'
> > 10 loops -> 0.0989 secs100 loops -> 0.991 secs
> > raw times: 0.999 0.985 0.987 0.985 0.985 0.982 0.982 0.982 0.981 0.985
> > 100 loops, best of 10: 9.81 msec per loop
>
> > ./python -m timeit -r 10 -v -s 'x = [None] * 1
> > def foo():
> >   mylist = list
> >   for i in x:
> > mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist;
> > mylist; mylist' 'foo()'
> > 10 loops -> 0.0617 secs
> > 100 loops -> 0.61 secs
> > raw times: 0.603 0.582 0.582 0.583 0.581 0.583 0.58 0.583 0.584 0.582
> > 100 loops, best of 10: 5.8 msec per loop
>
> > So global access is about 70% slower than local variable access.  To
> > put that in perspective, two local variable accesses will take longer
> > than a single global variable access.
>
> > This is a very extreme benchmark though.  In practice, other overheads
> > will probably drop the difference to a few percent at most.  Not that
> > important in my book.
>
> Your comparison is flawed, because the function call and the inner for
> loop cause a measurement offset that makes the locals advantage seems
> smaller than it is. In the interest of comparing the times for just the
> local lookup versus just the global lookup, I think the following
> timings are more appropriate:

That's why I used far more name lookups, to minimize the overhead.


> $ python2.5 -mtimeit -r10 -s"y=42" -s"def f(x): pass" "f(42)"
> 100 loops, best of 10: 0.3 usec per loop
> $ python2.5 -mtimeit -r10 -s"y=42" -s"def f(x): x" "f(42)"
> 100 loops, best of 10: 0.331 usec per loop
> $ python2.5 -mtimeit -r 10 -s"y=42" -s"def f(x): y" "f(42)"
> 100 loops, best of 10: 0.363 usec per loop

On my box, the best results I got after several runs were 0.399,
0.447, 0464.  Even less difference than my original results.


> There is no loop overhead here, and after subtracting the function call
> overhead, I get 31 nanoseconds per local lookup and 63 nanoseconds per
> global lookup, so local lookups are just about twice as fast as global
> lookups.
>
> True, whether this difference is significant does depend on how many
> name lookups your code makes and how much else it's doing, but if you're
> doing a lot of number crunching and not a lot of I/O, the difference
> might be significant. Also, even if using local names is only slightly
> faster than using globals, it's still not slower, and the resulting code
> is still more readable and more maintainable. Using locals is a win-win
> scenario.

You get very small speed gains (assuming your code is doing anything
significant), for a lot of effort (trying out different options,
seeing if they're actually faster on different boxes.)  The
readability cost is there, even if it is smaller than many of the
other obfuscations people attempt.  If the speed gains were really
that important you should rewrite in C, where you'd get far greater
speed gains.

So it only seems worthwhile when you really, *really* need to get a
slight speedup on your box, you don't need to get any more speedup
than that, and C is not an option.

Fwiw, I posted this after developing yet another patch to optimize
global lookups.  It does sometimes show an improvement on specific
benchmarks, but overall it harms performance.  Looking into why, it
doesn't make sense that a python dictionary lookup can have less cost
than two simple array indexes, but there you go.  Python dictionaries
are already damn fast.

--
Adam Olsen, aka Rhamphoryncus

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


Re: list index()

2007-08-30 Thread zzbbaadd
>
> How could it not be an exception, in the plain English sense of the
> word? Most certainly you're asking for the index because you want to do
> something with the index. If the item is not found, you have no index,
> so that's a special case that must be handled separately. There is no
> logical difference between handling that special case in an except
> clause versus handling it with an if-branch.

In my case of have done os.listdir() on two directories. I want to see
what files are in directory A that are not in directory B.
I have used exceptions in other languages and only do so on logic that
should never happen. In this case it is known that some of the files
will not be in both lists. I just want to know which ones.

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


Re: Python doesn't see the directories I create

2007-08-30 Thread Steve Holden
Steve Holden wrote:
[...]
> The fact is that some strings are always going to cause trouble. 
> Unfortunately programming itself is a task that requires a little more 
> knowledge to be applied to the task. Just learn the rules and move on.

As a quick follow-up, I had intended to comment on the usefulness of 
"verbatim literals".

string a = "hello, world";  // hello, world
string b = @"hello, world"; // hello, world
string c = "hello \t world";// hello world
string d = @"hello \t world";   // hello \t world
string e = "Joe said \"Hello\" to me";  // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me
string g = "server\\share\\file.txt";   // \\server\share\file.txt
string h = @"\\server\share\file.txt";  // \\server\share\file.txt
string i = "one\r\ntwo\r\nthree";

The @ character introduces a verbatim literal, and you can see from the 
examples given that they are implement a mixture of raw-string and 
triple-quote capabilities (even allowing multi-line string constants). I 
haven't fired up Visual Studio to verify, but I imagine you can even end 
a verbatim literal with a back-quote.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: list index()

2007-08-30 Thread Robert Kern
[EMAIL PROTECTED] wrote:
>> How could it not be an exception, in the plain English sense of the
>> word? Most certainly you're asking for the index because you want to do
>> something with the index. If the item is not found, you have no index,
>> so that's a special case that must be handled separately. There is no
>> logical difference between handling that special case in an except
>> clause versus handling it with an if-branch.
> 
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> I have used exceptions in other languages and only do so on logic that
> should never happen.

Python is different than those languages. Exceptions are used much more
frequently in Python and often for things that will *definitely* happen not just
those things that shouldn't.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: list index()

2007-08-30 Thread zzbbaadd
On Aug 30, 12:42 am, Bruno Desthuilliers  wrote:
> [EMAIL PROTECTED] a écrit :
>

> What's with using your brain instead of whining ?

I knew there would be at least one religious zealot.


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

Re: Python doesn't see the directories I create

2007-08-30 Thread Neil Cerutti
On 2007-08-30, Steve Holden <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> To me, Python's collection of special-purpose string literal
>> notations is one of its little warts.
>
> Well, it's a wart that's shared with many other languages -
> including, interestingly enough, Microsoft's very own C#, from
> whose documentation the following examples are taken:
>
> string a = "hello, world";  // hello, world
> string b = @"hello, world"; // hello, world
> string c = "hello \t world";// hello world
> string d = @"hello \t world";   // hello \t world
> string e = "Joe said \"Hello\" to me";  // Joe said "Hello" to me
> string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me
> string g = "server\\share\\file.txt";   // \\server\share\file.txt
> string h = @"\\server\share\file.txt";  // \\server\share\file.txt
> string i = "one\r\ntwo\r\nthree";

Still, that's only two.

> The fact is that some strings are always going to cause
> trouble. Unfortunately programming itself is a task that
> requires a little more knowledge to be applied to the task.

Or fortunately, depending on the dictates of your temperament. ;)

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


Re: list index()

2007-08-30 Thread Steve Holden
[EMAIL PROTECTED] wrote:
>> How could it not be an exception, in the plain English sense of the
>> word? Most certainly you're asking for the index because you want to do
>> something with the index. If the item is not found, you have no index,
>> so that's a special case that must be handled separately. There is no
>> logical difference between handling that special case in an except
>> clause versus handling it with an if-branch.
> 
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> I have used exceptions in other languages and only do so on logic that
> should never happen. In this case it is known that some of the files
> will not be in both lists. I just want to know which ones.
> 
And, as is so often the case, once the *real* problem is stated a more 
elegant solution become available - in this case, using sets.

afiles = set(os.listdir(dira))
bfiles = set(os.listdir(dirb))

for f in (afiles - bfiles):
   print "Not common:", f


You can also generate the files that are in one directory but ot the 
other with

(afiles | bfiles) - (afiles & bfiles)

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Is LOAD_GLOBAL really that slow?

2007-08-30 Thread Chris Mellon
On 8/30/07, Rhamphoryncus <[EMAIL PROTECTED]> wrote:
> On Aug 29, 8:33 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > On Wed, 2007-08-29 at 19:23 -0600, Adam Olsen wrote:
> > There is no loop overhead here, and after subtracting the function call
> > overhead, I get 31 nanoseconds per local lookup and 63 nanoseconds per
> > global lookup, so local lookups are just about twice as fast as global
> > lookups.
> >

__builtins__ lookups are an extra dict lookup slower than just global
variables, too. Don't forget those.


> > True, whether this difference is significant does depend on how many
> > name lookups your code makes and how much else it's doing, but if you're
> > doing a lot of number crunching and not a lot of I/O, the difference
> > might be significant. Also, even if using local names is only slightly
> > faster than using globals, it's still not slower, and the resulting code
> > is still more readable and more maintainable. Using locals is a win-win
> > scenario.
>
> You get very small speed gains (assuming your code is doing anything
> significant), for a lot of effort (trying out different options,
> seeing if they're actually faster on different boxes.)  The
> readability cost is there, even if it is smaller than many of the
> other obfuscations people attempt.  If the speed gains were really
> that important you should rewrite in C, where you'd get far greater
> speed gains.
>

I've doubled the speed of a processing loop by moving globals lookups
out of the loop. Rewriting in C would have taken at least a day, even
with Pyrex, localizing the lookup took about 2 minutes.

> So it only seems worthwhile when you really, *really* need to get a
> slight speedup on your box, you don't need to get any more speedup
> than that, and C is not an option.
>

It's not a huge optimization, but it's really easy to write if you
don't mind adding fake kwargs to your functions. Just for the heck of
it I also wrote a decorator that will re-write the bytecode so that
any global that can be looked up at function definition will be
re-written as a local (actually with LOAD_CONST). You can see it at
http://code.google.com/p/wxpsvg/wiki/GlobalsOptimization. Disclaimer:
While I've tested it with a variety of functions and it's never broken
anything, I've never actually used this for anything except an
intellectual exercise. Use at your own risk.

> Fwiw, I posted this after developing yet another patch to optimize
> global lookups.  It does sometimes show an improvement on specific
> benchmarks, but overall it harms performance.  Looking into why, it
> doesn't make sense that a python dictionary lookup can have less cost
> than two simple array indexes, but there you go.  Python dictionaries
> are already damn fast.
>

I certainly believe that changes to pythons internals to try to make
LOAD_GLOBAL itself faster can be difficult, with even "obvious"
optimizations ending up slower. However, LOAD_FAST (and LOAD_CONST)
are faster than LOAD_GLOBAL and, for the reason you just stated, is
unlikely to change.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 10:44 -0700, [EMAIL PROTECTED] wrote:
> >
> > How could it not be an exception, in the plain English sense of the
> > word? Most certainly you're asking for the index because you want to do
> > something with the index. If the item is not found, you have no index,
> > so that's a special case that must be handled separately. There is no
> > logical difference between handling that special case in an except
> > clause versus handling it with an if-branch.
> 
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> [...]

list.index() is the wrong tool for that job. Python has sets, use them.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 10:56 -0700, [EMAIL PROTECTED] wrote:
> On Aug 30, 12:42 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] a crit :
> >
> 
> > What's with using your brain instead of whining ?
> 
> I knew there would be at least one religious zealot.

While I agree that Bruno's response was perhaps needlessly snippy, your
original question was needlessly inflammatory, as if you somehow wanted
some "religious zealot" to act the way Bruno did. If we start labeling
people, this thread will earn you a label that rhymes with "roll".

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: gc.garbage

2007-08-30 Thread 7stud
On Aug 30, 3:50 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > gc.set_debug(gc.DEBUG_LEAK)
> > print gc.garbage
>
> > --output:--
> > []
> > gc: uncollectable 
> > gc: uncollectable 
> > gc: uncollectable 
> > gc: uncollectable 
>
> gc.garbage is filled only after these messages
> are printed, not before. You need to add an explicit
> call to gc.collect() if you want to see what
> uncollectable garbage you have.
>
> Regards,
> Martin

Hi,

Thanks for the response.  Now, when I run the code:


import gc

class Cat(object):
pass

class Dog(object):
pass

def some_func():
the_dog = Dog()
the_cat = Cat()
the_dog.cat = the_cat
the_cat.dog = the_dog

some_func()

gc.set_debug(gc.DEBUG_LEAK)
gc.collect()
print gc.garbage


I get this output:

-
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
[<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
{'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
object at 0x56e10>}]
---

Why are there two entries in the list for each uncollectable object?
Also, I haven't bound the names "cat" or "dog" anywhere in my
program.  What do those names mean in the list?

Doing some more testing, if I remove the __del__ methods:

---
class Cat(object):
pass

class Dog(object):
pass

def some_func():
the_dog = Dog()
the_cat = Cat()
the_dog.cat = the_cat
the_cat.dog = the_dog

some_func()

gc.set_debug(gc.DEBUG_LEAK)
gc.collect()
print gc.garbage
---

I get this output:

-
gc: collectable 
gc: collectable 
gc: collectable 
gc: collectable 
[<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
{'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
object at 0x56e10>}]


Now the objects are marked as collectable.  The docs say:


garbage
A list of objects which the collector found to be unreachable but
could not be freed (uncollectable objects).


So, I expected gc.garbage to be empty.  The docs also say:


garbage
...By default, this list contains only objects with __del__() methods.



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

Re: list index()

2007-08-30 Thread Neil Cerutti
On 2007-08-30, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> How could it not be an exception, in the plain English sense
>> of the word? Most certainly you're asking for the index
>> because you want to do something with the index. If the item
>> is not found, you have no index, so that's a special case that
>> must be handled separately. There is no logical difference
>> between handling that special case in an except clause versus
>> handling it with an if-branch.
>
> In my case of have done os.listdir() on two directories. I want
> to see what files are in directory A that are not in directory
> B.

In that case list.find would not be much of a win, but sets might
be.

 not_in_both = list(set(os.listdir("A")) - set(os.listdir("B")))

> I have used exceptions in other languages and only do so on
> logic that should never happen. In this case it is known that
> some of the files will not be in both lists. I just want to
> know which ones.

"Exceptions" has become somewhat a misnomer. iterators are
implemented using exceptions, and there's hardly anything more
common in modern Python code. The hair shirts and thumb-screws
necessary for using exceptions correctly in C++, aren't needed in
Python.

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


RE: list index()

2007-08-30 Thread Hamilton, William
> From: [EMAIL PROTECTED]
> >
> > How could it not be an exception, in the plain English sense of the
> > word? Most certainly you're asking for the index because you want to
do
> > something with the index. If the item is not found, you have no
index,
> > so that's a special case that must be handled separately. There is
no
> > logical difference between handling that special case in an except
> > clause versus handling it with an if-branch.
> 
> In my case of have done os.listdir() on two directories. I want to see
> what files are in directory A that are not in directory B.
> I have used exceptions in other languages and only do so on logic that
> should never happen. In this case it is known that some of the files
> will not be in both lists. I just want to know which ones.
> 

I think you may be confusing exceptions and assertions.  Asserts are
generally used to trap conditions that should not happen, while
exceptions in Python are a standardized way to handle errors of all
sorts.  Where in C you would, say, open a file and check the return code
to ensure that the file actually exists before using it, in Python you
wrap the open statement in a try/except block instead.


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


Re: list index()

2007-08-30 Thread zzbbaadd
> While I agree that Bruno's response was perhaps needlessly snippy, your
> original question was needlessly inflammatory, as if you somehow wanted
> some "religious zealot" to act the way Bruno did. If we start labeling
> people, this thread will earn you a label that rhymes with "roll".
>
That is correct. I did word it in a way that would hook the Bruno's of
the group. But I will probably have some more important questions so I
will word it differently in the future. Such as: I wish they were not
getting rid of dict.has_key() in Python 3, which I prefer to IN.


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


Re: list index()

2007-08-30 Thread zzbbaadd
Neil, Steve,

Thanks for the responses on sets. I have not used them before and was
not even aware Python had them. I will try them out.


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


Re: gc.garbage

2007-08-30 Thread 7stud
On Aug 30, 3:50 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > gc.set_debug(gc.DEBUG_LEAK)
> > print gc.garbage
>
> > --output:--
> > []
> > gc: uncollectable 
> > gc: uncollectable 
> > gc: uncollectable 
> > gc: uncollectable 
>
> gc.garbage is filled only after these messages
> are printed, not before. You need to add an explicit
> call to gc.collect() if you want to see what
> uncollectable garbage you have.
>
> Regards,
> Martin

Hi,

Thanks for the response.  I had a cut and paste error in my reply, so
here it is again with the corrections...

Now, if I run the code:


import gc

class Cat(object):
def __del__():
pass

class Dog(object):
def __del__():
pass

def some_func():
the_dog = Dog()
the_cat = Cat()
the_dog.cat = the_cat
the_cat.dog = the_dog

some_func()

gc.set_debug(gc.DEBUG_LEAK)
gc.collect()
print gc.garbage
---

I get this output:

--
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
gc: uncollectable 
[<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
{'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
object at 0x56e10>}]
---

Why are there two entries in the list for each uncollectable
object(same addresses)?  Also, I haven't bound the names "cat" or
"dog" anywhere in my program.  What do those names mean in the list?

Doing some further testing, if I eliminate the __del__ methods:

---
import gc

class Cat(object):
pass

class Dog(object):
pass

def some_func():
the_dog = Dog()
the_cat = Cat()
the_dog.cat = the_cat
the_cat.dog = the_dog

some_func()

gc.set_debug(gc.DEBUG_LEAK)
gc.collect()
print gc.garbage
---

I get this output:

-
gc: collectable 
gc: collectable 
gc: collectable 
gc: collectable 
[<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
{'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
object at 0x56e10>}]
-

The docs say:

-
garbage
A list of objects which the collector found to be unreachable but
could not be freed (uncollectable objects).


Since debugging doesn't show any uncollectable objects, why isn't
gc.garbage empty?  The docs also say:


garbage
...By default, this list contains only objects with __del__() methods.


Does set_debug() change the default?

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

Re: Creating a multi-tier client/server application

2007-08-30 Thread Jeff
Wow, there's a lot to respond to here.  Thanks everyone for your
help.  I'll try to go in order.

askel: Thanks, I've looked at this a little bit before, but now I've
looked into it a little further.  Seems pretty cool, but also fairly
complex.  Have you used it before?

David: Sounds like a pretty interesting app.  Thanks for the in-depth
description.  I went and checked out Twisted PB, and it seems
awesome.  I may very well go with that.  How was writing code with
it?  I may also end up using py2app, but I'm also going to have to
support Windows, (p2exe, then), and possibly Linux.  Well, maybe not
Linux, but I'll probably be doing most of the development in Linux, so
I guess that counts.

Paul:  Again, I appreciate all of your input.  Responses below--

> It's relatively easier to get someone like that involved
> in a project than someone who can do good visual stuff AND write code,
> as is (to some extent) needed for a client side GUI.
Well, it's going to be just me (maybe some part-time help, but nothing
I can rely on), so either way, I'm writing the whole thing.

>> 1) More responsive and user-friendly interfaces
> 1) is true in principle and but a heck of a lot of apps don't really
> use the capability.  There's tons of crappy gui apps out there that
> could be done just as well with no client installation.
Granted.  But what I will be writing really will take a lot of extra
work to get even close to the level of usability needed on the web vs.
a desktop app.  And I'll try not to write a crappy GUI ;-)

> 2) I don't understand this part.  Sort = server side.
> Export/import/printing: upload and download files?  Depending on your
> requirements a little bit of browser scripting may be enough to handle
> this.
Sorting certainly doesn't have to be done on the server side--in fact,
in most cases I can think of where it would be useful for this app, it
wouldn't have to be--in which case it's more responsive.  Certainly
exporting, importing and printing can all be done through the web--
I've done this plenty of times.  But there is a huge amount of
flexibility (and, in the case of printing, guaranteed style/quality/
layout) to be gained on the desktop.

For #3, see my previous response to Bruno.  It was a poor choice of
wording on my part.

As for the AJAX--I'm going to need to use it *a lot* for the sake of
my clients.  They're used to (and very much want) usable interfaces
that really can't be made without it.  And even if I use it liberally,
it still won't be anywhere as usable as a desktop application.

All that said, I am most likely going to go with a desktop
application.  In reality, I will have to do whatever my client wants.
Thank you *very* much for all of your input--one of the first things I
have to do is make them a list of the pros and cons of web vs. desktop
apps--and this will help a lot.

vanrpeter-whatever: Thanks for the support :-)  What did you use for
networking?  What ORMs did you try (or did you skip them altogether?)
As for what I'm building--it's a personnel tracking/payroll system--
see my first post for a fuller description.  Hours will be... well, a
lot.  Our current contract is for 4 days a week for a year, but that's
for development--I'm not sure how much of a support contract they'll
want afterwards, or if they'll want further development (probably).

Once again, thanks everyone!

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


Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 11:21 -0700, [EMAIL PROTECTED] wrote:
> I wish they were not
> getting rid of dict.has_key() in Python 3, which I prefer to IN.

That wish will only come true if you maintain your own fork of Python 3.
has_key() will go away, period. It has been made obsolete by "in", which
is faster and more concise.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: gc.garbage

2007-08-30 Thread Chris Mellon
On 8/30/07, 7stud <[EMAIL PROTECTED]> wrote:
> On Aug 30, 3:50 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > > gc.set_debug(gc.DEBUG_LEAK)
> > > print gc.garbage
> >
> > > --output:--
> > > []
> > > gc: uncollectable 
> > > gc: uncollectable 
> > > gc: uncollectable 
> > > gc: uncollectable 
> >
> > gc.garbage is filled only after these messages
> > are printed, not before. You need to add an explicit
> > call to gc.collect() if you want to see what
> > uncollectable garbage you have.
> >
> > Regards,
> > Martin
>
> Hi,
>
> Thanks for the response.  I had a cut and paste error in my reply, so
> here it is again with the corrections...
>
> Now, if I run the code:
>
> 
> import gc
>
> class Cat(object):
> def __del__():
> pass
>
> class Dog(object):
> def __del__():
> pass
>
> def some_func():
> the_dog = Dog()
> the_cat = Cat()
> the_dog.cat = the_cat
> the_cat.dog = the_dog
>
> some_func()
>
> gc.set_debug(gc.DEBUG_LEAK)
> gc.collect()
> print gc.garbage
> ---
>
> I get this output:
>
> --
> gc: uncollectable 
> gc: uncollectable 
> gc: uncollectable 
> gc: uncollectable 
> [<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
> {'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
> object at 0x56e10>}]
> ---
>
> Why are there two entries in the list for each uncollectable
> object(same addresses)?  Also, I haven't bound the names "cat" or
> "dog" anywhere in my program.  What do those names mean in the list?
>
Read your output carefully!

gc.garbage is a list of objects. The objects are printed just as they
would be anywhere else in Python. You've got the dog object, the cat
object, and the __dict__ of each instance.

> Doing some further testing, if I eliminate the __del__ methods:
>
> ---
> import gc
>
> class Cat(object):
> pass
>
> class Dog(object):
> pass
>
> def some_func():
> the_dog = Dog()
> the_cat = Cat()
> the_dog.cat = the_cat
> the_cat.dog = the_dog
>
> some_func()
>
> gc.set_debug(gc.DEBUG_LEAK)
> gc.collect()
> print gc.garbage
> ---
>
> I get this output:
>
> -
> gc: collectable 
> gc: collectable 
> gc: collectable 
> gc: collectable 
> [<__main__.Dog object at 0x56e10>, <__main__.Cat object at 0x56e30>,
> {'cat': <__main__.Cat object at 0x56e30>}, {'dog': <__main__.Dog
> object at 0x56e10>}]
> -
>
> The docs say:
>
> -
> garbage
> A list of objects which the collector found to be unreachable but
> could not be freed (uncollectable objects).
> 
>
> Since debugging doesn't show any uncollectable objects, why isn't
> gc.garbage empty?  The docs also say:
>
> 
> garbage
> ...By default, this list contains only objects with __del__() methods.
> 
>
> Does set_debug() change the default?
>

>From the last line of the documentation block you quoted above: "If
DEBUG_SAVEALL is set, then all unreachable objects will be added to
this list rather than freed."
-- 
http://mail.python.org/mailman/listinfo/python-list


create Powerpoint via com

2007-08-30 Thread Alan Isaac
Can someone point me to a simple example
or better yet tutorial for creating
a Powerpoint using Python.

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


Re: list index()

2007-08-30 Thread Steve Holden
[EMAIL PROTECTED] wrote:
>> While I agree that Bruno's response was perhaps needlessly snippy, your
>> original question was needlessly inflammatory, as if you somehow wanted
>> some "religious zealot" to act the way Bruno did. If we start labeling
>> people, this thread will earn you a label that rhymes with "roll".
>>
> That is correct. I did word it in a way that would hook the Bruno's of
> the group. But I will probably have some more important questions so I
> will word it differently in the future. Such as: I wish they were not
> getting rid of dict.has_key() in Python 3, which I prefer to IN.
> 
> 
Well, again Python gives you the flexibility to define your own dict 
subclass that has a has_key() method with the obvious implementation.

But why would you want to ignore built-in support like "value in dict"?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: list index()

2007-08-30 Thread zzbbaadd

> That wish will only come true if you maintain your own fork of Python 3.
> has_key() will go away, period. It has been made obsolete by "in", which
> is faster and more concise.

Is there really some reason  "key" IN dict can be implemented faster
than dict.has_key("key")???



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


Re: Important Research Project

2007-08-30 Thread CBFalconer
"E.D.G." wrote:
> 
> This report is being posted to a number of Internet Newsgroups to
> see if there are any experienced computer programmers who would
> like to provide some assistance with an effort to develop a Perl
> language computer program.

Where is Perl described in the C standard?  This seems rather OT.

-- 
 Chuck F (cbfalconer at maineline dot net)
   Available for consulting/temporary embedded and systems.
   


-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Chris Mellon
On 8/29/07, Russ <[EMAIL PROTECTED]> wrote:
>
> > But it's always a good idea to make your software "correct and as
> > reliable as possible", isn't it? The problem is the external constraints
> > on the project. As the old saying goes: "Cheap, fast, reliable: choose
> > any two".
>
> If you are suggesting that "programming by contract" is not
> appropriate for every application, you will get no argument from me.
> All I am suggesting is that having the option to use it when you need
> it is very desirable, and it can possibly enhance the versatility of
> Python by making Python more suitable for *some* mission-critical
> applications.
>

PEP 316 introduces new syntax for a limited use feature. That's pretty
much a no-starter, in my opinion, and past experience tends to bear
that out. Furthermore, it predates decorators  and context managers,
which give all the syntax support you need and let you move the actual
DBC features into a library. I can't remember if I mentioned this
before but I believe that Philip Ebys PEAK toolkit has some stuff you
could use for DBC.

> I once read a book on something called SPARK Ada, which also supports
> programming by contract. I was pleasantly surprised to discover
> yesterday that support for the such methods is also available for
> Python. However, the support would obviously be a bit stronger if it
> were in the core Python distribution.
>

If a well written contract library were to exist, and people were to
use it, and the author were interested, it would make a decent
candidate for inclusion in the standard library, and I wouldn't oppose
such a thing (for all my opinion is worth, ie essentially nothing).
The PEP 316 special syntax is another matter entirely.

The best way for this to happen is for you to find or write such a
library, and use it to write good code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Neil Cerutti
On 2007-08-30, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> That wish will only come true if you maintain your own fork of
>> Python 3. has_key() will go away, period. It has been made
>> obsolete by "in", which is faster and more concise.
>
> Is there really some reason  "key" IN dict can be implemented
> faster than dict.has_key("key")???

Yes. Looking up the has_key method by name is the slower part.

-- 
Neil Cerutti
We're not afraid of challenges. It's like we always say: If you want to go out
in the rain, be prepared to get burned. --Brazillian soccer player
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list index()

2007-08-30 Thread Chris Mellon
On 8/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > That wish will only come true if you maintain your own fork of Python 3.
> > has_key() will go away, period. It has been made obsolete by "in", which
> > is faster and more concise.
>
> Is there really some reason  "key" IN dict can be implemented faster
> than dict.has_key("key")???
>

Yes. As an exercise, I wont tell you the first most obvious reason -
see if you can figure it out. The dis module may help.
-- 
http://mail.python.org/mailman/listinfo/python-list


pure python for sms

2007-08-30 Thread Gerardo Herzig
Hi dudes. Im looking for a python implementation for sending sms to a 
cell phone. I was try using some free pages, but i want to use a python. 
Do i need a cellphone conected to my machine? Or can i send sms to some 
cell via some python library?

Waiting for advice.
Thanks!

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


Re: We need PIGs :)

2007-08-30 Thread [EMAIL PROTECTED]
On Aug 30, 12:10 am, "Martin Marcher" <[EMAIL PROTECTED]>
wrote:

[snip!]
>
> My idea was to define "Python Implementation Guidelines" (PIGs) that
> specify a problem formalize it enough so that implementations are
> interchangeable (in this example create a module that has an
> "authenticate(username, password)" method so that one could easily
> take that module for any given app and then authenticate against
> postgres, and also against my plaintext file (which was the original -
> quite useless - implementation).
>
> Does that sound like a good idea or would that be over formalization?
>

This may be over-formalization.  For specific problems, there
generally is a pythonic choice.  For instance, suppose your problem is
'I need an ORM' - well the pythonic choice is something along the
lines of SQLObject or SQLAlchemy.

Then there are other cases where there are too many choices - "I need
a web framework." -- turbogears, django, pylons, and whatever else you
want to throw into the pot.  (Be smart, choose pylons [just kidding,
but I did promote pylons and attach a just kidding disclaimer --
clever, huh?])

> Personally I think that would be great as I could search the PIGs at
> (hopefully) python.org find out the number and search at koders.com or
> code.google.com for python code that has "PIG: XXX" in the metadata
> docstring or wherever - maybe even a __pig__ = XXX variable.
>

I think most of what you're after may be in the python cookbook
(http://aspn.activestate.com/ASPN/Cookbook/Python) or the PyPi (http://
pypi.python.org/pypi).
> any input is welcome (also point me to the place where that can be
> found if it already exists)
> martin

Or maybe I completely misunderstand what you mean.

G' Day!
jw

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


Re: Important Research Project

2007-08-30 Thread dave_w
On Aug 30, 2:54 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Aug 30, 8:12 am, "E.D.G." <[EMAIL PROTECTED]> wrote:
>
> > Important Research Project  (Related to computer programming)
>
> > Posted by E.D.G. on August 30, 2007 [EMAIL PROTECTED]
>
> > This report is being posted to a number of Internet Newsgroups
>
> Always the hallmark of a considerate poster.
>
> > to see if
> > there are any experienced computer programmers who would like to provide
> > some assistance with an effort to develop a Perl language computer program.
>
> > Interested parties can try contacting me by e-mail or by posting a
> > response note to the comp.lang.perl.misc newsgroup.  They would need to
> > download a recent (free) MSI copy of Perl from the ActiveState Web site and
> > get it running on a Windows XP or Vista system.
>
> >http://www.activestate.com
>
> This is a little backwards, one usually presents their research topic
> *first* and their contact info *last*.  The reason?  SO PEOPLE KNOW
> WHAT THE @#$(&#!@ YOU ARE WORKING ON!  Ok, I'll bite, keep reading...
>
> > I am presently using Perl 5.8.8
>
> Whoop-de-doo for you.
>
> > but plan to upgrade to the latest
> > version as soon as possible.  People can use Windows 98 if that is the only
> > operating system available.  Perl also runs on other operating systems.  But
> > at this time I specifically need help with the Windows version.
>
> I suspect Perl is largely the same Perl on all those platforms.  Win
> 98?  Is this a zombie spam from the turn of the century?
>
> > The goal is to have a single Perl program (or modules) perform functions
> > that have been done by a sizeable collection of other language programs in
> > the past.
>
> Doing what!?  Grrr..., keep reading, there's gotta be a punch line...
>
> > Help is presently needed with learning how to get Perl to generate
> > charts and also produce standalone .exe copies of itself.  The plan is to
> > then make those .exe copies available to other scientific researchers around
> > the world for free use along with free use updates when they become
> > available.  If other researchers wish to get Perl running on their own
> > computers then they will probably also be given the source code for the
> > original program for free use so that they can do their own development
> > work.
>
> Ohmigod, is Google broken?  Or has Perl gone this long and this far
> without support for creating charts and graphs?  Sounds like about 10
> minutes of research.
>
> > Perl was originally chosen because it is quite versatile, is a free
> > download, and is supported both by ActiveState and quite a few independent
> > programmers.  So other researchers could get their own versions running
> > without having to worry about viruses or cost.
>
> (Why is this posted on all these non-Perl newsgroups, then?  I've
> *seen* Perl already, and never want to again!)
>
> > So far the work is fairly advanced.  The effort has been underway for at
> > least a decade.  
>
> ... and we are just getting around to plotting some data.
>
> > The core data generation program was formally copyrighted
> > several years ago.  
>
> Red flag #37 - "formally copyrighted", wooo-h
>
> > My present version of Perl will send data to Windows as
> > if it were being manually typed into the keyboard (important for controlling
> > other programs).  And it can directed to respond to most keystrokes even
> > when another program is the active one.  Unfortunately, Windows also
> > presently responds to those keystrokes.  And that complicates things a bit.
>
> ... and has for the past decade, and I still haven't figured it out.
>
> > Not being a professional computer programmer I have been finding it
> > difficult to get new features such as a chart generating ability merged with
> > and running with Perl.  And the entire research project is now being slowed
> > as a result.  One of my colleagues has done an extensive amount of work with
> > Basic.  And I even offered to pay him to help with the Perl development
> > effort.  But after he downloaded a copy of Perl and examined it he decided
> > that this would involve too much effort.  I have to agree with him.
>
> Maybe that up-front language choice could stand a review...
>
> > Once it is possible to create charts and .exe versions the plan is for
> > researchers around the world to develop Perl modules for generating a
> > variety of data related to sun, moon, planet, ocean tide crest and trough,
> > and Solid Earth Tide locations.  Most of those data can already be generated
> > with other programs.  Some of the data are not yet available anywhere as far
> > as I am aware.  If the effort is unusually successful the Perl program (or
> > modules) might eventually be converted to CGI programs that will run at one
> > or more Internet Web sites.
>
> AHHH!  The "research", I almost forgot!  Why is it left to the end of
> the message?  And do we still know what the @#(*&$ this "vari

subclassing Python types

2007-08-30 Thread zzbbaadd
I have read that you can derive from the base classes such as str,
list, dict.

I guess this would look like:

def MyString(str):
def MyList(list):
def MyDict(dict):


How do you access the data that is contained in the super class?

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


Re: Important Research Project

2007-08-30 Thread Tim Couper
Paul

Excellent post  .. brightens up the otherwise hum-drum life!

Tim

Dr Tim Couper
CTO, SciVisum Ltd

www.scivisum.com



Paul McGuire wrote:
> On Aug 30, 8:12 am, "E.D.G." <[EMAIL PROTECTED]> wrote:
>   
>> Important Research Project  (Related to computer programming)
>>
>> Posted by E.D.G. on August 30, 2007 [EMAIL PROTECTED]
>>
>> This report is being posted to a number of Internet Newsgroups
>> 
>
> Always the hallmark of a considerate poster.
>
>   
>> to see if
>> there are any experienced computer programmers who would like to provide
>> some assistance with an effort to develop a Perl language computer program.
>>
>> Interested parties can try contacting me by e-mail or by posting a
>> response note to the comp.lang.perl.misc newsgroup.  They would need to
>> download a recent (free) MSI copy of Perl from the ActiveState Web site and
>> get it running on a Windows XP or Vista system.
>>
>> http://www.activestate.com
>>
>> 
>
> This is a little backwards, one usually presents their research topic
> *first* and their contact info *last*.  The reason?  SO PEOPLE KNOW
> WHAT THE @#$(&#!@ YOU ARE WORKING ON!  Ok, I'll bite, keep reading...
>
>   
>> I am presently using Perl 5.8.8
>> 
>
> Whoop-de-doo for you.
>
>   
>> but plan to upgrade to the latest
>> version as soon as possible.  People can use Windows 98 if that is the only
>> operating system available.  Perl also runs on other operating systems.  But
>> at this time I specifically need help with the Windows version.
>>
>> 
>
> I suspect Perl is largely the same Perl on all those platforms.  Win
> 98?  Is this a zombie spam from the turn of the century?
>
>   
>> The goal is to have a single Perl program (or modules) perform functions
>> that have been done by a sizeable collection of other language programs in
>> the past.
>>
>> 
>
> Doing what!?  Grrr..., keep reading, there's gotta be a punch line...
>
>   
>> Help is presently needed with learning how to get Perl to generate
>> charts and also produce standalone .exe copies of itself.  The plan is to
>> then make those .exe copies available to other scientific researchers around
>> the world for free use along with free use updates when they become
>> available.  If other researchers wish to get Perl running on their own
>> computers then they will probably also be given the source code for the
>> original program for free use so that they can do their own development
>> work.
>>
>> 
>
> Ohmigod, is Google broken?  Or has Perl gone this long and this far
> without support for creating charts and graphs?  Sounds like about 10
> minutes of research.
>
>   
>> Perl was originally chosen because it is quite versatile, is a free
>> download, and is supported both by ActiveState and quite a few independent
>> programmers.  So other researchers could get their own versions running
>> without having to worry about viruses or cost.
>>
>> 
>
> (Why is this posted on all these non-Perl newsgroups, then?  I've
> *seen* Perl already, and never want to again!)
>
>   
>> So far the work is fairly advanced.  The effort has been underway for at
>> least a decade.  
>> 
>
> ... and we are just getting around to plotting some data.
>
>   
>> The core data generation program was formally copyrighted
>> several years ago.  
>> 
>
> Red flag #37 - "formally copyrighted", wooo-h
>
>   
>> My present version of Perl will send data to Windows as
>> if it were being manually typed into the keyboard (important for controlling
>> other programs).  And it can directed to respond to most keystrokes even
>> when another program is the active one.  Unfortunately, Windows also
>> presently responds to those keystrokes.  And that complicates things a bit.
>>
>> 
>
> ... and has for the past decade, and I still haven't figured it out.
>
>   
>> Not being a professional computer programmer I have been finding it
>> difficult to get new features such as a chart generating ability merged with
>> and running with Perl.  And the entire research project is now being slowed
>> as a result.  One of my colleagues has done an extensive amount of work with
>> Basic.  And I even offered to pay him to help with the Perl development
>> effort.  But after he downloaded a copy of Perl and examined it he decided
>> that this would involve too much effort.  I have to agree with him.
>>
>> 
>
> Maybe that up-front language choice could stand a review...
>
>   
>> Once it is possible to create charts and .exe versions the plan is for
>> researchers around the world to develop Perl modules for generating a
>> variety of data related to sun, moon, planet, ocean tide crest and trough,
>> and Solid Earth Tide locations.  Most of those data can already be generated
>> with other programs.  Some of the data are not yet available anywhere as far
>> as I am aware.  If the effort is unusually successful the Perl program (or
>> modules) might eventually be converted to

Re: list index()

2007-08-30 Thread Carsten Haese
On Thu, 2007-08-30 at 11:45 -0700, [EMAIL PROTECTED] wrote:
> > That wish will only come true if you maintain your own fork of Python 3.
> > has_key() will go away, period. It has been made obsolete by "in", which
> > is faster and more concise.
> 
> Is there really some reason  "key" IN dict can be implemented faster
> than dict.has_key("key")???

Yes, see e.g.
http://groups.google.com/group/comp.lang.python/msg/03e9b4276846b9c0

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: create Powerpoint via com

2007-08-30 Thread kyosohma
Alan,

On Aug 30, 1:37 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
> Can someone point me to a simple example
> or better yet tutorial for creating
> a Powerpoint using Python.
>
> Thanks,
> Alan Isaac

You should check our the following for information on using COM
itself:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Core Python Programming by Chun has an example in it using Tkinter. I
did it a while back, so here's the source:




# Core Python Chp 23, pg 994
# ppoint.pyw

from Tkinter import Tk
from time import sleep
from tkMessageBox import showwarning
import win32com.client as win32

warn = lambda app: showwarning(app, 'Exit?')
RANGE = range(3, 8)

def ppoint():
app = 'PowerPoint'
ppoint = win32.gencache.EnsureDispatch('%s.Application' % app)
pres = ppoint.Presentations.Add()
ppoint.Visible = True

s1 = pres.Slides.Add(1, win32.constants.ppLayoutText)
sleep(1)
sla = s1.Shapes[0].TextFrame.TextRange
sla.Text = 'Python-to-%s Demo' % app
sleep(1)
slb = s1.Shapes[1].TextFrame.TextRange
for i in RANGE:
slb.InsertAfter("Line %d\r\n" % i)
sleep(1)
slb.InsertAfter("\r\nTh-th-th-that's all folks!\r\n")

warn(app)
pres.Close()
ppoint.Quit()

if __name__ == '__main__':
Tk().withdraw()
ppoint()



I recommend getting ActiveState's Python distro as it comes with an
IDE that can browse COM objects fairly easily.

Hope that helps!

Mike

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


Re: list index()

2007-08-30 Thread MRAB
On Aug 30, 7:00 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> >> How could it not be an exception, in the plain English sense of the
> >> word? Most certainly you're asking for the index because you want to do
> >> something with the index. If the item is not found, you have no index,
> >> so that's a special case that must be handled separately. There is no
> >> logical difference between handling that special case in an except
> >> clause versus handling it with an if-branch.
>
> > In my case of have done os.listdir() on two directories. I want to see
> > what files are in directory A that are not in directory B.
> > I have used exceptions in other languages and only do so on logic that
> > should never happen. In this case it is known that some of the files
> > will not be in both lists. I just want to know which ones.
>
> And, as is so often the case, once the *real* problem is stated a more
> elegant solution become available - in this case, using sets.
>
> afiles = set(os.listdir(dira))
> bfiles = set(os.listdir(dirb))
>
> for f in (afiles - bfiles):
>print "Not common:", f
>
> You can also generate the files that are in one directory but ot the
> other with
>
> (afiles | bfiles) - (afiles & bfiles)
>
... which can be written more concisely as:

afiles ^ bfiles

:-)

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


Re: list index()

2007-08-30 Thread MRAB
On Aug 30, 5:41 pm, [EMAIL PROTECTED] wrote:
> On Aug 30, 12:09 am, Ben Finney <[EMAIL PROTECTED]>
> wrote:
>
> > [EMAIL PROTECTED] writes:
> > > What's with the index() function of lists throwing an exception on not
> > > found?
>
> > It's letting you know that the item isn't in the list. There's no
> > sensible return value from an "index" function in that condition.
>
> for str:
>
> find(   sub[, start[, end]])
> Return the lowest index in the string where substring sub is
> found, such that sub is contained in the range [start, end]. Optional
> arguments start and end are interpreted as in slice notation. Return
> -1 if sub is not found.
>
> -1 is used in other languages as well.

In 0-based languages it's often -1 whereas in 1-based languages it's
often 0.

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


Re: subclassing Python types

2007-08-30 Thread Arnaud Delobelle
On Aug 30, 8:00 pm, [EMAIL PROTECTED] wrote:
> I have read that you can derive from the base classes such as str,
> list, dict.
>
> I guess this would look like:
>
> def MyString(str):
> def MyList(list):
> def MyDict(dict):

You mean

class MyString(str):
...

> How do you access the data that is contained in the super class?

The same way that you access plain strings, lists or dicts: use the
methods of the super class.

HTH

PS: it is not so often a good idea to derive a class from these types.

--
Arnaud


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


Re: subclassing Python types

2007-08-30 Thread zzbbaadd
On Aug 30, 12:13 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Aug 30, 8:00 pm, [EMAIL PROTECTED] wrote:
>
> > I have read that you can derive from the base classes such as str,
> > list, dict.
>
> > I guess this would look like:
>
> > def MyString(str):
> > def MyList(list):
> > def MyDict(dict):
>
> You mean
>
> class MyString(str):
> ...
>
> > How do you access the data that is contained in the super class?
>
> The same way that you access plain strings, lists or dicts: use the
> methods of the super class.
>

I don't know what name I would use to call a method:


class MyString(str):
def __init__(strInput):
   ? = strInput


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



Re: subclassing Python types

2007-08-30 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
> I have read that you can derive from the base classes such as str,
> list, dict.
> 
> I guess this would look like:
> 
> def MyString(str):
> def MyList(list):
> def MyDict(dict):
> 
> 
Well, replace 'def' with 'class' and you're right.

> How do you access the data that is contained in the super class?
> 
This way:
 >>> class MyList(list):
...def do_something(self):
...   self.append(3)
...   print self
...
 >>> l = MyList((1, 2))
 >>> l
[1, 2]
 >>> l.do_something()
[1, 2, 3]


That is: Whenever you want to refer to the value refer to self (that is, 
refer to the instance of your class).

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


  1   2   3   >