Re: PIL issues

2006-07-31 Thread Amit Khemka
On 8/1/06, David Bear <[EMAIL PROTECTED]> wrote:
> I am trying to use PIL and when building it, PIL fails to find my jpeg
> library. I am using a python 2.4.3 that I build myself on Suse linux 9.3. I
> do have the following jpeg libraries:
>
> rpm -qa | grep jpeg
> jpeg-6b-738
> libjpeg-32bit-9.3-7
> libjpeg-6.2.0-738
>
>
> yet, when building PIL I get:
>
> python setup.py build_ext -i
> running build_ext
> 
> PIL 1.1.5 BUILD SUMMARY
> 
> version   1.1.5
> platform  linux2 2.4.2 (#4, Jul 27 2006, 14:34:30)
>   [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)]
> 
> *** TKINTER support not available
> *** JPEG support not available
> --- ZLIB (PNG/ZIP) support ok
> *** FREETYPE2 support not available
> 
> To add a missing option, make sure you have the required
> library, and set the corresponding ROOT variable in the
> setup.py script.
>
> I don't know what ROOT variable the message is referring too. Any advice
> would be appreciated.


This is because PIL, is not able to find the jpeg/other libraries .

1. Install jpeg-libs from sources: (http://www.ijg.org/files/jpegsrc.v6b.tar.gz)
2.0: "clean" the PIL build
2.1 In setup.py that comes with PIL, set the JPEG_ROOT to the jpeg-lib path
3.0 run setup.py

I hope that should help ..

cheers,
amit


-- 

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: realine not found error

2006-07-31 Thread Peter Otten
David Bear wrote:

> I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
> instance of python from the version packaged with suse.
> 
> Now when I start it I get an error:
> python
> Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
> [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> Traceback (most recent call last):
>   File "/etc/pythonstart", line 7, in ?
> import readline
> ImportError: No module named readline
> 
> however, I do have readline installed:
> 
> rpm -qa | grep readline
> readline-5.0-7.2
> readline-32bit-9.3-7.1

You may have to install the readline-devel package and the rebuild Python.

Peter

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


Re: ANN: Quest for the Holy Grail (a PyGame game)

2006-07-31 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: Wing IDE 2.1.1 released

2006-07-31 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: ANN: Quest for the Holy Grail (a PyGame game)

2006-07-31 Thread Horst F. JENS
very nice game, i like it.
-Horst
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code to retrieve web mail?

2006-07-31 Thread Paul McGuire
"John Savage" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have a free web mail address and would like to use python to retrieve
> files that have been emailed to me. The basic code would accommodate
> cookies, a login name and password, then download using the full URL I
> can provide. From postings here I thought mechanize held promise, but
> I've found it to contain filenames that are invalid for MSDOS (too many
> characters, and/or too many dots in the name, etc.) so I have little hope
> that the mechanize module can be used.
>
> I'm running python2.4.2 on plain MSDOS (not windows), so would appreciate
> a pointer to sample code that can do the job. I know that curl has this
> capability, but I'll learn something by tinkering with python code.
>
> Thanks.
> --
> John Savage   (my news address is not valid for email)

Instead of mimicking a browser to access this e-mail account through the web
interface, see if there is a POP3 access to your free e-mail (I'd be
surprised if there isn't).  POP3 programming (using the supplied poplib
module) is *very* simple in Python, handles login name and pwd, no
cookie-ing required.  The Python docs include this example:
http://docs.python.org/lib/pop3-example.html

-- Paul


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


Re: Pickle vs XML for file I/O

2006-07-31 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, crystalattice wrote:

> On Mon, 31 Jul 2006 14:35:39 -1000, Simon Forman <[EMAIL PROTECTED]>  
> wrote:
> 
>> What kind of trouble were you having with pickle?
>
> It's mostly a combination of things (I hope you can follow my logic).   
> First, to use "good programming practice", I want to implement a  
> try/except block for opening the pickle file.  But I can't figure out if  
> this block should be included outside the classes, included in just the  
> base class, or if the base and subclasses need it; I'm leaning to putting  
> outside the classes as a global method.

That's not a problem with pickle but where you think a potential IO error
is handled best.  Ask yourself if you can do something sensible at the
point where you catch an exception.  If you don't know what to do with it,
don't catch it and just let it propagate.

> When pickling a class instance, is the pickle statement placed within the  
> class (say, at the end of the class) or is it where the instance is  
> created, such as a test() method?

`pickle.dump()` and `pickle.load()` are not statements but just functions.
And you should place a call where you actually want to save or load
instances in your program flow.

> Plus, to modify data in a class, do I have to unpickle the whole thing  
> first or is there a way to modify the data while it's pickled?  Actually,  
> I think I can answer that last question:  a character instance, having  
> been created, will stay resident in memory until the player quits,  
> character dies, or otherwise is no longer needed.  At that point the  
> character instance should be pickled (if necessary) to disk; pickle  
> shouldn't be used while data modification is required and the class  
> instance is "active", correct?

Yes that's correct.  It wouldn't be different with XML.

> I also remember reading on a thread here that pickle sometimes has issues  
> when used with classes, which makes me hesitant to pickle an entire class  
> instance.  That's why I thought XML may be safer/better.

You can't pickle everything.  Files for example are unpickleable and you
can't pickle code so pickling classes is not that useful.

An advantage of `pickle` is that it's in the standard library and ready to
use for serialization.  To get an XML solution you must either write your
own serialization code or use a 3rd party library.

What are the problems you fear when using `shelve` by the way?

Ciao,
Marc 'BlackJack' Rintsch

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

[EMAIL PROTECTED] wrote:
> John Machin wrote:
> > [EMAIL PROTECTED] wrote:
> > > Philippe Martin wrote:
> > > > Yes, I came here for the "algorithm" question, not the code result.
> > >
> > > To turn BCD x to binary integer y,
> > >
> > >   set y to zero
> > >   for each nibble n of x:
> > > y = (((y shifted left 2) + y) shifted left 1) + n
> >
> > Yeah yeah yeah
> > i.e. y = y * 10 + n
> > he's been shown that already.
> >
> > Problem is that the OP needs an 8-decimal-digit (32-bits) answer, but
> > steadfastly maintains that he doesn't "have access to" long (32-bit)
> > arithmetic in his C compiler!!!
>
> And he doesn't need one. He might need the algorithms for shift and
> add.
>

I hate to impose this enormous burden on you but you may wish to read
the whole thread. He was given those "algorithms". He then upped the
ante to 24 decimal digits and moved the goalposts to some chip running
a cut-down version of Java ...

TTFN
John

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


Re: Pickle vs XML for file I/O

2006-07-31 Thread John Machin

crystalattice wrote:
>
> Plus, to modify data in a class

I presume the word "instance" is missing here ...

> do I have to unpickle the whole thing
> first or is there a way to modify the data while it's pickled?  Actually,
> I think I can answer that last question:  a character instance, having
> been created, will stay resident in memory until the player quits,
> character dies, or otherwise is no longer needed.  At that point the
> character instance should be pickled (if necessary) to disk; pickle
> shouldn't be used while data modification is required and the class
> instance is "active", correct?

A pickle is a snapshot of an object and its contents. If the real
scenery changes, you need to take another photo.

Unpickling creates another instance from the blueprint. You can repeat
this to obtain multiple distinct copies of the instance.

Partial unpickling is not possible.

Use cPickle if you can; it's much faster.

HTH,
John

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


Re: BCD List to HEX List

2006-07-31 Thread bryanjugglercryptographer

John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > Philippe Martin wrote:
> > > Yes, I came here for the "algorithm" question, not the code result.
> >
> > To turn BCD x to binary integer y,
> >
> >   set y to zero
> >   for each nibble n of x:
> > y = (((y shifted left 2) + y) shifted left 1) + n
>
> Yeah yeah yeah
> i.e. y = y * 10 + n
> he's been shown that already.
>
> Problem is that the OP needs an 8-decimal-digit (32-bits) answer, but
> steadfastly maintains that he doesn't "have access to" long (32-bit)
> arithmetic in his C compiler!!!

And he doesn't need one. He might need the algorithms for shift and
add.


-- 
--Bryan

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

Grant Edwards wrote:
> On 2006-08-01, Philippe Martin <[EMAIL PROTECTED]> wrote:
>
> >> Perhaps if Philippe could divulge the part number that's in
> >> the bottom right corner of the manual that he has, and/or any
> >> part number that might be mentioned in the first few pages of
> >> that manual, enlightenment may ensue 
> >
> > That was cute ... over and out !
>
> Or perhaps it may not.
>
> Methinks it was all just a rather good troll.
>
> --

Now we have a few more questions i.e. apart from what CPU is in
Phillipe's device:
1. WHO was Philippe replying to -- Simon or me?
2. WHAT was cute?
3. Grant thinks WHAT might have been a rather good troll by WHOM?

Ah well never mind ... I think I'll just report the whole thread to
thedailywtf and move on :-)

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


Re: Using Python for my web site

2006-07-31 Thread Luis M. González
I don't have experience with Django or any other python framework, but
I have used bare-bones mod_python and it rocks.
I wouldn't use PSP though...
It is not very polished, and they way it handles the "indentation
problem" in python is a little bit confussing.

IMHO the best way of using mod_python is with its publisher handler.
It let's you code your applications in a MVC (model view controller)
style.
This way you can cleanly separate presentation and logic, making your
code more concise, clear and mantainable.

With publisher, every function defined in your script represents a web
page in your site, and the html code can be moved to a template, that
could be PSP itself or Cheetah, for example (Cheetah is very good).

A very simple example:

#mysite.py

def index(req):
req.content_type = 'text/html'
req.write("""



""")

def printMyName(req, myname):
req.content_type = 'text/html'
req.write(myname)

# end of mysite.py

In this script, the function "index" is executed by default when you go
to http://yourserver/mysite.py, and it displays a text box and a submit
button.
(The first line indicates that the output will be in html format, and
"req.write" is equivalent to "print".)

If you enter your name and hit the submit button, your name is passed
to the "printMyName" function and printed in your browser's screen.

This way, both functions can be viewed like two separate pages within
your site.
So, with only one script, you can write a whole site if you want.

For more complex pages where html is used, you can place this
presentation code in templates, and then import them into your main
script.
Or else, you could simple use "req.write" to print your html directly
(as I did in "index").
Hope this helps...

Luis







northband wrote:
> Hi, I am interested in re-writing my website in Python vs PHP but have
> a few questions. Here are my specs, please advise as to which
> configuration would be best:
>
> 1.Dell Poweredge Server, w/IIS, currently Windows but considering
> FreeBSD
> 2. Site consists of result pages for auctions and items for sale (100
> per page)
> 3. MySQL (Dell Poweredge w/AMD) database server connected to my web
> server
> 4. Traffic, 30 million page loads/month
>
> I am trying to have the fastest page loads, averaging 100 items per
> result page.  I have read about using Apache's mod_python so I could
> use PSP.  Any help or tips are appreciated.
> 
> -Adam

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


ANN: Quest for the Holy Grail (a PyGame game)

2006-07-31 Thread Greg Ewing
This game is doubly Pythonic -- it uses PyGame, and
it's based on a Monty Python movie.

It was originally an entry in the Pygame.draw challenge
(http://media.pyweek.org/static/pygame.draw-0606.html).
I've put a slightly enhanced and bugfixed version on
my web page:

http://www.cosc.canterbury.ac.nz/greg.ewing/grailquest/index.html

It requires Python 2.3 or later and PyGame with
SDL_image and SDL_ttf support. That's all!

Comments, suggestions and amusing gameplay
anecdotes are welcome.

Have fun,

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code to retrieve web mail?

2006-07-31 Thread Cliff Wells
On Tue, 2006-08-01 at 01:47 +, John Savage wrote:
> I have a free web mail address and would like to use python to retrieve
> files that have been emailed to me. The basic code would accommodate
> cookies, a login name and password, then download using the full URL I
> can provide. From postings here I thought mechanize held promise, but
> I've found it to contain filenames that are invalid for MSDOS (too many
> characters, and/or too many dots in the name, etc.) so I have little hope
> that the mechanize module can be used.
> 
> I'm running python2.4.2 on plain MSDOS (not windows), so would appreciate
> a pointer to sample code that can do the job. I know that curl has this
> capability, but I'll learn something by tinkering with python code.

PyCurl certainly does have that capability, although the docs were
practically non-existent last I looked (and I've not tried it on DOS).
Still Google will help get you through it, along with the examples
included with the package, and once it's working PyCurl does an
outstanding job.

You might take a look at Beautiful Soup for parsing the HTML once PyCurl
has fetched it for you:

http://www.crummy.com/software/BeautifulSoup/

Also, no matter what method you finally end up with, you'll undoubtedly
need to mangle long filenames into 8.3 names, at least for attachments
and the like.

Regards,
Cliff

-- 

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


Re: How to catch python's STDOUT

2006-07-31 Thread Greg Ewing
[EMAIL PROTECTED] wrote:

> I dont want the outputs of print to be displayed on the console
> since it is used my fellow-workers
> But i need those prints for debugging purpose

import sys
sys.stdout = open("my_debugging_output.txt", "w")

Or you can replace sys.stdout with any object having
a write() method which does whatever you want with
the output.

You can similarly replace sys.stderr to capture
output written to standard error.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python for my web site

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 21:57 -0300, Gerhard Fiedler wrote:
> On 2006-07-31 18:23:17, Cliff Wells wrote:
> 
> > My point is to stop FUD right at that comment.  I don't doubt your
> > research from "a few years ago", but ancient research is entirely
> > irrelevant for making a decision *today*.
> 
> That's exactly the reason why I added this information. It might not be for
> you, but it is interesting for me (and might be for someone else) to see
> that I get a different feedback now than I got a few years ago. It tells
> something about the dynamic of the process that the mere status of today
> doesn't tell.

Well, perhaps I misunderstood your intent.  Sorry if I was short.

> Besides, "claimed to have" and "seemed to have" are not really FUD inducing
> terms :)

Taken in a vacuum, they can certainly add to an overall negative
impression.  PostgreSQL, in the past, has certainly had some hurdles
that made it a suboptimal choice for many people: performance and
difficulty in installation and management, among other things (I've
personally not had stability issues), lack of a native Win32 version,
etc, have made it the runner up in deployment to MySQL.  
Today, that's all changed.  PostgreSQL is comparable in performance to
MySQL (although I expect each outperforms the other in certain areas),
*easier* to install and maintain than MySQL, and its stability is
outstanding.  Release 8 also saw a native Windows version. For many
reasons, MySQL seems to be on the reverse track, sacrificing
performance, stability and ease of use in an attempt to catch up to
PostgreSQL in features.  
Nevertheless, there remains rumors and myths that stem from those old
days that cause many people to fear deploying PostgreSQL.  This is part
of the reason I'm always quick to jump on statements such as yours.  I
feel it's a disservice to the community to let those myths continue and
perhaps dissuade others from discovering what is today *the* premier
FOSS relational database.

> Anyway, I appreciate you sharing your experience (which in that area
> certainly is more than mine).

I'm glad I was able to add to the pool of knowledge (or at least the mud
puddle of anecdote).

Cliff

-- 

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


Re: Pickle vs XML for file I/O

2006-07-31 Thread crystalattice
On Mon, 31 Jul 2006 14:35:39 -1000, Simon Forman <[EMAIL PROTECTED]>  
wrote:

> crystalattice wrote:
>> I'm creating an RPG for experience and practice.  I've finished a
>> character creation module and I'm trying to figure out how to get the
>> file I/O to work.
>>
>> I've read through the python newsgroup and it appears that shelve
>> probably isn't the best option for various reasons.  This lead me to
>> try messing w/ pickle, but I can't figure out how to use it with
>> classes.  I've found many examples of using pickle w/ non-OOP code but
>> nothing that shows how to use it w/ classes, subclasses, etc.  I've
>> read the documentation but it doesn't explain it well enough for me.
>>
>> Then I started thinking perhaps I'm going about it wrong.  My current
>> thought is to save an instance of each character so all the info (name,
>> skills, hit points, etc.) is stored in one place.  But looking at
>> OpenRPG made me think that perhaps using XML to store the information
>> would be better.  Each character could have a separate XML file, though
>> I don't know how it would work if many NPC's are required.
>>
>> I guess my question is, what are the benifits of getting pickle to work
>> w/ my classes vs. converting all the character data into XML and just
>> writing that to a file?  Since most of the data would need to be
>> modified often, e.g. hit points, is one storage format better than the
>> other?  Can you even modify data if it's been pickled w/o having to
>> unpickle it, change the data, then repickle it?
>
> Um, there's nothing tricky to using pickle with classes:
>
> |>> import pickle
> |>> class foo: pass
> |>> f = foo()
> |>> pstr = pickle.dumps(f)
> |>> pstr
> '(i__main__\nfoo\np0\n(dp1\nb.'
> |>> newf = pickle.loads(pstr)
> |>> newf
> <__main__.foo instance at 0xb664690c>
>
> Pickle is simple and should work "out-of-the-box".  I wouldn't mess
> with XML until I was sure I needed it for something.
>
> What kind of trouble were you having with pickle?
>
> Peace,
> ~Simon
>
It's mostly a combination of things (I hope you can follow my logic).   
First, to use "good programming practice", I want to implement a  
try/except block for opening the pickle file.  But I can't figure out if  
this block should be included outside the classes, included in just the  
base class, or if the base and subclasses need it; I'm leaning to putting  
outside the classes as a global method.

When pickling a class instance, is the pickle statement placed within the  
class (say, at the end of the class) or is it where the instance is  
created, such as a test() method?

Do I even need to bother with having the try/except block and pickle  
statements in the character generation module or should I have a separate  
module that does the file I/O, such that it opens the new file, calls the  
character module and makes a new instance, then pickles it?

Plus, to modify data in a class, do I have to unpickle the whole thing  
first or is there a way to modify the data while it's pickled?  Actually,  
I think I can answer that last question:  a character instance, having  
been created, will stay resident in memory until the player quits,  
character dies, or otherwise is no longer needed.  At that point the  
character instance should be pickled (if necessary) to disk; pickle  
shouldn't be used while data modification is required and the class  
instance is "active", correct?

I also remember reading on a thread here that pickle sometimes has issues  
when used with classes, which makes me hesitant to pickle an entire class  
instance.  That's why I thought XML may be safer/better.


-- 
Python-based online RPG in development based on the Colonial Marines from  
"Aliens": http://cmrpg.sourceforge.net

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python-list Digest, Vol 35, Issue 6

2006-07-31 Thread support
This is an automated response.

Thank you for contacting the Technical Support team at The MathWorks Ltd.  A 
technical support representative will be contacting you within 1 business day.

The following information will help us in responding to your request.  If you 
have already provided the information requested below, no further action is 
required.

1) License number, release number, and operating system.  Typing “ver” at the 
MATLAB command prompt will list this information.

2) Exact text of any error message(s) received 

3) All files (M-files, Simulink models, data files) and steps to reproduce the 
issue. If you need to send in an executable or a zip file, please wait until a 
support engineer contacts you.

To provide this information, reply to this message keeping the Thread Id listed 
at the bottom of this message intact.

STUDENT VERSION USERS: If you are a student using the Student Version, please 
note that email and phone support is available for product installation, 
software crashes, or bug reporting.  For all other enquiries, contact your 
lecturer or visit the support web site at http://www.mathworks.co.uk/support/.

If you have any concerns about our technical support services, write to [EMAIL 
PROTECTED]

Technical Support Team
The MathWorks Ltd
Email: [EMAIL PROTECTED]
Tel: 01223 423200
Fax: 01223 423250
http://www.mathworks.co.uk/support

[THREAD ID: 1-2ZI8BP]

-Original Message-
From: [EMAIL PROTECTED]
Sent: 7/31/2006 11:46:55 PM
To: [EMAIL PROTECTED]
Subject: Python-list Digest, Vol 35, Issue 6   

Send Python-list mailing list submissions to
python-list@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

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


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

Re: suppressing the console in a GUI program

2006-07-31 Thread John Salerno
John Salerno wrote:
> Hi guys. I tried naming my file with a .pyw extension, but the console 
> still shows up. Why doesn't this work? And is there another, more 
> programmatic way to suppress it?
> 
> Thanks.

I just noticed that the console that opens isn't the normal one, it's 
IPython. Now how would I suppress that one as well? Again, any way to do 
  it in the program, or is that not a good idea for when it gets ported 
to another platform?
-- 
http://mail.python.org/mailman/listinfo/python-list


suppressing the console in a GUI program

2006-07-31 Thread John Salerno
Hi guys. I tried naming my file with a .pyw extension, but the console 
still shows up. Why doesn't this work? And is there another, more 
programmatic way to suppress it?

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


Re: BCD List to HEX List

2006-07-31 Thread Grant Edwards
On 2006-08-01, Philippe Martin <[EMAIL PROTECTED]> wrote:

>> Perhaps if Philippe could divulge the part number that's in
>> the bottom right corner of the manual that he has, and/or any
>> part number that might be mentioned in the first few pages of
>> that manual, enlightenment may ensue 
>
> That was cute ... over and out !

Or perhaps it may not.

Methinks it was all just a rather good troll.

-- 
Grant Edwards   grante Yow!  Where's the Coke
  at   machine? Tell me a joke!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FOR LOOPS

2006-07-31 Thread danielx
OriginalBrownster wrote:
> I am using a class called UploadedFile.
> I want to create a for loop to itterate through the objects within file
> name
>
> class UploadedFile(SQLObject):
>   filename = StringCol(alternateID=True)
>   abspath = StringCol()
>   uniqueid = IntCol()
>
> I'll show you a snippit of the code I am trying to use it in::
>
>
> zip= ["zip.txt"]
> file_path = [myfile.filename for myfile in
> UploadedFile.select(orderBy=UploadedFile.q.filename)]
>
> if kw:
> for filename in file_path:
> zip.append(filename)
> flash('Options selected'+ str(kw) + str(zip))
> else:
> pass
>
> When i run this the flash displays all the values for kw...however zip
> only shows up as "zip.txt" using the str function. Meaning that the FOR
> LOOP is not working correctly.
>
> Any ideas why this is happening?? perhaps someone could shoe me how to
> make a proper list for this if this is incorrect.
>
> Thank you

I'm not really familiar with SQLObject, but are you sure file_path is
not empty?

Also, a few small comments:

1. zip is a builtin function. I would choose a different name, even
though this is not strictly necessary.

2. You can accomplish what you seem to be intending with your loop
using list.extend.

3. That's an interesting thing to put in an else case. Why did you do
it that way instead of just leaving it out?

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


Re: readline not found error

2006-07-31 Thread Robert Kern
David Bear wrote:

> okay. Since I grabbed the python tar file from python.org, do I then assume
> that readline is not included in the python source distribution? if so,
> where would I find it. If not, what different build instructions do I need
> to follow to make it build with readline?

Oops. Sorry, I missed that part of what you said. Use

   $ ./configure --enable-readline

-- 
Robert Kern

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

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


FOR LOOPS

2006-07-31 Thread OriginalBrownster
I am using a class called UploadedFile.
I want to create a for loop to itterate through the objects within file
name

class UploadedFile(SQLObject):
filename = StringCol(alternateID=True)
abspath = StringCol()
uniqueid = IntCol()

I'll show you a snippit of the code I am trying to use it in::


zip= ["zip.txt"]
file_path = [myfile.filename for myfile in
UploadedFile.select(orderBy=UploadedFile.q.filename)]

if kw:
for filename in file_path:
zip.append(filename)
flash('Options selected'+ str(kw) + str(zip))
else:
pass

When i run this the flash displays all the values for kw...however zip
only shows up as "zip.txt" using the str function. Meaning that the FOR
LOOP is not working correctly.

Any ideas why this is happening?? perhaps someone could shoe me how to
make a proper list for this if this is incorrect.

Thank you

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


Re: Nested function scope problem

2006-07-31 Thread danielx
Gerhard Fiedler wrote:
> On 2006-07-30 09:54:14, Antoon Pardon wrote:
>
> > Aren't you looking too much at implementation details now?
>
> Possibly, but at this point I'm still trying to understand how Python does
> these things, and what the useful abstraction level is for me. I also still
> have very little experience how I'll put the things we've been discussing

Sorry I've been away from this sub-thread for a while (even though I
kinda started it :P). Yes, I'm also wondering what difference this big
huge argument makes on how I logically follow Python.

Personally, I find this metaphor in "Head First Java" from O'Reilly
Press really helpful for both Python and Java. Before anyone sends me a
letter bomb that says "Python != Java", let me say this: have phun :P.

Anyway, the metaphor goes something like this: variables (for objects,
not primitives) are like cups (just wait, it gets better). You can put
a remote control IN a cup. The remote control controls a "real" object
on the heap (ie, the data for the object is there).

Unfortunately, some of the effect of the metaphor is lost because I
cannot reporduce the very nice illustrations which came in the book :P.

Other than the fact that you declare variables in Java (going down
another letter-bomb-laden slippery slope), which means they stick
around even when they have no "remote controls", I pretty much think of
Python variables the same way: each variable LOGICALLY contains a
reference (ie, without regard to what the mechanics are) to some
amorphous glob of data, sitting on the heap. Therefore, when I do an
assignment, I am simply replacing the reference my variable is holding.
According to the metaphor, we are replacing the remote control our cup
is holding.

If an object is no longer visible (because all the references have
disappeared), then it should get garbage collected eventually. But
until the magical garbage-collecting angle of death makes is way
through the heap, our orphaned objects are PHYSICALLY still there until
they are forcefully evicted from memory. Logically, however, they were
gone as soon as we lost sight of them.

Java aside, My question is this: how will using this metaphor break the
way I logically follow Python?

> here into (Python) practice. While not new to programming, I'm new to
> Python.
>
> > AFAIU, one can also build a C++ class hierarchy that with some small
> > limitations in used operators, would have semantics very similar to
> > Python. Would you argue that those using such a C++ class hierarchy would
> > no longer be using variables in C++?
>
> Probably not. But for me it's mostly about useful terminology, not
> necessarily "correct" terminology. In order to talk about correct
> terminology, we'd have to use a common definition of "variable". This is a
> term so widely used that I'm not sure there is a useful single definition
> of it; do you know one?

This is another thing I was thinking the entire time I was reading this
argument, but I didn't want someone to answer me in a condescending
tone on what exactly a variable IS. I guess I should attribute that
quote to Bill Clinton :P.

>
> In any case, the following doesn't seem to be implementation detail (and
> rather a part of the language), but it's not really understandable with a
> C++ concept of "variable":
>
> >>> a=3
> >>> id(a)
> 3368152
> >>> b=a
> >>> id(b)
> 3368152
> >>> b=4
> >>> id(b)
> 3368140
>
> You don't expect the "identity" of the variable b to change with a simple
> assignment from a C/C++ point of view. You also don't expect the "identity"
> of a and b to be the same after assigning one to the other. You can create
> C++ classes that behave like that (you can implement Python in C++ :), but
> that doesn't mean that you expect C++ language constructs to behave like
> that.

I'm really not comfortable with C, but I disagree. What would you say
about this program:

#include 
#include 
#include 
#define tf(bool) (bool) ? "true" : "false"

const char * greeting = "hello world";

int main() {
  /* These mallocs don't really need to be hear for me to make my
 point, because as far as I know, what they return is garbage
 values anyway :P. I just put them there so my pointers are
 pointing to "real objects".*/
  char * string = (char *) malloc(sizeof(char)*100);
  char * letterBomb = (char *) malloc(sizeof(char)*100);

  strcpy(string, greeting);
  strcpy(letterBomb, greeting);

  printf("are we equal? %s\n", tf(strcmp(string, letterBomb) == 0));
  printf("are we IDENTICAL? %s\n", tf(string == letterBomb));

  printf("sabotage...\n");
  letterBomb = string;
  printf("are we identical NOW? %s\n", tf(string==letterBomb));
}

> 
> Gerhard

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


Re: BCD List to HEX List

2006-07-31 Thread Philippe Martin
John Machin wrote:

> 
> Simon Forman wrote:
>> Philippe, please!  The suspense is killing me.  What's the cpu!?
>>
>> For the love of God,  what's the CPU?
>>
>> I-can't-take-it-anymore-it's-such-a-simple-question-ingly yours,
> 
> Yes, please .
> 
> I've found a C compiler manual on the web for the Epson S1C33 CPU as
> well as the one for the S1C88 that Philippe pointed me at. They have
> two things in common:
> (1) explicitly mention support for 32-bit longs
> (2) in the bottom right corner of most pages, it has the part number
> (which includes S1Cxx) and the version number.
> 
> Philippe has what he believes to be the manual for the C compiler for
> the CPU in the device,  but couldn't find it on the web.
> 
> Perhaps if Philippe could divulge the part number that's in the bottom
> right corner of the manual that he has, and/or any part number that
> might be mentioned in the first few pages of that manual, enlightenment
> may ensue 
> 
> Cheers,
> John


That was cute ... over and out !

Long live Python.

A+

Philippe

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


Re: Help with arrays of strings

2006-07-31 Thread Jon Smirl
On Mon, 31 Jul 2006 18:33:34 -0700, Simon Forman wrote:
> Splitting a string into a list (array) of lines is easy enough,  if you
> want to discard the line endings,

Thanks for the pointers, that should be enough to get me started. I had
started off in the wrong direction looking for arrays instead of lists.

I'll code this up and give it try. Hopefully it can run though the 10GB of
data in a few hours and not take days.

Jon Smirl
[EMAIL PROTECTED]

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


code to retrieve web mail?

2006-07-31 Thread John Savage
I have a free web mail address and would like to use python to retrieve
files that have been emailed to me. The basic code would accommodate
cookies, a login name and password, then download using the full URL I
can provide. From postings here I thought mechanize held promise, but
I've found it to contain filenames that are invalid for MSDOS (too many
characters, and/or too many dots in the name, etc.) so I have little hope
that the mechanize module can be used.

I'm running python2.4.2 on plain MSDOS (not windows), so would appreciate
a pointer to sample code that can do the job. I know that curl has this
capability, but I'll learn something by tinkering with python code.

Thanks.
--
John Savage   (my news address is not valid for email)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with arrays of strings

2006-07-31 Thread Simon Forman
Jon Smirl wrote:
> I only have a passing acquaintance with Python and I need to modify some
> existing code. This code is going to get called with 10GB of data so it
> needs to be fairly fast.
>
> http://cvs2svn.tigris.org/ is code for converting a CVS repository to
> Subversion. I'm working on changing it to convert from CVS to git.
>
> The existing Python RCS parser provides me with the CVS deltas as
> strings.I need to get these deltas into an array of lines so that I can
> apply the diff commands that add/delete lines (like 10 d20, etc). What is
> the most most efficient way to do this? The data structure needs to be
> able to apply the diffs efficently too.
>
> The strings have embedded @'s doubled as an escape sequence, is there an
> efficient way to convert these back to single @'s?
>
> After each diff is applied I need to convert the array of lines back into
> a string, generate a sha-1 over it and then compress it with zlib and
> finally write it to disk.
>
> The 10GB of data is Mozilla CVS when fully expanded.
>
> Thanks for any tips on how to do this.
>
> Jon Smirl
> [EMAIL PROTECTED]

Splitting a string into a list (array) of lines is easy enough,  if you
want to discard the line endings,

lines = s.splitlines()

or, if you want to keep them,

lines = s.splitlines(True)

replacing substrings in a string is also easy,

s = s.replace('@@', '@')

For efficiency, you'll probably want to do the replacement first, then
split:

lines = s.replace('@@', '@').splitlines()


Once you've got your list of lines, python's awesome list manipulation
should makes applying diffs very easy.  For instance, to replace lines
3 to 7 (starting at zero) you could assign a list (containing the
replacement lines) to a "slice" of the list of lines:

lines[3:8] = replacement_lines

Where replacement_lines is a list containing the replacement lines.
There's a lot more to this, read up on python's lists.


To convert the list back into one string use the join() method; if you
kept the line endings,

s = "".join(lines)

or if you threw them away,

s = "\n".join(lines)

Python has standard modules for sha-1 digest, sha, and zlib
compression, zlib.  See http://docs.python.org/lib/lib.html

HTH, enjoy,
~Simon

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


Re: Windows vs. Linux

2006-07-31 Thread Dan
Andy Dingley wrote:
[snip]
 > Python is one of the best languages I've found for
 > platform-independence - significantly better than Perl.
[big snip]

This statement was given in the context of Windows and Linux, and I've 
precious little experience doing anything on Windows. So I won't 
challenge it in the least, and in fact do not doubt it.

But taken out of that context, I'll challenge it.  I was first exposed 
to Python about five or six years ago--my boss asked me to consider it. 
What I found was that the current version of Python was V2.2, but newest 
version (that I could find) that ran on VMS was V1.4.  I decided to 
stick with Perl, which provides excellent support for VMS.

Now that I no longer need to worry about VMS, I prefer Python. Quite a bit.

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


Re: readline not found error

2006-07-31 Thread David Bear
Robert Kern wrote:

> David Bear wrote:
>> I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
>> instance of python from the version packaged with suse.
>> 
>> Now when I start it I get an error:
>> python
>> Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
>> [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> Traceback (most recent call last):
>>   File "/etc/pythonstart", line 7, in ?
>> import readline
>> ImportError: No module named readline
>> 
>> however, I do have readline installed:
>> 
>> rpm -qa | grep readline
>> readline-5.0-7.2
>> readline-32bit-9.3-7.1
>> 
>> it id truly does exist:
>> 
>> locate readline
>> ...
>> /lib/libreadline.so.5
>> /lib/libreadline.so.5.0
>> /lib64/libreadline.so.5
>> /lib64/libreadline.so.5.0
> 
> However, these are not the Python readline module. The Suse package for it
> is probably called python-readline or something like that.
> 
okay. Since I grabbed the python tar file from python.org, do I then assume
that readline is not included in the python source distribution? if so,
where would I find it. If not, what different build instructions do I need
to follow to make it build with readline?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: realine not found error

2006-07-31 Thread Robert Kern
David Bear wrote:
> I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
> instance of python from the version packaged with suse.
> 
> Now when I start it I get an error:
> python
> Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
> [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> Traceback (most recent call last):
>   File "/etc/pythonstart", line 7, in ?
> import readline
> ImportError: No module named readline
> 
> however, I do have readline installed:
> 
> rpm -qa | grep readline
> readline-5.0-7.2
> readline-32bit-9.3-7.1
> 
> it id truly does exist:
> 
> locate readline 
> ...
> /lib/libreadline.so.5
> /lib/libreadline.so.5.0
> /lib64/libreadline.so.5
> /lib64/libreadline.so.5.0

However, these are not the Python readline module. The Suse package for it is 
probably called python-readline or something like that.

-- 
Robert Kern

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

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


Re: Using Python for my web site

2006-07-31 Thread Gerhard Fiedler
On 2006-07-31 18:23:17, Cliff Wells wrote:

> My point is to stop FUD right at that comment.  I don't doubt your
> research from "a few years ago", but ancient research is entirely
> irrelevant for making a decision *today*.

That's exactly the reason why I added this information. It might not be for
you, but it is interesting for me (and might be for someone else) to see
that I get a different feedback now than I got a few years ago. It tells
something about the dynamic of the process that the mere status of today
doesn't tell.

Besides, "claimed to have" and "seemed to have" are not really FUD inducing
terms :)

Anyway, I appreciate you sharing your experience (which in that area
certainly is more than mine).

Gerhard

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

Simon Forman wrote:
> Philippe, please!  The suspense is killing me.  What's the cpu!?
>
> For the love of God,  what's the CPU?
>
> I-can't-take-it-anymore-it's-such-a-simple-question-ingly yours,

Yes, please .

I've found a C compiler manual on the web for the Epson S1C33 CPU as
well as the one for the S1C88 that Philippe pointed me at. They have
two things in common:
(1) explicitly mention support for 32-bit longs
(2) in the bottom right corner of most pages, it has the part number
(which includes S1Cxx) and the version number.

Philippe has what he believes to be the manual for the C compiler for
the CPU in the device,  but couldn't find it on the web.

Perhaps if Philippe could divulge the part number that's in the bottom
right corner of the manual that he has, and/or any part number that
might be mentioned in the first few pages of that manual, enlightenment
may ensue 

Cheers,
John

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


RE: Python-list Digest, Vol 35, Issue 4

2006-07-31 Thread support
This is an automated response.

Thank you for contacting the Technical Support team at The MathWorks Ltd.  A 
technical support representative will be contacting you within 1 business day.

The following information will help us in responding to your request.  If you 
have already provided the information requested below, no further action is 
required.

1) License number, release number, and operating system.  Typing “ver” at the 
MATLAB command prompt will list this information.

2) Exact text of any error message(s) received 

3) All files (M-files, Simulink models, data files) and steps to reproduce the 
issue. If you need to send in an executable or a zip file, please wait until a 
support engineer contacts you.

To provide this information, reply to this message keeping the Thread Id listed 
at the bottom of this message intact.

STUDENT VERSION USERS: If you are a student using the Student Version, please 
note that email and phone support is available for product installation, 
software crashes, or bug reporting.  For all other enquiries, contact your 
lecturer or visit the support web site at http://www.mathworks.co.uk/support/.

If you have any concerns about our technical support services, write to [EMAIL 
PROTECTED]

Technical Support Team
The MathWorks Ltd
Email: [EMAIL PROTECTED]
Tel: 01223 423200
Fax: 01223 423250
http://www.mathworks.co.uk/support

[THREAD ID: 1-2ZFVQC]

-Original Message-
From: [EMAIL PROTECTED]
Sent: 7/31/2006 8:43:01 PM
To: [EMAIL PROTECTED]
Subject: Python-list Digest, Vol 35, Issue 4   

Send Python-list mailing list submissions to
python-list@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

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


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

Help with arrays of strings

2006-07-31 Thread Jon Smirl
I only have a passing acquaintance with Python and I need to modify some
existing code. This code is going to get called with 10GB of data so it
needs to be fairly fast. 

http://cvs2svn.tigris.org/ is code for converting a CVS repository to
Subversion. I'm working on changing it to convert from CVS to git.

The existing Python RCS parser provides me with the CVS deltas as
strings.I need to get these deltas into an array of lines so that I can
apply the diff commands that add/delete lines (like 10 d20, etc). What is
the most most efficient way to do this? The data structure needs to be
able to apply the diffs efficently too.

The strings have embedded @'s doubled as an escape sequence, is there an
efficient way to convert these back to single @'s?

After each diff is applied I need to convert the array of lines back into
a string, generate a sha-1 over it and then compress it with zlib and
finally write it to disk. 

The 10GB of data is Mozilla CVS when fully expanded.

Thanks for any tips on how to do this.

Jon Smirl
[EMAIL PROTECTED]

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


Re: BCD List to HEX List

2006-07-31 Thread Simon Forman
Philippe, please!  The suspense is killing me.  What's the cpu!?

For the love of God,  what's the CPU?

I-can't-take-it-anymore-it's-such-a-simple-question-ingly yours,
~Simon

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


realine not found error

2006-07-31 Thread David Bear
I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
instance of python from the version packaged with suse.

Now when I start it I get an error:
python
Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in ?
import readline
ImportError: No module named readline

however, I do have readline installed:

rpm -qa | grep readline
readline-5.0-7.2
readline-32bit-9.3-7.1

it id truly does exist:

locate readline 
...
/lib/libreadline.so.5
/lib/libreadline.so.5.0
/lib64/libreadline.so.5
/lib64/libreadline.so.5.0
...

I googled about for this and there were numerous hits on this problem from
others, but I never found a 'solution'.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle vs XML for file I/O

2006-07-31 Thread Simon Forman
crystalattice wrote:
> I'm creating an RPG for experience and practice.  I've finished a
> character creation module and I'm trying to figure out how to get the
> file I/O to work.
>
> I've read through the python newsgroup and it appears that shelve
> probably isn't the best option for various reasons.  This lead me to
> try messing w/ pickle, but I can't figure out how to use it with
> classes.  I've found many examples of using pickle w/ non-OOP code but
> nothing that shows how to use it w/ classes, subclasses, etc.  I've
> read the documentation but it doesn't explain it well enough for me.
>
> Then I started thinking perhaps I'm going about it wrong.  My current
> thought is to save an instance of each character so all the info (name,
> skills, hit points, etc.) is stored in one place.  But looking at
> OpenRPG made me think that perhaps using XML to store the information
> would be better.  Each character could have a separate XML file, though
> I don't know how it would work if many NPC's are required.
>
> I guess my question is, what are the benifits of getting pickle to work
> w/ my classes vs. converting all the character data into XML and just
> writing that to a file?  Since most of the data would need to be
> modified often, e.g. hit points, is one storage format better than the
> other?  Can you even modify data if it's been pickled w/o having to
> unpickle it, change the data, then repickle it?

Um, there's nothing tricky to using pickle with classes:

|>> import pickle
|>> class foo: pass
|>> f = foo()
|>> pstr = pickle.dumps(f)
|>> pstr
'(i__main__\nfoo\np0\n(dp1\nb.'
|>> newf = pickle.loads(pstr)
|>> newf
<__main__.foo instance at 0xb664690c>

Pickle is simple and should work "out-of-the-box".  I wouldn't mess
with XML until I was sure I needed it for something.

What kind of trouble were you having with pickle?

Peace,
~Simon

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


Pickle vs XML for file I/O

2006-07-31 Thread crystalattice
I'm creating an RPG for experience and practice.  I've finished a
character creation module and I'm trying to figure out how to get the
file I/O to work.

I've read through the python newsgroup and it appears that shelve
probably isn't the best option for various reasons.  This lead me to
try messing w/ pickle, but I can't figure out how to use it with
classes.  I've found many examples of using pickle w/ non-OOP code but
nothing that shows how to use it w/ classes, subclasses, etc.  I've
read the documentation but it doesn't explain it well enough for me.

Then I started thinking perhaps I'm going about it wrong.  My current
thought is to save an instance of each character so all the info (name,
skills, hit points, etc.) is stored in one place.  But looking at
OpenRPG made me think that perhaps using XML to store the information
would be better.  Each character could have a separate XML file, though
I don't know how it would work if many NPC's are required.

I guess my question is, what are the benifits of getting pickle to work
w/ my classes vs. converting all the character data into XML and just
writing that to a file?  Since most of the data would need to be
modified often, e.g. hit points, is one storage format better than the
other?  Can you even modify data if it's been pickled w/o having to
unpickle it, change the data, then repickle it?

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


Re: under naming

2006-07-31 Thread John Machin

David Bear wrote:
> I must have missed reading something important about naming conventions.
>
> I have found that if I have a python module where I have an identifier named
> with a beginning underscore that I cannot use from module import * to make
> that name available in another module.
>
> for example,
> module A
>
> _myvar = 'a local var'
>
> module B
> from A import *
>
> _myvar -- is not available.
>
> Is this in a pep somewhere ?
> 

http://www.python.org/doc/2.4.3/ref/import.html

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


Re: Working with Widget after Instance loses the reference

2006-07-31 Thread John McMonagle
On Mon, 2006-07-31 at 11:15 -0700, Al in Dallas wrote:
> I made the mistake of creating an instance of a widget and assigning it
> to a name I'd already used. Now, if I use root.children or
> root.slaves(), I can see the "lost" widget, but can I do anything else
> with the string of numbers that shows up when I use root.children? I'd
> like to destory the widget, for example. it would be even better if I
> could create a new name and have it reference the "lost" widget.
> 
> Of course, I can just kill my toplevel and start over.
> 


Consider the following code run in the python shell:

>>> from Tkinter import *
>>> r = Tk()
>>> b1 = Button(r, text='test')
>>> b1.pack()
>>> b2 = Button(r, text='test2')
>>> b2.pack()
>>> r.children
{'-1210160564': , '-1210225748':
}
>>> r.slaves()
[, ]
>>> b1 = 'xxx' 
>>> b1.destroy()
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'str' object has no attribute 'destroy'
>>> b1 = r.slaves()[0]
>>> b1.destroy()
>>>


So, as long as you know what your widget instance is in root.slaves() or
root.children you can assign it to a new name.




-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: under naming

2006-07-31 Thread Robert Kern
David Bear wrote:
> I must have missed reading something important about naming conventions.
> 
> I have found that if I have a python module where I have an identifier named
> with a beginning underscore that I cannot use from module import * to make
> that name available in another module.
> 
> for example,
> module A
> 
> _myvar = 'a local var'
> 
> module B
> from A import *
> 
> _myvar -- is not available.
> 
> Is this in a pep somewhere ?

No; this has been a feature since before the time of PEPs. However, it is 
documented here:

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

-- 
Robert Kern

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

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


Re: Nuther problem with 'dive into Python'

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 14:03 +0100, Ben Edwards wrote:
> Am going through Chapter 9 - HTTP Web Services in dive into Python.  It
> uses the following:
> 
> data = urllib.urlopen('http://diveintomark.org/xml/atom.xml').read()
> 
> The page no longer exists, can anyone recommend an alternative page to
> use?

Perhaps any one of the approximately 100 million pages with Atom
feeds?  

Google is your friend:

http://www.google.com/search?hl=en&lr=lang_en&safe=off&q=blog
+atom&btnG=Search

Results 1 - 10 of about 105,000,000 English pages for blog atom. 

Cliff

-- 

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


PIL issues

2006-07-31 Thread David Bear
I am trying to use PIL and when building it, PIL fails to find my jpeg
library. I am using a python 2.4.3 that I build myself on Suse linux 9.3. I
do have the following jpeg libraries:

rpm -qa | grep jpeg
jpeg-6b-738
libjpeg-32bit-9.3-7
libjpeg-6.2.0-738


yet, when building PIL I get:

python setup.py build_ext -i
running build_ext

PIL 1.1.5 BUILD SUMMARY

version   1.1.5
platform  linux2 2.4.2 (#4, Jul 27 2006, 14:34:30)
  [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)]

*** TKINTER support not available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available

To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

I don't know what ROOT variable the message is referring too. Any advice
would be appreciated.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


under naming

2006-07-31 Thread David Bear
I must have missed reading something important about naming conventions.

I have found that if I have a python module where I have an identifier named
with a beginning underscore that I cannot use from module import * to make
that name available in another module.

for example,
module A

_myvar = 'a local var'

module B
from A import *

_myvar -- is not available.

Is this in a pep somewhere ?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator for use with cgilib

2006-07-31 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> (if anyone still uses cgilib, in the presence of Django, TG, et al.)...
>
> I tried out a simple CGI Python script this week, and was a bit annoyed at
> the repetitive ,,, etc. opening and closing tags for
each
> request handler method.  So I wrote a decorator to handle this junk.  It's
> posted on the Python wiki at
>
http://wiki.python.org/moin/PythonDecoratorLibrary#head-f0d46c66e0a2653daae3f451d32405a283d6759b.
>
> -- Paul
>
>
Duh, that is to say, "for use with the cgi module."  There is no cgilib.

-- Paul


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


Decorator for use with cgilib

2006-07-31 Thread Paul McGuire
(if anyone still uses cgilib, in the presence of Django, TG, et al.)...

I tried out a simple CGI Python script this week, and was a bit annoyed at
the repetitive ,,, etc. opening and closing tags for each
request handler method.  So I wrote a decorator to handle this junk.  It's
posted on the Python wiki at
http://wiki.python.org/moin/PythonDecoratorLibrary#head-f0d46c66e0a2653daae3f451d32405a283d6759b.

-- Paul


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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

Philippe Martin wrote:
> Sorry forgot a few answers/comments:
>
> John Machin wrote:
> > SHOULD BE >=
> >currently add([6, 6], [4, 4] -> [10, 10]
>
> True, thanks
>
> > *** try - 10 instead of % 10
> > If the first operand is > 19, you have a bug!
> > This might save a few CPU cycles on your smartcard
>
> can it ? >

can WHAT do WHAT?

> each array value will be [0..9]

if so, you can use - 10 instead of %10
if not, then whatever produced your input has a bug

>
> >> SHOULD CHECK FOR CARRY AT END
> >>currently add([9], [8]) -> [7]
> >>should return [1, 7] or handle overflow somehow
>
> True, this actually should become an error from the card to the calling
> device. That would be a pretty large number though.
>
>
> >> MINUS ZERO?
> I just do not want to leave it at one(1) if it is.

The question is "what do you think you are achieving by having a  MINUS
sign in front of the zero instead of plain old ordinary zero?"

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


Re: ImportError raised in script, not interactive session.

2006-07-31 Thread Adam Blinkinsop
Jordan R McCoy wrote:
> If this isn't the case, what are you using for TARGET_DIR?

${TARGET_DIR} = /home/blinks/projects/overwatch/target/lib/python
I've started the interactive session from several different
directories, and never had a problem.

My make output (note the second item in sys.path):
--
cd /home/blinks/projects/overwatch/target/bin &&
PYTHONPATH="/home/blinks/projects/overwatch/target/lib/python"
./test.py
 *** sys.path: ['/home/blinks/projects/overwatch/target/bin',
'/home/blinks/projects/overwatch/target/lib/python',
'/usr/lib/python24.zip', '/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk',
'/usr/lib64/python2.4/lib-dynload', '/usr/lib/portage/pym',
'/usr/lib64/python2.4/site-packages',
'/usr/lib/python2.4/site-packages']
Traceback (most recent call last):
  File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
make: *** [test] Error 1
--

Oh, and:
--
$ ls /home/blinks/projects/overwatch/target/lib/python/
overwatch
--

Thanks for the help!  If you want a copy of the project to reproduce,
it's on Subversion at http://tools.assembla.com/svn/Overwatch/trunk
(should be readable).

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


Re: BCD List to HEX List

2006-07-31 Thread Philippe Martin
John Machin wrote:


> Have you actually tried it? Do you mean it barfs on the word "long"
> [meaning that it's not an ANSI-compliant C compiler], or that "long" is
> only 16 bits?

:-) if the documentation tells me there is no 32 bit support, why should I
not believe it ?

> because (1) [like I said before] gcc appears to be able to generate
> code for a vast number of different CPUs (2) because I find it very
> difficult to believe that a C compiler for the CPU on a device in
> current use won't support 32-bit longs -- and so far you have presented
> no credible evidence to the contrary

I can recall working on a sparclite many years ago (32 bits) with a
x-compiler called g++ (supported by cygnus) that handled the type "long
long" = 64 bits.

As far as the credible evidence ... you're hurting my feelings ;-)

> 
>>  and I googled S1C88 and sent you a
>> link as that is the name of the compiler's directory.
> 
> and is that or is it not the correct link for the documentation for the
> compiler that you are using??
> 

Neither can I ! - never found any documentation online ... got it from my
device supplier.

Regards,

Philippe


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


Re: Python help for Access database

2006-07-31 Thread John Machin

BartlebyScrivener wrote:
> John Machin wrote:
>
> >> or mxODBC
> >> [very good but not free].
>
> I love mxODBC. It's free for noncommercial use.
>

I was presuming that the OP was mucking about with Access only because
he was so constrained by his job :-)

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


RE: ImportError raised in script, not interactive session.

2006-07-31 Thread Jordan R McCoy
Assuming your setting the target directory to the overwatch folder, and you are 
starting the interactive session in your home directory, this is what is 
happening. The folder containing your package must be in the python path, not 
the folder itself. Try "PYTHONPATH=/home/directory python test.py". The reason 
it works in the interactive session, assuming you are starting it from your 
home directory, is that the current directory of the session is placed at the 
front of the import path; the value of PYTHONPATH is merely added after the 
current directory, and before the standard directories.

If this isn't the case, what are you using for TARGET_DIR?

Jordan

-Original Message-
From: [EMAIL PROTECTED] on behalf of Adam Blinkinsop
Sent: Mon 7/31/2006 5:42 PM
To: python-list@python.org
Subject: ImportError raised in script, not interactive session.
 
I'm writing a set of modules to monitor remote system services, and I'm
having a problem running my test scripts.  When I pass the scripts into
python, like so:

--
$ PYTHONPATH="${TARGET_DIR}" python test.py
--

I get an ImportError:

--
Traceback (most recent call last):
  File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
--

However, when I load up an interactive Python session:

--
$ PYTHONPATH="${TARGET_DIR}" python
--

I can do the exact same import statement with no problem:

--
Python 2.4.3 (#1, Jul 28 2006, 09:40:08)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from overwatch.view import console
>>> dir(console)
['Daemon', 'UI', '__builtins__', '__doc__', '__file__', '__name__',
'datetime']
--

My package directory is arranged under ${TARGET_DIR} as prescribed in
the Python docs:
overwatch/
..__init__.py
..[etc.]
..view/
__init__.py
console.py
[etc.]

All modules involved are my own, and I'm setting PYTHONPATH so I can
test with the package installed in my home directory (which I use
distutils to do).  I've checked online, and double-checked the Python
docs to make sure my modules are arranged properly, and it all looks
alright.  Any ideas?

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


RE: Python-list Digest, Vol 35, Issue 1

2006-07-31 Thread support
This is an automated response.

Thank you for contacting the Technical Support team at The MathWorks Ltd.  A 
technical support representative will be contacting you within 1 business day.

The following information will help us in responding to your request.  If you 
have already provided the information requested below, no further action is 
required.

1) License number, release number, and operating system.  Typing “ver” at the 
MATLAB command prompt will list this information.

2) Exact text of any error message(s) received 

3) All files (M-files, Simulink models, data files) and steps to reproduce the 
issue. If you need to send in an executable or a zip file, please wait until a 
support engineer contacts you.

To provide this information, reply to this message keeping the Thread Id listed 
at the bottom of this message intact.

STUDENT VERSION USERS: If you are a student using the Student Version, please 
note that email and phone support is available for product installation, 
software crashes, or bug reporting.  For all other enquiries, contact your 
lecturer or visit the support web site at http://www.mathworks.co.uk/support/.

If you have any concerns about our technical support services, write to [EMAIL 
PROTECTED]

Technical Support Team
The MathWorks Ltd
Email: [EMAIL PROTECTED]
Tel: 01223 423200
Fax: 01223 423250
http://www.mathworks.co.uk/support

[THREAD ID: 1-2ZFMI1]

-Original Message-
From: [EMAIL PROTECTED]
Sent: 7/31/2006 6:12:18 PM
To: [EMAIL PROTECTED]
Subject: Python-list Digest, Vol 35, Issue 1   

Send Python-list mailing list submissions to
python-list@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

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


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

Re: Windows vs. Linux

2006-07-31 Thread diffuser78
> I'd never recommend dual-boot for anything!
> Hardware is cheap, time and trouble is expensive.

Dual-booting if so easy and helpful, I have always found it to be
extremely useful.

You might have a bad experience but I have my laptop and desktop both
running dual boot successfully for 4 and a half years now.

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


RE: Python-list Digest, Vol 35, Issue 2

2006-07-31 Thread support
This is an automated response.

Thank you for contacting the Technical Support team at The MathWorks Ltd.  A 
technical support representative will be contacting you within 1 business day.

The following information will help us in responding to your request.  If you 
have already provided the information requested below, no further action is 
required.

1) License number, release number, and operating system.  Typing “ver” at the 
MATLAB command prompt will list this information.

2) Exact text of any error message(s) received 

3) All files (M-files, Simulink models, data files) and steps to reproduce the 
issue. If you need to send in an executable or a zip file, please wait until a 
support engineer contacts you.

To provide this information, reply to this message keeping the Thread Id listed 
at the bottom of this message intact.

STUDENT VERSION USERS: If you are a student using the Student Version, please 
note that email and phone support is available for product installation, 
software crashes, or bug reporting.  For all other enquiries, contact your 
lecturer or visit the support web site at http://www.mathworks.co.uk/support/.

If you have any concerns about our technical support services, write to [EMAIL 
PROTECTED]

Technical Support Team
The MathWorks Ltd
Email: [EMAIL PROTECTED]
Tel: 01223 423200
Fax: 01223 423250
http://www.mathworks.co.uk/support

[THREAD ID: 1-2ZFMNJ]

-Original Message-
From: [EMAIL PROTECTED]
Sent: 7/31/2006 6:46:59 PM
To: [EMAIL PROTECTED]
Subject: Python-list Digest, Vol 35, Issue 2   

Send Python-list mailing list submissions to
python-list@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

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


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

Re: Windows vs. Linux

2006-07-31 Thread diffuser78
Linux can let you do more in Python and this comes from my personal
exprience. Ubuntu Dapper should let you install drivers easily for
wireless...a little bit tweaking might be required but its worth the
effort. Python and Ubuntu rock...go fot it.

[EMAIL PROTECTED] wrote:
> Okay, once-upon-a-time I tried to start programming by learning C.  At
> the time I was younger and didn't really understand all that C had to
> offer.  I eventually moved over to Microsoft's Visual Basic.  It was
> nice to be able to design a visual application with no effort (too bad
> I didn't really learn the ins and outs of programming)
>
> Long story short, I want to get back into programming, and Python looks
> like a good choice for me to start with, and maybe become advanced
> with.  Right now I run Windows as my main operating system.  On my old
> laptop I ran Ubuntu, and liked it very much; however, my new laptop has
> a Broadcom wireless card, and it's not very Linux friendly.  Is Windows
> an okay enviornment in which to program under Python, or do you
> recommend that I run a dual-boot of Linux or maybe a VMWare install to
> program under Python?

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


ImportError raised in script, not interactive session.

2006-07-31 Thread Adam Blinkinsop
I'm writing a set of modules to monitor remote system services, and I'm
having a problem running my test scripts.  When I pass the scripts into
python, like so:

--
$ PYTHONPATH="${TARGET_DIR}" python test.py
--

I get an ImportError:

--
Traceback (most recent call last):
  File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
--

However, when I load up an interactive Python session:

--
$ PYTHONPATH="${TARGET_DIR}" python
--

I can do the exact same import statement with no problem:

--
Python 2.4.3 (#1, Jul 28 2006, 09:40:08)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from overwatch.view import console
>>> dir(console)
['Daemon', 'UI', '__builtins__', '__doc__', '__file__', '__name__',
'datetime']
--

My package directory is arranged under ${TARGET_DIR} as prescribed in
the Python docs:
overwatch/
..__init__.py
..[etc.]
..view/
__init__.py
console.py
[etc.]

All modules involved are my own, and I'm setting PYTHONPATH so I can
test with the package installed in my home directory (which I use
distutils to do).  I've checked online, and double-checked the Python
docs to make sure my modules are arranged properly, and it all looks
alright.  Any ideas?

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

Philippe Martin wrote:
> John Machin wrote:
>
> > So why don't you get a freely available "bignum" package, throw away
> > the bits you don' t want, and just compile it and use it, instead of
> > writing your own bug-ridden (see below) routines? Oh yeah, the bignum
> > package might use "long" and you think that you don't have access to
> > 32-bit longs in the C compiler for the 8-bit device that you mistook
> > for an arm but then said is an Smc8831 [Google can't find it] with a
> > CPU that you think is a SC88 [but the manual whose URL you gave is for
> > an S1C88] ...
> >
>
> Thanks for the fixes - still looking at it.
>
> You are correct, all "bignum" packages I found needed 32 bits.
>
> Yes I still see from my documentation that there is no "long" handled by my
> compiler.

Have you actually tried it? Do you mean it barfs on the word "long"
[meaning that it's not an ANSI-compliant C compiler], or that "long" is
only 16 bits?

>
> I did make a mistake on the CPU (and I really do not care what it is) - you
> wanted some ref (I still do not see why)

because (1) [like I said before] gcc appears to be able to generate
code for a vast number of different CPUs (2) because I find it very
difficult to believe that a C compiler for the CPU on a device in
current use won't support 32-bit longs -- and so far you have presented
no credible evidence to the contrary

>  and I googled S1C88 and sent you a
> link as that is the name of the compiler's directory.

and is that or is it not the correct link for the documentation for the
compiler that you are using??

>
> The reason I first came here was to not have to write my "... own
> bug-ridden ..." (how nice) ... I have plenty of other bugs to write first.
>

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


Re: Using Python for my web site

2006-07-31 Thread Bruno Desthuilliers
northband a écrit :
> Just spoke with my department and looks like we still want to go with a
> server scripting method.  Although MVC may be better fit, for the sake
> of the learning curve, we want to use a PSP style method.

I really don't think the learning curve will be a problem. We learned 
Django while using it for an app, and the app was completed and 
delivered within a week (total 8 man/day). Granted, it was a dead simple 
app, but it would have take as much time doing it in PHP. The last one 
we did was not trivial, and was ready to deliver in 2 weeks - one week 
before schedule. This very first release is still running, and we didn't 
have a single bug report. Not to say that Django is a silver-bullet, but 
it's actually the best tool we found for sql-based web apps so far.

> So as of now we are looking at using FreeBSD, MySQL, and some form of
> Python that will allow us to achieve great performance serving
> 30million page loads / month.

FWIW, when it comes to web apps, and given a reasonnably well 
designe/implemented app, "performance" is more a matter of 
tuning/hardware/etc than anything else.

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


Re: BCD List to HEX List

2006-07-31 Thread Philippe Martin
Sorry forgot a few answers/comments:

John Machin wrote:
> SHOULD BE >=
>currently add([6, 6], [4, 4] -> [10, 10]

True, thanks

> *** try - 10 instead of % 10
> If the first operand is > 19, you have a bug!
> This might save a few CPU cycles on your smartcard

can it ? each array value will be [0..9]

>> SHOULD CHECK FOR CARRY AT END
>>currently add([9], [8]) -> [7]
>>should return [1, 7] or handle overflow somehow

True, this actually should become an error from the card to the calling
device. That would be a pretty large number though.


>> MINUS ZERO?
I just do not want to leave it at one(1) if it is.


Regards,

Philippe

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


Re: Using Python for my web site

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 15:06 -0700, northband wrote:
> Makes sense, I will follow your advice.  Sounds like more time invest
> upfront will equal time saved over the long run.  I am defitely
> interested in proxy caching and load balancing.  Which do you
> recommend?  I have used #Pound while working for a university.

I currently use Pound, mostly for proxying to virtual hosts on my shared
hosting systems, but for heavy page hits and dynamic content, Squid is
probably of more interest since Pound doesn't do caching.

Regards,
Cliff


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


Re: Python help for Access database

2006-07-31 Thread BartlebyScrivener
John Machin wrote:

>> or mxODBC
>> [very good but not free].

I love mxODBC. It's free for noncommercial use.

http://www.egenix.com/files/python/mxODBC.html

rd

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


ELF format reader

2006-07-31 Thread Hugo Venturini
Hi, I am looking for an ELF format reader written in python. Does anyone know if it exists?H.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Using Python for my web site

2006-07-31 Thread Bruno Desthuilliers
northband a écrit :
> So seems the best approach would be a MVC model rather than server
> scripting?  

This is still "server-scripting" - at least since on the server-side and 
is done with something frequently labelled as a "script language" !-)

> Currently our site is built with a closed source hypertext
> preprocessor much like PHP.  So it would be easier for us to script
> another site,

Depends on how your app is written - one can do MVC with PHP too.

> but if we would gain performance via a MVC model,

This won't change anything to performances. What you can gain is a 
better design, well-decoupled code, hence far less maintenance problems.

> 
> I am not very familiar with developing via MVC,  any good tutorials out
> there or good places to start? 

Do the Django tutorial. They actually name things differently (ie they 
call controllers views and views templates), which can be a bit 
misleading, but that's really MVC.

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


Re: Using Python for my web site

2006-07-31 Thread Diez B. Roggisch
northband schrieb:
> So seems the best approach would be a MVC model rather than server
> scripting?  Currently our site is built with a closed source hypertext
> preprocessor much like PHP.  So it would be easier for us to script
> another site, but if we would gain performance via a MVC model, then
> that's what we need.

MVC and server side scripting are two totally orthogonal things - you 
don't do the one and ditch the other as a consequence of that.

MVC is a pattern of software design. It won't affect the performance 
itself, at least not the system performance. It most probably will boost 
your developing performance, as following the clear separation of data 
(model), application logic (controller) and view-logic (view) will help 
maintaining the codebase and make changes easier.

And MVC doesn't depend on the language used - you can even do that in 
PHP, albeit it makes things much more dependent on discipline.

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


Re: Using Python for my web site

2006-07-31 Thread Bruno Desthuilliers
Gerhard Fiedler a écrit :
> On 2006-07-31 15:00:15, Bruno Desthuilliers wrote:
> 
> 
>>In fact, the real question IMHO is: what would MySQL advantage over
>>PostgreSQL be ?-) 
> 
> 
> A few years ago I did some research, and the result was that while
> PostgreSQL was claimed to have more features and a better design, the
> reports of database corruption seemed to have been more frequent than with
> MySQL. The usual reason given was that MySQL was more mature.
 >
> I assume you don't agree... :)

I obviously don't, based on experience with both.

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


Re: BCD List to HEX List

2006-07-31 Thread Philippe Martin
John Machin wrote:

> So why don't you get a freely available "bignum" package, throw away
> the bits you don' t want, and just compile it and use it, instead of
> writing your own bug-ridden (see below) routines? Oh yeah, the bignum
> package might use "long" and you think that you don't have access to
> 32-bit longs in the C compiler for the 8-bit device that you mistook
> for an arm but then said is an Smc8831 [Google can't find it] with a
> CPU that you think is a SC88 [but the manual whose URL you gave is for
> an S1C88] ...
> 

Thanks for the fixes - still looking at it.

You are correct, all "bignum" packages I found needed 32 bits.

Yes I still see from my documentation that there is no "long" handled by my
compiler.

I did make a mistake on the CPU (and I really do not care what it is) - you
wanted some ref (I still do not see why) and I googled S1C88 and sent you a
link as that is the name of the compiler's directory.

The reason I first came here was to not have to write my "... own
bug-ridden ..." (how nice) ... I have plenty of other bugs to write first.



> *** WHAT HAPPENS IF arg1 > arg2?

cmp is called first.

Regards,


Philippe



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


Re: Using Python for my web site

2006-07-31 Thread northband
Makes sense, I will follow your advice.  Sounds like more time invest
upfront will equal time saved over the long run.  I am defitely
interested in proxy caching and load balancing.  Which do you
recommend?  I have used #Pound while working for a university.

-Adam


Cliff Wells wrote:
> On Mon, 2006-07-31 at 14:40 -0700, northband wrote:
> > Just spoke with my department and looks like we still want to go with a
> > server scripting method.  Although MVC may be better fit, for the sake
> > of the learning curve, we want to use a PSP style method.
>
> I'm with the others who suggest using an MVC framework.  The learning
> curve for Django, TurboGears, Pylons, et al, is ridiculously short, and
> the maintainability of the resulting code is infinitely superior.
>
> Why don't you take a look at the 20 minute wiki screencast that
> TurboGears has and make a decision then.  Although the screencast is
> specifically about TurboGears, a similar screencast could be made for
> almost any of the other MVC-style frameworks:
>
> http://files.turbogears.org/video/20MinuteWiki2nd.mov
> http://www.turbogears.org/preview/docs/tutorials/wiki20/index.html
>
> Developing in a PHP/ASP embedded style is an anachronism these days and
> for good reason.   Spend a couple days learning a modern framework.  The
> time will be well-spent and quickly made up in shortened development
> time and code maintainablility.
>
> > So as of now we are looking at using FreeBSD, MySQL, and some form of
> > Python that will allow us to achieve great performance serving
> > 30million page loads / month.
>
> If I were you, I'd cease worrying about the performance of the framework
> itself and research caching proxies and load balancing solutions
> instead.  The payoff in performance will be much higher and you won't
> have to make architectural compromises.
> 
> Regards,
> Cliff
> 
> --

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


Re: getting debug from urllib2

2006-07-31 Thread Ben Edwards
Thanks a lot, hove managed to get it working:

opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))

Ben

On Mon, 2006-07-31 at 12:33 -0400, Chris Lambacher wrote:
> On Mon, Jul 31, 2006 at 02:43:36PM +0100, Ben Edwards wrote:
> > Have been experimenting with HTTP stuff in python 2.4 and am having a
> > problem getting debug info. If I use utllib.utlopen I get debug but if I
> > user utllib2 I do not.  Below is the probram and the output I am
> > getting.
> > 
> > Any insight?
> urllib2 sets the debug level every time a connection is made.  The HTTPHandler
> classes provide a way of setting this, but there is no convenient way of doing
> this when using the urlopen interface.
> 
> -Chris
> > Ben
> > 
> > * Code *
> > 
> > import urllib, urllib2, httplib
> > 
> > url = 'http://www.mozillazine.org/atom.xml'
> > httplib.HTTPConnection.debuglevel = 1
> > 
> > print "urllib"
> > 
> > data = urllib.urlopen(url);
> > 
> > print "urllib2"
> > 
> > request = urllib2.Request(url)
> > opener = urllib2.build_opener()
> > feeddata = opener.open(request).read()
> > 
> > print "End\n"
> > 
> > * Output *
> > 
> > urllib
> > connect: (www.mozillazine.org, 80)
> > send: 'GET /atom.xml HTTP/1.0\r\nHost: www.mozillazine.org\r
> > \nUser-agent: Python-urllib/1.16\r\n\r\n'
> > reply: 'HTTP/1.0 200 OK\r\n'
> > header: Date: Mon, 31 Jul 2006 13:43:11 GMT
> > header: Server: Apache/2.0.55 (Gentoo) PHP/4.4.0-pl1-gentoo
> > header: Last-Modified: Thu, 27 Jul 2006 18:05:52 GMT
> > header: ETag: "20a1b4-6bcf-be12000"
> > header: Accept-Ranges: bytes
> > header: Content-Length: 27599
> > header: Content-Type: application/xml
> > header: Age: 5
> > header: X-Cache: HIT from mz5.mz.osuosl.org
> > header: X-Cache-Lookup: HIT from mz5.mz.osuosl.org:80
> > header: Connection: close
> > urllib2
> > End
> > 
> > 
> > 
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list


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


Re: Using Python for my web site

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 14:40 -0700, northband wrote:
> Just spoke with my department and looks like we still want to go with a
> server scripting method.  Although MVC may be better fit, for the sake
> of the learning curve, we want to use a PSP style method.

I'm with the others who suggest using an MVC framework.  The learning
curve for Django, TurboGears, Pylons, et al, is ridiculously short, and
the maintainability of the resulting code is infinitely superior.

Why don't you take a look at the 20 minute wiki screencast that
TurboGears has and make a decision then.  Although the screencast is
specifically about TurboGears, a similar screencast could be made for
almost any of the other MVC-style frameworks:

http://files.turbogears.org/video/20MinuteWiki2nd.mov
http://www.turbogears.org/preview/docs/tutorials/wiki20/index.html

Developing in a PHP/ASP embedded style is an anachronism these days and
for good reason.   Spend a couple days learning a modern framework.  The
time will be well-spent and quickly made up in shortened development
time and code maintainablility.

> So as of now we are looking at using FreeBSD, MySQL, and some form of
> Python that will allow us to achieve great performance serving
> 30million page loads / month.

If I were you, I'd cease worrying about the performance of the framework
itself and research caching proxies and load balancing solutions
instead.  The payoff in performance will be much higher and you won't
have to make architectural compromises.

Regards,
Cliff

-- 

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


Re: Python help for Access database

2006-07-31 Thread John Machin

shakir wrote:
> HI All,
>
> I need help for inserting recods into the access database using python
> script through ODBC. I can insert data without any problem if I hard
> coded the run_Date field. But I need run_Date field should be mytime..
> I am getting error Data type mismatch in criteria expression. in EXEC
>
> I really appreciate if anyone can help me.
>
> Thanks in advance
>
> Shakir
>
> # mdbupdate.py
>
> import sys
> import os
> import os.path
> import shutil
> import time
> import sys, string, os, win32com.client
> import odbc
>
>
> mytime = time.strftime('%m/%d/%Y')
> mytimeYMD = time.strftime('%Y%m%d')
> conn = odbc.odbc("test1_Data")
> cursor = conn.cursor()
>
> # data type in mdb is as follows: application -> Text, Run_Date ->
> Date, Run_dateYMD -> #number, status -> Script
>
> cursor.execute("INSERT INTO local_cmgenadm (Application,Run_Date,
> Run_DateYMD,status) values (\'MyApp1\',\'%s\', \'20060731\' ,
> \'Good\')")%mytime

1. Why do you think you need all those \ characters?

2. Try this elementary debugging procedure:

sql = "INSERT ..."
print sql
print mytime
print sql % mytime
# compare the result with your hard-coded effort
cursor.execute(sql)

3. You may wish to try the parameterised approach:

cursor.execute("insert ... values (?,?,?,?)", ( 'MyApp1',mytime,
'20060731' ,'Good'))

[google "SQL injection attack"]

4. You may wish to try another interface: adodbapi [I've used that OK
but the project seems dormant (last update 3 years ago)] or mxODBC
[very good but not free].
If you are not constrained to use MS Access, consider sqlite3.

Cheers,
John

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


Re: Using Python for my web site

2006-07-31 Thread northband
Just spoke with my department and looks like we still want to go with a
server scripting method.  Although MVC may be better fit, for the sake
of the learning curve, we want to use a PSP style method.

So as of now we are looking at using FreeBSD, MySQL, and some form of
Python that will allow us to achieve great performance serving
30million page loads / month.

-Adam

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


RE: Borg vs. Module

2006-07-31 Thread Jordan R McCoy
Tobiah:

>From the standpoint of implementation, I don't see much of a difference
unless you are specifically interested in the more limited functionality
of a module (vs. a class instance). If you aren't, then you can simply
instantiate your borg class and then insert it into sys.modules early in
the pipeline; future imports of that module will get your instantiated
class instead of the dummy module. Thus, you can use the import syntax
yet still have descriptors and other class-based features.

I would carefully consider doing this, though. It would be a somewhat
uncommon use of import mechanics, and a particularly confusing one at
that since the developer has to understand how the module-like object is
being used differently. The flexibility of the import mechanics is there
so that we can make something other than a common module look like a
common module; having it not act like a common module might be making
the endeavor overly complex and obscure.

For example, the Twisted framework uses this technique to allow global
access to the installed reactor via import syntax, which works well
within the framework. It did, however, throw me a bit when I first
encountered it, and drove me to pour over the source to find out what
was happening. Perhaps this was good, but I wonder if it would just have
been simpler to provide the same access through a module function (eg:
reactor.reactor() -> reactor instance). 

--
Jordan McCoy

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of tobiah
Sent: Monday, July 31, 2006 2:52 PM
To: python-list@python.org
Subject: Borg vs. Module

I am making a web app, made up of many modules
that all need access to some important data, like
the current session data, cookies, navigation history,
post/get variables, etc.

I decided to go with the 'Borg' idea, by assigning the
__dict__ of an object to a class variable so that each
instantiation of the Borg() would share the same data.
That way I can either pass the Borg around, or just
Borg() it if I need it in some obscure place.

Then I read an argument that it usually makes more sense
to just have a module with the data and functions that
I need, which all the other modules can simply import.
Since I only need one instance, I could just stuff data
and call 'methods' on this module, probably without even
changing existing syntax.

Are there any arguments as to which method is better?

Thanks,

Toby

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

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


Re: Using Python for my web site

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 17:58 -0300, Gerhard Fiedler wrote:
> On 2006-07-31 17:28:00, Cliff Wells wrote:
> 
> >> I assume you don't agree... :)
> > 
> > I certainly don't.  [...]
> 
> > Also, saying "a few years ago I did some research" in software terms is
> > pretty much equivalent to saying "I don't know".
> 
> Exactly. So what's your point with this comment?

My point is to stop FUD right at that comment.  I don't doubt your
research from "a few years ago", but ancient research is entirely
irrelevant for making a decision *today*.

However, had I let it pass, then someone else might not make that
distinction and come away with the impression that your research was
somehow still relevant and that PostgreSQL is less reliable than MySQL.

> I stated what was my impression at the time, with the hope that others
> might want to comment. Thanks for the comment. 

You're welcome.

> OTOH, anybody who says "I know" regarding a comparison in reliability
> between databases must have pretty good data to back that up. Few have.
> Most are in the "I don't know, but my impression is that ..." group. 

Absolutely.  I can only give you anecdotal evidence myself.  Further, if
someone were to present a whitepaper of some sort demonstrating that one
is superior with regard to reliability or performance, I'd probably be
highly suspect of their motives.  

Regardless, since my job as a hoster requires that I assist customers
with database issues, I have hands-on experience with dozens of
instances of each and my *very recent* experience tells me that MySQL is
far more prone to database corruption than PostgreSQL.  In the past 6
months, I've repaired or restored at least 4 MySQL databases (and for no
apparent reason, to boot), but I've had to do the same for exactly zero
PostgreSQL installs since I started hosting over 3 years ago.  And just
to be clear, the number of PostgreSQL installs far exceeds the number of
MySQL installs.  Were there equal numbers of each I'd expect even more
MySQL problems.

Regards,
Cliff

-- 

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


Re: Static Variables in Python?

2006-07-31 Thread tac-tics
> But of course:
>
>  >>> def fun():
>   global x = 10
>
> SyntaxError: invalid syntax
>  >>>

global x
x = 10

Close enough ^^;

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

Philippe Martin wrote:
> Paul Rubin wrote:
>
> > Philippe Martin <[EMAIL PROTECTED]> writes:
> >> I actually need numbers much larger than 32 bits.

***NOW*** you tell us, after all the stuffing about re 32 bits.

> >
> > What is the max size hex number you need?  What is the application if
> > you don't mind my asking?
>
> Well I am under NDA so I cannot tell you what the application is - I need
> numbers (dec) with up to 24 digits.

So why don't you get a freely available "bignum" package, throw away
the bits you don' t want, and just compile it and use it, instead of
writing your own bug-ridden (see below) routines? Oh yeah, the bignum
package might use "long" and you think that you don't have access to
32-bit longs in the C compiler for the 8-bit device that you mistook
for an arm but then said is an Smc8831 [Google can't find it] with a
CPU that you think is a SC88 [but the manual whose URL you gave is for
an S1C88] ...

>
> As I said, I went the other way - more data on the line (from dev 1 to dev
> 2) - but I feel there is no speed issue at this stage.
>
> Seems to work.

Nothing is what it seems. See below.

>
>
> Regards,
>
> Philippe
>
>
>
>  PYTHON **
> l2 = [1,2,3,4]
> l1 = [0,2,5,9]
>
>
> def sup (l1, l2): #assume same length
> for i in range(len(l1) ):
> if l1[i] > l2[i]:
> return 1
> if l1[i] < l2[i]:
> return -1
> return 0
>
>
>
> def add (l1, l2): #assume same length
> r = []
> idx =  range (len(l1))
> idx.reverse()
> carry = 0
> for i in idx:
>
> if l1[i] + l2[i] > 10:

 SHOULD BE >=
currently add([6, 6], [4, 4] -> [10, 10]

> carry = 1
> r.insert(0,(l1[i] + l2[i]) % 10)

*** try - 10 instead of % 10
If the first operand is > 19, you have a bug!
This might save a few CPU cycles on your smartcard

> else:
> r.insert(0,l1[i] + l2[i] + carry)
> carry = 0

 SHOULD CHECK FOR CARRY AT END
currently add([9], [8]) -> [7]
should return [1, 7] or handle overflow somehow

> return r
>
>
>
> def sub (l1,l2): #assume same length - sub l1 from l2

*** WHAT HAPPENS IF arg1 > arg2?

> r = []
> idx =  range (len(l1))
> idx.reverse()
> carry = 0
> for i in idx:
> print l1[i] + carry, l2[i]
> if ((l2[i]) - (l1[i]+carry) < 0) :
> print 'CARRY'
> r.insert(0,(((10 + l2[i])  - (l1[i]+carry
> carry = 1
> else:
> r.insert(0,(l2[i]) - (l1[i]+ carry))
> carry = 0
> return r
>
>
> print sub (l1,l2)
>
> * AND AM JUST TESTING IT IN JAVACARD **

with the bugs in the Python functions carried forward.

>
>
> //
> public byte CmpD(byte[] p_op1, byte[] p_op2,  byte p_len) {
> byte l_count = (byte)0;
> for (; l_count < p_len; l_count += 1) {
> short C = (short)(p_op1[l_count]);
> short D = (short)(p_op2[l_count]);
>
> if (C > D) return 1;
> if (C < D) return -1;
> }
>
> return 0;
>
> }
> 
> //
> public static void SubD(byte[] p_op1, byte[] p_op2, byte[] p_dest, byte
> p_len) {
> byte l_count = (byte)0;
> byte l_carry = (byte)0;
> for (l_count = (byte)(p_len - (byte)1); l_count >= (byte)0; l_count
> -= (byte)1) {
> if ((p_op2[l_count] - (byte)(p_op1[l_count]+l_carry) ) < 0) {
> p_dest[l_count] = (byte)(  ((byte)10 + p_op2[l_count]) -
> (byte)(p_op1[l_count] + l_carry)) ;
> l_carry = (byte)1;
> }
> else {
> p_dest[l_count] = (byte)(  p_op2[l_count] - (byte)(p_op
> [l_count] + l_carry)) ;
> l_carry = -(byte)0;

 MINUS ZERO?

> }
> }
>
> }
> 
> //
> public static void AddD(byte[] p_op1, byte[] p_op2, byte[] p_dest, byte
> p_len) {
> byte l_count = (byte)0;
> byte l_carry = (byte)0;
> for (l_count = (byte)(p_len - (byte)1); l_count >= (byte)0; l_count
> -= (byte)1) {
> if (p_op2[l_count] + (byte)(p_op1[l_count]) > 10) {
> p_dest[l_count] = (byte)( ( p_op2[l_count] + p_op
> [l_count] )% 10) ;
> l_carry = (byte)1;
> }
> else {
> p_dest[l_count] = (byte)(  p_op2[l_count] + p_op1[l_count] +
> l_carry) ;
> l_carry = -(byte)0;

 MINUS ZERO?
> }
> }
> 
> }

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


Re: Using Python for my web site

2006-07-31 Thread northband
So seems the best approach would be a MVC model rather than server
scripting?  Currently our site is built with a closed source hypertext
preprocessor much like PHP.  So it would be easier for us to script
another site, but if we would gain performance via a MVC model, then
that's what we need.

I am not very familiar with developing via MVC, any good tutorials out
there or good places to start? 

-Adam

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


Re: Static Variables in Python?

2006-07-31 Thread Paddy

Michael Yanowitz wrote:
> Is it possible to have a static variable in Python -
> a local variable in a function that retains its value.
>
>  For example, suppose I have:
>
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
>
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
>
>
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.
>
>
> Thanks in advance:
> Michael Yanowitz

You can do things with function attributes

def foo(x):
  foo.static += x
  return foo.static
foo.static = 0

If you are going to set function attributes a lot, then you might like
to addd an attriute setter decorator to your toolbox:

def attributeSetter( **kw):
" decorator creator: initialises function attributes"
def func2(func):
" decorator: initialises function attributes"
func.__dict__.update(kw)
return func
return func2

def accumulator(n):
""" return an accumulator function that starts at n
>>> x3 = accumulator(3)
>>> x3.acc
3
>>> x3(4)
7
>>> x3.acc
7
"""
@attributeSetter(acc = n)
def accum(i):
accum.acc+= i
return accum.acc
return accum


- Paddy

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


Re: Using Python for my web site

2006-07-31 Thread Gerhard Fiedler
On 2006-07-31 17:28:00, Cliff Wells wrote:

>> I assume you don't agree... :)
> 
> I certainly don't.  [...]

> Also, saying "a few years ago I did some research" in software terms is
> pretty much equivalent to saying "I don't know".

Exactly. So what's your point with this comment?

I stated what was my impression at the time, with the hope that others
might want to comment. Thanks for the comment. 

OTOH, anybody who says "I know" regarding a comparison in reliability
between databases must have pretty good data to back that up. Few have.
Most are in the "I don't know, but my impression is that ..." group. 

Gerhard

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


Re: Static Variables in Python?

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 15:21 -0400, Michael Yanowitz wrote:
>   Is it possible to have a static variable in Python - 
> a local variable in a function that retains its value.
> 
>  For example, suppose I have:
> 
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
> 
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
> 
>  
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.

BTW, I'm assuming this example was contrived.  In real life, I wonder
why you'd ever want to use anything besides:

bits = [ 0 ] * 16
bits [ 4 ] = 1
print "Bit Array:"
print ' '.join ( bits )

Having a "set_bit" function seems redundant when the language syntax
directly supports what you are trying to do.

Regards,
Cliff

-- 

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


Re: Static Variables in Python?

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 13:37 -0700, Cliff Wells wrote:
> On Mon, 2006-07-31 at 13:02 -0700, Cliff Wells wrote:
> 
> 
> > @attrs ( bits = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] )
> 
> Also, IMO, it's a bit more readable to write:
> 
> bits = [ 0 for i in range ( 16 ) ]

Or even:

bits = [ 0 ] * 16

Just be careful to only use that style when the contents of the array
are non-mutable.  The list comp does the right thing in that case (at
risk of going on a tangent):

Right:
>>> bits = [ { } for i in range ( 16 ) ]
>>> bits
[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
>>> bits [ 0 ][ 'a' ] = 1
>>> bits
[{'a': 1}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]

Wrong:
>>> bits = [ {} ] * 16
>>> bits [ 0 ][ 'a' ] = 1
>>> bits
[{'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1},
{'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1}, {'a': 1},
{'a': 1}, {'a': 1}]
>>>


Regards,
Cliff

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


Re: Static Variables in Python?

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 13:02 -0700, Cliff Wells wrote:


> @attrs ( bits = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] )

Also, IMO, it's a bit more readable to write:

bits = [ 0 for i in range ( 16 ) ]

which avoids the necessity of counting the zeros to know how many there
are.

Regards,
Cliff


-- 

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


Re: Static Variables in Python?

2006-07-31 Thread Bruno Desthuilliers
Michael Yanowitz a écrit :
>   Is it possible to have a static variable in Python - 
> a local variable in a function that retains its value.
> 
>  For example, suppose I have:
> 
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
> 
>print "\tBit Array:"
>int i

Syntax error

>while (i < len(bits):
>   print bits[i],

Nice infinite loop...

Python's canonical way to iterate over a sequence is the for loop:
for bit in bits:
   print bit,

And FWIW, for what you want to do, you don't even need a loop:
print "\n".join(map(str, bits))

>print '\n'


>  
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.

While there are some more or less hackish solutions (cf Roel answers and 
my answers to it), the usual way to have functions maintaining state is 
to define a class and instanciate it. Note that Python's functions are 
objects, and that it's possible to write your own callable objects too 
if you really want a function call syntax:

class Setbit(object):
   def __init__(self):
 self._bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
   def call(self, index, value):
 self._bits[index] = value
   def values(self):
 return self._bits[:]

set_bit = Setbit()
set_bit(1, 1)
print "".join(map(str, set_bit.values()))

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


Re: Static Variables in Python?

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 15:21 -0400, Michael Yanowitz wrote:
>   Is it possible to have a static variable in Python - 
> a local variable in a function that retains its value.
> 
>  For example, suppose I have:
> 
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
> 
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
 

Many people suggest that using a class for this is the Python idiom (and
perhaps it is), but I prefer to use a decorator for adding attributes to
functions in this case:

def attrs ( **kwds ):
''' taken from PEP 318 '''
def decorate ( f ):
for k in kwds:
setattr ( f, k, kwds [ k ] )
return f
return decorate

@attrs ( bits = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] )
def set_bit ( idx, val ):
set_bit.bits [ idx ] = int ( bool ( val ) )
print "Bit Array:"
for i in set_bit.bits:
print i,
print 


>>> set_bit ( 4, 1 )
Bit Array:
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
>>> set_bit ( 5, 1 )
Bit Array:
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0


Regards,
Cliff

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


Re: Using Python for my web site

2006-07-31 Thread Cliff Wells
On Mon, 2006-07-31 at 17:12 -0300, Gerhard Fiedler wrote:
> On 2006-07-31 15:00:15, Bruno Desthuilliers wrote:
> 
> > In fact, the real question IMHO is: what would MySQL advantage over
> > PostgreSQL be ?-) 
> 
> A few years ago I did some research, and the result was that while
> PostgreSQL was claimed to have more features and a better design, the
> reports of database corruption seemed to have been more frequent than with
> MySQL. The usual reason given was that MySQL was more mature.
> 
> I assume you don't agree... :)

I certainly don't.  MySQL provides two different ways to corrupt your
data: actual database corruption *and* data integrity corruption.  You
can escape the second by using InnoDB rather than MyISAM tables, but
that increases your chances of the first (InnoDB not being as "mature"
as either MyISAM or PostgreSQL).

Also, saying "a few years ago I did some research" in software terms is
pretty much equivalent to saying "I don't know".

Regards,
Cliff

-- 

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


Re: Static Variables in Python?

2006-07-31 Thread Bruno Desthuilliers
Roel Schroeven a écrit :
> Michael Yanowitz schreef:
> 
>>   Is it possible to have a static variable in Python - a local 
>> variable in a function that retains its value.
>>
(snip)
> 
> You could do it by defining static_bits as a keyword parameter with a 
> default value:
> 
(snip)
> It might be a better idea to use a class for this though:
> 
(snip)

Last solution being to use a closure:

def make_bits():
   bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
   def set_bit(bit_index, bit_value):
 bits[bit_index] = bit_values
   def get_bits():
 # returns a copy so we don't overwrite
 return bits[:]
   return set_bit, get_bits

set_bit, get_bits = make_bits()

But the better solution is probably to make it a class.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Static Variables in Python?

2006-07-31 Thread John Salerno
[EMAIL PROTECTED] wrote:
> tac-tics:
>> If you declare bits in set_bit() as "global bits = ...", it will create
>> it as a global variable without you having to declare it outside of the
>> function. Just be careful about name conflicts.
> 
> Are you sure?
> 
> def fun():
> global x = 10
> fun()
> print x
> 
> Bye,
> bearophile
> 

This works for me:

 >>> def fun():
global x
x = 10


 >>> fun()
 >>> print x
10
 >>>

But of course:

 >>> def fun():
global x = 10

SyntaxError: invalid syntax
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python for my web site

2006-07-31 Thread Gerhard Fiedler
On 2006-07-31 15:00:15, Bruno Desthuilliers wrote:

> In fact, the real question IMHO is: what would MySQL advantage over
> PostgreSQL be ?-) 

A few years ago I did some research, and the result was that while
PostgreSQL was claimed to have more features and a better design, the
reports of database corruption seemed to have been more frequent than with
MySQL. The usual reason given was that MySQL was more mature.

I assume you don't agree... :)

Gerhard

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


Re: Static Variables in Python?

2006-07-31 Thread Carsten Haese
On Mon, 2006-07-31 at 15:21, Michael Yanowitz wrote:
>   Is it possible to have a static variable in Python - 
> a local variable in a function that retains its value.
> 
>  For example, suppose I have:
> 
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
> 
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
> 
>  
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.

Python does not have static variables in the sense that C does. You can
fake it in various ways, though. If I had to do it, I'd define a
callable object instead of a function, along the lines of this:

class BitSetter(object):
  def __init__(self):
self.bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  def __call__(self, bit_index, bit_value):
self.bits[bit_index] = bit_value
# do something with self.bits here...
print self.bits

set_bit = BitSetter()

Now you can call set_bit(...) as if it were a function, and it'll behave
the way you want.

Hope this helps,

Carsten.


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


Python server j2me client ssl socket handshake error

2006-07-31 Thread karzem
I try to write simple midlet in java to connect with my server which
monitors processes in my PC. I've written almost everything and now
I've spend 4 days trying to set up a connection between them. Without
ssl everything works fine.
Here is my fragment of server program:

def verify_cb(conn, cert, errnum, depth, ok):
print 'Got certificate: %s' % cert.get_subject()
return ok

HOST =  "192.168.1.30"
PORT = 5007  # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ctx = SSL.Context(SSL.SSLv3_METHOD)
ctx.set_verify(SSL.VERIFY_NONE, verify_cb)
ctx.use_certificate_file('server.pem')
ctx.use_privatekey_file('server.pem')
ss = SSL.Connection(ctx,s)
ss.bind((HOST, PORT))
from src.xmlFunc import validateXml

while True :
ss.listen(1)
conn, addr = ss.accept()
print 'Connected by', addr
while True :
_data = conn.recv(1024)
print _data
if not _data: break
_data = "req_auth"
conn.send(_data)
conn.close()

in my client java application:

SecureConnection socket =
(SecureConnection)Connector.open("ssl://192.168.1.30:5007",Connector.READ_WRITE);

when I run server and client program the clients stops on line above.
Server accepts the connection and when I debug next line I get an
error:
[('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure') ,
('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')]

What I know is that when I use : openssl s_client -connect
192.168.1.30:5007 -ssl3
the output is:
 CONNECTED(0003)
depth=0 /C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
verify error:num=18:self signed certificate
verify return:1
depth=0 /C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
verify return:1
---
Certificate chain
 0 s:/C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
   i:/C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
---
Server certificate
-BEGIN CERTIFICATE-
MIIDEzCCAnygAwIBAgIJALjQF38yg5s8MA0GCSqGSIb3DQEBBQUAMGUxCzAJBgNV
BAYTAlBMMRAwDgYDVQQIEwdzbGFza2llMREwDwYDVQQHEwhwc3pjenluYTEhMB8G
A1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQ4wDAYDVQQDEwVhbG9oYTAe
Fw0wNjA3MjExMjE3MTJaFw0wNzA3MjExMjE3MTJaMGUxCzAJBgNVBAYTAlBMMRAw
DgYDVQQIEwdzbGFza2llMREwDwYDVQQHEwhwc3pjenluYTEhMB8GA1UEChMYSW50
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQ4wDAYDVQQDEwVhbG9oYTCBnzANBgkqhkiG
9w0BAQEFAAOBjQAwgYkCgYEAwqnpUJmd/0Osw8GxMmDAaxIrjxOqKMOwmlTO8cFG
KOFaNJsPt3J8niCwO+Wr8dyndOYVE2qGXll93Kc4hC3EiSup5VRs+ZeFcqtjBTVF
lzRFDP6VXkbUg7Y+urAVAN+tJnk4WFU/saYaaL+tXQUEqTfJZSsM+1CvJQLYojHt
BosCAwEAAaOByjCBxzAdBgNVHQ4EFgQUYJkhg0zJx4Whi6xx+Ln+goCzQfowgZcG
A1UdIwSBjzCBjIAUYJkhg0zJx4Whi6xx+Ln+goCzQfqhaaRnMGUxCzAJBgNVBAYT
AlBMMRAwDgYDVQQIEwdzbGFza2llMREwDwYDVQQHEwhwc3pjenluYTEhMB8GA1UE
ChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQ4wDAYDVQQDEwVhbG9oYYIJALjQ
F38yg5s8MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAfayADZebF1W5
Vgbzx0J5Y3B6QvmzshVYetfg+XKIe44G+2YKTYFZ/Db0BKpgBJLGmPzB0ZeFh++A
UcjxKrxVKCRiqCpaADSf/RY4XrYfO9d6p/zS1P6LuPgiTEzvGpXu01wtIq054EkG
K1p2KEQB9N5DWw9whYk8M3H2LGaV00E=
-END CERTIFICATE-
subject=/C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
issuer=/C=PL/ST=slaskie/L=pszczyna/O=Internet Widgits Pty Ltd/CN=aloha
---
No client certificate CA names sent
---
SSL handshake has read 985 bytes and written 329 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 1024 bit
Compression: zlib compression
Expansion: zlib compression
SSL-Session:
Protocol  : SSLv3
Cipher: AES256-SHA
Session-ID:
BB7FEA77B05B6B52C7F887D7F55DD2E31022B56CA11A865BDB1D5B008CE8DB1A
Session-ID-ctx:
Master-Key:
E40115FC6FA4AB99137AE92DFAF811F20E79563846A91410172416FE0324CF253AF82722ED41A56C4C7A9F0B3460F27B
Key-Arg   : None
   Compression: 1 (zlib compression)
Start Time: 1154375647
Timeout   : 7200 (sec)
Verify return code: 18 (self signed certificate)
---

I've read tons of tutorials and still have nothing what gives me the
solution of this problem.
I have Python 2.4.3 (#2, Apr 27 2006, 14:43:58)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] with OpenSSL 0.9.8a 11 Oct 2005

Can somebody help me... 
Best regards, Charles Zemanek

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


Re: BCD List to HEX List

2006-07-31 Thread John Machin

[EMAIL PROTECTED] wrote:
> Philippe Martin wrote:
> > Yes, I came here for the "algorithm" question, not the code result.
>
> To turn BCD x to binary integer y,
>
>   set y to zero
>   for each nibble n of x:
> y = (((y shifted left 2) + y) shifted left 1) + n

Yeah yeah yeah
i.e. y = y * 10 + n
he's been shown that already.

Problem is that the OP needs an 8-decimal-digit (32-bits) answer, but
steadfastly maintains that he doesn't "have access to" long (32-bit)
arithmetic in his C compiler!!!

>
> Do you need instruction on extracting nibbles, and shifting and
> adding integers?
> 
> A problem this small and simple does not call for a prototype.

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


Re: list of lists of lists ....

2006-07-31 Thread yomgui
thanks for all your answers

yomgui

yomgui wrote:
> 
> Hi,
> 
> I have a list of data (type A)
> my list can includes element of type A or a lists,
> these list can includes element of type A or a lists, and so on ...
> 
> is there a simple way to obtain a single list of all the elemets
> of type A ?
> 
> thanks
> 
> yomgui
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static Variables in Python?

2006-07-31 Thread bearophileHUGS
tac-tics:
> If you declare bits in set_bit() as "global bits = ...", it will create
> it as a global variable without you having to declare it outside of the
> function. Just be careful about name conflicts.

Are you sure?

def fun():
global x = 10
fun()
print x

Bye,
bearophile

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


Re: Windows vs. Linux

2006-07-31 Thread James Stroud
jean-michel bain-cornu wrote:
>Take care to use os.sep

This is an important point. You should read up on the os.path module to 
make sure you are doing things in a platform independent way, for 
example, its better to use:

   os.path.join('my', 'favorite', 'dir')

than

   "\\".join(['my', 'favorite', 'dir'])

because the latter will bonk on linux. The former is platform 
independent. This hits at the same issue as using os.sep:

   os.sep.join(['my', 'favorite', 'dir'])

But os.path has takes care of many of these issues in one module.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Borg vs. Module

2006-07-31 Thread tobiah
I am making a web app, made up of many modules
that all need access to some important data, like
the current session data, cookies, navigation history,
post/get variables, etc.

I decided to go with the 'Borg' idea, by assigning the
__dict__ of an object to a class variable so that each
instantiation of the Borg() would share the same data.
That way I can either pass the Borg around, or just
Borg() it if I need it in some obscure place.

Then I read an argument that it usually makes more sense
to just have a module with the data and functions that
I need, which all the other modules can simply import.
Since I only need one instance, I could just stuff data
and call 'methods' on this module, probably without even
changing existing syntax.

Are there any arguments as to which method is better?

Thanks,

Toby

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

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


Re: Static Variables in Python?

2006-07-31 Thread tac-tics

Michael Yanowitz wrote:
> Is it possible to have a static variable in Python -
> a local variable in a function that retains its value.
>
>  For example, suppose I have:
>
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
>
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
>
>
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.

If you declare bits in set_bit() as "global bits = ...", it will create
it as a global variable without you having to declare it outside of the
function. Just be careful about name conflicts.

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


Re: Static Variables in Python?

2006-07-31 Thread Roel Schroeven
Michael Yanowitz schreef:
>   Is it possible to have a static variable in Python - 
> a local variable in a function that retains its value.
> 
>  For example, suppose I have:
> 
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index] = bit_value
> 
>print "\tBit Array:"
>int i
>while (i < len(bits):
>   print bits[i],
>print '\n'
> 
>  
>I realize this can be implemented by making bits global, but can
> this be done by making it private only internal to set_bit()?  I don't
> want bits to be reinitialized each time. It must retain the set values
> for the next time it is called.

You could do it by defining static_bits as a keyword parameter with a 
default value:

 >>> def set_bit(bit_index, bit_value, static_bits=[0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0]):
static_bits[bit_index] = bit_value
return static_bits

 >>> set_bit(2, 1)
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 >>> set_bit(3, 1)
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 >>> set_bit(2, 0)
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

It might be a better idea to use a class for this though:

 >>> class Bits(object):
def __init__(self):
self.bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def set(self, index, value):
self.bits[index] = value
return self.bits


 >>> bits = Bits()
 >>> bits.set(2, 1)
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 >>> bits.set(3, 1)
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 >>> bits.set(2, 0)
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

When using a class, you can have different lists of bits independently 
of each other in a program. And you can define other operations on the 
bits: you could for example create methods to set or clear all bits at 
once. With your approach, set_bit is the only function that has access 
to the bits so you can't easily create other operations.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: XML parsing and writing

2006-07-31 Thread c00i90wn
Nice package ElementTree is but sadly it doesn't have a pretty print,
well, guess I'll have to do it myself, if you have one already can you
please give it to me? thanks :)

Stefan Behnel wrote:
> c00i90wn wrote:
> > Hey, I'm having a problem with the xml.dom.minidom package, I want to
> > generate a simple xml for storing configuration variables, for that
> > purpose I've written the following code, but before pasting it I'll
> > tell you what my problem is. On first write of the xml everything goes
> > as it should but on subsequent writes it starts to add more and more
> > unneeded newlines to it making it hard to read and ugly.
>
> Maybe you should try to get your code a little cleaner first, that usually
> helps in finding these kinds of bugs. Try rewriting it with ElementTree or
> lxml, that usually helps you in getting your work done.
>
> http://effbot.org/zone/element-index.htm
> http://codespeak.net/lxml/
> 
> Stefan

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


Static Variables in Python?

2006-07-31 Thread Michael Yanowitz
  Is it possible to have a static variable in Python - 
a local variable in a function that retains its value.

 For example, suppose I have:

def set_bit (bit_index, bit_value):
   static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
   bits [bit_index] = bit_value

   print "\tBit Array:"
   int i
   while (i < len(bits):
  print bits[i],
   print '\n'

 
   I realize this can be implemented by making bits global, but can
this be done by making it private only internal to set_bit()?  I don't
want bits to be reinitialized each time. It must retain the set values
for the next time it is called.


Thanks in advance:
Michael Yanowitz



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


  1   2   3   >