Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Gregor Horvath
Paul Rubin schrieb:

 
 Huh?  If my car has a feature that lets someone blow it to
 smithereens from hundreds of miles away without even intending to,
 that's somehow an advantage?

I would not accept a car that does constraint my driving directions. I 
want to drive for myself, because its fun.

 
 No problem, but any decision like that should be expressed in
 writing, by re-declaring the variable so it's no longer private.

Remember, its Python not Java.
Tastes are different and so are programming languages, but please do not 
make Python to a Java Clone.

I love python because of its simplicity, freedom, power and because its 
fun to program.
One reason is that it does not restrict the programer to tight und has 
genuine simple solutions, like the one with private instance variables.

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


Re: 1 Million users.. I can't Scale!!

2005-09-29 Thread simonwittber
yoda wrote:
 I'm considering moving to stackless python so that I can make use of
 continuations so that I can open a massive number of connections to the
 gateway and pump the messages out to each user simultaneously.(I'm
 thinking of 1 connection per user).

This won't help if your gateway works synchronously. You need to
determine what your gateway can do. If it works asynchronously,
determine the max bandwidth it can handle, then determine how many
messages you can fit into 4 seconds of that bandwidth. That should
provide you with a number of connections you can safely open and still
recieve acceptable response times.

 My questions therefore are:
 1)Should I switch to stackless python or should I carry out experiments
 with mutlithreading the application?

You will build a more scalable solution if you create a multi process
system. This will let you deploy across multiple servers, rather than
CPU's. Multithreading and Multiprocessing will only help you if your
application is IO bound.

If your application is CPU bound, multiprocessing and multithreading
will likely hurt your performance. You will have to build a parallel
processing application which will work across different machines. This
is easier than it sounds, as Python has a great selection of IPC
mechanisms to choose from.

 2)What architectural suggestions can you give me?

Multithreading will introduce extra complexity and overhead. I've
always ended up regretting any use of multithreading which I have
tried. Avoid it if you can.

 3)Has anyone encountered such a situation before? How did you deal with
 it?

Profile each section or stage of the operation. Find the bottlenecks,
and reduce it whichever way you can. Check out ping times. Use gigabit
or better. Remove as many switches and other hops between machines
which talk to each other.

Cache content, reuse it if you can. Pregenerate content, and stick it
in a cache. Cache cache cache! :-)

 4)Lastly, and probably most controversial: Is python the right language
 for this? I really don't want to switch to Lisp, Icon or Erlang as yet.

Absolutely. Python will let you easily implement higher level
algorithms to cope with larger problems.

Sw.

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


Re: 1 Million users.. I can't Scale!!

2005-09-29 Thread yoda
1. How are you transmitting your SMSs?
Currently, a number of different gateways are being used: 2 provide a
SOAP web service interface, 1 other provides a REST based web service.

A transaction using the SOAP web services takes 3-5 seconds to complete
(from the point of calling the method to receive an error\success
confirmation)
The REST web service transaction takes 1 second or less to complete.

 2. If you disable the actual transmission, how many SMSs can your
application generate per second?
Currently, the content is generated and a number of SMS per user are
generated. I'll have to measure this more accurately but a cursory
glance indicated that we're generting approximately 1000 sms per
second. (I'm sure this can't be right.. the parser\generator should be
faster than that:)

Additionally, I've just confirmed that the gateway's we use can pump
out 20-100 sms's per second. This is currently too slow and we'll
probably get direct access to the mobile operator's SMSC which provides
larger throughput

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


Mails not receiving from techint.com.bh domain

2005-09-29 Thread AAR
When the users of techint.com.bh send me mails to my Yahoo ID, 
they are receiving bounce-back error msg as below:

recipient was unavailable to take delivery of the message

to any Yahoo IDs.

Please explain - why they are getting this errors.

Regards,
Anees



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


duplicate entries

2005-09-29 Thread jackie chang

Dear Python Gurus:

I am a very new Python user, would really appreciate your help. 

I used Python to write a web form for users to enter. The underlined database is Oracle. One validation needs to enforce to eliminate duplicates entries. For example: one customer ID can only be entered onlyone time from the website, if a duplicate customer ID is attempted to enter, a message should pop back to inform the user about the invalid entry. I am enforcing primary key in the underlined Oracle table

How can I code in python make this happen and get the message posted? 

Your assistance is highly appreciated. 


		Yahoo! for Good 
Click here to donate to the Hurricane Katrina relief effort. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Strange Extension Module Behavior

2005-09-29 Thread Jeremy Moles
Hey guys. I have an extension module written in C that abstracts and
simplifies a lot of what we do here. I'm observing some strange behavior
and wanted to know if anyone had any advice as to how I should start
tracking this down. More specific suggestions are obviously appreciated,
but I really don't have a lot of information to provide so I'm not
hoping for a lot. :)

The module works 100% of the time if I run it non-interactively.
However, any attempt to run it in the interactive python interpreter
fails, in some cases silently and in other cases raising exceptions that
really shouldn't be appearing.

Anyways, I guess the core issue here is:

   What could cause an extension module to work within a script
   and not interactively? Are there fundamental issues with the
   standard Python infrastructure I'm not grasping?

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Paul Rubin
Gregor Horvath [EMAIL PROTECTED] writes:
 One reason is that it does not restrict the programer to tight und has
 genuine simple solutions, like the one with private instance
 variables.

If you don't want the compiler to make sure your private instance
variables stay private, then don't declare them that way.  You're the
one asking for less flexibility.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Kay Schluehr

Steve Holden wrote:
 could ildg wrote:
  Python is wonderful except that it has no real private and protected
  properties and methods.
  Every py object has dict so that you can easily find what fields and
  methods an obj has,
  this is very convenient, but because of this, py is very hard to support
  real private and
  protected?
  If private and protected is supported, python will be perfect.
 
 You only say that because you assume private and protected give you a
 security that they actually don't. They certainly make it more difficult
 to *spot* the security errors.

Honestly I like to use private/protect/public modifiers in C++ for the
sake of code documentation. I like to know which attributes are
dedicated to be known by other objects, which ones are for internal use
only and which ones should be at least publicly accessible within a
class hierarchy. This helps structuring code in the large and spotting
attention. Code becomes easier accessible. But if we have Sunday or I
get asked by serious programmers I also know the right technical
answers about protection rights, security etc.

Kay

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


Re: 1 Million users.. I can't Scale!!

2005-09-29 Thread Paul Rubin
yoda [EMAIL PROTECTED] writes:
 Currently, the content is generated and a number of SMS per user are
 generated. I'll have to measure this more accurately but a cursory
 glance indicated that we're generting approximately 1000 sms per
 second. (I'm sure this can't be right.. the parser\generator should be
 faster than that:)

Don't be sure.  Try some profiling, and maybe Psyco, C extensions,
etc.  Python is many things but it's not terribly fast at
interpreting.  It sounds like you have more bottlenecks than just the
python app though, starting with the SMS gateway issue that you just
mentioned.  If you get more gateway bandwidth and your application can
split across multiple boxes, then the simple short-term fix is buy
more boxes.  Longer term you need to re-examine the sw architecture
and possibly make changes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 1 Million users.. I can't Scale!!

2005-09-29 Thread yoda
Thanks for the whitepapers and incredibly useful advice.  I'm beginning
to get a picture of what I should be thinking about and implementing to
achieve this kind of scalability.  Before I go down any particular
route here's a synopsis of the application.

1)User requests are received only during subscription.  We currently
don't have any problems with this because subscription rates increase
along a  sigmoid curve.

2)Once a user subscribes we begin to send them content as it becomes
available.

3)The content is sports data. Content generation is dependent on the
day. On days when there's a lot of action, we can generate up to 20
separate items in a second every 10 minutes.

4)The content is event driven e.g. a goal is scored. It is therefore
imperative that we send the content to the subscribers within a period
of 5 minutes or less.

There is a difference between one million users each who make one request once 
a month, and one million users who are each hammering the system with ten 
requests a second. Number of users on its own is a meaningless indicator of 
requirements.
Quite true and this lack of clarity was a mistake on my part.  Requests
from users do not really become a significant part of this equation
because, as described above, once a user subscribes the onus is upon us
to generate messages throughout a given period determined by the number
of updates a user has subscribed to receive.

5)Currently, hardware is a constraint (we're a startup and can't afford
high end servers). I would prefer a solution that doesn't have to
result in any changes to the hardware stack. For now, let's assume that
hardware is not part of the equation and every optimization has to be
software based. (except the beautiful network  optimizations suggested)

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


Re: What does pygame.Movie mean by `an MPEG file'?

2005-09-29 Thread Kilian A. Foth
Christophe [EMAIL PROTECTED] wrote:
 Kilian A. Foth a écrit :
  I just found this amazing video puzzle game written with the pygame
  library, which promises to be infinite fun - but I can't get it to
  decode any video file I own, except the game's own example .mpg. All I
  have is lots and lots of useless .avi, .mp2, .wmv, and so on...
  
  Now, the pygame.Movie documentation says the Movie class can decode
  `MPEG movie files'. I know little about multimedia, but I thought
  divx/xvid video was a variant of MPEG4, and mp3 audio a variant of 
  MPEG1 Layer 3. So obviously, `MPEG movie files' means something more
  specific than just `contains MPEG streams'. Does anyone know what
  precisely it means? Even better, how should I instruct transcode or
  similar programs to re-encode existing files so that Movie objhects
  can be created from them?

 An mpeg file is a file with the .mpg or .mpeg extension. IIRC, it's a 
 raw mpeg 1 or 2 stream dumped in a file. Not sure about the raw stream 
 but I'm sure it can only be mpeg 1 or 2.

Alright, several tries later I now know the pygame accepts only MPEG
program stream containers, with MPEG1 video and MPEG2 audio. I found
that the command 

  mencoder -of mpeg -ovc lavc -oac lavc \
   -lavcopts acodec=mp2:vcodec=mpeg1video:vbitrate=5000 -o new.mpg old.avi

successfully creates such files. I'm off to play video puzzle now!


-- 
No animal was harmed in the composition of this message.

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


c/c++ and python

2005-09-29 Thread Mattia Adami
Hi to all!
I have a little problem. I want to develop an application in c/c++ that
creates a window with gtk+ accordinly to the information on a xml file.
The funcions that are called for manage the event should be written in
python. I don't know how to do it, can you help me? Is it possible?
Thanks a lot!

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


Re: Spoiler to Python Challenge (help!!!)

2005-09-29 Thread Ian Vincent
Terry Hancock [EMAIL PROTECTED] wrote in 
news:[EMAIL PROTECTED]:
 
 bz2.decompress(eval('' + user + ''))
 
 Sorry about that.  I was trying the other as an alternative,
 but in fact, it doesn't work.  So ignore that.

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


Re: c/c++ and python

