Newby Q: nested classes, access of upper method

2004-12-03 Thread Gregor Horvath
Hello,
class A(self):
  def A1():
pass
class B(self):
  def B1():
#
#***  How can I access A1 here ***
#
self.A1() # doesnet work because self references to  B
self.self.A1() #doesnt work either
Renanimg class B(self1): doesnt work either because self is not bound.
How can I access a method of a "upper" class?
--
Greg

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


Re: debian python2.4

2004-12-03 Thread Ganesan R
> "Marcos" == Marcos Dione <[EMAIL PROTECTED]> writes:

> On Fri, Dec 03, 2004 at 08:57:46PM +0530, km wrote:
>> 
>> Hi all,
>> is there a debian binary of python2.4 ? 

> well, 2.4 cvs is in since a couple of weeks in unstable. release will come
> up soon I guess.

2.4c1 has already made it into sarge. 2.4 has been already uploaded to
debian unstable, give it another week to make it into sarge.

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


Quixote+Nevow+LivePage

2004-12-03 Thread Mir Nazim
Hi

I am a PHP developer and in trying to get a better tool for developing
web apps, I have been strugling with zope for past few months and
still could not get anything useful work up and going. I really felt
that "Z" shaped learning curve. Yesterday I was looking at quixote. I
was surprized how simple it is. I think quiote gives the power without
getting into the way. And in just a few hours I had quite a good
understanding of framework and actually got something up and working
(http://www.quixote.ca/learn/1). I feel  quixote is the simplest way
to develop powerful web apps. I needed a simple and powerfull web
framework to develop web apps that are NOT content oriented and where
mostly GUI clients have ruled. And I think quixote is just the tool
for me.

I also came across nevow. Its is also good, rather very good.
Especially Live Page is really cool idea. It really help separate
logic and presentation and is simpler than MVC thing that I could
never get a nack of.

Now I have three questions:

Q1) Is it possibe to use "Nevow + LivePage + Quixote" together in a
web app. Live Page is really important for me as I am not into content
oriented web apps.

Q2) Is is nessary that LivePage only with Twisted or can work with any
web server like Apache.

Q3) I cannot understand how to get quixote up and working under Apache
using mod_python, FastCGI, SCGI (I have used only mod_php). A link to
a tutorial will be good.

I saw a paper A. M. Kuchling (http://www.amk.ca/talks/quixote/) that
said that nevow can be used with quixote but it did not mention
anything of LivePage.

Please provide comments, Pros and Cons of the aproach. Links to
relevent articles and tutorials are really appreciated

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


Help me asap!!

2004-12-03 Thread the_proud_family

HELP ME PLEASE!!
I can't get the ball to go up right side and then I need it to turn 
around and keep turning until velocity=0 I have been at it for the 
past 2 weeks now i give up and call for help. Please if anyone can 
gide me through i will be so grateful!! I have pasted my code below








from cmath import *
from visual import *

floor1 = box(length=10, height=0.5, width=4, color=color.blue)
floor1.pos = (-6,4,0)
floor1.axis= (5,-5,0)

floor2 = box(length=10, height=0.5, width=4, color=color.blue)
floor2.pos = (6,4,0)
floor2.axis= (-5,-5,0)

floor3 = box(length=7, height=0.5, width=4, color=color.blue)
floor3.pos = (0,1.25,0)

ball= sphere(radius=0.5, color=color.red)
ball.pos=(-8.6,7.5,0)
m=3. #kg
angle=asin(3.6/5.)#radians
g=-9.8
mu=.2
N=m*g*cos(angle)
F=m*g*sin(angle)
f=mu*N
lax=(-N*sin(angle)+f*cos(angle))/m
lay=(-N*cos(angle)-f*sin(angle)+m*g)/m
rax=(+N*sin(angle)+f*cos(angle))/m
ray=(-N*cos(angle)-f*sin(angle)+m*g)/m
ds=0.01
dt=0.01
vx=lax*dt
vy=lay*dt
ball.velocity=vector(vx,vy,0)

#print a

while 1:
rate(100)
ball.velocity.x=ball.velocity.x+lax*dt
ball.velocity.y=ball.velocity.y+lay*dt
ball.pos=ball.pos+ball.velocity*dt
if ball.x>-3.5 and ball.x<=3.5:
vx=sqrt(2*(-g*ball.y+0.5*(vx**2+vy**2)-f*ds))
ball.velocity.x=ball.velocity.x+mu*g*dt
ball.velocity.y=0
ball.pos=ball.pos+ball.velocity*dt
if ball.x>3.5 and ball.x<8.6:
vx=vx*cos(angle)
vy=sqrt(2/m*(m*-g*ball.y-f*ds))
#print vy
vy=vy*sin(angle)
#print vy
ball.velocity.x=ball.velocity.x+rax*dt
ball.velocity.y=ball.velocity.y+ray*dt
ball.pos=ball.pos+ball.velocity*dt
#print ball.pos






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


Re: Help With Hiring Python Developers

2004-12-03 Thread William Park
fuego <[EMAIL PROTECTED]> wrote:
> My company (http://primedia.com/divisions/businessinformation/) has
> two job openings that we're having a heckuva time filling.  We've
> posted at Monster, Dice, jobs.perl.org and python.jobmart.com.  Can
> anyone advise other job boards that might be helpful?  Also, feel free
> to have a look at the job description and let me know if there is
> anything that we're missing.  This is the first time we've recruited
> specifically for these Python and Zope, as we've had internal
> advocates who have brought its use to critical mass.
> http://jobs.primediabusiness.com/ar/internal_programmer_analyst/index.htm
> 
> Thanks in advance!

You are not being realistic.  
- "email marketing" means spams.
- "Perl and/or Python" and " "Zope and Plone" indicate that you
  don't know what you are doing, so you're simply listing what any
  clueless HR would be doing.
- Manhattan, New York is expensive place to live in, even you're
  paying Manhattan dollar.

Instead of listing what I should know, why don't you list what I would
be doing?  That is, what problems do you need to solve?

Yours truly,
-- 
William Park <[EMAIL PROTECTED]>
Open Geometry Consulting
Linux solution for data processing. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread rakanishu
I started with the official tutorial, then Dive Into Python, followed
by Learning Python. I also regularly read the python-tutor mail list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Peter Hansen
Jive wrote:
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
. You might consider
asking on the python-win32 list, which is more specifically directed at
Mark Hammond's stuff.
Okay.  How do I find the python-win32 list?  It's not a newsgroup,
apparently.
What happened when you typed "python-win32 list" into Google?
Was it broken at the time?  ;-)
http://mail.python.org/mailman/listinfo/python-win32
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help With Hiring Python Developers

2004-12-03 Thread Ed Leafe
On Dec 1, 2004, at 12:18 PM, Bill McClain wrote:
My company (http://primedia.com/divisions/businessinformation/) has
two job openings that we're having a heckuva time filling.
Allow offsite workers and you'll have all the candidates you want.
	Exactly. I'm 5 hours away in Rochester, NY, and might be interested in 
the job, but man, that commute would be a pain!  ;-)

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: debian python2.4

2004-12-03 Thread Marcos Dione
On Fri, Dec 03, 2004 at 08:57:46PM +0530, km wrote:
> 
> Hi all,
> is there a debian binary of python2.4 ? 

well, 2.4 cvs is in since a couple of weeks in unstable. release will come
up soon I guess.

-- 
(Not so) Random fortune:
sos fanático del fútbol? añorás el prode? http://ega.zidev.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace string except inside quotes?

2004-12-03 Thread Raymond Hettinger
<[EMAIL PROTECTED]> wrote > The code
>
> for text in open("file.txt","r"):
> print text.replace("foo","bar")[:-1]
>
> replaces 'foo' with 'bar' in a file, but how do I avoid changing text
> inside single or double quotes? For making changes to Python code, I
> would also like to avoid changing text in comments, either the '#' or
> '""" ... """' kind.

The source for the tokenize module covers all these bases.


Raymond Hettinger


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


Re: Need help on program!!!

2004-12-03 Thread Dan Perl

"Miklós P" <[EMAIL PROTECTED]> 
wrote in message news:[EMAIL PROTECTED]
>
> "Dan Perl" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>>
>> "Hopefully" for whom?  For us, who may have to work with him someday or
> use
>> a product that he developed?  Most of us here have been students (or 
>> still
>> are) and may sympathize with the OP, but personally I have been also a TA
> so
>> I have seen the other side and that's where my sympathy lies now.
>
> To me, it's my benignity towards the OP rather than my sympathy to the
> TAs...
> That's why I find the greedy guy's offer immoral.

I'm not sure what you mean by "benignity" here, but I think I agree with 
you.  Sympathy for TAs is not really my reason for how I feel towards 
someone cheating on their assignment.  I was just looking for something to 
oppose sympathy for a student (assuming that sympathy was the only possible 
reason to give him the solution).  I guess that is not the best argument I 
could have made.

Dan

> Best regards,
>  Miklós
>
> 


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


Re: Need help on program!!!

2004-12-03 Thread Miklós P

"Brad Tilley" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> elif first in (2,3,7):
>
> I think you mean 'elif first in (2,3,12):'
>
Seems you've grown out of school..  So why make the little rascal even
lazier? :-\

M.




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


Re: Need help on program!!!

2004-12-03 Thread Brad Tilley
Max M wrote:
Dan Perl wrote:
That was also my impression.  Even the description of the problem 
looks like it's just copied from the assignment, so probably didn't 
even take the time to restate the problem in his own words.

But we're speculating.  Either way, this is not a normal request: "I 
need a program to do this, plz help!"  To the OP: you can't seriously 
expect us to actually write the program for you, what kind of help are 
you looking for?

This?
# -*- coding: latin-1 -*-
"""
  a.. Play a dice game of Craps using a random number generator to simulate
the roll of the dice, the code for the rolling of the dice should take 
place
in a user written module named rolldice.

  b.. The rules of the game are as follows:
a.. 1st roll, a score of 7 or 11 wins.
b.. 1st roll, a score of 2, 3, or 12 loses.
c.. 1st roll, any number other than those listed above becomes the goal
number, you must keep rolling until you roll the goal number again.  If a 7
is rolled before you goal number, you lose.
"""
import random
def rolldice():
dice1, dice2 = random.randint(1,6), random.randint(1,6)
print dice1, dice2
return dice1, dice2
first1, first2 = rolldice()
first = first1, first2
roll = 1
if first in (7, 11):
print 'Congratulations, you win in roll %s' % roll
elif first in (2,3,7):
I think you mean 'elif first in (2,3,12):'
print 'Too bad, you loose in roll %s' % roll
result = 'draw'
while result == 'draw':
dice1, dice2 = rolldice()
roll += 1
if dice1 + dice2 == 7:
print 'Too bad, you loose in roll %s' % roll
result = None
elif (dice1, dice2) == (first1, first2):
print 'Congratulations, you win in roll %s' % roll
result = None
Hopefully his teacher doesn't know about Google, or he can be expelled 
from school for using it.

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


Re: Need help on program!!!

2004-12-03 Thread Miklós P

"Dan Perl" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Hopefully" for whom?  For us, who may have to work with him someday or
use
> a product that he developed?  Most of us here have been students (or still
> are) and may sympathize with the OP, but personally I have been also a TA
so
> I have seen the other side and that's where my sympathy lies now.
>
> Dan
>

To me, it's my benignity towards the OP rather than my sympathy to the
TAs...
That's why I find the greedy guy's offer immoral.

Best regards,
  Miklós


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


Re: Need help on program!!!

2004-12-03 Thread Brad Tilley
Darth Haggis wrote:
I need help writing a program
You are to write a python program to accomplish the following:

  a.. Play a dice game of Craps using a random number generator to simulate
the roll of the dice, the code for the rolling of the dice should take place
in a user written module named rolldice.
  b.. The rules of the game are as follows:
a.. 1st roll, a score of 7 or 11 wins.
b.. 1st roll, a score of 2, 3, or 12 loses.
c.. 1st roll, any number other than those listed above becomes the goal
number, you must keep rolling until you roll the goal number again.  If a 7
is rolled before you goal number, you lose.
Make the game continuous, until you tell it to stop.  You can bet the same
amount, or change you bet after each win or loss.  Print the results of each
roll and the running total of winnings or loses.

plz help!!!
Here's everything *except* the betting part. I don't gamble ;)
import random
class rolldice:
def first(self):
win = [7,11]
lose = [2,3,12]
x = random.randint(1,6)
y = random.randint(1,6)
z = x+y
print x, "+", y, "=", z
if z in win:
print "You won on the first roll!!!"
return 0
elif z in lose:
print "You lost on the first roll!!!"
return 0
else:
return z
def second(self, goal):
if goal > 0:
lose = 7
print "The goal number is:", goal
while True:
x = random.randint(1,6)
y = random.randint(1,6)
z = x+y
print x, "+", y, "=", z
if z == lose:
print "You lost!!!"
return 0
elif z == goal:
print "You won!!!"
return z
else:
continue
play = rolldice()
play.second(play.first())
--
http://mail.python.org/mailman/listinfo/python-list


