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

2005-10-04 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes:
> I assumed the Java model was based on the C++ model because it seems
> that everything in Java is based on C++, and they share the same
> vocabulary. If I'm wrong - well, that means you considered another
> language already.

I guess it's similar that way, however, C++ doesn't attempt any
enforcement at all, it has naked pointers, etc.

> Sure, Java might be a big improvement. But Python isn't Java. Rather
> than just throwing in something that works, do the legwork to verify
> that you're going to propose a best-of-breed solution. 

I don't think I've proposed anything so far.  I've just been trying to
answer some of the CPython cultists who claim that the concept is
useless.  I'd rather not think too carefully about Python changes of
this depth until after PyPy is fully deployed.  A lot of things that
some folks seem to think are deeply ingrained in Python, are really
just hacks that fell out of the C implementation.  Python has evolved
over time and it will continue to do so.

> If something perfect is available, wouldn't you feel awful if Python
> got saddled with something that wasn't perfected?

Oh, heaven forbid that anything like that might ever happen in Python. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Antoon Pardon
Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
>
>> Op 2005-10-03, Duncan Booth schreef <[EMAIL PROTECTED]>:
>>> Antoon Pardon wrote:
>>>
 A language where variable have to be declared before use, would allow
 to give all misspelled (undeclared) variables in on go, instead of
 just crashing each time one is encounterd.
>>>
>>> Wrong. It would catch at compile-time those misspellings which do not 
>>> happen to coincide with another declared variable.
>> 
>> Fine, it is still better than python which will crash each time
>> one of these is encountered.
>
> Python doesn't crash when it meets an undeclared variable. It raises an
> exception.

Your nit-picking. For the sake of finding misspelled variables the
difference is irrelevant.

>>> Moreover, it adds a burden on the programmer who has to write all those 
>>> declarations,
>> 
>> So? He has to write all those lines of code too.
>> 
>> People often promote unittesting here. Writing all those unittest is
>> an added burden too. But people think this burden is worth it.
>
> Yes, but there is no evidence that pre-declaration of variables is a
> burden worth carrying. It doesn't catch any errors that your testing
> wouldn't catch anyway.

Maybe not, but it may catch them earlier and may make them easier
to recognize.

Declarations also allow easier writable closures. Since the declaration
happens at a certain scope, the run time can easily find the correct
scope when a variable is rebound.

They also relieve a burden from the run-time, since all variables
are declared, the runtime doesn't has to check whether or not
a variable is accesible, it knows it is.

And if you provide type information with the declaration, more
efficient code can be produced.

>> I think writing declaration is also worth it. The gain is not as
>> much as with unittesting but neither is the burden, so that
>> balances out IMO
>
> Speaking as somebody who spent a long time programming in Pascal, I got
> heartedly sick and tired of having to jump backwards and forwards from
> where I was coding to the start of the function to define variables.

I have programmed a lot in Pascal too and Modula II and other languages.
I never found declarations that much a burden. That you got heartedly sick
of having to use declarations says very little about declarations and
says more about you.

I think language matters shouldn't be setlled by personal preferences.

> It got to the stage that sometimes I'd pre-define variables I thought I
> might need, intending to go back afterwards and delete the ones I didn't
> need. When the programmer is having to to jump through hoops to satisfy
> the compiler, there is something wrong.

Maybe it was your way of working. I never thought I had to go through
hoops to satisfy the compiler. You have to satisfy that compilor anyway,
for the moment I have more problems with colons that have to be put
after an "if", "else" etc than I ever had with declarations.

>>> and worse it adds a burden on everyone reading the code who 
>>> has more lines to read before understanding the code.
>> 
>> Well maybe we should remove all those comments from code too,
>> because all it does is add more lines for people to read.
>
> Well-written comments should give the reader information which is not in
> the code. If the comment gives you nothing that wasn't obvious from the
> code, it is pointless and should be removed.
>
> Variable declarations give the reader nothing that isn't in the code. If I
> write x = 15, then both I and the compiler knows that there is a variable
> called x. It is blindingly obvious. Why do I need to say "define x" first?

Because it isn't at all obvious at which scope that x is. Sure you can
define your language that rebinding is always at local scope, but that
you need to define it so, means it isn't that obvious.

Also the question is not whether or not there is a variable x, the
quesntions whether or not there should be a variable x. That is not
at all that obvious when you write x = 15.

> Pre-defining x protects me from one class of error, where I typed x
> instead of (say) n. That's fine as far as it goes, but that's not
> necessarily an _error_. If the typo causes an error, e.g.:

> def spam(n):
> return "spam " * x  # oops, typo
>
> then testing will catch it, and many other errors as well. Declaring the
> variable doesn't get me anything I wouldn't already get.

Yes it would have caught this error even before you had to begin
testing.

> But if it doesn't cause an error, e.g.:
>
> def spam(n):
> if n:
> return "spam " * n
> else:
> x = 0  # oops, typo
> return "spam " * n
> 
> This may never cause a failure, since n is always an integer. Since my
> other testing guarantees that n is always an integer,

This is naive. Testing doesn't guarantee anything. If this is what you
think about testing, then testing gives you a false impres

cgi relay for python cgi script

2005-10-04 Thread Amir Michail
Hi,

Is there an easy way to execute a python cgi script on a different
machine from the cgi server?

I could write my own server, but I was wondering if something is
available that would allow me to use a cgi script as is without
modification.

Amir

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Antoon Pardon
Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> On Mon, 03 Oct 2005 06:59:04 +, Antoon Pardon wrote:
>
>> Well I'm a bit getting sick of those references to standard idioms.
>> There are moments those standard idioms don't work, while the
>> gist of the OP's remark still stands like:
>> 
>>   egold = 0:
>>   while egold < 10:
>> if test():
>>   ego1d = egold + 1
>
> for item in [x for x in xrange(10) if test()]:
>
> But it isn't about the idioms. It is about the trade-offs. Python allows
> you to do things that you can't do in other languages because you
> have much more flexibility than is possible with languages that
> require you to declare variables before using them. The cost is, some
> tiny subset of possible errors will not be caught by the compiler. But
> since the compiler can't catch all errors anyway, you need to test for
> errors and not rely on the compiler. No compiler will catch this error:
>
> x = 12.0 # feet
> # three pages of code
> y = 15.0 # metres
> # three more pages of code
> distance = x + y
> if distance < 27:
> fire_retro_rockets()
>
> And lo, one multi-billion dollar Mars lander starts braking either too
> early or too late. Result: a new crater on Mars, named after the NASA
> employee who thought the compiler would catch errors.

Using (unit)tests will not guarantee that your programs is error free.

So if sooner or later a (unit)tested program causes a problem, will you
then argue that we should abondon tests, because tests won't catch
all errors.

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


Re: Python TNEF (winmail.dat attachment access) library?

2005-10-04 Thread Steven D'Aprano
Larry Bates wrote:

> Why not write Python class that uses CTypes and make it
> available as a recipe?  From a performance standpoint it
> is unlikely you can do better than to call the .dll and
> have it do the work for you.  Just a suggestion.

A pure Python solution will be cross-platform, while 
calling a Windows DLL will only work under Windows.

The optimal solution will be to call the DLL when it is 
available, and fall back on pure Python if it is not.


-- 
Steven.

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


Re: cgi relay for python cgi script

2005-10-04 Thread Fredrik Lundh
Amir Michail wrote:

> Is there an easy way to execute a python cgi script on a different
> machine from the cgi server?

http://www.google.com/search?q=reverse+proxy

 



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


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

2005-10-04 Thread Antoon Pardon
Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> On Mon, 03 Oct 2005 09:14:34 +, Antoon Pardon wrote:
>
>> If you are in a project with
>> multiple authors, your usage of private variables can break code
>> that other people rely on.
>
> If you are in a project with multiple authors, your usage of PUBLIC
> variables can break code that other people rely on.

Maybe then those shouldn't have been public variables in the first.

> That's why you have testing. You do test, don't you?

You do seem to think that testing will solve everything and
that any extra protection to get code correct is thus a
waste of time.

I don't share that view.

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


Re: semi-newbie module namespace confusion

2005-10-04 Thread David Murmann
Fredrik Lundh wrote:
> running a piece of python code as a script isn't the same thing as
> importing it as a module:

I ran into the same problem some time ago and even wanted to post here
about it, but found out that it had been reported as a bug three times
at sourceforge (if i remember correctly). The comments there explained
it of course, but I still think that this behavior is somehow "wrong".
I like to think of the import statement as a way to provide the names
defined in a module to the current namespace, so there is no "this gets
evaluated twice".
Now i wonder how difficult it would be to "correct" the behavior? And
would such a change break any code?

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


Re: semi-newbie module namespace confusion

2005-10-04 Thread Fredrik Lundh
David Murmann wrote:

> I ran into the same problem some time ago and even wanted to post here
> about it, but found out that it had been reported as a bug three times
> at sourceforge (if i remember correctly). The comments there explained
> it of course, but I still think that this behavior is somehow "wrong".
>
> I like to think of the import statement as a way to provide the names
> defined in a module to the current namespace, so there is no "this gets
> evaluated twice".

are you sure you understand the problem?  import does exactly what you
say; it creates a module object and populates it by running the code in the
module.

the problem is that when you hand Python a chunk of code (a script), it
doesn't necessarily know where it came from.  and even if you know the
filename it came from, there's no way to know if that chunk actually corre-
sponds to a module somewhere out there (the import system can map a
module name to a file, but it cannot map a file to a module name).

> Now i wonder how difficult it would be to "correct" the behavior?

there's no way to "fix" it without introducing a huge number of inconsistencies.

> And would such a change break any code?

any code that uses the "if __name__ == "__main__" pydiom, for a start.

 



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


Re: Python 3! Finally!

2005-10-04 Thread Christos Georgiou
On Fri, 30 Sep 2005 20:50:06 +0200, rumours say that Stefan Behnel
<[EMAIL PROTECTED]> might have written:

>Weird, though, the md5sum is the same as for the Python-2.4.2.tar.bz2 that I
>downloaded late (late!) yesterday evening and had forgotten in my download
>directory... just found it next to the new one... was still there, not
>overwritten...
>
>Well, maybe the changes needed to merit a V3 weren't that big after all...

No, it's just proof that the MD5 checksum isn't reliable and we should
move forward to SHA checksums.  Amazing coincidence.  Let's xpost to
some security newsgroup.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-04 Thread Christos Georgiou
On Tue, 27 Sep 2005 10:42:20 -0500, rumours say that Terry Hancock
<[EMAIL PROTECTED]> might have written:

>This works:
>
 bz2.decompress(eval(repr(user)))
>'huge'

>This may have some security issues, though, since it evaluates essentially
>any expression given for user.  I'd be interested to know if someone
>knows a more secure way.

given

a = "a tab\\x09between"

this is more secure than eval:

b= a.decode("string_escape")
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reply-To header

2005-10-04 Thread Steven D'Aprano
Mike Meyer wrote:

> When I notice that a list is broken (RFC 2822 says that
> reply-to is for the *author* of the message; anyone else setting it is
> doing so in violation of the RFC, and hence broken, no matter how
> useful it may be), 

Since when did obeying the RFC become important in and 
of itself? If there was a RFC that said that passwords 
should be limited to one alphanumeric character, would 
we slavishly follow it?

I have been known to change the reply-to address from 
the address I am sending from ([EMAIL PROTECTED] for example) to 
the address I want the reply to go to ([EMAIL PROTECTED]). There 
are many times I'm emailing people I know can't cope 
with the complicated task of changing the To address of 
their reply, so I change the reply-to header so that 
their reply goes where I want it to go to (which might 
be another email address of mine, or a different 
person, or a mailing list).

That's what reply to means, surely? What is the point 
of a reply-to header that must be the sender, since you 
already have a header that gives you the sender.

If the RFC says that the reply-to header doesn't 
actually mean the address the reply should go to, but 
only the sender, then the RFC is broken. "Where the 
reply goes to" is a *human* decision, not a technical 
one. If I send you an email saying "Please reply to 
[EMAIL PROTECTED]" then your mailer should 
honour that (although, since we are all adults, you 
should have the freedom to ignore my request and make a 
nuisance of yourself by emailing your reply to a 
different address).

Likewise, if I set the reply address to the list, then 
your mailer should reply to the list. Perhaps you can 
argue that *my decision* to have replies go to the list 
is a bad one, but that's a social issue, not a 
technical one.


> I tell my mailer to ignore reply-to on mail from
> that list. Similarly, I no longer try and explain to people how long
> lines violate RFCs and are a pain to read in well-behave mail readers,

By "well-behaved", do you mean "can't cope with long 
lines"? How curious -- that's precisely the opposite 
definition of well-behaved I use.

> or why mail readers that wrap text/plain content are broken.

Curiouser and curiouser. Again that's the exact 
opposite of my definition of broken.


-- 
Steven.

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


Re: Reply-To header

