SQLObject 0.8.2

2007-04-12 Thread Oleg Broytmann
Hello!

I'm pleased to announce the 0.8.2 release of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and
Firebird.  It also has newly added support for Sybase, MSSQL and MaxDB (also
known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.8.2

News and changes:
http://sqlobject.org/News.html


What's New
==

News since 0.8.1


* Fixed ConnectionHub.doInTransaction() - if the original connection was
  processConnection - reset processConnection, not threadConnection.

* Fixed a bug in DateValidator caused by datetime being a subclass of date.

* Fixed test_deep_inheritance.py - setup classes in the correct order
  (required for Postgres 8.0+ which is strict about referential integrity).

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[ANN] mlabwrap-1.0final

2007-04-12 Thread Alexander Schmolck
I'm pleased to finally announce mlabwrap-1.0:

Project website
---
http://mlabwrap.sourceforge.net/


Description
---

Mlabwrap-1.0 is a high-level python to matlab(tm) bridge that makes calling
matlab functions from python almost as convenient as using a normal python
library. It is available under a very liberal license (BSD/MIT) and should
work on all major platforms and (non-ancient) python and matlab versions and
either numpy or Numeric (Numeric support will be dropped in the future).


Examples


Creating a simple line plot:

 from mlabwrap import mlab; mlab.plot([1,2,3],'-o')

Creating a surface plot:

 from mlabwrap import mlab; from numpy import *
 xx = arange(-2*pi, 2*pi, 0.2)
 mlab.surf(subtract.outer(sin(xx),cos(xx)))

Creating a neural network and training it on the xor problem (requires netlab)

 net = mlab.mlp(2,3,1,'logistic')
 net = mlab.mlptrain(net, [[1,1], [0,0], [1,0], [0,1]], [0,0,1,1], 1000)

What the future holds
-

Please note that mlabwrap-1.0 will be the last non-bugfix release with Numeric
support. Future versions of mlabwrap will require numpy be a part of scipy's
scikits infrastructure (so the package name will be ``scikits.mlabwrap``) and
use setuptools rather than distutils so that it should be possible to
automatically download and install via EasyInstall.

The next major version of mlabwrap should also bring more powerful proxying
and marshalling facilities, but the default conversion behavior might be
changed to reflect the fact that matlab is becoming increasingly less
``double`` (-matrix) centric; although wrappers for old-style behavior will be
provided if backwards-incompatible interface changes are introduced, for
upwards compatibility it is recommended to explicitly pass in float64 arrays
rather than e.g. lists of ints if the desired input type that matlab should
see is a double array (i.e. use ``mlab.sin(array([1., 2., 3.])`` rather than
``mlab.sin([1,2,3])`` for production code in order to be on the safe side)).
Please have a look at http://www.scipy.org/Mlabwrap if you're interested in
the ongoing development of mlabwrap and planned features.


Feedback and support


The preferred formum for users to request help and offer feedback and keep
informed about new releases is mlabwrap-user:

 https://lists.sourceforge.net/lists/listinfo/mlabwrap-user

the list is low-volume and subscription is recommended.

Discussion of mlabwrap development takes place on the scipy-dev (please
mention mlabwrap in the subject line):

 http://projects.scipy.org/mailman/listinfo/scipy-dev 

cheers,

Alexander Schmolck, mlabwrap author and maintainer
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Python-URL! - weekly Python news and links (Apr 11)

2007-04-12 Thread Cameron Laird
QOTW:  Dictionaries are one of the most useful things in Python. Make sure
you know how to take adavantage of them... - Jeremy Sanders

Python has consistently failed to disappoint me. - Tal Einat


super() only works on new-style classes ... and has its own
set of gotchas:
http://groups.google.com/group/comp.lang.python/msg/f44c8c09e1593dcf

Yes, there certainly *are* times that connection to a terminal
makes a difference.  There also are ways to control that difference:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b5975d27da432e92/

Michael Bentley reports satisfaction with Wing IDE's ability
to debug multithreading Python:
http://groups.google.com/group/comp.lang.python/msg/f44c8c09e1593dcf

Does Python know about such matters as 'gt;' ('')?  Sure:
just import htmlentitydefs:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f96723282376f8c/

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d09417aedc1b807b/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

The Python Papers aims to publish the efforts of Python enthusiats.
http://pythonpapers.org/

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/python/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all
The old Python To-Do List now lives principally in a
SourceForge reincarnation.

Omaha Python Users Group - Meeting April 12, 2007

2007-04-12 Thread dundeemt
Omaha Python Users Group
http://www.OmahaPython.org

When: April 12, 2007 @ 7:00pm
Where:
  Reboot The User
  13416 A Street
  Omaha, NE 68144

For More Information, please see http://www.omahapython.org/

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

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


Re: __file__

2007-04-12 Thread 7stud
On Apr 11, 6:55 am, John Machin [EMAIL PROTECTED] wrote:
 On Apr 11, 8:03 pm, 7stud [EMAIL PROTECTED] wrote:



  Hi,

  Thanks for the response.

  On Apr 11, 12:49 am, Gabriel Genellina [EMAIL PROTECTED]
  wrote:

   __file__ corresponds to the filename used to locate and load the module,
   whatever it is. When the module is found on the current directory
   (corresponding to '' in sys.path), you get just the filename; if sys.path
   contains a relative path, that's what you get; the same for any absolute
   path.
   Whatever path worked to find and load the module, that's stored as
   __file__.

   If you plan to use it, it's a good idea to make it early into an absolute
   path (using os.path.abspath(__file__)) just in case the current directory
   changes.

  That last part doesn't seem to fit with your description above.  What
  does the current working directory have to do with the path that was
  used to load a module?  I would think the path that was used to load a
  module is constant.

 You are correct, but that is not what GG was talking about. Here is an
 example of what he meant:

 While your cwd is /bar, you load module foo from a *relative*( path,
 e.g. ./foo.py. If you do the os.path.abspath(./foo.py) immediately
 as recommended, you get the correct answer: /bar/foo.py. However if
 you change your cwd to /zot, then do the os.path.abspath(./foo.py),
 you get /zot/foo.py which is a nonsense.

 HTH,
 John

Thanks for all the help.

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


Re: pop() clarification

2007-04-12 Thread Bruno Desthuilliers
Hamilton, William a écrit :
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:python-
 [EMAIL PROTECTED] On Behalf Of Scott

 I understand all that.  What I don't understand is why all the
 documentation
 I see says, When removing a specific element from a list using pop()
 it
 must be in this format: list.pop([i]).
 At first I took that to mean that list.pop(i) would return some type
 of
 error, but it doesn't.
 I can't find any documentation saying that this rule that I keep
 reading
 about (again list.pop([i]) ) is the only format to use when removing a
 specific element because..with the explaination to follow.
 
 I believe that the [i] notation is to indicate that it has to be a valid
 index to your list.

And you're wrong. Well, it has to be a valid index, but this has nothing 
to do with the notation used. Google for Backus-Naur Form...

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


Re: py script modify it's Modified Time?

2007-04-12 Thread est
On 4月12日, 上午2时26分, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Wed, 11 Apr 2007 10:33:57 -0300, [EMAIL PROTECTED] escribió:

  On Apr 11, 6:14 am, est [EMAIL PROTECTED] wrote:
  I guess os.stat() could retrieve information about ctime, mtime of a
  path, but how can I change them? Is it possible to make it work both
  under Win32 and Linux?

  I am not sure if you can change a creation time of a file on NT, but
  the rest sounds possible; according to this post anyway:

 http://mail.python.org/pipermail/python-list/2001-August/100214.html

 That post is rather old... With os.utime you can set the access and  
 modified time, and it's portable.
 Creation time isn't stored on [the normal filesystems used by] Linux, and  
 on Windows you can use win32file.SetFileTime

  It mentions using the win32 modules, which can be found here:
 http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32_...

 Betterhttps://sourceforge.net/projects/pywin32/

 --
 Gabriel Genellina

Thanks guys ,you are of great healp!

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

redirecting stdout to a file as well as screen

2007-04-12 Thread SamG
How could i make, from inside the program, to have the stdout and
stderr to be printed both to a file as well the terminal(as usual).

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


Dyla 2007: 3rd Workshop on Dynamic Languages and Applications

2007-04-12 Thread alexandre . bergel
Dear colleges,

You might want to consider Dyla'07 as a good venue to present your
work and your favourite programming language.

Regards,
Alexandre


**
Call for Papers
Dyla 2007: 3rd Workshop on Dynamic Languages and Applications
July 31, 2007, Berlin (Collocated with ECOOP 2007)

http://dyla2007.unibe.ch
**

Objective
=

The goal of this workshop is to act as a forum where we can discuss
new advances in the conception, implementation and application of
object-oriented languages that radically diverge from the statically
typed class-based reflectionless doctrine. The goal of the workshop is
to discuss new as well as older forgotten languages and features in
this  context. Topics of interest include, but are certainly not
limited to:

  - agents, actors, active object, distribution, concurrency and
mobility
  - delegation, prototypes, mixins
  - first-class closures, continuations, environments
  - reflection and meta-programming
  - (dynamic) aspects for dynamic languages
  - higher-order objects  messages
  - ...  other exotic dynamic features which you would categorize as
OO
  - multi-paradigm  static/dynamic-marriages
  - (concurrent/distributed/mobile/aspect) virtual machines
  - optimisation of dynamic languages
  - automated reasoning about dynamic languages
  - regular syntactic schemes (cf. S-expressions, Smalltalk, Self)
  - Smalltalk, Python, Ruby, Scheme, Lisp, Self, ABCL, Prolog, ...
  - ... any topic relevant in applying and/or supporting dynamic
languages.

We solicit high-quality submissions on research results
and/or experience. Submitted papers must be unpublished
and not submitted for publication elsewhere. Submissions
should not exceed 10 pages, LNCS format (www.springer.com/lncs).


Submission
==

Prospective attendees are requested to submit a position paper or an
essay (max 10 pages, references included) on a topic relevant to the
workshop to Alexandre Bergel ([EMAIL PROTECTED]). Submissions
are demanded to be in .pdf format and should arrive before May 13,
2007.

A selection of the best papers will be made, which will require an
extension for an inclusion in a special issue in Electronic
Communications of the EASST  (eceasst.cs.tu-berlin.de). For this
purpose, a new deadline will be set after the workshop.

Moreover, Springer publishes a Workshop-Reader (as in the case of
previous ECOOPs) which appears after the Conference and which contains
Workshop-Reports (written by the organizers) and not the position
papers submitted by the participants.


Important dates
===

Submission due: May 13, 2007
Notification of Authors: May 31, 2007
ECOOP'07 Early Registration Date: June 15th.
Workshop: July 31, 2007


Organisers
==

Alexandre Bergel
Wolfgang De Meuter
Stéphane Ducasse
Oscar Nierstrasz
Roel Wuyts


Program committee
=

Alexandre Bergel(LERO  Trinity College Dublin, Ireland)
Johan Brichau   (Université catholique de Louvain, Belgium)
Pascal Costanza (Vrije Universiteit Brussel, Belgium)
Wolfgang De Meuter  (Vrije Universiteit Brussel, Belgium)
Stéphane Ducasse(University of Annecy, France)
Erik Ernst  (University of Aarhus, Denmark)
Robert Hirschfeld   (Hasso-Plattner-Institut, University of
Potsdam, Germany)
Oscar Nierstrasz(University of Bern, Switzerland)
Matthew Flatt   (University of Utah, USA)
Dave Thomas (Bedarra Research Labs, Canada)
Laurence Tratt  (King's College London, UK)
Roel Wuyts  (IMEC  Université Libre de Bruxelles,
Belgium)

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.software-artist.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.

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


reaching hidden methods + casting

2007-04-12 Thread per9000
Hi,
can I reach a hidden method when doing ugly inheritance in python?

 class A:
... def spin(self, n): print A, n
...
 class B:
... def spin(self, m): print B, m
...
 class C(A,B):
... def spin(self, k): print C, k
...
 myC = C()
 dir(myC)
['__doc__', '__module__', 'spin']

In f.x. the C-family of languages I guess something like this would
call B.spin:
((B)myC).spin(Lancelot); // almost forgot the ';'

Please correct me I am wrong (which I likely am) but as I understand
it this example calls the constructor of int instead of casting it,
right?
 leet = int('1337')
 leet
1337

So is there another way of digging into the past of a class? Or can/
should I create constructors for the classes A, B and C that takes
objects of the other classes?

Or should I have thought about getting unique names before I
implemented the ugly inheritance graph?

/Per

--

Per Erik Strandberg
blog: http://www.pererikstrandberg.se/blog/

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


Re: tuples, index method, Python's design

2007-04-12 Thread Antoon Pardon
On 2007-04-11, Steven D'Aprano [EMAIL PROTECTED] wrote:

 So how about it? All you people who desperately want tuples to grow an
 index method -- will any of you donate your time to write and maintain the
 code?

But as far as I understood the code is already there; the code for
list.index being usable almost as it is.

It doesn't seem to be a question of where to put valuable resource.
AFAIU it is simply a question of do the developers want it or not.

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


sqlite3 question

2007-04-12 Thread Jorgen Bodde
Hi all,

I am using sqlite3 in python, and I wonder if there is a way to know
if there are valid rows returned or not. For example I have a table
song with one entry in it. The ID of that entry is 1, so when I do;

 r = c.execute('select * from song where id = 1')
 for s in r:
... print s
... 
(1, u'Spikedrivers Blues', u'Mississippi John Hurt')

That works. But when I can't restore the row by e.g. an ID that does
not exist, I cannot see any method in 'r' (which is a SQLite.Cursor)
that can tell me if I have rows. As explained in the help, r.rowcount
does not give a valid result because it can't determine how many rows
are restored in advance.

All I can think of is a 'crappy' construction where I use the iterator
to see if there was something in there, but surely, there must be a
better way to know?

 r = c.execute('select * from song where id = 2')
 notfound = True
 for s in r:
... notfound = False
... print s
 if notfound:
... print 'No rows'

I am pretty new with Python, maybe there are some properties of an
iterator / sqlite3 I am not aware of that can tell me how many rows
are there?

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


Re: python regular expression help

2007-04-12 Thread 7stud
On Apr 11, 11:15 pm, [EMAIL PROTECTED] wrote:
 On Apr 11, 9:50 pm, Gabriel Genellina [EMAIL PROTECTED]
 lhs = re.compile(r'\s*(\b\w+\s*=)')
 for s in [ a = 4 b =3.4 5.4 c = 4.5,
 a = 4.5 b = 'h'  'd' c = 4.5 3.5]:
 tokens = lhs.split(s)
 results = [tokens[_] + tokens[_+1] for _ in range(1,len(tokens),

The only thing I can think when I look at that is: what a syntactic
abomination.

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


Re: tuples, index method, Python's design

2007-04-12 Thread Antoon Pardon
On 2007-04-11, Chris Mellon [EMAIL PROTECTED] wrote:
 On 11 Apr 2007 08:37:39 -0700, Paul Boddie [EMAIL PROTECTED] wrote:
 On 11 Apr, 16:14, Chris Mellon [EMAIL PROTECTED] wrote:
 
  If you want a language that just adds whatever methods anyone thinks
  of, along with whatever aliases for it any can think of, to every data
  type, you know where to find Ruby.

 Nobody is asking for Ruby, as far as I can see. I even submitted a
 quick patch to provide tuple.index (a method that has already been
 thought of), given the triviality of the solution, but you won't find
 me asking for a bundle of different convenience methods with all their
 aliases on every object, regardless of whether you can monkey-patch
 them after the fact or not. For example:


 Note that the mail I responded to was using being drunk, not knowing
 any better, and having fun as use cases for the method. That sounds
 like Ruby-style method proliferation to me ;)


 Note that, in that document, index and count are methods of
 MutableSequence. Quite why this should be from a conceptual
 perspective is baffling, but don't underestimate the legacy influence
 in such matters.


 Well, I'm not Guido obviously, but here's why I don't find it baffling.

 There are 2 main reasons why you'd use an immutable sequence for something:
 1) You want to make sure it's not modified by a callee. This is
 unPythonic and mostly unnecessary. Pass them a copy if you're that
 paranoid.

Why then does python itself provide immutables? I find this reasoning
more than baffling. There has been all these arguments about why
it is best to use immutables as dictionary keys. But the moment
the topic changes, someone else comes with the comment that
wanting your sequence to be immuatble is unpythonic.

I once had a problem I like to solve by having a dictionary
where the keys were multidimensional points on an integer grid.
For a number of reasons I thought it would be easier if I could
use lists, but most people argued that would be a bad idea and
that I should use tuples, because they are immutable.

Of course if I now would want to find out if the point is on an
axis and which axis that is, I cannot use index because that is
not available. 

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


Any Pythonistas in Mexico?

2007-04-12 Thread Hugo González Monteverde
Hola,

Leí este mail viejísimo en una lista. Yo uso Python y también quería 
saber quién pythoneaba en México. Todavía estás por ahí?

Saludos,


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


Re: reaching hidden methods + casting

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 04:18:19 -0300, per9000 [EMAIL PROTECTED] escribió:

 Hi,
 can I reach a hidden method when doing ugly inheritance in python?

 class A:
 ... def spin(self, n): print A, n
 ...
 class B:
 ... def spin(self, m): print B, m
 ...
 class C(A,B):
 ... def spin(self, k): print C, k
 ...
 myC = C()
 dir(myC)
 ['__doc__', '__module__', 'spin']

 In f.x. the C-family of languages I guess something like this would
 call B.spin:
 ((B)myC).spin(Lancelot); // almost forgot the ';'

Try this in Python:
B.spin(myC, Lancelot)

You can't ask the instance for myC.spin because that would retrieve  
C.spin; you need B.spin instead. But if you get it this way, it's not  
associated to a specific instance, so you must pass myC explicitely  
(becoming 'self').

 Please correct me I am wrong (which I likely am) but as I understand
 it this example calls the constructor of int instead of casting it,
 right?
 leet = int('1337')
 leet
 1337

Yes.

 So is there another way of digging into the past of a class? Or can/
 should I create constructors for the classes A, B and C that takes
 objects of the other classes?

No need for that. And usually, that's not what you want either: you're  
creating a *different* object that way, not calling a (shadowed) method on  
an existing object.

 Or should I have thought about getting unique names before I
 implemented the ugly inheritance graph?

Perhaps...

-- 
Gabriel Genellina

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


Re: python regular expression help

2007-04-12 Thread Qilong Ren
Hi,

Yeah, a little bit tricky. Actually it is part of some Fortran input file.

Thanks for suggestion! It helps a lot!

Thanks,Qilong

- Original Message 
From: Gabriel Genellina [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, April 11, 2007 9:50:00 PM
Subject: Re: python regular expression help

En Wed, 11 Apr 2007 23:14:01 -0300, Qilong Ren [EMAIL PROTECTED]  
escribió:

 Thanks for reply. That actually is not what I want. Strings I am dealing  
 with may look like this:
  s = 'a = 4.5 b = 'h'  'd' c = 4.5 3.5'
 What I want is
  a = 4.5
  b = 'h' 'd'
  c = 4.5 3.5

That's a bit tricky. You have LHS = RHS where RHS includes all the  
following text *except* the very next word before the following = (which  
is the LHS of the next expression). Or something like that :)

py import re
py s = a = 4.5 b = 'h'  'd' c = 4.5 3.5
py r = re.compile(r\w+\s*=\s*.*?(?=\w+\s*=|$))
py for item in r.findall(s):
...   print item
...
a = 4.5
b = 'h'  'd'
c = 4.5 3.5

-- 
Gabriel Genellina

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







   

Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html -- 
http://mail.python.org/mailman/listinfo/python-list

Re: redirecting stdout to a file as well as screen

2007-04-12 Thread Ant
On Apr 12, 8:14 am, SamG [EMAIL PROTECTED] wrote:
 How could i make, from inside the program, to have the stdout and
 stderr to be printed both to a file as well the terminal(as usual).

One way would be to create a custom class which has the same methods
as the file type, and held a list of file-like objects to write to.
e.g.

class multicaster(object):
def __init__(self, filelist):
self.filelist = filelist

def write(self, str):
for f in self.filelist:
f.write(str)
def writelines(self, str_list):
#etc

Then assign stdout and stderr to a new instance of one of these
objects:

mc = multicaster([sys.stdout, sys.stderr, log_file])
sys.stdout = mc
sys.stderr = mc

HTH


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


Re: Connection problems with irclib

2007-04-12 Thread Cousin Stanley

 Hi. I've written a bot in python, 
 using the irclib by Joel Rosdahl.

 Works fine from my linux box at home, 
 but when I upload it to my shell 
 at veritynet.net, can't seem to get it 
 to connect to an irc server.

 It doesn't report any errors.

 Anyone have any idea how I might go about 
 at least diagnosing the problem?

 Any suggestions might help.

Dropkick P  

  For a bit of inspiration you might take a look
  at Supybot which is a Python-based irc bot 

http://supybot.com

  It's designed to run from your local machine
  and connect to a remote irc server  

  I ran it from home 24/7 with virtually no problems at all
  for several months from a very modest and old Compaq box 
  running Debian Gnu/Linux Sarge which connected via aDSL 

  A brief description from the Debian package manager 

robust and user friendly Python IRC bot Supybot 
is a robust (it doesn't crash), user friendly 
(it's easy to configure) and programmer friendly 
(plugins are *extremely* easy to write) Python IRC bot.
It aims to be an adequate replacement for most existing 
IRC bots. It includes a very flexible and powerful ACL  
system for controlling access to commands, as well as 
more than 50 builtin plugins providing around 400 actual 
commands.


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


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


wxPython, mac, wx.HSCROLL not working

2007-04-12 Thread 7stud
Hi,

I'm trying to allow for a horizontal scrollbar on a textarea, but the
scrollbar won't appear when I enter a long string of text(by leaning
on one character on my keyboard):

import wx

app = wx.App()
win = wx.Frame(None, title=Text Editor, size=(150, 150) )

tb = wx.TextCtrl(win,
pos=(5, 35), size=(100, 100),
style=wx.TE_MULTILINE | wx.HSCROLL)

win.Show()
app.MainLoop()

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


Newbie help with array handling

2007-04-12 Thread loial
I am new to python and am converting an awk script to python

I need to store some data in an array/table of some form

keyvalue1, value1, value2, value3
keyvalue2, value1,value2, value3
keyvalue3, value1,value2,value3
etc

I will later need to sort in keyvalue order and also need to be able
to check if a key already exists

It is not clear how to do this in python. All the examples I see have
just a key and a single value

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 04:14:32 -0300, SamG [EMAIL PROTECTED] escribió:

 How could i make, from inside the program, to have the stdout and
 stderr to be printed both to a file as well the terminal(as usual).

A very minimal example:

import sys

class Tee(file):
 others = ()

 def write(self, data):
 file.write(self, data)
 for f in others:
 f.write(data)

tee = Tee(rc:\temp\output.log,wt)
tee.others = [sys.stdout, sys.stderr]
sys.stdout = sys.stderr = tee

print dir(sys)
sys.foo # error

-- 
Gabriel Genellina

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


Re: About Trolltech QT OpenSource license.

2007-04-12 Thread king kikapu
On Apr 12, 1:02 am, Robert Kern [EMAIL PROTECTED] wrote:
 All parts of the software have to be licensed compatibly with the GPL. The FSF
 has a fairly comprehensive list of the licenses they believe are 
 GPL-compatible.
 The source that you provide needs to be the preferred form for making
 modifications; i.e., you can't use a tool that obfuscates the code. You need 
 to
 provide the scripts that you use to build the software. You have to be careful
 about using patented techniques in your code. The source code must be offered 
 at
 no extra charge (this part of the license is a bit tricky, so please read the
 license and the commentaries).

Ok, i see...You said All parts of the software have to be licensed
compatibly with the GPL. What if, let's say, my application's GUI is
made by Qt (Open Source edition that is indeed under GPL license) and
in this application i use some module(s) that i bought from some other
company and they aren't under GPL, do you see any implication to
this ?

Thanks you all again!

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


Re: sqlite3 question

2007-04-12 Thread Rob Wolfe

Jorgen Bodde wrote:

 All I can think of is a 'crappy' construction where I use the iterator
 to see if there was something in there, but surely, there must be a
 better way to know?

  r = c.execute('select * from song where id = 2')
  notfound = True
  for s in r:
 ...   notfound = False
 ...   print s
  if notfound:
 ...   print 'No rows'

 I am pretty new with Python, maybe there are some properties of an
 iterator / sqlite3 I am not aware of that can tell me how many rows
 are there?

What about this:

if not c.fetchone():
  print No rows

or

print rowcount=, len(cur.fetchall())

--
HTH,
Rob

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


Re: Newbie help with array handling

2007-04-12 Thread rishi pathak

do something like this
{keyvalue1:[ value1, value2, value3],keyvalue2:[value1,value2,
value3],keyvalue3,:[value1,value2,value3]}

On 12 Apr 2007 00:58:54 -0700, loial [EMAIL PROTECTED] wrote:


I am new to python and am converting an awk script to python

I need to store some data in an array/table of some form

keyvalue1, value1, value2, value3
keyvalue2, value1,value2, value3
keyvalue3, value1,value2,value3
etc

I will later need to sort in keyvalue order and also need to be able
to check if a key already exists

It is not clear how to do this in python. All the examples I see have
just a key and a single value

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





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: tuples, index method, Python's design

2007-04-12 Thread Antoon Pardon
On 2007-04-11, Terry Reedy [EMAIL PROTECTED] wrote:

 BJrn Lindqvist [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 On 4/10/07, Steve Holden [EMAIL PROTECTED] wrote:
 One might perversely allow extension to lists and tuples to allow

[3, 4] in [1, 2, 3, 4, 5, 6]

 to succeed, but that's forcing the use case beyond normal limits.

 I'd love to have that! There are at least one million use cases for
 finding a sequence in a sequence and implementing it yourself is
 non-trivial. Plus then both list and tuple's index methods would work
 *exactly* like string's. It would be easier to document and more
 useful. A big win.

===
 It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

 Strings are special in that s[i] can only be a (sub)string of length 1.
 'b' in 'abc' is True.  This makes looking for longer substrings easy.

 However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
 looking for sublists is different from looking for items.

Well I think this illustrates nicely what can happen if you design by
use cases.

Let us assume for a moment that finding out if one list is a sublist of
a second list gets considered something usefull enough to be included
in Python. Now the in operator can't be used for this because it
would create ambiguities. So it would become either a new operator
or a new method. But whatever the solution it would be different
from the string solution.

Now if someone would have thought about how st1 in st2 would
generalize to other sequemce if st1 contained more than one
character they probably would have found the possible inconsistency
that could create and though about using an other way than using
the in-operator for this with strings. A way that wouldn't create
ambiguities when it was considered to be extended to other sequences.

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


reading from sys.stdin

2007-04-12 Thread 7stud
I can't break out of the for loop in this example:

--
import sys

lst = []
for line in sys.stdin:
lst.append(line)
break

print lst
---

But, I can break out of the for loop when I do this:

-
import sys

lst = []
for line in open(aaa.txt):
lst.append(line)
break

print lst
--

Why doesn't break work in the first example?

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


Re: Newbie help with array handling

2007-04-12 Thread bruce peng
use dir with list nested

for example:
{key1 : [value1, value2, value3], key2 : [value1, value2, vlaue4]}


loial [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I am new to python and am converting an awk script to python

 I need to store some data in an array/table of some form

 keyvalue1, value1, value2, value3
 keyvalue2, value1,value2, value3
 keyvalue3, value1,value2,value3
 etc

 I will later need to sort in keyvalue order and also need to be able
 to check if a key already exists

 It is not clear how to do this in python. All the examples I see have
 just a key and a single value
 


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


Re: sqlite3 question

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 04:38:06 -0300, Jorgen Bodde  
[EMAIL PROTECTED] escribió:

 I am using sqlite3 in python, and I wonder if there is a way to know
 if there are valid rows returned or not. For example I have a table
 song with one entry in it. The ID of that entry is 1, so when I do;

 r = c.execute('select * from song where id = 1')
 for s in r:
 ...   print s
 ...   
 (1, u'Spikedrivers Blues', u'Mississippi John Hurt')

 That works. But when I can't restore the row by e.g. an ID that does
 not exist, I cannot see any method in 'r' (which is a SQLite.Cursor)
 that can tell me if I have rows. As explained in the help, r.rowcount
 does not give a valid result because it can't determine how many rows
 are restored in advance.

If you are only interested on how many songs there are, use count(*):
c.execute('select count(*) from song where id = 1')
print c.fetchone()[0]

If you are going to process the results, just iterate over the rows as in  
your example.
Or, use the fetchone method; it returns the first row, or None if no data  
is available (don't forget to process that row too).
If you don't expect many rows, you can use rows = list(c), or rows =  
c.fetchall(), and check len(rows).

 I am pretty new with Python, maybe there are some properties of an
 iterator / sqlite3 I am not aware of that can tell me how many rows
 are there?

As with many generic iterators, unfortunately, you have to consume the  
elements in order to know its length.

-- 
Gabriel Genellina

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


Re: pop() clarification

2007-04-12 Thread Christophe
Carl Banks a écrit :
 On Apr 11, 3:10 pm, 7stud [EMAIL PROTECTED] wrote:
 On Apr 11, 10:44 am, Scott [EMAIL PROTECTED] wrote:



 As said before I'm new to programming, and I need in depth explaination to
 understand everything the way I want to know it, call it a personality quirk
 ;p.
 With pop() you remove the last element of a list and return its value:
 Now I know list is a bad name, but for the sake of arguement lets assume its
 not a built in sequence
 list = ['this', 'is', 'an', 'example']
 list.pop()
 'example'
 list
 ['this', 'is', 'an']
 I understand all that.  What I don't understand is why all the documentation
 I see says, When removing a specific element from a list using pop() it
 must be in this format: list.pop([i]).
 At first I took that to mean that list.pop(i) would return some type of
 error, but it doesn't.
 It's understandable that the definition of pop() is confusing in that
 way.  It looks like the argument should be a list.  As others have
 said, that is not what the brackets mean when the documents show the
 formal definition of a function.
 
 I wonder if the documentation could take advantage of Python 3000
 annotation syntax.  So
 
 pop([x])
 
 would be replaced in the docs by
 
 pop(x: OPTIONAL)
 
 Just a thought, probably not a good one.  The brackets are so
 pervasive that it's probably better to just let newbies be confused
 for a little bit.

I'd rather go for the overloading syntax. ie:


pop(i)
pop()

Remove the item at the given position in the list, and return it. If no 
index is specified, a.pop() removes and returns the last item in the list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading from sys.stdin

2007-04-12 Thread Diez B. Roggisch
7stud schrieb:
 I can't break out of the for loop in this example:
 
 --
 import sys
 
 lst = []
 for line in sys.stdin:
 lst.append(line)
 break
 
 print lst
 ---

Works for me. But only after the stdin is closed with a C-d.

I presume this is an OS thing. The first lines aren't communicated to 
the process until either the file is closed - C-d - or the buffer the OS 
puts before the stream is filled. You can switch to unbuffered behviour 
somehow, google for it. Termios should be in your query.

Either way, it's not python behaving differently.

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


Re: reading from sys.stdin

2007-04-12 Thread Michael Bentley

On Apr 12, 2007, at 3:20 AM, 7stud wrote:

 I can't break out of the for loop in this example:

 --
 import sys

 lst = []
 for line in sys.stdin:
 lst.append(line)
 break

 print lst
 ---

 But, I can break out of the for loop when I do this:

 -
 import sys

 lst = []
 for line in open(aaa.txt):
 lst.append(line)
 break

 print lst
 --

 Why doesn't break work in the first example?

My guess is because you've not entered an EOF.  Try entering ^D (or  
if you're on Windows I think it's ^Z) while using your first example  
and see what it does.


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


Re: Newbie help with array handling

2007-04-12 Thread bearophileHUGS
loial:
 I am new to python and am converting an awk script to python

It seems there are many people trying to convert awk code to
Python :-)


 I need to store some data in an array/table of some form
 keyvalue1, value1, value2, value3
 keyvalue2, value1,value2, value3
 keyvalue3, value1,value2,value3
 etc
 I will later need to sort in keyvalue order and also need to be able
 to check if a key already exists

The problem with multiple values is easy to manage, you just put them
into a  list:
[value1, value2, value3]
Such list can be used as the a value for a key:value pair inside a
dict, etc.

The problem is that Python doesn't have a built-in sorted dictionary
data structure. So if you need it there are some solutions:

1) If you don't need to cheek presence often, and you don't need to
remove many key:value pairs, then you can just use a list of lists
like this (a Python list is an array of references dynamic on the
right):

data = [[keyvalue1, value1, value2, value3], [keyvalue2,
value1,value2, value3], [keyvalue3, value1,value2,value3], ...]

Then you can test the presence of a key with something like:
key in (subl[0] for subl in data)

Such list data can be sorted too according to the key (untested), if
the keys are sortable objects:
from operator itemgetter
data.sort(key=itemgetter(0))


2) If you need the dict characteristics a lot, then you may use a dict
(but keys must be hashable objects):
ddata = {keyvalue1:[value1, value2, value3], keyvalue2:[value1,
value2, value3], ...}

This allows quick presence testing, insertions and removals, but it
can't be sorted according to the keys. So you may need to keep a
sorted list of the keys:
skeys = sorted(ddata)
Then you can use skeys as you need, fetching the values from ddata if/
when you need them (note that there is a bisect standard module too
that may help the management of a sorted list).
But you have to keep the two structures updated at the same time, or
re-create new skeys now and then...


3) If you want to be sure the two structures are always the same, then
you may need to find an ordered dict class around (or you can write it
yourself, but it may be too difficult for you), such implementation
usually keep a dict and a list inside, and keep them in sync. You can
probably use it as a normal dict, so its usage is rather clean and
easy.
Most of such implementations have a slow removal and add of items,
because removing/adding them from the list requires time. If you need
to perform many such operations on a lot of data, then there is a way
to do that too, using a different implementation of ordered dict, you
can start from this, that uses a double linked list structure, it's
slow, but such time is costant (note that this keeps the order of the
insertions, it doesn't sort keys according to their natural order, so
you need to modify the code):
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498195

Bye,
bearophile

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


Re: Newbie help with array handling

2007-04-12 Thread Bruno Desthuilliers
loial a écrit :
 I am new to python and am converting an awk script to python
 
 I need to store some data in an array/table of some form
 
 keyvalue1, value1, value2, value3
 keyvalue2, value1,value2, value3
 keyvalue3, value1,value2,value3
 etc

data = dict(
   keyvalue1=[value11, value12, value13],
   keyvalue2=[value21, value22, value23],
   keyvalue3=[value31, value32, value33]
)


 I will later need to sort in keyvalue order

for key in sorted(data.keys()):
   print %s : %s % (key, data[key])

 and also need to be able
 to check if a key already exists

if somekey in data:
   print somekey already exists

 It is not clear how to do this in python. All the examples I see have
 just a key and a single value

Everything in Python is an object, so nothing prevents you from using 
lists as 'values'.

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


Re: reading from sys.stdin

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 05:20:58 -0300, 7stud [EMAIL PROTECTED]  
escribió:

 I can't break out of the for loop in this example:

 --
 import sys

 lst = []
 for line in sys.stdin:
 lst.append(line)
 break

 print lst
 ---

Python 2.5.1c1 (r251c1:54692, Apr  5 2007, 09:19:18) [MSC v.1310 32 bit  
(Intel)]
  on win32
Type help, copyright, credits or license for more information.
py import sys
py lst = []
py for line in sys.stdin:
... lst.append(line)
... break
...
hola
que
tal
como
estan
^Z
py print lst
['hola\n']
---

I typed many lines, but lst contains only one item, as expected. Same as  
your regular file example: the file contains many lines, but only the  
first goes into the list.

-- 
Gabriel Genellina

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


Calling private base methods

2007-04-12 Thread Jorgen Bodde
Hi All,

Now that I am really diving into Python, I encounter a lot of things
that us newbies find difficult to get right. I thought I understood
how super() worked, but with 'private' members it does not seem to
work. For example;

 class A(object):
... def __baseMethod(self):
... print 'Test'

Deriving from A, and doing;

 class D(A):
... def someMethod(self):
... super(A, self).__baseMethod()
... print 'test3'

Will not work;

 p = D()
 p.someMethod()
Traceback (most recent call last):
 File interactive input, line 1, in module
 File interactive input, line 3, in someMethod
AttributeError: 'super' object has no attribute '_D__baseMethod'

Is it possible to call a private base method? I come from a C++
background, and I liked this construction as my base class has helper
methods so that I do not have to  duplicate code.

When I do;

 class E(object):
... def someMethod(self):
... print 'Hello'
...
 class F(E):
... def otherMethod(self):
... super(F, self).someMethod()
... print 'There'
...
 p = F()
 p.otherMethod()
Hello
There


This seems to work.

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


Re: reaching hidden methods + casting

2007-04-12 Thread Bruno Desthuilliers
per9000 a écrit :
 Hi,
 can I reach a hidden method when doing ugly inheritance in python?
 
 class A:
 ... def spin(self, n): print A, n
 ...
 class B:
 ... def spin(self, m): print B, m
 ...
 class C(A,B):
 ... def spin(self, k): print C, k
 ...
 myC = C()
 dir(myC)
 ['__doc__', '__module__', 'spin']
 
 In f.x. the C-family of languages I guess something like this would
 call B.spin:
 ((B)myC).spin(Lancelot); // almost forgot the ';'

B.spin(myC, lancelot)

In Python, the syntax:
some_instance.some_method(param)

is syntactic sugar for
   SomeClass.some_method(some_instance, param)

(assuming isinstance(some_instance, SomeClass) == True)

 Please correct me I am wrong (which I likely am) but as I understand
 it this example calls the constructor of int instead of casting it,
 right?
 leet = int('1337')
 leet
 1337

There's nothing like casting in Python - it would be meaningless in a 
dynamically typed language. The above example does not cast a string 
to an int, it creates an int - you have two distinct objects, whereas 
with casting you have two representations of the same object.

 Or should I have thought about getting unique names before I
 implemented the ugly inheritance graph?

This is a design question, and we don't have enough context to answer it.

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread SamG
On Apr 12, 1:00 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Thu, 12 Apr 2007 04:14:32 -0300, SamG [EMAIL PROTECTED] escribió:

  How could i make, from inside the program, to have the stdout and
  stderr to be printed both to a file as well the terminal(as usual).

 A very minimal example:

 import sys

 class Tee(file):
  others = ()

  def write(self, data):
  file.write(self, data)
  for f in others:
  f.write(data)

 tee = Tee(rc:\temp\output.log,wt)
 tee.others = [sys.stdout, sys.stderr]
 sys.stdout = sys.stderr = tee

 print dir(sys)
 sys.foo # error

 --
 Gabriel Genellina

This is only creating an out.log file and all the stdout and stderr
are logged there.

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


Re: Newbie help with array handling

2007-04-12 Thread 7stud

loial wrote:
 I am new to python and am converting an awk script to python

 I need to store some data in an array/table of some form

 keyvalue1, value1, value2, value3
 keyvalue2, value1,value2, value3
 keyvalue3, value1,value2,value3
 etc

 I will later need to sort in keyvalue order and also need to be able
 to check if a key already exists

 It is not clear how to do this in python. All the examples I see have
 just a key and a single value

Any python type can be a value for a key/value pair.  See if this
helps:

mydict = { zkeyvalue1:[1, red, 2.5], akeyvalue2:[1.5, black,
30] }

key = keyvalue50
if key in mydict:
print found it
else:
print invalid key

lst = sorted(mydict)
print lst

for key in lst:
print mydict[key],

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


Re: About Trolltech QT OpenSource license.

2007-04-12 Thread king kikapu
I dig a little bit more on the Trolltech's site and i think that this
page is telling all the truth:

http://www.trolltech.com/developer/downloads/qt/faq

So, this tells us all the good stuff people in this thread are talking
about, i think is clear enough.

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


Re: Calling private base methods

2007-04-12 Thread Enrico
Jorgen Bodde [EMAIL PROTECTED] ha scritto nel messaggio
news:[EMAIL PROTECTED]
 Hi All,

 Now that I am really diving into Python, I encounter a lot of things
 that us newbies find difficult to get right. I thought I understood
 how super() worked, but with 'private' members it does not seem to
 work. For example;

  class A(object):
 ... def __baseMethod(self):
 ... print 'Test'

 Deriving from A, and doing;

  class D(A):
 ... def someMethod(self):
 ... super(A, self).__baseMethod()
 ... print 'test3'

 Will not work;

if you type
 dir(A)

you'll get a method named
_A__baseMethod

From the documentation:
Private name mangling: When an identifier that textually occurs in a class
definition begins with two or more underscore characters and does not end in
two or more underscores, it is considered a private name of that class.
Private names are transformed to a longer form before code is generated for
them. The transformation inserts the class name in front of the name, with
leading underscores removed, and a single underscore inserted in front of
the class name. For example, the identifier __spam occurring in a class
named Ham will be transformed to _Ham__spam. This transformation is
independent of the syntactical context in which the identifier is used. If
the transformed name is extremely long (longer than 255 characters),
implementation defined truncation may happen. If the class name consists
only of underscores, no transformation is done.

Enrico


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


Pyqt programming question

2007-04-12 Thread Marcpp
I have a program (python + pyqt), with a button I'll would to open a
new dialog window to input text, when press save or ok, this text is
returned to the principal program.
I've seek in internet but i don't find anything.

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


Re: About Trolltech QT OpenSource license.

2007-04-12 Thread Robert Kern
king kikapu wrote:
 On Apr 12, 1:02 am, Robert Kern [EMAIL PROTECTED] wrote:
 All parts of the software have to be licensed compatibly with the GPL. The 
 FSF
 has a fairly comprehensive list of the licenses they believe are 
 GPL-compatible.
 The source that you provide needs to be the preferred form for making
 modifications; i.e., you can't use a tool that obfuscates the code. You need 
 to
 provide the scripts that you use to build the software. You have to be 
 careful
 about using patented techniques in your code. The source code must be 
 offered at
 no extra charge (this part of the license is a bit tricky, so please read the
 license and the commentaries).
 
 Ok, i see...You said All parts of the software have to be licensed
 compatibly with the GPL. What if, let's say, my application's GUI is
 made by Qt (Open Source edition that is indeed under GPL license) and
 in this application i use some module(s) that i bought from some other
 company and they aren't under GPL, do you see any implication to
 this ?

You will not be able to distribute your program if that module is under a
license which imposes more restrictions than the GPL does. The FSF maintains a
list of licenses which are compatible with the GPL:

  http://www.gnu.org/philosophy/license-list.html

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


parsing text in blocks and line too

2007-04-12 Thread flyzone
Goodmorning people :)
I have just started to learn this language and i have a logical
problem.
I need to write a program to parse various file of text.
Here two sample:

---
trial text bla bla bla bla error
  bla bla bla bla bla
  bla bla bla on more lines
trial text bla bla bla bla warning bla
  bla bla more bla to be grouped with warning
  bla bla bla on more lines
  could be one two or ten lines also withouth the tab beginning
again text
text can contain also blank lines
text no delimiters
--
Apr  8 04:02:08 machine text on one line
Apr  8 04:02:09 machine this is an error
Apr  8 04:02:10 machine this is a warning
--
parsing the file, I'll need to decide if the line/group is an error,
warning or to skip.
Mine problem if how logical do it: if i read line by line, I'll catch
the error/warning
on first and the second/third/more will be skipped by control.
Reading a group of line i could lose the order on the output: my idea
is to have
an output in html with the line in the color of the check (yellow for
warning,
red for error).
And i have also many rules to be followed so if i read one rule and
then i search
on the entire file, the check will be really slow.

Hope someone could give me some tips.
Thanks in advance

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


Re: Newbie help with array handling

2007-04-12 Thread loial
OK, thanks for the replies

One other thing...I need to update the values since they are basically
totals that I am accumulating.

How do I update a specific value for a specific key?


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


Re: Get Shift + TAB in ncurses.

2007-04-12 Thread Thomas Bellman
[EMAIL PROTECTED] wrote:

 Anyone can help me getting the shift + tab key combination ?
 I tried with getch () but with no success.
 May be using the sys.stdin ??

It's generally not possible.  Most terminals I have used send the
same character (ASCII code 9) when you press Shift-Tab as when
you press Tab.  You can't differentiate between Ctrl-X and
Shift-Ctrl-X either, or between Tab and Ctrl-I.

Your specific terminal may be sending some other character
sequence when you press Shift-Tab (my Xterm sends ESC [ Z by
default), or you may be able to program it to do so, but that
will only apply to your terminal, not to anyone else's.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
Don't tell me I'm burning the candle at both ! bellman @ lysator.liu.se
 ends -- tell me where to get more wax!! ! Make Love -- Nicht Wahr!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: redirecting stdout to a file as well as screen

2007-04-12 Thread SamG
On Apr 12, 12:40 pm, Ant [EMAIL PROTECTED] wrote:
 On Apr 12, 8:14 am, SamG [EMAIL PROTECTED] wrote:

  How could i make, from inside the program, to have the stdout and
  stderr to be printed both to a file as well the terminal(as usual).

 One way would be to create a custom class which has the same methods
 as the file type, and held a list of file-like objects to write to.
 e.g.

 class multicaster(object):
 def __init__(self, filelist):
 self.filelist = filelist

 def write(self, str):
 for f in self.filelist:
 f.write(str)
 def writelines(self, str_list):
 #etc

 Then assign stdout and stderr to a new instance of one of these
 objects:

 mc = multicaster([sys.stdout, sys.stderr, log_file])
 sys.stdout = mc
 sys.stderr = mc

 HTH



I have written this

import sys

class multicaster(object):
def __init__(self, filelist):
self.filelist = filelist

def write(self, str):
for f in self.filelist:
f.write(str)

log_file='out.log'
mc = multicaster([sys.stdout, sys.stderr, log_file])
sys.stdout = mc
sys.stderr = mc

print Hello

And i get this when i run the porgram.

HelloHelloTraceback (most recent call last):
Traceback (most recent call last):

Kindly advice!


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


Re: Pyqt programming question

2007-04-12 Thread Phil Thompson
On Thursday 12 April 2007 10:23 am, Marcpp wrote:
 I have a program (python + pyqt), with a button I'll would to open a
 new dialog window to input text, when press save or ok, this text is
 returned to the principal program.
 I've seek in internet but i don't find anything.

Use QInputDialog.getText()

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread 7stud
On Apr 12, 3:35 am, SamG [EMAIL PROTECTED] wrote:
 On Apr 12, 12:40 pm, Ant [EMAIL PROTECTED] wrote:



  On Apr 12, 8:14 am, SamG [EMAIL PROTECTED] wrote:

   How could i make, from inside the program, to have the stdout and
   stderr to be printed both to a file as well the terminal(as usual).

  One way would be to create a custom class which has the same methods
  as the file type, and held a list of file-like objects to write to.
  e.g.

  class multicaster(object):
  def __init__(self, filelist):
  self.filelist = filelist

  def write(self, str):
  for f in self.filelist:
  f.write(str)
  def writelines(self, str_list):
  #etc

  Then assign stdout and stderr to a new instance of one of these
  objects:

  mc = multicaster([sys.stdout, sys.stderr, log_file])
  sys.stdout = mc
  sys.stderr = mc

  HTH

 I have written this

 import sys

 class multicaster(object):
 def __init__(self, filelist):
 self.filelist = filelist

 def write(self, str):
 for f in self.filelist:
 f.write(str)

 log_file='out.log'
 mc = multicaster([sys.stdout, sys.stderr, log_file])
 sys.stdout = mc
 sys.stderr = mc

 print Hello

 And i get this when i run the porgram.

 HelloHelloTraceback (most recent call last):
 Traceback (most recent call last):

 Kindly advice!

Try:

log_file = open(out.log, w)

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


Re: Newbie help with array handling

2007-04-12 Thread 7stud
On Apr 12, 3:31 am, loial [EMAIL PROTECTED] wrote:
 OK, thanks for the replies

 One other thing...I need to update the values since they are basically
 totals that I am accumulating.

 How do I update a specific value for a specific key?

mydict[keyvalue1]

returns the value, which in this case is a list.  So, you could write:

lst = mydict[keyvalue1]
lst[0] = 4
list.append(red)

or you can do it directly:

mydict[keyvalue1][0] = 4
mydict[keyvalue1].append(red)

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


SQLite problems

2007-04-12 Thread bayer . justin
Hi there,

I run Python 2.5 on a Mac OS X system with SQLite 3.2.8 installed via
fink. Today I stumbled over the problem, that the sqlite3 module and
sqlite3 from fink do not seem to work well together. I brought it down
to this:

 from sqlite3 import Connection
 c = Connection(foo.bar)   # does not yet exist
 c.execute(CREATE TABLE foo (id integer))
 c.execute(INSERT INTO foo VALUES (1))
 c.execute(SELECT * FROM foo)
 c.execute(SELECT * FROM foo).fetchmany()
[(1,)]
 c.execute(INSERT INTO foo VALUES (2))
 c.execute(SELECT * FROM foo).fetchmany(2)
[(1,), (2,)]

Then in sqilte:

$ sqlite3 foo.bar
SQLite version 3.2.8
Enter .help for instructions
sqlite select * from foo;
SQL error: unsupported file format


If I create the database file with sqlite and open it from within
python, I cannot run any queries on that database, but no error is
thrown - it just passes silently.

Any ideas?

Regards,
-Justin

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread Antoon Pardon
On 2007-04-12, SamG [EMAIL PROTECTED] wrote:
 On Apr 12, 12:40 pm, Ant [EMAIL PROTECTED] wrote:
 On Apr 12, 8:14 am, SamG [EMAIL PROTECTED] wrote:

  How could i make, from inside the program, to have the stdout and
  stderr to be printed both to a file as well the terminal(as usual).

 One way would be to create a custom class which has the same methods
 as the file type, and held a list of file-like objects to write to.
 e.g.

 class multicaster(object):
 def __init__(self, filelist):
 self.filelist = filelist

 def write(self, str):
 for f in self.filelist:
 f.write(str)
 def writelines(self, str_list):
 #etc

 Then assign stdout and stderr to a new instance of one of these
 objects:

 mc = multicaster([sys.stdout, sys.stderr, log_file])
 sys.stdout = mc
 sys.stderr = mc

 HTH



 I have written this

 import sys

 class multicaster(object):
 def __init__(self, filelist):
 self.filelist = filelist

 def write(self, str):
 for f in self.filelist:
 f.write(str)

 log_file='out.log'

log_file is not a file but a string, So when you reach the
write method in your multicaster you get an atttribute error
because a string has no write method

 mc = multicaster([sys.stdout, sys.stderr, log_file])

Since sys.stdout and sys.stderr usually both refer to
the terminal, this will result in your output appearing
twice on the terminal

 sys.stdout = mc
 sys.stderr = mc

Maybe you are better of leaving sys.stderr as it is,
at least until you are sure your multicaster itself
is working as it should.

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


Re: tuples, index method, Python's design

2007-04-12 Thread Paul Boddie
On 12 Apr, 09:37, Antoon Pardon [EMAIL PROTECTED] wrote:

 Why then does python itself provide immutables? I find this reasoning
 more than baffling. There has been all these arguments about why
 it is best to use immutables as dictionary keys.

You've answered your own question. If you had a mutable dictionary
key, stored something in a dictionary using that key, then modified
the key and tried to retrieve the stored item using that same key
object, you might never find that item again. This is something of a
simplification (you'd have to look into details of things like
__hash__ and __eq__, I imagine), but this is just one area where
immutability is central to the operation of the feature concerned.

Other languages provide some control over immutability with things
like const, and there are good reasons for having such things,
although you do need to know what you're doing as a programmer when
using them. Some people might argue that the dictionary key example
given above is contrived: Of course it won't work if you modify the
key! they might say. Having some idea of which objects are immutable
can provide some protection from inadvertent mutation, however.

 But the moment the topic changes, someone else comes with the comment that
 wanting your sequence to be immuatble is unpythonic.

As soon as unpythonic is mentioned we enter subjective territory.

Paul

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


Re: Pyqt programming question

2007-04-12 Thread Marcpp
On 12 abr, 11:48, Phil Thompson [EMAIL PROTECTED] wrote:
 On Thursday 12 April 2007 10:23 am, Marcpp wrote:

  I have a program (python + pyqt), with a button I'll would to open a
  new dialog window to input text, when press save or ok, this text is
  returned to the principal program.
  I've seek in internet but i don't find anything.

 Use QInputDialog.getText()

 Phil

I can't do it, have you any example?
Thank you.

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


Re: sys.excepthook and threads

2007-04-12 Thread Dr. Peer Griebel
ian schrieb:
  Hi,
 
  sys.excepthook don't work if an exception come in a thread...
  It's normal or its a bug ? There are any tip ? look here :
  http://spyced.blogspot.com/2005_06_01_archive.html
 
  Thx

I think sys.excepthook is a thread local variable.  This means the
variable has to be set by the thread for which it should be active.

You did set sys.excepthook in your main thread. This setting is not
propagated to your newly created thread.

This is my observation...

Peer

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 06:01:18 -0300, SamG [EMAIL PROTECTED] escribió:

 On Apr 12, 1:00 pm, Gabriel Genellina [EMAIL PROTECTED]
 wrote:
 En Thu, 12 Apr 2007 04:14:32 -0300, SamG [EMAIL PROTECTED] escribió:

  How could i make, from inside the program, to have the stdout and
  stderr to be printed both to a file as well the terminal(as usual).

 class Tee(file):
  others = ()

  def write(self, data):
  file.write(self, data)
  for f in others:
  f.write(data)


 This is only creating an out.log file and all the stdout and stderr
 are logged there.

Sorry, `for f in others:` should read `for f in self.others:`

-- 
Gabriel Genellina

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread SamG
On Apr 12, 3:16 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Thu, 12 Apr 2007 06:01:18 -0300, SamG [EMAIL PROTECTED] escribió:



  On Apr 12, 1:00 pm, Gabriel Genellina [EMAIL PROTECTED]
  wrote:
  En Thu, 12 Apr 2007 04:14:32 -0300, SamG [EMAIL PROTECTED] escribió:

   How could i make, from inside the program, to have the stdout and
   stderr to be printed both to a file as well the terminal(as usual).

  class Tee(file):
   others = ()

   def write(self, data):
   file.write(self, data)
   for f in others:
   f.write(data)

  This is only creating an out.log file and all the stdout and stderr
  are logged there.

 Sorry, `for f in others:` should read `for f in self.others:`

 --
 Gabriel Genellina


Does not make difference, does this work for you? Im working on linux.
But this code looks portable except for the file path :)

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


Re: Calling private base methods

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 05:47:57 -0300, Jorgen Bodde  
[EMAIL PROTECTED] escribió:

 Now that I am really diving into Python, I encounter a lot of things
 that us newbies find difficult to get right. I thought I understood
 how super() worked, but with 'private' members it does not seem to
 work. For example;

Someone already told you what happens here. But aren't *private* methods  
supposed to be private? That is, not called from outside the class.

 Is it possible to call a private base method? I come from a C++
 background, and I liked this construction as my base class has helper
 methods so that I do not have to  duplicate code.

It's been a while since I do any serious work in C++, but AFAIK you  
*can't* call a private method from another class (even from a derived one)  
unless you use friend.
Maybe you want a protected method - by convention, in Python they're  
written as _name (single underscore).

-- 
Gabriel Genellina

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


Re: Pyqt programming question

2007-04-12 Thread Phil Thompson
On Thursday 12 April 2007 11:07 am, Marcpp wrote:
 On 12 abr, 11:48, Phil Thompson [EMAIL PROTECTED] wrote:
  On Thursday 12 April 2007 10:23 am, Marcpp wrote:
   I have a program (python + pyqt), with a button I'll would to open a
   new dialog window to input text, when press save or ok, this text is
   returned to the principal program.
   I've seek in internet but i don't find anything.
 
  Use QInputDialog.getText()
 
  Phil

 I can't do it, have you any example?

Look at the standarddialogs.py example that it included with PyQt.

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


Re: Pyqt programming question

2007-04-12 Thread Marcpp
On 12 abr, 12:07, Marcpp [EMAIL PROTECTED] wrote:
 On 12 abr, 11:48, Phil Thompson [EMAIL PROTECTED] wrote:

  On Thursday 12 April 2007 10:23 am, Marcpp wrote:

   I have a program (python + pyqt), with a button I'll would to open a
   new dialog window to input text, when press save or ok, this text is
   returned to the principal program.
   I've seek in internet but i don't find anything.

  Use QInputDialog.getText()

  Phil

 I can't do it, have you any example?
 Thank you.

I've created a personal dialog.

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


Re: Newbie help with array handling

2007-04-12 Thread 7stud
On Apr 12, 3:50 am, 7stud [EMAIL PROTECTED] wrote:
 On Apr 12, 3:31 am, loial [EMAIL PROTECTED] wrote:

 lst = mydict[keyvalue1]
 lst[0] = 4
 list.append(red)


Rather the last line there should read:

lst.append(red)

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


Re: tuples, index method, Python's design

2007-04-12 Thread Antoon Pardon
On 2007-04-12, Paul Boddie [EMAIL PROTECTED] wrote:
 On 12 Apr, 09:37, Antoon Pardon [EMAIL PROTECTED] wrote:

 Why then does python itself provide immutables? I find this reasoning
 more than baffling. There has been all these arguments about why
 it is best to use immutables as dictionary keys.

 You've answered your own question.

Well since it was meant as a rethorical question that is hardly
surprising. But may be I should work harder on my rethorical
skill since you missed that.

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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread Gabriel Genellina
En Thu, 12 Apr 2007 07:23:43 -0300, SamG [EMAIL PROTECTED] escribió:

   How could i make, from inside the program, to have the stdout and
   stderr to be printed both to a file as well the terminal(as usual).

  class Tee(file):
   others = ()

   def write(self, data):
   file.write(self, data)
   for f in others:
   f.write(data)

  This is only creating an out.log file and all the stdout and stderr
  are logged there.

 Sorry, `for f in others:` should read `for f in self.others:`

 Does not make difference, does this work for you? Im working on linux.
 But this code looks portable except for the file path :)

