Re: [Tutor] Paradox database files

2005-03-08 Thread Victor Bouffier
Hi all,
I know this is OT from Python, but does anybody know how to fix my 
library issues. I get some awkward dependencies issues from these pylib 
libraries.

# rpm -Uvh pxlib-0.4.3-1.i386.rpm
error: Failed dependencies:
   libbz2.so.1.0 is needed by pxlib-0.4.3-1.i386
but when I look into my libraries I find the necessary ones under /usr/lib:
# ll /usr/lib/libbz2*
-rwxr-xr-x  1 root root 67594 Jun 15  2004 /usr/lib/libbz2.a
lrwxrwxrwx  1 root root11 Feb  6 11:02 /usr/lib/libbz2.so -> libbz2.so.1
lrwxrwxrwx  1 root root15 Feb  6 10:10 /usr/lib/libbz2.so.1 -> 
libbz2.so.1.0.2
lrwxrwxrwx  1 root root24 Mar  8 09:41 /usr/lib/libbz2.so.1.0 -> 
/usr/lib/libbz2.so.1.0.2
-rwxr-xr-x  1 root root 71724 Jun 15  2004 /usr/lib/libbz2.so.1.0.2

I created the second-to-last symlink with no success. I also added 
'/usr/lib' to /etc/ld.so.conf as suggested in a newsgroup.

I've got a Fedora Core3 with both apt and yum installed, and both tell 
me I've got the latest libraries (bzip2-libs). If you believe I should 
post my question elsewhere, please let me know.
Thanks.
Victor

apple_py wrote:
---Original Message---
 

From: "Danny Yoo" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Paradox database files
Sent: 08 Mar 2005 01:51:35
On Mon, 7 Mar 2005, Victor Bouffier wrote:
> Does anybody know of a Python module to read from Paradox database
> files? I don't need to write back to the files. These files are being
> exported using a proprietary application and I need to parse them to
> extract transaction information.
Hi Victor,
You might be interested in 'pxview':
http://pxlib.sourceforge.net/pxview.html
which can extract CSV-formatted files out of Paradox Database files.  Once
you have your data in CSV format, then Python's "csv" module can come into
play:
http://www.python.org/doc/lib/module-csv.html
Alternatively, you might be able to use the pxlib Python bindings
directly.  According to:
http://pxlib.sourceforge.net/documentation.php?manpage=pxlib
a Python binding exists somewhere out there, though I haven't been able to
find it yet... ok, found it, but it appears you might need to check it out
of CVS:
http://cvs.sourceforge.net/viewcvs.py/pxlib/bindings/
so this might not be as easy to use right out of the box.
   

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

--
Victor Bouffier
Finance Manager
www.grupoandersons.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting a webpage via python

2005-03-08 Thread Paul Tremblay
Is there a simple way to get a web page with python? I have done no
network programming with python before. 

My router (a Linksys 54G model) stores the IP/MAC addresss in a web
page. There is no way for me to access them except through the web. 

Righ now, I am using this code:

command = 'lynx -reload -auth %s:%s -source http://%s/DHCPTable.asp > %s' % (
 self.__log_name, self.__log_password, self.__router_address, 
temp_out1)
(exit_status, out_text) = commands.getstatusoutput(command)

The lynx terminal browser dumps the raw HTML page to the out_text, and I
can then parse it.

I would like to make the code independent of lynx, if possible.

Thanks

Paul

-- 


*Paul Tremblay *
[EMAIL PROTECTED]*

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


Re: [Tutor] Paradox database files

2005-03-08 Thread Ewald Ertl
Hi Victor

on Tue, 08 Mar 2005 10:06:50 -0600  Victor Bouffier <[EMAIL PROTECTED]> wrote :
-

Victor Bouffier > Hi all,
Victor Bouffier > I know this is OT from Python, but does anybody know how to 
fix my 
Victor Bouffier > library issues. I get some awkward dependencies issues from 
these pylib 
Victor Bouffier > libraries.
Victor Bouffier > 
Victor Bouffier > # rpm -Uvh pxlib-0.4.3-1.i386.rpm
Victor Bouffier > error: Failed dependencies:
Victor Bouffier > libbz2.so.1.0 is needed by pxlib-0.4.3-1.i386
Victor Bouffier > 
Victor Bouffier > but when I look into my libraries I find the necessary ones 
under /usr/lib:
Victor Bouffier > 
Victor Bouffier > # ll /usr/lib/libbz2*
Victor Bouffier > -rwxr-xr-x  1 root root 67594 Jun 15  2004 /usr/lib/libbz2.a
Victor Bouffier > lrwxrwxrwx  1 root root11 Feb  6 11:02 /usr/lib/libbz2.so 
-> libbz2.so.1
Victor Bouffier > lrwxrwxrwx  1 root root15 Feb  6 10:10 
/usr/lib/libbz2.so.1 -> 
Victor Bouffier > libbz2.so.1.0.2
Victor Bouffier > lrwxrwxrwx  1 root root24 Mar  8 09:41 
/usr/lib/libbz2.so.1.0 -> 
Victor Bouffier > /usr/lib/libbz2.so.1.0.2
Victor Bouffier > -rwxr-xr-x  1 root root 71724 Jun 15  2004 
/usr/lib/libbz2.so.1.0.2
Victor Bouffier > 

Perhap's there is a problem with the RPM-Database. I don't know how rpm works 
internaly, but it 
controls somewhere in a "database", which packages are installed on the system. 