Same-O with ActiveState 2.3.4

2004-12-03 Thread Jive
I installed ActivePython2.3.  It does the same thing.

I am wondering if I have a corrupted MS Windows DLL somewhere.  If so, is
there any chance I can figure out which one it is?

Jive


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


Re: pythonwin broke

2004-12-03 Thread Jive
Do an experiment for me.  Open Pythonwin from the start menu.  Use the FILE
menu to open a .py file.  Now try to close the window you just opened using
the X button in the upper right.  Did it close?  Try closing Pythonwin using
its X button.



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


Re: Pythonic use of CSV module to skip headers?

2004-12-03 Thread Skip Montanaro

Ramon> I'm using the csv module to parse a tab-delimited file and
Ramon> wondered whether there was a more elegant way to skip an possible
Ramon> header line.

Assuming the header line has descriptive titles, I prefer the DictReader
class.  Unfortunately, it requires you to specify the titles in its
constructor.  My usual idiom is the following:

f = open(filename, "rb")# don't forget the 'b'!
reader = csv.reader(f)
titles = reader.next()
reader = csv.DictReader(f, titles)
for row in reader:
...

The advantage of the DictReader class is that you get dictionaries keyed by
the titles instead of tuples.  The code to manipulate them is more readable
and insensitive to changes in the order of the columns.  On the down side,
if the titles aren't always named the same you lose.

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


Re: pythonwin broke

2004-12-03 Thread Jean Brouwers

Well, we made several attempts to install Python 2.4 with a number of
extension packages on Windows XP and used the binaries from the Python
site, not ActivePython.

Previous to 2.4,  we did have several versions of Python installed on
Windows XP without any problem.  We installed 2.4 as usual in a
separate directory under Program Files.  But there were several
problems getting the 2.4 exe and IDLE started, in addition to issues
with some extensions.  Plus 2.3.4 could not be started any longer.

Uninstalling 2.4 did not quite work and *may* have broken the existing
2.3.4 installation.  Uninstalling and reinstalling that failed also,
until we manually cleaned up the Registry and StartUp folder.

As I mentioned, we did not investigate the 2.4 problem any further
since getting 2.3.4 back up and running was more critical than 2.4 due
to other problems with the extensions on 2.4.

Once all extensions exist for 2.4 we will try again.  And maybe, we
should use the ActivePython builds then ;-)

/Jean Brouwers
 
PS) We had no problem with Python 2.4 or any extensions on Lunix. 
Everything works fine there and all our Python code runs unmodified on
both 2.3 and 2.4 with extensions, without any failure or glitch.  The
difference *may* be that we rebuild the distribution on Linux but not
on Windows.



In article <[EMAIL PROTECTED]>, Trent
Mick <[EMAIL PROTECTED]> wrote:

> Jean Brouwers wrote:
> > PPS) It looks like Python 2.4 and Python 2.3 can not co-exist (in
> > different folders under Program Files) but we did not investigate that
> > any further.
> 
> That's not true. I have every version of Python back to 2.0 installed 
> and all running fine on my system. Obviously you can only have one of 
> your Python installations first on your PATH (and hence the one that 
> gets run by simply typing "python"). Also, you can only have one of you 
> Python installations registered as the default handler for .py files 
> (and hence the one that gets run by simple double-clicking on a .py file 
> in explorer or running a Python script without the extension from the 
> command line).
> 
> It is also possible that there is some little installer bug or detail on 
>   your environment that is causing the problem. You could try 
> ActivePython. I regularly install and uninstall ActivePython 2.3 and 2.4 
> installers and both installs are still working fine.
> 
> Cheers,
> Trent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Jive

"Jean Brouwers" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> We just went through a similar install-uninstall-reinstall cycle with
> Python 2.4 and 2.3 on Windows XP SP2.  Just uninstalling 2.4 and
> reinstalling 2.3 was not sufficient.
>
> It took several attempts to get things back to the original 2.3
> configuration.  After unininstalling both, we deleted all Python
> related entries in the Registry and in the StartUp folder.  Only after
> that did the reinstalled 2.3 plus extensions work fine again.

I've done that, but without success.  Which versions of 2.3 and Pythonwin
did you use?

Jive


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


Re: Need help on program!!!

2004-12-03 Thread Max M
Dan Perl wrote:
"Max M" <[EMAIL PROTECTED]> wrote in message 

Most of us here have been students (or still 
are) and may sympathize with the OP, but personally I have been also a TA so 
I have seen the other side and that's where my sympathy lies now.
My reply was a joke... My normal response has allways been "why should 
we do your homework for you,"

So I just turned it upside down. "Naturally I will do homework for 
random users on usenet. here it is."

I simply found the idea of asking for homework cheats on usenet, where 
it can be traced very easily... well not very clever.

> "Hopefully" for whom?  For us, who may have to work with him someday 
or use
> a product that he developed?

I have a feeling that this guy has a future in IT. He definitely has 
management potential.

--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Jive

"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>. You might consider
> asking on the python-win32 list, which is more specifically directed at
> Mark Hammond's stuff.

Okay.  How do I find the python-win32 list?  It's not a newsgroup,
apparently.



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


pythonwin still broke

2004-12-03 Thread Jive
I uninstalled Python and Pythonwin.  I verified that there was nothing left
in the registry or the startup folder.  I reinstalled Python using
Python-2.3.4.exe and Pythonwin using win32all-163.exe.

It's still broke.

The shortcut in the startup folder says

Target: C:\Python23\Pythonwin.exe
Start in: C:\Python23\lib\site-packages

When I open Pythonwin that way, once I open a file from the File menu, the
menu buttons on the new window and on the main Pythonwin frame become
inoperable.

I can keep that from happening by changing the Target to
C:\Python23\lib\site-packages\pythonwin\start_pythonwin.pyw.  (Just a wild
guess on my part.)  But then there's a different problem.  When I try to run
a module, I get the message,


Traceback (most recent call last):
  File
"C:\PYTHON23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
line 35, in _GetCurrentDebugger
_CheckNeedGUI()
  File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
line 21, in _CheckNeedGUI
pywin.framework.app.CreateDefaultGUI(dbgpyapp.DebuggerPythonApp)
  File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\framework\app.py",
line 392, in CreateDefaultGUI
appClass().InitInstance()
  File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\debugger\dbgpyapp.py",
line 33, in InitInstance
win32ui.LoadStdProfileSettings(numMRU)
win32ui: The profile settings have already been loaded.


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


Re: Semaphore or what should I use?

2004-12-03 Thread Josiah Carlson

Pierre Barbier de Reuille <[EMAIL PROTECTED]> wrote:
> 
> Ville Vainio a écrit :
> >>"Bastian" == Bastian Hammer <[EMAIL PROTECTED]> writes:
> > 
> > 
> > Bastian> Now I have to make sure, that both threads are
> > Bastian> synchronal, 1 thread edits something and the other is
> > Bastian> blocked until the first thread is ready.
> > 
> > Bastian> Isn´t it a good idea to do this with a semaphore?
> > 
> > Semaphore will do, but this is a classical use case for
> > threading.Lock.
> > 
> > There should be lots of stuff regarding locks (or more googleably,
> > "mutexes") on the net.
> > 
> 
> I don't agree. Mutexes (or locks) are best suited for critical sections 
> (ie. sections that cannot be run by many thread at the same time). The 
> kind of synchonisation Bastian want is not really semaphore either but 
> more event. This python "Event" object is described in the section 7.5.5 
> of the documentation of Python 2.3. There is no example, but I think 
> Event are quite strait forward : you creates it, then some thread block, 
> waiting the event to occure while some other thread execute until it set 
> the event, allowing the blocked thread to go on its own execution :)

You can agree or disagree as much as you want.  Fundamentally, they are
all equivalent.

The only thing that makes mutex 'special' is that one can have an
optional 'call this function with this argument when it gets the lock',
but that can be implemented with a standard Lock, Condition, Event,
Semaphore, etc.


 - Josiah

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


Re: Need help on program!!!

2004-12-03 Thread Brad Tilley
Grant Edwards wrote:
On 2004-12-03, Max M <[EMAIL PROTECTED]> wrote:

That was also my impression.  Even the description of the
problem looks like it's just copied from the assignment, so
probably didn't even take the time to restate the problem in
his own words.

[...]

Hopefully his teacher doesn't know about Google, or he can be
expelled from school for using it.

And there's always the chance the somebody intentionally posted
a wrong answer just to teach somebody a lesson.  I'm not
accusing Max of this, but I've seen it done in the past.
Perhaps Max teaches the class ;)
--
http://mail.python.org/mailman/listinfo/python-list


why no python setup.py uninstall?

2004-12-03 Thread Alia Khouri
If the cannonical way to install a python app is

   python setup.py install

one would expect the following to uninstall it

   python setup.py uninstall

However, distutils doesn't automatically take care of that for you. 

Is this by design? Or is this something that could/should be addressed
in a future version of distutils?

The reason this came up for me is that I have a scheduled script that
downloads the cvs/svn versions of certain python apps (w/extensions),
and then builds and installs them to site-packages automatically by
'python setup.py install'. Just to be extra clean about it, I would
prefer to uninstall first, and then install.


AK


PS: I also have to manually uninstall apps from Mac OS X panther:
searching for .plists etc. I wonder if that was deliberate or
otherwise too... hmm...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Nick Coghlan
Steven Bethard wrote:
Mel Wilson wrote:
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
I believe what Peter Otten was pointing out is that calling __eq__ is
not the same as using ==, presumably because the code for == checks the
types of the two objects and returns False if they're different before
the __eq__ code ever gets called.

Doesn't seem to:
[snip]
Check his example:
http://mail.python.org/pipermail/python-list/2004-November/252660.html
I suspect that example is due to the rule that "A op B" can be passed to any of 
the following, depending on the operator and the types of A and B:

A.__op__(B)
B.__op__(A)
B.__rop__(A)
The latter two get invoked when B is a proper subclass of A (using 'op' for 
commutative operations, and 'rop' for potentially non-commutative ones). This is 
so that subclasses can interact with parent classes correctly.

So, in Steven's original code, B.__eq__(A) was invoked, and returned False 
(since A was the parent class of B, not a subclass).

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-03 Thread Josiah Carlson

