Re: Yielding a chain of values

2005-08-31 Thread Bengt Richter
On Tue, 30 Aug 2005 21:23:39 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>> On Tue, 30 Aug 2005 23:12:35 +0200, Reinhold Birkenfeld <[EMAIL PROTECTED]> 
>> wrote:
>>>Bengt Richter wrote:
Maybe
 yield in inner()

could be sugar for the above and become something optimized?
>>>
>>>The problem here is that yield isn't a statement any more. It's now an
>>>expression, so it is not easy to find new syntax around it.
>> 
>> No, the idea was that it's still a statement, but what it
>> yields is "in inner()" which UIAM is illegal now, and would
>> signify "whatever sequence of elements is in inner()" --
>> really yield in seq -- I don't know what inner() was, but I assumed
>> an iterable.
>
>I believe he was referring indirectly to 
>http://www.python.org/peps/pep-0342.html (see item #1 in the 
>"Specification Summary" section), where yield will become an expression. 
>  This PEP has been accepted, thus his use of present tense, confusing 
>though it is when it's not in the released version of Python yet.
>
>Or I might be wrong. ;-)
Well, maybe it's right both ways ;-) I.e., even though yield "is" now
an expression, it is valid to use it as an expression-statement which
evaluates the expression and discards the value. So I think you could
still use the currently illegal "yield in" token sequence to mean that
what follows is to be taken as an iterable whose full sequence is
to be yielded sequentially as if

yield in iterable

were sugar for

for _ in iterable: yield _   

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


Re: Bicycle Repair Man usability

2005-08-31 Thread Adriaan Renting
I know the Eric3 Python IDE integrates with BRM, but I haven't had a need for 
much refactoring yet, so I haven't installed BRM. I've only used Eric3's 
build-in limited refactoring yet.

Adriaan Renting.

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


Re: telnet.read_until() from telnetlib

2005-08-31 Thread Jacek Popławski
my newsreader told me that [EMAIL PROTECTED] wrote:
> "If end of file is found and no text was read, raise EOFError.
> Otherwise, when nothing matches, return (-1, None, text) where text is
> the text received so far (may be the empty string if a timeout
> happened). "

What if:
- exception has not been raised
and:
- time passed is smaller than timeout?
How to interpret such behaviour?


-- 
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type

2005-08-31 Thread Antoon Pardon
Op 2005-08-30, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2005-08-29, Steve Holden schreef <[EMAIL PROTECTED]>:
>> 
>>>Antoon Pardon wrote:
>>>
Op 2005-08-27, Steve Holden schreef <[EMAIL PROTECTED]>:


>If you want an exception from your code when 'w' isn't in the string you 
>should consider using index() rather than find.


Sometimes it is convenient to have the exception thrown at a later
time.



>Otherwise, whatever find() returns you will have to have an "if" in 
>there to handle the not-found case.


And maybe the more convenient place for this "if" is in a whole different
part of your program, a part where using -1 as an invalid index isn't
at all obvious.



>This just sounds like whining to me. If you want to catch errors, use a 
>function that will raise an exception rather than relying on the 
>invalidity of the result.


You always seem to look at such things in a very narrow scope. You never
seem to consider that various parts of a program have to work together.

>>>
>>>Or perhaps it's just that I try not to mix parts inappropriately.
>> 
>> 
>> I didn't know it was inappropriately to mix certain parts. Can you
>> give a list of modules in the standard list I shouldn't mix.
>> 
>> 
So what happens if you have a module that is collecting string-index
pair, colleted from various other parts. In one part you
want to select the last letter, so you pythonically choose -1 as
index. In an other part you get a result of find and are happy
with -1 as an indictation for an invalid index. Then these
data meet.

>>>
>>>That's when debugging has to start. Mixing data of such types is 
>>>somewhat inadvisable, don't you agree?
>> 
>> 
>> The type of both data is the same, it is a string-index pair in
>> both cases. The problem is that a module from the standard lib
>> uses a certain value to indicate an illegal index, that has
>> a very legal value in python in general.
>> 
> Since you are clearly feeling pedantic enough to beat this one to death 
> with a 2 x 4 please let me substitute "usages" for "types".

But it's not my usage but python's usage.

> In the case of a find() result -1 *isn't* a string index, it's a failure 
> flag. Which is precisely why it should be filtered out of any set of 
> indexes. once it's been inserted it can no longer be distinguished as a 
> failure indication.

Which is precisely why it was such a bad choice in the first place.

If I need to write code like this:

  var = str.find('.')
  if var == -1:
var = None

each time I want to store an index for later use, then surely '-1'
shouldn't have been used here.


>>>I suppose I can't deny that people do things like that, myself included, 
>> 
>> 
>> It is not about what people do. If this was about someone implementing
>> find himself and using -1 as an illegal index, I would certainly agree
>> that it was inadvisable to do so. Yet when this is what python with
>> its libary offers the programmer, you seem reluctant find fault with
>> it.

> I've already admitted that the choice of -1 as a return value wasn't 
> smart. However you appear to be saying that it's sensible to mix return 
> values from find() with general-case index values.

I'm saying it should be possible without a problem. It is poor design
to return a legal value as an indication for an error flag.

> I'm saying that you 
> should do so only with caution. The fact that the naiive user will often 
> not have the wisdom to apply such caution is what makes a change desirable.

I don't think it is naive, if you expect that no legal value will be
returned as an error flag. 

>>>but mixing data sets where -1 is variously an error flag and a valid 
>>>index is only going to lead to trouble when the combined data is used.
>> 
>> 
>> Yet this is what python does. Using -1 variously as an error flag and
>> a valid index and when  people complain about that, you say it sounds like
>> whining.
>> 
> What I am trying to say is that this doesn't make sense: if you want to 
> combine find() results with general-case indexes (i.e. both positive and 
> negative index values) it behooves you to strip out the -1's before you 
> do so. Any other behaviour is asking for trouble.

I would say that choosing this particular return value as an error flag
was asking for trouble. My impression is that you are putting more
blame on the programmer which fails to take corrective action, instead
of on the design of find, which makes that corrective action needed
in the first place.

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


Re: Precise timings ?

2005-08-31 Thread Adriaan Renting
One of the limits of at least IBM compatible PC's is that in general they are 
not more accurate as about 1/64 th of a second if I recall correctly. I think 
this is the default tick size of the BIOS clock. Next to that the
BIOS clock itself doesn't need to be very accurate, I can easily drift like an 
hour a year.
Oh, and on top of that: If you are in a multi taksing operating system this 
complicates matters even further. Finally there's interrupts, as other posters 
pointed out.

This explains it very well:
http://www.beaglesoft.com/mainfaqclock.htm

There was a thread with the same question 'time.clock() problem under linux 
(precision=0.01s)' about a month ago.
I think it had some suggestion of using a soundcard sampling rate to get an 
accurate clock. I think that without an external calibrated device, you're not 
going to get any real accurate timing, precission isn't the same as accuracy.

Adriaan.




Adriaan Renting| Email: [EMAIL PROTECTED]
ASTRON | Phone: +31 521 595 200 (217 direct)
P.O. Box 2 | GSM:   +31 6 24 25 17 28
NL-7990 AA Dwingeloo   | FAX:   +31 521 597 332
The Netherlands| Web: http://www.astron.nl/~renting/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-31 Thread Antoon Pardon
Op 2005-08-30, Bengt Richter schreef <[EMAIL PROTECTED]>:
> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>
>>Op 2005-08-30, Terry Reedy schreef <[EMAIL PROTECTED]>:
>>>
>>> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
>>> news:[EMAIL PROTECTED]
>>>
 Really it's x[-1]'s behavior that should go, not find/rfind.
>>>
>>> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely 
>>> useful, especially when 'x' is an expression instead of a name.
>>
>>I don't think the ability to easily index sequences from the right is
>>in dispute. Just the fact that negative numbers on their own provide
>>this functionality.
>>
>>Because I sometimes find it usefull to have a sequence start and
>>end at arbitrary indexes, I have written a table class. So I
>>can have a table that is indexed from e.g. -4 to +6. So how am
>>I supposed to easily get at that last value?
> Give it a handy property? E.g.,
>
> table.as_python_list[-1]

Your missing the point, I probably didn't make it clear.

It is not about the possibilty of doing such a thing. It is
about python providing a frame for such things that work
in general without the need of extra properties in 'special'
cases.

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


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-31 Thread Bengt Richter
On 31 Aug 2005 07:26:48 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:

>Op 2005-08-30, Bengt Richter schreef <[EMAIL PROTECTED]>:
>> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>
>>>Op 2005-08-30, Terry Reedy schreef <[EMAIL PROTECTED]>:

 "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
 news:[EMAIL PROTECTED]

> Really it's x[-1]'s behavior that should go, not find/rfind.

 I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely 
 useful, especially when 'x' is an expression instead of a name.
>>>
>>>I don't think the ability to easily index sequences from the right is
>>>in dispute. Just the fact that negative numbers on their own provide
>>>this functionality.
>>>
>>>Because I sometimes find it usefull to have a sequence start and
>>>end at arbitrary indexes, I have written a table class. So I
>>>can have a table that is indexed from e.g. -4 to +6. So how am
>>>I supposed to easily get at that last value?
>> Give it a handy property? E.g.,
>>
>> table.as_python_list[-1]
>
>Your missing the point, I probably didn't make it clear.
>
>It is not about the possibilty of doing such a thing. It is
>about python providing a frame for such things that work
>in general without the need of extra properties in 'special'
>cases.
>
How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
That would give a consitent interpretation of seq[-1] and no errors
for any value ;-)

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


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-31 Thread Antoon Pardon
Op 2005-08-31, Bengt Richter schreef <[EMAIL PROTECTED]>:
> On 31 Aug 2005 07:26:48 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>
>>Op 2005-08-30, Bengt Richter schreef <[EMAIL PROTECTED]>:
>>> On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>>
Op 2005-08-30, Terry Reedy schreef <[EMAIL PROTECTED]>:
>
> "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
> news:[EMAIL PROTECTED]
>
>> Really it's x[-1]'s behavior that should go, not find/rfind.
>
> I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely 
> useful, especially when 'x' is an expression instead of a name.

I don't think the ability to easily index sequences from the right is
in dispute. Just the fact that negative numbers on their own provide
this functionality.

Because I sometimes find it usefull to have a sequence start and
end at arbitrary indexes, I have written a table class. So I
can have a table that is indexed from e.g. -4 to +6. So how am
I supposed to easily get at that last value?
>>> Give it a handy property? E.g.,
>>>
>>> table.as_python_list[-1]
>>
>>Your missing the point, I probably didn't make it clear.
>>
>>It is not about the possibilty of doing such a thing. It is
>>about python providing a frame for such things that work
>>in general without the need of extra properties in 'special'
>>cases.
>>
> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
> That would give a consitent interpretation of seq[-1] and no errors
> for any value ;-)

But the question was not about having a consistent interpretation for
-1, but about an easy way to get the last value.

But I like your idea. I just think there should be two differnt ways
to index. maybe use braces in one case.

  seq{i} would be pure indexing, that throws exceptions if you
  are out of bound

  seq[i] would then be seq{i%len(seq)}

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


Re: Bicycle Repair Man usability

2005-08-31 Thread Sybren Stuvel
Rex Eastbourne enlightened us with:
> Are there any Bicycle Repair Man users here?

I am.

> I recently got PyDev for Eclipse, which comes with BRM.

I use it from VIM.

> I am disappointed with what I've seen, although I'm not sure if I'm
> using its full functionality.

Why would it need more functionality?

> -Rename a function/variable
> -Block of code --> method and a method call

That seems nice to me.

> -Get rid of extra variables by shifting them inline (e.g.:
> a=1;b=2;c=a+b --> c=1+2)

This is already excess functionality IMO. If you're programming like
this and you want it to be replaced by 'c=1+2', you need to learn how
to properly write software. No tool will help you in that. But hey,
that's just my opinion. And I think it should be 'c=3' anyway ;-)

Sometimes I use constructs as 'a, b = 1, 2' and 'c = a+b', but that's
intensional. In such a case, 'a' and 'b' are settings that easily need
to be edited, and 'c' is just a calculation on them. In such a case, I
don't want to see 'c = 3' in my code.

I use BRM if I need to rename a function or variable, and that's about
it. I do the rest by hand faster than I can figure out how to use
additional software.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OpenSource documentation problems

2005-08-31 Thread Sybren Stuvel
Bryan Olson enlightened us with:
> I don't see any need to look beyond Python for a good example of
> poor documentation.  Are there serious Python programmers who don't
> constantly struggle with errors and omissions in the doc?

I don't have any problems with the documentation. It just works for
me. If you find any errors or omissions, fix them and send the
document maintainer an email. Why don't you help us by improving the
documentation?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-08-31 Thread John Bokma
Chris Head <[EMAIL PROTECTED]> wrote:

> John Bokma wrote:

>> And workplaces. Some people have more then one computer in the house.
>> My partner can check her email when I had her over the computer. When
>> I want to check my email when she is using it, I have to change the 
>> session, fire up Thunderbird (which eats away 20M), and change the 
>> session back.
>> 
>> [ .. ]
> 
> Hmm. That would just be a matter of preference. Personally I moved my
> Thunderbird profile into a shared directory and pointed everyone at
> it. Now only one login session can run Thunderbird at a time, but any
> login can see everyone's mailboxes.

She uses hotmail, yahoo!, etc. and I don't want her accidently delete my 
email.

>> Most people who use Thunderbird, yes. Different with OE, I am sure.
>> With a thin client *everybody*.
> 
> True. As a programmer I don't usually think about the people who never
> download updates. The way I look at it, if somebody doesn't have the
> latest version, they shouldn't be complaining about a bug.

A lot of non-programmers have no idea that there are bugs in their 
software other then the crashing ones.
 
>> Maybe because a lot of users aren't really heavy users. A nice
>> example (IMO) of a web client that works quite good: webmessenger ( 
>> http://webmessenger.msn.com/ ). It has been some time since I used it
>> the last time, but if I recall correctly I hardly noticed that I was 
>> chatting in a JavaScript pop up window.
> 
> Haven't ever needed to use that program.

Some of my customers use it. It has its uses, especially the block 
option :-D. (I don't believe that being available 24/7 has a positive 
effect on my work).

>> I rather have my email stored locally :-) But several webmail
>> services offer a form to download email.

s/form/way/

> I've not seen a service that allows that. Sounds nice.

IIRC gmail does it.

[ reducing traffic ]
> Eventually you reach the point where it's not bandwidth any more, it's
> server load. All these things like mod_gzip, deltas, and so on add
> server load.

True. On the other hand, servers get more and more powerful.

> As to the point about "page not modified", it's not in the HTML spec,

Hence I wrote:

>> RSS (I have the impression that there is no "page has not been 
>> modified" thing like with HTML,

> content. For best results (due to clock mismatches etc), the client
> should set the If-Modified-Since header to the value of the
> Last-Modified header sent by the server when the page was first
> requested and cached. 

But feed readers, at least the one I have had a look at, seem not to 
support this...

> I think we can agree that in some cases, Webmail is better, and in
> others, clients are better. Much of this will be personal preference,
> and I would like to see ISPs offering both methods of accessing e-mail
> (as mine in fact does - POP3 and Webmail).

Agreed.

-- 
John   Small Perl scripts: http://johnbokma.com/perl/
   Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

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


Re: Jargons of Info Tech industry

2005-08-31 Thread John Bokma
"T Beck" <[EMAIL PROTECTED]> wrote:

> John Bokma wrote:

[ Death of Usenet has been predicted often ]

> I suppose I was (as many people on the internet have a bad habit of
> doing) being more caustic than was strictly necessary.  I don't really
> forsee the death of usenet anytime soon, I just don't think the idea of
> it evolving is necessarily bad.  I don't really have alot of vested
> interest one way or the other, to be honest, and I'm perfectly happy
> with the way it is.

me too.

> I just think it's a naive view to presume it never will change, because
> change is what the internet as a whole was built on.

I can't think of changes that are coming to Usenet (other then ipv6)

-- 
John   Small Perl scripts: http://johnbokma.com/perl/
   Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

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


Re: Yielding a chain of values

2005-08-31 Thread Matt Hammond
> Well, maybe it's right both ways ;-) I.e., even though yield "is" now
> an expression, it is valid to use it as an expression-statement which
> evaluates the expression and discards the value. So I think you could
> still use the currently illegal "yield in" token sequence to mean that
> what follows is to be taken as an iterable whose full sequence is
> to be yielded sequentially as if
>
> yield in iterable
>
> were sugar for
>
> for _ in iterable: yield _

"yield in" could make sense when thought of as an expression too.

 x = yield in iterable

Would behave like a list comprehension. x would be assigned a list  
containing
the results of the successive yields. Equivalent to:

x = [ yield r for r in iterable ]

regards


Matt
-- 

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread Richie Hindle

[n00m]
> WHY ON THE EARTH <'module' object has no attribute 'AF_INET'> ???

Because you have a socket.py in d:\python23\00 which is being picked up
instead of Python's own socket module.  You shouldn't give your modules
the same name as Python's own modules.

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


Re: Adding bound methods dynamically...

2005-08-31 Thread Gregory Bond
Kevin Little wrote:

> I want to dynamically add or replace bound methods in a class.  I want


I asked a seemingly-unrelated question a week or so ago, and learned 
something interesting:

Python 2.3.4 (#2, Jul 12 2004, 12:46:36)
[GCC 3.3] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
 >>> def foo(self):
.. print "foo called"
..
 >>> class C(object):
.. pass
..
 >>> type(foo)

 >>> C.foo = foo
 >>> type(C.foo)

 >>> c = C()
 >>> c.foo()
foo called
 >>> type(c.foo)

 >>>

I.e. assigning a normal function object to a class object turns it into 
a member function!

You can read more in the thread with the subject 'keeping a ref to a 
non-member function in a class'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python doc problems example: gzip module

2005-08-31 Thread Xah Lee
today i need to use Python to decompress gzip files.

since i'm familiar with Python doc and have 10 years of computing
experience with 4 years in unix admin and perl, i have quickly located
the official doc:

 http://python.org/doc/2.4.1/lib/module-gzip.html

but after a minute of scanning, please someone tell me what the fuck is
it talking about?

Fuck the Python programing morons.

Thanks.

I just need to decompress files. Is it:

import gzip;
gzip.GzipFile("/Users/xah/access_log.1.gz");

can someone put a example into that fucking doc so that people don't
have to wade thru whatever fuck it is trying to sound big?

For more about Python doc, please see:
http://xahlee.org/perl-python/re-write_notes.html

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: OpenSource documentation problems

2005-08-31 Thread Michael Hudson
"Adriaan Renting" <[EMAIL PROTECTED]> writes:

> The good commercial docs are better because there it is understood
> how important this is.

Also, they are probably written by people who are trained technical
writers which has to help at least a bit... writing good documentation
is hard.

Whether the Python documentation is good or bad depends on what you're
comparing it to.  It's probably not as good, say, as Apple's
documentation for Cocoa, but it could certainly be much, much worse.

Cheers,
mwh

-- 
  Enlightenment is probably antithetical to impatience.
-- Erik Naggum, comp.lang.lisp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread n00m

Richie Hindle wrote:
> Because you have a socket.py in d:\python23\00 which is being picked up
> instead of Python's own socket module.  You shouldn't give your modules
> the same name as Python's own modules.

Yes, Richie! YOU are dmndly RIGHT! Thanks.

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


Re: Adding bound methods dynamically... CORRECTED

2005-08-31 Thread bruno modulix
Devan L wrote:
> Kevin Little wrote:
> 
>>I want to dynamically add or replace bound methods in a class.  

(snip)

> I'm not an expert, but why do you need to dynamically add or replace
> bound methods?

To modify the behaviour at runtime ?-)

There are a lot of idioms/patterns in dynamic languages that seems
somewhat alien at first, then become an obvious solution. When I
discovered first-class functions and anonymous functions with Python
some years ago, I wondered what could be the use of such things. Now I
couldn't live without...

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


Re: Python doc problems example: gzip module

2005-08-31 Thread Xah Lee
Today i need to use Python to compress/decompress gzip files.

I quickly found the official doc:
http://python.org/doc/2.4.1/lib/module-gzip.html

I'd imagine it being a function something like
GzipFile(filePath, comprress/decompress, outputPath)

however, scanning the doc after 20 seconds there's no single example
showing how it is used.

Instead, the doc starts with some arcane info about compatibility with
some zlib module and other software.

Then it talks in a very big computer sciency way with bad writing about
the main function GzipFile. No perspectives whatsoever about using it
to solve a problem nor a concrete description of how it functions.
Instead, jargons of Class, Constructor, Object etc are thrown together
with presumption of reader's expertise of Python's file objects and
gzip technical details.

after no understanding, and being not a Python expert, i wanted to read
about file objects but there's no link.

after locating the file object doc page
http://python.org/doc/2.4.1/lib/bltin-file-objects.html
itself talks in some obfuscated incomprehensible way.

---
Here's the detail of the GzipFile description:

class GzipFile( [filename[, mode[, compresslevel[, fileobj)
Constructor for the GzipFile class, which simulates most of the methods
of a file object, with the exception of the readinto() and truncate()
methods. At least one of fileobj and filename must be given a
non-trivial value.
The new class instance is based on fileobj, which can be a regular
file, a StringIO object, or any other object which simulates a file. It
defaults to None, in which case filename is opened to provide a file
object.

 yeah, blab blab blab. what the fuck are you talking about? So, how to
use it?

When fileobj is not None, the filename argument is only used to be
included in the gzip file header, which may includes the original
filename of the uncompressed file. It defaults to the filename of
fileobj, if discernible; otherwise, it defaults to the empty string,
and in this case the original filename is not included in the header.

 what the fuck??

The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
depending on whether the file will be read or written. The default is
the mode of fileobj if discernible; otherwise, the default is 'rb'. If
not given, the 'b' flag will be added to the mode to ensure the file is
opened in binary mode for cross-platform portability.

 discernible? so, what the fuck are exactly these modes? can't you
describe them concretely?

The compresslevel argument is an integer from 1 to 9 controlling the
level of compression; 1 is fastest and produces the least compression,
and 9 is slowest and produces the most compression. The default is 9.

Calling a GzipFile object's close() method does not close fileobj,
since you might wish to append more material after the compressed data.
This also allows you to pass a StringIO object opened for writing as
fileobj, and retrieve the resulting memory buffer using the StringIO
object's getvalue() method.

  huh? append more material? pass a StringIO? and memory buffer?


Motherfucking 90% of programers using this module really just want to
compress or decompress a file.

Fuck unix advocates and fuck Perlers and fuck Python morons.

PS For more about Python doc, please see:
http://xahlee.org/perl-python/re-write_notes.html

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: Python doc problems example: gzip module

2005-08-31 Thread Peter Maas
Xah Lee schrieb:
> today i need to use Python to decompress gzip files.
> 
> since i'm familiar with Python doc and have 10 years of computing
> experience with 4 years in unix admin and perl, i have quickly located
> the official doc:
> 
>  http://python.org/doc/2.4.1/lib/module-gzip.html
> 
> but after a minute of scanning, please someone tell me what the fuck is
> it talking about?
> 
> Fuck the Python programing morons.
> 
> Thanks.
> 
> I just need to decompress files. Is it:
> 
> import gzip;
> gzip.GzipFile("/Users/xah/access_log.1.gz");
> 
> can someone put a example into that fucking doc so that people don't
> have to wade thru whatever fuck it is trying to sound big?

Here's the example:
import gzip

# read fucked
fuckedfile = gzip.GzipFile('somefile.gz')
content = fuckedfile.read()
fuckedfile.close()

# write unfucked
unfuckedfile = file('somefile','w')
unfuckedfile.write(content)
unfuckedfile.close()

Please feel free to insert this fucking example into the fucking docs.

Have a nice ... eh fucking day :)

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-31 Thread Bryan Olson
Paul Rubin wrote:
 > Not every sequence needs __len__; for example, infinite sequences, or
 > sequences that implement slicing and subscripts by doing lazy
 > evaluation of iterators:
 >
 >   digits_of_pi = memoize(generate_pi_digits())  # 3,1,4,1,5,9,2,...
 >   print digits_of_pi[5]   # computes 6 digits and prints '9'
 >   print digits_of_pi($-5)  # raises exception

Good point. I like the memoize thing, so here is one:


class memoize (object):
 """ Build a sequence from an iterable, evaluating as needed.
 """

 def __init__(self, iterable):
 self.it = iterable
 self.known = []

 def extend_(self, stop):
 while len(self.known) < stop:
 self.known.append(self.it.next())

 def __getitem__(self, key):
 if isinstance(key, (int, long)):
 self.extend_(key + 1)
 return self.known[key]
 elif isinstance(key, slice):
 start, stop, step = key.start, key.stop, key.step
 stop = start + 1 + (stop - start - 1) // step * step
 self.extend_(stop)
 return self.known[start : stop : step]
 else:
 raise TypeError(_type_err_note), "Bad subscript type"


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


[ANN] FreeImagePy 1.0.0

2005-08-31 Thread Michele Petrazzo
What is?
  It' a python wrapper for FreeImage, Open Source library for developers
   who would like to support popular graphics image formats.

How work?
  It use a binary freeimage library present on the system and ctypes.

It 's released with the two public license GPL/FIPL:
GPL: GNU GENERAL PUBLIC LICENSE - freeimagepy.sf.net/license-gpl.txt
FIPL: FreeImage Public License - freeimagepy.sf.net/license-fi.tx

More informations can be found here:
http://freeimagepy.sf.net/

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


.pth files in working directory

2005-08-31 Thread Peter Maas
My goal is to have the top level of a directory tree in the Python
path without touching anything outside the directory. I tried to
create .pth files with the top level path in every subdirectory
but this doesn't work despite working directory being part of the
Python path.

Creating the pth file in .../site-packages works but I prefer to
have everything inside the directory tree so that removing the tree
is sufficient for a complete uninstall. Any hints are appreciated,
thanks.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


strange behaviour of str()

2005-08-31 Thread Juho Vuori
Hello,

I'm wondering about the following behaviour of str() with strings 
containing non-ASCII characters:

str(u'foo') returns 'foo' as expected.

str('lää') returns 'lää' as expected.

str(u'lää') raises UnicodeEncodeError

Is this behaviour sane? Possibly, but not documented at all. Somehow 
you'd expect str() to never fail. I'm hesitating about sending a bug 
report about a third party application, which fails because it is 
relaying on this.

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


Help with this error : Protocol wrong for this socket

2005-08-31 Thread bill . oldroyd
I am running Python 2.4.1 on a HP Tru64 Unix system.

When try to carry out a DNS query as follows :

t = socket.getaddrinfo("labs.bl.uk",None)

I get the error message

socket.error: (41, 'Protocol wrong type for socket')

Am I right in thinking this is something to with the DNS lookup ?. Does
anyone have any idea what may be causing the problem ?.

Bill

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


change date format

2005-08-31 Thread Xah Lee
Apache by default uses the following format for date:
30/Aug/2005

is there a module that turn this directly into mmdd?

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: change date format

2005-08-31 Thread Lars Gustäbel
[Xah Lee]
> Apache by default uses the following format for date:
> 30/Aug/2005
>
> is there a module that turn this directly into mmdd?

Use time.strptime() and time.strftime().

Not a single occurrence of the f**k word. You're making progress. Keep it up!

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Truth is the invention of a liar.
(Anonymous)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python doc problems example: gzip module

2005-08-31 Thread Fredrik Lundh
Peter Maas wrote:

> Please feel free to insert this fucking example into the fucking docs.

or use the fucking search engine.  searching for "python  example"
and clicking the "I feel lucky" button tends to work quite well.  e.g.

http://www.google.com/search?q=python+gzip+example&btnI=

 



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


Re: strange behaviour of str()

2005-08-31 Thread Fredrik Lundh
Juho Vuori wrote:

> str(u'lää') raises UnicodeEncodeError

> Is this behaviour sane? Possibly, but not documented at all.

str() on a Unicode string attempts to convert the string to an 8-bit
string using Python's default encoding, which is ASCII.  "ä" is not
an ASCII character.

if this problem appears in a 3rd party program, that program has
not been properly internationalized.

> Somehow you'd expect str() to never fail.

except for id() and type(), virtually all builtins can fail.  If you want
to convert something to a string no matter what it contains, repr() is
a better choice.  If you want to convert Unicode strings to a given
byte encoding, you have to use the encode method.

 



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

Re: Bicycle Repair Man usability

2005-08-31 Thread bruno modulix
matt wrote:
(snip)
> I'd like to hear other's experiences with refactoring in python.  Most
> of the projects I work on are quite small relative to some of the Java
> projects I've worked on.  

Python being much less verbose and much more dynamic than Java, the
LOCs/functionnalities ratio can be very different. So what would be a
medium-size project in Java usually become a small-size project in Python.


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


use threading without classes

2005-08-31 Thread billiejoex
Hi all. Hi would like to use two threads in a program but all the examples I 
found on the net use oop programming that I doesn't love too much. :-)
Can you code me a short example in wich two different functions are executed 
at the same time, plz?

Thank you all.


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


strange behaviour of str()

2005-08-31 Thread Uwe Schmitt
> 
> Hello,
> 
> I'm wondering about the following behaviour of str() with strings 
> containing non-ASCII characters:
> 
> str(u'foo') returns 'foo' as expected.
> 
> str('lää') returns 'lää' as expected.
> 
> str(u'lää') raises UnicodeEncodeError
> 

This does not work, because you need an encoder to convert
unicode to str. str() does not know a priori which  encoder
to use. There are many ways to encode a unicode string
to a classic byte-stream based string.

you have to procede as follows:

   >>> s=u"äää"
   >>> print s.encode("latin-1")
   äää

try "utf-8" and "utf-16" instead of "latin-1"

Greetings, Uwe.




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

Re: use threading without classes

2005-08-31 Thread Harlin Seritt
Is there any reason why you wouldn't want to do this using the the
threading class? To each his own I suppose. You can try the following
though you'll at least need to use functions:


import time
import thread

def myfunction(string,sleeptime,*args):
while 1:

print string
time.sleep(sleeptime) #sleep for a specified amount of time.

if __name__=="__main__":

thread.start_new_thread(myfunction,("Thread No:1",2))

while 1:pass

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


Re: Yielding a chain of values

2005-08-31 Thread Reinhold Birkenfeld
Matt Hammond wrote:
>> Well, maybe it's right both ways ;-) I.e., even though yield "is" now
>> an expression, it is valid to use it as an expression-statement which
>> evaluates the expression and discards the value. So I think you could
>> still use the currently illegal "yield in" token sequence to mean that
>> what follows is to be taken as an iterable whose full sequence is
>> to be yielded sequentially as if
>>
>> yield in iterable
>>
>> were sugar for
>>
>> for _ in iterable: yield _
> 
> "yield in" could make sense when thought of as an expression too.
> 
>  x = yield in iterable
> 
> Would behave like a list comprehension. x would be assigned a list  
> containing
> the results of the successive yields. Equivalent to:
> 
>   x = [ yield r for r in iterable ]

Which is quite different from

x = (yield) in iterable

which is currently (PEP 342) equivalent to

_ = (yield)
x = _ in iterable

So, no further tinkering with yield, I'm afraid.

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


Re: change date format

2005-08-31 Thread Fredrik Lundh
Lars Gustäbel wrote:

> Not a single occurrence of the f**k word. You're making progress.

perhaps, but why is he posting apache questions to the python list?

 



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

Re: Yielding a chain of values

2005-08-31 Thread Kay Schluehr
Reinhold Birkenfeld wrote:

> > x = [ yield r for r in iterable ]
>
> Which is quite different from
>
> x = (yield) in iterable
>
> which is currently (PEP 342) equivalent to
>
> _ = (yield)
> x = _ in iterable
>
> So, no further tinkering with yield, I'm afraid.
>
> Reinhold

Is the statement

   yield from iterable

also in danger to be ambigous?

The resolution of "(yield) from iterable" into

 _ = (yield)
 x = _ from iterable

would not result in valid Python syntax.

Kay

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


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread n00m
Funnily but I still can't get the code working... WITHOUT IDLE.
I think it's because of "import thread" line. Seems something
wrong with "opening" this module. In IDLE it works OK.

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


Re: OpenSource documentation problems

2005-08-31 Thread Bryan Olson
Terry Hancock wrote:
 > Bryan Olson wrote:
 >
 >>I don't see any need to look beyond Python for a good example of
 >>poor documentation.  Are there serious Python programmers who
 >>don't constantly struggle with errors and omissions in the doc?
 >
 > Uh, yes, actually.
 >
 > IMHO, the available Python documentation is, extremely helpful,
 > concise and accessible.  Maybe you aren't using all of it:

A plausible theory. I have some possibly-illustrative examples
of what I ran into within the last few weeks.

 > 1) Remember that any object or module you load will tell you
 > its contents with a dir() or give you automatically generated
 > documentation with help().  This documentation has the advantage
 > of being almost always accurate and up-to-date, even if it is
 > sometimes too brief and poorly explained.

I use dir() all the time; help() not so much. Typing help(help)
shows:

 Help on _Helper in module site:

 Type help() for interactive help, or help(object) for help
 about object.

That strikes me as not-particularly-helpful. Surely it should at
least direct the user to 'pydoc.help'.


 > 2) More in-depth documentation for the Python standard library
 > is available in the "Library Reference".  This covers everything
 > from built-in functions to fairly obscure modules that are nevertheless
 > in the Python library.

Three weeks ago, in trying to explain a point about Python's
zlib module, I discovered that the doc was wrong.

http://groups.google.com/group/comp.lang.python/msg/20609fff71a2ed02

The Python standard library is certainly useful, but in my
opinion the bar is set too low.


 > 3) Questions about the functioning of the language are most accurately
 > resolved by trying them out in the interpreter. This is usually
 > faster than any documentation search.  Python's interpreter is extremely
 > friendly and easy to start up, so this is really easy to do.

Then how does one distinguish stable, supported services, from
incidental behavior that can change without notice?


 > 4) But if you want a more theoretical and explained version of the
 > language, there's always the "Language Reference".

Which is what steered me wrong on the behavior of slice objects:

   http://groups.google.com/group/comp.lang.python/msg/66014427182265b9

That one cost me a hours, mostly because when I my own code
misbehaves in certain cases, a language/doc bug is not my first
guess.


 > Between these 4 sources, I can resolve almost any question that
 > comes up about the core Python language.
 >
 > Somewhat more obscure applications are covered by the "Extending
 > and Embedding" document, and there are other documents and tutorials
 > either in your Python distribution (if you have a good one) or on
 > the http://www.python.org website).

Three days ago, I wanted to know how to call C from Python, and
the "Extending and Embedding" document told me:

 (I won't dwell on how to call the Python parser with a
 particular string as input -- if you're interested, have a
 look at the implementation of the -c command line option in
 Python/pythonmain.c from the Python source code.)

I got the Python source distribution, and couldn't find that
file. So I went to the CVS archive, and still couldn't find the
file. I don't think it exists. Had that doc just said nothing
about it, I probably would have found PyRun_SimpleString and its
siblings in a few minutes. I suspect the document is out of
date, as it also seems to teach the use of deprecated methods.

Whatever else one says about open-source documentation, keeping
it current is a major unsolved problem.


 > If you're really looking for cookbook examples, there are specific
 > websites to check for, though I usually just hit Google with a
 > few keywords.  And if all that fails you, you can always ask the
 > people on this list.

I'm with you on that. (I used to work for Google, where finding
the doc means eating the dog-food.) I find that for any popular
software, typing error messages into Google yields a better
results-to-effort ratio than trying to look them up in a manual.


 > I have NEVER seen a closed source application or programming
 > language that came with that much documentation and support.

I'm no fan of Microsoft, but in general, the Win32 API is far
better documented than is Python. (Just don't use the searching
facilities on the MSDev CD's to find the doc; Google it up.)

[...]
 > I also have to say, that as a module writer, Python's support
 > for self-documenting code or "literate programming" is excellent.
 > I'm really coming to appreciate the value of this.

Unfortunately, it's also full of traps.


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


Re: .pth files in working directory

2005-08-31 Thread Peter Hansen
Peter Maas wrote:
> My goal is to have the top level of a directory tree in the Python
> path without touching anything outside the directory. I tried to
> create .pth files with the top level path in every subdirectory
> but this doesn't work despite working directory being part of the
> Python path.
> 
> Creating the pth file in .../site-packages works but I prefer to
> have everything inside the directory tree so that removing the tree
> is sufficient for a complete uninstall. Any hints are appreciated,
> thanks.

Not sure from the above description exactly what it is you want, but 
generally such non-standard sys.path and .pth manipulations are best 
handled by a sitecustomize.py file, possibly which makes its own calls 
to site.addsitedir() and such.  Try "help(site)" for more.

In this case, I think you'd have a sitecustomize.py which looks for .pth 
files in the current directory and calls site.addsitedir(), but I'm not 
sure.  Maybe if this doesn't work, an example would clarify things.

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


Re: use threading without classes

2005-08-31 Thread Peter Hansen
billiejoex wrote:
> Hi all. Hi would like to use two threads in a program but all the examples I 
> found on the net use oop programming that I doesn't love too much. :-)
> Can you code me a short example in wich two different functions are executed 
> at the same time, plz?

import time
from threading import Thread

def func1():
 print 'first func running'
 time.sleep(1)
 print 'first func done'

def func2():
 print 'second func running'
 time.sleep(1)
 print 'second func done'

Thread(target=func1).start()
Thread(target=func2).start()

Note that this is still using "OOP programming", and you can't 
effectively avoid this in Python without jumping through more hoops than 
you're really interested in, but this basically avoids the need to do 
OOP things like subclassing.

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


module not found in IIS virtual dir

2005-08-31 Thread Peter Maas
I'm trying to call python scripts from IIS in the following tree:

upgrade/
 util/
 __init__.py
 logonUser.py
 select/
 selectFiles.py

- select/ is referred from IIS as a virtual dir vselect.

- upgrade/ is inserted into the Python path via .pth file in
   .../site-packages.

- selectFiles.py has a line "from util import logonUser".

If I run selectFiles.py from the command line everything is ok. But
if I call it via IIS (http://localhost/vselect/selectFiles.py) there
is an error "No module named util" due the fact that selectFiles.py
still sees upgrade/ in the Python Path but upgrade/util/logonUser.py
can no longer be found by selectfiles.py (os.path.exists returns
false). This is strange because other modules, e.g. odbc.py are still
importable. Hope you can help me. Thanks.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread Richie Hindle

[n00m]
> Funnily but I still can't get the code working... WITHOUT IDLE.
> I think it's because of "import thread" line. Seems something
> wrong with "opening" this module. In IDLE it works OK.

It's difficult to diagnose your problem with so little information. Please
post:

 o The command you're typing into the command prompt
 o The error message you're getting
 o The full traceback
 o The code you're trying to run, or if it's too big then the piece that
   the last line of the traceback refers to

Thanks,

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


Re: Bicycle Repair Man usability

2005-08-31 Thread Kay Schluehr

Sybren Stuvel wrote:

> > -Get rid of extra variables by shifting them inline (e.g.:
> > a=1;b=2;c=a+b --> c=1+2)
>
> This is already excess functionality IMO.

I don't think that Rex talked about his programming style but about
three and only three refactoring methods survived in BRM from ~30
Fowler described in his book. By the way I can't remember the one you
picked up but I remember the reverse i.e. introducing intermediate
variable names for readability and debugging purposes.

Instead of writing f(g(h(...))) it is sometimes adaequate to write

x = h(...)
f(g(x))

I use this a lot in particular in C++. Optimzing compilers eliminate
runtime penalties. This is of course different in CPython.

In case of BRM I'm not sure why it is particular hard to implement
"Move Method" for instance? BRM is shipped with a lot of testcases
which is good but neither defines requirements nor leads a discussion
about refactoring methods in Python. Needless to say that the code is
not well documented. 

Kay

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


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread Steve Holden
n00m wrote:
> Funnily but I still can't get the code working... WITHOUT IDLE.
> I think it's because of "import thread" line. Seems something
> wrong with "opening" this module. In IDLE it works OK.
> 

Now, let's see ... [presses fingers to temples and exercises psychic 
powers] ... ah yes, its because you're DOING SOMETHING WRONG :-)

Unfortunately "can't get the code working" isn't a very helpful 
description. Can you explain (preferably with a traceback) how it fails?

Generally speaking, when you take your car into the garage (American: 
shop) because "it won't go" it's OK because the technicians can try and 
start it themselves. We don;t have your code readily to hand, so we need 
a bit more to go on.

Generally speaking you would do well to try the threading module rather 
than thread unless you have a specific reason for not doing so. But if 
you post your code (or even better a subset of your code that 
demonstrates the error so people can pick it apart for themselves) with 
a traceback from the interpreter or a full description of what you 
expected the code to do and what it actually does we'll be able to help 
much more easily.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Sockets: code works locally but fails over LAN

2005-08-31 Thread n00m
import socket, thread
host, port = '192.168.0.3', 1434
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((host, 1433))
s1.bind((host, port))
s1.listen(1)
cn, addr = s1.accept()

def VB_SCRIPT():
while 1:
data = cn.recv(4096)
if not data: return
s2.send(data)
print 'VB_SCRIPT:' + data + '\n\n'

def SQL_SERVER():
while 1:
data = s2.recv(4096)
if not data: return
cn.send(data)
print 'SQL_SERVER:' + data + '\n\n'

thread.start_new_thread(VB_SCRIPT,())
thread.start_new_thread(SQL_SERVER,())

=

The above code acts as an intermediator between a very simple VB script
and SQL Server. Like follows:
the vbs sends its requests to "fake" port 1434 and the python code
catches and re-sends them to sql server which listens to its DEFAULT
port = 1433... And vice versa.


=
VB script:
=

Set cn = CreateObject("ADODB.Connection")
cn.Open _
"Provider=sqloledb;Data Source=192.168.0.3,1434;" & _
"Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
"User ID=qwe;Password=asdasd;"

cn.Execute "select * from authors;"
cn.Close
Set cn = Nothing

=


It works fine (I see all client/server data printed in IDLE window)but
only locally. I.e. if vbs, python and sql server run on the same
machine.

If I run the vbs from some other machine in my LAN then it fails to
work out properly. Below is all that vbs and sql server are able to say
to each other:


===

VB_SCRIPT:
   SERVER qwe asdasd 00a5 Р·€Ut
 Microsoft (r) W 192.168.0.3,1434  asdasd
  OLEDB 


SQL_SERVER:
 Щ 3 г
 pubsmaster«0 E   # Changed database context
to 'pubs'.W   г
 
us_english «4 G   ' Changed language setting to us_english.W   г
cp1251 ­    Microsoft SQL Server  _ Вг 40964096э


VB_SCRIPT:
 G   4096  

==


In abt 30 seconds OLE DB Provider (on the vbs side) reports "General
Network Error".


PEOPLE, WHY ON THE EARTH IT DOES NOT WORK OVER LAN ???

PS:
Of course, without involving Python into the process vbs and sql server
communicate with each other just fine - no matter locally or over LAN;
on win2k machines or on/from NT 4.0 machine.

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

Re: .pth files in working directory

2005-08-31 Thread Peter Maas
Peter Hansen schrieb:
> Not sure from the above description exactly what it is you want,

I want a tree

top/
 install.py
 sub1/
 __init__.py
 mod1.py
 sub2/
 mod2.py

where I can do "from sub1 import mod1" in mod2.py no matter what the
absolute path of top is. To achieve this I start install.py once to
retrieve the absolute dir of itself (= abspath of top/) and creates
.pth files with its absolute dir in every subdirectory.

 > but
> generally such non-standard sys.path and .pth manipulations are best 
> handled by a sitecustomize.py file, possibly which makes its own calls 
> to site.addsitedir() and such.  Try "help(site)" for more.

But sitecustomize.py changes the Python installation, doesn't it?
This wouldn't be an advantage over putting a .pth file into
.../site-packages.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .pth files in working directory

2005-08-31 Thread Michael Ekstrand
On Wed, 31 Aug 2005 15:07:41 +0200
Peter Maas <[EMAIL PROTECTED]> wrote:
> I want a tree
> 
> top/
>  install.py
>  sub1/
>  __init__.py
>  mod1.py
>  sub2/
>  mod2.py
> 
> where I can do "from sub1 import mod1" in mod2.py no matter what the
> absolute path of top is. To achieve this I start install.py once to
> retrieve the absolute dir of itself (= abspath of top/) and creates
> .pth files with its absolute dir in every subdirectory.

If top/ is the working directory for your Python interpreter, the
problem is solved automatically. Python puts the current working
directory in the default search path. So, if you run

python sub2/mod2.py

then it would work.

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


Re: use threading without classes

2005-08-31 Thread billiejoex
Thank you for your helping. 


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


Re: Sockets: code works locally but fails over LAN

2005-08-31 Thread Peter Hansen
n00m wrote:
> import socket, thread
> host, port = '192.168.0.3', 1434
> s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s2.connect((host, 1433))
> s1.bind((host, port))
> s1.listen(1)
> cn, addr = s1.accept()
> 
> def VB_SCRIPT():
> while 1:
> data = cn.recv(4096)
> if not data: return
> s2.send(data)
> print 'VB_SCRIPT:' + data + '\n\n'
> 
> def SQL_SERVER():
> while 1:
> data = s2.recv(4096)
> if not data: return
> cn.send(data)
> print 'SQL_SERVER:' + data + '\n\n'

Several suggestions:

1. Use repr(data) instead of just 'data' above, to see better the actual 
bytes without the possibility of control characters like \r and \b 
screwing things up.

2. I'm not at all sure that accessing the same socket object 
simultaneously from two threads is safe.  You might consider creating a 
pair of Queue objects to safely communicate the information between the 
two threads.  That, of course, poses the problem of how do you wait on 
data to arrive from the socket and from the Queue at the same time.  One 
approach is to use non-blocking sockets or timeouts, while the other is 
to use a pre-existing asynchronous framework such as, say, Twisted, and 
avoid reinventing the wheel (and making all the same mistakes that other 
programmers have made zillions of times before you).

It's also possible this is not remotely related to your problem, but I 
suspect without knowing more about SQL Server, VB, and your own setup 
I'd be guessing wildly anyway...

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


Re: .pth files in working directory

2005-08-31 Thread Peter Hansen
Peter Maas wrote:
> Peter Hansen schrieb:
>> generally such non-standard sys.path and .pth manipulations are best 
>> handled by a sitecustomize.py file, possibly which makes its own calls 
>> to site.addsitedir() and such.  Try "help(site)" for more.
> 
> But sitecustomize.py changes the Python installation, doesn't it?
> This wouldn't be an advantage over putting a .pth file into
> .../site-packages.

You can have a local sitecustomize.py in the current directory, which 
wouldn't change the Python installation.  Would that help?

As far as I can tell, the current directory isn't added to the sys.path 
until after site.py executes, so I don't believe you can rely on .pth 
files to do anything like what you want.  Sitecustomize.py is it, with 
appropriate smarts inside.

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


Re: Bicycle Repair Man usability

2005-08-31 Thread Fredrik Lundh
Kay Schluehr wrote:

> Instead of writing f(g(h(...))) it is sometimes adaequate to write
>
> x = h(...)
> f(g(x))
>
> I use this a lot in particular in C++. Optimzing compilers eliminate
> runtime penalties. This is of course different in CPython.

if "x" is a local variable, the penality isn't that huge:

$ timeit "id(len(str(0)))"
100 loops, best of 3: 0.911 usec per loop

$ timeit "x = str(0); id(len(x))"
100 loops, best of 3: 0.968 usec per loop

globals are slower:

$ timeit -s "global x" "x = str(0); id(len(x))"
100 loops, best of 3: 1.26 usec per loop

 



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


Re: module not found in IIS virtual dir

2005-08-31 Thread Peter Maas
Peter Maas schrieb:
> I'm trying to call python scripts from IIS in the following tree:
[...]
> If I run selectFiles.py from the command line everything is ok. But
> if I call it via IIS (http://localhost/vselect/selectFiles.py) there
> is an error "No module named util" [...]

Forget it. It was an ACL issue. Silly mistake.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sockets: code works locally but fails over LAN

2005-08-31 Thread Grant Edwards
On 2005-08-31, Peter Hansen <[EMAIL PROTECTED]> wrote:

> 2. I'm not at all sure that accessing the same socket object 
> simultaneously from two threads is safe.

It's OK under Unix.  Having one thread handle rx and a
different one handle tx is a pretty widely used method.

Don't know about Win32...


-- 
Grant Edwards   grante Yow!  Someone in DAYTON,
  at   Ohio is selling USED
   visi.comCARPETS to a SERBO-CROATIAN
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python doc problems example: gzip module

2005-08-31 Thread Sybren Stuvel
Xah Lee enlightened us with:
> but after a minute of scanning, please someone tell me what the fuck
> is it talking about?

How difficult is it? The first line of the Gzip class explains it all
to me: "Constructor for the GzipFile class, which simulates most of
the methods of a file object"

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .pth files in working directory

2005-08-31 Thread Peter Maas
Michael Ekstrand schrieb:
> If top/ is the working directory for your Python interpreter, the
> problem is solved automatically. Python puts the current working
> directory in the default search path. So, if you run

IIS sets the the site path as working directory. So I would probably
have to change wd at the beginnig of every module. Each module would
read the top location from a .pth file in its directory. Yes that's
possible. Thanks for your help.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .pth files in working directory

2005-08-31 Thread Peter Maas
Peter Hansen schrieb:
> Peter Maas wrote:
>> But sitecustomize.py changes the Python installation, doesn't it?
>> This wouldn't be an advantage over putting a .pth file into
>> .../site-packages.
> 
> 
> You can have a local sitecustomize.py in the current directory, which 
> wouldn't change the Python installation.  Would that help?

I think this is what I need. Thanks, Peter.

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new line

2005-08-31 Thread Kuljo
Kuljo wrote:

> Kuljo wrote:
> 
>> Dear friends
>> I'm so sorry to bore you with this trivial problem. Allthou: I have
>> string having 0x0a as new line, but I should have \n instead.
>> How should I solve it?
>> I've tried
>text_new=tex_old.replace(str(0x0a), '\n')
>> and other things, but none of them worked.
>> Thanks in advance
> 
> 
> I have found this in the meantime:
> 
nl="\\"+"n"
text_new=replace(text_old, chr(10), nl)
> 
> It works.

Thanks Peter,
you are right, even
>>>text_new=replace(text_old, chr(10), "\\n")
works.
Yes, it was exactly what I needed. The problem actually was: I'm using Pilot
V for years and a part of my "knowledge base" is stored in den memo files.
On the PC side I'm using jpilot (Linux Kubuntu 5.04) which works perfectly.
Now I wanted to try out kontact (groupware). The shortcoming is that
kontact (actually kpilot in the background) does not import the memos. But
it store them in a folder as a file per memo. In this file are the cr/lf
indicated by hex 0a. The notes in kontact uses char \n instead. For this
translation I made a python script which works now.
Kind regards Kuljo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with string -> int conversion ?

2005-08-31 Thread Madhusudan Singh
Fredrik Lundh wrote:


>> The code is :
>>
>> void Form3::getNPrange()
>> {
> 
> what language is this?

Its python embedded in the designer workflow. pyuic extracts stuff from it,
and generates a python script from the ui.h file.

> 
> if the callback code is Python, you should be able to add a print
> statement to the line just before the failing "int" call:
> 
> print repr(signalrangestr), type(signalrangestr)
> signalrange = int(signalrangestr)
> 
> that print statement should be all you need to figure out what
> signalrangestr really is.

Thanks for the hint.

I get :

<__main__.qt.QString object at 0xb7c1a3ec> 

The question is :

How do I convert a QString to a plain string ?
-- 
http://mail.python.org/mailman/listinfo/python-list


socket.sslerror:(1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol')

2005-08-31 Thread Robert
socket.sslerror:(1, 'error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown protocol')

Got this from another computer/setup, which I cannot debug. What can be the
cause for this problem?

Python 2.3.5

trace:

[ ...(\'ClientCookie_urllib2_support.pyo\', 572, \'open\', None),
(\'ClientCookie_urllib2_support.pyo\', 472, \'http_response\', None),
(\'ClientCookie_urllib2_support.pyo\', 589, \'error\', None),
(\'urllib2.pyo\', 306, \'_call_chain\', None),
(\'ClientCookie_urllib2_support.pyo\', 181, \'http_error_302\', None),
(\'ClientCookie_urllib2_support.pyo\', 566, \'open\', None),
(\'urllib2.pyo\', 326, \'open\', None), (\'urllib2.pyo\', 306,
\'_call_chain\', None), (\'ClientCookie_urllib2_support.pyo\', 807,
\'https_open\', None), (\'ClientCookie_urllib2_support.pyo\', 656,
\'do_open\', None), (\'httplib.pyo\', 715, \'endheaders\', None),
(\'httplib.pyo\', 600, \'_send_output\', None), (\'httplib.pyo\', 567,
\'send\', None), (\'httplib.pyo\', 988, \'connect\', None), (\'socket.pyo\',
73, \'ssl\', None)]

Robert


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


Re: What are new-style classes?

2005-08-31 Thread Terry Hancock
On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote:
> The customary way is to use "class new_class(object):". There's no advantage 
> in using
> __metaclass__ except that you can set it globally for all classes in that 
> module
> (which can be confusing on its own).
> 
> My comment mostly referred to "new-style classes must be declared as a 
> subclass of
> a new-style class", which is not true.

Nonsense.  "__metaclass__" is simply an implementation detail.

We know that because it begins with "__".

Therefore it is invisible, and any delusion you may have that
you can see it is a complete non-issue.

In Python we call that encapsulation.

;-D

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Epydoc - Documenting class members?

2005-08-31 Thread Miki Tebeka
Hello,

Is there a way to document class members in Epydoc?

Something like:

class Point:
def __init__(self, x, y):
'''Create new point
@param x: X coord
@param y: Y coord
'''
self.x = x # How do I document here?
self.y = y # How do I document here?

Thanks.
--

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


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

'ps -A' command freezes Popen3

2005-08-31 Thread gao_bolin
Does anybody know why the following lines would freeze python [2.4.1 on
Linux]:

import popen2
a = popen2.Popen3('ps -A')
a.wait()

Thanks

B.

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


Infinity syntax. Re: Bug in string.find; was...

2005-08-31 Thread Kay Schluehr
Bengt Richter wrote:

> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
> That would give a consitent interpretation of seq[-1] and no errors
> for any value ;-)

Cool, indexing becomes cyclic by default ;)

But maybe it's better to define it explicitely:

seq[!i] = seq[i%len(seq)]

Well, I don't like the latter definition very much because it
introduces special syntax for __getitem__. A better solution may be the
introduction of new syntax and arithmetics for positive and negative
infinite values. Sequencing has to be adapted to handle them.

The semantics follows that creating of limits of divergent sequences:

!0 =  lim n
  n->infinity

That enables consistent arithmetics:

!0+k = lim n+k -> !0
n->infinity

!0/k = lim n/k ->  !0 for k>0,
n->infinity-!0 for k<0
   ZeroDevisionError for k==0


etc.

In Python notation:

>>> !0
!0
>>> !0+1
!0
>>> !0>n# if n is int
True
>>> !0/!0
Traceback (...)
...
UndefinedValue
>>> !0 - !0
Traceback (...)
...
UndefinedValue
>>> -!0
-!0
>>> range(9)[4:!0] == range(9)[4:]
True
>>> range(9)[4:-!0:-1] == range(5)
True

Life can be simpler with unbound limits.

Kay

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


Infinity syntax. Re: Bug in string.find; was...

2005-08-31 Thread Kay Schluehr
Bengt Richter wrote:

> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
> That would give a consitent interpretation of seq[-1] and no errors
> for any value ;-)

Cool, indexing becomes cyclic by default ;)

But maybe it's better to define it explicitely:

seq[!i] = seq[i%len(seq)]

Well, I don't like the latter definition very much because it
introduces special syntax for __getitem__. A better solution may be the
introduction of new syntax and arithmetics for positive and negative
infinite values. Sequencing has to be adapted to handle them.

The semantics follows that creating of limits of divergent sequences:

!0 =  lim n
  n->infinity

That enables consistent arithmetics:

!0+k = lim n+k -> !0
n->infinity

!0/k = lim n/k ->  !0 for k>0,
n->infinity-!0 for k<0
   ZeroDevisionError for k==0


etc.

In Python notation:

>>> !0
!0
>>> !0+1
!0
>>> !0>n# if n is int
True
>>> !0/!0
Traceback (...)
...
UndefinedValue
>>> !0 - !0
Traceback (...)
...
UndefinedValue
>>> -!0
-!0
>>> range(9)[4:!0] == range(9)[4:]
True
>>> range(9)[4:-!0:-1] == range(5)
True

Life can be simpler with unbound limits.

Kay

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


Python doc problems example: gzip module

2005-08-31 Thread Chermside, Michael
Title: Python doc problems example: gzip module






Xah Lee writes:

    [...]

> Fuck the Python programing[sic] morons.

    [...]


Peter Maas replies:

> Here's the example:

    [...]

> Have a nice ... eh fucking day :)


Thank you Peter... you're a hero. THIS is why c.l.py is such a helpful and

civil place to be.


-- Michael Chermside



 

 

 

* 

This email may contain confidential or privileged information. If you believe 

 you have received the message in error, please notify the sender and delete  

the message without copying or disclosing it. 

*  

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

Re: Problem with string -> int conversion ?

2005-08-31 Thread Fredrik Lundh
Madhusudan Singh wrote:

>> if the callback code is Python, you should be able to add a print
>> statement to the line just before the failing "int" call:
>>
>> print repr(signalrangestr), type(signalrangestr)
>> signalrange = int(signalrangestr)
>>
>> that print statement should be all you need to figure out what
>> signalrangestr really is.
>
> Thanks for the hint.
>
> I get :
>
> <__main__.qt.QString object at 0xb7c1a3ec> 
>
> The question is :
>
> How do I convert a QString to a plain string ?

googling for "pyqt qstring" brought up this page:

http://www.opendocspublishing.com/pyqt/x2068.htm

 



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


Re: dynamicly updating an objects fields

2005-08-31 Thread Robert Kern
Uwe Lauth wrote:
> kyle.tk wrote:
> 
>>I want to make a function that will work like this:
>>
>>def updateField(object, fieldName, newValue):
>>  object.fieldName = newValue
> 
> This function already exists in python.
> It is called settattr.

Or rather setattr.

-- 
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


plone site in separate database - MountFolder

2005-08-31 Thread krzychu
Hallo,
I have an existing plone site called "info", I've added some scripts to
it.
I would like to have that plone site into a separate ZODB
database(separate
.fs file).
There is a MountFolder product (1.2 - the latest release), by mean of
this
you can create MountFolder which data is stored in separate ZODB
database.
See manual
http://cvs.sourceforge.net/viewcvs.py/ingeniweb/MountFolder/README.txt?rev=1.6
(I don't use ZEO section).
Creating this MountFolder works fine. There is my registry in
etc/zope.conf
file of my zope instance:
   

  path $INSTANCE/var/infi2.fs

 mount-point /infi2
   container-class
Products.MountFolder.MountFolder.MountFolder
  

But I can't import my plone site or even create brand new plone site
from
Add menu in the MountFolder.
When I try to import my plone site I get the following error:
Error Type: AttributeError
Error Value: portal_types
When I try to add brand new plone site from Add menu (Plone Site
position) I
get the following error:
Error Type: AttributeError
Error Value: portal_url

I've noticed that some standard actions in MountFolder don't work as
well.
For instance when I try to paste Image object into MountFolder I get
error
too:
Error Type: AttributeError
Error Value: portal_url


How can I solve this problem?
Do you have any ideas how to put existing plone site into separate
database?

Regards
Criss

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


Re: Bicycle Repair Man usability

2005-08-31 Thread Peter Maas
Sybren Stuvel schrieb:
> I use BRM if I need to rename a function or variable, and that's about
> it. I do the rest by hand faster than I can figure out how to use
> additional software.

Sounds like "I can walk from Aachen to Cologne faster than figure
out how to drive a car" ;) I don't know BRM nor any other refactoring
tool but for a thorough decision one would have to know the ratio

time(learningTool)/time(doingByHand)

to calculate the break even point in terms of number(doingByHand).

-- 
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-08-31 Thread Ron Adam
Antoon Pardon wrote:

> Op 2005-08-31, Bengt Richter schreef <[EMAIL PROTECTED]>:
> 
>>On 31 Aug 2005 07:26:48 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>>
>>
>>>Op 2005-08-30, Bengt Richter schreef <[EMAIL PROTECTED]>:
>>>
On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:


>Op 2005-08-30, Terry Reedy schreef <[EMAIL PROTECTED]>:
>
>>"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
>>news:[EMAIL PROTECTED]
>>
>>
>>>Really it's x[-1]'s behavior that should go, not find/rfind.
>>
>>I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely 
>>useful, especially when 'x' is an expression instead of a name.
>
>I don't think the ability to easily index sequences from the right is
>in dispute. Just the fact that negative numbers on their own provide
>this functionality.
>
>Because I sometimes find it usefull to have a sequence start and
>end at arbitrary indexes, I have written a table class. So I
>can have a table that is indexed from e.g. -4 to +6. So how am
>I supposed to easily get at that last value?

Give it a handy property? E.g.,

table.as_python_list[-1]
>>>
>>>Your missing the point, I probably didn't make it clear.
>>>
>>>It is not about the possibilty of doing such a thing. It is
>>>about python providing a frame for such things that work
>>>in general without the need of extra properties in 'special'
>>>cases.
>>>
>>
>>How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
>>That would give a consitent interpretation of seq[-1] and no errors
>>for any value ;-)
> 
> 
> But the question was not about having a consistent interpretation for
> -1, but about an easy way to get the last value.
> 
> But I like your idea. I just think there should be two differnt ways
> to index. maybe use braces in one case.
> 
>   seq{i} would be pure indexing, that throws exceptions if you
>   are out of bound
> 
>   seq[i] would then be seq{i%len(seq)}

The problem with negative index's are that positive index's are zero 
based, but negative index's are 1 based.  Which leads to a non 
symmetrical situations.

Note that you can insert an item before the first item using slices. But 
not after the last item without using len(list) or some value larger 
than len(list).

 >>> a = list('abcde')
 >>> a[len(a):len(a)] = ['end']
 >>> a
['a', 'b', 'c', 'd', 'e', 'end']

 >>> a[-1:-1] = ['last']
 >>> a
['a', 'b', 'c', 'd', 'e', 'last', 'end'] # Second to last.

 >>> a[100:100] = ['final']
 >>> a
['a', 'b', 'c', 'd', 'e', 'last', 'end', 'final']


Cheers,
Ron














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


Re: Uploading images via cgi?

2005-08-31 Thread Paul Boddie
Chris Dewin wrote:
> chunk = fileitem.file.read(10), and fout.write (chunk) seem to be the
> key statements. Could  someone elaborate on these for me please? And why
> do they need to be in a while loop?

I imagine that the intention of reading only 10 bytes at a time is
to limit the amount of memory used by the process. In an environment
where the process is kept around (not CGI, however) doing so might be
critical since it has been alleged that Python isn't particularly good
at freeing memory back to the operating system.

One way of limiting the total size of uploaded files might be to
examine the "Content-Length" header and to reject (ie. not process)
uploads involving files above a certain size.

Paul

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


using python_ldap for authentication

2005-08-31 Thread tooper
Hello all,

I'd like to use an ldap server just for authentication, but I'm a
complete beginner with all the ldap stuff...

I've tried this from the python_ldap Demo examples :

--
import ldap, getpass

ldap_url="... validation ldap server URL & port ..."
l = ldap.initialize(ldap_url)

login_dn = "cn=thierry"
login_pw = getpass.getpass("Password for %s: " % login_dn)
l.simple_bind(login_dn, login_pw)
--

but it seems to succeed whatever the password I'm providing :-(

How to simply assess the binding really occured ?
Do I need to start doing stuff with the "l" object to catch an error
and realize I'm not in fact connected : that's my current workaround
but I'm not very proud of it...

Thanks in advance !

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


Re: change date format

2005-08-31 Thread dimitri pater
On 8/31/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
Lars Gustäbel wrote:> Not a single occurrence of the f**k word. You're making progress.perhaps, but why is he posting apache questions to the python list?
because we know all, we see all,  we are "Python programing (sic) morons" dimitri
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: 'ps -A' command freezes Popen3

2005-08-31 Thread Thomas Guettler
Am Wed, 31 Aug 2005 07:12:49 -0700 schrieb gao_bolin:

> Does anybody know why the following lines would freeze python [2.4.1 on
> Linux]:
> 
> import popen2
> a = popen2.Popen3('ps -A')
> a.wait()

Because "ps -A" produces a lot of output to stdout, so that
it blocks. It blocks until you read from the stdout of the subprocess.
If you don't read, it will wait forever. You can redirect the output to a
file "ps -A > /tmp/example". This won't block. Or you use the module
select if you are in a unix environment.

HTH,
  Thomas


-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


HTML tags optimization [ interesting problem]

2005-08-31 Thread DENG

hi all,

i use SGMLParser to process HTML files, in order to do some
optimizations,

something like this:

TEXT1TEXT2

optimise to

TEXT1TEXT2


at the very beginning, i was thinking of analysing each text-block, to
know their color, size, if is bold or italic, but i found it was too
complicated.

e.g

TEXT1

optimise to

TEXT1


but if there is TEXT2 exist

TEXT1TEXT2

we can not do any optimization.

my problem is I can not find a method to treat all those situation, I
had too much thinking and get fool now


anyone can give me some advices?

thanks




PS:

other examples:

1
TEXT
=>
TEXT

2
TEXT TEXT
=>
TEXT TEXT

3
TEXTTEXT
=>
TEXT

etc...

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


Re: Sockets: code works locally but fails over LAN

2005-08-31 Thread Jp Calderone
On 31 Aug 2005 06:03:00 -0700, n00m <[EMAIL PROTECTED]> wrote:
>import socket, thread
>host, port = '192.168.0.3', 1434
>s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s2.connect((host, 1433))
>s1.bind((host, port))
>s1.listen(1)
>cn, addr = s1.accept()
>
>def VB_SCRIPT():
>while 1:
>data = cn.recv(4096)
>if not data: return
>s2.send(data)
>print 'VB_SCRIPT:' + data + '\n\n'
>
>def SQL_SERVER():
>while 1:
>data = s2.recv(4096)
>if not data: return
>cn.send(data)
>print 'SQL_SERVER:' + data + '\n\n'
>
>thread.start_new_thread(VB_SCRIPT,())
>thread.start_new_thread(SQL_SERVER,())

This is about the same as:

mktap portforward --port 1434 --host 192.168.0.3 --dest_port 1433
twistd -f portforward.tap

You'll find the code behind these two commands here:



and here:



And of course, the main Twisted site is .

Some differences between portforward.tap and your code include:

portforward.tap will accept multiple connections, rather than just one.  
portforward.tap won't print out all the bytes it receives (I assume this is 
just for debugging purposes anyway - if not, a simple modification will cause 
it to do this).  portforward.tap won't non-deterministically drop traffic, 
since Twisted checks the return value of send() and properly re-transmits 
anything which has not actually been sent.

Hope this helps,

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


Improving my text processing script

2005-08-31 Thread pruebauno
I am sure there is a better way of writing this, but how?

import re
f=file('tlst')
tlst=f.read().split('\n')
f.close()
f=file('plst')
sep=re.compile('Identifier "(.*?)"')
plst=[]
for elem in f.read().split('Identifier'):
content='Identifier'+elem
match=sep.search(content)
if match:
plst.append((match.group(1),content))
f.close()
flst=[]
for table in tlst:
for prog,content in plst:
if content.find(table)>0:
flst.append('"%s","%s"'%(prog,table))
flst.sort()
for elem in flst:
print elem



What would be the best way of writing this program. BTW find>0 to check
in case table=='' (empty line) so I do not include everything.

tlst is of the form:

tablename1
tablename2

...

plst is of the form:

Identifier "Program1"
Name "Random Stuff"
Value "tablename2"
...other random properties
Name "More Random Stuff"
Identifier "Program 2"
Name "Yet more stuff"
Value "tablename2"
...


I want to know in what programs are the tables in tlst (and only those)
used.

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


Re: Infinity syntax. Re: Bug in string.find; was...

2005-08-31 Thread Bengt Richter
On 31 Aug 2005 07:13:26 -0700, "Kay Schluehr" <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>
>> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
>> That would give a consitent interpretation of seq[-1] and no errors
>> for any value ;-)
>
>Cool, indexing becomes cyclic by default ;)
>
>But maybe it's better to define it explicitely:
>
>seq[!i] = seq[i%len(seq)]
>
>Well, I don't like the latter definition very much because it
>introduces special syntax for __getitem__. A better solution may be the
>introduction of new syntax and arithmetics for positive and negative
>infinite values. Sequencing has to be adapted to handle them.
>
>The semantics follows that creating of limits of divergent sequences:
>
>!0 =  lim n
>  n->infinity
>
>That enables consistent arithmetics:
>
>!0+k = lim n+k -> !0
>n->infinity
>
>!0/k = lim n/k ->  !0 for k>0,
>n->infinity-!0 for k<0
>   ZeroDevisionError for k==0
>
>
>etc.
>
>In Python notation:
>
 !0
>!0
 !0+1
>!0
 !0>n# if n is int
>True
 !0/!0
>Traceback (...)
>...
>UndefinedValue
 !0 - !0
>Traceback (...)
>...
>UndefinedValue
 -!0
>-!0
 range(9)[4:!0] == range(9)[4:]
>True
 range(9)[4:-!0:-1] == range(5)
>True
Interesting, but wouldn't that last line be
 >>> range(9)[4:-!0:-1] == range(5)[::-1]

>Life can be simpler with unbound limits.
Hm, is "!0" a di-graph symbol for infinity?
What if we get full unicode on our screens? Should
it be rendered with unichr(0x221e) ? And how should
symbols be keyed in? Is there a standard mnemonic
way of using an ascii keyboard, something like typing
Japanese hiragana in some word processing programs?

I'm not sure about '!' since it already has some semantic
ties to negation and factorial and execution (not to mention
exclamation ;-)  If !0 means infinity, what does !2 mean?

Just rambling ... ;-)

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


command line arguments

2005-08-31 Thread Jon Hewer
hi

i am writing a little script and currently implementing command line
arguments following the guide by mark pilgrim from dive into python;

http://diveintopython.org/scripts_and_streams/command_line_arguments.html

thats all fine, however i am not sure of the BEST way to handle
multiple command line arguments

for my script, i want to be able to accept two arguments, a name and a
url, but i am not sure if its best to use one command line option/flag
(eg -n to specify name) and then grab the url from the extra data
which will be in 'args':

opts, args = getopt.getopt(sys.argv[1:], "n:", ["name="])

or to have two command line options/flags, -n and -u, and checking
that these have both been specified and then proceeding (this might be
a little messier)

any tips would be much appreciated

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


Re: SpamBayes wins PCW Editors Choice Award for anti-spam software.

2005-08-31 Thread Paul Boddie
Alan Kennedy wrote:

[PCW award to SpamBayes]

> (PCW, for those who don't know it, is sort of the UK's equivalent of Byte 
> Magazine,
> except that it's still publishing after almost 25 years).

Hmmm. Even Byte at its lowest point was far better than PCW ever was.

[...]

> The only problem was they listed the "manufacturer" of the software as
> SourceForge, so the product was known as "SourceForge SpamBayes".

PCW may still be publishing after 25 years (half the magazine being
adverts probably keeps it just about economically viable), but they
clearly haven't yet managed to shake off that classic 1980s mindset
where "everything is a product by a company" (and, given the
superficial understanding of software licensing still likely to be
pervasive in the mainstream UK IT press, "everything else is public
domain").

As for URLs and other things, last time I looked at the PCW Web site,
it was all time-limited (or page-view-limited) viewing for
non-subscribers. If British print distribution wasn't such a lock-in,
I'd imagine PCW would have taken its place alongside Byte, staring at
us from the print media fossil record.

Paul

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


graphical or flow charting design aid for python class development?

2005-08-31 Thread William Gill
Being somewhat new to Python, and having a tendency to over complicate 
things in my class design, I was wondering if anyone can suggest a 
simple graphical or flowcharting tool that they use to organize their 
class and program  design?  Because of a 55 mph head-on accident a few 
years back, I have short term memory problems, so flipping back and 
forth between pages of code is next to impossible for me to keep 
straight.  A simple graphical model  would allow me to 'see' everything 
in one view, and better organize my resulting code. I have had limited 
success using pydoc to view my classes, but it's not really much help in 
development, just review, and sometimes there is too much info.

I have used editors for other languages that allow the view to expand 
and collapse functions/methods (like message threads here on the board), 
which help, but I haven't seen anything like this for python.

Thanks for any suggestions.

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


ANN: Dabo 0.4.1

2005-08-31 Thread Paul McNett
We are happy to announce the release of Dabo 0.4.1, available for
download from:

http://dabodev.com/download

Dabo is a framework for developing 3-tier database applications, and
comes with database wrappers for MySQL, PostgreSQL, Firebird, and
SQLite. It wraps the wxPython GUI toolkit, making it easier to use and
more polymorphic, providing a nice property interface to the controls.

In addition to the main dabo-0.4.1 package, there are also updated
downloads for dabodemo-0.4.1 and daboide-0.2.1.

There have been numerous improvements in Dabo over the past few weeks
since 0.4, summarized here:

Improved test framework for uiwx. Now you can run ui/uiwx/test.py and
get almost all of the dabo controls in one form, and they are the same
tests that you get when you run an individual control directly.

Factored out the saving/restoring of user settings out of dApp into
the separate dUserSettingProvider class, which can be subclassed or
overridded by the developers. Added properties UserSettingProvider
and UserSettingProviderClass to dApp.

Dabo user settings are no longer saved to .userSettings.ini in the app
directory, but are saved to the user's home directory (in ~.dabo/) or
if on Windows, in /Application Data/Dabo/.

Support for SQLite added. As of this moment, Dabo supports several major
open-source database backends: MySQL, PostgreSQL, Firebird, and SQLite.
Next on the list should be Oracle, Sybase, and MS-SQL.

Started work implementing a Quick Report in the datanav library, which
replaces the old HTML Print Preview. This uses the fledgling Dabo Report
Writer to create a PDF rendition of the dataset.

Added new property for all controls: StatusText. When set, and when the
form has a status bar, that text will show in the form's status bar when
the mouse enters the control.

Expanded the dabo.ui.strToBmp() function to accept an optional scale
factor or width/height values. If they are passed, the returned bitmap
image is sized to those values.

Added an optional parameter to the bizobj and cursor's getDataSet()
method. If you send a list of field names, only those fields are returned.

Fixed some lingering bugs in the dabo.ui.uiwx package and the datanav
lib. dWizard works better now. Improved dGauge, dLine, dBox, dRadioBox,
dListBox, dToolBar, and dSizers.

Added simple decimal support to dTextBox.

Work continues on dGrid, specifically dColumn is now better worked
into the "Dabo Way".

Added dabo.trace() function, that will drop you into pdb.

dConnectInfo reworked to have better property names.

Removed dependency on PIL and reportlab from Dabo. These are dependencies
still, but only if you try to run a report.

Added dabo.lib.StopWatch.StopWatch class, which is a light Python
stopwatch with start(), stop(), reset() methods and Value property.

This is a partial list. Both Ed and Paul have been very busy with Dabo
since 0.4 a few weeks ago. Lots of bugfixes and enhancements were made,
and we encourage everyone to upgrade.

---
In addition, we'd like to note that the minesweeper game in dabodemo has
been greatly improved, and also the addition of the card game of
montana. The development of these games are helping us iron out user
interface issues that otherwise may have gone unnoticed.

The AppWizard in daboide/wizards has also been updated to produce even
better generated applications, ones that give the developer a starting
structure that is relatively easy to tweak, modify, and augment.


-- 
Paul McNett
http://paulmcnett.com
http://dabodev.com



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


Re: command line arguments

2005-08-31 Thread Peter Hansen
Jon Hewer wrote:
> i am writing a little script and currently implementing command line
> arguments following the guide by mark pilgrim from dive into python;
> 
> http://diveintopython.org/scripts_and_streams/command_line_arguments.html
> 
> thats all fine, however i am not sure of the BEST way to handle
> multiple command line arguments
> 
> for my script, i want to be able to accept two arguments, a name and a
> url, but i am not sure if its best to use one command line option/flag
> (eg -n to specify name) and then grab the url from the extra data
> which will be in 'args':
> 
> opts, args = getopt.getopt(sys.argv[1:], "n:", ["name="])
> 
> or to have two command line options/flags, -n and -u, and checking
> that these have both been specified and then proceeding (this might be
> a little messier)
> 
> any tips would be much appreciated

I would approach this as a usability issue for your users, rather than 
from the point of view of which is "a little messier" in the code.

What's the purpose of this utility?  Is it to do something with the URL? 
  And the URL must always be specified?  What about the name?  Also 
mandatory, or optional?  The relationship between the two?

I would guess (without yet knowing what you are doing) that if these 
things are not really *optional*, making them options is not the best 
approach and you might be better off just requiring them to be specified 
on the command line as two arguments.

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


To the python-list moderator

2005-08-31 Thread Terry Reedy
For a couple of years, I have been reading and posting and posting to 
python-list and c.l.p via gmane.news.orgs gmane.comp.python.general group. 
Today I got this from 'python-list-bounces', which I presume is a 'machine' 
rather than a 'human' address.

---
Your mail to 'Python-list' with the subject

Re: how to join two Dictionary together?

Is being held until the list moderator can review it for approval.

The reason it is being held:

Message has a suspicious header

Either the message will get posted to the list, or you will receive
notification of the moderator's decision.
-

Since I had nothing to do with the headers, the problem is between gmane's 
sending (perhaps when responding to a message from a particular site) and 
your review.  I hope this can be fixed.

Terry J. Reedy 


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


Re: OpenSource documentation problems

2005-08-31 Thread A.M. Kuchling
On Wed, 31 Aug 2005 12:14:35 GMT, 
> I use dir() all the time; help() not so much. Typing help(help)
> shows:
>
>  Help on _Helper in module site:
>
>  Type help() for interactive help, or help(object) for help
>  about object.
>
> That strikes me as not-particularly-helpful. Surely it should at
> least direct the user to 'pydoc.help'.

help *is* pydoc.help, or at least a trivial wrapper around it, so I don't
see the purpose of mentioning that.  The purpose of the wrapper is so naive
user can just type 'help' at an interpreter prompt:

>>> help
Type help() for interactive help, or help(object) for help about object.
>>>

What additions to that string would you suggest?

> Three weeks ago, in trying to explain a point about Python's
> zlib module, I discovered that the doc was wrong.
> http://groups.google.com/group/comp.lang.python/msg/20609fff71a2ed02

I don't think I'd change the Python docs to try to explain this, because I
have no confidence that we can get the details correct. BerkeleyDB, curses,
and the 'os' module pose similar problems.  For example, people sometimes
ask for more detail about POSIX functions, but no one wants to write a
Python-specific version of "Advanced Programming in the Unix Environment".  

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


can't start new thread

2005-08-31 Thread jdonnell
I posted this about a month ago and peter asked for a stack trace. I
didn't get the error again until yesterday and here is the stack trace
and what I posted before.

Traceback (most recent call last):
  File "./ab.py", line 240, in ?
main()
  File "./ab.py", line 217, in main
abThread.start()
  File "/usr/lib/python2.2/threading.py", line 396, in
start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread


I'm at a loss on this one. I have a multithreaded script that gets
'thread.error: can't start new thread' errors randomly. I
just got it right after starting the script when it was trying to
create the 5th thread. Usually the script will run for a while before
throwing this error, but sometimes it throws it right away.

This script has worked without a problem for months, but I did make
some changes recently. I don't see how those changes would cause
this error though. It's also on a VPS so it's possible that they
changed something in the OS. Does anyone have any suggestions about
possible causes of this error?

I'm using Python 2.2.3 on a custom vps version of FC1.

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


Re: What are new-style classes?

2005-08-31 Thread Reinhold Birkenfeld
Terry Hancock wrote:
> On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote:
>> The customary way is to use "class new_class(object):". There's no advantage 
>> in using
>> __metaclass__ except that you can set it globally for all classes in that 
>> module
>> (which can be confusing on its own).
>> 
>> My comment mostly referred to "new-style classes must be declared as a 
>> subclass of
>> a new-style class", which is not true.
> 
> Nonsense.

Given the rest of your post, I assume that this isn't meant as it sounds. 
Remember, I'm
German, so please bear with my sense of humour. ;)

>  "__metaclass__" is simply an implementation detail.
> 
> We know that because it begins with "__".
> 
> Therefore it is invisible, and any delusion you may have that
> you can see it is a complete non-issue.
> 
> In Python we call that encapsulation.
>
> ;-D

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


Re: can't start new thread

2005-08-31 Thread Paul Rubin
"jdonnell" <[EMAIL PROTECTED]> writes:
> This script has worked without a problem for months, but I did make
> some changes recently. I don't see how those changes would cause
> this error though. It's also on a VPS so it's possible that they
> changed something in the OS. Does anyone have any suggestions about
> possible causes of this error?

Maybe some other VPS(s) under the host OS have spun enough processes
or threads to make the host OS exhaust some limit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yielding a chain of values

2005-08-31 Thread Reinhold Birkenfeld
Kay Schluehr wrote:
> Reinhold Birkenfeld wrote:
> 
>> >x = [ yield r for r in iterable ]
>>
>> Which is quite different from
>>
>> x = (yield) in iterable
>>
>> which is currently (PEP 342) equivalent to
>>
>> _ = (yield)
>> x = _ in iterable
>>
>> So, no further tinkering with yield, I'm afraid.
>>
>> Reinhold
> 
> Is the statement
> 
>yield from iterable
> 
> also in danger to be ambigous?
> 
> The resolution of "(yield) from iterable" into
> 
>  _ = (yield)
>  x = _ from iterable
> 
> would not result in valid Python syntax.

Right.

Problem is, how would you define the "from" syntax: Is its use as
an expression allowed? What value does it have, then?

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


Re: can't start new thread

2005-08-31 Thread jdonnell
>Maybe some other VPS(s) under the host OS have spun enough processes
>or threads to make the host OS exhaust some limit.

I'm not familiar with any hard limits in linux. Is there a config file
with these settings?

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


ANN: Python GUI Editor...

2005-08-31 Thread [EMAIL PROTECTED]
I named this tool - FarPy GUIE, and is available at:
http://farpy.holev.com/

This is a quote from the site:

"GUIE (GUI Editor) provides a simple WYSIWYG GUI editor for wxPython.
The program was made in C# and saves the GUI that was created to a XML
format I called GUIML. This GUIML is a pretty standrad representation
of the GUI created with the program. Next, GUIE takes these GUIML files
and translates it to wxPython Python code. You may ask yourself why I
took the extra step? Why didn't I go straight from C# controls to
wxPython code? Why is GUIML neccessary? Well, it isn't. It is there
simply for people (or maybe I) to take the GUIML and convert it to
other languages. This, by affect can convert this tool from a Python
GUI editor, to "any programming language with a GUI module" GUI editor.

The GUI Editor was built to be as point & click as possible, trying to
avoid wxPython's sizers completly. This means that controls can go
anywhere, and you have the freedom to play with the GUI however you
want. However, this also means that until some more advanced aligning
features are added, this method might be a little awkward at first."

I must add that the tool is in it's early stages of development, and
basically I need the public's help to make it better.

Thanks,

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


Re: To the python-list moderator

2005-08-31 Thread Gregory Piñero
I got this same message.  I'm using gmail.

GregOn 8/31/05, Terry Reedy <[EMAIL PROTECTED]> wrote:
For a couple of years, I have been reading and posting and posting topython-list and c.l.p via gmane.news.orgs gmane.comp.python.general group.Today I got this from 'python-list-bounces', which I presume is a 'machine'
rather than a 'human' address.---Your mail to 'Python-list' with the subjectRe: how to join two Dictionary together?Is being held until the list moderator can review it for approval.
The reason it is being held:Message has a suspicious headerEither the message will get posted to the list, or you will receivenotification of the moderator's decision.-
Since I had nothing to do with the headers, the problem is between gmane'ssending (perhaps when responding to a message from a particular site) andyour review.  I hope this can be fixed.Terry J. Reedy
--http://mail.python.org/mailman/listinfo/python-list -- Gregory PiñeroChief Innovation Officer
Blended Technologies(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: can't start new thread

2005-08-31 Thread Terry Reedy

"jdonnell" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm using Python 2.2.3 on a custom vps version of FC1.

I am pretty sure there have been thread-related bug fixes since then. 
Trying the latest release (even if you can't use it for production) might 
give you some idea of the source of the failure (Python versus your OS).

Terry J. Reedy



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


Re: What are new-style classes?

2005-08-31 Thread Steve Holden
Reinhold Birkenfeld wrote:
> Terry Hancock wrote:
> 
>>On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote:
>>
>>>The customary way is to use "class new_class(object):". There's no advantage 
>>>in using
>>>__metaclass__ except that you can set it globally for all classes in that 
>>>module
>>>(which can be confusing on its own).
>>>
>>>My comment mostly referred to "new-style classes must be declared as a 
>>>subclass of
>>>a new-style class", which is not true.
>>
>>Nonsense.
> 
> 
> Given the rest of your post, I assume that this isn't meant as it sounds. 
> Remember, I'm
> German, so please bear with my sense of humour. ;)
> 
German? Humour? Surely some mistake :-)

not-talking-about-the-war-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Retrieving Filename from Path

2005-08-31 Thread Rob Cowie
Hi,

Given a string representing the path to a file, what is the best way to
get at the filename? Does the OS module provide a function to parse the
path? or is it acceptable to split the string using '/' as delimiters
and get the last 'word'. The reason I'm not entirely happy with that
method is that it is platform specific. I would prefer to use a built
in method if possible.

Cheers,

Rob Cowie

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


Re: What are new-style classes?

2005-08-31 Thread Reinhold Birkenfeld
Steve Holden wrote:
> Reinhold Birkenfeld wrote:
>> Terry Hancock wrote:
>> 
>>>On Tuesday 30 August 2005 04:09 pm, Reinhold Birkenfeld wrote:
>>>
The customary way is to use "class new_class(object):". There's no 
advantage in using
__metaclass__ except that you can set it globally for all classes in that 
module
(which can be confusing on its own).

My comment mostly referred to "new-style classes must be declared as a 
subclass of
a new-style class", which is not true.
>>>
>>>Nonsense.
>> 
>> 
>> Given the rest of your post, I assume that this isn't meant as it sounds. 
>> Remember, I'm
>> German, so please bear with my sense of humour. ;)
>> 
> German? Humour? Surely some mistake :-)

Hm, should have added "if any" above...

> not-talking-about-the-war-ly y'rs  - steve

No surprise it was the Brits who discovered the world's deadliest joke.

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


Re: Retrieving Filename from Path

2005-08-31 Thread robert . dowell
>>> import os.path
>>> help(os.path)
Help on module ntpath:

NAME
ntpath - Common pathname manipulations, WindowsNT/95 version.

FILE
c:\data\utils\python24\lib\ntpath.py

DESCRIPTION
Instead of importing this module directly, import os and refer to
this
module as os.path.

FUNCTIONS
abspath(path)
Return the absolute version of a path

basename(p)
Returns the final component of a pathname

commonprefix(m)
Given a list of pathnames, returns the longest common leading
component

dirname(p)
Returns the directory component of a pathname

exists(path)
Test whether a path exists

expanduser(path)
Expand ~ and ~user constructs.

If user or $HOME is unknown, do nothing.

expandvars(path)
Expand shell variables of form $var and ${var}.

Unknown variables are left unchanged.

getatime(filename)
Return the last access time of a file, reported by os.stat()

getctime(filename)
Return the creation time of a file, reported by os.stat().

getmtime(filename)
Return the last modification time of a file, reported by
os.stat()

getsize(filename)
Return the size of a file, reported by os.stat()

isabs(s)
Test whether a path is absolute

isdir(path)
Test whether a path is a directory

isfile(path)
Test whether a path is a regular file

islink(path)
Test for symbolic link.  On WindowsNT/95 always returns false

ismount(path)
Test whether a path is a mount point (defined as root of drive)

join(a, *p)
Join two or more pathname components, inserting "\" as needed

normcase(s)
Normalize case of pathname.

Makes all characters lowercase and all slashes into
backslashes.

normpath(path)
Normalize path, eliminating double slashes, etc.

realpath = abspath(path)
Return the absolute version of a path

split(p)
Split a pathname.

Return tuple (head, tail) where tail is everything after the
final slash.
Either part may be empty.

splitdrive(p)
Split a pathname into drive and path specifiers. Returns a
2-tuple
"(drive,path)";  either part may be empty

splitext(p)
Split the extension from a pathname.

Extension is everything from the last dot to the end.
Return (root, ext), either part may be empty.

splitunc(p)
Split a pathname into UNC mount point and relative path
specifiers.

Return a 2-tuple (unc, rest); either part may be empty.
If unc is not empty, it has the form '//host/mount' (or similar
using backslashes).  unc+rest is always the input path.
Paths containing drive letters never have an UNC part.

walk(top, func, arg)
Directory tree walk with callback function.

For each directory in the directory tree rooted at top
(including top
itself, but excluding '.' and '..'), call func(arg, dirname,
fnames).
dirname is the name of the directory, and fnames a list of the
names of
the files and subdirectories in dirname (excluding '.' and
'..').  func
may modify the fnames list in-place (e.g. via del or slice
assignment),
and walk will only recurse into the subdirectories whose names
remain in
fnames; this can be used to implement a filter, or to impose a
specific
order of visiting.  No semantics are defined for, or required
of, arg,
beyond that arg is always passed to func.  It can be used,
e.g., to pass
a filename pattern, or a mutable object designed to accumulate
statistics.  Passing None for arg is common.

DATA
__all__ = ['normcase', 'isabs', 'join', 'splitdrive', 'split',
'splite...
altsep = '/'
curdir = '.'
defpath = r'.;C:\bin'
devnull = 'nul'
extsep = '.'
pardir = '..'
pathsep = ';'
sep = r'\'
supports_unicode_filenames = True




Rob Cowie wrote:
> Hi,
>
> Given a string representing the path to a file, what is the best way to
> get at the filename? Does the OS module provide a function to parse the
> path? or is it acceptable to split the string using '/' as delimiters
> and get the last 'word'. The reason I'm not entirely happy with that
> method is that it is platform specific. I would prefer to use a built
> in method if possible.
> 
> Cheers,
> 
> Rob Cowie

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


Re: Code run from IDLE but not via double-clicking on its *.py

2005-08-31 Thread n00m
Richie; Steve; Thanks for your replies!

>  o The command you're typing into the command prompt
>  o The error message you're getting
>  o The full traceback
>  o The code you're trying to run, or if it's too big then the piece that
>the last line of the traceback refers to

1.
D:\>python23\python d:\python23\socket6.py [Enter]

It's OK so far. Python code is launched and starts listening
to port 1434 (see the code below; it's the same code as in my
neibouring topic).
Now I launch a vbs script (which will connect to port 1434).
I.e. I just double-click "my.vbs" file.
And... voila! In a moment & silently console window closes
without any error messages (or I just don't see them).
But VBS reports a network error. Tested on win2k and win98.


In IDLE it works ABSOLUTELY FINE! Prints statements in the
code do exactly what they must do.


import socket, thread
host, port = '127.0.0.1', 1434
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((host, 1433))
s1.bind((host, port))
s1.listen(1)
cn, addr = s1.accept()

def VB_SCRIPT():
while 1:
data = cn.recv(4096)
if not data: return
s2.send(data)
print 'VB_SCRIPT:' + data + '\n\n'

def SQL_SERVER():
while 1:
data = s2.recv(4096)
if not data: return
cn.send(data)
print 'SQL_SERVER:' + data + '\n\n'

thread.start_new_thread(VB_SCRIPT,())
thread.start_new_thread(SQL_SERVER,())

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


Re: global interpreter lock

2005-08-31 Thread [EMAIL PROTECTED]
phil hunt wrote:
> Some times concurrency is the best (or only) way to do a job. Other
> times, it's more trouble than its worth. A good programmer will know
> which is which, and will not use an overly complex solution for the
> project he is writing.

Also, a good programmer won't conflate concurrency with threads.

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


  1   2   >