Yes. And it's rather similar to your other example... Omit sys.stderr as  
Antoon Pardon suggested.

-- 
Gabriel Genellina

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


Re: Calling private base methods

2007-04-12 Thread 7stud
On Apr 12, 2:47 am, Jorgen Bodde [EMAIL PROTECTED] wrote:
 Is it possible to call a private base method? I come from a C++
 background, and I liked this construction as my base class has helper
 methods so that I do not have to  duplicate code.


I'd like to see some C++ code that does that!

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


Re: Pyqt programming question

2007-04-12 Thread Marcpp
On 12 abr, 12:34, Phil Thompson [EMAIL PROTECTED] wrote:
 On Thursday 12 April 2007 11:07 am, Marcpp wrote:

  On 12 abr, 11:48, Phil Thompson [EMAIL PROTECTED] wrote:
   On Thursday 12 April 2007 10:23 am, Marcpp wrote:
I have a program (python + pyqt), with a button I'll would to open a
new dialog window to input text, when press save or ok, this text is
returned to the principal program.
I've seek in internet but i don't find anything.

   Use QInputDialog.getText()

   Phil

  I can't do it, have you any example?

 Look at the standarddialogs.py example that it included with PyQt.

 Phil

I've need a personal dialog, not a standard.
Thank you.

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


Re: Calling private base methods

2007-04-12 Thread Duncan Booth
7stud [EMAIL PROTECTED] wrote:

 On Apr 12, 2:47 am, Jorgen Bodde [EMAIL PROTECTED] wrote:
 Is it possible to call a private base method? I come from a C++
 background, and I liked this construction as my base class has helper
 methods so that I do not have to  duplicate code.

 
 I'd like to see some C++ code that does that!
 
 

Easy:

#define private public
#include someheader
#undef private

then call the private methods as much as you want.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLite problems

2007-04-12 Thread martin . laloux

 I run Python 2.5 on a Mac OS X system with SQLite 3.2.8 installed via
 fink.


Why fink ?, it is very easy to make sqlite. download the source,
configure, make and install from terminal

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


Re: parsing text in blocks and line too

2007-04-12 Thread A.T.Hofkamp
On 2007-04-12, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Goodmorning people :)
 I have just started to learn this language and i have a logical
 problem.
 I need to write a program to parse various file of text.
 Here two sample:

 ---
 trial text bla bla bla bla error
   bla bla bla bla bla
   bla bla bla on more lines
 trial text bla bla bla bla warning bla
   bla bla more bla to be grouped with warning
   bla bla bla on more lines
   could be one two or ten lines also withouth the tab beginning
 again text
 text can contain also blank lines
 text no delimiters
 --
 Apr  8 04:02:08 machine text on one line
 Apr  8 04:02:09 machine this is an error
 Apr  8 04:02:10 machine this is a warning
 --

I would first read groups of lines that belong together, then decide on each
group whether it is an error, warning, or whatever.
To preserve order in a group of lines, you can use lists.

From your example you could first compute a list of lists, like

[ [ trial text bla bla bla bla error,
  bla bla bla bla bla,
  bla bla bla on more lines ],
  [ trial text bla bla bla bla warning bla,
  bla bla more bla to be grouped with warning,
  bla bla bla on more lines,
  could be one two or ten lines also withouth the tab beginning ],
  [ again text ],
  [ text can contain also blank lines ],
  [ ],
  [ text no delimiters ]
]

Just above the text no delimiters line I have added an empty line, and I
translated that to an empty group of lines (denoted with the empty list).

By traversing the groups (ie over the outermost list), you can now decide for
each group what type of output it is, and act accordingly.

 Hope someone could give me some tips.

Sure, however, in general it is appreciated if you first show your own efforts
before asking the list for a solution.

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


Re: NLTK, Random Sentence Generators?

2007-04-12 Thread Passer By
James Stroud [EMAIL PROTECTED] writes:

 Passer By wrote:
  James Stroud [EMAIL PROTECTED] writes:
 
 Passer By wrote:
 
 
 Has any created or not of examples of random sentence generators
 using n-gram models (or other models might be interesting).  I
 know of one example from a course at MIT, but besides that
 nothing.  Any help would be great.
 
 
 Best is to just cull text from your spam folder as these are often
 generated by similar means--but somehow I think you knew that.
 
  Emotive on Usenet? Thats original.
 
 Anonimity on usenet? That's suspiscious.

Paranoid Plunk?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 question

2007-04-12 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Jorgen Bodde
wrote:

 r = c.execute('select * from song where id = 1')
 for s in r:
 ...   print s
 ...   
 (1, u'Spikedrivers Blues', u'Mississippi John Hurt')
 
 That works. But when I can't restore the row by e.g. an ID that does
 not exist, I cannot see any method in 'r' (which is a SQLite.Cursor)
 that can tell me if I have rows. As explained in the help, r.rowcount
 does not give a valid result because it can't determine how many rows
 are restored in advance.

This should not work because `r` should not be a `Cursor` object.  The
`execute()`-Method returns an integer with the number of affected rows.

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


Re: parsing text in blocks and line too

2007-04-12 Thread James Stroud
A.T.Hofkamp wrote:
 On 2007-04-12, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Goodmorning people :)
 I have just started to learn this language and i have a logical
 problem.
 I need to write a program to parse various file of text.
 Here two sample:

 ---
 trial text bla bla bla bla error
   bla bla bla bla bla
   bla bla bla on more lines
 trial text bla bla bla bla warning bla
   bla bla more bla to be grouped with warning
   bla bla bla on more lines
   could be one two or ten lines also withouth the tab beginning
 again text
 text can contain also blank lines
 text no delimiters
 --
 Apr  8 04:02:08 machine text on one line
 Apr  8 04:02:09 machine this is an error
 Apr  8 04:02:10 machine this is a warning
 --
 
 I would first read groups of lines that belong together, then decide on each
 group whether it is an error, warning, or whatever.
 To preserve order in a group of lines, you can use lists.
 
 From your example you could first compute a list of lists, like
 
 [ [ trial text bla bla bla bla error,
   bla bla bla bla bla,
   bla bla bla on more lines ],
   [ trial text bla bla bla bla warning bla,
   bla bla more bla to be grouped with warning,
   bla bla bla on more lines,
   could be one two or ten lines also withouth the tab beginning ],
   [ again text ],
   [ text can contain also blank lines ],
   [ ],
   [ text no delimiters ]
 ]
 
 Just above the text no delimiters line I have added an empty line, and I
 translated that to an empty group of lines (denoted with the empty list).
 
 By traversing the groups (ie over the outermost list), you can now decide for
 each group what type of output it is, and act accordingly.
 
 Hope someone could give me some tips.
 
 Sure, however, in general it is appreciated if you first show your own efforts
 before asking the list for a solution.
 
 Albert

If groups have 0 indent first line and other lines in the group are 
indented, group the lines

blocks = []
block = []
for line in lines:
   if not line.startswith(' '):
 if block:
   blocks.append(block)
 block = []
   block.append(line)
if block:
   blocks.append(block)

But if 0 indent doesn't start a new block, don't expect this to work, 
but that is what I infer from your limited sample.

You can then look for warnings, etc., in the blocks--either in the loop 
to save memory or in the constructed blocks list.

James


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


Re: redirecting stdout to a file as well as screen

2007-04-12 Thread SamG
On Apr 12, 3:42 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Thu, 12 Apr 2007 07:23:43 -0300, SamG [EMAIL PROTECTED] escribió:



How could i make, from inside the program, to have the stdout and
stderr to be printed both to a file as well the terminal(as usual).

   class Tee(file):
others = ()

def write(self, data):
file.write(self, data)
for f in others:
f.write(data)

   This is only creating an out.log file and all the stdout and stderr
   are logged there.

  Sorry, `for f in others:` should read `for f in self.others:`

  Does not make difference, does this work for you? Im working on linux.
  But this code looks portable except for the file path :)

 Yes. And it's rather similar to your other example... Omit sys.stderr as
 Antoon Pardon suggested.

 --
 Gabriel Genellina


Thanks people i have got it working now...

with this program!

#END
import sys

class multicaster(object):
def __init__(self, filelist):
self.filelist = filelist

def write(self, str):
for f in self.filelist:
f.write(str)

log_file=open('out.log','w')
mc = multicaster([sys.stderr, log_file])
sys.stdout = mc
sys.stderr = mc
sys.stdout.write( Mojozoox\n)
sys.stderr.write( Hello\n)
#END

works perfect for my needs.

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


Re: reaching hidden methods + casting

2007-04-12 Thread per9000
On 12 Apr, 09:42, Gabriel Genellina [EMAIL PROTECTED] wrote:

 snip

  In f.x. the C-family of languages I guess something like this would
  call B.spin:
  ((B)myC).spin(Lancelot); // almost forgot the ';'

 Try this in Python:
 B.spin(myC, Lancelot)


 snip



Thanks, that was exactly the insight i needed.

/Per

--

Per Erik Strandberg
blog: http://www.pererikstrandberg.se/blog/

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


Re: Nice bug to loose a contest

2007-04-12 Thread aspineux
On 8 avr, 13:40, aspineux [EMAIL PROTECTED] wrote:
 This code works like the python one,
 I dont use buffered stdio f... functions,
 but the more 'system call' read and write

 int main()
 {
 char buf[120];
 int len;

 while (len=read(1, buf, sizeof(buf))) {
 write(1, buf, len);
 }
 return 0;

 }

 I dont understand what is appening,

But I have an idea !

It is possible to open a file in RW mode, nothing exceptional with
that.
And when connected in a terminal, you are connected through a file
called a PTY !
This file is open in RW !

File descriptors 0, 1 and 2 are certainly a view of this PTY and
then in fact the same thing !





 but you have to know their is a link between
 stdin and stdout in 'terminal mode', when you make a read on stdin,
 stdout is automatically flushed, this link disappears when onr is not
 liked to a terminal.
 This is to facilitate user input, to avoid to put a flush after each
 write,
 in fact before any user input.

 Hope someone else will give the trick

 On 8 avr, 12:52, stdazi [EMAIL PROTECTED] wrote:

  Hello,

  Yesterday, I was at a programming competition. We programmed on Linux
  liveCD's and Python was one of the allowed languages (among C and
  Java). I cared just about the algorithmic approach so I used Python.
  One of the main rules is, that the code reads its standard input and
  dumps the result on the standard output. Here happened my bigger
  programming mistake ever - I used the following approach :

  
  import sys
  print sys.stdout.readlines() # TYPO ! stdin != stdout
  

  So the WEIRD issue is, that it worked and, executing the following
  code I get :

  
  [EMAIL PROTECTED] ~ $ python la.py
  test
  test #2
  ['test \n', 'test #2\n']
  [EMAIL PROTECTED] ~ $
  

  Ok, as the algorithm worked perfectly, and all the test cases we were
  given were positive, I've continued with the next problem, copy/
  pasting the above idiom... When they tested the code, they used file
  redirection like :

  ==
  python la.py  /somefile
  ==

  And, my code resulted in no output/input (= 0 points), which can be
  proved here too :

  
  [EMAIL PROTECTED] ~ $ python la.py  /etc/passwd

  ===

  Some friend of mine told me that's the Unix way, (stdout can act like
  stdin) so I tried some C code :

  ===
1 #include stdio.h
2
3 int main() {
4 char buf[120];
5 while (fgets(buf, sizeof(buf), stdout) != NULL) {
6 puts(buf);
7 }
8return 0;
9}
  ===

  The code returns with no delay, so I'm really wondering where is that
  nice sys.{stdin,stdout} feature inplemented as pydoc doesn't mention
  anything. I'd spot the mistake before submitting the problem solutions
  if it was written in C :)

  Thanks!


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


Capturing the entry point of a script

2007-04-12 Thread SamG
If a function does not have main function defined and there is only a

if __name__=__main__:

how do i make a call to that using

profile.runcall( ...)

in my profiling script. Is there a way to find the entry point of a
script and indentify it with module method.

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


Capturing the entry point of a script

2007-04-12 Thread SamG
If a function does not have main function defined and there is only a

if __name__=__main__:

how do i make a call to that using

profile.runcall( ...)

in my profiling script. Is there a way to find the entry point of a
script and indentify it with module method.

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


Re: Code Explaination: Spelling correction code

2007-04-12 Thread Drew
On Apr 11, 11:27 pm, Steven Bethard [EMAIL PROTECTED] wrote:
 Drew wrote:
  I recently saw this website:http://www.norvig.com/spell-correct.html

  All the code makes sense to me save one line:

  def known_edits2(word):
  return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in
  NWORDS)

 This is the same as:

  result = set()
  for e1 in edits1(word):
  for e2 in edits1(e1):
  if e2 in NWORDS:
  result.add(e2)
  return result

 The thing between the ``set(`` and ``)`` is called a generator
 comprehension if you'd like to look into it further.

 STeVe

Steve -

Thanks for the response. I'm somewhat familiar with generator/list
comprehension but was unsure how multiple statements were evaluated
when chained together. From your explanation, I'm assuming they are
evaluated from the inside out rather than left to right or right to
left.

Does the mean that the comprehension on the inside is always evaluated
first?

Thanks,
Drew

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


Re: sqlite3 question

2007-04-12 Thread Carsten Haese
On Thu, 2007-04-12 at 13:43 +0200, Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED], Jorgen Bodde
 wrote:
 
  r = c.execute('select * from song where id = 1')
  for s in r:
  ... print s
  ... 
  (1, u'Spikedrivers Blues', u'Mississippi John Hurt')
  
  That works. But when I can't restore the row by e.g. an ID that does
  not exist, I cannot see any method in 'r' (which is a SQLite.Cursor)
  that can tell me if I have rows. As explained in the help, r.rowcount
  does not give a valid result because it can't determine how many rows
  are restored in advance.
 
 This should not work because `r` should not be a `Cursor` object.  The
 `execute()`-Method returns an integer with the number of affected rows.

It does work if 'c' is a connection object with a poorly chosen name.
According to
http://docs.python.org/lib/sqlite3-Connection-Objects.html , sqlite3
connection objects have a non-standard execute method that creates a
cursor, executes a query on that cursor, and returns that cursor.

Anyway, if you expect a query to return at most one row, such as when
you're filtering on the table's primary key, this is how I would do it:

cur.execute(select * from song where id = ?, (wanted_id,) )
song_row = cur.fetchone()
if song_row:
   # Do something with song_row
else:
   # Song not found

HTH,

Carsten.


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


Re: reading from sys.stdin

2007-04-12 Thread Maric Michaud
Le jeudi 12 avril 2007 10:34, Diez B. Roggisch a écrit :
 I presume this is an OS thing. The first lines aren't communicated to
 the process until either the file is closed - C-d - or the buffer the OS
 puts before the stream is filled. You can switch to unbuffered behviour
 somehow, google for it. Termios should be in your query.

I don't know if this a python or OS thing, but I know that iterating over a 
file is not like applying successive call to readline method. You should try 
to use readline instead.

The following work exactly the same on windows and Linux (python2.4) :

 f=open('txt')
 l=f.readline()
 while(l) :
...  print l,
...  print rest :  + f.read()
...  l=f.readline()
...
foo
rest : bar
baz

works as expected, while :

 f=open('txt')
 for l in f :
...  print l,
...  print rest :  + f.read()
...
foo
rest :
bar
rest :
baz
rest :

doesn't, it seems that file iteratiion itself use a buffer. In python 2.5, you 
just can't do this :

Python 2.5 (release25-maint, Dec  9 2006, 14:35:53)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
Type help, copyright, credits or license for more information.
 f=open('txt')
 for l in f :
...  print l,
...  print rest :  + f.read()
...
foo
Traceback (most recent call last):
  File stdin, line 3, in module
ValueError: Mixing iteration and read methods would lose data

-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 4 26 88 00 97
Mobile: +33 6 32 77 00 21
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-12 Thread Steve Holden
Antoon Pardon wrote:
 On 2007-04-11, Terry Reedy [EMAIL PROTECTED] wrote:
 BJrn Lindqvist [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 On 4/10/07, Steve Holden [EMAIL PROTECTED] wrote:
 One might perversely allow extension to lists and tuples to allow

[3, 4] in [1, 2, 3, 4, 5, 6]

 to succeed, but that's forcing the use case beyond normal limits.
 I'd love to have that! There are at least one million use cases for
 finding a sequence in a sequence and implementing it yourself is
 non-trivial. Plus then both list and tuple's index methods would work
 *exactly* like string's. It would be easier to document and more
 useful. A big win.

 ===
 It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

 Strings are special in that s[i] can only be a (sub)string of length 1.
 'b' in 'abc' is True.  This makes looking for longer substrings easy.

 However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
 looking for sublists is different from looking for items.
 
 Well I think this illustrates nicely what can happen if you design by
 use cases.
 
 Let us assume for a moment that finding out if one list is a sublist of
 a second list gets considered something usefull enough to be included
 in Python. Now the in operator can't be used for this because it
 would create ambiguities. So it would become either a new operator
 or a new method. But whatever the solution it would be different
 from the string solution.
 
That's because strings are different from other sequences. See below.

 Now if someone would have thought about how st1 in st2 would
 generalize to other sequemce if st1 contained more than one
 character they probably would have found the possible inconsistency
 that could create and though about using an other way than using
 the in-operator for this with strings. A way that wouldn't create
 ambiguities when it was considered to be extended to other sequences.
 
The fact is that strings are the only sequences composed of subsequences 
of length 1 - in other words the only sequences where type(s) == 
type(s[0:1]) is an invariant condition.

This was discussed (at my instigation, IIRC) on python-dev when Python 
(2.4?) adopted the enhanced semantics for in on strings - formerly 
only tests for single characters were allowed - but wasn't thought 
significant enough to deny what was felt to be a natural usage for 
strings only.

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

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


Re: Calling private base methods

2007-04-12 Thread Maric Michaud
Le jeudi 12 avril 2007 10:47, Jorgen Bodde a écrit :
  I thought I understood
 how super() worked, but with 'private' members it does not seem to
 work.
 I would add to what is already said, that you should just forget the 
private -public - protected concepts in Python.

There is no access control to members in Python, but :

- names not beginning by an underscore belong to the API of a class (C++ 
public) or module, whether they are methods or properties.
- names beginning by a single underscore are used internally by a class or a 
module, the caller should not use/import them at all.
- names enclosed by double underscore are parts of the language semantic, 
don't define yours.

All these are conventions.
Finally :

- names beginning by double underscore are mangled at class creation time, 
they should be used only to avoid name collision in subclasses (practically 
this is rarely needed).

Python is alot about conventions, please read and follow the PEP 8 : 
http://www.python.org/dev/peps/pep-0008/

-- 
_

Maric Michaud

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


Re: tuples, index method, Python's design

2007-04-12 Thread Steve Holden
Antoon Pardon wrote:
 On 2007-04-11, Terry Reedy [EMAIL PROTECTED] wrote:
 BJrn Lindqvist [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 On 4/10/07, Steve Holden [EMAIL PROTECTED] wrote:
 One might perversely allow extension to lists and tuples to allow

[3, 4] in [1, 2, 3, 4, 5, 6]

 to succeed, but that's forcing the use case beyond normal limits.
 I'd love to have that! There are at least one million use cases for
 finding a sequence in a sequence and implementing it yourself is
 non-trivial. Plus then both list and tuple's index methods would work
 *exactly* like string's. It would be easier to document and more
 useful. A big win.

 ===
 It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

 Strings are special in that s[i] can only be a (sub)string of length 1.
 'b' in 'abc' is True.  This makes looking for longer substrings easy.

 However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
 looking for sublists is different from looking for items.
 
 Well I think this illustrates nicely what can happen if you design by
 use cases.
 
 Let us assume for a moment that finding out if one list is a sublist of
 a second list gets considered something usefull enough to be included
 in Python. Now the in operator can't be used for this because it
 would create ambiguities. So it would become either a new operator
 or a new method. But whatever the solution it would be different
 from the string solution.
 
That's because strings are different from other sequences. See below.

 Now if someone would have thought about how st1 in st2 would
 generalize to other sequemce if st1 contained more than one
 character they probably would have found the possible inconsistency
 that could create and though about using an other way than using
 the in-operator for this with strings. A way that wouldn't create
 ambiguities when it was considered to be extended to other sequences.
 
The fact is that strings are the only sequences composed of subsequences 
of length 1 - in other words the only sequences where type(s) == 
type(s[0:1]) is an invariant condition.

This was discussed (at my instigation, IIRC) on python-dev when Python 
(2.4?) adopted the enhanced semantics for in on strings - formerly 
only tests for single characters were allowed - but wasn't thought 
significant enough to deny what was felt to be a natural usage for 
strings only.

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

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


Re: Capturing the entry point of a script

2007-04-12 Thread Steve Holden
SamG wrote:
 If a function does not have main function defined and there is only a
 
 if __name__=__main__:
 
 how do i make a call to that using
 
 profile.runcall( ...)
 
 in my profiling script. Is there a way to find the entry point of a
 script and indentify it with module method.
 
There is no way to do that without modifying your module (by the way, I 
think you should have said If a *module* does not ...).

The easiest way to do this is to replace the line

if __name == __main__:

with

def main():

and then at the end of the module put

if __name__ == __main__:
 main()

The second step is not required unless you still want the module to run 
as a standalone script.

Now you can call profile.runcall(module.main, ...)

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

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


Re: wxPython, mac, wx.HSCROLL not working

2007-04-12 Thread Bjoern Schliessmann
7stud wrote:

 I'm trying to allow for a horizontal scrollbar on a textarea, but
 the scrollbar won't appear when I enter a long string of text(by
 leaning on one character on my keyboard):

Works for me (Linux, self-built Python 2.5 and wxPython 2.8.3.0).

Regards,


Björn

-- 
BOFH excuse #285:

Telecommunications is upgrading. 

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


Re: reading from sys.stdin

2007-04-12 Thread Steve Holden
Maric Michaud wrote:
 Le jeudi 12 avril 2007 10:34, Diez B. Roggisch a écrit :
 I presume this is an OS thing. The first lines aren't communicated to
 the process until either the file is closed - C-d - or the buffer the OS
 puts before the stream is filled. You can switch to unbuffered behviour
 somehow, google for it. Termios should be in your query.
 
 I don't know if this a python or OS thing, but I know that iterating over a 
 file is not like applying successive call to readline method. You should try 
 to use readline instead.
 
That, of course, is because files are iterators.

 The following work exactly the same on windows and Linux (python2.4) :
 
 f=open('txt')
 l=f.readline()
 while(l) :
 ...  print l,
 ...  print rest :  + f.read()
 ...  l=f.readline()
 ...
 foo
 rest : bar
 baz
 
 works as expected, while :
 
 f=open('txt')
 for l in f :
 ...  print l,
 ...  print rest :  + f.read()
 ...
 foo
 rest :
 bar
 rest :
 baz
 rest :
 
 doesn't, it seems that file iteratiion itself use a buffer. In python 2.5, 
 you 
 just can't do this :
 
 Python 2.5 (release25-maint, Dec  9 2006, 14:35:53)
 [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
 Type help, copyright, credits or license for more information.
 f=open('txt')
 for l in f :
 ...  print l,
 ...  print rest :  + f.read()
 ...
 foo
 Traceback (most recent call last):
   File stdin, line 3, in module
 ValueError: Mixing iteration and read methods would lose data
 
But you *can* do this (untested):

for l in f:
   print l,
   print rest:, f.next()

Of course there are always edge cases. In this particular instance I 
suspect that the handling of files with odd numbers of lines might be 
slightly different, but I can't work up enough enthusiasm to actually 
run this code. The error method pretty much explains what the problem 
is: you have to iterate over files or read them, you shouldn't try and 
do both on the same file.

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

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


Binary To File

2007-04-12 Thread Robert Rawlins - Think Blue
Hello Guys,

 

Is there an easy way to take binary data and build it into a file? Generally
this will be BLOB data drawn from a database, the data will be for jpg
images, I want to take the blob data and build it into a physical .jpg file.

 

Is there a simple function for doing this in python? Like binary2file() or
something along those lines?

 

Thanks,

 

Rob

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

Pyqt calling custom dialog

2007-04-12 Thread Marcpp
I need to call a custom dialog from a program, and return parameters.
Any idea or example?

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


Re: Any Pythonistas in Mexico?

2007-04-12 Thread Marcpp
On 12 abr, 09:41, Hugo González Monteverde [EMAIL PROTECTED] wrote:
 Hola,

 Leí este mail viejísimo en una lista. Yo uso Python y también quería
 saber quién pythoneaba en México. Todavía estás por ahí?

 Saludos,

 Hugo G.

Yo vivo en España.
Usas el pyqt?

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


Re: Creating an EXE for XLRD + WIN32COM + wxWidgets application - Help request

2007-04-12 Thread Larry Bates
BrendanC wrote:
 I've started learninhg Python and have developed a small Python app
 that imports Excel data into an Access mdb/jet database. This
 application has dependencies on the following:
 
 XLRD - http://cheeseshop.python.org/pypi/xlrd/0.5.2  -  (to read Excel
 files)
 Python windows extensions - http://starship.python.net/crew/mhammond/win32/
 - to use ADO
 wxPython GUI toolkit - http://www.wxpython.org/ - for the GUI
 interface
 
 Ideally I'd like to create a standalone app that I can deliver to a
 client who can will run this on a Windows system that has Access
 installed. (Python will not be installed on this system).
 
 I'm planning to use P2YEXE for the build - however I'm not sure if it
 is possible to include all the required components for this in a
 package. I imagine there may be a few 'gotchas' with this.
 
 Any suggestions on how to do this and are there some additional issues
 I might run into?
 
 Thx in advance
 
 BrendanC
 
I can tell you that I've used py2exe to build quite a number of apps
that depended on many different pieces.  I have not experience with XLRD
but the other pieces you use work just fine.  Check on www.py2exe.org
for docs an wiki.  There is also a newsgroup at gmane.comp.python.py2exe
that you can submit questions to if you like.  I know that it is
monitored by Mark Hammond, Thomas Heller, and other users of py2exe
that can help you.

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


Re: tuples, index method, Python's design

2007-04-12 Thread Antoon Pardon
On 2007-04-12, Steve Holden [EMAIL PROTECTED] wrote:
 Antoon Pardon wrote:
 On 2007-04-11, Terry Reedy [EMAIL PROTECTED] wrote:
 BJrn Lindqvist [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 On 4/10/07, Steve Holden [EMAIL PROTECTED] wrote:
 One might perversely allow extension to lists and tuples to allow

[3, 4] in [1, 2, 3, 4, 5, 6]

 to succeed, but that's forcing the use case beyond normal limits.
 I'd love to have that! There are at least one million use cases for
 finding a sequence in a sequence and implementing it yourself is
 non-trivial. Plus then both list and tuple's index methods would work
 *exactly* like string's. It would be easier to document and more
 useful. A big win.

 ===
 It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

 Strings are special in that s[i] can only be a (sub)string of length 1.
 'b' in 'abc' is True.  This makes looking for longer substrings easy.

 However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
 looking for sublists is different from looking for items.
 
 Well I think this illustrates nicely what can happen if you design by
 use cases.
 
 Let us assume for a moment that finding out if one list is a sublist of
 a second list gets considered something usefull enough to be included
 in Python. Now the in operator can't be used for this because it
 would create ambiguities. So it would become either a new operator
 or a new method. But whatever the solution it would be different
 from the string solution.
 
 That's because strings are different from other sequences. See below.

 Now if someone would have thought about how st1 in st2 would
 generalize to other sequemce if st1 contained more than one
 character they probably would have found the possible inconsistency
 that could create and though about using an other way than using
 the in-operator for this with strings. A way that wouldn't create
 ambiguities when it was considered to be extended to other sequences.
 
 The fact is that strings are the only sequences composed of subsequences 
 of length 1 - in other words the only sequences where type(s) == 
 type(s[0:1]) is an invariant condition.

Yes this allows you to do some things for strings in a way that would
be impossible or ambiguous should you want to do the same things for
other kind of sequences. 

The question is: should you?  

if you want to provide new functionality for strings and you have
the choice between doing it 

  1) in a way, that will make it easy to extend this functionality
 in a consistent way to other sequences 

  2) in a way that will make it impossible to extend this functionality
 in a consistent way to other sequences.

then I think that unless you have very good arguments you should pick (1). 

Because if you pick (2) even if this functionality is never extened in
the language itself, you make it more difficult for programmers to add
this functionality in a consistent way to a subclass of list themselves.

People are always defending duck-typing in this news group and now python
has chosen to choose the option that makes duck-typing more difficult.

 This was discussed (at my instigation, IIRC) on python-dev when Python 
 (2.4?) adopted the enhanced semantics for in on strings - formerly 
 only tests for single characters were allowed - but wasn't thought 
 significant enough to deny what was felt to be a natural usage for 
 strings only.

Which I consider a pity.

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


Re: reading from sys.stdin

2007-04-12 Thread Matimus
On Apr 12, 1:20 am, 7stud [EMAIL PROTECTED] wrote:
 I can't break out of the for loop in this example:

 --
 import sys

 lst = []
 for line in sys.stdin:
 lst.append(line)
 break

 print lst
 ---

 But, I can break out of the for loop when I do this:

 -
 import sys

 lst = []
 for line in open(aaa.txt):
 lst.append(line)
 break

 print lst
 --

 Why doesn't break work in the first example?

1. Why are you breaking in the for loop? That will only give you the
first line.

2. Your issue is caused by buffered IO. Because of the buffered IO,
your code is equivalent to doing this:

lst = []
s = sys.stdin.read() #All* of the reading up to EOF is done upfront.

for line in s:
lst.append(line)
break # I'm sure you don't really want the break here though :)

One way to get around the buffering is to do this:

[code]
# Open a file or the input stream
if filename:
f = open(filename,r)
else:
f = sys.stdin

# Then you check to see if your file is interactive
if f.isatty():
# This is unbuffered, and will iterate the same as f
f = iter(raw_input(),)

# Now do your stuff
lst = []
for line in f:
lst.append(line)

print lst
[/code]

* well, not ALL, it will read in chunks. But, I think they are 4096
Byte chunks by default.

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


Re: Code Explaination: Spelling correction code

2007-04-12 Thread Steven Bethard
Drew wrote:
 On Apr 11, 11:27 pm, Steven Bethard [EMAIL PROTECTED] wrote:
 Drew wrote:
 def known_edits2(word):
 return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in
 NWORDS)

 This is the same as:

  result = set()
  for e1 in edits1(word):
  for e2 in edits1(e1):
  if e2 in NWORDS:
  result.add(e2)
  return result

 The thing between the ``set(`` and ``)`` is called a generator
 comprehension if you'd like to look into it further.
 
 Thanks for the response. I'm somewhat familiar with generator/list
 comprehension but was unsure how multiple statements were evaluated
 when chained together. From your explanation, I'm assuming they are
 evaluated from the inside out rather than left to right or right to
 left.
 
 Does the mean that the comprehension on the inside is always evaluated
 first?

Not really (at least for the most literal interpretation of ``evaluated 
first``). I find it easiest to think of translating them into regular 
for loops by adding the appropriate indentation.

Starting with:

(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS)

Adding newlines:

(e2
  for e1 in edits1(word)
  for e2 in edits1(e1)
  if e2 in NWORDS)

Adding indentation:

(e2
  for e1 in edits1(word)
  for e2 in edits1(e1)
  if e2 in NWORDS)

Moving the add/append to the bottom:

for e1 in edits1(word)
 for e2 in edits1(e1)
 if e2 in NWORDS
 e2

Adding the remaining boiler-plate:

result = set()
for e1 in edits1(word):
 for e2 in edits1(e1):
 if e2 in NWORDS:
 result.add(e2)


So multiple for- and if-expressions are evaluated in the same order that 
they would normally be in Python, assuming the proper whitespace was added.

HTH,

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


Re: tuples, index method, Python's design

2007-04-12 Thread Carsten Haese
On Thu, 2007-04-12 at 14:10 +, Antoon Pardon wrote:
 People are always defending duck-typing in this news group and now python
 has chosen to choose the option that makes duck-typing more difficult.

Au contraire! The inconsistent behavior of in is precisely what
duck-typing is all about: Making the operator behave in a way that makes
sense in its context. Nobody seems to be complaining about + behaving
inconsistently depending on whether you're adding numbers or
sequences.

-Carsten


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


Re: OT: Question about RGB color method

2007-04-12 Thread John Salerno
John Salerno wrote:
 Sorry for this non-Python question, but since it's computer related I 
 know you guys will have an answer, and I don't really know where else to 
 ask. Mainly I'm just curious anyway.
 
 I'm wondering, why do computers use a RGB color scheme instead of the 
 primary colors? Is there something you can't do with yellow? It seems 
 weird that RGB can be combined to make all colors, when that's supposed 
 to be the job of the primary colors. I'm sure there some technical 
 computer-related reason that it had to be this way.
 
 Thanks.

Thanks guys! This is fascinating...just something I've never really 
thought about before. The Wikipedia article will give me something to 
read while I'm bored at work! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading from sys.stdin

2007-04-12 Thread [EMAIL PROTECTED]
On Apr 12, 4:20 am, 7stud [EMAIL PROTECTED] wrote:
 I can't break out of the for loop in this example:

 --
 import sys

 lst = []
 for line in sys.stdin:
 lst.append(line)
 break

 print lst
 ---

You may want to look at a related issue:

http://www.python.org/sf/1633941

Thanks,
Raghu.


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


Re: reading from sys.stdin

2007-04-12 Thread [EMAIL PROTECTED]
On Apr 12, 10:25 am, Matimus [EMAIL PROTECTED] wrote:

 * well, not ALL, it will read in chunks. But, I think they are 4096
 Byte chunks by default.

If you are referring to the read ahead buffer size, it is 8192 bytes.

Raghu.

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


Re: SQLite problems

2007-04-12 Thread Kirk Job Sluder
[EMAIL PROTECTED] writes:

 Hi there,

 I run Python 2.5 on a Mac OS X system with SQLite 3.2.8 installed via
 fink. Today I stumbled over the problem, that the sqlite3 module and
 sqlite3 from fink do not seem to work well together. I brought it down
 to this:

 Any ideas?

miss-match of versions between the fink and the Apple-supplied sqlite3?



 Regards,
 -Justin


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


PyX in Console and Script IDE

2007-04-12 Thread Stefan Schwärzler
Hi NG,
i'm hanging with following problem in python:
i have installed PyX to generate eps in python. in console-mode (call
python in shell) there are no problem. calling pyx via python-script i
got the following error (in a python ide f.e. wing2.0):
ImportError: No module named _pykpathsea

Have i forgot a path?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading from sys.stdin

2007-04-12 Thread Maric Michaud
Le jeudi 12 avril 2007 16:25, Matimus a écrit :
 # Then you check to see if your file is interactive
 if f.isatty():
     # This is unbuffered, and will iterate the same as f
     f = iter(raw_input(),)

This should be f = iter(raw_input,) and this will end in a EOFError and stop 
on blank line.
So you need a wrapper like :

 def stdin_iterator() :
... while(True) :
... try : yield raw_input()
... except EOFError : return
...
 f = stdin_iterator()

Do you really need to iterate on the file this way instead of using the 
straightforward readline method ?

 import sys
 l=sys.stdin.readline()

 while(l) :
... print l,
... l=sys.stdin.readline()




-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 4 26 88 00 97
Mobile: +33 6 32 77 00 21
-- 
http://mail.python.org/mailman/listinfo/python-list


Omaha Python Users Group - Meeting April 12, 2007

2007-04-12 Thread dundeemt
Omaha Python Users Group
http://www.OmahaPython.org

When: April 12, 2007 @ 7:00pm
Where:
  Reboot The User
  13416 A Street
  Omaha, NE 68144

For More Information, please see http://www.omahapython.org/

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


  1   2   3   >