Donnal Walter <[EMAIL PROTECTED]> wrote:
> 
> Several months ago I tried using the telnet module (on Windows XP) to 
> communicate with a proprietary host on our network. This was 
> unsuccessful due to problems with "option negotiation", and I gave up on 
> the project for a while. I still have need for this, however, so I 
> recently started thinking about alternatives. I suppose I could dig deep 
> enough into option negotiation to use the socket module (with telnet as 
> a guide), but I am hoping to find a way to use fewer synapses.
> 
> Using the Windows C:> prompt (cmd.exe) I can telnet into this host with 
> no problems (the Windows telnet client performs option negotiation just 
> fine). Is there a straightforward way of using os.popen() (or os.fork() 
> or os.exec*() or os.wait*()) to connect to the host from Python via the 
> Windows telnet client?

I am sure it is possible with a little bit of pywin32 business.  You may
have better luck with the new subprocess module in Python 2.4, as it is
written with communication to/from console applications in mind.

 - Josiah

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


Re: pre-PEP generic objects

2004-12-03 Thread Istvan Albert
Steven Bethard wrote:
module) not to the __builtins__.  I don't see how this "litters the 
standard namespace".
Maybe then it doesn't.
but what are you saying? that a man cannot exaggerate and
fudge the facts in order to embellish his argument? :-)
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and generic programming

2004-12-03 Thread Phillip J. Eby
Ian Bicking <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Jive Dadson wrote:
> > If you have, for example, several data-types for matrices, how do you
> > write code that will automatically find the right routine for quickly
> > multiplying a vector by a diagonal matrix represented as a vector, and
> > automatically call the right code for multiplying by a sparse matrix
> > represented by some sparse coding, etc?
> 
> I haven't been following this thread, but Phillip Eby's recent 
> implementation of generic functions should be mentioned if it hasn't 
> been already:
> 
> http://dirtsimple.org/2004/11/generic-functions-have-landed.html
> 
> It might look something like this:
> 
> @dispatch.on('m1', 'm2')
> def matrix_mul(m1, m2):
>  "Multiply two matrices"
> 
> @matrix_mul.when(VectorMatrix, SparseMatrix)
> def matrix_mul_sparse(m1, m2):
>  "Special implementation"

Actually, it would be more like:

@dispatch.generic()
def matrix_mul(m1, m2):
"""Multiply two matrices"""

@matrix_mul.when("m1 in VectorMatrix and m2 in SparseMatrix")
def matrix_mul_sparse(m1, m2):
"""Special implementation"""

The 'dispatch.on()' decorator is for single-dispatch functions only. 
If you want to dispatch on multiple arguments or on logical
conditions, you use 'dispatch.generic()'.  The implementations for
single and multiple dispatch are completely separate, and use
different algorithms.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 and "Python Regrets"

2004-12-03 Thread Nick Coghlan
Tim Peters wrote:
[EMAIL PROTECTED]
Is there a list of expected incompatibilities with Python 2.3?
No.
PEP 3000 doesn't count?
Actually, PEP 3000 should be taken with a (large) grain of salt, since it's only 
updated somewhat irregularly - but it's the closest thing I know of to a 
proposed feature list for Py3K/3.0.

Cheers,
Nick.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is Python designed?

2004-12-03 Thread Arthur Rambo
Limin,

Look at this: http://wiki.cs.uiuc.edu/cs427/PYTHON
I think it may help.

Arthur

Limin Fu <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> To clarify, I mean the internal structure and design
> of python interpreter. Any hint? Thanks.
> Regards,
> Limin
> 
> 
>   
> __ 
> Do you Yahoo!? 
> Yahoo! Mail - 250MB free storage. Do more. Manage less. 
> http://info.mail.yahoo.com/mail_250
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT Licensing and plugins/scripting

2004-12-03 Thread Phil Thompson
On Friday 03 December 2004 2:50 pm, Fabio wrote:
> Hi all,
> I'm about to write an application, and I'd like to use PyQt, but before
> choosing this toolkit I would like to clarify some particular licensing
> issues; if some user has already touched these, I would like to hear from
> his experiences.
>
> This app should be cross-platform, so, given qt licensing policies, I would
> buy a commercial PyQt license and a commercial Qt license.
>
> Could I license the application under the GPL for Gnu/Linux and under a
> commercial license for Windows and Mac OS X?

As there is are GPL versions of Qt and PyQt for Mac OS X, it's only Windows 
you need to handle differently.

> If this is possible, I guess 
> that contributions to the GPLed version could not be incorporated in the
> commercial version, but this would not be a big problem.

"Minor" contributions you don't need to worry about. I think that the GPL FAQ 
covers what is considered "minor". For significant contributions you would 
need to get the agreement of the contributors beforehand. Some projects state 
that contributions will only be accepted if the copyright of those 
contributions are transferred to the main project author.

> The main issue with licensing is that I would like to give users of the
> application a scripting framework (for macros and the like), and eventually
> a plugin framework; PyQT redistribution policy states that if an user can
> get in touch with PyQT directly it should have a commercial license itself;
> how does this apply to those who want to develop commercial PyQT
> applications with a plugin/scripting framework?

The key is access to the Qt API. If your applications gives the users access 
to the API then those users are developers and need their own licenses. On 
the other hand if the API is sufficiently removed from the Qt API then you 
shouldn't have a problem. Your API should restrict itself to extending the 
capabilities of your application - the more general purpose you make it, the 
more you risk a visit from the lawyers.

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


Re: Python2.4: building '_socket' extension fails with `INET_ADDRSTRLEN' undeclared

2004-12-03 Thread "Martin v. Löwis"
Michael Ströder wrote:
I'm trying to build Python2.4 on a rather old Debian machine. I only 
have a shell account there. That's why I'm very limited in my actions.

Building _socket fails (see below) although I tried to use
configure --disable-ipv6
Any clue?
Hard to say, since you don't indicate what clues you are lacking.
In general, when the C compiler gives an error message, it is best
to try to understand the error message. The message reads
socketmodule.c:3350: `INET_ADDRSTRLEN' undeclared (first use this function)
This apparently refers to the line
char ip[INET_ADDRSTRLEN + 1];
which is part of the block
#ifdef ENABLE_IPV6
char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
#else
char ip[INET_ADDRSTRLEN + 1];
#endif
So it appears that on your system, INET_ADDRSTRLEN is not defined,
even if it is supposed to be defined on all systems, regardless
of whether they support IPv6.
Looking at a more recent system in /usr/include, I get
/usr/include$ grep -r ADDRSTRLEN .
./netinet/in.h:#define INET_ADDRSTRLEN 16
This is a clue, I think.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Steven Bethard
Mel Wilson wrote:
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
I believe what Peter Otten was pointing out is that calling __eq__ is
not the same as using ==, presumably because the code for == checks the
types of the two objects and returns False if they're different before
the __eq__ code ever gets called.

Doesn't seem to:
[snip]
Hmm... maybe it only shows up with subclassing?
>>> class C(object):
... def __eq__(self, other):
... return True
...
>>> class D(C):
... def __eq__(self, other):
... return False
...
>>> c, d = C(), D()
>>> c == 3
True
>>> 3 == c
True
>>> c == d
False
>>> d == c
False
>>> c.__eq__(d)
True
>>> d.__eq__(c)
False
STeve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Replace string except inside quotes?

2004-12-03 Thread Jeff Shannon
Michael J. Fromberger wrote:
It's not the most elegant solution in the world.   This code does NOT 
deal with the problem of commented text.  I think it will handle triple 
quotes, though I haven't tested it on that case.
 

I believe that it will probably work for triple quotes that begin and 
end on the same line.  Of course, the primary usage of triple-quotes is 
for multiline strings, but given that the file is being examined one 
line at a time,  you'd need some method of maintaining state in order to 
handle multiline strings properly.  (Note that this problem is true 
regardless of whether the strings are true triple-quoted multiline 
strings, or single-quoted single-line strings broken across two lines of 
source code using '\'.)

If the entire file is read in and processed as a single chunk, instead 
of line-by-line, then *some* of the problems go away (at the cost of 
potentially very large memory consumption and poor performance, if the 
file is large).  The fact that triple-quoted strings work out (mostly) 
correctly when viewed as three pairs of quotes will help.  But if a 
triple-quoted string *contains* a normally quoted string (e.g., """My 
"foo" object"""),  then things break down again.

In order to handle this sort of nested structure with anything 
resembling true reliability, it's necessary to step up to a true 
lexing/parsing procedure, instead of mere string matching and regular 
expressions.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rounding the elements of a Python array (numarray module)

2004-12-03 Thread Chris P.
S I wasn't sure if no one replied because a) this question was too
dumb or b) this question was too hard... it was definitely the former.
 But I'll post the answer, anyway:

I forgot to keep in mind - when reading the documentation, assume that
a
>>> from numarray import *
occurred first.

So here's the way to do it:
>>> import numarray
>>> a = numarray.array([1.6, 1.9, 2.1])
>>> rounded_a = numarray.around(a)

and rounded_a then equals ([2., 2., 2.])

- Chris

[EMAIL PROTECTED] (Chris P.) wrote in message news:<[EMAIL PROTECTED]>...
> Given an array called 'x' (created using the numarray library), is
> there a single command that rounds each of its elements to the nearest
> integer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pre-PEP generic objects

2004-12-03 Thread Steven Bethard
Ian Bicking wrote:
class bunch(object):
def __init__(self, **kw):
for name, value in kw.items():
# IMPORTANT!  This is subclass friendly: updating __dict__
# is not!
setattr(self, name, value)
Good point about being subclass friendly...  I wonder if there's an easy 
way of doing what update does though...  Update (and therefore __init__) 
allows you to pass in a Bunch, dict, (key, value) sequence or keyword 
arguments by taking advantage of dict's update method.  Is there a clean 
way of supporting all these variants using setattr?

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


ANN: python-ldap-2.0.6

2004-12-03 Thread Michael Ströder
Find a new release of python-ldap:
  http://python-ldap.sourceforge.net/
python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Released 2.0.6 2004-12-03
Changes since 2.0.5:
Lib/:
* Added sub-module ldap.dn
* Added function ldap.dn.escape_dn_chars()
* Special check when implicitly setting SUP 'top' to
  structural object classes without SUP defined to avoid
  a loop in the super class chain.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is Python designed?

2004-12-03 Thread Terry Reedy

"Limin Fu" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Thanks a lot for the explanations.
> So CPython used more or less the standard technique to
> implement the interpreter.

Yes.  Moreover, the code is still pretty clean (in most places, at least) 
after 15 years of development.  These two facts facilitate joining the 
development team.

If you want cutting-edge, mind twisting stuff, look into
Psyco extension (Armin Rigo, 1.3 just announced here)
Stackless extension (Christian Tismer)
PyPy (new interpreter written in Python, several people, has EU funding)

Terry J. Reedy



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


ANN: python-ldap-2.0.6

2004-12-03 Thread Michael Ströder
Find a new release of python-ldap:
  http://python-ldap.sourceforge.net/
python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Released 2.0.6 2004-12-03
Changes since 2.0.5:
Lib/:
* Added sub-module ldap.dn
* Added function ldap.dn.escape_dn_chars()
* Special check when implicitly setting SUP 'top' to
  structural object classes without SUP defined to avoid
  a loop in the super class chain.
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


Help with modules/packages.

2004-12-03 Thread Christopher J. Bottaro
Hello,
I want to be able to say stuff like "import CJB.ClassA" and "import
CJB.ClassB" then say "c = CJB.ClassA()" or "c = CJB.ClassB()".  CJB will be
a directory containing files "ClassA.py" and "ClassB.py".

Now that I think about it, that can't work because Python allows you 
import
different things from the same module (file).  If I said "import
CJB.ClassA", I'd have to instantiate ClassA like "c = CJB.ClassA.ClassA()".

I guess I could say "from CJB.ClassA import ClassA", but then I'd
instantiate like "c = ClassA()".  What I really want is to say "c =
CJB.ClassA()"...is that possible?

Is my understand of modules/packages correct or am I way off?

Thanks for the help.

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


Re: using cmd.exe as a telnet client

2004-12-03 Thread Jp Calderone
On Fri, 03 Dec 2004 16:31:40 -0600, Donnal Walter <[EMAIL PROTECTED]> wrote:
>Several months ago I tried using the telnet module (on Windows XP) to 
> communicate with a proprietary host on our network. This was 
> unsuccessful due to problems with "option negotiation", and I gave up on 
> the project for a while. I still have need for this, however, so I 
> recently started thinking about alternatives. I suppose I could dig deep 
> enough into option negotiation to use the socket module (with telnet as 
> a guide), but I am hoping to find a way to use fewer synapses.
> 
> Using the Windows C:> prompt (cmd.exe) I can telnet into this host with 
> no problems (the Windows telnet client performs option negotiation just 
> fine). Is there a straightforward way of using os.popen() (or os.fork() 
> or os.exec*() or os.wait*()) to connect to the host from Python via the 
> Windows telnet client?
> 

  cmd.exe is not a command line program.  It's a terminal (emulator).  
You might be able to use the telnet program, though.  Before doing this, 
I'd recommend looking at Twisted's telnet support (both the version in 1.3 
and the version that will be in 2.0), which actually supports option 
negotiation in a reasonable way.

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


Re: pre-PEP generic objects

2004-12-03 Thread Steven Bethard
Istvan Albert wrote:
On the other hand, it would be nice to have a module that
implements various design patterns. The Bunch, the Borg, the Null,
the Proxy all nicely documented tucked away in their separate
module. That would feel a lot less like littering the standard name space
with an class that just "seems"  to be useful.
From the (pre-)PEP:
"This PEP proposes a standard library addition..."
Bunch would go into the standard library (probably the collections 
module) not to the __builtins__.  I don't see how this "litters the 
standard namespace".

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


Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Steven Bethard
Mel Wilson wrote:
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
I believe what Peter Otten was pointing out is that calling __eq__ is
not the same as using ==, presumably because the code for == checks the
types of the two objects and returns False if they're different before
the __eq__ code ever gets called.

Doesn't seem to:
[snip]
Check his example:
http://mail.python.org/pipermail/python-list/2004-November/252660.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT Licensing and plugins/scripting

2004-12-03 Thread Kevin Walzer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
PyQt on OS X is also available under a GPL version. I have a binary
installer available at http://www.wordtech-software.com/pyqt-mac.html

Fabio wrote:
| Hi all,
| I'm about to write an application, and I'd like to use PyQt, but before
| choosing this toolkit I would like to clarify some particular licensing
| issues; if some user has already touched these, I would like to hear from
| his experiences.
|
| This app should be cross-platform, so, given qt licensing policies, I
would
| buy a commercial PyQt license and a commercial Qt license.
|
| Could I license the application under the GPL for Gnu/Linux and under a
| commercial license for Windows and Mac OS X? If this is possible, I guess
| that contributions to the GPLed version could not be incorporated in the
| commercial version, but this would not be a big problem.
|
| The main issue with licensing is that I would like to give users of the
| application a scripting framework (for macros and the like), and
eventually
| a plugin framework; PyQT redistribution policy states that if an user can
| get in touch with PyQT directly it should have a commercial license
itself;
| how does this apply to those who want to develop commercial PyQT
| applications with a plugin/scripting framework?
|
| Thanks,
| Fabio
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFBsO2QJmdQs+6YVcoRAmv5AKCClM58N6EgMVUkaVrp5gWzALxuCwCeI+Gt
5+gXRwfjtSPiu4DEnF5j86Q=
=WkvR
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: using cmd.exe as a telnet client

2004-12-03 Thread Grant Edwards
On 2004-12-03, Donnal Walter <[EMAIL PROTECTED]> wrote:

> Several months ago I tried using the telnet module (on Windows XP) to 
> communicate with a proprietary host on our network. This was 
> unsuccessful due to problems with "option negotiation", and I gave up on 
> the project for a while. I still have need for this, however, so I 
> recently started thinking about alternatives. I suppose I could dig deep 
> enough into option negotiation to use the socket module (with telnet as 
> a guide), but I am hoping to find a way to use fewer synapses.

You don't have to start from scratch. The telnet module has
hooks built-into it1 so that you can have it call your routines
to handle option negotiation.  I did it once to impliment some
extra Telnet protocol features, and it wasn't difficult.

-- 
Grant Edwards   grante Yow!  How's the wife? Is
  at   she at home enjoying
   visi.comcapitalism?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI Frames and classmethod

2004-12-03 Thread Scott David Daniels
Zak Arntson wrote:
Note the last line. When programming EVERY child I have to remember to
add this self.create_empty_state_methods() line.
My question: What are Pythonic alternatives to this sort of thing?
Now I can't be the first person to want a pre- and post- child init code! 
> I'm worried that I'm overlooking something or there's an even more
> Pythonic way to do things than above.
To your explicit question:  The trick is to name the middle part, and
override it you want.  Then your base class can invoke the appropriate
building at the point it likes.
Base frame looks like:
class BaseFrame(...):
def __init__(self, ):
self.input_state_machine = ...
# more pre-setup
self.addrules()
self.create_empty_states()
# more post-setup
def addrules():
pass
Button (for example) looks like:
class ButtonFrame(BaseFrame):
def addrules():
ism = self.input_state_machine
ism.add_rule("None", "LWait", (MOUSEBUTTONDOWN, 1))
ism.add_rule("LWait", "None", (MOUSEBUTTONDOWN, 2))
ism.add_rule("LWait", "None", (MOUSEBUTTONUP, 1))
See, you needn't even muck with __init__ here, if all you want is
some rules added.  Something which actually wants to do some init stuff:
class FunkFrame(BaseFrame):
def __init__(self, ...):
# more pre-setup
super(FunkFrame, self).__init__(self, ...)
# more post-setup
def addrules():
self.input_state_machine.add_rule(
 "None", "RWait", (MOUSEBUTTONDOWN, 1))
> My current approach is that in the Frame class, I have a method to
> call _after_ initialization that creates a bunch of dummy methods so
> the user doesn't have to implement EVERY state change method in a
Really, I think the above is a bad idea.  Don't implement empty
methods.  Make a dictionary of state transitions, and store code in it.
Note: you don't need a dictionary of dictionaries; you could use a
dictionary of pairs.  Do something on each attempted transition like the
following:
def change_state(self, newstate):
try:
action = self.transitions[self.current, newstate]
except KeyError:
raise NoRuleError, (self.current, newstate)
# or pass to ignore missing transitions.
else:
action(self)
This method belongs in BaseFrame and assumes a class like:
class NoRuleError(ValueError):
def __str__(self):
return 'No transition defined for %r -> %r' % self.args
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread howardrh
"Shawn Milo" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> I was just wondering what the best books were for learning Python.
> 
> Which books are good for getting started, and which should be saved for
> later, or or not useful except as a reference for the learned?


If you have any interest in using Python for numerical computation
take a look at Python Scripting for Computational Science by Hans
Peter Langtangen.  The book is quite expensive, about US $85, but well
worth it in my opinion as it covers just about all of the available
Python resources for numerical computation.
-- 
http://mail.python.org/mailman/listinfo/python-list


using cmd.exe as a telnet client

2004-12-03 Thread Donnal Walter
Several months ago I tried using the telnet module (on Windows XP) to 
communicate with a proprietary host on our network. This was 
unsuccessful due to problems with "option negotiation", and I gave up on 
the project for a while. I still have need for this, however, so I 
recently started thinking about alternatives. I suppose I could dig deep 
enough into option negotiation to use the socket module (with telnet as 
a guide), but I am hoping to find a way to use fewer synapses.

Using the Windows C:> prompt (cmd.exe) I can telnet into this host with 
no problems (the Windows telnet client performs option negotiation just 
fine). Is there a straightforward way of using os.popen() (or os.fork() 
or os.exec*() or os.wait*()) to connect to the host from Python via the 
Windows telnet client?

Thanks,
Donnal Walter
Arkansas Children's Hospital
--
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recommendations

2004-12-03 Thread Sean Dolan
Nathan Weston wrote:
I'm new to Python and am looking for a book to get me up to speed
quickly. I'm an experienced programmer and very proficient with Ruby,
so Python is coming easily to me and I don't need a gentle
introduction -- I just need a quick way to get familiar with common
Python idioms and important libraries.
http://www.diveintopython.org/
I'm also looking for a "gentler" book to help introduce some of my
co-workers to python. They are also experienced programmers, but
mostly in C++, with some Java/C# but minimal exposure to scripting
languages.
Any suggestions?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need help on program!!!

2004-12-03 Thread Jerry Sievers
"Darth Haggis" <[EMAIL PROTECTED]> writes:

> I need help writing a program
> 
> You are to write a python program to accomplish the following:
> 
>   a.. Play a dice game of Craps using a random number generator to simulate
> the roll of the dice, the code for the rolling of the dice should take place
> in a user written module named rolldice.

[snip]

I'll have this ready for you Monday AM.

Contact me for PayPal instructions!

Your Professor won't have a clue.  I'll even do it in an inefficient
way so's to make it look like done by a stressed out student.

HTH

-- 
---
Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobilehttp://www.JerrySievers.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recommendations

2004-12-03 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] (Nathan Weston) wrote:
>I'm new to Python and am looking for a book to get me up to speed
>quickly. I'm an experienced programmer and very proficient with Ruby,
>so Python is coming easily to me and I don't need a gentle
>introduction -- I just need a quick way to get familiar with common
>Python idioms and important libraries.
>
>I'm also looking for a "gentler" book to help introduce some of my
>co-workers to python. They are also experienced programmers, but
>mostly in C++, with some Java/C# but minimal exposure to scripting
>languages.

I'd recommend Alex Martelli's "Python in a Nutshell" for you and "Learning
Python" by Lutz and Ascher for your colleagues. They are both published by
O'Reilly.



== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recommendations

2004-12-03 Thread Manuzhai
Nathan Weston wrote:
I'm new to Python and am looking for a book to get me up to speed
quickly. I'm an experienced programmer and very proficient with Ruby,
so Python is coming easily to me and I don't need a gentle
introduction -- I just need a quick way to get familiar with common
Python idioms and important libraries.
I'm also looking for a "gentler" book to help introduce some of my
co-workers to python. They are also experienced programmers, but
mostly in C++, with some Java/C# but minimal exposure to scripting
languages.
Check this thread currently going on: 
http://groups.google.com/groups?hl=en&lr=&c2coff=1&safe=off&threadm=coqd91%246m2%241%40news.doit.wisc.edu&prev=/groups%3Fhl%3Den%26lr%3D%26c2coff%3D1%26safe%3Doff%26group%3Dcomp.lang.python

Regards,
Manuzhai
--
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Manuzhai
I've not read all of it, and it overlaps a fair bit with Learning 
Python, but the free Dive Into Python reads well and is often cited as a 
good intro for those with programming experience. 
. It is also available as a dead-tree 
product from APress.
I found Dive Into Python to be very useful when I got my hands wet with 
Python. It's a great read by a funny author, very much recommended.

Regards,
Manuzhai
--
http://mail.python.org/mailman/listinfo/python-list


RE: type cmp add

2004-12-03 Thread Robert Brewer
Zora Honey wrote:
> I've just discovered operator overloading via defining a 
> class's special
> methods and I think it's swell, or would be if I could figure out two
> things:
> 
> In order say, add things, I need to do some type checking. For a+b to
> work, both must be instances of the same class.  I can check to see if
> they are instances using if type(a)==types.InstanceType, but I don't
> know how determine which class it is in an instance of.  (This must
> somehow be possible because if I do "print a" without having 
> overloaded
> __str__, I get <__main__.C instance at 0x815b9ec> telling me it's an
> instance of class C).

a.__class__

> Also, how to I make an instance of a class from within the class?  I
> want c = a + b to return a new instance of value a + b 
> without changing
> a or b.  When I define the __add__ method, I have access to self and
> other, whose properties I can change at will, but how do I get a fresh
> instance of the class that I am writing?

self.__class__()


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Python compared with Xen (for XML)

2004-12-03 Thread Will Stuyvesant
Here is a comment on the paper "Programming with Circles,
Triangles and Rectangles" by Erik Meijer, Wolfram Schulte
and Gavin Bierman.  Google will find it quickly if you try.

In the paper they introduce Xen, an extension to C# for
better XML support.  They show how Lifting, Filtering and
Apply-to-all can be done so much better in C# with Xen.

How is Python, my favorite programming language, doing in
this respect?  Let's see:



Python for XML
==


Lifting
---

The example:
"bib.books.title"
[[an expression for all titles of books in bib]]

(stuff in double quotes "..." is suggested Xen code from the
article by E.Meijer et al., stuff in double square brackets
[[...]] is the intended meaning.  Python code is shown after
>>> , the prompt from the Python interactive interpreter.)

We can do this "Lifting" in Python with list comprehension:
>>> [b.title for b in bib.books]


Filtering
-

The example:
"bib.books[it.year >= 1998]"
[[An expression for the books from 1998 or later]]

This can also be done with Python list comprehensions.
>>> [b for b in bib.books if b.year >= 1998]


Apply-to-all


The example:
"bib.books.{print it}"
[[print all books: execute a code block for every book
in .books.]]

I would do it like this in Python:

for b in bib.books:
print b

looks much clearer to me than the .{...} stuff.  Oh and
maybe the new generator expressions can be used for this,
but they are new to me and I can hardly imagine clearer
syntax.  Anyone?

All that is needed for this to work in Python is that you
collect XML attributes in object attributes; and that you
give a name to the XML children of an XML element and put
them as a list into an object attribute with that name.  Go
wild and even define new classes for it dynamically, or
beforehand if you have the XML DTD or Schema.  Not too hard
a programming exercise; who is first?

As for the other content of the article it is my opinion
that they pay way too much attention to data-models and
types, and then strangle themselves trying to fit one
data-model onto another one, and a statically typed one too
for that! (C#, Java, even Visual Basic is mentioned for
laughing out loud).  Better try to get the job done first.

They did this work paid by microsoft.research.  I think
microsoft.research better pay some more attention to Python.
Or are they?  Are the "competitive edge" rumors true?

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


Re: pythonwin broke

2004-12-03 Thread David Bolen
Trent Mick <[EMAIL PROTECTED]> writes:

> It is also possible that there is some little installer bug or detail
> on your environment that is causing the problem. You could try
> ActivePython. I regularly install and uninstall ActivePython 2.3 and
> 2.4 installers and both installs are still working fine.

Just as another data point, I have all of Python 1.5.2, 2.0.1, 2.1.3,
2.2.3, 2.3.4 and 2.4 installed side by side on my Windows box, as
installed by their standard installers, without any problems.  And
that includes uninstall/reinstall cycles for patch releases of
versions older than the most recent (e.g., putting on 2.2.3 after a
2.3 variant was already installed).  The only real restriction is as
you noted - only one can own the file associations (or be associated
with the COM support for pywin32).

In case it matters, I do install everything as administrator for all
users and this is under 2K (my NT box has everything but 2.4).

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


Graphical box /interactive programme

2004-12-03 Thread cm012b5105
Hello i want to put an interactive text programme in to a graphical box
this is a small section of my text programme
s = raw_input ("Hello whats your name? ")
if s=='melvyn':
print "your my boss's Dad the one they call in indian language DEEP 
THOUGHT LITTLE HORSE"
if s=='carol':

print "ahhh you are my boss's mom the one they call WREATH WOMAN"
if s=='rebecca':
print "you must be the FLORIST WOMAN"
if s=='gareth':
print "you must be the one they call the TRUCKER"
if s=='carmel':
print "you must be my boss's wife"

s = raw_input ("what do you do for a living? ")
print "Ahh thats easy you dont do much then",s,"my boss is a Truck driver."


these are the instructions for a graphical boxfrom Tkinter import *

root = Tk()
cv = Canvas(root, width=400, height=300, bg="blue")
cv.pack()
cv.create_rectangle(50,30,320,290,outline="yellow",fill="red",width=10)

mainloop()

any way what i would like to do is create a programme that would run my text 
programme from this graphical box i tried to add the code for the box to the 
top of my text programme but when i run it i get the graphical box come up 
and my text   programme will not work untill i kill the box. i would be graet 
full if some body can help me acheive this.
thanks nige
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How is Python designed?

2004-12-03 Thread Limin Fu
Thanks a lot for the explanations.
So CPython used more or less the standard technique to
implement the interpreter. 

Are there any other interpretation techniques? I guess
many. But I'm quite new in this field and I couldn't
find good references on internet about this. If there
is anybody has such references, please send me some if
you don't mind. I would be appreciative very much.
Best,

Limin


--- Terry Reedy <[EMAIL PROTECTED]> wrote:

> 
> "Limin Fu" <[EMAIL PROTECTED]> wrote in message
> 
>
news:[EMAIL PROTECTED]
> > To clarify, I mean the internal structure and
> design
> > of python interpreter. Any hint? Thanks.
> 
> Ah... The interpreters (plural) are a separate issue
> from the language 
> itself (a Python program is a list of Python
> statements, etc).  We'll 
> presume that you specifically mean the CPython
> interpreter, as opposed to 
> Jython, Viper, Ironman, PyPy, Parrot, or the human
> brain.  For CPython:
> 
> human or other source code generator ==> Python
> source code
> 
> CPython compile phase:
> lexer ==> tokens
> parser ==> ast tree
> byte code generator ==> byte codes for Python
> virtual machine
>   (see the Lib Ref chapter on the dis module for VM
> commands)
> 
> CPython runtime phase:
> code evaluator  ==> computations
>(see source file ceval.c for the link between
> byte codes and C 
> functions)
> 
> CPython is currently both the reference
> implementation and the most 
> commonly used implementation.  Both facts could
> change in the future, 
> possibly even with divergence between the two roles.
>  Since Python is meant 
> to be a practical computer language as well as an
> abstract algorithm 
> language (for humans), a reference implementation is
> needed to show that 
> proposed language features can be sensibly
> implemented.
> 
> Terry J. Reedy
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 




__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 

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


Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Mel Wilson
In article <[EMAIL PROTECTED]>,
Steven Bethard <[EMAIL PROTECTED]> wrote:
>I believe what Peter Otten was pointing out is that calling __eq__ is
>not the same as using ==, presumably because the code for == checks the
>types of the two objects and returns False if they're different before
>the __eq__ code ever gets called.

Doesn't seem to:



Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class EQ(object):
... def __eq__ (self, other):
... return True
...
>>> eq = EQ()
>>> eq == 3
True
>>> 3 == eq
True
>>> class NEQ(object):
... def __eq__ (self, other):
... return False
...
>>> neq=NEQ()
>>> eq == neq
True
>>> neq == eq
False
>>>



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


Book Recommendations

2004-12-03 Thread Nathan Weston
I'm new to Python and am looking for a book to get me up to speed
quickly. I'm an experienced programmer and very proficient with Ruby,
so Python is coming easily to me and I don't need a gentle
introduction -- I just need a quick way to get familiar with common
Python idioms and important libraries.

I'm also looking for a "gentler" book to help introduce some of my
co-workers to python. They are also experienced programmers, but
mostly in C++, with some Java/C# but minimal exposure to scripting
languages.

Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Python-2.4 available at Python-Hosting.com

2004-12-03 Thread Remi Delon
Hello everyone,

I'm happy to announce that Python-2.4 is already available on all of
our servers.

People using Python CGI or Python-2.4-compatible application servers
will be able to use all the new features of Python-2.4 for their
website.

We've only installed a few third-party modules for it so far, but
we'll install more as they become available and as people need them.


About Python-Hosting.com:

Python-Hosting.com is a hosting provider specialized in Python.
Supported software includes Zope, Plone, Quixote, CherryPy, Webware,
 SkunkWeb, Twisted, Spyce, mod_python and others (in fact, pretty
 much everything you want that runs on Python).

Remi

PS: Python-Hosting.com will be 2 years old in a few weeks :-)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


cx_Freeze 3.0.1

2004-12-03 Thread Anthony Tuininga
What is cx_Freeze?
cx_Freeze is a set of utilities for freezing Python scripts into
executables using many of the techniques found in Thomas Heller's
py2exe, Gordon McMillan's Installer and the Freeze utility that ships
with Python itself.
Where do I get it?
http://starship.python.net/crew/atuining
http://www.computronix.com/utilities.shtml
(it may be a few days before the second site is updated)
What's new?
 1) Added option --default-path which is used to specify the path used
when finding modules. This is particularly useful when performing
cross compilations (such as for building a frozen executable for
Windows CE).
 2) Added option --shared-lib-name which can be used to specify the name
of the shared library (DLL) implementing the Python runtime that is
required for the frozen executable to work. This option is also
particularly useful when cross compiling since the normal method for
determining this information cannot be used.
 3) Added option --zip-include which allows for additional files to be
added to the zip file that contains the modules that implement the
Python script. Thanks to Barray Warsaw for providing the initial
patch.
 4) Added support for handling read-only files properly. Thanks to Peter
Grayson for pointing out the problem and providing a solution.
 5) Added support for a frozen executable to be a symbolic link. Thanks
to Robert Kiendl for providing the initial patch.
 6) Enhanced the support for running a frozen executable that uses an
existing Python installation to locate modules it requires. This is
primarily of use for embedding Python where the interface is C but
the ability to run from source is still desired.
 7) Modified the documentation to indicate that building from source on
Windows currently requires the mingw compiler
(http://www.mingw.org).
 8) Workaround the problem in Python 2.3 (fixed in Python 2.4) which
causes a broken module to be left in sys.modules if an ImportError
takes place during the execution of the code in that module. Thanks
to Roger Binns for pointing this out.
--
Anthony Tuininga
[EMAIL PROTECTED]
Computronix
Distinctive Software. Real People.
Suite 200, 10216 - 124 Street NW
Edmonton, AB, Canada  T5N 4A3
Phone:  (780) 454-3700
Fax:(780) 454-3838
http://www.computronix.com
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


MMA - Musical MIDI Accompaniment, Beta 0.12

2004-12-03 Thread Bob van der Poel
I'm pleased to announce the release of my program
mma - Musical MIDI Accompaniment
version: Beta 0.12
MMA is a accompaniment generator -- it creates midi tracks
for a soloist to perform over from a user supplied file
containing chords and MMA directives.
MMA is very versatile and generates excellent tracks. It comes
with an extensive user-extendable library with a variety of
patterns for various popular rhythms, an extensive user manual,
and several demo songs.
MMA is a command line driven program. It creates MIDI files
which need a sequencer or MIDI file play program.
MMA is written in Python. You'll need Python 2.3 (or later)
for MMA to function.
MMA is supplied in 4 tar.gz archives. Included:
mma-bin   -- the main script and library files.
mma-html  -- documentation in HTML format.
mma-pdf   -- documentation in PDF format.
mma-songs -- a collection of about 120 songs in MMA format.
If you get all four download packages the total size is still
less than 1.5 megabytes.
MMA is currently in final BETAs. We are hoping for a 1.0 release
early in 2005. Right now we need help in debugging the program,
creating songs for distribution, and new and improved
library files.
Best of all, MMA is free. It is released under the terms of the GNU
General Public License. It has been developed on a Linux platform,
but should be usable on just about any system. A detailed page now
exists on our web site on how-to install on a Windows system.
MMA is available on my personal home page:
http://mypage.uniserve.com/~bvdp/mma/mma.html
If you have any questions or comments, please send them
to: [EMAIL PROTECTED]
Beta 0.12: Bass patterns expanded, minor improvements to Scale and
Walk tracks, harmony improvements, a new MIDI INCLUDE directive,
improved solo voice methods, and general cleanups/fixes.
Comments appreciated!
--
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [EMAIL PROTECTED]
WWW:   http://mypage.uniserve.com/~bvdp
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


mxCGIPython - unofficial update for Python 2.4

2004-12-03 Thread Oleg Broytmann
Hello! I patched mxCGIPython for Python 2.4:

http://phd.pp.ru/Software/Python/misc/mxCGI/mxCGIPython.patch

   The patch adds 3 modules to Modules/Setup - zipimport, _symtable and
_csv; it also adds CGIPython/pyversion.c to be used instead of python,
becuase Makefile.cgi needs to know what version it is making before
python interpreter is built. A script CGIPython/remove-modules is used
in Makfile.cgi to remove modules from Modules/Setup to compile different
versions of Python; this is probably bad approach, and it is not very
portable; the script works on Linux and Solaris systems, but not on
FreeBSD - it requires an option for sed (-E) and a slightly different
regular expression - unescaped '+' instead of '\+'. Also there is a
special patch for BSD that removes "unset" lines.

   Other than that minor problems the thing works fine. This is far from
complete, of course, but that's all I can do. I rebuilt python 2.1.3,
2.2.3, 2.3.4 and 2.4.0 on Linux, Solaris 2.5.2, FreeBSD 4.9 and FreeBSD
5.3. The binaries are in the usual place:

   http://phd.pp.ru/Software/Python/misc/mxCGI/

Don't forget to make CGIPython/remove-modules executable.

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: PyQT Licensing and plugins/scripting

2004-12-03 Thread Jarek Zgoda
Fabio wrote:
I'm about to write an application, and I'd like to use PyQt, but before
choosing this toolkit I would like to clarify some particular licensing
issues; if some user has already touched these, I would like to hear from
his experiences.
This app should be cross-platform, so, given qt licensing policies, I would
buy a commercial PyQt license and a commercial Qt license.
Could I license the application under the GPL for Gnu/Linux and under a
commercial license for Windows and Mac OS X? If this is possible, I guess
that contributions to the GPLed version could not be incorporated in the
commercial version, but this would not be a big problem.
Right.
The main issue with licensing is that I would like to give users of the
application a scripting framework (for macros and the like), and eventually
a plugin framework; PyQT redistribution policy states that if an user can
get in touch with PyQT directly it should have a commercial license itself;
how does this apply to those who want to develop commercial PyQT
applications with a plugin/scripting framework?
This is vague, what one considers "get in touch"? If you perform any 
calculations and display results to the user, would it be "get in touch 
with PyQt"? I think not. If showing a window depends on your user's 
scripting code, then I thing it's "get in touch", but if you simply show 
a window with display widget (more or less advanced, be it QTextView or 
even sort of grid) with results, this doesn't cover the case, as PyQt is 
only used for display purposes -- just as with any other use of PyQt.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


type cmp add

2004-12-03 Thread Zora Honey
I've just discovered operator overloading via defining a class's special
methods and I think it's swell, or would be if I could figure out two
things:
In order say, add things, I need to do some type checking. For a+b to
work, both must be instances of the same class.  I can check to see if
they are instances using if type(a)==types.InstanceType, but I don't
know how determine which class it is in an instance of.  (This must
somehow be possible because if I do "print a" without having overloaded
__str__, I get <__main__.C instance at 0x815b9ec> telling me it's an
instance of class C).
Also, how to I make an instance of a class from within the class?  I
want c = a + b to return a new instance of value a + b without changing
a or b.  When I define the __add__ method, I have access to self and
other, whose properties I can change at will, but how do I get a fresh
instance of the class that I am writing?
Thanks,
zh
--
http://mail.python.org/mailman/listinfo/python-list


GUI Frames and classmethod

2004-12-03 Thread Zak Arntson
I'm currently implementing a game GUI, where there are three
components to the screen: A battle, a command button area and a city
view area. Each of these are rectangular, and handle interactions in
different ways.

For example, on the battle "frame" you can select units, right-click
to deliver context-sensitive commands, etc. On the command frame, you
select buttons to deliver commands, change the state of the battle
frame (i.e., a move command sets the battle frame to accept a move-to
location). This sort of thing.

So I'm implementing the frame code right now. Each Frame object has a
StateMachine object.  Which mean that in the __init__ code of a child
of Frame, you add rules to the StateMachine object:

###
class ButtonFrame(Frame):
def __init__(self, owner, pos, size=None):
Frame.__init__(self, owner, pos, size)
ism = self.input_state_machine

ism.add_rule("None", "LWait", (MOUSEBUTTONDOWN, 1))
##
ism.add_rule("LWait", "None", (MOUSEBUTTONDOWN, 2))
ism.add_rule("LWait", "None", (MOUSEBUTTONUP, 1))

###

This is all fine and good. Now, when creating a Frame child class, you
make an implicit agreement that you'll create methods for each state,
such as ButtonFrame.enter_state_LWait() or
ButtonFrame.leave_state_None().

My current approach is that in the Frame class, I have a method to
call _after_ initialization that creates a bunch of dummy methods so
the user doesn't have to implement EVERY state change method in a
Frame child:

###
##@classmethod -- Python 2.4
def _empty_state_method(self):
pass
_empty_state_method = classmethod(_empty_state_method)

def create_empty_state_methods(self):
ism = self.input_state_machine
for timing in ('enter','during','leave'):
for state in ism.states:
method = '%s_state_%s' % (timing, state)
if not hasattr(self.__class__, method):
setattr(self.__class__, method, Frame._empty_state_method)
###

This means that if the user hasn't implemented
ButtonFrame.during_state_LWait(), for example, an empty function will
be provided (pointing to _empty_state_method().

(Aside: I'm considering putting all these state methods in a
dictionary of dictionaries so you can do a quick
myButtonFrame.state_dict['during']['LWait'] to access the proper
method)

What this now means is that when implementing a child, I am not only
forcing a call to Frame.__init__(), but also
Frame.create_empty_state_methods(). So my ButtonFrame class looks
like:

###
class ButtonFrame(Frame):
def __init__(self, owner, pos, size=None):
Frame.__init__(self, owner, pos, size)
ism = self.input_state_machine

ism.add_rule("None", "LWait", (MOUSEBUTTONDOWN, 1))
##
ism.add_rule("LWait", "None", (MOUSEBUTTONDOWN, 2))
ism.add_rule("LWait", "None", (MOUSEBUTTONUP, 1))

self.create_empty_state_methods()
###

Note the last line. When programming EVERY child I have to remember to
add this self.create_empty_state_methods() line.

My question: What are Pythonic alternatives to this sort of thing?

I can think of a few solutions, but none of them seem to be obviously
advantageous:

1. All children don't call __init__, but have an _init() method that
is called by Frame.__init__(). That way ButtonFrame has an _init()
method rather than an __init__() method. This may be my best option.
###
class Frame:
def __init__(self, owner, pos, size=None):
self.owner = owner
self.children = []  
# more setup code here.

self._init()

self.create_empty_state_methods()
###

2. Frame has an init() function that needs to be called following the
instantiation of a Frame (or Frame child object). I'm not too keen on
this, because it requires creating the Frame object and _then_ running
an init() method. I try to keep that sort of thing to a minimum
because it makes quick object creation a little funky. (init() has to
return self so you can do a myList.append(ButtonFrame().init()))
###
class Frame:
def __init__(self, owner, pos, size=None):
self.owner = owner
self.children = []  
# more setup code here.

def init(self):
self.create_empty_state_methods()
return self

b = Frame()
b.init()
myList.append(b)
###

Phew! Hope that's not overly long! Now I can't be the first person to
want a pre- and post- child init code! I'm worried that I'm
overlooking something or there's an even more Pythonic way to do
things than above.

-- 
Zak Arntson
http://www.harlekin-maus.com - Games - Lots of 'em
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Mark Jackson
[EMAIL PROTECTED] (John Machin) writes:
> "Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
> PROTECTED]>...
> > Well I would suggest the Python in a Nutshell and the Python Cookbook  both 
> > by O'Reilly as references.  They are great for a desktop reference and I 
> > check them first before I google/search else where for answers.  Being they 
> > are reference books they or more on aide then a teaching device however I 
> > have learned from those books how to use certain standard classes, such as 
> > the re class for example. 
> 
> Somebody called O'Reilly taught you that Python has "standard
> classes", one of which is "re"??? Hmmm, can't have been O'Reilly the
> publisher; must have been O'Reilly the builder.

Or possibly O'Reilly the pundit.  Lucky he didn't tell you Python has
falafels.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
You should always save hyperbole until you really need it.
- Hobbes (Bill Watterson)


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


Re: How did you learn Python?

2004-12-03 Thread John Machin
"Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Well I would suggest the Python in a Nutshell and the Python Cookbook  both 
> by O'Reilly as references.  They are great for a desktop reference and I 
> check them first before I google/search else where for answers.  Being they 
> are reference books they or more on aide then a teaching device however I 
> have learned from those books how to use certain standard classes, such as 
> the re class for example. 

Somebody called O'Reilly taught you that Python has "standard
classes", one of which is "re"??? Hmmm, can't have been O'Reilly the
publisher; must have been O'Reilly the builder. Sybil! Where's that
garden gnome?
-- 
http://mail.python.org/mailman/listinfo/python-list


Zope side-by-side with Python 2.4

2004-12-03 Thread Robert
If I have Python 2.4 installed and I want to install the latest stable
Zope, will Zope have problems or does Zope looks to its own setup and
not my install of Python 2.4?

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


Re: Python 3000 and "Python Regrets"

2004-12-03 Thread Dieter Maurer
Tim Peters <[EMAIL PROTECTED]> writes on Wed, 1 Dec 2004 13:38:49 -0500:
> ...
> > Are serious Python programmers already taking care to avoid
> > using Python features that may disappear in Python 3000?
> 
> No, although some naturally avoid dubious features without being
> threatened .

Are there dubious features in Python? :-)


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


Re: Replace string except inside quotes?

2004-12-03 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> The code 
> 
> for text in open("file.txt","r"):
> print text.replace("foo","bar")[:-1]
> 
> replaces 'foo' with 'bar' in a file, but how do I avoid changing text
> inside single or double quotes? For making changes to Python code, I
> would also like to avoid changing text in comments, either the '#' or
> '""" ... """' kind.

The first part of what you describe isn't too bad, here's some code that 
seems to do what you want:

import re

def replace_unquoted(text, src, dst, quote = '"'):
r = re.compile(r'%s([^\\%s]|\\[\\%s])*%s' %
   (quote, quote, quote, quote))

out = '' ; last_pos = 0
for m in r.finditer(text):
out += text[last_pos:m.start()].replace(src, dst)
out += m.group()
last_pos = m.end()

return out + text[last_pos:].replace(src, dst)

Example usage: 
   print replace_unquoted(file('foo.txt', 'r').read(),
  "foo", "bar")

It's not the most elegant solution in the world.   This code does NOT 
deal with the problem of commented text.  I think it will handle triple 
quotes, though I haven't tested it on that case.

At any rate, I hope it may help you get started.

Cheers,
-M

-- 
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Jean Montambeault
Jean Montambeault wrote:
I am not only learning Python but programming itself ; reading your 
posts makes me believe that nobody is that much of a beginner here. Is 
there a newgroup or list for my type somewhere I can't find it ?

To illustrate my case this script :

# function to draw rings for an Olympic flag
def rings(size,offsetX,offsetY,coul):
x1,y1,x2,y2 = 170, 103, 170, 103,
can1.create_oval(x1-size-offsetX,y1+size+offsetY,\
 x2+size-offsetX,y2-size+offsetY,\
 width=8, outline=coul)
# **mainmainmainmainmainmain**
fen1=Tk()
can1=Canvas(fen1, bg='white', height=206, width=340)
can1.pack(side=LEFT)
bou_europe=Button(fen1, text='Europe',\
  command=rings(41, 100, -22, 'blue'))
bou_europe.pack( )
bou_asia=Button(fen1, text='Asia',\
  command=rings(size=41, offsetX=50,offsetY=22, 
coul='yellow'))
bou_asia.pack( )

bou_africa=Button(fen1, text='Africa',\
  command=rings(size=41, offsetX=0,offsetY=-22, 
coul='black'))
bou_africa.pack( )

bou_australia=Button(fen1, text='Australia',\
  command=rings(size=41, offsetX=-50,offsetY=22, 
coul='dark green'))
bou_australia.pack( )

bou_america=Button(fen1, text='America',\
  command=rings(size=41, offsetX=-100,offsetY=-22, 
coul='Red'))
bou_america.pack( )

bou_quit=Button(fen1, text='Quit', command=fen1.quit)
bou_quit.pack(side=BOTTOM)
fen1.mainloop()
fen1.destroy()

I just cannot figure out why the rings are draw right from the start and 
 don't wait for their buttons to be pressed before being drawn :  I've 
written similar functions before to draw lines, rectangles and whatever 
else with success.

Using Python 2.3, IDLE and Win2k.
Thanks for your time
Jean Montambeault
Thank you everybody !
If Tkinter hadn't been so polite... but without any error message I 
didn't know where to start to search. It is a shame that one can't pass 
parameters through 'command' in a simple manner. My intent was to make a 
function that could be of use in as many cases as possible. I was 
experimenting way off the intented target of the exercise. Nevertheless 
it was an occasion to learn a whole lot.

Thanks to Simon and Eric the adresses too.
Jean
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need help on program!!!

2004-12-03 Thread Dan Perl

"Max M" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hopefully his teacher doesn't know about Google, or he can be expelled 
> from school for using it.

"Hopefully" for whom?  For us, who may have to work with him someday or use 
a product that he developed?  Most of us here have been students (or still 
are) and may sympathize with the OP, but personally I have been also a TA so 
I have seen the other side and that's where my sympathy lies now.

Dan 


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


Re: finding byte order

2004-12-03 Thread Diez B. Roggisch
> But, in fact, he says the files are always big endian.  So, code like
> the following should address his problem.  Note I use type 'h' as an
> example so I can easily read samples.

I'm sorry, I confused that he asked for machine endianess. Then of course
you are right.

-- 
Regards,

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


HTTP response code

2004-12-03 Thread Jonas Galvez
Hi list, here's a question about urllib. Is it possible to simply 
retrieve the HTTP responde code for a given URL? I don't want to 
download the body of the HTTP message. I simply want to check the 
response code, like, if it is 200, 301 etc. Something like:

if urllib.urlopen(the_url).response_code == 200:
# ...

Is there an easy way to do this?
Should I be using urllib2 instead?


--
http://jonasgalvez.com
http://codeazur.com.br
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help on program!!!

2004-12-03 Thread Grant Edwards
On 2004-12-03, Max M <[EMAIL PROTECTED]> wrote:

>> That was also my impression.  Even the description of the
>> problem looks like it's just copied from the assignment, so
>> probably didn't even take the time to restate the problem in
>> his own words.

[...]

> Hopefully his teacher doesn't know about Google, or he can be
> expelled from school for using it.

And there's always the chance the somebody intentionally posted
a wrong answer just to teach somebody a lesson.  I'm not
accusing Max of this, but I've seen it done in the past.

-- 
Grant Edwards   grante Yow!  Yow! I like my new
  at   DENTIST...
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How did you learn Python?

2004-12-03 Thread Rocco Moretti
Shawn Milo wrote:
> How did you learn Python?
>
I was just wondering what the best books were for learning Python.
If you're open to options besides ink-on-tree, this is how I did it:
I read the official tutorial, trying stuff out in the interactive 
interpreter when I didn't get something/had questions. Read the first 
couple of sections of the Library Reference (especially the Built-in 
objects/functions), skimming when you get to those long lists of 
functions/objects. Decided "for language lawyers" was likely a joke; 
read/skimmed the Language Reference (turns out it's half a joke). Then I 
lurked on comp.lang.python.

I've since picked up a few books & looked at highly recommended on-line 
tutorials. For the most part, they mainly repeat the stuff in the 
official documentation and the stuff that isn't in there gets brought up 
on c.l.py eventually. But YMMV, and you may prefer other tutorials to 
the official one.

BTW, I've found the trickiest part of learning python really can't be 
taught in books. I mean, it's stated in the books, but the words don't 
really help. It's understanding the philosophy behind the way Python 
does things, like the object/assignment model and object orientation, 
that's key. This understanding comes from experience, and I think it's 
something we're all still working on.

P.S. I haven't said yet how much I've appreciated the excellent 
documetation the Python crew has put out. It was literally only an 
afternoon before I had completed the tutorial and had a good impression 
of what this "Python thing" was all about. I've since tried to do the 
same with other languages (eg. OCaml & TCL), but haven't had as much 
success. Kudos to Guido, Fred, and the others.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3000 and "Python Regrets"

2004-12-03 Thread TZOTZIOY
On Wed, 01 Dec 2004 15:44:03 -0500, rumours say that Steve Holden
<[EMAIL PROTECTED]> might have written:

>Brad Tilley wrote:

>> How about 'import classic'
>
>... or
>
>from __past__ import __mistakes__

I'll drink to that!

>looking-forwards-to-christmas-ly y'rs  - steve

In the PSU HQ everyday it's Chr
-- 
TZOTZIOY, I speak England very best,
"T!" --Brad Pitt as Achilles in unprecedented Ancient Greek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help on program!!!

2004-12-03 Thread Max M
Dan Perl wrote:
That was also my impression.  Even the description of the problem looks like 
it's just copied from the assignment, so probably didn't even take the time 
to restate the problem in his own words.

But we're speculating.  Either way, this is not a normal request: "I need a 
program to do this, plz help!"  To the OP: you can't seriously expect us to 
actually write the program for you, what kind of help are you looking for?
This?
# -*- coding: latin-1 -*-
"""
  a.. Play a dice game of Craps using a random number generator to simulate
the roll of the dice, the code for the rolling of the dice should take place
in a user written module named rolldice.
  b.. The rules of the game are as follows:
a.. 1st roll, a score of 7 or 11 wins.
b.. 1st roll, a score of 2, 3, or 12 loses.
c.. 1st roll, any number other than those listed above becomes the goal
number, you must keep rolling until you roll the goal number again.  If a 7
is rolled before you goal number, you lose.
"""
import random
def rolldice():
dice1, dice2 = random.randint(1,6), random.randint(1,6)
print dice1, dice2
return dice1, dice2
first1, first2 = rolldice()
first = first1, first2
roll = 1
if first in (7, 11):
print 'Congratulations, you win in roll %s' % roll
elif first in (2,3,7):
print 'Too bad, you loose in roll %s' % roll
result = 'draw'
while result == 'draw':
dice1, dice2 = rolldice()
roll += 1
if dice1 + dice2 == 7:
print 'Too bad, you loose in roll %s' % roll
result = None
elif (dice1, dice2) == (first1, first2):
print 'Congratulations, you win in roll %s' % roll
result = None
Hopefully his teacher doesn't know about Google, or he can be expelled 
from school for using it.

--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


PyQT Licensing and plugins/scripting

2004-12-03 Thread Fabio
Hi all,
I'm about to write an application, and I'd like to use PyQt, but before
choosing this toolkit I would like to clarify some particular licensing
issues; if some user has already touched these, I would like to hear from
his experiences.

This app should be cross-platform, so, given qt licensing policies, I would
buy a commercial PyQt license and a commercial Qt license.

Could I license the application under the GPL for Gnu/Linux and under a
commercial license for Windows and Mac OS X? If this is possible, I guess
that contributions to the GPLed version could not be incorporated in the
commercial version, but this would not be a big problem.

The main issue with licensing is that I would like to give users of the
application a scripting framework (for macros and the like), and eventually
a plugin framework; PyQT redistribution policy states that if an user can
get in touch with PyQT directly it should have a commercial license itself;
how does this apply to those who want to develop commercial PyQT
applications with a plugin/scripting framework?

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


Re: finding byte order

2004-12-03 Thread Scott David Daniels
biner wrote:
>   I am using a program that has to read binary data from files coming
> from different machines. The file are always written with big endian.
Diez B. Roggisch wrote:
 [Scott David Daniels wrote]
How about sys.byteorder?
This doesn't help, as he wants to read files from varying endianess - what
the _current_ endianess is doesn't matter here.
But, in fact, he says the files are always big endian.  So, code like
the following should address his problem.  Note I use type 'h' as an
example so I can easily read samples.
import sys, array
f =open('huge.dat')
v = array.array('h')   # Or whatever data type
v.fromfile(f, 4096)
f.close()
if sys.byteorder == 'little':
v.byteswap()
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythonwin broke

2004-12-03 Thread Trent Mick
Jean Brouwers wrote:
PPS) It looks like Python 2.4 and Python 2.3 can not co-exist (in
different folders under Program Files) but we did not investigate that
any further.
That's not true. I have every version of Python back to 2.0 installed 
and all running fine on my system. Obviously you can only have one of 
your Python installations first on your PATH (and hence the one that 
gets run by simply typing "python"). Also, you can only have one of you 
Python installations registered as the default handler for .py files 
(and hence the one that gets run by simple double-clicking on a .py file 
in explorer or running a Python script without the extension from the 
command line).

It is also possible that there is some little installer bug or detail on 
 your environment that is causing the problem. You could try 
ActivePython. I regularly install and uninstall ActivePython 2.3 and 2.4 
installers and both installs are still working fine.

Cheers,
Trent
--
Trent Mick
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Curses programming, threads?

2004-12-03 Thread Carl Banks
Bartlomiej Rymarski <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> Hello, 
> 
> I'm writing this little program, and I've came across a function
> that I need to call. Since the execution of the function takes a 
> real long time I want to put a timer, or an animated 'loading' 
> screen (it would be best if it was a progressbar). The questions is
> how to make two commands to run at the same time. 
> 
[snip]
>
> It would be best if I could operate with like this:
> 
> #v+
> def function:
>   do loader() while
>   connect_db()
> #v-
> 
> And the loader() function would run in a loop until connect_db() is 
> is finished. Is that possible in python? 

Generally speaking, to do this in C, on Unix, without threads, one
would use the setitimer system call, along with SIGALARM.  (Doubtful
available on all Unices, and there are probably other ways, but I'd
guess this is the most common way to do it.  It is available on Linux;
I've used it before.)  AFAIK, Python does not expose the setitimer
call, so you can't do it that way in Python without writing a C
extension.  (It would be a pretty simple extension to write, though.)

In Python, you could use the signal.alarm() call in much the same way.
 The downside is that you can only update the little animation once
per second.  Something like this could do what you want (untested):

def alarm_handler(*args):
if loaded:
return
update_animation()
signal.alarm(1)

signal.signal(signal.SIGALARM,alarm_handler)
signal.alarm(1)
loaded = False
connect_db()
loaded = True

But I recommend threads for this.  It's one of the easiest possible
uses of threads.  There's no complex communication involved; locks and
semaphores and stuff aren't required.  Just connect to the database in
a subthread, and have it set a global flag just before it exits. 
Animate in a loop in the main thread, checking the flag every
iteration, and when it's true, you're done.


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


Re: Need help on program!!!

2004-12-03 Thread Dan Perl
That was also my impression.  Even the description of the problem looks like 
it's just copied from the assignment, so probably didn't even take the time 
to restate the problem in his own words.

But we're speculating.  Either way, this is not a normal request: "I need a 
program to do this, plz help!"  To the OP: you can't seriously expect us to 
actually write the program for you, what kind of help are you looking for?

Dan

"Miklós P" <[EMAIL PROTECTED]> 
wrote in message news:[EMAIL PROTECTED]
>
> Seems very much like homework to me... ;)  And that's something you are
> supposed to do on your own..
>
> M. 


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


Re: question on regular expressions

2004-12-03 Thread Darren Dale
Michael Fuhr wrote:

> Darren Dale <[EMAIL PROTECTED]> writes:
> 
>> I'm stuck. I'm trying to make this:
>>
>> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C
>> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf
>>
>> (no linebreaks) look like this:
>>
>> ./mydoc1.pdf,./mydoc2.pdf
>>
>> my regular expression abilities are dismal.
> 
> This works for the example string you gave:
> 
> newstring = re.sub(r'[^,]*%5[Cc]', './', examplestring)
> 
> This replaces all instances of zero or more non-commas that are
> followed by '%5C' or '%5c' with './'.  Greediness causes the pattern
> to replace everything up to the last '%5C' before a comma or the
> end of the string.
> 
> Regular expressions aren't the only way to do what you want.  Python
> has standard modules for parsing URLs and file paths -- take a look
> at urlparse, urllib/urllib2, and os.path.
> 

Thanks to both of you. I thought re's were appropriate because the string I
gave is buried in an xml file. A more representative example is:

[...snip...]file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf[...snip...
data]file://C%5Cfolderx%5Cfoldery%5Cmydoc2.pdf[...snip...]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding byte order

2004-12-03 Thread Jp Calderone
On Fri, 03 Dec 2004 19:19:48 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> 
wrote:
>>   I would like to have a test to tell me if the current machine is
   ^^^
> > using big or small endian, this way I could use the array module in
> > the first case and the *slower* struct module on the second. I looked
> > but did not find. Is there a python function to know that?
> 
> There is no such test, as it's domain-specific if there _can_ be such a test
> or not. If your data is composed in a way that you can infer the endianess
> by reading e.g. a header at the beginning that has well-known fields, then
> it might work. But only you can do that.
> 
> For a pure binary file, there is absolutely no way of telling the endianess.

  I think you misread the question.

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


Re: question on regular expressions

2004-12-03 Thread Michael Fuhr
Darren Dale <[EMAIL PROTECTED]> writes:

> I'm stuck. I'm trying to make this:
>
> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C
> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf
>
> (no linebreaks) look like this:
>
> ./mydoc1.pdf,./mydoc2.pdf
>
> my regular expression abilities are dismal.

This works for the example string you gave:

newstring = re.sub(r'[^,]*%5[Cc]', './', examplestring)

This replaces all instances of zero or more non-commas that are
followed by '%5C' or '%5c' with './'.  Greediness causes the pattern
to replace everything up to the last '%5C' before a comma or the
end of the string.

Regular expressions aren't the only way to do what you want.  Python
has standard modules for parsing URLs and file paths -- take a look
at urlparse, urllib/urllib2, and os.path.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding byte order

2004-12-03 Thread Diez B. Roggisch
>   I would like to have a test to tell me if the current machine is
> using big or small endian, this way I could use the array module in
> the first case and the *slower* struct module on the second. I looked
> but did not find. Is there a python function to know that?

There is no such test, as it's domain-specific if there _can_ be such a test
or not. If your data is composed in a way that you can infer the endianess
by reading e.g. a header at the beginning that has well-known fields, then
it might work. But only you can do that.

For a pure binary file, there is absolutely no way of telling the endianess.
-- 
Regards,

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


Re: Need help on program!!!

2004-12-03 Thread Miklós P

"Darth Haggis" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I need help writing a program
>
> You are to write a python program to accomplish the following:
>
...
>
>
> Haggis
>

Seems very much like homework to me... ;)  And that's something you are
supposed to do on your own..

M.


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


RE: Need help on program!!!

2004-12-03 Thread Batista, Facundo
Title: RE: Need help on program!!!





[Darth Haggis]


#- I need help writing a program
#- 
#- You are to write a python program to accomplish the following:


Actually, your homework is *your* homework.


Regards,


.   Facundo



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

Re: finding byte order

2004-12-03 Thread Diez B. Roggisch
> How about sys.byteorder?

This doesn't help, as he wants to read files from varying endianess - what
the _current_ endianess is doesn't matter here.

-- 
Regards,

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


Need help on program!!!

2004-12-03 Thread Darth Haggis
I need help writing a program

You are to write a python program to accomplish the following:



  a.. Play a dice game of Craps using a random number generator to simulate
the roll of the dice, the code for the rolling of the dice should take place
in a user written module named rolldice.
  b.. The rules of the game are as follows:
a.. 1st roll, a score of 7 or 11 wins.
b.. 1st roll, a score of 2, 3, or 12 loses.
c.. 1st roll, any number other than those listed above becomes the goal
number, you must keep rolling until you roll the goal number again.  If a 7
is rolled before you goal number, you lose.


Make the game continuous, until you tell it to stop.  You can bet the same
amount, or change you bet after each win or loss.  Print the results of each
roll and the running total of winnings or loses.



plz help!!!



Haggis



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


RE: question on regular expressions

2004-12-03 Thread Robert Brewer
Darren Dale wrote:
> I'm stuck. I'm trying to make this:
> 
> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C
> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf
> 
> (no linebreaks) look like this:
> 
> ./mydoc1.pdf,./mydoc2.pdf

Regular expressions are much easier to write when you only have to worry
about single characters. So the first step might be to replace all of
the %5C's with \:

>>> a
'file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C%5Cfolderx%5Cfoldery
%5Cmydoc2.pdf'
>>> a = a.replace("%5C", "\\")
>>> a
'file://C:\\folder1\\folder2\\mydoc1.pdf,file://C\\folderx\\foldery\\myd
oc2.pdf'


Then you can use something like:

>>> re.findall(r"([^\\]*\.[^,]*)(?:,|$)", a)
['mydoc1.pdf', 'mydoc2.pdf']

...or Sean Ross' suggestion about urllib.


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Few things

2004-12-03 Thread Scott David Daniels
Josiah Carlson wrote:
An option if you want to get all of the base representations available
is a prefix notation that is similar to what already exists.  I'm not
advocating it (because I also think its crap), but the following fixes
the problems with your postfix notation, and is explicit about bases.
0_
like:
016_feff
02_10010010101
010_9329765872
08_767
The above syntax is:
1. unambiguous
2. readable from left-to-right
I built an interpreted language where based numbers were of the form:
   ..
It has 1 & 2, can often be snagged from standard lexers, and keeps _
available for group-separator (for things like 1_000_000_000).
The nice thing is that it is unambiguous no matter what base you
read in.  It also worked for floating point values, but we were never
happy with how the exponent should be done.
f..feff == 1.._1110__
== 1..1_111_111_011_111_111 == 7..77377
1..10010010101
9..9329765872
7..767
Takes a bit to associate 9 with base ten, but lexing the number is
duck soup.  Note I am not advocating this syntax any more than Josiah
is advocating his.  I just find alternate representations interesting.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: question on regular expressions

2004-12-03 Thread Sean Ross
"Darren Dale" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm stuck. I'm trying to make this:
>
> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C
> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf
>
> (no linebreaks) look like this:
>
> ./mydoc1.pdf,./mydoc2.pdf
>
> my regular expression abilities are dismal. I won't list all the
> unsuccessful things I've tried, in a nutshell, the greedy operators are
> messing me up, truncating the output to ./mydoc2.pdf. Could someone offer
a
> suggestion?
>
> Thanks,
> Darren

from os.path import basename
import urllib

url = 'file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf'
print './%s'%basename(urllib.url2pathname(url))

HTH,
Sean



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


Re: How did you learn Python?

2004-12-03 Thread Harry George
"Shawn Milo" <[EMAIL PROTECTED]> writes:

> I was just wondering what the best books were for learning Python.
> 
> Which books are good for getting started, and which should be saved for
> later, or or not useful except as a reference for the learned?
> 
> I have a decent programming background in VB, JavaScript, VBScript,
> Net.Data (IBM's macro language), regular expressions, and a teensy bit of
> Perl. My point is, I don't want something that is going to explain the basic
> programming concepts, but does give a good introduction to Python-specific
> things. Then, once I know how to get the job done, I would like a good book 
> or two at the intermediate to advanced level, to learn how to write really 
> good code.
> 
> I understand that resources such as this list and Google searches have all 
> the answers,
> but it seems like a more structured tool, such as a book or formal class, 
> would be
> of great benefit to me. The other languages I have used were picked up 
> because of the
> need to get a job done. As a result, I am able to get the job done, but any 
> experienced
> coder can show me six more efficient ways to do what I'm doing. I'm new to
> Python, and I want to do this one right. I believe that Python will be
> around for a good, long time, and it matches my values as an Open-Source/Linux
> supporter, while having relevance in the Windows and Mac world, as well. 
> Plus, it looks like it was designed extremely well, and I'm excited about the 
> principles I've read about.
> 
> Thanks,
> Shawn


For those who already know scripting, Beazley's "Python Essential
Reference" is great.  It *briefly* shows you how to do in python what
you already know how to do elsewhere.  Other people tell me
"Essential" is too terse for learning and they are more comfortable
with Quick Python or Learning Python.

For more idioms and design patterns, see the Python Cookbook for
specific tasks, and then read the "example" or "sample" code with the
various add-on modules you happen to install.

For day in and day out reference, have the python html documentation
on your machine and a bookmark to it.  Then read the "Library
Reference" whenever you need to remember the semantics/syntax of a
feature.

-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert !

2004-12-03 Thread Lonnie Princehouse
> bou_asia=Button(fen1, text='Asia',\
>command=rings(size=41, offsetX=50,offsetY=22, 
> coul='yellow'))

You're calling the rings function when you create the button.

What you really want is for "command" to be a callable object
that the button will invoke when it's clicked, e.g.:

def mycallback():
  print 'click'

mybutton = Button(parent, text='a button', command = mycallback)

Notice that there are no parentheses after mycallback -- it's not
being called, but the function itself is being passed as an argument.

In your case, you need to find a way to pass arguments to rings, so
you'll have to curry the function.  Here's one way to do it:

def rings_callback(**keywords):
# return an anonymous function that calls rings when invoked.
return lambda k=keywords: rings(**k)

bou_asia = Button(fen1, text='Asia',
   command=rings_callback(size=41, offsetX=50,offsetY=22,
coul='yellow'))

Hope that helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >