[Tutor] Accessing database

Kenneth Tsang smt@pacific.net.hk
Tue, 11 Sep 2001 16:40:39 +0800


Hi, I am working on an applications which need to have database access.
Please advise which module I should use (seems there are lot of them, lik=
e
sql.pyd-which I collect from zope, odbc.pyd-comes with win32 from Mark
Hammond's win32extensions...). And would like to see some sample code, if
possible.

My current development environment
win2000 running python
win32 extensions installed
wxPython installed use for front end development

Target database is ODBC based, (currently need to support MSAccess, MSSQL
and mySQL)

I have been looking around in web sites and different articles and no res=
ult
yet. Thanks.

cheers, Kenneth
--
Kenneth Tsang
email: smt@pacific.net.hk tel: +852 9468 4772
----- Original Message -----
From: <tutor-request@python.org>
To: <tutor@python.org>
Sent: Tuesday, September 11, 2001 12:01 AM
Subject: Tutor digest, Vol 1 #1081 - 13 msgs


Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-request@python.org

You can reach the person managing the list at
tutor-admin@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Re: Problem with IDLE in Windows (Kirby Urner)
   2. "Internal Server Error" (Jon Cosby)
   3. Re: "Internal Server Error" (Ignacio Vazquez-Abrams)
   4. Re: "Internal Server Error" (Kirby Urner)
   5. Re: i have a major problem (Sheila King)
   6. =CF=F0=EE=E4=E0=E6?=EF=EE=EA=F3=EF=EA?=EF=F0=EE=E4=F3=EA=F6=E8?=EF=EE=
=E8=F1?=EF=E0=F0=F2=ED=E5=F0=EE? (Anonymouse)
   7. RE: trouble running Grail (Simon Brunning)
   8. need some help (Sreenidhi.B.G)
   9. Windows IDE ..., Problems while executing python code ? (Ajaya Babu=
)
  10. Re: Help with cookies (James)
  11. RE: sending stdout to a text box (alan.gauld@bt.com)
  12. RE: sending stdout to a text box (Bill Tolbert)
  13. Re: trouble running Grail (Lance E Sloan)

--__--__--

Message: 1
Date: Sun, 09 Sep 2001 09:18:32 -0700
To: Charlie@begeistert.org
From: Kirby Urner <urnerk@qwest.net>
Subject: Re: [Tutor] Problem with IDLE in Windows
Cc: tutor@python.org


>
>d =3D Database("charlies_database")
>d.insert_database[dict]  # this generates an attribute error

The use of square brackets isn't defined in your object.
insert_database is a regular "callable" method, expecting
parentheses.  If you want to supply your own meaning for
square brackets, as if you were trying to set the value
of a list or dictionary item, you'd have to define
__setitem__ in your class -- but I don't see that this
is a priority in your case.  Just go:

d.insert_database(dict)

instead.  You may still get an error message, but it should
be a different one :-D

Kirby

PS:  didn't understand about escaped apostrophe exactly,
as your examples don't include any, but I'm glad you've
got that working.




--__--__--

Message: 2
Reply-To: <jcosby@mindspring.com>
From: "Jon Cosby" <jcosby@mindspring.com>
To: <tutor@python.org>
Date: Sun, 9 Sep 2001 10:19:33 -0700
Subject: [Tutor] "Internal Server Error"

Can somebody tell me why this works:

x =3D dict.items()
x.sort(paircomp)
for k, v in x:
k =3D string.replace(k, dir + '/', url)
k1 =3D string.replace(k, url, "")
print '<a href=3D\"' + k + '\">'
print '<b>', k1, '</b></a>&nbsp;', v, counter(v), 'matches<br>'
print '</body>'


But when I modify it slightly,


if len(dict) =3D 0:
print '<h3>No matches found</h3>'
else:
x =3D dict.items()
x.sort(paircomp)
for k, v in x:
k =3D string.replace(k, dir + '/', url)
k1 =3D string.replace(k, url, "")
print '<a href=3D\"' + k + '\">'
print '<b>', k1, '</b></a>&nbsp;', v, counter(v), 'matches<br>'
print '</body>'


I get an "internal server error"?


Jon Cosby

jcosby@mindspring.com
www.jcosby.com


--__--__--

Message: 3
Date: Sun, 9 Sep 2001 13:25:48 -0400 (EDT)
From: Ignacio Vazquez-Abrams <ignacio@openservices.net>
To: <tutor@python.org>
Subject: Re: [Tutor] "Internal Server Error"

On Sun, 9 Sep 2001, Jon Cosby wrote:

> Can somebody tell me why this works:
>
> x =3D dict.items()
> x.sort(paircomp)
> for k, v in x:
> k =3D string.replace(k, dir + '/', url)
> k1 =3D string.replace(k, url, "")
> print '<a href=3D\"' + k + '\">'
> print '<b>', k1, '</b></a>&nbsp;', v, counter(v), 'matches<br>'
> print '</body>'
>
>
> But when I modify it slightly,
>
>
> if len(dict) =3D 0:
              ^^^

> print '<h3>No matches found</h3>'
> else:
> x =3D dict.items()
> x.sort(paircomp)
> for k, v in x:
> k =3D string.replace(k, dir + '/', url)
> k1 =3D string.replace(k, url, "")
> print '<a href=3D\"' + k + '\">'
> print '<b>', k1, '</b></a>&nbsp;', v, counter(v), 'matches<br>'
> print '</body>'
>
>
> I get an "internal server error"?

If you try running it manually, you'll get a SyntaxError exception.

--
Ignacio Vazquez-Abrams  <ignacio@openservices.net>



--__--__--

Message: 4
Date: Sun, 09 Sep 2001 10:36:29 -0700
To: <jcosby@mindspring.com>
From: Kirby Urner <urnerk@qwest.net>
Subject: Re: [Tutor] "Internal Server Error"
Cc: tutor@python.org


>
>if len(dict) =3D 0:

                ^
Needs to be:   =3D=3D

Difficult to debug when running cgi unless you
trap the Python error and display it on the
server.  One option is to do something like
this:

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

   #!/usr/local/bin/python
   import cgi
   import sys        # include this
   import traceback  # include this

   sys.stderr =3D sys.stdout
   print "Content-Type: text/html\n"

   try:

     print """
   <html>\n
   <head>\n
   <title>Feedback</title>\n
   </head>\n<body>
   </body>\n
   </html>"""

   except:  # trap Python error and display in browser

       print "\n\n<PRE>"
       traceback.print_exc()
       print "\n</PRE>"

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

Kirby



--__--__--

Message: 5
From: Sheila King <sheila@thinkspot.net>
To: "Nick Wertzberger" <nwertz@home.com>
Cc: tutor@python.org
Subject: Re: [Tutor] i have a major problem
Date: Sun, 09 Sep 2001 10:44:15 -0700

On Sun, 9 Sep 2001 10:17:05 -0500, "Nick Wertzberger" <nwertz@home.com>
wrote about [Tutor] i have a major problem:

:every time i try to access a file named snakeoil.txt, i get htis message=
:
:Traceback (most recent call last):
:  File "<pyshell#2>", line 1, in ?
:    data=3Dopen("snakeoil.txt")
:IOError: [Errno 2] No such file or directory: 'snakeoil.txt'
:
:how do i fix this PROBLEM!?!?!?!?

I've recently been having problems of this type, myself.
If python says the file doesn't exist, then you must be doing something
wrong, like being in the wrong directory, spelling or case error or
something.

One thing that I have found to help, is adding a few lines to my script,
something like this:

>>> import os
>>> os.listdir(os.curdir)

This will return a list of all the files in the current directory.
Sometimes looking at the list of files that Python sees in the current
directory can be quite insightful.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




--__--__--

Message: 6
Date: 9 Sep 2001 21:09:28 -0000
To: List Member <tutor@python.org>
Reply-To: mailgrabber-feedback-1@lb.bcentral.com
From: "Anonymouse" <massmail@lb.bcentral.com>
Subject: [Tutor] =CF=F0=EE=E4=E0=E6?=EF=EE=EA=F3=EF=EA?=EF=F0=EE=E4=F3=EA=
=F6=E8?=EF=EE=E8=F1?=EF=E0=F0=F2=ED=E5=F0=EE?

                  =D3=E2=E0=E6=E0=E5=EC=FB?=E3=EE=F1=EF=EE=E4?

        =D7=F2?=F2=E0=EA=EE?=C8=ED=F4=EE=F0=EC=E0=F6? ?
=C8=ED=F4=EE=F0=EC=E0=F6? ?=FD=F2?=E2=EB=E0=F1=F2=FC, =E1=EE=E3=E0=F2=F1=F2=
=E2? =F3=F1=EF=E5? =EF=F0=EE=F6=E2=E5=F2=E0=ED=E8?
=CA=F2?=E2=EB=E0=E4=E5=E5?=E8=ED=F4=EE=F0=EC=E0=F6=E8=E5? =F2=EE?=F3=EF=F0=
=E0=E2=EB=FF=E5=F2.

=CE=CE?=AB=C2=C8=DD=CB=DC-=CC=BB =EF=F0=E5=E4=EB=E0=E3=E0=E5=F2 =C2=E0?=E2=
=EE=F1=EF=EE=EB=FC=E7=EE=E2=E0=F2=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E5=E3=EE =E7=E0=EA=E0=E7=E0.

      =CF=EE =E2=F1=E5=EC =E2=EE=EF=F0=EE=F1=E0=EC =E2=FB =EC=EE=E6=E5=F2=
=E5 =EE=E1=F0=E0=F9=E0=F2=FC? =EF=EE =F2=E5=EB=E5=F4=EE=ED=E0? 275-89-94,
746-68-78.


_______________________________________________________________________
Powered by List Builder
To unsubscribe follow the link:
http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=3D15131&subid=
=3D4F31
E628C99B6F48&msgnum=3D1


--__--__--

Message: 7
From: Simon Brunning <SBrunning@trisystems.co.uk>
To: 'Lance E Sloan' <lsloan@umich.edu>, tutor@python.org,
python-list@python.org
Subject: RE: [Tutor] trouble running Grail
Date: Mon, 10 Sep 2001 08:45:31 +0100

> From: Lance E Sloan [SMTP:lsloan@umich.edu]
> Why would the Grail author give two arguments to append?  Was
> there an old version of Python that allowed two arguments?

In a word, yes. See
<http://amk.ca/python/2.0/new-python.html#SECTION0001100000000000000000> =
for
an explanation.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileg=
ed.
It is intended solely for the addressee. Access to this email by anyone e=
lse
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.


--__--__--

Message: 8
Date: Mon, 10 Sep 2001 14:35:20 +0530
From: "Sreenidhi.B.G" <nidhi@ncoretech.com>
Organization: Encore Software Ltd
To: tutor@python.org
Subject: [Tutor] need some help

Helo,
    I am working on a small example where in I call my c function, and
I'm unable to link to the python library. I'm getting undefined
reference to these function calls, - PyArg_ParseTuple and Py_BuildValue.

can you please help me link this to python library. We are working on
Linux7.1.and we are using python 1.5

regards,
-sreenidhi,



--__--__--

Message: 9
From: "Ajaya Babu" <ajaya@ncoretech.com>
To: "PythonTutorlist (E-mail)" <tutor@python.org>
Date: Mon, 10 Sep 2001 17:04:55 +0530
Subject: [Tutor] Windows IDE ..., Problems while executing python code ?


Hi,

I am getting a suprising error with Windows IDE, When I want to test my c=
ode
on windows to check I jsut run uing Ctrl + F5, but when I have a import
statements for the user defined modules ..., python is telling me Import
error...like this...,

 File "C:\Python20\projects\VirtualHandset\utils.py", line 8, in ?
    from HandSetUtils import *
ImportError: No module named HandSetUtils


But suprisingly my modules are present there it self. Then I just copied
these files to the python installation directory...it started working
fine..., then I deleted from python installation directory..., but it
started working fine...then I closed all windows ..., this time again it
started giving the above problem...,

I very much cross checked the name and direcotry...,

I tried with setting path variable to solve this problem. But it did not
help much...,

Can any one suggest some thing to fix this problem.

with regards,
Ajaya





--__--__--

Message: 10
From: "James" <sendme105@hotmail.com>
To: <tutor@python.org>
Cc: <Charlie@begeistert.org>
Date: Mon, 10 Sep 2001 04:38:04 -0700
Subject: [Tutor] Re: Help with cookies

> Dear Python gurus and those who want to become such,
> I need to be able to pass a cookie in a url request.

import os, string
from urllib import *
from mimetools import Message

#redefine (override?) urlopen to enable cookie sending

def urlopen(url, data=3DNone, headers=3DNone):
    u =3D FancyURLopener()
    if headers:
        if type(headers) =3D=3D type({}):
            headers =3D headers.items()
        for kw, val in headers:
            u.addheader(kw, val)
    return u.open(url, data)

# The following gets the cookie info I need...

temppage=3D urlopen(source_url)
headers=3Dtemppage.info()
cookie =3D headers.getheader("set-cookie")
clist =3D string.split(cookie, ';')
temppage.close()

# ...to successfully open the page:

page =3D urlopen(source_url, headers=3D[('Cookie', clist[0])])


########

Warning: I'm new to programming.  I edited this code entirely from a
comp.python post found via google.

Let me know if it works.

James.






--__--__--

Message: 11
From: alan.gauld@bt.com
To: kalle@gnupung.net, tutor@python.org
Subject: RE: [Tutor] sending stdout to a text box
Date: Mon, 10 Sep 2001 13:59:56 +0100

> > run from a prompt. How can I catch this and route it to a
> text box in tkinter?

I posted a short example of this but it wasn't wondersfully commented.


Essentially you make sys.stdout point to an object which has
a write() method. (This could be your Tkinter application for
example)

Now when you call print the output will go to the new object.

Thus

class MyApp(Frame):
   def __init__(self):
     # do stuff here
     self.display =3D Text(....)  # create our text widget
     sys.stdout =3D self          # Set stdout here

   def write(self, s):   # provide the necessary write method
     self.display.insert(END.s)  # append the string s to the widget

   # other methods as usual...
   def foo(self):
      print "This is foo"   # will appear in text widget

Hope thats a little clearer.

Alan G.


--__--__--

Message: 12
Date: Mon, 10 Sep 2001 09:30:46 -0400 (EDT)
From: Bill Tolbert <bill_tolbert@bigfoot.com>
To: tutor@python.org
Subject: RE: [Tutor] sending stdout to a text box

Thanks for the reply Alan. Kalle posted a good example too (I'm the one
who asked originally). I'm close, but not quite where I want to be.

I'm trying to incorporate some utility scripts that use print statements
to tell the user what's going on (success, error, busy, etc). I want my
gui to consolidate these and just redirect the existing print statements
to the text widget on the gui.

Output from ICAREBackup goes to BogusFile and on to the text box, but not
until ICAREBackup finishes. I was looking for a way to provide
immediate feedback. Some of these utilities could run for a very long
time, leaving the user confused and ready to reboot without
feedback. Output to the shell window is immediate; it doesn't wait
until the script finishes. Can I duplicate that immediate feedback?

    def backup(self):
        import ICAREBackup
        sys.stdout =3D BogusFile(self.text_box)
        ICAREBackup.stdout =3D BogusFile(self.text_box)
        ICAREBackup.ICAREBackup()

Thanks guys,

Bill

On Mon, 10 Sep 2001 alan.gauld@bt.com wrote:

> > > run from a prompt. How can I catch this and route it to a
> > text box in tkinter?
>
> I posted a short example of this but it wasn't wondersfully commented.
>
>
> Essentially you make sys.stdout point to an object which has
> a write() method. (This could be your Tkinter application for
> example)
>
> Now when you call print the output will go to the new object.
>
> Thus
>
> class MyApp(Frame):
>    def __init__(self):
>      # do stuff here
>      self.display =3D Text(....)  # create our text widget
>      sys.stdout =3D self          # Set stdout here
>
>    def write(self, s):   # provide the necessary write method
>      self.display.insert(END.s)  # append the string s to the widget
>
>    # other methods as usual...
>    def foo(self):
>       print "This is foo"   # will appear in text widget
>
> Hope thats a little clearer.
>
> Alan G.
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D
Bill Tolbert



--__--__--

Message: 13
To: Ignacio Vazquez-Abrams <ignacio@openservices.net>
cc: tutor@python.org
Subject: Re: [Tutor] trouble running Grail
Date: Mon, 10 Sep 2001 09:55:54 -0400
From: Lance E Sloan <lsloan@umich.edu>


Ignacio Vazquez-Abrams wrote:
> Grail is _ancient_. I remember using Grail 0.6 a _looooong_ time ago.

Yes, it is pretty old.  But I'm convinced that most of the available
web browsers do several things wrong, or at least stupidly.  Since I'm
getting the hang of Python, Grail sounded like a good browser to poke
around in the guts of without feeling tainted afterwards.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Python & Perl CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"



--__--__--

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


End of Tutor Digest