2005-10-04 Thread Roel Schroeven
Mike Meyer wrote:
> Roel Schroeven <[EMAIL PROTECTED]> writes:
> 
>>Is that really the desired behaviour? IMO the least you can do if you're
>>searching for help is subscribing to the mailing list on which you're
>>looking for help. Me and many others don't like to receive replies
>>directly instead of via the mailing list; it's of no use, since we're
>>subscribed to the mailing list anyway.
> 
> 
> Rather than asking everyone else to modify their behavior for your
> convenience, why don't you fix the problem at your end? Check to see
> if the list will filter duplicates for you. Check to see if your
> mailer will filter duplicates for you. Or grit and bear it. You'll
> almost certainly get less unwanted mail from people who send you
> duplicates in reply to your messages than they would get from
> subscsribing to the list.

Don't overreact please -- I was just asking if what you described is
really the desired behavior, along with some of the reasons why I'm not
sure that it is. My experience of reading a number of mailing lists
throughout the years seem to indicate that most people prefer that
people looking for help subscribe to the mailing list. I might be wrong
of course, that's why I stated it as a question.

-- 
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: Python based unacceptable language filter

2005-10-04 Thread Frithiof Andreas Jensen

"David Pratt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi. Thank you for the links. I am looking for something that would
> function in a similar way to Yahoo's filter for it's message boards.
> Perhaps I should have used the term profanity instead of unacceptable
> language. I am not concerned about correcting sentence structure or
> poor grammar.

 Yo melonfarmer, you should watch the non-profane version of Repo-Man for
inspiration -  ;-)

PS:

Sites like "The Profanisaurus" provides plenty of workarounds for most of
the filters out there.


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


Re: Graphical debugger/code explorer

2005-10-04 Thread Florian Lindner
benz wrote:

PYTHON_IDE={
> 'spe' : 'http://spe.pycs.net/',
> 'eric3' : 'http://www.die-offenbachs.de/detlev/eric3.html',
> 'drpython' : 'http://drpython.sourceforge.net/'}

I've tried out eric3 and it looks promising. However, I have one problem. I
open a file which is part of Zope and set a breakpoint. Now I open the
runzope start script and execute it from within eric. This runzope script
calles (after running through a larger call-tree) the function where I set
the breakpoint. But execution is not stopped there Why?

Thanks,

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


Re: semi-newbie module namespace confusion

2005-10-04 Thread David Murmann
Fredrik Lundh wrote:
> David Murmann wrote:
> 
>> I ran into the same problem some time ago and even wanted to post here
>> about it, but found out that it had been reported as a bug three times
>> at sourceforge (if i remember correctly). The comments there explained
>> it of course, but I still think that this behavior is somehow "wrong".
>>
>> I like to think of the import statement as a way to provide the names
>> defined in a module to the current namespace, so there is no "this gets
>> evaluated twice".
> 
> are you sure you understand the problem?  import does exactly what you
> say; it creates a module object and populates it by running the code in the
> module.
maybe i don't... but i'm not convinced yet, see below.

> the problem is that when you hand Python a chunk of code (a script), it
> doesn't necessarily know where it came from.  and even if you know the
> filename it came from, there's no way to know if that chunk actually corre-
> sponds to a module somewhere out there (the import system can map a
> module name to a file, but it cannot map a file to a module name).
well, in my opinion python is not trying hard enough. to me it is
immediately obvious that the main module gets evaluated twice and
i am rather sure that one could introduce some magic of the kind
"oh, i reevaluate the main script here, the module does not get filled
the usual way but uses the existing objects instead". this would have
to happen on a very low level (when the file i just read from is known)
but i think it would be possible. whether the effort to do so is worth
it, is a different question...

>> Now i wonder how difficult it would be to "correct" the behavior?
> 
> there's no way to "fix" it without introducing a huge number of 
> inconsistencies.
> 
>> And would such a change break any code?
> 
> any code that uses the "if __name__ == "__main__" pydiom, for a start.
i wouldn't lose that, the main module should still be named "__main__",
it should just get more names (somehow) :)
i see, it's difficult at the moment

hoping i'm not completely wrong here, David.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Debug Build

2005-10-04 Thread Gerhard Häring
Fredrik Lundh wrote:
> "Celine & Dave" wrote:
> 
> 
>>What happens if I build Python with debug option
>>(--with-pydebug)? Do I see any changes in my program
>>output? What is --with-pydebug good for?
> 
> 
> from the README:
> 
> --with-pydebug:  Enable additional debugging code to help track down
> memory management problems.  This allows printing a list of all
> live objects when the interpreter terminates.

And that's why it's very useful for when developing Python extension 
modules. Not only does it help find reference count problems, 
--with-pydebug on, Python sometimes also complains earlier if you do 
"stupid" things in the C code. Or gives a helpful error message before 
crashing ;-)

-- Gerhard

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Steven D'Aprano
Mike Meyer wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> 
>>Declared variables have considerable labour costs, and only marginal
>>gains. Since the steps you take to protect against other errors will also
>>protect against mistyping variables, declarations of variables is of
>>little practical benefit.
> 
> 
> As far as I can tell, this is as much hearsay and personal experience
> as the alternate claim that not having them costs you lots of
> debugging time and errors. If anyone has pointers to real research
> into this area (I've heard the TRAK folks did some, but haven't been
> able to turn any up), I'd love to hear it.

Sorry, I have no hard research to point to. If I did, I 
would have referenced it.

> My gut reaction is that it's a wash. The time taken to declare
> variables in well-written code in a well-designed language - meaning
> the declarations and use will be close together - isn't all that
> great, but neither are the savings.

It isn't the typing time to declare variables, it is 
the context switching. You're focused on implementing 
an algorithm, realise you need to declare another 
variable, your brain does a mini-context switch, you 
scroll up to the declaration section, you declare it, 
you scroll back to where you were, and now you have to 
context switch again.

You've gone from thinking about the implementation of 
the algorithm to thinking about how to satisfy the 
requirements of the compiler. As context switches go, 
it isn't as big as the edit-compile-make-run method of 
testing, but it is still a context switch.

Or you just code without declaring, intending to go 
back and do it later, and invariably forget.

[snip]

> If I'm going to get compiler support for semantic checking like this,
> I want it to serious levels. I want function pre/post conditions
> checked. I want loop and class invariant checked. I want subsumption
> in my inheritance tree. Nuts - I want a complete, well-designed
> inheritance tree. Duck typing is great stuff, but if I'm going to be
> doing the work to declare everything, I want *everything* that can be
> checked checked.

We like to think of programming as a branch of 
engineering. It isn't, not yet.

I've worked for architects who were involved in some 
major engineering projects. One of the things I learnt 
is that there are times when you need to specify 
objects strictly. When only a 5% titanium stainless 
steel alloy will do, then *only* a 5% titanium 
stainless steel alloy will do. That's when you want 
strict type-checking.

But the rest of the time, just about any stainless 
steel will do, and sometimes you don't even care if it 
is steel -- iron will do the job just as well. If the 
nail is hard enough to be hammered into the wood, and 
long enough to hold it in place, it is good enough for 
the job. That's the real-world equivalent of duck typing.

Static typed languages that do all those checks are the 
equivalent of building the space shuttle, where 
everything must be specified in advance to the nth 
degree: it must not just be a three inch screw, but a 
three inch Phillips head anti-spark non-magnetic 
corrosion-resistant screw rated to a torque of 
such-and-such and capable of resisting vaccuum welding, 
extreme temperatures in both directions, and exposure 
to UV radiation. For that, you need a compiler that 
will do what Mike asks for: check *everything*.

I don't know whether there are languages that will 
check everything in that way. If there aren't, then 
perhaps there should be. But Python shouldn't be one of 
them. Specifying every last detail about the objects 
making up the space shuttle is one of the reasons why 
it costs umpty-bazillion dollars to build one, and 
almost as much to maintain it -- and it still has a 
safety record worse than most $10,000 cars.

That level of specification is overkill for most 
engineering projects, and it's overkill for most 
programming projects too. It is all well and good to 
tear your hair and rip your clothes over the 
possibility of the language allowing some hidden bug in 
the program, but get over it: there is always a trade 
off to be made between cost, time and risk of bugs. 
Python is a language that makes the trade off one way 
(fast development, low cost, high flexibility, moderate 
risk) rather than another (slow development, high cost, 
low flexibility, low risk).

We make the same trade offs in the real world too: the 
chair you sit on is not built to the same level of 
quality as the space shuttle, otherwise it would cost 
$100,000 instead of $100. Consequently, sometimes 
chairs break. Deal with it.


-- 
Steven.

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


Re: Reply-To header

2005-10-04 Thread Steve Holden
Steven D'Aprano wrote:
> Mike Meyer wrote:
> 
> 
>>When I notice that a list is broken (RFC 2822 says that
>>reply-to is for the *author* of the message; anyone else setting it is
>>doing so in violation of the RFC, and hence broken, no matter how
>>useful it may be), 
> 
> 
> Since when did obeying the RFC become important in and 
> of itself? If there was a RFC that said that passwords 
> should be limited to one alphanumeric character, would 
> we slavishly follow it?
> 
The day such an RFC is published will be the day RFCs stop being useful. 
Until that time the RFCs are pretty much the guide to desired behaviour 
on the Internet, and anyone willfully disobeying them is asking for trouble.

If an RFC was published saying you should give yourself a kick in the 
head for such inanity would you do it? ;-)

> I have been known to change the reply-to address from 
> the address I am sending from ([EMAIL PROTECTED] for example) to 
> the address I want the reply to go to ([EMAIL PROTECTED]). There 
> are many times I'm emailing people I know can't cope 
> with the complicated task of changing the To address of 
> their reply, so I change the reply-to header so that 
> their reply goes where I want it to go to (which might 
> be another email address of mine, or a different 
> person, or a mailing list).
> 
This is an entirely sensible use of the Reply-To address, and indeed 
many mail clients nowadays will allow you to set a Reply-To for each of 
the accounts you create.

Having in the past used accounts where the Reply-To was different from 
the originating address I am only too well aware, though, that there are 
several email clients and mailing systems that *don't* correctly action 
Reply-To, and instead respond to the originating address directly.

> That's what reply to means, surely? What is the point 
> of a reply-to header that must be the sender, since you 
> already have a header that gives you the sender.
> 
Quite.

> If the RFC says that the reply-to header doesn't 
> actually mean the address the reply should go to, but 
> only the sender, then the RFC is broken. "Where the 
> reply goes to" is a *human* decision, not a technical 
> one. If I send you an email saying "Please reply to 
> [EMAIL PROTECTED]" then your mailer should 
> honour that (although, since we are all adults, you 
> should have the freedom to ignore my request and make a 
> nuisance of yourself by emailing your reply to a 
> different address).
> 
Of course, few users actually bother to even check whether the address 
their mailer generates corresponds to anything in the original message, 
instead blindly relying on their software's behaviour for correctness 
(see above).

> Likewise, if I set the reply address to the list, then 
> your mailer should reply to the list. Perhaps you can 
> argue that *my decision* to have replies go to the list 
> is a bad one, but that's a social issue, not a 
> technical one.
> 
Most mailers will indeed do this. Except the ones that don't (see above 
...).

> 
> 
>>I tell my mailer to ignore reply-to on mail from
>>that list. Similarly, I no longer try and explain to people how long
>>lines violate RFCs and are a pain to read in well-behave mail readers,
> 
[...]

Having a mailer that can vary its behaviour from one list to another is 
something that's way beyond 90% of Internet mail users nowadays. Sadly 
we are talking about a problem that the majority of users don't even 
understand, happily sending their rich-text and HTML emails to mailing 
lists/newsgroups as well as individuals.

regards
  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: Graphical debugger/code explorer

2005-10-04 Thread ld
Florian Lindner wrote:

> Hello,
> in order to understand python code from a larger project (Zope 3) I'm
> looking for a tool that helps me with that. It should also help
> What (graphical) application running on Linux can you recommend?

Maybe you shoud tryy doxygen/happydoc etc?

Doxygen support python, just add '.py' extension to understanable files and
output syntax to 'java-like'.


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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Max M
spiffo wrote:
> The Main Issue in a nutshell
> 
> I am a corporate developer, working for a single company. Got a new project
> coming up and wondering if I should stay with Python for this new, fairly
> large project, are jump back on the 'safe' M$ bandwagon using a dot net
> language?


Hehe ...

I can run my very first Python program right now in the current version 
of Python. I cannot even find a platform to run my .asp code from that 
same timeframe ... So much for 'safe'!


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about smtplib

2005-10-04 Thread Piet van Oostrum
> Tim Roberts <[EMAIL PROTECTED]> (TR) wrote:

>TR> [EMAIL PROTECTED] wrote:
>>> cool. so this line
>>> server = smtplib.SMTP(localhost)
>>> is when i connect ?

>TR> Use the source, Luke.  Source code for every standard module is included on
>TR> your hard disk.  If you look in the __init__ for "class SMTP", your
>TR> question will be answered.

The documentation should be the ultimate reference for the API. The source
is just implementation detail which may change in the future.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Lasse Vågsæther Karlsen
While Microsoft and other big software vendors might have a roadmap
that ties you very tightly in with their budget, and also changes that
roadmap from time to time which breaks your current software, a lot of
open source projects have no roadmap at all.

This means that a .x.y.2 upgrade might very well kill your software in
the same way a 6-7 upgrade with VB might. The biggest reason for this,
as far as I can tell, is that open source projects are very much built
to integrate with other projects, simply because the source is
available and it's thus far easier to integrate them, but that also
means that unless you upgrade two integrated projects at the same time,
you risk an upgrade in one breaking the other.

As an example, Komodo from ActiveState has serious problems (on my 4
computers) debugging functions with Python 2.4.2. Right now I don't
know if Python 2.4.2 fixed a bug Komodo depended on or if 2.4.2
introduced a bug breaking Komodo, or if my computer is some freaky
thing that just refuses to behave. I'm reinstalling my office computer
these days so I'll see what happens then, but until that's done, I've
had to go back to 2.4.1 in order to debug properly.

With a 6.0 to 7.0 upgrade for a project, I expect problems. Even
Microsoft came out and said this new release will definitely break your
software projects. The whole point of an upgrade is that something that
did X before, does Y now, something different. Preferrably Y = X+1, but
sometimes it's radically different.

I think a main point in a lot of projects is that unless you have to
upgrade, don't. That way you can avoid a lot of problems by default.

Now, as for OP, the only way to easily get full support for all the new
Microsoft technology when it comes out will probably be to upgrade to
the latest and the greatest of the Microsoft tools. I bet the Python
community will react quicker than you can turn your head, but the tools
will still not be the same as Microsoft. Does it mean they won't be as
good ? No, it means they will be different. It means that you probably
can't follow Microsoft help when dealing with Python modules.

And that, is exactly as it should be.

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


Processing an image with numarray.nd image

2005-10-04 Thread Raphaël MARC
Hello,

Can anyone tell me how to open an image
and transform it into a list so that
the functions of the multi dimensionnal module of
numarray (numarray.nd image) can process it ?

Do I have to use PIL ?

So I would code something like :
import Image
im = Image.open("Python.jpg")
data = list(im.getdata())
import numarray.nd image as ti
ti.median filter(data,...)

Is that the correct way to do ?


Thanks for any help.


Raphaël
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Lasse Vågsæther Karlsen
Ok, when re-reading my post it seems that I'm saying that Python has no
roadmap. That was not my intent. I meant projects other than Python,
even though the problems I got with 2.4.2 is real, I suspect there's
something in Komodo that is the problem since I can run all my python
programs with 2.4.2 without problems, just not in Komodo.

I'll go wash my mouth now :P

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Frithiof Andreas Jensen

"bruno modulix" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> James A. Donald wrote:
> > I am contemplating getting into Python, which is used by engineers I
> > admire - google and Bram Cohen, but was horrified
>
> "horrified" ???
>
> Ok, so I'll give you more reasons to be 'horrified':
> - no private/protected/public access restriction - it's just a matter of
> conventions ('_myvar' -> protected, '__myvar' -> private)
> - no constants (here again just a convention : a name in all uppercase
> is considered a constant - but nothing will prevent anyone to modify it)
> - possibility to add/delete attributes to an object at runtime
> - possibility to modify a class at runtime
> - possibility to change the class of an object at runtime
> - possibility to rebind a function name at runtime
> 
>
> If you find all this horrifying too, then hi-level dynamic languages are
> not for you !-)

Not to mention that since the O.P. seem to assume that the compiler will
protect against deliberate subversion by evil programmers then he must be
further "horrified" to learn that, although it is harder to do the above in
f.ex. C++, it is not at all impossible, a carefully crafted pointer or a
little devious sub-classing goes a long way.

If all else fails, The humble Linker holds the Word of Power!

Tampering with linking is both the easiest way to subvert code reviews,
language checks and boundaries and also the hardest to discover because the
tampering will be buried somewhere deep inside the build process, the part
that never, ever gets reviewed because it is automated anyway and too
complex entirely so nobody sane will actually mess with it once it "works"
i.e. produces runnable code!.

Finally, given proper  permissions, one can of course re-link the binary
executable, should the occasion merit. Like when one needs HIP in Telnet
which is an absolute brd to build on a modern Linux box. (Somebody build
that *once* in maybe 1978, I think ;-) One can replace classes in Jar
archives too - possibly one can even get the Java runtime to load the "new
version" of a jar archive in preference to the shipped one ...


I.O.W:

Superficially, the compile-time checks of Java and C++ provides some checks
& boundaries but it comes at the expense of much more machinery with many
more intricate movable parts than *also* can be interfered with (or broken).

Python is simple and self-contained, thus it is pretty obvious - or at least
not too difficult, to check what *actually* goes on with an application.

If there is no trust, nothing can be done safely. If there is trust, then
most of the percieved safety just get in the way of work.


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


IDE crash

2005-10-04 Thread accolades
We've discussed this before in the group; IDEs that crash on completion
of a PyGame or PyOgre (or any other graphics library) script.

I have had this result with pretty much every IDE that I have tried.
Except Eclipse.

I just wanted to let everyone know, (in case anyone else out there is
picky about  being able to launch their program from within an IDE)
that Eclipse with PyDev or TruStudio does not crash upon exit of
graphics mode applications.

I have been using Eclipse with PyDev exclusively for a few weeks now,
and I am very pleased with the results.

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


Re: Controlling who can run an executable

2005-10-04 Thread Cigar
Mike Meyer wrote:
> First thing to know; you can't stop someone who's sufficiently
> determined to run the program.

I have explained to her that I can't prevent someone who REALLY wants
her program from tossing a rock through her front window and making off
with her PC.  They'd get the hardware and the executable along with the
client and transactions data.  She conceeded that that would be out of
my scope of being able to protect her program.

> > Ideas I've had to prevent someone from running the app:
> > - ask for a password every time the program is run. (I wonder how
> > quickly they will complain about this, not very secure once everyone
> > eventually finds out what the password is)
>
> If only authorized people have the password, then this works. The
> problem is that her employees are probably authorized, but she doesn't
> trust them to not take the program to her competition. Which brings
> up an alternative goal:

I may have to just put password protection in and if she hangs herself
by 'sharing' the password with underlings she trusts (at the
present)... again that's outside of my control of protecting her.

> > What I want:
> > - the simplest thing that could possibly work!
>
> Telling her "Don't let your employees near the computer with media, or
> when it's connect to a network."

Currently this app is running on a stand alone PC.  There was a big
concern about hackers getting at her program or data from over the
internet.  I complemented her on this level of security.  No floppy
drive either.

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Antoon Pardon
Op 2005-10-04, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> Mike Meyer wrote:
>
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> 
>>>Declared variables have considerable labour costs, and only marginal
>>>gains. Since the steps you take to protect against other errors will also
>>>protect against mistyping variables, declarations of variables is of
>>>little practical benefit.
>> 
>> 
>> As far as I can tell, this is as much hearsay and personal experience
>> as the alternate claim that not having them costs you lots of
>> debugging time and errors. If anyone has pointers to real research
>> into this area (I've heard the TRAK folks did some, but haven't been
>> able to turn any up), I'd love to hear it.
>
> Sorry, I have no hard research to point to. If I did, I 
> would have referenced it.
>
>> My gut reaction is that it's a wash. The time taken to declare
>> variables in well-written code in a well-designed language - meaning
>> the declarations and use will be close together - isn't all that
>> great, but neither are the savings.
>
> It isn't the typing time to declare variables, it is 
> the context switching. You're focused on implementing 
> an algorithm, realise you need to declare another 
> variable, your brain does a mini-context switch, you 
> scroll up to the declaration section, you declare it, 
> you scroll back to where you were, and now you have to 
> context switch again.
>
> You've gone from thinking about the implementation of 
> the algorithm to thinking about how to satisfy the 
> requirements of the compiler. As context switches go, 
> it isn't as big as the edit-compile-make-run method of 
> testing, but it is still a context switch.
>

Nobody forces you to work this way. You can just finish
your algorithm and declare your variables afterwards.

Besides likewise things can happen in python. If you
suddenly realise your class needs an instance variable,
chances are you will have to add initialisation code
for that instance variable in the __init__ method.
So either you do a context switch from implementing
whatever method you were working on to the initialisation
in __init__ and back or you just code without 
initialisation, intending to go back an do it later.

> Or you just code without declaring, intending to go 
> back and do it later, and invariably forget.

What's the problem, the compilor will allert you
to your forgetfullness and you can then correct
them all at once.

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


Re: Controlling who can run an executable

2005-10-04 Thread Paul Rubin
"Cigar" <[EMAIL PROTECTED]> writes:
> I may have to just put password protection in and if she hangs herself
> by 'sharing' the password with underlings she trusts (at the
> present)... again that's outside of my control of protecting her.

You could have the password automatically change once a month.  Give
her a master list of passwords and tell her to lock it away.  Each
month she refers to the list and gives underlings a new password.

> Currently this app is running on a stand alone PC.  There was a big
> concern about hackers getting at her program or data from over the
> internet.  I complemented her on this level of security.  No floppy
> drive either.

If the app is not being used too often, install it on a laptop and
lock the laptop in a drawer when not in use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes:
> > Or you just code without declaring, intending to go 
> > back and do it later, and invariably forget.
> 
> What's the problem, the compilor will allert you
> to your forgetfullness and you can then correct
> them all at once.

Thiat in fact happens to me all the time and is an annoying aspect of
Python.  If I forget to declare several variables in C, the compiler
gives me several warning messages and I fix them in one edit.  If I
forget to initialize several variables in Python, I need a separate
test-edit cycle to hit the runtime error for each one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pywordnet install problems

2005-10-04 Thread vdrab
Thanks, I already figured it out a few days ago.

In the wordnet.py file, just override the path (WNHOME and/or WNSEARCH)
to the wordnet 2.0directory that has the lexnames files etc... (on my
ubuntu box: '/usr/share/wordnet')
That seems to fix it, although python gives a few warnings at startup.
checking the web it seems this is a known issue.
Thanks for the help though... I didn't bother posting the solution as I
thought noone was interested anymore. 

cheers,
vdrab.

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


Re: Controlling who can run an executable

2005-10-04 Thread Cigar
Paul Rubin wrote:
> "Cigar" <[EMAIL PROTECTED]> writes:
> > Now that I'm three months into the development of this program, my
> > client tells me she would like to protect her investment by preventing
> > her employees from doing the same to her.  (Going to the competition
> > and using her program.)
>
> Exactly what is the threat here?

I think the BIGGEST threat here is a feeling of vulnerablity.  She now
realizes that she is in a position that her competition was many years
ago when she came into possesion of program the 'other side' was using
and that she is now vulnerable.  She wants to feel safe in the
knowledge that she didn't reach into her pocket and pay thousands of
dollars for a program that now could now be used by her competition.
Nobody wants to pay money to level the playing field for all in a
business environment.

> Misuse of confidential data, or

It's just a collection of names, addresses, phone numbers, birthdays
and drivers licences/health cards.  I can think of a few dishonest
things that could be done with this but her competition has the
basically the same clients.

> just the code itself?
> Does the code do anything that fantastic?

Not by my standards but it is slowly replacing a paper system.  (Police
officer shows up and says 'We've just arrested John Smith.  Has he sold
you anything in the last 90 days.  The client says 'Just a minute' and
reaches for a set of 4" d-ring binders and turns hundreds of pages
looking for a Smith name...)  My client is relived that this senario
will soon disappear.

> Did the employees sign NDA's?  Usually this kind of thing is taken care of by
> legal agreements.

Good question!  I'm pretty sure not but that's something I could
suggest to her.

> What is the competitor going to do with this code even if they get it?

Simplify their lives.  See above.

> It's just keeping track of transactions and stuff, right?

You are correct sir.

> It's being
> tailored to one person's specific preferences and requirements, and
> the competitor's needs will be different and they may as well just use
> something generic.

Not really.  The client just wants to track people and what they buy,
sell or put on buyback.  Their competitions needs are the same.

> Also, is there an office network?  Maybe you could run the program on
> a server that most employees wouldn't have access to.  They'd use it
> through some limited client program or through a web browser.

A network exists but the client insists on a standalone PC.

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


Re: Processing an image with numarray.nd image

2005-10-04 Thread Matt Feinstein
On Tue, 04 Oct 2005 11:56:51 +0200, Raphaël MARC
<[EMAIL PROTECTED]> wrote:

>Hello,
>
>Can anyone tell me how to open an image
>and transform it into a list so that
>the functions of the multi dimensionnal module of
>numarray (numarray.nd image) can process it ?
>
>Do I have to use PIL ?
>
>So I would code something like :
>import Image
>im = Image.open("Python.jpg")
>data = list(im.getdata())
>import numarray.nd image as ti
>ti.median filter(data,...)

I've been doing something like that...

from numarray import  *
import numarray.nd_image as Filter
import PIL.Image as Image

im = Image.open(file_name)
array_dat = reshape(array(list(im.getdata())), im.size)
filt_array_dat = Filter.correlate(array_dat, my_filter)

et cetera...

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: semi-newbie module namespace confusion

2005-10-04 Thread Andrew Gwozdziewycz
well, in my opinion python is not trying hard enough. to me it isimmediately obvious that the main module gets evaluated twice andi am rather sure that one could introduce some magic of the kind"oh, i reevaluate the main script here, the module does not get filledthe usual way but uses the existing objects instead". this would haveto happen on a very low level (when the file i just read from is known)but i think it would be possible. whether the effort to do so is worthit, is a different question...There is an easy fix to this situation, and it's called creating a new script that imports the modules. If it's truely a module (which I guess really everything in python is), it probably should only be run by itself for testing purposes only.Now i wonder how difficult it would be to "correct" the behavior? there's no way to "fix" it without introducing a huge number of inconsistencies.Plus, it's not broken to begin with. ---Andrew Gwozdziewycz[EMAIL PROTECTED]http://ihadagreatview.orghttp://plasticandroid.org -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Thread's, async_chat and asyncore

2005-10-04 Thread Matt Hammond
Hi Jos,

Have you looked at Kamaelia? Its a project I'm involved in to create a  
framework for highly concurrent systems, geared particularly for  
suitability for network server/client applications.

A system is built out of many small components, each with their own  
pseudo-thread of execution (implemented as python generators). They  
communicate with each other by reading from and sending to local inboxes  
and outboxes. These are then linked together, causing messages to be  
passed from component to component.

We're hopefully going to be making a new release soon, with some more  
interesting facilities. A Kamaelia system doing something similar could  
look something like this:

code snippet starts

#!/usr/bin/env python

 from Axon.Component import component
import time
import random

class PulseGenerator(component):
 def __init__(self, msg):
 super(PulseGenerator,self).__init__()
 self.msg = msg

 def main(self): # microprocess (generator)
 t=time.time()
 while 1:
 while time.time() < t:
 yield 1 # hand back control to scheduler
 t += random.random()
 self.send( self.msg, "outbox")


if __name__ == "__main__":
 from Kamaelia.Util.Splitter import Plug, PlugSplitter
 from Kamaelia.Chassis.ConnectedServer import SimpleServer
 from Kamaelia.Util.passThrough import passThrough
 from Axon.Scheduler import scheduler

 producer = PlugSplitter(PulseGenerator("hello!\n")).activate()

 def newClientHandler():
 return Plug(producer, passThrough()).activate()

 SimpleServer( protocol = newClientHandler, port = 1601 ).activate()

 scheduler.run.runThreads()

code snippet ends

The SimpleServer component uses the factory function 'newClientHandler' to  
create a component to handle the new client connection. In this case, its  
a 'plug' component that connects to a splitter component. The purpose of  
the splitter is to copy output to multiple destinations. In this case, the  
output comes from a PulseGenerator component.

In the above system there's only one producer. To deal with multiple  
games, I guess you'd have to write a component that handles the initial  
'conversation' with the client to establish which game they want to  
connect to, before then creating the 'plug' component to connect to the  
appropriate game server.

This is of course only one way to do it, and the 'plug' arrangement might  
not be the best eventual solution. We've also got a lookup-service, called  
the Co-ordinating Assistant Tracker. It translates name to references to  
inboxes or outboxes on components. You could, for example, use this  
service to look up components handling specific games.

I'd encourage you to take a look at our project site on sourceforge  
( http://kamaelia.sf.net/ ). There's some more introductory material and a  
tutorial or two which should give you a better idea about the system.

We'd be interested to know what you think, and whether you think you could  
build your application using it.

regards


Matt


-- 

| Matt Hammond
| R&D Engineer, BBC Research & Development, Tadworth, Surrey, UK.
| http://kamaelia.sf.net/
| http://www.bbc.co.uk/rd/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling who can run an executable

2005-10-04 Thread Paul Rubin
"Cigar" <[EMAIL PROTECTED]> writes:
> I think the BIGGEST threat here is a feeling of vulnerablity.  She now
> realizes that she is in a position that her competition was many years
> ago when she came into possesion of program the 'other side' was using
> and that she is now vulnerable.  She wants to feel safe in the
> knowledge that she didn't reach into her pocket and pay thousands of
> dollars for a program that now could now be used by her competition.
> Nobody wants to pay money to level the playing field for all in a
> business environment.

Suppose that competitor's program that her employee had illicitly
brought her wasn't protected, so she was able to run it.  You might
ask her whether, ethical issues aside, she would be willing to use it
on a daily basis, given it sounds like people in her industry know
each other enough that word would probably get back to the competitor,
and any resulting lawsuit would leave her up a creek.  If she's not
willing to use her competitor's program under those cirumstances,
should she really be afraid of her competitor using hers?  Also, if
all she got from the competitor was an .exe, she'd have no way to
customize it, and vice versa.

> It's just a collection of names, addresses, phone numbers, birthdays
> and drivers licences/health cards.  I can think of a few dishonest
> things that could be done with this but her competition has the
> basically the same clients.

Well, that sounds pretty confidential to me, but I'll take your word
for it that the competitors are more interested in the code than the
data.  I do think she's overestimating the threat.

> Not by my standards but it is slowly replacing a paper system.  (Police
> officer shows up and says 'We've just arrested John Smith.  Has he sold
> you anything in the last 90 days.  The client says 'Just a minute' and
> reaches for a set of 4" d-ring binders and turns hundreds of pages
> looking for a Smith name...)  My client is relived that this senario
> will soon disappear.

Is there something there that you can't do with a few spreadsheet macros?

> > What is the competitor going to do with this code even if they get it?
> Simplify their lives.  See above.

Lawsuits don't simplify anyone's life ;-).

> > Also, is there an office network?  Maybe you could run the program on
> > a server that most employees wouldn't have access to.  They'd use it
> > through some limited client program or through a web browser.
> 
> A network exists but the client insists on a standalone PC.

How about two PC's connected by a piece of ethernet cable, but no
outside network connection.  The server is a laptop or palmtop locked
in a desk drawer.  A little hole is drilled in the back of the drawer
for the power and network cables.  The network cable is connected to a
PC on top of the desk that the employees actually use, running a web
browser or the like.
-- 
http://mail.python.org/mailman/listinfo/python-list


What is executed when in a generator

2005-10-04 Thread Jerzy Karczmarczuk
I thought that the following sequence

gl=0
def gen(x):
 global gl
 gl=x
 yield x

s=gen(1)

suspends the generator just before the yield, so after the
assignment of s gl becomes 1.

Well, no. It is still zero. If I put

print "something"

before the yield, this doesn't get executed either. *EVERYTHING*
from the beginning until the yield gets executed only upon s.next().

Could you tell me please where can I read something in depth about the
semantics of generators? I feel a bit lost.
Thank you.


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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Peter Decker
On 10/3/05, spiffo <[EMAIL PROTECTED]> wrote:

> I am a corporate developer, working for a single company. Got a new project
> coming up and wondering if I should stay with Python for this new, fairly
> large project, are jump back on the 'safe' M$ bandwagon using a dot net
> language? Cross platform is NOT an issue, but COMPLETE control/compatability
> with MsSql Server (current and future versions) certainly is.
>
> Quick History
>
> Started out 10+ yrs ago using FoxPro, upgrading as Fox did, was a good
> system but never really loved it due to many factors I won't get into now.
>
> Did alot of work in Delphi, once version 5 came out... really loved it for
> awhile. Began using MS SQL server as database.
>
> Had a HUGE re-write of an old dos-based database system to do, did alot of
> work on it in Delphi 7, but really began to have issues with Delphi, even
> tho alot of it is fantastic.

Hey, you might want to take a look at Dabo . It
was written by a couple of ex-Fox guys, and is a complete 3-tier app
framework. They support several databases on the backend, and have
announced that they are looking for someone to help them add MS-SQL to
that list.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cgi relay for python cgi script

2005-10-04 Thread Amir Michail
Fredrik Lundh wrote:
> Amir Michail wrote:
>
> > Is there an easy way to execute a python cgi script on a different
> > machine from the cgi server?
>
> http://www.google.com/search?q=reverse+proxy
>
> 

Is there an easy way to do this without modifying the configuration of
the cgi server and without running a cgi server on the other machine
where the script will actually run?

Perhaps someone wrote a simple server that provides the required
environment for the cgi script to run?

I'm looking for something simple that does not require root access.

Amir

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


Re: What is executed when in a generator

2005-10-04 Thread Fredrik Lundh
Jerzy Karczmarczuk wrote:

> Could you tell me please where can I read something in depth about the
> semantics of generators? I feel a bit lost.

the behaviour is described in the language reference manual:

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

"When a generator function is called, it returns an iterator known as a
generator iterator, or more commonly, a generator. The body of the
generator function is executed by calling the generator's next()
method repeatedly until it raises an exception."

the above page points to the design document, which contains the full
story:

http://www.python.org/peps/pep-0255.html

"When a generator function is called, the actual arguments are bound to
function-local formal argument names in the usual way, but no code in
the body of the function is executed.  Instead a generator-iterator
object is returned; this conforms to the iterator protocol /.../

Each time the .next() method of a generator-iterator is invoked, the
code in the body of the generator-function is executed until a yield
or return statement (see below) is encountered, or until the end of
the body is reached."

 



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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Steve Holden
Paul Rubin wrote:
> Antoon Pardon <[EMAIL PROTECTED]> writes:
> 
>>>Or you just code without declaring, intending to go 
>>>back and do it later, and invariably forget.
>>
>>What's the problem, the compilor will allert you
>>to your forgetfullness and you can then correct
>>them all at once.
> 
> 
> Thiat in fact happens to me all the time and is an annoying aspect of
> Python.  If I forget to declare several variables in C, the compiler
> gives me several warning messages and I fix them in one edit.  If I
> forget to initialize several variables in Python, I need a separate
> test-edit cycle to hit the runtime error for each one.

Well I hope you aren't suggesting that declaring variables makes it 
impossible to forget to initalise them. So I don;t really see the 
relevance of this remark, since you simply add an extra run to fix up 
the "forgot to declare" problem. After that you get precisely one 
runtime error per "forgot to initialize".

regards
  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 is executed when in a generator

2005-10-04 Thread Matt Hammond
On Tue, 04 Oct 2005 12:48:03 +0100, Jerzy Karczmarczuk  
<[EMAIL PROTECTED]> wrote:

> before the yield, this doesn't get executed either. *EVERYTHING*
> from the beginning until the yield gets executed only upon s.next().
>
> Could you tell me please where can I read something in depth about the
> semantics of generators? I feel a bit lost.
> Thank you.

This is probably what you want:

http://www.python.org/doc/2.4.2/ref/yield.html

But you've basically got the idea anyway. I think the important thing is  
to think of the generator as a factory. When called, it returns you  
something you can iterate over by calling the next() method. Think of it  
almost like instantiation. In fact, you could write something functionally  
equivalent like this:

gl=0

class GeneratorLikeBehaviour:
   def __init__(self, x):
 self.state = 0
 self.x = x

   def next(self):
 global gl
 if self.state == 0:
   g1 = x
   self.state = 1
   return x
 else:
   raise StopIteration

s=gen(1)


Unless I've made a typo, you should get exactly the same behaviour.

The difference under the bonnet is that calling the generator has less  
overheads, as it is not a true function call - stack frames etc are not  
having to be set up fully. Instead they are (presumably) set aside between  
calls to s.next()

Hope this helps


Matt
-- 

| Matt Hammond
| R&D Engineer, BBC Research & Development, Tadworth, Surrey, UK.
| http://kamaelia.sf.net/
| http://www.bbc.co.uk/rd/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cgi relay for python cgi script

2005-10-04 Thread Fredrik Lundh
Amir Michail wrote:

> Is there an easy way to do this without modifying the configuration of
> the cgi server and without running a cgi server on the other machine
> where the script will actually run?
>
> Perhaps someone wrote a simple server that provides the required
> environment for the cgi script to run?
>
> I'm looking for something simple that does not require root access.

you could of course use something like

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

or some other light-weight web server, but you should probably have in mind
that doing things like this without coordinating with your server administrators
and security architects *before* you start tinkering can be a excellent way to
get fired...

 



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


Re: Dynamical loading of modules

2005-10-04 Thread Carsten Haese
On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
> Carsten Haese wrote:
> > On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
> > 
> >>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
> >>
> >>>Hi, I'm having some problems with implementing dynamical module loading. 
> >>>First let me
> >>>describe the scenario with an example:
> >>>
> >>>modules/
> >>>fruit/
> >>>__init__.py
> >>>apple.py
> >>>banana.py
> >>>
> >>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
> >>>problem lies in the
> >>>fact that I want to be able to just drop a new .py-file, for instance 
> >>>peach.py, and not change
> >>>__init__.py, and it should automatically pickup the new file in 
> >>>__init__.py. I've come halfway
> >>>by using some imp module magic in __init__.py, but the problem I have is 
> >>>that the instantiated
> >>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
> >>>I want it to be
> >>>fruit.Apple/fruit.Banana.
> >>>
> >>>Is there a smarter way of accomplishing what I am trying to do ?
> >>>If someone could give me a small example of how to achieve this I would 
> >>>be very grateful.
> >>
> >>How about something like this in fruit/__init__.py:
> >>
> >>import os
> >>
> >>fruit_dir = os.path.dirname(__file__)
> >>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
> >>x!='__init__.py')]
> >>for fruit_file in fruit_files:
> >>  module_name = fruit_files[:-3]
> > 
> >   ^^^ This should be fruit_file, of course.
> > 
> > 
> >>  exec "from %s import *" % module_name
> >>
> 
> Wouldn't
> 
>  __import__(module_name)
> 
> be better.

I don't see how a working example that meets the OP's requirements can
be constructed using __import__, but that may easily be due to my lack
of imagination. How would you do it?

Regards,

Carsten Haese.


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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Luis M. Gonzalez
> Boa Constructor, Iron Python etc... it seems all these projects get started,
> but never finished.

I don't know Boa (never liked it, never used it), but you could try
PythonCard: much higher level, easier and more productive. As for
Ironpython seems to be moving full steam towards a stable release
(current version is 0.9.2). And once it's ready, integration with other
MS technologies will be assured, so you shouldn't be concerned about
that.
If not Ironpython, Boo (which could be considered almost an static
version of Python for .NET) would be a great choice. It is already
integrated to SharpDevelop and soon it will be compliant with .NET 2.0.

It seems your concerns are all related to the future, and I think that
no matter what implementation of python you use, the future looks
brighter than ever, because the same code base will run on .NET, Pypy
(which will support many platforms) and java (through Jython) .

What other language gives you so many options?

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


Re: What is executed when in a generator

2005-10-04 Thread Steve Holden
Jerzy Karczmarczuk wrote:
> I thought that the following sequence
> 
> gl=0
> def gen(x):
>  global gl
>  gl=x
>  yield x
> 
> s=gen(1)
> 
> suspends the generator just before the yield, so after the
> assignment of s gl becomes 1.
> 
> Well, no. It is still zero. If I put
> 
> print "something"
> 
> before the yield, this doesn't get executed either. *EVERYTHING*
> from the beginning until the yield gets executed only upon s.next().
> 
> Could you tell me please where can I read something in depth about the
> semantics of generators? I feel a bit lost.
> Thank you.
> 

The first hing you need to realise is that s is a generator, and it 
needs to be used in an iterative context to see the (sequence of) 
yielded results:

  >>> s = gen(1)
  >>> s


The easiest way to do this is to use the generator in a loop - though of 
course in this case the sequence of yielded results is going to be of 
length 1 ...

  >>> for o in s:
  ...   print o
  ...
1
  >>>

It's easier to see the power of this when the generator yields several 
results, either from a loop or otherwise:

  >>> def shg(n):
  ...   for i in range(n):
  ... if i % 2:
  ...   yield i
  ...
  >>> s = shg(6)
  >>> s

  >>> for i in s:
  ...   print i
  ...
1
3
5
  >>>

The reason for this is so you can create multiple (parameterised) 
generators using different calls:

  >>> s1 = shg(3)
  >>> s2 = shg(7)
  >>> print [i for i in s1]
[1]
  >>> print [i for i in s2]
[1, 3, 5]
  >>>

Fredrik Lundh has already pointed you to the full description, so I'll 
content myself with adding that you can, if you want to you can call the 
generator's next() method to access the next in its sequence of results:

  >>> s1 = shg(3)
  >>> s2 = shg(7)
  >>> print [(i, s2.next()) for i in s1]
[(1, 1)]
  >>> print [i for i in s2]
[3, 5]

Hope this makes things a little clearer.

regards
  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: Dynamical loading of modules

2005-10-04 Thread Steve Holden
Carsten Haese wrote:
> On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
> 
>>Carsten Haese wrote:
>>
>>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
>>>
>>>
On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:


>Hi, I'm having some problems with implementing dynamical module loading. 
>First let me
>describe the scenario with an example:
>
>modules/
>   fruit/
>   __init__.py
>   apple.py
>   banana.py
>
>apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
>problem lies in the
>fact that I want to be able to just drop a new .py-file, for instance 
>peach.py, and not change
>__init__.py, and it should automatically pickup the new file in 
>__init__.py. I've come halfway
>by using some imp module magic in __init__.py, but the problem I have is 
>that the instantiated
>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
>I want it to be
>fruit.Apple/fruit.Banana.
>
>Is there a smarter way of accomplishing what I am trying to do ?
>If someone could give me a small example of how to achieve this I would 
>be very grateful.

How about something like this in fruit/__init__.py:

import os

fruit_dir = os.path.dirname(__file__)
fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
x!='__init__.py')]
for fruit_file in fruit_files:
 module_name = fruit_files[:-3]
>>>
>>>  ^^^ This should be fruit_file, of course.
>>>
>>>
>>>
 exec "from %s import *" % module_name

>>
>>Wouldn't
>>
>> __import__(module_name)
>>
>>be better.
> 
> 
> I don't see how a working example that meets the OP's requirements can
> be constructed using __import__, but that may easily be due to my lack
> of imagination. How would you do it?
> 
I was simply suggesting that you replace the exec statement with a call 
to __import__(). Wouldn't that work?

regards
  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: "no variable or argument declarations are necessary."

2005-10-04 Thread Antoon Pardon
Op 2005-10-04, Steve Holden schreef <[EMAIL PROTECTED]>:
> Paul Rubin wrote:
>> Antoon Pardon <[EMAIL PROTECTED]> writes:
>> 
Or you just code without declaring, intending to go 
back and do it later, and invariably forget.
>>>
>>>What's the problem, the compilor will allert you
>>>to your forgetfullness and you can then correct
>>>them all at once.
>> 
>> 
>> Thiat in fact happens to me all the time and is an annoying aspect of
>> Python.  If I forget to declare several variables in C, the compiler
>> gives me several warning messages and I fix them in one edit.  If I
>> forget to initialize several variables in Python, I need a separate
>> test-edit cycle to hit the runtime error for each one.
>
> Well I hope you aren't suggesting that declaring variables makes it 
> impossible to forget to initalise them. So I don;t really see the 
> relevance of this remark, since you simply add an extra run to fix up 
> the "forgot to declare" problem. After that you get precisely one 
> runtime error per "forgot to initialize".

Declaration and initialisation often go together. So the fixup
to declare is often enough a fixup for the initialisation too.

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


Swig and Python

2005-10-04 Thread Java and Swing
I am trying to wrap some C code I have.  Currently I have something
like...

defs.h
---
typedef unsigned long MY_DIGIT;

myapp.c
-
void MakeDigits(MY_DIGIT digits[]) {

}

char* GetString(char *inMessage, MY_DIGIT *digit) {
char *results;
...
...
return results;
}


...ok so my interface for swig looks like..

%module MyApp
%{
#include "math.h"
%}

extern void MakeDigits(MY_DIGIT digits[]);
extern char* GetString(char *inMessage, MY_DIGIT *digit);

%include "cpointer.i"
%pointer_functions(MY_DIGIT, digit_array);

%include "cmalloc.i"
%malloc(int);
%free(int);

...Ok, so I have a couple questions.
1)  How would I call MakeDigits from python?  In the C code I would
normally have something like...
MY_DIGIT tmp[10];
MakeDigits(tmp);

2)  How would I call GetString?  Again, in C I would have...
char *ptr;
char msg[100] = "Hello World";
MY_DIGIT x = 98;
ptr = GetString(msg, x);

3) Did I define MY_DIGIT correctly in my SWIG interface file?

4) If I try the following Python code...
x = new_digit_array()
print x
   then Python.exe dies...any idea?

thanks for the help.  I am trying to find my answers int he SWIG
docs...either i haven't found it or I didn't understand when I came
across it.

thanks in the mean time.

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


Re: cgi relay for python cgi script

2005-10-04 Thread Amir Michail
Fredrik Lundh wrote:
> Amir Michail wrote:
>
> > Is there an easy way to do this without modifying the configuration of
> > the cgi server and without running a cgi server on the other machine
> > where the script will actually run?
> >
> > Perhaps someone wrote a simple server that provides the required
> > environment for the cgi script to run?
> >
> > I'm looking for something simple that does not require root access.
>
> you could of course use something like
>
> http://docs.python.org/lib/module-CGIHTTPServer.html
>
> or some other light-weight web server, but you should probably have in mind
> that doing things like this without coordinating with your server 
> administrators
> and security architects *before* you start tinkering can be a excellent way to
> get fired...
>
> 

I would like to do this to improve performance by avoiding nfs. (The
required data is not on the cgi server.)

The advice I got was to use something like MySQL with a client/server
architecture.

However, I thought it would be easier to simply run the core part of
the script off the cgi server, thereby avoiding nfs for data lookups.

So I guess the point is that such a solution is more likely to be a
security risk than MySQL?

Amir

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


Re: Python profiler

2005-10-04 Thread Peter Tillotson
look in the gc module ...

Celine & Dave wrote:
> Hello All,
> 
> I am trying to find a profiler that can measure the
> memory usage in a Python program. I would like to
> gather some statistics about object usages. For
> example, I would like to be able to see how much time
> it takes to search for an item in a dict object, how
> many times it has to access the symbol table to
> retrieve a specific item, and things like that.
> 
> Thanks,
> 
> Dave
> 
> 
>   
> __ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ssh or other python editor

2005-10-04 Thread martijn
H!

I'm using a windows machine.
And a FreeBSD server where I run my python scripts.

I'm working/making my python scripts in a windows OS with putty now.
But I really want the python text colors and tab spacing like the
python windows IDE but the problem is that I can't find a good program.

Thanks

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


Re: What is executed when in a generator

2005-10-04 Thread Jerzy Karczmarczuk
Thank you all for some precisions about yield and generators.
But I would like to underline that I am *not* a complete newbie,
and I understand this stuff in general. I read the yield.html
material quite a time ago. But thank you for the PEP, I should
have scanned it more carefully.

My problem was the *context of suspension*. You see, when some text
speaks about the preservation of local state, etc., *a priori* the
following sequence

def gen()
   a
   b
   c
   yield x
   d
   e
   f
   yield y

*COULD BE* understood as follows. Upon the call s=gen(), a, b and c
*get* executed, change the global state, install some local, and then
the system makes the snapshot, and returns the generator with its
context. The call to next returns x to the caller, but the generator
works for some time, and executes d, e and f before the next suspension.

Now I know that this is not true. The CO- flag of the gen() procedure
inhibits the execution of the code altogether, and a, b, c are executed
upon the first s.next; d, e and f - upon the second next. Etc. OK,
that's it, I accept such behaviour, although the alternative could be
interesting as well.




Steve Holden wrote:

> The first hing you need to realise is that s is a generator, and it 
> needs to be used in an iterative context to see the (sequence of) 
> yielded results:

This is not exact, this is a *particular* consumer view of generators.
I don't want them for iterators, I use them as emulators of *lazy
programming*, I implement some co-recursive algorithms with them.
So i use next() when I wish, and never 'for'.

Thank you once more.

Jerzy Karczmarczuk


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


Re: Dynamical loading of modules

2005-10-04 Thread Carsten Haese
On Tue, 2005-10-04 at 08:32, Steve Holden wrote:
> Carsten Haese wrote:
> > On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
> > 
> >>Carsten Haese wrote:
> >>
> >>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
> >>>
> >>>
> On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
> 
> 
> >Hi, I'm having some problems with implementing dynamical module loading. 
> >First let me
> >describe the scenario with an example:
> >
> >modules/
> >   fruit/
> >   __init__.py
> >   apple.py
> >   banana.py
> >
> >apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
> >problem lies in the
> >fact that I want to be able to just drop a new .py-file, for instance 
> >peach.py, and not change
> >__init__.py, and it should automatically pickup the new file in 
> >__init__.py. I've come halfway
> >by using some imp module magic in __init__.py, but the problem I have is 
> >that the instantiated
> >objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
> >I want it to be
> >fruit.Apple/fruit.Banana.
> >
> >Is there a smarter way of accomplishing what I am trying to do ?
> >If someone could give me a small example of how to achieve this I would 
> >be very grateful.
> 
> How about something like this in fruit/__init__.py:
> 
> import os
> 
> fruit_dir = os.path.dirname(__file__)
> fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
> x!='__init__.py')]
> for fruit_file in fruit_files:
>  module_name = fruit_files[:-3]
> >>>
> >>>  ^^^ This should be fruit_file, of course.
> >>>
> >>>
> >>>
>  exec "from %s import *" % module_name
> 
> >>
> >>Wouldn't
> >>
> >> __import__(module_name)
> >>
> >>be better.
> > 
> > 
> > I don't see how a working example that meets the OP's requirements can
> > be constructed using __import__, but that may easily be due to my lack
> > of imagination. How would you do it?
> > 
> I was simply suggesting that you replace the exec statement with a call 
> to __import__(). Wouldn't that work?

Not the way I tried it by simply replacing my line with your line. (If
it matters, I'm on python 2.2 here.) First of all, the __import__
variant doesn't see the submodules unless I add fruit_dir to sys.path.
Secondly, the OP's requirements are that the classes that the submodules
implement be imported into fruit's namespace, and I don't see how to
make __import__ do that.

Regards,

Carsten Haese.


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


Re: Dynamical loading of modules

2005-10-04 Thread Steve Holden
Carsten Haese wrote:
> On Tue, 2005-10-04 at 08:32, Steve Holden wrote:
> 
>>Carsten Haese wrote:
>>
>>>On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
>>>
>>>
Carsten Haese wrote:


>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
>
>
>
>>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
>>
>>
>>
>>>Hi, I'm having some problems with implementing dynamical module loading. 
>>>First let me
>>>describe the scenario with an example:
>>>
>>>modules/
>>>  fruit/
>>>  __init__.py
>>>  apple.py
>>>  banana.py
>>>
>>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
>>>problem lies in the
>>>fact that I want to be able to just drop a new .py-file, for instance 
>>>peach.py, and not change
>>>__init__.py, and it should automatically pickup the new file in 
>>>__init__.py. I've come halfway
>>>by using some imp module magic in __init__.py, but the problem I have is 
>>>that the instantiated
>>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
>>>I want it to be
>>>fruit.Apple/fruit.Banana.
>>>
>>>Is there a smarter way of accomplishing what I am trying to do ?
>>>If someone could give me a small example of how to achieve this I would 
>>>be very grateful.
>>
>>How about something like this in fruit/__init__.py:
>>
>>import os
>>
>>fruit_dir = os.path.dirname(__file__)
>>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
>>x!='__init__.py')]
>>for fruit_file in fruit_files:
>>module_name = fruit_files[:-3]
>
> ^^^ This should be fruit_file, of course.
>
>
>
>
>>exec "from %s import *" % module_name
>>

Wouldn't

__import__(module_name)

be better.
>>>
>>>
>>>I don't see how a working example that meets the OP's requirements can
>>>be constructed using __import__, but that may easily be due to my lack
>>>of imagination. How would you do it?
>>>
>>
>>I was simply suggesting that you replace the exec statement with a call 
>>to __import__(). Wouldn't that work?
> 
> 
> Not the way I tried it by simply replacing my line with your line. (If
> it matters, I'm on python 2.2 here.) First of all, the __import__
> variant doesn't see the submodules unless I add fruit_dir to sys.path.
> Secondly, the OP's requirements are that the classes that the submodules
> implement be imported into fruit's namespace, and I don't see how to
> make __import__ do that.
> 

Please ignore my brainfart and proceed as per your plan :-)

regards
  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


dictionary interface

2005-10-04 Thread Antoon Pardon
I'm writing a Tree class, which should behave a lot like a dictionary.

In order to test this, I took the unittest from the source distribution
for dictionaries and used it to test against my Tree class.

Things are working out rather well, but I stumbled on a problem.

this unittest tries to test for '==' and '<' operators. However I
couldn't find anything in the documentation that defined how
dictionaries should behave with respect to these operators.

For the moment the best I can come up with is something like
the following:

  class Tree:

def __lt__(self, term):
  return set(self.iteritems()) < set(term.iteritems())

def __eq__(self, term):
  return set(self.iteritems()) == set(term.iteritems())

Would this be a correct definition of the desired behaviour?

Anyone a reference?

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


Re: Python <=> Excel question

2005-10-04 Thread Magnus Lycka
Gerry Blais wrote:
> Newbie questions:
> 
> Suppose abc.xls has sheets a, b, c.
> 
> How can I find, in Python, the sheet names?
> 
> Given a sheet name, how can I export the sheet as a csv file?
> 
> Finally, how can I, in Python, make a .txt version of a Word document?

I think Google will help you to find plenty of solutions to these
things. It's probably better to try something out and come here if
you're really stuck. You might want to start with this...
http://www.markcarter.me.uk/computing/python/excel.html

In general, it's typically helpful to use the VBA editor in Excel
to discover what the object model looks like, what methods there are
and what parameters they take etc. Then you can use this from Python
via win32com.client instead. You need the win32all extensions for
Python (or something like ctypes, but I never used that). ActivePython
contains win32all by default, but it's simple to install win32all for
a vanilla Python installation. It's reachable through the normal
Python download page (or via Google of course).

I'm sure some experimentation based on these hints can solve your
problem. It takes some time to understand the object model, and
how it maps to the Python interface, but it's not rocket science.

This book is really helpful for understanding how to use Python with
e.g. Word and Excel:
http://www.amazon.com/exec/obidos/tg/detail/-/1565926218
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what does 0 mean in MyApp(0)

2005-10-04 Thread Magnus Lycka
Alex wrote:

> Alterbnative 2 is simple and useful, so that's why everybody use that
> alternative.

Everybody doesn't... Particularly in Windows, it's common that
people make a .pyw-file, and then you don't see any console,
or otherwise they double-click on a .py-file, and if the app
dies with an error, they'll never get a chance to read the
traceback (unless they have a horribly slow computer). Even
worse, it they use command.com as their shell (default on
MS DOS derivates such as Windows ME) copying text from the
shell doesn't work very well, even if the shell didn't close.

Getting all printouts, tracebacks etc into a file is very
convenient during development. In a decent development
environment, you're likely to have a window open where you
do "tail -f" on the file.

Even in production, it's a good thing if it's at least possible
to enable output to a debug file. I've had that as a command
line switch, and asked users to turn that on and mail me the
resulting log file as they reproduced a buggy behaviour.
-- 
http://mail.python.org/mailman/listinfo/python-list


NNTP module capable of "MODE STREAM"

2005-10-04 Thread Klaus Alexander Seistrup
Hi,

I need a Python NNTP module that is capable of doing "MODE STREAM" as 
client and as server.  Does anyone here know of such a module except 
the twisted.protocols.nntp module?

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://streetkids.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling who can run an executable

2005-10-04 Thread Michael Ekstrand
On Tuesday 04 October 2005 01:43, Svennglenn wrote:
> Have the program check for a file hidden somewhere on the computer.
> For instance, if the file dummyfile.dll doesn't exist in the
> windows/system32 folder the program just doesn't start. And when you
> install the program on her computer just add this file. And if anyone
> copies the program the can't run it on any other computer because
> they doesn't know the name of the file that's needed to start the
> program.
>
> How about that?

But wouldn't the file name need to be stored in the program somewhere? 
as a string which can be discovered using relatively trivial processes?

That makes any protection difficult.

Being totally not a cryptographic expert... the solution I'd see would 
be an installer that encrypts the Python package (zip file?) with some 
hardware-specific key, and then decrypts it before running it (runner 
would need to be in C or something). Or maybe just embeds in itself a 
crypographic signature using a hardware key that is verified before the 
program can run.

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Istvan Albert
> What can one do to swiftly detect this type of bug?

While I can only speak from my own experience I can't  remember a
single instance where this type of bug caused any kind of serious
problem.  IMHO these are very trivial errors, that get caught
immediately and I would not  even qualify them as bugs, more like
typos, spelling mistakes, etc.

Real bugs are a lot more insidious than that, and they might even occur
more frequently  if there was type checking ...  since it might even
lead to longer code

just my $0.01

Istvan.

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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Benji York
Luis M. Gonzalez wrote:
> If not Ironpython, Boo (which could be considered almost an static
> version of Python for .NET) would be a great choice.

You could also use Python for .Net 
(http://www.zope.org/Members/Brian/PythonNet).
--
Benji York

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


Re: ssh or other python editor

2005-10-04 Thread projecktzero
[EMAIL PROTECTED] wrote:
> H!
>
> I'm using a windows machine.
> And a FreeBSD server where I run my python scripts.
>
> I'm working/making my python scripts in a windows OS with putty now.
> But I really want the python text colors and tab spacing like the
> python windows IDE but the problem is that I can't find a good program.
>
> Thanks

So you're using Putty to telenet/ssh into the FreeBSD server, but what
editor on you using on the FreeBSD server?

I use VIM on my Windows workstation to edit files on a linux server. I
have a network drive mounted to the linux server. Samba needs to be
running on the server. If the FreeBSD server has samba running, you can
mount a drive and use your Python Windows IDE.

If samba isn't available/set-up, you can try using FTP. You can then
use Crimson Editor which does the syntax coloring and can ftp to/from a
server.

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


Re: Controlling who can run an executable

2005-10-04 Thread Istvan Albert
>was using to track clients and transactions.  He couldn't demonstrate
>the program for one reason or another because it was protected in a way
>that neither could circumvent. (She didn't remember how it was
>protected, she had hired this person a long time ago.)

I'd venture to guess that neither of the people above knew much about
programming. So do the same, create a security measure that protects
against this level of 'threat'.

As others have pointed out the simplest way would be to detect the
presence of a hidden file, or some hardcoded system value, mac address
etc. Obscure this step even more by encrypting some of the information
so that one can't just simply view it in a hex editor.

Istvan.

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


Re: Dynamical loading of modules

2005-10-04 Thread Fredrik Lundh
Carsten Haese wrote:

> I don't see how to make __import__ do that.

hint: you might get more people to look at your problems/proposals if you
actually trim the replies a little.  (is 295 angle brackets in a single message
perhaps some kind of c.l.py record?)

 



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


Re: ssh or other python editor

2005-10-04 Thread martijn
>So you're using Putty to telenet/ssh into the FreeBSD server, but what
>editor on you using on the FreeBSD server?

I use pico for that.
That Samba isn't available but I can install it.

Or are there other editors for FreeBSD that I can run with putty ?

I'm going googling arround again,
Thanks.

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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Istvan Albert

Disclaimer: this is not a flame against Boo.

It just boggles my mind that a language that describes itself as
"python inspired syntax" keeps being touted as:

> Luis M. Gonzalez wrote:
> Boo (which could be considered almost an static version of Python for .NET)

Boo is *nothing* like a static version of Python. Stop perpetuating
this nonsense.

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


Re: Dynamical loading of modules

2005-10-04 Thread Fredrik Lundh
>  (is 295 angle brackets in a single message perhaps some kind of c.l.py 
> record?)

oh, nevermind.

 



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


Re: ssh or other python editor

2005-10-04 Thread martijn
googling arround give me a full list of python editors and other stuff
http://wiki.python.org/moin/PythonEditors

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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Paul Boddie
Lasse Vågsæther Karlsen wrote:
> While Microsoft and other big software vendors might have a roadmap
> that ties you very tightly in with their budget, and also changes that
> roadmap from time to time which breaks your current software, a lot of
> open source projects have no roadmap at all.
>
> This means that a .x.y.2 upgrade might very well kill your software in
> the same way a 6-7 upgrade with VB might.

I think this explanation confuses the term roadmap with general release
discipline. A lot of open source projects are, well, open about things
like API stability and will label their stuff as "alpha" if things are
going to change frequently - one complaint heard relatively often is
that many open source projects are reluctant to put out a 1.0 release
because they don't consider their work to be finished. Meanwhile, many
open source projects do try and preserve consistency between
micro-releases, with any inconsistency being a fault that should be
raised with the maintainers - such faults being a phenomenon not
limited to open source software, either.

> The biggest reason for this, as far as I can tell, is that open source 
> projects are very
> much built to integrate with other projects, simply because the source is
> available and it's thus far easier to integrate them, but that also
> means that unless you upgrade two integrated projects at the same time,
> you risk an upgrade in one breaking the other.

I'm not sure whether source availability is really the problem here.
I've experienced micro-release breakage and it was due to the
integration of lots of different libraries, many of which were upgraded
in the process of making the new micro-release of the software in
question, but with some of the more egregious breakage coming about
because in some micro-update of one of the libraries, the author
decided to radically change the available features of that library.
Since this was all Java-based, source availability really wasn't a
factor (these were all .jar files, after all); the problem could be
boiled down to good old release discipline: if one of your dependencies
plays fast and loose with API stability, expect some users to get
caught out.

If package maintainers make transitions of their software from release
2.4.2 to release 2.4.3 involve significant rewrites of your own
application, my advice involves either avoiding such packages from the
beginning or, if it's too late, considering what would be necessary to
maintain/subvert acceptably stable versions of them.

> I think a main point in a lot of projects is that unless you have to
> upgrade, don't. That way you can avoid a lot of problems by default.

This is good advice! The big difference between open source and
Microsoft, however, is that you can feasibly choose not to upgrade to
the next bloated/misguided release of some software and yet attempt to
roll in all the security updates and useful enhancements whose absence
would otherwise expose your applications to misuse or obsolescence.
Either path can involve a lot of hard work, but at least you get the
choice with open source software.

Paul

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


Re: dictionary interface

2005-10-04 Thread Robert Kern
Antoon Pardon wrote:
> I'm writing a Tree class, which should behave a lot like a dictionary.
> 
> In order to test this, I took the unittest from the source distribution
> for dictionaries and used it to test against my Tree class.
> 
> Things are working out rather well, but I stumbled on a problem.
> 
> this unittest tries to test for '==' and '<' operators. However I
> couldn't find anything in the documentation that defined how
> dictionaries should behave with respect to these operators.
> 
> For the moment the best I can come up with is something like
> the following:
> 
>   class Tree:
> 
> def __lt__(self, term):
>   return set(self.iteritems()) < set(term.iteritems())
> 
> def __eq__(self, term):
>   return set(self.iteritems()) == set(term.iteritems())
> 
> Would this be a correct definition of the desired behaviour?

No.

In [1]: {1:2} < {3:4}
Out[1]: True

In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems())
Out[2]: False

> Anyone a reference?

The function dict_compare in dictobject.c .

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: cgi relay for python cgi script

2005-10-04 Thread Steve Holden
Amir Michail wrote:
> Fredrik Lundh wrote:
> 
>>Amir Michail wrote:
>>
>>
>>>Is there an easy way to do this without modifying the configuration of
>>>the cgi server and without running a cgi server on the other machine
>>>where the script will actually run?
>>>
>>>Perhaps someone wrote a simple server that provides the required
>>>environment for the cgi script to run?
>>>
>>>I'm looking for something simple that does not require root access.
>>
>>you could of course use something like
>>
>>http://docs.python.org/lib/module-CGIHTTPServer.html
>>
>>or some other light-weight web server, but you should probably have in mind
>>that doing things like this without coordinating with your server 
>>administrators
>>and security architects *before* you start tinkering can be a excellent way to
>>get fired...
>>
>>
> 
> 
> I would like to do this to improve performance by avoiding nfs. (The
> required data is not on the cgi server.)
> 
> The advice I got was to use something like MySQL with a client/server
> architecture.
> 
> However, I thought it would be easier to simply run the core part of
> the script off the cgi server, thereby avoiding nfs for data lookups.
> 
> So I guess the point is that such a solution is more likely to be a
> security risk than MySQL?
> 
> Amir
> 
You are hardly likely to improve performance by substituting a fairly 
high-level application like CGI or MySQL for NFS. But later you suggest 
that security is the issue rather than performance. I'm confused.

regards
  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: ssh or other python editor

2005-10-04 Thread Fredrik Lundh
"projecktzero" wrote:

> If samba isn't available/set-up, you can try using FTP. You can then
> use Crimson Editor which does the syntax coloring and can ftp to/from a
> server.

are you guys for real?

is there any major text editor for Unix that doesn't support Python syntax
coloring and indentation these days?

 



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


Which SQL module to use?

2005-10-04 Thread mrstephengross
I'd like to do some basic SQL stuff in Python. It seems like there are
a heck of a lot of SQL modules for Python. What's the simplest and
easiest one to use?

Thanks,
--Steve ([EMAIL PROTECTED])

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


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Brian Quinlan
Have those of you who think that the lack of required declarations in 
Python is a huge weakness given any thought to the impact that adding 
them would have on the rest of the language? I can't imagine how any 
language with required declarations could even remotely resemble Python.

And if you want to use such a different language, wouldn't a different 
existing language better fit your needs...?

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


Re: ssh or other python editor

2005-10-04 Thread martijn
- I'm a newbie at freeBSD so I think there is , but I don't know where.
And i'm using putty on a windows OS what don't understand the syntax
coloring.

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


email module, redirecting to stdout

2005-10-04 Thread Laszlo Zsolt Nagy

  Hello,

I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()   
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go 
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an 
option for me, because I need to use stderr for other messages.

Thanks,

   Les

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


Re: ssh or other python editor

2005-10-04 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:
>- I'm a newbie at freeBSD so I think there is , but I don't know where.

I just complained when someone included the entire message thread in their
replies, but not including anything at all is pretty annoying too.

> And i'm using putty on a windows OS what don't understand the syntax
> coloring.

Putty isn't doing any syntax coloring; it just draws things in the color 
specified
by your editor.  If you don't get any colors, it's probably because your editor
isn't properly configured.  Explicitly setting the TERM variable to "xterm" 
might
help:

http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-term

(but I'm pretty sure ssh does this for you, so it's probably an editor 
configuration
issue.  checking the FAQ for your editor might be a good idea)

 



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


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread D H
Istvan Albert wrote:
> Disclaimer: this is not a flame against Boo.
> 
> It just boggles my mind that a language that describes itself as
> "python inspired syntax" keeps being touted as:
> 
> 
>>Luis M. Gonzalez wrote:
>>Boo (which could be considered almost an static version of Python for .NET)
> 
> 
> Boo is *nothing* like a static version of Python. Stop perpetuating
> this nonsense.


There is no static version of python, only a proposal[1] which was 
quickly stomped on and revised to be about slower runtime type-checking:

def gcd(a: int, b: int) -> int:
 while a:
 a, b = b%a, a
 return b

The boo equivalent is: (http://boo.codehaus.org/)

def gcd(a as int, b as int) as int:
 while a:
 a, b = b%a, a
 return b

Looks "nearly identical" to me.

(Istvan has been a long spewer of anti-boo FUD on this list)

[1] http://www.artima.com/weblogs/viewpost.jsp?thread=85551
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception raising, and performance implications.

2005-10-04 Thread leo
> However, I think the functionality you're asking for is available as
> inspect.currentframe(), and if the implementation is in "C" it may have a tiny
> performance advantage over the Python version.

You're absolutely right, in fact the code snippet from my OP was taken
directly from inspect.currentframe. We're intending on using this in
production, and I'm trying to gauge what the implications may be.

> Python uses exceptions internally, using StopIteration to terminate the
> iterator in a for: loop.

Wow, I was unaware of this. If Python internally uses exceptions, maybe
they aren't as detrimental as I thought.

That said, I will be judiciously profiling my code and measuring as
much as possible, I just wanted to throw this question out to the NG in
case anyone had done this before (and so I can put off learning the
profiler a little bit longer :) )

Thanks all for the replies.

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


Re: email module, redirecting to stdout

2005-10-04 Thread Peter Otten
Laszlo Zsolt Nagy wrote:

> I have this code:
> 
> s = smtplib.SMTP()
> s.set_debuglevel(1)
> s.connect(host=smtp_host)
> s.set_debuglevel(0)
> log("Connected, sending e-mail")
> sys.stdout.flush()
> s.sendmail(
> consts.EMAIL_FROMADDRESS,
> [to],
> msg.as_string()
> )
> log("E-mail sent OK")
> s.quit()
> 
> The problem is that whenever I set the debuglevel to 1, messages will go
> to stderr. I would like them to go to stdout. Using
> 
> sys.stderr = sys.stdout
> 
> has no effect. Redirecting stderr to stdout from the shell is not an
> option for me, because I need to use stderr for other messages.

smtplib obtains a copy of stderr by

from sys import stderr

Therefore you have to do

smtplib.stderr = sys.stdout

to get the desired effect.

Peter




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


Re: Which SQL module to use?

2005-10-04 Thread Philipp
mrstephengross schrieb:
> I'd like to do some basic SQL stuff in Python. It seems like there are
> a heck of a lot of SQL modules for Python. What's the simplest and
> easiest one to use?
> 
> Thanks,
> --Steve ([EMAIL PROTECTED])
> 

Do you have any DBMS in mind?

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


Re: Which SQL module to use?

2005-10-04 Thread Gerhard Häring
mrstephengross wrote:
> I'd like to do some basic SQL stuff in Python. It seems like there are
> a heck of a lot of SQL modules for Python. What's the simplest and
> easiest one to use?

It looks like pysqlite would be good for getting started with the 
SQL/Python combo:

http://www.pysqlite.org/

It's an embedded database engine, so you do not need to install a 
separate database server. Just import the module and you have a database 
engine in your Python:

 >>> from pysqlite2 import dbapi2 as sqlite

Now, let's create a database connection to a local file mydb.db. As this 
file does not exist, yet, SQLite will create it automatically.

 >>> con = sqlite.connect("mydb.db")
 >>> con


con is the database connection object.

Now, Python needs a cursor object for most database operations, so let's 
create one:

 >>> cur = con.cursor()
 >>> cur


We need data to play with, so let's create a simple table:

 >>> cur.execute("create table persons(id integer primary key, name text)")

Now let's populate the table:

 >>> cur.execute("insert into persons(name) values (?)", ("David",))
 >>> cur.execute("insert into persons(name) values (?)", ("Rachel",))
 >>> cur.execute("insert into persons(name) values (?)", ("Simon",))
 >>>

Commit the changes, so they're visible to other database connections 
that would open the file mydb.db.

 >>> con.commit()

Now let's try some queries:

 >>> cur.execute("select id, name from persons")
 >>> cur.fetchall()
[(1, u'David'), (2, u'Rachel'), (3, u'Simon')]
 >>>

Note that SQLite returns Unicode strings for TEXT.

Next, let's try to use a parametrized query. pysqlite uses the qmark 
style, so you just put ? as placeholders:

 >>> whichname = "Rachel"
 >>> cur.execute("select id, name from persons where name=?", (whichname,))
 >>> cur.fetchall()
[(2, u'Rachel')]

That's enough for a start I think.

Maybe I could whet your appetite. The pysqlite documentation has a few 
other small examples at 
http://initd.org/pub/software/pysqlite/doc/usage-guide.html#brief-tutorial

But nothing extensive, yet.

HTH,

-- Gerhard

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


Re: email module, redirecting to stdout

2005-10-04 Thread Just
In article <[EMAIL PROTECTED]>,
 Peter Otten <[EMAIL PROTECTED]> wrote:

> Laszlo Zsolt Nagy wrote:
> 
> > I have this code:
> > 
> > s = smtplib.SMTP()
> > s.set_debuglevel(1)
> > s.connect(host=smtp_host)
> > s.set_debuglevel(0)
> > log("Connected, sending e-mail")
> > sys.stdout.flush()
> > s.sendmail(
> > consts.EMAIL_FROMADDRESS,
> > [to],
> > msg.as_string()
> > )
> > log("E-mail sent OK")
> > s.quit()
> > 
> > The problem is that whenever I set the debuglevel to 1, messages will go
> > to stderr. I would like them to go to stdout. Using
> > 
> > sys.stderr = sys.stdout
> > 
> > has no effect. Redirecting stderr to stdout from the shell is not an
> > option for me, because I need to use stderr for other messages.
> 
> smtplib obtains a copy of stderr by
> 
> from sys import stderr
> 
> Therefore you have to do
> 
> smtplib.stderr = sys.stdout
> 
> to get the desired effect.

Ouch. I'd consider this a bug. "from sys import stderr" should at least 
be considered bad style.

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


Re: question about smtplib

2005-10-04 Thread nephish
thanks for all the help,
got it working ok now, connecting once, sending many.

thanks for the link too. 

cheers,
sk

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


Re: ssh or other python editor

2005-10-04 Thread Grant Edwards
On 2005-10-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I'm working/making my python scripts in a windows OS with putty now.
> But I really want the python text colors and tab spacing like the
> python windows IDE but the problem is that I can't find a good program.

Jed, Emacs, and Vim all have Python modes.   I'm sure most
decent programming editors do by now.

-- 
Grant Edwards   grante Yow!  Yow! Now we can
  at   become alcoholics!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please!

2005-10-04 Thread Luis M. Gonzalez
If you read again my comment, I said "almost" an static version of
Python for .NET.
That means that it's not a Python implementation, but another language.
It takes a lot from python though, and it is aknowledeged by its
creator in the first paragraph of its homepage.

And if you still feel the need to argue, please don't do it with me, do
it with Guido Van Rossum himself, who said that Boo is 95% Python, but
statically typed...
http://aws.typepad.com/aws/2005/01/amazon_devcon_g_5.html
Although he makes clear that he doesn't want python to become Boo.

So, we can safely say that Boo is "almost" a static python
implementation. Wether you like or not, is another problem, but please,
do not insist with your reiterative anti-boo ranting.

I'm not a Boo evangelist and I don't think I'm perpetuating any
"nonsense". I just made a simple comment in reply to an specific
question, and I think this comment is very pertinent.

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


Re: email module, redirecting to stdout

2005-10-04 Thread Peter Otten
Just wrote:

>> smtplib obtains a copy of stderr by
>> from sys import stderr

> Ouch. I'd consider this a bug. "from sys import stderr" should at least
> be considered bad style.
 
I'd rather say this is the low-tech equivalent to

debug = logging.getLogger("smtplib").debug

an approach which is currently only taken by the cookielib module.

Peter

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


Re: help w/ simple GPIB prog.

2005-10-04 Thread Dietmar Schwertberger
In article <[EMAIL PROTECTED]>, whoopsi
mailto:[EMAIL PROTECTED]> wrote:
>I thought I would simply be able to open a port, and send SCPI
> commands to configure and aquire values. But when I tried to run GPIB
> .py files from gpib-device-0.0.4 I got an error: "symbol 'ibsta' not
> found". Doing some searching I found that ibsta was refering to a
> library for GPIB (I'm assuming some .dll from a driver) and wrapping
> them???. But these instruments as far as I know don't need drivers.
Sounds like it's missing the driver for the GPIB board.
What kind of GPIB card is it? The driver should be available from the web
site of the manufacturer.


Regards,

Dietmar

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


Re: Which SQL module to use?

2005-10-04 Thread Ed Hotchkiss
I'm using MySQLdb. I use a FREE MySQL server at freesql.org. I also have an example class and some functions that use the module. even a simple script that turns a .cvs into a mysql table. 

contact me if interested. 
 
-edward
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Swig and Python

2005-10-04 Thread Steve Juranich
On 4 Oct 2005 05:46:27 -0700, Java and Swing <[EMAIL PROTECTED]> wrote:
> ...Ok, so I have a couple questions.
> 1)  How would I call MakeDigits from python?  In the C code I would
> normally have something like...
> MY_DIGIT tmp[10];
> MakeDigits(tmp);

How I usually do this is to write a typemap so that MY_DIGIT arrays
are automagically converted to/from regular python lists.  See the
SWIG docs on writing typemaps.  When that is done, you can call it
just like this:

MakeDigits(range(10))
MakeDigits([1, 3, 5, 7, 9])
# etc.

> 2)  How would I call GetString?  Again, in C I would have...
> char *ptr;
> char msg[100] = "Hello World";
> MY_DIGIT x = 98;
> ptr = GetString(msg, x);

This should happen for you fairly automatically:

GetString('Hello World', 98)

> 3) Did I define MY_DIGIT correctly in my SWIG interface file?

I can't really say.  I don't use typedefs all that much.  You can
always look at the generated C/C++ code to see if it looks right. 
Read the docs on the Python/C API if you haven't already.

> 4) If I try the following Python code...
> x = new_digit_array()
> print x
>then Python.exe dies...any idea?

Smells like a segfault from here.  Might have to put some printfs in
the generated code to find out exactly what's happening.

> thanks for the help.  I am trying to find my answers int he SWIG
> docs...either i haven't found it or I didn't understand when I came
> across it.

The SWIG user community also has a very helpful list.  Check out
http://www.swig.org/mail.html for more info.  You might find that your
SWIG related issues get addressed more quickly when posting to the
SWIG list.  There are lots of Python hackers on the list, too.  So
don't be afraid to ask fairly Python-centric questions either.

--
Steve Juranich
Tucson, AZ
USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Python script to install network printers

2005-10-04 Thread Matt Chan
Hi, I am trying to create a python script to install a set of network
printers. I have had success using an os.popen statement, using
rundll32 and printui.dll. This takes way too long. Can someone point
me in a quicker direction?

thanks,
Matt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ssh or other python editor

2005-10-04 Thread Graham Fawcett
[EMAIL PROTECTED] wrote:
> >So you're using Putty to telenet/ssh into the FreeBSD server, but what
> >editor on you using on the FreeBSD server?
>
> I use pico for that.
> That Samba isn't available but I can install it.
>
> Or are there other editors for FreeBSD that I can run with putty ?

I use Emacs on my win32 workstation to edit files on my Linux servers
via SSH. There are at least two Emacs third-party modules ("modes") --
Tramp and Hobo -- that allow you to edit files over SSH.

I use Hobo (never tried Tramp, I think it's for XEmacs anyway). There
is a bit of setup. You'll need to use "pageant" and authenticate by
RSA/DSA key. See PuTTY's Web site; you may also need to do some
Googling to set up agent-based authentication. Note that pageant will
make PuTTY authenticate automatically as well, so it's easy to test
whether your pageant setup is correct, apart from any Emacs-related
issues.

You might also need to configure Hobo slightly; email me if you want my
configuration details (though I can't help you with the
pageant/authentication stuff, so get that done first :-).

Once you're done, you can load, edit and save files quite
transparently. Not everybody's cup of tea, but there you are. :-)

Graham

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


Re: Exception raising, and performance implications.

2005-10-04 Thread Steve Holden
leo wrote:
>>However, I think the functionality you're asking for is available as
>>inspect.currentframe(), and if the implementation is in "C" it may have a tiny
>>performance advantage over the Python version.
> 
> 
> You're absolutely right, in fact the code snippet from my OP was taken
> directly from inspect.currentframe. We're intending on using this in
> production, and I'm trying to gauge what the implications may be.
> 
> 
>>Python uses exceptions internally, using StopIteration to terminate the
>>iterator in a for: loop.
> 
> 
> Wow, I was unaware of this. If Python internally uses exceptions, maybe
> they aren't as detrimental as I thought.
> 
> That said, I will be judiciously profiling my code and measuring as
> much as possible, I just wanted to throw this question out to the NG in
> case anyone had done this before (and so I can put off learning the
> profiler a little bit longer :) )
> 
> Thanks all for the replies.
> 
Do note, however, that detecting an exception inside the C framework of 
the interpreter carries less overhead than detecting an exception in 
Python itself.

That said, exceptions are probably rather more "lightweight" than you 
might imagine, so benchmarking (the profiler may not be best - have you 
come across "timeit.py"?) is the best way to go.

regards
  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: Will python never intend to support private, protected and public?

2005-10-04 Thread El Pitonero
Paul Rubin wrote:
>
> Let's see, say I'm a bank manager, and I want to close my cash vault
> at 5pm today and set its time lock so it can't be opened until 9am
> tomorrow, including by me.  Is that "handcuffs"?  It's normal
> procedure at any bank, for good reason. It's not necessarily some
> distrustful policy that the bank CEO set to keep me from robbing the
> bank.  I might have set the policy myself.  Java lets me do something
> similar with instance variables.  Why is it somehow an advantage for
> Python to withhold such a capability?

If so, you would probably be the type of person that also likes static
typing, type safety and variable declaration, right? You like your
language with extra baggages to improve some safety concerns, which
most Python programmers don't seem to need.

>   def countdown():
> n = 3
> while n > 0:
>yield n
>   g = countdown()
>   print g.next()  # 3
>   print g.next()  # 2
>
> where's the Python feature that lets me modify g's internal value of n
> at this point?

You missed the point. I have, for fun, built a GUI application in
Python, while the program is running. I just kept on adding more and
more code to it. This, while the Python program is running. I was able
to change the GUI's look-and-feel, add more buttons, menus, all while
the programming is running. I was able to change the class definition,
preserve the previous object state variables. For that, you already
have event-based program and can use module reload and some metaclass
tricks to automatically relink your objects to new classes. Sure,
Python is not as friendly as Lisp/Scheme for interactive programming,
but you can still do a lot.

> [Other stuff incomprehensible and snipped].

Sigh, I gave you the keywords: containment and aggregation.

There are two ways of enhancing functionality from an existing
object/class. One way is by inheritance, that's aggregation. Another
way is by containment, that means that instead of inheriting, you add
the additional features as an object contained in the new object.

Vault encapsulation is one way to do OOP. But by no means it is the
only way. The whole access level thing (the "private" keyword) is not
an essential part of OOP. The concept of a "private" namespace is not
necessary for OOP. Just because you learned OOP from one particular
school of thought, does not mean that that's the only way. Let us call
your OOP "school A".

Another way of OOP is to accept by default that everything in the class
hierarchy is inheritable. And Python is by no means the only language
that does that. Now, obviously in this type of OOP you can run into
name collision. But if you actually follow this other school of
thought, you would organize your variables differently. Let us call
this type of OOP "school B".

Let me be more clear: when you have variables that are so, so, so
private that no one else should touch, from school B's point of view,
those variables do not belong to the object. They belong to another
object.

Let us say there is a financial instrument that pays some fixed coupon
interest:

class Bond:
volatility = None
interest = None
def __init__(self):
self.volatility = 0.3 # volatility from credit risk
self.interest = 0.4

Now, you have another instrument that pays variable interest:

class VariableInterestBond(Bond):
volatility = None # this one collides with the base class
def __init__(self):
 Bond.__init__(self)
 self.volatility = 0.2 # volatility for variable interest
def calculate(self):
 interest = self.get_variable_interest()
 ...
def get_variable_interest(self):
 return self.interest * (1 + random.random()*self.volatility)
...

In this example, the subclass's "volatility" meant something else but
collides with the base class's "volatility". It should have been a
private variable, but now it accidentally overwrote an existing
variable.

We are trying to combine two "features" in the hierarchy tree:


Bond
|
|
+- Variable Interest
|
|
Variable-Interest Bond

There are two ways to add the "variable interest" feature to the "bond"
object. One way is by aggregation (inheritance), which is shown above.
Another way is by containment.

If the subsclass's "volatility" should be private and encapsulated from
the main class hierarchy (i.e. Bond-like objects), then from school B's
point of view, it does not belong to the bond object. It would be
better to encapsulate it into another object.

class VariableInterest:
volatility = None
def __init__(self, interest):
self.interest = interest
self.volatility = 0.2
def get_variable_interest(self):
 return self.interest * (1 + random.random()*self.volatility)

class VariableInterestBond(Bond):
variable_interest_calculator = None
def __init__(self):
 Bond.__init__(self)
 self.variable_interest_calculator =
VariableInterest(self.interest)
def calculate(self):
 

Re: Exception raising, and performance implications.

2005-10-04 Thread Phillip J. Eby
leo wrote:
>
> You're absolutely right, in fact the code snippet from my OP was taken
> directly from inspect.currentframe. We're intending on using this in
> production, and I'm trying to gauge what the implications may be.

Use sys._getframe() instead; it doesn't raise an exception.


> Wow, I was unaware of this. If Python internally uses exceptions, maybe
> they aren't as detrimental as I thought.

Exceptions raised from C code and caught by C code use considerably
less resources, so a "for" loop catching a StopIteration raised by a
built-in iterator will have better performance than Python code
catching an exception raised in Python code.  So, it's not necessarily
the case that the "for" loop scenario matches your scenario(s).  Always
measure.

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


Re: Controlling who can run an executable

2005-10-04 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Cigar" <[EMAIL PROTECTED]> wrote:

> I am developing a program for a client.  She runs a shop where her
> clients bring in items for sale or short term buyback.  Development of
> the program has been going great but she's mentioned that there is a
> 'feature' coming up in the next couple of weeks that she'd like me to
> implement that has me a bit worried.
> 
> My client has told me a story of how she hired someone from a competing
> store and that person had brought a copy of the program her competition
> was using to track clients and transactions.  He couldn't demonstrate
> the program for one reason or another because it was protected in a way
> that neither could circumvent. (She didn't remember how it was
> protected, she had hired this person a long time ago.)
> 
> Now that I'm three months into the development of this program, my
> client tells me she would like to protect her investment by preventing
> her employees from doing the same to her.  (Going to the competition
> and using her program.)
 ...

Call the competition and ask them what they used.  Point out that it 
worked.  If they won't tell you, just look at their software until you 
find out.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


how to debug when "Segmentation fault"

2005-10-04 Thread Maksim Kasimov

Hello,

my programm sometime gives "Segmentation fault" message (no matter how long the 
programm had run (1 day or 2 weeks). And there is nothing in log-files that can 
points the problem.
My question is how it possible to find out where is the problem in the code? 
Thanks for any help.

Python 2.2.3
FreeBSD

-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-04 Thread Mike Meyer
Antoon Pardon <[EMAIL PROTECTED]> writes:
> Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
>> On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
> Declarations also allow easier writable closures. Since the declaration
> happens at a certain scope, the run time can easily find the correct
> scope when a variable is rebound.

If it happens at runtime, then you can do it without declarations:
they're gone by then. Come to think of it, most functional languages -
which are the languages that make the heaviest use of closures - don't
require variable declarations.

> They also relieve a burden from the run-time, since all variables
> are declared, the runtime doesn't has to check whether or not
> a variable is accesible, it knows it is.

Not in a dynamic language. Python lets you delete variables at run
time, so the only way to know if a variable exists at a specific
point during the execution of an arbitrary program is to execute the
program to that point.

> And if you provide type information with the declaration, more
> efficient code can be produced.

Only in a few cases. Type inferencing is a well-understood
technology, and will produce code as efficient as a statically type
language in most cases.

> I think language matters shouldn't be setlled by personal preferences.

I have to agree with that. For whether or not a feature should be
included, there should either be a solid reason dealing with the
functionality of the language - meaning you should have a set of use
cases showing what a feature enables in the language that couldn't be
done at all, or could only be done clumsily, without the feature.

Except declarations don't add functionality to the language. They
effect the programing process. And we have conflicting claims about
whether that's a good effect or not, all apparently based on nothing
solider than personal experience. Which means the arguments are just
personal preferences.

Until someone does the research to provide hard evidence one way or
another, that's all we've got to work with. Which means that languages
should exist both with and with those features, and if one sides
experiences generalize to the population at large, they alternative
languages will die out. Which hasn't happened yet.

> But we should decide what language features are usefull and which are
> not by what some individual can or can't live without.

Um - that's just personal preference (though I may have misparsed your
sentence). What one person can't live without, another may not be able
to live with. All that means is that they aren't likely to be happy
with the same programming language. Which is fine - just as no
programming language can do everything, no programming language can
please everyone.

Antoon, at a guess I'd say that Python is the first time you've
encountered a dynamnic language. Being "horrified" at not having
variable declarations, which is a standard feature of such languages
dating back to the 1950s, is one such indication.

Dynamic languages tend to express a much wider range of programming
paradigms than languages that are designed to be statically
compiled. Some of these paradigms do away with - or relegate to the
level of "ugly performance hack" - features that someone only
experienced with something like Pascal would consider
essential. Assignment statements are a good example of that.

Given these kinds of differences, prior experience is *not* a valid
reason for thinking that some difference must be wrong. Until you have
experience with the language in question, you can't really decide that
some feature being missing is intolerable. You're in the same position
as the guy who told me that a language without a goto would be
unusable based on his experience with old BASIC, FORTRAN IV and
assembler.

Pick one of the many languages that don't require declarations. Try
writing a code in them, and see how much of a problem it really is in
practice, rather than trying to predict that without any
information. Be warned that there are *lots* of variations on how
undeclared variables are treated when referenced. Python raises
exceptions. Rexx gives them their print name as a value. Other
languages do other things.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >