[ANN] ConfigObj 4.3.2 Released

2006-06-04 Thread Fuzzyman
`ConfigObj 4.3.2 http://www.voidspace.org.uk/python/configobj.html`_
has just been released.

You can download it from `configobj-4.3.2.zip
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.3.2.zip`_.

ConfigObj is a config file reader and writer. It has *many* features,
but the main one is that it is simple to use. Its features include :

* Nested sections (subsections), to any level
* List values
* Multiple line values
* String interpolation (substitution)
* Integrated with a powerful validation system

- including automatic type checking/conversion
- repeated sections
- and allowing default values

* All comments in the file are preserved
* The order of keys/sections is preserved
* No external dependencies
* Full Unicode support
* A powerful ``unrepr`` mode for storing basic datatypes

This is a bugfix and minor feature enhancement release. There is a
bugfix in `unrepr mode
http://www.voidspace.org.uk/python/configobj.html#unrepr-mode`_, and
exception handling has been improved.

The full changelog is :

Changed error handling, if parsing finds a single error then that
error will be re-raised. That error will still have an ``errors`` and a
``config`` attribute. That means the error will be more comprehensible.

Fixed bug where '\n' terminated files could be truncated.

Bugfix in ``unrepr`` mode, it couldn't handle '#' in values.
(Thanks to Philippe Normand for the report.)

As a consequence of this fix, ConfigObj doesn't now keep inline
comments in ``unrepr`` mode. This is because the parser in the
`compiler package http://docs.python.org/lib/compiler.html`_ doesn't
keep comments. {sm;:-)}

Error messages are now more useful. They tell you the number of
parsing errors and the line number of the first error. (In the case of
multiple errors.)

Line numbers in exceptions now start at 1, not 0.

Errors in ``unrepr`` mode are now handled the same way as in the
normal mode. The errors stored will be an ``UnreprError``.

There is also a proposal to support `PEP 292
http://www.python.org/dev/peps/pep-0292/`_ string substitution (which
is much better). This will be the target of the next release of
**ConfigObj**.

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

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


New Python User group in Montreal

2006-06-04 Thread pierreth
Hello,

I am starting a new Python user group in the Montreal area. To do so, I
started a yahoo group on the subject at
http://ca.groups.yahoo.com/group/python-montreal. So welcome!

I taught it would be cool to be a French speaking user group. I hope
the language won't be a problem for you.

Your comments are welcome.

---
Pierre

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

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


Re: Hostmask matching

2006-06-04 Thread Marc Schoechlin
Hi !

Nexu [EMAIL PROTECTED] schrieb:
 I'm trying to write a def to match a string that is an irc hostmask. eg:
 [EMAIL PROTECTED]
 But using re.search(). I get an error when the string starts with '*'.
 What is the best way to solve this?

I suppose the problem occurs because you expression is not a valid
regular expression.

A correct regular expression should look like this:
[EMAIL PROTECTED]

Best regards

Marc Schoechlin

-- 
I prefer non-proprietary document-exchange.
http://sector7g.wurzel6.de/pdfcreator/
http://www.prooo-box.org/
Contact me via jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hostmask matching

2006-06-04 Thread Nexu
On Sun, 2006-06-04 at 06:26 +, Marc Schoechlin wrote:
 Hi !
 
 Nexu [EMAIL PROTECTED] schrieb:
  I'm trying to write a def to match a string that is an irc hostmask. eg:
  [EMAIL PROTECTED]
  But using re.search(). I get an error when the string starts with '*'.
  What is the best way to solve this?
 
 I suppose the problem occurs because you expression is not a valid
 regular expression.
 
 A correct regular expression should look like this:
 [EMAIL PROTECTED]
Thx for everyones input.

This solved the problem:
host = '[EMAIL PROTECTED]'
mask = '[EMAIL PROTECTED]'
newmask = re.sub('\*', '.*', re.sub('\?', '.', mask))
result in that:
re.search(newmask, host) == True


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


Re: Python less error-prone than Java

2006-06-04 Thread Kaz Kylheku
Christoph Zwerschke wrote:
 You will often hear that for reasons of fault minimization, you should
 use a programming language with strict typing:
 http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html

Quoting from that web page:

A programming language with strict typing and run-time checking should
be used.

This doesn't prescribe latent or manifest typing, only that there be
type checking.

There is no question that for reliability, it is necessary to have type
checking, whether at run time or earlier.

You can have statically typed languages with inadequate type safety,
and you can have dynamically typed languages with inadequate type
safety.

 Now the same thing, directly converted to Python:

 def binarySearch(a, key):
  low = 0
  high = len(a) - 1
  while low = high:
  mid = (low + high) / 2
  midVal = a[mid]
  if midVal  key:
  low = mid + 1
  elif midVal  key:
  high = mid - 1;
  else:
  return mid # key found
  return -(low + 1) # key not found.

 What's better about the Python version? First, it will operate on *any*
 sorted array, no matter which type the values have.

Uh huh! With hard-coded  and = operators, how stupid. What if you want
to use it on strings?

Would that be a case-insensitive lexicographic comparison, or
case-insensitive? How do you specify what kind of less-than and equal
you want to do?

-1 to indicate not found? Why copy Java braindamage induced by an
antiquated form of static typing? The Java version has to do that
because the return value is necessarily declared to be of type integer.


;; Common Lisp
;; Binary search any sorted sequence SEQ for ITEM, returning
;; the position (starting from zero) if the item is found,
;; otherwise returns NIL.
;;
;; :REF specifies positional accessing function, default is ELT
;; :LEN specifies function for retrieving sequence length
;; :LESS specifies function for less-than item comparison
;; :SAME specifies function for equality comparison

(defun binary-search (seq item
  key (ref #'elt) (len #'length)
   (less #') (same #'=))
  (loop with low = 0
and high = (funcall len seq)
while (= low high)
do
  (let* ((mid (truncate (+ low high) 2))
 (mid-val (funcall ref seq mid)))
(cond
  ((funcall less mid-val item)
   (setf low (1+ mid)))
  ((funcall same mid-val item)
   (return mid))
  (t (setf high (1- mid)))

Common Lisp integers are mathematical, so the overflow problem
described in your referenced article doesn't exist here.

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


Re: Python less error-prone than Java

2006-06-04 Thread Peter Otten
Kaz Kylheku wrote:

 Would that be a case-insensitive lexicographic comparison, or
 case-insensitive? How do you specify what kind of less-than and equal
 you want to do?

class Key(object):
def __init__(self, value, key):
self.keyval = key(value)
self.key = key
def __lt__(self, other):
return self.keyval  self.key(other)
def __gt__(self, other):
return self.keyval  self.key(other)

items = [Alpha, Beta, Delta, Gamma]
print binarySearch(items, Key(DELTA, str.lower)) # 2

You /can/ teach an old duck new tricks :-)

Peter
 

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


Re: Python less error-prone than Java

2006-06-04 Thread Kaz Kylheku
Ilpo Nyyssönen wrote:
 This is one big thing that makes code
 less error-prone: using existing well made libraries.
 You can find binary search from python standard library too (but actually the 
 API
 in Java is a bit better, see the return values).
 Well, you can say that the binary search is a good example and in real
 code you would use the stuff from the libraries.

The trouble with your point is that Christoph's original posting refers
to an article, which, in turn, at the bottom, refers to a bug database
which shows that the very same defect had been found in Sun's Java
library!

Buggy library code is what prompted that article.

 I'd say it is not
 good example: How often will you write such algorithms? Very rarely.

 Integer overflows generally are not those errors you run into in
 programs.

Except when you feed those programs inputs which are converted to
integers which are then fed as domain values into some operation that
doesn't fit into the range type.

Other than that, you are okay!

Like when would that happen, right?

 The errors happening most often are from my point of view:

 1. null pointer errors
 2. wrong type (class cast in Java, some weird missing attribute in python)
 3. array/list index out of bounds

 First and third ones are the same in about every language.

... other than C and C++, where their equivalents just crash or stomp
over memory, but never mind; who uses those? ;)

 The second
 one is one where the typing can make a difference.

Actually, the first one is also where typing can make a difference.
Instead of this stupid idea of pointers or references having a null
value, you can make a null value which has its own type, and banish
null pointers.

So null pointer errors are transformed into type errors: the special
value NIL was fed into an operation where some other type was expected.
And by means of type polymorphism, an operation can be extended to
handle the case of NIL.

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


Re: Hostmask matching

2006-06-04 Thread John Machin
On 4/06/2006 4:45 PM, Nexu wrote:
 On Sun, 2006-06-04 at 06:26 +, Marc Schoechlin wrote:
 Hi !

 Nexu [EMAIL PROTECTED] schrieb:
 I'm trying to write a def to match a string that is an irc hostmask. eg:
 [EMAIL PROTECTED]
 But using re.search(). I get an error when the string starts with '*'.
 What is the best way to solve this?
 I suppose the problem occurs because you expression is not a valid
 regular expression.

 A correct regular expression should look like this:
 [EMAIL PROTECTED]
 Thx for everyones input.
 
 This solved the problem:
   host = '[EMAIL PROTECTED]'
   mask = '[EMAIL PROTECTED]'
   newmask = re.sub('\*', '.*', re.sub('\?', '.', mask))
 result in that:
   re.search(newmask, host) == True

For a start, you must mean bool(re.search(newmask, host)) == True, 
because re.search() returns a MatchObject or None; neither of those will 
  ever compare equal to True.

Moving right along, you have only one facet of your multi-faceted 
multi-level problem fixed. Consider the following:

| newmask
'[EMAIL PROTECTED]'
| host = '[EMAIL PROTECTED]'
| bool(re.search(newmask, host))
True
| host2 = '[EMAIL PROTECTED]'
| bool(re.search(newmask, host2))
True
| host3 = '[EMAIL PROTECTED]'
| bool(re.search(newmask, host3))
True

You didn't answer either of my questions that would have told me whether 
host2 is a problem; if it is, you need a '$' at the end of newmask.

To fix the host3 problem, you need '\.' instead of '.'.

There is another possible host2-like problem: if you have a hostmask 
that starts with 'one' (i.e. no '*' at the front), what you are doing 
now will give True for incoming starting with 'anyone!' or 
'I_am_the_one!' or whatever. I don't think you want that to happen. Two 
solutions: (1) Put '^' at the start of newmask (2) use re.match() 
instead of re.search().

Another question: should you be doing a case-insensitive match? If so, 
you need re.search/match(newmask, host, re.IGNORECASE)

You may wish to consider looking at the fnmatch module, at three levels:
(1) calling fnmatch.fnmatchcase() may be good enough for your purpose
(2) you can use the undocumented fnmatch.translate(), like this:
 newmask = fnmatch.translate(mask)
and use re.match()
(3) you can find the source code in
YOUR_PYTHON_INSTALLATION_DIRECTORY/Lib/fnmatch.py,
copy the translate function, and rip out the lines that treat '[' as 
special.

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


Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
 Simon Percivall wrote:
 First: It's perfectly simple in Java to create a binary sort that
 sorts all arrays that contain objects; so wrong there.
 My point was that the *same* Java source example, directly converted to 
 Python would *automatically* accept all kinds of arrays.
 
 And the same code converted to SML would automatically work on all
 kinds of arrays and SML is statically typed.  It's a language issue,
 not a typing issue.

Ok, here the point was that Java has *explicit* static typing. SML is 
not a procedural language and uses *implicit* static typing. Therefore 
it shares some of the benefits of dynamically typed languages such as 
Python. However, an SML version of the program would probably still have 
the same bug as the Java version, right?

 No need to make any extra efforts.
 By the way, how would you do it in Java? With 
 function overloading? I would not call that perfectly simple.
 
 Since Java doesn't allow function overloading that clearly can't be
 the way.  J2SE 5.0 allows generic classes and functions that operate
 on generic containers.  There are some gotchas, but it's not drastically
 more complex than the original int-only java code.

Java doesn't allow function overloading? That would be new to me. Or did 
  you just want to nitpick that it should be more properly called 
method overloading in Java? And as you already said, there are some 
gotchas and you would have to wrap int and long etc. I still would not 
call that perfectly simple, as it is in Python.

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


Re: Python less error-prone than Java

2006-06-04 Thread Fredrik Lundh
Kaz Kylheku wrote:

 The trouble with your point is that Christoph's original posting refers
 to an article, which, in turn, at the bottom, refers to a bug database
 which shows that the very same defect had been found in Sun's Java
 library!

and as he points out at the top, it was the article author himself who 
wrote that library code:

 /.../ let me tell you how I discovered the bug: The version
of binary search that I wrote for the JDK contained the same
bug. It was reported to Sun recently when it broke someone's
program, after lying in wait for nine years or so.

/F

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


Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
Kaz Kylheku wrote:
  You can have statically typed languages with inadequate type safety,
  and you can have dynamically typed languages with inadequate type
  safety.

But the point in this example was that the Java program ironically had 
the bug *because* Java handles ints in a type-safe way, while Python 
does not.

  What's better about the Python version? First, it will operate on
  *any* sorted array, no matter which type the values have.
 
  Uh huh! With hard-coded  and = operators, how stupid. What if you
  want to use it on strings?
  Would that be a case-insensitive lexicographic comparison, or
  case-insensitive? How do you specify what kind of less-than and equal
  you want to do?

Where's the problem? The function uses the standard ordering of the 
values you feed to it, i.e. case-insensitive lexicographical order if 
you feed a lis of ordinary tuples of strings. You can also feed objects 
with a different ordering, like case-insensitive.

Anyway, that was completely not the point. The point was that you could 
take that Java program, convert it directly to Python, and have 
automatically eliminated a bug. I did not claim that the resulting 
Python program was automatically a real good and Pythonic one.

  -1 to indicate not found? Why copy Java braindamage induced by an
  antiquated form of static typing? The Java version has to do that

So you would call Python's str.find() method braindamaged as well?

But as I said, that was not the point here anyway.

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


Re: Python + WinCE + serial port

2006-06-04 Thread pcm
Fuzzyman wrote:

 
 pcm wrote:
 Hi,

 Has anyone ever worked on a Python-WinCE-based program that involved
 serial port management ?

 
 Because of the size of the runtime and the fragility of the GUI
 toolkits, there has been little serious development with PythonCE.
 (Little not none - and it's great to have Python available.)
 
 There is no built in support for the serial port in PythonCE (AFAIK).
 Your best bet is using ctypes (for which a PythonCE port has been done)
 and the microsoft API.
 
 Fuzzyman
 http://www.voidspace.org.uk/python/index.shtml
 
 Regards,
 
 Philippe




Thanks, does that mean that I need to write an extension to the WinCE API or
is that built-into the Python package ?

Regards,
Philippe



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


Re: Pyrex list/array

2006-06-04 Thread Jim Lewis
Thanks for your comments.

 You probably didn't expect the Inquisition...

Correct ;-)

 1. What is your speed requirement and how far short of that are you at  the 
 moment?

~10 times faster.

 2. Are you sure there is no Python or third-party module that does what you 
 want?

Yes.

 3. Is your algorithm the best possible?

I think so although of course one can never be certain.

 4. Is your Python implementation of that algorithm the best possible? Have 
 you exposed it to the critical gaze of the speed-freaks in this  newsgroup?

Thanks for the good suggestion but I want to try pyrex first.

 5. Does your architecture support psyco? If so, have you tried that and what 
 were the results?

Already using psyco.

 The question might be better asked on the Pyrex mailing list.

I did not find it - where is it?

 Almost any Python code is also valid Pyrex code. For a start, just compile 
 your function with Pyrex and compare the speed.

It's slower.

 What you do next is going to depend very much on what operations you are 
 performing on  the list and the objects it contains.

Simple list of ints. Comparing sections of lists between each other.

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


Re: Pyrex list/array

2006-06-04 Thread skip

 5. Does your architecture support psyco? If so, have you tried that
and what were the results?

Jim Already using psyco.

Is it substantially faster with psyco than without?  If psyco is performing
its magic on the critical section of code already, you are going to lose
that when switching to Pyrex.

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


Re: Pyrex list/array

2006-06-04 Thread Jim Lewis
 Is it substantially faster with psyco than without?  If psyco is performing
 its magic on the critical section of code already, you are going to lose
 that when switching to Pyrex.

Yes but from what I read Pyrex can be a lot faster than psyco under the
right circumstances.

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


Re: Pyrex list/array

2006-06-04 Thread skip

 Is it substantially faster with psyco than without?  If psyco is
 performing its magic on the critical section of code already, you are
 going to lose that when switching to Pyrex.

Jim Yes but from what I read Pyrex can be a lot faster than psyco under
Jim the right circumstances.

I'm sure that's true.  That also means under the wrong circumstances it
might not. ;-)  Can you post the code that's running too slowly?

Also, note that psyco learned some new tricks at the recent NeedForSpeed
sprint. You might want to check out the latest version from Subversion and
give it a whirl.

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


Re: if not CGI:

2006-06-04 Thread Max
Bruno Desthuilliers wrote:
 Max a écrit :
(snip)
 
 RoR is not bad, but really over-hyped. There's no shortage of at least 
 as good solutions in Python. You may want to look at Django, Turbogears, 
 Pylons, web.py etc. for fullstack MVC frameworks.

That's what I thought!

(snip)
 
 So the problem is not  are there good solutions, but which one to 
 choose !-) The answer of course depends on what you want and what you 
 like, but taking a few days to play with Turbogears, Django and Pylons 
 might be a good idea.

Good stuff. I'm downloading them now.


Thanks.

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


in python , could I accomplish the purpose that a=Console.read() used in C?

2006-06-04 Thread python
in python , could I accomplish the purpose that a=Console.read() used
in C?
when program is running, I wanna add a statement like
a=Console.read() in C language,it will wait for user's input, after
user's typing a character , and click enter key, the program will go
on running.

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


HOST - dreamhost.com / Liberality (Hosting, Basic Requirement)

2006-06-04 Thread Ilias Lazaridis
crossposted to 5 groups, which are affected by this case.

followup not applicable.

-

I am currently selecting a Hosting Provider / Project Host...

http://case.lazaridis.com/multi/wiki/Host

For this larger scale project...

http://case.lazaridis.com/multi

-

An incident within usenet has reminded me to include a very Basic
Requirement, which is Terms of Service / Liberality.

-

The incident:

http://xahlee.org/Periodic_dosage_dir/t2/harassment.html

It _seems_ that Mr. Xah Les's account was terminated by dreamhost.com
because of

a) the inability of several people to detect the interconnections within 
writings which lead to perfectly valid cross-posts within the usenet.

b) the non-liberal and essentially non-professional way of how 
dreamhost.com deals with abuse complaints.

-

The accusations of dreamhost.com are simply wrong.

The behaviour of dreamhost.com looks like a case of selective ruling, 
whilst using a right defined within the Terms of Service to terminate 
accounts essentially at free will.

Can someone trust his business or even his private activities to a
hosting company, which cancels accounts in such a way?

I do not:

http://case.lazaridis.com/multi/wiki/DreamhostAudit

But possibly I am wrong, and all this is just a missunderstanding.

-

To dreamhost.com:

You should install an autoresponder to your abuse email, which reminds
people that it is

* nearly inpossible to rate the content posted to usenet
* neally inpossible to detect validity of cross-posts
   especially within complex analytical/philosophical writings
* other important facts

People can then decide if they still wish to send the abuse complain
(e.g. can follow a link within the autoresponder).

You should additionally make a clear statement, that you do _not_ have
the right to cancel acounts _without_ any reason, and that you do _not_
intervene into a persons right to speek within the usenet, without a
clear and undoubtable proof of abuse (e.g. court decision, or at least 
verfication of independend entities or mediators).

Additionally, it would be gentle if your company would make a _public_ 
statement subjecting this case, thus any interested party can verify the 
validity of the statements.

-

To Mr. Xah Lee:

You should change to a more liberal services provider, one which
plays in the Major League and which respects free speech. Such a
provider would just reject such ridiculous abuse complaints.

If, for any reason, you are not able to switch to another hosting
provider, please let me know.

I will see what I can do for you to keep your free speech up.

Additionally, I would like to suggest you to not invest too much time 
into all this. Better use this time to find people and to react in an 
organized manner.

-

To the complaining people:

To which 'species' do you belong?

http://lazaridis.com/core/eval/species.html

Setting up an thread filter:

http://lazaridis.com/core/eval/filter.html

I have seldom seen a more ridiculous argumentation-line than then 
spam/abuse one.

-

To anyone:

Any form of censorship and suppression of freedom of expression should 
be kept out of from open-source projects and from usenet.

It is the within the responsibility of every entity (including 
commercial companies) to act against it.

http://dev.lazaridis.com/base/wiki/LiberalProjectDefinition

-
-
-

.

-- 
http://lazaridis.com

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


Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-04 Thread Kent Johnson
Laurent Pointal wrote:
 And I'll maintain a fixed URL at
 
 http://laurent.pointal.org/python/pqrc/

Broken at the moment.

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


Re: Pyrex list/array

2006-06-04 Thread John Machin
On 4/06/2006 7:59 PM, Jim Lewis wrote:
 Thanks for your comments.
 
 You probably didn't expect the Inquisition...
 
 Correct ;-)

Nobody does :-)

 
 The question might be better asked on the Pyrex mailing list.
 
 I did not find it - where is it?

Evidently somewhere near the Hall of the Mountain King. A reference to 
it is cunningly concealed in the last place one would think of finding 
it: under the heading Mailing List on the Pyrex home page :-) Here: 
http://lists.copyleft.no/mailman/listinfo/pyrex ... get in quick before 
the pirate moves it again.

 
 Almost any Python code is also valid Pyrex code. For a start, just compile 
 your function with Pyrex and compare the speed.
 
 It's slower.
 
 What you do next is going to depend very much on what operations you are 
 performing on  the list and the objects it contains.
 
 Simple list of ints. Comparing sections of lists between each other.

Do you mean alist[x:x+n] == alist[y:y+n] ?
If so, that's creating two new lists each of size n, and then comparing 
those two lists. I doubt that psyco would recognize that it didn't need 
to copy the two slices. The first step might be to write functions to 
compare without copying, e.g.:

def py_slices_cmp_eq(py_list, start1, start2, size):
 Return 1 if py_list[start1+size] == py_list[start2+size]
 else 0
 offset = start2 - start1
 for i in xrange(start1, start1+size):
 if py_list[i] != py_list[i+offset]:
 return 0
 return 1

See what psyco makes of that.
Then turn that into a cdef function for Pyrex.

If that's still not fast enough, then you might be in for some harder work:

Allocate memory for a C array, unpack your list into it, write 
comparison functions c_slices_cmp_* that operate on your array of ints.
There should be no Python stuff in there, only C constructs. You can 
even use memcmp() for the cmp_eq function.

Which brings us back to your original question Do I need to convert to 
array or something so pyrex can generate tight code? ...
1. Some of the above may help you to determine whether you need to.
2. Without any knowledge of the size of your list or what you are doing, 
we can't help you much more on whether you need to.
3. AFAICT, Pyrex doesn't do much in the way of optimisation, leaving 
that up to the C compiler. Generating tight code would depend more on 
you replacing appropriately-chosen Pythonisms with C-isms.

As for *how* to make your C array, something like this:

cdef extern from Python.h:
void   PyMem_Free(void *p)
void*  PyMem_Malloc(int n) except NULL
# untested -- compiles OK :-)
cdef int * int_array_from_list(object ilist):
 cdef int n, i
 cdef int * arrayp
 n = len(ilist)
 arrayp = int *PyMem_Malloc(n * sizeof(int))
 for i from 0 = i  n:
 arrayp[i] = ilist[i]
 return arrayp[0]

Hoping some of this helps,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging

2006-06-04 Thread Vinay Sajip
Hello Baurzhan,

 Consider the following scenario: root is CRITICAL, l01 is DEBUG, a debug
 message is logged on l01. l01 decides that the message should be
 printed, and _both_ root and l01 print it. Now, it is good that the
 message is propagated to root, but why doesn't root decide for itself
 whether to print it or not?

It's not propagated to the root logger (or to ancestor loggers in
general) - just to the handlers associated with ancestor loggers.

 For instance, I log root to syslog and have only critical messages
 there. I log l01 to console to debug. I want that my message to l01 is
 not printed by root since its level is CRITICAL. This is why I want that
 each logger re-evaluates the message level for itself. Could you perhaps
 give a useful example why one could want loggers to decide once?

You can set levels on handlers as well as loggers. So if you add a
syslog handler to the root and set its level to CRITICAL, only CRITICAL
messages are sent to syslog.

 And another thing I couldn't find how to do: I want to have several
 debug levels. I can log messages without problems, but numeric values in
 the configuration file cause error messages during
 logging.config.fileConfig. Can I specify numeric values in the config
 file?

You should use addLevelName to add custom levels. You can do e.g.

logging.MYCUSTOMLEVEL  = 25
logging.addLevelName(logging.MYCUSTOMLEVEL, MYCUSTOMLEVEL)

and then reference MYCUSTOMLEVEL in the config file.

Regards,

Vinay

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


Re: Python less error-prone than Java

2006-06-04 Thread nikie
Let's look at two different examples: Consider the following C# code:

static decimal test() {
   decimal x = 10001;
   x /= 100;
   x -= 100;
   return x;
}

It returns 0.01, as you would expect it. Now, consider the python
equivalent:

def test():
x = 10001
x /= 100
x -= 100
return x

It returns 0. Clearly an error!
Even if you used from __future__ import division, it would actually
return 0.015116, which, depending on the context, may
still be an intolerable error.

Morale: the problem isn't whether the the types are chosen at
compile-time or at runtime, it's simply _what_ type is chosen, and
whether it's appropriate or not.

I can even think of an example where C's (and Java's) bounded ints are
the right choice, while Python's arbitraty-precision math isn't: Assume
you get two 32-bit integers containing two time values (or values from
an incremental encoder, or counter values). How do you find out how
many timer ticks (or increments, or counts) have occured between those
two values, and which one was earlier? In C, you can just write:

   long Distance(long t1, long t0) { return t1-t0; }

And all the wraparound cases will be handled correctly (assuming there
have been less than 2^31 timer ticks between these two time values).
Distance will return a positive value if t1 was measured after t0, a
negative value otherwise, even if there's been a wraparound in between.
Try the same in Python and tell me which version is simpler!

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


Pyrex newbie question

2006-06-04 Thread Philip Smith
Just starting to use pyrex on windows.

Using pyrex version 0.9.3.1.win32

Using Activestate Python 2.4.3.12

Using Mingw compiler

When I try to run the pyrex demo it fails with a message:

undefined reference to '_imp__Py_NoneStruct' 

Anyone know why? 


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


Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-04 Thread gene tani

Laurent Pointal wrote:
 [for those who dont read clp.announce]

 The Python Quick Reference Card (PQRC) aims to provide a printable quick
 reference documentation for the Python language and some of its main
 standard libraries (currently for Python 2.4).

 PQRC tries to group informations about same/similar subject to avoid
 searching in multiple places.


very nice.  There's a few others I've collected over the years.  I
havent found an OS X dashboard widget yet tho:

http://rgruet.free.fr/#QuickRef

http://infohost.nmt.edu/tcc/help/pubs/python22.pdf
http://www.onlamp.com/python/excerpt/PythonPocketRef/examples/python.pdf
http://diveintopython.org/appendix/abstracts.html

http://www.yukoncollege.yk.ca/~ttopper/COMP118/rCheatSheet.html
http://www.schacherer.de/frank/tech/tools/python.html

http://www.experimentierkasten.de/python_php.pdf
http://ferg.org/pyref/index.html

http://projects.edgewall.com/python-sidebar/
http://jotsite.com/blogArchives/2006_03.php#000383

http://www.drweb.de/weblog/weblog/?p=571
http://www.petefreitag.com/item/455.cfm

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


Re: Pyrex list/array

2006-06-04 Thread Jim Lewis
 cunningly concealed in the last place one would think of finding it: under 
 the heading Mailing List on the Pyrex home page :-)

Hmmm - maybe I should try the scroll bar occassionally ;-)

 Do you mean alist[x:x+n] == alist[y:y+n] ?

OK, probably you an Skip are right - let's see if I missed something at
the Python level.

There are essentially two differences from your snip above. I am trying
to compute n and there are multiple (under 10) lists. Size of lists are
typically under 100 ints.

 ...See what psyco makes of that.

I'm doing a similar straightforward loop approach but it's too slow.

Jim

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


Re: PUDGE - Project Status, Alternative Solutions

2006-06-04 Thread Ilias Lazaridis
Ilias Lazaridis wrote:
 What is going on with the pudge project?

Any chance to get an comment on this?

 Mr. Patrik O'Brien (Orbtech LLC) had told me that there is no similar 
 tool available within the python domain, thus I have invested some 
 effort to create a Website template, and to enable pudge to generate 
 colored code:
 
 http://audit.lazaridis.com/schevo/wiki/SchevoWebsiteReview
 
 I like to reuse the results for personal projects, but I am wondering 
 that the pudge email-list is death (since the server update) - and that 
 no one of the project reacts to personal and public postings.
 
 Additionally, the schevo project removes the pudge stuff, mscott, the 
 developer which has introduced pudge removes it again (although this was 
 done with several other tools in the past, too):
 
 http://schevo.org/trac/changeset/2127
 
 -
 
 Is there a similar tool available, with which I can generate python 
 documentation / websites or both based on templates and reST?
 
 Or an overview of such tools?
 
 I mean such an organized tool is essential for developmente with python.
 
 .
 


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


Re: Python less error-prone than Java

2006-06-04 Thread D H
Christoph Zwerschke wrote:
 
 See the following web page if you dont find it ;-)
 http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
  

The point of that is that it did fail.  It threw an 
ArrayIndexOutOfBoundsException exception.  But it was just luck that 
happened.  Unfortunately I don't think java and C# have integer overflow 
checking turned on by default.

Take this longArithmetic benchmark here:
http://www.cowell-shah.com/research/benchmark/code
and a story about it here:
http://www.osnews.com/story.php?news_id=5602page=3

The java and C# versions are fast (15 seconds for me), BUT, they
give the incorrect result because of an overflow error.
The python version gives the correct result because it transparently
changes the underlying types to handle the larger numbers, BUT this
causes it to run over 20X slower than Java or C#.  It takes 10 minutes
to complete in python, not 15 seconds.  With psyco, it takes 5 minutes.

So to say the story you pointed out shows that python is superior
is a matter of perspective.  Yes, python gave the correct result
by silently changing the underlying types to longs, and that is
what I would expect of a scripting language.  But the price is
speed.  In both these cases, I would rather be made aware of the
error in the code and fix it so I didn't have to suffer slowdowns.

That is why in boo ( http://boo.codehaus.org/ ) luckily overflow 
checking is enabled by default, and it throws a overflow exception at
runtime to tell you something is wrong with your code.  When you
then fix for that, you get the same 15 second time just like java
and C#.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HOST - dreamhost.com / Liberality (Hosting, Basic Requirement)

2006-06-04 Thread Joachim Durchholz
Ilias Lazaridis schrieb:
 crossposted to 5 groups, which are affected by this case.
 
 followup not applicable.

Actually, in this case, yes.

 It _seems_ that Mr. Xah Les's account was terminated by dreamhost.com
 because of
 
 a) the inability of several people to detect the interconnections within 
 writings which lead to perfectly valid cross-posts within the usenet.

Actually, his posts are mostly off-topic.

 b) the non-liberal and essentially non-professional way of how 
 dreamhost.com deals with abuse complaints.

Unless you give some concrete facts, this is simply slander.
URLs don't count.

 To dreamhost.com:
 
 You should install an autoresponder to your abuse email, which reminds
 people that it is
 
 * nearly inpossible to rate the content posted to usenet
 * neally inpossible to detect validity of cross-posts
   especially within complex analytical/philosophical writings
 * other important facts

Why are you wasting our mental bandwidth with that?
Besides, it's utter nonsense. There's an infinity of invalid reasons, so 
you can't rule them out with an autoresponder.

 People can then decide if they still wish to send the abuse complain
 (e.g. can follow a link within the autoresponder).

Nope. Finding out the provider is enough of a barrier. Additional 
barriers are not really necessary.
Xah Lee has been irritating people for months.

I do share your concerns. Complaint handling often is unprofessional. 
However, in Xah Lee's case, he's indeed been irritating too many people 
for a too long time that *some* sanction is in fact appropriate.
I routinely kill his threads, but I'm reading a specific newsgroup for a 
purpose, and Xah Lee requires me to kill his. He's essentially doing 
semantic spam - analytical and philosophical writings may be well and 
fine, but they aren't appropriate on the newsgroups that I frequent (or 
only in very specific ways that Xah Lee doesn't address).

 To anyone:
 
 Any form of censorship and suppression of freedom of expression should 
 be kept out of from open-source projects and from usenet.
 
 It is the within the responsibility of every entity (including 
 commercial companies) to act against it.
 
 http://dev.lazaridis.com/base/wiki/LiberalProjectDefinition

There are many important goals. Free speech is indeed very high on the 
list. On the other hand, I'm pretty sure that Xah Lee will find another 
provider.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: linking errors with debug build of Python2.4.3

2006-06-04 Thread Martin Wiechert
You were right, leaving out --with-pydebug did the trick.

Thanks, Martin


On Sunday 28 May 2006 03:53, [EMAIL PROTECTED] wrote:
 Martin Wiechert wrote:
  Hi list,
 
  I've created a fresh build of Python 2.4.3 using the following
  configuration
 
  $ ./configure --with-pydebug --prefix=/usr/local/debug --enable-shared
  --with-fpectl --with-signal-module
 
  What did I do wrong?

 Try with just:  ./configure --with-pydebug --prefix=/usr/local/debug

 I think the problem is --enable-shared.  I'm not sure what you are
 doing, but you probably don't need the other options.  The signal
 module should always be built, I've never even seen the
 --with-signal-module option. :-)

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


Re: create a text file

2006-06-04 Thread Stan Cook
Fredrik Lundh wrote:
 Stan Cook wrote:
 
 I'm writing a script to list all of my music files' id3 tags to a 
 comma delimited file.  The only part I'm missing seems like it should 
 be the simplest.  I haven't used Python for the last couple of years.  
 My question is this:

 When I use os.open(file_variable,w), I get an error 
 message,TypeError: an integer is required.  Has something 
 changed?  Did I miss something???
 
 the function is called open, not os.open.
 
 there's an open function in the os module, but that's doing something 
 slightly different (see the library reference documentation for details 
 if you're curious).
 
 /F
 
Thanks, I found it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in python , could I accomplish the purpose that a=Console.read() used in C?

2006-06-04 Thread Dennis Benzinger
python wrote:
 in python , could I accomplish the purpose that a=Console.read() used
 in C?
 when program is running, I wanna add a statement like
 a=Console.read() in C language,it will wait for user's input, after
 user's typing a character , and click enter key, the program will go
 on running.
 


Use raw_input() http://docs.python.org/lib/built-in-funcs.html:

age = raw_input(Your age: )
print age


Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: carshing the interpreter in two lines

2006-06-04 Thread Mel Wilson
sam wrote:
 Mel:
 Wow that book brings back memories. I scanned my copy to review the
 subject covered, and came to the conclusion that mind reading
 algorithms are the answer.
 
I gathered from somewhere (but not the index to Andrew 
Hodges' biography) that Turing was toying with an idea for 
oracles, where a computation would be allowed to call out 
sometimes to a non-computational process to obtain some 
required result.  Used maybe by  interactive debugging programs.

 Cheers,Mel.

 Mel Wilson wrote:
[ ... ]
Douglas Hofstadter's _Goedel, Escher, Bach: an Eternal Golden Braid_.
[ ... ]
 Contracrostipunctus.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to print newline in xml?

2006-06-04 Thread uche . ogbuji
[EMAIL PROTECTED] wrote:
 I use Python/XML packages are xml.dom.minidom and xml.dom.ext (second
 just for PrettyPrint)

You don't need xml.dom.ext for prettyprint.  You can use
doc.toprettyxml()

I gather you want to tweak the prettyprinter to not add the newline
before the comment.  The only way to do this is to write your own
printing logic, which is really not that hard, if you just start by
copying the code from .writexml (used by .toprettyxml).

But there's an even easier (if slower) way: pretty print the document,
then parse it in again, remove the text node between the element in
question and the following comment, and then use .writexml() to
serialize it it again.

A few general notes:

* You cannot set the order of attributes in most XML tools, whether
Python or not.  This is unfortunate for people who would like to
preserve such details for usability reasons, but that's just the way
XML is.  The closest you can get is by using canonicalization [1],
which is available in PyXML as xml.dom.ext.c14n.  It just so happens
that canonical XML leaves the attributes in the order you want.  You
won't always be so lucky.

* You can always create text nodes by using doc.createTextNode.

* You can always remove text nodes (or any other kind) by using
.removeChild

* It's much easier to navigate if you use XPath.  PyXML has an
xml.xpath module you can use.

Good luck.

[1] http://www-128.ibm.com/developerworks/xml/library/x-c14n/

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Mel Wilson
Terry Reedy wrote:
 James J. Besemer [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 I propose that we extend the semantics of print such that if the object 
 to
 be printed is a generator then print would iterate over the resulting
 sequence of sub-objects and recursively print each of the items in order.
 Iterating over an iterator is usually destructive.  So you would be 
 printing what it was but no longer is.  This is why iterators are printed 
 differently from sequences.

I guess the motivation is the case of people who would set 
up an iterator specifically to print from it.

print-as-debug-aid would get badly broken by the proposal, 
and I'd find that painful.

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


Re: ideas for programs?

2006-06-04 Thread Florian Diesch
Brandon McGinty [EMAIL PROTECTED] wrote:


 I've been learning python for the past couple of months and writing
 misc scripts here and there, along with some web apps.
 I'm wondering if anyone has ideas of programs I might try my hand at making?

Something I wanted a few days ago: I have a graph described in the .dot
language (used by GraphViz http://www.graphviz.org) and want you get
things like shortest path between two nodes, all paths between two
nodes, all cycles and whatever graph theory knows as interesting. 


   Florian
-- 
http://www.florian-diesch.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installation Problem

2006-06-04 Thread Fredrik Lundh
Marshall Dudley wrote:
 I am trying to install python, but am having problems.  I did what the
 README file said, and it created an executible code in the current
 directory as it said it would when I typed make.

make doesn't install the interpreter by itself; you're supposed to use 
make install (or make altinstall) to do that.

just copying the interpreter binary around won't give you a complete 
install.

  It seemed to say to copy the executable over to the /usr/local
  directory, which I did.

the README says:

   To start building right away (on UNIX): type ./configure in the
   current directory and when it finishes, type make.  This creates an
   executable ./python; to install in /usr/local, first do su root
   and then make install.

the detailed installation section says:

   To install the Python binary, library modules, shared library modules
   (see below), include files, configuration files, and the manual page,
   just type

 make install

/.../

/F

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


Re: mutable member, bug or ...

2006-06-04 Thread Fredrik Lundh
Sambo wrote:

 By accident I assigned int to a class member 'count' which was
  initialized to (empty) string and had no error till I tried to
  use it as string, obviously. Why was there no error on assignment
  (near the end ).

Python uses dynamic typing, which means that objects have types, but 
variables don't.  A variable is just a name.

I suggest reading up on variables, namespaces and classes/instances in 
your favourite tutorial.  Python's not C++, and you won't get very far 
by pretending that it is.

/F

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


Re: deleting texts between patterns

2006-06-04 Thread Baoqiu Cui
John Machin [EMAIL PROTECTED] writes:

 Uh-oh.

 Try this:

 pat = re.compile('(?=abc\n).*?(?=xyz\n)', re.DOTALL)
 re.sub(pat, '', linestr)
 'blahfubarabc\nxyz\nxyzzy'

This regexp still has a problem.  It may remove the lines between two
lines like 'aaabc' and 'xxxyz' (and also removes the first two 'x's in
'xxxyz').

The following regexp works better:

  pattern = re.compile('(?=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE)

 lines = '''line1
... abc
... line2
... xyz
... line3
... aaabc
... line4
... xxxyz
... line5'''
 pattern = re.compile('(?=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE)
 print pattern.sub('', lines)
line1
abc
xyz
line3
aaabc
line4
xxxyz
line5
 

- Baoqiu

-- 
Baoqiu Cui cbaoqiu at yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: carshing the interpreter in two lines

2006-06-04 Thread Aahz
In article [EMAIL PROTECTED],
gangesmaster [EMAIL PROTECTED] wrote:

the following (random) code crashes my interpreter
(python 2.4.3/winxp):

from types import CodeType as code
exec code(0, 5, 8, 0, hello moshe, (), (), (), , , 0, )

i would expect the interpreter to do some verifying, at least for
sanity (valid opcodes, correct stack size, etc.) before executing
artbitrary code... after all, it was the BDFL who said I'm not
saying it's uncrashable. I'm saying that if you crash it, it's a
bug unless proven harebrained.

IIRC, this has been discussed before and deemed harebrained.  Check SF to
see whether this specific case has been submitted previously and submit
it if not.  Then post to python-dev if it's a new bug and ask for a
ruling on whether it's harebrained.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

I saw `cout' being shifted Hello world times to the left and stopped
right there.  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installation Problem

2006-06-04 Thread Marshall Dudley
Sorry, this is a FreeBSD system 4.8-RELEASE

I found another set of documents that say to use the following to
install::

python setup.py install

but after running it, I still have the same problem.

Marshall

Marshall Dudley wrote:

 I am trying to install python, but am having problems.  I did what the
 README file said, and it created an executible code in the current
 directory as it said it would when I typed make. It seemed to say to
 copy the executable over to the /usr/local directory, which I did.

 If I type ./python in the directory I did the make in I get:

 execonn# ./python
 Python 2.4.3 (#1, May 31 2006, 07:50:04)
 [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
 Type help, copyright, credits or license for more information.
 

 Which is I believe correct.

 But if I type /usr/local/python I get:

 Python 2.4.3 (#1, May 31 2006, 07:50:04)
 [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
 Type help, copyright, credits or license for more information.
 
 execonn# /usr/local/python
 Could not find platform independent libraries prefix
 Could not find platform dependent libraries exec_prefix
 Consider setting $PYTHONHOME to prefix[:exec_prefix]
 'import site' failed; use -v for traceback
 Python 2.4.3 (#1, May 31 2006, 07:50:04)
 [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
 Type help, copyright, credits or license for more information.
 

 So nothing that tries to use it works.

 Any assistance would be appreciated.

 Thanks,

 Marshall

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


Re: Installation Problem

2006-06-04 Thread Marshall Dudley
Fredrik Lundh wrote:

 Marshall Dudley wrote:
  I am trying to install python, but am having problems.  I did what the
  README file said, and it created an executible code in the current
  directory as it said it would when I typed make.

 make doesn't install the interpreter by itself; you're supposed to use
 make install (or make altinstall) to do that.

 just copying the interpreter binary around won't give you a complete
 install.

   It seemed to say to copy the executable over to the /usr/local
   directory, which I did.

 the README says:

To start building right away (on UNIX): type ./configure in the
current directory and when it finishes, type make.  This creates an
executable ./python; to install in /usr/local, first do su root
and then make install.

Yes, that is what I did. Since I ended up with no executable in /usr/local,
or /usr/local/bin and it said  This creates an
   executable ./python (which it did); to install in /usr/local I copied
the one it created over to /usr/local, then later /usr/local/bin



 the detailed installation section says:

To install the Python binary, library modules, shared library modules
(see below), include files, configuration files, and the manual page,
just type

  make install

 /.../

 /F

Yes, I typed make install.  But nothing gets put into /usr/local or
/usr/local/bin without me copying it over.  And if I run python it in the
directory I unpacked it in, it works, but if I run the copy in /usr/local or
/usr/local/bin it does not.

I also tried the instuctions on their web site:

python setup.py install

But get the same result, but it copies and puts the following 3 files in the
/usr/local/bin dir.

-rwxr-xr-x  1 root  wheel   96 May 31 07:50 idle
-rwxr-xr-x  1 root  wheel   81 May 31 07:50 pydoc
-rwxr-xr-x  1 root  wheel18017 May 31 07:50 smtpd.py

Marshall

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


Re: grouping a flat list of number by range

2006-06-04 Thread joh12005
Hello

 ... _, first_n = group[0]

what is the meaning of the underscore _ ? is it a special var ? or
should it be readed as a way of unpacking a tuple in a non useful var ?
like 

lost, first_n = group[0]

best regards.

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


Re: Installation Problem

2006-06-04 Thread Warren Block
Marshall Dudley [EMAIL PROTECTED] wrote:
 Sorry, this is a FreeBSD system 4.8-RELEASE

 I found another set of documents that say to use the following to
 install::

 python setup.py install

 but after running it, I still have the same problem.

[top-posting trimmed, please don't do that]

Doesn't the port work for 4.8?  It does work on FreeBSD 4.11, but there 
may have been changes to the ports system since 4.8.  (You should 
consider updating to 4.11.)

There are several patch files in the FreeBSD port, including
one to setup.py.

The easiest way is to cvsup your ports tree and then

cd /usr/ports/lang/python
make
make install
make clean

-- 
Warren Block * Rapid City, South Dakota * USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: grouping a flat list of number by range

2006-06-04 Thread K.S.Sreeram
Yup! '_' is just used as a dummy. Its a pretty common idiom. There's
nothing special about that variable.

[EMAIL PROTECTED] wrote:
 Hello
 
 ... _, first_n = group[0]
 
 what is the meaning of the underscore _ ? is it a special var ? or
 should it be readed as a way of unpacking a tuple in a non useful var ?
 like 
 
 lost, first_n = group[0]
 
 best regards.
 




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-04 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
 ... _, first_n = group[0]
 
 what is the meaning of the underscore _ ? is it a special var ? or
 should it be readed as a way of unpacking a tuple in a non useful var ?
 like 
 
 lost, first_n = group[0]

Yep, it's just another name.  lost would have worked just as well. 
It's pretty typical around here to see _ used when a tuple is unpacked 
but some of the values aren't used.  So if you see something like::

 for _, dirs, _ in os.walk(top):
 ...

it just means that the ... code is only going to use dirs (not the 
root path or files that are also available from the os.walk() iterator).

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


Python netstring module

2006-06-04 Thread Will McGugan
Hi folks,

I have just posted a python 'netstring' module on my blog. Comments welcome!

http://www.willmcgugan.com/2006/06/04/python-netstring-module/

Regards,

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


Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
nikie wrote:
  Let's look at two different examples: Consider the following C# code:
 
  static decimal test() {
 decimal x = 10001;
 x /= 100;
 x -= 100;
 return x;
 
  It returns 0.01, as you would expect it.

Yes, I would expect that because I have defined x as decimal, not int.

  Now, consider the python equivalent:
 
  def test():
  x = 10001
  x /= 100
  x -= 100
  return x

No, that's not the Python equivalent. The equivalent of the line

decimal x = 10001

in Python would be

x = 10001.0

or even:

from decimal import Decimal
x = Decimal(10001)

Setting x = 10001 would be equivalent to the C# code

int x = 10001

  It returns 0. Clearly an error!

That's not clearly an error. If you set int x = 10001 in C#, then you 
also get a 0. By setting x to be an integer, you are implicitely 
telling Python that you are not interested in fractions, and Python does 
what you want. Granted, this is arguable and will be changed in the 
__future__, but I would not call that an error.

By the way, the equivalent Python code to your C# program gives on my 
machine the very same result:
  x = 10001.0; x /= 100; x -= 100; print x
0.01

  Even if you used from __future__ import division, it would actually
  return 0.015116, which, depending on the context, may
  still be an intolerable error.

With from __future__ import division, I also get 0.01 printed. Anyway, 
if there are small discrepancies then these have nothing to do with 
Python but rather with the underlying floating-point hardware and C 
library, the way how you print the value and the fact that 0.01 can 
principally not be stored exactly as a float (nor as a C# decimal), only 
as a Python Decimal.

  I can even think of an example where C's (and Java's) bounded ints are
  the right choice, while Python's arbitraty-precision math isn't:
  Assume you get two 32-bit integers containing two time values (or
  values from an incremental encoder, or counter values). How do you
  find out how many timer ticks (or increments, or counts) have occured
  between those two values, and which one was earlier? In C, you can
  just write:
 
 long Distance(long t1, long t0) { return t1-t0; }
 
  And all the wraparound cases will be handled correctly (assuming there
  have been less than 2^31 timer ticks between these two time values).
  Distance will return a positive value if t1 was measured after t0, a
  negative value otherwise, even if there's been a wraparound in
  between. Try the same in Python and tell me which version is simpler!

First of all, the whole problem only arises because you are using a 
statically typed counter ;-) And it only is easy in C when your counter 
has 32 bits. But what about a 24 bit counter?

Anyway, in Python, you would first define:

def wrap(x, at=131):
 if x  -at:
 x += at*2
 elif x = at:
 x -= at*2
 return x

Then, the Python program would be as simple:

Distance = lambda t1,t0: wrap(t1-t0)

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


Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-04 Thread Laurent Pointal
Kent Johnson wrote:

 Laurent Pointal wrote:
 And I'll maintain a fixed URL at
 
 http://laurent.pointal.org/python/pqrc/
 
 Broken at the moment.

Its back.

Its at my home ADSL, normally online, but my provider reset the connexion
each 24h and its home maintained... the page contains only a link to the
other URL which has the data and is beyond a larger bandwidth server.

A+

Laurent.

 
 Kent

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


re beginner

2006-06-04 Thread SuperHik
hi all,

I'm trying to understand regex for the first time, and it would be very 
helpful to get an example. I have an old(er) script with the following 
task - takes a string I copy-pasted and wich always has the same format:

  print stuff
Yellow hat  2   Blue shirt  1
White socks 4   Green pants 1
Blue bag4   Nice perfume3
Wrist watch 7   Mobile phone4
Wireless cord!  2   Building tools  3
One for the money   7   Two for the show4

  stuff
'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue 
bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless 
cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'

I want to put items from stuff into a dict like this:
  print mydict
{'Wireless cord!': 2, 'Green pants': 1, 'Blue shirt': 1, 'White socks': 
4, 'Mobile phone': 4, 'Two for the show': 4, 'One for the money': 7, 
'Blue bag': 4, 'Wrist watch': 7, 'Nice perfume': 3, 'Yellow hat': 2, 
'Building tools': 3}

Here's how I did it:
  def putindict(items):
... items = items.replace('\n', '\t')
... items = items.split('\t')
... d = {}
... for x in xrange( len(items) ):
... if not items[x].isdigit(): d[items[x]] = int(items[x+1])
... return d
 
  mydict = putindict(stuff)


I was wondering is there a better way to do it using re module?
perheps even avoiding this for loop?

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


how not to run out of memory in cursor.execute

2006-06-04 Thread [EMAIL PROTECTED]
I am using cx_Oracle and MySQLdb to pull a lot of data from some tables
and I find that the cursor.execute method uses a lot of memory that
never gets garbage collected. Using fetchmany instead of fetchall does
not seem to make any difference, since it's the execute that uses
memory. Breaking the query down to build lots of small tables doesn't
help, since execute doesn't give its memory back, after reading enough
small tables execute returns a memory error. What is the trick to get
memory back from execute in cx_Oracle and MySQLdb?

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


Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Terry Reedy

Mel Wilson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 I guess the motivation is the case of people who would set
 up an iterator specifically to print from it.

for i in gen: print i,
print

is rather trivial and gives one the option to control formatting however.

tjr



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


Re: Python less error-prone than Java

2006-06-04 Thread nikie
Christoph Zwerschke wrote:

 nikie wrote:
   Let's look at two different examples: Consider the following C# code:
  
   static decimal test() {
  decimal x = 10001;
  x /= 100;
  x -= 100;
  return x;
  
   It returns 0.01, as you would expect it.

 Yes, I would expect that because I have defined x as decimal, not int.

   Now, consider the python equivalent:
  
   def test():
   x = 10001
   x /= 100
   x -= 100
   return x

 No, that's not the Python equivalent. The equivalent of the line

 decimal x = 10001

 in Python would be

 x = 10001.0

 or even:

 from decimal import Decimal
 x = Decimal(10001)

Hm, then I probably didn't get your original point: I thought your
argument was that a dynamically typed language was safer because it
would choose the right type (in your example, an arbitrary-pecision
integer) automatically. As you can see from the above sample, it
sometimes picks the wrong type, too. Now you tell me that this
doesn't count, because I should have told Python what type to use. But
shouldn't that apply to the Java binary-search example, too? I mean,
you could have told Java to used a 64-bit or arbitrary-length integer
type instead of a 32-bit integer (which would actually be equivalent to
the Python code), so it would do the same thing as the Python binary
search implementation.

 ...
 By the way, the equivalent Python code to your C# program gives on my
 machine the very same result:
   x = 10001.0; x /= 100; x -= 100; print x
 0.01

Try entering x in the interpreter, and read up about the difference
between str() and repr().


   Even if you used from __future__ import division, it would actually
   return 0.015116, which, depending on the context, may
   still be an intolerable error.

 With from __future__ import division, I also get 0.01 printed. Anyway,
 if there are small discrepancies then these have nothing to do with
 Python but rather with the underlying floating-point hardware and C
 library, the way how you print the value and the fact that 0.01 can
 principally not be stored exactly as a float (nor as a C# decimal), only
 as a Python Decimal.

The is OT, but what makes you think a C# decimal can't store 0.01?

   I can even think of an example where C's (and Java's) bounded ints are
   the right choice, while Python's arbitraty-precision math isn't:
   Assume you get two 32-bit integers containing two time values (or
   values from an incremental encoder, or counter values). How do you
   find out how many timer ticks (or increments, or counts) have occured
   between those two values, and which one was earlier? In C, you can
   just write:
  
  long Distance(long t1, long t0) { return t1-t0; }
  
   And all the wraparound cases will be handled correctly (assuming there
   have been less than 2^31 timer ticks between these two time values).
   Distance will return a positive value if t1 was measured after t0, a
   negative value otherwise, even if there's been a wraparound in
   between. Try the same in Python and tell me which version is simpler!

 First of all, the whole problem only arises because you are using a
 statically typed counter ;-) And it only is easy in C when your counter
 has 32 bits. But what about a 24 bit counter?

Easy, multiply it with 256 and it's a 32-bit counter ;-)
Fortunately, 24-bit-counters are quite rare. 16-bit or 32-bit counters
on the other hand are quite common, especially when you're working
close to the hardware (where C is at home). All I wanted to point out
is that bounded integers do have their advantages, because some people
in this thread apparently have never stumbled over them.

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


Re: re beginner

2006-06-04 Thread bearophileHUGS
SuperHik wrote:
 I was wondering is there a better way to do it using re module?
 perheps even avoiding this for loop?

This is a way to do the same thing without REs:

data = 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen
pants\t1\nBlue bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile
phone\t4\nWireless cord!\t2\tBuilding tools\t3\nOne for the
money\t7\tTwo for the show\t4'

data2 = data.replace(\n,\t).split(\t)
result1 = dict( zip(data2[::2], map(int, data2[1::2])) )

O if you want to be light:

from itertools import imap, izip, islice
data2 = data.replace(\n,\t).split(\t)
strings = islice(data2, 0, len(data), 2)
numbers = islice(data2, 1, len(data), 2)
result2 = dict( izip(strings, imap(int, numbers)) )

Bye,
bearophile

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


Re: re beginner

2006-06-04 Thread faulkner
you could write a function which takes a match object and modifies d,
pass the function to re.sub, and ignore what re.sub returns.

# untested code
d = {}
def record(match):
s = match.string[match.start() : match.end()]
i = s.index('\t')
print s, i# debugging
d[s[:i]] = int(s[i+1:])
return ''
re.sub('\w+\t\d+\t', record, stuff)
# end code

it may be a bit faster, but it's very roundabout and difficult to
debug.

SuperHik wrote:
 hi all,

 I'm trying to understand regex for the first time, and it would be very
 helpful to get an example. I have an old(er) script with the following
 task - takes a string I copy-pasted and wich always has the same format:

   print stuff
 Yellow hat2   Blue shirt  1
 White socks   4   Green pants 1
 Blue bag  4   Nice perfume3
 Wrist watch   7   Mobile phone4
 Wireless cord!2   Building tools  3
 One for the money 7   Two for the show4

   stuff
 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue
 bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless
 cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'

 I want to put items from stuff into a dict like this:
   print mydict
 {'Wireless cord!': 2, 'Green pants': 1, 'Blue shirt': 1, 'White socks':
 4, 'Mobile phone': 4, 'Two for the show': 4, 'One for the money': 7,
 'Blue bag': 4, 'Wrist watch': 7, 'Nice perfume': 3, 'Yellow hat': 2,
 'Building tools': 3}

 Here's how I did it:
   def putindict(items):
 ...   items = items.replace('\n', '\t')
 ...   items = items.split('\t')
 ...   d = {}
 ...   for x in xrange( len(items) ):
 ...   if not items[x].isdigit(): d[items[x]] = int(items[x+1])
 ...   return d
  
   mydict = putindict(stuff)


 I was wondering is there a better way to do it using re module?
 perheps even avoiding this for loop?
 
 thanks!

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


Re: re beginner

2006-06-04 Thread bearophileHUGS
 strings = islice(data2, 0, len(data), 2)
 numbers = islice(data2, 1, len(data), 2)

This probably has to be:

strings = islice(data2, 0, len(data2), 2)
numbers = islice(data2, 1, len(data2), 2)

Sorry,
bearophile

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


Re: Python less error-prone than Java

2006-06-04 Thread Alan Morgan
In article [EMAIL PROTECTED],
Christoph Zwerschke  [EMAIL PROTECTED] wrote:
 Simon Percivall wrote:
 First: It's perfectly simple in Java to create a binary sort that
 sorts all arrays that contain objects; so wrong there.
 My point was that the *same* Java source example, directly converted to 
 Python would *automatically* accept all kinds of arrays.
 
 And the same code converted to SML would automatically work on all
 kinds of arrays and SML is statically typed.  It's a language issue,
 not a typing issue.

Ok, here the point was that Java has *explicit* static typing. SML is 
not a procedural language and uses *implicit* static typing. Therefore 
it shares some of the benefits of dynamically typed languages such as 
Python. However, an SML version of the program would probably still have 
the same bug as the Java version, right?

 No need to make any extra efforts.
 By the way, how would you do it in Java? With 
 function overloading? I would not call that perfectly simple.
 
 Since Java doesn't allow function overloading that clearly can't be
 the way.  J2SE 5.0 allows generic classes and functions that operate
 on generic containers.  There are some gotchas, but it's not drastically
 more complex than the original int-only java code.

Java doesn't allow function overloading?

Brain fart.  You said function and I read operator.

Alan
-- 
Defendit numerus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python less error-prone than Java

2006-06-04 Thread Christoph Zwerschke
nikie wrote:
  Hm, then I probably didn't get your original point: I thought your
  argument was that a dynamically typed language was safer because it
  would choose the right type (in your example, an arbitrary-pecision
  integer) automatically.

No, my point was not to make a general statement. It just stumbled over 
that example and said to myself that wouldn't have happend with 
Python. And I thought it might be interesting for people on c.l.p as 
well. That was all.

  As you can see from the above sample, it
  sometimes picks the wrong type, too. Now you tell me that this
  doesn't count, because I should have told Python what type to use.

Yes. Python did not pick that type - you explicitely said that x 
should an int by setting x = 10001.

  I mean, you could have told Java to used a 64-bit or arbitrary-length
  integer type instead of a 32-bit integer (which would actually be
  equivalent to the Python code), so it would do the same thing
  as the Python binary search implementation.

Right, but then Java would do all index operations in that type, even 
for very small arrays when it's not necessary. That's why people 
probably don't do it.

  The is OT, but what makes you think a C# decimal can't store 0.01?

A C# data type summary gave me the impression that it was just a more 
accurate but still binary floating point type. But you're right, the 
name decimal should have given me a clue that it uses base 10 ;-)

So sorry for the confusion. Forget what I wrote about float. I should 
have corretly written that the equivalent to the C# statement

decimal x = 10001;

is the following Python statement

x = Decimal(10001)

If you do the equivalent thing, Python will give the same result as C#.

  All I wanted to point out is that bounded integers do have their
  advantages, because some people in this thread apparently have
  never stumbled over them.

Sure, I did not want to deny that. The main advantages are speed, and 
dealing with hardware related issues. Your Distance function in C is of 
course much faster than my Python implementation. Surely I wouldn't want 
to write a device driver in Python.

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


Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
SuperHik a écrit :
 hi all,
 
 I'm trying to understand regex for the first time, and it would be very 
 helpful to get an example. I have an old(er) script with the following 
 task - takes a string I copy-pasted and wich always has the same format:
 
   print stuff
 Yellow hat2Blue shirt1
 White socks4Green pants1
 Blue bag4Nice perfume3
 Wrist watch7Mobile phone4
 Wireless cord!2Building tools3
 One for the money7Two for the show4
 
   stuff
 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue 
 bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless 
 cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'
 
 I want to put items from stuff into a dict like this:
   print mydict
 {'Wireless cord!': 2, 'Green pants': 1, 'Blue shirt': 1, 'White socks': 
 4, 'Mobile phone': 4, 'Two for the show': 4, 'One for the money': 7, 
 'Blue bag': 4, 'Wrist watch': 7, 'Nice perfume': 3, 'Yellow hat': 2, 
 'Building tools': 3}
 
 Here's how I did it:
   def putindict(items):
 ... items = items.replace('\n', '\t')
 ... items = items.split('\t')
 ... d = {}
 ... for x in xrange( len(items) ):
 ... if not items[x].isdigit(): d[items[x]] = int(items[x+1])
 ... return d
  
   mydict = putindict(stuff)
 
 
 I was wondering is there a better way to do it using re module?
 perheps even avoiding this for loop?

There are better ways. One of them avoids the for loop, and even the re 
module:

def to_dict(items):
 items = items.replace('\t', '\n').split('\n')
 return dict(zip(items[::2], map(int, items[1::2])))

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


Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
strings = islice(data2, 0, len(data), 2)
numbers = islice(data2, 1, len(data), 2)
 
 
 This probably has to be:
 
 strings = islice(data2, 0, len(data2), 2)
 numbers = islice(data2, 1, len(data2), 2)

try with islice(data2, 0, None, 2)
-- 
http://mail.python.org/mailman/listinfo/python-list


Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread jj_frap
I'm new to programming in Python and am currently writing a three-card
poker simulator. I have completed the entire simulator other than
determining who has the best hand (which will be far more difficult
than the aspects I've codes thus far)...I store each player's hand in a
list of hand objects and I determine hand strength via a handstrength
list with one element for each player.

When I try to print the winner (I've not coded for kicker strength
and ties yet) via the max function, it returns the maximum value in the
list rather than the index associated with that value.

How do I return the index?

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


Re: ideas for programs?

2006-06-04 Thread Daniel Nogradi
 I've been learning python for the past couple of months and writing
 misc scripts here and there, along with some web apps.
 I'm wondering if anyone has ideas of programs I might try my hand at
 making?

You could put together a handy CSS generator library that could be
used from a python webapp to generate CSS stylesheets on the fly. I'm
sure many webdevelopers would find this helpful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Where is the ucs-32 codec?

2006-06-04 Thread beni . cherniavsky
Python seems to be missing a UCS-32 codec, even in wide builds (not
that it the build should matter).
Is there some deep reason or should I just contribute a patch?

If it's just a bug, should I call the codec 'ucs-32' or 'utf-32'?  Or
both (aliased)?
There should be  '-le' and '-be' variats, I suppose.  Should there be a
variant without explicit endianity, using a BOM to decide (like
'utf-16')?
And it should combine surrogates into valid characters (on all builds),
like the 'utf-8' codec does, right?

--
Beni Cherniavsky [EMAIL PROTECTED], who can only read email on
weekends.

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


Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Sybren Stuvel
jj_frap enlightened us with:
 When I try to print the winner (I've not coded for kicker strength
 and ties yet) via the max function, it returns the maximum value in
 the list rather than the index associated with that value.

 How do I return the index?

You can't even be sure it exists - there might be multiple maximum
values. What would you expect in such a case?

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: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread gene tani

jj_frap wrote:
 I'm new to programming in Python and am currently writing a three-card
 poker simulator. I have completed the entire simulator other than
 determining who has the best hand (which will be far more difficult
 than the aspects I've codes thus far)...I store each player's hand in a
 list of hand objects and I determine hand strength via a handstrength
 list with one element for each player.

 When I try to print the winner (I've not coded for kicker strength
 and ties yet) via the max function, it returns the maximum value in the
 list rather than the index associated with that value.

 How do I return the index?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/306862
http://www.rubyquiz.com/quiz24.html

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


RE: C# equivalent to range()

2006-06-04 Thread Delaney, Timothy (Tim)
Luis M. González wrote:

 There are thousands of threads to choose from in this forum.
 If they didn't like this question, they could have picked any other
 one to discuss.
 There's no need to be disagreeable :-)

Well, there are reasons to reply to a message stating that it's not on-topic 
for the group. The most common reaction to receiving no replies is to start a 
new thread petulantly asking why there were no answers to the original thread. 
If that one gets no replies the most common reaction is start another new 
thread stating that Python sucks, the newsgroup sucks, etc.

Not saying that this is what would have happened in this case, but it is the 
most common sequence of events. Better to head it off before it happens. At 
least any upset replies tend to be restricted to the one thread ;)

Unfortunately, posting a good response, whilst apparently helpful, tends to 
encourage further off-topic postings :(

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


RE: Which exceptions are recommended to me handled?

2006-06-04 Thread Delaney, Timothy (Tim)
Florencio Cano wrote:

 Hello,
 Is it recommended as a good programming practice to catch all
 exceptions and raise our own exceptions or let Python itself raise
 these kinds of exceptions?  
 For example imagine a function that needs an integer and '34' is
 passed, this is ok because inside the function it uses int(variable)
 but if a 'hello' is passed it will raise a ValueError exception. Is
 it better to handle this exception or let Python raise directly
 ValueError and stop execution or what is recommended?   

If you can validly handle the exception, do so. Otherwise, let it
propagate. Valid handling could be (for example) logging the error and
using a default value.

Note that it's a particularly bad idea to just replace one exception
with another exception (not suggesting that that is what you intended -
just something I've seen a lot ;)

try:
int(val)
except ValueError:
raise MyValueError('Bad value: ' + val)

The most important problem here is that you've lost the stack trace from
the original exception. The next most important is that anything else
that believes it can handle a ValueError now won't be able to.

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


Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Erik Max Francis
gene tani wrote:

 http://www.rubyquiz.com/quiz24.html

His question was for three-card poker, not normal poker.  The ranking of 
hands in three-card poker isn't the same as in normal best five-card 
poker rankings; for instance, in three-card poker, a straight beats a flush.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Could it be / That we need loving to survive
   -- Neneh Cherry
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] ConfigObj 4.3.2 Released

2006-06-04 Thread Fuzzyman
`ConfigObj 4.3.2 http://www.voidspace.org.uk/python/configobj.html`_
has just been released.

You can download it from `configobj-4.3.2.zip
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.3.2.zip`_.

This is a bugfix and minor feature enhancement release. There is a
bugfix in `unrepr mode
http://www.voidspace.org.uk/python/configobj.html#unrepr-mode`_, and
exception handling has been improved.

The full changelog is :

Changed error handling, if parsing finds a single error then that
error will be re-raised. That error will still have an ``errors`` and a
``config`` attribute. That means the error will be more comprehensible.

Fixed bug where '\n' terminated files could be truncated.

Bugfix in ``unrepr`` mode, it couldn't handle '#' in values.
(Thanks to Philippe Normand for the report.)

As a consequence of this fix, ConfigObj doesn't now keep inline
comments in ``unrepr`` mode. This is because the parser in the
`compiler package http://docs.python.org/lib/compiler.html`_ doesn't
keep comments. {sm;:-)}

Error messages are now more useful. They tell you the number of
parsing errors and the line number of the first error. (In the case of
multiple errors.)

Line numbers in exceptions now start at 1, not 0.

Errors in ``unrepr`` mode are now handled the same way as in the
normal mode. The errors stored will be an ``UnreprError``.

There is also a proposal to support `PEP 292
http://www.python.org/dev/peps/pep-0292/`_ string substitution (which
is much better). This will be the target of the next release of
**ConfigObj**.

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


Re: Where is the ucs-32 codec?

2006-06-04 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

 Python seems to be missing a UCS-32 codec, even in wide builds (not
 that it the build should matter).
 Is there some deep reason or should I just contribute a patch?
 
 If it's just a bug, should I call the codec 'ucs-32' or 'utf-32'?  Or
 both (aliased)?
 There should be  '-le' and '-be' variats, I suppose.  Should there be a
 variant without explicit endianity, using a BOM to decide (like
 'utf-16')?
 And it should combine surrogates into valid characters (on all builds),
 like the 'utf-8' codec does, right?

Note that UTF-32 is UCS-4.  UCS-32 (Universial Character Set in 32 
octets) wouldn't make much sense.

Not that Python has a UCS-4 encoding available either.  I'm really not 
sure why.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Could it be / That we need loving to survive
   -- Neneh Cherry
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] ConfigObj 4.3.2 Released

2006-06-04 Thread Fuzzyman
`ConfigObj 4.3.2 http://www.voidspace.org.uk/python/configobj.html`_
has just been released.

You can download it from `configobj-4.3.2.zip
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=configobj-4.3.2.zip`_.

ConfigObj is a config file reader and writer. It has *many* features,
but the main one is that it is simple to use. Its features include :

* Nested sections (subsections), to any level
* List values
* Multiple line values
* String interpolation (substitution)
* Integrated with a powerful validation system

- including automatic type checking/conversion
- repeated sections
- and allowing default values

* All comments in the file are preserved
* The order of keys/sections is preserved
* No external dependencies
* Full Unicode support
* A powerful ``unrepr`` mode for storing basic datatypes

This is a bugfix and minor feature enhancement release. There is a
bugfix in `unrepr mode
http://www.voidspace.org.uk/python/configobj.html#unrepr-mode`_, and
exception handling has been improved.

The full changelog is :

Changed error handling, if parsing finds a single error then that
error will be re-raised. That error will still have an ``errors`` and a
``config`` attribute. That means the error will be more comprehensible.

Fixed bug where '\n' terminated files could be truncated.

Bugfix in ``unrepr`` mode, it couldn't handle '#' in values.
(Thanks to Philippe Normand for the report.)

As a consequence of this fix, ConfigObj doesn't now keep inline
comments in ``unrepr`` mode. This is because the parser in the
`compiler package http://docs.python.org/lib/compiler.html`_ doesn't
keep comments. {sm;:-)}

Error messages are now more useful. They tell you the number of
parsing errors and the line number of the first error. (In the case of
multiple errors.)

Line numbers in exceptions now start at 1, not 0.

Errors in ``unrepr`` mode are now handled the same way as in the
normal mode. The errors stored will be an ``UnreprError``.

There is also a proposal to support `PEP 292
http://www.python.org/dev/peps/pep-0292/`_ string substitution (which
is much better). This will be the target of the next release of
**ConfigObj**.

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


Re: mutable member, bug or ...

2006-06-04 Thread Bruno Desthuilliers
Sambo a écrit :
 By accident I assigned int to a class member 'count' which was 
 initialized to (empty) string and had no error till I tried to use it as 
 string, obviously. Why was there no error on assignment( near the end ).

Python is dynamically typed - which means that it's not the name that 
holds type info, but the object itself. names are just, well, names...

BTW, I failed to see where you assigned an int to the class attribute 
'count'. I just saw a try to call a string - which should raise a TypeError.

 class Cgroup_info:

Do yourself (and anyone having to work on or with your code) a favour: 
use new-style classes (ie : inherit from 'object'). And FWIW, the 
convention for class names is CamelCase - preferably without MS-like 
hungarian annotation.

group_name = 
count = 0  #last time checked and processed/retrieved
first = 0
last = 
retrieval_type = # allways , ask( if more than some limit), 
 none
date_checked = 
time_checked = 
new_count = 
new_first = 
new_last = 
 # local storage maintanance vars
pointer_file = 
message_file = 
 #maintanance vars   cur_mess_num = 0
cur_mess_id = 

All these are *class* attributes (meaning they belong to the class 
object itself, not to instances). I really doubt this is what you want. 
If you hope to have all the above as instance attributes, you must 
assign them to the instance (usually in the __init__() method, which 
main purpose is to initialize the newly created instance.

def __init__( self ):
group_name = 

this creates a local variable 'group_name', bound to an empty string. 
Using the reference to the current instance (usually named 'self', and 
always passed in as first param) is *not* optional.

count = 0  #last time checked and processed/retrieved

and this creates a local variable 'count', bound to string '0'.

Of course, both are lost as soon as the __init__() returns.

def get_count( self ):
print self.count, type( self.count )
return string.atoi( self.count, 10 )

the string module is mostly deprecated. Use str object methods instead - 
  or if you just want to create an int from it's representation as a 
string, int(self.count).

 class server_info:
def (server_info::)get_group_stat( self, grp ):

invalid syntax.

   gr_info = Cgroup_info()

and a problem with indentation here.

gr_info.group_name = grp

Tthis create a new instance attribute group_name on the gr_info 
object. This instance attribute will shadow the class attribute of the 
same name.

Also, FWIW, if you always know the value for group_name when 
instanciating a Cgroup_info object, you might as well pass it to the 
initializer.

try:
ind = self.group_list.index( grp )

The common convention for indices in each and every language is 'i'. If 
you really want a meaningful name, then group_index would be better.

Also, for this kind of lookups, dicts are really faster than lists.

except ValueError:
gr_info.count(0)

I didn't see any method count() in the declaration of class 
CGroup_info. I saw an attribute named count, but it was bound to a 
string - which is not callable.

return ( gr_info )

parenthesis here are useless (and FWIW, they would be just as useless in 
C++).

print ind
if len( self.group_list[ind].split() ) == 4:
gr_info.count = self.group_list[ind].split()[1]
gr_info.first = self.group_list[ind].split()[2]
gr_info.last = self.group_list[ind].split()[3]

group_list[ind] is the same as grp, isn't it ? if so, using grp directly 
might be much more efficient *and* much more readable.

Also, you're calling 4 times the same method. This is highly 
inefficient. Try this instead:
parts = grp.split()
if len(parts) == 4:
  gr_info.count, gr_info.first, gr_info.last = parts[1:]


 else:
gr_info.count = gr_info.first = gr_info.last = 0

This style of chained assignment can be a real gotcha in Python. In 
this case, it is safe since 0 is immutable. But using a mutable object 
instead would lead to probably unexpected results. Try this:

a = b = []
a.append(1)
print b

You have to understand that Python variables (the correct name is 
bindings) are just the association (in a given namespace) of a name 
and a *reference* (kind of a smart pointer) to an object.

return( gr_info )   

Here's a possible rewrite of your code. It's certainly not how it should 
be done, but (apart from going into wild guesses) it's difficult to come 
up with anything better without knowing the specs. Anyway, it should 
help you grasp a more pythonic way to do things:

class GroupInfo(object):

def __init__(self, group_name, count=0, first=0, last=):
self.group_name = group_name
self.count = count  #last time checked and processed/retrieved
self.first = first
self.last = last


Re: Where is the ucs-32 codec?

2006-06-04 Thread M�ta-MCI
Hi!

Look at: http://cjkpython.berlios.de   (iconvcodec)

(Serge Orlov has built a version for Python 2.4 special for me; thanks to 
him).


@-salutations
-- 
Michel Claveau


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


Re: [OT] in python , could I accomplish the purpose that a=Console.read() used in C?

2006-06-04 Thread Bruno Desthuilliers
python a écrit :
 in python , could I accomplish the purpose that a=Console.read() used
 in C?

ot mode='pedantic'
There's nothing like Console.read() in ansi-C.
/ot

(see Dennis's post for the answer to your question)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re beginner

2006-06-04 Thread John Machin
On 5/06/2006 10:38 AM, Bruno Desthuilliers wrote:
 SuperHik a écrit :
 hi all,

 I'm trying to understand regex for the first time, and it would be 
 very helpful to get an example. I have an old(er) script with the 
 following task - takes a string I copy-pasted and wich always has the 
 same format:

   print stuff
 Yellow hat2Blue shirt1
 White socks4Green pants1
 Blue bag4Nice perfume3
 Wrist watch7Mobile phone4
 Wireless cord!2Building tools3
 One for the money7Two for the show4

   stuff
 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue 
 bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless 
 cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'

 I want to put items from stuff into a dict like this:
   print mydict
 {'Wireless cord!': 2, 'Green pants': 1, 'Blue shirt': 1, 'White 
 socks': 4, 'Mobile phone': 4, 'Two for the show': 4, 'One for the 
 money': 7, 'Blue bag': 4, 'Wrist watch': 7, 'Nice perfume': 3, 'Yellow 
 hat': 2, 'Building tools': 3}

 Here's how I did it:
   def putindict(items):
 ... items = items.replace('\n', '\t')
 ... items = items.split('\t')
 ... d = {}
 ... for x in xrange( len(items) ):
 ... if not items[x].isdigit(): d[items[x]] = int(items[x+1])
 ... return d
  
   mydict = putindict(stuff)


 I was wondering is there a better way to do it using re module?
 perheps even avoiding this for loop?
 
 There are better ways. One of them avoids the for loop, and even the re 
 module:
 
 def to_dict(items):
 items = items.replace('\t', '\n').split('\n')

In case there are leading/trailing spaces on the keys:

items = [x.strip() for x in items.replace('\t', '\n').split('\n')]

 return dict(zip(items[::2], map(int, items[1::2])))
 
 HTH

Fantastic -- at least for the OP's carefully copied-and-pasted input.
Meanwhile back in the real world, there might be problems with multiple 
tabs used for 'prettiness' instead of 1 tab, non-integer values, etc etc.
In that case a loop approach that validated as it went and was able to 
report the position and contents of any invalid input might be better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Bruno Desthuilliers
James J. Besemer a écrit :
 
(snip)
 
 PEP -- EXTEND PRINT TO EXPAND GENERATORS
 
 NUTSHELL
 
 I propose that we extend the semantics of print such that if the 
 object to be printed is a generator then print would iterate over the 
 resulting sequence of sub-objects and recursively print each of the 
 items in order.
 

Please, don't:

from itertools import cycle
def mygen():
 return cycle('this is a very bad idea'.split())


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


Re: Using print instead of file.write(str)

2006-06-04 Thread Bruno Desthuilliers
Tim Roberts a écrit :
 Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 
 
Sion Arrowsmith a écrit :

(snip)
more flexible? More convenient, yes. More powerful, maybe. But I
don't see more flexible. Everything print can to stdout.write() can
do. The reverse isn't true. eg (this appears to be a FAQ on this
group, although I can't find it in the FAQ):

for x in range(10):
sys.stdout.write(str(x))

to print:

0123456789

The reverse isn't true ???

  print .join(str(x) for x in range(10))
  
 What he meant it that it is impossible to produce 0123456789 using 10
 separate print statements, while it IS possible with 10 separate writes.

why on earth would someone try to use 10 consecutive I/O operations on 
the same stream when it can be done with 1 ???
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using print instead of file.write(str)

2006-06-04 Thread Bruno Desthuilliers
John Machin a écrit :
(snip)
 ... or was that a rhetorical question?

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


Re: deleting texts between patterns

2006-06-04 Thread John Machin
On 5/06/2006 2:51 AM, Baoqiu Cui wrote:
 John Machin [EMAIL PROTECTED] writes:
 
 Uh-oh.

 Try this:

 pat = re.compile('(?=abc\n).*?(?=xyz\n)', re.DOTALL)
 re.sub(pat, '', linestr)
 'blahfubarabc\nxyz\nxyzzy'
 
 This regexp still has a problem.  It may remove the lines between two
 lines like 'aaabc' and 'xxxyz' (and also removes the first two 'x's in
 'xxxyz').
 
 The following regexp works better:
 
   pattern = re.compile('(?=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE)
 

You are quite correct. Your reply, and the rejoinder below, only add to 
the proposition that regexes are not necessarily the best choice for 
every text-processing job :-)

Just in case the last line is 'xyz' but is not terminated by '\n':

pattern = re.compile('(?=^abc\n).*?(?=^xyz$)', re.DOTALL | re.MULTILINE)

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


Re: Installation Problem

2006-06-04 Thread Marshall Dudley
Warren Block wrote:

 Marshall Dudley [EMAIL PROTECTED] wrote:
  Sorry, this is a FreeBSD system 4.8-RELEASE
 
  I found another set of documents that say to use the following to
  install::
 
  python setup.py install
 
  but after running it, I still have the same problem.

 [top-posting trimmed, please don't do that]

 Doesn't the port work for 4.8?  It does work on FreeBSD 4.11, but there
 may have been changes to the ports system since 4.8.  (You should
 consider updating to 4.11.)

 There are several patch files in the FreeBSD port, including
 one to setup.py.

 The easiest way is to cvsup your ports tree and then

 cd /usr/ports/lang/python
 make
 make install
 make clean

 --
 Warren Block * Rapid City, South Dakota * USA

Now I have a python that runs, but the application I want to run it on
denyhosts gives me the following error:

Python = 2.3 required.  You are using: 2.2.2 (#1, Jun  4 2006, 16:29:13)
[GCC 2.95.4 20020320 [FreeBSD]]

##

Visit http://www.python.org and download a more recent version of
Python.

You should install this version in addition to your current version
(rather than upgrading your current version) because your system might
depend on the current version.  After installing the newer version, for
instance version 2.4, simply invoke DenyHosts explicitly with the new
version of python, eg:

$ python2.4 ./denyhosts.py

##

Is it not possible to install the latest version of python on my FreeBSD
system?  Upgrading the FreeBSD is not an option since this is a production
system and everything else is working fine.

Marshall

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


Adding attribute to objetcs

2006-06-04 Thread Miguel Galves
Hello,I`m starting to learn python, and I hava a very good background in Javaand C/C++ programming. I was reading Dive into python chapter aboutOO and I saw that in python we can do the following:class Person:
 passjoe = new Person()joe.name = Joejoe.age = 13It seems that it is possible to add attributes to any object instancein run time, as in _javascript_. It seems to me that it can be a source
of errors. One that come in my mind is the follwing:class Person:
 name = 

joe = new Person()
joe.nome = JoeThe code above adds an attribute called nome, but the programmer may think it's name.What is the real interest of this feature ? Is there a way to block this kind of error ?
Thanks,Miguel-- Miguel Galves - Engenheiro de ComputaçãoJá leu meus blogs hoje? Para geeks http://log4dev.blogspot.comPra pessoas normais
http://miguelgalves.blogspot.comNão sabendo que era impossível, ele foi lá e fez...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: integer to binary...

2006-06-04 Thread Bruno Desthuilliers
Grant Edwards a écrit :
 On 2006-06-02, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 
Grant Edwards a écrit :

On 2006-06-01, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

does anyone know a module or something to convert numbers like integer
to binary format ?

They _are_ in binary format.

Not really.
 
 Yes, really.

No, not really.

  Otherwise the bitwise boolean operations you
 demonstrated wouldn't work as shown.

Ho yes ?

 
(7).__class__

type 'int'

dir((7))

['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute__', '__getnewargs__', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__',
'__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__',
'__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__',
'__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__',
'__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__',
'__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']

 
 The fact that they impliment the xor operator is pretty much
 proof that integers are

... objects, instance of the int class. Not really what I'd call binary 
format !-)

Now if you go that way, it's of course true that everything on a 
computer ends up in a binary format It's true.

 stored in binary format -- xor is only
 defined for binary numbers.
 
class Prisonner(object):
   def __xor__(self, other):
 return I'm not a (binary) number, I'm a free man

The fact that an object implements the xor operator is pretty much proof 
that the guy that wrote the class decided to implement the xor operator !-)

Grant, I of course agree that, *for practical means*, one can consider 
that Python's integer are already in binary format - for a definition 
of binary format being you can do bitwise ops on them. But the truth 
is that Python integers are objects (in the OO meaning) holding integer 
values - not integer values themselves.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reordering elements of a list

2006-06-04 Thread Roberto Bonvallet
greenflame [EMAIL PROTECTED]:
 Roberto: I do not understand the first half of the last line of your
 code.

[mainlist[i - 1] for i in orderinglist] is a list made with the
elements of orderinglist, but instead of taking the actual value i
from the list, the value that is taken is mainlist[i - 1].

If orderinglist is [3, 4, 2, 1], then [mainlist[i - 1] for i in
orderinglist] is:

[mainlist[3 - 1], mainlist[4 - 1], mainlist[2 - 1], mainlist[1 - 1]]

Remember that indexing starts from 0.
-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re beginner

2006-06-04 Thread Paul McGuire
John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Fantastic -- at least for the OP's carefully copied-and-pasted input.
 Meanwhile back in the real world, there might be problems with multiple
 tabs used for 'prettiness' instead of 1 tab, non-integer values, etc etc.
 In that case a loop approach that validated as it went and was able to
 report the position and contents of any invalid input might be better.

Yeah, for that you'd need more like a real parser... hey, wait a minute!
What about pyparsing?!

Here's a pyparsing version.  The definition of the parsing patterns takes
little more than the re definition does - the bulk of the rest of the code
is parsing/scanning the input and reporting the results.

The pyparsing home page is at http://pyparsing.wikispaces.com.

-- Paul


stuff = 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue
bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless
cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'
print Original input string:
print stuff
print

from pyparsing import *

# define low-level elements for parsing
itemWord = Word(alphas, alphanums+.!?)
itemDesc = OneOrMore(itemWord)
integer = Word(nums)

# add parse action to itemDesc to merge separate words into single string
itemDesc.setParseAction( lambda s,l,t:  .join(t) )

# define macro element for an entry
entry = itemDesc.setResultsName(item) + integer.setResultsName(qty)

# scan through input string for entry's, print out their named fields
print Results when scanning for entries:
for t,s,e in entry.scanString(stuff):
print t.item,t.qty
print

# parse entire string, building ParseResults with dict-like access
results = dictOf( itemDesc, integer ).parseString(stuff)
print Results when parsing entries as a dict:
print Keys:, results.keys()
for item in results.items():
print item
for k in results.keys():
print k,=, results[k]


prints:

Original input string:
Yellow hat 2 Blue shirt 1
White socks 4 Green pants 1
Blue bag 4 Nice perfume 3
Wrist watch 7 Mobile phone 4
Wireless cord! 2 Building tools 3
One for the money 7 Two for the show 4

Results when scanning for entries:
Yellow hat 2
Blue shirt 1
White socks 4
Green pants 1
Blue bag 4
Nice perfume 3
Wrist watch 7
Mobile phone 4
Wireless cord! 2
Building tools 3
One for the money 7
Two for the show 4

Results when parsing entries as a dict:
Keys: ['Wireless cord!', 'Green pants', 'Blue shirt', 'White socks', 'Mobile
phone', 'Two for the show', 'One for the money', 'Blue bag', 'Wrist watch',
'Nice perfume', 'Yellow hat', 'Building tools']
('Wireless cord!', '2')
('Green pants', '1')
('Blue shirt', '1')
('White socks', '4')
('Mobile phone', '4')
('Two for the show', '4')
('One for the money', '7')
('Blue bag', '4')
('Wrist watch', '7')
('Nice perfume', '3')
('Yellow hat', '2')
('Building tools', '3')
Wireless cord! = 2
Green pants = 1
Blue shirt = 1
White socks = 4
Mobile phone = 4
Two for the show = 4
One for the money = 7
Blue bag = 4
Wrist watch = 7
Nice perfume = 3
Yellow hat = 2
Building tools = 3


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


Re: C# equivalent to range()

2006-06-04 Thread Neuruss
Delaney, Timothy (Tim) wrote:
 Well, there are reasons to reply to a message stating that it's not on-topic 
 for the group. The most common reaction to receiving no replies is to start a 
 new thread petulantly asking why there were no answers to the original 
 thread. If that one gets no replies the most common reaction is start another 
 new thread stating that Python sucks, the newsgroup sucks, etc.

 Not saying that this is what would have happened in this case, but it is the 
 most common sequence of events. Better to head it off before it happens. At 
 least any upset replies tend to be restricted to the one thread ;)

 Unfortunately, posting a good response, whilst apparently helpful, tends to 
 encourage further off-topic postings :(

 Tim Delaney

Tim,

I don't think it was entirely off topic, although I understand your
point.
It happens that I'm using Ironpython, and I wanted to improve the
performance of a script by writing a c# extension.
Writing extensions in other languages (c, c++ and now c#) is a common
practice amongst python programers, and that was the purpose of my
question.

I asked especifically the equivalence of a couple of python features in
this language.
And I did it here, because chances were that someone would understand
what I was asking, (which was how to translate those python features
into another language).

I could have asked this question in a c# related forum, but then I
should have had to explain how range and extend work in python...

Actualy, someone replied with a couple of lines, and this was just what
I wanted!
That person was very kind and I'm sure it didn't take more than a few
seconds to write his reply. I'm sure he was satisfied by helping me,
and I was satisfied too by his kind reply.

What about the others?
Are they worried about the storage limit of this forum perhaps?
Or it was the wasted bandwidth?
What was exactly the reason for being that annoyed? Am I forcing them
to read my question or to post a reply?

I grant that perhaps I should have explained why I needed this advice.
But I'm not using this forum to learn another thing. I am a (budding)
python programmer looking for a solution, and my question was very
especific and to the point.

Anyway, if someone still feels that the question is off topic, there
are better ways to point it out (as you're doing now).

If these people's life suck, I suggest they buy a punching bag to
discharge their frustation. I don't think this forum is the best place
for doing it.

Regards,
Neuruss

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


Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Steven Bethard
jj_frap wrote:
 I'm new to programming in Python and am currently writing a three-card
 poker simulator. I have completed the entire simulator other than
 determining who has the best hand (which will be far more difficult
 than the aspects I've codes thus far)...I store each player's hand in a
 list of hand objects and I determine hand strength via a handstrength
 list with one element for each player.
 
 When I try to print the winner (I've not coded for kicker strength
 and ties yet) via the max function, it returns the maximum value in the
 list rather than the index associated with that value.
 
 How do I return the index?

Can you do something like::

 max_val, max_index = max((x, i) for i, x in enumerate(my_list))

?  If any two x values are equal, this will return the one with the 
lower index.  Don't know if that matters to you.

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


Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Robert Kern
Steven Bethard wrote:
 Can you do something like::
 
  max_val, max_index = max((x, i) for i, x in enumerate(my_list))
 
 ?  If any two x values are equal, this will return the one with the 
 lower index.  Don't know if that matters to you.

Wouldn't it return the one with the highest index?

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: re beginner

2006-06-04 Thread John Machin
On 5/06/2006 10:07 AM, Paul McGuire wrote:
 John Machin [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Fantastic -- at least for the OP's carefully copied-and-pasted input.
 Meanwhile back in the real world, there might be problems with multiple
 tabs used for 'prettiness' instead of 1 tab, non-integer values, etc etc.
 In that case a loop approach that validated as it went and was able to
 report the position and contents of any invalid input might be better.
 
 Yeah, for that you'd need more like a real parser... hey, wait a minute!
 What about pyparsing?!
 
 Here's a pyparsing version.  The definition of the parsing patterns takes
 little more than the re definition does - the bulk of the rest of the code
 is parsing/scanning the input and reporting the results.
 

[big snip]

I didn't see any evidence of error handling in there anywhere.


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


Lots of orphaned PyCon wiki pages...

2006-06-04 Thread skip

Over the past couple days I've been trying to reduce the large number of
orphaned wiki pages, deleting many, stitching many others back into the
fabric.  There are a bunch of orphaned PyCon-related pages, mostly subpages
of PyCon2005 and PyCon2006.  Would someone with PyCon-fu want to check them
out and decide their fate?  If so, visit

http://wiki.python.org/moin/OrphanedPages

and scroll down to the P section.

Thanks,

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


Re: re beginner

2006-06-04 Thread Paul McGuire
John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 5/06/2006 10:07 AM, Paul McGuire wrote:
  John Machin [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  Fantastic -- at least for the OP's carefully copied-and-pasted input.
  Meanwhile back in the real world, there might be problems with multiple
  tabs used for 'prettiness' instead of 1 tab, non-integer values, etc
etc.
  In that case a loop approach that validated as it went and was able to
  report the position and contents of any invalid input might be better.
 
  Yeah, for that you'd need more like a real parser... hey, wait a minute!
  What about pyparsing?!
 
  Here's a pyparsing version.  The definition of the parsing patterns
takes
  little more than the re definition does - the bulk of the rest of the
code
  is parsing/scanning the input and reporting the results.
 

 [big snip]

 I didn't see any evidence of error handling in there anywhere.


Pyparsing has a certain amount of error reporting built in, raising a
ParseException when a mismatch occurs.

This particular grammar is actually pretty error-tolerant.  To force an
error, I replaced One for the money with 1 for the money, and here is
the exception reported by pyparsing, along with a diagnostic method,
markInputline:


stuff = 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen pants\t1\nBlue
bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile phone\t4\nWireless
cord!\t2\tBuilding tools\t3\nOne for the money\t7\tTwo for the show\t4'
badstuff = 'Yellow hat\t2\tBlue shirt\t1\nWhite socks\t4\tGreen
pants\t1\nBlue bag\t4\tNice perfume\t3\nWrist watch\t7\tMobile
phone\t4\nWireless cord!\t2\tBuilding tools\t3\n1 for the money\t7\tTwo for
the show\t4'
pattern = dictOf( itemDesc, integer ) + stringEnd
print pattern.parseString(stuff)
print
try:
print pattern.parseString(badstuff)
except ParseException, pe:
print pe
print pe.markInputline()

Gives:
[['Yellow hat', '2'], ['Blue shirt', '1'], ['White socks', '4'], ['Green
pants', '1'], ['Blue bag', '4'], ['Nice perfume', '3'], ['Wrist watch',
'7'], ['Mobile phone', '4'], ['Wireless cord!', '2'], ['Building tools',
'3'], ['One for the money', '7'], ['Two for the show', '4']]

Expected stringEnd (at char 210), (line:6, col:1)
!1 for the money 7   Two for the show4

-- Paul


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


Freezing a static executable

2006-06-04 Thread Will Ware
I am trying to freeze a static executable. I built a static Python
executable this way:
./configure --disable-shared --prefix=/usr/local
make
make install
Even that didn't give me a really static executable, though:
$ ldd /usr/local/bin/python
linux-gate.so.1 =  (0xe000)
libpthread.so.0 = /lib/tls/libpthread.so.0 (0xb7f44000)
libdl.so.2 = /lib/libdl.so.2 (0xb7f4)
libutil.so.1 = /lib/libutil.so.1 (0xb7f3c000)
libm.so.6 = /lib/tls/libm.so.6 (0xb7f17000)
libc.so.6 = /lib/tls/libc.so.6 (0xb7de9000)
/lib/ld-linux.so.2 (0xb7f7)
Then I typed this:
/usr/local/bin/python
/home/wware/Python-2.4.1/Tools/freeze/freeze.py foo.py
ldd foo
$ ldd foo
linux-gate.so.1 =  (0xe000)
libpthread.so.0 = /lib/tls/libpthread.so.0 (0xb7f5a000)
libdl.so.2 = /lib/libdl.so.2 (0xb7f56000)
libutil.so.1 = /lib/libutil.so.1 (0xb7f52000)
libm.so.6 = /lib/tls/libm.so.6 (0xb7f2d000)
libc.so.6 = /lib/tls/libc.so.6 (0xb7dff000)
/lib/ld-linux.so.2 (0xb7f86000)
What stupid thing am I doing wrong?
TIA for any advice
Will Ware

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


Re: C# equivalent to range()

2006-06-04 Thread Neuruss

Dennis Lee Bieber wrote:
   What most of us saw was a blunt request on how to implement a Python
 construct in some other language that may not be familiar to us.

I'm curious, who are us?

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


Re: Python less error-prone than Java

2006-06-04 Thread Ilpo Nyyssönen
Kaz Kylheku [EMAIL PROTECTED] writes:

 Buggy library code is what prompted that article.

Yes, but it is an error type that happens very rarely still. And so it
seems that very few programs even notice that bug in that library. 

 Except when you feed those programs inputs which are converted to
 integers which are then fed as domain values into some operation that
 doesn't fit into the range type.

If the input value range is limited, you want to get an error, if out
of range value is given. If you want to handle unlimited values, you
really need to take a look that you can do it. Think for example
storing such value to a database.

 1. null pointer errors
 2. wrong type (class cast in Java, some weird missing attribute in python)
 3. array/list index out of bounds

 First and third ones are the same in about every language.

 ... other than C and C++, where their equivalents just crash or stomp
 over memory, but never mind; who uses those? ;)

It is not different. Your crash can tell you that it was a null
pointer. Your crash can tell you that you stomped over memory. You
just get the information about the error in different way.

 Instead of this stupid idea of pointers or references having a null
 value, you can make a null value which has its own type, and banish
 null pointers.

Yes and I actually think that as bad thing. It is nice to be able to
tell the difference between null pointer and wrong type. Of course if
the error message tells you that you had null there, it is not a
problem, but what if you somehow lose the error message and get only
the exception class name? (Yes, you should always keep the message
too, but it does happen.)

-- 
Ilpo Nyyssönen # biny # /* :-) */
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Steven Bethard
Robert Kern wrote:
 Steven Bethard wrote:
 Can you do something like::

  max_val, max_index = max((x, i) for i, x in enumerate(my_list))

 ?  If any two x values are equal, this will return the one with the 
 lower index.  Don't know if that matters to you.
 
 Wouldn't it return the one with the highest index?

Yes sorry.  Mentally switched my min and max calls.

Thanks for the catch.

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


[ python-Bugs-1484556 ] Output of KlocWork on Python2.4.3 sources

2006-06-04 Thread SourceForge.net
Bugs item #1484556, was opened at 2006-05-09 13:14
Message generated for change (Comment added) made by tebeka
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1484556group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Miki Tebeka (tebeka)
Assigned to: Nobody/Anonymous (nobody)
Summary: Output of KlocWork on Python2.4.3 sources

Initial Comment:
We're evaluating KlocWork (http://www.klocwork.com),
I've ran it on the source of Python 2.4.3 and the
output is attached (1562 warnings).

--

Comment By: Miki Tebeka (tebeka)
Date: 2006-06-04 12:53

Message:
Logged In: YES 
user_id=358087

I'll try to see if I can sneak it in, can't promise anything
though

--

Comment By: A.M. Kuchling (akuchling)
Date: 2006-05-31 17:26

Message:
Logged In: YES 
user_id=11375

The Coverity scans also probably report some of the same
bugs, so many of these problems may be fixed in the 2.5 trunk.  

If you're still evaluating, you could try running the tool
on the 2.5 trunk (snapshot available from
http://svn.python.org/snapshots/) and see if the results are
shorter.


--

Comment By: Martin v. Löwis (loewis)
Date: 2006-05-10 07:45

Message:
Logged In: YES 
user_id=21627

Thanks for these results. Unfortunately, they seem to
contain many false positives, so it is unclear how one
should proceed with them.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1484556group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1496315 ] strptime: wrong default values used to fill in missing data

2006-06-04 Thread SourceForge.net
Bugs item #1496315, was opened at 2006-05-28 11:26
Message generated for change (Comment added) made by markus_gritsch
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1496315group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Markus Gritsch (markus_gritsch)
Assigned to: Brett Cannon (bcannon)
Summary: strptime: wrong default values used to fill in missing data

Initial Comment:
The documentation of strptime() says: The default
values used to fill in any missing data are (1900, 1,
1, 0, 0, 0, 0, 1, -1).  As the example below shows,
this is not the case.

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310
32 bit (Intel)] on win32
Type help, copyright, credits or license for
more information.
 import time
 time.strptime('', '')
(1900, 1, 1, 0, 0, 0, 0, 1, -1)
 time.strptime('2006', '%Y')
(2006, 1, 1, 0, 0, 0, 6, 1, -1)
 time.strptime('2006-05', '%Y-%m')
(2006, 5, 1, 0, 0, 0, 0, 121, -1)
 time.strptime('2006-05-26', '%Y-%m-%d')
(2006, 5, 26, 0, 0, 0, 4, 146, -1)
 time.strptime('2006-05-26 21', '%Y-%m-%d %H')
(2006, 5, 26, 21, 0, 0, 4, 146, -1)
 time.strptime('2006-05-26 21:06', '%Y-%m-%d %H:%M')
(2006, 5, 26, 21, 6, 0, 4, 146, -1)
 time.strptime('2006-05-26 21:06:11', '%Y-%m-%d
%H:%M:%S')
(2006, 5, 26, 21, 6, 11, 4, 146, -1)


--

Comment By: Markus Gritsch (markus_gritsch)
Date: 2006-06-04 18:57

Message:
Logged In: YES 
user_id=553904

Thank you

--

Comment By: Brett Cannon (bcannon)
Date: 2006-05-31 04:22

Message:
Logged In: YES 
user_id=357491

Rev. 46569 has more clear wording for HEAD and rev. 46570
has it for 2.4 .

--

Comment By: Brett Cannon (bcannon)
Date: 2006-05-28 20:29

Message:
Logged In: YES 
user_id=357491

The docs need to be fixed to say those are the default
values except when strptime() can infer better ones.  There
is a lot of smarts in the algorithm that do calculations to
fill in missing data as best as possible, and that is what
is happening here.

Thanks for the bug report.  I will try to fix this some time
this week.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1496315group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1500167 ] interpret termination, object deleting

2006-06-04 Thread SourceForge.net
Bugs item #1500167, was opened at 2006-06-03 20:55
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1500167group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Jan Martinek (johnymart)
Assigned to: Nobody/Anonymous (nobody)
Summary: interpret termination, object deleting

Initial Comment:
Hello,

I found out a strange behavior. This code

#!/usr/bin/python
class M:
  b = 0
  def __del__(self):
M.b = 0

a1 = M()

results in exception when the program terminates.

Exception exceptions.AttributeError: 'NoneType' object
has no attribute 'b' in bound method M.__del__ of
__main__.M instance at 0x2ab50a28 ignored

Note that the code must be run from an executable file
-not from the python interpretter. Otherwise the
exception is not thrown.

An interesting thing is that changing the last line to

a = M()

also prevents python from throwing the exception. Why
does it depend on variable's name?

bye
Jan Martinek

--

Comment By: Martin v. Löwis (loewis)
Date: 2006-06-04 21:56

Message:
Logged In: YES 
user_id=21627

On shutdown time, Python clears each module by replacing all
module entries with None. So at some point, it does
  a1 = None # or a1 = None
and at some other point, it does
  M = None
Depending on the order in which these happen, M might be
None (i.e. might not be class M anymore) when __del__ runs.

The order in which these happen depends on the order which
the names have in the module's dict. This, in turn, depends
on the hash values of the strings, modulo the size of the
dictionary. Apparently, a1 gets hashed after M, but a
gets hashed before M.

This isn't really a bug, atleast not one that we plan to
fix. The order in which modules get emptied is unspecified,
and it can easily happen that things are gone when some
destructor runs. Classes should be written to be resistent
against this behaviour, e.g. by writing

  def __del__(self):
self.__class__.b = 0 # name M might be gone already

Closing this as won't fix.


--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1500167group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1498051 ] MSVC compiler problems with .NET v2.0

2006-06-04 Thread SourceForge.net
Bugs item #1498051, was opened at 2006-05-31 11:15
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1498051group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Distutils
Group: Python 2.4
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Retief Gerber (hrgerber)
Assigned to: Nobody/Anonymous (nobody)
Summary: MSVC compiler problems with .NET v2.0

Initial Comment:
There is a problem with msvccompiler.py that does not 
allow it to work with MS Visual Studio 2005 and .NET 
v2.0

msvccompiler.py
__revision__ = $Id: msvccompiler.py,v 1.64.2.4 
2005/08/07 20:50:37 loewis Exp $
from line 128 

if version  7.0:
self.set_macro(FrameworkSDKDir, 
net, sdkinstallrootv1.1)
else:
self.set_macro(FrameworkSDKDir, 
net, sdkinstallroot)

should be replaced with 

if version == 7.1:
self.set_macro(FrameworkSDKDir, 
net, sdkinstallrootv2.0)
elif version  7.0:
self.set_macro(FrameworkSDKDir, 
net, sdkinstallrootv1.1)
else:
self.set_macro(FrameworkSDKDir, 
net, sdkinstallroot)

I dont have must dev experience on distutils, so this 
might not be the best solution


--

Comment By: Martin v. Löwis (loewis)
Date: 2006-06-04 22:05

Message:
Logged In: YES 
user_id=21627

This is not a bug. You shouldn't use Visual Studio 2005 to
build extensions for Python. Python extensions should be
built with the same version of the Microsoft compiler that
was used to build Python itself. For Python 2.4 and 2.5,
that's Visual Studio 2003.

Closing as not-a-bug.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1498051group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1494314 ] Cannot use high-numbered sockets in 2.4.3

2006-06-04 Thread SourceForge.net
Bugs item #1494314, was opened at 2006-05-24 15:51
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1494314group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Smith (mlrsmith)
Assigned to: Nobody/Anonymous (nobody)
Summary: Cannot use high-numbered sockets in 2.4.3

Initial Comment:
Python 2.4.3 introduced (in Modules/socketmodule.c) the
IS_SELECTABLE() macro, to check whether calling
select() on a given file descriptor is permissible.

However, it executes this check even when it won't
actually call select(). Specifically, select() is
called ONLY when s-sock_timeout  0 (in
internal_select mostly, but also internal_connect).

I have a twisted application which uses many FDs
(several thousand), and upgrading python to 2.4.3 makes
it hit this limit (at 1024 file descriptors),
regardless of ulimit settings. Twisted itself always
uses non-blocking I/O on sockets, so with older
versions of python this worked fine.

A simple solution relies on the fact that select is
only ever actually called, and changes the
IS_SELECTABLE macro as in the attached fairly trivial
patch. This is sufficient to restore my application to
its previous state (where it works fine).

This doesn't solve the more general problem in
socketmodule - that we simply can't do all operations
properly with the current reliance on select(), though,
and it seems like a bit of a hack...  If I wrote up a
patch to use poll() on systems where it's available,
throughout socketmodule.c, in preference to select(),
would this be accepted?

Mike



--

Comment By: Martin v. Löwis (loewis)
Date: 2006-06-04 22:14

Message:
Logged In: YES 
user_id=21627

A patch to replace internal_select with poll(2) where
available is acceptable. The current version should be
conditionally kept. That Windows doesn't have poll(2) is no
problem: its select implementation supports arbitrarily
large FDs (just like poll).

Relaxing the IS_SELECTABLE usage to cases where select is
actually going to be called is optional: there shouldn't be
too many systems left without select where people still want
to open many file descriptors.

--

Comment By: Tim Peters (tim_one)
Date: 2006-06-01 00:27

Message:
Logged In: YES 
user_id=31435

akuchling:  No, poll() is not part of the Windows socket API.

--

Comment By: Michael Smith (mlrsmith)
Date: 2006-05-31 23:39

Message:
Logged In: YES 
user_id=1488997

That, of course, is the problem - select() is available more
or less universally, but poll() is not. However, it's not
terribly difficult to write a poll() wrapper using select(),
though doing so in general would have serious performance
issues (the specific uses in socketmodule.c do not hit this
problem), and retains the limitations of select. 

It's not clear that the complexity of doing this is
worthwhile compared to just implementing the simple API
needed internally to socketmodule.c using both APIs (i.e.
just adding a poll() option).

Regardless, it'd be nice if at least the basic fix I wrote
up went in - it solves the immediate problem, at least.

--

Comment By: A.M. Kuchling (akuchling)
Date: 2006-05-31 20:39

Message:
Logged In: YES 
user_id=11375

I expect such a patch would be acceptable.  The largest
issue is probably whether poll() is available everywhere, or
if we'd be stuck maintaining both select() and poll() based
versions of internal_select().  Does Windows support poll()
at all?

--

Comment By: Michael Smith (mlrsmith)
Date: 2006-05-29 16:13

Message:
Logged In: YES 
user_id=1488997

Yes, I had my ulimit set appropriately.

There's no problem with _opening_ many sockets (at least, I
don't think there is) - the problem is with trying to do
something (like call socket.recv()) with them.

The code in socketmodule.c is pretty clear - and having
upgraded to 2.4.3 with ubuntu dapper, I _am_ running into this.

For now, we're having to keep all our production machines on
2.4.2.


--

Comment By: Gabriel Wicke (gabrielwicke)
Date: 2006-05-29 16:11

Message:
Logged In: YES 
user_id=956757

Please disregard my comments completely- just opening more
than 1024 files does not trigger this bug, but doing a
socket.send() on the 1025th socket does.

--

Comment By: Gabriel Wicke 

[ python-Bugs-1489051 ] keyword and topic help broken in Pythonwin IDE

2006-06-04 Thread SourceForge.net
Bugs item #1489051, was opened at 2006-05-15 20:46
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1489051group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: 3rd Party
Status: Open
Resolution: None
Priority: 5
Submitted By: BartlebyScrivener (bscrivener)
Assigned to: Martin v. Löwis (loewis)
Summary: keyword and topic help broken in Pythonwin IDE

Initial Comment:
Using ActivePython 2.4.3 on Windows XP

While in the Pythonwin IDE, if I seek keyword help by
issuing the following command:

help ('while')

I get:

Sorry, topic and keyword documentation is not available
because the Python HTML documentation files could not
be found.  If you have installed them, please set the
environment variable PYTHONDOCS to
indicate their location.

My PYTHONDOCS variable is set to:

c:\python24\Doc\Python-Docs-2.4.2\ref

which appears to be correct (ie the help html files are
installed
there).

Searching this group, I found someone else complaining
about the same behavior with no clear resolution.

http://tinyurl.com/pblev

See also

http://tinyurl.com/mbokp

--

Comment By: Martin v. Löwis (loewis)
Date: 2006-06-04 22:20

Message:
Logged In: YES 
user_id=21627

bscrivener, please run

hh -decompile c:\python24\doc\html c:\python24\Doc\python24.chm

and report whether that fixes the problem.

--

Comment By: BartlebyScrivener (bscrivener)
Date: 2006-05-30 02:45

Message:
Logged In: YES 
user_id=1523094

 From what I understand, HTML help hasn't shipped with
 Python on Windows for a few releases (likely around the
 time that .chm help files started shipping).

The two tiny urls, esp. the second one illuminate just where
the bug is in Pydoc, but the fix recommended by the poster
doesn't work. The problem happens even after downloading
html help and pointing pydoc to it in the Pythondocs
environment variable. I don't know enough to explore
further, which is why I need a nice working help function :)
I would think this would be an urgent fix for Python
evangelism.  rd

--

Comment By: Žiga Seilnacht (zseil)
Date: 2006-05-30 02:42

Message:
Logged In: YES 
user_id=1326842

The problem is on your side.
You should set the PYTHONDOCS environment variable
to the root directory of the html documentation, eg.:

PYTHONDOCS=c:\python24\Doc\Python-Docs-2.4.2

and not:

PYTHONDOCS=c:\python24\Doc\Python-Docs-2.4.2\ref


--

Comment By: Josiah Carlson (josiahcarlson)
Date: 2006-05-30 00:30

Message:
Logged In: YES 
user_id=341410

From what I understand, HTML help hasn't shipped with Python
on Windows for a few releases (likely around the time that
.chm help files started shipping).

If you've got html help files installed, and it's still not
picking them up, could you dig deeper into why this is the case.

--

Comment By: Georg Brandl (gbrandl)
Date: 2006-05-30 00:24

Message:
Logged In: YES 
user_id=849994

Okay, reopening.

--

Comment By: BartlebyScrivener (bscrivener)
Date: 2006-05-30 00:19

Message:
Logged In: YES 
user_id=1523094

Sorry, if I was unclear. IDLE is not third party, is it?

So I'm saying that on Windows XP, using the install from
Python.org help() is BROKEN. Search in the Python Google
group and you'll find many other references to same. Pydoc
no longer  provides help on topic or keywords. It will do
modules. In short it's PYDOC that is broken, not Pythonwin IDE.

Thanks,

rick

--

Comment By: Georg Brandl (gbrandl)
Date: 2006-05-29 23:00

Message:
Logged In: YES 
user_id=849994

Closing as 3rd party.

--

Comment By: BartlebyScrivener (bscrivener)
Date: 2006-05-21 02:51

Message:
Logged In: YES 
user_id=1523094

help('topic') or help('keyword') doesn't work in IDLE or
Pythonwin IDE



--

Comment By: Josiah Carlson (josiahcarlson)
Date: 2006-05-20 09:00

Message:
Logged In: YES 
user_id=341410

Since you are using the Pythonwin IDE, which was written and
is supported by Mark Hammond via the pywin32 project,
perhaps you should be visiting his project page instead:
http://sf.net/projects/pywin32

--

You can respond by visiting: 

  1   2   >