On an old SuSE-System I can search, to which package a file belongs

rpm -q -f /usr/lib/libbz2.so
bzip2-1.0.2-103

Here I see, that libbz2.so belongs to the bzip2-Package. 
The other way is to list the files belonging to a package: 

rpm -q -l bzip2-1.0.2-103
/usr/bin/bunzip2
/usr/bin/bzcat
/usr/bin/bzip2
/usr/bin/bzip2recover
/usr/include/bzlib.h
/usr/lib/libbz2.a
/usr/lib/libbz2.la
/usr/lib/libbz2.so
/usr/lib/libbz2.so.1
/usr/lib/libbz2.so.1.0.0

During the installation/update-Process, I think, rpm looks up, all dependencys 
mentioned 
in the rpm if they are installed on the system via the "database" where it 
logs, 
what is installed. 

Try if you can get a package to which your /usr/lib/libbz2.so.1 belongs. 

The other way is, to install the rpm-Package without depdency-check's, but this 
could result in the availability of the pxlib-Package, but it perhaps does not 
work. 
You've to test this, before you keep the package.

"rpm -Uvh --nodeps"

This should ignore the dependencies and install the package. 



--- end --
HTH Ewald

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


RE: [Tutor] getting a webpage via python

2005-03-08 Thread Eric Culpepper

You could use the builtin modules like urllib2, httplib, or you could use John 
Lee's spifftastic module "mechanize". I use mechanize a lot for automating 
downloading files from various partner websites my company has relations with.

http://docs.python.org/lib/module-httplib.html
http://docs.python.org/lib/module-urllib2.html
http://wwwsearch.sourceforge.net/mechanize/

Good luck.

Eric Culpepper
[EMAIL PROTECTED] 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Paul Tremblay
Sent: Tuesday, March 08, 2005 10:21 AM
To: python tutor
Subject: [Tutor] getting a webpage via python


Is there a simple way to get a web page with python? I have done no
network programming with python before. 

My router (a Linksys 54G model) stores the IP/MAC addresss in a web
page. There is no way for me to access them except through the web. 

Righ now, I am using this code:

command = 'lynx -reload -auth %s:%s -source http://%s/DHCPTable.asp > %s' % (
 self.__log_name, self.__log_password, self.__router_address, 
temp_out1)
(exit_status, out_text) = commands.getstatusoutput(command)

The lynx terminal browser dumps the raw HTML page to the out_text, and I
can then parse it.

I would like to make the code independent of lynx, if possible.

Thanks

Paul

-- 


*Paul Tremblay *
[EMAIL PROTECTED]*

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


Re: [Tutor] getting a webpage via python

2005-03-08 Thread Ewald Ertl
Hi Paul!

As mentioned earlier by Kent in this group under the subject:

Subject: Re: [Tutor] Downloading from http

