Re: multiple parameters in if statement

2006-04-16 Thread John Machin
On 16/04/2006 1:43 PM, John Zenger wrote:
> 
> The other thing I'd recommend is stick that long list of fields in a 
> list, and then do operations on that list:
> 
> fields = ['delete_id', 'delete_date', 'delete_purchasetype', 
> 'delete_price', 'delete_comment']
> 
> then to see if all those fields are empty:
> 
> everything = ""
> for field in fields:
> everything += form.get(field,"")

Or everything = "".join(form.get(field, "") for field in fields)

Somewhat labour-intensive. It appears from the OP's description that no 
other entries can exist in the dictionary. If this is so, then:

everything = "".join(form.values())

but what the user sees on screen isn't necessarily what you get, so:

everything = "".join(form.values()).strip()

> if everything == "":
> print "Absolutely nothing entered!"
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating through a nested list

2006-04-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Steven
D'Aprano wrote:

> for obj in Array:
> if isinstance(obj, list):
> for item in obj:
> print item
> else:
> print obj

I would "reverse" that check and test `obj` for not being a string::

 for obj in Array:
 if not isinstance(obj, basestring):
 for item in obj:
 print item
 else:
 print obj

This way it works with other types of iterables than lists too.  Often
strings are the only type that one don't want to iterate over in such a
context.

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


keyboard command to break out of infinite loop?

2006-04-16 Thread BartlebyScrivener
Running Python on Win XP.

When running commands with the interpreter, if you get stuck in a while
loop, is there a keyboard command to break out of it?

Or is the only way out a triple-finger salute and End Task?

rd

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


How to pass variable to test class

2006-04-16 Thread Podi
Hi,

Newbie question about unittest. I am having trouble passing a variable
to a test class object.

MyCase class will potentially have many test functions.

Any help would be much appreciated.

Thanks,
P

# File MyCase.py
import unittest

class MyCase(unittest.TestCase):
def __init__(self, value):
super(MyCase, self).__init__()
self.value = value
def test1(self):
print self.value
def test2(self):
print 'world'

if __name__ == '__main__':
msg = 'Hello'
myCase = MyCase(msg)
suite = unittest.TestSuite()
suite.addTest(myCase)
unittest.TextTestRunner(verbosity=2).run(suite)


D:\MyWorks>MyCase.py
Traceback (most recent call last):
  File "D:\MyWorks\MyCase.py", line 14, in ?
myCase = MyCase(msg)
  File "D:\MyWorks\MyCase.py", line 5, in __init__
super(MyCase, self).__init__()
  File "C:\Python24\lib\unittest.py", line 208, in __init__
raise ValueError, "no such test method in %s: %s" % \
ValueError: no such test method in : runTest

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


Re: Writing backwards compatible code

2006-04-16 Thread Dave Brueck
Steven D'Aprano wrote:
> I came across an interesting (as in the Chinese curse) problem today. I
> had to modify a piece of code using generator expressions written with
> Python 2.4 in mind to run under version 2.3, but I wanted the code to
> continue to use the generator expression if possible.
[snip]
> What techniques do others use?

About the only reliable one I know of is to not use syntax from the newer 
version, period, if the code needs to run on old versions. Your example was 
pretty straightforward, but unless the use case is always that simple it's too 
easy to have two separate versions of the code to maintain, and there's no way 
to enforce that changes/fixes to one will be duplicated in the other.

So... if you have to take the time to make one that works with the older 
version, you might as well just use it exclusively.

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


Re: Async Sleep?

2006-04-16 Thread Daniel Nogradi
> Hi all,
>
> Does a async sleep exist?
> How to check this every 10 sec, but that the CPU is free?

I would use a separate thread for this, perhaps even a completely
detached daemon. You might want to check the docs for threading:

http://docs.python.org/lib/module-threading.html

and these recipes on how to create a daemon:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52216

You can also spawn a separate process with the spawn* family of
functions. If you use them with the os.P_NOWAIT mode, your program
will not hang until the spawned process finishes. See:

http://docs.python.org/lib/os-process.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple parameters in if statement...

2006-04-16 Thread Peter Otten
Kun wrote:

> [EMAIL PROTECTED] wrote:
>> Kun wrote:
>>> I am trying to make an if-statement that will not do anything and print
>>> 'nothing entered' if there is nothing entered in a form.  I have the
>>> following code that does that, however, now even if I enter something
>> 
>> Yes, but did you enter everything?
>> 
>>> into the form, the code still outputs 'nothing entered'.
>> 
>> The logic doesn't imply "nothing", it implies "not everything".
>> The else clause will execute if ANY item is not enetered.
>> 
>>> This violates
>>> the if statement and I am wondering what I did wrong.
>>>
>>>  if form.has_key("delete_id") and form["delete_id"].value != "" and
>>> form.has_key("delete_date") and form["delete_date"].value != "" and
>>> form.has_key("delete_purchasetype") and
>>> form["delete_purchasetype"].value != "" and form.has_key("delete_price")
>>> and form["delete_price"].value != "" and form.has_key("delete_comment")
>>> and form["delete_comment"].value != "":
>>>  delete_id=form['delete_id'].value
>>>  delete_date=form['delete_date'].value
>>>  delete_purchasetype=form['delete_purchasetype'].value
>>>  delete_price=form['delete_price'].value
>>>  delete_comment=form['delete_comment'].value
>>>  else:
>>>  print "ERROR: Nothing entered!"
>>>  raise Exception
>> 
> How do I make this so that it only prints 'nothing entered' when none of
> the fields are entered?

def has_data(form, fields):
for field in fields:
if form.has_key(field) and form[field] != "":
return True
return False

fields = ["delete_id", "delete_date", "delete_purchasetype", "delete_price",
"delete_comment"]

if not has_data(form, fields):
print "nothing entered"

Just testing for

if field in form: ...

instead of 

if form.has_key(field) and form[field] != "": ...

is probably sufficient if form is a cgi.FieldStorage.

Peter

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


Re: keyboard command to break out of infinite loop?

2006-04-16 Thread zweistein
Try CTRL + C. If it doesn't work, CTRL + Pause/Break should also work
(if you're running it from the CLI).

HTH

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


Re: Unified web API for CGI and mod_python?

2006-04-16 Thread Alexis Roda
Tim Chase escribió:
  >
> [EMAIL PROTECTED] cd ~tim/WebStack-1.1.2
> [EMAIL PROTECTED] python2.3 setup.py install
> running install
> error: invalid Python installation: unable to open 
> /usr/lib/python2.3/config/Makefile (No such file or directory)
> 

apt-get install python2.3-dev


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


Re: py2exe problem

2006-04-16 Thread bwaha

"Serge Orlov" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bwaha wrote:
> > First time trying to create an executable with py2exe.  I have a small
> > program which makes use of python23 (2.3.5?), wxpython ('2.6.2.1'),
> > matplotlib ('0.83.2'), win32com (latest?), Numeric ('23.7') on Windows
XP &
> > Win2000. The program runs without problem but as an exe it doesn't even
get
> > to showing the GUI.
>
> Do you have more than one wxwindows installed? Check you site-packages.
> Do you follow documentation
> http://wiki.wxpython.org/index.cgi/MultiVersionInstalls ? Seems like
> py2exe picks wrong wxwindows. Insert printing of wx.VERSION and
> wx.PlatformInfo and try to run it packaged and non-packaged.
>
>   Serge
>

Thanks for the suggestion, but I definitely have only one version installed.
In fact I uninstalled it and installed an earlier version (2.5.5.1) to see
if it was specifically wxPython related. No change.



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


sort in Excel

2006-04-16 Thread MK
Hello,

Does anyone knows how can I

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


sort in Excel

2006-04-16 Thread MK
Hello,

Does anyone knows how can I

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


sort in Excel

2006-04-16 Thread MK
Hello,

Does anyone knows how to use the Excel sort function in python?

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


Re: Upgrading and modules

2006-04-16 Thread Brian Elmegaard
"BartlebyScrivener" <[EMAIL PROTECTED]> writes:

> Are you saying you're on Windows?

Yes
> http://www.activestate.com/Products/ActivePython/

> It's a one-click, msi install with everything you need for win32,
> including IDE etc.

I don't it includes every possible module, e.g., py2exe, ctypes,
mysqldb, wxpython...

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with python output redirection

2006-04-16 Thread Fredrik Lundh
Steven D'Aprano wrote:

> So, let me say firstly that I wish the following code to be put into
> the public domain

so you're taking the work by others ("for m in x", "print m", and so on)
and think that by posting it to usenet as if you wrote it yourself, you
can release it into the public domain ?





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


Re: Calling Python from Matlab

2006-04-16 Thread Carl
Kelvie Wong wrote:

> I have a suspicion it is the collaborative effort that is the problem
> here -- I try to use Python whenever possible for
> engineering/numerical analysis, but the established industry standard
> (for most disciplines of engineering) is still MATLAB.
> 
> Although Python is arguably better in most respects, especially being
> a full-blown programming language (and modules such as SciPy and NumPy
> are just great), but it's hard to expect your co-workers to be using
> Python for analysis also.
> 
> On 15 Apr 2006 16:00:08 -0700, Michael Tobis <[EMAIL PROTECTED]> wrote:
>> I'm afraid I can't be very helpful to you, but you could be most
>> helpful to some of us.
>>
>> Can you elaborate on what specifically you found difficult? In some
>> circles Python is regarded as a direct competitor to Matlab. Your
>> preference for Python for "other things than standard mathematical
>> work" in a scientific or engineering context could be most useful if
>> you have some real-world examples.
>>
>> Also, can you elaborate on what (if anything) it is about Matlab that
>> you feel you can't replicate in Python? Are you aware of matplotlib and
>> numpy?
>>
>> thanks
>> mt
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
This is exactly my problem! 

I have to use Matlab at work because it is the language my fellow co-workers
use. At my previous work we used Python as our language of choice. I never
had had to use Matlab because Numeric, numarray, SciPy, etc were already
there. These libraries worked beautifully with Python!

My major problem with Matlab is not the language; it is a quite nice
language, comparable to Python and R. The problem is the lack of libraries
for doing things that are not basic mathematical stuff, such as reading
text from files, handling strings, pickling, etc. When you are used to
Python's large number of high-quality modules you feel disadvantaged being
confined to using only Matlab.

I have learnt that Matlab provides a facility for executing Perl commands
and running Perl scripts, but I have not used it yet. It would have been
nice to have the possibility of mixing Matlab and Python code, by using
inlining, for example!  

One option could be to use Perl to call Python from within Matlab. 

Carl

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


Re: Help with python output redirection

2006-04-16 Thread Robert Kern
Fredrik Lundh wrote:
> Steven D'Aprano wrote:
> 
>>So, let me say firstly that I wish the following code to be put into
>>the public domain
> 
> so you're taking the work by others ("for m in x", "print m", and so on)
> and think that by posting it to usenet as if you wrote it yourself, you
> can release it into the public domain ?

I don't think there's a judge in the world that would think those few characters
are copyrightable by themselves.

-- 
Robert Kern
[EMAIL PROTECTED]

"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: py2exe problem

2006-04-16 Thread Serge Orlov
bwaha wrote:
> Thanks for the suggestion, but I definitely have only one version installed.
> In fact I uninstalled it and installed an earlier version (2.5.5.1) to see
> if it was specifically wxPython related. No change.

Then why don't you try to print what is passed to SetValue in the exe,
just change windows = ['mpival3.py'] in setup.py with console =
['mpival3.py'] and add prints.

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


Re: List operation: Removing an item

2006-04-16 Thread Fulvio
On Sunday 16 April 2006 13:37, Terry Reedy wrote:
>Do you really need the items sorted?

Do you really think he isn't a troll?

See the latest thread on lists end related PEP.
However there's always some good info on your reply (all of those had reply to 
OP).

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


Re: String pattern matching

2006-04-16 Thread Jim Lewis
>You can do this with a regular expression...

I tried the plain RE approach and found it no faster than my
direct-coded version. Anyone have any ideas on how to code this problem
elegantly without RE? My code is long and cumbersome - 200 lines! Speed
is my primary concern but low LOC would be nice of course. The sezman
approach above seems a bit complex.

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


ANN: Pyrex 0.9.4 - LValue Casts are Dead!

2006-04-16 Thread greg
Pyrex 0.9.4 is now available:

   http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

Highlights of this version:

   No more lvalue casts
 I have redesigned the code generator to eliminate the need
 for lvalue casting. This means that Pyrex-generated code
 should now be gcc4-compatible, although I haven't tested
 this. Let me know if you find any remaining lvalue casts;
 they should be fairly easy to fix now.

   C++ compilable
 The generated code should now be compilable as either C
 or C++ without errors (although there may still be
 warnings). However, note that you can still only call
 C++ functions if they have been declared "extern C",
 even if you compile the Pyrex output as C++. I hope to
 introduce some C++ interface features soon.

   And more...
   A slew of other improvements and bug fixes have been
   made, see the CHANGES.txt file in the distribution or
   on the web page.


What is Pyrex?
--

Pyrex is a language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.

--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury,  | Carpe post meridiam! |
Christchurch, New Zealand  | (I'm not a morning person.)  |
[EMAIL PROTECTED]+--+
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keyboard command to break out of infinite loop?

2006-04-16 Thread kodi

BartlebyScrivener wrote:
> Running Python on Win XP.
>
> When running commands with the interpreter, if you get stuck in a while
> loop, is there a keyboard command to break out of it?
>
> Or is the only way out a triple-finger salute and End Task?
> 
> rd



ctrl+c

or ctrl+c+enter

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


Re: PEP 359: The "make" Statement

2006-04-16 Thread Azolex
Steven Bethard wrote:
> Rob Williscroft wrote:
>> I don't know wether this has been suggested or not, but what about def:
>>
>> def namespace ns:
>>   x = 1
>>
>> def type blah(object):
>>   pass
>>
>>   def property x:
>> def get():
>>   return ns.x
> 
> I think that's probably a bad idea because it would make people think 
> that the statement acts like a function definition, when it actually 
> acts like a class definition.

maybe this could be marked with an appropriate decorator ?

@namespace(mytype)
def ns(base1,base2) :
 ...

the decorator could take the function object apart, recover the bases 
arguments, run the code with a referenced local dict...

hum, since in 2.4 exec allows a dict-like object as locals, it should 
even be possible to hack together a pretty concise hierarchical xml 
builder syntax embedded in current python - using neither the 'with' nor 
the 'make' statement, but simply defs !  Note that only the root of the 
(sub)tree  would need to be a decorated "def" since embedded defs could 
then be caught through the locals pseudo-dict.

Looks possible... at a first glance, the one thing that's unclear (to 
me) is how to deal with closure variables. To learn more, my tendency 
would be to launch a challenge :

"Simulate function call and execution using an exec statement, as 
precisely as possible"

I'll repeat that question in another thread...

Best, az.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 359: The "make" Statement

2006-04-16 Thread gangesmaster
?

i really liked it


-tomer

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


Python certification/training

2006-04-16 Thread chrisBrat
Hi,

Are there any certifications that are available for developers learning
Python? Where?

I'm specifically looking for distance/on-line courses or certifications
but welcome any information available. 

Thanks
Chris

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


Re: List operation: Removing an item

2006-04-16 Thread Steven D'Aprano
On Sun, 16 Apr 2006 01:37:44 -0400, Terry Reedy wrote:

> 
> "Miguel E." <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Hi,
>>
>> I've been (self) studying Python for the past two months and I have had
>> no background in OOP whatsoever.
>>
>> I was able to write an interactive program that randomly selects an item
>> from a list. From a Main Menu, the user has the option to add items to
>> an empty list, show the list, run the random selector, and of course
>> quit the program. The program also complains if a user tries to add an
>> item that is already in the list prompting the user to enter another 
>> item.
> 
> Do you really need the items sorted?  I strongly suspect that a set would 
> work better.  Much easier to randomly add, delete, and check membership.

The OP didn't say anything about having the items sorted.

I think he's trying to learn how to use Python, as he says, and
specifically learn about lists at this moment. Telling him to use sets
isn't going to help him learn about lists.


-- 
Steven.

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


Re: List operation: Removing an item

2006-04-16 Thread Steven D'Aprano
On Sun, 16 Apr 2006 19:05:50 +0800, Fulvio wrote:

> On Sunday 16 April 2006 13:37, Terry Reedy wrote:
>>Do you really need the items sorted?
> 
> Do you really think he isn't a troll?

[scratches head]

The OP looks like a beginner trying to experiment with Python as a way of
learning how to program in it. What makes you think he's a troll?


-- 
Steven.

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


Re: sort in Excel

2006-04-16 Thread MK
u do it like this:

from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlApp.Workbooks.Open("D:\python\sortme.csv")
xlApp.Range("A1:C100").Sort(Key1=xlApp.Range("B1"), Order1=2)
xlApp.ActiveWorkbook.Close(SaveChanges=1)
xlApp.Quit()
del xlApp

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


Re: Help with python output redirection

2006-04-16 Thread Steven D'Aprano
On Sun, 16 Apr 2006 12:16:39 +0200, Fredrik Lundh wrote:

> Steven D'Aprano wrote:
> 
>> So, let me say firstly that I wish the following code to be put into
>> the public domain
> 
> so you're taking the work by others ("for m in x", "print m", and so on)
> and think that by posting it to usenet as if you wrote it yourself, you
> can release it into the public domain ?

???

You're joking, right?

Look, I'm not having a good run at the moment telling when folks are being
funny, so if you trying to introduce a note of levity into the discussion,
ha ha I laughed so much my sides burst.

But if you are being serious, and for the benefit of anyone else out there
who doesn't get the joke and thinks there is something of substance to
your claim:

(1) If I didn't already have the copyright to the code, I simply can't
transfer ownership to it or reassign copyright no matter what I say;

(2) If you read my post, I think it is abundantly clear that my intention
was not to claim copyright on it at all;

(3) Only because the Original Poster appeared to be concerned about
copyright on the code I posted, I released it, simply to reassure the OP;

(4) As far as me posting individual Python statements (like for, print
etc.) as if I wrote them myself, that's ludicrous. A writer's copyright on
a work does not imply copyright on the individual words; likewise a
programmer's copyright on a program does not mean he claims copyright on
the language itself.

So, just so there is no misunderstanding:

- I did not write the Python language, I do not have ownership of the
copyright to the Python language, and it is not my intention to transfer
copyright of the Python language (in whole or in part) to the public
domain, even if I were able to, which I am not.

- I do not have copyright on any code not written by me, consequently I'm
not releasing the copyright on any code not written by me.

- I am, however, explicitly releasing from copyright the code written by
me in the earlier message with the subject line "Re: Help with python
output redirection" dated Sat, 15 Apr 2006 12:09:17 +1000, and then
re-posted as quoted text in a message with the same subject line dated
Sun, 16 Apr 2006 11:35:04 +1000.

- In the event that the appropriate laws do not allow me to release from
copyright the code, I offer it to anyone who wants to copy such a trivial
few lines of code into their own work with an unlimited, non-exclusive,
transferable, warranty-less licence.

- None of this is a substitute for paying a lawyer many hundreds of
dollars to be told that no judge is going to rule copyright infringement
for copying such a trivial work, and that this whole exercise was an utter
waste of time.


Sheesh. I have to deal with enough legal waffle at work, I didn't think
I'd be held to such pedantic standards about a trivial four-line piece of
code on Usenet.

Oh, Fredrik, if your intention was to demonstrate just what a PITA overly
strict copyright law is, you're preaching to the converted brother.


-- 
Steven.

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


Re: Help for a complete newbie

2006-04-16 Thread fatal.serpent
There was an extra space before ready. It works otherwise. Use the code
below or just remove the space.
Heres the fixed code:
ready = raw_input("Ready to proceed ? TYPE (y)es or (n)o: ")

if ready  == "y":
print "You are Ready"
else:
print "Try again"
Ralph H. Stoos Jr. wrote:
> All,
>
> I am reading a Python tutorial for complete non-programmers.
>
> The code below is so simple as to be insulting but the assignment of the
> "ready" variable gives a syntax error.
>
> The code reads letter-for-letter like the tutorial states.
>
> Here is a dump.  Can anyone tell me what is wrong?
>
> ***
>
> print " "
> print "This \"autotp\" program will create raw bitmap test pattern images."
> print " "
> print "Please read the information below thoroughly:"
> print " "
> print "1. Graphic files MUST be TIFF images."
> print "2. Images MUST have been ripped though a Nuvera system as a Print
> and Save job"
> print "3. Images should already be named with the desired file name."
> print "4. The Lead Edge and file name should be identified in the image."
> print "5. The name includes the purpose for, resolution of, side, and
> paper size"
> print "6. Images should be rotated to print correctly from Service
> Diagnostics."
> print " "
> print "EXAMPLE: Bypass_BFM_Damage_1200x1200_Letter.tif"
> print " "
>
> # Get the decision if operator is ready
>   ready = raw_input("Ready to proceed ? TYPE (y)es or (n)o: ")
>
>   if ready  == "y":
>   print "You are Ready"
>   else:
>   print "Try again"
>
> OUTPUT from execution
>
>   File "autotp.py", line 21
>  ready = raw_input("Ready to proceed ? TYPE (y)es or (n)o: ")
>  ^
> ***
>
> Please respond to the group and to:  [EMAIL PROTECTED]
> 
> Thanks,
> 
> Ralph

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


Re: Calling Python from Matlab

2006-04-16 Thread AgenteSegreto
I've been a Matlab user for years and have recently started using
Python with matplotlib and NumPy for most of my work.  The only thing I
found that is still lacking is a 3D capability in matplotlib.  I was
trying to visualize a hill climbing algorithm and I couldn't find
anything comparable to Matlab's 'surface', 'mesh', or 'plot3'.  I think
VTK would have done the trick but there's only so much time in the
day...

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


Tkinter

2006-04-16 Thread Jay
I wold like to be able to generate buttons from a list in a file.
How would I go about making each button have a different command,
Lets say make the button print its label instead of print "."

The problem I have is I don't know what the list is going to be until
it is opened or how big so I carnet make a def for each.

And I don't know how to do it with a loop

Thanks

--Code---

from Tkinter import *

class App:
def __init__(self, root):

self.DisplayAreaListsFrame = Frame(root)
self.DisplayAreaListsFrame.pack()

Lists = ["A1","B2","C3","D4"]

for i in Lists:
self.DisplayAreaListButton = Button(
self.DisplayAreaListsFrame,
text=i,
command=self.ListButtonCommand)
self.DisplayAreaListButton.pack(side=LEFT,padx=10)

def ListButtonCommand(self):
print "."

root = Tk()
app = App(root)
root.mainloop()

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


vote

2006-04-16 Thread memlük
http://www.hemalhemsat.com/main/auctiondetail/437717/diger/mezarlariniza_muhendis_eli_degsin.php

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


Using Python To Create An Encrypted Container

2006-04-16 Thread Michael Sperlle
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems
to need changes to the kernel before it can be installed, and I have no
intention of going through whatever hell that would cause.

If I could create a large file that could be encrypted, and maybe add
files to it by appending them and putting in some kind of delimiter
between files, maybe a homemade version of truecrypt could be constructed.

Any idea what it would take?

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


Re: Tkinter

2006-04-16 Thread Fredrik Lundh
"Jay" wrote:

> I wold like to be able to generate buttons from a list in a file.
> How would I go about making each button have a different command,
> Lets say make the button print its label instead of print "."
>
> The problem I have is I don't know what the list is going to be until
> it is opened or how big so I carnet make a def for each.

def is an executable statement, and creates a new function object
everytime it's executed.  if you want a new function for each pass
through a loop, just put the def inside the loop:

> from Tkinter import *
>
> class App:
> def __init__(self, root):
>
> self.DisplayAreaListsFrame = Frame(root)
> self.DisplayAreaListsFrame.pack()
>
> Lists = ["A1","B2","C3","D4"]
>
> for i in Lists:

   def callback(text=i):
   print text

> self.DisplayAreaListButton = Button(
> self.DisplayAreaListsFrame,
> text=i,
> command=callback)
> self.DisplayAreaListButton.pack(side=LEFT,padx=10)
>
> root = Tk()
> app = App(root)
> root.mainloop()

the only think that's a little bit tricky is scoping: you can access all
variables from the __init__ method's scope from inside the callbacks,
but the callbacks will be called after the loop is finished, so the "i"
variable will be set to the *last* list item for all callbacks.

to work around this, you have to explicitly pass the *value* of "i" to
to the callback; the "text=i" part in the above example uses Python's
default argument handling to do exactly that.





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


Re: Using Python To Create An Encrypted Container

2006-04-16 Thread Paul Rubin
Michael Sperlle <[EMAIL PROTECTED]> writes:
> If I could create a large file that could be encrypted, and maybe add
> files to it by appending them and putting in some kind of delimiter
> between files, maybe a homemade version of truecrypt could be constructed.
> Any idea what it would take?

If by container you mean a user-level file system with transparent
encryption, there are a bunch of ways to do it, but it's system
hacking, Python doesn't come into it much.  If you just want an
encrypted archive, then put your files into a normal zip file and
encrypt the zip file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unified web API for CGI and mod_python?

2006-04-16 Thread Tim Chase
>>[EMAIL PROTECTED] cd ~tim/WebStack-1.1.2
>>[EMAIL PROTECTED] python2.3 setup.py install
>>running install
>>error: invalid Python installation: unable to open 
>>/usr/lib/python2.3/config/Makefile (No such file or directory)
> 
> apt-get install python2.3-dev

Worked like a charm, and the WebStack install took place 
uneventfully.  Only took half an hour to download the .deb 
packages over dialup :-/

Thanks for your help!

-tim




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


Re: Python certification/training

2006-04-16 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>Are there any certifications that are available for developers learning
>Python? Where?
>
>I'm specifically looking for distance/on-line courses or certifications
>but welcome any information available.

Question is, what do you want it for?  There is currently no certificate
generally recognized by the Python community.  If you're simply looking
for Python training, there are several options; if you want recognition,
your best option is to make code available to the community.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python To Create An Encrypted Container

2006-04-16 Thread garabik-news-2005-05
Michael Sperlle <[EMAIL PROTECTED]> wrote:
> Is it possible? Bestcrypt can supposedly be set up on linux, but it seems
> to need changes to the kernel before it can be installed, and I have no
> intention of going through whatever hell that would cause.
> 
> If I could create a large file that could be encrypted, and maybe add
> files to it by appending them and putting in some kind of delimiter
> between files, maybe a homemade version of truecrypt could be constructed.
> 
> Any idea what it would take?
> 

you can either use fuse and its python bindings - this is rather trivial
filesystem-wise, of course there are challenges in order to implement
encryption effectively and efficiently (this is what encfs or phonebook
do, but they are written in C)

Or implement encrypted  network block device in python - again, this
should not be _that_ hard.

Or implement either nfs or samba server with transparent encrypted
storage - this is what (again in C) cfs does. If you go the samba way,
it would be even cross-platform - but I have no idea how difficult it
would be to implement a samba server in python.

In all the cases, performance is going to be THE issue.

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter

2006-04-16 Thread Jay
I still dont quite get it, is their sum kind of way you can [def Newdef
+ i()] for example so that the def is different from the string, all
the buttons now have numbers on

If I am not mistaken Fredrik Lundh rote the tutorial Learning to
program (Python) www.freenetpages.co.uk/hp/alan.gauld/   and
www.effbot.org

If this is the same person then thank you for everything I no about
python it seams what ever I try and learn about Python it is always you
who helps or has wrote docs to help Newbie's and well everyone
really.

---code---
 from Tkinter import *

class App:
def __init__(self, root):

self.DisplayAreaListsFrame = Frame(root)
self.DisplayAreaListsFrame.pack()

Lists = ["A1","B2","C3","D4"]
for i in Lists:
def i():
print i
self.DisplayAreaListButton = Button(
self.DisplayAreaListsFrame,
text=i,
command=i)
self.DisplayAreaListButton.pack(side=LEFT,padx=10)



root = Tk()
app = App(root)
root.mainloop()

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


for sale: internetDotComs.com

2006-04-16 Thread internetDotComs.com
  domain for sale:  internetdotcoms.com

  http://www.afternic.com/name.php?id=11866440

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


Re: Python certification/training

2006-04-16 Thread chrisBrat
Hi,

Thanks for the response.

I currently work as a Java developer but I have lots of interest in
Python.

I asked about training/certification because its proved to be a good
way for me to learn in the past.

My aim is not to gain recognition but more to measure my understanding
- a sort of benchmark. I have been so far unable to find any courses
offering training in my country that would not bankrupt me (I live in
South Africa).

Guess I'll work through examples and tutorials on the net.

Thanks
Chris

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


Re: Using Python To Create An Encrypted Container

2006-04-16 Thread Michael Sperlle
On Sun, 16 Apr 2006 08:11:12 -0700, Paul Rubin wrote:

> Michael Sperlle <[EMAIL PROTECTED]> writes:
>> If I could create a large file that could be encrypted, and maybe add
>> files to it by appending them and putting in some kind of delimiter
>> between files, maybe a homemade version of truecrypt could be
>> constructed. Any idea what it would take?
> 
> If by container you mean a user-level file system with transparent
> encryption, there are a bunch of ways to do it, but it's system hacking,
> Python doesn't come into it much.  If you just want an encrypted archive,
> then put your files into a normal zip file and encrypt the zip file.

I've tried that, but the encryption and decryption take a long time
compared to opening/closing the container, once it's made.

The only other thing I can think of is making it non-readable for anyone
except root, but have the feeling that's not too secure.


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


Validate XML against DTD and/or XML Schema?

2006-04-16 Thread Reid Priedhorsky
Hi folks,

I have a need to validate XML files against both DTDs and XML Schema from
the command line.

In an ideal world, I'd be able to do something like:

  $ python validate.py foo.xml

which would then parse and validate foo.xml using the schema or DTD
referenced within it.

What I'm looking for is the contents of validate.py. A Python solution
isn't essential, but I like Python and I'm doing some other light XML
stuff in Python, so I'd prefer it.

I did some Googling, but I'm a little overwhelmed by the quantity and
variety of stuff I found, and I found a lot of stuff that was out of date.
I thought it would be useful to ask here.

Let me know if you have any questions, and thanks very much for any help.

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


Re: Python certification/training

2006-04-16 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>I asked about training/certification because its proved to be a good
>way for me to learn in the past.
>
>My aim is not to gain recognition but more to measure my understanding
>- a sort of benchmark. I have been so far unable to find any courses
>offering training in my country that would not bankrupt me (I live in
>South Africa).

Then may I suggest that you subscribe to the tutor list?  That will give
you a good place to ask questions; as you learn Python, answering other
people's questions will give you a good way to hone your own knowledge.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keyboard command to break out of infinite loop?

2006-04-16 Thread BartlebyScrivener
Thank you, both. I'll put in on a sticky!

rick

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


Re: keyboard command to break out of infinite loop?

2006-04-16 Thread Scott David Daniels
zweistein wrote:
> Try CTRL + C. If it doesn't work, CTRL + Pause/Break should also work
> (if you're running it from the CLI).
> 
> HTH
> 
Note: this will raise a KeyboardInterrupt exception, which you might
inadvertently be catching.  If you have been lazy and written:
 try:
 
 except:
 
You may get to  if the Control-C (or Control-Break) is
processed in the  section.  This is one reason we always
urge people to be specific about the exceptions they expect.  The
following code demonstrates what is happening:

 try:
 response = raw_input('Prompt: ')
 except:
 print 'Got here'

If you run this code and hit Control-C in response to the prompt
(guaranteeing you are inside the try-except block), you will see
a "Got here" printed.  Similarly, you can look for this one exception,
and treat it specially:

 try:
 response = raw_input('Prompt: ')
 except KeyboardInterrupt, error:
 print 'Got here with "%s" (%r)' % (error, error)

Running this and entering Control-C at the prompt will show you
that the exception you get from a KeyboardInterrupt has a reasonable
repr (the result of the %r translation), but its str conversion (the
result of the %s translation) is a zero length string (which is kind
of hard to see in a print).

So, avoid "except:" when catching exceptions, and your life will be
happier.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple parameters in if statement

2006-04-16 Thread John Zenger
Yup, join is better.  The problem with using form.values() is that it 
will break if the HTML changes and adds some sort of new field that this 
function does not care about, or if an attacker introduces bogus fields 
into his query.

John Machin wrote:
> On 16/04/2006 1:43 PM, John Zenger wrote:
> 
>>
>> The other thing I'd recommend is stick that long list of fields in a 
>> list, and then do operations on that list:
>>
>> fields = ['delete_id', 'delete_date', 'delete_purchasetype', 
>> 'delete_price', 'delete_comment']
>>
>> then to see if all those fields are empty:
>>
>> everything = ""
>> for field in fields:
>> everything += form.get(field,"")
> 
> 
> Or everything = "".join(form.get(field, "") for field in fields)
> 
> Somewhat labour-intensive. It appears from the OP's description that no 
> other entries can exist in the dictionary. If this is so, then:
> 
> everything = "".join(form.values())
> 
> but what the user sees on screen isn't necessarily what you get, so:
> 
> everything = "".join(form.values()).strip()
> 
>> if everything == "":
>> print "Absolutely nothing entered!"
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending part of a page as the body of an email

2006-04-16 Thread Jesse Hager
Kun wrote:
> I currently have a python-cgi script that extracts data from a mysql 
> table.  I would like to save this data as a string and send it to a 
> recipient via email.
> 
> I know how to send email using the smtp lib, but what I do not know his 
> how to save a portion of the page as a string.  Any pointers?

#At the top of your CGI script import these
import sys
import StringIO

#Create a StringIO object to hold output
string_io = StringIO.StringIO()
#Save the old sys.stdout so we can go back to it later
old_stdout = sys.stdout

#Normal output goes here



#To start capturing output replace sys.stdout with the StringIO object
sys.stdout = string_io

#Captured output goes here

#To finish capturing
sys.stdout = old_stdout

#To get the captured text from the StringIO object do:
captured_text = string_io.getvalue()

#To output the captured text to the original sys.stdout
#If this is omitted, the captured_text will not be sent to the browser
old_stdout.write(captured_text)

#You can repeat this capturing section several times and the output
#will accumulate in the StringIO object. To clear the contents of the
#StringIO object between sections do:
#string_io.truncate(0)



#More normal output goes here
#Do whatever you want with captured_text here...


#When finished with string_io, close it to free up the memory buffers
string_io.close()


--
Jesse Hager
email = "[EMAIL PROTECTED]".decode("rot13")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 359: The "make" Statement

2006-04-16 Thread Steven Bethard
Tim Hochberg wrote:
> Tim Hochberg wrote:
>> I don't think that's correct. I think that with a suitably designed 
>> HtmlDocument object, the following should be possible:
>>
>> with HtmlDocument("Title") as doc:
>> with doc.element("body"):
>>doc.text("before first h1")
>>with doc.element("h1", style="first"):
>>   doc.text("first h1")
>># I don't understand the point of tail, but you could do that too
>>doc.text("after first h1")
>>with doc.element("h1", style="second"):
>>doc.text("second h1")
>>doc.text("after second h1")
>>
> Here's code to do this. It would be probably be better to use elment 
> tree or some such instead of pushing out the HTML directly, but this 
> should get the idea across (testing using 2.5a1):
[snip]

Thanks, that's great!  If you don't mind, I'm going to steal your code 
for the PEP.  I think it makes a pretty good case against expanding the 
statement semantics to include customizing the dict in which the code is 
executed.

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


Re: Using Python To Create An Encrypted Container

2006-04-16 Thread Heiko Wundram
Am Sonntag 16 April 2006 19:11 schrieb Michael Sperlle:
> The only other thing I can think of is making it non-readable for anyone
> except root, but have the feeling that's not too secure.

Huh? If you don't trust your operating system to correctly validate 
file-permissions for you (on a server, on a client system which can be booted 
by others than you or from which the physical harddisk can be extracted the 
security implications are completely different), you're in absolutely no 
position to even want encryption, because any malicious user can replace your 
encryption code with code of his own, so that it's easily breakable by him.

Of course there are temporary local priviledge escalations (in some 
applications, or even in the kernel of your operating system), but if you 
rely on the operating system to keep your encryption code secure, you might 
as well rely on the operating system to keep your data secure, because that's 
basically the same thing.

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


Re: XML-RPC server via xinetd

2006-04-16 Thread Martin P. Hellwig
Jos Vos wrote:
> Hi,
> 
> I'm trying to figure out how to implement a XML-RPC server that
> is called by xinetd i.s.o. listening on a TCP socket itself.
> 
> I already have implemented a stand-alone XML-RPC server using
> SimpleXMLRPCServer, but I now want something similar, that is
> started via xinetd (i.e. reading/writing via stdin/stdout).
> 
> Any hints or code examples?
> 
> Thanks,
> 

Isn't this just a standard daemon functionality?
So if you could wrap up your program in a daemon like fashion (e.g. 
http://homepage.hispeed.ch/py430/python/daemon.py) and then point the 
xinetd configuration to the right script, it should just work?

Beware that I didn't try this myself yet ;-) though should do in the 
near future so if you could give a head ups on your progress I would 
appreciate it.

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


Re: keyboard command to break out of infinite loop?

2006-04-16 Thread BartlebyScrivener
Thank you, Scott. I'm still learning my exceptions (obviously, or I
wouldn't get stuck in a while loop ;).

That was instructive. On my machine, it is Ctrl + Break that does it.
Ctrl + C doesn't do anything.

What I should really do is figure out roughly how many times the while
loop should run, and then put an outer limit on it, so that it will run
normally as long as it doesn't exceed x, after which it breaks and
says, "Hey, Dummy, you were headed into an infinite loop."

Could be a good exercise.

Thank you again.

rick

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


Re: Python certification/training

2006-04-16 Thread Richard Marsden
Aahz wrote:
> Then may I suggest that you subscribe to the tutor list?  That will give
> you a good place to ask questions; as you learn Python, answering other
> people's questions will give you a good way to hone your own knowledge.


Which is?  :-)



Richard (who might also be interested - in the tutor list, not the 
certification)

-- 
Richard Marsden
Winwaed Software Technology, http://www.winwaed.com
http://www.mapping-tools.com for MapPoint tools and add-ins
Pre-Order MapPoint 2006 now:  http://www.mapping-tools.com/mappoint2006
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiple parameters in if statement

2006-04-16 Thread John Machin
On 17/04/2006 5:13 AM, John Zenger top-posted:
> Yup, join is better.  The problem with using form.values() is that it 
> will break if the HTML changes and adds some sort of new field that this 
> function does not care about, or if an attacker introduces bogus fields 
> into his query.

If one is worried about extra keys introduced by error or malice, then 
one should check for that FIRST, and take appropriate action. Code which 
is concerned with the values attached to the known/valid keys can then 
avoid complications caused by worrying about extra keys.

> 
> John Machin wrote:
>> On 16/04/2006 1:43 PM, John Zenger wrote:
>>
>>>
>>> The other thing I'd recommend is stick that long list of fields in a 
>>> list, and then do operations on that list:
>>>
>>> fields = ['delete_id', 'delete_date', 'delete_purchasetype', 
>>> 'delete_price', 'delete_comment']
>>>
>>> then to see if all those fields are empty:
>>>
>>> everything = ""
>>> for field in fields:
>>> everything += form.get(field,"")
>>
>>
>> Or everything = "".join(form.get(field, "") for field in fields)
>>
>> Somewhat labour-intensive. It appears from the OP's description that 
>> no other entries can exist in the dictionary. If this is so, then:
>>
>> everything = "".join(form.values())
>>
>> but what the user sees on screen isn't necessarily what you get, so:
>>
>> everything = "".join(form.values()).strip()
>>
>>> if everything == "":
>>> print "Absolutely nothing entered!"
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help for a complete newbie

2006-04-16 Thread John Machin
On 17/04/2006 12:22 AM, fatal.serpent top-posted:
> There was an extra space before ready.

Space? Strange. Both Google groups & my newsreader display it as 8 
spaces. I could have sworn it was a tab.

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


Re: XML-RPC server via xinetd

2006-04-16 Thread Jos Vos
On Sun, Apr 16, 2006 at 10:13:19PM +0200, Martin P. Hellwig wrote:

> Isn't this just a standard daemon functionality?

What is "a standard daemon"? :-)

> So if you could wrap up your program in a daemon like fashion (e.g. 
> http://homepage.hispeed.ch/py430/python/daemon.py) and then point the 
> xinetd configuration to the right script, it should just work?

In fact, the standard use *is* a daemon (that is, accepting connections
on a certain port) and I want it to be *not* a daemon.  For the daemon
method I use something similar to "daemonize", but now I want it to
*not* do the binds etc. to listen on a port.

The problem is that the server initialization *requires* a server
address (host, port pair), but I don't see how to tell it to use
the stdin socket (and I'm afraid this is not possible, but I'm not
sure).

-- 
--Jos Vos <[EMAIL PROTECTED]>
--X/OS Experts in Open Systems BV   |   Phone: +31 20 6938364
--Amsterdam, The Netherlands| Fax: +31 20 6948204
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python from Matlab

2006-04-16 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Carl <[EMAIL PROTECTED]> wrote:

>My major problem with Matlab is not the language; it is a quite nice
>language, comparable to Python and R.

Having done a bunch of MATLAB GUI programming for a client a few years 
ago, I would not agree that MATLAB is a "nice" language at all. The 
basic matrix stuff is fine, but all the structure stuff had a definite 
feling of being tacked on. The GUI stuff in particular was very fiddly 
to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Async Sleep?

2006-04-16 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Aleksandar Cikota" <[EMAIL PROTECTED]> wrote:

>How to check this every 10 sec, but that the CPU is free?

Or better still, why not set a notification on the directory, so you're 
woken up every time something happens to it?

Look up the inotify mechanism, which was added in version 2.6.13 of the 
Linux kernel.
-- 
http://mail.python.org/mailman/listinfo/python-list


filling today's date in a form

2006-04-16 Thread Kun
i have a form which takes in inputs for a mysql query. one of the inputs 
is 'date'.  normally, a user has to manually enter a date, but i am 
wondering if there is a way to create a button which would automatically 
insert today's date in the date form field if the user chooses to use 
today's date.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: filling today's date in a form

2006-04-16 Thread Felipe Almeida Lessa
Em Dom, 2006-04-16 às 19:22 -0400, Kun escreveu:
> i have a form 

Which kind of form? Which toolkit?

> which takes in inputs for a mysql query. one of the inputs 
> is 'date'.  normally, a user has to manually enter a date, 

Enter the date in which kind of control?

> but i am 
> wondering if there is a way to create a button which would automatically 
> insert today's date in the date form field if the user chooses to use 
> today's date.

Almost 100% sure that there is, but I can't tell you if or how if you
don't tell us how you are doing what you are doing.

-- 
Felipe.

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

Re: Python certification/training

2006-04-16 Thread Dan Sommers
On Sun, 16 Apr 2006 17:04:21 -0500,
Richard Marsden <[EMAIL PROTECTED]> wrote:

> Aahz wrote:

>> Then may I suggest that you subscribe to the tutor list?  That will
>> give you a good place to ask questions; as you learn Python,
>> answering other people's questions will give you a good way to hone
>> your own knowledge.

> Which is?  :-)

http://mail.python.org/mailman/listinfo/tutor

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validate XML against DTD and/or XML Schema?

2006-04-16 Thread Jim
For DTD's: have you stumbled across:

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/220472

?

Jim

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


Re: List operation: Removing an item

2006-04-16 Thread Terry Reedy

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sun, 16 Apr 2006 01:37:44 -0400, Terry Reedy wrote:
>> Do you really need the items sorted?  I strongly suspect that a set 
>> would
>> work better.  Much easier to randomly add, delete, and check membership.
>
> The OP didn't say anything about having the items sorted.

Which, along with the specification of unique members, is why I questioned 
the wisdom of using a list which is sorted and does allow duplicates.

> I think he's trying to learn how to use Python, as he says, and
> specifically learn about lists at this moment. Telling him to use sets
> isn't going to help him learn about lists.

Learning about how to use any particular type includes learning when to use 
it and just as importantly, when not to use it.  The OP's difficulties seem 
to me to stem from not using the right type.  It would have been a 
disservice to him for nobody to mention that and steer him in a better 
direction.

Terry Jan Reedy



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


PyWeek done

2006-04-16 Thread Carl Banks
If anyone wants a little dose of what Python can do in a week, PyWeek
is done.  All these games were written in one week; there's some real
impressive ones.  No homemade C extensions, either.

http://www.pyweek.org/2/

My entry (Army of Aerojockey) didn't do so well, unfortunately.  Well,
I was aiming pretty high for an individual entry.  I [EMAIL PROTECTED] hate
collision detection.


Carl Banks

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


Re: XML-RPC server via xinetd

2006-04-16 Thread Martin P. Hellwig
Jos Vos wrote:

> 
> The problem is that the server initialization *requires* a server
> address (host, port pair), but I don't see how to tell it to use
> the stdin socket (and I'm afraid this is not possible, but I'm not
> sure).
> 

If I understood it correctly you want the python server bind be 
depending on whatever is configured in xinetd.conf and not be defined in 
the your program itself?

I tested a bit around with my FreeBSD machine but indeed the OS 
environment gives me nothing interesting back, leaving that option out 
but I do can specify command line arguments so you could pick them up 
with sys.argv.

I looked up how you can specify arguments in xinetd and according to 
various resources I filtered out (gotta over these gnu type 
documentation...) that you can use "server_args" in the per service 
configuration to specify arguments.

Although not really elegant it is doable to do an on the fly port binding.

Now I just hope I understood your problem :-)

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


Re: Upgrading and modules

2006-04-16 Thread Lawrence Oluyede
Brian Elmegaard <[EMAIL PROTECTED]> writes:

> I don't it includes every possible module, e.g., py2exe, ctypes,
> mysqldb, wxpython...

Right but since Python doesn't have a full-integrated central packaging
(despite the ongoing Pypi project and Eby's efforts in setuptools) you have to
do it manually :)

How many modules do you really use? It's a matter of minutes. 

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should I learn Python instead?

2006-04-16 Thread Lawrence Oluyede
"fyleow" <[EMAIL PROTECTED]> writes:
> I'm a student/hobbyist programmer interested in creating a web project.

I'm a student too and I've done a little Python web related stuff long ago.

>  It's nothing too complicated, I would like to get data from an RSS
> feed and store that into a database.  I want my website to get the
> information from the database and display parts of it depending on the
> criteria I set.

That's a really easy thing to do. You're lucky because thanks to Mark Pilgrim
we have one of the best RSS/Atom parsing libraries out there:
http://feedparser.org/

It's quite simple:

1 - you parse the feed
2 - you take the data
3 - you display them in your html page with one of the python frameworks
available. 

> I just finished an OO programming class in Java and I thought it would
> be a good idea to do this in C# since ASP.NET makes web applications
> easier than using Java (that's what I've heard anyway).  

It's quite right. ASP.NET is easier than JSP and J2EE stuff but Python is
better to me :)

> I thought it
> would be easy to pick up since the language syntax is very similar but
> I'm getting overwhelmed by the massive class library.  MSDN docs are
> very good and thorough but the language just seems a little unwieldy
> and too verbose.

Yeah they like in that way. A 4+ class library and gigatons of
documents. All is verbose in their static world: documents, books, languages :(

> This is how to access an RSS feed and create an XML document to
> manipulate it.

I know the author of the RSS.NET library and I used it in the past, it can save
you some machinery. But why get a bad language with a good library instead of a
wonderful library and a very good language :) ?

> Is Python easier than C#?  

IMHO yes.

> Can
> someone show how to access an XML document on the web and have it ready
> to be manipulated for comparison?  Any other advice for a newbie?

Start with the examples on the feedparser homepage. Then choose a framework
(Turbogears? CherryPy?) and then it's a matter of _minutes_ to have a HTML page
filled with your data.

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: filling today's date in a form

2006-04-16 Thread Kun
Felipe Almeida Lessa wrote:
> Em Dom, 2006-04-16 às 19:22 -0400, Kun escreveu:
>> i have a form 
> 
> Which kind of form? Which toolkit?
> 
>> which takes in inputs for a mysql query. one of the inputs 
>> is 'date'.  normally, a user has to manually enter a date, 
> 
> Enter the date in which kind of control?
> 
>> but i am 
>> wondering if there is a way to create a button which would automatically 
>> insert today's date in the date form field if the user chooses to use 
>> today's date.
> 
> Almost 100% sure that there is, but I can't tell you if or how if you
> don't tell us how you are doing what you are doing.
> 
Form is an html form called by a python cgi file using fieldstorage.

Date as in '2006-04-16'... is that what you meant by control?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: py2exe problem

2006-04-16 Thread bwaha

"Serge Orlov" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> bwaha wrote:
> > Thanks for the suggestion, but I definitely have only one version
installed.
> > In fact I uninstalled it and installed an earlier version (2.5.5.1) to
see
> > if it was specifically wxPython related. No change.
>
> Then why don't you try to print what is passed to SetValue in the exe,
> just change windows = ['mpival3.py'] in setup.py with console =
> ['mpival3.py'] and add prints.
>

Thanks. Turned out to be user error. I was trying to SetValue(None).


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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-16 Thread Aahz
In article <[EMAIL PROTECTED]>,
Petr Prikryl <[EMAIL PROTECTED]> wrote:
>"Aahz" wrote...
>> Bruno Desthuilliers wrote:
>>>Aahz a écrit :

 Classic classes are *NOT* deprecated.
>>>
>>>Perhaps not *officially* yet...
>>
>> Not even unofficially.  The point at which we have deprecation is when
>> PEP8 gets changed to say that new-style classes are required for
>> contributions.
>
>My question: Could the old classes be treated in a new Python treated
>as new classes with "implicit" base object? (I know the Zen... ;-)
>
>Example: I use usually a very simple classes. When I add "(object)" to
>my class definitions, the code continues to works fine -- plus I have
>new features to use.  Why this cannot be done automatically? What could
>be broken in the old code if it was threated so?

Method resolution order is the primary up-front difference, but
introspective code can also have problems.  If you're tired of adding
"(object)", put

__metaclass__ = type

at the top of your modules.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"
-- 
http://mail.python.org/mailman/listinfo/python-list

Decode html, or is it unicode, how?

2006-04-16 Thread brandon.mcginty
Hi All,
I've done a bunch of searching in google and in python's help, but,
I haven't found any function to decode a string like:
Refresh! (ihenvyr)
In to plain english.
I'd also looked for the urldecode function in urllib, but that had been
deprecated.
If anyone here can give me a hand, I'd aprishiate it; it's probably very
simple, but...

Thx,

--
Brandon McGinty
Feel free to contact me for technical support, or just to chat; I always
have time to talk and help, and an open ear.
Email:[EMAIL PROTECTED]
Skype:brandon.mcginty
Msn:[EMAIL PROTECTED]
Aim:brandonmcginty (Not currently available.)
Cell:(480)-202-5790 (Weekends and nights only, please.)
"Kindness is a language that the deaf can hear and the blind can see."
Mark Twain

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.4.1/313 - Release Date: 4/15/2006
 

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


passing string from one file to another

2006-04-16 Thread Kun
I have a python-cgi form whose sole purpose is to email.

It has the fields 'to', 'from', 'subject', 'body', etc. and if the user 
fills them out and clicks submit, it will invoke another file called 
mail.py which uses smtplib to send the message.

This works fine but instead of typing in a 'body', i would like the 
initial python program to just send a string as the body of the email. 
now normally i'd just set the msg in the mail.py file equal to the 
string, however, i do not know how to link a string from another python 
file to the mail.py file.

does anyone know a solution to this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: passing string from one file to another

2006-04-16 Thread Kun
Kun wrote:
> I have a python-cgi form whose sole purpose is to email.
> 
> It has the fields 'to', 'from', 'subject', 'body', etc. and if the user 
> fills them out and clicks submit, it will invoke another file called 
> mail.py which uses smtplib to send the message.
> 
> This works fine but instead of typing in a 'body', i would like the 
> initial python program to just send a string as the body of the email. 
> now normally i'd just set the msg in the mail.py file equal to the 
> string, however, i do not know how to link a string from another python 
> file to the mail.py file.
> 
> does anyone know a solution to this?

i am aware that i could write the string to a text file and invoke it 
with the second python program, however, unfortunately i do not have 
write permission on the server i am working with, thus we need to find 
some other way...

your help would be greatly appreciated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-16 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote:
   ...
> >Example: I use usually a very simple classes. When I add "(object)" to
> >my class definitions, the code continues to works fine -- plus I have
> >new features to use.  Why this cannot be done automatically? What could
> >be broken in the old code if it was threated so?
> 
> Method resolution order is the primary up-front difference, but
> introspective code can also have problems.  If you're tired of adding

The crucial difference between the old-style classes and the new ones is
about how Python lookups special methods.  On an instance of an
old-style class, the lookup is on the instance itself:

>>> class old: pass
... 
>>> o=old()
>>> o.__str__=lambda:'zap'
>>> print o
zap

while on new-style classes, the lookup is ONLY on the class:

>>> class new(object): pass
... 
>>> n=new()
>>> n.__str__=lambda:'zap'
>>> print n
<__main__.new object at 0x51a4b0>


The change is in fact a very important improvement, but it badly breaks
backwards compatibility, which explains why it can't be applied
automatically (within the 2.* line).


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


Re: passing string from one file to another

2006-04-16 Thread I V
Kun wrote:
> This works fine but instead of typing in a 'body', i would like the
> initial python program to just send a string as the body of the email.
> now normally i'd just set the msg in the mail.py file equal to the
> string, however, i do not know how to link a string from another python
> file to the mail.py file.

Where does mail.py get the body from at the moment? And how are you
invoking mail.py? The obvious would be to import mail.py and call a
function in it; then, you would just need to change the string you pass
to the function. But presumably that's not how you've got it set up or
you wouldn't be asking the question. If you can explain a bit more how
your program works that would be helpful, maybe post an exerpt of the
code that shows where mail.py gets invoked from the main program, and
the bit of mail.py that accesses the body that gets sent.

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


locale, format monetary values

2006-04-16 Thread Rares Vernica
Hi,

Can I use locale to format monetary values? If yes, how? If no, is there 
something I can use?

E.g.,
I have 1 and I want to get "$10,000".

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


Re: passing string from one file to another

2006-04-16 Thread Kun
I V wrote:
> Kun wrote:
>> This works fine but instead of typing in a 'body', i would like the
>> initial python program to just send a string as the body of the email.
>> now normally i'd just set the msg in the mail.py file equal to the
>> string, however, i do not know how to link a string from another python
>> file to the mail.py file.
> 
> Where does mail.py get the body from at the moment? And how are you
> invoking mail.py? The obvious would be to import mail.py and call a
> function in it; then, you would just need to change the string you pass
> to the function. But presumably that's not how you've got it set up or
> you wouldn't be asking the question. If you can explain a bit more how
> your program works that would be helpful, maybe post an exerpt of the
> code that shows where mail.py gets invoked from the main program, and
> the bit of mail.py that accesses the body that gets sent.
> 
mail currently gets the body from an input box.

this is where mail.py gets invoked:



Email Results




SMTP Server:


Username:


Password:


From:


To:


Subject:


Message:



"""






this is mail.py




#!/usr/bin/env python
import cgi
import smtplib
import os
import sys
import urllib
import re
from email.MIMEText import MIMEText

print "Content-type: text/html\n"

form = cgi.FieldStorage() #Initializes the form dictionary to take data 
from html form
key = [ 'SMTP Server', 'Username', 'Password', 'From', 'To', 'Subject', 
'Message' ]

def get(form, key):
 if form.has_key(key):
 return form[key].value
 else:
 return ""

if get(form, "SMTP Server") or get(form, "Username") or get(form, 
"Password") or get(form, "From") or get(form, "To") or get(form, 
"Subject") or get(form, "Message"):
 print ''
else:
 print 'Error: You did not enter any Email parameters'
 print ''
 print 'Email Confirmation 
PageYour email has been sent."""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: passing string from one file to another

2006-04-16 Thread I V
Kun wrote:
> mail currently gets the body from an input box.
>
> this is where mail.py gets invoked:

OK, I'm a bit confused. Where is the "initial python program" in all
this? You seem to have an one python program (mail.py) and an HTML
form. As it stands, I don't see why you can't change mail.py so that it
refers to your string instead of msg.as_string() .

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


any update to this?

2006-04-16 Thread micklee74
hi
i was looking at this :
http://www.python.org/doc/essays/comparisons.html
on comparisons of python and other languages? are there any updates to
this doc? or is there
other reliable source for such comparison elsewhere? thanks

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


Re: passing string from one file to another

2006-04-16 Thread Kun
I V wrote:
> Kun wrote:
>> mail currently gets the body from an input box.
>>
>> this is where mail.py gets invoked:
> 
> OK, I'm a bit confused. Where is the "initial python program" in all
> this? You seem to have an one python program (mail.py) and an HTML
> form. As it stands, I don't see why you can't change mail.py so that it
> refers to your string instead of msg.as_string() .
> 
the html i pasted is part of a python-cgi file that is the 'initial' 
file. i can't just tell mail.py to use the string because the string is 
defined in the first python profile, not mail.py.
-- 
http://mail.python.org/mailman/listinfo/python-list


attaching an excel file using MIME in smtp

2006-04-16 Thread Kun
does anyone know how to attach an excel file to send out using smtplib 
and MIME?
-- 
http://mail.python.org/mailman/listinfo/python-list