RE: Does altering a private member decouple the property's value?

2007-06-22 Thread Ethan Kennerly
Thanks for the help!  Using the "class name (object)" syntax fixed my
problem.

Usually, I don't need properties, but in the case of a dependent attribute,
I used a set method of a property to update that dependent attribute.  I
have a stopwatch class with a time limit property.  When the time limit is
changed, the dependent attribute, remaining time, should also change.

I am having to unteach myself some of the defensive programming techniques
in C++, such as using name mangling to ensure privacy, when privacy is not
the most important criterion.  For prototyping, starting public and going
"private" later is more efficient when refactoring.  And since properties
have the same access signature as a public member, it can be done without
changes to the client.

-- Ethan


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


Retrieving a stacktrace from an exception object / forwarding an exception

2007-06-22 Thread Samuel
Hi,

I am trying to wrap a function that throws an exeption in such a way
that the stacktrace is logged into a file and the exception is
forwarded after that. For example:

---
def my_func():
raise Exception("hello")

def wrapper():
try:
my_func()
except Exception, e:
f = open("logfile", 'a')
f.write(e.stacktrace())
raise e

wrapper() # should throw the exception with a stacktrace showing
my_func()
---

Any idea if and how this can be done?

-Samuel

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


Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Gabriel Genellina
En Fri, 22 Jun 2007 02:48:50 -0300, Roc Zhou <[EMAIL PROTECTED]>  
escribió:

> I know what's wrong. Thank you. And I think
> try:
> return self.__dict__[attr_name]
> is unnecessary, because python will do it itself for us.

Exactly; by the time __getattr__ is called, you already know attr_name is  
not there.

> So now I have to overload __str__, but how can I make self.__str__
> print as builtin str(): at here, I want get the result like:
> 
> ?

I would do the opposite: *only* create inexistent attributes when they are  
not "special". This way you don't mess with Python internals.

...   def __getattr__(self, name):
... if name[:2]!='__' or name[-2:]!='__':
...   self.__dict__[name] = 'inexistent'
...   return self.__dict__[name]
... raise AttributeError,name

This way you don't create "fake" attributes for things like __bases__ by  
example, and dir(), vars(), repr() etc. work as expected.

-- 
Gabriel Genellina

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


Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Gabriel Genellina
En Fri, 22 Jun 2007 03:43:26 -0300, Roc Zhou <[EMAIL PROTECTED]>  
escribió:

> I'm sorry but I still have a question, look at this example:
 class test:
> ... def __init__(self):
> ... self.x = 1
> ... def __getattr__(self, attr_name):
> ... print attr_name
> ... if attr_name == 'y':
> ... return 2
> ... else:
> ... raise AttributeError, attr_name
> ...
 t = test()
 t.x
> 1
 t.y
> y
> 2
 print t.x
> 1
 print t
> __str__
> __repr__
> <__main__.test instance at 0xb7f6d6cc>
>
> Since __str__ and __repr__ does not exist because their names was
> printed, why not the "AttributeError" be raised?

This is the implementation of str() in action; tries to find a __str__  
method and fails; tries to find a __repr__ instead and fails; then uses  
the default representation.
See 

-- 
Gabriel Genellina

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


Re: Packing a simple dictionary into a string - extending struct?

2007-06-22 Thread Jonathan Fine
Jonathan Fine wrote:

> Thank you for this suggestion.  The growing adoption of JSON in Ajax
> programming is a strong argument for my using it in my application, although
> I think I'd prefer something a little more binary.
> 
> So it looks like I'll be using JSON.

Well, I tried.  But I came across two problems (see below).

First, there's bloat.  For binary byte data, one average one
character becomes just over 4.

Second, there's the inconvenience.  I can't simple take a
sequence of bytes and encode them using JSON.  I have to
turn them into Unicode first.  And I guess there's a similar
problem at the other end.

So I'm going with me own solution: 
http://mathtran.cvs.sourceforge.net/mathtran/py/bytedict.py?revision=1.1&view=markup

It seems to be related to cerializer:
http://home.gna.org/oomadness/en/cerealizer/index.html

It seems to me that JSON works well for Unicode text, but not
with binary data.  Indeed, Unicode hides the binary form of
the stored data, presenting only the code points.  But I don't
have Unicode strings!

Here's my test script, which is why I'm not using JSON:
===
import simplejson

x = u''
for i in range(256):
 x += unichr(i)

print len(simplejson.dumps(x)), '\n'

simplejson.dumps(chr(128))
===

Here's the output
===
1046  # 256 bytes => 256 * 4 + 34 bytes

Traceback (most recent call last):
  
   File "/usr/lib/python2.4/encodings/utf_8.py", line 16, in decode
 return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: 
unexpected code byte
===

-- 
Jonathan

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


Re: why __repr__ affected after __getattr__ overloaded?

2007-06-22 Thread Peter Otten
Roc Zhou wrote:

> I'm sorry but I still have a question, look at this example:
 class test:
> ... def __init__(self):
> ... self.x = 1
> ... def __getattr__(self, attr_name):
> ... print attr_name
> ... if attr_name == 'y':
> ... return 2
> ... else:
> ... raise AttributeError, attr_name
> ...
 t = test()
 t.x
> 1
 t.y
> y
> 2
 print t.x
> 1
 print t
> __str__
> __repr__
> <__main__.test instance at 0xb7f6d6cc>
> 
> Since __str__ and __repr__ does not exist because their names was
> printed, why not the "AttributeError" be raised?

Because classic classes invoke

t.__getattr__(self, "__repr__")

and expect that to return a proper __repr__() method -- unless __getattr__()
raises an AttributeError: 

>>> class Test:
... def __getattr__(self, name):
... if name == "__repr__":
... raise AttributeError
... return "" % name
...
>>> t = Test()
>>> t
<__main__.Test instance at 0x401d42ac>

If you use newstyle classes you won't run into that particular problem:

>>> class Test(object):
... def __getattr__(self, name):
... return "" % name
...
>>> t = Test()
>>> t
<__main__.Test object at 0x401d426c>
>>> t.yadda
""

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-22 Thread Paul Rubin
John Nagle <[EMAIL PROTECTED]> writes:
> What we need are better implementations than CPython, not
> hokey attribute schemes bolted onto the language.  We're seeing
> stuff go in that's easy to add to CPython, but not necessarily
> good for the language as a whole.

I think it was a real loss that Python 3.0 proposals were closed
before PyPy was widely deployed and we had a chance to get more
experience with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Internationalised email subjects

2007-06-22 Thread bugmagnet
Thanks Martin,

The "Some Chinese characters" are loaded from a MySQL table and are
encoded in GB2312 format.

I've added the following line at the top of the code:

# -*- coding: GB2312 -*-

I've also added the following line into the code:

h = Header(subject.encode('GB2312'), 'GB2312')

Note that the 'subject' variable consists of GB2312 encoded text, so I
am not sure if it is necessary to call the subject.encode('GB2312')
method.  When I try to execute this code, I get the following error:

File "/home/web88/html/app/test.py", line 17,
in Header(subject.encode('GB2312'), 'GB2312')
LookupError: unknown encoding: GB2312

Any idea what may be wrong?


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


Re: "assert" annoyance

2007-06-22 Thread Miles
On Jun 22, 2:45 am, "Evan Klitzke" <[EMAIL PROTECTED]> wrote:
> On 6/21/07, Miles <[EMAIL PROTECTED]> wrote:
>
> > On Jun 22, 1:31 am, Paul Rubin  wrote:
> > > What I really want is for any assertion failure, anywhere in the
> > > program, to trap to the debugger WITHOUT blowing out of the scope
> > > where the failure happened, so I can examine the local frame.  That
> > > just seems natural, but I don't see an obvious way to do it.
>
> > You could run the entire program through pdb:
> > 
> > #!/usr/bin/env python -m pdb
>
> > print "Hello!"
> > assert False
> > print "...world!"
> > 
>
> You can only pass one argument to a command that you invoke with the
> shebang sequence, so this won't work the way you wrote it.
>
> --
> Evan Klitzke <[EMAIL PROTECTED]>

It actually does work on my system (OS X); I didn't realize it wasn't
portable.

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


Re: "assert" annoyance

2007-06-22 Thread Thomas Heller
Paul Rubin schrieb:
> So I have some assert statements in my code to verify the absence of
> some "impossible" conditions.  They were useful in debugging and of
> course I left them in place for "real" runs of the program.  Umpteen
> hours into a run, an assertion failed, and of course since failure
> was "impossible", I didn't catch the exception so the whole program
> crashed.  I don't know what I'd have done with the exception anyway,
> since it would have had to be caught at an outer scope where the
> data I cared about was no longer around, or else I'd have had to
> predict in advance what I needed to examine and pass that as a
> an arg to the assert statement.
> 
> What I really want is for any assertion failure, anywhere in the
> program, to trap to the debugger WITHOUT blowing out of the scope
> where the failure happened, so I can examine the local frame.  That
> just seems natural, but I don't see an obvious way to do it.  Am I
> missing something?  I guess I could replace all the assertions with
> function calls that launch pdb, but why bother having an assert
> statement?

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

Thomas

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


Thanks a lot Gabriel :) :: unable to execute to a python script

2007-06-22 Thread Bala Subramanyam vemu


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

configparser shuffles all sections ?

2007-06-22 Thread stef
hello,

I just used configparser for the first time and discovered that it 
shuffled all my sections,
and the contents of the sections too.

This makes human manipulation of the file impossible.

Is there a way to prevent this shuffling,
or are there other libraries that can handle windows ini-files without 
reshuffling ?

thanks,
Stef Mientki

Kamer van Koophandel - handelsregister 41055629  / Netherlands Chamber of 
Commerce - trade register 41055629


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


Re: sqlite newbie questions

2007-06-22 Thread [EMAIL PROTECTED]
On Jun 21, 11:54 am, Luis M. González <[EMAIL PROTECTED]> wrote:
> You need to learn sql if you want to deal with databases.
> Don't worry, it's very easy, and here is a very good resource to get
> you up and running in a few minutes:http://www.sqlcourse.com
>
> Good luck!
> Luis

Thanks Luis, will check out the site you recommended.

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

Re: "assert" annoyance

2007-06-22 Thread Evan Klitzke
On 6/22/07, Miles <[EMAIL PROTECTED]> wrote:
> On Jun 22, 2:45 am, "Evan Klitzke" <[EMAIL PROTECTED]> wrote:
> > On 6/21/07, Miles <[EMAIL PROTECTED]> wrote:
> >
> > > On Jun 22, 1:31 am, Paul Rubin  wrote:
> > > > What I really want is for any assertion failure, anywhere in the
> > > > program, to trap to the debugger WITHOUT blowing out of the scope
> > > > where the failure happened, so I can examine the local frame.  That
> > > > just seems natural, but I don't see an obvious way to do it.
> >
> > > You could run the entire program through pdb:
> > > 
> > > #!/usr/bin/env python -m pdb
> >
> > > print "Hello!"
> > > assert False
> > > print "...world!"
> > > 
> >
> > You can only pass one argument to a command that you invoke with the
> > shebang sequence, so this won't work the way you wrote it.
> >
> > --
> > Evan Klitzke <[EMAIL PROTECTED]>
>
> It actually does work on my system (OS X); I didn't realize it wasn't
> portable.

This sort of surprised me (in a good way), since I just took the one
argument rule for granted. It's always bugged me that I couldn't do,
say, #!/usr/bin/env python -O. So it's nice to see that OS X splits
the arguments, even if this isn't completely portable! I did some
research on this and it looks like a few other Unices do it too. If
anyone is interested, there's a table documenting the behavior of
different systems at
http://www.in-ulm.de/~mascheck/various/shebang/#results

Maybe I should start using a Mac ;-)

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


Why Pay For Cable? Turn Your Computer Into A TV

2007-06-22 Thread edcwealth1
3000 Channels delivered straight to your desktop!
Stop the monthly Cable bills for mediocre TV and get high quality
streaming satellite TV directly on your PC!

http://cgeer319.ipodpsp.hop.clickbank.net/

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


sqlite newbie question - how to know if a table exists?

2007-06-22 Thread [EMAIL PROTECTED]
Hello,

Another newbie question: How do I know if there is a table with
certain name in a sqlite database? What i'm doing now is just create
the table with that name, if exception occurs, that means the table is
already created. Am i correct? Any better way? Thank you.

kelie

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


header intact

2007-06-22 Thread datulaida ali

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

Apple Pie Parser with Python?

2007-06-22 Thread datulaida ali

Hi,

How to integrate Apple Pie Parser with Python? Any suggestion to parsed text
with Python?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: configparser shuffles all sections ?

2007-06-22 Thread stef
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, stef wrote:
>
>   
>> I just used configparser for the first time and discovered that it 
>> shuffled all my sections, and the contents of the sections too.
>> 
>
> The data is stored in dictionaries.
>   
So there should be some way to sort it ?
>   
>> This makes human manipulation of the file impossible.
>> 
>
> Why so?
>   
I've about 1000 sections ;-)

> Ciao,
>   Marc 'BlackJack' Rintsch
>   

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


Re: configparser shuffles all sections ?

2007-06-22 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, stef wrote:

> I just used configparser for the first time and discovered that it 
> shuffled all my sections, and the contents of the sections too.

The data is stored in dictionaries.

> This makes human manipulation of the file impossible.

Why so?

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


Re: "assert" annoyance

2007-06-22 Thread Ben Finney
Paul Rubin  writes:

> So I have some assert statements in my code to verify the absence of
> some "impossible" conditions.  They were useful in debugging and of
> course I left them in place for "real" runs of the program.  Umpteen
> hours into a run, an assertion failed, and of course since failure
> was "impossible", I didn't catch the exception so the whole program
> crashed.

This is exactly the sort of check which is best done as unit
tests. The program has no 'assert' cruft in it, and the tests can be
as comprehensive as needed without having any impact on the actual
running program.

-- 
 \ Legionnaire: "We have their leader captive!"  C泡r: "Is he |
  `\bound?"  Legionnaire: "Of his health I know not, sir."  -- The |
_o__)Goon Show, _The Histories Of Pliny The Elder_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Vilnius/Post EuroPython PyPy Sprint 12-14th of July

2007-06-22 Thread Michael Hudson
The PyPy team is sprinting at EuroPython again and we invite
you to participate in our 3 day long sprint at the conference hotel
- Reval Hotel Lietuva.

If you plan to attend the sprint we recommend you to listen to the PyPy
technical talks (`EuroPython schedule`_) during the
conference since it will give you a good overview of the status of development.

On the morning of the first sprint day (12th) we will also have a
tutorial session for those new to PyPy development.  As 3 days is relatively
short for a PyPy sprint we suggest to travel back home on the 15th if
possible (but it is ok to attend less than 3 days too).

--
Goals and topics of the sprint
--

There are many possible and interesting sprint topics to work on - here
we list some possible task areas:

* completing the missing python 2.5 features and support
* write or port more extension modules (e.g. zlib is missing)
* identify slow areas of PyPy through benchmarking and work on improvements,
  possibly moving app-level parts of the Python interpreter to interp-level
  if useful.
* there are some parts of PyPy in need of refactoring, we may spend some time
  on those, for example:

- rctypes and the extension compiler need some rethinking
- support for LLVM 2.0 for the llvm backend
- ...

* some JIT improvement work
* port the stackless transform to ootypesystem
* other interesting stuff that you would like to work on ...;-)


Registration


If you'd like to come, please subscribe to the `pypy-sprint mailing list`_
and drop a note about your interests and post any questions.  More
organisational information will be sent to that list.

Please register by adding yourself on the following list (via svn):

  http://codespeak.net/svn/pypy/extradoc/sprintinfo/post-ep2007/people.txt

or on the pypy-sprint mailing list if you do not yet have check-in rights:

  http://codespeak.net/mailman/listinfo/pypy-sprint

---
Preparation (if you feel it is needed):
---

* read the `getting-started`_ pages on http://codespeak.net/pypy

* for inspiration, overview and technical status you are welcome to
  read `the technical reports available and other relevant documentation`_

* please direct any technical and/or development oriented questions to
  pypy-dev at codespeak.net and any sprint organizing/logistical
  questions to pypy-sprint at codespeak.net

* if you need information about the conference, potential hotels,
  directions etc we recommend to look at http://www.europython.org.


We are looking forward to meet you at the Vilnius Post EuroPython
PyPy sprint!

The PyPy team


.. See also ..

.. _getting-started:
http://codespeak.net/pypy/dist/pypy/doc/getting-started.html
.. _`pypy-sprint mailing list`:
http://codespeak.net/mailman/listinfo/pypy-sprint
.. _`the technical reports available and other relevant
documentation`: http://codespeak.net/pypy/dist/pypy/doc/index.html
.. _`EuroPython schedule`: http://europython.org/timetable
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Indenting in Emacs

2007-06-22 Thread Michael Hoffman
John J. Lee wrote:
> Eugene Morozov <[EMAIL PROTECTED]> writes:
> 
>> Steven W. Orr пишет:
>>  > Ok. I'm not stupid but I do not see a 4.78 anywhere even though I
>> see refs
>>> from google. I have 4.75 The SVN tree doesn't seem to even have
>>> that. 
>>>
>>> I checked the latest copy out from sourceforge and that was 4.75 too.
>>>
>>> Can someone please tell me where to find the latest?
>>>
>> It's from Emacs 22.
> 
> Note that's a different python-mode to the old one that lives on SF.
> Yes, there are now two of them.

Which one is better?
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Internationalised email subjects

2007-06-22 Thread bugmagnet
Thanks Richie,

I've tried removing the encode('GB2312') line, so the code looks like
this:

h = Header(subject, 'GB2312')

However, this line still causes the following error message:

Traceback (most recent call last):
File "/home/web88/html/app/sendmail.py", line 314, in
h = Header(subject, 'GB2312')
File "/usr/lib/python2.2/email/Header.py", line 188, in __init__
self.append(s, charset, errors)
File "/usr/lib/python2.2/email/Header.py", line 272, in append
ustr = unicode(s, incodec, errors)
LookupError: unknown encoding: gb2312 )

Any ideas?

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


Re: sqlite newbie question - how to know if a table exists?

2007-06-22 Thread Gerhard Häring
[EMAIL PROTECTED] wrote:
> Hello,
> 
> Another newbie question: How do I know if there is a table with
> certain name in a sqlite database? What i'm doing now is just create
> the table with that name, if exception occurs, that means the table is
> already created. Am i correct? Any better way? Thank you.

That approach is ok. If your SQLite library is recent enough (I don't 
know the exact version), you can use "create table if not exists ...".

For older SQLite releases, you can check like this:

len(con.execute("pragma table_info(?)", ("tablename",)).fetchall()) > 0

or

con.execute("select count(*) from sqlite_master where name=?",
   ("tablename" ,)).fetchone()

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


Re: Retrieving a stacktrace from an exception object / forwarding an exception

2007-06-22 Thread alg
Use the traceback module:

def log_exception():
"""This function will log the current exception's traceback
   to logfile
"""
import traceback
f = open("logfile", 'a')
traceback.print_exc(32, f)
f.close()

def my_func():
raise Exception

def wrapper():
try:
my_func()
except Exception, e:
log_exception()
raise e


On Jun 21, 11:54 pm, Samuel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am trying to wrap a function that throws an exeption in such a way
> that the stacktrace is logged into a file and the exception is
> forwarded after that. For example:
>
> ---
> def my_func():
> raise Exception("hello")
>
> def wrapper():
> try:
> my_func()
> except Exception, e:
> f = open("logfile", 'a')
> f.write(e.stacktrace())
> raise e
>
> wrapper() # should throw the exception with a stacktrace showing
> my_func()
> ---
>
> Any idea if and how this can be done?
>
> -Samuel


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


Re: Retrieving a stacktrace from an exception object / forwarding an exception

2007-06-22 Thread Gabriel Genellina
En Fri, 22 Jun 2007 03:54:12 -0300, Samuel <[EMAIL PROTECTED]> escribió:

> I am trying to wrap a function that throws an exeption in such a way
> that the stacktrace is logged into a file and the exception is
> forwarded after that. For example:
>
> ---
> def my_func():
> raise Exception("hello")
>
> def wrapper():
> try:
> my_func()
> except Exception, e:
> f = open("logfile", 'a')
> f.write(e.stacktrace())
> raise e
>
> wrapper() # should throw the exception with a stacktrace showing
> my_func()
> ---
>
> Any idea if and how this can be done?

- see the traceback module  

- use a bare raise (not raise e); this reraises the active exception  
without changing its context.

-- 
Gabriel Genellina

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


Re: configparser shuffles all sections ?

2007-06-22 Thread Nick Craig-Wood
stef <[EMAIL PROTECTED]> wrote:
>  I just used configparser for the first time and discovered that it 
>  shuffled all my sections,
>  and the contents of the sections too.
> 
>  This makes human manipulation of the file impossible.
> 
>  Is there a way to prevent this shuffling,

You could try getting yourself an ordered dictionary implmentation,
say

  http://www.voidspace.org.uk/python/odict.html

Then doing something like this (untested)

class MyConfigParser(SafeConfigParser):
def __init__(self, defaults=None):
SafeConfigParser.__init__(defaults)
self._sections = odict()
self._defaults = odict()

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-22 Thread Dave Baum
In article <[EMAIL PROTECTED]>,
 kaens <[EMAIL PROTECTED]> wrote:

> On 6/20/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> 
> > That is exactly the problem - there is no "some more" static typing.
> > There is static typing - or not. You can't have it "just a bit".
> 
> Couldn't a language be made so that if you declared a variable like, say:
> 
> string foo = "I'm a string"
> 
> it would be a string, and always a string, and if you declared a variable like
> 
> foo = "i'm a dynamic variable"
> 
> it would be considered dynamic?
> 
> This doesn't seem like it would be too hard to add in to a language
> that already had dynamic typing (But then again, I am inexperienced -
> although interested in - language design).
> 
> It seems to me like this could be really useful, but I'm not aware of
> any language implementing something like this.

Common Lisp has a mechanism similar to what you described.  In general, 
variables are completely dynamic.  However, it is possible to declare 
individual variables to be of specific types.  There are also 
declarations that allow you to specify your preferences for speed versus 
safety.  The upshot of all of this is that the language is a dynamic 
language most of the time, but the programmer can choose to give the 
compiler a bit more information, and with that information a good 
compiler can generate more efficient code (often competitive with the 
speed of C code).

The Common Lisp approach is not without its problems (for one thing, a 
lot of the behavior when type declarations are not met is implementation 
dependent).  But I think there are some ideas in there that could be 
applied to Python.

On the other hand, I'm pretty happy with Python/SWIG/C++ for performance 
critical code, so I'm not sure if optional static typing would really be 
of much use unless the Python compiler got *very* good at generating 
optimized code when declarations were present.

I still think it would be handy to easily specify the expected types of 
function arguments.  I sometimes write code in this pattern:

def foo(a, b):
"a, b - instances of Bar"
assert isinstance(a, Bar)
assert isinstance(b, Bar)
# do some stuff

Note that the expectation that 'a' and 'b' are to be of type Bar is 
specified twice: once for a runtime check, once for the docstring.  It 
might be nice if there were a mechanism to specify it once and have the 
docstring and runtime check both make use of that information:

>>>def foo(Bar a, Bar b):
>>># do some stuff

>>>foo(1, Bar())
TypeError: argument a is not of type Bar

>>>help(foo)
foo(Bar a, Bar b)

On the downside, this sort of mechanism might do more harm than good.  
For one thing, it would really clash with duck typing.  For another, 
anyone coming to Python from Java/C++ would probably use those 
declarations *everywhere*, even when there isn't a good reason to limit 
the type.

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


Re: string formatter %x and a class instance with __int__ cannot handle long

2007-06-22 Thread Gabriel Genellina
En Thu, 21 Jun 2007 05:36:42 -0300, Kenji Noguchi <[EMAIL PROTECTED]>  
escribió:

> I confirmed that "%08x" % int(y) works. And yes, I'm hoping so.
> It actually works that way if the v is less than or equal to 0x7.
>
>> It is a bug, at least for me, and I have half of a patch addressing it.  
>> As a workaround, convert explicitely to long before formatting.
>
> I'm interested in your patch.  What's the other half still missing?

As you have seen, PyString_Format doesn't handle well objects that can be  
converted to long but are not longs themselves; I've modified that  
function, but PyUnicode_Format has a similar problem, that's "the other  
half".
Maybe this weekend I'll clean those things and submit the patch.

-- 
Gabriel Genellina

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-22 Thread Ben Finney
Paul Rubin  writes:

> I think it was a real loss that Python 3.0 proposals were closed
> before PyPy was widely deployed and we had a chance to get more
> experience with it.

I think it's great that we're going to get Python 3.0 soon, and that
Python 4.0 proposals will benefit from a long period of familiarity
with widely-deployed PyPy :-)

-- 
 \   "I bought some batteries, but they weren't included; so I had |
  `\ to buy them again."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Retrieving a stacktrace from an exception object / forwarding an exception

2007-06-22 Thread Samuel
Thanks, Guys, this works as expected.

-Samuel

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


Re: Type of __builtins__ changes from module import to execution?

2007-06-22 Thread Marc Christiansen
Adam Hupp <[EMAIL PROTECTED]> wrote:
> I've noticed some unexpected behavior with __builtins__ during module
> import.  It seems that during module import __builtins__  is a dict
> but at all other times it is a module.
> 
> For example, if the file testmod.py has these contents:
> 
> print type(__builtins__)
> print "has str attr", hasattr(__builtins__, 'str')
> 
> The output differs depending on how it is run:
> 
> $ python ~/testmod.py
> 
> has str True
> 
> vs.
> 
> $ python -c 'import testmod'
> 
> has str False
> 
> Anyone know if there a reason for this behavior?Is it a bug?  I've
> seen this in 2.4 and 3.0.
> 
> -Adam

No, it's not a bug. __builtins__ is an implementation detail. You want
__builtin__. See 

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


Re: Does altering a private member decouple the property's value?

2007-06-22 Thread Bruno Desthuilliers
Ethan Kennerly a écrit :
> Thanks for the help!  Using the "class name (object)" syntax fixed my
> problem.
> 
(snip)
 >
> I am having to unteach myself some of the defensive programming techniques
> in C++, such as using name mangling to ensure privacy, when privacy is not
> the most important criterion.  For prototyping, starting public and going
> "private" later is more efficient when refactoring. 

(just a clarification for Python new-comers reading this thread)

This is the usual way to handle public (non-callable) attributes - 
starting with a plain attribute, then refactoring to a property if and 
when needed.

But this doesn't imply you should only use 'public' attributes. While it 
has no real notion of privacy (ie: no language-enforced access 
restriction), Python has a well-established convention for marking 
attributes and methods as "protected" : prefixing the name with a 
*single* underscore. This won't invoke any name-mangling nor prevent 
direct access to the attribute, but warn anyone that this attribute is 
implementation, IOW "don't mess with it or you're on your own".

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


Re: configparser shuffles all sections ?

2007-06-22 Thread Steven D'Aprano
On Fri, 22 Jun 2007 09:28:42 +0200, stef wrote:

> hello,
> 
> I just used configparser for the first time and discovered that it 
> shuffled all my sections,
> and the contents of the sections too.
> 
> This makes human manipulation of the file impossible.

Having read the rest of this thread, I think Stef is not worried about
*human* manipulation. There is nothing stopping a human from editing the
INI file in a text editor, except perhaps the sheer size of the file.

But what I think is the actual problem is that, having read the INI file
into dictionaries, the order is lost. For that matter, so are comments,
and probably whitespace. That makes it impractical to generate an INI
file, then read it with configparser, make changes to the configparser
data, then write it back to the INI file.

Unfortunately, I don't think configparser can deal with that, and I'm not
aware of any libraries that will.


-- 
Steven

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Michal Nazarewicz
Twisted <[EMAIL PROTECTED]> writes:

> On Jun 20, 5:03 pm, Kaldrenon <[EMAIL PROTECTED]> wrote:
>> I still have a good deal to learn, even of the basics, but I've toyed
>> with it casually for a little bit (a total of two hours at most, but
>> almost certainly less) and I already know enough that finding out how
>> to do anything else IS trivial. It's not a program whose controls
>> throw themselves at you, exactly, but with a touch of patience and a
>> genuine interest in learning, it's not too bad.
>
> I don't know what software you're describing, but it's obviously not
> emacs, unless there have been some HUGE changes to (at minimum) the
> help and pane-navigation (er, excuse me, "window"-navigation)
> controls...

I don't know about *your* version of Emacs but in *my* version one can
switch windows using mouse.  I think that's pretty easy especially for
beginners who are used to Windows.

There was also a Help menu on menu bar but I disabled menu bar since
keybindings are more convenient for me.

-- 
Best regards, _ _
 .o. | Liege of Serenly Enlightened Majesty of  o' \,=./ `o
 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
 ooo +---ooO--(_)--Ooo--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Neil Cerutti
On 2007-06-21, Douglas Alan <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> writes:
>> Seriously, maybe Python looks like 'blub' (thanks, Paul
>> Graham), to the skilled Lisp user, but it makes a lot of other
>> languages look like 'blub', too, including, sometimes, Lisp:
>> Lisp has to 'blub' generators.
>
> Actually, Scheme has first class continuations, and with
> continuations and macros you could easily implement generators,
> and I'm sure someone has.  Whether such a library has been
> widely adopted for Scheme, though, I have no idea.

A strength of Lisp is the ability to cherry-pick features from
different Lisp implementations, as seen here.

Common Lisp has powerful macro facilities and generates fast
code, but hasn't got continuations.

Scheme has continuations, but is *not* fast, and has simpler,
more complicated macro facilities. ;)

> "Lisp is worth learning for the profound enlightenment
> experience you will have when you finally get it; that
> experience will make you a better programmer for the rest of
> your days, even if you never actually use Lisp itself a lot."
> -- Eric Raymond

You don't need to learn Lisp to get the ephiphany, though.
Haskell, Ocaml or ML would likely be more enlightening to a
Python programmer, who will see much of Lisp as old hat.

That said, I wouldn't give up the summer I spent studying _Simply
Scheme_. Writing recursive code seemed totally alien to me before
that. On the other hand, _Simply Scheme_ uses a logo-like
adaptation of Scheme for 90% of the course, wisely disguising the
total weird unintuitiveness of list manipulation until the
student has been fully brainwashed. ;)

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


Re: Packing a simple dictionary into a string - extending struct?

2007-06-22 Thread John Machin
On Jun 22, 5:08 pm, Jonathan Fine <[EMAIL PROTECTED]> wrote:
> Jonathan Fine wrote:
> > Thank you for this suggestion.  The growing adoption of JSON in Ajax
> > programming is a strong argument for my using it in my application, although
> > I think I'd prefer something a little more binary.
>
> > So it looks like I'll be using JSON.
>
> Well, I tried.  But I came across two problems (see below).
>
> First, there's bloat.  For binary byte data, one average one
> character becomes just over 4.
>
> Second, there's the inconvenience.  I can't simple take a
> sequence of bytes and encode them using JSON.  I have to
> turn them into Unicode first.  And I guess there's a similar
> problem at the other end.
>
> So I'm going with me own 
> solution:http://mathtran.cvs.sourceforge.net/mathtran/py/bytedict.py?revision=...
>

def unpack(bytes, unpack_entry=unpack_entry):
'''Return dictionary gotten by unpacking supplied bytes.
Both keys and values in the returned dictionary are byte-strings.
'''
bytedict = {}
ptr = 0
while 1:
key, val, ptr = unpack_entry(bytes, ptr)
bytedict[key] = val
if ptr == len(bytes):
break
# That's beautiful code -- as pretty as a cane-toad.
# Well-behaved too, a very elegant response to unpack(pack({}))
# Try this:
blen = len(bytes)
while ptr < blen:
key, val, ptr = unpack_entry(bytes, ptr)
bytedict[key] = val

return bytedict

HTH,
John

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


Re: something similar to shutil.copytree that can overwrite?

2007-06-22 Thread Ben Sizer
On 22 Jun, 02:34, Justin Ezequiel <[EMAIL PROTECTED]>
wrote:
> def copytree(src, dst, symlinks=False):
> """Recursively copy a directory tree using copy2().
>
> The destination directory must not already exist.
>
> XXX Consider this example code rather than the ultimate tool.
>
> """
> names = os.listdir(src)
> if not os.path.exists(dst): os.makedirs(dst) # add check here

That's the easy bit to fix; what about overwriting existing files
instead of copying them? Do I have to explicitly check for them and
delete them? It seems like there are several different copy functions
in the module and it's not clear what each of them do. What's the
difference between copy, copyfile, and copy2? Why do the docs imply
that they overwrite existing files when copytree skips existing
files?

--
Ben Sizer

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


Re: subprocess.popen question

2007-06-22 Thread [EMAIL PROTECTED]
On Jun 22, 12:10 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 22 Jun 2007 01:05:36 -0300, [EMAIL PROTECTED]  
> <[EMAIL PROTECTED]> escribió:
>
>
>
>
>
> >> >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v",
> >> >> >> "outfile=testdat.sco", "i1.sco"]
> >> >> >> output = subprocess.Popen(cmd,
> >> >> stdout=subprocess.PIPE).communicate()[0]
> >> >> >> lines = output.splitlines()
> >> >> >> for line in lines:
> >> >> >>print line
>
> >> >> >  C:\dex_tracker\pipe1.py
> >> >> > Traceback (most recent call last):
> >> >> >  File "C:\dex_tracker\pipe1.py", line 14, in
> >> >> > last_line = subprocess.Popen([cmd],
> >> >> > stdout=subprocess.PIPE).communicate()[0]
> >> >> >  File "C:\Python25\lib\subprocess.py", line 593, in __init__
> >> >> > errread, errwrite)
> >> >> >  File "C:\Python25\lib\subprocess.py", line 793, in _execute_child
> >> >> > startupinfo)
> >> >> > WindowsError: [Error 2] The system cannot find the file specified
> >> >> > Script terminated.
>
> >> >> > I can write it out as a batch file and then run it but that is a  
> >> messy
> >> >> > hack..
>
> >> >> If cmd is a list of arguments, like the example above, you should use
> >> >> subprocess.Popen(cmd,...) (like the example above, too).
>
> >> > I had cut and pasted the example in to get that error...  could it be
> >> > a problem with ms windows??? (I am at a library computer befour work
> >> > so that ended my testing)
>
> >> Note the call to subprocess.Popen- is the first argument [cmd] or cmd?
> >> What do you get with print repr(cmd)?
> >> Do you have gawk installed on that machine too?
>
> > gawk is installed..  I do fine when I just call gawk I get all the
> > options to use with it but the minute I try to use the options with it
> > I have problems.  I have done it with batch files but then I would
> > have to write out a batch file and then run the batch file.  seems
> > like more work than I should have to do to use options with a command
> > line program..  I have done this in other cases with os.startfile and
> > other cases and would like to fix it.
>
> Ok, but please check *what* are the arguments toPopen. If cmd is a *list*  
> as shown on the first quoted line on this message, you should call  
> subprocess.Popen(cmd, ...) as shown on the third line on this message, but  
> your traceback shows that you are usingPopen([cmd], ...)
> Can you see the difference?
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -

I seemed to have it working sorta when I run it and save the results I
am noticing that in spe it spaces correctly but when I save it to a
file I can open it in wordpad there is only one line.  when I open in
up in WinXound (A csound editor) it is double spaced.  if I do it in a
batch file the output file is spaced correctly..  when I do splitlines
it is giving me one charecter down the page as output..  Do I need to
do something or can I do something to put an end of line charecter in
the output??

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

RE: Changing the names of python keywords

2007-06-22 Thread vedrandekovic
Hello again,

Thanks for everything previously, I was change  the grammar and Lib/
keyword.py, now
Python recognize "koristiti" as a keyword, but that is not enough:

when I write in my python shell:

>>> koristiti os   # "koristiti" get keyword "color", but I get 
>>> error:

File "", line 1
koristi os
 ^
SyntaxError: invalid syntax

and now, when I write:

>>> import os   # "import" don't get keyword "color" but still 
>>> working



 
Please help me,thanks

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


Re: eggs considered harmful

2007-06-22 Thread Harry George
[EMAIL PROTECTED] (John J. Lee) writes:

> Harry George <[EMAIL PROTECTED]> writes:
> [...]
> > These are unacceptable behaviors.  I am therefore dropping ZODB3, and
> > am considering dropping TurboGears and ZSI.  If the egg paradigm
> > spreads, yet more packages will be dropped (or will never get a chance
> > to compete for addition).
> > 
> > I've asked before, and I'll ask again: If you are doing a Python
> > project, please make a self-sufficient tarball available as well.  You
> > can have dependencies, as long as they are documented and can be
> > obtained by separate manual download. 
> 
> 1. Given the presumptuous tone of your own message, I guess I'm not in
> danger of coming across as more rude than you when I point out that
> your requirements are just that: your own.  The rest of the world
> won't *always* bend over backwards to support just exactly what you'd
> most prefer.
> 

You deleted the "...at least here", which was intended to make clear I
was NOT speaking for the world at large, though possibly for a large
chunk of corporate life.  Also, this wasn't out of the lbue.  I ha ve
previously discussed this with several development teasm privately,
but the trend appears to be accelerating

> 2. You can run your own private egg repository.  IIRC, it's as simple
> as a directory of eggs and a plain old web server with directory
> listings turned on.  You then run easy_install -f URL package_name
> instead of easy_install package_name .  The distutils-sig archives
> will have more on this.

Again, not speaking for anyone else: With 500 OSS packages, all of
which play by the same tarball rules, we don't have resources to
handle eggs differently.

> 
> 3. Alternatively, you could create bundled packages that include
> dependencies (perhaps zc.buildout can do that for you, even? not sure)
> 

No resources for special handling.  

> 
> John




-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Discovery of unpickleables in class heirarchies.

2007-06-22 Thread Brian L. Troutwine
I've a need to pickle arbitrary class hierarchies, which, luckily, can
be made to conform to the pickle protocol. At the moment, however, I'm
having a rather hard time discovering which classes in a heirarchy
cannot be pickles. For instance, say class A has class B in it's
__dict__ and let class B have a file handler in its __dict__. When I
call cPickle.dumps(A) UnpickleableError will be raised when B's file
handler is reached, but the error will only report being unable to
pickle the file handler, saying nothing of B or A. I wouldn't expect
cPickle to do that, but I do need to know somehow that class B has
failed to pickle properly.

To that end I've quickly hacked out a class that, ideally, will take
an object that I'm attempting to pickle and, if the pickling does not
succeed, recurse through the class heirarchy collecting information on
which objects were not pickled. It is here: http://deadbeefbabe.org/paste/5218
The output, for the above example would be:


  


However, it seems to be taking a rather long time. Perhaps my class
heirarchies are too deep, or my recursion is flawed. Can anyone see a
bug in my code, or have a better way of discovering this information
altogether?

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


Re: rsync module?

2007-06-22 Thread kyosohma
On Jun 21, 7:40 pm, "Evan Klitzke" <[EMAIL PROTECTED]> wrote:
> Are there any python modules for accessing rsync from python? I would
> like to be able to rsync files from a python script to a remote server
> running an rsync daemon. I'm well aware that I can invoke rsync using
> subprocess, os.system, etc., but I am curious if there is a way to do
> it directly.
>
> --
> Evan Klitzke <[EMAIL PROTECTED]>

I found the following doing a quick Google search:

http://www.vdesmedt.com/~vds2212/rsync.html
http://freshmeat.net/projects/pysync/
http://www.nongnu.org/rdiff-backup/

Mike

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


What was that web interaction library called again?

2007-06-22 Thread Harald Korneliussen
Hi,

I remember I came across a python library that made it radically
simple to interact with web sites, connecting to gmail and logging in
with four or five lines, for example. I thought, "that's interesting,
I must look into it sometime". Now there's this child I know who asked
me about programming, especially programs that could do things like
this, how difficult it was, and so on. I mentioned how I though Python
was a good intro to programming, and there was a library which was
perfect for what he wanted.

Only now I've forgotten the name of the library! And try as I might, I
can't find it with google. I know there are modules for it in the
standard libraries, but this thing was brilliantly simple in
comparison. It might have been some sort of research project, I can't
remember... but perhaps someone here can remind me what it was? If so,
there may be yet another young python programmer in training :-)

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Bjorn Borud
[Twisted <[EMAIL PROTECTED]>]
| 
| I think it is quite relevant. Clunky computer interfaces may not be so
| dramatically dangerous, but they certainly can hamper productivity.
| Between Windows bugs and gratuitous misfeatures (e.g. DRM) and Unix
| clunkiness, billions of dollars of potential productivity is lost
| worldwide every *month*.

bah, UNIX is not user hostile;  it is just selective about its
friends.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Bjorn Borud
[Robert Uhl <[EMAIL PROTECTED]>]
| 
| Why should the ignorant decide?  Do you leave the decision of what great
| art is to 3 year olds and their doting parents?  Do you leave the
| decision of what great food is to the ignorant, unwashed,
| McDonald's-devouring masses?  Why then do you leave the decision of
| what's a useful interface to those with insufficient experience?

Robert does have a point; however, one needs to take into account that
it is very difficult to judge the quality of an interface if it is one
that is very familiar to you or if the inner workings are obvious to
you.  this is why programmers often make bad UI designers: we are
intimately familiar with the inner workings, and to us it is okay if
the UI is just a thin layer on top of a system we've made.

(I'd say the web is a better showcase for this.  there seems to be no
end to the number of websites that have awkward interaction modes.
nor do people seem particularly shy about adding "just one more" thing
to an already crowded interface -- because they're blind to the wall
of complexity it presents to the occasional user).

editors like Emacs is not something which is designed for the casual
user, so what the casual user thinks is irrelevant.  (also note that
the definition of "casual user" has changed).

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What was that web interaction library called again?

2007-06-22 Thread Michael Hoffman
Harald Korneliussen wrote:
> Hi,
> 
> I remember I came across a python library that made it radically
> simple to interact with web sites, connecting to gmail and logging in
> with four or five lines, for example. I thought, "that's interesting,
> I must look into it sometime". Now there's this child I know who asked
> me about programming, especially programs that could do things like
> this, how difficult it was, and so on. I mentioned how I though Python
> was a good intro to programming, and there was a library which was
> perfect for what he wanted.
> 
> Only now I've forgotten the name of the library! And try as I might, I
> can't find it with google. I know there are modules for it in the
> standard libraries, but this thing was brilliantly simple in
> comparison. It might have been some sort of research project, I can't
> remember... but perhaps someone here can remind me what it was? If so,
> there may be yet another young python programmer in training :-)

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


Re: eggs considered harmful

2007-06-22 Thread Harry George
Robert Kern <[EMAIL PROTECTED]> writes:

> Harry George wrote:
> > ...at least around here.
> > 
> > I run a corporate Open Source Software Toolkit, which makes hundreds
> > of libraries and apps available to thousands of technical employees.
> > The rules are that a) a very few authorized downloaders obtain
> > tarballs and put them in a depot and b) other users get tarballs from
> > the depot and build from source.
> > 
> > Historically, python packages played well in this context.  Install
> > was a simple download, untar, setup.py build/install.
> > 
> > Eggs and with other setuptools-inspired install processes break this
> > paradigm.  The tarballs are incomplete in the first place.  The builds
> > sometimes wander off to the internet looking for more downloads.  The
> > installs sometimes wander off to the internet looking for
> > compatibility conditions.  (Or rather they try to do so and fail
> > because I don't let themn through the firewall.)
> 
> Have you considered establishing a policy that these setuptools-using packages
> should be installed using the --single-version-externally-managed option to 
> the
> install command? This does not check for dependencies.

I didn't know that one.  I'll try it.  Thanks.

> 
> Alternately, you can provide a company repository of the tarballs and their
> depedencies tarballs. Your users can use the easy_install option --find-links 
> to
> point to that URL such that they do not have to go outside of the firewall to
> install everything.
> 

This is a possibility.  The tarballs can be seen in a directory
listing.  They are in different subdirs (for different "bundles" of
functionality), so I'll need -f to look several places.

> > These are unacceptable behaviors.  I am therefore dropping ZODB3, and
> > am considering dropping TurboGears and ZSI.  If the egg paradigm
> > spreads, yet more packages will be dropped (or will never get a chance
> > to compete for addition).
> 
> I'm sorry to hear that.

Me too.  We worked long and hard to get Python established as a
standard language for corporate systems development, we have a host of
projects that need ZSI, and I look forward to making further inroads
into C++, Java, and VB development camps.  Didn't really need a
roadblock at this point.

> 
> > I've asked before, and I'll ask again: If you are doing a Python
> > project, please make a self-sufficient tarball available as well.  You
> > can have dependencies, as long as they are documented and can be
> > obtained by separate manual download. 
> 
> Given the options I outlined above, you can easily satisfy these requirements
> for the vast majority of setuptools-using packages that are out there. There 
> are
> a handful of packages that only distribute the eggs and not the source 
> tarballs,
> but those are rare.
> 

I agree pure eggs are rare.  The fact that they increased this past
quarter was what concerned me.  ZODB even looks like a normal tarball,
builds ok, but uses a easy-install-style lookup during install.


> -- 
> 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
> 

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "assert" annoyance

2007-06-22 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes:
> > So I have some assert statements in my code to verify the absence of
> > some "impossible" conditions.  They were useful in debugging and of
> > course I left them in place for "real" runs of the program.  Umpteen
> > hours into a run, an assertion failed, and of course since failure
> > was "impossible", I didn't catch the exception so the whole program
> > crashed.
> 
> This is exactly the sort of check which is best done as unit
> tests. The program has no 'assert' cruft in it, and the tests can be
> as comprehensive as needed without having any impact on the actual
> running program.

I don't understand what you're trying to say here.  The code was
tested before I ran it with real data.  The asserts triggered because
there was a real problem, so removing them would not have been the
right thing to do.  On the other hand, the code had already been
tested without discovering the problem.  The problem could not have
been found without running the program for hours, not something one
would normally do in a unit test, and also it involved an unexpected
error from a remote program (a 3GB process had run out of memory).
Unit tests are not a magic wand that discover every problem that a
program could possibly have.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "assert" annoyance

2007-06-22 Thread Paul Rubin
Thomas Heller <[EMAIL PROTECTED]> writes:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287

Thanks!  This looks very useful.
-- 
http://mail.python.org/mailman/listinfo/python-list


EMBEDDING > Run Python & Run C Function

2007-06-22 Thread anonymisiert85
At the moment i can run python-string-code from C (MinGW, WinXP)

But how can i register a C-function in python-RUNTIME and call this C
function from python - without wrapper dll's or libs???


STEPS:
initialize python
regsiter foo()  ### don't know how to do this
run python-script "c=foo(a,b)"
finalize


my C function should do this:


char* foo (char* a, char* b)
{
  char* c="return one strings";
  return c;
}


have someone a idea?
i checked the online docs - but i don't understand :-(
can someone post a short sample? please...

thank you

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


Re: What was that web interaction library called again?

2007-06-22 Thread Rob De Almeida
On Jun 22, 11:19 am, Harald Korneliussen <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I remember I came across a python library that made it radically
> simple to interact with web sites, connecting to gmail and logging in
> with four or five lines, for example. I thought, "that's interesting,
> I must look into it sometime". Now there's this child I know who asked
> me about programming, especially programs that could do things like
> this, how difficult it was, and so on. I mentioned how I though Python
> was a good intro to programming, and there was a library which was
> perfect for what he wanted.

httplib2?

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


Re: Thunderbird access to this newsgroup

2007-06-22 Thread anonymisiert85
hm i have the same problem with thunderbird + comp.lang.python

so that i decided to use google for first time

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Bjorn Borud
[Falcolas <[EMAIL PROTECTED]>]
| 
| I took a moment to look at the gui editor which has been made
| available to me, and short of the "remove leading spaces" commands, I
| do not need to remove my hands from the keyboard if I do not want
| to.

well, that depends on the editing features you use.  I use a lot of
features I am not consciously aware of, so if I were to list what I
require from an editor, I would have trouble enumerating them.

I can't even tell you what keys they are bound to because I just use
them instinctively.  the same goes for VI. (VI having the added
benefit of a really systematic way to organize editing actions into a
sort of a matrix (a useful metaphor I was made aware of by an "expert
VI user" who showed me how to make some editing operations more
efficiently))

having people who are good at efficient editing show you some tricks
really pays off btw.  I can't bear to watch other people edit text
because they are doing so much manual labor that could have been
avoided if they had just bothered to learn more effective editing
habits.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the names of python keywords and functions

2007-06-22 Thread Stargaming
[EMAIL PROTECTED] schrieb:
> Hello,
> 
> I am trying to make a program for 3D modelling with "programming".And
> I want make my own program commands,
> 
> for example when user type code in my program:
> 
> "<> OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),
> 
> my program must write this code in some user file, but my
> 
> program must read this command like: "import os".How
> 
> can I do something like that??
> 
>Please, HELP ME somebody!!!
> 

Besides your request is sorta weird (languages are mostly meant to give 
a ruleset of expressions, not a framework of mutability, at least the 
more widespread ones), Python does not support something like this out 
of the box. There have been several discussions about such features and 
they were all abandoned due to unification.

You can, of course, follow the "normal" track to implement any language 
and write a parser, lexer, compiler and whatever. Tools like 
`pyparsing`_ or `PLY`_ might help you (there are much more).
Though, there *is* a mutable codeset of Python called `Logix`_. As far 
as I glanced at it, it is pretty mutable and might fit your needs perfectly.

Ah, and if you perhaps remove the leading << there, this might be pretty 
much implementable by overloading __rshift__ at your koristiti object.

HTH,
Stargaming

.. _pyparsing: http://pyparsing.wikispaces.com/
.. _PLY: http://www.dabeaz.com/ply/ply.html
.. _Logix: http://livelogix.net/logix/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question: parsing street name from address

2007-06-22 Thread Eric
On Jun 21, 6:03 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 22, 4:43 am, Eric <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 21, 9:47 am, cjl <[EMAIL PROTECTED]> wrote:
>
> > > P:
>
> > > I am working on a project that requires geocoding, and have written a
> > > very simple geocoder that uses the Google service.
>
> > > I would like to be able to extract the name of the street from the
> > > addresses in my data, however they vary significantly. Here a some
> > > examples:
>
> > > 25 Main St
> > > 2500 14th St
> > > 12 Bennet Pkwy
> > > Pearl St
> > > Bennet Rd and Main st
> > > 19th St
>
> > > As you can see, sometimes I have the house number, and sometimes I do
> > > not. Sometimes the street name is a number. Sometimes I simply have
> > > the names of intersecting streets.
>
> > > I would like to be able to parse the above into the following:
>
> > > Main St
> > > 14th St
> > > Bennet Pkwy
> > > Pearl St
> > > Bennet Rd
> > > Main St
> > > 19th St
>
> > > How might I approach this complex parsing problem?
>
> > > -CJL
>
> > You might be able to use consistencies in your data to make this
> > simpler.  If the examples you have there are representative, it looks
> > like what you should do is look for a word like 'St' or 'Rd' and then
> > return that word and the previous word.
>
> The OP's data already contains
> [corner|cnr [of]] Foo Rd and|& Bar St
> and real world data will contain things like
> 1234 John F Kennedy Memorial Drive
> 456 Broadway
>
> As Paul wrote, "Parsing street addresses is a very complex parsing
> problem", even when you restrict yourself to one mostly-English-
> speaking country. Software written under such restrictions rapidly
> breaks down elsewhere (Rue de la Paix, Wilhelmstrasse, Avenida 9 de
> Julio, etc) and blows up altogether when street names aren't used in
> postal addresses (e.g. Japan).

No doubt that address parsing is, in general, a very difficult
problem.  However, it may not be necessary for him to solve the
general problem.  If his dataset is more limited in formats then his
problem is much simpler.

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


Re: try/except with multiple files

2007-06-22 Thread Stargaming
Matimus wrote:
> It depends, what are you going to do if there is an exception? If you
> are just going to exit the program, then that works fine. If you are
> going to just skip that file, then the above wont work. If you are
> going to return to some other state in your program, but abort the
> file opening, you might want to close any files that were opened. The
> closing can be taken care if in the except block, but you will have to
> know which ones opened successfully.
> 
> In general I would do something like this for multiple files:
> 
> [code]
> filenames = ["fname1","fname2","fname3"]
> for fn in filenames:
> try:
> f = open(fn)
> except IOError:
> # handle exception
> #do something with f
> [/code]
> 
> But, that might not work for you if the files aren't homogeneous (each
> have similar contents). If the files have distinctly different
> purposes, I would just wrap them each in their own try/except block.
> 
> I rambled a bit there, but I hope it helps.
> 
> Matt
> 

Heh, reminded me of http://worsethanfailure.com/Articles/Code-Reuse.aspx 
at the first glance. SCNR.

To add something on-topic, I'd just stick with the "one try for all 
files" option if your need is really "Try to open all files, if *at 
least one* of them fails, recover/abort/foobar/...".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-22 Thread Bjorn Borud
[Martin Gregorie <[EMAIL PROTECTED]>]
|
| Yep, and the same people think a command line is to be avoided at all
| costs. "I mean, its so /last century/ and you can't do anything useful
| with it anyway".

I have a friend who is a carpenter.  he switched to Linux a few years
ago because he was tired of how slow windows was and how easily it was
infested with malware.  he really, really doesn't give a toss what it
says on the tin, he's a _user_ and that's it.  to my surprise, finds
Linux as easy, if not easier to use, than windows.  (he still has to
use windows for his invoicing system.  everything else he does in
Linux).

I have observed similar opinions in other non-computer-freaks.  people
who see the computer only as a tool and are only interested in getting
the job done.  they have a surprising preference for Linux.  (not many
of them have ever been exposed to OSX though, and I'd suspect they'd
prefer that since it is far more streamlined).

| Obligatory OT comment: right now I have two xterm sessions open with
| which I've been writing a Swing/JDBC app using nowt but a bash shell,
| cvs, microEmacs and (of course) J2SE. I don't need no steenking IDE.

I used J2SE, Ant, Emacs, Xterm, bash and Firefox as my main tools when
I wrote most of my production Java code.  and it is not exactly what
you'd call "hobbyist projects" either. :-)

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-22 Thread Alex Martelli
Dave Baum <[EMAIL PROTECTED]> wrote:
   ...
> I still think it would be handy to easily specify the expected types of
> function arguments.  I sometimes write code in this pattern:
> 
> def foo(a, b):
> "a, b - instances of Bar"
> assert isinstance(a, Bar)
> assert isinstance(b, Bar)
> # do some stuff

so in 3.0 you'll be able to spell that

@checkanddoc
def foo(a: Bar, b: Bar): ...

for some suitable decorator checkanddoc (and be assured that there will
be a bazillion such decorators written to exploit the new syntax, of
varying intent and quality).  That's why 3.0 introduces that syntax
(args can be spelled :) without giving it any semantics
beyond the fact that the info is recorded with the function object and
can be introspected from it -- enabling a thousand flowers to bloom in
terms of such decorators.

> On the downside, this sort of mechanism might do more harm than good.
> For one thing, it would really clash with duck typing.  For another, 
> anyone coming to Python from Java/C++ would probably use those 
> declarations *everywhere*, even when there isn't a good reason to limit
> the type.

Sure, even more than they currently use wanton isinstance calls (or even
worse, type(x)==... checks).  But hopefully the new "syntax hook" will
also allow GOOD decorators to emerge (e.g., ones doing adaptation rather
than mere checks).


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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Bjorn Borud
[Kaldrenon <[EMAIL PROTECTED]>]
| 
| I don't think anyone can make the argument that any (past or current)
| graphics-based editor is as efficient when being used to its fullest
| as a text-based editor. It's basic math - it takes measurably more
| time to move a hand to the mouse, move/click the mouse, and more the
| hand back to the touch-typing position than it does to execute even a
| moderately complex series of keystrokes. Maybe not large amounts of
| time -per action-, but it doesn't take too long for it to add up if
| you spend a lot of time editing.

a lot of IDE's are getting quite good and you don't have to mouse
around all that much.  I think the main reason I stick to Emacs is
because I use it for a wider range of tasks -- not just programming.

also, the IDE's I've used in the past were sluggish and for some
reason the font-rendering was really hard to get right (if at
all). when you spend the majority of your waking hours editing text,
interactive response time and "editing ergonomics" matter a lot.


this reminds me that it is probably time to give IDEs another chance.
it has been a couple of years since the last time I tried a couple for
Java.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


I need some cleanings tips and advice.

2007-06-22 Thread CleaningTips
Me and my buddy made a website called www.CleaningTips.com, its
basically a free forum and  free blog driven web site dedicated as a
source people can goto to find out how to clean and remove stains from
pretty much anything. Problem is, as of yet, you couldn't find out how
to clean anything right now cause the site is new and no one has found
it yet.

We don't know enough about cleaning and tips and tricks to really fill
the site. Were looking to get more useful content so that the website
eventually shows up in search results.

If anyone here is interested, visit www.CleaningTips.com/forum.html,
and if there is anything you could add to the site please feel free to
do so. Email me at [EMAIL PROTECTED] if you find anything that
could improve the site or if something doesn't seem to be working
properly.

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


Re: howto run a function w/o text output?

2007-06-22 Thread Stargaming
dmitrey schrieb:
> hi all,
> I have a
> y = some_func(args)
> statement, and the some_func() produces lots of text output. Can I
> somehow to suppress the one?
> Thx in advance, D.
> 

Either rewrite it or pipe sys.stdout to some other file-like object but 
your console while running it. The StringIO 
(http://docs.python.org/lib/module-StringIO.html) module might help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Giorgos Keramidas
On 21 Jun 2007 16:52:17 +0200, Bjorn Borud <[EMAIL PROTECTED]> wrote:
> on my tombstone will say
> "here lies the last Emacs user on earth. M-x rip".

Hahaha!  Very good one :-)

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Neil Cerutti
On 2007-06-22, Douglas Alan <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> writes:
>> That said, I wouldn't give up the summer I spent studying _Simply
>> Scheme_.
>
> Sounds like fun.  Is this like a kinder, gentler version of SICP?

No, it is a prequel. Along with "How to Design Programs" it is
meant specifically as a primer for SICP, and an introduction to
computer science.

> I'm not sure, though, that I could have learned computer
> science properly without the immortal characters of Ben
> Bittwiddler and Harry Reasoner intruding into every problem
> set.

http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=3662

_Simply Scheme_ has the cute Little Computer People, and amusing
cartoons. If you aren't a Rolling Stones, Beatles, or Monty
Python fan then the examples may seem arbitrary. The authors
chose to make most of their exercises and examples about
manipulating sentences, rather than computing math functions.

It won't much other than a nice diversion if you've already
mastered the material in SICP.

-- 
Neil Cerutti
Low Self-Esteem Support Group will meet Thursday at 7 to 8:30 p.m. Please use
the back door. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some cleanings tips and advice.

2007-06-22 Thread Neil Cerutti
["Followup-To:" header set to comp.lang.python.]
On 2007-06-22, Colin B. <[EMAIL PROTECTED]> wrote:
> In comp.lang.perl.misc [EMAIL PROTECTED] wrote:
>> Me and my buddy made a website called www.stupidpinheads.com, its
>> basically a free forum and  free blog driven web site dedicated as a
>> source people can goto to find out how to clean and remove stains from
>> pretty much anything. Problem is, as of yet, you couldn't find out how
>> to clean anything right now cause the site is new and no one has found
>> it yet.
>
> Let's see if I get this right.
>
> You create a website for a subject that you know nothing about. Then you
> try to solicit content in a bunch of programming language newsgroups.
>
> Wow, that's pretty pathetic, even for a google-groups poster!

Maybe they lost the business plan. It's not surprising, since it
was probably written on a napkin.

-- 
Neil Cerutti
Ask about our plans for owning your home --sign at mortgage company
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-22 Thread Joost Kremers
[Followup-To: header set to comp.emacs]
Bjorn Borud wrote:
> sure, but often it is just simpler, while you are fiddling around in a
> shell, to just fire up vi to do some quick editing than to bounce back
> and forth between windows.  it is usually quicker too if you have to
> navigate deep directory trees -- if you're already in the directory
> where the file is, it'd be fewer keystrokes to specify the file than
> opening it in emacs.  even with tab-completion.

well, ok, typing `emacsclient ' requires more keystrokes than `vi
', but that's why i have an alias ec for it...


-- 
Joost Kremers  [EMAIL PROTECTED]
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Douglas Alan
Neil Cerutti <[EMAIL PROTECTED]> writes:

> That said, I wouldn't give up the summer I spent studying _Simply
> Scheme_.

Sounds like fun.  Is this like a kinder, gentler version of SICP?

I'm not sure, though, that I could have learned computer science
properly without the immortal characters of Ben Bittwiddler and Harry
Reasoner intruding into every problem set.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-22 Thread Bjorn Borud
[David Kastrup <[EMAIL PROTECTED]>]
| 
| The idea is to start Emacs once and use it for everything.

...which is fine as long as you are only fiddling around on one
machine or you have emacs windows running on all your machines.

for my main use, I do start Emacs just once though.  for instance at
work my Emacs has been running for as long as the machine has been up.

| > so if the context was system administration, I'd vote for vi as
| > well. if the context was programming I'd vote Emacs.
| 
| You know you can use something like
| C-x C-f /su::/etc/fstab RET
| (or /sudo::/etc/fstab) in order to edit files as root in a normal
| Emacs session?

sure, but often it is just simpler, while you are fiddling around in a
shell, to just fire up vi to do some quick editing than to bounce back
and forth between windows.  it is usually quicker too if you have to
navigate deep directory trees -- if you're already in the directory
where the file is, it'd be fewer keystrokes to specify the file than
opening it in emacs.  even with tab-completion.

also, I make extensive use of the readline and history features when
fiddling about in the shell.  shells have a lot of context if you use
them effectively.  context that isn't easy to transport between the
shell and emacs -- and it isn't really easy to explain either.

-Bjørn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the names of python keywords

2007-06-22 Thread Ognjen Bezanov
[EMAIL PROTECTED] escribió:
> Hello again,
> 
> Thanks for everything previously, I was change  the grammar and Lib/
> keyword.py, now
> Python recognize "koristiti" as a keyword, but that is not enough:
> 
> when I write in my python shell:
> 
 koristiti os   # "koristiti" get keyword "color", but I 
 get error:
> 
> File "", line 1
> koristi os
>  ^
> SyntaxError: invalid syntax
> 
> and now, when I write:
> 
 import os   # "import" don't get keyword "color" but still 
 working
> 
> 
> 
>  
> Please help me,thanks
> 

Sorry, but I am having some trouble understanding what exactly you are 
trying to do.

Mozda bi bilo lakse da objasnis na neki drugi jezik, sta mislis o tome?

Ogi.



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


howto run a function w/o text output?

2007-06-22 Thread dmitrey
hi all,
I have a
y = some_func(args)
statement, and the some_func() produces lots of text output. Can I
somehow to suppress the one?
Thx in advance, D.

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


Re: The Modernization of Emacs

2007-06-22 Thread Joel J. Adamson
Martin Gregorie <[EMAIL PROTECTED]> writes:

> Bjorn Borud wrote:
> Yep, and the same people think a command line is to be avoided at all
> costs. "I mean, its so /last century/ and you can't do anything useful
> with it anyway".

Funny ;)

It's funny that people consider typing commands to be "old-fashioned"
because pointing with a mouse is the stone-age device; typing was only
invented in the 19th century ;)  

Xerox PARC (not Apple nor MIcrosoft) excelled in helping computers fit
in to how people already lived, not the other way around.

Joel

-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109

A webpage of interest:
http://www.gnu.org/philosophy/sylvester-response.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite newbie question - how to know if a table exists?

2007-06-22 Thread [EMAIL PROTECTED]
On Jun 22, 12:07 am, Gerhard Häring <[EMAIL PROTECTED]> wrote:
> That approach is ok. If your SQLite library is recent enough (I don't
> know the exact version), you can use "create table if not exists ...".

>
> -- Gerhard


Thanks Gerhard. I'm using sqlite3 that came with Python2.5
installation. So "create table if not exists" works.

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

Re: Setuptools, build and install dependencies (was: eggs considered harmful)

2007-06-22 Thread Harry George
Ben Finney <[EMAIL PROTECTED]> writes:

> Harry George <[EMAIL PROTECTED]> writes:
> 
> > Historically, python packages played well in this context.  Install
> > was a simple download, untar, setup.py build/install.
> >
> > Eggs and with other setuptools-inspired install processes break this
> > paradigm.  The tarballs are incomplete in the first place.  The builds
> > sometimes wander off to the internet looking for more downloads.  The
> > installs sometimes wander off to the internet looking for
> > compatibility conditions.  (Or rather they try to do so and fail
> > because I don't let themn through the firewall.)
> 
> If you provide the build and install script with all the dependencies
> already present (in the current directory), my experience is that
> setuptools does not do any network actions.
> 
> -- 
>  \   "Self-respect: The secure feeling that no one, as yet, is |
>   `\ suspicious."  -- Henry L. Mencken |
> _o__)  |
> Ben Finney

Thanks for the idea.  It doesn't work so well in our context, since
many dependencies are installed long before a particular egg is
attempted.  

We need to know the dependencies, install them in dependency order,
and expect the next package to find them.  "configure" does this for
hundreds of packages.  cmake, scons, and others also tackle this
problem.  Python's old setup.py seems to be able to do it.  

However, as I understand it, setuptools can't detect previously
installed python packages if they were not installed via eggs.  Thus,
my ZSI install was failing on "PyXML>=8.3", even though PyXML 8.4 is
installed.  I can't afford to drag copies of all the dependent source
tarballs into an egg's currdir just so it can find them.  (We have 6 GB
of tarballs -- who knows how much untarred source that would be.)

I just found hints that you should not attempt to install ZSI form
tarball, but should rather install from an egg.  So I was able to
install ZSI for py2.4.

Unfortunately, that means I would have to carry
python-version-dependent renditions of every egg.  We have people
running on py23, py24, and py25, thus tripling the number of
tarballs/eggs to manage.  This is the very reason we went to a
*source* based repository.

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need some cleanings tips and advice.

2007-06-22 Thread Colin B.
In comp.lang.perl.misc [EMAIL PROTECTED] wrote:
> Me and my buddy made a website called www.stupidpinheads.com, its
> basically a free forum and  free blog driven web site dedicated as a
> source people can goto to find out how to clean and remove stains from
> pretty much anything. Problem is, as of yet, you couldn't find out how
> to clean anything right now cause the site is new and no one has found
> it yet.

Let's see if I get this right.

You create a website for a subject that you know nothing about. Then you
try to solicit content in a bunch of programming language newsgroups.

Wow, that's pretty pathetic, even for a google-groups poster!

Begone with you.

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


Python plain-text database or library that supports joins?

2007-06-22 Thread felciano
Hello --

Is there a convention, library or Pythonic idiom for performing
lightweight relational operations on flatfiles? I frequently find
myself writing code to do simple SQL-like operations between flat
files, such as appending columns from one file to another, linked
through a common id. For example, take a list of addresses and append
a 'district' field by looking up a congressional district from a
second file that maps zip codes to districts.

Conceptually this is a simple database operation with a join on a
common field (zip code in the above example). Other case use other
relational operators (projection, cross-product, etc) so I'm really
looking for something SQL-like in functionality. However, the data is
in flat-files, the file structure changes frequently, the files are
dynamically generated from a range of sources, are short-lived in
nature, and otherwise not warrant the hassle of a database setup. So
I've been looking around for a nice, Pythonic, zero-config (no
parsers, no setup/teardown, etc) solution for simple queries that
handles a database of csv-files-with-headers automatically. There are
number of solutions that are close, but in the end come up short:

- KirbyBase 1.9 (latest Python version) is the closest that I could
find, as it lets you keep your data in flatfiles and perform
operations using the field names from those text-based tables, but it
doesn't support joins (the more recent Ruby version seems to).
- Buzhug and Sqlite have their data structures w no automatic .tab
or .csv parsing (unless sqlite includes a way to map flatfiles to
sqlite virtual tables that I don't know about).
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/159974 is
heading in the right direction, as it shows how to perform relational
operations on lists and are index based rather than field-name based.
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498130 and
http://furius.ca/pubcode/pub/conf/common/bin/csv-db-import.html
provide ways of automatically populating DBs but not the reverse
(persist changes back out to the data files)

The closest alternatives I've found are the GNU textutils that support
join, cut, merge, etc but I need to add additional logic they don't
support, nor do they allow field-level write operations from Python
(UPDATE ... WHERE ...). Normally I'd jump right in and start coding
but this seems like something so common that I would have expected
someone else to have solved, so in the interest of not re-inventing
the wheel I thought I'd see if anyone had any other suggestions. Any
thoughts?

Thanks!

Ramon

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


Re: SimplePrograms challenge

2007-06-22 Thread [EMAIL PROTECTED]
Ah, I mistook you for someone who gives a shit.

- You DID see my post on comp.lang.python and
  deliberately ignored it.

- You then lied and claimed there was no discussion.

- You then lied and claimed my example merely
  duplicated other examples.

- You claimed to be offended by my characterization
  of your obfuscation policy as foolish and then
  turned around and proved it was foolish by
  admitting you couldn't comprehend the example
  because it didn't have enough comments. Duh!

You're going to end up with a really short fucking
list if you ignore and delete that which you can't
understand.

Great way to encourage contributions.

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-06-22 Thread Paul Boddie
On 22 Jun, 12:41, Ben Finney <[EMAIL PROTECTED]>
wrote:
>
> I think it's great that we're going to get Python 3.0 soon, and that
> Python 4.0 proposals will benefit from a long period of familiarity
> with widely-deployed PyPy :-)

I'm not going to name and shame anyone, but here's part of a genuine
docstring from a program I downloaded not so long ago:

  It was tested for python 4.0.  It certainly doesn't work for python
  versions earlier than 3.3.

If I need to speculate about future Python versions, I know who to
ask. ;-)

Paul

P.S. I agree with the sentiment that the annotations feature of Python
3000 seems like a lot of baggage. Aside from some benefits around
writing C/C++/Java wrappers, it's the lowest common denominator type
annotation dialect that dare not be known as such, resulting from a
lack of consensus about what such a dialect should really do, haunted
by a justified fear of restrictive side-effects imposed by a more
ambitious dialect (eg. stuff you get in functional languages) on
dynamically-typed code. I don't think the language should be modified
in ways that only provide partial, speculative answers to certain
problems when there's plenty of related activity going on elsewhere
that's likely to provide more complete, proven answers to those
problems.

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


Re: comparing two lists and returning "position"

2007-06-22 Thread hiro
On Jun 22, 2:16 am, hiro <[EMAIL PROTECTED]> wrote:
> On Jun 22, 1:46 am, Charles Sanders <[EMAIL PROTECTED]>
> wrote:
>
> > Paul Rubin wrote:
>
> > > from itertools import izip
> > > pos = map(dict(izip(l2, count())).__getitem__, l1)
>
> > or probably less efficiently ...
>
> >  >>> l1 = [ 'abc', 'ghi', 'mno' ]
> >  >>> l2 = [ 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr']
> >  >>> pos = [ l2.index(i) for i in l1 ]
> >  >>> print pos
> > [0, 2, 4]
>
> > Charles
>
> Hey Guys thanks for the feedback and the suggestions.
> Charles I got your implementation to work so many thanks for this.
>
> this is what I had so far
>
> for spam in l1:
> for eggs in l2:
> if spam == eggs:
> print "kaka", spam, eggs
>
> so its almost working just need the index, I'll
> continue playing with the nested loop approach for a bit more.
>
> Thanks once again guys

Hi once again, Charles.. I have tried your approach in my data set l2
and it keeps crashing on me,
bare in mind that I have a little over 10 million objects in my list
(l2) and l1 contains around 4 thousand
objects.. (i have enough ram in my computer so memory is not a
problem)

python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32

error is : ValueError: list.index(x): x not in list

when using Charles's
pos = [ l2.index(i) for i in l1 ]
print pos

does anybody know of if I have to many data points ? the nested for
loop approach seems to be working(still have get the index "position"
returned though)
Charles's approach works fine with less data.

Cheers, -d

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


Re: Promijena imena pythonovim kljucnim rijecima

2007-06-22 Thread vedrandekovic

Ognjen Bezanov je napisao/la:
> [EMAIL PROTECTED] escribió:
> > Hello again,
> >
> > Thanks for everything previously, I was change  the grammar and Lib/
> > keyword.py, now
> > Python recognize "koristiti" as a keyword, but that is not enough:
> >
> > when I write in my python shell:
> >
>  koristiti os   # "koristiti" get keyword "color", but I 
>  get error:
> >
> > File "", line 1
> > koristi os
> >  ^
> > SyntaxError: invalid syntax
> >
> > and now, when I write:
> >
>  import os   # "import" don't get keyword "color" but still 
>  working
> >
> >
> >
> >
> > Please help me,thanks
> >
>
> Sorry, but I am having some trouble understanding what exactly you are
> trying to do.
>
> Mozda bi bilo lakse da objasnis na neki drugi jezik, sta mislis o tome?
>
> Ogi.

Pozdrav,

(Hrvatski)

Pokusavam napraviti nesto kao "programski jezik" tj. program za 3D
modeliranje kodom, u tom programu
zelim sve kljucne rijeci iz programskog jezika Python ali i
preimenovati kao svoje npr.

kada korisnik u mom programu upise:

>>> koristiti os

ja zelim da moj program to procita kao " import os"
ja sam u file-u  Lib/keywords.pyzamijenio kljucnu rijec s
"koristiti",sada python "koristiti" prepoznaje
kao kljucnu rijec, a "import" ne.Sada kada napisem:

>>> import os  # i dalje je sve uredu samo sto import ne "dobije" boju
>>> koristiti os  # a kod ovoga koristiti "dobije" boju kljucne rijeci ali ja 
>>> dobim gresku:
SyntaxError: invalid syntax

 
Molim vas pomoc s ovim se mucim vec mjesec dana,pozdrav i
HVALA!

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


Re: howto run a function w/o text output?

2007-06-22 Thread Matimus
On Jun 22, 9:56 am, dmitrey <[EMAIL PROTECTED]> wrote:
> hi all,
> I have a
> y = some_func(args)
> statement, and the some_func() produces lots of text output. Can I
> somehow to suppress the one?
> Thx in advance, D.

[code]
import sys
import os

sys.stdout = open(os.devnull,"w")
[/code]

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Douglas Alan
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Thu, 21 Jun 2007 15:25:37 -0400, Douglas Alan wrote:

>> You are imagining something very different from what is proposed.
>> Lisp-like macros don't allow "anything goes".

> Provided people avoid doing anything "which would be considered very 
> rude" (your own words).

No, Lisp macros are entirely contained within a begin and end
delimiter, which is introduced by the name of the macro.  E.g., here
is a real example of some Lisp code that I wrote aeons ago using the
loop macro:

   (loop for index from 0 below size
  for element in contents
  do (store (arraycall t array index)
element)
  finally (return (make-htable BUCKETS size
   ARRAY array
   KEY-PRINTER key-printer
   ITEM-PRINTER item-printer)

The syntactical extensions supported by the loop macro can only begin
starting immediately after "(loop " and they end with the matching
closing parenthesis.  There's no way in Lisp to write a macro whose
syntactical extensions can extend outside of this very explicitly
delimited scope.  Nor can they mess with Lisp's tokenization.

> Python already allows me to shoot myself in the foot, if I wish. I'm 
> comfortable with that level of freedom. I'm not necessarily comfortable 
> with extensions to the language that would allow me the freedom to shoot 
> myself in the head.

Lisp macros don't let you shoot yourself in the head -- only in the
foot.  Being able to do

   True = False

is being able to shoot yourself in the head.  And Python certainly
lets you do that.

> I would need to be convinced of the advantages, as would many other
> people, including the BDFL.

The proof is in the pudding for anyone who has seen the advantages it
brings to Lisp.  As Paul Graham points out, it's hard to look up and
see the advantages of what is up there in a more powerful language.
It's only easy to look down and see the disadvantages of what is
missing from a less powerful language.  To understand the advantages,
one has to be willing to climb the hill and take in the view.

> It isn't clear exactly what functionality a hypothetical Python macro 
> system would include,

It should be largely equivalent to what is provided by Lisp.
Admittedly this is a bit more difficult for Python, as Lisp's syntax
is eminently suited for macros, while Python's is not.  One would
probably want to take a look at how Dylan solved this problem, as
Dylan implements Lisp-like macros even though it has an Algol-like
syntax.  Or you could look at the paper I wrote (for a class) on the
design of Python-like language that would support macros.  My paper is
only a rough sketch, however.

> let alone whether the benefits would outweigh the costs,

They pay off in boatloads in the Lisp community.

> (It took Lisp half a century and millions of dollars of corporate
> funding to reach where it is now.

Ummm, not really.  Lisp hasn't really changed very much since the late
'70s, and prior to that, most of the work on Lisp was just done in a
few university labs (e.g., MIT) and at Xerox Parc.  Any work and money
that has been spent on Lisp since then has just been in trying to
market it, or standardize it, or design hardware suited to running it
faster, or build better development environments for it, or optimizing
compilers, etc.

Lisp, itself, is rather easily to implement.  (Getting it to run as
fast as C is more of a challenge, what with good garbage collectors
and all being non-trivial to implement, but performance doesn't seem
to be much of an issue for the Python community.)  I made my own Lisp
implementation in C++ in two weeks.  (Not really a production dialect,
but it worked.)  Kyoto Common Lisp, which was definitely a production
implementation, was implemented by two people in a couple of years.
(It compiled Common Lisp into C.)

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Robert Uhl
Falcolas <[EMAIL PROTECTED]> writes:
>
> Being a primarily windows user, I have to question your assertion that
> using ctrl-f for find causes a "mental context switch". For me, in 90%
> of the windows applications, finding something is as simple as ctrl-f,
> the phrase, hit enter. Not terribly different from your set of
> commands. The biggest difference is that if I need to use a Find
> feature I might not often use, I have a visual interface to all the
> related search functions. On the other hand, a terminal program would
> necessitate a memory search at best, or a trip to the help pages at
> worst.

That's the advantage of a well-organised set of commands.  If you want
to use regexp search, you have to look at the dialogue box and click on
a checkbox--which would be a context switch.

That's even assuming that your editor _offers_ regexp search.  If emacs
didn't have it, I could add it, and it'd be just as much part of the
editor as if it were included...

> The best part of my windows knowledge is that it's transferable to
> most (all?) of the applications I work with. Find is usually ctrl-f.
> Undo is ctrl-z. Save is ctrl-s, yadda yadda. Such knowledge is rarely
> transferable from terminal programs in my experience -- what may be
> true for one program (emacs) is wildly different in another program
> (vi), and useless in yet another (pico).

Consistency is nice.  That's be why the emacs are found throughout
Unix.  In fact, for a long time Netscape used emacs bindings on Macs and
Windows.  Among these bindings are C-a to go the beginning of a line,
C-e to go to the end, C-k to kill from point to the end of the line, M-b
and M-f to move forward and back by word and so forth.

It's Mac OS and Windows which are inconsistent.  Emacs has been around
since they were mere glimmers in the eye of Jobs & Gates...

-- 
Robert Uhl 
Just because I'm not doing anything, doesn't mean I have nothing to do!
--Ellen Winnie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Douglas Alan
"Terry Reedy" <[EMAIL PROTECTED]> writes:

> "Douglas Alan" <[EMAIL PROTECTED]> wrote in message 

> | > But why is the ability to abstract syntax good?

> | It allows the community to develop language features in a modular way
> | without having to sully the code base for the language itself.

> Anyone can write modules, experimental or otherwise, without touching the 
> code base for any particular implementation.

> For those whose know one of the implementation languages, source code 
> control systems allow one to do experiments on branches without 'sullying' 
> the trunk or impeding the development thereof.

When I said "without having to sully the code base", I meant that one
can implement a language feature for the target language as a loadable
module written entirely within the language itself, and without having
to understand anything particularly deep or specific about the language
implementation details.

I.e., I could write a new object system for Lisp faster than I could
even begin to fathom the internal of CPython.  Not only that, I have
absolutely no desire to spend my valuable free time writing C code.
I'd much rather be hacking in Python, thank you very much.

> One of the goals of the PyPy project was to allow people to experiment with 
> syntax extensions in Python itself.  (But I don't know how easy that is 
> yet.)

PyPy sounds like a very interesting project indeed!

> But I think that overall the problem of designing new syntax is more
> in the design than the implementation.  Anything new has to be
> usable, readable, not clash too much with existing style, not
> introduce ambiguities, and not move the extended language outside
> the LL(1) [I believe that is right] subset of CFLs.

People (myself included) haven't had much trouble implementing nice
and useful macro packages for Lisp.  Admittedly, it's a harder problem
for a language that doesn't have a Lisp-like syntax.  I believe that
Dylan has macros without having a Lisp-like syntax, but Dylan is
really a dialect of Lisp, only with a more traditional Algol-like
syntax veneered onto it.  My guess is that a macro developer for Dylan
would have to be familiar with an underlying hidden intermediate Lisp
syntax.  (Though I'm just really just spouting that guess out of my
butt.)

A few years back, I designed a somewhat Python-like language with a
macro facility for a class on dynamic languages and their
implementations.  I didn't implement it, however, and I doubt that
I'll have time to get around to it in this lifetime.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing two lists and returning "position"

2007-06-22 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, hiro wrote:

> Hi once again, Charles.. I have tried your approach in my data set l2
> and it keeps crashing on me,
> bare in mind that I have a little over 10 million objects in my list
> (l2) and l1 contains around 4 thousand
> objects.. (i have enough ram in my computer so memory is not a
> problem)
> 
> python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> (Intel)] on win32
> 
> error is : ValueError: list.index(x): x not in list

So you are saying you get this error with the value of `x` actually in the
list!?  Somehow hard to believe.

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


Re: comparing two lists and returning "position"

2007-06-22 Thread hiro
On Jun 22, 1:56 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, hiro wrote:
> > Hi once again, Charles.. I have tried your approach in my data set l2
> > and it keeps crashing on me,
> > bare in mind that I have a little over 10 million objects in my list
> > (l2) and l1 contains around 4 thousand
> > objects.. (i have enough ram in my computer so memory is not a
> > problem)
>
> > python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> > (Intel)] on win32
>
> > error is : ValueError: list.index(x): x not in list
>
> So you are saying you get this error with the value of `x` actually in the
> list!?  Somehow hard to believe.
>
> Ciao,
> Marc 'BlackJack' Rintsch

yes I do

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


Re: comparing two lists and returning "position"

2007-06-22 Thread hiro
On Jun 22, 1:58 pm, hiro <[EMAIL PROTECTED]> wrote:
> On Jun 22, 1:56 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
>
>
> > In <[EMAIL PROTECTED]>, hiro wrote:
> > > Hi once again, Charles.. I have tried your approach in my data set l2
> > > and it keeps crashing on me,
> > > bare in mind that I have a little over 10 million objects in my list
> > > (l2) and l1 contains around 4 thousand
> > > objects.. (i have enough ram in my computer so memory is not a
> > > problem)
>
> > > python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> > > (Intel)] on win32
>
> > > error is : ValueError: list.index(x): x not in list
>
> > So you are saying you get this error with the value of `x` actually in the
> > list!?  Somehow hard to believe.
>
> > Ciao,
> > Marc 'BlackJack' Rintsch
>
> yes I do

I doubled, trippled check my data already (even doing a search by hand
using vim) and the data is fine.  Still looking into it though

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


Re: What was that web interaction library called again?

2007-06-22 Thread felciano
Maybe http://twill.idyll.org/

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-06-22 Thread Falcolas
On Jun 22, 11:28 am, Robert Uhl <[EMAIL PROTECTED]> wrote:
> That's the advantage of a well-organised set of commands.  If you want
> to use regexp search, you have to look at the dialogue box and click on
> a checkbox--which would be a context switch.

Again, you are assuming that the editor isn't set up in a way which
allows this to be done from the keyboard.

ctrl-f, alt-e, type, enter

> That's even assuming that your editor _offers_ regexp search.  If emacs
> didn't have it, I could add it, and it'd be just as much part of the
> editor as if it were included...

One advantage I'm more than happy to cede to you - the current program
I use is closed source and not extensible. Though, I'm sure that there
are editors for windows/mac/xwindows which are as extensible as emacs.

> It's Mac OS and Windows which are inconsistent.  Emacs has been around
> since they were mere glimmers in the eye of Jobs & Gates...

Inconsistent? I would have to disagree. They changed paradigms -
terminal text based interfaces to GUIs. You wouldn't expect a piece of
software built for a terminal to be backwards compatibility to punch
card interfaces, would you? Why would a GUI based program limit itself
to functionality as defined by a terminal application?

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Douglas Alan
"Terry Reedy" <[EMAIL PROTECTED]> writes:

> | But why is the ability to abstract syntax good?

> I think this points to where Sussman went wrong in his footnote and
> Alan in his defense thereof.  Flexibility of function -- being able
> to do many different things -- is quite different from flexibility
> of syntax 

I think you are setting up a false dichotomy.  One that is related to
the false unification that annoying people used to always make when
they would perpetually argue that it wasn't important which
programming language you programmed in, as they are all Turing
equivalent anyway.  Well, I sure as hell don't want to write all my
programs for a Turning machine, and a Turing machine is certainly
Turing equivalent!

Functionality is no good if it's too cumbersome to use.  For instance,
Scheme gives you first class continuations, which Python doesn't.
Continuations let you do *all sorts* of interesting things that you
just cannot do in Python.  Like backtracking, for instance.  (Well
maybe you could do backtracking in Python with lots of putting code
into strings and liberal use of eval, for all I know, but the results
would almost certainly be too much of a bear to actually use.)

Now, continuations, by themselves, in Scheme actually don't buy you
very much, because although they let you do some crazy powerful
things, making use of them to do so, is too confusing and verbose.  In
order to actually use this very cool functionality, you need macros so
that you can wrap a pretty and easy-to-use face on top of all the
delicious continuation goodness.

You'll, just have to trust me on this one.  I've written code with
continuations, and I just couldn't make heads or tails out of the code
a few hours later.  But when prettied-up with a nice macro layer, they
can be a joy to behold.

|>oug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2007-06-22 Thread com4

On 6/19/07, Tom Gur <[EMAIL PROTECTED]> wrote:


Hi,
which IDE would you recommend for a python ?



I also use VIM, but I use a couple plugins to make it more ide-esque (If you
can call it that).

The first is the project plugin:
http://vim.sourceforge.net/scripts/script.php?script_id=69
This will make a split window on the lefthand side with a list of files and
folders. You can specify a file extension whitelist. *.py works out very
well. I bind F3 to :Project to open and close that window quickly

The other plugin I use is BufExplorer:
http://www.vim.org/scripts/script.php?script_id=42
This will show you a list of open files and let you switch between them (S
will split the choice with the current file(s)). I bind F2 to :BufExplorer

--

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

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

Tailing a log file?

2007-06-22 Thread Evan Klitzke
Everyone,

I'm interested in writing a python program that reads from a log file
and then executes actions based on the lines. I effectively want to
write a loop that does something like this:

while True:
log_line = log_file.readline()
do_something(log_line)

Where the readline() method blocks until a new line appears in the
file, unlike the standard readline() method which returns an empty
string on EOF. Does anyone have any suggestions on how to do this?
Thanks in advance!

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


Re: EMBEDDING > Run Python & Run C Function

2007-06-22 Thread Farshid Lashkari
[EMAIL PROTECTED] wrote:
> At the moment i can run python-string-code from C (MinGW, WinXP)
> 
> But how can i register a C-function in python-RUNTIME and call this C
> function from python - without wrapper dll's or libs???

Have a look at the following documentation page on extending/embedding 
python. I believe it does exactly what you want.

http://www.python.org/doc/ext/extending-with-embedding.html

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


Re: howto run a function w/o text output?

2007-06-22 Thread Evan Klitzke
On 6/22/07, dmitrey <[EMAIL PROTECTED]> wrote:
> hi all,
> I have a
> y = some_func(args)
> statement, and the some_func() produces lots of text output. Can I
> somehow to suppress the one?
> Thx in advance, D.

In addition to the other solutions proposed, on a *nix system you can
do os.close(1); os.close(2) to suppress output to stdout and stderr.

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


Re: I need some cleanings tips and advice.

2007-06-22 Thread Kaldrenon
On Jun 22, 1:09 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> Maybe they lost the business plan. It's not surprising, since it
> was probably written on a napkin.

Or perhaps they HAD a bunch of good cleaning tips, but accidentally
threw them out while cleaning?

Tip: don't throw stuff out unless you don't need it any more. =P

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


Re: Tailing a log file?

2007-06-22 Thread Evan Klitzke
On 6/22/07, Evan Klitzke <[EMAIL PROTECTED]> wrote:
> Everyone,
>
> I'm interested in writing a python program that reads from a log file
> and then executes actions based on the lines. I effectively want to
> write a loop that does something like this:
>
> while True:
> log_line = log_file.readline()
> do_something(log_line)
>
> Where the readline() method blocks until a new line appears in the
> file, unlike the standard readline() method which returns an empty
> string on EOF. Does anyone have any suggestions on how to do this?
> Thanks in advance!

I checked the source code for tail and they actually poll the file by
using fstat and sleep to check for changes in the file size. This
didn't seem right so I thought about it more and realized I ought to
be using inotify. So I guess I answered my own question.

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


Re: Tailing a log file?

2007-06-22 Thread Kenji Noguchi
something like this? unix tail command does more fancy stuff
like it waits for timeout, and check if the file is truncated
or depending on incoming data it sleeps seconds , etc etc.

#!/usr/bin/env python
import sys, select

while True:
ins, outs, errs = select.select([sys.stdin],[],[])
for i in ins:
print i.readline()


2007/6/22, Evan Klitzke <[EMAIL PROTECTED]>:
> On 6/22/07, Evan Klitzke <[EMAIL PROTECTED]> wrote:
> > Everyone,
> >
> > I'm interested in writing a python program that reads from a log file
> > and then executes actions based on the lines. I effectively want to
> > write a loop that does something like this:
> >
> > while True:
> > log_line = log_file.readline()
> > do_something(log_line)
> >
> > Where the readline() method blocks until a new line appears in the
> > file, unlike the standard readline() method which returns an empty
> > string on EOF. Does anyone have any suggestions on how to do this?
> > Thanks in advance!
>
> I checked the source code for tail and they actually poll the file by
> using fstat and sleep to check for changes in the file size. This
> didn't seem right so I thought about it more and realized I ought to
> be using inotify. So I guess I answered my own question.
>
> --
> Evan Klitzke <[EMAIL PROTECTED]>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tailing a log file?

2007-06-22 Thread Stephen R Laniel
On Fri, Jun 22, 2007 at 11:46:56AM -0700, Evan Klitzke wrote:
> I checked the source code for tail and they actually poll the file by
> using fstat and sleep to check for changes in the file size. This
> didn't seem right so I thought about it more and realized I ought to
> be using inotify. So I guess I answered my own question.

I've not thought about it much, but how about using Twisted?
Something like the LineReceiver class seems appropriate
here.

http://twistedmatrix.com/documents/current/api/twisted.protocols.basic.LineReceiver.html

-- 
Stephen R. Laniel
[EMAIL PROTECTED]
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tailing a log file?

2007-06-22 Thread Falcolas
On Jun 22, 12:50 pm, "Kenji Noguchi" <[EMAIL PROTECTED]> wrote:
> > I checked the source code for tail and they actually poll the file by
> > using fstat and sleep to check for changes in the file size. This
> > didn't seem right so I thought about it more and realized I ought to
> > be using inotify. So I guess I answered my own question.

I built something which worked on the "check stat and sleep" method.
Using notify or select may work, but it's not portible to Windows
systems, which may or may not be an issue for you.

#! /usr/bin/env python

import os
import sys
import time
from stat import *

class Watchfile(object):

def __init__(self, f_loc):

self.file_loc = f_loc

self.prev_lm = 0
self.last_read_pos = 0

f = open(self.file_loc, "r")
for l in f:
pass
self.last_read_pos = f.tell()
f.close()

self.prev_lm = os.stat(self.file_loc)[ST_MTIME]

def changed(self):

lm_time = os.stat(self.file_loc)[ST_MTIME]

if lm_time > self.prev_lm:
return True
else:
return False

def get_since_last_read(self):

f = open(self.file_loc, "r")

f.seek(self.last_read_pos)
lines = f.readlines()
self.last_read_pos = f.tell()

f.close

self.prev_lm = os.stat(self.file_loc)[ST_MTIME]
return lines

if __name__ == "__main__":
x_file = Watchfile("")
y_file   = Watchfile("")

while True:

if x_file.changed():

lines = x_file.get_since_last_read()

# do something

if y_file.changed():

lines = y_file.get_since_last_read()

# do something else

try:
time.sleep(5)
except KeyboardInterrupt:
break

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


Adding method to a class on the fly

2007-06-22 Thread John Henry
Hi list,

I have a need to create class methods on the fly.  For example, if I
do:

class Dummy:
def __init__(self):
exec '''def method_dynamic(self):\n\treturn
self.method_static("it's me")'''
return

def method_static(self, text):
print text
return

I like that to be the same as:

class Dummy:
def __init__(self):
return

def method_dynamic(self):
return self.method_static("it's me")

def method_static(self, text):
print text
return

so that I can do:

dum=Dummy.method_dynamic()

and see "it's me" printed.

Can that be done?

Thanks,

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


  1   2   3   >