[Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread Asrarahmed Kadri

Hi folks,

I want to develop an application which uses a database and some forms to
enter/modify the database.
The application should also generate reports based on some fields.

What should I be using? Python or VB...

I want to use Python.. IN that case, what should be my choice for the
Database..

Thanks in anticipation.

Best Regards,
Asrarahmed Kadri




--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] file.read() doesn't give full contents of compressed files

2007-02-20 Thread Barton David
Hi,
I'm really confused, and I hope somebody can explain this for me...
 
I've been playing with compression and archives, and have some .zip,
.tar, .gz and .tgz example files to test my code on.
I can read them using either zipfile, tarfile, gzip or zlib, and that's
fine. But just reading them in 'raw' doesn't give me the whole string of
(compressed) bytes.
 
i.e...
 
len( file("mytestfile","r").read() ) != os.path.getsize("mytestfile")
 
Not even close, in fact. It seems like file.read() just stops after
reading a small portion of each example file, but why would that happen?
And what could I do if I wanted to read in the entire (compressed)
contents as a string?
 
thanks for any insight,
 
Dave (using Python 2.4 and windows)

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] file.read() doesn't give full contents of compressed files

2007-02-20 Thread Kent Johnson
Barton David wrote:
> Hi,
> I'm really confused, and I hope somebody can explain this for me...
>  
> I've been playing with compression and archives, and have some .zip, 
> .tar, .gz and .tgz example files to test my code on.
> I can read them using either zipfile, tarfile, gzip or zlib, and that's 
> fine. But just reading them in 'raw' doesn't give me the whole string of 
> (compressed) bytes.
>  
> i.e...
>  
> len( file("mytestfile","r").read() ) != os.path.getsize("mytestfile")
>  
> Not even close, in fact. It seems like file.read() just stops after 
> reading a small portion of each example file, but why would that happen? 
> And what could I do if I wanted to read in the entire (compressed) 
> contents as a string?

Why do you think it stops reading? len() should be giving a bigger 
number than getsize() because you are reading the file in text mode 
which will convert \n to \r\n. Try file("mytestfile","rb").

Kent

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


Re: [Tutor] file.read() doesn't give full contents of compressed files

2007-02-20 Thread Barton David
Oh... of course. Thanks and sorry for missing the bleeding obvious.

Mind you, when reading in 'txt mode' rather than binary, len() actually
gives a much *smaller* size than getsize. Does the conversion into txt
happen to introduce some sort of terminator character that stops
file.read() from going to the end?

Dave


-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 20 February 2007 12:53
To: Barton David
Cc: tutor@python.org
Subject: Re: [Tutor] file.read() doesn't give full contents of
compressed files

Barton David wrote:
> Hi,
> I'm really confused, and I hope somebody can explain this for me...
>  
> I've been playing with compression and archives, and have some .zip, 
> .tar, .gz and .tgz example files to test my code on.
> I can read them using either zipfile, tarfile, gzip or zlib, and 
> that's fine. But just reading them in 'raw' doesn't give me the whole 
> string of
> (compressed) bytes.
>  
> i.e...
>  
> len( file("mytestfile","r").read() ) != os.path.getsize("mytestfile")
>  
> Not even close, in fact. It seems like file.read() just stops after 
> reading a small portion of each example file, but why would that
happen?
> And what could I do if I wanted to read in the entire (compressed) 
> contents as a string?

Why do you think it stops reading? len() should be giving a bigger
number than getsize() because you are reading the file in text mode
which will convert \n to \r\n. Try file("mytestfile","rb").

Kent


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] file.read() doesn't give full contents of compressed files

2007-02-20 Thread Kent Johnson
Barton David wrote:
> Oh... of course. Thanks and sorry for missing the bleeding obvious.
> 
> Mind you, when reading in 'txt mode' rather than binary, len() actually
> gives a much *smaller* size than getsize. Does the conversion into txt
> happen to introduce some sort of terminator character that stops
> file.read() from going to the end?

Actually, yes. A ctrl-Z is treated as an end-of-file when reading a file 
in text mode on Windows.
http://groups.google.com/group/comp.lang.python/msg/4604aac0222a0043?hl=en&;

Kent

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


Re: [Tutor] file.read() doesn't give full contents of compressed files

2007-02-20 Thread Barton David
I see. Thanks for that.

dave 

-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 20 February 2007 13:30
To: Barton David
Cc: tutor@python.org
Subject: Re: [Tutor] file.read() doesn't give full contents of
compressed files

Barton David wrote:
> Oh... of course. Thanks and sorry for missing the bleeding obvious.
> 
> Mind you, when reading in 'txt mode' rather than binary, len() 
> actually gives a much *smaller* size than getsize. Does the conversion

> into txt happen to introduce some sort of terminator character that 
> stops
> file.read() from going to the end?

Actually, yes. A ctrl-Z is treated as an end-of-file when reading a file
in text mode on Windows.
http://groups.google.com/group/comp.lang.python/msg/4604aac0222a0043?hl=
en&

Kent


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread carpentier . th
Selon [EMAIL PROTECTED]:

> Hi!
>
> With python, you can work with a lot of Database, likes mysql, oracle,
> sqlite,
> SQLServer, PostgreSQL
>
> If you use Python2.5, sqlite3 is already installed.
>
> However, you can choose any data base which you want to use.
>
> Thomas
>
>
> Selon Asrarahmed Kadri <[EMAIL PROTECTED]>:
>
> > Hi folks,
> >
> > I want to develop an application which uses a database and some forms to
> > enter/modify the database.
> > The application should also generate reports based on some fields.
> >
> > What should I be using? Python or VB...
> >
> > I want to use Python.. IN that case, what should be my choice for the
> > Database..
> >
> > Thanks in anticipation.
> >
> > Best Regards,
> > Asrarahmed Kadri
> >
> >
> >
> >
> > --
> > To HIM you shall return.
> >
>
>
>


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


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread Bob Gailer
Asrarahmed Kadri wrote:
>
> Hi folks,
>  
> I want to develop an application which uses a database and some forms 
> to enter/modify the database.
> The application should also generate reports based on some fields.
>  
> What should I be using? Python or VB...
>  
> I want to use Python.. IN that case, what should be my choice for the 
> Database..
The choice of DB, IMHO, is independent of the programming language. Both 
VB and Python can interact with almost any database system.

What are your criteria for a database? Single or multiple user? Local or 
remote server? Size? Transaction rate?

-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread Don Taylor
Asrarahmed Kadri wrote:

> I want to develop an application which uses a database and some forms to 
> enter/modify the database.
> The application should also generate reports based on some fields.
>  
> What should I be using? Python or VB...

That is both a religious question, and fighting words...
>  
> I want to use Python.. IN that case, what should be my choice for the 
> Database..
>

Ahhh, that is ok then.

Assuming this is not a web-based application, then take a look at the 
Dabo framework:

http://dabodev.com/

It supports MySQL, PostgreSQL, Firebird and SQLite backends at the moment.

Take a look through the screencasts to get an idea about what Dabo can 
do for you.

http://dabodev.com/documentation

Don.

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


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread johnf
On Tuesday 20 February 2007 06:49, Don Taylor wrote:
> Asrarahmed Kadri wrote:
> > I want to develop an application which uses a database and some forms to
> > enter/modify the database.
> > The application should also generate reports based on some fields.
> >
> > What should I be using? Python or VB...
>
> That is both a religious question, and fighting words...
>
> > I want to use Python.. IN that case, what should be my choice for the
> > Database..
>
> Ahhh, that is ok then.
>
> Assuming this is not a web-based application, then take a look at the
> Dabo framework:
>
> http://dabodev.com/
>
> It supports MySQL, PostgreSQL, Firebird and SQLite backends at the moment.
>
> Take a look through the screencasts to get an idea about what Dabo can
> do for you.
>
> http://dabodev.com/documentation
>
> Don.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
Supports Ms SQL too.  
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] It lives...

2007-02-20 Thread Kirk Z Bailey
I'm back.

Melted my life, got a divorce, gutted the house, acquired true love, 2 
cats, redid house, new job, and dentures. Let's see, I still need a 
total blood change-out, but other than that, I did it all.

Now I can start paying attention to python and wiki's again.

And this is good, because the new edition of python does not like my 
windows wiki very well. Seems when it reads the page in, it creates the 
data in a list- with everything in one cell, not one line per cell. 
Hmmm it did not used to do this... bitrot?


-- 
end

Very Truly yours,
  - Kirk Bailey,
Largo Florida

kniht
   +-+
   | BOX |
   +-+
think

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


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread Asrarahmed Kadri

Thanks a lot for the support...

Cheers

On 2/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


Hi!

With python, you can work with a lot of Database, likes mysql, oracle,
sqlite,
SQLServer, PostgreSQL

If you use Python2.5, sqlite3 is already installed.

However, you can choose any data base which you want to use.

Thomas


Selon Asrarahmed Kadri <[EMAIL PROTECTED]>:

> Hi folks,
>
> I want to develop an application which uses a database and some forms to
> enter/modify the database.
> The application should also generate reports based on some fields.
>
> What should I be using? Python or VB...
>
> I want to use Python.. IN that case, what should be my choice for the
> Database..
>
> Thanks in anticipation.
>
> Best Regards,
> Asrarahmed Kadri
>
>
>
>
> --
> To HIM you shall return.
>






--
To HIM you shall return.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using SQLite with matplotlib - queries vs. lists

2007-02-20 Thread Pine Marten
I'm a novice hoping to use data stored in an SQLite database to make simple 
graphs using matplotlib embedded in a wxPython GUI.  I noticed that 
matplotlib uses lists of integers to make graphs, such as the simple example 
(from the tutorial) of:

from pylab import *
plot([1,2,3,4])
show()

But SQLite queries return as a list of tuples in rows, not a list of 
numbers.  For some reason I haven't found a way any ready-made converter for 
this purpose.  As an exercise, I've wrote this function that converts them:

#takes the result of a fetchall() in sql and returns it as a list of numbers
#assumes you've done the query first, i.e. cur.execute('SELECT * FROM 
table')
import sqlite3
import string
def query_to_list():
queryresult = cur.fetchall()
print "Queryresult is ", queryresult
queryrows = []
for tuple in queryresult:
num = tuple[0]
queryrows.append(num)
querylist = []
for row in queryrows:
num = int(row)
querylist.append(num)
print "Query list is: ", querylist

My question is, is there a better way to do this, or is there a ready-made 
way to go from an sql database to matplotlib?  I tried searching for it in 
various ways but haven't found anything.  I feel as though there should be a 
more direct way to go from a db to a plot.

Thanks in advance,
Chae

_
Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month. 
Intro*Terms  http://www.NexTag.com

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


Re: [Tutor] using SQLite with matplotlib - queries vs. lists

2007-02-20 Thread Kent Johnson
Pine Marten wrote:
> I'm a novice hoping to use data stored in an SQLite database to make simple 
> graphs using matplotlib embedded in a wxPython GUI.  I noticed that 
> matplotlib uses lists of integers to make graphs, such as the simple example 
> (from the tutorial) of:
> 
> from pylab import *
> plot([1,2,3,4])
> show()
> 
> But SQLite queries return as a list of tuples in rows, not a list of 
> numbers.  For some reason I haven't found a way any ready-made converter for 
> this purpose.  As an exercise, I've wrote this function that converts them:
> 
> #takes the result of a fetchall() in sql and returns it as a list of numbers
> #assumes you've done the query first, i.e. cur.execute('SELECT * FROM 
> table')
> import sqlite3
> import string
> def query_to_list():
> queryresult = cur.fetchall()
> print "Queryresult is ", queryresult
> queryrows = []
> for tuple in queryresult:
> num = tuple[0]
> queryrows.append(num)
> querylist = []
> for row in queryrows:
> num = int(row)
> querylist.append(num)
> print "Query list is: ", querylist

This whole function can be replaced with
 querylist = [ int(row[0]) for rowin cur.fetchall() ]

PS Don't use tuple as a variable name, you will shadow the built-in tuple.

Kent

> 
> My question is, is there a better way to do this, or is there a ready-made 
> way to go from an sql database to matplotlib?  I tried searching for it in 
> various ways but haven't found anything.  I feel as though there should be a 
> more direct way to go from a db to a plot.
> 
> Thanks in advance,
> Chae
> 
> _
> Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month. 
> Intro*Terms  http://www.NexTag.com
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


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


[Tutor] how to read one bit of a byte

2007-02-20 Thread shawn bright

lo there all,

i am reading a binary file with open('myfile', 'rb')

then i do a read(1) to read one byte. cool so far.

but how do i read the individual bits of a byte

i mean if i have a = read(1)

how do i know what the msb of a is ?

i need to know because i have to see if the msb is set and i also need to
know the value of the next bit.

any tips would be greatly appreciated.

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


Re: [Tutor] how to read one bit of a byte

2007-02-20 Thread Luke Paireepinart
shawn bright wrote:
> lo there all,
>
> i am reading a binary file with open('myfile', 'rb')
>
> then i do a read(1) to read one byte. cool so far.
>
> but how do i read the individual bits of a byte
>
> i mean if i have a = read(1)
>
> how do i know what the msb of a is ?
>
> i need to know because i have to see if the msb is set and i also need 
> to know the value of the next bit.
Well, you know the value of the MSB is...
1 2 4 8 16 32 64 128
so if you divide the value by 128, and get a 1 and not a 0, then it's set.
People commonly write functions to make binary lists from values.
-Luke
>
> any tips would be greatly appreciated.
>
> thanks
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

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


[Tutor] re and MULTILINE

2007-02-20 Thread Marilyn Davis
Hello Tutors,

I'm trying to get a grip on MULTILINE and I guess I don't have it.

Here's some code:

#!/usr/bin/env python
import re

def sub_it(mo):
return 'xxx'

def test(re_str, data):
return re.sub(re_str, sub_it, data, re.MULTILINE)

if __name__ == '__main__':
data = '''Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 
93756:9/21/46:43500
Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
'''
re_str = r'''(d+)$'''
print test(re_str, data)

re_str = r'''(d+)'''
print test(re_str, data)

'''
./re_test2.py
Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 93756:9/21/46:43500
Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:xxx

Betty Boop:xxx-xxx-xxx:xxx Ware Road, Milton, PA xxx:xxx/xxx/xxx:43500
Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
'''

If I don't anchor it with '$', it gets all the digit-groups in the first line 
except the last one.  Why not the last one?  Whay not the other lines?

If I do anchor it, it only gets the last group on the last line.  What's up 
with that?

What I really want, is to mess with each of the last digit-groups on each line. 
 But I can't find them.

The exercise is from Ellie Quigley's "Perl by Example"

Thank you for any help.

Marilyn Davis


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


[Tutor] Reading compressed files

2007-02-20 Thread Shadab Sayani
Hi,
  I have compressed files compressed using different techniques  (especially 
unix compress). So I want to have a module that reads any  of these 
(.Z,.bz,.tgz files) files and manipulates the data.
  The data has a syntax.It contains
  HEADER (some information)
  BODY  (some information)
  FOOTER   (some information)
  If it were a normal text file I can get the values corresponding to HEADER 
BODY and FOOTER by open function.
  But here the files are in different format .Z , .bz ,.tgz,.gz .But I  know 
these are the only formats.Also I cannot rely upon the extensions  of the file 
(a .Z file can have no extension at all).Is there a way to  identify  which 
file am I reading and then  read it?If so how  to read it?
  Thanks and Regards,
  Shadab.
 Send instant messages to your online friends http://uk.messenger.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re and MULTILINE

2007-02-20 Thread Kent Johnson
Marilyn Davis wrote:
> Hello Tutors,
>
> I'm trying to get a grip on MULTILINE and I guess I don't have it.
>
> Here's some code:
>
> #!/usr/bin/env python
> import re
>
> def sub_it(mo):
> return 'xxx'
>
> def test(re_str, data):
> return re.sub(re_str, sub_it, data, re.MULTILINE)
>   
The fourth argument to re.sub() is a count, not flags. You have to 
compile the regex and pass the MULTILINE flag to the compile, or include 
the flag in the actual regex with *|(?m)|*.

Kent


> 
> if __name__ == '__main__':
> data = '''Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 
> 93756:9/21/46:43500
> Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
> '''
> re_str = r'''(d+)$'''
> print test(re_str, data)
> 
> re_str = r'''(d+)'''
> print test(re_str, data)
>
> '''
> ./re_test2.py
> Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 93756:9/21/46:43500
> Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:xxx
>
> Betty Boop:xxx-xxx-xxx:xxx Ware Road, Milton, PA xxx:xxx/xxx/xxx:43500
> Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
> '''
>
> If I don't anchor it with '$', it gets all the digit-groups in the first line 
> except the last one.  Why not the last one?  Whay not the other lines?
>
> If I do anchor it, it only gets the last group on the last line.  What's up 
> with that?
>
> What I really want, is to mess with each of the last digit-groups on each 
> line.  But I can't find them.
>
> The exercise is from Ellie Quigley's "Perl by Example"
>
> Thank you for any help.
>
> Marilyn Davis
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   

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


[Tutor] summer_v04.py

2007-02-20 Thread Christopher Spears
I've been working on a version of a script I found in
"Programming Python".  The helpful users of this forum
gave me some advice to make the code less wordy.  Here
is the code:

#!/usr/bin/python
import string

def find_longest_line(fileName):
line_list = [line.split() for line in open(fileName,
'r').readlines()]
numCols = max(len(cols) for cols in line_list)
#print numCols
return numCols

def summer(fileName):
length_longest_col = find_longest_line(fileName)
sums = [0] * length_longest_col
for line in line_list:
cols = string.split(line)
for i in range(len(cols)):
sums[i] = sums[i] + float(cols[i])
return sums

if __name__ == '__main__':
import sys
print summer(sys.argv[1])
#print find_longest_line(sys.argv[1])

The code opens a file called table.txt:
1   5   10  2   1.0
2   10  20  4   2.0 3
3   15  30  8   3   2   1
4   20  40  16  4.0

Then the script adds the columns in the file together.

However, when I run the script, I get a syntax error:

[EMAIL PROTECTED] ./text_proc 151> ./summer_v04.py
table.txt
  File "./summer_v04.py", line 6
numCols = max(len(cols) for cols in line_list)
  ^
SyntaxError: invalid syntax

I can't figure out what the error is.

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


Re: [Tutor] summer_v04.py

2007-02-20 Thread John Fouhy
On 21/02/07, Christopher Spears <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] ./text_proc 151> ./summer_v04.py
> table.txt
>   File "./summer_v04.py", line 6
> numCols = max(len(cols) for cols in line_list)
>   ^
> SyntaxError: invalid syntax

What version of python are you running?

If you are running 2.3.x or earlier, you will need to rewrite this as:

numCols = max([len(cols) for cols in line_list])

(because you are using a generator expression, and they were only
introduced in 2.4)

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


Re: [Tutor] re and MULTILINE

2007-02-20 Thread Marilyn Davis
On Tue, 20 Feb 2007, Kent Johnson wrote:

> Marilyn Davis wrote:
> > Hello Tutors,
> >
> > I'm trying to get a grip on MULTILINE and I guess I don't have it.
> >
> > Here's some code:
> >
> > #!/usr/bin/env python
> > import re
> >
> > def sub_it(mo):
> > return 'xxx'
> >
> > def test(re_str, data):
> > return re.sub(re_str, sub_it, data, re.MULTILINE)
> >   
> The fourth argument to re.sub() is a count, not flags. You have to 
> compile the regex and pass the MULTILINE flag to the compile, or include 
> the flag in the actual regex with *|(?m)|*.

Thank you so much!!  Duh.  Geeso, I looked at that for hours.

I should have asked for help sooner.

Gratefully,

Marilyn

> 
> Kent
> 
> 
> > 
> > if __name__ == '__main__':
> > data = '''Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 
> > 93756:9/21/46:43500
> > Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> > James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
> > '''
> > re_str = r'''(d+)$'''
> > print test(re_str, data)
> > 
> > re_str = r'''(d+)'''
> > print test(re_str, data)
> >
> > '''
> > ./re_test2.py
> > Betty Boop:245-836-2837:6937 Ware Road, Milton, PA 93756:9/21/46:43500
> > Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> > James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:xxx
> >
> > Betty Boop:xxx-xxx-xxx:xxx Ware Road, Milton, PA xxx:xxx/xxx/xxx:43500
> > Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
> > James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
> > '''
> >
> > If I don't anchor it with '$', it gets all the digit-groups in the first 
> > line except the last one.  Why not the last one?  Whay not the other lines?
> >
> > If I do anchor it, it only gets the last group on the last line.  What's up 
> > with that?
> >
> > What I really want, is to mess with each of the last digit-groups on each 
> > line.  But I can't find them.
> >
> > The exercise is from Ellie Quigley's "Perl by Example"
> >
> > Thank you for any help.
> >
> > Marilyn Davis
> >
> >
> > ___
> > 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] summer_v04.py

2007-02-20 Thread Rikard Bosnjakovic
On 2/21/07, John Fouhy <[EMAIL PROTECTED]> wrote:

> (because you are using a generator expression, and they were only
> introduced in 2.4)

List comprehensions were implemented in v2.0. The OP probably does not
use an older version, but as far as I can see, his syntax error line
uses parenthesis - not brackets - hence the error.


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


Re: [Tutor] how to read one bit of a byte

2007-02-20 Thread shawn bright

great, thanks for this. appreciate it a lot.

sk

On 2/20/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:


shawn bright wrote:
> lo there all,
>
> i am reading a binary file with open('myfile', 'rb')
>
> then i do a read(1) to read one byte. cool so far.
>
> but how do i read the individual bits of a byte
>
> i mean if i have a = read(1)
>
> how do i know what the msb of a is ?
>
> i need to know because i have to see if the msb is set and i also need
> to know the value of the next bit.
Well, you know the value of the MSB is...
1 2 4 8 16 32 64 128
so if you divide the value by 128, and get a 1 and not a 0, then it's set.
People commonly write functions to make binary lists from values.
-Luke
>
> any tips would be greatly appreciated.
>
> thanks
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


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


[Tutor] Function for converting ints from base10 to base2?

2007-02-20 Thread Dick Moores
I was surprised to be unable to find a function in Python for 
converting ints from base10 to base2. Is there one?

I wrote one, but have I reinvented the wheel again? (Even if I have, 
it was an interesting exercise for me.)

I know some of you CS people won't like what I do with negative ints, 
but I wanted it this way. On other points than that, I'd appreciate 
criticism/suggestions.

===
def computeBin(n):
 """converts base10 integer n to base2 b as string"""
 from math import log, floor
 sign = ''
 if n == 0:
 b = '0'
 else:
 if n < 0:
 sign = "-"
 n = -n
 e = int(floor(log(n,2)))
 b = '1'

 for x in range(e):
 r = n % 2**e
 if r >= 2**(e-1):
 b += '1'
 else:
 b += '0'
 e -= 1
 return sign + b

def printResult(n,b):
 print "%d is %s" % (n, b)

def confirmResult(n,b):
 print "Confirming using int():"
 print "int(%s,2) is %s" % (b, int(b,2))

if __name__ == '__main__':
 n = 1234567890
 b = computeBin(n)
 printResult(n,b)
 confirmResult(n,b)
==

Dick Moores

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


Re: [Tutor] Function for converting ints from base10 to base2?

2007-02-20 Thread David Perlman
I suspect the function I sent out earlier, using octal conversion and  
a lookup table, will be faster.  But it would be very interesting to  
see some simple benchmarks.

On Feb 20, 2007, at 10:47 PM, Dick Moores wrote:

> I was surprised to be unable to find a function in Python for
> converting ints from base10 to base2. Is there one?
>
> I wrote one, but have I reinvented the wheel again? (Even if I have,
> it was an interesting exercise for me.)
>
> I know some of you CS people won't like what I do with negative ints,
> but I wanted it this way. On other points than that, I'd appreciate
> criticism/suggestions.
>
> ===
> def computeBin(n):
>  """converts base10 integer n to base2 b as string"""
>  from math import log, floor
>  sign = ''
>  if n == 0:
>  b = '0'
>  else:
>  if n < 0:
>  sign = "-"
>  n = -n
>  e = int(floor(log(n,2)))
>  b = '1'
>
>  for x in range(e):
>  r = n % 2**e
>  if r >= 2**(e-1):
>  b += '1'
>  else:
>  b += '0'
>  e -= 1
>  return sign + b
>
> def printResult(n,b):
>  print "%d is %s" % (n, b)
>
> def confirmResult(n,b):
>  print "Confirming using int():"
>  print "int(%s,2) is %s" % (b, int(b,2))
>
> if __name__ == '__main__':
>  n = 1234567890
>  b = computeBin(n)
>  printResult(n,b)
>  confirmResult(n,b)
> ==
>
> Dick Moores
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
-dave
After all, it is not *that* inexpressible.
-H.H. The Dalai Lama



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


[Tutor] list problem

2007-02-20 Thread Kirk Bailey
ok, getting back to python and wikiness, I have a problem, this software 
of mine seems to exibit different behavior under the latest edition of 
python (2.5) than under the version used when I first wrote it (2.3).

It loads the page file, but returns it as a list (which is correcft) of 
one element, the entire file is in one cell. Prior, it returned each 
line as an element in the list. this is causing me some processing 
problems, and I am not a happy camper.

I am still getting out the WD-40 and loosening up rusty hinges and 
joints oin my python processing prefrontals, it's been quite a while. I 
cna post the current program to a website if it would help, or send it 
to you off list directly.

The idea is to use MiniWiki in one's windoze laptop as a wiki/notebook. 
Wikinehesa is optimied for freebsd/linux and works fine as is.

Discussion on or off list is saught. Constructive criticism will be 
graciously received and thanked.

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


Re: [Tutor] list problem

2007-02-20 Thread Luke Paireepinart
Kirk Bailey wrote:
> ok, getting back to python and wikiness, I have a problem, this software 
> of mine seems to exibit different behavior under the latest edition of 
> python (2.5) than under the version used when I first wrote it (2.3).
>
> It loads the page file, but returns it as a list (which is correcft) of 
> one element, the entire file is in one cell. Prior, it returned each 
> line as an element in the list. this is causing me some processing 
> problems, and I am not a happy camper.
>
> I am still getting out the WD-40 and loosening up rusty hinges and 
> joints oin my python processing prefrontals, it's been quite a while. I 
> cna post the current program to a website if it would help, or send it 
> to you off list directly.
>
> The idea is to use MiniWiki in one's windoze laptop as a wiki/notebook. 
> Wikinehesa is optimied for freebsd/linux and works fine as is.
>
> Discussion on or off list is saught. Constructive criticism will be 
> graciously received and thanked.
>
>   
If you could give us a snippet of input data,
as well as the function and the 10 or so lines preceding and following 
it, that returns a single-element list,
we could probably help.  Or better yet, write a new function that's very 
simple that just displays the behavior you don't want.
It sounds like you have a lot of code, though, and since you know where 
the problem is occurring it's easier if you give us an excerpt,
the cliffs notes version, if you will, than for one of us to read 
through your code.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list problem

2007-02-20 Thread Rikard Bosnjakovic
On 2/21/07, Kirk Bailey <[EMAIL PROTECTED]> wrote:

[...]
> Discussion on or off list is saught. Constructive criticism will be
> graciously received and thanked.

Without links, pointers, code or anything grippable I find it
difficult to comment or discuss anything, since i haven't got the
faintest idea or your setup, environments, applications, and the like.

How about giving it another go, feeding us with more info?

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


Re: [Tutor] list problem

2007-02-20 Thread Luke Paireepinart
Kirk:
Please reply to this message, not the other one I sent,
and please reply on-list in the future, using the 'reply-all' button 
rather than 'reply.'
Otherwise the message just goes to me instead of to everyone, which is 
the default on this list.
This copy of your e-mail is forwarded to the list, so use a 'reply-all' 
on it so everyone can see your reply.
-Luke


Original e-mail:

Kirk Bailey wrote:
> ok, here comes some code:
>
> f1=open(pagename,'r')
> page=f1.readlines()
> f1.close()
>
> at the end of which, the data is in page, which is a list. But 
> something strange is going on here. all the data is in a single cell! 
> it's a one cell list! Say what?
>
> Later on, when we try to itenerate the list and do things line by 
> line, it takes the entire thing at one swallow, and this creates some 
> trouble.
>
> Here's is a link to the entire program.
> http://www.tinylist.org/MW.txt
> this is the reader engine for a wiki to be used in a windows environment.
>
>
>
> Luke Paireepinart wrote:
>> Kirk Bailey wrote:
>>> ok, getting back to python and wikiness, I have a problem, this 
>>> software of mine seems to exibit different behavior under the latest 
>>> edition of python (2.5) than under the version used when I first 
>>> wrote it (2.3).
>>>
>>> It loads the page file, but returns it as a list (which is correcft) 
>>> of one element, the entire file is in one cell. Prior, it returned 
>>> each line as an element in the list. this is causing me some 
>>> processing problems, and I am not a happy camper.
>>>
>>> I am still getting out the WD-40 and loosening up rusty hinges and 
>>> joints oin my python processing prefrontals, it's been quite a 
>>> while. I cna post the current program to a website if it would help, 
>>> or send it to you off list directly.
>>>
>>> The idea is to use MiniWiki in one's windoze laptop as a 
>>> wiki/notebook. Wikinehesa is optimied for freebsd/linux and works 
>>> fine as is.
>>>
>>> Discussion on or off list is saught. Constructive criticism will be 
>>> graciously received and thanked.
>>>
>>>   
>> If you could give us a snippet of input data,
>> as well as the function and the 10 or so lines preceding and 
>> following it, that returns a single-element list,
>> we could probably help.  Or better yet, write a new function that's 
>> very simple that just displays the behavior you don't want.
>> It sounds like you have a lot of code, though, and since you know 
>> where the problem is occurring it's easier if you give us an excerpt,
>> the cliffs notes version, if you will, than for one of us to read 
>> through your code.
>> -Luke
>>
>>
>

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


Re: [Tutor] Function for converting ints from base10 to base2?

2007-02-20 Thread Dick Moores
Well, I can't compare mine with yours (where is it?), but using the 
template in timeit.py:

template = """
def inner(_it, _timer):
 from decToBin import computeBin
 _t0 = _timer()
 for _i in _it:
 computeBin(12345678901234567890)
 _t1 = _timer()
 return _t1 - _t0
"""
I get these results:

for computeBin(12345678901234567890)
1000 loops, best of 3: 448 usec per loop

for computeBin(1234567890)
1 loops, best of 3: 59.7 usec per loop

for computeBin(12345)
1 loops, best of 3: 35.2 usec per loop

Dick Moores

At 09:04 PM 2/20/2007, David Perlman wrote:
>I suspect the function I sent out earlier, using octal conversion and
>a lookup table, will be faster.  But it would be very interesting to
>see some simple benchmarks.
>
>On Feb 20, 2007, at 10:47 PM, Dick Moores wrote:
>
> > I was surprised to be unable to find a function in Python for
> > converting ints from base10 to base2. Is there one?
> >
> > I wrote one, but have I reinvented the wheel again? (Even if I have,
> > it was an interesting exercise for me.)
> >
> > I know some of you CS people won't like what I do with negative ints,
> > but I wanted it this way. On other points than that, I'd appreciate
> > criticism/suggestions.
> >
> > ===
> > def computeBin(n):
> >  """converts base10 integer n to base2 b as string"""
> >  from math import log, floor
> >  sign = ''
> >  if n == 0:
> >  b = '0'
> >  else:
> >  if n < 0:
> >  sign = "-"
> >  n = -n
> >  e = int(floor(log(n,2)))
> >  b = '1'
> >
> >  for x in range(e):
> >  r = n % 2**e
> >  if r >= 2**(e-1):
> >  b += '1'
> >  else:
> >  b += '0'
> >  e -= 1
> >  return sign + b
> >
> > def printResult(n,b):
> >  print "%d is %s" % (n, b)
> >
> > def confirmResult(n,b):
> >  print "Confirming using int():"
> >  print "int(%s,2) is %s" % (b, int(b,2))
> >
> > if __name__ == '__main__':
> >  n = 1234567890
> >  b = computeBin(n)
> >  printResult(n,b)
> >  confirmResult(n,b)
> > ==
> >
> > Dick Moores
> >
>
>--
>-dave
>After all, it is not *that* inexpressible.
>-H.H. The Dalai Lama


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