python-dev Summary for 2006-07-01 through 2006-07-15

2006-08-15 Thread steven . bethard
python-dev Summary for 2006-07-01 through 2006-07-15


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-07-01_2006-07-15]



=
Announcements
=

---
Python 2.5 schedule
---

Python continues to make progress towards Python 2.5 final. See `PEP 356`_ for 
more details and the full schedule.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing threads:

- `TRUNK FREEZE for 2.5b2, tomorrow Tuesday 11th, 00:00 UTC 
http://mail.python.org/pipermail/python-dev/2006-July/067189.html`__
- `Subject: RELEASED Python 2.5 (beta 2) 
http://mail.python.org/pipermail/python-dev/2006-July/067255.html`__
- `TRUNK is UNFROZEN. 
http://mail.python.org/pipermail/python-dev/2006-July/067259.html`__

--
ctypes in the Python trunk
--

Martin v. Lowis successfully imported the ctypes history into the Python trunk, 
so ctypes now shares its repository with the rest of Python. Thanks everyone 
for your hard work!

Contributing threads:

- `Moving the ctypes repository to python.org 
http://mail.python.org/pipermail/python-dev/2006-July/066962.html`__
- `Subversion outage Friday 15:00 GMT 
http://mail.python.org/pipermail/python-dev/2006-July/067101.html`__
- `SVN write access is back 
http://mail.python.org/pipermail/python-dev/2006-July/067125.html`__
- `Extended Subversion outage: Friday 16:40 GMT 
http://mail.python.org/pipermail/python-dev/2006-July/067127.html`__


=
Summaries
=

-
Rebinding non-local names
-

A bug in the Python trunk that allowed augmented assignment to rebind names in 
outer scopes initiated a new discussion about how to allow Python code to 
rebind non-local names, e.g.::

def counter(n=0):
def increment(i=1):
n += i # change the n in counter
return n
return increment

Guido definitely didn't like the idea of introducing a new rebinding operator, 
e.g. ``:=`` or ``.=``. Phillip J. Eby suggested that a dot prefix to the name 
could indicate rebinding, e.g.::

def counter(n=0):
def increment(i=1):
.n += i
return .n
return increment

Guido felt uncomfortable with this proposal because it would mean that in 
referencing a value the only difference between ``.NAME`` and ``NAME`` was 
whether or not the name was assigned to at another place in the same function. 
This ambiguity could be avoided by requiring all references to names in outer 
scopes to be prefixed by the dot, but that seemed like too large of a change 
for Python.

There was also some discussion of trying to reuse the global keyword, but most 
folks felt that ``outer`` or ``nonlocal`` was a better name::

def counter(n=0):
def increment(i=1):
nonlocal n
n += i
return n
return increment

Guido requested a PEP on the subject, but at the time of this summary, none was 
available.

Contributing threads:

- `2.5 and beyond 
http://mail.python.org/pipermail/python-dev/2006-July/066857.html`__
- `Lexical scoping in Python 3k 
http://mail.python.org/pipermail/python-dev/2006-July/066862.html`__
- `Explicit Lexical Scoping (pre-PEP?) 
http://mail.python.org/pipermail/python-dev/2006-July/066978.html`__

--
Python and backwards incompatibilities
--

A `complaint by Greg Black`_ about Python introducing backward 
incompatibilities started a long discussion about how Python developers could 
stay in better touch with existing user code. Greg Black's code had relied on 
undocumented behavior in time.strftime() that had allowed zeros to be passed in 
as default values. When that behavior changed in Python 2.4, Greg's code (along 
with a number of other people's code) was broken. Python core didn't have any 
unittests for the behavior, so no tests started failing when the change was 
made.

Glyph suggested adding a mechanism so that user projects could submit 
buildslaves to run their test suites when changes are made to Python. The goal 
here would be to identify any de facto coding standards that weren't tested for 
in Python's test suite. If a change to Python caused major projects like 
Twisted or Zope to start failing dramatically, that change should be 
reconsidered even if it didn't break any documented behavior. People generally 
thought this was a great idea, particularly since it might catch some of these 
changes earlier than alpha or beta releases.

There was also some concern that the Python 2.5 release cycle had been sped up 
too much and users hadn't had enough time to report errors. However, adding 
more beta releases (which seemed to be the major suggestion) also adds more 
work for release managers and requires more schedule coordination so that 

LDTP 0.5.0 released !!!

2006-08-15 Thread A Nagappan
Issue VIII - 10 August 2006

We are proud to announce the release of LDTP 0.5.0. This release
features number of important breakthroughs in the history of LDTP as
well as in the field of Test Automation. This release note covers a
brief introduction on LDTP followed by the list of new features and
major bug fixes which makes this new version of LDTP the best of the
breed. Useful references have been included at the end of this article
for those who wish to hack / use LDTP.

LDTP developers had the privilege of participating in the Google Summer
of Code contest. Special thanks to the mentors of LDTP in the event
Varadhan and Emily Chen. We also thank Prashanth Mohan ('Casanova') for
his wonderful contributions acting as student developer for LDTP as part
of this event.

LDTP Planet has been set up by Prashanth Mohan ('Casanova') for sharing
information more effectively across the community. You can have access
to the planet through the
following link http://ldtp.freedesktop.org/planet/

About LDTP
==

Linux Desktop Testing Project is aimed at producing high quality test
automation framework and cutting-edge tools that can be used to test
Linux Desktop and improve it. It uses the Accessibility libraries to
poke through the application's user interface. The framework also has
tools to record test-cases based on user events in the interface of the
application which is under testing. We strive to help in building a
quality desktop.

Whats new in this release...


+ Recording using LDTP
This new version of LDTP features a recorder tool which would help in
generating automation scripts automatically by recording user events.
This would greatly reduce the time required for creating and maintaining
automation scripts. Thanks to Venkateswaran ('whacko'), Harishankaran
('sp2hari') and Theyagarajan ('Taggy') for making this happen. For more
information on this please refer to
http://ldtp.freedesktop.org/wiki/RecordHOWTO

+ Integration with Tinderbox - LDTP has been integrated with the GNOME
jhbuild. Using this feature one can execute test scripts automatically
at the end of successful
completion of package building using jhbuild. This was done as part of
Google SoC. Thanks to Prashanth Mohan ('Casanova') again for his
wonderful contribution.
Please refer to the following links for more information.
* http://prashblog.be/2006/07/27/ldtp-integrated-into-jhbuild/
* http://www.0d.be/2006/07/25/integrating-ldtp-into-jhbuild/
* http://tieguy.org/blog/2006/07/26/little-bits-of-awesomeness/

+ Automation scripts
* More than 70 new scripts for Gedit has been developed and is available
for download with this release. Kudos to Lakshmi Narasimhan
('narasim_7') and 'addict3d' for their excellent work. You can download
them from http://people.freedesktop.org/~prashmohan/gedit/
* New automation scripts for Evolution are being developed by Prashanth
Mohan ('Casanova') as part of his SoC contribution. These scripts can be
downloaded from http://people.freedesktop.org/~prashmohan/evolution/

+ Documentation updates
LDTP documentation section in the LDTP web site has been updated with
the latest list of automation APIs. Thanks to our maintainer Nagappan
('nags') for his contribution.

+ Bug fixes
This version includes loads of bug fixes to address important issues
like memory leak, API functionality etc., For a detailed list please
refer to release notes section of our project site hosted in
http://ldtp.freedesktop.org. Thanks to all the developers for their
contribution.

Whats in Store...
=

+ We are very pleased with the ongoing work on porting LDTP to ARM
platform by people from Palm Source, China. One of their latest
contribution has led to an Object Oriented LDTP approach. It still under
development but you can have a taste of this new recipe by following
this link http://ldtp.freedesktop.org/wiki/Object_2oriented_20LDTP

+ With Google SoC in full steam, we are awaiting more breakthroughs by
our LDTP team pabe downloaded from the
following location http://ldtp.freedesktop.org/wiki/Downloads

References
==

For detailed information on LDTP framework and latest updates visit
http://ldtp.freedesktop.org

For information on various APIs in LDTP including those added for this
release can be got from http://ldtp.freedesktop.org/user-doc/index.html

To subscribe to LDTP mailing lists, visit
http://ldtp.freedesktop.org/wiki/Mailing_20list

IRC Channel - #ldtp on irc.freenode.net

For suggestions to improve this newsletter, please write to
[EMAIL PROTECTED]

Nagappan A [EMAIL PROTECTED]
Linux Desktop Testing Project - http://ldtp.freedesktop.org
http://nagappanal.blogspot.com

Novell, Inc.
SUSE® Linux Enterprise 10
Your Linux is ready™
http://www.novell.com/linux


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

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


python-dev Summary for 2006-07-16 through 2006-07-31

2006-08-15 Thread steven . bethard
python-dev Summary for 2006-07-16 through 2006-07-31


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-07-16_2006-07-31]



=
Announcements
=

---
Python 2.5 schedule
---

After inserting a third beta release to allow some more time for testing the 
new features, Python continues to make progress towards the final Python 2.5 
release. See `PEP 356`_ for more details and the full schedule.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing threads:

- `outstanding bugs to fix for 2.5 
http://mail.python.org/pipermail/python-dev/2006-July/067680.html`__
- `Py2.5 release schedule 
http://mail.python.org/pipermail/python-dev/2006-July/067768.html`__

---
How to submit a patch to Python
---

Just a few reminders for all those still new to python-dev. When submitting a 
new patch to SourceForge, don't assign it to anyone. Most python developers get 
email notifications for new patches and will assign it to themselves if 
appropriate. If you feel like the approach the patch takes might need 
discussion, it's alright to present it to python-dev and ask for some feedback. 
If you do, be sure to put the patch number and url (e.g. 
http://bugs.python.org/sourceforge_id) near the top of the message, so that 
developers can easily find it.

And if you don't want to wait for your patch to be looked at (which may take 
some time as all developers are volunteers), a few of the folks here, including 
Martin v. Lowis, have offered a five-for-one deal. Simply find five other 
patches, and check them for things like:

* Does the code look okay?
* Does Python build with it applied?
* Do all unit tests pass?
* Does the patch have tests?
* Does the patch have documentation?

Then post your notes to the five patch trackers and post a final message to 
python-dev indicating the patches you reviewed and the patch which you'd like 
to have someone look at for you.

Contributing threads:

- `new guy 
http://mail.python.org/pipermail/python-dev/2006-July/067509.html`__
- `first draft of bug guidelines for www.python.org/dev/ 
http://mail.python.org/pipermail/python-dev/2006-July/067601.html`__
- `Patch submitted, now what? 
http://mail.python.org/pipermail/python-dev/2006-July/067858.html`__


Demos of trackers to replace SourceForge


There are currently three potential trackers that have successfully imported 
the SourceForge data with demos online: roundup_, jira_ and launchpad_. Try 'em 
out, and send your discussions and comments to [EMAIL PROTECTED] and put your 
reports and reviews `on the wiki`_.

.. _roundup: http://efod.se/python-tracker/
.. _jira: http://jira.python.atlassian.com/secure/Dashboard.jspa
.. _launchpad: https://demo.launchpad.net/products/python/+bugs
.. _on the wiki: http://wiki.python.org/moin/CallForTrackers

Contributing thread:

- `More tracker demos online 
http://mail.python.org/pipermail/python-dev/2006-July/067686.html`__


=
Summaries
=

--
Restricted execution in Python
--

Brett Cannon decided this fortnight to go for an all-out capabilities based 
restricted execution design, and posted a `new design document`_. As part of 
this work, Brett planned to rewrite most of the import machinery in pure Python 
code, hopefully cleaning up some of the idiosyncrasies of the current import.c 
mechanisms, and allowing him to do things like restrict imports to only .py 
files, not .pyc files. Armin Rigo pointed out that a good place to start would 
be the `PyPy import implementation`_.

On the restricted execution front, one of the things that is now likely to 
happen in Brett's sandboxing branch is that ``object.__subclasses__()`` and 
dangerous constructors like the one for the code object will be completely 
removed from the Python level. This means a few backwards incompatible changes, 
but Brett suggested that they should only break pretty advanced and esoteric 
Python code. Since it's for his Ph.D. dissertation, he didn't want to tie his 
hands by requiring full backwards compatibility, and he was fine with waiting 
to merge his branch until Python 3000.

.. _new design document: 
http://svn.python.org/view/python/branches/bcannon-sandboxing/securing_python.txt
.. _PyPy import implementation: 
http://codespeak.net/svn/pypy/dist/pypy/module/__builtin__/importing.py

Contributing threads:

- `Capabilities / Restricted Execution 
http://mail.python.org/pipermail/python-dev/2006-July/067481.html`__
- `new security doc using object-capabilities 
http://mail.python.org/pipermail/python-dev/2006-July/067555.html`__

--
Character case and locales
--

Mihai Ibanescu asked about a 

Re: yet another noob question

2006-08-15 Thread starGaming

Jason Nordwick wrote:
 *mouth agape*

 Wow. That really sucks. I make extensive use of reduce. It seems to run more 
 than twice as fast as a for loop.

  t = Timer('bino.reduceadd(bino.bits)', 'import bino')
  s = Timer('bino.loopadd(bino.bits)', 'import bino')
  t.timeit(10)
 1.2373670396656564
  s.timeit(10)
 2.6450051612705039
  t.timeit(100)
 11.312374896809501
  s.timeit(100)
 25.817132345032689

 where

 bits = map(lambda x:randint(0,1), xrange(100))

 def reduceadd(v):
   return reduce(add, v)

 def loopadd(v):
   sum = 0
   for x in v:
   sum = add(sum, x)
   return sum



 (Yes, I know there are better ways to sum up a list, but I just wanted to 
 test the performance of the loop against reduce. In most of my reduce usages, 
 the function passed to reduce is much more complex.)
[...]

Assuming Guido van Rossum is right and reduce() is only useful for
arithmetic expressions (could you show an example where you use it
else?), you could take advantage of more built-ins.
To spoiler the result of this, the loop-variant is slightly (in this
test: 2ms) faster.
The results on my amd64 3k+ were:
Reduce: 0.5686828074520.56633643382
For-loop: 0.56633643382

#!/usr/bin/env python
#
#

from random import randint
from timeit import Timer
from operator import add

def bits():
return [randint(0,1) for x in xrange(1000)]
# use def  list comprehension since lambda/map will be removed in
Python 3.0, too


print bits()[0:5]
print bits()[0:5] # it's working.

def reducefunc(x):
return reduce(add,x)
def loopfunc(x):
y = 0
for i in x: y += i
return y

x = bits()
print reducefunc(x)
print loopfunc(x) # both give proper output

print sum(Timer(reducefunc(bits()), from __main__ import bits,
reducefunc).repeat(20,100))/20
print sum(Timer(loopfunc(bits()), from __main__ import bits,
loopfunc).repeat(20,100))/20

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


Re: python-dev Summary for 2006-07-01 through 2006-07-15

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: ANN: byteplay - a bytecode assembler/disassembler

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: RELEASED: scgi 1.11

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: ANN: Crunchy version 0.7 is here!

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: LDTP 0.5.0 released !!!

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: python-dev Summary for 2006-07-16 through 2006-07-31

2006-08-15 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


ANN: byteplay - a bytecode assembler/disassembler

2006-08-15 Thread spam . noam
Hello,

I would like to present a module that I have wrote, called byteplay.
It's a Python bytecode assembler/disassembler, which means that you can
take Python code object, disassemble them into equivalent objects which
are easy to play with, play with them, and then assemble a new,
modified, code object.

I think it's pretty useful if you like to learn more about Python's
bytecode - playing with things and seeing what happens is a nice way to
learn, I think.

Here's a quick example. We can define this stupid function:

 def f(a, b):
... print (a, b)
 f(3, 5)
(3, 5)

We can convert it to an equivalent object, and see how it stores the
byte code:

 from byteplay import *
 c = Code.from_code(f.func_code)
 from pprint import pprint; pprint(c.code)
[(SetLineno, 2),
 (LOAD_FAST, 'a'),
 (LOAD_FAST, 'b'),
 (BUILD_TUPLE, 2),
 (PRINT_ITEM, None),
 (PRINT_NEWLINE, None),
 (LOAD_CONST, None),
 (RETURN_VALUE, None)]

We can change the bytecode easily, and see what happens. Let's insert a
ROT_TWO opcode, that will swap the two arguments:

 c.code[3:3] = [(ROT_TWO, None)]
 f.func_code = c.to_code()
 f(3, 5)
(5, 3)

You can download byteplay from
http://byteplay.googlecode.com/svn/trunk/byteplay.py and you can read
(and edit) the documentation at http://wiki.python.org/moin/ByteplayDoc
. I will be happy to hear if you find it useful, or if you have any
comments or ideas.

Have a good day,
Noam Raphael

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


Re: Memory problem

2006-08-15 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Yi Xing wrote:

 Is there a way that I can define a two-dimensional array in 
 array.array()? Thanks.

If you need more than one dimension you really should take a look at
`numarray` or `numpy`.  What are you going to do with the data once it's
loaded into memory?

Ciao,
Marc 'BlackJack' Rintsch

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


what is the keyword is for?

2006-08-15 Thread daniel
I'm so confused by the keyword is and == equal sign, it seems they
could be exchanged in some contexts, but not in others, what's the
difference between them in terms of comparation?

thanks...

daniel

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


Re: Mega Newbie Questions: Probably FAQs

2006-08-15 Thread Simon Forman
Zeph wrote:
 Python
 Pros: Free. Open source. Deep. Flexible. Rich community and third party
 stuff. Well documented.

 Cons: Interpreted.

 Unknown: Secure (meaning not easily reverse engineered) code? Performance?

Very recent thread on this subject:
http://groups.google.ca/group/comp.lang.python/browse_frm/thread/b4e08adec2d835f5/af340f17faec4055

Peace,
~Simon

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


What would be the best way to run python client in the background

2006-08-15 Thread gel
Hi
I have written a python client server app that keeps an eye on
processes starting and ending on a client and makes decision on what to
do based on information from the server end.  I want to run the client
end of the app more or less invisibly (no console) on the XP clients
when ever a users logs on.  What would be the best way to get this
done?  A bit more info on the purpose of the app... it is to act as a
licence server, where we have a limited number of licences for software
and the software installed on all PCs.  The app will only allow a pre
defined number of clients to run the software at any one time.

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


Re: what is the keyword is for?

2006-08-15 Thread Kirk McDonald
daniel wrote:
 I'm so confused by the keyword is and == equal sign, it seems they
 could be exchanged in some contexts, but not in others, what's the
 difference between them in terms of comparation?
 
 thanks...
 
 daniel
 

  'is' compares object identity. == compares values.

  a = [1, 2, 3]
  b = [1, 2, 3]
  a is b
False
  a == b
True

In this example, a and b refer to two separate lists that happen to hold 
the same values. Thus, 'is' returns False, and == returns True. On the 
other hand:

  c = d = [4, 5, 6]
  c is d
True
  c == d
True

Here, c and d refer to the same list. Therefore, 'is' returns true (they 
both refer to the same object), as does == (an object is always equal to 
itself, unless you overload the equality check in a weird way).

The distinction can easily be seen if we try to mutate these lists:

  a.append(4)
  a is b
False
  a == b
False
  c.append(7)
  c is d
True
  c == d
True

When we mutate a, b is not affected. They are two different lists, and 
changing 'a' makes it so they are no longer equal.

When we mutate c, d IS affected; they refer to the same list.

You can easily confuse yourself if you ever talk about applying 'is' to 
(for example) integers. Python may re-use certain small integers when 
you might not expect it to; this is done in the interests of efficiency. 
If you only compare the /values/ of numbers (with ==), then you will 
never notice this.

  a = 1
  b = 1
  c = 100
  d = 100
  a is b
True
  c is d
False

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


Newbie: calling the originating class ...

2006-08-15 Thread donkeyboy
This is probably very straightforwards to someone with experience, but
I will try to explain my predicament:

I'm trying to code a simulation, where you have a Simulation class that
knows everything about the simulation, and in turn classes that the
Simulation calls when it wants to make new instances -- for the time
being, let's call the called classes Agents (sorry, saw the Matrix
again last night!).

In the Simulation class, there's information about the simulation that
each Agent wants to know. As such, I wrote a method in the Simulation
class for the Agents to call, to get the said required information.
However, I can't figure out a way for the Agents to call the
Simulations methods -- is this even possible?

The pseudo-code I'm using is as follows:

s = Simulation()

class Simulation:
# create a number of agents
...
# Simulation information
important_stuff = 10

def showImportant(self):
return important_stuff

class Agents:
my_stuff = s.showImportant

... which fails: I get errors saying the global name 's' is not
defined. Any thoughts? Is what I'm trying to do even possible, or
should I be doing something else?

Thanks in advance!!

DB

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


Re: Best IDE for Python

2006-08-15 Thread Bruce Who
Hi, sjdevnull

I'm a vimmer too, and I wonder what plugins you are using. What you
said sounds interesting. Could you tell us more about the plugins?
Object browser is what I need most, but so far I've no idea what
plugin can do this for me, :-(

On 14 Aug 2006 15:02:13 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Yu-Xi Lim wrote:
  Eclipse+PyDev has the advantage over emacs when it comes to big
  projects, IMO. It has features like refactoring, better project
  management, code coverage

 Emacs and vim both have good integration of BicycleRepairMan for python
 refactoring.  I don't know what better project management or code
 coverage in eclipse entail, but I've posted before that if you think
 vim/emacs are just syntax highlighting/indenting text editors you've
 got them misconfigured.

 The beautiful thing about vim in particular is that it uses Python as
 an internal scripting language, so it's very easy to extend it to add
 whatever you want.

 e.g. in vim I get
 * Syntax checking, if I type invalid python code it gets highlighted as
 an error (if I type, say, if a=1: and hit return, it gets highlighted
 since I need an == there).
 * Object browser, with dropdowns showing the parent and child classes
 of the current class, and the ability to jump to various class methods
 * Normal tag-jump stuff, so I can drill down into the method/function
 call I'm looking at and then pop back up (keeping a stack so I can
 drill down arbitrarily deep to follow the flow of the code)
 * Interactive help, so when, say, I type foo.blah( then the status line
 displays the first line of the docstring/python doc/preceding comment
 for foo.blah.  E.g. if I type cmp( then the status line shows cmp(x,
 y) Compare the two objects X and Y and return an integer according to
 ... and if I hit F1 then I get the full help text
 * Editor control for uncaught errors--if I code I'm debugging raises an
 uncaught exception, the editor jumps directly to it.  Even works for
 web development, if I hit a page in my dev server that raises an
 exception, it brings my editor right there.

 and lots more (version control integration, easy mapping of keys to
 restart the webserver after I make changes, etc).  And there's some
 internal crap (e.g. we work on lots of clients who have client-specific
 versions of some objects; I have a client menu so that if I pick one,
 then I'll jump to their client-specific version of the current file (or
 the base generic version if there isn't a specific one), tags will
 follow the right client versions, etc).

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

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


ReStructuredText

2006-08-15 Thread Cliff Wells
Started playing with docutils and don't understand why the following
doesn't work:


 from docutils.core import publish_parts
 t = '''
...
... 1. this is a test
... #. this is another line
... #. oh, screw it!
...
... '''
 publish_parts ( t, writer_name = 'html' ) [ 'body' ]
u'p1. this is a test\n#. this is another line\n#. oh, screw it!/p\n'



Why doesn't the above turn out an enumerated list?  It looks like all
the examples I've seen, and I've tried adding and removing blank lines
around it to no avail.  

Regards,
Cliff

-- 

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


Re: Best IDE for Python

2006-08-15 Thread Tyronem
Yep thanks all for your replies. and yes i meant free and open source
software, left an s out :)
Tryker wrote:
 Gotta love PyScripter. Light, easy to use, free.
 http://mmm-experts.com/Products.aspx?ProductID=4

 [EMAIL PROTECTED] wrote:
  Hi All, What do you find the best IDE for creating web applications in
  Python is? Preferably FOS IDE.
  
  Cheers

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


Re: ReStructuredText

2006-08-15 Thread Cliff Wells
On Tue, 2006-08-15 at 09:35 +0200, Sybren Stuvel wrote:
 Cliff Wells enlightened us with:
  Why doesn't the above turn out an enumerated list?
 
 You have to indent the list:
 
  from docutils.core import publish_parts
  t = '''
 ... 
 ...1. this is a test
 ...#. this is another line
 ...#. oh, screw it!
 ... '''
  publish_parts(t, writer_name='html')['body']
 u'blockquote\nol class=arabic simple\nlithis is a
 test/li\nlithis is another line/li\nlioh, screw
 it!/li\n/ol\n/blockquote\n'

Thanks for the response.  Must be a bug in my version:

Python 2.4.2 (#1, Feb 13 2006, 15:24:20)
[GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2
Type help, copyright, credits or license for more information.
 from docutils.core import publish_parts
 t = '''
...
... 1. this is a test
... #. this is another line
... #. oh, screw it!
...
... '''
 publish_parts ( t, writer_name = 'html' ) [ 'body' ]
u'blockquote\n1. this is a test\n#. this is another line\n#. oh, screw
it!/blockquote\n'

Guess I'll stick to HTML.

Regards,
Cliff
-- 

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


RE: What would be the best way to run python client in the background

2006-08-15 Thread Tim Golden
[gel]

| I have written a python client server app [...]
| I want to run the client end of the app more or less invisibly 
| (no console) on the XP clients when ever a users logs on.  

You say when[]ever a user logs on but does this app
need to be run on a per-user basis? Or could it run all
the time -- ie as a Windows Service -- and do enough to
determine which user is logged on when it needed to?

The normal way is to run a Win32 service. There are several
posts on the subject around the Python and Python-Win32
mailing lists / newsgroups. The alternative is to set something
to run when any user logs in to run without a window. Again,
there are posts on the subject, including one I seem to remember
from Robin Becker, which tell how to do this kind of thing.

Let us know if you can't find anything which seems to
fit the bill.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: what is the keyword is for?

2006-08-15 Thread daniel
many thanks to Sybren and Kirk for your helpful explanation.

when I tried to check the stuff out, found sth interesting that if you
define variables in a style like this:
a = b = ['a', 'b']
changing one list affects the other, and they still refer to same
object. in fact, seems all compound types (dictionary for instance)
behave in this way.

however, when list is replaced with other built-in  types like integers
:
a = b = 3
changing one of them cause the two objects differ...


best regards.

daniel

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


Re: ReStructuredText

2006-08-15 Thread Cliff Wells
On Tue, 2006-08-15 at 16:02 +0800, limodou wrote:
 On 8/15/06, Cliff Wells [EMAIL PROTECTED] wrote:
  Thanks for the response.  Must be a bug in my version:
 
 Which version of docutils you are using, in my computer is good.
 
 u'ol class=arabic simple\nlithis is a test/li\nlithis is
 another line/li\nlioh, screw it!/li\n/ol\n'

 docutils.__version__
'0.3.7'


Regards,
Cliff

-- 

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


Re: ReStructuredText

2006-08-15 Thread Cliff Wells
On Tue, 2006-08-15 at 00:56 -0700, Cliff Wells wrote:


Ah, I got it.  From the docs:

(Auto-enumerated lists are new in Docutils 0.3.8.)

and I've got 0.3.7

Damn.  Thanks for the responses.

Regards,
Cliff

-- 

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


how to deepcopy a slice object?

2006-08-15 Thread Alexandre Guimond
Hi all,

i'm trying to deepcopy a slice object but i get the following error.
Does anyone know a workaround?

ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
on win32
Type help, copyright, credits or license for more information.
 import copy
 copy.deepcopy( slice( 1, 10, 2 ) )
Traceback (most recent call last):
  File stdin, line 1, in ?
  File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
  File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct
y = callable(*args)
  File C:\Program Files\Python\lib\copy_reg.py, line 92, in
__newobj__
return cls.__new__(cls, *args)
TypeError: slice expected at least 1 arguments, got 0

thx for any help.

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


Making a multithread app that runs several instances of whatever the app did before

2006-08-15 Thread olbion
Hi

I've aquired a program written in Python, and without much knowledge of
the language I'm trying to make some changes to it. The original
program starts, runs a certain process and then finishes. I want to
adapt it so that, at a certain stage of the process, a new process is
started from scratch, running at the same time as the original one.
When the original one is finished, it should exit without causing the
newer process to stop.

I've successfully achieved this using sys.popen methods to start
separate processes, but come to realise that running seperate processes
is not a very good solution, since it uses up more memory and becomes
harder to manage. I'd like the same thing to be achieved using threads.

I've come as far as being able to start the program which runs the
first thread. My problem arrises when I want the new thread to be
started. It seems that if I do this by calling a function from within
the thread, I'm unable to stop the original thread whenever that
finishes. I imagine that what I've achieved is something like:

Start file (eg start.py) starts Thread 1
Thread 1 starts a new thread (Thread 2) and becomes the parent of that
thread
Thread 2 starts a new thread (Thread 3)... and so on

I think that what I want is something like:

Start file starts Thread 1
Thread 1 informs start file that a new thread should be started; start
file starts Thread 2
... and so on

So, if my thinking so far is correct, how can a thread cause another
thread to be started without becoming its parent?

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


Re: what is the keyword is for?

2006-08-15 Thread Martin v. Löwis
daniel wrote:
 when I tried to check the stuff out, found sth interesting that if you
 define variables in a style like this:
 a = b = ['a', 'b']
 changing one list affects the other, and they still refer to same
 object. in fact, seems all compound types (dictionary for instance)
 behave in this way.
 
 however, when list is replaced with other built-in  types like integers
 :
 a = b = 3
 changing one of them cause the two objects differ...

Ah, but make a difference between change a variable, and change an
object.

py a = b = [1,2,3]
py a[0] = 6   # don't change the variable a, just change the object
py a
[6, 2, 3]
py b
[6, 2, 3]
py a=[7,8,9]  # change the variable a;
   # it's now a different object than b
py a
[7, 8, 9]
py b
[6, 2, 3]

For some objects, change the object is impossible. If you have

a = b = 3

then there is no way to change the object 3 to become 4 (say);
integer objects are immutable. So for these, to make a change,
you really have to change the variable, not the value.

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


Re: ReStructuredText

2006-08-15 Thread Cliff Wells
On Tue, 2006-08-15 at 16:10 +0800, limodou wrote:
 On 8/15/06, Cliff Wells [EMAIL PROTECTED] wrote:
  On Tue, 2006-08-15 at 16:02 +0800, limodou wrote:
   On 8/15/06, Cliff Wells [EMAIL PROTECTED] wrote:
Thanks for the response.  Must be a bug in my version:
  
   Which version of docutils you are using, in my computer is good.
  
   u'ol class=arabic simple\nlithis is a test/li\nlithis is
   another line/li\nlioh, screw it!/li\n/ol\n'
 
   docutils.__version__
  '0.3.7'
  
 
 Oh, the newest version is 0.4

Yeah, right after you asked, I tried 0.4, but it failed with a
traceback.  I ended up installing 0.3.9 and it works fine (and didn't
require the list to be indented either, FWIW).

For anyone who cares, the traceback with 0.4 was:

Python 2.4.2 (#1, Feb 13 2006, 15:24:20)
[GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2
Type help, copyright, credits or license for more information.
 from docutils.core import publish_parts
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/lib/python2.4/site-packages/docutils/core.py, line 23,
in ?
from docutils import frontend, io, utils, readers, writers
  File /usr/lib/python2.4/site-packages/docutils/readers/__init__.py,
line 15, in ?
from docutils.transforms import universal
  File
/usr/lib/python2.4/site-packages/docutils/transforms/__init__.py, line
69, in ?
class Transformer(TransformSpec):
  File
/usr/lib/python2.4/site-packages/docutils/transforms/__init__.py, line
78, in Transformer
default_transforms = (universal.Decorations,
AttributeError: 'module' object has no attribute 'FinalChecks'



Regards,
Cliff

-- 

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


Re: sending mailing list with smtplib

2006-08-15 Thread 3KWA

Gabriel Genellina wrote:

 Specify didn't work at least... see
 http://www.catb.org/~esr/faqs/smart-questions.html

Ooops, didn't work explained (the worst is I bought and read ESR's book
:()

list.txt=
email1
email2
email3
...
emailn

email1 received from:xsbar.com to:email1 subject: [xsbar] alive and
kicking ... message

from email2 onwards it seems what happened is that the recipient list
kept growing,
email 2 received from:[EMAIL PROTECTED] to:email1 to:email2 subject: ...
email3 received from:[EMAIL PROTECTED] to:email1 to:email2 to:email3
subject:...
...
emailn received from:[EMAIL PROTECTED] to:email1 to:email2 to:email3 ...
to:emailn subject:...

Many didn't receive the email because the header grew too big (I
received 1257 failure notice ~50% of them for header too big or
inappropriate recipient list).

Apologize for the inaccuracy of my first post

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


Re: ReStructuredText

2006-08-15 Thread limodou
 Yeah, right after you asked, I tried 0.4, but it failed with a
 traceback.

But my version works good.

 I ended up installing 0.3.9 and it works fine (and didn't
 require the list to be indented either, FWIW).

Yeah.

 For anyone who cares, the traceback with 0.4 was:

 Python 2.4.2 (#1, Feb 13 2006, 15:24:20)
 [GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2
 Type help, copyright, credits or license for more information.
  from docutils.core import publish_parts
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib/python2.4/site-packages/docutils/core.py, line 23,
 in ?
 from docutils import frontend, io, utils, readers, writers
   File /usr/lib/python2.4/site-packages/docutils/readers/__init__.py,
 line 15, in ?
 from docutils.transforms import universal
   File
 /usr/lib/python2.4/site-packages/docutils/transforms/__init__.py, line
 69, in ?
 class Transformer(TransformSpec):
   File
 /usr/lib/python2.4/site-packages/docutils/transforms/__init__.py, line
 78, in Transformer
 default_transforms = (universal.Decorations,
 AttributeError: 'module' object has no attribute 'FinalChecks'



-- 
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: start a multi-sockets server (a socket/per thread) with different ports but same host

2006-08-15 Thread zxo102
Bryan,
   Thanks for your note. Finally, I have made one listener socket for
all the connections work plus Queue-communication between the threads
in wxpython Gui and the threads for socket connections.
Trying to make that twisted example code in this topic for one
listener socket-all the connections but failed. That twisted example
only accepts one client connection. I have printed out the Twisted help
file (256 pages). Too much to read.

Ouyang


Bryan Olson 写道:

 zxo102 wrote:
 I am doing a small project using socket server and thread in python.
   This is first time for me to use socket and thread things.
 Here is my case. I have 20 socket clients.  Each client send a set
  of sensor data per second to a socket server.  The socket server will
  do two things: 1. write data into a file via bsddb; 2. forward the data
  to a GUI written in wxpython.
 I am thinking the code should work as follow (not sure it is
  feasible)
20 threads, each thread takes care of a socket server with a
  different port.
 I want all socket servers start up and wait for client connection.
  In the attached demo code, It stops at the startup of first socket
  server somewhere in the following two lines and waits for client call:
 
 lstn.listen(5)
 (clnt,ap) = lstn.accept()

 It will block there, waiting for connection.

Any ideas how to handle these 20 clients?  Really appreciate your
  suggestions.

 One reserved port for each client strikes me as whacked,
 as does coding a server to handle exactly 20 of them. Since
 you say this is your first socket server, maybe you just
 haven't seen the usual techniques.

 Normally, one listener socket accepts all the connections.
 Each call to accept() returns a new, independent socket for the
 connection. You can then start a thread to handle the new
 socket. Untested:


listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.bind(('', 2000))
listener.listen(5)
while True: # or some should_continue() thing
sock, _ = listener.accept()
thread.start_new_thread(service_function, (sock,))
# Or start threads via class Threading


 To update the GUI, you could use the Queue from the Python
 library, and call wxPostEvent to tell the GUI go wake up and
 check the queue.
 
 
 -- 
 --Bryan

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

Re: what is the keyword is for?

2006-08-15 Thread daniel

Martin v. Löwis wrote:
 daniel wrote:
  when I tried to check the stuff out, found sth interesting that if you
  define variables in a style like this:
  a = b = ['a', 'b']
  changing one list affects the other, and they still refer to same
  object. in fact, seems all compound types (dictionary for instance)
  behave in this way.
 
  however, when list is replaced with other built-in  types like integers
  :
  a = b = 3
  changing one of them cause the two objects differ...

 Ah, but make a difference between change a variable, and change an
 object.

 py a = b = [1,2,3]
 py a[0] = 6   # don't change the variable a, just change the object
 py a
 [6, 2, 3]
 py b
 [6, 2, 3]
 py a=[7,8,9]  # change the variable a;
# it's now a different object than b
mm, python runtime might allocate a new chunk of memory for this... but
might not for the previous operation..
 py a
 [7, 8, 9]
 py b
 [6, 2, 3]

 For some objects, change the object is impossible. If you have

 a = b = 3

 then there is no way to change the object 3 to become 4 (say);
 integer objects are immutable. So for these, to make a change,
 you really have to change the variable, not the value.

sounds reasonable, I tried tuple which is also immutable, it behaves
the same as integers. 

 Regards,
 Martin

tks Martin...

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


Re: start a multi-sockets server (a socket/per thread) with different ports but same host

2006-08-15 Thread zxo102
That twisted example  only accepts one client connection  if only one
port is available.


zxo102 写道:

 Bryan,
Thanks for your note. Finally, I have made one listener socket for
 all the connections work plus Queue-communication between the threads
 in wxpython Gui and the threads for socket connections.
 Trying to make that twisted example code in this topic for one
 listener socket-all the connections but failed. That twisted example
 only accepts one client connection. I have printed out the Twisted help
 file (256 pages). Too much to read.

 Ouyang


 Bryan Olson 写道:

  zxo102 wrote:
  I am doing a small project using socket server and thread in python.
This is first time for me to use socket and thread things.
  Here is my case. I have 20 socket clients.  Each client send a set
   of sensor data per second to a socket server.  The socket server will
   do two things: 1. write data into a file via bsddb; 2. forward the data
   to a GUI written in wxpython.
  I am thinking the code should work as follow (not sure it is
   feasible)
 20 threads, each thread takes care of a socket server with a
   different port.
  I want all socket servers start up and wait for client connection.
   In the attached demo code, It stops at the startup of first socket
   server somewhere in the following two lines and waits for client call:
  
  lstn.listen(5)
  (clnt,ap) = lstn.accept()
 
  It will block there, waiting for connection.
 
 Any ideas how to handle these 20 clients?  Really appreciate your
   suggestions.
 
  One reserved port for each client strikes me as whacked,
  as does coding a server to handle exactly 20 of them. Since
  you say this is your first socket server, maybe you just
  haven't seen the usual techniques.
 
  Normally, one listener socket accepts all the connections.
  Each call to accept() returns a new, independent socket for the
  connection. You can then start a thread to handle the new
  socket. Untested:
 
 
 listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 listener.bind(('', 2000))
 listener.listen(5)
 while True:   # or some should_continue() thing
 sock, _ = listener.accept()
 thread.start_new_thread(service_function, (sock,))
 # Or start threads via class Threading
 
 
  To update the GUI, you could use the Queue from the Python
  library, and call wxPostEvent to tell the GUI go wake up and
  check the queue.
  
  
  -- 
  --Bryan

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

Re: hide python code !

2006-08-15 Thread Armin Steinhoff
Bayazee wrote:
 hi
 can we hide a python code ?
 if i want to write a commercial software can i hide my source code from
 users access ?
 we can conver it to pyc but this file can decompiled ... so ...!!
 do you have any idea about this ...?

Use Pyrex in order to build C-Modules from the critical parts of your 
software.

 
 ---
 First Iranian Open Source Community : www.python.ir

Interesting ... but you are not a member of this community. Right?

--Armin


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


Re: how to deepcopy a slice object?

2006-08-15 Thread Simon Forman
Alexandre Guimond wrote:
 Hi all,

 i'm trying to deepcopy a slice object but i get the following error.
 Does anyone know a workaround?

 ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
 Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
 on win32
 Type help, copyright, credits or license for more information.
  import copy
  copy.deepcopy( slice( 1, 10, 2 ) )
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy
 y = _reconstruct(x, rv, 1, memo)
   File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct
 y = callable(*args)
   File C:\Program Files\Python\lib\copy_reg.py, line 92, in
 __newobj__
 return cls.__new__(cls, *args)
 TypeError: slice expected at least 1 arguments, got 0

 thx for any help.

Why would you want to [deep]copy a slice object?

Anyway,  I don't know much about them, other than that they are
slightly unusual objects that play a very restricted role in python,
rather like the Ellipsis.

Workarounds are possible, I think, but really you almost certainly
don't need to do this.

Peace,
~Simon

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


Re: sending mailing list with smtplib

2006-08-15 Thread Steve Holden
3KWA wrote:
 Gabriel Genellina wrote:
 
Specify didn't work at least... see
http://www.catb.org/~esr/faqs/smart-questions.html
 
 
 Ooops, didn't work explained (the worst is I bought and read ESR's book
 :()
 
 list.txt=
 email1
 email2
 email3
 
 emailn
 
 email1 received from:xsbar.com to:email1 subject: [xsbar] alive and
 kicking ... message
 
 from email2 onwards it seems what happened is that the recipient list
 kept growing,
 email 2 received from:[EMAIL PROTECTED] to:email1 to:email2 subject: ...
 email3 received from:[EMAIL PROTECTED] to:email1 to:email2 to:email3
 subject:...
 
 emailn received from:[EMAIL PROTECTED] to:email1 to:email2 to:email3 ...
 to:emailn subject:...
 
 Many didn't receive the email because the header grew too big (I
 received 1257 failure notice ~50% of them for header too big or
 inappropriate recipient list).
 
 Apologize for the inaccuracy of my first post
 
OK, now the problem is that you clearly aren't running the code you 
posted, you are running *somethinglike* the code you posted, but that 
has (an) error(s) the code you posted didn't.

So let's see the version with the print statements in it, not the 
sanitised version you didn't copy-and-paste fro your python source :-)

For the record, it's clear that youa ren't resetting the senders to an 
empty list each time but growing it as you go round the loop. If this 
helps you find your error, at least confirm that you did indeed find the 
problem.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: TypeError: 'module' object is not callable (newby question)

2006-08-15 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Charles Russell wrote:

 Another newby question:  __name__ and __file__ appear to be 
 predefined variables.  To look up their meaning in the manual, is there 
 some method less clumsy than grepping the whole collection of .html 
 source files?  I can't find any comprehensive index.

Here's the index of the reference manual:

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

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to deepcopy a slice object?

2006-08-15 Thread Alexandre Guimond
Here is my reason:

I have an object that contrains a 2D regular grid (matrix). In this
regular grid, I place points at regular intervals. In essence, i have
something like (my code is obviously more complex, this is just to show
what I want to do)

obj.grid = numpy.zeros( ( 100, 100 ) )
obj.grid[ obj.y1: obj.y2 : obj.ys, obj.x1 : obj.x2 : obj.xs ] =
embedded_parameters
result = somefunc( obj.grid )

My goal was to reduce the number of elements in my obj object by
replacing y1, y2, ys, and x1, x2, xs by 2 slice objects, and then do:

obj.grid[ obj.slicey, obj.slicex ] = embedded_parameters

But when I do this and then try to deepcopy my object, it doesn't work,
as in the example below.

Its not a big thing. I just liked the idea of having less elements in
my obj class and actually modeling my slice concept by a slice object,
specially since i'm going to 3D and 4D grid, and its somewhat annoying
to carry so many indices in my class definition.

Simon Forman wrote:
 Alexandre Guimond wrote:
  Hi all,
 
  i'm trying to deepcopy a slice object but i get the following error.
  Does anyone know a workaround?
 
  ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
  Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
  on win32
  Type help, copyright, credits or license for more information.
   import copy
   copy.deepcopy( slice( 1, 10, 2 ) )
  Traceback (most recent call last):
File stdin, line 1, in ?
File C:\Program Files\Python\lib\copy.py, line 204, in deepcopy
  y = _reconstruct(x, rv, 1, memo)
File C:\Program Files\Python\lib\copy.py, line 336, in _reconstruct
  y = callable(*args)
File C:\Program Files\Python\lib\copy_reg.py, line 92, in
  __newobj__
  return cls.__new__(cls, *args)
  TypeError: slice expected at least 1 arguments, got 0
 
  thx for any help.

 Why would you want to [deep]copy a slice object?

 Anyway,  I don't know much about them, other than that they are
 slightly unusual objects that play a very restricted role in python,
 rather like the Ellipsis.

 Workarounds are possible, I think, but really you almost certainly
 don't need to do this.
 
 Peace,
 ~Simon

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


Re: what is the keyword is for?

2006-08-15 Thread Steve Holden
daniel wrote:
 Martin v. Löwis wrote:
[...]
For some objects, change the object is impossible. If you have

a = b = 3

then there is no way to change the object 3 to become 4 (say);
integer objects are immutable. So for these, to make a change,
you really have to change the variable, not the value.

 
 sounds reasonable, I tried tuple which is also immutable, it behaves
 the same as integers. 
 
Well spotted. Tuples are indeed immutable, as are strings, unicode 
strings, integers and floats.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Newbie: calling the originating class ...

2006-08-15 Thread Steve Holden
donkeyboy wrote:
 This is probably very straightforwards to someone with experience, but
 I will try to explain my predicament:
 
 I'm trying to code a simulation, where you have a Simulation class that
 knows everything about the simulation, and in turn classes that the
 Simulation calls when it wants to make new instances -- for the time
 being, let's call the called classes Agents (sorry, saw the Matrix
 again last night!).
 
 In the Simulation class, there's information about the simulation that
 each Agent wants to know. As such, I wrote a method in the Simulation
 class for the Agents to call, to get the said required information.
 However, I can't figure out a way for the Agents to call the
 Simulations methods -- is this even possible?
 
 The pseudo-code I'm using is as follows:
 
 s = Simulation()
 
 class Simulation:
 # create a number of agents
 ...
 # Simulation information
 important_stuff = 10
 
 def showImportant(self):
 return important_stuff
 
 class Agents:
 my_stuff = s.showImportant
 
  which fails: I get errors saying the global name 's' is not
 defined. Any thoughts? Is what I'm trying to do even possible, or
 should I be doing something else?
 
Well obviously your agents each need a reference to the simulation. In 
the simulation methods the simulation instance can be referred to as 
self, so you can pass that as an argument to the agent creator. As in:

[EMAIL PROTECTED] ~/Projects/Python
$ !cat
cat test44.py
#
# Calling all reactive agents (with apologies to William Burroughs)
#
class Simulation:

 def __init__(self, howmany):
 self.agents = []
 for i in range(howmany):
 self.agents.append(Agent(self, i))

 def showImportant(self, agent):
 return agent.number, self

 def listAgents(self):
 for a in self.agents:
 a.showMe()

class Agent:

 def __init__(self, sim, number):
 self.sim = sim
 self.number = number

 def showMe(self):
 print Agent, self.number, reporting:
 result = self.sim.showImportant(self)
 print result

s = Simulation(5)
s.listAgents()

[EMAIL PROTECTED] ~/Projects/Python
$ python test44.py
Agent 0 reporting:
(0, __main__.Simulation instance at 0x186c6c8c)
Agent 1 reporting:
(1, __main__.Simulation instance at 0x186c6c8c)
Agent 2 reporting:
(2, __main__.Simulation instance at 0x186c6c8c)
Agent 3 reporting:
(3, __main__.Simulation instance at 0x186c6c8c)
Agent 4 reporting:
(4, __main__.Simulation instance at 0x186c6c8c)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Making a multithread app that runs several instances of whatever the app did before

2006-08-15 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 Hi
 
 I've aquired a program written in Python, and without much knowledge of
 the language I'm trying to make some changes to it. The original
 program starts, runs a certain process and then finishes. I want to
 adapt it so that, at a certain stage of the process, a new process is
 started from scratch, running at the same time as the original one.
 When the original one is finished, it should exit without causing the
 newer process to stop.
 
 I've successfully achieved this using sys.popen methods to start
 separate processes, but come to realise that running seperate processes
 is not a very good solution, since it uses up more memory and becomes
 harder to manage. I'd like the same thing to be achieved using threads.
 
 I've come as far as being able to start the program which runs the
 first thread. My problem arrises when I want the new thread to be
 started. It seems that if I do this by calling a function from within
 the thread, I'm unable to stop the original thread whenever that
 finishes. I imagine that what I've achieved is something like:
 
 Start file (eg start.py) starts Thread 1
 Thread 1 starts a new thread (Thread 2) and becomes the parent of that
 thread
 Thread 2 starts a new thread (Thread 3)... and so on
 
 I think that what I want is something like:
 
 Start file starts Thread 1
 Thread 1 informs start file that a new thread should be started; start
 file starts Thread 2
  and so on
 
 So, if my thinking so far is correct, how can a thread cause another
 thread to be started without becoming its parent?
 
Read up on demonised (sp?) threads in the documentation from threading.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: yet another noob question

2006-08-15 Thread Jason Nordwick
I use reduce to also do indexing, hashing with upsert semantics of lists of 
key-value pairs, transitioning through a state table, etc...

Somebody else pointed out to me how odd it is of Python to be ditching reduce 
when Guido van Rossum was hired by Google, and Google is literally built on map 
and reduce (http://en.wikipedia.org/wiki/Mapreduce).

Here is a code fragment I pulled from what I am currently working on (with a 
little modification to make things simple):

First build a tree:

 def byn(a,n): return [[a[i] for i in x] for x in zip(*[range(y,len(a),n) 
 for y in range(n)])]
...
 def whilep(pred,f,x):
... while pred(x): x = f(x)
... return x
...
 t = whilep(lambda x:1len(x), lambda x:byn(x,2), map(chr,range(97,97+16)))

 t
['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]], [[['i', 'j'], ['k', 
'l']], [['m', 'n'], ['o', 'p']

Now if I had the list [0,1,0,0,1] and needed to find what letter it encodes:

 t[0][1][0][0][1]
'j'

But sometimes, I want to be able to index branches or the leaves are at 
different depths, so I essentially have a list of indexes to follow:

 def indexDepth(a,i): return reduce(lambda x,y: x[y], i, a)
...
 indexDepth(t,[0,1,0,0,1])
'j'


Also, I completely understand your timings, but you are not timing reduce 
against a hand coded loop, but instead the operator '+' against the function 
add, as the function symbol lookup and call seem to have a heavy price. Reduce 
was one of the nice ways to eliminate some of those lookups.

-j


[EMAIL PROTECTED] wrote:
 Jason Nordwick wrote:
 *mouth agape*

 Wow. That really sucks. I make extensive use of reduce. It seems to run more 
 than twice as fast as a for loop.

 t = Timer('bino.reduceadd(bino.bits)', 'import bino')
 s = Timer('bino.loopadd(bino.bits)', 'import bino')
 t.timeit(10)
 1.2373670396656564
 s.timeit(10)
 2.6450051612705039
 t.timeit(100)
 11.312374896809501
 s.timeit(100)
 25.817132345032689

 where

 bits = map(lambda x:randint(0,1), xrange(100))

 def reduceadd(v):
  return reduce(add, v)

 def loopadd(v):
  sum = 0
  for x in v:
  sum = add(sum, x)
  return sum



 (Yes, I know there are better ways to sum up a list, but I just wanted to 
 test the performance of the loop against reduce. In most of my reduce 
 usages, the function passed to reduce is much more complex.)
 [...]
 
 Assuming Guido van Rossum is right and reduce() is only useful for
 arithmetic expressions (could you show an example where you use it
 else?), you could take advantage of more built-ins.
 To spoiler the result of this, the loop-variant is slightly (in this
 test: 2ms) faster.
 The results on my amd64 3k+ were:
 Reduce: 0.5686828074520.56633643382
 For-loop: 0.56633643382
 
 #!/usr/bin/env python
 #
 #
 
 from random import randint
 from timeit import Timer
 from operator import add
 
 def bits():
 return [randint(0,1) for x in xrange(1000)]
 # use def  list comprehension since lambda/map will be removed in
 Python 3.0, too
 
 
 print bits()[0:5]
 print bits()[0:5] # it's working.
 
 def reducefunc(x):
 return reduce(add,x)
 def loopfunc(x):
 y = 0
 for i in x: y += i
 return y
 
 x = bits()
 print reducefunc(x)
 print loopfunc(x) # both give proper output
 
 print sum(Timer(reducefunc(bits()), from __main__ import bits,
 reducefunc).repeat(20,100))/20
 print sum(Timer(loopfunc(bits()), from __main__ import bits,
 loopfunc).repeat(20,100))/20
 

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


Re: Newbie: calling the originating class ...

2006-08-15 Thread Diez B. Roggisch
donkeyboy wrote:

 This is probably very straightforwards to someone with experience, but
 I will try to explain my predicament:
 
 I'm trying to code a simulation, where you have a Simulation class that
 knows everything about the simulation, and in turn classes that the
 Simulation calls when it wants to make new instances -- for the time
 being, let's call the called classes Agents (sorry, saw the Matrix
 again last night!).
 
 In the Simulation class, there's information about the simulation that
 each Agent wants to know. As such, I wrote a method in the Simulation
 class for the Agents to call, to get the said required information.
 However, I can't figure out a way for the Agents to call the
 Simulations methods -- is this even possible?
 
 The pseudo-code I'm using is as follows:
 
 s = Simulation()
 
 class Simulation:
 # create a number of agents
 ...
 # Simulation information
 important_stuff = 10
 
 def showImportant(self):
 return important_stuff
 
 class Agents:
 my_stuff = s.showImportant
 
 ... which fails: I get errors saying the global name 's' is not
 defined. Any thoughts? Is what I'm trying to do even possible, or
 should I be doing something else?

Besides the fact that the above can't work, as you can't instantiate a
Simulation object before defining its class, you have basically two options
here (while they come in many disguises):

 - have only one instance of Simulation and a defined way to access it - in
OO-terms called a singleton. There are several ways to accomplish that:

   - a real singleton or borg-pattern, that allows you to use the
Simulation constructor

   - a module global variable you assign it to  then use it.

   - classmethods

 - pass an instance of a Simulation to each Agent, either at
construction-time or later on explicit.


Depending on how the overall system is supposed to run, either ways have
their benefits - if you only run one simulation, the first approach enables
you to only use the simulation object where you need it, and not pass it
around to other objects that maybe don't need it themselves but have other
objects contained/instantiated that do so. But naturally, no parallel
universe with only one simulation

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


Re: how to deepcopy a slice object?

2006-08-15 Thread Duncan Booth
Simon Forman wrote:

 Why would you want to [deep]copy a slice object?

I would guess the original poster actually wanted to copy a data structure 
which includes a slice object somewhere within it. That is a perfectly 
reasonable albeit somewhat unusual thing to want, however it doesn't work.

Similarly in Python 2.4 you cannot deepcopy functions. That has been fixed 
in Python 2.5 but I guess nobody has tried deepcopying slices before so 
they haven't been fixed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling wxPython app for Windows; Single EXE

2006-08-15 Thread Vincent Delporte
On Mon, 14 Aug 2006 17:46:11 -0500, Philippe Martin
[EMAIL PROTECTED] wrote:
Yes there is a way to make one .exe/.msi for everything ... but it does
require purchasing a tool such as VC++.

I have python + wxWindows + my stuff + many other libraries in one installer
(takes 120 Megs (sigh))

I know. An empty frame with wxPython runs at ... 12MB :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yet another noob question

2006-08-15 Thread Steve Holden
Jason Nordwick wrote:
 I use reduce to also do indexing, hashing with upsert semantics of lists of 
 key-value pairs, transitioning through a state table, etc...
 
 Somebody else pointed out to me how odd it is of Python to be ditching reduce 
 when Guido van Rossum was hired by Google, and Google is literally built on 
 map and reduce (http://en.wikipedia.org/wiki/Mapreduce).
 

That seems a bit literal. Just because they use a tool called MapReduce 
that doesn't imply that thay chose to implement it with the Python map() 
and reduce() functions. It's a distributed application, in case you 
hadn't noticed ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: yet another noob question

2006-08-15 Thread Jason Nordwick
That isn't what I meant. If there was a a point (and I'm not really sure that 
I'm even trying to make one), the point was that Google makes heavy use of 
reduce-like functionality, essentially implementing a distributed reduce across 
a cluster. From what I hear, they use a lot of Python and hired van Rossum for 
a reason. It just seems odd (don't read anything into this than mere cocked 
eyebrows) that the language designer that they hired and obviously have a lot 
of trust in would decide that reduce was essentially pointless. Google's 
distributed reduce seems to point in opposite way.

However, if reduce could be rolled into the list comprehension syntax, that 
would be even better. Or take it that extra step and roll a grouping 
functionality in there too, then you would have map, reduce, group, and filter 
all in one construct. You could call it select (joins are merely indexes into 
other structures).

-j


Steve Holden wrote:
 Jason Nordwick wrote:
 I use reduce to also do indexing, hashing with upsert semantics of lists of 
 key-value pairs, transitioning through a state table, etc...

 Somebody else pointed out to me how odd it is of Python to be ditching 
 reduce when Guido van Rossum was hired by Google, and Google is literally 
 built on map and reduce (http://en.wikipedia.org/wiki/Mapreduce).

 
 That seems a bit literal. Just because they use a tool called MapReduce 
 that doesn't imply that thay chose to implement it with the Python map() 
 and reduce() functions. It's a distributed application, in case you 
 hadn't noticed ...
 
 regards
   Steve

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


dictionary update

2006-08-15 Thread Chris
I have a instance attribute self.xds and a local variable xds in the 
instance . Both are dictionaries. I understand that I can update 
self.xds with xds as follows: self.xds.update(xds)

However I have many instance attributes, self.i, and local variables i.
I'd like to be able to do this:

for i in list_of_i's:
 self.i.update(i)

How can this be done (I'm assuming it can be).

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


Re: TypeError: 'module' object is not callable (newby question)

2006-08-15 Thread Charles Russell
Charles Russell wrote:
  I haven't found the magic word to invoke a
 .py script from the python prompt (like  the command source in csh, 
 bash, tcl?) 

Seems to be execfile()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'module' object is not callable (newby question)

2006-08-15 Thread Charles Russell
Marc 'BlackJack' Rintsch wrote:

 Here's the index of the reference manual:
 
   http://docs.python.org/ref/genindex.html
 
Thanks.  When I go up a level from there, I find a pointer to the index 
right at the bottom of the table of contents, which I had overlooked.
-- 
http://mail.python.org/mailman/listinfo/python-list


pickling or xml or other?

2006-08-15 Thread placid
Hi all,

I have an application were i want the user to configure some settings
which are variables within different classes.

My question is should i just pickle out these variables to a file in
some particular order then read it back. Or use xml to save the config
values ? Which one scales better if settings increase?

Other sugestions? 

-Cheers

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


Re: pickling or xml or other?

2006-08-15 Thread Diez B. Roggisch
placid wrote:

 Hi all,
 
 I have an application were i want the user to configure some settings
 which are variables within different classes.
 
 My question is should i just pickle out these variables to a file in
 some particular order then read it back. Or use xml to save the config
 values ? Which one scales better if settings increase?
 
 Other sugestions?

ConfigParser. And scaling of something that by definition is supposed to
be written by humans isn't a matter here. What matters is that a
config-file can be edited on the commandline using vi (or the editor of
your choice) - a pickle can't. So I'd certainly advise against the
pickling.

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


Re: Basic Boost.Python Question

2006-08-15 Thread Hoop
Hi Neil,
I have never heard of IronPython. Do you know if you can embedd the
Python interpreter ?
Thanks
Jeff

Neil Hodgson wrote:
 Hoop:

  I am starting on an application that will developed in VS2005, probably
  using C++/CLI.

 I haven't heard any reports of Boost.Python code being compatible
 with C++/CLI so you may need to add an adaptation layer. To run inside
 .NET, I'd choose IronPython.
 
 Neil

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


Re: dictionary update

2006-08-15 Thread Sion Arrowsmith
Chris  [EMAIL PROTECTED] wrote:
I have a instance attribute self.xds and a local variable xds in the 
instance . Both are dictionaries. I understand that I can update 
self.xds with xds as follows: self.xds.update(xds)

However I have many instance attributes, self.i, and local variables i.
I'd like to be able to do this:

for i in list_of_i's:
 self.i.update(i)

How can this be done (I'm assuming it can be).

I think what you want is:

for i in list_of_is:
getattr(self, i).update(locals()[i])

assuming list_of_is is a list of names not a list of the local
dicts (ie [xds, ...] not [xds, ...]).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Beginner Textbook

2006-08-15 Thread M_M
Hi,

I am looking for a simple text book to introduce 13 to 18 year olds to 
python programming. Suggestion?

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


Re: Beginner Textbook

2006-08-15 Thread Michiel Sikma
Introducing 13 year olds to a programming language? You're gonna have  
a hard time finding good literature for that. Even if you do, it's  
going to cost a lot of time to guide them.

Beginning Python: From Novice to Professional by Magnus Lee Hetland  
might be a good choice. ISBN: 159059519X.

Michiel

Op 15-aug-2006, om 14:48 heeft M_M het volgende geschreven:

 Hi,

 I am looking for a simple text book to introduce 13 to 18 year olds to
 python programming. Suggestion?

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

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


Re: Beginner Textbook

2006-08-15 Thread Daniel Dittmar
M_M wrote:
 I am looking for a simple text book to introduce 13 to 18 year olds to 
 python programming. Suggestion?

If they're Germans: Python für Kids
http://www.amazon.de/gp/product/3826609514/028-9407382-2771748?v=glancen=299956

or Python Programming for the Absolute Beginner
http://www.amazon.com/gp/product/1592000738/104-2712970-0839936?v=glancen=283155
which seems to use a game as demo project.

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


Re: Beginner Textbook

2006-08-15 Thread M_M
Michiel Sikma wrote:
 Introducing 13 year olds to a programming language? You're gonna have a 
 hard time finding good literature for that. Even if you do, it's going 
 to cost a lot of time to guide them.
 
 Beginning Python: From Novice to Professional by Magnus Lee Hetland 
 might be a good choice. ISBN: 159059519X.
 
 Michiel
 
 Op 15-aug-2006, om 14:48 heeft M_M het volgende geschreven:
 
 Hi,

 I am looking for a simple text book to introduce 13 to 18 year olds to
 python programming. Suggestion?

 New to python.
 --http://mail.python.org/mailman/listinfo/python-list
 
Thanks - a very bright lot of 13 year olds- need the challenge!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Textbook

2006-08-15 Thread Michiel Sikma

Op 15-aug-2006, om 15:16 heeft M_M het volgende geschreven:

 Thanks - a very bright lot of 13 year olds- need the challenge!
 --  
 http://mail.python.org/mailman/listinfo/python-list

I think that every 13 year old should be taught Python. It's an  
extremely intuitive language that can mean a lot to their  
understanding of the workings of computers. Or at least a whole lot  
more than just the basic Microsoft Word stuff...

Actually, I might take back what I said earlier. I'm sure that  
they'll do just fine after a few lessons. I was able to make my 14  
year old sister understand a C program that converts Fahrenheit to  
Celsius, afterall... :)

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


Re: Beginner Textbook

2006-08-15 Thread hiaips

M_M wrote:
 Michiel Sikma wrote:
  Introducing 13 year olds to a programming language? You're gonna have a
  hard time finding good literature for that. Even if you do, it's going
  to cost a lot of time to guide them.
 
  Beginning Python: From Novice to Professional by Magnus Lee Hetland
  might be a good choice. ISBN: 159059519X.
 
  Michiel
 
  Op 15-aug-2006, om 14:48 heeft M_M het volgende geschreven:
 
  Hi,
 
  I am looking for a simple text book to introduce 13 to 18 year olds to
  python programming. Suggestion?
 
  New to python.
  --http://mail.python.org/mailman/listinfo/python-list
 
 Thanks - a very bright lot of 13 year olds- need the challenge!

There's a book called Learning with Python: How to Think Like a
Computer Scientist that's geared towards high schoolers. It may be
perfect for your students, depending on what you're looking for. In any
case, here's a link:
http://greenteapress.com/thinkpython/

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


Re: dictionary update

2006-08-15 Thread Steve Holden
Chris wrote:
 I have a instance attribute self.xds and a local variable xds in the 
 instance . Both are dictionaries. I understand that I can update 
 self.xds with xds as follows: self.xds.update(xds)
 
 However I have many instance attributes, self.i, and local variables i.
 I'd like to be able to do this:
 
 for i in list_of_i's:
  self.i.update(i)
 
 How can this be done (I'm assuming it can be).
 
 thx Chris

Well, I'm note sure you have explained the problem fully, but if what 
you mean is that you want to update an instance's variables from a 
dictionary this can be achieved with

   self.__dict__.update(xds)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: hide python code !

2006-08-15 Thread Gerhard Fiedler
On 2006-08-15 05:40:31, Armin Steinhoff wrote:

 First Iranian Open Source Community : www.python.ir
 
 Interesting ... but you are not a member of this community. Right?

You know how to read a thread, right? :)

Gerhard

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


Re: modifying __new__ of list subclass

2006-08-15 Thread Ken Schutte
Steven Bethard wrote:
 
 The __new__ method is for immutable types.  So things like str and int 
 do their initialization in __new__.  But for regular mutable types, you 
 should do your initialization in __init__::
 

I see... So, is there a use for __new__ in mutable types?   From my 
list-derirved class, it was obviously being called, but it's return 
value is totally ignored?

Thanks for the reply.

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


Re: Beginner Textbook

2006-08-15 Thread Tim Williams
On 15/08/06, M_M [EMAIL PROTECTED] wrote:
 Hi,

 I am looking for a simple text book to introduce 13 to 18 year olds to
 python programming. Suggestion?


You might consider Learn to programme using Python  by Alan Gauld
as a means to introduce both programming and python at the same time.

http://www.freenetpages.co.uk/hp/alan.gauld/

The cover describes itself as  A Tutorial for hobbyists,
self-starters and all who want to learn the art of computer
programming

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


Re: Compiling wxPython app for Windows; Single EXE

2006-08-15 Thread GHUM
Daniel,

I am using py2exe since more then 4 years, so I am rather biased.

I read PyInstaller page and was positively impressed by the manual and
all the good words.
There is one major difference which will keep me with py2exe:

with PyInstaller and single file there is:
When first started, it finds that it needs to extract these files
before it can run for real.

and with 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 they are never unpacked to the file system is the USP of py2exe
to me at the moment.

What is less then optimal with both packages, is that MSVCR71.DLL needs
to be distributed separately :(

Harald

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


Re: How to execute a file outside module's namespace?

2006-08-15 Thread Piet van Oostrum
 Slawomir Nowaczyk [EMAIL PROTECTED] (SN) wrote:

SN Hello,
SN Let's say I have a module emacs, defining function eexecfile(file):

SN def eexecfile(file):
SN # do other stuff
SN execfile(file,globals())
SN # do other stuff

SN Now, assume I have file test.py containing an assignment x=1

SN If I run python and do:

SN import emacs
SN emacs.eexecfile(test.py)
SN print emacs.x   # works, x was put in module namespace
SN print x # doesn't work, x is not defined in main script namespace

SN What is the best way to make print x work? Using the following:

emacs.py:

def eexecfile(file, glob):
# do other stuff
execfile(file,glob)

main:

import emacs
emacs.eexecfile(test.py, globals())
print x

-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


IDLE system wide settings

2006-08-15 Thread staham
Hi,

Is it possible to change the settings for the IDLE program via either
the command line or via environment variables?
The things I would like to change is to choose UTF-8 and Classic UNIX
keys.

I understand that it's possible to edit the program, but I'd rather
just set an environment variable.

best regards,
Staffan

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


Re: hide python code !

2006-08-15 Thread Philippe Martin
Bayazee wrote:

 
 Armin Steinhoff wrote:
 Bayazee wrote:
  hi
  can we hide a python code ?
  if i want to write a commercial software can i hide my source code from
  users access ?
  we can conver it to pyc but this file can decompiled ... so ...!!
  do you have any idea about this ...?

 Use Pyrex in order to build C-Modules from the critical parts of your
 software.

 
  ---
  First Iranian Open Source Community : www.python.ir

 Interesting ... but you are not a member of this community. Right?

 --Armin
 
 
 Hi
 thanx for your answers . i read all of your replys carefully ...
 i am an open source Programmer ! i love to distribute my sources and
 use other ideas ! but asking a question is't reason of using it ! i
 want to find a way to hide python source codes ! can we do it ? how ?
 but i dont want to use it 
 this is a question that i must be answer to a friend !

Then the answer could be a question: can we hide any source/binary ?

Hardware tokens (ex: smart cards) are used just for that purpose. So as long
as you distribute a PC with your package and are certain it cannot be
tempered with (the correct O/S, administrative rights, encrypted
partitions .) ... but I do not think there is such a PC out there.

You might want to read this:

http://www.commoncriteriaportal.org/
www.commoncriteriaportal.org/public/files/ccintroduction.pdf
http://en.wikipedia.org/wiki/Common_Criteria


Philippe







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


Re: what is the keyword is for?

2006-08-15 Thread Terry Reedy

Sybren Stuvel [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 'is' compares the object's addresses.

It actually compares the objects' integer identifiers.  That happens to be 
the linear memory address for CPython, but not necesarily so for other 
interpreters.

tjr



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


Re: pycrust xmlrpclib problem

2006-08-15 Thread Pat
Timothy Gee wrote:
 Have do a lot of lab work making use of xmlrpclib and am quite
 dependent on it. I just started working with pycrust under Linux RH9,
 and wanted to use it as my standard python environment, however, when I
 import xmlrpclib, I get a segmentation fault. Command line still works
 fine however. Details for pycrust are:
 PyCrust 0.9.5

 Yet another Python shell, only flakier.

 Half-baked by Patrick K. O'Brien,
 the other half is still in the oven.

 Shell Revision: 1.9.2.10
 Interpreter Revision: 1.6.2.1

 Platform: linux2
 Python Version: 2.4.1
 wxPython Version: 2.6.3.3
   (wxGTK, unicode, gtk2, wx-assertions-on, SWIG-1.3.27)
 Linux Info:
 Linux rtphostb06 2.4.20-18.9 #1 Thu May 29 07:08:16 EDT 2003 i686 i686
 i386 GNU/Linux

 Anyone had a similar problem? Any workarounds?
 -Tim-

It works fine for me on Windows XP with wxPython 2.6.2.1, so you may
want to report this on the wxPython mailing list and see if anyone else
has the same problem.  Unless you've already done that.  I haven't been
actively involved with wxPython in some time.

--
Patrick K. O'Brien
Orbtech   http://www.orbtech.com
Schevohttp://www.schevo.org
Louie http://www.pylouie.org

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


Reference Variables In Python Like Those In PHP

2006-08-15 Thread Chaos
Is It possible to have reference variables like in PHP

ex.

?php

$x = 1;
$y = $x;

$y += 1;

echo $x;
echo \n
echo $y;

?

This would show

2
2

Is this available in python?

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


Re: Best IDE for Python

2006-08-15 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
 Hi All, What do you find the best IDE for creating web applications in
 Python is? Preferably FOS IDE.

 Cheers

I like ActiveState's Komodo.  It's heavyweight and not free ($30 for
the personal edition) but it also supports Perl, Ruby, PHP and TCL.  I
started using it mostly on Windows but I've used it on Linux more
recently (and it runs on Solaris and OSX now too).
It has all the bells and whistles and probably won't appeal too much to
hardcore emacs/vim people because it is so GUI oriented and nowhere
near as fast.  Also, it's text editor is similar to the ones you get
with other popular IDE's like MS DevStudio and Eclipse i.e. not very
powerful.
I've used it extensively with Python and it handles whitespace
indentation beautifully.  I like that it also supports Perl because I
use Perl quite a bit too.
That being said, I'm going to give Wing IDE a try at some point soon.

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


Re: Reference Variables In Python Like Those In PHP

2006-08-15 Thread Terry Reedy

Chaos [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Is It possible to have reference variables like in PHP
 ?php
 $x = 1;
 $y = $x;
 $y += 1;
 echo $x;
 echo \n
 echo $y;
 ?

 This would show
 2
 2
 Is this available in python?

No, in the literal meaning of your question.  But..
1. The concept 'reference variable' pertains to PHP's object model, which 
is different from Python's.
2. They are means, not ends.  So a possibly more useful question would be 
along the lines of In PHP, I do this with a reference variable.  How can I 
accomplish the same goal in Python?

Terry Jan Reedy



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


Re: Reference Variables In Python Like Those In PHP

2006-08-15 Thread Neil Cerutti
On 2006-08-15, Chaos [EMAIL PROTECTED] wrote:
 Is It possible to have reference variables like in PHP

 ex.

?php

 $x = 1;
 $y = $x;

 $y += 1;

 echo $x;
 echo \n
 echo $y;

 ?

 This would show

 2
 2

 Is this available in python?

If you store an item in a one-element list, you can use the list
like a reference, but it's not syntactically transparent.

 x = [1]
 y = x

Now x and y refer to the same list. Now you can change the
elements in the list through y.

 y[0] += 1
 x
[2]
 y
[2]

-- 
Neil Cerutti
Sermon Outline: I. Delineate your fear II. Disown your fear III.
Displace your rear --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hide python code !

2006-08-15 Thread Alex Martelli
Gerhard Fiedler [EMAIL PROTECTED] wrote:

 On 2006-08-14 20:48:45, Damjan wrote:
 
  I think you increase your chances of Microsoft not even being in the same
  room with your software 100-fold if you release it under.. say GPL.
 
 ... and have the money to run a law suit? Patents, licenses etc are only as
 strong as the money that backs them, mostly. 

I guess that's an advantage of GPL: there's a foundation (with much
better funding than you could raise as an individual) which will gladly
fight for GPL, both in the courts and in the arena of public opinion --
I believe that, so, far, they've won every single fight they've picked,
by just the joint threat of lawsuits and public shaming campaigns.

It just isn't worth Microsoft's while to take the public-relations hit
of such a fight: much cheaper for them to re-implement your ideas than
to copy your GPL'd code.


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


Re: modifying __new__ of list subclass

2006-08-15 Thread Alex Martelli
Ken Schutte [EMAIL PROTECTED] wrote:

 Steven Bethard wrote:
  
  The __new__ method is for immutable types.  So things like str and int
  do their initialization in __new__.  But for regular mutable types, you
  should do your initialization in __init__::
 
 I see... So, is there a use for __new__ in mutable types?   From my 
 list-derirved class, it was obviously being called, but it's return 
 value is totally ignored?

Wrong: the return value of __new__ is most definitely NOT totally
ignored, since it's what gets passed as the first argument of __init__
(as long as it's an instance of the type in question).  Easy to check
for yourself, e.g.:

 class ha(list):
...   def __new__(cls, *a):
... x = list.__new__(cls, *a)
... x.foo = 23
... return x
... 
 z = ha()
 z.foo
23
 

as you can see, the totally ignored hypothesis is easily disproved.

Of course, there's no particular reason why class ha would _want_ to set
the .foo attribute in __new__ rather than __init__, so that doesn't yet
answer your other question about is there a use.  That answer is a
resounding yes, but the uses may be subtler than you're considering:
for example, you may use the subtype as a general-purpose factory, so
that instantiating the subtype may return objects that are not in fact
instances of the subtype (that bypasses the __init__ call); or, the
overriding of __new__ may go together with the overriding of __init__
(so that the latter doesn't blast the object's state) for such purposes
as singletons or more generally types with a finite pool of instances.


Alex

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


STAF(Software Testing Automation Framework) with STAX for running python test suites/cases

2006-08-15 Thread [EMAIL PROTECTED]
Hi everyone,

I am researching GUI's that I can use for running my python test
sctipts which will make reports and monitor the tests ect...(bringing
my application away form the comand prompt)

I believe the applications STAF and STAX at
http://staf.sourceforge.net/index.php provide this functionality.

I have downloaded these applications and installed them but I keep
geting the error RC:2 as soon as I start the STAX application. I have
installed using the default setup with windows xp pro. I was wondering
if anyone had any luck using this product for this purpose.

I would greatly appricate any reply thank's for your time

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


Re: Beginner Textbook

2006-08-15 Thread John Salerno
M_M wrote:
 Hi,
 
 I am looking for a simple text book to introduce 13 to 18 year olds to 
 python programming. Suggestion?
 
 New to python.

This might be good for your needs. It teaches the basics of computer 
science using Python:

http://www.amazon.com/gp/product/1887902996/sr=8-1/qid=1155656105/ref=pd_bbs_1/104-2407734-1621520?ie=UTF8
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best IDE for Python

2006-08-15 Thread Keith Perkins
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 Hi All, What do you find the best IDE for creating web applications in
 Python is? Preferably FOS IDE.

 Cheers
 
 I like ActiveState's Komodo.  It's heavyweight and not free ($30 for
 the personal edition) but it also supports Perl, Ruby, PHP and TCL.  I
 started using it mostly on Windows but I've used it on Linux more
 recently (and it runs on Solaris and OSX now too).
 It has all the bells and whistles and probably won't appeal too much to
 hardcore emacs/vim people because it is so GUI oriented and nowhere
 near as fast.  Also, it's text editor is similar to the ones you get
 with other popular IDE's like MS DevStudio and Eclipse i.e. not very
 powerful.
 I've used it extensively with Python and it handles whitespace
 indentation beautifully.  I like that it also supports Perl because I
 use Perl quite a bit too.
 That being said, I'm going to give Wing IDE a try at some point soon.
 
Have you tried SPE (Stani's Python Editor) http://stani.be/python/spe/
Free, and available for Linux, Mac, and Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hide python code !

2006-08-15 Thread Ben Sizer
Paul Boddie wrote:
 Successful software businesses are not merely founded on the process of
 having ideas and implementing them - they might also need to be
 effective at delivering those ideas and going through the whole process
 again and again. Writing a neat utility for Windows is not by itself
 the foundation of a successful business - other factors are critical,
 whether they be continuous improvements, service, support, or a number
 of other things.

Yes, but this was never about 'successful software businesses' as such.
I'm not saying anyone deserves to earn a living just because they
created something, but that it is useful for them to be able to reduce
the ways in which others with more resources can replicate that
creation. You don't even need to be a 'successful' business to kill a
competitor, just to have more money in the bank for as long as the
competition exists. (eg. MS vs Netscape, Creative vs Aureal.)

 So, if we decide to ignore people waving pieces of paper around which
 make some claim to an idea or some way of solving some problem, instead
 investigating the actual code, others have pointed out already that if
 you provide just a binary and there exist people who want to know what
 you've done, those people will find it out whether you make it easy for
 them or not.

Yes, in much the same way that there is no point ever locking your
doors or installing burglar alarms, as a determined thief will
eventually steal your belongings.

I find it strange that people (at least on c.l.py) often equate
'imperfect protection' with 'pointless protection'. The all-or-nothing
attitude makes no sense. If you can halve the number of people who can
deduce your algorithm, that helps. If you can double the time it takes
for those people to deduce it, that also helps. If it took you months
of RD, the value of even imperfect protection rises.

 Now, if we sidestep the issue of decompiling binaries and
 cast the affected work as some kind of service, the question can now be
 expressed as whether you should expect to be rewarded forever for
 providing such a service.

But what is 'forever'? Is it a single service for one customer that
persists forever? Or is it a service that will be invoked many times by
different customers forever? Since these are completely different
scenarios, the answer is it depends.

 such issues could possibly increase competitive
 pressure rather than enhance any supposed competitive advantage if
 people felt that the market wasn't providing enough in the way of
 choice in that area.

I'm not interested in whether it's a sound business decision or not.
I'm just interested in the developer's right and/or ability to make
that call.

  I'm not saying I agree with extending the copyright period, however I
  do think you can't just compare it to 'a day at work'. It's a totally
  different set of circumstances which requires a different set of rules
  to both encourage artists to continue creating while benefitting
  society in the long run too.

 For some of those musicians (ie. probably not Sir Cliff Richard), it
 probably was a day at work for which they were badly paid, whilst
 others (eg. Sir Cliff Richard) went on to make quite a bit of money. Of
 course, one can always argue that the result of this particular kind of
 day at work is something that can be enjoyed again and again, but then
 you should consider the issue of why the person working at the car
 factory doesn't get paid royalties every time you turn the key in the
 ignition (even if it's just $0.0001 each time).

There's a key distinction to be made here, at least legally.

Session musicians do work for hire - they're paid by the
hour/day/whatever, and typically have no copyright to the work they
perform on. They are analogous to the person at the car factory. Any
royalties they receive - typically none - would be from the contractual
agreement and nothing to do with copyright.

On the other hand, writing musicians/composers typically will be paid
absolutely nothing for their original creation. They never get paid for
it as such, but they can (and typically do) yield the copyright to a
publishing company in return for an agreed royalty rate on sales of the
reproduced item. They don't so much get paid forever for a service
rendered long ago, they just have their payment spread out over an
indefinite period of time, and that is dependent on people buying that
item.

This is no different from me investing my own time and money into
manufacturing 10,000 cars and selling them between now and 50 years
from now. The major difference is that replicating creative work is
typically much cheaper and easier than replicating automobiles, hence
the existence of various laws safeguarding intellectual property, as
without such laws there would be little incentive to create any such
works that were non-trivial. No-one is going to pay you up front for
it, so you need a way of protecting future potential income. Since that
future income 

Re: Best IDE for Python

2006-08-15 Thread [EMAIL PROTECTED]
I've had a similar experience and tried about everything.  Personally -
eclipse with PyDev has been the winner for me.  I also still do a bunch
of Java coding - so there is an added benefit of one tool across
languages.  The final thing I really like with eclipse is the svn
plugins - making life very easy.  Also, if your doing web/xml and other
stuff - there is a plugin for eclipse for it ;)  Not all the plugins
work as seemlessly together (i abandon eclipse for the majority of
plone/zope stuff - most of it isn't python - and setting up eclipse to
be happy with the output of archgen has not been worth the bother - I'm
sure it's possible)

PyLint can kind of be a pain if your on a low powered box, but tweaking
the settings (and I had to do a bit of tweaking) can alleviate the
problems, but still let you reap the benefits.

Anand

Yu-Xi Lim wrote:
 Michiel Sikma wrote:
  By FOS, do you mean FOSS (Free and Open Source Software)? I've never
  seen the acronym FOS used.

 Maybe he was trying for Free Open Source IDE without the
 semi-redundant Software

  I personally use Eclipse with PyDev.
  http://www.eclipse.org/
  http://pydev.sourceforge.net/

 Eclipse+PyDev has the advantage over emacs when it comes to big
 projects, IMO. It has features like refactoring, better project
 management, code coverage. emacs has the advantage of being faster and
 smaller, and if all you need is a syntax-aware (smart indentation,
 syntax highlighting) editor and integrated debugger, emacs is more than
 enough.

 I've tried the other free IDEs like IDLE, SPE, eric3, TruStudio (for
 Eclipse), Boa, Komodo, WingIDE. I have various issues with them,
 including instability, poor automatic indentation, bad GUI (too many
 subwindows or uncustomizable), costly, no refactoring, and no project
 management.

 It's strangely ironic. I consider Eclipse to be a lousy Java IDE
 especially compared to commercial offerings and yet that's what the
 project started out as.

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


Re: Beginner Textbook

2006-08-15 Thread [EMAIL PROTECTED]

M_M wrote:
 Hi,

 I am looking for a simple text book to introduce 13 to 18 year olds to
 python programming. Suggestion?

 New to python.

On the Python site is a list of tutorials on this page:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers, towards the
end of the page you'll find a few entries for younger students. Good
luck!

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


Re: Best IDE for Python

2006-08-15 Thread Andre Meyer
PyDev is really nice. I use it a lot and it works great.It's just a bit heavy and why should one need a Java IDE for Python development ;-)Another issue is the lack of integration with a UML tool (code generation and reverse engineering), though an ArgoUML plugin is in the making (not for eclipse).
btw What Web/XML plugins are you using with eclipse?regardsAndreOn 15 Aug 2006 09:03:44 -0700, 
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
I've had a similar experience and tried about everything.Personally -eclipse with PyDev has been the winner for me.I also still do a bunchof Java coding - so there is an added benefit of one tool acrosslanguages.The final thing I really like with eclipse is the svn
plugins - making life very easy.Also, if your doing web/xml and otherstuff - there is a plugin for eclipse for it ;)Not all the pluginswork as seemlessly together (i abandon eclipse for the majority of
plone/zope stuff - most of it isn't python - and setting up eclipse tobe happy with the output of archgen has not been worth the bother - I'msure it's possible)PyLint can kind of be a pain if your on a low powered box, but tweaking
the settings (and I had to do a bit of tweaking) can alleviate theproblems, but still let you reap the benefits.AnandYu-Xi Lim wrote: Michiel Sikma wrote:  By FOS, do you mean FOSS (Free and Open Source Software)? I've never
  seen the acronym FOS used. Maybe he was trying for Free Open Source IDE without the semi-redundant Software  I personally use Eclipse with PyDev.
  http://www.eclipse.org/  http://pydev.sourceforge.net/ Eclipse+PyDev has the advantage over emacs when it comes to big
 projects, IMO. It has features like refactoring, better project management, code coverage. emacs has the advantage of being faster and smaller, and if all you need is a syntax-aware (smart indentation,
 syntax highlighting) editor and integrated debugger, emacs is more than enough. I've tried the other free IDEs like IDLE, SPE, eric3, TruStudio (for Eclipse), Boa, Komodo, WingIDE. I have various issues with them,
 including instability, poor automatic indentation, bad GUI (too many subwindows or uncustomizable), costly, no refactoring, and no project management. It's strangely ironic. I consider Eclipse to be a lousy Java IDE
 especially compared to commercial offerings and yet that's what the project started out as.--http://mail.python.org/mailman/listinfo/python-list
-- Dr. Andre P. Meyerhttp://python.openspace.nl/meyerTNO Defence, Security and Safety
http://www.tno.nl/Delft Cooperation on Intelligent Systemshttp://www.decis.nl/Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: modifying __new__ of list subclass

2006-08-15 Thread Steven Bethard
Ken Schutte wrote:
 Steven Bethard wrote:

 The __new__ method is for immutable types.  So things like str and int 
 do their initialization in __new__.  But for regular mutable types, 
 you should do your initialization in __init__::
 
 I see... So, is there a use for __new__ in mutable types?   From my 
 list-derirved class, it was obviously being called, but it's return 
 value is totally ignored?

Not ignored, it's just having it's __init__ method called after your 
__new__ method.

It might help for a moment to consider what happens when you call a 
class object, e.g.::

 c = C()

Just like any other object, when Python sees the ``()``, it looks for a 
__call__ method on the object.  Now classes are instances of the 
``type`` type, which has a call method that looks something like::

 def __call__(cls, *args, **kwargs):
 result = cls.__new__(cls, *args, **kwargs)
 if isinstance(result, cls):
 result.__init__(*args, **kwargs)
 return result

What's happening in your list case is that list.__init__ clears the list::

  l = [1, 2, 3]
  l.__init__()
  l
 []

So even though your __new__ method returns the object you want, the 
__init__ method is clearing out all the items you've added and then 
re-adding them as it normally would. To prove this to yourself, take a 
look at what happens when we override __init__::

  class mylist(list):
 ... def __new__(cls, items):
 ... result = super(mylist, cls).__new__(cls)
 ... for item in items:
 ... result.append('%s_' % item)
 ... return result
 ...
  mylist([1, 2, 3])
 [1, 2, 3]
  class mylist(list):
 ... def __new__(cls, items):
 ... result = super(mylist, cls).__new__(cls)
 ... for item in items:
 ... result.append('%s_' % item)
 ... return result
 ... def __init__(self, items):
 ... pass
 ...
  mylist([1, 2, 3])
 ['1_', '2_', '3_']

Of course, I've made __new__ work above, but the simpler solution is 
just to override __init__ since that's where all the work's being done 
anyway.

See Alex Martelli's response to answer your question So, is there a use 
for __new__ in mutable types?.  You'd probably only want to override 
__new__ if you were going to use the class as a factory to produce a 
bunch of different types of objects.

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


Re: Best IDE for Python

2006-08-15 Thread [EMAIL PROTECTED]
Bruce Who wrote:
 Hi, sjdevnull

 I'm a vimmer too, and I wonder what plugins you are using. What you
 said sounds interesting. Could you tell us more about the plugins?
 Object browser is what I need most, but so far I've no idea what
 plugin can do this for me, :-(

It's like a 15 minute job to write something basic.

Mine's a little more complicated since I deal with ugly things like
finding the parent class in cases like:

import generic.base.klass
...
BaseKlass = generic.base.klass.someKlass
...
class newKlass(BaseKlass):

and similar constructs.  I use the following in my vimrc:

you might need to add directories to sys.path before the following
line
probably also wand to bracket parts of it in 'if have(gui_running)'
python import vimrc
au GUIEnter * py vimrc.tags.fakeTagsMenu()
au BufEnter *.py aunmenu Tags
au BufEnter *.py py vimrc.tags.buildMenu()
au BufLeave *.py menu disable Tags
au BufEnter * py vimrc.tags.fakeTagsMenu()

And then I have a vimrc.py with, among other things:
--
import tags
import os
import vim
def cur_x():
return vim.current.window.cursor[1]
def cur_y():
return vim.current.window.cursor[0]
def relativePath(absolutePath):
cwd = os.getcwd()
if absolutePath.startswith(cwd):
absolutePath = absolutePath[len(cwd):]
while absolutePath[0] == '/':
absolutePath = absolutePath[1:]
return absolutePath
return absolutePath
--
And a tags.py:
--
#!/usr/bin/python
try:
import vim
import vimrc
except:
pass

def findParentClass(currLoc = None, showMenu=0, allLines=None):
if not allLines:
allLines = vim.current.buffer
if currLoc == None:
currLoc = vimrc.cur_y()
lines = [ line for line in allLines[:currLoc] if
line.startswith(class ) ]if len(lines) == 0:
lines = [ line for line in allLines[currLoc:] if
line.startswith(class
) ]
else:
lines.reverse()
if len(lines) == 0:
return None

try:
klass = lines[0].split((, 1)[1].split())[0]
except:
return None
currKlass = lines[0].split( , 1)[1]
currKlass = currKlass.split(:)[0]
try:
currKlass = currKlass.split(()[0]
except:
pass

renameLines = []
for i in range(len(allLines)):
line = allLines[i]
while line.endswith(\\):
line = line[:-1] + allLines[i+1]
i=i+1
if line.endswith( as %s % klass) or line.startswith(%s
=%klass) or line.startswith(%s=%klass):
renameLines.append(line)

if len(renameLines)0:
parseLine = renameLines[-1]
if parseLine.endswith(as %s%klass):
klass = parseLine.split( )[-3]
else:
klass = parseLine.split(.)[-1]
if . in klass:
klass = klass.split(.)[-1]
if showMenu:
if klass == currKlass:
generic = generic
else:
generic = none
vim.command('502menu silent Tags.Parent:%s :call
FindTag(%s, %s)C-M' %(klass, klass, generic))
try:
klass = klass.split(.)[-1]
except:
pass
return klass
def YankLine():
try:
word = vim.current.line
word = word.split( )[-1]
except:
return
try:
vim.command(silent tag %s%word)
except:
return
stuff = vim.current.line
vim.command(normal ^T)
print stuff
def buildChildEntries():
rv = 0
for line in vim.current.buffer:
if line.startswith(class ):
klass = line.split( , 1)[1]
try:
klass = klass.split(()[0]
except:
pass
try:
klass = klass.split(:)[0]
except:
pass
klass = klass.strip()
fileName = vimrc.relativePath(vim.current.buffer.name)
lines = [ line.strip() for line in open(oobr,
r).readlines() if
line.startswith(%s:%klass)]
for line in lines:
rv = 1
splitline = line.split(:)
child = splitline[1]
childBase = childFile.split(/)[-1]
childBase = childBase.split(.)[0]
if _ in childBase and not
fileName.startswith(childBase) and not fileName.startswith(generic)
and not fileName.startswith(libs):
continue
vim.command('502menu silent Tags.Child:%s :call
FindTag(%s,%s)C-M' % (childBase, child, childFile))
vim.command('502menu silent Tags.-children- :')
return rv
def editObject():
vim.command(:e object.py)
vim.command(:set buftype=nowrite)
vim.command(:set bufhidden=delete)
vim.command(:set noswapfile)
def buildParentEntries():
foundSome = 0
for i in range(len(vim.current.buffer)):
if vim.current.buffer[i].startswith(class):
if findParentClass(i, showMenu=1):
foundSome = 1
return foundSome


def 

file object and eof

2006-08-15 Thread KraftDiner
I open a file in python by
f = open('filename', mode='rb')

how can I tell if I am at the end of file?
f.eof() isn't implmented.

How can I implement its functionallity?

Thanks.
B.

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


Re: file object and eof

2006-08-15 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], KraftDiner
wrote:

 I open a file in python by
 f = open('filename', mode='rb')
 
 how can I tell if I am at the end of file?
 f.eof() isn't implmented.
 
 How can I implement its functionallity?

Try to read something.  If the empty string is returned you are at the end
of the file.  Or write a function that uses `os.path.filesize()` and the
`tell()` method of the file.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


How to tell machines endianism.

2006-08-15 Thread KraftDiner
How can you tell if the host processor is a big or little endian
machine?

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


Re: recommended general-purpose string template packages?

2006-08-15 Thread vj
I use preppy from reportlab:

http://www.reportlab.org/preppy.html

It's one file, is fast and can be easily embedded in any application.

Vineet

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


Re: hide python code !

2006-08-15 Thread Paul Boddie
Ben Sizer wrote:
 Paul Boddie wrote:
  Successful software businesses are not merely founded on the process of
  having ideas and implementing them - they might also need to be
  effective at delivering those ideas and going through the whole process
  again and again. Writing a neat utility for Windows is not by itself
  the foundation of a successful business - other factors are critical,
  whether they be continuous improvements, service, support, or a number
  of other things.

 Yes, but this was never about 'successful software businesses' as such.

If success is defined as staying in business whilst making a profit,
then the issue is inseparable from being successful. As the
single-person developer of a small application that did something quite
innovative who charges a small fee for your product, isn't the goal
at least to cover your costs? If you're making software purely to
contribute to society, where the money isn't important, what relevance
does this have to you increasing your chances of survival 10-fold?
Few people contribute to society whilst deliberately obscuring the
thing they're trying to contribute.

 I'm not saying anyone deserves to earn a living just because they
 created something, but that it is useful for them to be able to reduce
 the ways in which others with more resources can replicate that
 creation. You don't even need to be a 'successful' business to kill a
 competitor, just to have more money in the bank for as long as the
 competition exists. (eg. MS vs Netscape, Creative vs Aureal.)

While that is often true, I've already noted several disadvantages that
can outweigh pure financial superiority in such large businesses.

  So, if we decide to ignore people waving pieces of paper around which
  make some claim to an idea or some way of solving some problem, instead
  investigating the actual code, others have pointed out already that if
  you provide just a binary and there exist people who want to know what
  you've done, those people will find it out whether you make it easy for
  them or not.

 Yes, in much the same way that there is no point ever locking your
 doors or installing burglar alarms, as a determined thief will
 eventually steal your belongings.

Despite the pictures various people seem intent on painting, most
contributions to this thread have focused on the tradeoffs involved in
securing algorithms via compilation, obfuscation, and so on.
Analogies about houses and alarms fail to capture the sophistication of
the matter, especially considering the different views on what your
belongings in the context of writing software for profit actually are.

 I find it strange that people (at least on c.l.py) often equate
 'imperfect protection' with 'pointless protection'. The all-or-nothing
 attitude makes no sense. If you can halve the number of people who can
 deduce your algorithm, that helps. If you can double the time it takes
 for those people to deduce it, that also helps. If it took you months
 of RD, the value of even imperfect protection rises.

Imperfect protection isn't pointless but it comes at a cost. Perhaps
Skype's elaborate protection scheme gave that company such an advantage
over its competitors that having the scheme described publicly has had
little impact on its market position. However, such work doesn't just
happen at zero cost, and where people decide to roll their own rather
than purchase some kind of system to do the job, it can be quite a
distraction (both strategically and financially) from just focusing on
the rest of the business.

  Now, if we sidestep the issue of decompiling binaries and
  cast the affected work as some kind of service, the question can now be
  expressed as whether you should expect to be rewarded forever for
  providing such a service.

 But what is 'forever'? Is it a single service for one customer that
 persists forever? Or is it a service that will be invoked many times by
 different customers forever? Since these are completely different
 scenarios, the answer is it depends.

That a continuous stream of possibly different people keep demanding
your service and rewarding you for having provided it. The real,
non-computing world exhibits an abundance of services, of course, and
the area where the right to profit from providing a service becomes
controversial is where monopolies are providing such services.
Technical protections (reinforced by strict legislation) and patents
also serve to impose monopolies, which is why people feel so strongly
about such matters.

[...]

 I'm not interested in whether it's a sound business decision or not.
 I'm just interested in the developer's right and/or ability to make
 that call.

Of course the developer can make that call. The intention was to inform
such developers that yes, there are ways of protecting your trade
secrets, but that it's better to understand the tradeoffs than to rely
totally on some potentially flawed solution.

[Cliff Richard's day at work]

 On the 

Re: file object and eof

2006-08-15 Thread Grant Edwards
On 2006-08-15, KraftDiner [EMAIL PROTECTED] wrote:

 I open a file in python by
 f = open('filename', mode='rb')

 how can I tell if I am at the end of file?

I don't believe you can unless you try to read from the file.

 f.eof() isn't implmented.

 How can I implement its functionallity?

You don't, generally.

There's probably a better, more Pythonic way to accomplish
your goal, but you're going to have to tell us what it is.

-- 
Grant Edwards   grante Yow!  But was he mature
  at   enough last night at the
   visi.comlesbian masquerade?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell machines endianism.

2006-08-15 Thread Steve Holden
KraftDiner wrote:
 How can you tell if the host processor is a big or little endian
 machine?
 

One possible way is to use the struct module to encode an integer value 
in native and little-endian modes and see if the result comes out the 
same or different.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: How to tell machines endianism.

2006-08-15 Thread Jean-Paul Calderone
On 15 Aug 2006 10:06:02 -0700, KraftDiner [EMAIL PROTECTED] wrote:
How can you tell if the host processor is a big or little endian
machine?


  sys.byteorder

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


Re: hide python code !

2006-08-15 Thread Gerhard Fiedler
On 2006-08-15 12:04:18, Alex Martelli wrote:

 It just isn't worth Microsoft's while to take the public-relations hit
 of such a fight: much cheaper for them to re-implement your ideas than
 to copy your GPL'd code.

Exactly. So by publishing the ideas as GPL code, the author presents them
not only the ideas very clearly and well documented, but also an example
implementation. If there was some RD work involved, it may be a better
thing (in terms of protection) not to publish it. The protection from GPL
is pretty much worthless if the worth is more in the principle than it the
execution.

Gerhard

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


idea on how to get/set nested python dictionary values

2006-08-15 Thread jojoba
hello!

i am trying to come up with a simple way to access my values in my
nested python dictionaries

here is what i have so far, but i wanted to run it by the geniuses out
there who might see any probems with this...
here is an example:

+++
def SetNewDataParam(Data, paramPath, NewData):
ParamList  = paramPath.split('/')
numParams  = len(ParamList)
for i in range(0, numParams):
if i != (numParams-1):
Data = Data[ParamList[i]]
else:
Data[ParamList[i]] = NewData


Data  = {'a':{'b':{'c':1}}}
paramPath = 'a/b/c'
NewData= 666
SetNewDataParam(Data, paramPath, NewData)
+++


so it works!
when i do:
print Data, i get
{'a':{'b':{'c':666}}}


but i am hesistant to be throwing around dictionary references
how is this working
shouldn't my line above:
Data = Data[ParamList[i]]
screw up my original Data dictionary

Thanks to anyone with comments on this
By the way, i love the idea of using tuples as keys, but my code is so
far along that i dont wanna switch to that elegant way (maybe on a
future project!)
take care,
jojoba

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


Creating Charts in Excel with pyExcelerator.ExcelMagic

2006-08-15 Thread implicate_order
Greetings,

I'm new to python and am in the process of writing a script to parse
some CSV data, spread it across multiple Excel worksheets and then
generate charts. I searched the internet to find some place where I
could look up a HOWTO doc/recipe to do that using either pyExcelerator
or win32com.client.

Could someone point me in the right direction?
I'm at the stage where the spreadsheet and associated data worksheets
are ready. The chart is created (with win32com.client).  I need to know
how I can use win32com.client to actually generate some data based on
the contents of a particular work sheet.

 from win32com.client import *
 xl = win32com.client.Dispatch(Excel.Application)
 wb = xl.Workbooks.open(C:\scripts\dummytest.xls)
 xl.Visible = 1
 ws = wb.Worksheets(1)
 ws.Range('$A1:$D1').Value = ['NAME', 'PLACE', 'RANK', 'PRICE']
 ws.Range('$A2:$D2').Value = ['Foo', 'Fooland', 1, 100]
 ws.Range('$A3:$D3').Value = ['Bar', 'Barland', 2, 75]
 ws.Range('$A4:$D4').Value = ['Stuff', 'Stuffland', 3, 50]
 wb.Save()
 wb.Charts.Add()
 wc1 = wb.Charts(1)

At this point, I'm lost -- I couldn't find any lucid docs to indicate
what can be done to populate the chart from the worksheet ws.

Any help would be greatly appreciated.

TIA

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


X windows and Python?

2006-08-15 Thread Paul Rubin
I'd like to program my Python script to put a string into the X
windows cut buffer.  Can anyone suggest the simplest way to do that?
Maybe I can do it by putting up a Tkinter text widget, sticking the
string into it, and selecting it (I'm checking the docs) but uggh.
I'd prefer not to have to put anything on the screen.  I just want to
put the string into the cut buffer so I can paste it into another
program.

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


Re: X windows and Python?

2006-08-15 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes:
 I'd like to program my Python script to put a string into the X
 windows cut buffer.

Hmm, looks like I can use w.clipboard_append with an arbitrary tkinter
widget, maybe without having to actually display anything.  I'll try
that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: X windows and Python?

2006-08-15 Thread David Boddie
Paul Rubin wrote:  I'd like to program my Python script to put a
string into the X  windows cut buffer.  Can anyone suggest the
simplest way to do that?  Maybe I can do it by putting up a Tkinter
text widget, sticking the  string into it, and selecting it (I'm
checking the docs) but uggh.  I'd prefer not to have to put anything
on the screen.  I just want to  put the string into the cut buffer so
I can paste it into another  program.   Maybe this does what you need:
 http://python-xlib.sourceforge.net/  David

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


  1   2   3   >