Mark Kels wrote:
 > On Sat, 12 Feb 2005 09:25:10 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
 > 
 >>urllib or urllib2 or maybe httplib maybe?
 >>
 >>urlopen( url[, data])
 > I'm sorry, but I didn't understood a thing (maybe its because of my
 > bad english, and mybe its because I'm just dumb :). Anyway, can you
 > give me a code example or a link to a tutorial that talks about this ?

   >>> from urllib import urlopen
   >>> u=urlopen('http://www.google.com')
   >>> d=u.read()
   >>> print d[:200]
 Google

Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote:
Is there a simple way to get a web page with python? I have done no
network programming with python before. 

My router (a Linksys 54G model) stores the IP/MAC addresss in a web
page. There is no way for me to access them except through the web. 

Righ now, I am using this code:
command = 'lynx -reload -auth %s:%s -source http://%s/DHCPTable.asp > %s' % (
 self.__log_name, self.__log_password, self.__router_address, 
temp_out1)
(exit_status, out_text) = commands.getstatusoutput(command)
You can use urllib2 to do this. It is a little work to set it up to use Basic authentication. Here 
is an example (slightly modified from the urllib2 example page):

import urllib2
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('realm', '127.0.0.1', 'username', 'password')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
print urllib2.urlopen('http://127.0.0.1/my/protected/page.html').read()
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Paradox database files

2005-03-08 Thread Victor Bouffier
That did the trick. Thanks Ewald.
FYI, I used the '--nodeps' directive once I realized there were really 
no major issues.
I still needed to keep the added symlink since the px libraries couldn't 
find the libbz2.so.1.0 file.

Thanks again to all. That was great help.
Victor
Ewald Ertl wrote:
Hi Victor
on Tue, 08 Mar 2005 10:06:50 -0600  Victor Bouffier <[EMAIL PROTECTED]> wrote :
-
Victor Bouffier > Hi all,
Victor Bouffier > I know this is OT from Python, but does anybody know how to fix my 
Victor Bouffier > library issues. I get some awkward dependencies issues from these pylib 
Victor Bouffier > libraries.
Victor Bouffier > 
Victor Bouffier > # rpm -Uvh pxlib-0.4.3-1.i386.rpm
Victor Bouffier > error: Failed dependencies:
Victor Bouffier > libbz2.so.1.0 is needed by pxlib-0.4.3-1.i386
Victor Bouffier > 
Victor Bouffier > but when I look into my libraries I find the necessary ones under /usr/lib:
Victor Bouffier > 
Victor Bouffier > # ll /usr/lib/libbz2*
Victor Bouffier > -rwxr-xr-x  1 root root 67594 Jun 15  2004 /usr/lib/libbz2.a
Victor Bouffier > lrwxrwxrwx  1 root root11 Feb  6 11:02 /usr/lib/libbz2.so -> libbz2.so.1
Victor Bouffier > lrwxrwxrwx  1 root root15 Feb  6 10:10 /usr/lib/libbz2.so.1 -> 
Victor Bouffier > libbz2.so.1.0.2
Victor Bouffier > lrwxrwxrwx  1 root root24 Mar  8 09:41 /usr/lib/libbz2.so.1.0 -> 
Victor Bouffier > /usr/lib/libbz2.so.1.0.2
Victor Bouffier > -rwxr-xr-x  1 root root 71724 Jun 15  2004 /usr/lib/libbz2.so.1.0.2
Victor Bouffier > 

Perhap's there is a problem with the RPM-Database. I don't know how rpm works internaly, but it 
controls somewhere in a "database", which packages are installed on the system. 

On an old SuSE-System I can search, to which package a file belongs
rpm -q -f /usr/lib/libbz2.so
bzip2-1.0.2-103
Here I see, that libbz2.so belongs to the bzip2-Package. 
The other way is to list the files belonging to a package: 

rpm -q -l bzip2-1.0.2-103
/usr/bin/bunzip2
/usr/bin/bzcat
/usr/bin/bzip2
/usr/bin/bzip2recover
/usr/include/bzlib.h
/usr/lib/libbz2.a
/usr/lib/libbz2.la
/usr/lib/libbz2.so
/usr/lib/libbz2.so.1
/usr/lib/libbz2.so.1.0.0
During the installation/update-Process, I think, rpm looks up, all dependencys mentioned 
in the rpm if they are installed on the system via the "database" where it logs, 
what is installed. 

Try if you can get a package to which your /usr/lib/libbz2.so.1 belongs. 

The other way is, to install the rpm-Package without depdency-check's, but this 
could result in the availability of the pxlib-Package, but it perhaps does not work. 
You've to test this, before you keep the package.

"rpm -Uvh --nodeps"
This should ignore the dependencies and install the package. 


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

--
Victor Bouffier
Finance Manager
www.grupoandersons.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: [Pysqlite-users] Querying 2 databases together

2005-03-08 Thread Liam Clarke
Care to post the SQL of what you're trying to do?


On Tue, 8 Mar 2005 17:01:07 +0100, Pierre-Yves Delens
<[EMAIL PROTECTED]> wrote:
> bonjour,
> 
> Iread through SqLite syntax (Attach), and found some old posts on PySqLite,
> but..
> 
> I didn't manage to join a table from a 2d database file in my query.
> 
> Does someone have examples or snippets ?
> 
> Thanks on forward
> 
> ___
> P-Y Delens, ing-arch. manager
> 
> LIENTERFACES - PY Delens, sprl
> Avenue Dolez, 243  -  1180   Bruxelles
> 
> phone : 32 2 375 55 62
> fax :  32 2 374 75 74
> mail : [EMAIL PROTECTED]
> web : www.lienterfaces.be
> ___
> 
> ---
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> ___
> Pysqlite-users mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/pysqlite-users
> 


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


[Tutor] Re: [Pysqlite-users] Querying 2 databases together

2005-03-08 Thread Liam Clarke
Ack - wrong list.


On Wed, 9 Mar 2005 06:52:57 +1300, Liam Clarke <[EMAIL PROTECTED]> wrote:
> Care to post the SQL of what you're trying to do?
> 
> 
> On Tue, 8 Mar 2005 17:01:07 +0100, Pierre-Yves Delens
> <[EMAIL PROTECTED]> wrote:
> > bonjour,
> >
> > Iread through SqLite syntax (Attach), and found some old posts on PySqLite,
> > but..
> >
> > I didn't manage to join a table from a 2d database file in my query.
> >
> > Does someone have examples or snippets ?
> >
> > Thanks on forward
> >
> > ___
> > P-Y Delens, ing-arch. manager
> >
> > LIENTERFACES - PY Delens, sprl
> > Avenue Dolez, 243  -  1180   Bruxelles
> >
> > phone : 32 2 375 55 62
> > fax :  32 2 374 75 74
> > mail : [EMAIL PROTECTED]
> > web : www.lienterfaces.be
> > ___
> >
> > ---
> > SF email is sponsored by - The IT Product Guide
> > Read honest & candid reviews on hundreds of IT Products from real users.
> > Discover which products truly live up to the hype. Start reading now.
> > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> > ___
> > Pysqlite-users mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/pysqlite-users
> >
> 
> --
> 'There is only one basic human right, and that is to do as you damn well 
> please.
> And with it comes the only basic human duty, to take the consequences.
> 


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


Re: [Tutor] getting a webpage via python

2005-03-08 Thread Paul Tremblay
On Tue, Mar 08, 2005 at 11:50:12AM -0500, Kent Johnson wrote:
> 
> Paul Tremblay wrote:
> 
> You can use urllib2 to do this. It is a little work to set it up to use 
> Basic authentication. Here is an example (slightly modified from the 
> urllib2 example page):
> 
> import urllib2
> 
> # Create an OpenerDirector with support for Basic HTTP Authentication...
> auth_handler = urllib2.HTTPBasicAuthHandler()
> auth_handler.add_password('realm', '127.0.0.1', 'username', 'password')
> opener = urllib2.build_opener(auth_handler)
> # ...and install it globally so it can be used with urlopen.
> urllib2.install_opener(opener)
> print urllib2.urlopen('http://127.0.0.1/my/protected/page.html').read()
> 
> Kent
> 

This is giving me 401 error, authorization required. Here's what I have:


auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
print urllib2.urlopen('http://nnn.nnn.n.n').read()

This is almost the literal code, except I changed my log in name and
passowrd.

What am I supposed to put for realm? I checked the docs on line, and it
doens't mention what realm is.

Also, I assume I am supposed to use the loopback address when I set up
the handler?

Also, I know I am going to have another question once I solve this one,
and since it is directly related, I'll ask it now. How can I use a
password system that is not hardcoded in my text? Should I just setup a
password file? 

Thanks

Paul



-- 


*Paul Tremblay *
[EMAIL PROTECTED]*

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


Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote:
This is giving me 401 error, authorization required. Here's what I have:
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
print urllib2.urlopen('http://nnn.nnn.n.n').read()
This is almost the literal code, except I changed my log in name and
passowrd.
What am I supposed to put for realm? I checked the docs on line, and it
doens't mention what realm is.
The realm name is part of the web server authentication configuration. If you browse to the web page 
in your browser it will show the realm in the auth dialog. For example my browser (Firefox) shows

Enter user name and password for "Curriculum Builder" at http://localhost
The realm name is "Curriculum Builder"
Also, I assume I am supposed to use the loopback address when I set up
the handler?
No, use your server name, in your example nnn.nn.n.n
Also, I know I am going to have another question once I solve this one,
and since it is directly related, I'll ask it now. How can I use a
password system that is not hardcoded in my text? Should I just setup a
password file? 
Yes, something like that. You will have to store the password in plaintext (or a reversible cipher) 
since that is what HTTPBasicAuthHandler needs.

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


Re: [Tutor] getting a webpage via python

2005-03-08 Thread Paul Tremblay


On Tue, Mar 08, 2005 at 01:42:40PM -0500, Kent Johnson wrote:
> Date: Tue, 08 Mar 2005 13:42:40 -0500
> From: Kent Johnson <[EMAIL PROTECTED]>
> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
> Cc: python tutor 
> Subject: Re: [Tutor] getting a webpage via python
> 
> Paul Tremblay wrote:
> >This is giving me 401 error, authorization required. Here's what I have:
> >
> >
> >auth_handler = urllib2.HTTPBasicAuthHandler()
> >auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password')
> >opener = urllib2.build_opener(auth_handler)
> ># ...and install it globally so it can be used with urlopen.
> >urllib2.install_opener(opener)
> >print urllib2.urlopen('http://nnn.nnn.n.n').read()
> >
> >This is almost the literal code, except I changed my log in name and
> >passowrd.
> >
> >What am I supposed to put for realm? I checked the docs on line, and it
> >doens't mention what realm is.
> 
> The realm name is part of the web server authentication configuration. If 
> you browse to the web page in your browser it will show the realm in the 
> auth dialog. For example my browser (Firefox) shows
> 
> Enter user name and password for "Curriculum Builder" at http://localhost
> 
> The realm name is "Curriculum Builder"


Thanks. I got it to work.

I tired to open the page in Koqueror web browser and got this message:

Authorization Dialog


You need to supply a username and password to access this site.

Site: WRT54G at nnn.nnn.n.n

I tried useing "Authorizaiton Dialog" with no success. So I tried opening
the same page with lynx with the trace option on. I found that lynx used
WRT54G as the realm, so I tried it and it worked.

> 
> >Also, I assume I am supposed to use the loopback address when I set up
> >the handler?
> 
> No, use your server name, in your example nnn.nn.n.n
> 
> >Also, I know I am going to have another question once I solve this one,
> >and since it is directly related, I'll ask it now. How can I use a
> >password system that is not hardcoded in my text? Should I just setup a
> >password file? 
> 
> Yes, something like that. You will have to store the password in plaintext 
> (or a reversible cipher) since that is what HTTPBasicAuthHandler needs.
> 

So I just make a file called /etc/router_passwords  and include
something like 

WRT54G username password

Then parse the file, and supply the info to the password handler? This
is easy to do, and I guess it is secure. I am networking on a home
system, so security is not so big a concern. However, I have seen a lot
of people struggle with getting router addresses from the WRT54G,so I
thought I might offer my script, and I wanted to do things a secure,
normal way.

Thanks

Paul

-- 


*Paul Tremblay *
[EMAIL PROTECTED]*

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


Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote:
So I just make a file called /etc/router_passwords  and include
something like 

WRT54G username password
Then parse the file, and supply the info to the password handler? This
is easy to do, and I guess it is secure. 
No, it's not secure at all. In either case (password in the script, password in a file) you are 
saving a cleartext password in a text file on your computer. I don't think either one is really any 
more secure than the other. To make your separate file really secure you would have to encrypt it 
some how.

The thing is, Basic auth is inherently insecure - the password is sent Base64 encoded to the web 
server. Base64 is easily reversed, it is not a secure encoding. So unless you are using HTTPS for a 
secure link, you are pretty much out of luck anyway.

I am networking on a home
system, so security is not so big a concern. However, I have seen a lot
of people struggle with getting router addresses from the WRT54G,so I
thought I might offer my script, and I wanted to do things a secure,
normal way.
If it were me, for my own use, I would probably just put the password in the script. One advantage 
of putting it in a separate file is that you can share the script as is, you don't have to edit out 
your password each time you send it. On the other hand you have to document the separate file. So 
for a script you are going to share there might be a small convenience factor to using a separate 
file. But I don't think there is any difference in security.

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


[Tutor] Using signal handlers

2005-03-08 Thread Michael Lange
Hello tutors,

I experience problems with signal handlers, and the explanatzions in the docs 
don't
seem to help me much.

The code I try to handle basically comes down to this (it's supposed to run on 
linux only, btw):

from Tkinter import *
import tkSnack

root = Tk()
tkSnack.initializeSnack(root)
root.mainloop()

initializeSnack() tries to access the sound device, however if this fails it 
tries forever and doesn't return.
I *thought* a signal handler might be what I need, and in fact it partially 
works, at least
initializeSnack() is stopped when I add this:

from Tkinter import *
import tkSnack, signal

root = Tk()
signal.signal(signal.SIGALRM, signal.getsignal(signal.SIGALRM))
signal.alarm(5)
tkSnack.initializeSnack(root)
signal.alarm(0)
root.mainloop()

Now when the audio device is busy, after 5 seconds the app prints "Alarm clock" 
and exits.
However I would prefer to have a more controlled exit, but as soon as I define 
a custom
signal handler it's the same as before - it never gets called.

Any help is much appreciated

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


[Tutor] HELP: subclass of int

2005-03-08 Thread Shidai Liu
Hi all,

I'll sum up a question as following:

def int5():
'''return 5'''
return 5

class my_int(int):
def __init__(self):
self.id = int5()
int.__init__(self, self.id)  # FIXME: this line doesn't work

the above code act like this:
>>> I = my_int()
>>> I
0

I want it to be like this:
>>> I = my_int()
>>> I
5

Please, if you know a solution, help me out!

-- 
With best wishes!
Shidai
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP: subclass of int

2005-03-08 Thread Max Noel
On Mar 8, 2005, at 22:10, Shidai Liu wrote:
Hi all,
I'll sum up a question as following:
def int5():
'''return 5'''
return 5
class my_int(int):
def __init__(self):
self.id = int5()
int.__init__(self, self.id)  # FIXME: this line doesn't work
	I'm not absolutely confident with inheritance in Python (nearly all of 
my serious OO work has been in Java), but shouldn't the call to the 
superclass's constructor be the very first statement of the subclass's 
constructor?

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

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


