MichiPUG October meeting: Python 2.6

2008-10-01 Thread Kevin Dangoor
Our regularly scheduled MichiPUG meeting is coming on Thursday,  
October 2nd. The meeting will be at its usual time (7 PM) and at the  
usual place (SRT Solutions [1]).


This month meeting topic is Python 2.6. A few months ago, we discussed  
Python 3.0 and all the new features that had to offer. It seems to  
make more sense to focus on Python 2.6, because it's a release that we  
can likely use sometime soon. Coincidentally, Python 2.6 final is due  
out tomorrow [2].


So check out what's new in Python 2.6 [3] and come to the meeting with  
your choices of favorite new features.




[1]: http://groups.google.com/group/michipug/web/SRT%20Solutions

[2]: http://www.python.org/dev/peps/pep-0361/

[3]: http://docs.python.org/dev/whatsnew/2.6.html


--
Kevin Dangoor
Product Manager
SitePen, Inc.
Web development experts:
development, support, training

[EMAIL PROTECTED]
http://www.sitepen.com
650.968.8787
(Timezone: US/Eastern)




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

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


PyCon 2009 (US) - Call for Tutorials

2008-10-01 Thread Greg Lindstrom
The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
pre-conference days devoted to tutorials on Wednesday March 25  Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at 
http://us.pycon.org/2009/tutorials/proposals/.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact [EMAIL PROTECTED]

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Texas Python Regional Unconference Reminders

2008-10-01 Thread Travis Vaught

Greetings,

The Texas Python Regional Unconference is coming up this weekend  
(October 4-5) and I wanted to send out some more details of the  
meeting.  The web page for the meeting is here:


http://www.scipy.org/TXUncon2008

The meeting is _absolutely free_, so please add yourself to the  
Attendees page if you're able to make it.  Also, if you're planning to  
attend, please send me the following information (to [EMAIL PROTECTED] 
) so I can request wireless access for you during the meeting:


 - Full Name
 - Phone or email
 - Address
 - Affiliation

There are still opportunities to present your pet projects at the  
meeting, so feel free to sign up on the presentation schedule here:


http://www.scipy.org/TXUncon2008Schedule

For those who are in town Friday evening, we're planning to get  
together for a casual dinner in downtown Austin that night.  We'll  
meet at Enthought offices (http://www.enthought.com/contact/map-directions.php 
) and walk to a casual restaurant nearby.  Show up as early as 5:30pm  
and you can hang out and tour the Enthought offices--we'll head out to  
eat at 7:00pm sharp.


Best,

Travis


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

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


ANN: eGenix mxODBC Connect Database Interface for Python 0.9.2 (beta)

2008-10-01 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
eGenix.com mxODBC Connect

  Database Interface for Python

   Version 0.9.2 (beta)


  Our new client-server product for connecting Python applications
 to relational databases - from all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-0.9.2-beta.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS
SQL Server, Oracle or DB2 that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please have a look at the product page:

http://www.egenix.com/products/python/mxODBCConnect/

* About Python:
Python is an object-oriented Open Source programming language which
runs on all modern platforms (http://www.python.org/). By integrating
ease-of-use, clarity in coding, enterprise application connectivity
and rapid application design, Python establishes an ideal programming
platform for todays IT challenges.

* About eGenix:
eGenix is a consulting and software product company focused on
providing professional quality services and products to Python
users and developers (http://www.egenix.com/).



NEWS

mxODBC Connect 0.9.2 is our second public beta release of the new
mxODBC Connect product.

It comes with improved documentation, enhanced SQL Server support
on Linux and now runs on Python 2.6 as well (in addition to
Python 2.3, 2.4 and 2.5).

*SPECIAL OFFER*

If you would like to participate in the beta as tester, please see
our beta program page:

http://www.egenix.com/products/python/mxODBCConnect/beta.html

In order to make participation in the beta program more interesting
for our users, we will be giving out *free discount coupons* to all
participants who report back bugs in the product.



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 01 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


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

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


RELEASED Python 2.6 final

2008-10-01 Thread Barry Warsaw

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team and the Python community, I  
am happy to announce the release of Python 2.6 final.  This is the  
production-ready version of the latest in the Python 2 series.


There are many new features and modules, improvements, bug fixes, and  
other changes in Python 2.6.  Please see the What's new page for  
details


http://docs.python.org/dev/whatsnew/2.6.html

as well as PEP 361

http://www.python.org/dev/peps/pep-0361/

While Python 2.6 is backward compatible with earlier versions of  
Python, 2.6 has many tools and features that will help you migrate to  
Python 3.  Wherever possible, Python 3.0 features have been added  
without affecting existing code.  In other cases, the new features can  
be enabled through the use of __future__ imports and command line  
switches.


Python 3.0 is currently in release candidate and will be available  
later this year.  Both Python 2 and Python 3 will be supported for the  
foreseeable future.


Source tarballs, Windows installers, and Mac disk images can be  
downloaded from the Python 2.6 page:


http://www.python.org/download/releases/2.6/

(Please note that due to quirks in the earth's time zones, the Windows  
installers will be available shortly.)


Bugs can be reported in the Python bug tracker:

http://bugs.python.org

Enjoy,
- -Barry

Barry Warsaw
[EMAIL PROTECTED]
Python 2.6/3.0 Release Manager
(on behalf of the entire python-dev team)

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSOREJ3EjvBPtnXfVAQLAigP/aEnrdvAqk7wbNQLFbmBonIr2YQbd1vEu
TyTr5imYXFWGNfv1/JMeMBjMfwpHi1bgPEDTLEZdhDRNj/G1h4NqqnpfJS0lfIaU
4JBKwnsO80se/RGyupcs5f09UdKxOljhbFKEw46CHDkd9lE+cqy2yhetEwyx3c3+
AVC11sjcO54=
=Oxo3
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: How to emit UTF-8 from console mode?

2008-10-01 Thread Martin v. Löwis
 LC_CTYPE=en_US.UTF-8 urxvt-X.exe
 perl -wle binmode STDOUT, q[:utf8]; print chr() for 0x410 .. 0x430;

 Can someone help me translate it into python?

LC_CTYPE=en_US.UTF-8 urxvt-X.exe
python -c 'for i in range(0x410, 0x431):print unichr(i),'

 I would not expect it to work 
 from cmd.exe with python

It should work in cmd.exe, as long as the terminal's encoding supports
these characters in the first place. Use chcp.exe to find out what the
terminal's encoding is. The Python program is not completely equivalent,
as it leaves the output encoding to Python, rather than assuming a fixed
UTF-8 output encoding.

Regards,
Martin

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


Re: How to emit UTF-8 from console mode?

2008-10-01 Thread Mark Tolonen


Martin v. Löwis [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

LC_CTYPE=en_US.UTF-8 urxvt-X.exe
perl -wle binmode STDOUT, q[:utf8]; print chr() for 0x410 .. 0x430;



Can someone help me translate it into python?


LC_CTYPE=en_US.UTF-8 urxvt-X.exe
python -c 'for i in range(0x410, 0x431):print unichr(i),'


I would not expect it to work
from cmd.exe with python


It should work in cmd.exe, as long as the terminal's encoding supports
these characters in the first place. Use chcp.exe to find out what the
terminal's encoding is. The Python program is not completely equivalent,
as it leaves the output encoding to Python, rather than assuming a fixed
UTF-8 output encoding.

Regards,
Martin


Make sure you are using the Lucida Console font for the cmd.exe window and 
type the commands:


chcp 1251
python -c print ''.join(unichr(i) for i in range(0x410,0x431))

Output:

АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯа

UTF-8 encoding (chcp 65001)  doesn't work (Python doesn't recognize it: 
LookupError: unknown encoding: cp65001) and I couldn't get any Chinese 
code pages to work either.  There is some trick I don't know, because 
Chinese versions of Windows can display Chinese.  I have the East Asian 
languages installed and Chinese IME enabled, but it doesn't help for console 
apps.


--Mark

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

Re: Python arrays and sting formatting options

2008-10-01 Thread Marc 'BlackJack' Rintsch
On Tue, 30 Sep 2008 23:40:22 +, Steven D'Aprano wrote:

 On Tue, 30 Sep 2008 14:34:31 +, Marc 'BlackJack' Rintsch wrote:
 
 There is no array.  The data type is called list in Python, so
 `result` is a nested list.  And in Python it quite unusual to build
 lists by creating them with the final size filled with place holder
 objects and then fill the real values in.  Instead lists are typically
 created by appending values to existing lists, using list comprehension
 or the `list()` function with some iterable object.
 
 I would weaken that claim a tad... I'd say it is usual to write
 something like this:
 
 alist = []
 for x in some_values:
 alist.append(something_from_x)
 
 
 but it is not uncommon (at least not in my code) to write something like
 this equivalent code instead:
 
 alist = [None]*len(some_values)
 for i, x in enumerate(some_values):
 alist[i] = something_from_x

I have never done this, except in the beginning I used Python, and -- 
maybe more importantly -- I've never seen this in others code.  I really 
looks like a construct from someone who is still programming in some 
other language(s).

 Most often the first way is most natural, but the second way is
 sometimes more natural.

When will it be more natural to introduce an unnecessary index?

 And Marc, I think you're being a little unfair to the OP, who is clearly
 unfamiliar with Python. I've been using Python for perhaps ten years,
 and I still find your code above dense and hard to comprehend. It uses a
 number of advanced Python concepts that a newbie is going to have
 trouble with:
 
 - the with statement acts by magic; if you don't know what it does, it's
 an opaque black box.

Everything acts by magic unless you know what it does.  The Fortran

  read(*,*)(a(i,j,k),j=1,3)

in the OP's first post looks like magic too.  I admit that my code shows 
off advanced Python features but I don't think ``with`` is one of them.  
It makes it easier to write robust code and maybe even understandable 
without documentation by just reading it as English text.

 - you re-use the same name for different uses, which can cause
 confusion.

Do you mean `lines`?  Then I disagree because the (duck) type is always 
iterable over lines.  I just changed the content by filtering.

 - generator expressions.
 
 - functional programming using partial.
 
 - you call a function that uses a list comprehension with both map and
 iterator slicing inside it.
 
 
 No wonder the OP had trouble with it. *I* have trouble with it, and
 would need to sit down at the interactive interpreter and play around
 with it for a while to be sure what it actually does. If it was your
 intention to make Python look as obtuse and mysterious as possible, you
 almost succeeded. The one things you missed was to replace the
 read_group function with a lambda in the partial.

Well that would make the code harder to understand.  ;-)

Serious, I think it should be easy to understand the code for someone who 
knows Python.  Yes a newbie will have trouble to understand this, but 
Python is not Fortran and IMHO I haven't used something really exotic or 
strange nor did I wrote convoluted and hard to understand things like 
deeply nested list comprehensions.

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


ssh keepalive

2008-10-01 Thread loial
I have a problem with a ssh connection in python

I get the error

'NoneType' object has no attribute 'exec_command'

I am thinking that maybe the ssh connection is timeing out.

Since I have no control over the configuration of the ssh server(which
is AIX 5.23), is there anything I can do in python to ensure that the
ssh session does not timeout?

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


list to tuple conversion

2008-10-01 Thread sc
clp:

Thanx to a recent thread I am able to have a print string
with a variable number of formatters -- what I now lack for
the creation of an elegant print statement is a tuple -- 
following is the code, the last line of which does not work:

code
#!/usr/bin/python
import xml.sax
import eaddyhandler
parser = xml.sax.make_parser()
h = eaddyhandler.EAddyHandler()
parser.setContentHandler(h)
parser.parse(.ea.xml)
for i in range(1, len(h.m)):
k = r%06d % i
col = len(h.m[k])
if col  2 and h.m[k][0]   :
print (col * '%-30s') % h.m[k]
/code

What's going on is I have an oocalc spreadsheet for 
e-addresses -- column 1 has the name, and then I keep 
adding e-addresses for ppl when they get new ones, as 
successive entries on their row, meaning each row has
a variable number of e-address columns.  I have an xml
extractor that runs before this script using 
odf.opendocument, which works famously.

My class, EAddyHandler, also works, and builds its dictionary 
of rows in 'm', forgive me, no flames please, I needed a 
short name for the dictionary I have to type it so many times.
The key to 'm' is an 'r' + row number, so I can get
stuff out of it and it's still in the right order, fun
with dictionaries.

What I was hoping for was something that could vary the
source for the print statement as cleanly as the 'col'
multiplication creates the print format, but the list,
'h.m[k]' is not a tuple, it's a list, and I'm just not 
quite where I am trying to get with this.

If there were a builtin function that took a list and 
returned a tuple, I'd be there, but if there is such a
thing I need someone to point me at it.  I can't help
thinking I am missing some obvious construct, and I'll
be advised to go reread the tutorial, but I'm not there,
and if you can take pity on me and point me there, I'll
be your friend for life.  Well -- I'll be grateful...

TIA,

Scott

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


Re: Output of pexpect

2008-10-01 Thread Lie Ryan
On Tue, 30 Sep 2008 20:48:12 -0700, Anh Khuong wrote:


 I am using pexpect and I want to send output of pexpet to both stdout
 and log file concurrently. Anybody know a solution for it please let me
 know.

One way is to create a file-like object that forked the output to stdout 
and the logfile.

class forkwriter(object):
def __init__(self, filename):
self.file = open(filename, 'w')
def write(self, s):
sys.stdout.write(s)
self.file.write(s)

I've never used pexpect myself though, but if pexpect write things to the 
to the stdout, then you can redirect stdout

import sys
sys.stdout =  forkwriter('mylog.log')

(note: the forkwriter class would have to be modified a bit to use the 
background sys.__stdout__ instead of sys.stdout)

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


Re: list to tuple conversion

2008-10-01 Thread Pekka Laukkanen
2008/10/1 sc [EMAIL PROTECTED]:
 If there were a builtin function that took a list and
 returned a tuple, I'd be there, but if there is such a
 thing I need someone to point me at it.  I can't help
 thinking I am missing some obvious construct, and I'll
 be advised to go reread the tutorial, but I'm not there,
 and if you can take pity on me and point me there, I'll
 be your friend for life.  Well -- I'll be grateful...

 tuple
type 'tuple'
 tuple([1,2,3])
(1, 2, 3)
--
http://mail.python.org/mailman/listinfo/python-list


Re: list to tuple conversion

2008-10-01 Thread Gary M. Josack

sc wrote:

clp:

Thanx to a recent thread I am able to have a print string
with a variable number of formatters -- what I now lack for
the creation of an elegant print statement is a tuple -- 
following is the code, the last line of which does not work:


code
#!/usr/bin/python
import xml.sax
import eaddyhandler
parser = xml.sax.make_parser()
h = eaddyhandler.EAddyHandler()
parser.setContentHandler(h)
parser.parse(.ea.xml)
for i in range(1, len(h.m)):
k = r%06d % i
col = len(h.m[k])
if col  2 and h.m[k][0]   :
print (col * '%-30s') % h.m[k]
/code

What's going on is I have an oocalc spreadsheet for 
e-addresses -- column 1 has the name, and then I keep 
adding e-addresses for ppl when they get new ones, as 
successive entries on their row, meaning each row has

a variable number of e-address columns.  I have an xml
extractor that runs before this script using 
odf.opendocument, which works famously.


My class, EAddyHandler, also works, and builds its dictionary 
of rows in 'm', forgive me, no flames please, I needed a 
short name for the dictionary I have to type it so many times.

The key to 'm' is an 'r' + row number, so I can get
stuff out of it and it's still in the right order, fun
with dictionaries.

What I was hoping for was something that could vary the
source for the print statement as cleanly as the 'col'
multiplication creates the print format, but the list,
'h.m[k]' is not a tuple, it's a list, and I'm just not 
quite where I am trying to get with this.


If there were a builtin function that took a list and 
returned a tuple, I'd be there, but if there is such a

thing I need someone to point me at it.  I can't help
thinking I am missing some obvious construct, and I'll
be advised to go reread the tutorial, but I'm not there,
and if you can take pity on me and point me there, I'll
be your friend for life.  Well -- I'll be grateful...

TIA,

Scott

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

 L = [1,2,3,4,5]
 t = tuple(L)
 t
(1, 2, 3, 4, 5)

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


Event-driven framework (other than Twisted)?

2008-10-01 Thread Phillip B Oldham
Are there any python event driven frameworks other than twisted?
--
http://mail.python.org/mailman/listinfo/python-list


Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Phillip B Oldham
Are there any python micro-frameworks (like ruby's Camping)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: ssh keepalive

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 00:30:59 -0700, loial wrote:

 I have a problem with a ssh connection in python
 
 I get the error
 
 'NoneType' object has no attribute 'exec_command'
 
 I am thinking that maybe the ssh connection is timeing out.
 
 Since I have no control over the configuration of the ssh server(which
 is AIX 5.23), is there anything I can do in python to ensure that the
 ssh session does not timeout?

No, it's a NoneType object (i.e. your variable contains None)
Show us a bit of your code, so we can see why is None there.

My guess is that you're trying to perform something on a function that 
does things in-place and doesn't return anything (e.g. list.append, 
list.sort)

 a = [1, 3, 4, 2]
 a = a.sort()
 print a
[None, None, None, None]

 # should be
 a = [1, 3, 4, 2]
 a.sort()
 print a
[1, 2, 3, 4]

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


Re: XMLRPC - C Client / Python Server

2008-10-01 Thread care02
On 30 Sep, 21:58, Michael Torrie [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I have implemented a simple Python XMLRPC server and need to call it
  from a C/C++ client. What is the simplest way to do this? I need to
  pass numerical arrays from C/C++ to Python.

 Which do you need, C or C++?  They are two different languages with
 different possibilities for libraries.

 As the other poster mentioned, xmlrpc-c is a good one for C, and also
 comes with bindings for C++ which I have used.  Getting xmlrpc-c
 compiled can be a real challenge though.  I recommend you use binary
 packages for your distribution of Linux.  If you need it on Win32, then
 you'll have to spend a day or two figuring out how to build it on
 Windows.  I eventually got the both the C and C++ client library built
 in Mingw with libcurl as the transport.  But it was a real pain.

My problem is that I need xmlrpc-c (preferably the C++ bindings) on
windows. I have just started to build xmlrpc-c on windows, but no
success yet, seems to be quite troublesome. Are there any other xmlrpc
libraries for C/C++ around with prebuilt binaries that work in a
client/server configuration with Python as a xmlrpc server?

Carl

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


Re: XMLRPC - C Client / Python Server

2008-10-01 Thread Chris Rebert
On Wed, Oct 1, 2008 at 1:05 AM,  [EMAIL PROTECTED] wrote:
 On 30 Sep, 21:58, Michael Torrie [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I have implemented a simple Python XMLRPC server and need to call it
  from a C/C++ client. What is the simplest way to do this? I need to
  pass numerical arrays from C/C++ to Python.

 Which do you need, C or C++?  They are two different languages with
 different possibilities for libraries.

 As the other poster mentioned, xmlrpc-c is a good one for C, and also
 comes with bindings for C++ which I have used.  Getting xmlrpc-c
 compiled can be a real challenge though.  I recommend you use binary
 packages for your distribution of Linux.  If you need it on Win32, then
 you'll have to spend a day or two figuring out how to build it on
 Windows.  I eventually got the both the C and C++ client library built
 in Mingw with libcurl as the transport.  But it was a real pain.

 My problem is that I need xmlrpc-c (preferably the C++ bindings) on
 windows. I have just started to build xmlrpc-c on windows, but no
 success yet, seems to be quite troublesome. Are there any other xmlrpc
 libraries for C/C++ around with prebuilt binaries that work in a
 client/server configuration with Python as a xmlrpc server?

The whole point of XML-RPC is to be language-neutral, so the with
Python part of your requirements is superfluous.
On that note, you might want to try asking in a newsgroup/mailinglist
that's more XML-RPC or Windows or C(++) specific.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com


 Carl

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

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


Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 01:01:41 -0700, Phillip B Oldham wrote:

 Are there any python event driven frameworks other than twisted?

Most GUI package use event-driven model (e.g. Tkinter).

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


Re: list to tuple conversion

2008-10-01 Thread sc
Gary M. Josack wrote:

 sc wrote:
 clp:

 Thanx to a recent thread I am able to have a print string
 with a variable number of formatters -- what I now lack for
 the creation of an elegant print statement is a tuple --
 following is the code, the last line of which does not work:

 code
 #!/usr/bin/python
 import xml.sax
 import eaddyhandler
 parser = xml.sax.make_parser()
 h = eaddyhandler.EAddyHandler()
 parser.setContentHandler(h)
 parser.parse(.ea.xml)
 for i in range(1, len(h.m)):
 k = r%06d % i
 col = len(h.m[k])
 if col  2 and h.m[k][0]   :
 print (col * '%-30s') % h.m[k]
 /code

 What's going on is I have an oocalc spreadsheet for
 e-addresses -- column 1 has the name, and then I keep
 adding e-addresses for ppl when they get new ones, as
 successive entries on their row, meaning each row has
 a variable number of e-address columns.  I have an xml
 extractor that runs before this script using
 odf.opendocument, which works famously.

 My class, EAddyHandler, also works, and builds its dictionary
 of rows in 'm', forgive me, no flames please, I needed a
 short name for the dictionary I have to type it so many times.
 The key to 'm' is an 'r' + row number, so I can get
 stuff out of it and it's still in the right order, fun
 with dictionaries.

 What I was hoping for was something that could vary the
 source for the print statement as cleanly as the 'col'
 multiplication creates the print format, but the list,
 'h.m[k]' is not a tuple, it's a list, and I'm just not
 quite where I am trying to get with this.

 If there were a builtin function that took a list and
 returned a tuple, I'd be there, but if there is such a
 thing I need someone to point me at it.  I can't help
 thinking I am missing some obvious construct, and I'll
 be advised to go reread the tutorial, but I'm not there,
 and if you can take pity on me and point me there, I'll
 be your friend for life.  Well -- I'll be grateful...

 TIA,

 Scott

 --
 http://mail.python.org/mailman/listinfo/python-list
   
   L = [1,2,3,4,5]
   t = tuple(L)
   t
 (1, 2, 3, 4, 5)

fine, documented now, for the world to see, I'm an idiot,
fine, but anyway, thank you both, I'll shutup now.

sc

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


Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Sam
Did you try WebPy?
http://webpy.org/ Hum, the website seems to be down today

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


Интернет магазин для похуде ния Shop Body

2008-10-01 Thread ShopBody.ru
Мы рады предложить Вашему вниманию товары для здоровья самые
качественные и эффективные товары ведущих производителей мира: пояса,
бандажи, корсеты, корректоры осанки, изделия для похудения и лечения
целлюлита, массажеры и миостимуляторы, аппараты физиотерапии и
медтехнику, наборы для ухода за руками, а также: термобелье и грелки,
фиксаторы суставов, косметику для уход за лицом и волосами,
принадлежности и техника для дома и дачи, техника и приспособления для
кухни, домашние тренажеры и спортивные товары, ортопедические подушки
и матрасы и многое другое.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Phillip B Oldham
On Oct 1, 9:25 am, Lie Ryan [EMAIL PROTECTED] wrote:
 Most GUI package use event-driven model (e.g. Tkinter).

I've noticed that. I'm thinking more for a web environment (instead of
MVC) or as a HTTP server. I know Twisted has TwistedWeb, but I'm
looking for alternatives.
--
http://mail.python.org/mailman/listinfo/python-list


Интернет магазин для похуде ния ShopBody

2008-10-01 Thread ShopBody.ru
Интернет магазин товаров для красоты и здоровья ShopBody Мировые
бренды. Профессиональная консультация. Моментальная доставка. Товары
почтой. Широкий ассортимент. Интернет-магазин для похудения и борьбы с
целлюлитом Shopbody
--
http://mail.python.org/mailman/listinfo/python-list

Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Phillip B Oldham
On Oct 1, 9:53 am, Sam [EMAIL PROTECTED] wrote:
 Did you try WebPy?http://webpy.org/Hum, the website seems to be down today

Not yet - I'm hoping the python community can suggest some examples of
micro/small frameworks (which just supply the basics; no forms/
templating/ORM/etc) so I can compare and select the one which suits my
needs.
--
http://mail.python.org/mailman/listinfo/python-list


Using Tkinter and Tix together opens a new DOS Window in addition to the actual GUI on windows XP

2008-10-01 Thread dudeja . rajat
Hi,


I m using Tkinter and Tix. I'm using Tkinter mainly for all the widgets
except for the TixComboBox for which I use Tix.

My event loop starts like this:

myRoot = Tix.Tk()
myRoot.title(Test Automation)#
myAppGUIObject = myAppGUI(myRoot, logger)  #myAPPGUI is the class for
creating GUI
myRoot.mainloop()

The problem is as soon as I doubel click on this script a DOS window opens
up in addition to the GUI.

I don't why is this happening? I assume the problem is becuase I'm using the
statement:
Tix.Tk()
when I'm using tix for only a combo box and the rest of the widgets are
tkinter widgets.


So,
1. Is the above approach fine?
2. How can I stop the dos window from opening up?

-- 
Regrads,
Rajat
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python arrays and sting formatting options

2008-10-01 Thread Steven D'Aprano
On Tue, 30 Sep 2008 19:44:40 -0500, Grant Edwards wrote:

 On 2008-09-30, Steven D'Aprano [EMAIL PROTECTED]
 wrote:
 On Tue, 30 Sep 2008 10:57:19 -0500, Grant Edwards wrote:

 How would the python equivalent go ?
 
 You would drag yourself out of the 1960s, install numpy, and then do
 something like this:

 I think that was thoughtlessly rude to somebody who is asking a
 perfectly reasonable question.
 
 Sheesh.  I guess I should have added a smiley face.
 
 So much for trying to be helpful.


Oh the rest of your post was helpful. I think you were trying to be 
funny, but I think you failed.




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


Re: list to tuple conversion

2008-10-01 Thread Gabriel Genellina

En Wed, 01 Oct 2008 04:51:33 -0300, sc [EMAIL PROTECTED] escribió:


Thanx to a recent thread I am able to have a print string
with a variable number of formatters -- what I now lack for
the creation of an elegant print statement is a tuple --
following is the code, the last line of which does not work:

for i in range(1, len(h.m)):
k = r%06d % i
col = len(h.m[k])
if col  2 and h.m[k][0]   :
print (col * '%-30s') % h.m[k]
/code


Another alternative would be:

print ''.join('%-30s' % item for item in h.m[k])

You may need to add square brackets [ ] inside the parenthesis () if your  
Python version is older than 2.5


--
Gabriel Genellina

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


Re: how to search multiple textfiles ? (Python is slow ?)

2008-10-01 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Stef
Mientki wrote:

 Lawrence D'Oliveiro wrote:

 In message [EMAIL PROTECTED], Stef
 Mientki wrote:

 I'm really amazed by the speed of Python !!
 It can only be beaten by findstr, which is only available on windows.

 Did you try find -exec grep -F?
   
 well my windows version doesn't understand that :

I assumed when you said It can only be beaten by findstr, which is only
available on windows, that meant you had tried some non-Windows options,
before concluding that Windows findstr was the fastest.
--
http://mail.python.org/mailman/listinfo/python-list


Re: One class per file?

2008-10-01 Thread Lawrence D'Oliveiro
In message
[EMAIL PROTECTED], HCB
wrote:

 The book Code Complete recommends that you put only one class in a
 source file ...

That would only apply to languages like C with no namespace control.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd Errors

2008-10-01 Thread Lawrence D'Oliveiro
In message
[EMAIL PROTECTED],
Aaron Castironpi Brady wrote:

 Do you ever want to scream from the rooftops, 'append' operates by
 side-effect!?

No. It's an effect, not a side-effect.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Comparing float and decimal

2008-10-01 Thread Mark Dickinson
On Sep 30, 8:07 pm, Terry Reedy [EMAIL PROTECTED] wrote:
 Documenting the problem properly would mean changing the set
 documentation to change at least the definitions of union (|), issubset
 (=), issuperset (=), and symmetric_difference (^) from their current
 math set based definitions to implementation based definitions that
 describe what they actually do instead of what they intend to do.  I do
 not like this option.

I was thinking more of a single-line warning in the set documentation
to the effect that funny things happen in the absence of transitivity
of equality, perhaps pointing the finger at Decimal as the most
obvious troublemaker;  the Decimal documentation could elaborate on
this.
That is, rather than documenting exactly what the set operations do,
document what they're supposed to do (just as now) and declare that
behaviour is undefined for sets of elements for which transitivity
fails.

 (1A) All that is needed for fix equality transitivity corruption and the
 consequent set/dictview problems is to correctly compare integral
 values.  For this, Decimal hash seems fine already.  For the int i I
 tried, hash(i) == hash(float(i)) == hash(Decimal(i)) ==
 hash(Fraction(i)) == i.

Good point.  Though I'd be a bit uncomfortable with having
Decimal(1) == 1.0 return True, but Decimal('0.5') == 0.5 return False.
Not sure what the source of my discomfort is;  partly I think it's
that I want to be able to explain the comparison rules at the
level of types;  having some floats behave one way and some behave
another feels odd.  And explaining to confused users exactly
why Decimal behaves this way could be fun.

I think I'd prefer option 1 to option 1a.

 (3) Further isolate decimals by making decimals also unequal to all
 ints.  Like (1A), this would easily fix transitivity breakage, but I
 would consider the result less desirable.

I'd oppose this.  I think having decimals play nicely with integers
is important, both practically and theoretically.  There's probably
also already existing code that depends on comparisons between
integers and Decimals working as expected.

So I guess my ranking is 0  1  1a  3, though I could live
with any of 0, 1, or 1a.

It's really the decimal module that's breaking the rules here;
I feel it's the decimal module's responsibility to either
fix or document the resulting problems.

It would also be nice if it were made more obvious somewhere
in the docs that transitivity of equality is important
for correct set and dict behaviour.

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


Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Michele Simionato
On Oct 1, 10:58 am, Phillip B Oldham [EMAIL PROTECTED] wrote:
 On Oct 1, 9:53 am, Sam [EMAIL PROTECTED] wrote:

  Did you try WebPy?http://webpy.org/Hum, the website seems to be down today

 Not yet - I'm hoping the python community can suggest some examples of
 micro/small frameworks (which just supply the basics; no forms/
 templating/ORM/etc) so I can compare and select the one which suits my
 needs.

How about wsgiref in the standard library? It is as small as you can
get without
resorting to CGI.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Phillip B Oldham
On Oct 1, 10:29 am, Michele Simionato [EMAIL PROTECTED]
wrote:
 How about wsgiref in the standard library? It is as small as you can
 get without resorting to CGI.

Interesting... I'll be sure to check that out also.

Someone also mentioned Paste/WebOb, so now I have 3 to test.

Any others?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python arrays and sting formatting options

2008-10-01 Thread Steven D'Aprano
On Wed, 01 Oct 2008 06:58:11 +, Marc 'BlackJack' Rintsch wrote:


 I would weaken that claim a tad... I'd say it is usual to write
 something like this:
 
 alist = []
 for x in some_values:
 alist.append(something_from_x)
 
 
 but it is not uncommon (at least not in my code) to write something
 like this equivalent code instead:
 
 alist = [None]*len(some_values)
 for i, x in enumerate(some_values):
 alist[i] = something_from_x
 
 I have never done this, except in the beginning I used Python, and --
 maybe more importantly -- I've never seen this in others code.  I really
 looks like a construct from someone who is still programming in some
 other language(s).


It occurs at least twice in the 2.5 standard library, once in 
sre_parse.py:

groups = []
groupsappend = groups.append
literals = [None] * len(p)
for c, s in p:
if c is MARK:
groupsappend((i, s))
# literal[i] is already None
else:
literals[i] = s



and another time in xdrlib.py:

succeedlist = [1] * len(packtest)
count = 0
for method, args in packtest:
print 'pack test', count,
try:
method(*args)
print 'succeeded'
except ConversionError, var:
print 'ConversionError:', var.msg
succeedlist[count] = 0
count = count + 1




 Most often the first way is most natural, but the second way is
 sometimes more natural.
 
 When will it be more natural to introduce an unnecessary index?

We can agree that the two idioms are functionally equivalent. Appending 
is marginally less efficient, because the Python runtime engine has to 
periodically resize the list as it grows, and that can in principle take 
an arbitrary amount of time if it causes virtual memory paging. But 
that's unlikely to be a significant factor for any but the biggest lists.

So in the same way that any while-loop can be rewritten as a recursive 
function, and vice versa, so these two idioms can be trivially re-written 
from one form to the other. When should you use one or the other?

When the algorithm you have is conceptually about growing a list by 
appending to the end, then you should grow the list by appending to the 
end. And when the algorithm is conceptually about dropping values into 
pre-existing pigeon holes, then you should initialize the list and then 
walk it, modifying the values in place.

And if the algorithm in indifferent to which idiom you use, then you 
should use whichever idiom you are most comfortable with, and not claim 
there's Only One True Way to build a list.


 And Marc, I think you're being a little unfair to the OP, who is
 clearly unfamiliar with Python. I've been using Python for perhaps ten
 years, and I still find your code above dense and hard to comprehend.
 It uses a number of advanced Python concepts that a newbie is going
 to have trouble with:
 
 - the with statement acts by magic; if you don't know what it does,
 it's an opaque black box.
 
 Everything acts by magic unless you know what it does.  The Fortran
 
   read(*,*)(a(i,j,k),j=1,3)
 
 in the OP's first post looks like magic too.  

It sure does. My memories of Fortran aren't good enough to remember what 
that does.

But I think you do Python a disservice. One of my Perl coders was writing 
some Python code the other day, and he was amazed at how guessable Python 
was. You can often guess the right way to do something. He wanted a set 
with all the elements of another set removed, so he guess that s1-s2 
would do the job -- and it did. A lot of Python is amazingly readable to 
people with no Python experience at all. But not everything.


 I admit that my code shows
 off advanced Python features but I don't think ``with`` is one of them.
 It makes it easier to write robust code and maybe even understandable
 without documentation by just reading it as English text.

The first problem with with is that it looks like the Pascal with 
statement, but acts nothing like it. That may confuse anyone with Pascal 
experience, and there are a lot of us out there.

The second difficulty is that:

with open('test.txt') as lines:

binds the result of open() to the name lines. How is that different 
from lines = open('test.txt')? I know the answer, but we shouldn't 
expect newbies coming across it to be anything but perplexed.

Now that the newbie has determined that lines is a file object, the very 
next thing you do is assign something completely different to 'lines':

lines = (line for line in lines if line.strip())

So the reader needs to know that brackets aren't just for grouping like 
in most other languages, but also that (x) can be equivalent to a for-
loop. They need to know, or guess, that iterating over a file object 
returns lines of the file, and they have to keep the two different 
bindings of lines straight in their head in a piece of code that uses 
lines twice and line three times.

And then they hit the 

Re: Odd Errors

2008-10-01 Thread Steven D'Aprano
On Wed, 01 Oct 2008 22:14:49 +1300, Lawrence D'Oliveiro wrote:

 In message
 [EMAIL PROTECTED],
 Aaron Castironpi Brady wrote:
 
 Do you ever want to scream from the rooftops, 'append' operates by
 side-effect!?
 
 No. It's an effect, not a side-effect.

Side-effect has the technical meaning in functional languages of any 
change of state that isn't the creation and return of a function result.

People who have been influenced by such functional languages, and many 
Python users are, often use the same meaning. I for one have no 
difficulty understanding from context the difference between append 
operates by side-effect and a function which modifies global variables 
is having side-effects.



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


Re: One class per file?

2008-10-01 Thread Bruno Desthuilliers

Lawrence D'Oliveiro a écrit :

In message
[EMAIL PROTECTED], HCB
wrote:


The book Code Complete recommends that you put only one class in a
source file ...


That would only apply to languages like C with no namespace control.


classes in C ?-)

OTHO, 'one class per file' is a standard idiom in Java and IIRC in C++ 
(which both have namespaces one way or another)

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


Re: Wait or not?

2008-10-01 Thread Christian Heimes

Eric wrote:

I've been wanting to learn Python for a while now but I can't decide
on whether to wait for Python 3's final release and learn it or just
go ahead and learn 2.x. Would it be hard to make the transition being
a noob?


I suggest you stick to Python 2.5 or 2.6 for now. It's going to take 
several months to years until the majority of 3rd party software 
supports the 3.x series.


Christian

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


Re: Shed Skin (restricted) Python-to-C++ compiler 0.0.29

2008-10-01 Thread srepmub

 Not to sound negative, but what's with the 0.0.x version numbers ?
 Maybe it's just me, but seeing a zero major/minor version give me the
 impression of experimental/pre-alpha project, which (from my very
 limited knowledge) doesn't do justice to shedskin's current state.

I know of too many bugs to be comfortable calling it 0.1 just yet..
And I really want to improve extension module support (as mentioned)
first. There's not much else holding back a 0.1 release.


Thanks,
Mark.



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


parse a normal textfile

2008-10-01 Thread devi thapa
hi all

   I have one normal text file. I need to parse the file, that too
in an associative way .
suppose that below is the normal textfile

name='adf'
id  =1
value=344

So when I give 'name' as an input, the output must be 'adf'

so please help me out with this.

regards,
devi.
--
http://mail.python.org/mailman/listinfo/python-list

Tix: Windows XP: Problem - how to stop root window from popping up with Tix

2008-10-01 Thread dudeja . rajat
Hi,

Im using Tix on widows XP and I've tried many ways to suppress the root
window. But so far I'm unable to do it.


Please suggest how can I suppress the root window.

My code is as follows:

import Tix
myRoot = Tix.Tk()

myRoot.withdraw()
myRoot.deiconify()



myRoot.title(Test Automation)
#Create GUI Object and pass the logger object
myAppGUIObject = myAppGUI(myRoot, logger)   #My AppGUI class creates the GUI
which heavily uses the Tkinter widgets and only TixComboBox

myRoot.mainloop()


Please suggest if there is anything I'm missing.


Thanks and regards,
Rajat
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python arrays and sting formatting options

2008-10-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Oct 2008 09:35:03 +, Steven D'Aprano wrote:

 On Wed, 01 Oct 2008 06:58:11 +, Marc 'BlackJack' Rintsch wrote:
 
 I would weaken that claim a tad... I'd say it is usual to write
 something like this:
 
 alist = []
 for x in some_values:
 alist.append(something_from_x)
 
 
 but it is not uncommon (at least not in my code) to write something
 like this equivalent code instead:
 
 alist = [None]*len(some_values)
 for i, x in enumerate(some_values):
 alist[i] = something_from_x
 
 I have never done this, except in the beginning I used Python, and --
 maybe more importantly -- I've never seen this in others code.  I
 really looks like a construct from someone who is still programming in
 some other language(s).
 
 
 It occurs at least twice in the 2.5 standard library, once in
 sre_parse.py:
 
 groups = []
 groupsappend = groups.append
 literals = [None] * len(p)
 for c, s in p:
 if c is MARK:
 groupsappend((i, s))
 # literal[i] is already None
 else:
 literals[i] = s
 
 and another time in xdrlib.py:
 
 succeedlist = [1] * len(packtest)
 count = 0
 for method, args in packtest:
 print 'pack test', count,
 try:
 method(*args)
 print 'succeeded'
 except ConversionError, var:
 print 'ConversionError:', var.msg
 succeedlist[count] = 0
 count = count + 1

I guess the first falls into the micro optimization category because it 
binds `groups.append` to a name to spare the attribute look up within the 
loop.

Both have in common that not every iteration changes the list, i.e. the 
preset values are not just place holders but values that are actually 
used sometimes.  That is different from creating a list of place holders 
that are all overwritten in any case.

 - the with statement acts by magic; if you don't know what it does,
 it's an opaque black box.
 
 Everything acts by magic unless you know what it does.  The Fortran
 
   read(*,*)(a(i,j,k),j=1,3)
 
 in the OP's first post looks like magic too.
 
 It sure does. My memories of Fortran aren't good enough to remember what
 that does.
 
 But I think you do Python a disservice. One of my Perl coders was
 writing some Python code the other day, and he was amazed at how
 guessable Python was. You can often guess the right way to do something.

I think my code would be as guessable to a Lisp, Scheme, or Haskell 
coder.  Okay, Lispers and Schemers might object the ugly syntax.  ;-)

 I admit that my code shows off advanced Python features but I don't
 think ``with`` is one of them. It makes it easier to write robust code
 and maybe even understandable without documentation by just reading it
 as English text.
 
 The first problem with with is that it looks like the Pascal with
 statement, but acts nothing like it. That may confuse anyone with Pascal
 experience, and there are a lot of us out there.

But Python is not Pascal either.  Nonetheless a Pascal coder might guess 
what the ``with`` does.  Not all the gory details but that it opens a 
file and introduces `lines` should be more or less obvious to someone who 
has programmed before.

 The second difficulty is that:
 
 with open('test.txt') as lines:
 
 binds the result of open() to the name lines. How is that different
 from lines = open('test.txt')? I know the answer, but we shouldn't
 expect newbies coming across it to be anything but perplexed.

Even if newbies don't understand all the details they should be 
introduced to ``with`` right away IMHO.  Because if you explain all the 
details, even if they understand them, they likely will ignore the 
knowledge because doing it right is a lot of boiler plate code.  So 
usually people write less robust code and ``with`` is a simple way to 
solve that problem.

 Now that the newbie has determined that lines is a file object, the very
 next thing you do is assign something completely different to 'lines':
 
 lines = (line for line in lines if line.strip())
 
 So the reader needs to know that brackets aren't just for grouping like
 in most other languages, but also that (x) can be equivalent to a for-
 loop. They need to know, or guess, that iterating over a file object
 returns lines of the file, and they have to keep the two different
 bindings of lines straight in their head in a piece of code that uses
 lines twice and line three times.

Yes the reader needs to know a basic Python syntax construct to 
understand this.  And some knowledge from the tutorial about files.  So 
what?

 And then they hit the next line, which includes a function called
 partial, which has a technical meaning out of functional languages and
 I am sure it will mean nothing whatsoever to anyone unfamiliar to it.
 It's not something that is guessable, unlike open() or len() or
 append().

Why on earth has everything to be guessable for someone who doesn't know 
Python or even programming at all?


Re: Tix: Windows XP: Problem - how to stop root window from popping up with Tix

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 11:33:59 +0100, dudeja.rajat wrote:

 Hi,
 
 Im using Tix on widows XP and I've tried many ways to suppress the root
 window. But so far I'm unable to do it.
 
 
 Please suggest how can I suppress the root window.
 
 My code is as follows:
 
 import Tix
 myRoot = Tix.Tk()
 
 myRoot.withdraw()
 myRoot.deiconify()
 
 
 
 myRoot.title(Test Automation)
 #Create GUI Object and pass the logger object myAppGUIObject =
 myAppGUI(myRoot, logger)   #My AppGUI class creates the GUI which
 heavily uses the Tkinter widgets and only TixComboBox
 
 myRoot.mainloop()
 
 
 Please suggest if there is anything I'm missing.
 
 
 Thanks and regards,
 Rajat

The root window is the main window, not the DOS box. I think in windows, 
you should use pythonw.exe or something to open the python script so not 
to open a dos box.

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


Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Oct 2008 01:02:24 -0700, Phillip B Oldham wrote:

 Are there any python micro-frameworks (like ruby's Camping)?

Maybe `CherryPy`!?  It's the heart of other frameworks that add 
templating, ORM and the like to it.

Another consideration might be `Werkzeug`.

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


Re: closures and dynamic binding

2008-10-01 Thread jhermann
I didn't see this mentioned in the thread yet: the double-lambda is
unnecessary (and a hack). What you should do when you need early
binding is... early binding. ;)

Namely:

f = [lambda n=n: n for n in range(10)]
print f[0]()
print f[1]()

Note the n=n, this prints 0 and 1 instead of 9/9.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ssh keepalive

2008-10-01 Thread Marc 'BlackJack' Rintsch
On Wed, 01 Oct 2008 08:07:43 +, Lie Ryan wrote:

 a = [1, 3, 4, 2]
 a = a.sort()
 print a
 [None, None, None, None]

*That* would be really odd.  The last line should be just a singel `None` 
and not a list.  :-)

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


Re: ssh keepalive

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 10:47:28 +, Marc 'BlackJack' Rintsch wrote:

 On Wed, 01 Oct 2008 08:07:43 +, Lie Ryan wrote:
 
 a = [1, 3, 4, 2]
 a = a.sort()
 print a
 [None, None, None, None]
 
 *That* would be really odd.  The last line should be just a singel
 `None` and not a list.  :-)
 
 Ciao,
   Marc 'BlackJack' Rintsch

Ah yeah, I originally intended to give a list of list example, but 
changed mind and forgot to change that last line.

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


Re: Eggs, VirtualEnv, and Apt - best practices?

2008-10-01 Thread jhermann
Our solution consists of:
 * our own base python distribution, decoupled from the OS one (for
various reasons, one being version independency)
 * distutils / setuptools / virtualenv is included in that python
installation, no other eggs installed in site-packages
 * virtualenv + Paver to manage build environments
 * Paver plugins containing standard (continuous) build targets
 * a hand-crafted tool that builds an RPM (.deb would be easy, too)
from an egg URL / filename, packaging a ready-to-run virtualenv
environment into the RPM; it's a rather shallow shell above virtualenv
and rpmbuild, automating the process and enforcing company standards.
--
http://mail.python.org/mailman/listinfo/python-list


Re: closures and dynamic binding

2008-10-01 Thread Paul Boddie
On 1 Okt, 12:43, jhermann [EMAIL PROTECTED] wrote:

 f = [lambda n=n: n for n in range(10)]
 print f[0]()
 print f[1]()

 Note the n=n, this prints 0 and 1 instead of 9/9.

Yes, Terry mentioned this in his response to my first message. Not
with lambdas, however, but he did state that he didn't believe that
such a distinction needed to be made clear to everyone.

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


Isolated environment for execfile

2008-10-01 Thread Igor Kaplan
Hello python gurus.

  I got quite unusual problem and all my searches to find the answer on my 
own were not successful.
  Here is the scenario:
  I have the python program, let's call it script1.py, this program needs to 
execute another python script, let's call it script2.py.
  In script1.py I have the statement:
execfile('script2.py')
  Everything is fine beside one thing. The script2.py is pretty big python 
program which does a lot of things and also while runs, it modifies many 
variables and module members, such for example as sys.path. So when 
script2.py exits all changes which it does are visible in my main program, 
script1.py. Even more, I need to execute script2.py in loop, several times 
during script1.py session. And all changes, which script2.py does just 
accumulate.

  I wander, is there any way to execute script2.py in it's own environment, 
so when script2.py exits, all modifications, which it is done in global 
modules are gone?
Ideally I would love to have the following.

script1.py:
import sys
i = 10
print len(sys.path) # displays 5 for example
execfile('script2.py')
print i # still displays 10
print len(sys.path) # still displays 5

script2.py:
import sys
i += 10
sys.path.insert(0, '\\my folder')

  Sorry for such long and probably confusing message. As you probably see, I 
am not really strong python programmer and don't know advanced techniques. I 
have spent several days trying to look for the solution, the problem is, I 
even don't know what to look for. All references to execfile more talk about 
saving the environment instead of isolating it.
  Would so much appreciate any help.

  Thanks in advance.

   Igor.


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


Re: Tix: Windows XP: Problem - how to stop root window from popping up with Tix

2008-10-01 Thread dudeja . rajat
On Wed, Oct 1, 2008 at 11:44 AM, Lie Ryan [EMAIL PROTECTED] wrote:

 On Wed, 01 Oct 2008 11:33:59 +0100, dudeja.rajat wrote:

  Hi,
 
  Im using Tix on widows XP and I've tried many ways to suppress the root
  window. But so far I'm unable to do it.
 
 
  Please suggest how can I suppress the root window.
 
  My code is as follows:
 
  import Tix
  myRoot = Tix.Tk()
 
  myRoot.withdraw()
  myRoot.deiconify()
 
 
 
  myRoot.title(Test Automation)
  #Create GUI Object and pass the logger object myAppGUIObject =
  myAppGUI(myRoot, logger)   #My AppGUI class creates the GUI which
  heavily uses the Tkinter widgets and only TixComboBox
 
  myRoot.mainloop()
 
 
  Please suggest if there is anything I'm missing.
 
 
  Thanks and regards,
  Rajat

 The root window is the main window, not the DOS box. I think in windows,
 you should use pythonw.exe or something to open the python script so not
 to open a dos box.

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


No, even that does not help. :-(

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

Re: Are there any python micro-frameworks (like ruby's Camping)?

2008-10-01 Thread Sam
On Oct 1, 3:42 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 On Wed, 01 Oct 2008 01:02:24 -0700, Phillip B Oldham wrote:
  Are there any python micro-frameworks (like ruby's Camping)?

 Maybe `CherryPy`!?  It's the heart of other frameworks that add
 templating, ORM and the like to it.

Yeah definitely check out CherryPy.  Not sure if it's micro enough for
you, but it's pretty sweet.  ;)

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


change line with columns when print

2008-10-01 Thread sandric ionut


Hello:
I have a text file that looks like:
0 23
1 342
3 31
and I want to read the file and print it out like:
0 1 3
23 342 31

How can I do this?

Thnak you in advance,

Ionut


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

Re: change line with columns when print

2008-10-01 Thread sandric ionut
Thank you Almar

It worked :), I now have to format it nicely

Ionut



- Original Message 
From: Almar Klein [EMAIL PROTECTED]
To: python-list@python.org
Sent: Wednesday, October 1, 2008 2:57:00 PM
Subject: Re: change line with columns when print


Hi,

probably not the best solution, but this should work:

L1 = []
L2 = []
for i in file:
    tmp = i.split( )
    L1.append(tmp[0])
    L2.append(tmp[1])
    
for i in L1:
    print i,
print # new line
for i in L2:
    print i,
print # new line 

Almar



2008/10/1 sandric ionut [EMAIL PROTECTED]



Hello:
I have a text file that looks like:
0 23
1 342
3 31
and I want to read the file and print it out like:
0 1 3
23 342 31

How can I do this?

Thnak you in advance,

Ionut



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


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

Re: parse a normal textfile

2008-10-01 Thread Tino Wildenhain

devi thapa wrote:

hi all
 
   I have one normal text file. I need to parse the file, that 
too in an associative way .

suppose that below is the normal textfile

name='adf'
id  =1
value=344



there are many approaches to config files. But
in your special example, it looks like a simplified
mapping, so

parsed=eval(dict(%s) % ,.join(line
 for line
 in file(textfile)
 if line.strip()
 )
)

 parsed['name']
'adf'

but of course eval() is dangerous, so feel free to
explore more then this one solution.

Regards
Tino



smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: change line with columns when print

2008-10-01 Thread D'Arcy J.M. Cain
On Wed, 1 Oct 2008 04:43:34 -0700 (PDT)
sandric ionut [EMAIL PROTECTED] wrote:
 
 
 Hello:
 I have a text file that looks like:
 0 23
 1 342
 3 31
 and I want to read the file and print it out like:
 0 1 3
 23 342 31
 
 How can I do this?

Probably tons of ways.  Here's one with no input checking.

L = [x.strip().split() for x in open(infile) if x]
for i in range(2):
  print ' '.join([x[i] for x in L])

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: change line with columns when print

2008-10-01 Thread Almar Klein
Hi,

probably not the best solution, but this should work:

L1 = []
L2 = []
for i in file:
tmp = i.split( )
L1.append(tmp[0])
L2.append(tmp[1])

for i in L1:
print i,
print # new line
for i in L2:
print i,
print # new line

Almar


2008/10/1 sandric ionut [EMAIL PROTECTED]


 Hello:
 I have a text file that looks like:
 0 23
 1 342
 3 31
 and I want to read the file and print it out like:
 0 1 3
 23 342 31

 How can I do this?

 Thnak you in advance,

 Ionut




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

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

Re: change line with columns when print

2008-10-01 Thread sandric ionut
Even better,

Thank you all

Ionut



- Original Message 
From: D'Arcy J.M. Cain [EMAIL PROTECTED]
To: sandric ionut [EMAIL PROTECTED]
Cc: python-list@python.org
Sent: Wednesday, October 1, 2008 3:13:55 PM
Subject: Re: change line with columns when print

On Wed, 1 Oct 2008 04:43:34 -0700 (PDT)
sandric ionut [EMAIL PROTECTED] wrote:
 
 
 Hello:
 I have a text file that looks like:
 0 23
 1 342
 3 31
 and I want to read the file and print it out like:
 0 1 3
 23 342 31
 
 How can I do this?

Probably tons of ways.  Here's one with no input checking.

L = [x.strip().split() for x in open(infile) if x]
for i in range(2):
  print ' '.join([x[i] for x in L])

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED]        |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212    (DoD#0082)    (eNTP)  |  what's for dinner.



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

PyCon 2009 (US) - Call for Tutorials

2008-10-01 Thread Greg Lindstrom
The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
pre-conference days devoted to tutorials on Wednesday March 25  Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at 
http://us.pycon.org/2009/tutorials/proposals/.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact [EMAIL PROTECTED]

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
--
http://mail.python.org/mailman/listinfo/python-list

Re: Tix: Windows XP: Problem - how to stop root window from popping up with Tix

2008-10-01 Thread Scott David Daniels

Lie Ryan wrote:

On Wed, 01 Oct 2008 11:33:59 +0100, dudeja.rajat wrote:
Please suggest how can I suppress the root window 
The root window is the main window, not the DOS box. I think in windows, 
you should use pythonw.exe or something to open the python script so not 
to open a dos box.


And you can accomplish this as a clicky by renaming your program from
someprog.py to someprog.pyw.

--Scott David Daniels
[EMAIL PROTECTED]

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


Re: IDLE doesn't run on OSX 10.3.9

2008-10-01 Thread thomascribbs
Just did a new install of Tcl/tk from activestate.com and IDLE still
not working...

-Tom




On Sep 30, 1:15 pm, Kevin Walzer [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Just installed Python 2.5.2 on a PowerPC G4 running OSX 10.3.9 and
  when clicking on the IDLE icon  in the MacPython 2.5 folder nothing
  happens, program doesn't execute...

  I've uninstalled, reinstalled over again...

  I friend of mine just installed the same 2.5.2 download from the
  Python.org website on OSX 10.4.11 and all went fine...but shouldn't it
  install on 10.3.9 as well?

  Anyone have any ideas?  Thanks.
  -Tom

 Do you have Tcl/Tk installed? It doesn't come on 10.3.9 by default.

 --
 Kevin Walzer
 Code by Kevinhttp://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


text file

2008-10-01 Thread yqyq22
HI all,
i have some problem with the code belove, i have a list of servers in
a textfile (elencopc.txt) i would to retrieve informations via WMI
( cicle for ), but i don't understand if the code is correct:

import win32com.client
import string
import sys
listserver = open('c:\\elencopc.txt','r')
objWMIService = win32com.client.Dispatch(WbemScripting.SWbemLocator)
objSWbemServices = objWMIService.ConnectServer(listserver,root
\cimv2)
colItems = objSWbemServices.ExecQuery(Select * from
Win32_QuickFixEngineering)
for objItem in colItems:
print Caption: , objItem.Caption
print Description: , objItem.Description
print Fix Comments: , objItem.FixComments
print HotFix ID: , objItem.HotFixID
print Install Date: , objItem.InstallDate
print Installed By: , objItem.InstalledBy
print Installed On: , objItem.InstalledOn
print Name: , objItem.Name
print Service Pack In Effect: , objItem.ServicePackInEffect
print Status: , objItem.Status

I receive the error :
ile C:\Python25\Lib\site-packages\win32com\client\dynamic.py, line
258, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator',
'The RPC server is unavailable. ', None, 0, -2147023174), None)

MY big dubt is if the code is correct... because if i use vbscript all
works fine..
thanks a lot in advance
--
http://mail.python.org/mailman/listinfo/python-list


Re: text file

2008-10-01 Thread yqyq22
On Oct 1, 4:03 pm, [EMAIL PROTECTED] wrote:
 HI all,
 i have some problem with the code belove, i have a list of servers in
 a textfile (elencopc.txt) i would to retrieve informations via WMI
 ( cicle for ), but i don't understand if the code is correct:

 import win32com.client
 import string
 import sys
 listserver = open('c:\\elencopc.txt','r')
 objWMIService = win32com.client.Dispatch(WbemScripting.SWbemLocator)
 objSWbemServices = objWMIService.ConnectServer(listserver,root
 \cimv2)
 colItems = objSWbemServices.ExecQuery(Select * from
 Win32_QuickFixEngineering)
 for objItem in colItems:
     print Caption: , objItem.Caption
     print Description: , objItem.Description
     print Fix Comments: , objItem.FixComments
     print HotFix ID: , objItem.HotFixID
     print Install Date: , objItem.InstallDate
     print Installed By: , objItem.InstalledBy
     print Installed On: , objItem.InstalledOn
     print Name: , objItem.Name
     print Service Pack In Effect: , objItem.ServicePackInEffect
     print Status: , objItem.Status

 I receive the error :
 ile C:\Python25\Lib\site-packages\win32com\client\dynamic.py, line
 258, in _ApplyTypes_
     result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
 retType, argTypes) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator',
 'The RPC server is unavailable. ', None, 0, -2147023174), None)

 MY big dubt is if the code is correct... because if i use vbscript all
 works fine..
 thanks a lot in advance

My problem is how to translate this vbs in python:

Dim fso
Dim strComputer
Set fso = CreateObject(Scripting.FileSystemObject)
Set ElencoPC = fso.OpenTextFile(elencoPC.txt , 1, False)
Do Until ElencoPC.AtEndOfStream
strComputer = ElencoPC.ReadLine

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


Re: IDLE doesn't run on OSX 10.3.9

2008-10-01 Thread Kevin Walzer

[EMAIL PROTECTED] wrote:

Just did a new install of Tcl/tk from activestate.com and IDLE still
not working...

-Tom


Did you install Tcl/Tk 8.5? It won't work with the build of Python from 
python.org (it looks for 8.4).



--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zsi interoperability

2008-10-01 Thread Mailing List SVR
Il giorno mar, 16/09/2008 alle 08.31 +0200, Mailing List SVR ha scritto:
 Il giorno lun, 15/09/2008 alle 20.26 +0200, Marco Bizzarri ha scritto:
  On Mon, Sep 15, 2008 at 8:15 PM, Stefan Behnel [EMAIL PROTECTED] wrote:
   Mailing List SVR wrote:
   I have to implement a soap web services from wsdl, the server is
   developed using oracle, is zsi or some other python library for soap
   interoperable with oracle soa?
  
   No idea, but I'd definitely try soaplib before ZSI.
  
   Stefan
  
  I'm working on a project where I need to write a client for SOAP with
  Attachments; I can see ZSI does not support it; is soaplib any better?
  
 
 I don't need soap attachments, I have some images but are base64 encoded
 string, all other field are string, however my server require client
 certificate authentication,
 
 does soaplib or zsi work in this environment?
 
 is really strange that there isn't a standard and well manteined
 soap-1.2 implementation for python so we can talk without
 interoperability issue with axis2,metro,cxf,oracle,.net ecc.. :-(
 
 thanks
 Nicola

I can confirm that zsi (2.0) works fine in my environment:

- oracle soa, as soap server
- class generation from wsdl
- several complex types
- no soap attachments (I transfer image as base64 encoded string)

regards
Nicola

 
  Can you argument your suggestion a little more?
  
  Regards
  Marco
  
  
  
 
 --
 http://mail.python.org/mailman/listinfo/python-list

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


indirectly addressing vars in Python

2008-10-01 Thread Ross
Forgive my newbieness - I want to refer to some variables and indirectly 
 alter them.  Not sure if this is as easy in Python as it is in C.


Say I have three vars: oats, corn, barley

I add them to a list: myList[{oats}, {peas}, {barley}]

Then I want to past that list around and alter one of those values. 
That is I want to increment the value of corn:


myList[1] = myList[1] + 1

Is there some means to do that?.   Here's my little session trying to 
figure this out:


 oats = 1
 peas = 6
 myList=[]
 myList
[]
 myList.append(oats)
 myList
[1]
 myList.append(peas)
 myList
[1, 6]
 myList[1]= myList[1]+1
 myList
[1, 7]
 peas
6


So I don't seem to change the value of peas as I wished.  I'm passing 
the values of the vars into the list, not the vars themselves, as I 
would like.


Your guidance appreciated...

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


Peek inside iterator (is there a PEP about this?)

2008-10-01 Thread Luis Zarrabeitia

Hi there.

For most use cases I think about, the iterator protocol is more than enough. 
However, on a few cases, I've needed some ugly hacks.

Ex 1:

a = iter([1,2,3,4,5]) # assume you got the iterator from a function and
b = iter([1,2,3]) # these two are just examples.

then,

zip(a,b)

has a different side effect from

zip(b,a)

After the excecution, in the first case, iterator a contains just [5], on the 
second, it contains [4,5]. I think the second one is correct (the 5 was never 
used, after all). I tried to implement my 'own' zip, but there is no way to 
know the length of the iterator (obviously), and there is also no way 
to 'rewind' a value after calling 'next'.

Ex 2:

Will this iterator yield any value? Like with most iterables, a construct

if iterator:
   # do something

would be a very convenient thing to have, instead of wrapping a 'next' call on 
a try...except and consuming the first item.

Ex 3:

if any(iterator):
   # do something ... but the first true value was already consumed and 
   # cannot be reused. Any cannot peek inside the iterator without 
   # consuming the value.

Instead,

i1, i2 = tee(iterator)
if any(i1):
   # do something with i2

Question/Proposal:

Has there been any PEP regarding the problem of 'peeking' inside an iterator? 
Knowing if the iteration will end or not, and/or accessing the next value, 
without consuming it? Is there any (simple, elegant) way around it?

Cheers,

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python script for tracert

2008-10-01 Thread Thomas Guettler

Hi,

I wrote small python only script for tcptraceroute some time ago.
This works without a subprocess:

http://www.thomas-guettler.de/scripts/tcptraceroute.py.txt

Gabriel Genellina schrieb:
En Tue, 30 Sep 2008 03:53:21 -0300, cindy jones [EMAIL PROTECTED] 
escribió:


Hello.. I'm trying to do a scripting for tracert  in windows using 
python...

I'm using popen(), but it displays only after the tracert is completed. i
want the results to be displayed for every route.

can anyone help me in this..


Use the subprocess module:

import subprocess
host = 'www.microsoft.com'
p = subprocess.Popen([tracert, '-d', '-w', '100', host], 
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

while True:
line = p.stdout.readline()
if not line: break
print '--',line,
p.wait()




--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: Texas Python Regional Unconference Reminders

2008-10-01 Thread Travis E. Oliphant

Travis Vaught wrote:

Greetings,

The Texas Python Regional Unconference is coming up this weekend 
(October 4-5) and I wanted to send out some more details of the 
meeting.  The web page for the meeting is here:


http://www.scipy.org/TXUncon2008

The meeting is _absolutely free_, so please add yourself to the 
Attendees page if you're able to make it.  Also, if you're planning to 
attend, please send me the following information (to 
[EMAIL PROTECTED]) so I can request wireless access for you during 
the meeting:


 - Full Name
 - Phone or email
 - Address
 - Affiliation


Travis E. Oliphant
1-512-826-7480
515 Congress Ave, Suite 2100
Enthought, Inc.

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


Re: indirectly addressing vars in Python

2008-10-01 Thread Jeremy Sanders
Ross wrote:

   myList[1]= myList[1]+1

The problem is this makes myList[1] point to a new integer, and not the one
that peas points to.

Python 2.5.1 (r251:54863, Jul 10 2008, 17:25:56)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type help, copyright, credits or license for more information.
 oats=[1]
 peas=[6]
 mylist = [oats, peas]
 mylist[1][0] = mylist[1][0]+1
 mylist
[[1], [7]]
 peas
[7]

This is because integers are immutable, but lists are mutable.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Thomas Guettler

Phillip B Oldham schrieb:

On Oct 1, 9:25 am, Lie Ryan [EMAIL PROTECTED] wrote:

Most GUI package use event-driven model (e.g. Tkinter).


I've noticed that. I'm thinking more for a web environment (instead of
MVC) or as a HTTP server. I know Twisted has TwistedWeb, but I'm
looking for alternatives.


Please explain what you want to do. Maybe the spread toolkit
can help you:

http://www.spread.org/index.html

HTH,
  Thomas


--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: indirectly addressing vars in Python

2008-10-01 Thread Grant Edwards
On 2008-10-01, Ross [EMAIL PROTECTED] wrote:

 Forgive my newbieness - I want to refer to some variables and
 indirectly alter them.  Not sure if this is as easy in Python
 as it is in C.

Python doesn't have variables.  It has names bound to objects.
When you do an assignment, that binds (or rebinds) a name to an
object.  There is no such thing as a C-like variable (a named
region of memory with a fixed location into which you can write
different values).

Some objects (e.g. lists, dictionaries) are mutable (you can
change their value or contents), some objects (e.g. strings,
integers, floats) are not mutable.

 Say I have three vars: oats, corn, barley

 I add them to a list: myList[{oats}, {peas}, {barley}]

 Then I want to past that list around and alter one of those
 values.  That is I want to increment the value of corn:

 myList[1] = myList[1] + 1

 Is there some means to do that?.  Here's my little session
 trying to figure this out:

  oats = 1
  peas = 6

Those two lines created two integer objects with values 1 and 6
and bound the names oats and peas to those two objects.

  myList=[]
  myList
 []
  myList.append(oats)

That line finds the object to which the name oats is
currently bound and appends that object to the list.

  myList
 [1]
  myList.append(peas)

Likewise for the object to which the name peas is currently
bound.

  myList
 [1, 6]
  myList[1]= myList[1]+1

That line creates a new integer object (whose value happens to
be 7) and replaces the object at position 1 in the list with
the new object.

  myList
 [1, 7]
  peas
 6
 

 So I don't seem to change the value of peas as I wished.

Correct.  The name peas is still bound to the same object it
was before 

 I'm passing the values of the vars into the list, not the vars
 themselves, as I would like.

There are no vars as the word is used in the context of C
programming.  Just names and objects.

Here's an article explaining it:

http://rg03.wordpress.com/2007/04/21/semantics-of-python-variable-names-from-a-c-perspective/

A couple other good references:

http://starship.python.net/crew/mwh/hacks/objectthink.html
http://effbot.org/zone/python-objects.htm

-- 
Grant Edwards   grante Yow! What GOOD is a
  at   CARDBOARD suitcase ANYWAY?
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: indirectly addressing vars in Python

2008-10-01 Thread Chris Rebert
On Wed, Oct 1, 2008 at 7:53 AM, Ross [EMAIL PROTECTED] wrote:
 Forgive my newbieness - I want to refer to some variables and indirectly
  alter them.  Not sure if this is as easy in Python as it is in C.

 Say I have three vars: oats, corn, barley

 I add them to a list: myList[{oats}, {peas}, {barley}]

You mean:
myList = [oats, peas, barley]

And you're not adding *variables* to a list, you're adding *values* to
the list. The list elements (and the Python runtime) have *no idea*
what variables they are/were bound to.


 Then I want to past that list around and alter one of those values. That is
 I want to increment the value of corn:

 myList[1] = myList[1] + 1

This won't do what you're expecting. Integers in Python are immutable,
so instead of changing the value of 'corn', you're calculating a new
int object and overwriting the first element of the list with it.


 Is there some means to do that?.   Here's my little session trying to figure
 this out:

 oats = 1
 peas = 6
 myList=[]
 myList
 []
 myList.append(oats)
 myList
 [1]
 myList.append(peas)
 myList
 [1, 6]
 myList[1]= myList[1]+1
 myList
 [1, 7]
 peas
 6


 So I don't seem to change the value of peas as I wished.  I'm passing the
 values of the vars into the list, not the vars themselves, as I would like.

 Your guidance appreciated...

Python uses *call-by-object*, not call-by-value or call-by-reference
semantics, so unlike C/C++ but like Java you can't make a reference
to a variable and use that to non-locally rebind the variable to a new
value. To do what you want, you need to create a mutable value that
can be updated. You could code a MutableInt class wrapping 'int', or
you could use a dictionary to hold the values and then always refer to
the values using the dictionary. There are a few other ways to do it.

Hope that elucidates it for you somewhat. Then again I am a little
short on sleep :)

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com


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

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


Re: How to emit UTF-8 from console mode?

2008-10-01 Thread Siegfried Heintze

Make sure you are using the Lucida Console font for the cmd.exe window and
type the commands:

chcp 1251
python -c print ''.join(unichr(i) for i in range(0x410,0x431))

Output:

?

Wowa! I was not aware of that chcp command! Thanks! How could I do that 
chcp 1251 programatically?

The code was a little confusing because those two apostrophes look like a 
double quote!

But what are we doing here? Can you convince me that we are emitting UTF-8? 
I need UTF-8 because I need to experiment with some OS function calls that 
give me UTF-16 and I need to emit UTF-16 or UTF-8.

I think part of the problem is that Lucida Console is not as capable as 
Arial Unicode MS or the fonts used by urxvt-X.

Thanks,
Siegfried


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


Re: change line with columns when print

2008-10-01 Thread MRAB
On Oct 1, 1:13 pm, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote:
 On Wed, 1 Oct 2008 04:43:34 -0700 (PDT)

 sandric ionut [EMAIL PROTECTED] wrote:

  Hello:
  I have a text file that looks like:
  0 23
  1 342
  3 31
  and I want to read the file and print it out like:
  0 1 3
  23 342 31

  How can I do this?

 Probably tons of ways.  Here's one with no input checking.

 L = [x.strip().split() for x in open(infile) if x]
 for i in range(2):
   print ' '.join([x[i] for x in L])

Here's another way:

rows = [line.strip().split() for line in open(infile) if line]
columns = zip(*rows)
for col in columns:
print  .join(col)

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


How to give a global variable to a function which is in a module?

2008-10-01 Thread Kurda Yon
Hi,

I would like to declare a global variable, which is seen to a
particular function. If I do as the following it works:

x = 1
def test():
  global x
  print x
  return 1

However, it does not helps since my function is in a separate file. In
other words I have a main program which has the following structure:

from test import test
x = 1
y = test()

and I have a test.py file which contains the test function:
def test():
  global x
  print x
  return 1

In this case the test does not see the global variable x. How can I
make the x to be visible?

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


Re: indirectly addressing vars in Python

2008-10-01 Thread Bruno Desthuilliers

Chris Rebert a écrit :

On Wed, Oct 1, 2008 at 7:53 AM, Ross [EMAIL PROTECTED] wrote:

Forgive my newbieness - I want to refer to some variables and indirectly
 alter them.  Not sure if this is as easy in Python as it is in C.

Say I have three vars: oats, corn, barley

I add them to a list: myList[{oats}, {peas}, {barley}]


You mean:
myList = [oats, peas, barley]

And you're not adding *variables* to a list, you're adding *values* 


s/values/references to objects/, actually

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

Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Phillip B Oldham
On Oct 1, 4:12 pm, Thomas Guettler [EMAIL PROTECTED] wrote:
 Please explain what you want to do.

I'm primarily looking for alternatives to MVC frameworks for web
development, particularly SAAS. I've looked around, and some
whitepapers suggest that event-based frameworks often perform better
than MVC. Since I'm looking at SAAS, having a view is pretty
pointless since I'll either be using Thrift, returning simple HTTP
headers, or returning some sort of JSON/YAML/XML content (possibly
based on accept headers).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to give a global variable to a function which is in a module?

2008-10-01 Thread Bruno Desthuilliers

Kurda Yon a écrit :

Hi,

I would like to declare a global variable, which is seen to a
particular function.


First point : there's no real 'global' scope in Python. 'global' really 
means 'module-level'.


Second point : globals are Bad(tm) anyway.


If I do as the following it works:

x = 1
def test():
  global x
  print x
  return 1


You don't even need the global statement here, since you're not 
rebinding x within the function.



However, it does not helps since my function is in a separate file. In
other words I have a main program which has the following structure:

from test import test
x = 1
y = test()


That's obviously something you *don't* want - functions depending on 
global variables that can be changed from anywhere. Ok, like any golden 
rule, this one is meant to be bypassed sometimes, but unless you fully 
understand why this is 99 times out of 100 a BadThing(tm) to do, just 
don't do it.


for the record, this would work:

import test
test.x = 42
y = test()

But once again : unless you really know what you're doing and why you're 
doing it, just don't do it.



and I have a test.py file which contains the test function:
def test():
  global x
  print x
  return 1

In this case the test does not see the global variable x. How can I
make the x to be visible?


Pass it to the function.

# test.py
def test(x):
   print x
   return x + 42

# main.py
from test import test
y = test(2)

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


Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Bruno Desthuilliers

Phillip B Oldham a écrit :

On Oct 1, 4:12 pm, Thomas Guettler [EMAIL PROTECTED] wrote:

Please explain what you want to do.


I'm primarily looking for alternatives to MVC frameworks for web
development, particularly SAAS. I've looked around, and some
whitepapers suggest that event-based frameworks often perform better
than MVC. Since I'm looking at SAAS, having a view is pretty
pointless since I'll either be using Thrift, returning simple HTTP
headers, or returning some sort of JSON/YAML/XML content (possibly
based on accept headers).


view doesn't imply (x)html - any valid HTTP response is ok. The whole 
point of decoupling controler from view (in web MVC) is to allow the 
same controler to return different views.

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


Re: indirectly addressing vars in Python

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 10:53:08 -0400, Ross wrote:

 Forgive my newbieness - I want to refer to some variables and indirectly
   alter them.  Not sure if this is as easy in Python as it is in C.
 
 Say I have three vars: oats, corn, barley
 
 I add them to a list: myList[{oats}, {peas}, {barley}]
 
 Then I want to past that list around and alter one of those values. That
 is I want to increment the value of corn:
 
 myList[1] = myList[1] + 1
 
 Is there some means to do that?.   Here's my little session trying to
 figure this out:
 
   oats = 1
   peas = 6
   myList=[]
   myList
 []
   myList.append(oats)
   myList
 [1]
   myList.append(peas)
   myList
 [1, 6]
   myList[1]= myList[1]+1
   myList
 [1, 7]
   peas
 6
  
  
 So I don't seem to change the value of peas as I wished.  I'm passing
 the values of the vars into the list, not the vars themselves, as I
 would like.
 
 Your guidance appreciated...
 
 Ross.

Short answer: Python is not C.

Long answer: In python, integers are immutable (they do not change), i.e. 
if you do:
a = 1
b = 2
c = a + b
 
a + b creates a new integer object that has the value 3 and assign it to c

Other examples of immutable values are: number types, string, tuple, etc.

In python, variable is usually called name. The concept of variable 
and name is slightly different.

In C, a variable contains an object. In python, a name contains a pointer 
to an object. (the term pointer is used a bit loosely here)

In python, a list is a list of pointers to objects.

i.e.:

   |-- Hello World
myList |-- 1
   |-- 6

when you do, for example, myList[2] + 1
what you're doing is:
1. fetch the value of myList[2] (i.e. 6)
2. do an arithmetic addition of 6 + 1
3. create a new integer object with value 7
4. bind myList[2] to that new integer object (_new integer object_ since 
integer is immutable, you cannot change its value[1])

in short, pea is left intact since pea points to integer object 6.

beware though, that things are different if myList[2] is a mutable value 
instead and the operation is an in-place operation, e.g. list.sort

 a = [1, 2]
 b = [3, 2]
 myList.append(a)
 myList.append(b)
 myList[1].sort()
 myList
[[1, 2], [2, 3]]
 b
[2, 3]

in this case a, b is mutable object, so:
myList.append(x) binds myList to the list object pointed by x
myList[1].sort() is an in-place sort to the list object [3, 2] (i.e. it 
mutates the list [3, 2] instead of creating a new list[1]).

in this case:

myList |-- [1, 2]
   |-- [3, 2]

myList[1].sort(), being an in-place sort, modifies the list object [3, 2] 
in-place. Since b points to the same list object, b's list is changed too.

To summarize, you don't usually use that line of thinking in python. If 
you really insists, though is not pythonic (and is really absurd anyway), 
you may use this:

 a = [1]
 b = [2]
 myList.append(a)
 myList.append(b)
 myList[1][0] = myList[1][0] + 1
 myList
[[1], [2]]
 b
[3]

[1] Well, not always though, in CPython (the standard python reference 
implementation), small immutable values are cached as speed optimization. 
This is a safe operation, except for identity testing. But that doesn't 
matter much, since identity testing of immutable is moot.
[2] If you want a sorting operation that returns a new list, use sorted
(list)

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


string concatenate

2008-10-01 Thread sandric ionut
Hi:

I have the following situation:
    nameAll = []
    for i in range(1,10,1):
    n = name + str([i])
    nameAll += n
    print nameAll

I get:

['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2', ']', 'n', 
'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[', '4', ']', 'n', 'a', 'm', 
'e', '[', '5', ']', 'n', 'a', 'm', 'e', '[', '6', ']', 'n', 'a', 'm', 'e', '[', 
'7', ']', 'n', 'a', 'm', 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']

but I would like to have it as:

name1 name2 name3 ...name10

How can I do it?

Thank you,

Ionut


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

Re: string concatenate

2008-10-01 Thread Tommy Grav


On Oct 1, 2008, at 12:41 PM, sandric ionut wrote:


Hi:

I have the following situation:
nameAll = []
for i in range(1,10,1):
n = name + str([i])
nameAll += n
print nameAll

I get:

['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2',  
']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[',  
'4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e',  
'[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm',  
'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']


but I would like to have it as:

name1 name2 name3 ...name10

How can I do it?

Thank you,

Ionut


 nameAll = []
 for i in xrange(1,10,1):
n = name + str(i)
nameAll.append(n)
 print nameAll
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']


list.append() is the right tool for adding new elements to a list.

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


Fwd: string concatenate

2008-10-01 Thread Tommy Grav

On Oct 1, 2008, at 12:41 PM, sandric ionut wrote:


Hi:

I have the following situation:
   nameAll = []
   for i in range(1,10,1):
   n = name + str([i])
   nameAll += n
   print nameAll

I get:

['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2',  
']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[',  
'4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e',  
'[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm',  
'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']


but I would like to have it as:

name1 name2 name3 ...name10

How can I do it?

Thank you,

Ionut


 nameAll = []
 for i in xrange(1,10,1):
n = name + str(i)
nameAll.append(n)
 print nameAll
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']


list.append() is the right tool for adding new elements to a list.

Cheers
 Tommy

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


Re: text file

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 07:19:44 -0700, yqyq22 wrote:
 My problem is how to translate this vbs in python:
 
 Dim fso
 Dim strComputer
 Set fso = CreateObject(Scripting.FileSystemObject) Set ElencoPC =
 fso.OpenTextFile(elencoPC.txt , 1, False) Do Until
 ElencoPC.AtEndOfStream
 strComputer = ElencoPC.ReadLine
 
 thanks

try this:

fso = open('elencoPC.txt', 'r')
for line in f:
strComputer = line


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


Re: text file

2008-10-01 Thread Tim Golden

[EMAIL PROTECTED] wrote:

HI all,
i have some problem with the code belove, i have a list of servers in
a textfile (elencopc.txt) i would to retrieve informations via WMI
( cicle for ), but i don't understand if the code is correct:



Try this, using http://timgolden.me.uk/python/wmi.html :

code
import wmi

#
# For the test to work
#
open (elencopc.txt, w).write (localhost)

for server in open (elencopc.txt).read ().splitlines ():
  c = wmi.WMI (server)
  print SERVER:, server
  for item in c.Win32_QuickFixEngineering ():
print item # or print item.Caption, etc.
  print
  print

/code

If you get RPC Server unavailable, it usually means that
the WMI service isn't running on that machine. Usually.

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


Re: string concatenate

2008-10-01 Thread D'Arcy J.M. Cain
On Wed, 1 Oct 2008 09:41:57 -0700 (PDT)
sandric ionut [EMAIL PROTECTED] wrote:
 Hi:
 
 I have the following situation:
     nameAll = []
     for i in range(1,10,1):
     n = name + str([i])
     nameAll += n
     print nameAll
 
 I get:
 
 ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2', ']', 'n', 
 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[', '4', ']', 'n', 'a', 
 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e', '[', '6', ']', 'n', 'a', 'm', 
 'e', '[', '7', ']', 'n', 'a', 'm', 'e', '[', '8', ']', 'n', 'a', 'm', 'e', 
 '[', '9', ']']
 
 but I would like to have it as:
 
 name1 name2 name3 ...name10

nameAll = [name%d % x for x in range(1,10,1)]

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


decent interactive python shell on MS Windows?

2008-10-01 Thread james . kirin39
Hi everyone,

After having used Python on Linux for some time, I now have to do
Python coding on Windows. I am big fan of the interactive Python shell
to test, eg, regexps.

Is there an interactive Python shell on Windows that supports:

- easy copy-pasting to/from an editor? (as opposed to the cumbersome
mark, copy and then paste sequence that any terminal on Windows
seems forced to adopt)

- readline-like command history (up/down for previous/next command,
Ctr-R for searching, etc) ?

I have tried the python.org shell (difficult copy-pasting),
ActiveState's (no readline command history) and iPython (difficult
copy-pasting). Do you know of any decent interactive python shell on
Windows that comes close to the friendliness of the standard one on
Linux?

Thanks in advance

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


Re: Fwd: string concatenate

2008-10-01 Thread sandric ionut
Thank you:
 
but I would like to have them not like:
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']
 
but like
name1 name2 name3 name4 name5 name6 name7 name8 name9
 
Is it possible?
 
Ionut



- Original Message 
From: Tommy Grav [EMAIL PROTECTED]
To: Python List python-list@python.org
Sent: Wednesday, October 1, 2008 7:50:25 PM
Subject: Fwd: string concatenate

On Oct 1, 2008, at 12:41 PM, sandric ionut wrote:

 Hi:

 I have the following situation:
    nameAll = []
    for i in range(1,10,1):
        n = name + str([i])
        nameAll += n
    print nameAll

 I get:

 ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2',  
 ']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[',  
 '4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e',  
 '[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm',  
 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']

 but I would like to have it as:

 name1 name2 name3 ...name10

 How can I do it?

 Thank you,

 Ionut

 nameAll = []
 for i in xrange(1,10,1):
    n = name + str(i)
    nameAll.append(n)
 print nameAll
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']

list.append() is the right tool for adding new elements to a list.

Cheers
  Tommy

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



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

Re: decent interactive python shell on MS Windows?

2008-10-01 Thread Tim Golden

[EMAIL PROTECTED] wrote:

Is there an interactive Python shell on Windows that supports:

- easy copy-pasting to/from an editor? (as opposed to the cumbersome
mark, copy and then paste sequence that any terminal on Windows
seems forced to adopt)

- readline-like command history (up/down for previous/next command,
Ctr-R for searching, etc) ?



Yes. The Windows command shell does all these
things. To do use mouse selecting and right-click
pasting, go to the System Menu on your console and select
Properties  Options  Quick Edit Mode. You can then
use the mouse to select an area (as though on notepad)
and Enter to select. Likewise, already-selected text
can be right-click pasted straight in. I use this whenever
I'm posting code-samples to this list: I work them up in
a console, select-copy them out, paste them into an email,
then select-copy them back and paste into a new console
to make sure I haven't made any assumptions.

Check out the use of up/down arrows as usual, plus
F7 for history and F8 for history-completion.

It's not everyone's cup of tea but I've been using
it happily for years.

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


Re: decent interactive python shell on MS Windows?

2008-10-01 Thread Gary Herron
[EMAIL PROTECTED] wrote:
 Hi everyone,

 After having used Python on Linux for some time, I now have to do
 Python coding on Windows. I am big fan of the interactive Python shell
 to test, eg, regexps.

 Is there an interactive Python shell on Windows that supports:

 - easy copy-pasting to/from an editor? (as opposed to the cumbersome
 mark, copy and then paste sequence that any terminal on Windows
 seems forced to adopt)

 - readline-like command history (up/down for previous/next command,
 Ctr-R for searching, etc) ?

 I have tried the python.org shell (difficult copy-pasting),
 ActiveState's (no readline command history) and iPython (difficult
 copy-pasting). Do you know of any decent interactive python shell on
 Windows that comes close to the friendliness of the standard one on
 Linux?

 Thanks in advance

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

I use a window's port of
rxvt
running cygwin's bash shell.

Bash gives you all the command-history readline like capabilities, and
the rxvt window implements all the cut/past mouse actions you're used to
from Linux/Unix terminal windows.

Together, these make windows feel almost civilized.

Happy Googling for them,
Gary Herron



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


Re: Fwd: string concatenate

2008-10-01 Thread D'Arcy J.M. Cain
On Wed, 1 Oct 2008 10:03:50 -0700 (PDT)
sandric ionut [EMAIL PROTECTED] wrote:
 Thank you:
  
 but I would like to have them not like:
 ['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
 'name8', 'name9']
  
 but like
 name1 name2 name3 name4 name5 name6 name7 name8 name9

Slight mod from my previous suggestion then.

nameAll = ' '.join([name%d % x for x in range(1,10,1)])

Have you gone through the tutorial yet?

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Peek inside iterator (is there a PEP about this?)

2008-10-01 Thread Peter Otten
Luis Zarrabeitia wrote:

 For most use cases I think about, the iterator protocol is more than
 enough. However, on a few cases, I've needed some ugly hacks.
 
 Ex 1:
 
 a = iter([1,2,3,4,5]) # assume you got the iterator from a function and
 b = iter([1,2,3]) # these two are just examples.

Can you provide a concrete use case?
 
 then,
 
 zip(a,b)
 
 has a different side effect from
 
 zip(b,a)
 
 After the excecution, in the first case, iterator a contains just [5], on
 the second, it contains [4,5]. I think the second one is correct (the 5
 was never used, after all). I tried to implement my 'own' zip, but there
 is no way to know the length of the iterator (obviously), and there is
 also no way to 'rewind' a value after calling 'next'.
 
 Ex 2:
 
 Will this iterator yield any value? Like with most iterables, a construct
 
 if iterator:
# do something

I don't think this has a chance. By adding a __len__ to some iterators R.
Hettinger once managed to break GvR's code. The BDFL was not amused.
 
 would be a very convenient thing to have, instead of wrapping a 'next'
 call on a try...except and consuming the first item.
 
 Ex 3:
 
 if any(iterator):
# do something ... but the first true value was already consumed and
# cannot be reused. Any cannot peek inside the iterator without
# consuming the value.

for item in iflter(bool, iterator):
   # do something
   break

is not that bad.

 Instead,
 
 i1, i2 = tee(iterator)
 if any(i1):
# do something with i2
 
 Question/Proposal:
 
 Has there been any PEP regarding the problem of 'peeking' inside an
 iterator? Knowing if the iteration will end or not, and/or accessing the
 next value, without consuming it? Is there any (simple, elegant) way
 around it?

Personally I think that Python's choice of EAFP over LBYL is a good one, but
one that cannot easily be reconciled with having peekable iterators. If I
were in charge I'd rather simplify the iterator protocol (scrap send() and
yield expressions) than making it more complex.

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


Re: Peek inside iterator (is there a PEP about this?)

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 10:46:33 -0400, Luis Zarrabeitia wrote:

 Hi there.
 
 For most use cases I think about, the iterator protocol is more than
 enough. However, on a few cases, I've needed some ugly hacks.
 
 Ex 1:
 
 a = iter([1,2,3,4,5]) # assume you got the iterator from a function and
 b = iter([1,2,3]) # these two are just examples.
 
 then,
 
 zip(a,b)
 
 has a different side effect from
 
 zip(b,a)
 
 After the excecution, in the first case, iterator a contains just [5],
 on the second, it contains [4,5]. I think the second one is correct (the
 5 was never used, after all). I tried to implement my 'own' zip, but
 there is no way to know the length of the iterator (obviously), and
 there is also no way to 'rewind' a value after calling 'next'.
 
 Ex 2:
 
 Will this iterator yield any value? Like with most iterables, a
 construct
 
 if iterator:
# do something
 
 would be a very convenient thing to have, instead of wrapping a 'next'
 call on a try...except and consuming the first item.
 
 Ex 3:
 
 if any(iterator):
# do something ... but the first true value was already consumed and
# cannot be reused. Any cannot peek inside the iterator without #
consuming the value.
 
 Instead,
 
 i1, i2 = tee(iterator)
 if any(i1):
# do something with i2
 
 Question/Proposal:
 
 Has there been any PEP regarding the problem of 'peeking' inside an
 iterator? 

No (or I'm not aware of any). Why? Because for some iterable, it is not 
possible to know in advance its length (video data stream, for example), 
or whether it'd ever end (the digits of pi).

Second, in python, iterator is a use-once object, it is not designed to 
be reused. Some languages, especially the purely functional ones, allow 
multiple use of iterator because they guarantee immutability, python 
allows mutable object, and is unable to provide that.

 Knowing if the iteration will end or not, and/or accessing the
 next value, without consuming it? 

No, it is not possible to do that for some iterators. For example, this 
code:

import time
class Iterable(object):
def __iter__(self):
return self
def next(self):
return time.time()

if you peeked the iterator in advance, the result would be different 
compared to the result when you actually need it. 

 Is there any (simple, elegant) way
 around it?

Simple, but probably not that elegant, if you need such a fine control, 
use while loop.

 Cheers,
 
 --
 Luis Zarrabeitia (aka Kyrie)
 Fac. de Matemática y Computación, UH.
 http://profesores.matcom.uh.cu/~kyrie


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

Re: Isolated environment for execfile

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 11:11:29 +, Igor Kaplan wrote:

 Hello python gurus.
 
   I got quite unusual problem and all my searches to find the answer on
   my
 own were not successful.
   Here is the scenario:
   I have the python program, let's call it script1.py, this program
   needs to
 execute another python script, let's call it script2.py.
   In script1.py I have the statement:
 execfile('script2.py')
   Everything is fine beside one thing. The script2.py is pretty big
   python
 program which does a lot of things and also while runs, it modifies many
 variables and module members, such for example as sys.path. So when
 script2.py exits all changes which it does are visible in my main
 program, script1.py. Even more, I need to execute script2.py in loop,
 several times during script1.py session. And all changes, which
 script2.py does just accumulate.
 
   I wander, is there any way to execute script2.py in it's own
   environment,
 so when script2.py exits, all modifications, which it is done in global
 modules are gone?
 Ideally I would love to have the following.
(snip)
   Thanks in advance.
 
Igor.

I smelled a really strong sign of bad code.

1. In python, functional style programming is very much preferred. In 
short, functional style programming requires that: a function never makes 
a side-effect (python doesn't enforce this[1] as python is not a pure 
functional language).

2. In any programming language, the use of global variable must be 
minimized, and modifying global is even more frowned upon.

Aside:
If you need an isolated environment, it is probably much better if you 
use class. Each instance of a class lives separately, independent to each 
other.

e.g.:
class Test(object):
def func(self, n):
self.n = n
a = Test()
b = Test()
a.func(10)
b.func(20)
print a.n # 10
print b.n # 20

[1] in fact, many built-in standard library do use side-effects, and OOP-
style programming (more appropriately Java-style OOP) relies heavily on 
side-effect.

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


Re: what does python -i use as input stream (stdin)?

2008-10-01 Thread Almar Klein
Hello again,
I wanted to give your solution a try, but got stuck.
The file that I want to replace the standard input with is a pseudo file
object with a custom read method. I have a hard time finding out how
to have a file descriptor (or fileno) associated with it.

I tried inheriting from the file class (using a dummy file on disk), and
then
overriding the read() and __init__() method. To test I used
os.read(my_file_no,1),
but it reads the contents of my dummy file rather than using my read method.
So obviously it does some low level stuff there...

Again I have the feeling this is impossible, but I thought that the last
time too :)

Almar

2008/9/30 Almar Klein [EMAIL PROTECTED]

 Wow,
 it's that easy...
 thanks!

 2008/9/29 Gabriel Genellina [EMAIL PROTECTED]

 En Fri, 26 Sep 2008 04:29:42 -0300, Almar Klein [EMAIL PROTECTED]
 escribió:

  I would still like to hear if anyone knows how I can change the input
 stream
 that
 is used when running python -i, but I would not be surprised if it is
 impossible...


 Sure you can. You have to replace the file descriptor 0, that is,
 standard input; sys.stdin reads from there. The standard way is to use
 os.dup2:

 c:\temptype foo.txt
 This line read from foo.txt


 c:\temptype redirect.py
 import os

 inp = open(foo.txt,r)
 os.dup2(inp.fileno(), 0)
 print raw_input-, raw_input()

 c:\temppython redirect.py
 raw_input- This line read from foo.txt

 This is not


 --
 Gabriel Genellina

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



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

Re: parse a normal textfile

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 14:09:09 +0200, Tino Wildenhain wrote:

 devi thapa wrote:
 hi all
  
I have one normal text file. I need to parse the file, that
 too in an associative way .
 suppose that below is the normal textfile
 
 name='adf'
 id  =1
 value=344
 
 
 there are many approaches to config files. But in your special example,
 it looks like a simplified mapping, so
 
 parsed=eval(dict(%s) % ,.join(line
   for line
   in file(textfile)
   if line.strip()
   )
  )
 
   parsed['name']
 'adf'
 
 but of course eval() is dangerous, so feel free to explore more then
 this one solution.
 
 Regards
 Tino

There is no need to use eval on that, you could just use:

f = open('file.conf')
conf = {}
for line in f:
key, value = line.split('=', 1)
conf[key] = value

a bit more obscure:

conf = dict(line.split('=', 1) for line in open('file.conf'))

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


ANN: eGenix mxODBC Connect Database Interface for Python 0.9.2 (beta)

2008-10-01 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
eGenix.com mxODBC Connect

  Database Interface for Python

   Version 0.9.2 (beta)


  Our new client-server product for connecting Python applications
 to relational databases - from all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-0.9.2-beta.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS
SQL Server, Oracle or DB2 that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please have a look at the product page:

http://www.egenix.com/products/python/mxODBCConnect/

* About Python:
Python is an object-oriented Open Source programming language which
runs on all modern platforms (http://www.python.org/). By integrating
ease-of-use, clarity in coding, enterprise application connectivity
and rapid application design, Python establishes an ideal programming
platform for todays IT challenges.

* About eGenix:
eGenix is a consulting and software product company focused on
providing professional quality services and products to Python
users and developers (http://www.egenix.com/).



NEWS

mxODBC Connect 0.9.2 is our second public beta release of the new
mxODBC Connect product.

It comes with improved documentation, enhanced SQL Server support
on Linux and now runs on Python 2.6 as well (in addition to
Python 2.3, 2.4 and 2.5).

*SPECIAL OFFER*

If you would like to participate in the beta as tester, please see
our beta program page:

http://www.egenix.com/products/python/mxODBCConnect/beta.html

In order to make participation in the beta program more interesting
for our users, we will be giving out *free discount coupons* to all
participants who report back bugs in the product.



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 01 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


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


Re: Event-driven framework (other than Twisted)?

2008-10-01 Thread Lie Ryan
On Wed, 01 Oct 2008 18:09:20 +0200, Bruno Desthuilliers wrote:

 Phillip B Oldham a écrit :
 On Oct 1, 4:12 pm, Thomas Guettler [EMAIL PROTECTED] wrote:
 Please explain what you want to do.
 
 I'm primarily looking for alternatives to MVC frameworks for web
 development, particularly SAAS. I've looked around, and some
 whitepapers suggest that event-based frameworks often perform better
 than MVC. Since I'm looking at SAAS, having a view is pretty
 pointless since I'll either be using Thrift, returning simple HTTP
 headers, or returning some sort of JSON/YAML/XML content (possibly
 based on accept headers).
 
 view doesn't imply (x)html - any valid HTTP response is ok. The whole
 point of decoupling controler from view (in web MVC) is to allow the
 same controler to return different views.

In fact, MVC and event-driven is two entirely different concept. You can 
have both, or none. It is, in the end, your choice which one to use or 
whether you want to use both or none.

Event-driven programming is a concept that your programs are entirely 
composed of function definition and binding that function definition to 
events. The rest is handled by a mainloop, which calls the appropriate 
functions when it receives something.

MVC is a separation of concern. In MVC code you want that there is a 
clear boundary between code that handles Model, View, and Controller, so 
it'd be easier to manage the code.

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

Re: problem with ImportError: No module named... and sockets

2008-10-01 Thread Daniel
On Sep 30, 5:49 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Tue, 30 Sep 2008 19:44:51 -0300, Daniel [EMAIL PROTECTED]  
 escribió:



  On Sep 30, 4:17 pm, Gabriel Genellina [EMAIL PROTECTED]
  wrote:
  En Tue, 30 Sep 2008 18:38:19 -0300, Daniel [EMAIL PROTECTED]  
  escribió:

   [BEGIN CODE]
   #!/usr/bin/python
   import SocketServer
   import os, sys
   newpath = os.path.normpath( os.path.join( __file__, ../../.. ))
   sys.path.insert(0, newpath)

   from pop.command.UpdateCommand import *
   import cPickle

   Traceback (most recent call last):
   [...]
   ImportError: No module named UpdateCommand

   I import the module at the top of the file server.py, but it doesn't
   throw the ImportError until it tries to unpickle.

  Notice that you don't import the UpdateCommand module - you import all  
  names defined inside it instead. It's not the same thing.
  Seehttp://effbot.org/zone/import-confusion.htm

  --
  Gabriel Genellina

  Thank you Gabriel,

  The class inside that module has the same name, UpdateCommand.  Since
  this is the object that was pickled, it should be available to the
  unpickle command.  I already understood the difference between import
  methods and I think I'm covered.  I did just try import
  pop.command.TesterUpdateCommand instead and I get the same error.

 (TesterUpdateCommand != UpdateCommand...)

 In your *pickling* code, just before pickling the object, see what you get  
  from this:

          cls = obj.__class__
          print cls.__module__
          print cls.__name__

 Suppose you get SomeModuleName and SomeClassName. Then, in your  
 *unpickling* environment, this must succeed:

          import SomeModuleName
          cls = SomeModuleName.SomeClassName

 If not, you should rearrange things (on both sides, probably) to make the  
 reference work. This is basically what pickle does.

 Looks like the module lives in a package - make sure you import the  
 *package* both when pickling and unpickling. The sys.path manipulation  
 looks suspicious.

 --
 Gabriel Genellina

This turned out to be a problem with PyScripter.  When I open the same
files in Komodo they work fine.

Sorry for the trouble.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >