Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-06 Thread Lasse Vågsæther Karlsen
Ok, that one looks more sleak than what I came up with.

Couple of things I learn from your solution, please correct me if I
misunderstood something:

1. list containing other lists will sort itself based on first element
on lists inside ?
2. sort(), pop() is not costly operations

Other than that you seem to not use the cmp operator but that's easily
fixed.

This one looks much better than mine, here's what I came up with:

def merge_sorted(iterables, comparer=None):
"""
Generator that will take a list of iterables/generators that is
individually sorted, and then produce
values in a sorted order by taking the lowest value from each
source each call.

@param iterables: List of iterables/generators to retrieve values
from
@type iterables: List of iterables/generators

@param comparer: Optional fn(v1, v2) function that can compare two
values, should return <0 if v10 if v1>v2 and ==0 if v1==v2.
@type comparer: function-object, example: lambda x, y: x-y

@note: The "list of iterables" can actually be anything that
produces a list of iterables, so you can
use a function that yields lists for instance.
"""

# First convert whatever we're given into a list of sources
iterables = [iterable for iterable in iterables]

# This series of if-statements will determine how many sources we
have and work out sub-problems
# that are manageable.
if len(iterables) != 2:
if len(iterables) == 0:
# List, but no sources
pass
elif len(iterables) == 1:
# Only 1 source, just return its contents
for value in iterables[0]:
yield value
elif len(iterables) == 3:
# 3 sources, sub-divide into 0 <--> (1, 2)
left_iterable = iterables[0]
right_iterable = merge_sorted([iterables[1], iterables[2]],
comparer)
for value in merge_sorted([left_iterable, right_iterable],
comparer):
yield value
elif len(iterables) == 4:
# 4 sources, sub-divide into (0, 1) <--> (2, 3)
left_iterable = merge_sorted([iterables[0], iterables[1]],
comparer)
right_iterable = merge_sorted([iterables[2], iterables[3]],
comparer)
for value in merge_sorted((left_iterable, right_iterable),
comparer):
yield value
elif len(iterables) > 4:
# >4 sources, sub-divide into (0, 1) <--> (2, ...)
left_iterable = merge_sorted([iterables[0], iterables[1]],
comparer)
right_iterable = merge_sorted(iterables[2:], comparer)
for value in merge_sorted((left_iterable, right_iterable),
comparer):
yield value
raise StopIteration

# The method will only get here if there is only two sources, which
is an easy case to handle
i1 = iter(iterables[0])
i2 = iter(iterables[1])

# Grab the first two values from the two sources, if possible
try:
v1 = i1.next()
has_v1 = True
except StopIteration:
has_v1 = False
try:
v2 = i2.next()
has_v2 = True
except StopIteration:
has_v2 = False

# As long as we got values from both generates/iterators/whatever,
compare and yield the lowest of the
# two, and then get the next value from the corresponding source
while has_v1 and has_v2:
# Work out which of v1 and v2 comes first
if comparer is not None:
comp = comparer(v1, v2)
if comp <= 0:
yield_v1 = True
else:
yield_v1 = False
else:
if v1 <= v2:
yield_v1 = True
else:
yield_v1 = False

# Yield the next value, then grab a new value from the
corresponding source
if yield_v1:
yield v1
try:
v1 = i1.next()
except StopIteration:
has_v1 = False
else:
yield v2
try:
v2 = i2.next()
except StopIteration:
has_v2 = False

# When we get here, we got 3 possibilities:
#  1. has_v1 == True, has_v2 == False --> yield rest of v1/i1 and
just exit on StopIteration exception
#  2. has_v1 == False, has_v1 == True --> yield rest of v2/i2 and
just exit on StopIteration exception
#  3. has_v1 == has_v2 == False --> while-loops will skip, function
falls off the end
while has_v1:
yield v1
v1 = i1.next()
while has_v2:
yield v2
v2 = i2.next()

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


RE: Build spoofed IP packets

2005-10-06 Thread Payton, Zack
See scapy.py
I've completed windows support at this time and am currently testing it,
working out some bugs.
If you want a copy just ask.  I need some testers.
It can do almost any packet transmissions you want. (google it)
Z
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread DaveM
On Fri, 07 Oct 2005 00:33:43 -, Grant Edwards <[EMAIL PROTECTED]> wrote:

>On 2005-10-06, DaveM <[EMAIL PROTECTED]> wrote:
>
>>>Frankly, I can't watch Shakespeare or movies like "the full
>>>monty" or "trainspotting" because I can't understand a damn
>>>word they say. British talk sounds like gibberish to me for the
>>>most part.
>>
>> Not just you. It always amuses me in trips to the US that
>> British voices (outside of the movies) are often subtitled,
>> while first-generation Americans whose English is. um,
>> limited, are not.
>
>What?!?  I've never seen a British voice (inside or outside of
>the movies) subtitled -- with the exception of one of a
>nightclub scenes in one movie (I think it was Trainspotting)
>where the dialog was inaudible because of the music.

I noticed this watching news footage rather than imported shows. I haven't
seen 'Trainspotting', but I have seen Scottish accents subtitled
(unnecessarily) on English TV, to understandable anger across the border -
so this isn't uniquely a US phenomenon, to be fair.


>For example: In British English one uses a plural verb when the
>subject consists of more than one person.  Sports teams,
>government departments, states, corporations etc. are 
>grammatically plural.  In American, the verb agrees with the
>word that is the subject, not how many people are denoted by
>that word.
>
>In sports (thats "sport" for you Brits):

Yes.

> American: Minnesota is behind 7-0.  The Vikings are behind 7-0.
>  British: Minnesota are behind 7-0. The Vikings are behind 7-0.

True.

>In politics:

>  American: The war department has decided to cancel the program.
>   British: The war department have decided to cancel the program.

Not sure about this one. They may be used interchangeably as neither strikes
me as sounding "odd".

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


Re: os.access with wildcards

2005-10-06 Thread Leif K-Brooks
mike wrote:
> i'd like to use
> 
>os.access(path,mode)
> 
> where path may contain linux style wildcards.

os.access(glob.glob(path), mode)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyObject_New

2005-10-06 Thread Gerhard Häring
Jeremy Moles wrote:
> [...] What I'm trying
> now is the following:
> 
>   PyObject* obj = _PyObject_New(&PyType_MyType);
>   obj = PyObject_Init(obj, &PyType_MyType);
>   
>   ...
> 
>   return obj;
> 
> When "obj" gets back to the interpreter, Python sees it (or rather, it's
> __repr__) in accordance with what it "should" be. However, any attempt
> to USE the object results in a segfault. I feel my problem is simply
> that I'm not allocating "obj" correctly in the C++ function.
> 
> If anyone has any advice, I would really appreciate it.

When I looked for info on this, I didn't find any good documentation, 
either.

I'm currently using code like the following in pysqlite 
(http://initd.org/tracker/pysqlite/browser/pysqlite/trunk/src/connection.c?rev=154):

126 if (factory == NULL) {
127 factory = (PyObject*)&CursorType;
128 }
129 
130 cursor = PyObject_CallFunction(factory, "O", self);

So, basically I'm just calling the type like any other callable object. 
I don't remember if there was a reason why I didn't use 
PyObject_CallObject instead, at the time ...

In any case, this approach worked fine for me.

-- Gerhard

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


os.access with wildcards

2005-10-06 Thread mike
i'd like to use

   os.access(path,mode)

where path may contain linux style wildcards.
i've failed so far.
my workaround is the bash command.

   os.system('[ -e %s ]' % fn )

any suggestions?

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


py2exe 0.6.3 released

2005-10-06 Thread Jimmy Retzlaff
py2exe 0.6.3 released
=

py2exe is a Python distutils extension which converts Python scripts
into executable Windows programs, able to run without requiring a
Python installation. Console and Windows (GUI) applications, Windows
NT services, exe and dll COM servers are supported.

Changes in 0.6.3:

* First release assembled by py2exe's new maintainer, Jimmy
  Retzlaff. Code changes in this release are from Thomas Heller
  and Gordon Scott.

* The dll-excludes option is now available on the command line.
  It was only possible to specify that in the options argument to
  the setup function before.

  The dll-excludes option can now be used to filter out dlls like
  msvcr71.dll or even w9xpopen.exe.

* Fix from Gordon Scott: py2exe crashed copying extension modules
  in packages.

Changes in 0.6.2:

* Several important bugfixes:

  - bundled extensions in packages did not work correctly, this
made the wxPython single-file sample fail with newer wxPython
versions.

  - occasionally dlls/pyds were loaded twice, with very strange
effects.

  - the source distribution was not complete.

  - it is now possible to build a debug version of py2exe.

Changes in 0.6.1:

* py2exe can now bundle binary extensions and dlls into the
  library-archive or the executable itself.  This allows to
  finally build real single-file executables.

  The bundled dlls and pyds are loaded at runtime by some special
  code that emulates the Windows LoadLibrary function - they are
  never unpacked to the file system.

  This part of the code is distributed under the MPL 1.1, so this
  license is now pulled in by py2exe.

* By default py2exe now includes the codecs module and the
  encodings package.

* Several other fixes.

Homepage:



Download from the usual location:



Enjoy,
Jimmy
-- 
http://mail.python.org/mailman/listinfo/python-list


where to find information about errors/exceptions in socket.py

2005-10-06 Thread mirandacascade
Version of python: 2.4
O/S: Win2K

I will be writing some python scripts to do some client-side
programming that involves socket.py.  I expect that I will be making
calls to the following methods/functions:

connect_ex()
setsockopt()
sendall()
recv()
close()

Where can one find information about whether the functions/methods
above return error codes that provide some indication as to whether the
function/method succeeded?  Is there an exception class for handling
exceptions raised in socket.py?  If so, where can one find information
about it?

I consulted the docstrings and didn't find much about return codes or
exception classes.  Also looked at the Lutz "Programming Python"
text...it devotes several pages to socket programming, but I didn't
observe much with regard to error/exception handling.

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


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-06 Thread Terry Hancock
On Monday 03 October 2005 03:48 am, Volker Grabsch wrote:
> Fredrik Lundh wrote:
> > /... snip comment that the natural order is C, X, Y and that programmers 
> > that
> > care about readable code will probably want to be extremely careful with 
> > this
> > new feature .../
> 
> That's also my opinion, but OTOH, Guido's syntax is more close to the syntax
> of list comprehensions.

GvR's syntax has the advantage of making grammatical sense in English (i.e.
reading it as written pretty much makes sense).

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

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


Re: Where to find python c-sources

2005-10-06 Thread Terry Hancock
On Monday 03 October 2005 12:26 pm, John J. Lee wrote:
> [Tor Erik S�nvisen]
> > socketmodule.c, but I can't locate this file... Where should I look?
> 
> [John, finding 'socketmodule.c' responds well to "I'm Feeling Lucky"]
> > Does google vary in its results across the globe?
> 
> [Michael]
> > The search terms might be obvious to you, but it simply means your google-fu
> > is strong, and the strong should help the weak. (or not attack them at
> > least...)
> 
> You believe that Tor is dumb enough not to think of searching for
> "socketmodule.c" when, um, searching for socketmodule.c?

No, ironically, the problem is that Tor is too *smart* to search
for "socketmodule.c" -- it requires *unlearning* the experience
from searching physical libraries where subject catalogs and librarians
are the "search engine".  They don't respond to the same type of
search terms as machines do.

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

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

Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread Neil Hodgson
Grant Edwards:

> Where exactly did you see all these
> sub-titled British TV/movies?

I've noticed this too when travelling but can't recall precise 
details. Perhaps it is on the international versions of American 
channels such as CNN which are commonly watched by people with less 
English and hence less ability to handle accents.

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


Re: Continuous system simulation in Python

2005-10-06 Thread Robert Kern
Dennis Lee Bieber wrote:
> On Fri, 7 Oct 2005 01:12:22 +0200, Nicolas Pernetty
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>>I'm aware of SimPy for discrete event simulation, but I haven't found
>>any work about continuous system.
>>I would like to develop a generic continous system simulator, and so
>>would be eager to join any open source effort on the subject.
>>
>>For instance, it would be useful for modelling an airplane with all the
>>dynamics (flight simulator).
>
>   Unless that flight simulator is running on some big ugly ANALOG
> computer (the ones that used rheostats, transformers, and amplifiers),
> they all are really using discrete time intervals and computing values
> at those time points. Such computation may require integration of
> continuous functions from previous time step to current time step.

I think Nicolas means "(discrete event) simulation" as opposed to
"discrete (event simulation)" and "(continuous system) simulation" as
opposed to "continuous (system simulation)". The methods used in SimPy
to model (discrete events) don't apply terribly well to simulating many
(continuous systems) like airplane dynamics. For example, an ODE
integrator would probably want to adaptively select its timesteps as
opposed to laying out a uniform discretization upfront.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: Where to find python c-sources

2005-10-06 Thread Terry Hancock
On Friday 30 September 2005 04:37 pm, John J. Lee wrote:
> "Tor Erik Sønvisen" <[EMAIL PROTECTED]> writes:
> > Thanks for the answers... And yes, I have searched google! 
> 
> How odd -- the most useful link (the viewcvs page for this source
> file) is the very first link for me when I search for socketmodule.c
> 
> Does google vary in its results across the globe?

Of course you meant to be snippy and sarcastic, but you've actually
exemplified the reason why so many people don't find such a thing
with Google.  Like all search engines, you have to know the right
keyword -- to a fair degree of precision -- in order to find what
you're looking for.

This is very unlike asking a question of a human being.  *People*
respond much better to general subject headings such as "socket
module" or "python sources" rather than looking for something
ultra-specific like a particular file name.  Researchers take this
training with them when they approach Google and treat it like
a magic librarian -- they give it the same thing they would come
to a human librarian with.

Of course, that shows they are less adept with machines than you
are, just as your reply shows you are less adept with humans.

Both sides could probably learn from the encounter. ;-)

Seriously, though, for anybody new to using search engines, it
is a very useful rule of thumb -- search for a specific word
likely to appear on the page you are looking for, and not
elsewhere.

This also shows where Google fails and newsgroups succeed: when
you know what you want, but don't know what it's called. Often,
all a poster really needs is the right keyword to use.

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

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

non descriptive error

2005-10-06 Thread Timothy Smith
i try to run my app and i get this

%python DutyShift.py
error


thats it. thats the error. mya pp was previously working, and i did make 
some fairly large changes to it, but i'd expect a more descriptive 
message then just "error". anyidea where i need to start looking?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python recipes: list mixin, improved timeit, etc

2005-10-06 Thread barnesc

I added some recipes to the Python Cookbook:

 - listmixin

   Use ListMixin to create custom list classes from a small subset of
   list methods:

   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440656

 - pytime

   Improves on timeit by allowing you to time a function directly
   (no need for confusing import and exec B.S.), and not requiring
   you to specify the number of iterations for the timing loop.

   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440657

 - bitlist

   An example of listmixin: A memory compacted list of bits, uses
   1 byte per every 8 elements.

   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440658


I hope you find these useful.

You can find more Python stuff by myself (and other misc thoughts) at
my blog (http://barnesc.blogspot.com/).

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread Rick Wotnaz
Mike Meyer <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Grant Edwards <[EMAIL PROTECTED]> writes:
>> On 2005-10-06, DaveM <[EMAIL PROTECTED]> wrote:
Frankly, I can't watch Shakespeare or movies like "the full
monty" or "trainspotting" because I can't understand a damn
word they say. British talk sounds like gibberish to me for
the most part.
>>> Not just you. It always amuses me in trips to the US that
>>> British voices (outside of the movies) are often subtitled,
>>> while first-generation Americans whose English is. um,
>>> limited, are not.
>> What?!?  I've never seen a British voice (inside or outside of
>> the movies) subtitled -- with the exception of one of a
>> nightclub scenes in one movie (I think it was Trainspotting)
>> where the dialog was inaudible because of the music.
> 
> Maybe they were dubbed? I know America International dubbed the
> first version of "Mad Max" that they imported into the US. Then
> again, American International is well-know for their quality.

A couple of nights ago, I was amused and amazed to see subtitles 
during NBC news interviews with some good citizens of Louisiana. I 
don't know what NBC was thinking. I didn't think the accents were 
especially thick, either. I had no difficulty understanding the 
spoken words except in one stretch where background noise obscured 
some bits. I've certainly heard some New Yorkers with harder-to-
understand speech, though without subtitles. I suppose I could be 
fooling myself in thinking I understood them.

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread Grant Edwards
On 2005-10-07, Mike Meyer <[EMAIL PROTECTED]> wrote:

>>> Not just you. It always amuses me in trips to the US that
>>> British voices (outside of the movies) are often subtitled,
>>> while first-generation Americans whose English is. um,
>>> limited, are not.
>>
>> What?!?  I've never seen a British voice (inside or outside of
>> the movies) subtitled -- with the exception of one of a
>> nightclub scenes in one movie (I think it was Trainspotting)
>> where the dialog was inaudible because of the music.
>
> Maybe they were dubbed?

I don't think so.  Where exactly did you see all these
sub-titled British TV/movies?

In all the British movies and TV shows I've seen in the US, the
British actors sound the same as the do on British TV. I don't
recall ever going to a theater in England, but I've seen plenty
of TV in England.  To me the dialog sounds the same as it does
in the US.

> I know America International dubbed the first version of "Mad
> Max" that they imported into the US. Then again, American
> International is well-know for their quality.

That could be.

-- 
Grant Edwards   grante Yow!  LIFE is a
  at   never-ending INFORMERCIAL!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far (about editing tools)

2005-10-06 Thread Michael Ekstrand
On Thursday 06 October 2005 15:45, Micah Elliott wrote:
> On Oct 06, Kenneth McDonald wrote:
> > The only _real_ problem is the eclipse learning curve.
>
> The only real *advantage* of Eclipse (over other suggested tools) is
> its highly hyped automatic refactoring.  Admittedly, I have not used
> it for Python development, but I'm skeptical of the feasibility of
> auto-refactoring in general, and therefore acknowledge *no*
> advantage. Furthermore, Eclipse requires java and is thusly not
> provided on any linux distro I'm familiar with, which I consider a
> huge roadblock.  And as mentioned, it's bloated.

Eclipse is massively bloated. We're using it for a class I'm taking 
where we have to program in Java... when I start Eclipse on my 1.7GHz 
laptop w/ 256 MB ram, Eclipse is very slow and KDE takes forever to 
switch desktops or applications... Eclipse running brings my entire 
laptop to a near-standstill.

And refactoring: Eclipse has incredible Java refactoring, which works 
beautifully due to Java's highly static nature. Eclipse is by far the 
best tool I've ever seen for browsing and manipulating Java projects. 
But Python's highly dynamic nature makes automatic refactoring 
difficult, and I find Bicycle Repair Man has difficulty with even some 
highly trivial refactoring things (renaming the variable in a for loop 
in one place I tried to use it...).

> I would suspect that the majority of Python programmers write in one
> of vim or emacs. Anyone got stats?

+1 Vim. But no stats.

Perhaps a survey of Python source files found on the Internet for 
prevailing modelines would be revealing?

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread Mike Meyer
Grant Edwards <[EMAIL PROTECTED]> writes:
> On 2005-10-06, DaveM <[EMAIL PROTECTED]> wrote:
>>>Frankly, I can't watch Shakespeare or movies like "the full
>>>monty" or "trainspotting" because I can't understand a damn
>>>word they say. British talk sounds like gibberish to me for the
>>>most part.
>> Not just you. It always amuses me in trips to the US that
>> British voices (outside of the movies) are often subtitled,
>> while first-generation Americans whose English is. um,
>> limited, are not.
> What?!?  I've never seen a British voice (inside or outside of
> the movies) subtitled -- with the exception of one of a
> nightclub scenes in one movie (I think it was Trainspotting)
> where the dialog was inaudible because of the music.

Maybe they were dubbed? I know America International dubbed the first
version of "Mad Max" that they imported into the US. Then again,
American International is well-know for their quality.

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


divide

2005-10-06 Thread Shi Mu
I have three points in a rectangle and i wonder how to use PYTHON to divide the rectangle into three
parts with each point located in the different part.
For instance, Point A 
goes to Part I, Point B goes to Part II and Point C goes to Part III.
And the distance between any point within Part I and Point A is smaller than to Point B and Point C. And the similar rule applies to Part II and Part III.
Thanks for any idea.
-- 
http://mail.python.org/mailman/listinfo/python-list

PyObject_New

2005-10-06 Thread Jeremy Moles
Hey guys, sorry to ask another question of this nature, but I can't find
the answer or a single example of it anywhere. I'm sure it's been asked
before, but my google-fu isn't strong enough to find anything.

I have the following:

struct MyType {
PyObject_HEAD
...
};

PyTypeObject PyType_MyType = { ... }

Now, elsewhere in the code I want to create an instance of this custom
type in C/C++ (rather than in the Python interpreter, where this all
seems to happen magically) and return it from a method. What I'm trying
now is the following:

PyObject* obj = _PyObject_New(&PyType_MyType);
obj = PyObject_Init(obj, &PyType_MyType);

...

return obj;

When "obj" gets back to the interpreter, Python sees it (or rather, it's
__repr__) in accordance with what it "should" be. However, any attempt
to USE the object results in a segfault. I feel my problem is simply
that I'm not allocating "obj" correctly in the C++ function.

If anyone has any advice, I would really appreciate it.

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

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

>>Frankly, I can't watch Shakespeare or movies like "the full
>>monty" or "trainspotting" because I can't understand a damn
>>word they say. British talk sounds like gibberish to me for the
>>most part.
>
> Not just you. It always amuses me in trips to the US that
> British voices (outside of the movies) are often subtitled,
> while first-generation Americans whose English is. um,
> limited, are not.

What?!?  I've never seen a British voice (inside or outside of
the movies) subtitled -- with the exception of one of a
nightclub scenes in one movie (I think it was Trainspotting)
where the dialog was inaudible because of the music.

While we're off this topic again topic, I was watching a BBC
series "Space Race" the other night.  The British actors did a
passable job with the American accents in the scenes at Fort
Bliss in Texas, but the writers wrote British English lines for
them to speak in their American accents.

For example: In British English one uses a plural verb when the
subject consists of more than one person.  Sports teams,
government departments, states, corporations etc. are 
grammatically plural.  In American, the verb agrees with the
word that is the subject, not how many people are denoted by
that word.

In sports (thats "sport" for you Brits):

 American: Minnesota is behind 7-0.  The Vikings are behind 7-0.
  British: Minnesota are behind 7-0. The Vikings are behind 7-0.

In politics:

  American: The war department has decided to cancel the program.
   British: The war department have decided to cancel the program.

And so on...

-- 
Grant Edwards   grante Yow!  I think I am an
  at   overnight sensation right
   visi.comnow!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie using python to update sql table

2005-10-06 Thread LenS
I have created a python program that takes a flat file and changes some
of the data and create a new flat file with the changes.  Part of this
process requires that I try to find a particular model car in an MS Sql
table.  This part of the program is now working great.

It has come to my attention that some of the information in the flat
file could be used to update our information in the MS Sql table that I
currently run the query on.  Basicly I create a recordset of vehicles
from the MS Sql table based on vehicle year and make and once I have
this recordset I run it through logic which does a reqular expression
compare on the vehicle VIN no to the
VIN number in the table to get a match.  I would like to update this
record in the table with info. in the flat file.  I believe there
should be some way to update the fields in this record of the recordset
and then update the table.  I am not an sql expert and would appreciate
someone pointing me in the right direction.  Contained below is a
listing of my code;

# The following code creates a connection object,
# assigns the connection string, opens the
# connection object, and then verifies a good
# connection.

oConn = Dispatch('ADODB.Connection')

oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\
 "Data Source=uicesv05;" +\
 "uid=aiis;" +\
 "pwd=aiis;" +\
 "database=auto_mo_001"

oConn.Open()
if oConn.State == adStateOpen:
print "Database connection SUCCEEDED"
else:
print "Database connection FAILED"

# The following code creates a command object,
# assigns the command to the connection object,
# sets the query, creates the parameters objects to
# be passed to the command object and requests the
# query to be prepared (compiled by the SQL system).

oCmd = Dispatch('ADODB.Command')
oCmd.ActiveConnection = oConn
oCmd.CommandType = adCmdText

oCmd.CommandText = """\
SELECT
VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,
VO_DESCRIPTION,VO_MODEL_ID
FROM D014800 INNER JOIN D014900
ON VA_MK_NUMBER_VER = VO_MAKE_NO AND
VA_MK_YEAR = VO_YEAR
WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ?
"""

vyear = ''
vmake = ''
oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput)
oParmYear.Size = 4
oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput)
oParmMake.Size = 10

oCmd.Parameters.Append(oParmYear)
oCmd.Parameters.Append(oParmMake)

oCmd.Prepared = True

...

def wrkveh(ifile,strstart,maxcnt):
""" wrkveh function does an SQL record lookup to try an select
the correct vehicle in the V1sta make and model files.  If the
correct model is found I move V1sta's make model and body
descriptions to the flat file.  Currently, I hard code a 1 for
vehicle use.  The drive segment is an occurs 6"""
cnt = 0
vehwrk = ''
while cnt < maxcnt:
if ifile[strstart:strstart + 10] == '  ':
vehwrk = vehwrk + ifile[strstart:strstart + 133]
else:
vmake = ifile[strstart:strstart + 10]
vyear = ifile[strstart + 98:strstart + 102]
vvin4_8 = ifile[strstart +53:strstart + 58]
vmodel = ''
vbody = ''
oParmYear.Value = vyear
oParmMake.Value = vmake
(oRS, result) = oCmd.Execute()
while not oRS.EOF:
wvin =
oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.')
wvin.replace('*','.')
wvin = wvin[0:5]
r1 = re.compile(wvin)
if r1.match(vvin4_8):
vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value
vmodel = oRS.Fields.Item("VO_MODEL").Value
vbody = oRS.Fields.Item("VO_DESCRIPTION").Value
vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value
print 'DRC model ' + vmake + ' ' + vyear + ' ' +
vmodel + \
  ' ' + vmodelid
break
else:
oRS.MoveNext()
else:
print 'DRC model NOT FOUND'
vehwrk = vehwrk + vmake + vmodel + vbody
vehwrk = vehwrk + ifile[strstart + 50:strstart + 107]
vehwrk = vehwrk + '1'
vehwrk = vehwrk + ifile[strstart + 108:strstart + 133]
strstart += 133
cnt += 1

return vehwrk

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


Re: Simple prototype text editor in python

2005-10-06 Thread Scott David Daniels
Robert Kern wrote:
> thakadu wrote:
>>Regarding the license I have not yet decided what type
>>of license (if any, since its very few lines of code)  but probably
>>will be GPL or BSD style. I have no former experience in
>>licensing code so any suggestions will be welcome there as well.

I've heard the MIT license (a BSD-style license) is a well-written
(legally) license that makes clear you still get credit, don't get
particular blame for ill side-effects, and allows others to use
and modify.  I personally like this style for Python code, since
that is the way Python was handed to me.

The GPL and LGPL are good alternatives if you believe in forcing
others to pen their code in exchange for using yours.  Pick
carefully there.

I'd suggest that picking from the above is the most useful,
picking from the larger range of "well-known" licenses is
second best, and writing your own is worst.  You might even
write "all rights reserved; write me for a particular case"
and get about the same response that writing your own will
get.  The reason for this ordering is that the MIT, LGPL,
and GPL are all licenses that are well-understood by most
programmers, so they needn't go into "reading like a lawyer"
mode to think about whether they can use things based on your
code.  The more work they have to do, the less likely they
will even look at your code (if they behave anything like me).

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Pyro 3.5 (remote objects)

2005-10-06 Thread Irmen de Jong
I'm glad to announce the new version of Python's own powerful
remote method invocation technology -- Pyro 3.5 (final)!

You can get it via http://pyro.sourceforge.net, then go
to the SF project homepage download area.

It has many new features and improvements over Pyro 3.4,
which was released mor than a year ago.

Most important new stuff:
- more efficient socket code, up to 20% performance gain
- mobile code bug fixes
- name server bug fixes
- added a few interesting new examples
- manual has been updated
- various other minor fixes and improvements

For the full list, see the change log in the manual:
http://pyro.sourceforge.net/manual/12-changes.html#latest

Have fun, and thanks for your interest, support, and feedback!

--Irmen de Jong


---> What is Pyro?
Pyro is an acronym for PYthon Remote Objects. Pyro is an advanced and
powerful Distributed Object Technology system written entirely in Python,
that is designed to be very easy to use.

It is extremely easy to implement a distributed system with Pyro, because all
network communication code is abstracted and hidden from your application.
You just get a remote Python object and invoke methods on the object on
the other machine.

Pyro offers you a Name Server, an Event Service, mobile objects, remote
exceptions, dynamic proxies, remote attribute access, automatic
reconnection, a very good and detailed manual, and many examples to get
you started right away.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-06 Thread Mike C. Fletcher
Lasse Vågsæther Karlsen wrote:

>I need to merge several sources of values into one stream of values. All 
>of the sources are sorted already and I need to retrieve the values from 
>them all in sorted order.
>
>In other words:
>s1 = [10, 20, 30, 40, 50]
>s2 = [15, 25]
>s3 = [17, 27, 37]
>
>for value in ???(s1, s2, s3):
> print value
>
>will print out 10, 15, 17, 20, 25, 27, 30, 37, 40, 50 in that order.
>
>The sources are cursors retrieving data from several databases, not from 
>the same server, and there's a potential for a large number of rows from 
>several of the sources. As such, any method that would load it all into 
>memory and sort it is no good as it would too much memory.
>
>Is there a function or whatnot in Python that will do what I want? I 
>have come up with my own method but since it uses generators I'm not 
>sure how much overhead there is. Additionally, since the values 
>retrieved from the cursors will be dictionaries of "fieldname":value 
>pairs, the method would either need to handle that construct (and be 
>told what fieldname to sort on), or be able to take a function object to 
>use for the comparison operation.
>
>Basically, I'll use my own function for this unless someone can point me 
>to something that is already available. Couldn't seem to find anything 
>in the builtin modules but I didn't find glob.glob when I was looking 
>for how to find filenames either so who knows what it's called :)
>
>Since I need to deal with a variable list of sources (that is, 2 in one 
>application, 3 in another and 4-5 in a third), a simple 2-source method 
>isn't enough but if it's better than what I do for 2 sources then I can 
>make a wrapper for it, since that's what I do anyway.
>  
>
I doubt you'll find a prebuilt one, it's fairly easy to create your own, 
after all.  Generators are fairly fast constructs in Python, btw.  
Here's what I whipped up in a few minutes:

def firstIter( value ):
it = iter( value )
try:
return it.next(), it
except StopIteration, err:
return None, None

def inorder( comparision, *args ):
iterators = [
[value,it]
for (value,it) in [ firstIter( arg ) for arg in args ]
if it is not None
]
iterators.sort()
while iterators:
yield iterators[0][0]
try:
value = iterators[0][0] = iterators[0][1].next()
except StopIteration, err:
iterators.pop(0)
else:
if len(iterators) > 1 and comparision( value, 
iterators[1][0]) == 1:
iterators.sort()
continue

if __name__ == "__main__":
s1 = [10, 20, 30, 40, 50]
s2 = [15, 25]
s3 = [17, 27, 37]
s4 = []
for value in inorder(cmp, s1, s2, s3, s4):
print value


Anyway, have fun,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Continuous system simulation in Python

2005-10-06 Thread hrh1818
A good starting point is the book "Python Scripting for Computational
Science" by Hans Petter Langtangen.  The book covers topics that go
from simulating second order mechanical systems to solving partial
differentail equations.

Howard

Nicolas Pernetty wrote:
> Hello,
>
> I'm looking for any work/paper/ressource about continuous system
> simulation using Python or any similar object oriented languages (or
> even UML theory !).
>
> I'm aware of SimPy for discrete event simulation, but I haven't found
> any work about continuous system.
> I would like to develop a generic continous system simulator, and so
> would be eager to join any open source effort on the subject.
>
> For instance, it would be useful for modelling an airplane with all the
> dynamics (flight simulator).
>
> Python is my language of choice because of the keyword 'generic'. Being
> an object oriented dynamic language, it's perfect for such a task.
> Unfortunately I'm a novice when it comes to object oriented
> design and development, so I would prefer to start from something
> already existent instead of starting from scratch.
>
> If you had any idea on the subject, I would be really glad to discuss it
> with you.
> 
> Thanks in advance,
> 
> P.S. : for email, replace nowhere by yahoo

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


Re: Force flushing buffers

2005-10-06 Thread Scott David Daniels
Madhusudan Singh wrote:
> I have a python application that writes a lot of data to a bunch of 
> files
> from inside a loop. Sometimes, the application has to be interrupted and I
> find that a lot of data has not yet been writen (and hence is lost). How do
> I flush the buffer and force python to write the buffers to the files ? I
> intend to put this inside the loop.
> 
> Thanks.
 ...
 files_to_close = []
 try:
somefile = open(somename, 'w')
files_to_close.append(somefile)
... calculations, probably in a loop ...
 finally:
 for afile in files_to_close:
 afile.close()
 ...

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Force flushing buffers

2005-10-06 Thread skip

Madhusudan> How do I flush the buffer and force python to write the
Madhusudan> buffers to the files ? I intend to put this inside the loop.

f = open("somefile", "w")
f.write("foo")
f.flush()

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


Force flushing buffers

2005-10-06 Thread Madhusudan Singh
Hi

I have a python application that writes a lot of data to a bunch of 
files
from inside a loop. Sometimes, the application has to be interrupted and I
find that a lot of data has not yet been writen (and hence is lost). How do
I flush the buffer and force python to write the buffers to the files ? I
intend to put this inside the loop.

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-10-06 Thread DaveM
On Tue, 28 Jun 2005 14:52:44 -0700, James Stroud <[EMAIL PROTECTED]>
wrote:

>Frankly, I can't watch Shakespeare or movies like "the full monty" or 
>"trainspotting" because I can't understand a damn word they say. British talk 
>sounds like gibberish to me for the most part.

Not just you. It always amuses me in trips to the US that British voices
(outside of the movies) are often subtitled, while first-generation
Americans whose English is. um, limited, are not.

Try pretending the British accents are from naturalised US citizens. That
should do the trick.

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


Continuous system simulation in Python

2005-10-06 Thread Nicolas Pernetty
Hello,

I'm looking for any work/paper/ressource about continuous system
simulation using Python or any similar object oriented languages (or
even UML theory !).

I'm aware of SimPy for discrete event simulation, but I haven't found
any work about continuous system.
I would like to develop a generic continous system simulator, and so
would be eager to join any open source effort on the subject.

For instance, it would be useful for modelling an airplane with all the
dynamics (flight simulator).

Python is my language of choice because of the keyword 'generic'. Being
an object oriented dynamic language, it's perfect for such a task.
Unfortunately I'm a novice when it comes to object oriented
design and development, so I would prefer to start from something
already existent instead of starting from scratch.

If you had any idea on the subject, I would be really glad to discuss it
with you.

Thanks in advance,

P.S. : for email, replace nowhere by yahoo
-- 
http://mail.python.org/mailman/listinfo/python-list


dcop module under Python 2.4

2005-10-06 Thread qwweeeit
Hi all,
at the end I upgraded to 2.4, but now I am not able to load dcop module
(part of the Python-KDE3 bindings).
Any help?
Bye.

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


Re: interactive window vs. script: inconsistent behavior

2005-10-06 Thread Larry Bates
This also works and IMHO reads better:

d="5-18-05 to 5-31-05"
f,t=d.split(' to '))

Larry Bates

Bell, Kevin wrote:
> The following works in the interactive window of PythonWin, but fails in
> a script.  TypeError: Objects of type 'slice' can not be converted to a
> COM VARIANT
> 
> I just need to parse out these dates, but it's making me crazy.
> Shouldn't it work in both the interactive window and a script?  
> 
> 
> 
d = "5-18-05 to 5-31-05"
print d[0:d.find("to")-1]
> 
> 5-18-05
> 
print d[d.find("to")+3:]
> 
> 5-31-05
> 
> 
> 
> 
> 
> Kev
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Bug in COM Makepy utility? (ActivePython 2.4)

2005-10-06 Thread Steve M
When I use the COM Makepy utility on one computer with WindowsXP,
ActivePython 2.3 and I select the library Microsoft Word 10.0 Object
Library (8.2), things work fine.
When I have WindowsXP, ActivePython 2.4 (build 247) and Microsoft Word
11.0 Object Library (8.3), then I get the following SyntaxError, and on
two different computers I tested this. More on the error below, but has
anyone else had this problem? Will there soon be a newer build of
ActivePython? I've never used the standard Python distribution with
manually installed win32all package, just because its so easy to deploy
ActivePython. Should I consider switching, now that I'm on the topic?


>>> Generating to 
>>> C:\Python24\lib\site-packages\win32com\gen_py\00020905---C000-0046x0x8x3\__init__.py
Building definitions from type library...
Generating...
Importing module
Failed to execute command:
from win32com.client import makepy;makepy.main()
Traceback (most recent call last):
  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\toolmenu.py",
line 103, in HandleToolCommand
exec "%s\n" % pyCmd
  File "", line 1, in ?
  File "C:\Python24\lib\site-packages\win32com\client\makepy.py", line
363, in main
GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel,
bForDemand = bForDemand, bBuildHidden = hiddenSpec)
  File "C:\Python24\lib\site-packages\win32com\client\makepy.py", line
274, in GenerateFromTypeLibSpec
gencache.AddModuleToCache(info.clsid, info.lcid, info.major,
info.minor)
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py",
line 555, in AddModuleToCache
mod = _GetModule(fname)
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py",
line 634, in _GetModule
mod = __import__(mod_name)
  File
"C:\Python24\lib\site-packages\win32com\gen_py\00020905---C000-0046x0x8x3\__init__.py",
line 2831
 '{00020960---C000-0046}' : 'Pane',
'{00020961---C000-0046}' : 'Windows',
   ^
 SyntaxError: invalid syntax


I don't entirely understand the error (I'm rather ignorant of the whole
process Makepy is doing, come to think of it...). First of all, when I
load the file with the alleged syntax error into Scite, the line where
the caret is pointing to is actually 2838, not line 2831. Further, I
cannot detect any syntax errors based on visual inspection. In fact,
when I copy/paste lines 2830-2840 into a new script and put "d = {"
before the lines and "}" after the lines, it is syntactically valid
python that executes without complaint. I don't know how "dynamically"
this file is being generated, but somethin' ain't right.

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


RE: Merging sorted lists/iterators/generators into one stream of values...

2005-10-06 Thread Delaney, Timothy (Tim)
Lasse Vågsæther Karlsen wrote:

> I need to merge several sources of values into one stream of values.
> All of the sources are sorted already and I need to retrieve the
> values from them all in sorted order.
> 
> In other words:
> s1 = [10, 20, 30, 40, 50]
> s2 = [15, 25]
> s3 = [17, 27, 37]
> 
> for value in ???(s1, s2, s3):
>  print value
> 
> will print out 10, 15, 17, 20, 25, 27, 30, 37, 40, 50 in that order.
> 
> The sources are cursors retrieving data from several databases, not
> from the same server, and there's a potential for a large number of
> rows from several of the sources. As such, any method that would load
> it all into memory and sort it is no good as it would too much memory.

I would suggest retrieving the first element from each data source. Then for 
the smallest element, keep retrieving from that data source until it is no 
longer the smallest element, at which time you switch to the data source with 
the smallest element.

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


Python, alligator kill each other

2005-10-06 Thread infidel
By Denise Kalette
Associated Press

MIAMI - The alligator has some foreign competition at the top of the
Everglades food chain, and the results of the struggle are horror-movie
messy.

A 13-foot Burmese python recently burst after it apparently tried to
swallow a live 6-foot alligator whole, authorities said.

...

... It is unknown how many pythons are competing with the thousands of
alligators in the Everglades, but at least 150 have been captured in
the past two years ...

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


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

2005-10-06 Thread Bengt Richter
On 6 Oct 2005 06:44:41 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:

>Op 2005-10-06, Bengt Richter schreef <[EMAIL PROTECTED]>:
>> On 5 Oct 2005 09:27:04 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>
>>>Antoon Pardon wrote:
>>>
 It also is one possibility to implement writable closures.
 
 One could for instace have a 'declare' have the effect that
 if on a more inner scope such a declared variable is (re)bound it
 will rebind the declared variable instead of binding a local name.
>>>
>>>That is one possibility, but I think that it would be better to use a 
>>>keyword at the point of the assigment to indicate assignment to an outer 
>>>scope. This fits with the way 'global' works: you declare at (or near) the 
>>>assignment that it is going to a global variable, not in some far away part 
>>>of the code, so the global nature of the assignment is clearly visible. The 
>>>'global' keyword itself would be much improved if it appeared on the same 
>>>line as the assignment rather than as a separate declaration.
>>>
>>>e.g. something like:
>>>
>>>var1 = 0
>>>
>>>def f():
>>>  var2 = 0
>>>
>>>  def g():
>>> outer var2 = 1 # Assign to outer variable
>>> global var1 = 1 # Assign to global
>>
>> IMO you don't really need all that cruft most of the time. E.g., what if ':='
>> meant 'assign to variable wherever it is (and it must exist), searching 
>> according
>> to normal variable resolution order (fresh coinage, vro for short ;-), 
>> starting with
>> local, then lexically enclosing and so forth out to module global (but not 
>> to builtins).'
>
>Just some ideas about this
>
>1) Would it be usefull to make ':=' an expression instead if a
>   statement?
Some people would think so, but some would think that would be tempting the 
weak ;-)

>
>I think the most important reason that the assignment is a statement
>and not an expression would apply less here because '==' is less easy
>to turn into ':=' by mistake than into =
>
>Even if people though that kind of bug was still too easy
>
>2) What if we reversed the operation. Instead of var := expression,
>   we write expression =: var.
>
>IMO this would make it almost impossible to write an assignment
>by mistake in a conditional when you meant to test for equality.
It's an idea. You could also have both, and use it to differentiate
pre- and post-operation augassign variants. E.g.,

alist[i+:=2] # add and assign first, index value is value after adding

alist[i=:+2] # index value is value before adding and assigning

Some people might think that useful too ;-)

Hm, I wonder if any of these variations would combine usefully with the new
short-circuiting expr_true if cond_expr else expr_false ...

Sorry I'll miss the flames, I'll be off line a while ;-)

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


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

2005-10-06 Thread Mike Meyer
Barbier de Reuille <[EMAIL PROTECTED]> writes:

> Dans l'article <[EMAIL PROTECTED]>, Mike Meyer a écrit :
>> Pierre Barbier de Reuille <[EMAIL PROTECTED]> writes:
>>> Mike Meyer a écrit :
 Antoon Pardon <[EMAIL PROTECTED]> writes:
 
>Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
>
>>On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
>
>Declarations also allow easier writable closures. Since the declaration
>happens at a certain scope, the run time can easily find the correct
>scope when a variable is rebound.
 If it happens at runtime, then you can do it without declarations:
 they're gone by then. Come to think of it, most functional languages -
 which are the languages that make the heaviest use of closures - don't
 require variable declarations.
>>> Well, can you give a single example of such language ? Because all the
>>> functionnal language I know but one do need variable declaration : lisp,
>>> scheme, ocaml, haskell do need variable declaration ! Erlang do not ...
>> 
>> Scheme and lisp don't need variable declerations. Last time I looked,
>> Schemd didn't even *allow* variable declerations.
>
> When you want local variable in lisp you do :
>
> (let ((a 3)) (+ a 1))

Excep that's not a decleration, that's a binding. That's identical to
the Python fragment:

   a = 3
   return a + 1

except for the creation of the new scope. Not a variable decleration
in site.

> For global variable you may do:
>
> (defparameter *a* 4)
>
> or:
>
> (defvar *a* 4)

That's not Scheme. When I was writing LISP, those weren't
required. Which is what I said: variable declarations aren't required,
and aren't allowedd in Scheme.

> However, either way, variable assignment is done via :
>
> (setf *a* 5)
> (setf a 10)
>
> This is what I call variable declaration as you have different way
> to declare global variables and to assign them ... So the
> two operations are well defined and different.

Python uses "global foo" to declare global variables.

> And here there is a difference between static language and
> declarative ones ... Lisp is a dynamic language that needs variable
> declarations.

LISP doesn't need variable declarations. I certainly never wrote any
when I was writing it.

 Except declarations don't add functionality to the language. They
 effect the programing process. And we have conflicting claims about
 whether that's a good effect or not, all apparently based on nothing
 solider than personal experience. Which means the arguments are just
 personal preferences.
>>> Well, so why not *allow* for variable declaration ? Languages like Perl
>>> does that successfully ... you don't like : you don't do ! you like :
>>> you do ! A simple option at the beginning of the file tell the compilor
>>> if variable declaration is mandatory or not !
>> 
>> Perl is a red herring. Unless it's changed radically since I last
>> looked, undeclared variables in Perl have dynamic scope, not lexical
>> scope. While dynamically scoped variables are a powerful feature, and
>> there have been proposals to add them to Python, having them be the
>> default is just *wrong*. If I were writing in Perl, I'd want
>> everything declared just to avoid that. Of course, if Python behaved
>> that way, I'd do what I did with Perl, and change languages.
>
> I never said to adopt the whole Perl variable semantic. I just pointed
> what I think is a good idea in Perl and that help (IMHO) precising what
> I intended ...

And I pointed out that it's a good idea in Perl because it does
something that it doesn't need doing in Python.

 Dynamic languages tend to express a much wider range of programming
 paradigms than languages that are designed to be statically
 compiled. Some of these paradigms do away with - or relegate to the
 level of "ugly performance hack" - features that someone only
 experienced with something like Pascal would consider
 essential. Assignment statements are a good example of that.
>>> Well, could you be more specific once more ? I can't that many paradigm
>>> only available on dynamically typed languages ... beside duck-typing
>>> (which is basically a synonym for dynamically-typed)
>> I said "dynamic languages", *not* "dynamically typed languages". They
>> aren't the same thing. Dynamic languages let you create new functions,
>> variables and attributes at run time. Python lets you delete them as
>> well.  This means that simle declarations can't tell you whether or
>> not a variable will exist at runtime, because it may have been added
>> at run time.
> Ok, I misunderstood ... however, can you still point some *usefull*
> paradigm available to dynamic languages that you cannot use with static
> ones ? As there are so many, it shouldn't be hard for you to show us
> some !

I find the ability to add attributes to an object or class at run time
useful.

  http://www.mired.org/home/mwm/
I

Re: Lambda evaluation

2005-10-06 Thread Joshua Ginsberg
That's a damned elegant solution -- thank you...

However in trying to simplify my problem for presentation here, I think
I oversimplified a bit too much. Try this one:

>>> d = {}
>>> for x in [1,2,3]:
... d[x] = lambda *args: args[0]*x
...
>>> d[1](3)
9

The lambda is going to have to take arbitrary arguments, so I can't
specify x=x before the arbitrary arguments (otherwise, it gets
overridden) and I can't specify it afterward (syntax error). :-/ Thanks!

-jag

On Thu, 2005-10-06 at 16:27 -0400, Jp Calderone wrote:
> On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg <[EMAIL PROTECTED]> wrote:
> >So this part makes total sense to me:
> >
>  d = {}
>  for x in [1,2,3]:
> >... d[x] = lambda y: y*x
> >...
>  d[1](3)
> >9
> >
> >Because x in the lambda definition isn't evaluated until the lambda is
> >executed, at which point x is 3.
> >
> >Is there a way to specifically hard code into that lambda definition the
> >contemporary value of an external variable? In other words, is there a
> >way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
> >case that d[1](3) = 3?
> 
> There are several ways, but this one involves the least additional typing:
> 
> >>> d = {}
> >>> for x in 1, 2, 3:
> ... d[x] = lambda y, x=x: y * x
> ... 
> >>> d[1](3)
> 3
> 
> Who needs closures, anyway? :)
> 
> Jp

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


Re: Compile as static

2005-10-06 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
> However the executable size is always the same :/ Please assist.

At a minimum, you should edit Modules/Setup to compile all extension
modules in.

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


Re: So far (about editing tools)

2005-10-06 Thread Kenneth McDonald
As I did mention in my original post, Eclipse is indeed bloated.  
However, in spite of that, I've found it both fast and reliable (much  
to surprise). The only real problem is learning what functionality  
(the majority) to ignore.

PyDev offers nice integration with Python. If I run a python program  
from within PyDev, errors are reported on the console, and clicking  
on an error takes me to the offending line number. Jython is also  
supported, though I haven't tried it.

I personally gave up on Emacs after spending four hours trying to get  
a perfectly simple keybinding working, and receiving no response from  
the emacs mailing list--they were apparently as mystified as I.

I don't mean to push Eclipse, but I looked at it several times before  
trying it, and backed off due to the concerns mentioned here. Once I  
actually sat down with it for about four hours to _concentrate_ on  
it, though, it rapidly became obvious that it with PyDev really was  
the best Python solution I'd found. If you do a lot of Python work,  
it's worth the effort to learn.

Ken
On 6-Oct-05, at 3:24 PM, Paul Rubin wrote:

> Micah Elliott <[EMAIL PROTECTED]> writes:
>
>> Furthermore, Eclipse requires java and is thusly not provided on any
>> linux distro I'm familiar with, which I consider a huge  
>> roadblock.  And
>> as mentioned, it's bloated.
>>
>
> It comes with Fedora Core 4 and is compiled with gcj.
>
>
>> I would suspect that the majority of Python programmers write in  
>> one of
>> vim or emacs. Anyone got stats?
>>
>
> I'm a long time emacs bigot but lately I've been editing Python with
> IDLE.  IDLE leaves a lot to be desired but its integration is very
> convenient.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>

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


Re: New Python book

2005-10-06 Thread Aahz
In article <[EMAIL PROTECTED]>,
Scott David Daniels  <[EMAIL PROTECTED]> wrote:
>
>You could ask over on comp.lang.python.education 

comp.lang.python.education is a rogue newsgroup; it won't appear on many
newsservers.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The way to build large Python applications is to componentize and
loosely-couple the hell out of everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda evaluation

2005-10-06 Thread Duncan Booth
Jp Calderone wrote:

> On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg
> <[EMAIL PROTECTED]> wrote: 
>>So this part makes total sense to me:
>>
> d = {}
> for x in [1,2,3]:
>>... d[x] = lambda y: y*x
>>...
> d[1](3)
>>9
>>
>>Because x in the lambda definition isn't evaluated until the lambda is
>>executed, at which point x is 3.
>>
>>Is there a way to specifically hard code into that lambda definition
>>the contemporary value of an external variable? In other words, is
>>there a way to rewrite the line "d[x] = lambda y: y*x" so that it is
>>always the case that d[1](3) = 3?
> 
> There are several ways, but this one involves the least additional
> typing: 
> 
> >>> d = {}
> >>> for x in 1, 2, 3:
> ... d[x] = lambda y, x=x: y * x
> ... 
> >>> d[1](3)
> 3
> 
> Who needs closures, anyway? :)
> 

Just for completeness, here's the lambda free closure version:

>>> def timesx_factory(x):
def timesx(y):
return y * x
return timesx

>>> d = dict((x, timesx_factory(x)) for x in range(1,4))
>>> d[1](3)
3
>>> d[2](3)
6
>>> 
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-06 Thread Steve Holden
Ron Adam wrote:
> Fredrik Lundh wrote:
> 
> 
>>Ron Adam wrote:
>>
>>
>>
>>>Is there a way to conditionally decorate?  For example if __debug__ is
>>>True, but not if it's False?  I think I've asked this question before. (?)
>>
>>
>>the decorator is a callable, so you can simply do, say
>>
>>from somewhere import debugdecorator
>>
>>if not __debug__:
>>debugdecorator = lambda x: x
> 
> 
> Ah... thanks.
> 
> I suppose after(if) lambda is removed it would need to be.
> 
> def nulldecorator(f):
> return f
> 
> if not __debug__:
>debugdecorator = nulldecorator
> 
It would be easier to write

 if not __debug__:
 def debugdecorator(f):
 return f

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

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


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

2005-10-06 Thread Barbier de Reuille
Dans l'article <[EMAIL PROTECTED]>, Mike Meyer a écrit :
> Pierre Barbier de Reuille <[EMAIL PROTECTED]> writes:
>> Mike Meyer a écrit :
>>> Antoon Pardon <[EMAIL PROTECTED]> writes:
>>> 
Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:

>On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:

Declarations also allow easier writable closures. Since the declaration
happens at a certain scope, the run time can easily find the correct
scope when a variable is rebound.
>>> If it happens at runtime, then you can do it without declarations:
>>> they're gone by then. Come to think of it, most functional languages -
>>> which are the languages that make the heaviest use of closures - don't
>>> require variable declarations.
>> Well, can you give a single example of such language ? Because all the
>> functionnal language I know but one do need variable declaration : lisp,
>> scheme, ocaml, haskell do need variable declaration ! Erlang do not ...
> 
> Scheme and lisp don't need variable declerations. Last time I looked,
> Schemd didn't even *allow* variable declerations.

When you want local variable in lisp you do :

(let ((a 3)) (+ a 1))

For global variable you may do:

(defparameter *a* 4)

or:

(defvar *a* 4)

However, either way, variable assignment is done via :

(setf *a* 5)
(setf a 10)

This is what I call variable declaration as you have different way
to declare global variables and to assign them ... So the
two operations are well defined and different. And here there is a
difference between static language and declarative ones ... Lisp is a
dynamic language that needs variable declarations.

> 
>>> Only in a few cases. Type inferencing is a well-understood
>>> technology, and will produce code as efficient as a statically type
>>> language in most cases.
>> Type inferencing only works for statically typed languages AFAIK ! In a
>> dynamically typed languages, typing a variable is simply impossible as
>> any function may return a value of any type !
> 
> I think we're using different definitions of statically typed
> here. A language that is statically typed doesn't *need* type
> inferencing - the types are all declared! Type determines the thypes
> by inferenceing them from an examination of the program. So, for
> instance, it can determine that this function:

Well, indeed ... statically typed means only one thing : each *variable*
has a *static* type, i.e. a type determined at compile time. Once again,
OCaml and Haskell *are* statically typed but as they have type inference
you don't *need* to explicitely type your functions / variables. However
you *may* if you want ...

> 
> def foo():
> return 1
> 
> Won't ever return anything but an integer.
> 
I think language matters shouldn't be setlled by personal preferences.
>>> I have to agree with that. For whether or not a feature should be
>>> included, there should either be a solid reason dealing with the
>>> functionality of the language - meaning you should have a set of use
>>> cases showing what a feature enables in the language that couldn't be
>>> done at all, or could only be done clumsily, without the feature.
>> Wrong argument ... with that kind of things, you would just stick with
>> plain Turing machine ... every single computation can be done with it !
> 
> "Computation" is is not the same thing as "Functionality". If you
> think otherwise, show me how to declare an object with a Turing
> machine.

Well, that was "bad spirit" from me ;) My argument here wasn't serious
in any mean ...

> 
> And there's also the issue of "clumsily". Turing machines are clumsy
> to program in.
> 
> 
>>> Except declarations don't add functionality to the language. They
>>> effect the programing process. And we have conflicting claims about
>>> whether that's a good effect or not, all apparently based on nothing
>>> solider than personal experience. Which means the arguments are just
>>> personal preferences.
>> Well, so why not *allow* for variable declaration ? Languages like Perl
>> does that successfully ... you don't like : you don't do ! you like :
>> you do ! A simple option at the beginning of the file tell the compilor
>> if variable declaration is mandatory or not !
> 
> Perl is a red herring. Unless it's changed radically since I last
> looked, undeclared variables in Perl have dynamic scope, not lexical
> scope. While dynamically scoped variables are a powerful feature, and
> there have been proposals to add them to Python, having them be the
> default is just *wrong*. If I were writing in Perl, I'd want
> everything declared just to avoid that. Of course, if Python behaved
> that way, I'd do what I did with Perl, and change languages.

I never said to adopt the whole Perl variable semantic. I just pointed
what I think is a good idea in Perl and that help (IMHO) precising what
I intended ...

> 
>>> Antoon, at a guess I'd say that Python is the first time you've
>>> encountered a dynamnic language. Bein

Re: interactive window vs. script: inconsistent behavior

2005-10-06 Thread Duncan Booth
Bell, Kevin wrote:

> The following works in the interactive window of PythonWin, but fails in
> a script.  TypeError: Objects of type 'slice' can not be converted to a
> COM VARIANT
> 
> I just need to parse out these dates, but it's making me crazy.
> Shouldn't it work in both the interactive window and a script?  
> 
> 
 d = "5-18-05 to 5-31-05"
 print d[0:d.find("to")-1]
> 5-18-05
 print d[d.find("to")+3:]
> 5-31-05

> 

Not surprisingly, the above three lines work perfectly well in a script:

d = "5-18-05 to 5-31-05"
print d[0:d.find("to")-1]
print d[d.find("to")+3:]

and the output is:
C:\temp>t.py
5-18-05
5-31-05

Perhaps if you were to post an actual script which doesn't work and the 
actual error it generates, it might be possible to help you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda evaluation

2005-10-06 Thread Steve M
Here's another one:

>>> d = {}
>>> for x in [1,2,3]:
... d[x] = (lambda z: lambda y: y * z) (x)
... 
>>> d[1](3)
3
>>> d[2](3)
6

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


RE: interactive window vs. script: inconsistent behavior

2005-10-06 Thread Bell, Kevin
Oops!  Sorry about that post.  I'm pulling data from excel, and needed
to convert the object I pulled into a string before slicing.

I guess I should look (more thoroughly) before I leap.




-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Bell, Kevin
Sent: Thursday, October 06, 2005 2:44 PM
To: python-list@python.org
Subject: interactive window vs. script: inconsistent behavior

The following works in the interactive window of PythonWin, but fails in
a script.  TypeError: Objects of type 'slice' can not be converted to a
COM VARIANT

I just need to parse out these dates, but it's making me crazy.
Shouldn't it work in both the interactive window and a script?  


>>> d = "5-18-05 to 5-31-05"
>>> print d[0:d.find("to")-1]
5-18-05
>>> print d[d.find("to")+3:]
5-31-05
>>>




Kev


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


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

2005-10-06 Thread Ron Adam
Fredrik Lundh wrote:

> Ron Adam wrote:
> 
> 
>>Is there a way to conditionally decorate?  For example if __debug__ is
>>True, but not if it's False?  I think I've asked this question before. (?)
> 
> 
> the decorator is a callable, so you can simply do, say
> 
> from somewhere import debugdecorator
> 
> if not __debug__:
> debugdecorator = lambda x: x

Ah... thanks.

I suppose after(if) lambda is removed it would need to be.

def nulldecorator(f):
return f

if not __debug__:
   debugdecorator = nulldecorator


> or
> 
> def debugdecorator(func):
> if __debug__:
> ...
> else:
> return func
> 
> etc.

This one came to mind right after I posted.  :-)


>  




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


interactive window vs. script: inconsistent behavior

2005-10-06 Thread Bell, Kevin
The following works in the interactive window of PythonWin, but fails in
a script.  TypeError: Objects of type 'slice' can not be converted to a
COM VARIANT

I just need to parse out these dates, but it's making me crazy.
Shouldn't it work in both the interactive window and a script?  


>>> d = "5-18-05 to 5-31-05"
>>> print d[0:d.find("to")-1]
5-18-05
>>> print d[d.find("to")+3:]
5-31-05
>>>




Kev


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


Re: Lambda evaluation

2005-10-06 Thread Fredrik Lundh
Joshua Ginsberg wrote:

> So this part makes total sense to me:
>
> >>> d = {}
> >>> for x in [1,2,3]:
> ... d[x] = lambda y: y*x
> ...
> >>> d[1](3)
> 9
>
> Because x in the lambda definition isn't evaluated until the lambda is
> executed, at which point x is 3.
>
> Is there a way to specifically hard code into that lambda definition the
> contemporary value of an external variable? In other words, is there a
> way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
> case that d[1](3) = 3?

from earlier today:

http://article.gmane.org/gmane.comp.python.general/424262





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


ctypes questions

2005-10-06 Thread James Hu

Convert 

unsigned long imageSize;
Frame.pBuffer=new unsigned char[ imageSize ]

To 

buffer = (c_ubyte * imageSize)()# create array
Frame.pBuffer = addressof(buffer)

Frame.pBuffer =  (c_ubyte * imageSize)()
TypeError: can't multiply sequence by non-int

Please help me out, thanks in advance

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


SetBackgroundColor doesn't work for me

2005-10-06 Thread Tool69
Hi,
I'm on Linux Ubuntu Breezy with wxPython 2.6.1 and Python 2.4.1
installed.
I've made an app, but the BackgroundColors won't work on any of my
ListBoxes, they only work with Windows XP. Does someone had this
problem before ? Any suggestion ? 
thanks.

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


Re: Lambda evaluation

2005-10-06 Thread Jp Calderone
On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg <[EMAIL PROTECTED]> wrote:
>So this part makes total sense to me:
>
 d = {}
 for x in [1,2,3]:
>... d[x] = lambda y: y*x
>...
 d[1](3)
>9
>
>Because x in the lambda definition isn't evaluated until the lambda is
>executed, at which point x is 3.
>
>Is there a way to specifically hard code into that lambda definition the
>contemporary value of an external variable? In other words, is there a
>way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
>case that d[1](3) = 3?

There are several ways, but this one involves the least additional typing:

>>> d = {}
>>> for x in 1, 2, 3:
... d[x] = lambda y, x=x: y * x
... 
>>> d[1](3)
3

Who needs closures, anyway? :)

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


Re: So far (about editing tools)

2005-10-06 Thread Paul Rubin
Micah Elliott <[EMAIL PROTECTED]> writes:
> Furthermore, Eclipse requires java and is thusly not provided on any
> linux distro I'm familiar with, which I consider a huge roadblock.  And
> as mentioned, it's bloated.

It comes with Fedora Core 4 and is compiled with gcj.

> I would suspect that the majority of Python programmers write in one of
> vim or emacs. Anyone got stats?

I'm a long time emacs bigot but lately I've been editing Python with
IDLE.  IDLE leaves a lot to be desired but its integration is very
convenient.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-06 Thread Mike Meyer
Paul Rubin  writes:

> Mike Meyer <[EMAIL PROTECTED]> writes:
>> I think we're using different definitions of statically typed
>> here. A language that is statically typed doesn't *need* type
>> inferencing - the types are all declared! Type determines the thypes
>> by inferenceing them from an examination of the program. 
>
> I thought static typing simply means the compiler knows the types of
> all the expressions (whether through declarations or inference) so it
> can do type checking at compile time:
>
>> So, for instance, it can determine that this function:
>> 
>> def foo():
>> return 1
>> 
>> Won't ever return anything but an integer.
>
> Static typing in this case would mean that re.match('a.*b$', foo())
> would get a compile time error, not a runtime error, since re.match
> expects two string arguments.  This can happen through type inference
> w/o declarations.

Except for two problems:

One you noted:

> Note apropos the private variable discussion that CPython can't
> guarantee that foo() always returns an integer.  Something might
> change foo.func_code.co_code or something like that.

Two is that dynamic binding means that foo may not refer to the above
function when you get there at run time.

>> Maybe you're still writing code for a language with declerations? I
>> never felt that need. Then again, I came to Python from a language
>> that didn't require declerations: Scheme.
> I've done a fair amount of Lisp programming and have found the lack of
> compile-time type checking to cause about the same nuisance as in
> Python.

So have I - basically none at all.

>> > Well, in the end, I would really like an *option* at the beginning of a
>> > module file requiring variable declaration for the module. It would
>> > satisfy both the ones who want and the ones who don't want that ...
>> Nope. It would just change the argument from "Python should have ..."
>> to "You should always use ..." or "Module foo should use ...".
> Perl has a feature like that right now, and it doesn't lead to many such
> arguments.

As noted elsewhere, Perl isn't a good comparison. You don't simply say
"This variable exists", you say "this variable is local to this
function". Undeclared variables are dynamically bound, which means you
can get lots of non-obvious, nasty bugs that won't be caught by unit
testing. Making all your variables lexically bound (unless you really
need a dynamically bound variable) is a good idea. But that's already
true in Python.

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


Lambda evaluation

2005-10-06 Thread Joshua Ginsberg
So this part makes total sense to me:

>>> d = {}
>>> for x in [1,2,3]:
... d[x] = lambda y: y*x
...
>>> d[1](3)
9

Because x in the lambda definition isn't evaluated until the lambda is
executed, at which point x is 3.

Is there a way to specifically hard code into that lambda definition the
contemporary value of an external variable? In other words, is there a
way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
case that d[1](3) = 3?

Thanks!

-jag

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


Re: So far (about editing tools)

2005-10-06 Thread Micah Elliott
On Oct 06, Kenneth McDonald wrote:
> The only _real_ problem is the eclipse learning curve.

The only real *advantage* of Eclipse (over other suggested tools) is its
highly hyped automatic refactoring.  Admittedly, I have not used it for
Python development, but I'm skeptical of the feasibility of
auto-refactoring in general, and therefore acknowledge *no* advantage.
Furthermore, Eclipse requires java and is thusly not provided on any
linux distro I'm familiar with, which I consider a huge roadblock.  And
as mentioned, it's bloated.

> But, given  that eclipse will be around for a _long_ time, and given
> how nicely  PyDev is coming along, I actually expect this to become
> the de facto  standard Python editor (though it will take a while).

Was this a troll??  If so, you got me to bite.  I haven't heard a
feature mentioned in this thread that can't be done at least as easily
with a capable text editor like vim or emacs.

I'm not trying to start another editor war here.  They tend to have a
steeper learning curve than IDEs, but in my experience are largely worth
the learning investment.  I just wanted to say that I really doubt the
possibility of Eclipse becoming anywhere near standard, given any amount
of time.

I would suspect that the majority of Python programmers write in one of
vim or emacs. Anyone got stats?

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-06 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes:
> I think we're using different definitions of statically typed
> here. A language that is statically typed doesn't *need* type
> inferencing - the types are all declared! Type determines the thypes
> by inferenceing them from an examination of the program. 

I thought static typing simply means the compiler knows the types of
all the expressions (whether through declarations or inference) so it
can do type checking at compile time:

> So, for instance, it can determine that this function:
> 
> def foo():
> return 1
> 
> Won't ever return anything but an integer.

Static typing in this case would mean that re.match('a.*b$', foo())
would get a compile time error, not a runtime error, since re.match
expects two string arguments.  This can happen through type inference
w/o declarations.

Note apropos the private variable discussion that CPython can't
guarantee that foo() always returns an integer.  Something might
change foo.func_code.co_code or something like that.

> Maybe you're still writing code for a language with declerations? I
> never felt that need. Then again, I came to Python from a language
> that didn't require declerations: Scheme.

I've done a fair amount of Lisp programming and have found the lack of
compile-time type checking to cause about the same nuisance as in
Python.  I also notice that the successors to the old-time Lisp/Scheme
communities seem to now be using languages like Haskell.

> > Well, in the end, I would really like an *option* at the beginning of a
> > module file requiring variable declaration for the module. It would
> > satisfy both the ones who want and the ones who don't want that ...
> 
> Nope. It would just change the argument from "Python should have ..."
> to "You should always use ..." or "Module foo should use ...".

Perl has a feature like that right now, and it doesn't lead to many such
arguments.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: date reformatting

2005-10-06 Thread elbertlev
setup.py install

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


Re: date reformatting

2005-10-06 Thread Larry Bates
There's more than one way, but this one will work for
dates prior to 2000.

import time
datestring='8-15-05'
d=time.strptime(datestring,'%m-%d-%y')
number=1*d[0]+100*d[1]+d[2]
print number

-Larry Bates

Bell, Kevin wrote:
> Anyone aware of existing code to turn a date string "8-15-05" into the
> number 20050815?
> 
> The dateutil module has a parse method that looks perfect, I downloaded
> and unzipped it, but could figure out how to install it.  I using
> windows XP and py2.4.  
> 
> Any ideas?
> 
> 
> Kev
> 

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


Re: So far (about editing tools)

2005-10-06 Thread Kenneth McDonald
This is something I fought with for a long time. My overwhelming vote  
is Eclipse with the PyDev plugin. (Google search should reveal this).  
Here are the pros and cons.

1) Eclipse is a _big_ system, with a strong emphasis on Java. So  
there's a lot of functionality you need to learn to ignore, and  
finding all of the different settings you're interested in can be a  
chore. And you'll need to learn the "Eclipse Way" (eg using  
repositories.)

2) Also, some of the eclipse dialogs are not the most intuitive,  
IMHO. Though to be fair, almost no programs do a good job of this.

3) But, given its weight, Eclipse is surprisingly fast.

4) Also, Eclipse has _very_ flexible (including multistroke)  
keybindings. It comes with predefined emacs keybindings.

5) And, PyDev is really _quite_ nice. It can also use PyLint, which  
is a big plus. (It was the first time I'd used PyLint, and it caught  
a _lot_ of potential errors.)

6) Finally, the eclipse layout is very flexible, and can be set up to  
be almost entirely keyboard-navigable.

The only _real_ problem is the eclipse learning curve. But, given  
that eclipse will be around for a _long_ time, and given how nicely  
PyDev is coming along, I actually expect this to become the de facto  
standard Python editor (though it will take a while).

Oh yeah, installation is (pretty) simple.


Ken



On 6-Oct-05, at 2:36 PM, CppNewB wrote:

> I am absolutely loving my experience with Python.  Even vs. Ruby,  
> the syntax
> feels very clean with an emphasis on simplification.
>
> My only complaint is that there doesn't appear to be a great  
> commercial IDE
> for the language.  I've tried Komodo, etc and they are nice  
> applications,
> but they don't feel like they give me the "power" like a Visual  
> Studio or
> Delphi (I wish I could articulate better the differences). 
> Finding a
> descent GUI builder has been a challenge as well.  Most of them  
> have support
> for Dialogs, but what about more complex UI's?  I may need a  
> resizable frame
> within a resizable frame? I haven''t found a GUI builder with a  
> great feel
> yet.
>
> Other than that, my experience has been wonderful.  Even after my
> complaints, I plan on sticking with Python for a while.
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>

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


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

2005-10-06 Thread Fredrik Lundh
Ron Adam wrote:

> Is there a way to conditionally decorate?  For example if __debug__ is
> True, but not if it's False?  I think I've asked this question before. (?)

the decorator is a callable, so you can simply do, say

from somewhere import debugdecorator

if not __debug__:
debugdecorator = lambda x: x

or

def debugdecorator(func):
if __debug__:
...
else:
return func

etc.

 



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


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

2005-10-06 Thread Paul Rubin
Brian Quinlan <[EMAIL PROTECTED]> writes:
> Without a clear idea of the nature of the proposal, it is impossible
> to assess it's costs and benefits. So could a proponent of optional
> declarations please provide a more clear proposal?

There is no proposal on the table.  There's a discussion of how this
stuff can work, and whether it's useful.  As for how the compiler
deals with imported modules, see for example Common Lisp or Haskell or
ML--how do they do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-06 Thread Ron Adam
Bengt Richter wrote:
> On Wed, 05 Oct 2005 11:10:58 GMT, Ron Adam <[EMAIL PROTECTED]> wrote:

>>Looking at it from a different direction, how about adding a keyword to 
>>say,  "from this point on, in this local name space, disallow new 
>>names".  Then you can do...
>>
>>def few(x,y):
>>   a = 'a'
>>   b = 'b'
>>   i = j = k = l = None
>>   no_new_names
>>   # raise an error after here if a new name is used.
>>   ...
>>   for I in range(10):   <--  error
>>  ...
>>
>>This is more suitable to Pythons style than declaring types or variables 
>>I think.  Add to this explicit name-object locking to implement 
>>constants and I think you would have most of the features you want.
>>
> 
> You can do that now with a decorator, if you are willing to assign something
> to no_new_names (so it won't give you a name error if it doesn't exist). E.g.,

Works for me.

__lock_names__ = True

It's not too different than __name__ == '__main__'...


>  >>> def nnn(f):
>  ... names = f.func_code.co_names
>  ... assert 'no_new_names' not in names or names[-1]=='no_new_names', 
> 'Bad name:%r'%names[-1]
>  ... return f
>  ...
>  >>> @nnn
>  ... def few(x,y):
>  ... a = 'a'
>  ... b = 'b'
>  ... i = j = k = l = None
>  ... no_new_names=None
>  ... for i in range(10): print i,
>  ...
>  Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 3, in nnn
>  AssertionError: Bad name:'range'

Hmm... To make it work this way, the globals and arguments need to have 
local references.

@nnn
def few(x,y):
 global range
 range = range
 x,y = x,y
 a = 'a'
 b = 'b'
 i = j = k = l = None
 L = 1
 __no_new_names__ = True
 L += 1
 for i in range(x,y):
 print I

>  >>> @nnn
>  ... def few(x,y):
>  ... a = 'a'
>  ... b = 'b'
>  ... i = j = k = l = None
>  ... no_new_names=None
>  ... return a,b,i,j,k,l
>  ...
>  >>> few(123,456)
>  ('a', 'b', None, None, None, None)
> 
> No guarantees, since this depends on the unguaranteed order of 
> f.func_code.co_names ;-)

I had the thought that collecting the names from the 'STORE FAST' lines 
of dis.dis(f) would work nicely, but...  dis.dis() doesn't return a 
string like I expected, but prints the output as it goes.  This seems 
like it would be easy to fix and it would make the dis module more 
useful.  I'd like to be able to do...

D = dis.dis(f)

An alternate option to output the disassembly to a list of of tuples. 
That would make analyzing the output really easy.  ;-)

Something like...

good_names = []
nnnames = False
for line in dis.dislist(f):
if line[2] = 'SAVE_FAST':
if not nnnames:
if line[-1] = '(__no_new_names__)':
nnnames=True
continue
good_names.append(line[-1])
else:
 assert line[-1]in good_names, 'Bad name:%r'% line[-1] 



So, I wonder what kind of errors can be found by analyzing the disassembly?


>>so...
>>
>>no_new_names # limit any new names
>>lock_name name   # lock a name to it's current object
> 
> That last one you could probably do with a decorator that imports dis and
> checks the disassembly (or does the equivalent check of the byte code) of f
> for STORE_FASTs directed to particular names after the lock_name name 
> declaration,
> which you would have to spell as a legal dummy statement like
> lock_name = 'name'
> 
> or perhaps better, indicating a locked assignment e.g. to x by
> 
> x = lock_name = expr  # lock_name is dummy target to notice in 
> disassembly, to lock x from there on

Using dis.dis it becomes two sequential 'STORE_FAST' operations.  So add 
(x) to the don't change list, and catch it on the next 'STORE_FAST' for 
(x).  ;-)

  28  12 LOAD_GLOBAL  2 (True)
  15 DUP_TOP
  16 STORE_FAST   0 (x)
  19 STORE_FAST   8 (__lock_name__)


>>Since names are stored in dictionaries,  a dictionary attribute to 
>>disallow/allow new keys, and a way to set individual elements in a 
>>dictionary to read only would be needed.  Once you can do that and it 
>>proves useful, then maybe you can propose it as a language feature.
> 
> I would want to explore how to compose functionality with existing elements
> before introducing either new elements or new syntax. E.g., the dictionaries
> used for instance attribute names and values already exist, and you can 
> already
> build all kinds of restrictions on the use of attribute names via properties
> and descriptors of other kinds and via __getattribute__ etc.

That was more or less what I had in mind, but I think keeping things as 
passive as possible is what is needed.  One thought is to use this type 
of thing along with __debug__.

if __debug__: __nnn__ = True


Wouldn't a debug block or suite be better than an if __debug__:?  Just a 
thought.  Even if the -0 optio

Re: date reformatting

2005-10-06 Thread Fredrik Lundh
"Bell, Kevin" wrote:

> Anyone aware of existing code to turn a date string "8-15-05" into the
> number 20050815?

date = "8-15-05"

import re
m, d, y = map(int, re.match("(\d+)-(\d+)-(\d+)$", date).groups())
number = 2000 + y*1 + m*100 + d

print number

 



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


Re: IDLE won't run on WinXP

2005-10-06 Thread Lasse Vågsæther Karlsen
Lasse Vågsæther Karlsen wrote:
> striker wrote:
> 
>> I just downloaded and installed Python 2.4.2 on a Windows XP machine.
>> Everything I have tried so far has worked except for IDLE.  Is there

> Just a thought though, during the installation of Python on one machine 
> it mentioned that a dll was missing from my machine, try uninstalling it 


Try this page:

http://starship.python.net/crew/mhammond/win32/

it mentions MFC71.DLL for Python 2.4.2 that is likely to not be installed.

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


Re: IDLE won't run on WinXP

2005-10-06 Thread Lasse Vågsæther Karlsen
striker wrote:
> I just downloaded and installed Python 2.4.2 on a Windows XP machine.
> Everything I have tried so far has worked except for IDLE.  Is there
> some setting that I need to check?  Any help would be greatly
> appreciated.
> Kevin
> 

It runs perfectly for me, on several Windows XP machines running a 
variety of service packs, so it's not a general Windows XP problem.

Do you get any error messages? any indication as to what might be wrong 
that you can share with use? Does it crash ? Does anything happen when 
you click the start menu item?

Just a thought though, during the installation of Python on one machine 
it mentioned that a dll was missing from my machine, try uninstalling it 
and reinstalling it and see if the text you get at some point tells you 
that this dll is missing. I find it various places on the web, and I 
remember the text said something about Idle or Pythonwin, so it might be 
what you need. I think the name was something like MSVCRT71.DLL but 
don't think I got it 100% right just there... :P

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


Re: So far

2005-10-06 Thread Jaime Wyant
On 10/6/05, Bell, Kevin <[EMAIL PROTECTED]> wrote:
> I like pythonWin other than the white background where you write your 
> scripts, because after awhile it's bad on the eyes.  Does anyone know of a 
> free IDE that will allow control of this, as well as the coloring of 
> keywords, etc?
>

xemacs will do this.  But it will take "some getting used to" if you
have never used it.

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


Re: So far

2005-10-06 Thread Jaime Wyant
On 10/6/05, CppNewB <[EMAIL PROTECTED]> wrote:
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax
> feels very clean with an emphasis on simplification.
>

Yes.  We all love python, welcome aboard!

> My only complaint is that there doesn't appear to be a great commercial IDE
> for the language.  I've tried Komodo, etc and they are nice applications,
> but they don't feel like they give me the "power" like a Visual Studio or
> Delphi (I wish I could articulate better the differences).Finding a
> descent GUI builder has been a challenge as well.  Most of them have support
> for Dialogs, but what about more complex UI's?  I may need a resizable frame
> within a resizable frame? I haven''t found a GUI builder with a great feel
> yet.
>

wingide is really nice, but costs money.  It supports auto-completion
in a really intelligent way.  However, it was just too resource hungry
on my laptop - (1.4ghz Pentium(m), 512 mb ram).  Sometimes
autocompletion was just too slow (i noticed the HD spinning).

You're probably not going to find a GUI builder that has a nice
polished feel, like Delphi or Visual studio.  The *closest* thing you
may find to this would be Python's Boa-Constructor
(http://boa-constructor.sourceforge.net/).

If you choose to use wxPython as your GUI framework, then you may not
need a fancy-schmancy IDE.  I find that xemacs along with xrced work
really well for me.

The toughest thing about wxPython (and wxWidgets) is wrapping your
brain around sizers.  They're easy to understand -- until something
doesn't quite layout the way you expected.  Unusual layouts are always
a programmer's misunderstanding of sizers (at least in my experience).

I recommend trying either wxGlade/xrced for gui building (i find
wxGlade's latest release to be *REALLY* unstable for me in windows). 
Next use xemacs or Stanni's python editor to edit your code.

You'll be amazed at how productive you can be once you *learn* how to
handle building guis with one app, and manually tieing in the event
handlers in your editor of choice.  This will also `not hide' a lot of
things that goes on behind the scenes.

> Other than that, my experience has been wonderful.  Even after my
> complaints, I plan on sticking with Python for a while.

That's great!
jw
-- 
http://mail.python.org/mailman/listinfo/python-list


IDLE won't run on WinXP

2005-10-06 Thread striker
I just downloaded and installed Python 2.4.2 on a Windows XP machine.
Everything I have tried so far has worked except for IDLE.  Is there
some setting that I need to check?  Any help would be greatly
appreciated.
Kevin

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


Re: replacments for stdio?

2005-10-06 Thread Ido . Yehieli
Yes, i thought so myself.

Thanks,
Ido.

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


date reformatting

2005-10-06 Thread Bell, Kevin

Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?

The dateutil module has a parse method that looks perfect, I downloaded
and unzipped it, but could figure out how to install it.  I using
windows XP and py2.4.  

Any ideas?


Kev

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


Merging sorted lists/iterators/generators into one stream of values...

2005-10-06 Thread Lasse Vågsæther Karlsen
I need to merge several sources of values into one stream of values. All 
of the sources are sorted already and I need to retrieve the values from 
them all in sorted order.

In other words:
s1 = [10, 20, 30, 40, 50]
s2 = [15, 25]
s3 = [17, 27, 37]

for value in ???(s1, s2, s3):
 print value

will print out 10, 15, 17, 20, 25, 27, 30, 37, 40, 50 in that order.

The sources are cursors retrieving data from several databases, not from 
the same server, and there's a potential for a large number of rows from 
several of the sources. As such, any method that would load it all into 
memory and sort it is no good as it would too much memory.

Is there a function or whatnot in Python that will do what I want? I 
have come up with my own method but since it uses generators I'm not 
sure how much overhead there is. Additionally, since the values 
retrieved from the cursors will be dictionaries of "fieldname":value 
pairs, the method would either need to handle that construct (and be 
told what fieldname to sort on), or be able to take a function object to 
use for the comparison operation.

Basically, I'll use my own function for this unless someone can point me 
to something that is already available. Couldn't seem to find anything 
in the builtin modules but I didn't find glob.glob when I was looking 
for how to find filenames either so who knows what it's called :)

Since I need to deal with a variable list of sources (that is, 2 in one 
application, 3 in another and 4-5 in a third), a simple 2-source method 
isn't enough but if it's better than what I do for 2 sources then I can 
make a wrapper for it, since that's what I do anyway.

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


Book "Python and Tkinter Programming"

2005-10-06 Thread striker
Does anyone who has this book willing to sell it.  Please e-mail me the
condition and any other details if you are interested.
Thanks,
Kevin

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


Re: How to prevent logging warning?

2005-10-06 Thread Vinay Sajip
Thomas Heller wrote:

> I do *not* think 'no handler' is a misconfiguration. Is it possible to
> differentiate between a misconfiguration and 'no configuration'?

It's a fair point. The line was more blurred when the logging package
was newly released into the wild ;-) But "no configuration" could be
caused e.g. by an unreadable config file, which might also be
categorised as a "misconfiguration".

> That would be fine.  But there are also other ways - you could, for
> example, print the warning only when __debug__ is False.  And you could
> use the warnings module instead of blindly printing to stderr, this way
> it could also be filtered out.

Compatibility with 1.5.2 precludes use of the warnings module. If using
raiseExceptions meets your requirement, I'll use that. I'm not sure
it's a good idea for the behaviour to change between running with and
without -O.

> BTW: Since I have your attention now, is the graphical utility to
> configure the logging.conf file still available somewhere, and
> compatible with the current logging package (with 'current' I mean
> the one included with Python 2.3.5)?

You can always get my attention via email :-) The graphical utility
(logconf.py) is available from the download at

http://www.red-dove.com/python_logging.html#download

AFAIK it should work OK with 2.3.5, though I haven't tested it recently
as there wasn't much interest in it. In fact you're the first person to
ask! It generates a few extra entries in the config file which are used
by the utility only, which are seemingly regarded as "cruft" by most
people.

Regards,


Vinay Sajip

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


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

2005-10-06 Thread Mike Meyer
Pierre Barbier de Reuille <[EMAIL PROTECTED]> writes:
> Mike Meyer a écrit :
>> Antoon Pardon <[EMAIL PROTECTED]> writes:
>> 
>>>Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
>>>
On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
>>>
>>>Declarations also allow easier writable closures. Since the declaration
>>>happens at a certain scope, the run time can easily find the correct
>>>scope when a variable is rebound.
>> If it happens at runtime, then you can do it without declarations:
>> they're gone by then. Come to think of it, most functional languages -
>> which are the languages that make the heaviest use of closures - don't
>> require variable declarations.
> Well, can you give a single example of such language ? Because all the
> functionnal language I know but one do need variable declaration : lisp,
> scheme, ocaml, haskell do need variable declaration ! Erlang do not ...

Scheme and lisp don't need variable declerations. Last time I looked,
Schemd didn't even *allow* variable declerations.

>> Only in a few cases. Type inferencing is a well-understood
>> technology, and will produce code as efficient as a statically type
>> language in most cases.
> Type inferencing only works for statically typed languages AFAIK ! In a
> dynamically typed languages, typing a variable is simply impossible as
> any function may return a value of any type !

I think we're using different definitions of statically typed
here. A language that is statically typed doesn't *need* type
inferencing - the types are all declared! Type determines the thypes
by inferenceing them from an examination of the program. So, for
instance, it can determine that this function:

def foo():
return 1

Won't ever return anything but an integer.

>>>I think language matters shouldn't be setlled by personal preferences.
>> I have to agree with that. For whether or not a feature should be
>> included, there should either be a solid reason dealing with the
>> functionality of the language - meaning you should have a set of use
>> cases showing what a feature enables in the language that couldn't be
>> done at all, or could only be done clumsily, without the feature.
> Wrong argument ... with that kind of things, you would just stick with
> plain Turing machine ... every single computation can be done with it !

"Computation" is is not the same thing as "Functionality". If you
think otherwise, show me how to declare an object with a Turing
machine.

And there's also the issue of "clumsily". Turing machines are clumsy
to program in.


>> Except declarations don't add functionality to the language. They
>> effect the programing process. And we have conflicting claims about
>> whether that's a good effect or not, all apparently based on nothing
>> solider than personal experience. Which means the arguments are just
>> personal preferences.
> Well, so why not *allow* for variable declaration ? Languages like Perl
> does that successfully ... you don't like : you don't do ! you like :
> you do ! A simple option at the beginning of the file tell the compilor
> if variable declaration is mandatory or not !

Perl is a red herring. Unless it's changed radically since I last
looked, undeclared variables in Perl have dynamic scope, not lexical
scope. While dynamically scoped variables are a powerful feature, and
there have been proposals to add them to Python, having them be the
default is just *wrong*. If I were writing in Perl, I'd want
everything declared just to avoid that. Of course, if Python behaved
that way, I'd do what I did with Perl, and change languages.

>> Antoon, at a guess I'd say that Python is the first time you've
>> encountered a dynamnic language. Being "horrified" at not having
>> variable declarations, which is a standard feature of such languages
>> dating back to the 1950s, is one such indication.
> Dynamic language and variable declaration are non-related issues ! You
> can have statically-typed language without variable declaration (i.e.
> BASIC) and dynamically-typed language with (i.e. Lisp) ! Please, when
> you says something about languages, at least give 1 name of language
> asserting what you're saying !

Declerations and typing are *also* non-related issues. See Perl. Also
see the subject line.

>> Dynamic languages tend to express a much wider range of programming
>> paradigms than languages that are designed to be statically
>> compiled. Some of these paradigms do away with - or relegate to the
>> level of "ugly performance hack" - features that someone only
>> experienced with something like Pascal would consider
>> essential. Assignment statements are a good example of that.
> Well, could you be more specific once more ? I can't that many paradigm
> only available on dynamically typed languages ... beside duck-typing
> (which is basically a synonym for dynamically-typed)

I said "dynamic languages", *not* "dynamically typed languages". They
aren't the same thing. Dynamic languages let you cr

Re: Can Python replace TCL/Expect

2005-10-06 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Jorgen Grahn  <[EMAIL PROTECTED]> wrote:
.
.
.
>It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's
>limitations several times in several places.
>
>... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I
>have to admit that its expect functionality is far superior to Python's.
.
.
.
'Salright.  There are Tcl programmers who feel the same way,
for example, about Python and its object orientation.

On to more constructive matters:  what are you doing about
Pexpect's limitations?  Have the maintainers responded to you
when you write?  Are you tempted to compose enhancements for
yourself?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread bruno modulix
CppNewB wrote:
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE

Why "commercial" ?


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


Re: Build spoofed IP packets

2005-10-06 Thread billie
> It's SP2. Microsoft decided allowing raw socket access is a security 
> threat and disabled it in SP2.
Uhm.. I heard about that. Damn it. :-\ 


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


Re: Extending Python

2005-10-06 Thread Jorgen Grahn
On 5 Oct 2005 10:38:21 -0700, Tuvas <[EMAIL PROTECTED]> wrote:
> I am looking for a good tutorial on how to extend python with C code. I
> have an application built in C that I need to be able to use in Python.
> I have searched through various sources, starting of course with the
> Python site itself, and others, but I felt a bit lacking from the
> Python site, it seems it was only made for those who installed the
> source distribution, as for the other people...

So -- install the source distribution, then! You only want one or two
example files from it anyway. I have seen no need for it, personally.
You certainly don't have to compile your own Python to extend it.

> Anyways, thanks for the
> help!

Some work in progress, for what it's worth. Might serve as an example, but
don't trust it too much. It's yet-another literal interface to libpcap.

  http://snipabacken.dyndns.org/~grahn/tmp/pcap2/

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Accessibility of Docs on Win32: Navigation, Names and PyDoc

2005-10-06 Thread Veli-Pekka T�til
Hi,
My first post here. I've found some serious accessibility flaws in the 
Python 2.4 docs and wish they could be rectified over time. I'm very new to 
Python and initially contacted docs at python org, However, I haven't gotten 
a reply for a week or so, and figured out I could post here for a larger 
audience, then.

Original message follows:

Hello,
I'm a visually impaired programmer concerned about the accessibility of
Python documentation. I'm still new to Python and mainly using Perl and
Java, largely because of the relatively inaccessible documentation in
Python.

I'd like to report three key issues that I've discovered related to Python
documentation as follows:

1. Navigation in Functions

A single page tends to contain a large number of functions with no way for
screen reader users to find the next function or get a quick overview of
what's on offer. Sighted folk can easily skim through the page but people
relying on screen reader programs or heavy magnification can concentrate
only on a very small area of the screen. This is often referred to as the
straw analogy because it resembles looking at the screen contents through a
thin straw.

Many of the more advanced Windows screen readers such as Freedom
Scientific's Jaws (the most popular) or Dolphin Supernova (the one I'm
using) can list and directly navigate to links, frames and headings on the
page provided that you are using Internet Explorer or HTML help. However,
these features are only marginally helpful in Python documentation.

I've looked at the source and it appears function names are bold tt elements
of class function. This representation has several drawbacks from an
accessibility point of view:

Firstly, there are no means for moving in terms of TT elements directly.
Secondly, TT elements cannot be listed or randomly navigated to from the
keyboard. And finally even the semantics are lost as the readre doesn't
announce the class function. In stead you are told meaningless details such
as that the function name is in Courier New 12 point and the parentheses
following the name are Times New Roman 13 point. Confronted with this info
alone, it is not at all clear that this formatting has special significance.

Some basic or very new screen readers like MIcrosoft Narrator, Gnome's
Gnopernicus or Apple's VoiceOver do even worse. You might not get the
formatting information at all, and many readres don't offer as wide and
extensive a variety of navigation functions as JAws or SUpernova do. One
quick-n-dirty solution is to find the function names in the HTML source but
it is very difficult to read because of all the numeric identifiers and HTml
tags themselves.

One easy fix would be to turn the function names preceeding their
documentation into headings. This would give the right semantics and allow
direct navigation for the more advanced readers. However, listing links, or
finding a link based on some text, are screen reader or Web browser specific
actions and not universally available.

Another way used in say JavaDoc is to include a separate navigation section
having function prototypes and the first sentence of their description at
the top of the file. While the link based method is generally effective,
some screen readres have difficulty in quickly returning to the top or
moving the focus to links close to something at the bottom of the page. In
addition to issues encountered with headings, many browsers only offer
sequential navigation from one link to the next using the tab key. SO if you
have dozens of functions, you need to press tab or shit+tab loads, or else
use some screen reader specific action to rapidly move to a particular link.

It should also be noted that one should use the whole prototype as a link
and not just the name as in JavaDoc. The reason is that if functions differ
by their signature alone, it is tedious to figure out which function is in
question based on the link name. HTMl guidelines recommend that links are
independent of their surroundings (context-free?).

To universally get rid of the lack of link listing or quick navigation
facilities, an additional HTML list box could be added. The items should be
in alphabetical order and there should be a separate default button for
actually jumping to the selected list item. Auto-jumps are bad because
traversing and reading the list item names from the keyboard can cause focus
changes. So  you may be unexpectedly taken away from the list box and might
not have enough time to read the whole name or ponder whether it is the one
you want. If using list separators, they shouldn't be made of punctuation
characters alone because many screen reader users, me included, have
punctuation set to none and thus nothing is spoken. The navigation list
ought to have a clearly visible and unambiguous text label saying that it is
a navigation list. Do avoid the term menu because to Windows screen reader
users, list boxes are never prompted as being menus, unlike on the Mac.

Even list b

Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
WELL, I figured it out--thanks to everyone's help. There were instances
of the object and I am a total moron.

Thanks again to everyone who helped me stomp this out. :)

On Wed, 2005-10-05 at 21:58 -0400, Jeremy Moles wrote:
> So, here is my relevant code:
> 
>   PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> 
> And here ismy error message:
> 
>   argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> 
> I know PyType_vector3d "works" (as I can use them in the interpreter all
> day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> not...)
> 
> I've spent hours and hours on this and I'm finally just giving up and
> asking. I've tried everything to get my program to verify that arg1 is
> really a PyType_vector3d, but to no avail.
> 
> If I take out the "!" in the format string and just use "O", I can at
> least get past PyArg_ParseTuple. Then I try something like...
> 
>   PyObject_TypeCheck(arg1, &PyType_vector3d)
> 
> Which also fails, but I know for a fact that arg1's PyObject_Repr is
> what it should be. (pylf.core.vector3d)
> 
> I guess my question is: what in the world could be causing this to fail?
> It seems like I'm just not able to use ParseType or BuildValue to create
> objects of my own type.
> 
> I know I haven't provided a lot of information, but does anyone have any
> ideas or where I should start looking?
> 

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


Re: Simple prototype text editor in python

2005-10-06 Thread thakadu
Thanks Robert

I have packaged it up with distutils and included the
license in the README.txt file.
I think I am missing something as I have only
seen a place (under submissions) on
http://python.org/pypi?%3Aaction=submit_form
to submit the PKG_INFO file, or to submit a url manually
but nowhere to actually upload the distribution file. (the tar.gz file)

Am I looking in the wrong place? Or is it acceptable to post a .tar.gz
file in place of the PKG_INFO file?

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


Re: So far

2005-10-06 Thread Michael Schneider
Take a look at:

http://wingware.com/

It is only $35.00 for an IDE. (30 day free eval version)

I use eclipse for java, and have become quite fond of tab completion.

Mike

CppNewB wrote:
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: So far

2005-10-06 Thread Bell, Kevin
I like pythonWin other than the white background where you write your scripts, 
because after awhile it's bad on the eyes.  Does anyone know of a free IDE that 
will allow control of this, as well as the coloring of keywords, etc?



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christophe
Sent: Thursday, October 06, 2005 9:50 AM
To: python-list@python.org
Subject: Re: So far

CppNewB a écrit :
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 

Try PyQT with eric3 as an IDE.

http://www.die-offenbachs.de/detlev/eric3.html
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacments for stdio?

2005-10-06 Thread Martin Miller
In what way would you like to get "stdin to work"? In Bryan's post in
the Application(Frame).__init__() he binds some lambda functions to key
strokes which allow control-C copying of text in the window.

Seems like additonal application-specific things might be possible, but
then the code would no longer be generic. Interaction with the main
application would likely be tricky because each output window is
lanuched as a separate process when output is first sent to it.

As far a redistribution goes, I would think anything posted to the
public comp.lang.python usenet newgroup is unencumbered unless the
author indicates otherwise -- or at most covered by the same open
source license as Python.

-Martin


[EMAIL PROTECTED] wrote:
> yes,
> I've tried it aswell - nice work indeed!
> 
> now, maybe also get stdin to work from this TK window... ;-)

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


Re: Swig and pointers

2005-10-06 Thread Java and Swing
(reposting, i was just told how I should properly reply via
groups.google.com)

im sorry, why would it be md_ptr?  what is md_ptr?

i tried..
%include cpointer.i
%pointer_functions(MY_DIGIT, digit_ptr)

ptr = new_digit_ptr()
doIt("a message", ptr)
...doesnt work..still needs a DIGIT **


Miki Tebeka wrote:
> Hello Java,
>
> > ...
> > extern int doIt(char *a, MY_DIGIT **digit);
> > %include cpointer.i
> > %pointer_functions(MY_DIGIT, md_prt);
> Don't you mean md_ptr?
>
> > %typemap(in) (char *a, MY_DIGIT **argv) {
> >   /* Check if is a list */
> >   if (PyList_Check($input)) {
> > int i;
> > $1 = PyList_Size($input);
> > $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *));
> > for (i = 0; i < $1; i++) {
> >   PyObject *o = PyList_GetItem($input,i);
> >   if (PyString_Check(o))
> > $2[i] = PyString_AsString(PyList_GetItem($input,i));
> >   else {
> > PyErr_SetString(PyExc_TypeError,"list must contain strings");
> > free($2);
> > return NULL;
> >   }
> > }
> > $2[i] = 0;
> >   } else {
> > PyErr_SetString(PyExc_TypeError,"not a list");
> > return NULL;
> >   }
> > }
> >
> > %typemap(freearg) (char *a, MY_DIGIT **argv) {
> >   free((MY_DIGIT *) $2);
> > }
> >
> >
> > ..from Python I am trying
> >
> > >> ptr = []
> > >> doIt("blah", ptr)
> >
> > I thought this was the correct approach as described here:
> > http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59
> >
> > However, python comes back and says "TypeError: argument number 2: a
> > 'MY_DIGIT **' is expected, 'list([])' is received"
> >
> > ..any ideas?
> Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks
> like you need to do:
> ptr = new_md_prt()
>
> HTH.
> --
> 
> Miki Tebeka <[EMAIL PROTECTED]>
> http://tebeka.bizhat.com
> The only difference between children and adults is the price of the toys

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


Re: Absolultely confused...

2005-10-06 Thread Tim Peters
[Jeremy Moles]
> ...
> I may be missing something critical here, but I don't exactly grok what
> you're saying; how is it even possible to have two instances of
> PyType_vector3d? It is (like all the examples show and all the extension
> modules I've done in the past) a static structure declared and assigned
> to all at once, only once.

The most common cause is inconsistent import statements, with one
place using package-relative import but another place explicitly
specifying the package.  Here's a simple pure Python example, with
this directory structure:

playground/
package_dir/
__init__.py
source.py
module.py

__init__.py is empty; it just serves to make `package_dir` a package.

source.py defines a single type, named Type:

class Type(object):
pass

module.py imports source.Type in two different ways, then prints various stuff:

from source import Type as one_way # package-relative import
from package_dir.source import Type as another_way

print one_way is another_way
print one_way.__name__, another_way.__name__
print repr(one_way), repr(another_way)

import sys
for k, v in sys.modules.items():
 if "source" in k:
 print k, v

Now _from_ playground, run module.py:

python playground/module.py

This is the output, with annotations; I ran this on Windows, so expect
to see backslashes :

False

That is, one_way is not the same object as another_way:  there are two
distinct instances of the Type object.

Type Type

Although they're distinct, they have the same __name__, "Type".

 

Their reprs differ, though, showing the path via which they were imported.

source 
package_dir.source 

That's two lines of output from crawling over sys.modules:  there are
two distinct instances of the entire `source` module.  That's the real
cause of the multiple `Type` instances.

package-relative import is rarely a good idea.  Are you doing that anywhere?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shelve object back to dictionary

2005-10-06 Thread Fredrik Lundh
Ryan Krauss wrote:

> Is there an easy way to convert a shelved object back to a dictionary?
>  When I save a dictionary using shelve and then load it in a later
> session, I have an object whose property names are the keys of the
> dictionary used as an input to shelve.  For example, instead of
> user['name'] I have user.name.  I would prefer to have the scripts I
> write to analyze the saved data have a similar syntax to the ones I
> used to create it, so I would rather deal with a dictionary after I
> load the shelved data.

session 1:

>>> import shelve
>>> db = shelve.open("foo")
>>> d = {"a": 1, "b": 2}
>>> db["key"] = d
>>> print d
{'a': 1, 'b': 2}
>>> print db["key"]
{'a': 1, 'b': 2}
>>> db.close()

session 2:

>>> import shelve
>>> db = shelve.open("foo")
>>> db["key"]
{'a': 1, 'b': 2}
>>> type(db["key"])

>>> db["key"].key
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'dict' object has no attribute 'key'
>>>

are you sure you're saving dictionaries?  what does "print type(obj)" print
for objects from your shelve?  what does the following print for your data-
base ?

>>> import anydbm
>>> db = anydbm.open("")
>>> db[db.keys()[0]]





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


Re: Compile as static

2005-10-06 Thread Micah Elliott
On Oct 06, [EMAIL PROTECTED] wrote:
> Has anyone had any luck with this? Im trying to compile python 2.4.2 on
> Slackware 10.1 into one large executable. One which contains everything
> required to run python (as static). So python doesn't look for
> dynamically shared objects like libpthread.so.0.
> 
> I have tried ./configure --disable-dynamic
>  --enable-dynamic=NO
>  --enable-static
> 
> However the executable size is always the same :/ Please assist.

ldd is your friend for seeing the dependencies.  I see what you mean,
though.  I'm no autoconf expert, but AFAICT this was not an intended
feature.  My attempted grok of the Makefile also supports this theory.
And I don't see any of the options you specified as being valid.  Using
"--disable-shared" also doesn't affect "python", but does appear to make
libpython static, but I think it is regardless.  You can force the issue
with:

   $ ../configure ...
   $ make LDFLAGS=-static
   $ ls -l ./python
   -rwxr-xr-x  1 mdelliot support 218 Oct  6 08:06 ./python
   $ ldd ./python
   not a dynamic executable

But this gives some import warnings, and running has some problems...

Then I found these, indicating that it is easy ;-)

http://groups.google.com/group/comp.lang.python/browse_frm/thread/9407982ad24b62ec/5018f9abebaa285a?lnk=st&q=build+python+static&rnum=3&hl=en#5018f9abebaa285a

http://groups.google.com/group/comp.lang.python/browse_frm/thread/1ac371489ed4040b/076580464204cd79?lnk=st&q=build+python+static&rnum=5&hl=en#076580464204cd79

http://groups.google.com/group/comp.lang.python/browse_frm/thread/c532cc6469e29488/c6fcc1afbd7c41b0?lnk=st&q=build+python+static&rnum=17&hl=en#c6fcc1afbd7c41b0

It might be nice to have an autoconf option to make this more obvious
for guys like us.  Maybe this is just a rare need.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie ? MS Sql update of record

2005-10-06 Thread len
I have created a python program that takes a flat file and changes some
of the data and create a new flat file with the changes.  Part of this
process requires that I try to find a particular model car in an MS Sql
table.  This part of the program is now working great.

It has come to my attention that some of the information in the flat
file could be used to update our information in the MS Sql table that I
currently run the query on.  Basicly I create a recordset of vehicles
from the MS Sql table based on vehicle year and make and once I have
this recordset I run it through logic which does a reqular expression
compare on the vehicle VIN no to the
VIN number in the table to get a match.  I would like to update this
record in the table with info. in the flat file.  I believe there
should be some way to update the fields in this record of the recordset
and then update the table.  I am not an sql expert and would appreciate
someone pointing me in the right direction.  Contained below is a
listing of my code;

# The following code creates a connection object,
# assigns the connection string, opens the
# connection object, and then verifies a good
# connection.

oConn = Dispatch('ADODB.Connection')

oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\
 "Data Source=uicesv05;" +\
 "uid=aiis;" +\
 "pwd=aiis;" +\
 "database=auto_mo_001"

oConn.Open()
if oConn.State == adStateOpen:
print "Database connection SUCCEEDED"
else:
print "Database connection FAILED"

# The following code creates a command object,
# assigns the command to the connection object,
# sets the query, creates the parameters objects to
# be passed to the command object and requests the
# query to be prepared (compiled by the SQL system).

oCmd = Dispatch('ADODB.Command')
oCmd.ActiveConnection = oConn
oCmd.CommandType = adCmdText

oCmd.CommandText = """\
SELECT
VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,
VO_DESCRIPTION,VO_MODEL_ID
FROM D014800 INNER JOIN D014900
ON VA_MK_NUMBER_VER = VO_MAKE_NO AND
VA_MK_YEAR = VO_YEAR
WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ?
"""

vyear = ''
vmake = ''
oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput)
oParmYear.Size = 4
oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput)
oParmMake.Size = 10

oCmd.Parameters.Append(oParmYear)
oCmd.Parameters.Append(oParmMake)

oCmd.Prepared = True

...

def wrkveh(ifile,strstart,maxcnt):
""" wrkveh function does an SQL record lookup to try an select
the correct vehicle in the V1sta make and model files.  If the
correct model is found I move V1sta's make model and body
descriptions to the flat file.  Currently, I hard code a 1 for
vehicle use.  The drive segment is an occurs 6"""
cnt = 0
vehwrk = ''
while cnt < maxcnt:
if ifile[strstart:strstart + 10] == '  ':
vehwrk = vehwrk + ifile[strstart:strstart + 133]
else:
vmake = ifile[strstart:strstart + 10]
vyear = ifile[strstart + 98:strstart + 102]
vvin4_8 = ifile[strstart +53:strstart + 58]
vmodel = ''
vbody = ''
oParmYear.Value = vyear
oParmMake.Value = vmake
(oRS, result) = oCmd.Execute()
while not oRS.EOF:
wvin =
oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.')
wvin.replace('*','.')
wvin = wvin[0:5]
r1 = re.compile(wvin)
if r1.match(vvin4_8):
vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value
vmodel = oRS.Fields.Item("VO_MODEL").Value
vbody = oRS.Fields.Item("VO_DESCRIPTION").Value
vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value
print 'DRC model ' + vmake + ' ' + vyear + ' ' +
vmodel + \
  ' ' + vmodelid
break
else:
oRS.MoveNext()
else:
print 'DRC model NOT FOUND'
vehwrk = vehwrk + vmake + vmodel + vbody
vehwrk = vehwrk + ifile[strstart + 50:strstart + 107]
vehwrk = vehwrk + '1'
vehwrk = vehwrk + ifile[strstart + 108:strstart + 133]
strstart += 133
cnt += 1

return vehwrk

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


Re: Can Python replace TCL/Expect

2005-10-06 Thread Jorgen Grahn
On Thu, 06 Oct 2005 11:08:09 GMT, Cameron Laird <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> Robert Kern  <[EMAIL PROTECTED]> wrote:
>>[EMAIL PROTECTED] wrote:
>>> Hi
>>> 
>>> I'm learning Python. I don't know whether Python can do something like
>>> Expect can do. If yes, please show me how to do it.
...
> 2.  While Pexpect indeed "can do something like Expect", 
> it does NOT have all the facilities and polish of the
> latter.
> 3.  But very, VERY few of Expect's users are aware of more
> than a handful of Expect's functions, let alone use them,
> so it's fair to say that Pexpect does everything Expect
> does, within the realm of ordinary use.

It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's
limitations several times in several places.

... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I
have to admit that its expect functionality is far superior to Python's.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Grant Edwards
On 2005-10-06, Flavio <[EMAIL PROTECTED]> wrote:
> Ok,
>
> I got it!
>
> Its vey insecure, and it is not guaranteed to work. Fine.
>
> Now what would you do if you wanted to pass a lot of variables (like a
> thousand) to a function and did not wanted the declare them in the
> function header?

Pass them in a dictionary or tuple or list or object with
attributes.

-- 
Grant Edwards   grante Yow!  Am I SHOPLIFTING?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread Christophe
CppNewB a écrit :
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 

Try PyQT with eric3 as an IDE.

http://www.die-offenbachs.de/detlev/eric3.html
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-10-06 Thread Pierre Barbier de Reuille
Mike Meyer a écrit :
> Antoon Pardon <[EMAIL PROTECTED]> writes:
> 
>>Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
>>
>>>On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
>>
>>Declarations also allow easier writable closures. Since the declaration
>>happens at a certain scope, the run time can easily find the correct
>>scope when a variable is rebound.
> 
> 
> If it happens at runtime, then you can do it without declarations:
> they're gone by then. Come to think of it, most functional languages -
> which are the languages that make the heaviest use of closures - don't
> require variable declarations.

Well, can you give a single example of such language ? Because all the
functionnal language I know but one do need variable declaration : lisp,
scheme, ocaml, haskell do need variable declaration ! Erlang do not ...

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

Type inferencing only works for statically typed languages AFAIK ! In a
dynamically typed languages, typing a variable is simply impossible as
any function may return a value of any type !

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

Wrong argument ... with that kind of things, you would just stick with
plain Turing machine ... every single computation can be done with it !

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

Well, so why not *allow* for variable declaration ? Languages like Perl
does that successfully ... you don't like : you don't do ! you like :
you do ! A simple option at the beginning of the file tell the compilor
if variable declaration is mandatory or not !

> Until someone does the research to provide hard evidence one way or
> another, that's all we've got to work with. Which means that languages
> should exist both with and with those features, and if one sides
> experiences generalize to the population at large, they alternative
> languages will die out. Which hasn't happened yet.
> 
> 
>>But we should decide what language features are usefull and which are
>>not by what some individual can or can't live without.
> 
> 
> Um - that's just personal preference (though I may have misparsed your
> sentence). What one person can't live without, another may not be able
> to live with. All that means is that they aren't likely to be happy
> with the same programming language. Which is fine - just as no
> programming language can do everything, no programming language can
> please everyone.
> 
> Antoon, at a guess I'd say that Python is the first time you've
> encountered a dynamnic language. Being "horrified" at not having
> variable declarations, which is a standard feature of such languages
> dating back to the 1950s, is one such indication.

Dynamic language and variable declaration are non-related issues ! You
can have statically-typed language without variable declaration (i.e.
BASIC) and dynamically-typed language with (i.e. Lisp) ! Please, when
you says something about languages, at least give 1 name of language
asserting what you're saying !

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

Well, could you be more specific once more ? I can't that many paradigm
only available on dynamically typed languages ... beside duck-typing
(which is basically a synonym for dynamically-typed)

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

After more than two years of Python programming, I still fill the need
for variable declarations. It would remove tons of bugs for little works
and would also clarify the scope of any single variable.

> P

shelve object back to dictionary

2005-10-06 Thread Ryan Krauss
Is there an easy way to convert a shelved object back to a dictionary?
 When I save a dictionary using shelve and then load it in a later
session, I have an object whose property names are the keys of the
dictionary used as an input to shelve.  For example, instead of
user['name'] I have user.name.  I would prefer to have the scripts I
write to analyze the saved data have a similar syntax to the ones I
used to create it, so I would rather deal with a dictionary after I
load the shelved data.

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


Re: So far

2005-10-06 Thread Benji York
CppNewB wrote:
> Most of them have support for Dialogs, but what about more complex
> UI's?  I may need a resizable frame within a resizable frame? I
> haven''t found a GUI builder with a great feel yet.

I *highly* recommend wxDesigner.  I've used it extensively.  It's cheap 
and has a demo version you can download (the demo can't save your 
designs, but can generate code so you can try it out).
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
Well, there's certainly no doubting that all of you are right. I guess
now I need to track down how this is happening and either fix it or
understand it so that I can explain why I'm having to work around it. :)

Many, many thanks. :)

On Thu, 2005-10-06 at 16:48 +0200, Daniel Dittmar wrote:
> Jeremy Moles wrote:
> > So, here is my relevant code:
> > 
> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> > 
> > And here ismy error message:
> > 
> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> > 
> 
> It looks as if two PyType_vector3d exist in your system
> - the one that created the object passed to your routine
> - the one in your extension code
> 
> As PyType_vector3d probably comes from a shared object/DLL
> - does your code accesses really the same shared object that is also 
> loaded by the Python interpreter? It could be that you linked with a 
> specific file, but Python loads something different from $PYTHONPATH
> - on Windows, you couldn't simply import a variable from a DLL, you had 
> to call a special routine to get the pointer
> 
> One possible portable solution: in your module initialization
> - import pylf.core
> - create an object of type vector3d
> - use your knowledge about the inner structure of Python objects and get 
> the pointer to the PyType from the object
> - store it in a module static variable TypeVector3D
> - pass that variable to PyArg_ParseTuple
> 
> Browse the Python Extension API, maybe partts or all of this are already 
> available.
> 
> There's still a problem left when pylf.core gets reloaded (rare, but 
> possible). I assume the shared object also gets reloaded, which means 
> that the type objects gets loaded to a new address and PyArg_ParseTuple 
> will complain again. I'm not sure if there is a solution to this, 
> because there still could be objects create from the old module.
> 
> Maybe you should just check the type yourself by comparing the class 
> names buried in the PyType. You could cache one or two type pointers to 
> speed this up.
> 
> Daniel

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


  1   2   >