[Tutor] Acessing files in Windows 2000

2005-03-08 Thread Dave S
I have a script that converts data relating to my work.
It works great on my Linux system but some of my colleagues run windows. 
I am attempting to convert the file paths to windows but am having no luck.

I need to access 'memo.txt' in 'my documents' on windows & am struggling.
I have tried just about every combination of \ and / and \\ and // but 
to no avail.
I need something like ...

C:\My Documents\memo.txt
Can anyone advise me ?
Dave
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread John Purser
Try c:\\my documents\\memo.txt

John 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Dave S
Sent: Tuesday, March 08, 2005 14:24
To: Python Tutor
Subject: [Tutor] Acessing files in Windows 2000

I have a script that converts data relating to my work.

It works great on my Linux system but some of my colleagues run windows. 
I am attempting to convert the file paths to windows but am having no luck.

I need to access 'memo.txt' in 'my documents' on windows & am struggling.
I have tried just about every combination of \ and / and \\ and // but 
to no avail.
I need something like ...

C:\My Documents\memo.txt

Can anyone advise me ?

Dave


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

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


Re: [Tutor] HELP: subclass of int

2005-03-08 Thread jfouhy
Quoting Max Noel <[EMAIL PROTECTED]>:

>   I'm not absolutely confident with inheritance in Python (nearly all of
> my serious OO work has been in Java), but shouldn't the call to the 
> superclass's constructor be the very first statement of the subclass's 
> constructor?

No ...

Or, well, maybe --- but __init__ is technically not the constructor.

The constructor is responsible for doing the nitty gritty work of constructing
an object, which is, I guess, why you feel it should be called first (because
you don't want to be messing with an object that does not fully exist yet).

But in python, by the time __init__ is called, the object has been fully
constructed.  __init__ is just a special method that gets called immediately
after construction.  But otherwise, there is nothing special or magical about 
it.

You could even do this if you wanted:

class myClass(object):
 ...
 def reInitialise(self):
  self.__init__()

although I'm not sure if this would be considered good practice :-)

[as to the original question --- someone else will have to answer, sorry, 'cause
I don't know]

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


RE: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Eric Culpepper

Try something like this (change the username to the user you're logged in as, 
or Administrator if that's how you're logged in):

c:\\documents and settingsmy documents\\memo.txt


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Dave S
Sent: Tuesday, March 08, 2005 4:24 PM
To: Python Tutor
Subject: [Tutor] Acessing files in Windows 2000


I have a script that converts data relating to my work.

It works great on my Linux system but some of my colleagues run windows. 
I am attempting to convert the file paths to windows but am having no luck.

I need to access 'memo.txt' in 'my documents' on windows & am struggling.
I have tried just about every combination of \ and / and \\ and // but 
to no avail.
I need something like ...

C:\My Documents\memo.txt

Can anyone advise me ?

Dave


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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Max Noel
On Mar 8, 2005, at 22:26, John Purser wrote:
Try c:\\my documents\\memo.txt
John
Or even better, c:/My Documents/memo.txt
	In most programming languages, you can use the slash as a path 
separator under Windows as well. It'll save you a lot of trouble.

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

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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread jfouhy
Quoting Dave S <[EMAIL PROTECTED]>:

> I need to access 'memo.txt' in 'my documents' on windows & am
> struggling.
> I have tried just about every combination of \ and / and \\ and // but 
> to no avail.
> I need something like ...
> 
> C:\My Documents\memo.txt
> 
> Can anyone advise me ?

I've never had any trouble accessing files in Win2k with python.  

The following would all work for me:

f1 = file('c:\\My Docments\\memo.txt')
f2 = file('c:/My Documents/memo.txt')
f3 = file(os.path.normpath('c:/My Documents/memo.txt'))  # os.path.normpath
normalizes a path; it also converts / to \\ on Windows platforms

Is your path correct?  The "My Documents" folder doesn't normally live in the
root in Win2k; it is more likely to be found somewhere like C:\Documents and
Settings\Username\My Documents.  Or, in an office environment, it might be on a
network share --- eg, H:\.

HTH.

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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Dave S
John Purser wrote:
Try c:\\my documents\\memo.txt
John 
 

Unfortunately thats a no go ...
palm.py
palm memo.txt to oocalc data.csv convertor, written by lentil ;)
[EMAIL PROTECTED] - enter "palm software" in the title or it will be junked
09-03-2005  v1.02w Coded for Windows
07-03-2005  v1.02  Coded capitalization() + default to mon
03-03-2005  v1.01  Squished 1/9 decode bug
02-03-2005  v1.00  Coded for Linux
Traceback (most recent call last):
 File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 
268, in ?
   palm_conv()
 File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 
54, in palm_conv
   memo = open(memo_file, 'r')
IOError: [Errno 2] No such file or directory: 'c:\\my documents\\memo.txt'
>>>

If I try c:\\
or
c:\
it always comes out as c:\\... and fails
Dave
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread John Purser
I agree with a previous poster, check your path.  I think either the path
doesn't exist or you don't have permission to get to it.

John 

-Original Message-
From: Dave S [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 08, 2005 14:50
To: [EMAIL PROTECTED]
Cc: 'Python Tutor'
Subject: Re: [Tutor] Acessing files in Windows 2000

John Purser wrote:

>Try c:\\my documents\\memo.txt
>
>
>John 
>  
>
Unfortunately thats a no go ...

palm.py

palm memo.txt to oocalc data.csv convertor, written by lentil ;)
[EMAIL PROTECTED] - enter "palm software" in the title or it will be junked

09-03-2005  v1.02w Coded for Windows
07-03-2005  v1.02  Coded capitalization() + default to mon
03-03-2005  v1.01  Squished 1/9 decode bug
02-03-2005  v1.00  Coded for Linux

Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 
268, in ?
palm_conv()
  File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 
54, in palm_conv
memo = open(memo_file, 'r')
IOError: [Errno 2] No such file or directory: 'c:\\my documents\\memo.txt'
 >>>

If I try c:\\

or

c:\

it always comes out as c:\\... and fails

Dave


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


Re: [Tutor] HELP: subclass of int

2005-03-08 Thread Terry Carroll
On Tue, 8 Mar 2005, Shidai Liu wrote:

> I'll sum up a question as following:
> 
> def int5():
> '''return 5'''
> return 5
> 
> class my_int(int):
> def __init__(self):
> self.id = int5()
> int.__init__(self, self.id)  # FIXME: this line doesn't work
> 
> the above code act like this:
> >>> I = my_int()
> >>> I
> 0
> 
> I want it to be like this:
> >>> I = my_int()
> >>> I
> 5

You'll want to use the __new__ method, see 
http://www.python.org/2.2.3/descrintro.html#__new__

Example:

>>> def int5():
... '''return 5'''
... return 5
...
>>> class my_int(int):
...def __new__(self):
...   return int.__new__(self, int5())
...
>>> i = my_int()
>>> i
5
>>>

As someone else pointed out, you probably ought to call int.__init__ as 
well.

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


RE: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Shitiz Bansal
I faced the same problem once.Dont remember the
solution, but it is definitely the slashes which are
causing the problem.I couldnt find a specific rule in
whole of microsoft documentation, so i assume it has
to be hit and try.Try a mix of backslashes n forward
slashes till u get there.
Whats worse, I had found that the rule is different
for different versions of windows.Just proves what we
all know...Windows Suxx.
 
--- John Purser <[EMAIL PROTECTED]> wrote:
> I agree with a previous poster, check your path.  I
> think either the path
> doesn't exist or you don't have permission to get to
> it.
> 
> John 
> 
> -Original Message-
> From: Dave S [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, March 08, 2005 14:50
> To: [EMAIL PROTECTED]
> Cc: 'Python Tutor'
> Subject: Re: [Tutor] Acessing files in Windows 2000
> 
> John Purser wrote:
> 
> >Try c:\\my documents\\memo.txt
> >
> >
> >John 
> >  
> >
> Unfortunately thats a no go ...
> 
> palm.py
> 
> palm memo.txt to oocalc data.csv convertor, written
> by lentil ;)
> [EMAIL PROTECTED] - enter "palm software" in the title
> or it will be junked
> 
> 09-03-2005  v1.02w Coded for Windows
> 07-03-2005  v1.02  Coded capitalization() + default
> to mon
> 03-03-2005  v1.01  Squished 1/9 decode bug
> 02-03-2005  v1.00  Coded for Linux
> 
> Traceback (most recent call last):
>   File "C:\Documents and
> Settings\Administrator\Desktop\palm.py", line 
> 268, in ?
> palm_conv()
>   File "C:\Documents and
> Settings\Administrator\Desktop\palm.py", line 
> 54, in palm_conv
> memo = open(memo_file, 'r')
> IOError: [Errno 2] No such file or directory:
> 'c:\\my documents\\memo.txt'
>  >>>
> 
> If I try c:\\
> 
> or
> 
> c:\
> 
> it always comes out as c:\\... and fails
> 
> Dave
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




__ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Terry Carroll
On Tue, 8 Mar 2005, Dave S wrote:

> IOError: [Errno 2] No such file or directory: 'c:\\my documents\\memo.txt'

My two thoughts.

1) is there actually a directory named "my documents" at the root?  I 
don't know about Win2000, but for Win XP, the "my documents" directory is 
actually 

 C:\Documents and Settings\username\My Documents

2) The embedded space may be the issue, although I doubt that's it.


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


[Tutor] regular expression question

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

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


Re: [Tutor] HELP: subclass of int

2005-03-08 Thread Shidai Liu
On Tue, 8 Mar 2005 17:15:00 -0800 (PST), Terry Carroll <[EMAIL PROTECTED]> 
wrote:
> On Tue, 8 Mar 2005, Shidai Liu wrote:
> 
> > I'll sum up a question as following:
> >
> > def int5():
> > '''return 5'''
> > return 5
> >
> > class my_int(int):
> > def __init__(self):
> > self.id = int5()
> > int.__init__(self, self.id)  # FIXME: this line doesn't work
> >
> > the above code act like this:
> > >>> I = my_int()
> > >>> I
> > 0
> >
> > I want it to be like this:
> > >>> I = my_int()
> > >>> I
> > 5
> 
> You'll want to use the __new__ method, see
> http://www.python.org/2.2.3/descrintro.html#__new__

Great link. It explains so much.

> 
> Example:
> 
> >>> def int5():
> ... '''return 5'''
> ... return 5
> ...
> >>> class my_int(int):
> ...def __new__(self):
> ...   return int.__new__(self, int5())
> ...
> >>> i = my_int()
> >>> i
> 5
> >>>
> 
> As someone else pointed out, you probably ought to call int.__init__ as
> well.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

It works. Thanks very much!

-- 
With best wishes!
Shidai
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

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

I can easily get the spot after "Dog," and I can also get it to ignore 
this spot if "Dog" is followed by "Cat." But what I'm having trouble 
with is how to match the spot after "Cat" if this word does indeed exist 
in the string.


. >>> import re
. >>> my_re = re.compile(r'(dog)(cat)?') # the ? means "find one or zero 
of these, in other words cat is optional.
. >>> m = my_re.search("This is a nice dog is it not?")
. >>> dir(m)
['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict', 
'groups', 'span', 'start']
. >>> m.span()
(15, 18)
. >>> m = my_re.search("This is a nice dogcat is it not?")
. >>> m.span()
(15, 21)

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

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


Re: [Tutor] regular expression question

2005-03-08 Thread Danny Yoo


On Tue, 8 Mar 2005, Mike Hall wrote:

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

Hi Mike,

You may want to look at "lookahead" assertions.  These are patterns of the
form '(?=...)' or '(?!...).  The documentation mentions them here:

   http://www.python.org/doc/lib/re-syntax.html

and AMK's excellent "Regular Expression HOWTO" covers how one might use
them:

http://www.amk.ca/python/howto/regex/regex.html#SECTION00054

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


Re: [Tutor] regular expression question

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


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

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

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


Re: [Tutor] regular expression question

2005-03-08 Thread Sean Perry
Mike Hall wrote:
First, thanks for the response. Using your re:
my_re = re.compile(r'(dog)(cat)?')

...I seem to simply be matching the pattern "Dog".  Example:
 >>> str1 = "The dog chased the car"
 >>> str2 = "The dog cat parade was under way"
 >>> x1 = re.compile(r'(dog)(cat)?')
 >>> rep1 = x1.sub("REPLACE", str1)
 >>> rep2 = x2.sub("REPLACE", str2)
 >>> print rep1
The REPLACE chased the car
 >>> print rep2
The REPLACE cat parade was under way
...what I'm looking for is a match for the position in front of "Cat", 
should it exist.

Because my regex says 'look for the word "dog" and remember where you 
found it. If you also find the word "cat", remember that too'. Nowhere 
does it say "watch out for whitespace".

r'(dog)\s*(cat)?' says match 'dog' followed by zero or more whitespace 
(spaces, tabs, etc.) and maybe 'cat'.

There is a wonderful O'Reilly book called "Mastering Regular 
Expressions" or as Danny points out the AMK howto is good.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression question

2005-03-08 Thread Danny Yoo


On Tue, 8 Mar 2005, Mike Hall wrote:

> Yes, my existing regex is using a look behind assertion:
>
> (?<=dog)
>
> ...it's also checking the existence of "Cat":
>
> (?!Cat)
>
> ...what I'm stuck on is how to essentially use a lookbehind on "Cat",
> but only if it exists.

Hi Mike,



[Note: Please do a reply-to-all next time, so that everyone can help you.]

Regular expressions are a little evil at times; here's what I think you're
thinking of:

###
>>> import re
>>> pattern = re.compile(r"""dog(?!cat)
...| (?<=dogcat)""", re.VERBOSE)
>>> pattern.match('dogman').start()
0
>>> pattern.search('dogcatcher').start()
>>> pattern.search('dogman').start()
0
>>> pattern.search('catwoman')
>>>
###

but I can't be sure without seeing some of the examples you'd like the
regular expression to match against.


Best of wishes to you!

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


Re: [Tutor] regular expression question

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

(?<=dog)

...if that makes sense :) thanks.

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

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

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

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


Re: [Tutor] regular expression question

2005-03-08 Thread Danny Yoo


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



Hi Mike,

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

###
>>> pattern.search('dogcatcher').start()
6
###

Sorry about that!

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


Re: [Tutor] regular expression question

2005-03-08 Thread Mike Hall
Sorry, my last reply crossed this one (and yes, I forgot again to CC 
the list).
I'm experimenting now with your use of the "or" operator( "|") between 
two expressions, thanks.


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

On Tue, 8 Mar 2005, Mike Hall wrote:
Yes, my existing regex is using a look behind assertion:
(?<=dog)
...it's also checking the existence of "Cat":
(?!Cat)
...what I'm stuck on is how to essentially use a lookbehind on "Cat",
but only if it exists.
Hi Mike,

[Note: Please do a reply-to-all next time, so that everyone can help 
you.]

Regular expressions are a little evil at times; here's what I think 
you're
thinking of:

###
import re
pattern = re.compile(r"""dog(?!cat)
...| (?<=dogcat)""", re.VERBOSE)
pattern.match('dogman').start()
0
pattern.search('dogcatcher').start()
pattern.search('dogman').start()
0
pattern.search('catwoman')
###
but I can't be sure without seeing some of the examples you'd like the
regular expression to match against.
Best of wishes to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Danny Yoo

[Windows bashing cut]

Python's support for Windows stuff is actually quite good, thanks to the
work of Mark Hammond:

http://starship.python.net/crew/mhammond/

A lot of us here do use Windows for COM programming.  Let's get back to
talking about Python programming and let's help Dave with his problem.


The os.path module contains a function called expanduser() that returns
the home directory of a given user.

http://www.python.org/doc/lib/module-os.path.html#l2h-1720

I believe this should reliably return a path that looks something like
'\\Documents and Settings\\[username]' on Windows systems.


Dave, what happens if you try something like this?

##
import os.path
print os.path.expanduser('~/memo.txt')
f = open(os.path.expanduser('~/memo.txt'))
##

Show us what you see, and we can work from there.  Can you also give us
the complete path where you see 'memo.txt' on your system?  Just right
click the file; it should show up somewhere on the file's property page.


Best of wishes to you!

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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread R. Alan Monroe
> I have a script that converts data relating to my work.

> It works great on my Linux system but some of my colleagues run windows. 
> I am attempting to convert the file paths to windows but am having no luck.

> I need to access 'memo.txt' in 'my documents' on windows & am struggling.
> I have tried just about every combination of \ and / and \\ and // but 
> to no avail.
> I need something like ...

> C:\My Documents\memo.txt

You'll have to come up with some windows-specific trick to find out
the current user, because "my documents" is actually in
c:\documents and settings\currentusername\my documents\

Try getting it from the HOMEPATH environment variable.

import os
print os.environ['HOMEPATH']


Alan

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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Max Noel
On Mar 9, 2005, at 01:13, Shitiz Bansal wrote:
Whats worse, I had found that the rule is different
for different versions of windows.Just proves what we
all know...Windows Suxx.
The Windows OS sucks!
And blows!
At the same time!
(name the reference, get a cookie ;) )
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

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


Re: [Tutor] HELP: subclass of int

2005-03-08 Thread Kent Johnson
Shidai Liu wrote:
Hi all,
I'll sum up a question as following:
def int5():
'''return 5'''
return 5
class my_int(int):
def __init__(self):
self.id = int5()
int.__init__(self, self.id)  # FIXME: this line doesn't work
the above code act like this:
I = my_int()
I
0
I want it to be like this:
I = my_int()
I
5
Please, if you know a solution, help me out!
When you subclass an immutable type like int (or float, string, ...) you have to define __new__ 
instead of __init__. See this page for an example and some explanation:
http://www.python.org/2.2.3/descrintro.html#__new__

Kent


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


[Tutor] working with new classes

2005-03-08 Thread C Smith
Hello,
After learning about the new class behavior, I am trying to implement a 
circular type list where, for example, you can compare the nth value to 
the "(n+1)th" value without worrying about going past the end of the 
list. (An old approach might be to create a function that converts a 
given index to the real index (e.g. maps the "(n+1)th" value back to 
the 1st value), but I thought I would try subclassing the list 
behavior.)

Seeing an ASPN entry on circular lists 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52246), I 
first tried to define a "turn" method for the list.  The following works

###
class ring(list):
def turn(self, incr=1):
tail=self[incr:]
head = self[:incr]
self[:] = tail+head
l=ring(range(10))
l.turn(5) #the list now has a turn method
print l   #--> [5, 6, 7, 8, 9, 0, 1, 2, 3, 4]
###
Then I tried to redefine how the list is initialized, desiring to give 
it a "zero" attribute which will be used whenever an item from the list 
is requested. I'm hoping not to have work with slices of the list--I 
just change how it is accessed.  BUT...it doesn't work. Apparently 
__getitem__ is not accessed in order to print the list; and Python 
crashes when I try to print a single element.

Am I trying to subclass the wrong aspects of the list?
###
class Ring(list):
def __init__(self, l):
self[:] = l
self._zero = 0

def turn(self, incr=1):
self._zero+=incr
def __getitem__(self, i):
return self[(i-self._zero)%len(self)]
l=Ring(range(10))
print l
l.turn(5)
print l#same as original
print l[0] #crashes python
###
/c
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor