Re: How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Heiko Wundram
On Friday 13 May 2005 01:21, Christopher J. Bottaro wrote:
> For those of you following the Python Documentation thread, this is a good
> example of how the PHP manual is "better".  I found how to do this in a few
> seconds in PHP.  I searched the Python docs for "class name", "classname",
> "introspection" and "getclass".  I looked in the Class section of the
> tutorial also and also the Programming FAQ.  The "related functions"
> section of the PHP manual is really helpful.  It would be cool if in the
> section for the built-in function isinstance() or issubclass() there is a
> section for "related functions" that would point me to getclassname(obj)
> (if it exists).

There is no function to do this in Python (so you'll have a hard time finding 
it in the docs :-)), but there is a __bases__ member in any class/type which 
lists the immediate bases (and this is documented in the language reference, 
along with a reference in the tutorial when OO is introduced). Now, the 
following method lists all base classes:

def getBases(cls):
bases = []
stack = [cls]
new_stack = []
while stack:
for cls in stack:
if cls not in bases:
bases.append(cls)
new_stack.extend(cls.__bases__)
stack = new_stack
new_stack = []
return bases

Example:

>>> class x(object):
...   pass
...
>>> class y(x):
...   pass
...
>>> class z(object):
...   pass
...
>>> class a(z,y):
...   pass
...
>>> def getBases(cls):
... bases = []
... stack = [cls]
... new_stack = []
... while stack:
... for cls in stack:
... if cls not in bases:
... bases.append(cls)
... new_stack.extend(cls.__bases__)
... stack = new_stack
... new_stack = []
... return bases
...
>>> getBases(a)
[, , , , ]

HTH!

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


Re: bash like expansion

2005-05-12 Thread bill
Quick glance at the reference manual, and I think that pipes.Template
may do exactly what I want.  Is that what you're referring to?

I realized when I woke up that I have another slight irritant:
I need to be able to intelligently parse a command line.  ie
I need to correctly parse each of the following strings:

"echo foo"
"/bin/echo 'the cat'"
"$(which echo) foo"

and generate the list:
["/bin/echo", arg] where arg is either "foo" or "the cat"

I believe that Template will help me with this as well.  I'll look into
it today, after the dogs are walked...(note, shlex becomes annoying
here, as it will correctly tokenize "the cat" for me, but it splits
/bin/echo up into 4 tokens, which I now have to parse)

My current solution is to use os.system(a), but I'd much rather parse a
and use an exec function.

I'm not too concerned about portability accross different shells, as
long as it works in (ba)sh.  Also, I'm constrained to python 2.2, so I
have no doubt that there is a "shInterpret" module in 2.3 or 2.4!!

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


Re: Python Documentation (should be better?)

2005-05-12 Thread Steven Bethard
Ron Adam wrote:
> What I would like to see is something like the following for each item:
> 
> 0. reference @ sequence code
> 2. "Builtin" | "import "
> 3. Type/class: Name/Syntax
> 4. Description with examples
> 6. Links to other references of this item in docs
> 7. Links to related functions or objects in same doc type
> 8. Keywords

I'm unclear from your description.  What constitutes an "item"?  Only 
functions?  Or are types and modules "items" too?

One of the original complaints was that the page for string methods 
wasn't easily accessible.  How does this address that problem?  I guess 
you could search for all records with Type: str.  Would the constructor 
for str show up this way?

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


Re: Python Documentation (should be better?)

2005-05-12 Thread Greg Ewing
Ivan Van Laningham wrote:
> Hi All--
> The Python docs are not ideal.  I can never remember, for instance,
> where to find string methods (not methods in the string module, but
> methods with '')

Curiously I had the same problem just the other day,
except with list instead of string. I think the problem
is that the sections on the actual built-in types
(list, str, dict, etc.) are one level too far down
to appear in the table of contents of the Library
Reference.

If things could be rearranged so that their names
actually appeared in the table of contents, I think
it would make a big difference in this area.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.3.4, cx_Oracle 4.1 and utf-8 - trouble

2005-05-12 Thread Maxim Kuleshov
Hello!

Trying to fetch long varchar2 column and get the following error:

cx_Oracle.DatabaseError: column at array pos 0 fetched with error: 1406

i.e. string buffer is not much enough to fetch the string.

# fragment of code...
myCon = cx_Oracle.connect(user, psw, dsn)
myCur = myCon.cursor()
myCur.execute("""
select COLUMN from TABLE where ID=1
""")
for record in myCur.fetchall():
# ...

Error is reproduced only if actual string value longer than half of
declared column size. For short strings all is ok.

If I print myCur.description, I get:

[('COLUMN', , 250, 250, 0, 0, 1)]

250 - declared column max size, but I guess cx_Oracle allocates only 250
bytes(!), so if my string longer than 125 chars (utf-8 national char
occupies > 1 byte) - I get the error.

Is it bug or what? Any suggestions?

Extra info:
  OS - SuSE Linux 9.2
  Client - Oracle Client 9.2.0.1.0
  NLS_LANG="RUSSIAN_CIS.UTF8"

--
Best regards, Maxim Kuleshov
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Documentation (should be better?)

2005-05-12 Thread Ron Adam
Steven Bethard wrote:

> Skip Montanaro wrote:
> 
>>Mike> Given that Python hides the difference between user-defined
>>Mike> objects and built-in objects, it's not clear to me that anything
>>Mike> other than the current system, with all the classes/types in one
>>Mike> place, makes sense.
>>
>>Maybe the Module Index should be renamed "Module/Type Index" and embellished
>>with the builtin types, so that you'd find "float (builtin)", "string
>>(builtin)", "dict (builtin)", etc. in the appropriate alphabetical
>>positions.
> 
> 
> +1
> 
> Yeah, I'd love to see something like this.  My preference would actually 
> to be to leave the "Global Module Index" the same and add a "Builtin 
> Type Index" along the lines of the module index.
> 
> One of my current problems with the documentation is that, for builtin 
> types, the constructor is found in "Built-in Functions"[1], but the 
> methods are found in some subsection of "Built-in Types"[2]. 
> Additionally, the "Built-in Types"[2] section mixes protocols like the 
> Sequence, Iterator and Mapping protocols with the methods of some of the 
>   builtin types that implement these protocols.

The two manuals on my book shelf that are the most worn are Alex 
Martelli's "Python in a Nutshell", (A 2.5 version would be really nice.. 
hint to Alex), and a C pocket reference.  Both are organized by 
*subject* and not by library/include.

What I would like to see is something like the following for each item:

0. reference @ sequence code
2. "Builtin" | "import "
3. Type/class: Name/Syntax
4. Description with examples
6. Links to other references of this item in docs
7. Links to related functions or objects in same doc type
8. Keywords

In this way, each item can be a complete entry in a data base that can 
be sorted in different ways.  Alphabetical, by subject, by library,  etc...

The quick reference guide description should mirror the doc strings. 
Short but sweet if possible. Any changes to one should be made to the other.

An advanced technical language manual would also be nice for both those 
who are interested, and to record implementing details.  To start it 
could just be any current technical details that do not fit well in the 
other categories.

So summing up:

+ Each item/object in a database in a consistent way.
+ Four main categories:  Tutor, Quick Ref, Full Ref, and Technical Ref.
+ Cross reference links in each item.
+ Dependency, ie... "from  import  listed with each item.
+ keywords enabling look up and searches by subject

As it's been pointed out several times, most of this is already there. 
The hard part, and it may not be as hard as I think, is generating the 
web pages from this in a nice way, and to create a good search interface 
that can create a list of links by a chosen reference selection.

The rest of this is a matter of presentation and details.  Which I think 
  can be worked out, and done to be very similar to the existing pages.



Example from Python Docs:

4.1.3 String functions

The following functions are available to operate on string and Unicode 
objects. They are not available as string methods.

capwords(   s)
 Split the argument into words using split(), capitalize each word 
using capitalize(), and join the capitalized words using join(). Note 
that this replaces runs of whitespace characters by a single space, and 
removes leading and trailing whitespace.

maketrans(  from, to)
 Return a translation table suitable for passing to translate() or 
regex.compile(), that will map each character in from into the character 
at the same position in to; from and to must have the same length.

 Warning: Don't use strings derived from lowercase and uppercase as 
arguments; in some locales, these don't have the same length. For case 
conversions, always use lower() and upper().



Could become something like:

"""
Python Quick Ref: 4.1.3.1
import string
Function: capwords(s) -> string

Returns a copy of string  with the first letter of each word capitalized.

S = string.capwords("a lowercase string")

Also see capwords: |tutor|full_docs|tech_docs|
Related to: |string.swapcase|string.title|string.capitalize|
Keywords: |standard library|string module|function|string|capital
"""

"""
Python Quick Ref: 4.1.3.2
import string
Function: maketrans(from, to) -> table

Return a translation table suitable for passing to translate() or 
regex.compile(), that will map each character in  into the 
character at the same position in ;  and  must have the 
same length.

table = maketrans('abcdefg', 'ABCDEFG')

Also see maketrans: |tutor|full_docs|tech_docs|
Related to:|regex.compile|string.translate||string.strip|string.replace|
Keywords: |standard library|string module|function|string|change
"""


Note that each individual record is complete and stands alone, with 
links to a few other relavant items.  The keywords allow for some nice 
search results.  The notes left off would be in the full docs reference. 
  (The

Re: [perl-python] Range function

2005-05-12 Thread Jürgen Exner
Xah Lee wrote:
> Today we'll be writing a function called Range.

I don't think so. Unless you meant to write "Today WE'll be writing "

> The Perl documentation is as follows.

Bullshit. The Perl documentation is part of any Perl installation but you 
didn't link to it anywhere left alone quote it.
Actually I'm glad you didn't, it's quite large after all.

jue



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


Re: Escape spaces in strings

2005-05-12 Thread Andrew Dalke
Florian Lindner wrote:
> is there a function to escape spaces and other characters in string for
> using them as a argument to unix command? In this case rsync
> (http://samba.anu.edu.au/rsync/FAQ.html#10)

It's best that you use the subprocess module and completely skip
dealing with shell escapes.  The module is standard with 2.4 but
you can get the module and use it for 2.2 or 2.3.

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

http://cvs.sourceforge.net/viewcvs.py/*checkout*/python/python/dist/src/Lib/subprocess.py

Andrew
[EMAIL PROTECTED]

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


Re: Unique Elements in a List

2005-05-12 Thread Andrew Dalke
Scott David Daniels wrote:
> Again polynomial, not exponential time.  Note that there is no
> polynomial time algorithm with (k < 1), since it takes O(n) time
> to read the problem.

Being a stickler (I develop software after all :) quantum computers
can do better than that.  For example, Grover's algorithm
  http://en.wikipedia.org/wiki/Grover%27s_algorithm
for searching an unsorted list solves the problem in O(N**0.5) time.

Being even more picky, I think the largest N that's been tested
so far is on the order of 5.

Andrew
[EMAIL PROTECTED]

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


Re: OSx 10.4 lacks pythonIDE?

2005-05-12 Thread Robert Kern
baza wrote:
> Where is the IDE in 'Tiger' for the mac? Don't tell me I have to use 
> text edit all the time??

PythonIDE never came with the OS. You have to install it yourself.

http://homepages.cwi.nl/~jack/macpython/

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation
is as follows.

Perl & Python & Java Solutions will be posted in 48 hours.

This is Perl-Python a-day. See
http://xahlee.org/web/perl-python/python.html

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

--

Range

 Range($iMax) generates the list [1, 2, ... , $iMax].

 Range($iMin, $iMax) generates the list [$iMin, ... , $iMax].

 Range($iMin, $iMax, $iStep) uses increment $iStep, with the last
element
 in the result being less or equal to $iMax. $iStep cannot be 0. If
 $iStep is negative, then the role of $iMin and $iMax are reversed.

 If Range fails, 0 is returned.

 Example:

  Range(5); # returns [1,2,3,4,5]

  Range(5,10); # returns [5,6,7,8,9,10]

  Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8]

  Range( 5, -4, -2); # returns [5,3,1,-1,-3]

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

[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation
is as follows.

Perl & Python & Java Solutions will be posted in 48 hours.

This is Perl-Python a-day. See
http://xahlee.org/web/perl-python/python.html

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

--

Range

 Range($iMax) generates the list [1, 2, ... , $iMax].

 Range($iMin, $iMax) generates the list [$iMin, ... , $iMax].

 Range($iMin, $iMax, $iStep) uses increment $iStep, with the last
element
 in the result being less or equal to $iMax. $iStep cannot be 0. If
 $iStep is negative, then the role of $iMin and $iMax are reversed.

 If Range fails, 0 is returned.

 Example:

  Range(5); # returns [1,2,3,4,5]

  Range(5,10); # returns [5,6,7,8,9,10]

  Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8]

  Range( 5, -4, -2); # returns [5,3,1,-1,-3]

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

Re: Python features

2005-05-12 Thread Andrew Dalke
Peter Dembinski wrote:
> If you want to redirect me to Google, don't bother.  IMO ninety percent
> of writings found on WWW is just a garbage.

Sturgeon's law: Ninety percent of everything is crap. 


Andrew
[EMAIL PROTECTED]

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


OSx 10.4 lacks pythonIDE?

2005-05-12 Thread baza
Where is the IDE in 'Tiger' for the mac? Don't tell me I have to use 
text edit all the time??

B
-- 
Computer says 'No'

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


Re: tkFileDialog question

2005-05-12 Thread James Stroud
Oops,

That should have been,


class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0, columnspan=2)
self.button1 = Button(self.myContainer1,
 command=(lambda: self.button1Click()))
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("", self.button1Click)

def button1Click(self, event=None):
filePick = tkFileDialog.askopenfilename()


On Thursday 12 May 2005 03:43 pm, [EMAIL PROTECTED] wrote:
> I am creating a very simple GUI with one Entry widget and
> one Button.  The purpose of the Button widget is to Browse for
> a file using tkFileDialog.askopenfilename().
>
> I bind the button to a handler which spawns a tkFileDialog. This
> works but the button __stays depressed__ after the handler returns!
> Any ideas why?
>
> class MyApp:
>   def __init__(self, parent):
>   self.myParent = parent
>   self.myContainer1 = Frame(parent)
>   self.myContainer1.pack()
>
>   self.entry = Entry(self.myContainer1)
>   self.entry.grid(row=0,column=0 columnspan=2)
>
>   self.button1 = Button(self.myContainer1)
>   self.button1.configure(text="...")
>   self.button1.grid(row=0, column=2)
>   self.button1.bind("", self.button1Click)
>   self.button1.bind("", self.button1Click)
>
>
>   def button1Click(self, event):
>   filePick = tkFileDialog.askopenfilename()

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: tkFileDialog question

2005-05-12 Thread James Stroud
I think you are better off not binding a button like you are doing.
Use the "command" option to get the behavior you want. E.g:

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0, columnspan=2)
self.button1 = Button(self.myContainer1,
command=(lambda: self.button1Click(self)))
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("", self.button1Click)

def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()


James

On Thursday 12 May 2005 03:43 pm, [EMAIL PROTECTED] wrote:
> I am creating a very simple GUI with one Entry widget and
> one Button.  The purpose of the Button widget is to Browse for
> a file using tkFileDialog.askopenfilename().
>
> I bind the button to a handler which spawns a tkFileDialog. This
> works but the button __stays depressed__ after the handler returns!
> Any ideas why?
>
> class MyApp:
>   def __init__(self, parent):
>   self.myParent = parent
>   self.myContainer1 = Frame(parent)
>   self.myContainer1.pack()
>
>   self.entry = Entry(self.myContainer1)
>   self.entry.grid(row=0,column=0 columnspan=2)
>
>   self.button1 = Button(self.myContainer1)
>   self.button1.configure(text="...")
>   self.button1.grid(row=0, column=2)
>   self.button1.bind("", self.button1Click)
>   self.button1.bind("", self.button1Click)
>
>
>   def button1Click(self, event):
>   filePick = tkFileDialog.askopenfilename()

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Python 2.4 & BLT ?

2005-05-12 Thread Ron Adam
StepH wrote:
> Ron Adam a écrit :
> 
>>StepH wrote:
>>
>>
>>>Ron Adam a écrit :
>>>
>>>
StepH wrote:



>Hi,
>
>I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
>distibution...
>
>I'v try to download btlz-for-8.3.exe, but when i try to install it, 
>i've a msgbox saying to the file is corrupt...
>
>Any idea ?
>
>Thanks.
>
>StepH.



Have you tried blt2.4z-for-8.4exe?

http://blt.sourceforge.net
>>>
>>>
>>>
>>>yes.  When i try to execute it, a small msgbox apprea with the msg:
>>>Corrupt installation detected!
>>>
>>>Any idea ?
>>
>>
>>Sounds like it might not be a corrupted install exe file, but a 
>>previously installed version that is corrupted.
>>
> 
> 
> Hum, i've try to re-install all from scratch without success...
> 
> 
>>Does the message box say anything else?  With just "Corrupt installation 
>>detected!", it could also be a support file or missing dll that the 
>>installer needs.
> 
> 
> Yes.  It's the only message that is displayed.
> I've to go ahead...  so for now i'll use tk.Canvas for my display...
> 
> If you have idea ?

A little googling found the following which may give you a clue or ideas 
of further searches.  Also run a virus scanner on the file before hand.

http://www.noteworthysoftware.com/composer/faq/90.htm
http://www.transcender.com/faqs/detail.aspx?pn=tradwnldinstallarticle00900&full=True&tree=True
http://www.visagesoft.com/help/index.php?_a=knowledgebase&_j=questiondetails&_i=5
http://www.wise.com/KBArticle.aspx?articleno=1034

As a last resort, you may also be able to check the exe file by using a 
zip file reader such as winzip or powerarchiver.  You should be able to 
extract the individual files that way, but it may be a bit of a task to 
figure out where to put them.

Hope this helps,

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


Re: How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Bengt Richter
On Thu, 12 May 2005 23:30:21 GMT, Farshid Lashkari <[EMAIL PROTECTED]> wrote:

>This will get the name of an objects class
>
>obj.__class__.__name__
>
>This will return a tuple of its base classes
>
>obj.__class__.__bases__

But not all base classes that it inherits from, e.g.,

 >>> class C(object): pass
 ...
 >>> class B1(C): pass
 ...
 >>> class B2(C): pass
 ...
 >>> class A(B1, B2): pass
 ...
 >>> obj = A()
 >>> obj.__class__.__name__
 'A'
 >>> obj.__class__.__bases__
 (, )

 >>> type(obj)
 
 >>> type(obj).mro()
 [, , , , ]
 >>> tuple(x.__name__ for x in type(obj).mro())
 ('A', 'B1', 'B2', 'C', 'object')



>
>Christopher J. Bottaro wrote:
>> I actually want all the parent classes too.  So if D derives off C derives
>> off B derives off A, I ultimately want a tuple ('D', 'C', 'B', 'A').
>> 
>> For those of you following the Python Documentation thread, this is a good
>> example of how the PHP manual is "better".  I found how to do this in a few
>> seconds in PHP.  I searched the Python docs for "class name", "classname",
>> "introspection" and "getclass".  I looked in the Class section of the
>> tutorial also and also the Programming FAQ.  The "related functions"
>> section of the PHP manual is really helpful.  It would be cool if in the
>> section for the built-in function isinstance() or issubclass() there is a
>> section for "related functions" that would point me to getclassname(obj)
>> (if it exists).
>> 
>> Thanks for the help.
>> 
>> -- C
>> 

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


Re: Decompyle will not Compile.

2005-05-12 Thread eternl_knight
Yeah, I know the site. In fact, his service is based off of a
deriviative of the code I am trying to compile. Thanks though.

What I don't understand is the fact that I cannot locate either
"initdecompyle" or "marshal_20" in the source code, yet it appears to
compile on FreeBSD & Linux (given the fact that there are binary
packages for those platforms).

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


suspected cPickle memory leak

2005-05-12 Thread Al Franz
 I believe there is a memory leak in cPickle.  I am using python2.2.  I 
have a parallel code which uses array() and indices() from Numeric to 
massage data buffers before being sent and received by Pypar.  Pypar 
subsequently uses cPickle to pickle the data.  After many hours of 
execution, my code crashes with one of the following error messages 
(depending upon the run):

 a = zeros(shape, typecode, savespace)
MemoryError:  can't allocate memory for array

or:

 s = dumps(x, 1)
MemoryError:  out of memory

I have since modified my code to use a different data format so cPickle is 
no longer used from PyPar and now the code runs fine.

 -- Al Franz
 Computer Scientist
 Lawrence Livermore National Laboratory 


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


Re: How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Farshid Lashkari
This will get the name of an objects class

obj.__class__.__name__

This will return a tuple of its base classes

obj.__class__.__bases__

Christopher J. Bottaro wrote:
> I actually want all the parent classes too.  So if D derives off C derives
> off B derives off A, I ultimately want a tuple ('D', 'C', 'B', 'A').
> 
> For those of you following the Python Documentation thread, this is a good
> example of how the PHP manual is "better".  I found how to do this in a few
> seconds in PHP.  I searched the Python docs for "class name", "classname",
> "introspection" and "getclass".  I looked in the Class section of the
> tutorial also and also the Programming FAQ.  The "related functions"
> section of the PHP manual is really helpful.  It would be cool if in the
> section for the built-in function isinstance() or issubclass() there is a
> section for "related functions" that would point me to getclassname(obj)
> (if it exists).
> 
> Thanks for the help.
> 
> -- C
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python features

2005-05-12 Thread Lonnie Princehouse

> Quoting from that link:
> There are three main types of programming languages.
>
>  * Imperative
>  * Functional
>  * Declarative
>

Aren't functional languages a subset of declarative?

(c.f. http://en.wikipedia.org/wiki/Declarative_programming)

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


How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Christopher J. Bottaro
I actually want all the parent classes too.  So if D derives off C derives
off B derives off A, I ultimately want a tuple ('D', 'C', 'B', 'A').

For those of you following the Python Documentation thread, this is a good
example of how the PHP manual is "better".  I found how to do this in a few
seconds in PHP.  I searched the Python docs for "class name", "classname",
"introspection" and "getclass".  I looked in the Class section of the
tutorial also and also the Programming FAQ.  The "related functions"
section of the PHP manual is really helpful.  It would be cool if in the
section for the built-in function isinstance() or issubclass() there is a
section for "related functions" that would point me to getclassname(obj)
(if it exists).

Thanks for the help.

-- C

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


tkFileDialog question

2005-05-12 Thread jaime . suarez
I am creating a very simple GUI with one Entry widget and
one Button.  The purpose of the Button widget is to Browse for
a file using tkFileDialog.askopenfilename().

I bind the button to a handler which spawns a tkFileDialog. This
works but the button __stays depressed__ after the handler returns!
Any ideas why?

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0 columnspan=2)

self.button1 = Button(self.myContainer1)
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("", self.button1Click)
self.button1.bind("", self.button1Click)


def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()

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


Re: bash like expansion

2005-05-12 Thread Mike Meyer
"bill" <[EMAIL PROTECTED]> writes:

> Consider the following:
>
> import os, commands
> os.environ['QWE']="string with foo"
> a = '$QWE  ${QWE/foo/baz}'
> b = commands.getoutput('echo ' + a)
>
>
> This does what I want, which is to expand
> a according to the standard bash expansion rules
> (so b now references "string with foo string with baz"),
> but it doesn't feel right.
>
> Is there a more pythonic way to interpret strings according
> to shell rules for word expansion?  Relying on commands
> feels like a kludge, and shlex is way too much work for this
> (not to mention that it doesn't really address the issue).

Well, if you really want shell rules, I think you're out of
luck. Espcially since those rules tend to vary depending on what shell
you're running. I don't think that even shlex will do what you want.
If you just want the simple cases you used in your example, you might
check out the Template module in 2.4.

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


Re: pyvm -- faster python

2005-05-12 Thread Mike Meyer
Paul Rubin  writes:

> Andrew Dalke <[EMAIL PROTECTED]> writes:
>
>> Years ago, presented at one of the Python conferences, was a program
>> to generate C code from the byte code  The conclusion I recall
>> was that it wasn't faster - at best a few percent - and there was a
>> big memory hit because of all the duplicated code.  One thought was
>> that the cache miss caused some of the performance problems.  Does
>> that count as a compiler?
>
> I would say it counts as a compiler and that other languages have
> used a similar compilation approach and gotten much better speedups.
> For example, Java JIT compilers.  The DEC Scheme-to-C translator
> and Kyoto Common Lisp also produced C output from their compilers
> and got really significant speedups.  Part of the problem may be
> with the actual Python language.

The DEC Scheme->C compiler (yes, it was an honest to gods compiler -
it just generated C instead of machine code) doesn't sound very
similar to generating C code from byte code. The latter sounds like a
straightforward translation of byte code to C.  The Scheme->C
compiler, on the other hand, used all the optimizations known to LISP
compiler writers. It would, with the right settings, produce code that
was comparable to hand-coded C. So unless the Python compiler that
produced the byte code in the first place does all those optimizations
(which I don't know), you're not going to get results that compare
with the Scheme->C system.

> Despite the shrieks of the "Python is not Lisp!" crowd, Python
> semantics and Lisp semantics aren't THAT different, and yet compiled
> Lisp implementations com completely beat the pants off of interpreted
> Python in terms of performance.  I don't think Python can ever beat
> carefully coded C for running speed, but it can and should aim for
> parity with compiled Lisp.

There are people out there who claim that compiling carefully coded
LISP can compete with compiling carefully coded C. They use such
systems in real-world, time-critical applications. The thing is, to
get that performance, they had to go back and tell the compiler what
the types of all the variables are, and disable all the runtime type
checking.

So if this is a real goal, you now have some idea of what to look
forward to in Python's future.

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


Re: Launch file in Notepad

2005-05-12 Thread Brian van den Broek
Fredrik Lundh said unto the world upon 2005-05-12 13:52:
> Brian van den Broek wrote:
> 
> 
>>>I'm trying to lauch Notepad from Python to open a textfile:
>>>
>>>import os
>>>b1="c:\test.txt"
>>>os.system('notepad.exe ' + b1)
>>>
>>>However, the t of test is escaped by the \, resulting in Notepad trying
>>>to open "c: est.txt".
>>>
>>>How do I solve this?
>>
>>There are several ways, but the preferred solution is to switch the
>>slash direction: "c:/test.txt". Python's smart enough to notice its
>>running on Windows and do the right thing with the slash.
> 
> 
> that's slightly misleading: on the API level, most functions can handle
> both kinds of slashes.  functions like open(), os.remove(), shutil.copy()
> etc. handles either case just fine.  and in most cases, this is handled
> on the Win API level (or in the C library), not by Python.
> 
> however, in this case, the user passes a string to os.system().  that
> string is passed *as is* to the command shell (which, in this case,
> passes it on to notepad.exe as is).
> 
> 

Thanks to Fredrik and everyone else who contributed to the thread to 
correct my mistake.

Best to all,

Brian vdB

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


Re: pyvm -- faster python

2005-05-12 Thread Paul Rubin
Rocco Moretti <[EMAIL PROTECTED]> writes:
> Python, as a procedural language, makes extensive use of globals &
> mutable variables  IIUC, in Lisp, as a functional language, "all
> politics is local."  Global-like variables are much rarer, and
> mutability is severely limited.

Some people write Lisp code in a functional style, but not everyone.
Lisp provides mutable objects as much as Python does--maybe more,
for example, Lisp strings are mutable.  Overall I'd say there's not
much difference between Lisp and Python in this regard.  Lisp lets
the programmer supply static type declarations that the compiler
can use, but those are optional.  When you use them, you get faster
output code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with csv module

2005-05-12 Thread John Machin
On Wed, 11 May 2005 23:52:56 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote:

>John Machin <[EMAIL PROTECTED]> writes:
>> The CSV format is not defined at all, AFAIK.
>
>Just for the record, http://www.ietf.org/internet-drafts/draft-shafranovich-mime-csv-05.txt
>
"  Bletch"   ,"""Bletch""",   "Bletch   "

Fortunately, being a draft, it's not "for the record". 

Anyway, thanks for pointing that out.


>. You'll also see application that deal with the application/csv MIME
>type.

I'm sorry; my parser's on the fritz: I'll see (when? where?) what
application(s?) that deal with the (proposed?) MIME type?


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


Re: Python Documentation (should be better?)

2005-05-12 Thread Rocco Moretti
Terry Hancock wrote:

> *But you do have to remember that strings are documented under "sequences"
> this is probably my biggest complaint about the Library Reference --- 
> something
> as important as string methods should have its own heading in the top-level
> outline.  But that's a nitpick, of course.

I'd agree. My one complaint about the documentation, if I had one, would 
be that the organizational structure is non-intuitive. ("Why are 
dictionaries/lists/strings part of the 'library'?") But once you get the 
organization down, I have few complaints.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Launch file in Notepad

2005-05-12 Thread Greg Krohn
George wrote:
> Newbie question:
> 
> I'm trying to lauch Notepad from Python to open a textfile:
> 
> import os
> b1="c:\test.txt"
> os.system('notepad.exe ' + b1)
> 
> However, the t of test is escaped by the \, resulting in Notepad trying 
> to open "c: est.txt".
> 
> How do I solve this?
> 
> (By the way, b1 comes from a command line parameter, so the user enters 
> c:\test.txt as command line parameter.)
> 
> George

The \t will only be interpreted as TAB if it was entered as part of
your python code. If the \t was entered as a command line arg it will
be interpreted as a \ and a t. For example:


#test.py
import sys
b1 = sys.argv[1]
b2 = "C:\test.txt"
print b1
print b2

will result in this:

C:\>test.py C:\test.txt
C:\test.txt
C:  est.txt


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


Re: TAKE_FOCUS

2005-05-12 Thread phil

Thanks, works great.


>>I have a function I need to run when the window
>>gets the focus. How do you do that in Tkinter
>>on Win32?
>>
> 
> binding the  event should work.
> 
> (and make sure that the takefocus option is set)


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


Re: pyvm -- faster python

2005-05-12 Thread Rocco Moretti
Paul Rubin wrote:

> Despite the shrieks of the "Python is not Lisp!" crowd, Python
> semantics and Lisp semantics aren't THAT different, and yet compiled
> Lisp implementations com completely beat the pants off of interpreted
> Python in terms of performance.  

I know little about Lisp compilation, so I could be mistaken, but I was 
under the impression that one of the differences between Python & Lisp 
is directly relevant to compilation issues.

Python, as a procedural language, makes extensive use of globals & 
mutable variables. Not only can the contents of a variable change, but 
that change can non-explicitly affect a function in a "remote" part of 
the program, hence the requirement for the Global Interpreter Lock. 
Tracking how changes propagate in Python is non-trivial, as evidenced by 
the difficulty of replacing the GIL with a less "obtrusive" alternative.

IIUC, in Lisp, as a functional language, "all politics is local." 
Global-like variables are much rarer, and mutability is severely 
limited. In this case it is much easier to track how a piece of code 
alters the program's state - the propagation of those changes are 
handled explicitly, and once you have a reference to a piece of data, 
you don't have to worry about some other function changing the value on 
you. As such, it's a lot easier to write an optimizing compiler - you 
can place much greater limits on what is known at compile time.

It's been quite a while since I've looked at Lisp/functional languages, 
though, so I could be misunderstanding what I remember.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bash like expansion

2005-05-12 Thread Paul McGuire
Something in this vein?

>>> baseString = "string with %s"
>>> [ baseString % ss for ss in ('foo', 'baz') ]
['string with foo', 'string with baz']
>>> b = " ".join([ baseString % ss for ss in ('foo', 'baz') ])
>>> b
'string with foo string with baz'
>>>

-- Paul

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


Re: Launch file in Notepad

2005-05-12 Thread Bengt Richter
On Thu, 12 May 2005 16:30:36 GMT, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

>On Thu, 12 May 2005 15:14:09 GMT, [EMAIL PROTECTED] (Bengt Richter) declaimed
>the following in comp.lang.python:
>
>
>> 
>> I don't know why MS used backslashes when unix had a perfectly good path 
>> syntax
>> (not to mention drive letter idiocy). Maybe some legal idiocy, wanting to be
>> different to be safe from SCO types?
>>
>   The MS-DOS precursor (and/or CP/M) used "/" to introduce command
>line options. This meant, when subdirectories were introduced, they had
>to come up with a new separator character.
>
Or overcome some NIH and switch to '-' for command line options? ;-)

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


Re: Exception value cut off

2005-05-12 Thread Fredrik Lundh
"Ryan, Adam" wrote:

> sys.exc_info()[1] returns the first 308 characters of an error message from
> a module.  Is there a way to increase the length so it doesn't get cut off?

sys.exc_info()[1] returns the entire contents of the exception parameter.
if it's cut off, it's either cut off by the code raising the exception (C code
sometimes uses a fixed-size buffer to format the exception string), or by
the tool you're using to display the exception.





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


Re: Python features

2005-05-12 Thread david . tolpin
> There are three main types of programming languages.
>
>  * Imperative
>  * Functional
>  * Declarative
>

animals are divided into:

* those that belong to the Emperor,
* embalmed ones,
* those that are trained,
* suckling pigs,
* mermaids,
* fabulous ones,
* stray dogs,
* those included in the present classification,
* those that tremble as if they were mad,
* innumerable ones,
* those drawn with a very fine camelhair brush,
* others,
* those that have just broken a flower vase,
* those that from a long way off look like flies.

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


Re: Problem combining python code and html

2005-05-12 Thread Hansan
Hi all and thanks for the help, With help from Fredrik I got the code 
working, I will also look into the links you guys have suggested.
Hope you all are feeling well and happy.



"has" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hansan wrote:
>
>> And is there a nother way to combine python code and html templates?
>
> There's a decent list of Python templating engines at:
>
> http://www.python.org/moin/WebProgramming
>
> Look about a third of the way down down under "Variable
> Insertion-Replacement Templating Applications (Pre-processors)". The
> title is ridiculous but the links are sound.
>
> HTH
> 


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


Re: Interactive shell for demonstration purposes

2005-05-12 Thread Bengt Richter
On Thu, 12 May 2005 17:41:29 +0200, Brian Quinlan <[EMAIL PROTECTED]> wrote:

>Bengt Richter wrote:
>> If you make your console 96 wide and set the font to Lucida Console Bold 
>> 24point,
>> it will probably expand to near full screen on 1024x768. You can set the 
>> scroll buffer
>> to a couple hundred lines and adjust console widow height to suit. Use the 
>> properties
>> from the system icon, or get there by Alt-Space P etc.
>
>That's not bad. There are two caveats:
>1. you have to set the width to 72 characters (instead of 80) at
>1024x768 with 24 point fonts
Well, you don't _have_ to ;-) E.g., I have my screen buffer size set to 96 wide 
and 200 high,
so when I select 24-pt bold Lucida Console, I don't see more than about 68 
characters within
the frame, but I can scroll horizontally to see to the 96 limit. If I output 
more than 96 wide,
it wraps to the next line. You may want to set wrap/buffer width at 72, but 
that's a choice, not
a have-to, at least on my system ;-)

>2. you can't run in full-screen mode
Well, my system permits it, sort of, but it does force some layout and ugly 
raster font that reminds
of a black BSOD and is probably controlled by some registry stuff that I am too 
lazy to pursue.
I had to kill it (the console window) to get back to a normal console window, 
but that is probably
because I don't know the secret incantation off hand ;-/

Anyway, HIIH (happy if it helped ;-)

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


Re: How "return" no return ?

2005-05-12 Thread kaerbuhez
Ximo a écrit :
> I am doing my own interpreter with the Python languaje.
> 
> Do you understand me?
> 

I will do my best : I guess that you are about to write your own non 
python interpreter (I mean, it will interpret some language that is not 
Python) and your interpreter sadly writes "None" when there is none to 
write.
Is that correct ?
If yes, I suggest that you replace somewhere in your code:
print result
by
if result is not None: print result

I know that this is not the question but if it is right that your 
interpreter is not a python interpreter and that you build a console on 
top of it (I know many assumptions, ...), I would like to kindly suggest 
you to use something else that the Python prompt (">>>") - at least on 
this NG - I am afraid that _this_ didn't help anybody to understand what 
you meant.

If by pure coincidence, this helped you, it would unexpectingly enlight 
my day ... and please don't tell me that my english is perfect, I know 
it perfectly well.

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


Re: Escape spaces in strings

2005-05-12 Thread Jp Calderone
On Fri, 13 May 2005 00:49:21 +0200, Florian Lindner <[EMAIL PROTECTED]> wrote:
>Hello,
>is there a function to escape spaces and other characters in string for
>using them as a argument to unix command? In this case rsync
>(http://samba.anu.edu.au/rsync/FAQ.html#10)
>
>Thx,
>
>Florian

  Yes, but you don't want to use them.  Instead, use a process launching 
function which doesn't smoosh arguments together into a single string which 
then needs to be parsed.  For example, os.execl, os.spawnl, or subprocess.call.

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


Re: Python Polymorphism

2005-05-12 Thread Fredrik Lundh
Carlos Moreira wrote:

> Supose that I want to create two methos (inside a
> class) with exactly same name, but number of
> parameters different:

that's known as multimethods, or multiple dispatch.  it's a kind of
polymorphism; it's not the only way to do it, nor is it the only thing
that qualifies as polymorphism.

(in OO lingo, polymorphism usually means that a variable can hold
objects of different types/classes, and that the language can per-
form a given operation on an object without having to know in ad-
vance what type/class it belongs to).

Python only supports single-dispatch in itself, but you can use the
existing mechanisms to implement multimethods in different ways.
for some ways to do it, see:

http://www.artima.com/weblogs/viewpost.jsp?thread=101605
http://www-106.ibm.com/developerworks/library/l-pydisp.html

however, solving your problem is of course trivial; just change

> class myClass:
>  myAttribute = 0
>  def myMethod(self):
>   self.myAttribute += 1
>  def myMethod(self, myValue):
>   self.myAttribute += myValue

to

class myClass:
myAttribute = 0
def myMethod(self, myValue=1):
self.myAttribute += myValue

and you're done.

> I want to use the power of polymorphism to modelate
> the problem.

the problem you described can be trivially solved with a default
argument.  maybe you should come up with a more realistic pro-
blem?





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


Escape spaces in strings

2005-05-12 Thread Florian Lindner
Hello,
is there a function to escape spaces and other characters in string for
using them as a argument to unix command? In this case rsync
(http://samba.anu.edu.au/rsync/FAQ.html#10)

Thx,

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


Re: Python 2.4 & BLT ?

2005-05-12 Thread StepH
Ron Adam a écrit :
> StepH wrote:
> 
>> Ron Adam a écrit :
>>
>>> StepH wrote:
>>>
>>>
 Hi,

 I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
 distibution...

 I'v try to download btlz-for-8.3.exe, but when i try to install it, 
 i've a msgbox saying to the file is corrupt...

 Any idea ?

 Thanks.

 StepH.
>>>
>>>
>>>
>>> Have you tried blt2.4z-for-8.4exe?
>>>
>>> http://blt.sourceforge.net
>>
>>
>>
>> yes.  When i try to execute it, a small msgbox apprea with the msg:
>> Corrupt installation detected!
>>
>> Any idea ?
> 
> 
> Sounds like it might not be a corrupted install exe file, but a 
> previously installed version that is corrupted.
>

Hum, i've try to re-install all from scratch without success...

> Does the message box say anything else?  With just "Corrupt installation 
> detected!", it could also be a support file or missing dll that the 
> installer needs.

Yes.  It's the only message that is displayed.
I've to go ahead...  so for now i'll use tk.Canvas for my display...

If you have idea ?

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


Re: pyvm -- faster python

2005-05-12 Thread François Pinard
[Paul Rubin]

> François Pinard <[EMAIL PROTECTED]> writes:
>
> > Deep down, why or how not having a [traditional, to-native-code]
> > compiler is a deficiency for CPython?  We already know that such a
> > beast would not increase speed so significantly, while using much
> > more memory.

> I'd say the opposite.  The 4x speedup from Psyco is quite significant.
> The speedup would be even greater if the language itself were more
> compiler-friendly.

Psyco is not a traditional compiler.  Compilation occurs at run-time, as
typing information is not available without observation.

> > So far, it seems that the only way to get speed is to attach static
> > type information to some variables.

> No of course not, there's quite a bit of overhead in interpretation in
> general.  Plus, having to do a dictionary lookup for 'bar' in every
> call like foo.bar() adds overhead and I don't think I'd call fixing
> that as similar to adding static type info.

The dictionary lookup does not occur for local variables.  Changes are
planned in Python so lookups may be avoided in a few cases of global
variables.  But until (and despite!) such changes occur, compilation
does not buy you much, here.  This has been much studied and debated.

> > Some compilation avenues do it through information added either in
> > Python source code or in extraneous declarative files, other
> > approaches do it by delaying compilation until such information is
> > discovered at run-time.

> Also, lots of times one can do type inference at compile time.

Yes, particularily in simple or small programs.  I vaguely remember
that the unborn Viper (or Vyper?) was promising compile time type
inference.  It seems that so far, in many years, no one really succeeded
in demonstrating a definite advantage in this direction, at least, not
enough for the community to follow in.

> > The former taints the purity of real CPython as the only source.

> I don't understand this.  What purity?  Why is real CPython the
> only source?  There are dozens of C compilers and none of them is
> the "only source".  Why should Python be different?

Because it is.  There are not dozens of Python compilers.  A few, maybe.

Pyrex gives me a lot of speed, given I taint my Python sources with
cdefs, ctypes, etc.  Oh, I'm absolutely happy with Pyrex when I starve
for speed, but I know and you know that we are not writing pure Python
then.  And if, for not touching sources, one supplements them with
separate declarative files, my Python code may look pure, but I have to
maintain those files as well, and Python is not my only source anymore.

So, to get back to the origin of our argument, I'm still not tempted
to think that Python not having a compiler makes it deficient, because
having a compiler (at least in the traditional acceptation of the term)
would not buy it much enough.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter puzzler

2005-05-12 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

>I have a gui with a bunch of buttons, labels, the usual stuff.  It
>uses the grid manager:
>
>   gui = Frame()
>   gui.grid()
>   gui.Label().grid()  # put some widgets into the gui
>   ...# more widgets
>
>Now at the the very bottom of the gui, I want to add two more buttons,
>let's say "stop" and "go".  I want "stop" to appear in the gui's lower
>left corner and "go" to appear in the gui's lower right corner.
>Suppose that up to now, row 16 is the last row in the gui.  Then this
>works:
>
>Button(gui, text="stop").grid(sticky=W)   # starts row 17
>Button(gui, text="go").grid(row=17, column=1, sticky=E)
>
>But I don't really want that hardwired row number and I don't want to
>keep counting rows and adjusting stuff if I stick new rows in the gui.

A couple of options here:
- Put the main portion of the gui into one frame and pack or grid the 
button frame below that. That sounds like a natural solution to this 
problem based on the way you describe it. (if you do that, I suggest 
packing the buttons into their frame; although I usually use the gridder 
when in doubt, the packer is often the most natural layout manager for a 
row of buttons).

- Increment as you go:
   row = 0

   wdg.grid(row=row, column=0, ...)
   row += 1

   wdg2.grid(row=row, column=0, ...)
   row += 1

- If you are doing a lot of similar layout, it is worth creating a class 
to do your gridding for you. Each instance grids widgets in a particular 
frame. It keeps  track of the row # for you. For use an existing 
gridder, for instance RO.Wdg.Gridder in the RO package 
.


>So I try the obvious, make one Frame widget containing both new buttons:
>stopgo = Frame(gui)
>Button(stopgo, "stop").grid(sticky=W)
>Button(stopgo, "go").grid(sticky=E)
>
>and try to stretch it across the bottom row of the gui:
>
>stopgo.grid(sticky=E+W)

This looks OK to me so I'm not sure what's wrong; I think I'd have to 
see your actual code. I suggest examining the size of the stopgo frame 
by setting its background color.

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


Re: Python Polymorphism

2005-05-12 Thread infidel
carlos> Supose that I want to create two methos (inside a
carlos> class) with exactly same name, but number of
carlos> parameters different

That isn't polymorphism, that's function overloading.

carlos> Look, I don't want to use things like:
carlos>
carlos>   def myMethod(self, myValue=None):
carlos>if(not myValue):
carlos> self.myAttribute += 1
carlos>else:
carlos> self.myAttribute += myValue

Pick another language then.  Or try:

def myMethod(self, myValue=1):
self.myAttribute += myValue

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


Re: Python Polymorphism

2005-05-12 Thread Roel Schroeven
Carlos Moreira wrote:

> So, let's try again.
> Supose that I want to create two methos (inside a
> class) with exactly same name, but number of
> parameters different:
> 
> class myClass:
>  myAttribute = 0
>  def myMethod(self):
>   self.myAttribute += 1
>  def myMethod(self, myValue):
>   self.myAttribute += myValue
> 
> Both method hold same identifier, the only difference
> in them signture are parameters.
> How could I simulate the situation above, using the
> language dynamic link (or polymorphism, as you
> prefer)?

Ah, that's not polymorphism; it's method overloading. And AFAIK it is 
not possible in Python.

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

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


Re: Python Polymorphism

2005-05-12 Thread Dan Sommers
On Thu, 12 May 2005 13:00:45 -0700 (PDT),
Carlos Moreira <[EMAIL PROTECTED]> wrote:

> Look, I don't want to use things like:

> 
>   def myMethod(self, myValue=None):
>if(not myValue):
> self.myAttribute += 1
>else:
> self.myAttribute += myValue
> 

How about:

def myMethod( self, myValue = 1 ):
self.myAttribute += myValue

Callers of myMethod look exactly like they would look if you had written
two methods:

a.myMethod( ) # add 1 to a.myAttribute
a.myMethod( 22 ) # add 22 to a.myAttribute

> I want to use the power of polymorphism to modelate the problem.

Polymorphism in Python is a solution looking for a problem.

Regards,
Dan

-- 
Dan Sommers

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


Re: Python features

2005-05-12 Thread Gary D. Duzan
In article <[EMAIL PROTECTED]>,
Peter Dembinski <[EMAIL PROTECTED]> wrote:
>
>
>On Sun, 08 May 2005 10:02:42 +0200, André Roberge  
><[EMAIL PROTECTED]> wrote:
>
>> Imperative programming languages are the most commonly used languages.  
>> Examples of this type of language are C, C++, Ada, Fortran, Algol, Java,  
>> Python, Perl, and so on.
>
>How about lambda construction?  Isn't Python imperative language that
>includes some functional mixins?
>
>I mean -- can you say Python is fully imperative language?

   I don't know that "fully imperative" is necessarily meaningful.
We could say that Python supports statements which don't rebind a
variable to a value, but that doesn't seem helpful.  You can do
things without side effects in Python, and you can use things in
a functional style like map, but the overall language more closely
reflects an imperative style, so we call it an imperative language.

Gary Duzan
BBN Technologies


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

Re: Problem combining python code and html

2005-05-12 Thread has
Hansan wrote:

> And is there a nother way to combine python code and html templates?

There's a decent list of Python templating engines at:

http://www.python.org/moin/WebProgramming

Look about a third of the way down down under "Variable
Insertion-Replacement Templating Applications (Pre-processors)". The
title is ridiculous but the links are sound.

HTH

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


Exception value cut off

2005-05-12 Thread Ryan, Adam

sys.exc_info()[1] returns the first 308 characters of an error message from
a module.  Is there a way to increase the length so it doesn't get cut off?

Cheers,

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


Re: Python Polymorphism

2005-05-12 Thread Carlos Moreira

--- Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> so phrases like

 

> (etc)
> 
> doesn't tell you that polymorphism is a fundamental
> part of the language,
> and used all over the place.  or did you have a
> non-OO meaning of the
> word in mind?

Ok, I prefer to think that I could be more specific.
So, let's try again.
Supose that I want to create two methos (inside a
class) with exactly same name, but number of
parameters different:

class myClass:
 myAttribute = 0
 def myMethod(self):
  self.myAttribute += 1
 def myMethod(self, myValue):
  self.myAttribute += myValue

Both method hold same identifier, the only difference
in them signture are parameters.
How could I simulate the situation above, using the
language dynamic link (or polymorphism, as you
prefer)?

Look, I don't want to use things like:


  def myMethod(self, myValue=None):
   if(not myValue):
self.myAttribute += 1
   else:
self.myAttribute += myValue


I want to use the power of polymorphism to modelate
the problem.

   Thanks and best regards

Cadu Moreira



__ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search. 
http://info.mail.yahoo.com/mail_250
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-12 Thread Edvard Majakari
Scott David Daniels <[EMAIL PROTECTED]> writes:

> Normally this is called a polynomial, rather than exponential increase.
> Exponential increases are typically of the form (C^N) (they are all
> equivalent).
> Polynomial times are hallways characterized by their largest exponent,
> So you never call something O(N^3 - N^2) Since, as N gets large enough,
> The N^2 term shrinks to non-existence.

Yup, you are of course, completely correct. I was thinking of "exponent here
is two" and mistakenly named in exponential. 

my_text.replace('exponent','polynom'), there :)

Reminding of ignoring terms with smaller exponent was good, too.

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exPyCrypto confusion

2005-05-12 Thread Kip Lehman

The example[2,3,4].py files in the ezPyCrypto are instructive.

Using the techniques in those files and modifying your test script,
the desired behavior is attainable.

Two items had to be changed.  
Instead of k.exportKey(), you have to use k.exportKeyPrivate(). 
On the other end instead of ke.decString() you have to use the 
decStringFromAscii() method.

amended script--
import os
import ezPyCrypto

###

KEY_FILE = '/Users/scott/pyprogs/the_key.txt'

###

msg = 'Meeting delayed 30 hours'
print "plaintext msg: %s" % msg
print '-' * 48
k = ezPyCrypto.key(512)

cipher = k.encStringToAscii(msg)
print cipher
print '-' * 48

decoded1 = k.decStringFromAscii(cipher)
print "recovered msg: %s" % decoded1

print '-' * 48, '\n'

# So far so good. encrypted and decrypted as expected.
# Now try to put the key in a file for transport on eg a USB drive.

pubPrivKey = k.exportKeyPrivate()
print "pubPrivKey:\n%s" % pubPrivKey
f = open(TEST_KEY_FILE, 'w')
f.write(pubPrivKey)
f.close()
print "pubPrivKey written to file -> %s" % os.path.basename(KEY_FILE)
print '-' * 48, '\n'

# Now get string representation of pubPrivKey and use it to create
# a new key instance (nk) that can be used to decode the cipher

f = open(TEST_KEY_FILE, 'r')
inPubPrivKey = f.read()
f.close()

# create a new key object and auto-import private key
nk = ezPyCrypto.key(inPubPrivKey)
print "pubPrivKey read in from file -> %s, new key instance created" % \
  os.path.basename(KEY_FILE)
decoded2 = nk.decStringFromAscii(cipher)
print "recovered msg using pubPrivKey: %s" % decoded2

end script--

Happy en/de crypting...

Kip Lehman
kipster  t  earthlink  net



--
Still waiting for PanAm, Amtrack and the USPS to deliver my .sig

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


Re: pyvm -- faster python

2005-05-12 Thread david . tolpin
> I don't think Python can ever beat
> carefully coded C for running speed, but it can and should aim for
> parity with compiled Lisp.

But common lisp compilers often beat C compilers in speed for similar
tasks
of moderate complexity. In particular, CMUCL beats GCC in numerical
computations.

David

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


Re: increment bits

2005-05-12 Thread Bill Mill
On 12 May 2005 12:19:15 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> How do i manipulate arrays to increment 8 bits at a time.
> 
> I need to generate a pattern like
> 01,02,03,.0xFF

>>> [hex(n) for n in range(256)]
['0x0', '0x1', '0x2', '0x3', '0x4', '0x5', '0x6', '0x7', '0x8', '0x9', '0xa', '0
xb', '0xc', '0xd', '0xe', '0xf', '0x10', '0x11', '0x12', '0x13', '0x14', '0x15',
 '0x16', '0x17', '0x18', '0x19', '0x1a', '0x1b', '0x1c', '0x1d', '0x1e', '0x1f',

 '0xe8', '0xe9', '0xea', '0xeb', '0xec', '0xed', '0xee', '0xef', '0xf0', '0xf1',
 '0xf2', '0xf3', '0xf4', '0xf5', '0xf6', '0xf7', '0xf8', '0xf9', '0xfa', '0xfb',
 '0xfc', '0xfd', '0xfe', '0xff']

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


Re: pyvm -- faster python

2005-05-12 Thread Paul Rubin
Andrew Dalke <[EMAIL PROTECTED]> writes:

> Years ago, presented at one of the Python conferences, was a program
> to generate C code from the byte code  The conclusion I recall
> was that it wasn't faster - at best a few percent - and there was a
> big memory hit because of all the duplicated code.  One thought was
> that the cache miss caused some of the performance problems.  Does
> that count as a compiler?

I would say it counts as a compiler and that other languages have
used a similar compilation approach and gotten much better speedups.
For example, Java JIT compilers.  The DEC Scheme-to-C translator
and Kyoto Common Lisp also produced C output from their compilers
and got really significant speedups.  Part of the problem may be
with the actual Python language.  One of the reasons for wanting
real compilation as a high priority, is that the presence of a
compiler will affect future evolution of the language, in a way
that makes it more conducive to compilation.

Despite the shrieks of the "Python is not Lisp!" crowd, Python
semantics and Lisp semantics aren't THAT different, and yet compiled
Lisp implementations com completely beat the pants off of interpreted
Python in terms of performance.  I don't think Python can ever beat
carefully coded C for running speed, but it can and should aim for
parity with compiled Lisp.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyvm -- faster python

2005-05-12 Thread Paul Rubin
François Pinard <[EMAIL PROTECTED]> writes:
> Deep down, why or how not having a [traditional, to-native-code]
> compiler is a deficiency for CPython?  We already know that such a beast
> would not increase speed so significantly, while using much more memory.

I'd say the opposite.  The 4x speedup from Psyco is quite significant.
The speedup would be even greater if the language itself were more
compiler-friendly.

> So far, it seems that the only way to get speed is to attach static
> type information to some variables.  

No of course not, there's quite a bit of overhead in interpretation in
general.  Plus, having to do a dictionary lookup for 'bar' in every
call like foo.bar() adds overhead and I don't think I'd call fixing
that as similar to adding static type info.

> Some compilation avenues do it through information added either in
> Python source code or in extraneous declarative files, other
> approaches do it by delaying compilation until such information is
> discovered at run-time.

Also, lots of times one can do type inference at compile time.

> The former taints the purity of real CPython as the only source.

I don't understand this.  What purity?  Why is real CPython the
only source?  There are dozens of C compilers and none of them is
the "only source".  Why should Python be different?
-- 
http://mail.python.org/mailman/listinfo/python-list


increment bits

2005-05-12 Thread [EMAIL PROTECTED]
Hello,

How do i manipulate arrays to increment 8 bits at a time.

I need to generate a pattern like
01,02,03,.0xFF

Thanks,
-Ashton

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


Re: How "return" no return ?

2005-05-12 Thread Michael Spencer
Ximo wrote:
> I am doing my own interpreter with the Python languaje.
> 
> Do you understand me?
> 
> 
> 
> "Fredrik Lundh" <[EMAIL PROTECTED]> escribió en el mensaje 
> news:[EMAIL PROTECTED]
> 
>>"Ximo" wrote:
>>
>>
>>>I am doing a interpret of lines and it show me a prompt, and I want if I
>>>write a declaration as "int a" my progrtam return de prompt and nothing
>>>more, for exemple:
>>>
>>>

You may be looking for the flags argument to the compile function:

  >>> exec compile("int(3)","","single")
  3
  >>> exec compile("int(3)","","exec")
  >>>
  >>> help(compile)
  Help on built-in function compile in module __builtin__:

  compile(...)
  compile(source, filename, mode[, flags[, dont_inherit]]) -> code object

  Compile the source string (a Python module, statement or expression)
  into a code object that can be executed by the exec statement or eval().
  The filename will be used for run-time error messages.
  The mode must be 'exec' to compile a module, 'single' to compile a
  single (interactive) statement, or 'eval' to compile an expression.
  The flags argument, if present, controls which future statements influence
  the compilation of the code.
  The dont_inherit argument, if non-zero, stops the compilation inheriting
  the effects of any future statements in effect in the code calling
  compile; if absent or zero these statements do influence the compilation,
  in addition to any features explicitly specified.
  >>>

Michael

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


Re: pyvm -- faster python

2005-05-12 Thread Kay Schluehr
Stelios Xanthakis wrote:
> Kay Schluehr wrote:
>
> >
> > Yes. What we are seeking for and this may be the meaning of Armins
> > intentiously provocative statement about the speed of running HLLs
is a
> > successor of the C-language and not just another VM interpreter
that is
> > written in C and limits all efforts to extend it in a flexible and
> > OO-manner. Python is just the most promising dynamic OO-language to
> > follow this target.
> >
>
> Bytecode engine is the best method for dynamic code execution
> ("exec", eval, etc).  A low level OOP language would be very suitable
> for a python VM.

Why this? eval() consumes a string, produces a code object and executes
it. Wether the code-object is bytecode or a chunk of machine code makes
a difference in the runtime but does not alter the high level
behavioural description of eval(). In either way the compile() function
behind eval is a JIT.

> pyvm has that. A big part of it is written in "lightweight C++" [1].
> That makes it less portable as the lwc preprocessor is using GNU-C
> extensions.

Hmmm... I'm not amazingly happy that it is not ANSI-C++. To be honest I
don't want to learn lw-C++ and the peculiaritys of the translator and
debuging through translated code. This may be an interesting study on
it's own but it is just not me who is interested in it. Using an
experimental language to write an experimental VM is clearly out of my
motivation ( only as a remark for the quest of contribution not as a
general criticism ).

> However, it's the same extensions also used by the linux
> kernel and AFAIK the intel compiler supports them too.
>
> So probably the bigger "competitor" of pyvm is boost-python.

How could boost-Python be a "competitor"? Isn't it just an ANSI
C++-binding that relates heavily on templates that are not even
supported by lw-C++?

Regards,
Kay

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


Re: Python features

2005-05-12 Thread Peter Dembinski
On Sun, 08 May 2005 10:02:42 +0200, Andrà Roberge  
<[EMAIL PROTECTED]> wrote:

[...]

> google for "python" and "functional"; first link:
> http://www-106.ibm.com/developerworks/linux/library/l-prog.html

[...]

> Imperative programming languages are the most commonly used languages.  
> Examples of this type of language are C, C++, Ada, Fortran, Algol, Java,  
> Python, Perl, and so on.

How about lambda construction?  Isn't Python imperative language that
includes some functional mixins?

I mean -- can you say Python is fully imperative language?

If you want to redirect me to Google, don't bother.  IMO ninety percent
of writings found on WWW is just a garbage.

-- 
http://www.peter.dembinski.prv.pl
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: urllib download insanity

2005-05-12 Thread Paul Rubin
Skip Montanaro <[EMAIL PROTECTED]> writes:
> Timothy> downloading the OLD file i've deleted! if i download it via IE,
> Timothy> i get the new file. SO, my only conculsion is that urllib is
> Timothy> caching it some where. BUT i'm already calling urlcleanup(), so
> Timothy> what else can i do?  here is the code
> 
> Is there a proxy between you and the web server?

IE also caches extremely aggressively itself.  There are a lot of
different HTTP headers that affect caching.  You have to set ALL of
them to not cache.  You have to set the cache control header AND set
an expiration date in the past, and maybe a couple other things like
that too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working directory for debugging in pythonwin

2005-05-12 Thread Colin J. Williams
Thomas Pfaff wrote:
> Hello all,
> 
> I started using the nice Pythonwin IDE together with Python 2.3 (I have
> come to prefer its editor to IDLE).
> My problem is, that when I want to run a script in the debugger, I can
> give the script name and arguments, but I can't tell it in which
> directory it should run.
> 
> I googled this group but didn't find anything helpful so far.
> 
> I could use some os.chdir in my code, but that's ugly and I neither want
> to copy the script around to the places where I would like to test it.
> 
> Any suggestions?
> 
> Thanks in advance
> 
> 
> Thomas
Thomas,

When you have initiated PythonWin, try opening (^O) the file you wish to 
debug.  By selecting the file directory and file you have chosen the 
current working directory for the file.

Alternatively, in the Windows Explorer, try right clicking on the py 
file you wish to debug.  One of the options given is likely to be PythonWin.

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


Re: Python Documentation (vs PHP stuff)

2005-05-12 Thread Paul Rubin
Roel Schroeven <[EMAIL PROTECTED]> writes:
> In my experience, the user comments in many cases are almost useless.
> Sometimes just confusing, sometimes contradicting each other, sometimes
> even incorrect. Sometimes correct and useful too, but IMO that gets
> drown between all the others.

One thing they are useful for is identifying the places where the
official documentation is deficient.  Even if the user comments are
wrong, it shows the user was having a problem with what was supplied.
I think Python's docs could benefit a lot from that.  There are
parts of the Python docs that are hopelessly incomplete or confusing.
-- 
http://mail.python.org/mailman/listinfo/python-list


bash like expansion

2005-05-12 Thread bill
Consider the following:

import os, commands
os.environ['QWE']="string with foo"
a = '$QWE  ${QWE/foo/baz}'
b = commands.getoutput('echo ' + a)


This does what I want, which is to expand
a according to the standard bash expansion rules
(so b now references "string with foo string with baz"),
but it doesn't feel right.

Is there a more pythonic way to interpret strings according
to shell rules for word expansion?  Relying on commands
feels like a kludge, and shlex is way too much work for this
(not to mention that it doesn't really address the issue).

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


Re: Importing modules

2005-05-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Another item (for me...) difficult, is "import modules", and "plenty of
> information" (as you said) does not help me much: the mechanism of
> variable visibility and namespaces is not clear to me.

have you read this

http://effbot.org/zone/python-objects.htm

and

http://effbot.org/zone/import-confusion.htm

?





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


Re: How "return" no return ?

2005-05-12 Thread Bill Mill
On 5/12/05, Ximo <[EMAIL PROTECTED]> wrote:
> I am doing my own interpreter with the Python languaje.
> 
> Do you understand me?

Well, to be frank, no. However, Frederik's point still stands; in the
python langage, "int a" is syntactically invalid. If you're writing
your own interpreter, it should still be syntactically invalid.

Could you perhaps repeat your question with an example of what
behavior is surprising you?

Peace
Bill Mill
bill.mill at gmail.com

> 
> "Fredrik Lundh" <[EMAIL PROTECTED]> escribió en el mensaje
> news:[EMAIL PROTECTED]
> > "Ximo" wrote:
> >
> >> I am doing a interpret of lines and it show me a prompt, and I want if I
> >> write a declaration as "int a" my progrtam return de prompt and nothing
> >> more, for exemple:
> >>
> >> >>> 2+2
> >> 4
> >> >>> int a
> >> >>>
> >>
> >> Then I'm finding that de function which execute "int a" return me
> >> nothing,
> >> and no
> >>
> >> >>> int a
> >> None
> >> >>>
> >
> > what Python version are you using?  here's what a normal Python
> > interpreter is supposed to do with your example:
> >
>  2+2
> > 4
>  int a
> >  File "", line 1
> >int a
> >^
> > SyntaxError: invalid syntax
> 
> >
> > 
> >
> >
> >
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com Dispatch() and SetPriorityClass()

2005-05-12 Thread Roger Upole
The ie object exposes its window handle as attribute HWND, and you should
be able to use win32process.GetWindowThreadProcessId to get the thread id
and process id that created the window.

   hth

   Roger

"Chris Curvey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> if I'm using Dispatch() to manage a COM object (IE), is there a way to
> get ahold of the process handle so that I can bump it's priority?
>





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


Re: Python Documentation (should be better?)

2005-05-12 Thread Steven Bethard
Skip Montanaro wrote:
> Mike> Given that Python hides the difference between user-defined
> Mike> objects and built-in objects, it's not clear to me that anything
> Mike> other than the current system, with all the classes/types in one
> Mike> place, makes sense.
> 
> Maybe the Module Index should be renamed "Module/Type Index" and embellished
> with the builtin types, so that you'd find "float (builtin)", "string
> (builtin)", "dict (builtin)", etc. in the appropriate alphabetical
> positions.

+1

Yeah, I'd love to see something like this.  My preference would actually 
to be to leave the "Global Module Index" the same and add a "Builtin 
Type Index" along the lines of the module index.

One of my current problems with the documentation is that, for builtin 
types, the constructor is found in "Built-in Functions"[1], but the 
methods are found in some subsection of "Built-in Types"[2]. 
Additionally, the "Built-in Types"[2] section mixes protocols like the 
Sequence, Iterator and Mapping protocols with the methods of some of the 
  builtin types that implement these protocols.

Here's what I'd like to see happen:

(1) Restructure the "Built-In Objects"[3] section to split "Built-in 
Types" into "Built-in Protocols" and "Built-in Types".  "Built-in 
Protocols" would describe:

  * the Numeric Procotol (__add__, __sub__, __mul__, etc.)
  * the Iterator Protocol (__iter__, next, etc.)
  * the Sequence Protocol (__len__, __getitem__, __iter__, etc.)
  * the Mapping Protocol  (__len__, __getitem__, __iter__, etc.)
  * the File Protocol (read, write, close, etc.)
  * the Set Protocol (__len__, __contains__, etc.)
and possibly
  * the String Protocol (Sequence Protocol + upper, lower, etc.)

"Built-in Types" would describe the types that implement the above 
Protocols, i.e.:

  * bool (Numeric)
  * complex (Numeric)
  * dict (Mapping)
  * file (File, Iterator)
  * float (Numeric)
  * frozenset (Set)
  * function -- link to description of functions
  * int (Numeric)
  * list (Sequence)
  * long (Numeric)
  * object -- link to description of classes
  * set (Set)
  * str (Sequence)
  * tuple (Sequence)
  * type -- link to description of classes
  * unicode (Sequence)
  * xrange (Sequence)

Not sure if I got them all, but that should be close.  Probably this 
section should also contain all the types listed in "Other Built-in 
Types"[4]

(2) Fill in each new "Built-in Type" section with:

  * the constructor documentation (from "Built-in Functions"[1])
  * links to each Protocol that the type implements
  * descriptions of partial implementations of Protocols (e.g. tuple is 
an immutable Sequence)
  * any additional methods of the type that are not part of a protocol

(3) Add a separate page like "Global Module Index"[4] called "Built-in 
Type Index" that links to the sections of the new "Built-in Types".


IMVHO, this would make finding docs about the builtins much easier.

However, this is a fairly large change.  A simpler change that would 
probably get 60-70% of the benefit, would be to just create the 
"Built-in Type Index" page, and link to the current page describing that 
built-in type's Protocol.  It might be a little confusing to click on a 
link that said "str type" and end up at the "Sequence Types" page, but I 
think people could get over it if the more comprehensive solution isn't 
acceptable.

STeVe

[1] http://docs.python.org/lib/built-in-funcs.html
[2] http://docs.python.org/lib/types.html
[3] http://docs.python.org/lib/builtin.html
[4] http://docs.python.org/lib/typesother.html
[5] http://docs.python.org/modindex.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Polymorphism

2005-05-12 Thread Fredrik Lundh
Carlos Moreira wrote:

> Are you talking about:
> http://docs.python.org/tut/tut.html
>
> I fear that doesn't exist one word about polymorphism
> (in an explicit way).

so phrases like

"Strings can be concatenated (glued together) with the + operator,
and repeated with *"

"Like string indices, list indices start at 0, and lists can be sliced,
concatenated and so on"

"The built-in function len() also applies to lists"

"Python's for statement iterates over the items of any sequence"

"The statement result.append(b) calls a method of the list object
result. A method is a function that 'belongs' to an object and is
named obj.methodname, where obj is some object (this may be an
expression), and methodname is the name of a method that is
defined by the object's type. Different types define different
methods. Methods of different types may have the same name
without causing ambiguity."

(etc)

doesn't tell you that polymorphism is a fundamental part of the language,
and used all over the place.  or did you have a non-OO meaning of the
word in mind?





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


Re: How "return" no return ?

2005-05-12 Thread Ximo
I am doing my own interpreter with the Python languaje.

Do you understand me?



"Fredrik Lundh" <[EMAIL PROTECTED]> escribió en el mensaje 
news:[EMAIL PROTECTED]
> "Ximo" wrote:
>
>> I am doing a interpret of lines and it show me a prompt, and I want if I
>> write a declaration as "int a" my progrtam return de prompt and nothing
>> more, for exemple:
>>
>> >>> 2+2
>> 4
>> >>> int a
>> >>>
>>
>> Then I'm finding that de function which execute "int a" return me 
>> nothing,
>> and no
>>
>> >>> int a
>> None
>> >>>
>
> what Python version are you using?  here's what a normal Python
> interpreter is supposed to do with your example:
>
 2+2
> 4
 int a
>  File "", line 1
>int a
>^
> SyntaxError: invalid syntax

>
> 
>
>
> 


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

Re: Python Documentation (should be better?)

2005-05-12 Thread Fredrik Lundh
Christopher J. Bottaro wrote:

> My idea for a manual's table of contents:
>
> 1.  Variables

python doesn't have variables.  the corresponding construct is
described in chapter 4 in the language reference.

> 2.  Conditional and Branching Constructs

chapter 6 and 7 in the language reference:

> 3.  Looping Constructs

chapter 7 in the language reference.

> 4.  Functions

chapter 5 for function calls (functions are just one of many
kinds of callable objects).

chapter 7 in the language reference for definitions.

> 5.  Modules

chapter 6 in the language reference for use.

chapter 8 in the language reference for definitions.

> 6.  Classes

chapter 5 in the language reference for use (classes are just
one of many kinds of callable objects, and instances are just
one of many kinds of objects with attributes).

chapter 7 in the language reference for definitions.

> 7.  Exceptions

chapter 4 in the language reference.

> 8.  Built-in
>8.1  Functions

chapter 2.1 in the library reference (titled "Built-in Functions")

>8.2  Types

chapter 2.3 in the library reference (titled "Built-in Types")

so everything you asked for can be the language reference manual
and the first two chapters of the library reference manual, in pretty
much the same order as you wanted it (the exceptions chapter is
the exception)

> (i.e. not in a manual, but the library reference).

if a reference manual is not a manual, we have a terminology problem.





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


Re: Launch file in Notepad

2005-05-12 Thread Fredrik Lundh
Brian van den Broek wrote:

> > I'm trying to lauch Notepad from Python to open a textfile:
> >
> > import os
> > b1="c:\test.txt"
> > os.system('notepad.exe ' + b1)
> >
> > However, the t of test is escaped by the \, resulting in Notepad trying
> > to open "c: est.txt".
> >
> > How do I solve this?
>
> There are several ways, but the preferred solution is to switch the
> slash direction: "c:/test.txt". Python's smart enough to notice its
> running on Windows and do the right thing with the slash.

that's slightly misleading: on the API level, most functions can handle
both kinds of slashes.  functions like open(), os.remove(), shutil.copy()
etc. handles either case just fine.  and in most cases, this is handled
on the Win API level (or in the C library), not by Python.

however, in this case, the user passes a string to os.system().  that
string is passed *as is* to the command shell (which, in this case,
passes it on to notepad.exe as is).





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


Re: Problem combining python code and html

2005-05-12 Thread Fredrik Lundh
"Hansan" wrote:

> The change did remove the error message, and I can see what was wrong.
> However there is now a new problem, the only thing that is displayed is one
> single character and that is: <
>
> Do you or anyone else have a suggestion to what the cause to this new
> problem is ?

my fault; I somehow expected you to figure out that you had to fix up
the rest of the function as well, and forgot that you were just cutting
and pasting from a rather lousy example, without understand all the de-
tails.

here's the rest of the relevant code:

if SubResult[1] == 0:
raise BadTemplateException

print "Content-Type: text/html\n\n"
print SubResult[0]

in the original code, re.subn returns a 2-tuple containing the new string
and a count, but replace only returns the string.  the easiest way to fix
this is to get rid of the BadTemplate check; just replace the above code
with:

print "Content-Type: text/html\n\n"
print SubResult

if you really want the BadTemplateException, you can do:

if SubResult == TemplateInput:
raise BadTemplateException

print "Content-Type: text/html\n\n"
print SubResult

hope this helps!

(I was about to add a short comment on how this illustrates why examples
are not a universal solution to all documentation problems, unless they're
carefully written and carefully documented.  but such talk will only offend
the PHP crowd, so I better skip that)





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


Re: Python Documentation (should be better?)

2005-05-12 Thread Bill Mill
On 5/12/05, Terry Reedy <[EMAIL PROTECTED]> wrote:
> 
> "Skip Montanaro" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Maybe the Module Index should be renamed "Module/Type Index" and
> > embellished
> > with the builtin types, so that you'd find "float (builtin)", "string
> > (builtin)", "dict (builtin)", etc. in the appropriate alphabetical
> > positions.
> 
> +1
> 
> TJR
> 

+1

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


Re: Python Polymorphism

2005-05-12 Thread Carlos Moreira

--- Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> www.python.org

:-/

> 
> (have you read the tutorial?)

Are you talking about:
http://docs.python.org/tut/tut.html

I fear that doesn't exist one word about polymorphism
(in an explicit way).
Anyway, I use Python since 2000 year and already use
OO Python features since the begin. But now, I need
more technical informations.

   Thanks and best regards

Cadu Moreira



Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html

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


Re: How "return" no return ?

2005-05-12 Thread Fredrik Lundh
"Ximo" wrote:

> I am doing a interpret of lines and it show me a prompt, and I want if I
> write a declaration as "int a" my progrtam return de prompt and nothing
> more, for exemple:
>
> >>> 2+2
> 4
> >>> int a
> >>>
>
> Then I'm finding that de function which execute "int a" return me nothing,
> and no
>
> >>> int a
> None
> >>>

what Python version are you using?  here's what a normal Python
interpreter is supposed to do with your example:

>>> 2+2
4
>>> int a
  File "", line 1
int a
^
SyntaxError: invalid syntax
>>>





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


Re: Python Polymorphism

2005-05-12 Thread Fredrik Lundh
Carlos Moreira wrote:

>  How could I use Python polymorphism?
>  Which kind of structures Python give me to use
> polymorphism?
>  Where can I find specific documentation?

www.python.org

(have you read the tutorial?)





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


Re: Python Documentation (should be better?)

2005-05-12 Thread Terry Reedy

"Skip Montanaro" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Maybe the Module Index should be renamed "Module/Type Index" and 
> embellished
> with the builtin types, so that you'd find "float (builtin)", "string
> (builtin)", "dict (builtin)", etc. in the appropriate alphabetical
> positions.

+1

TJR



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


Re: Speed of the different python-based HTTP-servers

2005-05-12 Thread Irmen de Jong
Thomas W wrote:

> I don't expect this project to have alot of traffic once online, but it
> would kinda suck if my software couldn't handle it if it really took
> off.

What would be "a lot"

> So my question is; based on the very brief description above, are there
> any of the python-based frameworks that fits my project better than the
> others? And are there some of the frameworks that doesn't scale
> particulary well? Benchmarks anyone?

With the note that benchmarks are dangerous, here are some numbers:
http://snakelets.sourceforge.net/benchmark.html

I'd say just install it on your own system and run your own tests.

> I want to use ZPT or simpleTAL for templating and SQLObject for
> database-access etc if that makes any differences.

Snakelets has Ypages for templating, but it is not really
difficult to use your own template library (someone is successfully
using PyMeld, for instance).
It is database agnostic, meaning that no database code whatsoever
is in the package. This means that you are 100% free to choose
your own db persistence system.

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


Re: Can get reference of a part of a list?

2005-05-12 Thread F. Petitjean
Le Fri, 13 May 2005 00:58:49 +0800, flyaflya a écrit :
> I want make a 2-D array from a list,all elements is references of 
> list's,like this:
> a = [1,2,3,4]
> b = [ [1,2], [3,4] ]
> when change any elements of a, the elements of b will change too, so I 
> can  use some function for list to change b.
> c/c++ can work in this way,I think let b[0] = a[0:2], b[1] = a[2:3],but 
> it's not reference,it's copy.
If the original list contains only numeric values of the same type, i.e
only integers or only floats, the Numeric array reshape() function is
what you need :

import Numeric as N
aa = N.array([1, 2, 3, 4])
bb = N.reshape(aa, (2, 2))
print bb
array([[1, 2],
   [3, 4]])
bb[0][:] = (7, 8)
aa
array([7, 8, 3, 4])
That is there is only one homogeneous list of values, no copy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can get reference of a part of a list?

2005-05-12 Thread Terry Reedy

"flyaflya" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I want make a 2-D array from a list,all elements is references of
> list's,like this:
> a = [1,2,3,4]
> b = [ [1,2], [3,4] ]
> when change any elements of a, the elements of b will change too, so I
> can  use some function for list to change b.
> c/c++ can work in this way,I think let b[0] = a[0:2], b[1] = a[2:3],but
>it's not reference,it's copy.

Look into Numerical Python or Numarray, where slices are views instead of 
copies.

TJR



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


Re: Python Graphing Utilities.

2005-05-12 Thread Petr Mikulik
> A pslatex backend certainly would be interesting. A Gnuplot backend
> would probably not be feasible. Does it expose its raw drawing operations?

There is a patch
[ 1027032 ] Connect gnuplot_x11 to exterior application window
http://sourceforge.net/tracker/index.php?func=detail&aid=1027032&group_id=2055&atid=302055

which allows to "Connect gnuplot_x11 to exterior application window...".

If you test it, please write a note there and the patch can go to cvs.

---
PM

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


Can get reference of a part of a list?

2005-05-12 Thread flyaflya
I want make a 2-D array from a list,all elements is references of 
list's,like this:
a = [1,2,3,4]
b = [ [1,2], [3,4] ]
when change any elements of a, the elements of b will change too, so I 
can  use some function for list to change b.
c/c++ can work in this way,I think let b[0] = a[0:2], b[1] = a[2:3],but 
it's not reference,it's copy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding startup files

2005-05-12 Thread Bernhard Herzog
Grant Edwards <[EMAIL PROTECTED]> writes:

> On 2005-05-11, jeff elkins <[EMAIL PROTECTED]> wrote:
>
>> I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
>
> argv[0] contains whatever is put there by the program that
> exec'ed you, and can therefore contain just about anything (or
> nothing).  It may not contain a full path, and your program's
> install directory may not be in your $PATH (it be executed by a
> shortcut or symlink).

That's true for the C-level, i.e. main's argv.  If you're only concerned
about CPython and the program is a script living in a file, then
sys.argv[0] is the filename the python interpreter itself used to read
the script.  Hence it's a valid filename that refers to the script.  It
may be a relative filename, of course, in which case it won't be correct
anymore if the program changes its working directory.

  Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python with MSC.Mentat

2005-05-12 Thread Jeroen Kleijer

Hi all,

I'm running into a very strange problem at work.
We're using an application called MSC.Mentat (modelling/meshing
application) which provides a programmable interface through Python.

Because we were told that the Python version they ship is missing some
libraries we compiled it ourselves on both Solaris 9 and RedHat EL 3.0

When we use some of our inhouse scripts, which were written by a
student who has left us a long time ago, the scripts work great on the
Solaris version. (they were once written with Python 1.5 in mind so we
get some string/strop errors but nothin terribly wrong)

However, if we use the exact same method for our Linux version, Mentat
(which calls the Python scripts) core dumps with the following
messages:

Traceback (most recent call last):
  File "main_process.py", line 6, in ?
from read_data_file import retrieve_param
  File "read_data_file.py", line 3, in ?
from pickle import *
  File "pickle.py", line 33, in ?
import struct
ImportError:
/cadappl/python/2.2.4-64/lib/python2.2/lib-dynload/struct.so:
undefined symbol: PyInt_FromLong
Exception py_mentat.error: 'Error in module main\n' in 'garbage
collection' ignored
Fatal Python error: unexpected exception during garbage collection

When I do an 'nm' on the struct.so file I can see that PyInt_FromLong
is undefined (along with a whole batch of others) but this is the same
on the Solaris version so that can't be it.

Do you have any idea what could cause this?

Kind regards,

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


Tix hlist and item_exists

2005-05-12 Thread theoryboy
I can't seem to get this function to work. If the item does not exist I
get an exception, rather than a return value of false. Here's an
example:


#!/usr/bin/python

from Tix import *

root = Tk()
listBox = HList(root)
item = "some item"
if not listBox.item_exists(item, 0):
listBox.add(item, itemtype=TEXT, text=item)


Any ideas?

Peter

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


Debugging python with c++ extensions under windows with eclipse CDT

2005-05-12 Thread peter
Hello all,

I would like to debug my python libraries, written in c++, with GDB
(gnu debugger)
I'm using the mingw compiler in a windows environment.  As development
environment I use eclipse with the CDT plugin.  This plugin also has a
nice GUI frontend for the GDB.

I've already tried several setups, no setup seemed to work.

Therefore my first question simply is: has anybody already succeeded in
using the GDB used by eclipse CDT to debug a c++ extension?
Is this actually the best way to debug DLLs in windows? Is visual
studio better suited for the job?  Is there another option I am not
aware of?

thx a lot for reading so far

Peter


In the following section I explain in detail what I've already tried.
It can easily be skipped.

Ok, an overview of the things I've already done:
first, to use mingw with the python distribution, I've first followed
http://sebsauvage.net/python/mingw.html in order to get an adjusted
libpython23.a  Otherwise you cannot use the mingw compiler with python
under windows

In order to debug my code, I've found in this newsgroup the topic:
   "Debugging python with C++ extensions"
and similar I've found
http://ruby.wag.caltech.edu/Tutorials/double-debugger.html

I've tried somewhat similar in my eclipse CDT environment:
I start a python script, which pauses at a point I've inserted:
>>>a = raw_input("")
Now I can start the GDB and attach it to this running python process...

In eclipse this is "right mouse click" > debug > debug > "c/c++ attach
to local application"
I create a new configuration of this type, fill in the correct DLL.
(making sure my binary parser was correct, this is usually the problem
if you can't find any binaries)

all this did not same to work...

I get an error" Cannot access memory at address 0x68f52bcc
Cannot access memory at address 0x68f52bcc"
and I no longer understand anything which is going on in the the
debugger.

So again the basic question is: has anybody already succeeded in using
the GDB for debugging python c++ libraries in windows?
Does this also work when you use the eclipse environment?

once again, kind regards

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


Re: Unique Elements in a List

2005-05-12 Thread Scott David Daniels
Edvard Majakari wrote:
> I realized that, but maybe I should've pointed it out too. For the OP if
> he/she is unaware - notation O(N^2) (big O n squared) means the computing time
> of the algorithm increases exponentially (where exponent is 2) relative to the
> size of the input.
Normally this is called a polynomial, rather than exponential increase.
Exponential increases are typically of the form (C^N) (they are all
equivalent).
Polynomial times are hallways characterized by their largest exponent,
So you never call something O(N^3 - N^2) Since, as N gets large enough,
The N^2 term shrinks to non-existence.

 http://en.wikipedia.org/wiki/Exponential_time

 > ... generally one should avoid using exponential O(n^k) (where k > 1)

Again polynomial, not exponential time.  Note that there is no
polynomial time algorithm with (k < 1), since it takes O(n) time
to read the problem.


--Scott David Daniels
[EMAIL PROTECTED]

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


Python Polymorphism

2005-05-12 Thread Carlos Moreira
Dear all,

 How could I use Python polymorphism?
 Which kind of structures Python give me to use
polymorphism?
 Where can I find specific documentation?

  Thanks and Best regards.

Cadu Moreira



__ 
Do you Yahoo!? 
Make Yahoo! your home page 
http://www.yahoo.com/r/hs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Documentation (should be better?)

2005-05-12 Thread Skip Montanaro

Mike> Given that Python hides the difference between user-defined
Mike> objects and built-in objects, it's not clear to me that anything
Mike> other than the current system, with all the classes/types in one
Mike> place, makes sense.

Maybe the Module Index should be renamed "Module/Type Index" and embellished
with the builtin types, so that you'd find "float (builtin)", "string
(builtin)", "dict (builtin)", etc. in the appropriate alphabetical
positions.

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


Re: urllib download insanity

2005-05-12 Thread Andrew Dalke
Timothy Smith wrote:
> ok what i am seeing is impossible.
> i DELETED the file from my webserver, uploaded the new one. when my app 
> logs in it checks the file, if it's changed it downloads it. the 
> impossible part, is that on my pc is downloading the OLD file i've 
> deleted! if i download it via IE, i get the new file. SO, my only 
> conculsion is that urllib is caching it some where. BUT i'm already 
> calling urlcleanup(), so what else can i do?

Here are some ideas to use in your hunt.

 - If you are getting a cached local file then the returned object
will have a "name" attribute.

   result = urllib.retrieve(".")
   print result.fp.name

As far as I can tell, this will only occur if you use
a tempcache or a file URL.


  - You can force some debugging of the open calls, to see if
your program is dealing with a local file.

>>> old_open = open
>>> def my_open(*args):
...   print "opening", args
...   return old_open(*args)
... 
>>> open("/etc/passwd")

>>> import __builtin__
>>> __builtin__.open = my_open
>>> open("/etc/passwd")
opening ('/etc/passwd',)

>>> 

You'll may also need to change os.fdopen because that's used
by retrieve if it needs a tempfile.

If you want to see where the open is being called from,
use one of the functions in the traceback module to print
the stack trace.

  - for surety's sake, also do 

import webbrowser
webbrowser.open(url)

just before you do 

urllib.retrieve(url, filename)

This will double check that your program is using the URL you
expect it to use.

  - beyond that, check that you've got network activity,

You could check the router lights, or use a web sniffer like
ethereal, or set up a debugging proxy

  - check the headers.  If your ISP is using a cache then
it might insert a header into what it returns.  But if
it was caching then your IE view should have seen the cached
version as well.

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


Re: How "return" no return ?

2005-05-12 Thread Tim Williams

- Original Message - 
From: "Corrado Gioannini" <[EMAIL PROTECTED]>


> On Thu, May 12, 2005 at 04:42:34PM +0100, Tim Williams wrote:
> > Just don't use a return statement at all,  or do something like
> > 
> > [function body]
> > if not val = None:
> > return val
> > [end of function]
> 
> i didn't understood that.
> if you don't return nothing explicitly the function returns None.
> (or am i wrong?)

No, you're right,  my bad :)

Was thinking about something else similar and got stuck in a mindset


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


Re: Compiling Tcl apps redux

2005-05-12 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,  <[EMAIL PROTECTED]> wrote:
.
.
.
>Absolutely!  Looking at the wiki there are a bunch of solutions, all of
>which work in specialized circumstances.  Nothing like, say the "freeze"
>script of Python.
.
.
.
!?!  Has Python's freeze changed so much that it's now a
universal solution?  I need to re-acquaint myself with it
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Documentation (should be better?)

2005-05-12 Thread Mike Meyer
"Christopher J. Bottaro" <[EMAIL PROTECTED]> writes:

> because there are no namespaces or classes, but still I think Python could
> do something similar.  Say for instance search for "append" and it will
> come back with a page for list's append, a page for array's append, etc.

A seperate page for each method of every class? Ouch. I think that's
serious overkill. Having the entries for the methods in the pages be
labelled, so that a search could return a direct link to the
appropriate paragraph, that would be a major improvement.

> If I wanted to learn about "types" in Python, where do I look?  The PHP
> manual has a whole section on the built-in types, how to get the type of a
> var, how to change cast the type of a var, etc.  I think that is such an
> important and basic part of any language, yet its scattered all over Python
> documention, difficult to find (i.e. not in a manual, but the library
> reference).

Python variables don't have types. Python objects have types. Python
further confuses the issue by overloading "types" to mean builtin
types, which are different classes, which can both instantiate as a
variable. If you're doing things Pythonically, you generally don't
care what type a variable has - you care that it supports the
operations you want. Changing the type of an object is either
impossible or dificult, depending on the object - and not to be
undertaken lightly.

What I'm trying to say is that "type" just isn't as important a
concept in Python as it is in other languages. PHP, for instance,
apparently has a number of automatic conversions between types if
various operations are applied, so you have to care what type an
object is or risk getting it converted accidently. Python doesn't do
that. Many languages have typed variables, so everything you do will
depend on the type of the variable. Python doesn't do that. Some OO
languages conflate types and classes, and use isinstane for type
checking. Python doesn't do that.  All that python cares about - and
all that you really need to care about - is that the object referenced
by the variable support the features you want to use.

> I guess what I'm trying to say is that there should be a "manual" which is
> half way between the tutorial and the library reference, that is organized
> more like a traditional manual (whatever that means, right?) and is more
> easily searchable.

Given that Python hides the difference between user-defined objects
and built-in objects, it's not clear to me that anything other than
the current system, with all the classes/types in one place, makes
sense.

That's not to say the documentation can't be improved. I'm just not
convinced that a "manual" pulling in parts from multiple different
places is an improvement.

That said, I'd like to ask what's wrong with the language reference?
It provides a nice reference on the syntax and semantics of the
language. What does the tutorial provide that you can't get from the
Language Reference?

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


Re: a cx_Oracle ORA-01036 problem

2005-05-12 Thread Damjan
>> SQL = """insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \
>> :DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'),
>> to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)"""
>> 

> Try using a variable name other than "id" for the CARDREF variable... say
> "card_id".  id is a built in function name; I suspect your problem may be
> that you are assiging that function to the variable rather than your
> intended value...

I changed it to 'cardref' but I'm still getting the same error.


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


Re: How "return" no return ?

2005-05-12 Thread Corrado Gioannini
On Thu, May 12, 2005 at 04:42:34PM +0100, Tim Williams wrote:
> Just don't use a return statement at all,  or do something like
> 
> [function body]
> if not val = None:
> return val
> [end of function]

i didn't understood that.
if you don't return nothing explicitly the function returns None.
(or am i wrong?)

c.
-- 
Hi, I'm a .signature virus! Copy me to your .signature file and
help me propagate, thanks!


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


Re: pyvm -- faster python

2005-05-12 Thread Andrew Dalke
Paul Rubin wrote:
> Yes, there are several Python compilers already
 ...
> It's true that CPython doesn't have a compiler and that's a serious
> deficiency.  A lot of Python language features don't play that well
> with compilation, and that's often unnecessary.  So I hope the baseline
> implementation changes to a compiled one before the language evolves
> too much more.

Years ago, presented at one of the Python conferences, was a
program to generate C code from the byte code.  It would still
make calls to the Python run-time library (just as C does to
its run-time library).

The presenter did some optimizations, like not decref at the
end of one instruction when the next immediately does an incref
to it.  The conclusion I recall was that it wasn't faster -
at best a few percent - and there was a big memory hit because
of all the duplicated code.  One thought was that the cache miss
caused some of the performance problems.

Does that count as a compiler?

Andrew
[EMAIL PROTECTED]

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


  1   2   >