2005-09-29 Thread Alessandro Bottoni
Mattia Adami wrote:

 Hi to all!
 I have a little problem. I want to develop an application in c/c++ that
 creates a window with gtk+ accordinly to the information on a xml file.
 The funcions that are called for manage the event should be written in
 python. I don't know how to do it, can you help me? Is it possible?
 Thanks a lot!

Yes, it is possible. Most likely, you will have to embed a Python
interpreter in your app. Have a look at the ExtendingEmbedding section of
the Python manual.

As an alternative, you can use your C++ code as an extension of Python (a
module). Again, have a look at the ExtendingEmbedding section of the
Python manual.

BTW: are you aware of the existence of PyGTK and wxPython?

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


Documenting members

2005-09-29 Thread Lasse Vågsæther Karlsen
I have a Connection class that exposes members for the hostname, etc.

ie.

class Connection:
 def __init__(...):
 self.server = server

is there any way to document this server member? The only way I know 
of right now is to expose it as a property and add the doc string to 
that definition.

I've tried finding an example in the lib code installed with Python but 
can't seem to track down anything that is documented like that.

-- 
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[EMAIL PROTECTED]
PGP KeyID: 0x2A42A1C2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Paul Rubin
Dennis Lee Bieber [EMAIL PROTECTED] writes:
   Ah, but in the way of your code -- it is not your car... It is the
 car you supplied to someone hundreds of miles away... And they are
 perfectly free to open the hood... tamper with the engine programming, etc.

I don't understand what you're getting at.  If they're free to edit
the code, then why should they complain about private variables?  They
can change the declaration if they need to.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: c/c++ and python

2005-09-29 Thread Mattia Adami
Thanks a lot, very clear and usefull anser!

Yes, I know PyGTK and wxPython, but I want to develop a plugin for
another application that requires c++. I guess that embedding is the
appropriate way.

Thanks.

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


Re: Telephony project

2005-09-29 Thread Roger
 Thanks for all the helpful postings!  A clearer specification for
my project is that the CALLER speaks directly to list_member.  And
enters, thru GUI checkbox(s), answering: r_u_ok?; Send chuch member to
visit list_member; call Social Worker, help needed, etc. An important
element is to verify that the elderly member has been called.  When,
and by whom.  And if additional care, contact is needed.
 After reading replys I think I can do all Python work.  I'm
looking at pySerial to manage the phone calls.The s/w needs to be
GUI, ez to use (elderly volunteers) and work on donated (read 'old')
hardware.  Thank you all for your advice, pointers, and suggestions.  rm

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Gregor Horvath
Paul Rubin schrieb:
 
 If you don't want the compiler to make sure your private instance
 variables stay private, then don't declare them that way.  You're the
 one asking for less flexibility.  

I want to declare them as privat, but want to give the flexibilty to 
access them at the users own risk.

Declaring everything as public is nonsene, because there should be a 
garanteed stable interface.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Paul Rubin
Gregor Horvath [EMAIL PROTECTED] writes:
  If you don't want the compiler to make sure your private instance
  variables stay private, then don't declare them that way.  You're the
  one asking for less flexibility.
 
 I want to declare them as private, but want to give the flexibilty to
 access them at the users own risk.

What else do you want to let users do at their own risk?  Treat
integers as pointers, like in C?  Both are violations of type safety.

 Declaring everything as public is nonsene, because there should be a
 garanteed stable interface.

You could have a friend declaration like in C++, if you want to let
some class see the private instance variables of another class.  

I can't think of a single time that I've ever seen a legitimate use of
name mangling to reach from one class into another in a Python
application (I don't count something like a debugger).  If you're got
some concrete examples I wouldn't mind looking.
-- 
http://mail.python.org/mailman/listinfo/python-list


A quick c.l.p netiquette question

2005-09-29 Thread Peter Corbett
I've written a program to illustrate a few... syntactic issues with
Python. It's 158 80 character lines long.

About how short should a program be to be postable to this newsgroup -
in other words, at what length should you stick it on a web page and
post a link?

Peter

-- 
A frightful hobgoblin is stalking throughout Europe.
 - The Communist Manifesto, 1st English Edition
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: byte code generated under linux == bad magic number under

2005-09-29 Thread skip

Fredrik byte code is portable between platforms, but it's not portable
Fredrik between different major Python releases (2.4.2 can run 2.4.1
Fredrik bytecodes, but not 2.3 bytecodes, etc).

There is one slight problem with transporting .pyc files.  The generated
.pyc file records the absolute path to the .py file from which it was
generated.  If it is moved to a different filesystem -- even if the .py file
goes along for the ride -- tracebacks display an incorrect path and fail to
display the corresponding source line.

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread skip

Peter About how short should a program be to be postable to this
Peter newsgroup - in other words, at what length should you stick it on
Peter a web page and post a link?

158 lines is probably not a killer.  However, consider what misbehaving news
and mail readers are likely to do to the indentation of your script before
embedding it in a message.  The net being the somewhat less safe place than
it used to be, many people may be hesitant to open attachments either.  It
might well be safer to simply toss it on a personal website and provide a
link.

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


A rather unpythonic way of doing things

2005-09-29 Thread Peter Corbett
One of my friends has recently taken up Python, and was griping a bit
about the language (it's too prescriptive for his tastes). In
particular, he didn't like the way that Python expressions were a bit
crippled. So I delved a bit into the language, and found some sources
of syntactic sugar that I could use, and this is the result:

http://www.pick.ucam.org/~ptc24/yvfc.html

Peter

-- 
A frightful hobgoblin is stalking throughout Europe.
 - The Communist Manifesto, 1st English Edition
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread en.karpachov
On Wed, 28 Sep 2005 08:14:50 -0500
Chris Gonnerman wrote:

 There are two philosophies about programming:
 
 -- Make it hard to do wrong.
 
 -- Make it easy to do right.
 
 What you are promoting is the first philosophy: Tie the programmer's
 hands so he can't do wrong.  Python for the most part follows the
 second philosophy,

So it is for the very this reason there is no assignment operator in the
Python?

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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle

[Peter]
 http://www.pick.ucam.org/~ptc24/yvfc.html

Beautiful!  Greenspun's Tenth Rule[1] performed before your very eyes!  (Not
quite, because you started with Python so you were already half way there.
And yours probably isn't buggy.  8-)

[1] http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A quick c.l.p netiquette question

2005-09-29 Thread Peter Corbett
[EMAIL PROTECTED] writes:
 
 Peter About how short should a program be to be postable to this
 Peter newsgroup - in other words, at what length should you stick it on
 Peter a web page and post a link?
 
 158 lines is probably not a killer.  However, consider what misbehaving news
 and mail readers are likely to do to the indentation of your script before
 embedding it in a message.  The net being the somewhat less safe place than
 it used to be, many people may be hesitant to open attachments either.  It
 might well be safer to simply toss it on a personal website and provide a
 link.

Good advice, but in this case indentation isn't as important as
usual. Still, I like to keep a little formatting for readability.

Thanks,

Peter

-- 
A frightful hobgoblin is stalking throughout Europe.
 - The Communist Manifesto, 1st English Edition
-- 
http://mail.python.org/mailman/listinfo/python-list


PDF Viewer

2005-09-29 Thread Pepe Pena

I am new to programming and need some guidance on the development of the following application. The proposed application will display two pdf documents simultaneously to be viewed and simple navigation will be facilitated (i.e. turning pages). 

Furthermore, the pdf documents must be linked to one another. If a particular page is viewed in one document, the second document will display a specific page.

Can anyone please provide any assistance or comments on how I should proceed to create the mentioned application using Python within the windows environment, thank you.
		Yahoo! for Good 
Click here to donate to the Hurricane Katrina relief effort. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Gregor Horvath
Paul Rubin schrieb:
 
 You could have a friend declaration like in C++, if you want to let
 some class see the private instance variables of another class.  

Everything is said on this topic. There are two ligitimate solutions to 
the problem of private instance variables. Its a matter of taste, and 
mine is the pythonic one.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Paul Rubin
Gregor Horvath [EMAIL PROTECTED] writes:
 Everything is said on this topic. There are two ligitimate solutions
 to the problem of private instance variables. Its a matter of taste,
 and mine is the pythonic one.

The Pythonic solution is to have both solutions available, and Python
in fact used to have both (name mangling and the Bastion class).  But
Bastion turned out not to work, and it's not easy to fix that under
CPython, so it was removed.  Now the Bastion class is gone, and only
name mangling is left.  Maybe Bastion can come back under Pypy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Paul Rubin
Peter Corbett [EMAIL PROTECTED] writes:
 http://www.pick.ucam.org/~ptc24/yvfc.html
 

Madness!  I love it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope3 Examples?

2005-09-29 Thread bruno modulix
Markus Wankus wrote:
 Hi All,
 
 Does anyone know of any good Zope3 examples?  

Ask the Zope mailing-list. Zope is a world by itself, and is usually not
discussed here.

BTW, Zope3 is a really really new thing, so you won't find much existing
apps. When it's said that it offers 'the best from Plone', (s/plone/cmf/
IMHO), it's about framework/system architecture, not OOTB application.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another time challenge

2005-09-29 Thread Eddie Corns
[EMAIL PROTECTED] writes:

Hey there pythoneers

i have another question about time, specifically, the mxDateTime
module.
i have been able to get a RelativeDateTimeDiff between two times,
it gives me a difference between two DateTimes in the form of +3days
+2hours etc...

so, if i have a date that is 6 days and 6 hours from another day,
it will give me Days+6, hours+5.

what i need is something like 6.4 days or close to it.
is there an easy way to convert this ?

if not i can write up something to do the math.

i guess i am just looking for a cleaner shortcut.

You could extract the hours,mins,secs part to a DateTimeDelta which supports
float() and just divide that into 86400.0.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steve Holden
Paul Rubin wrote:
 Gregor Horvath [EMAIL PROTECTED] writes:
 
If you don't want the compiler to make sure your private instance
variables stay private, then don't declare them that way.  You're the
one asking for less flexibility.

I want to declare them as private, but want to give the flexibilty to
access them at the users own risk.
 
 
 What else do you want to let users do at their own risk?  Treat
 integers as pointers, like in C?  Both are violations of type safety.
 
 
Declaring everything as public is nonsene, because there should be a
garanteed stable interface.
 
 
 You could have a friend declaration like in C++, if you want to let
 some class see the private instance variables of another class.  
 
 I can't think of a single time that I've ever seen a legitimate use of
 name mangling to reach from one class into another in a Python
 application (I don't count something like a debugger).  If you're got
 some concrete examples I wouldn't mind looking.

[psst ... do you think they've stopped now?]
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.pycon.org

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


Re: duplicate entries

2005-09-29 Thread Steve Holden
jackie chang wrote:
 Dear Python Gurus:
 
  
 
 I am a very new Python user, would really appreciate your help.
 
  
 
 I used Python to write a web form for users to enter. The underlined 
 database is Oracle. One validation needs to enforce to eliminate 
 duplicates entries. For example: one customer ID can only be entered 
 only one time from the website, if a duplicate customer ID is attempted 
 to enter, a message should pop back to inform the user about the invalid 
 entry. I am enforcing primary key in the underlined Oracle table
 
  
 
 How can I code in python make this happen and get the message posted?
 
  
 
 Your assistance is highly appreciated.
 
There are many web frameworks and tools for interacting with databases 
on the web. Try a look through the just over eight million hits in

http://www.google.com/search?hl=enlr=q=python+web+database

(hint: the first two or three pages will be the best. Look for books by 
people whose names seem familiar :-).

Some of those links will contain real examples of code and give you a 
useful idea of how some things can be done. Others will doubtless post 
more specific advice, so I am trying to provide a little background in 
case it should be needed.

More specific (Google) searches will also give insights into different 
aspects of this problem.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.pycon.org

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Peter Hansen
Peter Corbett wrote:
 I've written a program to illustrate a few... syntactic issues with
 Python. It's 158 80 character lines long.
 
 About how short should a program be to be postable to this newsgroup -
 in other words, at what length should you stick it on a web page and
 post a link?

Does it really have to be 158 lines to demonstrate these few issues?  I 
for one almost never take the time to dig through 158 lines of someone 
else's code, partly on the assumption that almost any interesting issue 
can be covered (using Python, specifically) in about a dozen lines of 
code.  YMMV

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


Re: Will Python Be Good For This Type Of Project?

2005-09-29 Thread Steve Holden
Hal Vaughan wrote:
 I'm self taught and most of what I've been working on for the past several
 years has been entirely in Perl and Java.  I've noticed that I can code
 about 5 times faster in Perl than Java, in part because I feel like
 whenever I want to do something in Java, I have to create an object, do a
 few preperatory things, then do what I need, but in Perl, I just call the
 routine.
 
 Java, however, does much better at cross platform apps, especially if I need
 a GUI (I find Swing easy to use).   I need to write a setting editor which
 basically consists of a GUI with a lot of checkboxes, radio buttons, and
 option select lists.  I originally had something to do this in Javascript,
 but Javascript was not strong enough to let me create data structures to
 keep track of the data.  I had to store it in 3d arrays, which was hard to
 keep up with.
 
If you find Swing interfaces easy to build ans use then Jython should be 
a natural: you can do all the GUI stuff in Java and control it from 
Jython, thereby neatly avoiding yet another potential What's the best 
GUI toolkit [answer: same place as the world's best hamburger].

 I was planning on writing the new setting editor in Java for several
 reasons, including the ability to create my own objects to store groups of
 settings.  I also can write it so it'll run on a computer by itself, or as
 an applet with very little extra work.  That's a benefit, since it means it
 can be run from anywhere through a Java enabled browser and a username and
 password.  It can also be run on a system where it's been installed without
 using a browser (either way, it reads and writes the settings from a URL).
 
Java does have the advantage when it comes to dynamic clients right now, 
given that the Python virtual machine can't be assumed to be available 
in the browser environment.

 Someone on a mailing list I'm on has suggested that I look into Python, and
 use Jython to compile it.  I see that I can write applications and applets
 in Python (but I haven't seen references to being able to write one
 application just once and have it work as both).  I also know Python is a
 higher level than Java (a few people I know say it's almost like writing
 pseudo code).
 
I have been known to provoke people by calling Java object-oriented 
COBOL, but if you're happy with Java you might find Python a bit terse, 
and be a bit nervous about it's apparently happy-go-lucky attitude to 
namespace protection.

If you like to be able to easily mix procedural and object-oriented 
approaches then I think you might want to give Python a try.

 At this time I don't know Python (I've looked at some sample code and I'm
 still getting used to loops and if statements without closing braces!). 
 What I'm trying to determine is 1) if it's relatively easy to write a
 program to work as an application AND an applet (depending on how it's
 called), 2) If it'll handle the networking to read what amounts to web
 pages full of setting info and write that back in POST statements without
 problems from the user's point of view and easily from the programmer's
 point of view, 3) What coding time and difficulty is like in Python
 compared to, most specifically, Java and Perl, 4) Is it easy for me to
 interface Java and Python classes seamlessly, and 5) (I realize only I can
 answer this for sure, but opinions and experience of others would be a
 help!) Is Python easy enough and fast enough to code in that it'd be worth
 me taking time to learn it and doing the project Python instead of Java?
 
1) You'll need advice about applet from someone more versed in Jython 
than I.

2) Definitely no problems in the networking department

3) Not as terse as Perl, somewhat faster than Java would be my opinion, 
but I'm only one data point. I found the verbiage of common Java idioms 
irritating, there's nothing like that with Python.

4) Yes.

5) You should learn a new language now and then just to stay in practice 
and get in touch with newer ideas. Python isn't that hard for a Java 
programmer to learn, though naturally there are differences. The two 
languages in combination should give everyone what they want (though of 
course there are always some people who just want to complain about he 
way things are).

 Any help, thoughts, comments, and such are appreciated!
 
 Thank you!
 
 Hal 

Some of each to get you going. I hope this has helped.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.pycon.org

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Fredrik Lundh
Peter Hansen wrote:

 Does it really have to be 158 lines to demonstrate these few issues?  I
 for one almost never take the time to dig through 158 lines of someone
 else's code, partly on the assumption that almost any interesting issue
 can be covered (using Python, specifically) in about a dozen lines of
 code.

did you click on the link he posted a little later?

 YMMV

no, YVFC.

/F 



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


Re: Zope3 Examples?

2005-09-29 Thread Markus Wankus
bruno modulix wrote:
 Markus Wankus wrote:
 Hi All,

 Does anyone know of any good Zope3 examples?  
 
 Ask the Zope mailing-list. Zope is a world by itself, and is usually not
 discussed here.
 
 BTW, Zope3 is a really really new thing, so you won't find much existing
 apps. When it's said that it offers 'the best from Plone', (s/plone/cmf/
 IMHO), it's about framework/system architecture, not OOTB application.
 

Will do - thanks for the info.

Yeah - I was wondering if that's what 'the best from Plone' meant after 
I installed it - however there seem to be a lot of Plone people with 
their backs up over Zope3 moving in on their territory.  If it doesn't 
do all the cool GUI stuff (yet) I would think it could only be good for 
Plone to move to Zope3 as well.  It would only make it faster and more 
lightweight.  Ah well - off to the Zope mailing list.

FWIW - I shuddered at all the different Python web frameworks out there 
and I didn't want to get into coding a site right away.  However - it 
looked like I didn't have much choice so I figured if I was going to do 
it I may as well go whole hog and jump into the uber-framework that is 
Zope.  Perhaps I should give my head a shake and try out a nice, simple 
alternative first.  I have a feeling I'll be trying out Snakelets.  I 
really like the idea of a self-contained webserver that is 
super-lightweight.

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Richie Hindle

[Peter]
 Does it really have to be 158 lines to demonstrate these few issues?

I think you missed the other Peter's second post, where he points to his
program: http://www.pick.ucam.org/~ptc24/yvfc.html

I didn't read every one of his 158 lines, but his code is pure poetry, or
possibly triple-distilled evil, depending on your point of view.  158 lines
very well spent either way!

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documenting members

2005-09-29 Thread Miki Tebeka
Hello Lasse,

 I have a Connection class that exposes members for the hostname, etc.
 
 ie.
 
 class Connection:
  def __init__(...):
  self.server = server
 
 is there any way to document this server member? The only way I know 
 of right now is to expose it as a property and add the doc string to 
 that definition.
 
 I've tried finding an example in the lib code installed with Python but 
 can't seem to track down anything that is documented like that.
IIRC Epydoc can do it. However you can't place the documentation directly
next to the member but in the class document string.

Bye.
--

Miki Tebeka [EMAIL PROTECTED]
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgp5iITzOAXxE.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: converting Word to MediaWiki

2005-09-29 Thread Peter Hansen
Jeff Schwab wrote:
 ChiTownBob wrote:
 
 Perl just sucks, as all good Python hackers know!
 
 
 I disagree.  Perl has saved my butt more times than I care to count. 
 Python certainly has its advantages, but I won't be giving up Perl any 
 time soon.

Are the two necessarily in conflict?  Perl can save your butt and 
_still_ suck!

;-) ;-)

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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Jeff Schwab
Peter Corbett wrote:
 One of my friends has recently taken up Python, and was griping a bit
 about the language (it's too prescriptive for his tastes). In
 particular, he didn't like the way that Python expressions were a bit
 crippled. So I delved a bit into the language, and found some sources
 of syntactic sugar that I could use, and this is the result:
 
 http://www.pick.ucam.org/~ptc24/yvfc.html

Yuma Valley Agricultural Center?
Yaak Valley Forest Council?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting Word to MediaWiki

2005-09-29 Thread Jorge Godoy
Peter Hansen [EMAIL PROTECTED] writes:

 Are the two necessarily in conflict?  Perl can save your butt and _still_ 
 suck!

If it pays the bill... :-)

-- 
Jorge Godoy  [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A quick c.l.p netiquette question

2005-09-29 Thread Duncan Booth
Richie Hindle wrote:

 
 [Peter]
 Does it really have to be 158 lines to demonstrate these few issues?
 
 I think you missed the other Peter's second post, where he points to
 his program: http://www.pick.ucam.org/~ptc24/yvfc.html
 
 I didn't read every one of his 158 lines, but his code is pure poetry,
 or possibly triple-distilled evil, depending on your point of view. 
 158 lines very well spent either way!
 
Yes, but by his own admission he could have posted it as 1 rather longer 
line and it would have still worked (I verified this, it really does work 
as a single line Python program).

I must admit to being impressed, and also seriously concerned about Peter 
Corbett's sanity.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another time challenge

2005-09-29 Thread nephish
cool, thanks
-shawn

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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle

[Peter]
 http://www.pick.ucam.org/~ptc24/yvfc.html

[Jeff]
 Yuma Valley Agricultural Center?
 Yaak Valley Forest Council?

I went through the same process.  My guess is Yes, Very F'ing Clever.
Peter?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


return own type from Python extention?

2005-09-29 Thread elho
I used the examples from the Extending and Embedding the Python 
Interpreter tutorial and this works. I can use my types with python.
But I do not know how to creat my own Python variable in an python 
extending c-code. What will I have to creat this and return it to my 
python programm?
-- 
http://mail.python.org/mailman/listinfo/python-list


User-defined augmented assignment

2005-09-29 Thread Pierre Barbier de Reuille
Hello,

a discussion began on python-dev about this. It began by a bug report,
but is shifted and it now belongs to this discussion group.

The problem I find with augmented assignment is it's too complex, it's
badly explained, it's error-prone. And most of all, I don't see any
use-case for it !

The most common error is to consider that :

 a += b == a.__iadd__(b)

when the truth is :

 a += b == a = a.__iadd__(b)

which can be very confusing, as the two a are not necessarily the
same. It then leads to subtle errors like:

 class A(object):
   a = 0

 a = A()
 b = A()
 a.a += 1
 A.a += 2
 print a.a
1
 print b.a
2

Also, the following behavior is pretty confusing :

 a = [1]
 b = [a]
 c = (a,)
 b[0] += [2] # Ok, no pb
 print a
[1,2]
 c[0] += [3]
Traceback (most recent call last):
  File string, line 1, in ?
TypeError: object doesn't support item assignment
 print a
[1,2,3]

Then, in the standard library, there is no use-case of user-defined
augmented assignment I could find. Of course, I find the augmented
assignement itself very useful ! I use it a lot with immutable objects
(strings, numbers, tuples, ...) but I tend to avoid it with mutables,
and so it seems in the standard library that uses extensively the
extend method of lists and very seldom the += operator with lists.
And even where the a+=b is used, it could be replaced with either
a.extend(b) or a = a+b without bugs.

So, what I would suggest is to drop the user-defined augmented
assignment and to ensure this equivalence :

a X= b = a = a X b

with 'X' begin one of the operators.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Paul Boddie
Paul Rubin wrote:
 If changing the way a class uses its own private variables breaks an 
 application
 because another class was using the private variable unexpectedly,
 then that's bad, regardless of whether the other class's author was
 notified or not.  It's better to let the compiler automatically flag
 these things, than to depend on conventions.

The problem with Python's compiler as it is today is that it can't
generally detect private attribute access: information about an
object/class being accessed is only guaranteed to be available at
run-time. Of course, Bastion and its peers [1] solve this by
introducing run-time environments which seek to guarantee attribute
privacy.

As for the merits of private/protected/final attributes and methods,
I've seen enough time-wasting and premature security optimisations to
know that such facilities can also waste a tremendous amount of time in
multi-person projects.

Paul

[1] At EuroPython there was a talk about protecting object attributes
in Ubuntu Launchpad [2], for which the slides are apparently
unavailable, and while chatting about this later on I noted that I'd
seen something like it before. The realisation that mxProxy [3] was
this apparently often overlooked thing occurred more or less
simultaneously with the realisation that I was talking to its author.
:-)

[2]
http://www.python-in-business.org/ep2005/talk.chtml?talk=1610track=692

[3] http://www.egenix.com/files/python/mxProxy.html

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


Re: User-defined augmented assignment

2005-09-29 Thread Reinhold Birkenfeld
Pierre Barbier de Reuille wrote:

 So, what I would suggest is to drop the user-defined augmented
 assignment and to ensure this equivalence :
 
 a X= b = a = a X b
 
 with 'X' begin one of the operators.

It can be done, but it's unnecessary for mutable objects like
sets or lists. A new object must be created in these cases where
one would suffice.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steven D'Aprano
On Wed, 28 Sep 2005 22:07:56 -0700, Paul Rubin wrote:

 One that is in other languages not even possible. A clear disadvantage.
 Python gives me power and does not take it away like the others.
 
 Huh?  If my car has a feature that lets someone blow it to
 smithereens from hundreds of miles away without even intending to,
 that's somehow an advantage?

Funny you should mention that.

The other day I stopped at a service station to fill up. I noticed a line
of cars at a bowser over in the corner. The bowser was wrapped in a big
yellow tape saying Caution!!! Warning!!! Experimental Petrol, for private
use only!!! USE AT OWN RISK!!! CAUTION CAUTION CAUTION Read the Manual
Before Using!!!

So naturally I filled up with my car with this private petrol, because I
hoped that it would give me more power when accelerating.

Well, it certainly did that, wow you should have seen my car go! But alas
I should have read the manual first, just like they said. It turned out
that this experimental petrol contained an additive that did not suit my
car's engine. Three days later, smoke started pouring out of the engine
and then it caught fire.

I could have read the manual, which I later found out was aware of the
risk of fire and gave simple instructions for how to avoid it (adding a
cup of ethanol to a full tank of petrol was all it would have taken to
prevent the harmful chemical reaction). Instead I made the decision to
ignore it, and suffered the consequences.

Now, I could take responsibility for my own stupidity in ignoring the
warnings and just assuming that there would be no side-effects.

Or I could stamp my feet and holler at the top of my voice that it is the
petrol seller's fault, and that he should have locked this special fuel
away and banned everyone else from using it, to protect idiots like myself
from shooting myself in the foot. (Or setting my car on fire, as the case
may be.)

After all, while I made a free choice to use the private petrol, despite
all the warnings and all the reasons why I should not, it certainly
shouldn't be my responsibility to deal with the consequences of my own
choice.


 The engineering decisions regarding my application should be on my
 side, not the language lawyers.
 
 No problem, but any decision like that should be expressed in
 writing, by re-declaring the variable so it's no longer private.

How do you see this working in practice?

Say you have written a class, with a private variable. I decide that I
need access to that variable, for reasons you never foresaw. What happens
next? I ask you nicely to please change your class and turn that private
attribute into a public one. What happens if you refuse? Can I have you
taken out and shot and seize ownership of your class, or do I have to
copy and paste your class into my code, creating a duplicate class I can
modify as much as I like?



-- 
Steven.

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Steve Holden
Richie Hindle wrote:
 [Peter]
 
Does it really have to be 158 lines to demonstrate these few issues?
 
 
 I think you missed the other Peter's second post, where he points to his
 program: http://www.pick.ucam.org/~ptc24/yvfc.html
 
 I didn't read every one of his 158 lines, but his code is pure poetry, or
 possibly triple-distilled evil, depending on your point of view.  158 lines
 very well spent either way!
 
I particularly like the warranty:

  # NO WARRANTY: If you use this for anything important, you're mad!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.pycon.org

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


Re: return own type from Python extention?

2005-09-29 Thread elho
Thx, but my Problem is to get my own type before.
If I have a C-Type, I know how tu return it from the Python extention, 
but how will it work with my own type?
I expect something like the following:

static PyObject* wrap_MyFunction (PyObject* self, PyObject* args)
{
   :
   MyPyType *myType = MyTypeNew ();
   return (PyObject*)myType;
}

How will the Konstructor-Funktion look for MyPyType to call this in C-Code.

...If I explain my problem to confuesed here more informations:
I have one function for MyPyType to construct it by calling from python:

static PyObject* PyMyType_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds)
{
 PyMyType *self;
 self = (PyMyType*)type-tp_alloc(type, 0);
 if (self != NULL) {
 self-test = 0;
 }
 return (PyObject *)self;
}

..but how do I have to call this from C-Code or how will another 
Funktion for this look like?



Jeremy Moles wrote:
 You can use Py_BuildValue for most what you're probably going to need.
 
 http://docs.python.org/api/arg-parsing.html
 
 On Thu, 2005-09-29 at 15:39 +0200, elho wrote:
 
I used the examples from the Extending and Embedding the Python 
Interpreter tutorial and this works. I can use my types with python.
But I do not know how to creat my own Python variable in an python 
extending c-code. What will I have to creat this and return it to my 
python programm?
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Set up Windows environment with python

2005-09-29 Thread Jim

My company resells windows machines, and we install our software, and
do a bunch of customization to make sure that all the desktop settings
are optimal...  we adjust the screen resolution, color depth, and
referesh rate,  remove shadows from menus and the mouse pointer, set
the power management options, disable the screensaver, etc... (very
long list)

I've started doing most of what I want with ctypes:

def disableShadows():
# constants taken from WinUser.h in the PlatformSDK
SPI_SETCURSORSHADOW = 0x101B
rv =
ctypes.windll.user32.SystemParametersInfoA(SPI_SETCURSORSHADOW, 0,
False, win32con.SPIF_SENDWININICHANGE)

# remove shadows from menus
SPI_SETDROPSHADOW = 0x1025
rv = ctypes.windll.user32.SystemParametersInfoA(SPI_SETDROPSHADOW,
0, False, win32con.SPIF_SENDWININICHANGE)

But I'm finding that none of the changes seem to be permanent.  I'm
wondering if I need to start changing the current Explorer theme
information instead, or go right to the registry and start changing
values.

Desktop wallpaper changes work, but they aren't permanent... rebooting
restores the previous desktop wallpaper.

Does anyone have any experience with this sort of system preperation
scripting?

Thanks,
-Jim

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


PyWin SendMessage

2005-09-29 Thread g.franzkowiak
Hello everybody,

I've tryed to use an interprocess communication via
SendMessage on Windows.
Unfortunately, nothing goes on

#
#! /usr/bin/env python

import win32api, win32ui, win32con
import struct, array


typedef struct tagCOPYDATASTRUCT {  // cds
DWORD dwData;
DWORD cbData;
PVOID lpData;
} COPYDATASTRUCT;


def packCopyData(nNum, sString):
int_buffer  = array.array(L,[nNum])
char_buffer = array.array('c', sString)
int_buffer_address  = int_buffer.buffer_info()[0]
char_buffer_address = char_buffer.buffer_info()[0]
char_buffer_size= char_buffer.buffer_info()[1]
copy_struct = struct.pack(pLp,# dword*, dword, char*
  int_buffer_address,
  char_buffer_size,
  char_buffer)
return copy_struct


# get the window handle
hwnd = win32ui.FindWindow(None, special window)

# print just for fun
print hwnd

cds = packCopyData(1, '1')
print cds

# try to send it a message
win32api.SendMessage(hwnd,
 win32con.WM_COPYDATA,
 0,
 cds)

#

The last parameter shut be an integer, but I think it must be a pointer ?

Any experience or a tip for me ?


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


Re: User-defined augmented assignment

2005-09-29 Thread Pierre Barbier de Reuille
Reinhold Birkenfeld a écrit :
 Pierre Barbier de Reuille wrote:
 
 
So, what I would suggest is to drop the user-defined augmented
assignment and to ensure this equivalence :

a X= b = a = a X b

with 'X' begin one of the operators.
 
 
 It can be done, but it's unnecessary for mutable objects like
 sets or lists. A new object must be created in these cases where
 one would suffice.

Well, my point is: the benefit is too small compared to the
disadvantage. If you really have a mutable (let say a list with +=) then
you do:

 a.extend(b)

and there is no interpretation error possible. BTW, that's what's done
in the standard library ...

Pierre

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


What python idioms for private, protected and public?

2005-09-29 Thread Michael Schneider
I have been following this thread with great interest.

I have been coding in C++ since the late 80's and Java since the late 90's.


I do use private in these languages, with accessors to get at internal 
data.

This has become an ingrained idiom for me.  When I create a python 
object, it is natural for me to want  to use familiar idioms.


Hare are the places where private is useful to me:


Design Intent:

1) mark an object as dirty in a setter (anytime the object is changed, 
the dirty flag is set without requiring a user to set the dirty flag

2) enforce value constraints (even if just during debugging)

3) lazy init, don't bring the data in until needed

4) adding debug info

5)  more here


I do write code that violates private
- memory ptr access in C++
- reflection in java
- aspects in java

I usually violate private when adding an aspect to a class, and
I don't want this code in every class.  Example,  persistence.


I really like the C# properties, you can access data with a data
accessor, but add functionality is triggered when accessing the data.

I like the data access syntax, better then the set/get functions.  I 
need the functionality to achieve the design goals above, so i use 
function, but the are ugly, especially in math code.


It would be easy for me to say Add public and private to python so I
can code the way that I am used to.  What are some python alternatives 
to achieve the design intents specified above above?

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


Re: return own type from Python extention?

2005-09-29 Thread Jeremy Moles
Building a fully-fledged, custom Python object in C isn't a trivial
task; it isn't a hard one either, but it isn't trivial. :) Basically, as
far as I know, you'll need to create a PyTypeObject structure, populate
it accordingly, and then call a few setup functions on it...

// 

static PyTypeObject WEE = {
...
};

Py_TypeReady(WEE);

module = Py_InitModule*(...) // There are a few versions of this

PyModule_AddObject(module, WEE, (PyObject*)(WEE));

// -

This is all from memory--I know I left out having to at least INCREF the
static WEE. At any rate, I'm sure you can find some samples easy enough.
And if not, I can let you try and grok some of my extension code...

On Thu, 2005-09-29 at 15:59 +0200, elho wrote:
 Thx, but my Problem is to get my own type before.
 If I have a C-Type, I know how tu return it from the Python extention, 
 but how will it work with my own type?
 I expect something like the following:
 
 static PyObject* wrap_MyFunction (PyObject* self, PyObject* args)
 {
:
MyPyType *myType = MyTypeNew ();
return (PyObject*)myType;
 }
 
 How will the Konstructor-Funktion look for MyPyType to call this in C-Code.
 
 ...If I explain my problem to confuesed here more informations:
 I have one function for MyPyType to construct it by calling from python:
 
 static PyObject* PyMyType_new(PyTypeObject *type, PyObject *args, 
 PyObject *kwds)
 {
  PyMyType *self;
  self = (PyMyType*)type-tp_alloc(type, 0);
  if (self != NULL) {
  self-test = 0;
  }
  return (PyObject *)self;
 }
 
 ..but how do I have to call this from C-Code or how will another 
 Funktion for this look like?
 
 
 
 Jeremy Moles wrote:
  You can use Py_BuildValue for most what you're probably going to need.
  
  http://docs.python.org/api/arg-parsing.html
  
  On Thu, 2005-09-29 at 15:39 +0200, elho wrote:
  
 I used the examples from the Extending and Embedding the Python 
 Interpreter tutorial and this works. I can use my types with python.
 But I do not know how to creat my own Python variable in an python 
 extending c-code. What will I have to creat this and return it to my 
 python programm?
  
  

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


Problem with long strings in the Boost.Python getting_started2 sample ?

2005-09-29 Thread Sylvain MARIE
Hi all,

I am discovering Boost.Python, and weird exceptions in my dummy extension 
modules lead me to think there is a potential problem with the 
getting_started2 sample :
if you replace the first lines

 hi = hello('California')
 hi.greet()
'Hello from California'

by
 hi = hello('A longer name with more than 15 chars')
 hi.greet()
'Hello from A longer name with more than 15 chars'

then the unit test asserts !?!? I get a c++ exception :-(

Please tell me we can use strings longer than 15 chars with Boost.Python :-)
(I'm using Boost 1.33.0 with VC7.1, and the bjam makefiles)

thank you very much in advance!
Sylvain 


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


Re: return own type from Python extention?

2005-09-29 Thread Jeremy Moles
One more thing! :)

The _new method probably isn't what you want to modify the actual interl
C object; the initproc method actually gives you a pointer to it as it's
first object... (it's the tp_init member in the PyTypeObject sturcture.)

On Thu, 2005-09-29 at 15:59 +0200, elho wrote:
 Thx, but my Problem is to get my own type before.
 If I have a C-Type, I know how tu return it from the Python extention, 
 but how will it work with my own type?
 I expect something like the following:
 
 static PyObject* wrap_MyFunction (PyObject* self, PyObject* args)
 {
:
MyPyType *myType = MyTypeNew ();
return (PyObject*)myType;
 }
 
 How will the Konstructor-Funktion look for MyPyType to call this in C-Code.
 
 ...If I explain my problem to confuesed here more informations:
 I have one function for MyPyType to construct it by calling from python:
 
 static PyObject* PyMyType_new(PyTypeObject *type, PyObject *args, 
 PyObject *kwds)
 {
  PyMyType *self;
  self = (PyMyType*)type-tp_alloc(type, 0);
  if (self != NULL) {
  self-test = 0;
  }
  return (PyObject *)self;
 }
 
 ..but how do I have to call this from C-Code or how will another 
 Funktion for this look like?
 
 
 
 Jeremy Moles wrote:
  You can use Py_BuildValue for most what you're probably going to need.
  
  http://docs.python.org/api/arg-parsing.html
  
  On Thu, 2005-09-29 at 15:39 +0200, elho wrote:
  
 I used the examples from the Extending and Embedding the Python 
 Interpreter tutorial and this works. I can use my types with python.
 But I do not know how to creat my own Python variable in an python 
 extending c-code. What will I have to creat this and return it to my 
 python programm?
  
  

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


Re: Set up Windows environment with python

2005-09-29 Thread Brett Hoerner
I don't have experience with scipting this... but I know that
resolution for example is stored in registry, and _that_ is what is
loaded when you boot.

I think most, if not all, of your changes will be found in the registry
(for permenance).

Also, have you checked out PyWin32?  It's just a big pre-made wrapper
for the Win32 stuff, not sure if it will be more/less work than ctypes
but it could make it easier on you.

PyWin32
http://sourceforge.net/project/showfiles.php?group_id=78018

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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Peter Corbett
Richie Hindle [EMAIL PROTECTED] writes:
 
 [Peter]
  http://www.pick.ucam.org/~ptc24/yvfc.html
 
 [Jeff]
  Yuma Valley Agricultural Center?
  Yaak Valley Forest Council?
 
 I went through the same process.  My guess is Yes, Very F'ing Clever.
 Peter?

You're all thinking about it the wrong way (he says, being cryptic).

Peter

-- 
A frightful hobgoblin is stalking throughout Europe.
 - The Communist Manifesto, 1st English Edition
-- 
http://mail.python.org/mailman/listinfo/python-list


A Moronicity of Guido van Rossum

2005-09-29 Thread Xah Lee
A Moronicity of Guido van Rossum

Xah Lee, 200509

On Guido van Rossum's website:
 http://www.artima.com/weblogs/viewpost.jsp?thread=98196
dated 20050826, he muses with the idea that he would like to remove
lambda, reduce(), filter() and map() constructs in a future version
Python 3000.

Guido wrote:
«filter(P, S) is almost always written clearer as [x for x in S if
P(x)], and this has the huge advantage that the most common usages
involve predicates that are comparisons, e.g. x==42, and defining a
lambda for that just requires much more effort for the reader (plus the
lambda is slower than the list comprehension)»

the form “[x for x in S if P(x)]” is certainly not more clear than
“filter(P, S)”. The latter is clearly a function. What the fuck is
the former? A function every programer in any language can understand
and appreciate its form and function. What the fuck would anyone to
expect everyone to appreciate a Python syntactical idiosyncrasy “[x
for ...]”?

also, the argument that the from “filter(F,S)” being cumbersome
because the first argument is a function and that mostly likely it
would be a function that returns true and false thus most people will
probably use the form “lambda” and that is quite cumbersome than if
the whole thing is written with the syntactical idiosyncrasy “[x for
...]”, is rather inane, as you can now see.

The filter(decision_function,list) form is clean, concise, and helps
thinking. Why it helps thinking? Because it condenses the whole
operation into its mathematical essence with the most clarity. That is,
it filters, of a list, and by a yes/no decision function. Nothing is
more, and nothing can be less. It is unfortunate that we have the
jargon Lambda and Predicate developed by the morons in the tech geekers
of the functional programing community. The lambda could be renamed
Pure Function and the Predicate could be called True/False function,
but the world being the way they are already, it is unwise to rewrite
every existing Perl program just because somebody invented another
language.

If the predicate in lambda in filter() is cumbersome, so would exactly
the same thing appear in the syntactical idiosyncrasy “[x for x in S
if P(x)]”.

Guido added this sting as a afterthought:
«(plus the lambda is slower than the list comprehension)»

Which is faster is really the whim and capacity of Python
implementators. And, just before we were using criterion of simplicity.
The concept of a function every programer understands, what the fuck is
a List Comprehension?
Why don't you scrap list comprehension in Python 3000 and create a
table() function that's simpler in syntax and more powerful in
semantics? ( See http://xahlee.org/perl-python/list_comprehension.html
)

Guido wrote:
«Why drop lambda? Most Python users are unfamiliar with Lisp or
Scheme, so the name is confusing; also, there is a widespread
misunderstanding that lambda can do things that a nested function can't
-- I still recall Laura Creighton's Aha!-erlebnis after I showed her
there was no difference! Even with a better name, I think having the
two choices side-by-side just requires programmers to think about
making a choice that's irrelevant for their program; not having the
choice streamlines the thought process. Also, once map(), filter() and
reduce() are gone, there aren't a whole lot of places where you really
need to write very short local functions; Tkinter callbacks come to
mind, but I find that more often than not the callbacks should be
methods of some state-carrying object anyway (the exception being toy
programs).»

In the outset Guido here assumes a moronitude about the set of Python
users and what they are familiar of. Python users 10 years ago are not
the same Python users today, and will certainly not be the same 10
years later if you chop off lambda. Things change, math literacy
advances, and what users you have changes with what you are. A pure
function (lambda) is the gist of a mathematical idea embodied in
computer languages, not something from LISP or Scheme as tech geeking
morons wont to think.

Guido wrote:
«... there is a widespread misunderstanding that lambda can do things
that a nested function can't...».

One is so insulted by a bigshot in the industry of quoting something so
disparate then shot it down as if showing his perspicacity.

A lambda is a syntax for function or a name for the concept of
function. What the fuck does it mean that a lambda isn't as powerful as
nested function??

The lambda in Python is really ill. It is designed with a built-in
limitation in the first place, and regarded as some foreign substance
in the Imperative crowd such as the Pythoners. If there's any problem
with lambda, it is with lambda in Python and Pythoner's attitude.

Guido wrote:
«Also, once map(), filter() and reduce() are gone, there aren't a
whole lot of places where you really need to write very short local
functions;»

Of course, you begin to write things like Java, in three thousand words
just to 

Re: Will python never intend to support private, protected and public?

2005-09-29 Thread en.karpachov
On Fri, 30 Sep 2005 00:16:02 +1000
Steven D'Aprano wrote:

 Say you have written a class, with a private variable. I decide that I
 need access to that variable, for reasons you never foresaw.

What if the access to that variable was forbidden for reasons you never
foresaw? What if the class author decide to remove the variable in the next
version of the class, because it's not an interface, but only a part of the
class implementation?

 What happens
 next? I ask you nicely to please change your class and turn that private
 attribute into a public one. What happens if you refuse? Can I have you
 taken out and shot and seize ownership of your class, or do I have to
 copy and paste your class into my code, creating a duplicate class I can
 modify as much as I like?

Yes, that's how it works in the open source. What's wrong with it? You
don't need _this_ class, because it's functionality doesn't fit to you. So
you take the source code and write another class, doing exactly what you
want it to do.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Michael Ekstrand
On Thursday 29 September 2005 03:57, Paul Rubin wrote:
 I can't think of a single time that I've ever seen a legitimate use
 of name mangling to reach from one class into another in a Python
 application (I don't count something like a debugger).  If you're got
 some concrete examples I wouldn't mind looking.

I've done it in one project, my YaPIE library 
(http://sourceforge.net/projects/yapie). But it's kinda ugly, and 
probably not the right way to do things, and I don't even use the 
library myself anymore (it grew out of frustration with some XML 
parsing issues, before I did a little Java and learned to use SAX).

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steve Holden
Paul Rubin wrote:
 Dennis Lee Bieber [EMAIL PROTECTED] writes:
 
  Ah, but in the way of your code -- it is not your car... It is the
car you supplied to someone hundreds of miles away... And they are
perfectly free to open the hood... tamper with the engine programming, etc.
 
 
 I don't understand what you're getting at.  If they're free to edit
 the code, then why should they complain about private variables?  They
 can change the declaration if they need to.

Similarly they can rewrite it in Perl if they don't like it being in 
Python. So what? Most people have *zero* interest in looking behind the 
interface of the code they use, whether it's an API or a GUI.

Effectively this whole thread seems to have become an argument about 
what kind of boxes you can have around namespaces. For the vast majority 
who don't care the discussion will seem a little academic.

Should namespaces be protected? The lazy Pythonista's answer to that 
question is:

   import os; f = os.popen(python -m this)
   for l in f:
  ...   if namespaces in l.lower().split(): print l[:-1]
  ...
Namespaces are one honking great idea -- let's do more of those!
  

[note that my laziness extends to the gratuitous introduction of a 
separate process to produce the source data. Can I claim extra points
for that?]

So it should come as no surprise to anyone that namespaces appear in 
many contexts in Python. So, why this sudden urge (you may wonder, if 
you don't think much about code purity) to have private and its 
buddies. The security police have arrived, and you can be pretty sure 
nothing much is going to be fun from here on in.

Think about it: we have a language that has an eval() function and an 
exec statement, and people are concerned that some service consumer 
shouldn't be allowed to go poking around inside namespaces? What do we 
have to do, put up signs saying do not stab yourself with a knife? If 
people want control without discipline (which is effectively what 
private and the like purport to do) then Python just may not be your 
language ...

Access to another object's namespace is almost invariably all-or-nothing 
in Python, which (it should not be overlooked) has introspection 
capabilities. With this ability to poke around in the bowels of the 
system to perform deep magic comes a corresponding responsibility: don't 
abuse the privilege, and behave in a disciplined (sort of) way.

To avoid naming conflicts, Python provides a mechanism (name mangling) 
which pretty much guarantees that your names won't conflict with anybody 
else's, *even if you subclass a class whose methods use the same name*. 
This was a thoughtful addition, widely ignored by experienced 
programmers. It was never intended to stop people from poking around 
under the hood - simply to ensure that you wouldn't *accidentally* start 
poking around under the hood of a parent class's implementation because 
of a name clash.

C++ and cronies are not introspective languages (Java is and, like 
Python, can mess about with its own workings; because of Java's many 
constraints this turns out to be much less fun than in Python, but of 
course Jython will give you access to many useful Java resources in a 
much saner context) and non-introspective programmers frequently recoil 
in horror when faced with the prospect of losing the training wheels :-)

Given the denizens of this particular list/newsgroup I am sure I will be 
bombarded by a host of ways I could have produced the output of import 
this without creating a new process. So, to try and forestall various 
further expansions of this thread, let me produce a FAQ (which is 
clearly quite bogus, since I am still writing it) for this post.

Q: It's inefficient to start another process.

A: When I need to do it six million times a second I'll remember that.
This was a one-off example. I have already wasted more time
discussing this issue than I would have saved in the first
thousand runs of a rewrite.

Q: It isn't cross-platform.

A: Well it runs on Windows, Cygwin and Linux, so it doesn't do badly.

Q: You could have done it some other way.

A: Please get over this obsession. There will always be more than
one way to do most things despite the output from a simpler (but
non-portable) solution

$ python -m this | grep way
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.

Note that word obvious: nobody says you *have* to do things the
obvious way.

Q: Are you Dutch or something?

A: No such luck. But I'm not Belgian either :-)

a-voice-said-smile-things-could-be-worse-so-i-smiled-and-sure-enough-things-got-worse-ly
 
y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: What python idioms for private, protected and public?

2005-09-29 Thread Michael Ekstrand
On Thursday 29 September 2005 09:08, Michael Schneider wrote:
 Design Intent:

 1) mark an object as dirty in a setter (anytime the object is
 changed, the dirty flag is set without requiring a user to set the
 dirty flag

2 ways: wrap every attribute that is to be set in a property object (in 
new-style classes), and set it in the setter there.

Or override __setattr__ to set the dirty flag.

Or, if you want overkill, but a potentially cleaner interface in some 
cases, a metaclass could also be contrived to accomplish this (crud, 
you can do _anything_ with a metaclass).

 2) enforce value constraints (even if just during debugging)

Python's property objects

def _get_foo(self, foo):
return self.__foo
def _set_foo(self, foo, val):
if self.__is_valid_foo(val):
self.__foo = foo
else:
raise ValueError(Invalid foo)
foo = property(_get_foo, _set_foo, doc=Foo property)

 3) lazy init, don't bring the data in until needed

Define __getattr__. Or use a metaclass (but I tend to think of 
metaclasses as a solution to too many things - see previous thread 
about synchronization for details).

 4) adding debug info

A metaclass to do tracing, whatever - they let you modify the nature of 
your class greatly on the fly.

 5)  more here

Overriding magic methods (esp. getattr/setattr), various decorators 
(ether existing or custom for your purposes), metaclasses, etc.

 I usually violate private when adding an aspect to a class, and
 I don't want this code in every class.  Example,  persistence.

Persistence can be done with subclassing, with a base class that sets up 
persistence (I did this in PHP4 once, an ugly object model if I've ever 
seen one). Metaclasses might be cleaner.

 I really like the C# properties, you can access data with a data
 accessor, but add functionality is triggered when accessing the data.

Python has these - use property objects. property() is documented under 
Built-In Functions

 I like the data access syntax, better then the set/get functions.  I
 need the functionality to achieve the design goals above, so i use
 function, but the are ugly, especially in math code.

Yes, get/set is highly ugly IMHO. I have to do Java for one of my 
classes now... I frequently want to gag over the forced usage of such 
things.

 It would be easy for me to say Add public and private to python so I
 can code the way that I am used to.  What are some python
 alternatives to achieve the design intents specified above above?

See above :-). I think you'll find that you can accomplish most or all 
of your purposes, and then a few you may not have thought of yet.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steven D'Aprano
On Wed, 28 Sep 2005 16:36:03 -0700, Paul Rubin wrote:

 Steven D'Aprano [EMAIL PROTECTED] writes:
 No, but that is precisely why Python's semi-private variables are
 usually better. Names like _X and class.__X are warnings to the developer
 use these at your own risk, without preventing developers who need them
 from using them. You have most of the benefits of private variables with
 none of the disadvantages.
 
 I'm sorry but I thought the idea was to actually reduce the risk of
 bugs, not merely attach the risk to the right person.  If changing the
 way a class uses its own private variables breaks an application
 because another class was using the private variable unexpectedly,
 then that's bad, regardless of whether the other class's author was
 notified or not.  It's better to let the compiler automatically flag
 these things, than to depend on conventions.

Better for who? The idiot who doesn't take even a modicum of attention to
the class creator who warns Use these variables with care because they
are subject to change without notice?

Or better for the developers who were prevented from making careful,
intelligent use of the variables because of an misguided attempt to
protect them from changes to the code that may or may not ever take place?

You count the risk of bugs from semi-private variables, but you don't
count the cost of lost opportunities caused by preventing access to those
variables. Nor do you count the cost of copy and paste coding, both in
extra development time and extra maintenance.

Of course if you ignore the costs and lost opportunities of locked-down
private variables they will be better.


-- 
Steven.

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


Re: converting Word to MediaWiki

2005-09-29 Thread Michael Ekstrand
On Thursday 29 September 2005 07:43, Peter Hansen wrote:
 Are the two necessarily in conflict?  Perl can save your butt and
 _still_ suck!

Hear, hear!

Although I think it's the vi user in me that makes me like Perl...

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Simon Brunning
On 9/29/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 What if the access to that variable was forbidden for reasons you never
 foresaw? What if the class author decide to remove the variable in the next
 version of the class, because it's not an interface, but only a part of the
 class implementation?

Then your code breaks. You can't say you weren't warned.

But if too much is made private, chances are you could never get your
code working in the first place. This has happened to me several times
when using 3rd party Java components. Serves us right for using closed
source libraries, I suppose, but that wasn't my decision.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Michael Ekstrand
On Thursday 29 September 2005 04:53, Peter Corbett wrote:
 One of my friends has recently taken up Python, and was griping a bit
 about the language (it's too prescriptive for his tastes). In
 particular, he didn't like the way that Python expressions were a bit
 crippled. So I delved a bit into the language, and found some sources
 of syntactic sugar that I could use, and this is the result:

 http://www.pick.ucam.org/~ptc24/yvfc.html

Umm, TMTOWTDI? As uniform as Python is, it still is flexible...

Brilliant. Simply brilliant.

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


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread Michael Goettsche
On Thursday 29 September 2005 16:24, Xah Lee wrote:
 A Moronicity of Guido van Rossum

 Xah Lee, 200509


Assuming you want to reach people to convince them your position is right, why 
don't you try that in proper language? moron occured 7 times in your not 
too long text, that doesn't let you look like a tech moron or a math moron, 
but just like a moron.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread fraca7
Richie Hindle a écrit :
 [Peter]
 
http://www.pick.ucam.org/~ptc24/yvfc.html
 
 
 [Jeff]
 
Yuma Valley Agricultural Center?
Yaak Valley Forest Council?
 
 
 I went through the same process.  My guess is Yes, Very F'ing Clever.
 Peter?
 

print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
ord('a')), 'yvfc'))

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


Re: A rather unpythonic way of doing things

2005-09-29 Thread Jeff Schwab
fraca7 wrote:
 Richie Hindle a écrit :
 
 [Peter]

 http://www.pick.ucam.org/~ptc24/yvfc.html



 [Jeff]

 Yuma Valley Agricultural Center?
 Yaak Valley Forest Council?



 I went through the same process.  My guess is Yes, Very F'ing Clever.
 Peter?

 
 print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
 ord('a')), 'yvfc'))
 
 :)

LOL.  Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Cyril Bazin
Crypthonic could be the exact word...On 29 Sep 2005 15:19:11 +0100, Peter Corbett [EMAIL PROTECTED]
 wrote:Richie Hindle [EMAIL PROTECTED]
 writes: [Peter]  http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff]  Yuma Valley Agricultural Center?
  Yaak Valley Forest Council? I went through the same process.My guess is Yes, Very F'ing Clever. Peter?You're all thinking about it the wrong way (he says, being cryptic).
Peter--A frightful hobgoblin is stalking throughout Europe. - The Communist Manifesto, 1st English Edition--http://mail.python.org/mailman/listinfo/python-list

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

Re: What python idioms for private, protected and public?

2005-09-29 Thread Fredrik Lundh
Michael Schneider wrote:

 1) mark an object as dirty in a setter (anytime the object is changed,
 the dirty flag is set without requiring a user to set the dirty flag

properties.

 2) enforce value constraints (even if just during debugging)

properties.  (when you no longer need to enforce things, switch back
to a plain attribute).

 3) lazy init, don't bring the data in until needed

properties.

 4) adding debug info

properties.

 5)  more here

properties.

 It would be easy for me to say Add public and private to python so I
 can code the way that I am used to.

huh?  what do private and public have to do with what you're describing?

 What are some python alternatives to achieve the design intents specified
 above above?

properties.

http://users.rcn.com/python/download/Descriptor.htm#properties

/F 



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 What if the access to that variable was forbidden for reasons you never
 foresaw? What if the class author decide to remove the variable in the next
 version of the class, because it's not an interface, but only a part of the
 class implementation?

you mean when he breaks into your computer and installs the new version
without you noticing?

if you think that once you've put private labels on all accidental stuff, 
nothing
will break during upgrades, you're clearly very new to this thing called pro-
gramming...

/F 



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


Re: Set up Windows environment with python

2005-09-29 Thread Thomas Heller
Jim [EMAIL PROTECTED] writes:

 My company resells windows machines, and we install our software, and
 do a bunch of customization to make sure that all the desktop settings
 are optimal...  we adjust the screen resolution, color depth, and
 referesh rate,  remove shadows from menus and the mouse pointer, set
 the power management options, disable the screensaver, etc... (very
 long list)

 I've started doing most of what I want with ctypes:

 def disableShadows():
 # constants taken from WinUser.h in the PlatformSDK
 SPI_SETCURSORSHADOW = 0x101B
 rv =
 ctypes.windll.user32.SystemParametersInfoA(SPI_SETCURSORSHADOW, 0,
 False, win32con.SPIF_SENDWININICHANGE)

 # remove shadows from menus
 SPI_SETDROPSHADOW = 0x1025
 rv = ctypes.windll.user32.SystemParametersInfoA(SPI_SETDROPSHADOW,
 0, False, win32con.SPIF_SENDWININICHANGE)

 But I'm finding that none of the changes seem to be permanent.  I'm
 wondering if I need to start changing the current Explorer theme
 information instead, or go right to the registry and start changing
 values.

 Desktop wallpaper changes work, but they aren't permanent... rebooting
 restores the previous desktop wallpaper.

 Does anyone have any experience with this sort of system preperation
 scripting?

From looking at the MSDN docs, it seems you have to add
SPIF_UPDATEINIFILE (Writes the new system-wide parameter setting to the
user profile) to the last argument.

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


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread dataw0lf
Michael Goettsche wrote:

 Assuming you want to reach people to convince them your position is right, 
 why 
 don't you try that in proper language? moron occured 7 times in your not 
 too long text, that doesn't let you look like a tech moron or a math moron, 
 but just like a moron.

Actually, an angry moron, due to the use of the expletive 'fuck' 4 times
in said text.

-- 

Joshua Simpson -- dataw0lf.org
Lead Network Administrator/Engineer Aero-Graphics Inc.
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWin SendMessage

2005-09-29 Thread Thomas Heller
g.franzkowiak [EMAIL PROTECTED] writes:

 Hello everybody,

 I've tryed to use an interprocess communication via
 SendMessage on Windows.
 Unfortunately, nothing goes on

 #
 #! /usr/bin/env python

 import win32api, win32ui, win32con
 import struct, array

 
 typedef struct tagCOPYDATASTRUCT {  // cds
 DWORD dwData;
 DWORD cbData;
 PVOID lpData;
 } COPYDATASTRUCT;
 

 def packCopyData(nNum, sString):
 int_buffer  = array.array(L,[nNum])
 char_buffer = array.array('c', sString)
 int_buffer_address  = int_buffer.buffer_info()[0]
 char_buffer_address = char_buffer.buffer_info()[0]
 char_buffer_size= char_buffer.buffer_info()[1]
 copy_struct = struct.pack(pLp,# dword*, dword, char*
   int_buffer_address,
   char_buffer_size,
   char_buffer)
 return copy_struct

After packCopyData(...) returns, the arrays are destroyed, which will
probably void their contents.  You must keep them alive until you don't
need the COPYDATASTRUCT instance any longer.  For this kind of stuff,
ctypes may be easier to use than pywin32.

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Rocco Moretti
[EMAIL PROTECTED] wrote:
 On Fri, 30 Sep 2005 00:16:02 +1000
 Steven D'Aprano wrote:
 
Say you have written a class, with a private variable. I decide that I
need access to that variable, for reasons you never foresaw.
 
 What if the access to that variable was forbidden for reasons you never
 foresaw? What if the class author decide to remove the variable in the next
 version of the class, because it's not an interface, but only a part of the
 class implementation?

What if the class author removes a non-private variable or changes a 
method's documented parameters in the next version of the class, because 
he think it'll work better, or just because he can?

People who think that forbidding access to private variables/methods 
will save themselves from upgrade woes are deluding themselves.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Rocco Moretti
fraca7 wrote:
 Richie Hindle a écrit :
 
 [Peter]

 http://www.pick.ucam.org/~ptc24/yvfc.html



 [Jeff]

 Yuma Valley Agricultural Center?
 Yaak Valley Forest Council?



 I went through the same process.  My guess is Yes, Very F'ing Clever.
 Peter?

 
 print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
 ord('a')), 'yvfc'))

Less pythonic:

__import__('sys').stdout.write(''.join(map(lambda x: chrord(x) - 
ord('a')) + 13) % 26) + ord('a')), 'yvfc'))

More Pythonic:

print 'yvfc'.decode('rot13')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread Jorge Godoy
Michael Goettsche [EMAIL PROTECTED] writes:

 On Thursday 29 September 2005 16:24, Xah Lee wrote:
  A Moronicity of Guido van Rossum
 
  Xah Lee, 200509
 
 
 Assuming you want to reach people to convince them your position is right, 
 why 
 don't you try that in proper language? moron occured 7 times in your not 
 too long text, that doesn't let you look like a tech moron or a math moron, 
 but just like a moron.

His intent was never to convince people or pass information.  Look for older
posts from him, where people here tried showing him some mistakes or made
suggestions to enhance his contribution and he simply ignored everything.

It looks like he thinks he's omniscient and always righ.  Almost (?) a
deity. :-) 


By the way, the doctor said it is dangerous to contradict him... ;-)

-- 
Jorge Godoy  [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread Fredrik Lundh
fraca7 wrote:

 print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
 ord('a')), 'yvfc'))

that's spelled

print yvfc.decode(rot-13)

or, if you prefer,

print yvfc.encode(rot-13)

, in contemporary python.

/F 



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


portable way to get process infos

2005-09-29 Thread Tarek Ziadé
Hi,

I am getting infos on the current process, under linux, by reading the
file pointed by:

'/proc/%d/status' % os.getpid()

huh :(

There's probably another way to do it on win32 but,
i was wondering if there's a way or an existing extension out there
 to do make it work on any platform.

Regards,

Tarek

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steven D'Aprano
On Thu, 29 Sep 2005 18:29:36 +0400, en.karpachov wrote:

 On Fri, 30 Sep 2005 00:16:02 +1000
 Steven D'Aprano wrote:
 
 Say you have written a class, with a private variable. I decide that I
 need access to that variable, for reasons you never foresaw.
 
 What if the access to that variable was forbidden for reasons you never
 foresaw? What if the class author decide to remove the variable in the next
 version of the class, because it's not an interface, but only a part of the
 class implementation?

I either write buggy code that breaks when the class author changes the
variable, or I write code that is careful, does not make assumptions about
the nature of the variable, and fails gracefully when the author changes
or removes the variable.

In the first case, I'm responsible for the bug, and will hang my head in
shame. In the second case, I impress people with the quality of my code
and get surrounded by hundreds of adoring women who want to have my
children. (Well I can dream can't I?)

But either way, the original class author may never remove the variable,
in which case I have all the advantages of accessing that semi-private
variable with none of the disadvantages.

This, of course, assumes that there are some advantages of accessing the
variable. If there are none, then I would be foolish to make a rod for my
own back by bypassing the class author's supported API for no benefit.


 What happens
 next? I ask you nicely to please change your class and turn that private
 attribute into a public one. What happens if you refuse? Can I have you
 taken out and shot and seize ownership of your class, or do I have to
 copy and paste your class into my code, creating a duplicate class I can
 modify as much as I like?
 
 Yes, that's how it works in the open source. 

Oh please, it does not. We hardly ever have people taken out and shot so
we can take their code. That's more Microsoft's way of doing business...

*wink*

 What's wrong with it? You
 don't need _this_ class, because it's functionality doesn't fit to you. So
 you take the source code and write another class, doing exactly what you
 want it to do.

Perhaps I don't have access to the source code at all, only the .pyc file,
but I've learnt the secret name of the private attribute from the book
Undocumented Tricks And Tips For Pythonistas.

Or I do have access to the source code, but under a licence that does not
allow me to legally modify the code and distribute it. Should I break the
law and risk a civil suit or even jail for copyright infringement?

Or maybe I just don't feel like taking on the responsibility of
maintaining the entire class, but feel that it is perfectly within my
capabilities to update my code if and when one specific private variable
gets modified or removed.

Or maybe I just don't like the idea of introducing bugs and duplicating
labour by copying and pasting code.


-- 
Steven.

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


New Python chess module

2005-09-29 Thread Will McGugan
Hi folks,

I've written a Python chess module that does the following.

* Reads / Writes PGN files
* Write FEN files
* Validates moves
* Lists legal moves
* Detects check / mate / stalemate / 50 move rule / threefold repetition

Its still rough around the edges and not fully tested. I'll eventualy 
release a more polished version and possibly put it on Sourceforge. In 
the meantime I would be grateful for any feedback..

http://www.willmcgugan.com/chess.zip

I am aware of the chess module by Erik Max Francis. It may have been 
more sensible to work on his version, but I did this mainly for the fun 
of it. I wrote a chess game in C++ a while back 
(http://www.chesscommander.com) and I thought it would be interesting to 
re-implement the chess library part in Python.


Regards,

Will McGugan
--
http://www.willmcgugan.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Roel Schroeven
Steve Holden schreef:

There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
 
Note that word obvious: nobody says you *have* to do things the
obvious way.
 
 Q: Are you Dutch or something?
 
 A: No such luck. But I'm not Belgian either :-)

Some of us are!

Since we Belgians live so close to the Dutch, chances are that the
obvious way is obvious to us too. It's just that it's also obvious to us
that we're obviously not going to take the obvious route. We'll do it
our own way, thank you very much :)

I'm not taking it so far to start using Perl though.

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

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread could ildg
**Encapsulation** is one of the 3 basic characteristics of OOP.When I firstly turned to python, it was my first script language.That time I found that python has not real private properties,I felt weird. If an oop language can't encapsulate something I want,
is it really an oop language? I asked myself. And after thinking forsome days, I answered myself that python is just a script language,it has no private stuff just want to keep python easy. An easy language
is hard to do difficult works, surely. But when I came to know *Ruby* some days ago, I found that not allscript languages have no private functionalities. Ruby has everythingthat encapsulation should has. In ruby there is a very popular web
framework named Ruby On Rails. Many programmers are studyat rails these days, And some people think that rails is even betterthan J2EE. So I asked myself, why is rails written in Ruby but notPython since python is such a good language? Why did the author
choose ruby other than python?On the comparison between py and ruby, the encapsulation of Ruby**beats** Python.Why does oop languages need encapsulation?Because it make programming easier.
Now I give some examples where real private is very very needed.The counter of a list-like object is very comman in our programms.This kind of variables can only be modified by the functions of theclass itself. We can't let others has the opportunity to modify it.
If it's modified outside the class directly, the programm will becomevery diffict to maintain and understand. At this time, python is not betterthan C.Sometimes I don't want a variable to be changed directly,
It can only be changed through a method. Because I want to do some extra works when it's changed. e.g:___class a: i=0 def setI(iii): if self.i!=iii:
 self.i=iii #do some extra works here, e.g, notify the observers that #this property is changed, or do some logging things.___In the class a above, when i is changed, I will do some extra works,
the extra works could be very import, so I want to keep i invisibleto some others, they can only change i by the method setI. But pythoncan't ensure i to be invisible, everyone can change it whenever theywant! This is dangerous.
Some guys will say that they will pay very much attention when theychange the variable i. But, I just want to say that this is only the easiestsituation because there is only **one** class and only **one** variable 
which should be visited cautiously. But what will you do when there arehundreds of classes and each class has dozens of such variables? I thinkeverybody can imagine how difficult it will be when he faces this
situation.Every programmer is just a human being, but not God. Our life is limited,our time is limited, so we need to use convenient tools to save time.Private variables guarantee that we will never make stupid mistakes
to change them incautiously and it will tell us that YOU ARE WRONG whenyou try to change or visit them. They save energy for us, they save timefor us, they make us to be God!I don't want to give any more examples where private variables should be
used. If you think it's not needed, that's not import for me. I just want to saythat encapsulation is very very needed, just as one's cock, it's his, and it'sonly his. He can't unconditionally let anyboy else tough it. Because it's
dangerous. So he should hide it, but not to expose it and tell everybody elseverytime Don't tough my cock, it's my private stuff!.I use python for more than a year and I can't leave it because I am familiar
with my everyday necessary libs. And it's so convenient to interact withpython from Delphi or C or C++. I like pyton, so I like python to be perfect,I wish everyone of us could have a perfect python, so it is with you, isn't it?

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

Re: A rather unpythonic way of doing things

2005-09-29 Thread Simon Brunning
On 9/29/05, Fredrik Lundh [EMAIL PROTECTED] wrote:
 fraca7 wrote:

  print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
  ord('a')), 'yvfc'))

 that's spelled

 print yvfc.decode(rot-13)

 or, if you prefer,

 print yvfc.encode(rot-13)

 , in contemporary python.

I'm not sure that being more comprehensible is considered a virtue in
this thread, /F. ;-)

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Steve Holden
Fredrik Lundh wrote:
 Steve Holden wrote:
 
 
To avoid naming conflicts, Python provides a mechanism (name mangling)
which pretty much guarantees that your names won't conflict with anybody
else's, *even if you subclass a class whose methods use the same name*.
 
 
 as long as you don't cheat, that is:
 
 # your code
 
 class Secret:
 def __init__(self):
 self.__hidden = very secret value
 
 # my code
 
 from yourcode import Secret
 
 class Secret(Secret):
 def gethidden(self):
 return self.__hidden
 
 s = Secret()
 print s.gethidden()
 

I thought you'd know me well enough to know I'd *never* cheat :-)

Nice way to point out that Pythin is indeed a consenting adults language.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.pycon.org

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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Simon Brunning
On 9/29/05, could ildg [EMAIL PROTECTED] wrote:
 **Encapsulation** is one of the 3 basic characteristics of OOP.

Pyhton has encapsulation. On objetcts members are encapsulated in a
namespace all of its own. You can't change these by accident.

 Every programmer is  just a human being, but not God. Our life is limited,
 our time is limited, so we need to use convenient tools to save time.
 Private variables guarantee that we will never make stupid mistakes

Private variables prevent the developer of the *client* of a class
from making a small subset of all possible stupid mistakes. But if the
developer of the classitself is mistaken in marking a variable as
private, and if the language enforces this, then there is nothing at
all that the client can do to fix it. Why should the developer of the
class be more likely to be god-like than the user of the class? This
has happened to me more than once.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to increment a date, and how to convert it ?

2005-09-29 Thread [EMAIL PROTECTED]
Hi !

1.
I have a code. I want to convert from wx.DatePickerCtrl.Value to 
mx.DateTime.
But I don't know, how to do it simply.

2.
I need to increment this date by 6 days.
How to do it ? (I search for a simple way, like Delphi-s d2:=d1+6)


The code section is:

from mx import DateTime as mxDT
v=self.datePickerCtrl1.GetValue()
print type(v),v # wx._misc.DateTime
d1=mxDT.Date(2005,01,01)
print type(d1),d1  # DateTime

Thanks for advance: dd



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


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Bill Mill
 ___
 class a:
 i=0
 def setI(iii):
 if self.i!=iii:
 self.i=iii
 #do some extra works here, e.g, notify the observers that
 #this property is changed, or do some logging things.
 ___
 In the class a above, when i is changed, I will do some extra works,
 the extra works could be very import, so I want to keep i invisible
 to some others, they can only change i by the method setI. But python
 can't ensure i to be invisible, everyone can change it whenever they
 want! This is dangerous.


 class test(object):
...   __i = 0
...   def incr(self, n): self.__i += 1; print incremented i
...   def geti(self): print got i; return self.__i
...   i = property(geti, incr)
...
 t = test()
 t.i
got i
0
 t.i += 5
got i
incremented i
 t.i
got i
1
 dir(t)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash_
_', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr_
_', '__setattr__', '__str__', '__weakref__', '_test__i', 'geti', 'i', 'incr']

 #here's how the crazy hackers subclassing your code can break your super
... #special private variable!
...
 t._test__i += 6
 t.i
got i
7

But, if your users can't figure out that they shouldn't be changing
the variable called t._test__i without expecting side effects, what do
you think of the users of your class?

Python is for consenting adults.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-29 Thread Bill Mill
Error correction time!

  #here's how the crazy hackers subclassing your code can break your super
 ... #special private variable!
 ...

That should be using your code not subclassing your code. D'oh!

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set up Windows environment with python

2005-09-29 Thread Jim
Thanks Thomas!  That did it.

I can now set the wallpaper, mouse shadows, menu shadows, and I can
disable the screensaver.

Does anyone know how I can adjust the power options?  I want to make
sure any hibernate or standby options are set to Never.

Thanks,
-Jim

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


Re: [Python-Dev] PEP 350: Codetags

2005-09-29 Thread Phillip J. Eby
At 09:10 AM 9/28/2005 -0700, Micah Elliott wrote:
I agree that proof of value is necessary.  Without a spec though it
will be hard to get people to know about a convention/toolset, so it's
a bit of a chicken-egg problem -- I can't have a pep until the tools are
in use, but the tools won't be used until programmers have
means/motivation to use them, a pep.

My point about the lack of motivation was that there was little reason 
shown why this should be a PEP instead of either:

1. Documentation for a specific tool, or group of tools
2. A specific project's process documentation

Are you proposing that this format be used by the Python developers for 
Python itself?  A process spec like this seems orthogonal to 
Python-the-language.

To put it another way, this seems like writing a PEP on how to do eXtreme 
Programming, or perhaps a PEP on how the blogging trackback protocol 
works.  Certainly you might implement those things using Python, but the 
spec itself seems entirely orthogonal to Python.  I don't really see why 
it's a PEP, as opposed to just a published spec on your own website, unless 
you intend for say, the Python stdlib to conform to it.

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


Re: New Python chess module

2005-09-29 Thread could ildg
Very good~On 9/29/05, Will McGugan [EMAIL PROTECTED] wrote:
Hi folks,I've written a Python chess module that does the following.* Reads / Writes PGN files* Write FEN files* Validates moves* Lists legal moves* Detects check / mate / stalemate / 50 move rule / threefold repetition
Its still rough around the edges and not fully tested. I'll eventualyrelease a more polished version and possibly put it on Sourceforge. Inthe meantime I would be grateful for any feedback..
http://www.willmcgugan.com/chess.zipI am aware of the chess module by Erik Max Francis. It may have beenmore sensible to work on his version, but I did this mainly for the funof it. I wrote a chess game in C++ a while back
(http://www.chesscommander.com) and I thought it would be interesting tore-implement the chess library part in Python.Regards,Will McGugan--
http://www.willmcgugan.com--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Will python never intend to support private, protected and public?

2005-09-29 Thread skip

 **Encapsulation** is one of the 3 basic characteristics of OOP.

This isn't an encapsulation issue.  From the first hit on Google for the
word:

In programming, the process of combining elements to create a new
entity.  For example, a procedure is a type of encapsulation because it
combines a series of computer instructions.  Likewise, a complex data
type, such as a record or class, relies on encapsulation.  Object-
oriented programming languages rely heavily on encapsulation to create
high-level objects.  Encapsulation is closely related to abstraction and
information hiding.

Python does encapsulation just fine.  Your beef is with its information
hiding.

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


  1   2   3   >