ANN: Leo 4.4.6 beta 2 released

2008-01-16 Thread Edward K Ream
Leo 4.4.6 beta 2 is available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

Leo 4.4.6 fixes several recently reported bugs, all minor.

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.6:

- Fixes all known bugs.
- Added @auto importers for javascript and xml files.
- Added find-next-clone and toggle-sparse-move commands.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://leo.tigris.org/source/browse/leo/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html


Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html


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

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


ANN: cssutils 0.9.5a2

2008-01-16 Thread Christof Hoeke
what is it
--
A Python package to parse and build CSS Cascading Style Sheets.

main changes since 0.9.5a1
--
0.9.5a2 is a Bugfix release fixing a few minor issues

for full details for 0.9.5a2 see the relevant CHANGELOG: 
http://cssutils.googlecode.com/svn/tags/TAG_0.9.5a2/CHANGELOG.txt

A few (minor) non-backwards compatible changes have been made in 0.9.5, 
please see 
http://cssutils.googlecode.com/svn/tags/TAG_0.9.5a2/documentation/migrate.txt 
for migration help.


license
---
cssutils is published under the LGPL.

download

for download options for see http://cthedot.de/cssutils/

cssutils needs Python 2.4 or higher (tested with Python 2.5 on Vista only)


bug reports, comments, etc are very much appreciated!

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

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


Re: no pass-values calling?

2008-01-16 Thread Ben Finney
Christian Heimes [EMAIL PROTECTED] writes:

 Ben Finney wrote:
  The term reference is fine, since that's exactly how it works.
  One gets at an object via some reference, be it a name or some
  access into a container object. When an object has no more
  references to itself, it becomes a candidate for garbage
  collection. And so on.
 
 Thanks you, but I know exactly how Python works. I'm actually
 developing CPython and PythonDotNET.

Uh, okay. I didn't ask for you to flash your credentials, but if that
is significant to you, be my guest.

 Anyway your message doesn't help a newbie and it gives most
 certainly the wrong impression. You are using words that have a
 different meaning in other languages. If you explain Python w/o the
 words variable, pointer, reference or call-by-value you have a much
 better chance to explain it right. Trust me :)

I've done my share of explaining of Python to people, and found
reference to be exactly the right term to help the newbie understand
what's happening and what they should expect.

I agree with you on variable, pointer, and call-by-value. Those
don't describe how Python works, and thus only confuse the matter.
Thus I avoid them, and correct newbies who appear to be getting
confused because of those existing concepts.

-- 
 \I don't accept the currently fashionable assertion that any |
  `\   view is automatically as worthy of respect as any equal and |
_o__)opposite view.  -- Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: itertools.groupby

2008-01-16 Thread Paul Rubin
Tobiah [EMAIL PROTECTED] writes:
 I tried doing this with a simple example, but noticed
 that [].sort(func) passes two arguments to func, whereas
 the function expected by groupby() uses only one argument.

Use: [].sort(key=func)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import from question

2008-01-16 Thread Ben Finney
Tobiah [EMAIL PROTECTED] writes:

 This is a little surprising. So from mod import * really copies
 all of the scalars into new variables in the local namespace.

No. Nothing is copied. All the objects (remembering that in Python,
*everything* is an object) created by the code in module 'mod' are
given names in the current namespace.

 I always ASSumed that the two forms of import were equivalent, but
 that one form did away with the need to be explicit about the
 namespace: mod.thing Obviously this is far from the case.

Yes. In fact the main difference is in what namespace the module's
objects are made available.

-- 
 \  The way to build large Python applications is to componentize |
  `\  and loosely-couple the hell out of everything.  -- Aahz |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Generic string import like in strptime?

2008-01-16 Thread Andre
Hi there

Is there a function like strptime, which takes a string and converts it 
into an array depending on a format string I provide. Like:
 a = '3456\tblub-blib.0.9'
 b = '%d\t%s-%s.%f'
 c = mysticalfunction(a,b) 
 print c
[3456,'blub','blib',0.9]


Many thanks

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


Re: where do my python files go in linux?

2008-01-16 Thread Jorgen Bodde
Hi All,

Sorry for the late reply back, I had a busy weekend ... it seems there
is no clear way to do it and maybe that is why I was / am so confused.

Eventually I searched for *.py files, and like I said most apps seem
to install in /usr/share/{app} I believe that location is for data
only that is shared between users. But for simplicity's sake I put my
whole python application in there. It saves me setting a lot of paths
differently.

I made a symbolic link in /usr/bin that points to /usr/share/{app}/{app}.py

This all seems to work fine. When I am getting more experienced with
Debian / Ubuntu and linux overall, I will re-evaluate this and see if
I can improve it.

Thanks all for your answer,
- Jorgen

On Jan 14, 2008 4:30 PM, Nick Craig-Wood [EMAIL PROTECTED] wrote:
 Paul Boddie [EMAIL PROTECTED] wrote:
   On 14 Jan, 08:47, A.T.Hofkamp [EMAIL PROTECTED] wrote:
  
   Rather than re-inventing the wheel, please have a look at distutils:
   http://docs.python.org/lib/module-distutils.html
  
   It does most if not all of the things you want to do.
   If you want something more advanced, read about eggs.
 
   Although distutils does some of the work needed by the inquirer, it
   falls far short of what is needed to make a Debian package - that's
   why you have the new Debian Python policy and why the authors
   specifically refer to both distutils and setuptools in that document.

 It would be nice to have an equivalent to dh-make-perl which takes a
 CPAN module and makes a .deb directly.

   http://packages.debian.org/stable/devel/dh-make-perl

 What I usually do is

 python setup.py bdist_rpm

 Then use alien to convert the resulting .rpm into a .deb

 I don't think these create particularly policy compliant .debs but
 they are good enough for local usage.

   Meanwhile, even stdeb [1] doesn't appear to completely automate the
   production of Debian packages using distutils.

 Looks interesting though!

   [1] http://stdeb.python-hosting.com/

 --
 Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
 --

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

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


ANN: CaltrainPy 0.2

2008-01-16 Thread Heikki Toivonen
CaltrainPy is a Caltrain (http://caltrain.com/) schedule program and
library written in Python. It uses Tkinter for GUI.

What is new in version 0.2?

- AM/PM indicators
- train types
- can be used as a module to parse Caltrain schedule
- MIT License
- setup.py

Parsing of Caltrain schedule requires BeautifulSoup. The results can be
returned as Python, HTML or JSON (python-json required).

It is available on Cheeseshop, but unfortunately it does not seem to
work correctly if installed with easy_install. Downloading and
installing with:

python setup.py install

works ok.

Blog post with screenshot here:
http://www.heikkitoivonen.net/blog/2008/01/16/caltrainpy-02/

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


anti-spam policy for c.l.py?

2008-01-16 Thread _wolf
this list has been receiving increasing amounts of nasty OT spam
messages for some time. are there any plans to prevent such messages
from appearing on the list or to purge them retrospectively?

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


Re: searching an XML doc

2008-01-16 Thread grflanagan
On Jan 15, 9:33 pm, Gowri [EMAIL PROTECTED] wrote:
 Hello,

 I've been reading about ElementTreee and ElementPath so I could use
 them to find the right elements in the DOM. Unfortunately neither of
 these seem to offer XPath like capabilities where I can find elements
 based on tag, attribute values etc. Are there any libraries which can
 give me XPath like functionality?

 Thanks in advance

Create your query like:

ns0 = '{http://a.b.com/phedex}'

query = '%srequest/%sstatus' % (ns0, ns0)

Also, although imperfect, some people have found this useful:

http://gflanagan.net/site/python/utils/elementfilter/elementfilter.py.txt

[CODE]

test = '''phedexData xmlns=http://a.b.com/phedex;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation=http://a.b.com/phedex requests.xsd
!--  Low priority replication request --
request id=1234 last_update=1060199000.0
status
approvedT1_RAL_MSS/approved
approvedT2_London_ICHEP/approved
disapprovedT2_Southgrid_Bristol/
disapproved
pending/
move_pending/
/status
subscription open=1 priority=0 type=replicate
items
dataset/PrimaryDS1/ProcessedDS1/
Tier/dataset
block/PrimaryDS2/
ProcessedDS2/Tier/block/block
/items
/subscription
/request
/phedexData
'''

from xml.etree import ElementTree as ET

root = ET.fromstring(test)

ns0 = '{http://a.b.com/phedex}'

from rattlebag.elementfilter import findall, data

#http://gflanagan.net/site/python/utils/elementfilter/
elementfilter.py.txt

query0 = '%(ns)srequest/%(ns)sstatus' % {'ns': ns0}
query1 = '%(ns)srequest/%(ns)[EMAIL PROTECTED]replicate]/%
(ns)sitems' % {'ns': ns0}
query2 = '%(ns)[EMAIL PROTECTED]/%(ns)sstatus/%(ns)sapproved' %
{'ns': ns0}

print 'With ElementPath: '
print root.findall(query0)
print
print 'With ElementFilter:'
for query in [query0, query1, query2]:
print
print '+'*50
print 'query: ', query
print
for item in findall(root, query):
print 'item: ', item
print 'xml:'
ET.dump(item)

print '-'*50
print
print 'approved: ', data(root, query2)

[/CODE]

[OUTPUT]
With ElementPath:
[Element {http://a.b.com/phedex}status at b95ad0]

With ElementFilter:

++
query:  {http://a.b.com/phedex}request/{http://a.b.com/phedex}status

item:  Element {http://a.b.com/phedex}status at b95ad0
xml:
ns0:status xmlns:ns0=http://a.b.com/phedex;
ns0:approvedT1_RAL_MSS/ns0:approved
ns0:approvedT2_London_ICHEP/ns0:approved
ns0:disapprovedT2_Southgrid_Bristol/
ns0:disapproved
ns0:pending /
ns0:move_pending /
/ns0:status


++
query:  {http://a.b.com/phedex}request/{http://a.b.com/
[EMAIL PROTECTED]
==replicate]/{http://a.b.com/phedex}items

item:  Element {http://a.b.com/phedex}items at b95eb8
xml:
ns0:items xmlns:ns0=http://a.b.com/phedex;
ns0:dataset/PrimaryDS1/ProcessedDS1/
Tier/ns0:
dataset
ns0:block/PrimaryDS2/
ProcessedDS2/Tier
/block/ns0:block
/ns0:items


++
query:  {http://a.b.com/[EMAIL PROTECTED]/{http://a.b.com/
phedex}status/
{http://a.b.com/phedex}approved

item:  Element {http://a.b.com/phedex}approved at b95cd8
xml:
ns0:approved xmlns:ns0=http://a.b.com/phedex;T1_RAL_MSS/
ns0:approved

item:  Element {http://a.b.com/phedex}approved at b95cb0
xml:
ns0:approved xmlns:ns0=http://a.b.com/phedex;T2_London_ICHEP/
ns0:approved

--

approved:  ['T1_RAL_MSS', 'T2_London_ICHEP']
INFO End logging.
[/OUTPUT]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: searching an XML doc

2008-01-16 Thread Gowri
Hi Gerard,

I don't know what to say :) thank you so much for taking time to post
all of this. truly appreciate it :)
-- 
http://mail.python.org/mailman/listinfo/python-list


using pyopengl 3.0.0b1 with py2exe

2008-01-16 Thread Sébastien Ramage
Hi !

How can I make an exe that use the new pyopengl 3.0.0b1 ???
I use py2exe 0.6.6

with the 3.0.0a6 version I have make it working by copying the egg and
by
forcing loading it at the start of the app
but it doesn't work with this version

py2exe correctly detect it and include it in the app but I get this

Traceback (most recent call last):
File texas.py, line 8, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\GL\__init__.pyo, line 2, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\raw\GL\__init__.pyo, line 6, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\raw\GL\constants.pyo, line 7, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\platform\__init__.pyo, line 20, in module
ImportError: No module named pkg_resources

if I add an unzipped copy of setuptools in my app folder, py2exe
include
pkg_resources but I get this

Traceback (most recent call last):
File texas.py, line 8, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\GL\__init__.pyo, line 2, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\raw\GL\__init__.pyo, line 6, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\raw\GL\constants.pyo, line 7, in module
File zipextimporter.pyo, line 82, in load_module
File OpenGL\platform\__init__.pyo, line 57, in module
File OpenGL\platform\__init__.pyo, line 53, in _load
RuntimeError: Unable to find an implementation for the 'win32' ('nt')
platform


if anybody ahs a solution

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


Shed Skin (restricted) Python-to-C++ Compiler 0.0.26

2008-01-16 Thread Mark Dufour
Hi all,

I have just released Shed Skin 0.0.26, with the following goodies:

-Almost complete support for os.path (bootstrapped using Shed Skin)
-Support for collections.defaultdict (completing collections)
-Much improved support for the os module (though many methods remain)
-Support for 5 of 7 last missing str methods
-Added support for getopt.gnu_getopt (bootstrapped)
-Improved support for locales
-Optimized string addition (a+b+c..)
-Much better documentation (tutorial)
-Added a Debian package
-Squashed many bugs
-Moved to Google code hosting

Please have a look at my latest blog entry for more details about the
release, or visit the new Google code hosting site:

http://shed-skin.blogspot.com
http://shedskin.googlecode.com


Thanks,
Mark Dufour.
-- 
One of my most productive days was throwing away 1000 lines of code
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no pass-values calling?

2008-01-16 Thread Steven D'Aprano
On Wed, 16 Jan 2008 17:46:39 +1100, Ben Finney wrote:

 Christian Heimes [EMAIL PROTECTED] writes:
 
 Dennis Lee Bieber wrote:
 Since all variable names in Python are references to objects,
  anything accessed using a name is accessed by reference.
 
 Anybody using the terms variable, reference or call-by-value is most
 likely explaining Python the wrong way.
 
 The term reference is fine, since that's exactly how it works. One
 gets at an object via some reference, be it a name or some access into a
 container object. When an object has no more references to itself, it
 becomes a candidate for garbage collection. And so on.

The term reference *by itself* is fine, so long as there is no 
possibility of confusion with the very common concept of call by 
reference (or pass by reference). 

But since the Original Poster himself raised the question of whether 
Python is call by reference or call by value, that should be a great big 
warning flag to avoid the term reference until he's reset his brain. 
Python is not C, and if you talk about Python using C terminology without 
making it absolutely crystal clear that the semantics of that terminology 
is different in Python, then you'll just reinforce the O.P.'s 
misunderstandings.

Python might have references in the generic sense, but in the specific 
sense that it is understood by most people with C/Pascal/Java/Perl 
experience, Python does not.



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


Re: anti-spam policy for c.l.py?

2008-01-16 Thread Bruno Desthuilliers
_wolf a écrit :
 this list has been receiving increasing amounts of nasty OT spam
 messages for some time. are there any plans to prevent such messages
 from appearing on the list or to purge them retrospectively?

Apart from checking posts headers and complaining about the relevant 
ISPs, there's not much you can do AFAIK. This is usenet, not a mailing-list.

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


Re: no pass-values calling?

2008-01-16 Thread Bruno Desthuilliers
J. Peng a écrit :
 On Jan 16, 2008 2:30 PM, Steven D'Aprano
 [EMAIL PROTECTED] wrote:
 On Wed, 16 Jan 2008 13:59:03 +0800, J. Peng wrote:

 Hi,

 How to modify the array passed to the function? I tried something like
 this:

 a
 [1, 2, 3]
 def mytest(x):
 ...   x=[4,5,6]

 This line does NOT modify the list [1, 2, 3]. What it does is create a
 new list, and assign it to the name x. It doesn't change the existing
 list.

 
 Sounds strange.
 In perl

This is Python, not Perl. Please follow the links provided by Steven and 
read carefully.

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


Re: anti-spam policy for c.l.py?

2008-01-16 Thread Jeroen Ruigrok van der Werven
-On [20080116 12:51], Bruno Desthuilliers ([EMAIL PROTECTED]) wrote:
Apart from checking posts headers and complaining about the relevant 
ISPs, there's not much you can do AFAIK. This is usenet, not a mailing-list.

It is both actually. python-list@python.org is linked to comp.lang.python due
to a news gateway.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
I accept that some things will never change, I've let your tiny minds
magnify my agony...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: no pass-values calling?

2008-01-16 Thread Torsten Bronger
Hallöchen!

J. Peng writes:

 On Jan 16, 2008 2:30 PM, Steven D'Aprano
 [EMAIL PROTECTED] wrote:
 On Wed, 16 Jan 2008 13:59:03 +0800, J. Peng wrote:

 How to modify the array passed to the function? I tried
 something like this:

 a
 [1, 2, 3]
 def mytest(x):
 ...   x=[4,5,6]


 This line does NOT modify the list [1, 2, 3]. What it does is
 create a new list, and assign it to the name x. It doesn't
 change the existing list.

 Sounds strange.
 In perl we can modify the variable's value like this way:

 $ perl -le '
 $x=123;
 sub test {
 $x=456;
 }
 test;
 print $x '
 456

But here, it is a global name rather than a parameter.  However, I
don't speak Perl.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no pass-values calling?

2008-01-16 Thread Neil Cerutti
On Jan 15, 2008 10:09 PM, J. Peng [EMAIL PROTECTED] wrote:
 Hello,

 I saw this statement in Core Python Programming book,

 All arguments of function calls are made by reference, meaning that
 any changes to these parameters within the function
 affect the original objects in the calling function.

Yes, that's generally correct. But you must be careful about what is
meant by changes to parameters. Assigning a new value to a parameter
name (inside the function, a parameter is just a local variable) does
not change the original object--it only rebinds the local variable to
a new object.

In the following function, a is rebound with an assignment statement,
while b is mutated, i.e., changed, with an assignment statement.

def f(a, b):
a = 12
b.value = 14

Argument a will never be changed, while argument b will be. Python's
argument passing semantics are extremely simple. It's the assignment
statement that's tricky: some assignments mutate/change objects, and
some only rebind names.

 Does this mean there is not pass-values calling to a function in
 python? only pass-reference calling? Thanks!

Neither is quite true. Values are passed by binding parameter names to
their corresponding arguments. This is similar to pass-by-reference in
some cases (when the argument is mutated) but not in others (when the
argument is not mutated). Thinking of it as pass-by-reference may help
you to understand it, but bear in mind that Python's references may
be rebound to new objects, which is quite different from the usual
behavior of references.

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


Re: Python too slow?

2008-01-16 Thread Paul Boddie
On 16 Jan, 02:17, Jaimy Azle [EMAIL PROTECTED] wrote:

 Wow, serious... what you've done was really, really cool... :)

In practice, not that cool. ;-)

 I was expect there are nobody willing to do to have python runs Java
 Language (such as PyPy) over CPython. Perhaps your javaclass does not work
 just like as PyPy, but really... it is damned cool to get CPython execute
 java byte-code, congratulations...

Well, the limitations that stopped me working on it are listed on the
page I referenced, so it wasn't that cool in the end. In fact, the
project grew out of just wanting to inspect .class files and pull out
method signatures, but it was so tempting to see whether Java
bytecodes could be rewritten and run in a CPython environment.

I think the benefits of running Java on CPython are significantly less
than those had by running Python on the Java VM (or another VM).
Firstly, who wants to write statically typed code which then runs on a
virtual machine that can't take advantage of the type declarations?
Secondly, isn't it just better to use a virtual machine with just-in-
time compilation and all sorts of security mechanisms if you're
wanting to write the Java code that, when compiled, can take advantage
of all that stuff? In other words: what makes CPython a compelling VM
for the Java programmer?

My perspective now is that it's a lot more interesting to target
Python for virtual machines other than the CPython one because that's
where the performance and functionality benefits are most likely to be
found. And the most important motivation for this: I prefer writing
Python, not Java. ;-)

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


Re: Generic string import like in strptime?

2008-01-16 Thread Neil Cerutti
On Jan 16, 2008 3:34 AM, Andre [EMAIL PROTECTED] wrote:
 Hi there

 Is there a function like strptime, which takes a string and converts it
 into an array depending on a format string I provide. Like:
  a = '3456\tblub-blib.0.9'
  b = '%d\t%s-%s.%f'
  c = mysticalfunction(a,b)
  print c
 [3456,'blub','blib',0.9]

No, not in the standard distribution of Python.

In Python, you're expected to use appropriate string methods, or hold
your nose and drag out the re module. There are some scanf-like
libraries for Python available on the net, e.g.,
http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/.  None of them have
become popular enough with Python users to make it into the standard
distribution.

An excellent tool that can be used in these cases is pyparsing, which
is also not in the standard distribution.
http://pyparsing.wikispaces.com/

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


Re: Basic inheritance question

2008-01-16 Thread Lie
On Jan 15, 9:00 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Lie a écrit :



  On Jan 7, 2:46 am, Bruno Desthuilliers
  [EMAIL PROTECTED] wrote:
  Lie a écrit :

  On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
  Jeroen Ruigrok van der Werven wrote:
  Shouldn't this be:
  self.startLoc = start
  self.stopLoc = stop
  Thanks! Of course it should. Old Java habits die slowly.
  No, seriously it isn't Java habits only, most other languages wouldn't
  need explicit calling of class name.
  Where is the explicit calling of class name exactly ?

  Perhaps I was a bit tired when writing that (I wouldn't understand
  what I wrote if I were you)... what I meant is most other languages
  doesn't usually enforce us to explicitly state the containing class
  name, which in python is generally called self.

 'self' (or whatever you name it) is not the containing class name,

Current instance is what I meant, thanks for pointing out the
incorrect term I used.

 it's the first argument of the function - which usually happens to be
 the current instance when the function is used as a method.

And that's the point, self (or anything you name it) is almost always
the current instance and that makes it functionally the same as Me and
this in VB and Java.

  Most other languages
  1) automatically assign the containing class' object

 s/containing class' object/current instance/

  in a keyword
  (Java: this, VB: Me) behind the screen,

 That's not very far from what a Python method object does -
 automatically assign the current instance to something. The difference
 is that Python uses functions to implement methods (instead of having
 two distinct contructs), so the only reliable way to inject the
 reference to the current instance is to pass it as an argument to the
 function (instead of making it pop from pure air).

It isn't very far, but Python makes it obvious about the assignment
(not behind the screen).

 There are some benefits to this solution. One of them is the ability to
   dynamically assign functions as methods. So if you do have some
 function taking an object as first argument, you can easily turn it into
 a method.

Indeed, many languages doesn't allow dynamic assignment of function
which makes having an automatic assignment of current instance to Me/
this possible and with minimal harm.

  and 2) automatically searches
  variable name in both the local variable table and the containing
  class variable table  (so to refer to a class variable named var from a
  method inside the class, we only need to write var, not self.var as in
  python).

 This - as you know - cannot work well with Python's scoping rules and
 dynamicity. Anyway, implicit object reference is definitively a
 BadThing(tm) wrt/ readbility, specially with multiparadigm languages
 (like Python or C++). Why do you think s many C++ shops impose the
 m_something naming scheme ?

Implicit object reference for the containing class has little harm, if
a class is so complex that there are more than 10 class-level
variable, then it is obvious that that class needs to be fragmented to
smaller classes. Remembering less than 10 variable and avoiding naming
collision among just 10 variable is not hard (and 10 is really too
many, most classes should only use 2-4 variables), especially if you
have a good IDE that employs Intellisense-like technology (IDLE has
it). And it is always a Bad Thing(tm) to use the same name for two
variable in the class and in function (which is the main and only
source of possible ambiguity) in ANY language, even in Python.

 Anyway, I actually know 3 languages (4 if C# works the same) that has
 this implicit 'this' (or whatever the name) 'feature', and at least 5
 that don't. So I'm not sure that the most other languages qualifier
 really applies to point 2 !-)

What's this 5 languages? Are they a mainstream, high-level languages
or lesser known, low-level languages? C-family, Java, and Basic are
the Big Three of high-level programming language.

  In VB, Me is extremely rarely used,

 I used to systematically use it - like I've always systematically used
 'this' in C++  and Java.

And that is what reduces readability. A proficient VB/C/Java
programmer would frown upon the extra, unneeded garbage as they
thought it was clear already that the variable refers to a class-level
variable. It is a different story if, like Python, the use of self is
enforced by the language, the self wouldn't be viewed as extra
unnecessary garbage.

  in Python, self is all
  over the place. Well, there is positive and negative to both sides,
  convenience in VB, and flexibility in Python.

 As far as I'm concerned, there's *no* positive point in implicit object
 reference, and there has never been (and before some paranoid nutcase
 around accuse me of overzealous biggotry : I already held this very same
 opinion years before I discovered Python).

There is one major positive point: convenience and shorter code.
(isn't that two?)
As 

Re: no pass-values calling?

2008-01-16 Thread cokofreedom
On Jan 16, 1:21 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
 On Jan 15, 2008 10:09 PM, J. Peng [EMAIL PROTECTED] wrote:

  Hello,

  I saw this statement in Core Python Programming book,

  All arguments of function calls are made by reference, meaning that
  any changes to these parameters within the function
  affect the original objects in the calling function.

 Yes, that's generally correct. But you must be careful about what is
 meant by changes to parameters. Assigning a new value to a parameter
 name (inside the function, a parameter is just a local variable) does
 not change the original object--it only rebinds the local variable to
 a new object.

 In the following function, a is rebound with an assignment statement,
 while b is mutated, i.e., changed, with an assignment statement.

 def f(a, b):
 a = 12
 b.value = 14

 Argument a will never be changed, while argument b will be. Python's
 argument passing semantics are extremely simple. It's the assignment
 statement that's tricky: some assignments mutate/change objects, and
 some only rebind names.

  Does this mean there is not pass-values calling to a function in
  python? only pass-reference calling? Thanks!

 Neither is quite true. Values are passed by binding parameter names to
 their corresponding arguments. This is similar to pass-by-reference in
 some cases (when the argument is mutated) but not in others (when the
 argument is not mutated). Thinking of it as pass-by-reference may help
 you to understand it, but bear in mind that Python's references may
 be rebound to new objects, which is quite different from the usual
 behavior of references.

 --
 Neil Cerutti [EMAIL PROTECTED]

So basically the scope is the reason for confusion a lot of the time?

def some_name():
alist = [5]
bint = 5
cstring = '5'
ddictionary = {0:5}

def other_name(alist, bint, cstring, ddictionary):
alist = 4
bint = 4
cstring = '4'
ddictionary = 4
print other_name:,
print alist, bint, cstring, ddictionary

def another_name(alist, bint, cstring, ddictionary):
alist[0] = 3
# bint cannot be changed it is immutable
# cstring cannot be changed it is immutable
ddictionary[0] = 3
print another_name:,
print alist, bint, cstring, ddictionary

another_name(alist, bint, cstring, ddictionary)
other_name(alist, bint, cstring, ddictionary)
print our entries are now:,
print alist, bint, cstring, ddictionary
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no pass-values calling?

2008-01-16 Thread Neil Cerutti
On Jan 16, 2008 7:58 AM,  [EMAIL PROTECTED] wrote:
 On Jan 16, 1:21 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
  In the following function, a is rebound with an assignment statement,
  while b is mutated, i.e., changed, with an assignment statement.
 
  def f(a, b):
  a = 12
  b.value = 14
 
  Argument a will never be changed, while argument b will be. Python's
  argument passing semantics are extremely simple. It's the assignment
  statement that's tricky: some assignments mutate/change objects, and
  some only rebind names.

 So basically the scope is the reason for confusion a lot of the time?

No, my hypothesis is that Python's assignment statement semantics are
the tricky part--once you understand them, the utter simplicity of
Python's argument passing semantics will be evident.

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


Re: Why this apparent assymetry in set operations?

2008-01-16 Thread Colin J. Williams
Steven D'Aprano wrote:
 On Tue, 15 Jan 2008 11:25:25 -0500, Colin J. Williams wrote:
 
 I'm sorry, there appears to be a bug: # tSet.py
 import sets
 s1= sets.Set([1, 2, 3])
 s1.union_update([3, 4,5])
 print(s1)
 s2= sets.Set([6, 7, 8])
 s1 |+ s2  # This fails:
 exceptions.TypeError: bad operand type for unary +: 'Set'
 
 And so it should fail. Did you mean |= instead of |+ ?
 
 
Thanks, keyboard error.

Colin W.

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


plz help how to print python variable using os.system()

2008-01-16 Thread jitender001001
hi all
   i m new to python and i have a problem of printing python
variable using os.system() in bash

   !/usr/bin/env python

var = /home/anonymous
os.system(echo $var)

 it is not working..
   i want to print string  using os.system() plz help
-- 
http://mail.python.org/mailman/listinfo/python-list


Unknown cause to error (new to python)

2008-01-16 Thread Brandon Perry
Hi, I am having to compile a standalone version of python for the web
server I use (they don't allow access to /usr/bin/python). I posted
earlier about a GLib error, but I have fixed that now. I am very close
to getting this to work, but I am getting some weird errors.

File /home/vminds/public_html/torrents/python/lib/python2.2/socket.py,
line 41, in ?
File /home/vminds/public_html/torrents/python/lib/python2.2/httplib.py, line 
71, in ?
File /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/zurllib.py, 
line 4, in ?
File 
/home/vminds/public_html/torrents/TF_BitTornado/BitTornado/download_bt1.py, 
line 4, in ?
File /home/vminds/public_html/torrents/TF_BitTornado/btphptornado.py, line 
15, in ?

I am using 2.2 for compatibility purposes.

Thanks, Brandon

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


Re: plz help how to print python variable using os.system()

2008-01-16 Thread Lutz Horn
Hi,

On Wed, 16 Jan 2008 05:29:08 -0800 (PST), [EMAIL PROTECTED] said:
 var = /home/anonymous
 os.system(echo $var)

os.system(echo %s % var)

Lutz
-- 
GnuPG Key: 1024D/6EBDA359 1999-09-20
Key fingerprint = 438D 31FC 9300 CED0 1CDE  A19D CD0F 9CA2 6EBD A359
http://dev-random.dnsalias.net/0x6EBDA35.asc
http://pgp.cs.uu.nl/stats/6EBDA359.html

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


Re: no pass-values calling?

2008-01-16 Thread cokofreedom

 No, my hypothesis is that Python's assignment statement semantics are
 the tricky part--once you understand them, the utter simplicity of
 Python's argument passing semantics will be evident.

Indeed, I find the simple nature of it and the fact things tend not to
change is extremely useful. It is an advantage to have rules to abide
by that cannot be ignored or by-passed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting Thread Gotcha

2008-01-16 Thread Duncan Booth
Hendrik van Rooyen [EMAIL PROTECTED] wrote:

 It would have been nice, however, to have gotten something like:
 
 TypeError - This routine needs a tuple.
 
 instead of the silent in line calling of the routine in question,
 while failing actually to start a new thread.

Given that the start_new_thread function never actually got called, what 
code exactly do you expect to complain about the absence of a tuple?

 
 It seems to act no different from plain old:
 
 kbd_driver (port_q,kbd_q)
 
 Is it worth the trouble of learning how to submit a bug report?

On your own code? There doesn't appear to be a bug in anyone else's code 
here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown cause to error (new to python)

2008-01-16 Thread Diez B. Roggisch
Brandon Perry wrote:

 Hi, I am having to compile a standalone version of python for the web
 server I use (they don't allow access to /usr/bin/python). I posted
 earlier about a GLib error, but I have fixed that now. I am very close
 to getting this to work, but I am getting some weird errors.
 
 File /home/vminds/public_html/torrents/python/lib/python2.2/socket.py,
 line 41, in ?
 File /home/vminds/public_html/torrents/python/lib/python2.2/httplib.py,
 line 71, in ? File
 /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/zurllib.py,
 line 4, in ? File
 /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/download_bt1.py,
 line 4, in ? File
 /home/vminds/public_html/torrents/TF_BitTornado/btphptornado.py, line
 15, in ?
 
 I am using 2.2 for compatibility purposes.

I don't see no error - is that all stacktrace you get?

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


Re: Interesting Thread Gotcha

2008-01-16 Thread Bjoern Schliessmann
Hendrik van Rooyen wrote:
 Absolutely! - well spotted!

This is no threading problem at all; not even a syntax problem. If
you don't know exactly what start_new_thread and kbd_driver
functions do it's impossible to tell if your code does what is
intended.

 It would have been nice, however, to have gotten something like:
 
 TypeError - This routine needs a tuple.
 
 instead of the silent in line calling of the routine in question,
 while failing actually to start a new thread.

Exactly which part of the code should give you this warning?

 Is it worth the trouble of learning how to submit a bug report?

For your problem not, IMHO, as a bug report for it will be closed
quickly.

Regards,


Björn

-- 
BOFH excuse #330:

quantum decoherence

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


Re: anti-spam policy for c.l.py?

2008-01-16 Thread Bruno Desthuilliers
Jeroen Ruigrok van der Werven a écrit :
 -On [20080116 12:51], Bruno Desthuilliers ([EMAIL PROTECTED]) wrote:
 Apart from checking posts headers and complaining about the relevant 
 ISPs, there's not much you can do AFAIK. This is usenet, not a mailing-list.
 
 It is both actually. python-list@python.org is linked to comp.lang.python due
 to a news gateway.

Yes, I know - but the OP explicitely mentionned c.l.py (re-read the 
title), not the ML.

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

list classes in package

2008-01-16 Thread Dmitry
Hi All,

I've trying to develop one Python application, and
neet to solve one problem. I need to list all classes defined in one
package (not module!).

Could anybody please show me more convinient (correct) way to
implement this?

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


Re: Unknown cause to error (new to python)

2008-01-16 Thread Bruno Desthuilliers
Brandon Perry a écrit :
 Hi, I am having to compile a standalone version of python for the web
 server I use (they don't allow access to /usr/bin/python). I posted
 earlier about a GLib error, but I have fixed that now. I am very close
 to getting this to work, but I am getting some weird errors.
 
 File /home/vminds/public_html/torrents/python/lib/python2.2/socket.py,
 line 41, in ?
 File /home/vminds/public_html/torrents/python/lib/python2.2/httplib.py, 
 line 71, in ?
 File /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/zurllib.py, 
 line 4, in ?
 File 
 /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/download_bt1.py, 
 line 4, in ?
 File /home/vminds/public_html/torrents/TF_BitTornado/btphptornado.py, line 
 15, in ?

Sorry but my crystal ball is broken. Please post the *whole* traceback.

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


Re: Basic inheritance question

2008-01-16 Thread Bjoern Schliessmann
Lie wrote:
 [EMAIL PROTECTED] wrote:

 I used to systematically use it - like I've always systematically
 used 'this' in C++  and Java.
 
 And that is what reduces readability. 

IMHO not, IOPHO not. This is the nth time (n  1) this discussion
comes up here. If I have learned one thing from those very lengthy
discussions, it's that Python's self handling is not going to
change.

 A proficient VB/C/Java programmer would frown upon the extra,
 unneeded garbage as they thought it was clear already that the
 variable refers to a class-level variable. 

C programmers surely have no opinion concerning C because it has no
native classes.

Personally, I've seen many C++ programs with complex class designs
where it definitely helps to consistently use this-. I cannot
remember all local (and global) variables in bigger methods.

 There is one major positive point: convenience and shorter code.
 (isn't that two?)

Shorter code is not per se positive, neither is it convenient. If it
was, everyone would use perl.

Regards,


Björn

-- 
BOFH excuse #109:

The electricity substation in the car park blew up.

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


Re: UTF-8 in basic CGI mode

2008-01-16 Thread Sion Arrowsmith
coldpizza  [EMAIL PROTECTED] wrote:
I am using this 'word' variable like this:

print u'''input type=text name=blabla value=%s''' % (word)

and apparently this causes exceptions with non-ASCII strings.

I've also tried this:
print u'''input type=text name=blabla value=%s''' %
(word.encode('utf8'))
but I still get the same UnicodeDecodeError..

Your 'word' is a byte string (presumably UTF8 encoded). When python
is asked to insert a byte string into a unicode string (as you are
doing with the % operator, but the same applies to concatenation
with the + operator) it attempts to convert the byte string into
unicode. And the default encoding is 'ascii', and the ascii codec
takes a very strict view about what an ASCII character is -- and
that is that only characters below 128 are ASCII.

To get it to work, you need to *decode* word. It is already UTF8
(or something) encoded. Under most circumstances, use encode() to
turn unicode strings to byte strings, and decode() to go in the
other direction.

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

Re: Python help for a C++ programmer

2008-01-16 Thread Lutz Horn
Hi,

On Wed, 16 Jan 2008 06:23:10 -0800 (PST), mlimber [EMAIL PROTECTED]
said:
 I'm writing a text processing program to process some survey results.
 I'm familiar with C++ and could write it in that, but I thought I'd
 try out Python. I've got a handle on the file I/O and regular
 expression processing, but I'm wondering about building my array of
 classes (I'd probably use a struct in C++ since there are no methods,
 just data).

You could try something like this.

#!/usr/bin/env python

class Response:
def __init__(self, name, age, iData, sData):
self.name = name
self.age = age
self.iData = iData
self.sData = sData

def sourceOfResponses():
return [[you, 42, [1, 2, 3], [foo, bar, baz]],
[me, 23, [1, 2, 3], [ham, spam, eggs]]]

if __name__ == __main__:
responses = []
for input in sourceOfResponses:
response = Response(input.name, input.age,
input.iData, input.sData)
reponses.append(response)

Lutz
-- 
GnuPG Key: 1024D/6EBDA359 1999-09-20
Key fingerprint = 438D 31FC 9300 CED0 1CDE  A19D CD0F 9CA2 6EBD A359
http://dev-random.dnsalias.net/0x6EBDA35.asc
http://pgp.cs.uu.nl/stats/6EBDA359.html

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


Re: Python help for a C++ programmer

2008-01-16 Thread Neil Cerutti
On Jan 16, 2008 9:23 AM, mlimber [EMAIL PROTECTED] wrote:
 I'm writing a text processing program to process some survey results.
 I'm familiar with C++ and could write it in that, but I thought I'd
 try out Python. I've got a handle on the file I/O and regular
 expression processing, but I'm wondering about building my array of
 classes (I'd probably use a struct in C++ since there are no methods,
 just data).

 I want something like (C++ code):

  struct Response
  {
std::string name;
int age;
int iData[ 10 ];
std::string sData;
  };

  // Prototype
  void Process( const std::vectorResponse );

  int main()
  {
std::vectorResponse responses;

while( /* not end of file */ )
{
  Response r;

  // Fill struct from file
  r.name = /* get the data from the file */;
  r.age = /* ... */;
  r.iData[0] = /* ... */;
  // ...
  r.sData = /* ... */;
  responses.push_back( r );
}

 // Do some processing on the responses
 Process( responses );
  }

 What is the preferred way to do this sort of thing in Python?

It depends on the format of your data (Python provides lots of
shortcuts for handling lots of kinds of data), but perhaps something
like this, if you do all the parsing manually:

class Response(object):
def __init__(self, extern_rep):
# parse or translate extern_rep into ...
self.name = ...
self.age = ...
# Use a dictionary instead of parallel lists.
self.data = {...}
def process(self):
# Do what you need to do.

fstream = open('thedatafile')

for line in fstream:
# This assumes each line is one response.
Response(line).process()

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


Python help for a C++ programmer

2008-01-16 Thread mlimber
I'm writing a text processing program to process some survey results.
I'm familiar with C++ and could write it in that, but I thought I'd
try out Python. I've got a handle on the file I/O and regular
expression processing, but I'm wondering about building my array of
classes (I'd probably use a struct in C++ since there are no methods,
just data).

I want something like (C++ code):

 struct Response
 {
   std::string name;
   int age;
   int iData[ 10 ];
   std::string sData;
 };

 // Prototype
 void Process( const std::vectorResponse );

 int main()
 {
   std::vectorResponse responses;

   while( /* not end of file */ )
   {
 Response r;

 // Fill struct from file
 r.name = /* get the data from the file */;
 r.age = /* ... */;
 r.iData[0] = /* ... */;
 // ...
 r.sData = /* ... */;
 responses.push_back( r );
   }

// Do some processing on the responses
Process( responses );
 }

What is the preferred way to do this sort of thing in Python?

Thanks in advance! --M
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python help for a C++ programmer

2008-01-16 Thread Tim Chase
 I want something like (C++ code):
 
  struct Response
  {
std::string name;
int age;
int iData[ 10 ];
std::string sData;
  };
 
  // Prototype
  void Process( const std::vectorResponse );
 
  int main()
  {
std::vectorResponse responses;
 
while( /* not end of file */ )
{
  Response r;
 
  // Fill struct from file
  r.name = /* get the data from the file */;
  r.age = /* ... */;
  r.iData[0] = /* ... */;
  // ...
  r.sData = /* ... */;
  responses.push_back( r );
}
 
 // Do some processing on the responses
 Process( responses );
  }
 
 What is the preferred way to do this sort of thing in Python?

Without knowing more about the details involved with parsing the 
file, here's a first-pass whack at it:

   class Response(object):
 def __init__(self, name, age, iData, sData):
   self.name = name
   self.age = age
   self.iData = iData
   self.sData = sData

 def __repr__(self):
   return '%s (%s)' % self.name

   def parse_response_from_line(line):
 name, age, iData, sData = line.rstrip('\n').split('\t')
 return Response(name, age, iData, sData)

   def process(response):
 print 'Processing %r' % response

   responses = [parse_response_from_line(line)
 for line in file('input.txt')]

   for response in responses:
 process(response)


That last pair might be condensed to just

   for line in file('input.txt'):
 process(parse_response_from_line(line))

Things get a bit hairier if your input is multi-line.  You might 
have to do something like

   def getline(fp):
 return fp.readline().rstrip('\n')
   def response_generator(fp):
 name = None
 while name != '':
   name = getline(fp)
   age = getline(fp)
   iData = getline(fp)
   sData = getline(fp)
   if name and age and iData and sData:
 yield Response(name, age, iData, sData)

   fp = file('input.txt')
   for response in response_generator(fp):
 process(response)

which you can modify accordingly.

-tkc




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


Paramiko/SSH blues....

2008-01-16 Thread Tarun Kapoor
I am using paramiko to do an SFTP file transfer... I was able to connect
to the remote server using an SFTP client I have just to make sure
that username and password are working.. But when i try to connect
using this script it fails 

**hostname, username and password are declared.

# now, connect and use paramiko Transport to negotiate SSH2 across
the connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))

t = paramiko.Transport(sock)
event = threading.Event()
t.start_client(event)

event.wait(15)

if not t.is_active():
print 'SSH negotiation failed.'
sys.exit(1)
else:
print SSH negotiation sucessful

event.clear()

t.auth_password(username=username, password=password,event=event)

if not t.is_authenticated():
print not authenticated
output:
SSH negotiation successful
not authenticated

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


Re: Basic inheritance question

2008-01-16 Thread Bruno Desthuilliers
Lie a écrit :
 On Jan 15, 9:00 pm, Bruno Desthuilliers bruno.
 [EMAIL PROTECTED] wrote:
 Lie a écrit :



 On Jan 7, 2:46 am, Bruno Desthuilliers
 [EMAIL PROTECTED] wrote:
 Lie a écrit :
(snip)
 No, seriously it isn't Java habits only, most other languages wouldn't
 need explicit calling of class name.
 Where is the explicit calling of class name exactly ?
 
 Perhaps I was a bit tired when writing that (I wouldn't understand
 what I wrote if I were you)... what I meant is most other languages
 doesn't usually enforce us to explicitly state the containing class
 name, which in python is generally called self.
 
 'self' (or whatever you name it) is not the containing class name,
 
 Current instance is what I meant, thanks for pointing out the
 incorrect term I used.
 
 it's the first argument of the function - which usually happens to be
 the current instance when the function is used as a method.
 
 And that's the point, self (or anything you name it) is almost always
 the current instance

# this is a plain function. In this function,
# 'obj' can be whatever that happens to have a (numeric)
# 'stuff' attribute
def func(obj, arg):
   return (obj.stuff + arg) / 2.0

# this is a class with an instance attribute 'stuff'
class Foo(object):
def __init__(self, bar):
  self.stuff = bar + 42


# this is another (mostly unrelated) class
# with a class attribute 'stuff'
class Bar(object):
   stuff = 42


# this is a dummy container class:
class Dummy(object): pass


# now let's play:
import new

d = Dummy()
d.stuff = 84
print func(d, 1)

d.baaz = new.instancemethod(func, d, type(d))
print d.baaz(2)

f = Foo(33)
print func(f, 3)
Foo.baaz = func
f.baaz(4)

print func(Bar, 5)
Bar.baaz = classmethod(func)
Bar.baaz(6)


  and that makes it functionally the same as Me and
 this in VB and Java.

Depends on the context, cf above !-)


 Most other languages
 1) automatically assign the containing class' object
 s/containing class' object/current instance/

 in a keyword
 (Java: this, VB: Me) behind the screen,
 
 That's not very far from what a Python method object does -
 automatically assign the current instance to something. The difference
 is that Python uses functions to implement methods (instead of having
 two distinct contructs), so the only reliable way to inject the
 reference to the current instance is to pass it as an argument to the
 function (instead of making it pop from pure air).
 
 It isn't very far, but Python makes it obvious about the assignment
 (not behind the screen).

Exactly. And given both the simplicity of the solution and what it let 
you do, that's a *very* GoodThing(tm) IMHO.

(snip)

 and 2) automatically searches
 variable name in both the local variable table and the containing
 class variable table  (so to refer to a class variable named var from a
 method inside the class, we only need to write var, not self.var as in
 python).
 This - as you know - cannot work well with Python's scoping rules and
 dynamicity. Anyway, implicit object reference is definitively a
 BadThing(tm) wrt/ readbility, specially with multiparadigm languages
 (like Python or C++). Why do you think s many C++ shops impose the
 m_something naming scheme ?
 
 Implicit object reference for the containing class has little harm, if
 a class is so complex that there are more than 10 class-level
 variable, then it is obvious that that class needs to be fragmented to
 smaller classes.

Not necessarily. There are general rules (like 'keep your classes small 
and focused', which I wholefully agree with), there are guidelines (like 
'more than 10 member variables might smell like refactoring), and 
there's real life, where one very often faces classes that have much 
more than 10 member variables and still are as small and focused as 
possible.

 Remembering less than 10 variable and avoiding naming
 collision among just 10 variable is not hard (and 10 is really too
 many, most classes should only use 2-4 variables),

I really doubt you'll be able to write any working non-trivial software 
trying to strictly follow this rule.

 especially if you
 have a good IDE that employs Intellisense-like technology (IDLE has
 it).

IDLE is certainly not a good IDE in my book.

 And it is always a Bad Thing(tm) to use the same name for two
 variable in the class and in function (which is the main and only
 source of possible ambiguity) in ANY language, even in Python.

Ho, yes Like, this would be bad ?

class Person(object):
   def __init__(self, firstname, lastname, birthdate, gender):
 self.firstname = firstname
 self.lastname = lastname
 self.birthdate = birthdate
 self.gender = gender


C'mon, be serious. It's often hard enough to come with sensible names, 
why would one have to find synonyms too ? Try to come with something 
more readable than the above, and let us know. Seriously, this braindead 
rule about  not using the same name for an attribute and a local var 
obviously comes from languages where the 

MSI read support in msilib?

2008-01-16 Thread Floris Bruynooghe
Hi

The introduction from the msilib documentation in python 2.5 claims it
supports reading an msi.  However on the Record class there is only a
GetFieldCount() method and some Set*() methods.  I was expecting to
see GetString() and GetInteger() methods to be able to read the
values.

Maybe I'm missing something?  Is there an other way to read the data
of a record?

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


Re: list classes in package

2008-01-16 Thread Diez B. Roggisch
Dmitry wrote:

 Hi All,
 
 I've trying to develop one Python application, and
 neet to solve one problem. I need to list all classes defined in one
 package (not module!).
 
 Could anybody please show me more convinient (correct) way to
 implement this?

Look at the module inspect and it's predicates. Something like


for name in dir(module_or_package):
if inspect.isclass(getattr(module_or_package, name)):
   print %s is a class % name


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


paramiko

2008-01-16 Thread Tarun Kapoor
I am using paramiko to do an SFTP file transfer... I was able to connect
to the remote server using an SFTP client I have just to make sure that
username and password are working.. This is the code.

   

# now, connect and use paramiko Transport to negotiate SSH2 across
the connection

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.connect((hostname, port))



t = paramiko.Transport(sock)

event = threading.Event()

t.start_client(event)

 

event.wait(15)

 

if not t.is_active():

print 'SSH negotiation failed.'

sys.exit(1)

else:

print SSH negotiation sucessful

 

event.clear()



t.auth_password(username=username, password=password,event=event)

 

if not t.is_authenticated():

print not authenticated

output:

SSH negotiation successful

not authenticated

 

 

 

Tarun

 

Waterstone Capital Management

2 Carlson Parkway, Suite 260

Plymouth, MN 55447

 

Direct: 952-697-4123

Cell:612-205-2587



Disclaimer

This e-mail and any attachments is confidential and intended solely for the use 
of the individual(s) to whom it is addressed. Any views or opinions presented 
are solely those of the author and do not necessarily represent those of 
Waterstone Capital Management, L.P and affiliates. If you are not the intended 
recipient, be advised that you have received this e-mail in error and that any 
use, dissemination, printing, forwarding or copying of this email is strictly 
prohibited. Please contact the sender if you have received this e-mail in 
error. You should also be aware that e-mails are susceptible to interference 
and you should not assume that the contents of this e-mail originated from the 
sender above or that they have been accurately reproduced in their original 
form. Waterstone Capital Management, L.P. and affiliates accepts no 
responsibility for information, or errors or omissions in this e-mail or use or 
misuse thereof. If in doubt, please verify the authenticity with the sender.

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

Re: no pass-values calling?

2008-01-16 Thread Mel
J. Peng wrote:

 Sounds strange.
 In perl we can modify the variable's value like this way:
 
 $ perl -le '
 $x=123;
 sub test {
 $x=456;
 }
 test;
 print $x '
 456

Not all that strange.  The Python equivalent is

x=123
sub test()
 global x
 x=456
test()
print x

Python assignment works by binding an object with a name in a 
namespace.  I suspect that perl does something similar, and the 
differences are in the rules about which namespace to use.

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


Re: Python help for a C++ programmer

2008-01-16 Thread Bruno Desthuilliers
mlimber a écrit :
 I'm writing a text processing program to process some survey results.
 I'm familiar with C++ and could write it in that, but I thought I'd
 try out Python. I've got a handle on the file I/O and regular
 expression processing,

FWIW, and depending on your text format, there may be better solutions 
than regexps.

 but I'm wondering about building my array of
 classes (I'd probably use a struct in C++ since there are no methods,
 just data).

If you have no methods and you're sure you won't have no methods, then 
just use a dict (name-indexed record) or a tuple (position-indexed record).

 I want something like (C++ code):
 
  struct Response
  {
std::string name;
int age;
int iData[ 10 ];
std::string sData;
  };
 
  // Prototype
  void Process( const std::vectorResponse );
 
  int main()
  {
std::vectorResponse responses;
 
while( /* not end of file */ )
{
  Response r;
 
  // Fill struct from file
  r.name = /* get the data from the file */;
  r.age = /* ... */;
  r.iData[0] = /* ... */;
  // ...
  r.sData = /* ... */;
  responses.push_back( r );
}
 
 // Do some processing on the responses
 Process( responses );
  }
 
 What is the preferred way to do this sort of thing in Python?

# assuming you're using a line-oriented format, and not
# worrying about exception handling etc...

def extract(line):
data = dict()
data['name'] = # get the name
data['age'] = # get the age
data['data'] = # etc...
return data


def process(responses):
   # code here

if name == '__main__':
 import sys
 path = sys.argv[1]
 responses = [extract(line) for line in open(path)]
 process(response)

If you have a very huge dataset, you may want to either use tuples 
instead of dicts (less overhead) and/or use a more stream-oriented 
approach using generators - if applyable of course (that is, if you 
don't need to extract all results before processing)

HTH

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


Re: Interesting Thread Gotcha

2008-01-16 Thread Diez B. Roggisch
Hendrik van Rooyen wrote:

 Dan the,,,ail.com wrote:
 
 
  keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))
 
 Needs to be
  keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))
 
 Commas are important!
 
 -Dan
 
 Absolutely! - well spotted!
 
 As the first correct respondent, you win the freedom to spend a week in
 Naboomspruit at your own expense.
 
 It would have been nice, however, to have gotten something like:
 
 TypeError - This routine needs a tuple.
 
 instead of the silent in line calling of the routine in question,
 while failing actually to start a new thread.

You can't prevent the silent inline-calling - otherwise, how would you do
this:

def compute_thread_target():
def target():
pass
return target

thread.start_new_thread(compute_thread_target())


Of course start_new_thread could throw an error if it got nothing callable
as first argument. No idea why it doesn't.

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


Re: error/warning color customization in interactive console?

2008-01-16 Thread Ian Clark
On 2008-01-16, yhvh [EMAIL PROTECTED] wrote:
 Is it possible to output error messages in a different color?
 I'm using Terminal on Gnome.

 print \033[1;31mHello\033[0m There!

Some reading:
http://en.wikipedia.org/wiki/ANSI_escape_code
http://www.ioncannon.net/ruby/101/fun-with-ansi-escape-codes/

Also, you might look at sys.excepthook to colorize an uncaught exception,
and PYTHONSTARTUP to load code automagically before an interactive
session.

Ian

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


Re: Generic string import like in strptime?

2008-01-16 Thread Paul Hankin
On Jan 16, 8:34 am, Andre [EMAIL PROTECTED] wrote:
 Hi there

 Is there a function like strptime, which takes a string and converts it
 into an array depending on a format string I provide. Like: a = 
 '3456\tblub-blib.0.9'
  b = '%d\t%s-%s.%f'
  c = mysticalfunction(a,b)
  print c

 [3456,'blub','blib',0.9]

Use regular expressions: see http://docs.python.org/lib/node49.html

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


Re: list classes in package

2008-01-16 Thread Guilherme Polo
2008/1/16, Diez B. Roggisch [EMAIL PROTECTED]:
 Dmitry wrote:

  Hi All,
 
  I've trying to develop one Python application, and
  neet to solve one problem. I need to list all classes defined in one
  package (not module!).
 
  Could anybody please show me more convinient (correct) way to
  implement this?

 Look at the module inspect and it's predicates. Something like


 for name in dir(module_or_package):
 if inspect.isclass(getattr(module_or_package, name)):
print %s is a class % name


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


You should be able to adapt this one. You need to pass a directory to
it (warning: directory names including dots will cause you errors):

import os
import sys
import pyclbr

def pkg_modules(package):
return filter(lambda x: x.endswith(.py), os.listdir(package))

def module_classes(module):
dict = pyclbr.readmodule_ex(module, [])
objs = dict.values()
objs.sort(lambda a, b: cmp(getattr(a, 'lineno', 0),
   getattr(b, 'lineno', 0)))

print module
for obj in objs:
if isinstance(obj, pyclbr.Class):
print   class %s %s line: %d % (obj.name, obj.super, obj.lineno)

def pkg_classes(package):
for module in pkg_modules(package):
module_classes(%s.%s % (package, module[:-3]))

if __name__ == __main__:
pkg_classes(sys.argv[1])

-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown cause to error (new to python)

2008-01-16 Thread Brandon Perry
Sorry, this is all I can get. :-(

This isn't my webserver, so the only error logs I get are what they give
me. I guess I will just have to keep working at it.

Thanks for looking at it though, Brandon


On Wed, 2008-01-16 at 15:12 +0100, Bruno Desthuilliers wrote:
 Brandon Perry a écrit :
  Hi, I am having to compile a standalone version of python for the web
  server I use (they don't allow access to /usr/bin/python). I posted
  earlier about a GLib error, but I have fixed that now. I am very close
  to getting this to work, but I am getting some weird errors.
  
  File /home/vminds/public_html/torrents/python/lib/python2.2/socket.py,
  line 41, in ?
  File /home/vminds/public_html/torrents/python/lib/python2.2/httplib.py, 
  line 71, in ?
  File 
  /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/zurllib.py, 
  line 4, in ?
  File 
  /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/download_bt1.py,
   line 4, in ?
  File /home/vminds/public_html/torrents/TF_BitTornado/btphptornado.py, 
  line 15, in ?
 
 Sorry but my crystal ball is broken. Please post the *whole* traceback.
 

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

Internet

2008-01-16 Thread i . shoba3
Internet
You are using internet

http://padmagirl.blogspot.com
%
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-16 Thread Ed Jensen
[EMAIL PROTECTED] wrote:
 A lecturer gave me the perfect answer to the question of speed.
 
 You have two choices when it comes to programming. Fast code, or fast
 coders.

You're either with us, or against us.

George W. Bush




My understanding is that while CPython performance won't be winning
any awards anytime soon, Jython and IronPython are pretty impressive
performers.

Disclaimer: I haven't personally used Jython or IronPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown cause to error (new to python)

2008-01-16 Thread Bruno Desthuilliers
Brandon Perry a écrit :
(top-post corrected)
 
 On Wed, 2008-01-16 at 15:12 +0100, Bruno Desthuilliers wrote:
 Brandon Perry a écrit :
(snip context)
 but I am getting some weird errors.

 File /home/vminds/public_html/torrents/python/lib/python2.2/socket.py,
 line 41, in ?
 File /home/vminds/public_html/torrents/python/lib/python2.2/httplib.py, 
 line 71, in ?
 File 
 /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/zurllib.py, 
 line 4, in ?
 File 
 /home/vminds/public_html/torrents/TF_BitTornado/BitTornado/download_bt1.py,
  line 4, in ?
 File /home/vminds/public_html/torrents/TF_BitTornado/btphptornado.py, 
 line 15, in ?
 
 Sorry but my crystal ball is broken. Please post the *whole* traceback.


 Sorry, this is all I can get. :-(
 
 This isn't my webserver, so the only error logs I get are what they give
 me. I guess I will just have to keep working at it.

Then looks like you're in for hard time. Trying to solve a problem 
without any relevant information is not rationaly possible. Perhaps you 
should try voodoo ?

 Thanks for looking at it though, Brandon

Sorry, can't help much here.

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

Re: Generic string import like in strptime?

2008-01-16 Thread Andre' John
Nice. Thanks a lot.

Andre


On Wed, 16 Jan 2008, Paul Hankin wrote:

 On Jan 16, 8:34 am, Andre [EMAIL PROTECTED] wrote:
  Hi there
 
  Is there a function like strptime, which takes a string and converts it
  into an array depending on a format string I provide. Like: a = 
  '3456\tblub-blib.0.9'
   b = '%d\t%s-%s.%f'
   c = mysticalfunction(a,b)
   print c
 
  [3456,'blub','blib',0.9]
 
 Use regular expressions: see http://docs.python.org/lib/node49.html
 
 --
 Paul Hankin
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko

2008-01-16 Thread Guilherme Polo
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:




 I am using paramiko to do an SFTP file transfer… I was able to connect to
 the remote server using an SFTP client I have just to make sure that
 username and password are working.. This is the code.



 # now, connect and use paramiko Transport to negotiate SSH2 across the
 connection

 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

 sock.connect((hostname, port))



 t = paramiko.Transport(sock)

 event = threading.Event()

 t.start_client(event)



 event.wait(15)



 if not t.is_active():

 print 'SSH negotiation failed.'

 sys.exit(1)

 else:

 print SSH negotiation sucessful



 event.clear()



 t.auth_password(username=username, password=password,event=event)



 if not t.is_authenticated():

 print not authenticated

 output:

 SSH negotiation successful

 not authenticated







 Tarun



 Waterstone Capital Management

 2 Carlson Parkway, Suite 260

 Plymouth, MN 55447



 Direct: 952-697-4123

 Cell:612-205-2587
  Disclaimer This e-mail and any attachments is confidential and intended
 solely for the use of the individual(s) to whom it is addressed. Any views
 or opinions presented are solely those of the author and do not necessarily
 represent those of Waterstone Capital Management, L.P and affiliates. If you
 are not the intended recipient, be advised that you have received this
 e-mail in error and that any use, dissemination, printing, forwarding or
 copying of this email is strictly prohibited. Please contact the sender if
 you have received this e-mail in error. You should also be aware that
 e-mails are susceptible to interference and you should not assume that the
 contents of this e-mail originated from the sender above or that they have
 been accurately reproduced in their original form. Waterstone Capital
 Management, L.P. and affiliates accepts no responsibility for information,
 or errors or omissions in this e-mail or use or misuse thereof. If in doubt,
 please verify the authenticity with the sender.
 --
 http://mail.python.org/mailman/listinfo/python-list


You are missing an event.wait() after t.auth_password.
Also, why are you passing this magic value 15 to event.wait() ? That
parameter is passed to class _Verbose to indicate if debug messages
should be displayed or not, so typical values would be 0/1 or
False/True.

-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-16 Thread cokofreedom
On Jan 16, 5:52 pm, Ed Jensen [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  A lecturer gave me the perfect answer to the question of speed.

  You have two choices when it comes to programming. Fast code, or fast
  coders.

 You're either with us, or against us.

 George W. Bush

 My understanding is that while CPython performance won't be winning
 any awards anytime soon, Jython and IronPython are pretty impressive
 performers.

 Disclaimer: I haven't personally used Jython or IronPython.

Indeed, it is as Paul Rudin said;
It's more a continuum than that suggests. The tricky bit is deciding
in each situation where you should be on the continuum.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko

2008-01-16 Thread Tarun Kapoor
# now, connect and use paramiko Transport to negotiate SSH2 across
the connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))

t = paramiko.Transport(sock)
t.start_client()
key = t.get_remote_server_key()

event = threading.Event()
t.auth_password(username=username, password=password, event=event)
event.wait()

if not t.is_authenticated():
print not authenticated

output:
not authenticated




On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:





  I am using paramiko to do an SFTP file transfer... I was able to connect to
  the remote server using an SFTP client I have just to make sure that
  username and password are working.. This is the code.

  # now, connect and use paramiko Transport to negotiate SSH2 across the
  connection

  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

  sock.connect((hostname, port))

  t = paramiko.Transport(sock)

  event = threading.Event()

  t.start_client(event)

  event.wait(15)

  if not t.is_active():

  print 'SSH negotiation failed.'

  sys.exit(1)

  else:

  print SSH negotiation sucessful

  event.clear()

  t.auth_password(username=username, password=password,event=event)

  if not t.is_authenticated():

  print not authenticated

  output:

  SSH negotiation successful

  not authenticated

  Tarun

  Waterstone Capital Management

  2 Carlson Parkway, Suite 260

  Plymouth, MN 55447

  Direct: 952-697-4123

  Cell:612-205-2587
   Disclaimer This e-mail and any attachments is confidential and intended
  solely for the use of the individual(s) to whom it is addressed. Any views
  or opinions presented are solely those of the author and do not necessarily
  represent those of Waterstone Capital Management, L.P and affiliates. If you
  are not the intended recipient, be advised that you have received this
  e-mail in error and that any use, dissemination, printing, forwarding or
  copying of this email is strictly prohibited. Please contact the sender if
  you have received this e-mail in error. You should also be aware that
  e-mails are susceptible to interference and you should not assume that the
  contents of this e-mail originated from the sender above or that they have
  been accurately reproduced in their original form. Waterstone Capital
  Management, L.P. and affiliates accepts no responsibility for information,
  or errors or omissions in this e-mail or use or misuse thereof. If in doubt,
  please verify the authenticity with the sender.
  --
 http://mail.python.org/mailman/listinfo/python-list

 You are missing an event.wait() after t.auth_password.
 Also, why are you passing this magic value 15 to event.wait() ? That
 parameter is passed to class _Verbose to indicate if debug messages
 should be displayed or not, so typical values would be 0/1 or
 False/True.

 --
 -- Guilherme H. Polo Goncalves

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


read_nonblocking error in pxssh

2008-01-16 Thread jrpfinch
I'm attempting to use the pxssh to execute commands on a remote
machine and do stuff with the output.  Both machines are running SSH
Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris 9.

I am hitting a problem with read_nonblocking in the pexpect module as
follows:

 import pxssh
 s=pxssh.pxssh()
 s.login(myhost,root,mypass)
Trying command: ssh -q -l root gerard
Expect returned i=2
Expect returned i=1
Traceback (most recent call last):
  File stdin, line 1, in module
  File pxssh.py, line 244, in login
if not self.synch_original_prompt():
  File pxssh.py, line 134, in synch_original_prompt
self.read_nonblocking(size=1,timeout=10) # GAS: Clear out the
cache before getting the prompt
  File /opt/python2.5.1/lib/python2.5/site-packages/pexpect.py, line
824, in read_nonblocking
raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().

Running the ssh command from the shell yields:

bash-2.05# ssh -q -l root myhost
[EMAIL PROTECTED]'s password:
Last login: Wed Jan 16 17:10:32 2008 from x.x.x.x
Sun Microsystems Inc.   SunOS 5.9   Generic January 2003
Sun Microsystems Inc.   SunOS 5.9   Generic January 2003
[EMAIL PROTECTED]:/ #

I would be grateful if anyone could make a suggestion as to where I go
next?  Is read_nonblocking(), the correct method to be using here?
Are there any options in pxssh I need to explore (I've tried ssh -t,
but this means the password entry fails with raise ExceptionPxssh
('password refused')).

Many thanks

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


Re: anti-spam policy for c.l.py?

2008-01-16 Thread _wolf
On Jan 16, 3:11 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Jeroen Ruigrok van der Werven a écrit :

  -On [20080116 12:51], Bruno Desthuilliers ([EMAIL PROTECTED]) wrote:
  Apart from checking posts headers and complaining about the relevant
  ISPs, there's not much you can do AFAIK. This is usenet, not a 
  mailing-list.

  It is both actually. [EMAIL PROTECTED] is linked to comp.lang.python due
  to a news gateway.

 Yes, I know - but the OP explicitely mentionned c.l.py (re-read the
 title), not the ML.

technically correct, but the idea is of course to keep all those
archives relatively clean and informative. the new fad i've observed
seems to be to initiate whole threads where previously spam very often
stopped short of any second post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko

2008-01-16 Thread Guilherme Polo
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 # now, connect and use paramiko Transport to negotiate SSH2 across
 the connection
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((hostname, port))

 t = paramiko.Transport(sock)
 t.start_client()
 key = t.get_remote_server_key()

 event = threading.Event()
 t.auth_password(username=username, password=password, event=event)
 event.wait()

 if not t.is_authenticated():
 print not authenticated

 output:
 not authenticated


This is a different problem I guess, now you are usin get_remote_server_key.
And why are you creating event after calling start_client without
specifying it ?




 On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 
 
 
 
   I am using paramiko to do an SFTP file transfer... I was able to connect 
   to
   the remote server using an SFTP client I have just to make sure that
   username and password are working.. This is the code.
 
   # now, connect and use paramiko Transport to negotiate SSH2 across the
   connection
 
   sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
   sock.connect((hostname, port))
 
   t = paramiko.Transport(sock)
 
   event = threading.Event()
 
   t.start_client(event)
 
   event.wait(15)
 
   if not t.is_active():
 
   print 'SSH negotiation failed.'
 
   sys.exit(1)
 
   else:
 
   print SSH negotiation sucessful
 
   event.clear()
 
   t.auth_password(username=username, password=password,event=event)
 
   if not t.is_authenticated():
 
   print not authenticated
 
   output:
 
   SSH negotiation successful
 
   not authenticated
 
   Tarun
 
   Waterstone Capital Management
 
   2 Carlson Parkway, Suite 260
 
   Plymouth, MN 55447
 
   Direct: 952-697-4123
 
   Cell:612-205-2587
Disclaimer This e-mail and any attachments is confidential and intended
   solely for the use of the individual(s) to whom it is addressed. Any views
   or opinions presented are solely those of the author and do not 
   necessarily
   represent those of Waterstone Capital Management, L.P and affiliates. If 
   you
   are not the intended recipient, be advised that you have received this
   e-mail in error and that any use, dissemination, printing, forwarding or
   copying of this email is strictly prohibited. Please contact the sender if
   you have received this e-mail in error. You should also be aware that
   e-mails are susceptible to interference and you should not assume that the
   contents of this e-mail originated from the sender above or that they have
   been accurately reproduced in their original form. Waterstone Capital
   Management, L.P. and affiliates accepts no responsibility for information,
   or errors or omissions in this e-mail or use or misuse thereof. If in 
   doubt,
   please verify the authenticity with the sender.
   --
  http://mail.python.org/mailman/listinfo/python-list
 
  You are missing an event.wait() after t.auth_password.
  Also, why are you passing this magic value 15 to event.wait() ? That
  parameter is passed to class _Verbose to indicate if debug messages
  should be displayed or not, so typical values would be 0/1 or
  False/True.
 
  --
  -- Guilherme H. Polo Goncalves

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



-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko

2008-01-16 Thread Tarun Kapoor
On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:



  # now, connect and use paramiko Transport to negotiate SSH2 across
  the connection
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.connect((hostname, port))

  t = paramiko.Transport(sock)
  t.start_client()
  key = t.get_remote_server_key()

  event = threading.Event()
  t.auth_password(username=username, password=password, event=event)
  event.wait()

  if not t.is_authenticated():
  print not authenticated

  output:
  not authenticated

 This is a different problem I guess, now you are usin get_remote_server_key.
 And why are you creating event after calling start_client without
 specifying it ?





  On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
   2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

I am using paramiko to do an SFTP file transfer... I was able to 
connect to
the remote server using an SFTP client I have just to make sure that
username and password are working.. This is the code.

# now, connect and use paramiko Transport to negotiate SSH2 across 
the
connection

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.connect((hostname, port))

t = paramiko.Transport(sock)

event = threading.Event()

t.start_client(event)

event.wait(15)

if not t.is_active():

print 'SSH negotiation failed.'

sys.exit(1)

else:

print SSH negotiation sucessful

event.clear()

t.auth_password(username=username, password=password,event=event)

if not t.is_authenticated():

print not authenticated

output:

SSH negotiation successful

not authenticated

Tarun

Waterstone Capital Management

2 Carlson Parkway, Suite 260

Plymouth, MN 55447

Direct: 952-697-4123

Cell:612-205-2587
 Disclaimer This e-mail and any attachments is confidential and intended
solely for the use of the individual(s) to whom it is addressed. Any 
views
or opinions presented are solely those of the author and do not 
necessarily
represent those of Waterstone Capital Management, L.P and affiliates. 
If you
are not the intended recipient, be advised that you have received this
e-mail in error and that any use, dissemination, printing, forwarding or
copying of this email is strictly prohibited. Please contact the sender 
if
you have received this e-mail in error. You should also be aware that
e-mails are susceptible to interference and you should not assume that 
the
contents of this e-mail originated from the sender above or that they 
have
been accurately reproduced in their original form. Waterstone Capital
Management, L.P. and affiliates accepts no responsibility for 
information,
or errors or omissions in this e-mail or use or misuse thereof. If in 
doubt,
please verify the authenticity with the sender.
--
   http://mail.python.org/mailman/listinfo/python-list

   You are missing an event.wait() after t.auth_password.
   Also, why are you passing this magic value 15 to event.wait() ? That
   parameter is passed to class _Verbose to indicate if debug messages
   should be displayed or not, so typical values would be 0/1 or
   False/True.

   --
   -- Guilherme H. Polo Goncalves

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

 --
 -- Guilherme H. Polo Goncalves


ok here is the problem... I don't know what is the correct way... The
only demos i have from the paramiko library use a hostkeyfile. since i
don't have that i thought i would use the get_remote_key to get the
key and then connect it using the code in the demo.. But clearly
nothing is working...I should not HAVE to use the key since i should
be able to authenticate using the password...

Can you please suggest the right way to go ?

Thanks for your time !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting Thread Gotcha

2008-01-16 Thread Dan
On Jan 16, 11:06 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Hendrik van Rooyen wrote:
  Dan the,,,ail.com wrote:

   keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))

  Needs to be
   keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))

  Commas are important!

  -Dan

  Absolutely! - well spotted!

  As the first correct respondent, you win the freedom to spend a week in
  Naboomspruit at your own expense.

  It would have been nice, however, to have gotten something like:

  TypeError - This routine needs a tuple.

  instead of the silent in line calling of the routine in question,
  while failing actually to start a new thread.

 You can't prevent the silent inline-calling - otherwise, how would you do
 this:

 def compute_thread_target():
 def target():
 pass
 return target

 thread.start_new_thread(compute_thread_target())

 Of course start_new_thread could throw an error if it got nothing callable
 as first argument. No idea why it doesn't.

 Diez

Of course, in his case, having start_new_thread throw an error
wouldn't have helped, since he went into an infinite loop while
evaluating the parameters for start_new_thread.

Would it be possible to have pychecker (or some such) warn that there
is an insufficient parameter count to start_new_thread? I guess that
would require knowing the type of thread. . .

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


Re: paramiko

2008-01-16 Thread Guilherme Polo
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 
 
   # now, connect and use paramiko Transport to negotiate SSH2 across
   the connection
   sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   sock.connect((hostname, port))
 
   t = paramiko.Transport(sock)
   t.start_client()
   key = t.get_remote_server_key()
 
   event = threading.Event()
   t.auth_password(username=username, password=password, event=event)
   event.wait()
 
   if not t.is_authenticated():
   print not authenticated
 
   output:
   not authenticated
 
  This is a different problem I guess, now you are usin get_remote_server_key.
  And why are you creating event after calling start_client without
  specifying it ?
 
 
 
 
 
   On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 I am using paramiko to do an SFTP file transfer... I was able to 
 connect to
 the remote server using an SFTP client I have just to make sure that
 username and password are working.. This is the code.
 
 # now, connect and use paramiko Transport to negotiate SSH2 
 across the
 connection
 
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 sock.connect((hostname, port))
 
 t = paramiko.Transport(sock)
 
 event = threading.Event()
 
 t.start_client(event)
 
 event.wait(15)
 
 if not t.is_active():
 
 print 'SSH negotiation failed.'
 
 sys.exit(1)
 
 else:
 
 print SSH negotiation sucessful
 
 event.clear()
 
 t.auth_password(username=username, password=password,event=event)
 
 if not t.is_authenticated():
 
 print not authenticated
 
 output:
 
 SSH negotiation successful
 
 not authenticated
 
 Tarun
 
 Waterstone Capital Management
 
 2 Carlson Parkway, Suite 260
 
 Plymouth, MN 55447
 
 Direct: 952-697-4123
 
 Cell:612-205-2587
  Disclaimer This e-mail and any attachments is confidential and 
 intended
 solely for the use of the individual(s) to whom it is addressed. Any 
 views
 or opinions presented are solely those of the author and do not 
 necessarily
 represent those of Waterstone Capital Management, L.P and affiliates. 
 If you
 are not the intended recipient, be advised that you have received this
 e-mail in error and that any use, dissemination, printing, forwarding 
 or
 copying of this email is strictly prohibited. Please contact the 
 sender if
 you have received this e-mail in error. You should also be aware that
 e-mails are susceptible to interference and you should not assume 
 that the
 contents of this e-mail originated from the sender above or that they 
 have
 been accurately reproduced in their original form. Waterstone Capital
 Management, L.P. and affiliates accepts no responsibility for 
 information,
 or errors or omissions in this e-mail or use or misuse thereof. If in 
 doubt,
 please verify the authenticity with the sender.
 --
http://mail.python.org/mailman/listinfo/python-list
 
You are missing an event.wait() after t.auth_password.
Also, why are you passing this magic value 15 to event.wait() ? That
parameter is passed to class _Verbose to indicate if debug messages
should be displayed or not, so typical values would be 0/1 or
False/True.
 
--
-- Guilherme H. Polo Goncalves
 
   --
  http://mail.python.org/mailman/listinfo/python-list
 
  --
  -- Guilherme H. Polo Goncalves


 ok here is the problem... I don't know what is the correct way... The
 only demos i have from the paramiko library use a hostkeyfile. since i
 don't have that i thought i would use the get_remote_key to get the
 key and then connect it using the code in the demo.. But clearly
 nothing is working...I should not HAVE to use the key since i should
 be able to authenticate using the password...

 Can you please suggest the right way to go ?

You don't need to use key to authenticate using username and password,
indeed. And you don't. Your first email was almost correct, you just
needed to add event.wait() after t.auth_password. It worked here after
doing that change. You can check out my version:

import sys
import socket
import paramiko
import threading

if len(sys.argv) != 4:
print %s hostname user password % sys.argv[0]
sys.exit(1)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((sys.argv[1], 22))

t = paramiko.Transport(sock)
event = threading.Event()
t.start_client(event)

event.wait()

if not t.is_active():
print 'SSH negotiation failed.'
sys.exit(1)
else:
print SSH negotiation sucessful

event.clear()
t.auth_password(username=sys.argv[2], 

Help with python shell

2008-01-16 Thread cbmeeks
I just upgraded my Python install up to version 2.5.1 (from 2.4.x)
using source code and compiling.

Everything went fine until I enter the command line mode and press any
arrow keys.

When I press UP arrow, I was getting my previous command as always but
now I get:   ^[[A

What can I do to fix this??

Thanks!

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


Re: Interesting Thread Gotcha

2008-01-16 Thread Diez B. Roggisch
Dan schrieb:
 On Jan 16, 11:06 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Hendrik van Rooyen wrote:
 Dan the,,,ail.com wrote:
 keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))
 Needs to be
 keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))
 Commas are important!
 -Dan
 Absolutely! - well spotted!
 As the first correct respondent, you win the freedom to spend a week in
 Naboomspruit at your own expense.
 It would have been nice, however, to have gotten something like:
 TypeError - This routine needs a tuple.
 instead of the silent in line calling of the routine in question,
 while failing actually to start a new thread.
 You can't prevent the silent inline-calling - otherwise, how would you do
 this:

 def compute_thread_target():
 def target():
 pass
 return target

 thread.start_new_thread(compute_thread_target())

 Of course start_new_thread could throw an error if it got nothing callable
 as first argument. No idea why it doesn't.

 Diez
 
 Of course, in his case, having start_new_thread throw an error
 wouldn't have helped, since he went into an infinite loop while
 evaluating the parameters for start_new_thread.
 
 Would it be possible to have pychecker (or some such) warn that there
 is an insufficient parameter count to start_new_thread? I guess that
 would require knowing the type of thread. . .

What has this to do with the second argument? It's perfectly legal to 
have a function as thread-target that takes no arguments at all, so 
enforcing a second argument wouldn't be helpful - all it would do is to 
force all developers that don't need an argument tuple to pass the empty 
tuple. So there was no insufficient argument count.

And none of these would solve the underlying problem that in python 
expressions are evaluated eagerly. Changing that would mean that you end 
up with a totally new language.

the only thing that could help to a certain extend would be static 
types. Which we don't want here :)

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


Re: Help with python shell

2008-01-16 Thread Diez B. Roggisch
cbmeeks schrieb:
 I just upgraded my Python install up to version 2.5.1 (from 2.4.x)
 using source code and compiling.
 
 Everything went fine until I enter the command line mode and press any
 arrow keys.
 
 When I press UP arrow, I was getting my previous command as always but
 now I get:   ^[[A
 
 What can I do to fix this??

Compiling with readline support? I guess that's missing.

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


Current Special Vicoden

2008-01-16 Thread hetileva69812
Living in Pain. We can help

Pain Meds Online

discoveyamazing.com


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


Re: Interesting Thread Gotcha

2008-01-16 Thread Dan
On Jan 16, 1:33 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Dan schrieb:



  On Jan 16, 11:06 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Hendrik van Rooyen wrote:
  Dan the,,,ail.com wrote:
  keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))
  Needs to be
  keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))
  Commas are important!
  -Dan
  Absolutely! - well spotted!
  As the first correct respondent, you win the freedom to spend a week in
  Naboomspruit at your own expense.
  It would have been nice, however, to have gotten something like:
  TypeError - This routine needs a tuple.
  instead of the silent in line calling of the routine in question,
  while failing actually to start a new thread.
  You can't prevent the silent inline-calling - otherwise, how would you do
  this:

  def compute_thread_target():
  def target():
  pass
  return target

  thread.start_new_thread(compute_thread_target())

  Of course start_new_thread could throw an error if it got nothing callable
  as first argument. No idea why it doesn't.

  Diez

  Of course, in his case, having start_new_thread throw an error
  wouldn't have helped, since he went into an infinite loop while
  evaluating the parameters for start_new_thread.

  Would it be possible to have pychecker (or some such) warn that there
  is an insufficient parameter count to start_new_thread? I guess that
  would require knowing the type of thread. . .

 What has this to do with the second argument? It's perfectly legal to
 have a function as thread-target that takes no arguments at all, so
 enforcing a second argument wouldn't be helpful - all it would do is to
 force all developers that don't need an argument tuple to pass the empty
 tuple. So there was no insufficient argument count.

 And none of these would solve the underlying problem that in python
 expressions are evaluated eagerly. Changing that would mean that you end
 up with a totally new language.

 the only thing that could help to a certain extend would be static
 types. Which we don't want here :)

 Diez

It doesn't seem to be legal in my version of python (or the doc):

 import thread
 def bat():
print hello


 thread.start_new_thread(bat)

Traceback (most recent call last):
  File pyshell#12, line 1, in module
thread.start_new_thread(bat)
TypeError: start_new_thread expected at least 2 arguments, got 1
 thread.start_new_thread(bat, ())
2256hello




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


Re: A question about event handlers with wxPython

2008-01-16 Thread Erik Lind

Mike Driscoll [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Jan 15, 2:20 pm, Erik Lind [EMAIL PROTECTED] wrote:
 That all looks cool. I will experiment more. I'm a bit slow on this as 
 only
 two weeks old so far.

 Thanks for the patience

 No problem. I'm pretty slow with some toolkits too...such as
 SQLAlchemy. Ugh.

 Mike

BTW,

The wxPython group that you mentionedis that 
http://wxforum.shadonet.com/?





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


Re: MSI read support in msilib?

2008-01-16 Thread Martin v. Löwis
 The introduction from the msilib documentation in python 2.5 claims it
 supports reading an msi.  However on the Record class there is only a
 GetFieldCount() method and some Set*() methods.  I was expecting to
 see GetString() and GetInteger() methods to be able to read the
 values.
 
 Maybe I'm missing something? 

I think you are right - there is indeed stuff missing; few people have
noticed so far.

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


Re: A question about event handlers with wxPython

2008-01-16 Thread Mike Driscoll
On Jan 16, 12:45 pm, Erik Lind [EMAIL PROTECTED] wrote:
 Mike Driscoll [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

  On Jan 15, 2:20 pm, Erik Lind [EMAIL PROTECTED] wrote:
  That all looks cool. I will experiment more. I'm a bit slow on this as
  only
  two weeks old so far.

  Thanks for the patience

  No problem. I'm pretty slow with some toolkits too...such as
  SQLAlchemy. Ugh.

  Mike

 BTW,

 The wxPython group that you mentionedis thathttp://wxforum.shadonet.com/  
  ?

I think those are C++ users using the pure C++ wx. I meant the
following:

http://wxpython.org/maillist.php

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


Creating unique combinations from lists

2008-01-16 Thread breal
I have three lists... for instance

a = ['big', 'small', 'medium'];
b = ['old', 'new'];
c = ['blue', 'green'];

I want to take those and end up with all of the combinations they
create like the following lists
['big', 'old', 'blue']
['small', 'old', 'blue']
['medium', 'old', 'blue']
['big', 'old', 'green']
['small', 'old', 'green']
['medium', 'small', 'green']
['big', 'new', 'blue']
['small', 'new', 'blue']
['medium', 'new', 'blue']
['big', 'new', 'green']
['small', 'new', 'green']
['medium', 'new', 'green' ]

I could do nested for ... in loops, but was looking for a Pythonic way
to do this.  Ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting Thread Gotcha

2008-01-16 Thread Diez B. Roggisch
Dan schrieb:
 On Jan 16, 1:33 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Dan schrieb:



 On Jan 16, 11:06 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Hendrik van Rooyen wrote:
 Dan the,,,ail.com wrote:
 keyboard_thread = thread.start_new_thread(kbd_driver (port_q,kbd_q))
 Needs to be
 keyboard_thread = thread.start_new_thread(kbd_driver, (port_q,kbd_q))
 Commas are important!
 -Dan
 Absolutely! - well spotted!
 As the first correct respondent, you win the freedom to spend a week in
 Naboomspruit at your own expense.
 It would have been nice, however, to have gotten something like:
 TypeError - This routine needs a tuple.
 instead of the silent in line calling of the routine in question,
 while failing actually to start a new thread.
 You can't prevent the silent inline-calling - otherwise, how would you do
 this:
 def compute_thread_target():
 def target():
 pass
 return target
 thread.start_new_thread(compute_thread_target())
 Of course start_new_thread could throw an error if it got nothing callable
 as first argument. No idea why it doesn't.
 Diez
 Of course, in his case, having start_new_thread throw an error
 wouldn't have helped, since he went into an infinite loop while
 evaluating the parameters for start_new_thread.
 Would it be possible to have pychecker (or some such) warn that there
 is an insufficient parameter count to start_new_thread? I guess that
 would require knowing the type of thread. . .
 What has this to do with the second argument? It's perfectly legal to
 have a function as thread-target that takes no arguments at all, so
 enforcing a second argument wouldn't be helpful - all it would do is to
 force all developers that don't need an argument tuple to pass the empty
 tuple. So there was no insufficient argument count.

 And none of these would solve the underlying problem that in python
 expressions are evaluated eagerly. Changing that would mean that you end
 up with a totally new language.

 the only thing that could help to a certain extend would be static
 types. Which we don't want here :)

 Diez
 
 It doesn't seem to be legal in my version of python (or the doc):
 
 import thread
 def bat():
   print hello
 
 
 thread.start_new_thread(bat)
 
 Traceback (most recent call last):
   File pyshell#12, line 1, in module
 thread.start_new_thread(bat)
 TypeError: start_new_thread expected at least 2 arguments, got 1
 thread.start_new_thread(bat, ())
 2256hello

Ah, I thought it was optional, as in the threading.Thread(target=..., 
args=)-version. Sorry for not looking that up.

Then you'd might stand a chance that pychecker can find such a situation 
- but of course not on a general level, as in the above - that would 
only work with type-annotations.



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


Re: Help with python shell

2008-01-16 Thread cbmeeks
On Jan 16, 1:33 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 cbmeeks schrieb:

  I just upgraded my Python install up to version 2.5.1 (from 2.4.x)
  using source code and compiling.

  Everything went fine until I enter the command line mode and press any
  arrow keys.

  When I press UP arrow, I was getting my previous command as always but
  now I get:   ^[[A

  What can I do to fix this??

 Compiling with readline support? I guess that's missing.

 Diez

I tried ./configure --enable-readline   but that didn't do the trick.
ARG!!  This is annoying.

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


RE: Creating unique combinations from lists

2008-01-16 Thread Reedick, Andrew


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:python-
 [EMAIL PROTECTED] On Behalf Of breal
 Sent: Wednesday, January 16, 2008 2:15 PM
 To: python-list@python.org
 Subject: Creating unique combinations from lists
 
 I have three lists... for instance
 
 a = ['big', 'small', 'medium'];
 b = ['old', 'new'];
 c = ['blue', 'green'];
 
 I want to take those and end up with all of the combinations they
 create like the following lists
 ['big', 'old', 'blue']
 ['small', 'old', 'blue']
 ['medium', 'old', 'blue']
 ['big', 'old', 'green']
 ['small', 'old', 'green']
 ['medium', 'small', 'green']
 ['big', 'new', 'blue']
 ['small', 'new', 'blue']
 ['medium', 'new', 'blue']
 ['big', 'new', 'green']
 ['small', 'new', 'green']
 ['medium', 'new', 'green' ]
 
 I could do nested for ... in loops, but was looking for a Pythonic way
 to do this.  Ideas?


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

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


handlers.SocketHandler and exceptions

2008-01-16 Thread writeson
Hi all,

On our Linux systems at work I've written a Twisted logging server
that receives log messages from multiple servers/processes to post
them to a log file, essentially serializing all the process log
messages. This works well, that is until I tried this test code:

try:
t = 10 / 0
except Exception, e:
log.exception(divide by zero)

where log is the logger instance retreived from a call to getLogger().
The problem is the handlers.SocketHandler tries to cPickle.dump() the
log record, which in this case contains an exc_info tuple, the last
item of which is a Traceback object. The pickling fails with an
unpickleable error and that's that.

Does anyone have any ideas how to handle this situation? I'd hate to
have to give up using the log.exception(...) call as it's useful to
get strack trace information in the log file.

Thanks in advance,
Doug Farrell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko

2008-01-16 Thread Tarun Kapoor
On Jan 16, 12:22 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:



  On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
   2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

# now, connect and use paramiko Transport to negotiate SSH2 across
the connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))

t = paramiko.Transport(sock)
t.start_client()
key = t.get_remote_server_key()

event = threading.Event()
t.auth_password(username=username, password=password, event=event)
event.wait()

if not t.is_authenticated():
print not authenticated

output:
not authenticated

   This is a different problem I guess, now you are usin 
   get_remote_server_key.
   And why are you creating event after calling start_client without
   specifying it ?

On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

  I am using paramiko to do an SFTP file transfer... I was able to 
  connect to
  the remote server using an SFTP client I have just to make sure that
  username and password are working.. This is the code.

  # now, connect and use paramiko Transport to negotiate SSH2 
  across the
  connection

  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

  sock.connect((hostname, port))

  t = paramiko.Transport(sock)

  event = threading.Event()

  t.start_client(event)

  event.wait(15)

  if not t.is_active():

  print 'SSH negotiation failed.'

  sys.exit(1)

  else:

  print SSH negotiation sucessful

  event.clear()

  t.auth_password(username=username, 
  password=password,event=event)

  if not t.is_authenticated():

  print not authenticated

  output:

  SSH negotiation successful

  not authenticated

  Tarun

  Waterstone Capital Management

  2 Carlson Parkway, Suite 260

  Plymouth, MN 55447

  Direct: 952-697-4123

  Cell:612-205-2587
   Disclaimer This e-mail and any attachments is confidential and 
  intended
  solely for the use of the individual(s) to whom it is addressed. 
  Any views
  or opinions presented are solely those of the author and do not 
  necessarily
  represent those of Waterstone Capital Management, L.P and 
  affiliates. If you
  are not the intended recipient, be advised that you have received 
  this
  e-mail in error and that any use, dissemination, printing, 
  forwarding or
  copying of this email is strictly prohibited. Please contact the 
  sender if
  you have received this e-mail in error. You should also be aware 
  that
  e-mails are susceptible to interference and you should not assume 
  that the
  contents of this e-mail originated from the sender above or that 
  they have
  been accurately reproduced in their original form. Waterstone 
  Capital
  Management, L.P. and affiliates accepts no responsibility for 
  information,
  or errors or omissions in this e-mail or use or misuse thereof. If 
  in doubt,
  please verify the authenticity with the sender.
  --
 http://mail.python.org/mailman/listinfo/python-list

 You are missing an event.wait() after t.auth_password.
 Also, why are you passing this magic value 15 to event.wait() ? That
 parameter is passed to class _Verbose to indicate if debug messages
 should be displayed or not, so typical values would be 0/1 or
 False/True.

 --
 -- Guilherme H. Polo Goncalves

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

   --
   -- Guilherme H. Polo Goncalves

  ok here is the problem... I don't know what is the correct way... The
  only demos i have from the paramiko library use a hostkeyfile. since i
  don't have that i thought i would use the get_remote_key to get the
  key and then connect it using the code in the demo.. But clearly
  nothing is working...I should not HAVE to use the key since i should
  be able to authenticate using the password...

  Can you please suggest the right way to go ?

 You don't need to use key to authenticate using username and password,
 indeed. And you don't. Your first email was almost correct, you just
 needed to add event.wait() after t.auth_password. It worked here after
 doing that change. You can check out my version:

 import sys
 import socket
 import paramiko
 import threading

 if len(sys.argv) != 4:
 print %s hostname user password % sys.argv[0]
 sys.exit(1)

 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((sys.argv[1], 22))

 t = paramiko.Transport(sock)
 event = threading.Event()
 t.start_client(event)

 event.wait()

 if not 

Re: Help with python shell

2008-01-16 Thread Diez B. Roggisch
cbmeeks schrieb:
 On Jan 16, 1:33 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 cbmeeks schrieb:

 I just upgraded my Python install up to version 2.5.1 (from 2.4.x)
 using source code and compiling.
 Everything went fine until I enter the command line mode and press any
 arrow keys.
 When I press UP arrow, I was getting my previous command as always but
 now I get:   ^[[A
 What can I do to fix this??
 Compiling with readline support? I guess that's missing.

 Diez
 
 I tried ./configure --enable-readline   but that didn't do the trick.
 ARG!!  This is annoying.

You don't just need to enable it - the readline lib needs to be 
installed, including the possible devel-package (If you are under linux) 
for the headers.

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


Re: Creating unique combinations from lists

2008-01-16 Thread breal
On Jan 16, 11:33 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
  -Original Message-
  From: [EMAIL PROTECTED] [mailto:python-
  [EMAIL PROTECTED] On Behalf Of breal
  Sent: Wednesday, January 16, 2008 2:15 PM
  To: [EMAIL PROTECTED]
  Subject: Creating unique combinations from lists

  I have three lists... for instance

  a = ['big', 'small', 'medium'];
  b = ['old', 'new'];
  c = ['blue', 'green'];

  I want to take those and end up with all of the combinations they
  create like the following lists
  ['big', 'old', 'blue']
  ['small', 'old', 'blue']
  ['medium', 'old', 'blue']
  ['big', 'old', 'green']
  ['small', 'old', 'green']
  ['medium', 'small', 'green']
  ['big', 'new', 'blue']
  ['small', 'new', 'blue']
  ['medium', 'new', 'blue']
  ['big', 'new', 'green']
  ['small', 'new', 'green']
  ['medium', 'new', 'green' ]

  I could do nested for ... in loops, but was looking for a Pythonic way
  to do this.  Ideas?

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

Thanks for the reply.  I never realized you could use list
comprehension like this... AWESOME!
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Wing IDE 3.0.3 released

2008-01-16 Thread Wingware
Hi,

We're happy to announce version 3.0.3 of Wing IDE, an advanced development
environment for the Python programming language. It is available from:

http://wingware.com/downloads

This release focuses on fixing some usability issues found in Wing 3.0.2,
including fixes for input handling in Debug I/O, Zope debugging on
64-bit Linux, several emacs and vi mode improvements, and about 34
other bugs.

See the change log for details:

http://wingware.com/pub/wingide/3.0.3/CHANGELOG.txt

It is a free upgrade for all Wing 3.0 users.

*About Wing IDE*

Wing IDE is an integrated development environment for the Python programming
language.  It provides powerful debugging, editing, code intelligence,
testing, and search capabilities that reduce development and debugging
time, cut down on coding errors, and make it easier to understand
and navigate Python code.

New features added in Wing 3.0 include:

* Multi-threaded debugger
* Debug value tooltips in editor, debug probe, and interactive shell
* Autocompletion and call tips in debug probe and interactive shell
* Automatically updating project directories
* Testing tool, currently supporting unittest derived tests (*)
* OS Commands tool for executing and interacting with external commands (*)
* Rewritten indentation analysis and conversion (*)
* Introduction of Wing IDE 101, a free edition for beginning programmers
* Available as a .deb package for Debian and Ubuntu
* Support for Stackless Python
* Support for 64 bit Python on Windows and Linux

(*)'d items are available in Wing IDE Professional only.

System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or
Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit).

*Purchasing  Upgrading*

Wing IDE Professional  Wing IDE Personal are commercial software and require
a license  to run.  To upgrade a 2.x license or purchase a new 3.x license:

Upgrade:   https://wingware.com/store/upgrade
Purchase:  https://wingware.com/store/purchase

Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost
1/2 the normal price to upgrade.

-- 
The Wingware Team

Wingware | Python IDE
Advancing Software Development

www.wingware.com


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


Re: Help with python shell

2008-01-16 Thread cbmeeks
On Jan 16, 2:35 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 cbmeeks schrieb:



  On Jan 16, 1:33 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  cbmeeks schrieb:

  I just upgraded my Python install up to version 2.5.1 (from 2.4.x)
  using source code and compiling.
  Everything went fine until I enter the command line mode and press any
  arrow keys.
  When I press UP arrow, I was getting my previous command as always but
  now I get:   ^[[A
  What can I do to fix this??
  Compiling with readline support? I guess that's missing.

  Diez

  I tried ./configure --enable-readline   but that didn't do the trick.
  ARG!!  This is annoying.

 You don't just need to enable it - the readline lib needs to be
 installed, including the possible devel-package (If you are under linux)
 for the headers.

 Diez

That worked!

I had to install readline-devel and rebuild with --enable-readline

Thanks!

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


Re: Creating unique combinations from lists

2008-01-16 Thread Martin v. Löwis
 I could do nested for ... in loops, but was looking for a Pythonic way
 to do this.  Ideas?

I find nested for loops very Pythonic. Explicit is better than implicit,
and simple is better than complex.

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


Re: paramiko

2008-01-16 Thread Guilherme Polo
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 On Jan 16, 12:22 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 
 
   On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 # now, connect and use paramiko Transport to negotiate SSH2 across
 the connection
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((hostname, port))
 
 t = paramiko.Transport(sock)
 t.start_client()
 key = t.get_remote_server_key()
 
 event = threading.Event()
 t.auth_password(username=username, password=password, event=event)
 event.wait()
 
 if not t.is_authenticated():
 print not authenticated
 
 output:
 not authenticated
 
This is a different problem I guess, now you are usin 
get_remote_server_key.
And why are you creating event after calling start_client without
specifying it ?
 
 On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
   I am using paramiko to do an SFTP file transfer... I was able to 
   connect to
   the remote server using an SFTP client I have just to make sure 
   that
   username and password are working.. This is the code.
 
   # now, connect and use paramiko Transport to negotiate SSH2 
   across the
   connection
 
   sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
   sock.connect((hostname, port))
 
   t = paramiko.Transport(sock)
 
   event = threading.Event()
 
   t.start_client(event)
 
   event.wait(15)
 
   if not t.is_active():
 
   print 'SSH negotiation failed.'
 
   sys.exit(1)
 
   else:
 
   print SSH negotiation sucessful
 
   event.clear()
 
   t.auth_password(username=username, 
   password=password,event=event)
 
   if not t.is_authenticated():
 
   print not authenticated
 
   output:
 
   SSH negotiation successful
 
   not authenticated
 
   Tarun
 
   Waterstone Capital Management
 
   2 Carlson Parkway, Suite 260
 
   Plymouth, MN 55447
 
   Direct: 952-697-4123
 
   Cell:612-205-2587
Disclaimer This e-mail and any attachments is confidential and 
   intended
   solely for the use of the individual(s) to whom it is addressed. 
   Any views
   or opinions presented are solely those of the author and do not 
   necessarily
   represent those of Waterstone Capital Management, L.P and 
   affiliates. If you
   are not the intended recipient, be advised that you have received 
   this
   e-mail in error and that any use, dissemination, printing, 
   forwarding or
   copying of this email is strictly prohibited. Please contact the 
   sender if
   you have received this e-mail in error. You should also be aware 
   that
   e-mails are susceptible to interference and you should not assume 
   that the
   contents of this e-mail originated from the sender above or that 
   they have
   been accurately reproduced in their original form. Waterstone 
   Capital
   Management, L.P. and affiliates accepts no responsibility for 
   information,
   or errors or omissions in this e-mail or use or misuse thereof. 
   If in doubt,
   please verify the authenticity with the sender.
   --
  http://mail.python.org/mailman/listinfo/python-list
 
  You are missing an event.wait() after t.auth_password.
  Also, why are you passing this magic value 15 to event.wait() ? 
  That
  parameter is passed to class _Verbose to indicate if debug messages
  should be displayed or not, so typical values would be 0/1 or
  False/True.
 
  --
  -- Guilherme H. Polo Goncalves
 
 --
http://mail.python.org/mailman/listinfo/python-list
 
--
-- Guilherme H. Polo Goncalves
 
   ok here is the problem... I don't know what is the correct way... The
   only demos i have from the paramiko library use a hostkeyfile. since i
   don't have that i thought i would use the get_remote_key to get the
   key and then connect it using the code in the demo.. But clearly
   nothing is working...I should not HAVE to use the key since i should
   be able to authenticate using the password...
 
   Can you please suggest the right way to go ?
 
  You don't need to use key to authenticate using username and password,
  indeed. And you don't. Your first email was almost correct, you just
  needed to add event.wait() after t.auth_password. It worked here after
  doing that change. You can check out my version:
 
  import sys
  import socket
  import paramiko
  import threading
 
  if len(sys.argv) != 4:
  print %s hostname user password % sys.argv[0]
  

Re: itertools.groupby

2008-01-16 Thread Tobiah
Paul Rubin wrote:
 Tobiah [EMAIL PROTECTED] writes:
 I tried doing this with a simple example, but noticed
 that [].sort(func) passes two arguments to func, whereas
 the function expected by groupby() uses only one argument.
 
 Use: [].sort(key=func)

Oh cool.  Thanks.

Only in 2.4+ it seems.


 a = [1,2,3,4,5]
 def sorter(thing):
... return thing % 2 == 0
...
 a.sort(key = sorter)
 print a
[1, 3, 5, 2, 4]



Nifty

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: Help wanted with GTK+ program

2008-01-16 Thread DBenjamin
On Jan 8, 5:49 pm, [EMAIL PROTECTED] wrote:
 I'm working on a simple GTK+ wrapper around the flash Pandora Radio
 player (Pandora.com).

 It's very basic right now but I've got it almost working.
 I'm using gtkmozembed to fetch and use the player and dbus to detect
 multimedia keys.
 The only problem I'm having is that the mozembed widget doesn't seem
 to recognize the fake keypress event sent to it.

 CODE

 #!/usr/bin/env python

 import gtk
 import gtkmozembed
 import dbus
 from dbus.mainloop.glib import DBusGMainLoop

 class Wrapper:
 def __init__(self):
 # Set-up the wrapper for the player

 self.win = gtk.Window() # Create a new GTK window called 'win'

 self.win.set_title(Pandora Player) # Set the title of the
 window
 self.win.set_icon_from_file('favicon.ico') # Set the window
 icon to a web browser icon
 self.win.set_position(gtk.WIN_POS_CENTER) # Position the
 window in the centre of the screen

 self.win.connect(destroy, self.close_window) # Connect the
 'destroy' event to the 'CloseWindow' function, so that the app will
 quit properly

 # Handle media keys under Gnome
 DBusGMainLoop(set_as_default=True)
 bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
 settings = bus.get_object('org.gnome.SettingsDaemon', '/org/
 gnome/SettingsDaemon') # Connect to gnome settings D-Bus
 settings.connect_to_signal(MediaPlayerKeyPressed,
 self.action)

 # Create the browser widget
 gtkmozembed.set_profile_path(/tmp, simple_browser_user) #
 Set a temporary Mozilla profile (works around some bug)
 self.mozbrowser = gtkmozembed.MozEmbed() # Create the browser
 widget

 # Set-up the browser widget before we display it
 self.win.add(self.mozbrowser) # Add the 'mozbrowser' widget to
 the main window 'win'
 self.mozbrowser.load_url(https://www.pandora.com:443/radio/
 tuner_8_2_0_2_pandora.swf) # Load Pandora
 self.mozbrowser.set_size_request(640,540) # Size arrived at
 after careful trial and error
 self.mozbrowser.show() # Needed for correct size

 self.win.show_all() # Show the window

 def PlayPause(self, ):
 event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
 event.keyval = gtk.keysyms.space
 event.time = 0 # assign current time
 self.mozbrowser.grab_focus()
 self.win.emit('key_press_event', event)

 def ThumbsDown(self):
 event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
 event.keyval = gtk.keysyms.minus
 event.time = 0 # assign current time
 self.mozbrowser.grabfocus()
 self.win.emit('key_press_event', event)

 def ThumbsUp(self):
 event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
 event.keyval = gtk.keysyms.plus
 event.time = 0 # assign current time
 self.mozbrowser.grabfocus()
 self.win.emit('key_press_event', event)

 def Skip(self):
 event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
 event.keyval = gtk.keysyms.Right
 event.time = 0 # assign current time
 self.mozbrowser.grabfocus()
 self.win.emit('key_press_event', event)

 # Handles key presses
 def action(self, *keys):
 for key in keys:
 if key == Play:
 self.PlayPause()
 elif key == Stop:
 self.ThumbsUp()
 elif key == Previous:
 self.ThumbsDown()
 elif key == Next:
 self.Skip()

 def close_window(self, caller_widget):
 Close the window and exit the app
 gtk.main_quit() # Close the app fully

 if __name__ == __main__:
 wrapper = Wrapper()
 gtk.main()

I was looking for something like you are writing and seen this post,
maybe it would help you?
http://rjoblog.wordpress.com/2007/12/19/pandora-4-all/
He is showing this url:  https://www.pandora.com/radio/tuner_8_2_0_2_pandora.swf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl Template Toolkit: Now in spicy new Python flavor

2008-01-16 Thread [EMAIL PROTECTED]
On Jan 15, 1:45 pm, George Sakkis [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] wrote:
   I'd like to inform the Python community that the powerful and popular
   Template Toolkit system, previously available only in its original
   Perl implementation, is now also available in a beta Python
   implementation:

  http://tt2.org/python/index.html

   I created this port both as a fun programming project, and for use in
   environments where  Perl is not available, for reasons technical,
   cultural, or otherwise.  The extensive Perl test suites have also been
   ported, and most templates require no or very little modification.

 How does it compare with other mainstream Python template engines
 such as Cheetah, Mako, etc. ?

I can't claim a comprehensive familiarity with Python template
offerings, but all of the packages approved for use at my previous
workplace left me cold.  The most popular were ClearSilver and Django,
and both felt horribly limiting compared to the Template Toolkit,
which I became acquainted with when hacking on Bugzilla some years
ago.  Neither supports what I would consider very basic operations on
the template data.  Nothing like the following can be expressed in
those packages:


from pprint import PrettyPrinter
from template import Template

print Template().processString(
  the list is [% a.pformat(b(c + d)) %],
  { a: PrettyPrinter(2, 40), b: range, c: 10, d: 20 }
)


Here we have a template that includes a method call, a function call,
and simple addition.  Neither Django nor ClearSilver can manage any of
these three things.  Both of those packages offer other features not
found in the Template Toolkit; it was the relative impotence of the
templating systems that drove me to attack the translation.

 Unless I missed it, the documentation
 covers the Perl version only.

The online documentation, yes.  All source-level documentation (from
which the online documentation is largely drawn) has been converted
into Python docstrings in the source code.  They can be read by
browsing the Subversion repository or by importing the code and using
help(); eg:

 import template.stash
 help(template.stash)
... module docs ...
 help(template.stash.Stash)
... class docs ...
 help(template.stash.Stash.get)
... method docs ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import from question

2008-01-16 Thread Terry Reedy

Ben Finney [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| Tobiah [EMAIL PROTECTED] writes:
|
|  This is a little surprising. So from mod import * really copies
|  all of the scalars into new variables in the local namespace.

'Scalar' is not a Python term.  Neither is 'object pointer' really,
except in respect to the CPython implementation.

| No. Nothing is copied. All the objects (remembering that in Python,
| *everything* is an object) created by the code in module 'mod' are
| given names in the current namespace.

To amplify, 'from mod import *' is, I believe, more or less equivalent to

import mod
for name in mod.__all__
   exec %s = mod.%s % name,name
del mod

except, of course, that the imported module would not actually be bound to 
'mod'
(and need deleting) so that there is no conflict with mod containing the 
name 'mod'.




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


Re: searching an XML doc

2008-01-16 Thread Stefan Behnel
grflanagan wrote:
 On Jan 15, 9:33 pm, Gowri [EMAIL PROTECTED] wrote:
 I've been reading about ElementTreee and ElementPath so I could use
 them to find the right elements in the DOM. Unfortunately neither of
 these seem to offer XPath like capabilities where I can find elements
 based on tag, attribute values etc. Are there any libraries which can
 give me XPath like functionality?
 
 Create your query like:
 
 ns0 = '{http://a.b.com/phedex}'
 
 query = '%srequest/%sstatus' % (ns0, ns0)

lxml supports the same thing, BTW, and how to work with namespaces is
explained in the tutorial:

http://codespeak.net/lxml/dev/tutorial.html#namespaces

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


Re: import from question

2008-01-16 Thread Tobiah
Ben Finney wrote:
 Tobiah [EMAIL PROTECTED] writes:
 
 This is a little surprising. So from mod import * really copies
 all of the scalars into new variables in the local namespace.
 
 No. Nothing is copied. All the objects (remembering that in Python,
 *everything* is an object) created by the code in module 'mod' are
 given names in the current namespace.

Yeah, copied.  Just as in:

 a = 3
 b = a
 a = 5
 b
3




given b.py:

##
thing = 0
##

and a.py:

##
from b import *
import b

print thing
print b.thing

b.thing = 1
print b.thing
print thing
###

0
0
1
0

-- 
Posted via a free Usenet account from http://www.teranews.com

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


Re: paramiko

2008-01-16 Thread Tarun Kapoor
On Jan 16, 1:56 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:



  On Jan 16, 12:22 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
   2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
 2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

  # now, connect and use paramiko Transport to negotiate SSH2 
  across
  the connection
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.connect((hostname, port))

  t = paramiko.Transport(sock)
  t.start_client()
  key = t.get_remote_server_key()

  event = threading.Event()
  t.auth_password(username=username, password=password, 
  event=event)
  event.wait()

  if not t.is_authenticated():
  print not authenticated

  output:
  not authenticated

 This is a different problem I guess, now you are usin 
 get_remote_server_key.
 And why are you creating event after calling start_client without
 specifying it ?

  On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
   2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:

I am using paramiko to do an SFTP file transfer... I was able 
to connect to
the remote server using an SFTP client I have just to make sure 
that
username and password are working.. This is the code.

# now, connect and use paramiko Transport to negotiate SSH2 
across the
connection

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.connect((hostname, port))

t = paramiko.Transport(sock)

event = threading.Event()

t.start_client(event)

event.wait(15)

if not t.is_active():

print 'SSH negotiation failed.'

sys.exit(1)

else:

print SSH negotiation sucessful

event.clear()

t.auth_password(username=username, 
password=password,event=event)

if not t.is_authenticated():

print not authenticated

output:

SSH negotiation successful

not authenticated

Tarun

Waterstone Capital Management

2 Carlson Parkway, Suite 260

Plymouth, MN 55447

Direct: 952-697-4123

Cell:612-205-2587
 Disclaimer This e-mail and any attachments is confidential and 
intended
solely for the use of the individual(s) to whom it is 
addressed. Any views
or opinions presented are solely those of the author and do not 
necessarily
represent those of Waterstone Capital Management, L.P and 
affiliates. If you
are not the intended recipient, be advised that you have 
received this
e-mail in error and that any use, dissemination, printing, 
forwarding or
copying of this email is strictly prohibited. Please contact 
the sender if
you have received this e-mail in error. You should also be 
aware that
e-mails are susceptible to interference and you should not 
assume that the
contents of this e-mail originated from the sender above or 
that they have
been accurately reproduced in their original form. Waterstone 
Capital
Management, L.P. and affiliates accepts no responsibility for 
information,
or errors or omissions in this e-mail or use or misuse thereof. 
If in doubt,
please verify the authenticity with the sender.
--
   http://mail.python.org/mailman/listinfo/python-list

   You are missing an event.wait() after t.auth_password.
   Also, why are you passing this magic value 15 to event.wait() ? 
   That
   parameter is passed to class _Verbose to indicate if debug 
   messages
   should be displayed or not, so typical values would be 0/1 or
   False/True.

   --
   -- Guilherme H. Polo Goncalves

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

 --
 -- Guilherme H. Polo Goncalves

ok here is the problem... I don't know what is the correct way... The
only demos i have from the paramiko library use a hostkeyfile. since i
don't have that i thought i would use the get_remote_key to get the
key and then connect it using the code in the demo.. But clearly
nothing is working...I should not HAVE to use the key since i should
be able to authenticate using the password...

Can you please suggest the right way to go ?

   You don't need to use key to authenticate using username and password,
   indeed. And you don't. Your first email was almost correct, you just
   needed to add event.wait() after t.auth_password. It worked here after
   doing that change. You can check out my version:

   

Re: module naming conventions

2008-01-16 Thread Terry Reedy

Tobiah [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
|
|  Release your package as free software on the Cheeseshop
|  URL:http://cheeseshop.python.org/. If the name you want is already
|  taken, pick one that will help users distinguish yours from the
|  existing one.
| 
|
| I like this idea.  I developed a library with a name that got
| a couple of obscure software related hits on Google.  I checked
| sourceforge, and found that the name was available, so I stuck
| my flag in the dirt.
|
| It was a python module, so I suppose I will have to look into
| the cheeseshop.  Is that as open as sourceforge, or is it only
| for mature, sophisticated modules?

Look at the cheeseshop page, but I would say that 'mature' and
'sophisticated' are too high a bar.  'Potentially useful and 
not-known-to-be-buggy'
should be more like it. 



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


Re: paramiko

2008-01-16 Thread Guilherme Polo
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 On Jan 16, 1:56 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 
 
   On Jan 16, 12:22 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 On Jan 16, 11:38 am, Guilherme Polo [EMAIL PROTECTED] wrote:
  2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
   # now, connect and use paramiko Transport to negotiate SSH2 
   across
   the connection
   sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   sock.connect((hostname, port))
 
   t = paramiko.Transport(sock)
   t.start_client()
   key = t.get_remote_server_key()
 
   event = threading.Event()
   t.auth_password(username=username, password=password, 
   event=event)
   event.wait()
 
   if not t.is_authenticated():
   print not authenticated
 
   output:
   not authenticated
 
  This is a different problem I guess, now you are usin 
  get_remote_server_key.
  And why are you creating event after calling start_client without
  specifying it ?
 
   On Jan 16, 11:11 am, Guilherme Polo [EMAIL PROTECTED] wrote:
2008/1/16, Tarun Kapoor [EMAIL PROTECTED]:
 
 I am using paramiko to do an SFTP file transfer... I was able 
 to connect to
 the remote server using an SFTP client I have just to make 
 sure that
 username and password are working.. This is the code.
 
 # now, connect and use paramiko Transport to negotiate 
 SSH2 across the
 connection
 
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 sock.connect((hostname, port))
 
 t = paramiko.Transport(sock)
 
 event = threading.Event()
 
 t.start_client(event)
 
 event.wait(15)
 
 if not t.is_active():
 
 print 'SSH negotiation failed.'
 
 sys.exit(1)
 
 else:
 
 print SSH negotiation sucessful
 
 event.clear()
 
 t.auth_password(username=username, 
 password=password,event=event)
 
 if not t.is_authenticated():
 
 print not authenticated
 
 output:
 
 SSH negotiation successful
 
 not authenticated
 
 Tarun
 
 Waterstone Capital Management
 
 2 Carlson Parkway, Suite 260
 
 Plymouth, MN 55447
 
 Direct: 952-697-4123
 
 Cell:612-205-2587
  Disclaimer This e-mail and any attachments is confidential 
 and intended
 solely for the use of the individual(s) to whom it is 
 addressed. Any views
 or opinions presented are solely those of the author and do 
 not necessarily
 represent those of Waterstone Capital Management, L.P and 
 affiliates. If you
 are not the intended recipient, be advised that you have 
 received this
 e-mail in error and that any use, dissemination, printing, 
 forwarding or
 copying of this email is strictly prohibited. Please contact 
 the sender if
 you have received this e-mail in error. You should also be 
 aware that
 e-mails are susceptible to interference and you should not 
 assume that the
 contents of this e-mail originated from the sender above or 
 that they have
 been accurately reproduced in their original form. Waterstone 
 Capital
 Management, L.P. and affiliates accepts no responsibility for 
 information,
 or errors or omissions in this e-mail or use or misuse 
 thereof. If in doubt,
 please verify the authenticity with the sender.
 --
http://mail.python.org/mailman/listinfo/python-list
 
You are missing an event.wait() after t.auth_password.
Also, why are you passing this magic value 15 to event.wait() 
? That
parameter is passed to class _Verbose to indicate if debug 
messages
should be displayed or not, so typical values would be 0/1 or
False/True.
 
--
-- Guilherme H. Polo Goncalves
 
   --
  http://mail.python.org/mailman/listinfo/python-list
 
  --
  -- Guilherme H. Polo Goncalves
 
 ok here is the problem... I don't know what is the correct way... The
 only demos i have from the paramiko library use a hostkeyfile. since i
 don't have that i thought i would use the get_remote_key to get the
 key and then connect it using the code in the demo.. But clearly
 nothing is working...I should not HAVE to use the key since i should
 be able to authenticate using the password...
 
 Can you please suggest the right way to go ?
 
You don't need to use key to authenticate using username and password,

Re: Creating unique combinations from lists

2008-01-16 Thread Tim Chase
 a = ['big', 'small', 'medium'];
 b = ['old', 'new'];
 c = ['blue', 'green'];
 
 I want to take those and end up with all of the combinations they
 create like the following lists
 ['big', 'old', 'blue']
 ['small', 'old', 'blue']
 ['medium', 'old', 'blue']
 ['big', 'old', 'green']
 ['small', 'old', 'green']
 ['medium', 'small', 'green']
 ['big', 'new', 'blue']
 ['small', 'new', 'blue']
 ['medium', 'new', 'blue']
 ['big', 'new', 'green']
 ['small', 'new', 'green']
 ['medium', 'new', 'green' ]
 
 I could do nested for ... in loops, but was looking for a Pythonic way
 to do this.  Ideas?

You can use a recursive generator:

   def iterall(*iterables):
 if iterables:
   for head in iterables[0]:
 for remainder in iterall(*iterables[1:]):
   yield [head] + remainder
 else:
   yield []

   for thing in iterall(
   ['big', 'medium', 'small'],
   ['old', 'new'],
   ['blue', 'green'],
   ):
 print thing

The two for-loops plus recursion should handle any number of 
parameters, so if you were so inclined, you could do

   for thing in iterall(
   ['big', 'medium', 'small'],
   ['old', 'new'],
   ['blue', 'green'],
   ['smelly', 'fragrant'],
   ['spatula', 'avocado'],
   ):
 print thing

and get all 3*2*2*2*2 items.  Or count in binary:

   for i, bitstream in enumerate(iterall(
   [0, 1],
   [0, 1],
   [0, 1],
   [0, 1],
   [0, 1],
   [0, 1],
   )):
 print ''.join(map(str, bitstream)), '=', i

When you're iterating over combinations of items in groups of 
lists, I prefer the clarity of this over something like

   [(a,b,c,d,e) for a in [0,1] for b in [0,1] for c in [0,1] for 
d in [0,1] for e in [0,1]]


-tkc


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


Re: error/warning color customization in interactive console?

2008-01-16 Thread Zentrader
On Jan 15, 5:44 pm, yhvh [EMAIL PROTECTED] wrote:
 Is it possible to output error messages in a different color?
 I'm using Terminal on Gnome.

For the few times that I want to do this, this simple form works with
xterm.
for j in range(1,10):
   os.system(tput setaf +str(j))
   print test for , j
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating unique combinations from lists

2008-01-16 Thread Matimus
On Jan 16, 11:15 am, breal [EMAIL PROTECTED] wrote:
 I have three lists... for instance

 a = ['big', 'small', 'medium'];
 b = ['old', 'new'];
 c = ['blue', 'green'];

 I want to take those and end up with all of the combinations they
 create like the following lists
 ['big', 'old', 'blue']
 ['small', 'old', 'blue']
 ['medium', 'old', 'blue']
 ['big', 'old', 'green']
 ['small', 'old', 'green']
 ['medium', 'small', 'green']
 ['big', 'new', 'blue']
 ['small', 'new', 'blue']
 ['medium', 'new', 'blue']
 ['big', 'new', 'green']
 ['small', 'new', 'green']
 ['medium', 'new', 'green' ]

 I could do nested for ... in loops, but was looking for a Pythonic way
 to do this.  Ideas?

I would probably just create a generator:

def permute(a,b,c):
for x in a:
for y in b:
for z in c:
yield [x,y,z]

all_combos = list(permute(
['big', 'small', 'medium'],
['old', 'new'],
['blue', 'green']))

print all_combos


I'm using nested for loops, but I sure find it easy to read that way.
Though, using list comprehension does pretty much the same thing. It
appears that Tim Chase has posted a more generic version of the above.

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


Re: import from question

2008-01-16 Thread Ben Finney
Tobiah [EMAIL PROTECTED] writes:

 Ben Finney wrote:
  Tobiah [EMAIL PROTECTED] writes:
 
  This is a little surprising. So from mod import * really copies
  all of the scalars into new variables in the local namespace.
 
  No. Nothing is copied. All the objects (remembering that in Python,
  *everything* is an object) created by the code in module 'mod' are
  given names in the current namespace.
 
 Yeah, copied.  Just as in:
 
  a = 3
  b = a
  a = 5
  b
 3
 

Again, those aren't copies. There is only one instance of each value,
referenced by multiple names. This is made clearer by using a mutable
value:

 a = [1, 2, 3]
 b = a
 c = b
 a = [4, 5, 6]
 a, b, c
([4, 5, 6], [1, 2, 3], [1, 2, 3])

 a.append(spam)
 b.append(eggs)
 a, b, c
([4, 5, 6, 'spam'], [1, 2, 3, 'eggs'], [1, 2, 3, 'eggs'])

The value referenced by 'b' and 'c' is one instance; they don't have
copies of the value. Assignment binds a reference to a value, it
doesn't make a copy.

A copy is what's implemented by the standard library 'copy' module,
hence the name.

-- 
 \   Whenever you read a good book, it's like the author is right |
  `\   there, in the room talking to you, which is why I don't like to |
_o__)read good books.  -- Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating unique combinations from lists

2008-01-16 Thread Steven D'Aprano
On Wed, 16 Jan 2008 11:15:16 -0800, breal wrote:

 I could do nested for ... in loops, but was looking for a Pythonic way
 to do this.  Ideas?

What makes you think nested loops aren't Pythonic?


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


  1   2   >