Re: reading id3 tags with python

2006-11-24 Thread LaundroMat
Heh, a description of the error would be nice indeed.

Just a preliminary warning: with this code you will also be parsing
directories. id3reader can't handle those ofcourse.

Better add a check such as eg:
if os.path.isfile(os.path.join(directory, file)):
# do your thing

laundro

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


Newbie Developing a Python Extension

2006-11-24 Thread Jeremy
Hi,

I have been working on Linux 2.6.9 to adapt a C++ module to work as a Python
extension with the following setup.py file:

from distutils.core import setup, Extension

sm=Extension(
 'tdma',
 define_macros=[('__USE_POSIX199309','1')],
 include_dirs=['/usr/include','/usr/include/python2.3'],
 library_dirs=['/usr/lib'],
 sources=['Bitstrea.cpp','bytequeu.cpp','debug.cpp','dlist.cpp',
  'GrPort.cpp','IoPort.cpp','LMEmu.cpp','LMEmuPdu.cpp',
  'MacPyIf.cpp','per_os_clk.cpp','timer.cpp'])

setup(name='MySm',
 version='0.1.0',
 description='TDMA MAC',
 ext_modules=[sm])

The extension uses the POSIX call clock_gettime() and things seem fine when
generating the tdma.so file. However, when running the Python program, at a 
line 'from tdma import init,txdn,txup,...', I get an error message saying 
'ImportError: /home/.../tdma.so: undefined symbol: clock_gettime'.

What is wrong here? Is the from-import statement right?

Why is it, when I use 'import sm' or 'from sm import...', I get the message 
'ImportError: No module named sm'?

Thanks,
Jeremy 


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


Re: Is time.time() < time.time() always true?

2006-11-24 Thread Hendrik van Rooyen
"Tim Roberts" <[EMAIL PROTECTED]> wrote:


> "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
> 
> >"flamesrock" <[EMAIL PROTECTED]> wrote:
> >
> >8<--
> >
> >>  since the statement itself
> >> occurs at one time instant..
> >
> >nothing, but nothing, can occur at one time instant
> 
> Well, as long as we're being pedantic, surely that should read "only one
> thing can occur at any time instant..."

No its worse than that - what I mean is that everything takes finite time...

:-)  Hendrik


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


Local variables persist in functions?

2006-11-24 Thread 120psi
I'm a bit baffled.  Here is a bit of fairly straightforward code:

def _chunkify( l, chunkSize, _curList = list() ):
print _curList   # yay for printf debugging
if len( l ) <= chunkSize:
_curList.append( l )
else:
newChunk = l[:chunkSize]
_curList.append( newChunk )
_chunkify( l[chunkSize:], chunkSize, _curList )
return _curList

_chunkify simply breaks a sequence into a sequence of smaller lists of
size <= chunkSize.  The first call works fine, but if I call it
multiple times, weirdness happens.

chunks = _chunkify( list, size )   # _curList keeps its previous value!
chunks = _chunkify( list, size, list() )# this works as expected

Considering the default value of _curList, these statements should be
identical.  Any pointers?  Did I miss something in the python reference
manual?  (running 2.4.3, fyi)

Thanks,
Nils

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


Re: Abelson and Python

2006-11-24 Thread cfbolz

Fredrik Lundh schrieb:

> markscottwright wrote:
>
>  > If it were that easy, the PyPy guys would be done by now.
>
> if the PyPy guys had focused on writing a Python interpreter in Python,
> they'd been done by now.
>
> 

The "Python interpreter in Python" part of PyPy _is_ done. Since quite
a while even (something like July 2005) compilation to C works, and the
interpreter was more or less finished since quite a while before that.
There were some things missing at that point but interpretation of
Python code that didn't use any fancy builtin modules worked.

Cheers,

Carl Friedrich Bolz

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


Re: Local variables persist in functions?

2006-11-24 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> 
> Considering the default value of _curList, these statements should be
> identical.  Any pointers?  Did I miss something in the python reference
> manual?  (running 2.4.3, fyi)

See the FAQ:

http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access to variable from external imported module

2006-11-24 Thread John Machin

jim-on-linux wrote:
> GinTon,
>
> I think this is what you want.
>
>
> class Kdoi:

Is that a typo?

>def __init__(self) :
>self.Fdo()
>

What is all this K and F stuff?

>def Fdo(self):
>
>  searchterm = 'help'
>  print searchterm #local
>
>  self.searchterm = searchterm
>  print self.searchterm #used inside the class
>
>  Kdo.searchterm = searchterm   #
>  print Kdo.searchterm #used outside the class
>  Kdomore()
>
>
>
> class Kdomore(Kdo):
>  def __init__(self) :
>  self.Fdomore()
>
>  def Fdomore(self):
>  searchterm =  Kdo.searchterm   # 
>  print searchterm

It's not apparent what the print statements are for -- are they part of
an attempt to debug your code?

What gives you the idea that this is what the OP wants or needs?

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


Re: Local variables persist in functions?

2006-11-24 Thread John Machin

[EMAIL PROTECTED] wrote:
> I'm a bit baffled.  Here is a bit of fairly straightforward code:
>
> def _chunkify( l, chunkSize, _curList = list() ):

Quite apart from the default argument problem, which Duncan has
addressed, you have some problems with style and variable names. In
particular: give variables meaningful names ; "L".lower() is not
meaningful and also suffers from confusion with the digit 1 in some
fonts. There is no necessity for the _ in _curList in the above line.

Please consider reading http://www.python.org/dev/peps/pep-0008/

> print _curList   # yay for printf debugging
> if len( l ) <= chunkSize:
> _curList.append( l )
> else:
> newChunk = l[:chunkSize]
> _curList.append( newChunk )
> _chunkify( l[chunkSize:], chunkSize, _curList )
> return _curList
>
> _chunkify simply breaks a sequence into a sequence of smaller lists of
> size <= chunkSize.  The first call works fine, but if I call it
> multiple times, weirdness happens.
>
> chunks = _chunkify( list, size )   # _curList keeps its previous value!
> chunks = _chunkify( list, size, list() )# this works as expected

Is the first "list" a list, or is it the name of the same function that
you are calling to provide the 3rd argument?

[snip]

HTH,
John

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


Re: The Python Papers Edition One

2006-11-24 Thread Shane Hathaway
[EMAIL PROTECTED] wrote:
> Ben Finney wrote:
>> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>>
>>> Yes, it's true that you can't resell copies of The Python Papers for
>>> personal profits, but you may derive from it, reproduce and
>>> propagate it. You're quite right to point it out.
>> Then please revise the false statement that the publication is "free
>> as in beer and freedom", or make it true by releasing the documents
>> under a license that does grant conventional free-software freedoms.
>>
>> --
>>  \   "They can not take away our self respect if we do not give it |
>>   `\  to them."  -- Mahatma Gandhi |
>> _o__)  |
>> Ben Finney
> 
> I thought I just had. In what way does the statement "Yes, it's true
> that you can't resell copies of The Python Papers for personal profits,
> but you may derive from it, reproduce and propagate it" not provide
> such a revision and clarification? Seriously, let me know what exact
> statement you feel needs to be made, and I will endorse it accordingly
> if it is accurate.

The phrase "free as in freedom" is commonly understood differently from
the way you are using it.  Free as in freedom usually grants the right
to distribute for a fee.  Many Linux distributors depend on that right;
otherwise they wouldn't have the right to sell CDs.

IMHO your licensing terms are fine; you don't need to switch from the CC
license.  Just avoid the term "free as in freedom", since the Free
Software Foundation has assigned that phrase a very specific meaning.

Shane

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


Re: Access to variable from external imported module

2006-11-24 Thread robert
GinTon wrote:
> Thanks Robert, the best solution is get all local variables, else is
> impossible access to them.

For test purposes/ex post inspection you could also uncomment the line in:

def f(a=1):
b=2
c=3
#globals().update(locals())
return a+b
--

then it is more easy and you can get it like:

module.c


You can also create a total stack trace dynamically with this trick function:

def mktb():
try: raise UserWarning
except: return sys.exc_info()[2]

def f(a=1):
b=2
c=3
global ftb;ftb=mktb()
return a+b


and then fully inspect the total situation in the func (and all down the call 
history) ex post at any time with

>>> f()
>>> pdb.post_mortem(module.ftb)   # then do once 'up' in 
>>> pdb/pywin.debugger...
>>> pywin.debugger.post_mortem(module.ftb)


Which other programming language can do things like this? 
( Unfortunately (legacy) Python has no possibility to (re-)continue execution 
from exceptions/traces other than by simple generators )

Robert



> robert ha escrito:
>> GinTon wrote:
>>> I would to access to values that are created locally in that method
>> after the method has executed? usually the return value?
>> or you want to get all local variables, then make a func/method
>>
>> def f(a=1):
>> b=2
>> c=3
>> return locals()  #X/Object(locals())
>>
>> 
>>
>> d=module.f()
>> print d['c'] # d.c
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Local variables persist in functions?

2006-11-24 Thread robert
[EMAIL PROTECTED] wrote:
> I'm a bit baffled.  Here is a bit of fairly straightforward code:
> 
> def _chunkify( l, chunkSize, _curList = list() ):
> print _curList   # yay for printf debugging
> if len( l ) <= chunkSize:
> _curList.append( l )
> else:
> newChunk = l[:chunkSize]
> _curList.append( newChunk )
> _chunkify( l[chunkSize:], chunkSize, _curList )
> return _curList
> 
> _chunkify simply breaks a sequence into a sequence of smaller lists of
> size <= chunkSize.  The first call works fine, but if I call it
> multiple times, weirdness happens.
> 
> chunks = _chunkify( list, size )   # _curList keeps its previous value!
> chunks = _chunkify( list, size, list() )# this works as expected
> 
> Considering the default value of _curList, these statements should be
> identical.  Any pointers?  Did I miss something in the python reference
> manual?  (running 2.4.3, fyi)
> 

the default list() is only created once when the function is defined. And its 
later its always the same list
Use

def _chunkify( l, chunkSize, _curList=None ):
_curList = _curList or []
...

then it works.

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


Re: socket.error connection refused

2006-11-24 Thread Vania

For anyone interested restarting windows fixed the connection problem.

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


Modules - Jython Vs Python?

2006-11-24 Thread Patrick Finnegan
How many of the Python modules written in C have been rewritten and and
ported to Java to run under Jython? I am talking about SMTP, LDAP,
WIN2K,XML etc.  Is there a list anywhere ?

Thanks

Patrick.

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


Re: socket.error connection refused

2006-11-24 Thread robert
Vania wrote:
> Hi, I'm not sure this is the proper forum but I try nevertheless.
> The problem I'am facing is that the socket library always fail to
> connect to an URL. The net effect is that I can not use setuptools.
> I'm using Python2.4 on a windows XPPRO Sp2 machine.
> The firewall is disabled.
> There is no NLTM proxy.
> I connect to the internet through a NAT server (and it works).
> Other than with easy_install I tried to connect to a number of external
> urls
> (all of them running) and even to localhost,
> directly in script using urllib
> and the error is always the same errno:  10061 connection refused.
> Any ideas?


urllib.urlopen can pick up an invalid proxy setting from environ or IE-settings.

routers/NAT servers sometimes need a 2nd tick - all browsers try it 2..4 times 
before displaying "no connection" - this is (unfortunately) not the default 
behavior of the "browser" urllib.

if bare

>>> import httplib
>>> h=httplib.HTTPConnection('www.google.com')
>>> h.connect()
>>> h.request('GET','/')
>>> h.getresponse().read()
'\n302 
Moved\n302 Moved\nThe document has moved\nhttp://www.google.de/";>here.\r\n\r\n'
>>> 

fails on multiple trials, then you have a very strange network setup. maybe 
multiple/confusing NIC's ...


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


Re: Python work in UK

2006-11-24 Thread vasudevram

Hi,

A few suggestions, you may have tried them already:

Search for UK Python jobs on major job sites like Monster, Dice, etc.
Some (like Monster) have country-specific sites, I think. I know
Monster has an India-specific site, it probably also has one for the
UK.

Have you considered the option of being a freelancer and working via
Net job sites like eLance, Guru.com, oDesk?

Also check out the Python job board at
http://www.python.org/community/jobs/

HTH
Vasudev
---
Site: http://www.dancingbison.com
Blogs:
http://jugad.livejournal.com
http://dancingbison.blogspot.com
Open source project:
http://www.dancingbison.com/products.html
---

Will McGugan wrote:
> Hi,
>
> I'd love to work in Python, for the sake of my blood pressure, but there
> doesnt seem to be that many jobs that look for Python as the main skill.
> I use Python at work from time to time, and occasionaly get to spend
> several days on a Python project but the majority of the time I use C++.
> How can I make that leap to working with Python? There doesn't seem to
> be many UK positions on the jobs section of Python.org or the usual jobs
> sites. Any recommended jobs sites or tips? (I have googled)
>
> In the off chance that a potential empolyer is reading this, I'm looking
> for something in web development, applications, graphics or other
> interesting field. Here is a copy of my CV.
>
> http://www.willmcgugan.com/cvwillmcgugan.pdf
> 
> Regards,
> 
> Will McGugan
> -- 
> http://www.willmcgugan.com

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


locking bsddb objects

2006-11-24 Thread Antoon Pardon
This is a little project using python 2.3.5, I want to use one of
the bsddb objects, but I also need to protect against concurrent
access and modification. IMO this would be something for
fcntl.flock or fcntl.lockf. However the bsddb objects don't provide
a fileno method.

So how do I protect against concurrent access and modification?

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


Pimping the 'cgi' module (was: Re: python gaining popularity according to a study)

2006-11-24 Thread Christoph Haas
On Thursday 23 November 2006 21:29, robert wrote:
> When a LAMP programmer comes to Python, there are so many different
> confusing things. It starts with a 'non-documented' cgi module - a
> 'High-Level-Interface', that cannot even iterate over the form items. A
> name ZOPE in focus which reveals to be a monster system with 2-year
> learning-curve, ready for running an article editorial system for TOP-10
> newspaper companies, but unable to make simple things simple. A handful
> of different Djangos - choose one for each weekday and programmer ...
> And Ruby made it with this single-known simple URL-to-method-router (And
> possibly when coming from PHP & Perl one recognizes ::@$_$%§§%/&... and
> the old namespace dirt) If there would have been a good cgi-system and a
> somewhat comfortable advanced URL-to-OO-router (beyond the socket
> wrapper HTTPServer) well exposed in the Python standard lib, the numbers
> would be probably very different today ...

I can fully second that. Coming from Perl and being used to the CGI module 
that is de-facto standard and already doing things much better than 
Python's equivalent my first thought was: "Does Python really expect me to 
re-invent the wheel to write basic CGIs?" So I started creating 
cookie-based session handlers, form field handling etc.

The reason of my posting it not only to complain though. My Python skills 
are average but I would really like to help contribute some code on this 
topic. I don't know Ruby-on-Rails myself but I have worked with CGIs for 
ten years both in C (yuk) and Perl (Perl=semi-yuk / Perl-CGI=yum) and 
think I know what people coming from Perl expect. And I'm not speaking of 
Zope or Django or huge frameworks. I try to avoid frameworks wherever I 
can (I want to write Python - not Zope or Django). I rather rely on the 
standard library unless it's really saving me time and worth learning 
another language. Are frameworks perhaps even telling that the standard 
library is still lacking in some way?

I'm thinking of features like:
- cookie handling
- cookie-session handling (similar to PHP or Perl's CGI::Session; combined
  with database backends or simple text files)
- handling of form fields (Perl's CGI class can easily redisplay what
  has been entered in the fields when they got submitted through a )
- accessing parameters (honestly I haven't yet understood why I need to use
  .value on FielStorage dictionaries - why isn't it just a plain
  dictionary?)
- state keeping (storing the contents of all form fields on disk
  to retrieve it later)
- creating form elements easily (option lists for example from
  dictionaries and lists like in Perl)
- creating standard HTML elements (or do you remember how DOCTYPE
  looks without looking it up?)
- handling of file uploads (which is just a recipe on ActivePython
  at the moment)
- controlling HTTP headers (expires, redirections, charset)
- convenience functions e.g. for getting the client IP address without
  needing to read ENV['REMOTE_ADDR']

Well, of course there are modules like 'cgi' or 'cookielib' and others may 
argue that everything is already there. And there is a 'Web.py' already (I 
assume every CGI programmer has written their own Web.py already). But 
can't we come closer to what other scripting languages provide? Something 
common? Can't a simple form-based CGI just be a matter of a dozen lines? 
When it comes to CGIs Python loses its elegance for no reason.

I'm ready to invest work and ideas if anyone else is interested. Perhaps 
some day it makes it into the standard library or at least gives us 
something between the features of the standard library and huge framework 
monsters - something people can be pointed at when starting with Python 
and CGIs. I'll probably do that anyway because my web projects all use 
their own reinvented wheel and I'm losing the overview. And even Perl has 
come that route - it started with a cgi-lib.pl which later became 
the 'CGI' standard module.

Is it just a matter of lacking resources or interest? Even if there is no 
interest I'll probably read "man CGI" and "man CGI::Session" again and 
start implementing something nifty for ex-perlies like myself. Hmmm, 
batteries included even for CGI programmers, a man can dream. :)

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


bz2.readline() slow ?

2006-11-24 Thread Soeren Sonnenburg
Dear all,

I am a bit puzzled, as

-snip-
import bz2
f=bz2.BZ2File('data/data.bz2');

while f.readline():
pass
-snip-

takes twice the time (10 seconds) to read/decode a bz2 file
compared to

-snip-
import bz2
f=bz2.BZ2File('data/data.bz2');
x=f.readlines()
-snip-

(5 seconds). This is even more strange as the help(bz2) says:

 |  readlines(...)
 |  readlines([size]) -> list
 |  
 |  Call readline() repeatedly and return a list of lines read.
 |  The optional size argument, if given, is an approximate bound on the
 |  total number of bytes in the lines returned.

This happens on python2.3 - python2.5 and it does not help to specify a
maximum line size.

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


Re: The Python Papers Edition One

2006-11-24 Thread Paul Boddie
Shane Hathaway wrote:
>
> IMHO your licensing terms are fine; you don't need to switch from the CC
> license.  Just avoid the term "free as in freedom", since the Free
> Software Foundation has assigned that phrase a very specific meaning.

Agreed. It should also be noted that Debian - amongst the strictest
with regard to software and content licensing - do not regard the CC
licences as being "free as in freedom":

http://en.wikipedia.org/wiki/Creative_Commons_licenses
http://people.debian.org/~evan/ccsummary.html
http://people.debian.org/~evan/draftresponse.txt

Consequently, it may be appropriate to remind authors to also make
their works more widely available under a licence that may permit
further distribution, if that is desirable.

Paul

P.S. I still don't really understand why the FSF unreservedly
recommends the Free Art licence when it has a "choice of law" clause
that has prevented things like the GPL-compatibility of other licences
in the past.

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


Re: Local variables persist in functions?

2006-11-24 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> chunks = _chunkify( list, size )   # _curList keeps its previous value!
> chunks = _chunkify( list, size, list() )# this works as expected
>
> Considering the default value of _curList, these statements should be
> identical.  Any pointers?

http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm

> Did I miss something in the python reference manual?  (running 2.4.3, fyi)

the paragraph that starts with "Default parameter values are evaluated when
the function definition is executed." in bold,  perhaps.  I've highlighted it
on this page:

http://effbot.org/pyref/def.htm

 



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


Re: Simple threading

2006-11-24 Thread jrpfinch
Thank you for your help - the application is proceeding well.

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


Re: Pimping the 'cgi' module (was: Re: python gaining popularity according to a study)

2006-11-24 Thread Paul Boddie
Christoph Haas wrote:
> On Thursday 23 November 2006 21:29, robert wrote:
> > When a LAMP programmer comes to Python, there are so many different
> > confusing things. It starts with a 'non-documented' cgi module - a
> > 'High-Level-Interface', that cannot even iterate over the form items. A
> > name ZOPE in focus which reveals to be a monster system with 2-year
> > learning-curve, ready for running an article editorial system for TOP-10
> > newspaper companies, but unable to make simple things simple.

Zope was simultaneously one of the best things to happen in Python Web
programming, but also one of the worst, mostly because people saw the
power of the solution, correctly realised that it could do a lot of
things they would otherwise have to do themselves, but then got locked
into an approach which wasn't suitable for every kind of application.
It was like having a handful of fairly promising parties ruined by the
opening night of an expensive nightclub where the first two drinks were
free.

> > A handful of different Djangos - choose one for each weekday and programmer 
> > ...

The handful of Djangos isn't necessarily a problem, but there is this
"all or nothing" mentality in writing and promoting Web frameworks. Or
rather, an "all or lots of little pieces" mentality. One is left either
with a room full of tiny Lego bricks to put together, or one actually
has to be the python and swallow a large solution whole, hoping that it
all tastes good - even the nasty parts.

> > And Ruby made it with this single-known simple URL-to-method-router (And
> > possibly when coming from PHP & Perl one recognizes ::@$_$%§§%/&... and
> > the old namespace dirt) If there would have been a good cgi-system and a
> > somewhat comfortable advanced URL-to-OO-router (beyond the socket
> > wrapper HTTPServer) well exposed in the Python standard lib, the numbers
> > would be probably very different today ...

There was probably a window of opportunity to include the old Bobo
dispatcher (or perhaps the "Poor Man's Zope" stuff) in the standard
library, but rigid dispatchers of that style arguably aren't sufficient
any more, even though they can be regarded almost as the original
"URL-to-OO router". If you look now, there are a number of
dispatchers/routers that work in a more-or-less independent way from
frameworks, however.

> I can fully second that. Coming from Perl and being used to the CGI module
> that is de-facto standard and already doing things much better than
> Python's equivalent my first thought was: "Does Python really expect me to
> re-invent the wheel to write basic CGIs?" So I started creating
> cookie-based session handlers, form field handling etc.

The standard library expects you to do that, yes, since many of the
Web-related modules were written in the infancy of the Web and have
only been conservatively updated since. I remember when the cookie
handling went in, and it was a big but overdue event back then.

> I rather rely on the standard library unless it's really saving me time and 
> worth learning
> another language. Are frameworks perhaps even telling that the standard
> library is still lacking in some way?

I believe so, and I'm not alone with that opinion.

> I'm thinking of features like:

[List of HTTP-related, persistence-related and templating-related
things]

> I'm ready to invest work and ideas if anyone else is interested.

Take a look at this page for some other work with similar goals:

http://wiki.python.org/moin/WebStandardisation

> Perhaps some day it makes it into the standard library or at least gives us
> something between the features of the standard library and huge framework
> monsters - something people can be pointed at when starting with Python
> and CGIs. I'll probably do that anyway because my web projects all use
> their own reinvented wheel and I'm losing the overview. And even Perl has
> come that route - it started with a cgi-lib.pl which later became
> the 'CGI' standard module.

Some people will argue that you just want a big framework (implying
that they know what you want better than you do), whilst others will
talk about lots of reusable middleware. I don't disagree with the
component-based solution mindset, but the bricks really have to be
bigger, and there needs to be a picture on the box showing what the
finished model looks like, along with some clear instructions on
getting started.

> Is it just a matter of lacking resources or interest? Even if there is no
> interest I'll probably read "man CGI" and "man CGI::Session" again and
> start implementing something nifty for ex-perlies like myself. Hmmm,
> batteries included even for CGI programmers, a man can dream. :)

I am aware of at least one person who seems dissatisfied with the
current level of standardisation and who wants something a bit more
obvious for those who don't want to take the "30 second Wiki" route.
Perhaps they could openly publish their ideas or proposals and we could
establish some kind of uno

Active State and Komodo...

2006-11-24 Thread Steve Thompson
Hello all,

I was wondering the differnced there were betwee Active State's python and
the open source version of python. Would I have to unistall my opend souce
python? Additonally, how does Active State's Komodo IDE vs. the eric3 IDE
unler SuSE Linux v. 10.i?

Addionally, is the eric IDE (version 3) an acceptible IDE or are there
more easy and more productive IDE's for perl?

I'm urining Gnome v. 12.2.2 and Eric v 3.8.1

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


Re: Email headers and non-ASCII characters

2006-11-24 Thread Christoph Haas
On Thursday 23 November 2006 16:31, Max M wrote:
> Christoph Haas skrev:
> > Hello, everyone...
> >
> > I'm trying to send an email to people with non-ASCII characters in
> > their names. A recpient's address may look like:
> >
> > "Jörg Nørgens" <[EMAIL PROTECTED]>
> >
> > My example code:
> >
> > =
> > def sendmail(sender, recipient, body, subject):
> >message = MIMEText(body)
> >message['Subject'] = Header(subject, 'iso-8859-1')
> >message['From'] = Header(sender, 'iso-8859-1')
> >message['To'] = Header(recipient, 'iso-8859-1')
> >
> >s = smtplib.SMTP()
> >s.connect()
> >s.sendmail(sender, recipient, message.as_string())
> >s.close()
> > =
> >
> > However the Header() method encodes the whole expression in
> > ISO-8859-1:
> >
> > =?iso-8859-1?q?=22J=C3=B6rg_N=C3=B8rgens=22_=3Cjoerg=40nowhere=3E?=
> >
> > However I had expected something like:
> >
> > "=?utf-8?q?J=C3=B6rg?= =?utf-8?q?_N=C3=B8rgens?=" <[EMAIL PROTECTED]>
> >
> > Of course my mail transfer agent is not happy with the first string
>
> Why offcourse?

Because my MTA doesn't care about MIME. It just transports the email. And 
it expects an email address in <...> but doesn't decode =?iso...? strings.

> But it seems that you are passing the Header object a 
> utf-8 encoded string, not a latin-1 encoded.
> You are telling the header the encoding. Not asking it to encode.

Uhm, okay. Let's see:

u'"Jörg Nørgens" <[EMAIL PROTECTED]>'.encode('latin-1')

=> '"J\xc3\xb6rg N\xc3\xb8rgens" <[EMAIL PROTECTED]>'

So far so good. Now run Header() on it:

=> '=?utf-8?b?IkrDtnJnIE7DuHJnZW5zIiA8am9lcmdAbm93aGVyZT4=?='

Still nothing like <...> in it and my MTA is unhappy again. What am I 
missing? Doesn't anyone know how mail clients handle that encoding?

Desperately,
 Christoph
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python work in UK

2006-11-24 Thread Gerard Flanagan

Will McGugan wrote:

> Hi,
>
> I'd love to work in Python, for the sake of my blood pressure, but there
> doesnt seem to be that many jobs that look for Python as the main skill.
> I use Python at work from time to time, and occasionaly get to spend
> several days on a Python project but the majority of the time I use C++.
> How can I make that leap to working with Python? There doesn't seem to
> be many UK positions on the jobs section of Python.org or the usual jobs
> sites. Any recommended jobs sites or tips? (I have googled)
>

Hi Will

I recommend 'cwjobs.co.uk' and 'reed.co.uk'.  I got my current (Python)
contract through MCG recruitment (mcg-recruitment.com), and I've just
accepted a Python/Zope position through  sienared.com - both of these
are in London and came via CWjobs. I don't know about the rest of the
country but there is definitely pure Python work in London if you look
for it.

Good Luck.

Gerard

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


Re: Pimping the 'cgi' module

2006-11-24 Thread robert
Christoph Haas wrote:
> On Thursday 23 November 2006 21:29, robert wrote:
>> When a LAMP programmer comes to Python, there are so many different
>> confusing things. It starts with a 'non-documented' cgi module - a
>> 'High-Level-Interface', that cannot even iterate over the form items. A
>> name ZOPE in focus which reveals to be a monster system with 2-year
>> learning-curve, ready for running an article editorial system for TOP-10
>> newspaper companies, but unable to make simple things simple. A handful
>> of different Djangos - choose one for each weekday and programmer ...
>> And Ruby made it with this single-known simple URL-to-method-router (And
>> possibly when coming from PHP & Perl one recognizes ::@$_$%§§%/&... and
>> the old namespace dirt) If there would have been a good cgi-system and a
>> somewhat comfortable advanced URL-to-OO-router (beyond the socket
>> wrapper HTTPServer) well exposed in the Python standard lib, the numbers
>> would be probably very different today ...
> 
> I can fully second that. Coming from Perl and being used to the CGI module 
> that is de-facto standard and already doing things much better than 
> Python's equivalent my first thought was: "Does Python really expect me to 
> re-invent the wheel to write basic CGIs?" So I started creating 
> cookie-based session handlers, form field handling etc.

That exactly is where Python lost real numbers. All kinds of fancy things are 
in the standard lib, but not these must-have's in a good collection ..

> The reason of my posting it not only to complain though. My Python skills 
> are average but I would really like to help contribute some code on this 
> topic. I don't know Ruby-on-Rails myself but I have worked with CGIs for 
> ten years both in C (yuk) and Perl (Perl=semi-yuk / Perl-CGI=yum) and 
> think I know what people coming from Perl expect. And I'm not speaking of 
> Zope or Django or huge frameworks. I try to avoid frameworks wherever I 
> can (I want to write Python - not Zope or Django). I rather rely on the 
> standard library unless it's really saving me time and worth learning 
> another language. Are frameworks perhaps even telling that the standard 
> library is still lacking in some way?

well, note, for that they have named it Ruby-On-Rails, so its still the 
language - leveraged. 
While it is Zope/Django/Ego-on-Python ... ?

So its about the right level of a framework. (even a cgi module is a framework.)

I think i could learn to like this one as basic intuitive idea: 
http://www.cherrypy.org/

Unless a Guido'ed version of such thing is not _selected_ into the stdlib or at 
least promoted single-mindedly and prominently by far before 
high-tech-but-low-number names like Zope and Django, Python will continue to 
bleed out heavily on numbers vs. Ruby.

First need of course: an update of that cgi "module".

> I'm thinking of features like:
> - cookie handling
> - cookie-session handling (similar to PHP or Perl's CGI::Session; combined
>   with database backends or simple text files)
> - handling of form fields (Perl's CGI class can easily redisplay what
>   has been entered in the fields when they got submitted through a )
> - accessing parameters (honestly I haven't yet understood why I need to use
>   .value on FielStorage dictionaries - why isn't it just a plain
>   dictionary?)
> - state keeping (storing the contents of all form fields on disk
>   to retrieve it later)
> - creating form elements easily (option lists for example from
>   dictionaries and lists like in Perl)
> - creating standard HTML elements (or do you remember how DOCTYPE
>   looks without looking it up?)
> - handling of file uploads (which is just a recipe on ActivePython
>   at the moment)
> - controlling HTTP headers (expires, redirections, charset)
> - convenience functions e.g. for getting the client IP address without
>   needing to read ENV['REMOTE_ADDR']

tell it loud

> Well, of course there are modules like 'cgi' or 'cookielib' and others may 

Cookie. (cookielib is for clients.)
But read the doc chapter "Cookie -- HTTP state management"...
What is 'input': "If input is given, it is passed to the load() method. " ...
So first read the "Example", oo  :-)

I tell you - you will know how to achieve cookie/session handling before you 
read all source code and the RFC's

So its not much disadvantage to not know about the existence of this module.

> argue that everything is already there. And there is a 'Web.py' already (I 
> assume every CGI programmer has written their own Web.py already). But 

yes - which Web.py :-)   another v0.138 : http://webpy.org/ ?

> can't we come closer to what other scripting languages provide? Something 
> common? Can't a simple form-based CGI just be a matter of a dozen lines? 
> When it comes to CGIs Python loses its elegance for no reason.

No other language could do it in less lines. There is no other excuse than: 
*

> I'm ready to invest work and ideas if anyone else is interest

Re: socket.error connection refused

2006-11-24 Thread Vania

Thanks for the explanation.
Probably the fact that I was working inside a virtual machine
didn't help.

Vania

robert ha scritto:

> Vania wrote:
> > Hi, I'm not sure this is the proper forum but I try nevertheless.
> > The problem I'am facing is that the socket library always fail to
> > connect to an URL. The net effect is that I can not use setuptools.
> > I'm using Python2.4 on a windows XPPRO Sp2 machine.
> > The firewall is disabled.
> > There is no NLTM proxy.
> > I connect to the internet through a NAT server (and it works).
> > Other than with easy_install I tried to connect to a number of external
> > urls
> > (all of them running) and even to localhost,
> > directly in script using urllib
> > and the error is always the same errno:  10061 connection refused.
> > Any ideas?
>
>
> urllib.urlopen can pick up an invalid proxy setting from environ or 
> IE-settings.
>
> routers/NAT servers sometimes need a 2nd tick - all browsers try it 2..4 
> times before displaying "no connection" - this is (unfortunately) not the 
> default behavior of the "browser" urllib.
>
> if bare
>
> >>> import httplib
> >>> h=httplib.HTTPConnection('www.google.com')
> >>> h.connect()
> >>> h.request('GET','/')
> >>> h.getresponse().read()
> ' content="text/html;charset=utf-8">\n302 
> Moved\n302 Moved\nThe document has moved\n HREF="http://www.google.de/";>here.\r\n\r\n'
> >>>
>
> fails on multiple trials, then you have a very strange network setup. maybe 
> multiple/confusing NIC's ...
> 
> 
> Robert

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


Re: The Python Papers Edition One

2006-11-24 Thread Carl Banks
Shane Hathaway wrote:
> Just avoid the term "free as in freedom", since the Free
> Software Foundation has assigned that phrase a very specific meaning.

Bah.  FSF is not an arbiter of the language.  People whose idea of
"free" differs from FSF's still need to differentiate it from the
monetary sense of the word free.

Carl Banks

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


Re: Pimping the 'cgi' module

2006-11-24 Thread Christoph Haas
On Friday 24 November 2006 13:08, robert wrote:
> well, note, for that they have named it Ruby-On-Rails, so its still the
> language - leveraged. While it is Zope/Django/Ego-on-Python ... ?

If by that you mean that neither Zope nor Django are exactly pythonic I 
think I concur.

> Unless a Guido'ed version of such thing is not _selected_ into the
> stdlib or at least promoted single-mindedly and prominently by far
> before high-tech-but-low-number names like Zope and Django, Python will
> continue to bleed out heavily on numbers vs. Ruby.

Guido seems to have been confused about the rank growth of web based 
frameworks himself. So it's even less likely one of them gets included as 
part of the standard library in finite time.

> First need of course: an update of that cgi "module".

Oh, yeah. I just joined the Web SIG and found out that WSGI seems the way 
to go. At a first look it seems horrible if you just want to provide a CGI 
module. But there must be some reason for its existence. :) Looking 
further through http://wiki.python.org/moin/WebFrameworks my head starts 
to spin. Somehow I sadly feel I would just add another incomplete 
framework to that pile.

I'm especially unsure whether it's good or bad to create another "I'm sick 
of the standard library"-style module. I've just become a bit less 
confident to actually contribute something useful there. Overwhelming.

> python-dev is fully occupied with top-notch inner life. Of course that
> is the basis. But key issues in lib&tools were simply forgotten - left
> to a random community.

Which doesn't match the "batteries included" fuss at all. Of course the 
basis has to be good, too. And there are so many paradigms today that no 
core-python developer can really be expected to provide good standard 
modules for everyone.

> Go for a start. In order to realize that essential batteries in good
> quality within time - even after 10 years now - it is necessary, to hook
> python-dev for even requesting it actively. Just adding to
> http://wiki.python.org/moin/WebProgramming and
> http://wiki.python.org/moin/WebFrameworks is not the task. It requires
> some organization and somewhat a selection process in addition to good
> (probably existing) code v0.1xxx material. I think it would not be
> overly complex. Both, a new cgi and possibly included snake "rails" (vs
> "oil")

Oil is deprecated anyway. :) I'll see if I can find my way into the SIG. 
And - yes - adding another framework will surely not help us out of the 
divergence. The more frameworks there are the more people seem to feel 
urged to say "heck, it will be easier to write my own framework than 
evaluate all 30 packages on that page".

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


Re: Email headers and non-ASCII characters

2006-11-24 Thread Leo Kislov

Christoph Haas wrote:
> Hello, everyone...
>
> I'm trying to send an email to people with non-ASCII characters in their
> names. A recpient's address may look like:
>
> "Jörg Nørgens" <[EMAIL PROTECTED]>
>
> My example code:
>
> =
> def sendmail(sender, recipient, body, subject):
>message = MIMEText(body)
>message['Subject'] = Header(subject, 'iso-8859-1')
>message['From'] = Header(sender, 'iso-8859-1')
>message['To'] = Header(recipient, 'iso-8859-1')
>
>s = smtplib.SMTP()
>s.connect()
>s.sendmail(sender, recipient, message.as_string())
>s.close()
> =
>
> However the Header() method encodes the whole expression in ISO-8859-1:
>
> =?iso-8859-1?q?=22J=C3=B6rg_N=C3=B8rgens=22_=3Cjoerg=40nowhere=3E?=
>
> However I had expected something like:
>
> "=?utf-8?q?J=C3=B6rg?= =?utf-8?q?_N=C3=B8rgens?=" <[EMAIL PROTECTED]>
>
> Of course my mail transfer agent is not happy with the first string
> although I see that Header() is just doing its job. I'm looking for a way
> though to encode just the non-ASCII parts like any mail client does. Does
> anyone have a recipe on how to do that? Or is there a method in
> the "email" module of the standard library that does what I need? Or
> should I split by regular expression to extract the email address
> beforehand? Or a list comprehension to just look for non-ASCII character
> and Header() them? Sounds dirty.

Why dirty?

from email.Header import Header
from itertools import groupby
h = Header()
addr = u'"Jörg Nørgens" <[EMAIL PROTECTED]>'
def is_ascii(char):
return ord(char) < 128
for ascii, group in groupby(addr, is_ascii):
h.append(''.join(group),"latin-1")

print h
=>
"J =?iso-8859-1?q?=F6?= rg N =?iso-8859-1?q?=F8?= rgens"
<[EMAIL PROTECTED]>

  -- Leo

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


NFS server

2006-11-24 Thread srj
i wish to develop an NFS server usin python from scratch( some wise guy
told me i'ts easy!).
can i get any kinda tutorial for this??

any suggestions on how 2 begin?

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


Re: Email headers and non-ASCII characters

2006-11-24 Thread Max M
Christoph Haas skrev:
> On Thursday 23 November 2006 16:31, Max M wrote:
>> Christoph Haas skrev:
>>> Hello, everyone...
>>>
>>> I'm trying to send an email to people with non-ASCII characters in
>>> their names. A recpient's address may look like:
>>>
>>> "Jörg Nørgens" <[EMAIL PROTECTED]>
>>>
>>> My example code:
>>>
>>> =
>>> def sendmail(sender, recipient, body, subject):
>>>message = MIMEText(body)
>>>message['Subject'] = Header(subject, 'iso-8859-1')
>>>message['From'] = Header(sender, 'iso-8859-1')
>>>message['To'] = Header(recipient, 'iso-8859-1')
>>>
>>>s = smtplib.SMTP()
>>>s.connect()
>>>s.sendmail(sender, recipient, message.as_string())
>>>s.close()
>>> =
>>>
>>> However the Header() method encodes the whole expression in
>>> ISO-8859-1:
>>>
>>> =?iso-8859-1?q?=22J=C3=B6rg_N=C3=B8rgens=22_=3Cjoerg=40nowhere=3E?=
>>>
>>> However I had expected something like:
>>>
>>> "=?utf-8?q?J=C3=B6rg?= =?utf-8?q?_N=C3=B8rgens?=" <[EMAIL PROTECTED]>
>>>
>>> Of course my mail transfer agent is not happy with the first string
>> Why offcourse?
> 
> Because my MTA doesn't care about MIME. It just transports the email. And 
> it expects an email address in <...> but doesn't decode =?iso...? strings.
> 
>> But it seems that you are passing the Header object a 
>> utf-8 encoded string, not a latin-1 encoded.
>> You are telling the header the encoding. Not asking it to encode.
> 
> Uhm, okay. Let's see:
> 
> u'"Jörg Nørgens" <[EMAIL PROTECTED]>'.encode('latin-1')
> 
> => '"J\xc3\xb6rg N\xc3\xb8rgens" <[EMAIL PROTECTED]>'
> 
> So far so good. Now run Header() on it:
> 
> => '=?utf-8?b?IkrDtnJnIE7DuHJnZW5zIiA8am9lcmdAbm93aGVyZT4=?='
> 
> Still nothing like <...> in it and my MTA is unhappy again. What am I 
> missing? Doesn't anyone know how mail clients handle that encoding?


 >>> address = u'"Jörg Nørgens" <[EMAIL PROTECTED]>'.encode('latin-1')
 >>> address
'"J\xf6rg N\xf8rgens" <[EMAIL PROTECTED]>'
 >>> from email.Header import Header
 >>> hdr = str(Header(address, 'latin-1'))
 >>> hdr
'=?iso-8859-1?q?=22J=F6rg_N=F8rgens=22_=3Cjoerg=40nowhere=3E?='

Is this not correct?

At least roundtripping works:

 >>> from email.Header import decode_header
 >>> encoded, coding = decode_header(hdr)[0]
 >>> encoded, coding
('"J\xf6rg N\xf8rgens" <[EMAIL PROTECTED]>', 'iso-8859-1')
 >>> encoded.decode(coding)
u'"J\xf6rg N\xf8rgens" <[EMAIL PROTECTED]>'

And parsing the address works too.

 >>> from email.Utils import parseaddr
 >>> parseaddr(encoded.decode(coding))
(u'J\xf6rg N\xf8rgens', u'[EMAIL PROTECTED]')
 >>>

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: socket.error connection refused

2006-11-24 Thread Bjoern Schliessmann
Vania wrote:

> For anyone interested restarting windows fixed the connection
> problem.

Some nifty "firewall" software? 8)

Regards,


Björn

-- 
BOFH excuse #78:

Yes, yes, its called a design limitation

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


Re: Abelson and Python

2006-11-24 Thread Chris Mellon
On 11/23/06, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> markscottwright wrote:
> > Fredrik Lundh wrote:
> >> markscottwright wrote:
> >>
> >>  > If it were that easy, the PyPy guys would be done by now.
> >>
> >> if the PyPy guys had focused on writing a Python interpreter in Python,
> >> they'd been done by now.
> >>
> >> 
> >
> > Isn't that the point of PyPy?  It's what their mission statement says
> > (http://codespeak.net/pypy/dist/pypy/doc/architecture.html#mission-statement):
> >
> > "PyPy is an implementation of the Python programming language written
> > in Python itself, flexible and easy to experiment with."
> >
> > This is something that is amazingly easy to do in scheme, since the
> > language is so simple, but is typically pretty difficult to do in other
> > languages
> >
> > That said, I see now that the course we're talking about isn't the same
> > as the old 6.001 course, and presumably has different pedagogical goals.
> >
> There are a more than a few library functions in the Python code that
> are written in C in CPython.  Not only is PyPy trying to get the
> _entire_ Python system into Python, it is trying to do so in a
> friendly-to-translation-in-a-statically-typed-language way.
>
> Besides, if you can freely use "eval" and "exec", how hard is a pure
> python language interpreter?
>

It's pretty trivial, and thats why I've always been unimpressed by
"implemente a  language interpreter in  lines" type statements.
It's a cute toy but what's the real learning  opportunity there?

Now, writing a compiler/interpreter from the ground up is a more
valuable experience, but does it really matter if the language is the
same one you wrote the compiler in? It gets harder the more
complicated the syntax and semantics of the language are, but, say,
python 1.0 would probably be a suitable goal for coursework.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NFS server

2006-11-24 Thread Diez B. Roggisch
srj wrote:

> i wish to develop an NFS server usin python from scratch( some wise guy
> told me i'ts easy!).
> can i get any kinda tutorial for this??
> 
> any suggestions on how 2 begin?

Ask the wise guy. All others install an NFS server.

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


How do I access a main frunction from an import module?

2006-11-24 Thread Jim
Hi,

I have created an import module.  And would like to access a function
from the main script, e.g.,

file abc.py:
###
def a():
m()
return None


file main.py:
#
from abc import *
def m():
print 'something'
return None

a()
##

python25.exe main.py

Thanks,
Jim

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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread robert
Jim wrote:
> Hi,
> 
> I have created an import module.  And would like to access a function
> from the main script, e.g.,
> 
> file abc.py:
> ###
> def a():
> m()
> return None
> 
> 
> file main.py:
> #
> from abc import *
> def m():
> print 'something'
> return None
> 
> a()
> ##
> 
> python25.exe main.py
> 

import __main__
...
__main__.m()


but better make a start.py and "import main" - then its symmetric


Robert


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


Re: Pimping the 'cgi' module

2006-11-24 Thread Fredrik Lundh
Christoph Haas wrote:

>> well, note, for that they have named it Ruby-On-Rails, so its still the
>> language - leveraged. While it is Zope/Django/Ego-on-Python ... ?
>
> If by that you mean that neither Zope nor Django are exactly pythonic I
> think I concur.

Django is highly Pythonic (it's pure Python plus templates, and has the same
"pencil-like qualities" as Python itself).  Zope 3 is highly Pythonic too, but a
rather more advanced form of Python.  but they're both application servers,
not CGI scripting environments.

>> First need of course: an update of that cgi "module".
>
> Oh, yeah. I just joined the Web SIG and found out that WSGI seems the way
> to go. At a first look it seems horrible if you just want to provide a CGI
> module.

WSGI is a CGI replacement, not a CGI implementation.  Which is a good thing,
because what really matters, if you think about what a web server is doing, is 
the
HTTP protocol, not an old and not always practical httpd extension standard.
WSGI simply provides plumbing for working very close to the HTTP level.

(you can of course create a WSGI-compatible adapter for CGI in no time at
all, but that's not really the point of WSGI).

> Somehow I sadly feel I would just add another incomplete  framework to that
> pile.

as they say, if you don't understand history, you're bound to repeat it ;-)

> I'm especially unsure whether it's good or bad to create another "I'm sick
> of the standard library"-style module. I've just become a bit less
> confident to actually contribute something useful there. Overwhelming.

Building a "like cgi.py, but with more support for the kind of things people 
actually
need" library would be an excellent idea.  It's not clear from your posts that 
you
"get" what things like Django and Zope do, and how that's different from "CGI
programming", but if you have a deep understanding of the latter, I'm sure you
could come up with a nice "cgi2.py" library with relatively little effort.  Get 
to
work!

 



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


Re: Abelson and Python

2006-11-24 Thread Fredrik Lundh
Chris Mellon wrote;

> Now, writing a compiler/interpreter from the ground up is a more
> valuable experience, but does it really matter if the language is the
> same one you wrote the compiler in? It gets harder the more
> complicated the syntax and semantics of the language are, but, say,
> python 1.0 would probably be a suitable goal for coursework.

I'd pick mini-python plus basic classes:

http://hetland.org/python/mini-python.php

 



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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Carl Banks

Jim wrote:
> I have created an import module.  And would like to access a function
> from the main script, e.g.,
>
> file abc.py:
> ###
> def a():
> m()
> return None
> 
>
> file main.py:
> #
> from abc import *
> def m():
> print 'something'
> return None
>
> a()
> ##


You can do it with "from __main__ import m" atop abc.py (the module
invoked at the command line is always called __main__).

However, I *highly* suggest you put m in another file.  Importing
variables from __main__ would make your program incompatible with many
useful tools.  For example, if you invoke the Python profiler on your
code, like this:

python -m profile main.py

it will break your code, because __main__ no longer refers to main.py
but to profile.py (from the Python library).  Importing from __main__
adversely affects tools such as PyChecker and PyLint.

The exception to this would be if abc.py is specifically designed as a
utility for interactive use; then it would be ok and useful.


Carl Banks

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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Anton Vredegoor
Jim wrote:

> I have created an import module.  And would like to access a function
> from the main script, e.g.,
> 
> file abc.py:
> ###
> def a():
> m()
> return None
> 
> 
> file main.py:
> #
> from abc import *
> def m():
> print 'something'
> return None
> 
> a()

import sys
def a():
 sys.modules['__main__'].m()
 return None

Anton

'now why would anyone want to do *that* ?'


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


Re: Active State and Komodo...

2006-11-24 Thread BartlebyScrivener
Steve Thompson wrote:
>
> I was wondering the differnced there were betwee Active State's python and
> the open source version of python.

The biggest difference at the moment is that ActiveState is still using
Python 2.4.3 in their distribution. They should be coming out with 2.5
soon.

Sounds like you are running Suse?  So you already have some version of
Python, right? You can search this group at comp.lang.python on Google
Groups--try "python versions linux"--or something like that--but the
issue you need to watch out for is running two different versions on
Linux.

Long and short, you don't want to uninstall the version of Python that
came with your Suse, because other programs on your machine probably
use that particular version. It's easy to install an ADDITIONAL
distribution of Python and run it separately, but again. Search the
list
for how to do that, and how to run them separately once you do.

I'm just moving to Linux myself, so can't provide the expertise. Unless
there is some killer feature of 2.5 you need, I would just use the
Python that came with your Suse.

rd

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


Re: Local variables persist in functions?

2006-11-24 Thread 120psi

> http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

Thanks for the link.  I think I'll stick to None as the default value,
as that's a good way to keep the usability and make my code work ;)

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


Re: Pimping the 'cgi' module

2006-11-24 Thread Thomas Guettler
Christoph Haas wrote:
...
> Oh, yeah. I just joined the Web SIG and found out that WSGI
> seems the way
> to go.
...

I don't want a standard, i want *one* implementation. In the
Java world, there are a lot of standards and N*standards 
implementations. In the end you have the opposite of what
a standard should give you: Bad interopability.

One implemantation (which is in the standard library) would
be the right coice. But what could I do? (I am not a python
core developer)? I could only create a new web framework.
And that's why there are so many.

I hope Guido (or someone else who can do this) will decide to choose one
soon. 


 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: Local variables persist in functions?

2006-11-24 Thread 120psi

John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > I'm a bit baffled.  Here is a bit of fairly straightforward code:
> >
> > def _chunkify( l, chunkSize, _curList = list() ):
>
> Quite apart from the default argument problem, which Duncan has
> addressed, you have some problems with style and variable names. In
> particular: give variables meaningful names ; "L".lower() is not
> meaningful and also suffers from confusion with the digit 1 in some
> fonts. There is no necessity for the _ in _curList in the above line.
>
> Please consider reading http://www.python.org/dev/peps/pep-0008/
>
> > print _curList   # yay for printf debugging
> > if len( l ) <= chunkSize:
> > _curList.append( l )
> > else:
> > newChunk = l[:chunkSize]
> > _curList.append( newChunk )
> > _chunkify( l[chunkSize:], chunkSize, _curList )
> > return _curList
> >
> > _chunkify simply breaks a sequence into a sequence of smaller lists of
> > size <= chunkSize.  The first call works fine, but if I call it
> > multiple times, weirdness happens.
> >
> > chunks = _chunkify( list, size )   # _curList keeps its previous value!
> > chunks = _chunkify( list, size, list() )# this works as expected
>
> Is the first "list" a list, or is it the name of the same function that
> you are calling to provide the 3rd argument?
>
> [snip]
>
> HTH,
> John

> Please consider reading http://www.python.org/dev/peps/pep-0008/
Done.  Veru useful, thank you.  Even though it's not the most correct
way or using the leading _, I was using it to sort of say 'don't set
this when calling', and yes--"L" is a bad name for a list, and I
probably should have used something else (even if this code is more of
a one-off than anything else).

Anyhow, thanks.

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


Re: fast listdir & stat

2006-11-24 Thread [EMAIL PROTECTED]

robert wrote:
> I want to get the files and sizes and times etc. stats of a dir fast.
> os.listdir & iterating with os.stat seems not to run at optimal speed for 
> network folders. Is there a faster possibility? (both for Win & *nix ; best 
> platform independent)
>
>
> Robert

An alternative is to work with os.walk() it returns a generator  - see
http://docs.python.org/lib/lib.html, and os.path.getsize(),
os.path.gettmtime() - see http://docs.python.org/lib/module-os.path.html

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


Re: Python work in UK

2006-11-24 Thread Steven Wayne
On Thu, 23 Nov 2006 19:28:26 +, Will McGugan
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'd love to work in Python, for the sake of my blood pressure, but there 
> doesnt seem to be that many jobs that look for Python as the main skill. 
> I use Python at work from time to time, and occasionaly get to spend 
> several days on a Python project but the majority of the time I use C++. 
> How can I make that leap to working with Python? There doesn't seem to 
> be many UK positions on the jobs section of Python.org or the usual jobs 
> sites. Any recommended jobs sites or tips? (I have googled)
>
> In the off chance that a potential empolyer is reading this, I'm looking 
> for something in web development, applications, graphics or other 
> interesting field. Here is a copy of my CV.
>
> http://www.willmcgugan.com/cvwillmcgugan.pdf
>
> Regards,
>
> Will McGugan

www.riverhall.co.uk are looking.

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


Re: Active State and Komodo...

2006-11-24 Thread Steve Thompson
On Fri, 24 Nov 2006 06:35:21 -0500, Steve Thompson wrote:

> Hello all,
> 
> I was wondering the differnced there were betwee Active State's python and
> the open source version of python. Would I have to unistall my opend souce
> python? Additonally, how does Active State's Komodo IDE vs. the eric3 IDE
> unler SuSE Linux v. 10.i?
> 
> Addionally, is the eric IDE (version 3) an acceptible IDE or are there
> more easy and more productive IDE's for perl?
> 
> I'm urining Gnome v. 12.2.2 and Eric v 3.8.1
> 
> Thanks Steve

Sorry, it was too early in the morning when I wrote this. The last 2
paragraphs should read "Addionally, is the eric IDE (version 3) an acceptible 
IDE or are there
more easy and more productive IDE's for python?".

"I'm using Gnome v. 12.2.2 and Eric v 3.8.1"

Thanks again,

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


Re: fast listdir & stat

2006-11-24 Thread robert
[EMAIL PROTECTED] wrote:
> robert wrote:
>> I want to get the files and sizes and times etc. stats of a dir fast.
>> os.listdir & iterating with os.stat seems not to run at optimal speed for 
>> network folders. Is there a faster possibility? (both for Win & *nix ; best 
>> platform independent)
>>
> 
> An alternative is to work with os.walk() it returns a generator  - see
> http://docs.python.org/lib/lib.html, and os.path.getsize(),
> os.path.gettmtime() - see http://docs.python.org/lib/module-os.path.html

would be even slower - 2 or 3 (network) calls for each file. os.walk just uses 
listdir. 

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


synching with os.walk()

2006-11-24 Thread Andre Meyer

Hi all

os.walk() is a nice generator for performing actions on all files in a
directory and subdirectories. However, how can one use os.walk() for walking
through two hierarchies at once? I want to synchronise two directories (just
backup for now), but cannot see how I can traverse a second one. I do this
now with os.listdir() recursively, which works fine, but I am afraid that
recursion can become inefficient for large hierarchies.

thanks for your help
André
-- 
http://mail.python.org/mailman/listinfo/python-list

ANNOUNCE: WSGI XSS Prevention Middleware

2006-11-24 Thread [EMAIL PROTECTED]
Hi,

I've just written a python WSGI middleware class to mitigate
XSS flaws, it's released under the python license. I've
attached the docs below.

Cheers

Rich.

WSGI Middleware class that prevents cross-site scripting flaws
in WSGI applications being exploited. Potentially malicious GET
and POST variables are checked for, and if found, a 403
Forbidden response is sent to the client.

Note that this class can false positive on input such as XML
or passwords containing the '<' character, so it is not useful
in all contexts. In addition, you should note that this
middleware is not a replacement for properly validating
input and quoting output.

This class can be downloaded from:
http://www.westpoint.ltd.uk/dist/wsgisecurity.zip

Author: Richard Moore, [EMAIL PROTECTED]
Copyright: (c) 2006 Westpoint Ltd
License: Released under the Python License
Version: 1.0

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


Re: Active State and Komodo...

2006-11-24 Thread Steve Thompson
On Fri, 24 Nov 2006 07:09:36 -0800, BartlebyScrivener wrote:

> Steve Thompson wrote:
>>
>> I was wondering the differnced there were betwee Active State's python and
>> the open source version of python.
> 
> The biggest difference at the moment is that ActiveState is still using
> Python 2.4.3 in their distribution. They should be coming out with 2.5
> soon.
> 
> Sounds like you are running Suse?  So you already have some version of
> Python, right? You can search this group at comp.lang.python on Google
> Groups--try "python versions linux"--or something like that--but the
> issue you need to watch out for is running two different versions on
> Linux.
> 
> Long and short, you don't want to uninstall the version of Python that
> came with your Suse, because other programs on your machine probably
> use that particular version. It's easy to install an ADDITIONAL
> distribution of Python and run it separately, but again. Search the
> list
> for how to do that, and how to run them separately once you do.
> 
> I'm just moving to Linux myself, so can't provide the expertise. Unless
> there is some killer feature of 2.5 you need, I would just use the
> Python that came with your Suse.
> 
> rd

Thanks BartlebyScrivener, but are there any other IDE's that are better,
in your opinion, than Eric version 3. I'm using gnome and eric is built
for KDE. I don't care it there open source or Id I have tp puchase one.

Thanks again,

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


pexpect problems

2006-11-24 Thread flynnguy
I am trying to essentially fork a rsync process from my python script
and I am having some issues with the forking part. My program basically
checks to see if I need to transfer a file and if it does, it calls the
transferItem() function below:

def transferItem(filelist):
hostname, passwd, transdir, filepath =  filelist
command = "nice -n +19 %s --partial --bwlimit=\"%d\" \"%s\" %s:%s"
% (COMMAND_TO_CHECK, BANDWIDTH_LIMIT, filepath, hostname, transdir)
p = pexpect.spawn(command)
try:
ret = p.expect(["(yes/no)", "Password:"])
if ret == 0:
p.sendline("yes")
p.expect("Password:")
p.sendline(passwd)
p.expect(pexpect.EOF, timeout=999)
except:
print 'problem transferring file'

Now this seems to partially work (it transfers the file) but I have a
few issues I'm hoping someone can help me with. First there is the
timeout issue. Without the timeout=999 parameter, the default timeout
is 30 seconds. I'd rather not have any timeout because the files I need
to transfer can be quite large and may take several days in some cases.
I tried p.close(wait=False) but that creates a defunct process and
doesn't seem to transfer any of the file. I can also say p.interact()
which won't timeout on me but it also doesn't fork into the background.


I thought the best solution would be to use the p.interact() and fork
the process but I can't seem to get that working. Anyone have any ideas
or suggestions that might help me?

Also just as a background in case it helps, I am currently writing a
pickled object (List of list) to a file using a web frontend (using
django) and then I have a monitor script which first checks if it
should transfer a file (based on how many transfers are currently
running) and then opens the pickled object and pop's off the first item
and sends that as input to the above function which I'm hoping will
start the rsync and then keep on chugging. I'd really appreciate any
help anyone could offer.
-Chris

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


Re: Pimping the 'cgi' module

2006-11-24 Thread robert
Christoph Haas wrote:
> On Friday 24 November 2006 13:08, robert wrote:
>> well, note, for that they have named it Ruby-On-Rails, so its still the
>> language - leveraged. While it is Zope/Django/Ego-on-Python ... ?
> 
> If by that you mean that neither Zope nor Django are exactly pythonic I 
> think I concur.

on-python, but not python-on :-) - as we discussed about "framework vs. 
directness/intuition"
Zope and Django's Ego certainly won't fit into/near the stdlib

>> Unless a Guido'ed version of such thing is not _selected_ into the
>> stdlib or at least promoted single-mindedly and prominently by far
>> before high-tech-but-low-number names like Zope and Django, Python will
>> continue to bleed out heavily on numbers vs. Ruby.
> 
> Guido seems to have been confused about the rank growth of web based 
> frameworks himself. So it's even less likely one of them gets included as 
> part of the standard library in finite time.

Yet so he will decide about the magnitude of order of future Python users. I'm 
sure the door will open once ..
Py3K will not make as big a change regarding this magnitude. 

>> First need of course: an update of that cgi "module".
> 
> Oh, yeah. I just joined the Web SIG and found out that WSGI seems the way 
> to go. At a first look it seems horrible if you just want to provide a CGI 
> module. But there must be some reason for its existence. :) Looking 
> further through http://wiki.python.org/moin/WebFrameworks my head starts 
> to spin. Somehow I sadly feel I would just add another incomplete 
> framework to that pile.
> 
> I'm especially unsure whether it's good or bad to create another "I'm sick 
> of the standard library"-style module. I've just become a bit less 
> confident to actually contribute something useful there. Overwhelming.

tying selected techniques together on the right level is the task. Its not 
forbidden to learn a little from Rails and Perl module structure.

>> python-dev is fully occupied with top-notch inner life. Of course that
>> is the basis. But key issues in lib&tools were simply forgotten - left
>> to a random community.
> 
> Which doesn't match the "batteries included" fuss at all. Of course the 
> basis has to be good, too. And there are so many paradigms today that no 
> core-python developer can really be expected to provide good standard 
> modules for everyone.
> 
>> Go for a start. In order to realize that essential batteries in good
>> quality within time - even after 10 years now - it is necessary, to hook
>> python-dev for even requesting it actively. Just adding to
>> http://wiki.python.org/moin/WebProgramming and
>> http://wiki.python.org/moin/WebFrameworks is not the task. It requires
>> some organization and somewhat a selection process in addition to good
>> (probably existing) code v0.1xxx material. I think it would not be
>> overly complex. Both, a new cgi and possibly included snake "rails" (vs
>> "oil")
> 
> Oil is deprecated anyway. :) I'll see if I can find my way into the SIG. 
> And - yes - adding another framework will surely not help us out of the 
> divergence. The more frameworks there are the more people seem to feel 
> urged to say "heck, it will be easier to write my own framework than 
> evaluate all 30 packages on that page".
> 
>  Christoph
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: synching with os.walk()

2006-11-24 Thread 120psi
> os.walk() is a nice generator for performing actions on all files in a
> directory and subdirectories. However, how can one use os.walk() for walking
> through two hierarchies at once? I want to synchronise two directories (just
> backup for now), but cannot see how I can traverse a second one. I do this
> now with os.listdir() recursively, which works fine, but I am afraid that
> recursion can become inefficient for large hierarchies.

I've run into wanting to work with parallel directory structures
before, and what I generally do is something like:

for root, dirs, files in os.walk( dir1 ):
  dir2_root = dir2 + root[len(dir1):]
  for f in files:
dir1_path = os.path.join( root, f )
dir2_path = os.path.join( dir2_root, f )

Does this work for your needs?
-- Nils

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


Re: Newbie Developing a Python Extension

2006-11-24 Thread Carl Banks

Jeremy wrote:
> Hi,
>
> I have been working on Linux 2.6.9 to adapt a C++ module to work as a Python
> extension with the following setup.py file:
>
> from distutils.core import setup, Extension
>
> sm=Extension(
>  'tdma',
>  define_macros=[('__USE_POSIX199309','1')],
>  include_dirs=['/usr/include','/usr/include/python2.3'],
>  library_dirs=['/usr/lib'],
>  sources=['Bitstrea.cpp','bytequeu.cpp','debug.cpp','dlist.cpp',
>   'GrPort.cpp','IoPort.cpp','LMEmu.cpp','LMEmuPdu.cpp',
>   'MacPyIf.cpp','per_os_clk.cpp','timer.cpp'])
>
> setup(name='MySm',
>  version='0.1.0',
>  description='TDMA MAC',
>  ext_modules=[sm])
>
> The extension uses the POSIX call clock_gettime() and things seem fine when
> generating the tdma.so file. However, when running the Python program, at a
> line 'from tdma import init,txdn,txup,...', I get an error message saying
> 'ImportError: /home/.../tdma.so: undefined symbol: clock_gettime'.

You're missing a library.  From the clock_gettime man page:

NOTE
   Most  systems  require  the program be linked with the librt
library to
   use these functions.

So you need to build the extention with librt.  Try adding a 'libraries
= ['rt']' option to the extension definition.  (Unfortunately, on
Linux, builduing a shared object without specifying libraries needed
passes silently.  It'd be nice if there was an option to require all
undefined non-Python symbols to be accounted for by some library, but
that would be a lot of work to implement.)


Carl Banks

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


Re: Pimping the 'cgi' module

2006-11-24 Thread robert
Thomas Guettler wrote:
> Christoph Haas wrote:
> ...
>> Oh, yeah. I just joined the Web SIG and found out that WSGI
>> seems the way
>> to go.
> ...
> 
> I don't want a standard, i want *one* implementation. In the
> Java world, there are a lot of standards and N*standards 
> implementations. In the end you have the opposite of what
> a standard should give you: Bad interopability.
>
> One implemantation (which is in the standard library) would
> be the right coice. But what could I do? (I am not a python
> core developer)? I could only create a new web framework.
> And that's why there are so many.
> 
> I hope Guido (or someone else who can do this) will decide to choose one
> soon. 

yes. this talking about formation of somewhat a standardization gremium within 
some years etc. is not the task.
There is enough base material. There are guys who have an overview of what is 
good. There are guys who know the details.
A decision call from the inner circle for an actual (probably joint) 
implementation is necessary.

Regarding the python-on..-"framework" the greatest danger would be, to make it 
too big. ( its not about full replacement of the existing big packages )

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


Re: synching with os.walk()

2006-11-24 Thread Paddy

Andre Meyer wrote:

> Hi all
>
> os.walk() is a nice generator for performing actions on all files in a
> directory and subdirectories. However, how can one use os.walk() for walking
> through two hierarchies at once? I want to synchronise two directories (just
> backup for now), but cannot see how I can traverse a second one. I do this
> now with os.listdir() recursively, which works fine, but I am afraid that
> recursion can become inefficient for large hierarchies.
>
> thanks for your help
> André

Walk each tree individually gathering file names relative to the head
of the tree and modification data.

compare the two sets of data to generate:
 1. A list of what needs to be copied from the original to the copy.
 2. A list of what needs to be copied from the copy to the original

Do the copying.

|You might want to show the user what needs to be done and give them
the option of aborting after generating the copy lists.

- Paddy.

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


Invoking Python from Cygwin problem.

2006-11-24 Thread Ant
Hi all,

Using cygwin and Python 2.5, I have the following scripts, one bash
script and the other a python script:
---
#!/bin/bash

TEST_VAR=`./test.py`
TEST_VAR2=Test2

echo "Test var: $TEST_VAR OK"
echo "Test var2: $TEST_VAR2 OK"

--
#!/usr/bin/python
print "Testing",

Running the bash script, I get the following output:

OKt var: Testing
Test var2: Test2 OK

Does anyone have any idea why the script would mess up the first echo?
Are there some kind of control characters being appended to the python
output in Windows? Looks like a CR character, but why?

Cheers,

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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Bjoern Schliessmann
Jim wrote:

> I have created an import module.  And would like to access a
> function from the main script, e.g.,

May I ask why? This style violates "normal" module philosophy.

Regards,


Björn

-- 
BOFH excuse #307:

emissions from GSM-phones

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


Re: NFS server

2006-11-24 Thread Bjoern Schliessmann
srj wrote:

> i wish to develop an NFS server usin python from scratch( some
> wise guy told me i'ts easy!).

That wise guy must be very wise, or stupid 8)

> can i get any kinda tutorial for this??
> 
> any suggestions on how 2 begin?

- Read RFCs about NFS
- Read the Python tutorial
- If you want it even easier, read the Twisted tutorial additionally

Regards,


Björn

-- 
BOFH excuse #279:

The static electricity routing is acting up...

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


Re: synching with os.walk()

2006-11-24 Thread Paddy

Paddy wrote:

> Andre Meyer wrote:
>
> > Hi all
> >
> > os.walk() is a nice generator for performing actions on all files in a
> > directory and subdirectories. However, how can one use os.walk() for walking
> > through two hierarchies at once? I want to synchronise two directories (just
> > backup for now), but cannot see how I can traverse a second one. I do this
> > now with os.listdir() recursively, which works fine, but I am afraid that
> > recursion can become inefficient for large hierarchies.
> >
> > thanks for your help
> > André
>
> Walk each tree individually gathering file names relative to the head
> of the tree and modification data.
>
> compare the two sets of data to generate:
>  1. A list of what needs to be copied from the original to the copy.
>  2. A list of what needs to be copied from the copy to the original
>
> Do the copying.
>
> |You might want to show the user what needs to be done and give them
> the option of aborting after generating the copy lists.
>
> - Paddy.
P.S. If you are on a Unix type system you can use tar to do the copying
as you can easily compress the data if it needs to go over a sow link,
and tar will take care of creating any needed directories in the
destination if you create new directories as well as new files.
- Paddy.

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


Re: reading id3 tags with python

2006-11-24 Thread jeff
well, heres the error::
##
Traceback (most recent call last):
  File "./main.py", line 28, in ?
info = id3.Reader(file)
  File "/home/jeffrey/Documents/Music/.rename/id3reader.py", line 187,
in __init__
self._readId3()
  File "/home/jeffrey/Documents/Music/.rename/id3reader.py", line 306,
in _readId3
self._interpretFlags()
  File "/home/jeffrey/Documents/Music/.rename/id3reader.py", line 341,
in _interpretFlags
self._readExtHeader = _readExtHeader_rev3
NameError: global name '_readExtHeader_rev3' is not defined

also, i didnt account for Y/N/Yes/No, whatever because this script is
just for myself (also why i didnt use that function to join pathnames,
i oonly realy use linux anymore)

and what do you mean by 'id3reader' cant do directories? my for loop
just does each file in the dirextory

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


Re: Pimping the 'cgi' module

2006-11-24 Thread robert
Fredrik Lundh wrote:
> Christoph Haas wrote:
> 
>>> well, note, for that they have named it Ruby-On-Rails, so its still the
>>> language - leveraged. While it is Zope/Django/Ego-on-Python ... ?
>> If by that you mean that neither Zope nor Django are exactly pythonic I
>> think I concur.
> 
> Django is highly Pythonic (it's pure Python plus templates, and has the same
> "pencil-like qualities" as Python itself).  Zope 3 is highly Pythonic too, 
> but a
> rather more advanced form of Python.  but they're both application servers,
> not CGI scripting environments.

pythonic yes, but ..-on-python

>>> First need of course: an update of that cgi "module".
>> Oh, yeah. I just joined the Web SIG and found out that WSGI seems the way
>> to go. At a first look it seems horrible if you just want to provide a CGI
>> module.
> 
> WSGI is a CGI replacement, not a CGI implementation.  Which is a good thing,
> because what really matters, if you think about what a web server is doing, 
> is the
> HTTP protocol, not an old and not always practical httpd extension standard.
> WSGI simply provides plumbing for working very close to the HTTP level.
> 
> (you can of course create a WSGI-compatible adapter for CGI in no time at
> all, but that's not really the point of WSGI).

its a low level tech basis. Regarding the discussion here, its also the enabler 
for the confusion :-)

>> Somehow I sadly feel I would just add another incomplete  framework to that
>> pile.
> 
> as they say, if you don't understand history, you're bound to repeat it ;-)

we are currently bound to repeat 30+ histories. no wonder - nobody will ever 
understand it and go to Rails & Co.

>> I'm especially unsure whether it's good or bad to create another "I'm sick
>> of the standard library"-style module. I've just become a bit less
>> confident to actually contribute something useful there. Overwhelming.
> 
> Building a "like cgi.py, but with more support for the kind of things people 
> actually
> need" library would be an excellent idea.  It's not clear from your posts 
> that you
> "get" what things like Django and Zope do, and how that's different from "CGI
> programming", but if you have a deep understanding of the latter, I'm sure you
> could come up with a nice "cgi2.py" library with relatively little effort.  
> Get to
> work!

think both are missing standard modules: cgi2 and a comfortable 
OO-dispatcher/server with clear tutorials. And to have them in front on the 
Python display window.


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


Re: synching with os.walk()

2006-11-24 Thread Thomas Ploch

>> os.walk() is a nice generator for performing actions on all files in a
>> directory and subdirectories. However, how can one use os.walk() for walking
>> through two hierarchies at once? I want to synchronise two directories (just
>> backup for now), but cannot see how I can traverse a second one. I do this
>> now with os.listdir() recursively, which works fine, but I am afraid that
>> recursion can become inefficient for large hierarchies.
> 
> I've run into wanting to work with parallel directory structures
> before, and what I generally do is something like:
> 
> for root, dirs, files in os.walk( dir1 ):
>   dir2_root = dir2 + root[len(dir1):]
>   for f in files:
> dir1_path = os.path.join( root, f )
> dir2_path = os.path.join( dir2_root, f )
> 

Wouldn't it be better to implement tree traversing into a class, then
you can traverse two directory trees at once and can do funny things
with it?

Thomas

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


Re: Active State and Komodo...

2006-11-24 Thread BartlebyScrivener
Steve Thompson wrote:
> On Fri, 24 Nov 2006 06:35:21 -0500, Steve Thompson wrote:
>
> > Addionally, is the eric IDE (version 3) an acceptible IDE or are there
> > more easy and more productive IDE's for perl?

Perl? You're on a Python list?  Anyway, the subject of IDEs comes up
every other day. If you want comparisons or discussion of Eric and
Python, search the group for "Eric IDE"

http://groups.google.com/group/comp.lang.python/search?q=eric+ide&start=0&scoring=d&;

If the link breaks, use:

http://tinyurl.com/yxy8vv

I use vim 7.0 and Komodo myself. Both are cross platform. You'll see
hundreds of different opinions here.

rd

"A couple of months in the laboratory can save a couple of hours in the
library."

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


Re: Local variables persist in functions?

2006-11-24 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm a bit baffled.  Here is a bit of fairly straightforward code:
>
> def _chunkify( l, chunkSize, _curList = list() ):
>print _curList   # yay for printf debugging

Check out Winpdb at http://www.digitalpeers.com/pythondebugger/.

-- Paul


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


Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

That sounds like a good approach.

On 24 Nov 2006 08:27:09 -0800, Paddy <[EMAIL PROTECTED]> wrote:



Andre Meyer wrote:

> Hi all
>
> os.walk() is a nice generator for performing actions on all files in a
> directory and subdirectories. However, how can one use os.walk() for
walking
> through two hierarchies at once? I want to synchronise two directories
(just
> backup for now), but cannot see how I can traverse a second one. I do
this
> now with os.listdir() recursively, which works fine, but I am afraid
that
> recursion can become inefficient for large hierarchies.
>
> thanks for your help
> André

Walk each tree individually gathering file names relative to the head
of the tree and modification data.

compare the two sets of data to generate:
1. A list of what needs to be copied from the original to the copy.
2. A list of what needs to be copied from the copy to the original

Do the copying.

|You might want to show the user what needs to be done and give them
the option of aborting after generating the copy lists.

- Paddy.

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

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

Re: Python popenX() slowness on AIX?

2006-11-24 Thread allenjo5
Stefaan A Eeckels wrote:
> On 21 Nov 2006 13:02:14 -0800
> [EMAIL PROTECTED] wrote:
>
> > The fact that it does this in Python code instead of C is the main
> > cause of the slowness.  So, unless Python is changed to do this in C,
> > it's always going to be slow on AIX :-(
>
> I guess that the reason it's slow is that there are many descriptors to
> try and close. Reducing them using ulimit -n could improve the speed.
>
> AIX has a fcntl command to close all open file descriptors from a
> descriptor onwards:
>
> fcntl(3, F_CLOSEM);
>
> This of course should be used instead of the loop:
>
> import sys
> import fcntl
>
> __all__ = ["popen2", "popen3", "popen4"]
>
> ...
>
> def _run_child(self, cmd):
> if isinstance(cmd, basestring):
> cmd = ['/bin/sh', '-c', cmd]
> try:
> os.fcntl(3, 10, 0)
> except OSError:
> pass
> try:
> os.execvp(cmd[0], cmd)
> finally:
> os._exit(1)
>
> 10 happens to be the value of F_CLOSEM (from /usr/include/fcntl.h).
> I've currently no access to an AIX system with Python, but it could be
> worth trying.

Yes, very much worth it.  F_CLOSEM is _so_ much better than the loop,
even in C.   Using your brilliant suggestion, I now have a simple patch
to the python source that implements it for any OS that happens to have
the fcntl F_CLOSEM option.   It is below in its entirety.  I believe I
got the try: stuff correct, but since I'm new to Python, I'd appreciate
any comments.

I have another patch to implement my os.rclose(x,y) method, which would
improve the speed of popenX() for the OSes that don't have F_CLOSEM, by
doing the close() loop in C instead of Python,  but I don't know if it
would be as likely to be accepted as this probably would be.

Now, where do I send my proposed patch for consideration?

John.

--- ./Modules/fcntlmodule.c.origThu Jun  3 08:47:26 2004
+++ ./Modules/fcntlmodule.c Fri Nov 24 11:18:23 2006
@@ -545,6 +545,11 @@
 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1;
 #endif

+/* For systems like AIX that have F_CLOSEM to close multiple fds */
+#ifdef F_CLOSEM
+if (ins(d, "F_CLOSEM", (long)F_CLOSEM)) return -1;
+#endif
+
 #ifdef HAVE_STROPTS_H
/* Unix 98 guarantees that these are in stropts.h. */
INS(I_PUSH);
--- ./Lib/popen2.py.origThu Feb 10 08:46:14 2005
+++ ./Lib/popen2.py Fri Nov 24 11:37:15 2006
@@ -8,6 +8,7 @@

 import os
 import sys
+import fcntl

 __all__ = ["popen2", "popen3", "popen4"]

@@ -65,11 +66,18 @@
 def _run_child(self, cmd):
 if isinstance(cmd, basestring):
 cmd = ['/bin/sh', '-c', cmd]
-for i in range(3, MAXFD):
-try:
-os.close(i)
-except OSError:
-pass
+   try:
+   if fcntl.F_CLOSEM:
+   try:
+   fcntl.fcntl(3, fcntl.F_CLOSEM, 0)
+   except OSError:
+   pass
+   except AttributeError:
+   for i in range(3, MAXFD):
+   try:
+   os.close(i)
+   except OSError:
+   pass
 try:
 os.execvp(cmd[0], cmd)
 finally:

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


Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

What I forgot to mention is that I want this to run unmodified from both
Windows and Linux (and Mac). Otherwise, there are enough options to choose
from, besides developing it myself, I guess.

On 24 Nov 2006 08:37:13 -0800, Paddy <[EMAIL PROTECTED]> wrote:



Paddy wrote:

> Andre Meyer wrote:
>
> > Hi all
> >
> > os.walk() is a nice generator for performing actions on all files in a
> > directory and subdirectories. However, how can one use os.walk() for
walking
> > through two hierarchies at once? I want to synchronise two directories
(just
> > backup for now), but cannot see how I can traverse a second one. I do
this
> > now with os.listdir() recursively, which works fine, but I am afraid
that
> > recursion can become inefficient for large hierarchies.
> >
> > thanks for your help
> > André
>
> Walk each tree individually gathering file names relative to the head
> of the tree and modification data.
>
> compare the two sets of data to generate:
>  1. A list of what needs to be copied from the original to the copy.
>  2. A list of what needs to be copied from the copy to the original
>
> Do the copying.
>
> |You might want to show the user what needs to be done and give them
> the option of aborting after generating the copy lists.
>
> - Paddy.
P.S. If you are on a Unix type system you can use tar to do the copying
as you can easily compress the data if it needs to go over a sow link,
and tar will take care of creating any needed directories in the
destination if you create new directories as well as new files.
- Paddy.

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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: synching with os.walk()

2006-11-24 Thread Paddy

Paddy wrote:
> P.S. If you are on a Unix type system you can use tar to do the copying
> as you can easily compress the data if it needs to go over a sow link,

Sow links, transfers your data and then may form a tasty sandwich when
cooked.

(The original should, of course, read ...slow...)
- Pad.

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


Re: synching with os.walk()

2006-11-24 Thread Andre Meyer

Cool, this seems to work.

thanks!


On 24 Nov 2006 08:12:08 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


> os.walk() is a nice generator for performing actions on all files in a
> directory and subdirectories. However, how can one use os.walk() for
walking
> through two hierarchies at once? I want to synchronise two directories
(just
> backup for now), but cannot see how I can traverse a second one. I do
this
> now with os.listdir() recursively, which works fine, but I am afraid
that
> recursion can become inefficient for large hierarchies.

I've run into wanting to work with parallel directory structures
before, and what I generally do is something like:

for root, dirs, files in os.walk( dir1 ):
  dir2_root = dir2 + root[len(dir1):]
  for f in files:
dir1_path = os.path.join( root, f )
dir2_path = os.path.join( dir2_root, f )

Does this work for your needs?
-- Nils

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





--
Dr. Andre P. Meyerhttp://python.openspace.nl/meyer
TNO Defence, Security and Safety  http://www.tno.nl/
Delft Cooperation on Intelligent Systems  http://www.decis.nl/

Ah, this is obviously some strange usage of the word 'safe' that I wasn't
previously aware of. - Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Modules - Jython Vs Python?

2006-11-24 Thread Khalid Zuberi
Patrick Finnegan writes:

> 
> How many of the Python modules written in C have been rewritten and and
> ported to Java to run under Jython? I am talking about SMTP, LDAP,
> WIN2K,XML etc.  Is there a list anywhere ?
> 

There's a list on the jython wiki of absent modules:

  http://wiki.python.org/jython/AbsentModules

though i can't vouch for it being up to date.

- kz





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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Jim

Bjoern Schliessmann wrote:
> Jim wrote:
>
> > I have created an import module.  And would like to access a
> > function from the main script, e.g.,
>
> May I ask why? This style violates "normal" module philosophy.
>
> Regards,
>
>
> Björn
>
> --
> BOFH excuse #307:
>
> emissions from GSM-phones

Application abc is designed as a complete module.  The user is to
script their own functions to work with application abc.
 
Thanks,
JIm

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


Re: Active State and Komodo...

2006-11-24 Thread hg
Steve Thompson wrote:
> On Fri, 24 Nov 2006 07:09:36 -0800, BartlebyScrivener wrote:
> 
>> Steve Thompson wrote:
>>> I was wondering the differnced there were betwee Active State's python and
>>> the open source version of python.
>> The biggest difference at the moment is that ActiveState is still using
>> Python 2.4.3 in their distribution. They should be coming out with 2.5
>> soon.
>>
>> Sounds like you are running Suse?  So you already have some version of
>> Python, right? You can search this group at comp.lang.python on Google
>> Groups--try "python versions linux"--or something like that--but the
>> issue you need to watch out for is running two different versions on
>> Linux.
>>
>> Long and short, you don't want to uninstall the version of Python that
>> came with your Suse, because other programs on your machine probably
>> use that particular version. It's easy to install an ADDITIONAL
>> distribution of Python and run it separately, but again. Search the
>> list
>> for how to do that, and how to run them separately once you do.
>>
>> I'm just moving to Linux myself, so can't provide the expertise. Unless
>> there is some killer feature of 2.5 you need, I would just use the
>> Python that came with your Suse.
>>
>> rd
> 
> Thanks BartlebyScrivener, but are there any other IDE's that are better,
> in your opinion, than Eric version 3. I'm using gnome and eric is built
> for KDE. I don't care it there open source or Id I have tp puchase one.
> 
> Thanks again,
> 
> Steve
I like Eclipse/Pydev better

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


Pydev configuration

2006-11-24 Thread Sébastien Boisgérault
Hi,

Did anyone managed to change the code font family/size
in Pydev (Python Editor Plugin for Eclipse) ? I found how
to change the color mapping (Windows/Preference/Pydev)
but did not found the font setting.

Cheers,

SB

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


Re: Access to variable from external imported module

2006-11-24 Thread jim-on-linux






On Friday 24 November 2006 03:30, John Machin 
wrote:
> jim-on-linux wrote:
> > GinTon,
> >
> > I think this is what you want.
> >
> >
> > class Kdoi:
>
> Is that a typo?
   No, it's a style. life seems to be easier  
to me if one is consistent, all my classes begin 
with K.
>
> >def __init__(self) :
> >self.Fdo()
>
> What is all this K and F stuff?
>
   It's my style. life seems to be easier  to me 
if one is consistent all my function begin with 
F.

I started doing things like this when the only way 
to debug was to read each line of code and try to 
figgure out if it was the problem.
They are my personal sign posts. 
> >def Fdo(self):
> >

> >  searchterm = 'help'
> >  print searchterm #local
> >
> >  self.searchterm = searchterm
> >  print self.searchterm #used inside the
> > class
> >
> >  Kdo.searchterm = searchterm   #
> >  print Kdo.searchterm #used outside the
> > class Kdomore()
> >
> >
> >
> > class Kdomore(Kdo):
> >  def __init__(self) :
> >  self.Fdomore()
> >
> >  def Fdomore(self):
> >  searchterm =  Kdo.searchterm   #
> >  print searchterm
>
> It's not apparent what the print statements are
> for -- are they part of an attempt to debug
> your code?
>
print shows the results wherever a print statement 
turns up the results = 'help' .
I didn't run the code, and it has it has a coding 
error but if removed, the results should be; 

   searchterm = 'help'
   self.searchterm = 'help'
   Kdo.searchterm = 'help'

   Sound silly but many people have trouble with  
getting a variable from here to there in their 
code. This shows that it can be done

> What gives you the idea that this is what the
> OP wants or needs?

If I remember right,  he refrased  his first 
question and asked a second one. 
Sometimes people don't take the time to write 
correctly, the questions that are really in their 
mind. So I guessed.  If Im wrong, he will ignore 
it.  If I'm right, he will use it.  

Also, I have found that other will latch on to the 
ideas presented  in these email responses. And 
they will use them, even though the response was 
not exactly what the original emailer wanted.

And, I sometimes I do use print statements to 
debug, I have used other ways but on linux, I 
prefer a print statement.

jim-on-linux
http://www.inqvista.com 











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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread John Machin
Jim wrote:
> Hi,
>
> I have created an import module.  And would like to access a function
> from the main script, e.g.,
>
> file abc.py:
> ###
> def a():
> m()
> return None
> 
>
> file main.py:
> #
> from abc import *
> def m():
> print 'something'
> return None
>
> a()
> ##
>
> python25.exe main.py
>

Although there are literally correct answers to your question, the best
answer is "Don't do that. You would be creating circular references
between modules, and run the risk of emulating the mythical ooloo bird
by disappearing up your own fundamental orifice". Some possible
practical solutions:

1. Put the m function in a 3rd file/module. Then any other module which
needs it can import/call.

2. If you think that's not a good idea, then put it in abc.py (it's not
used in main.py in your example).

3. Maybe this will suit what you are really trying to do:

 file abc.py:
 ###
 def a(argfunc): # <=
 argfunc() # <=
 

 file main.py:
 #
 from abc import *
 def m():
 print 'something'

 a(m) # <=
 ##

4. If you think *that's* not a good idea, then you might like to
explain at a higher level what you are *really* trying to achieve :-)
E.g. "Function m is one of n functions in main.py of which abc.py
may/must call 0, 1, or many because blah blah blah ..."

BTW, "return None" at the very end of a function is redundant. The
Python compiler generates "return None" automagically (implicitly!?)
instead of letting you fall off the end of the world. Which book or
tutorial are you using?

BTW #2: "python25.exe main.py" ?? If you are on Windows, have Python
2.4 as your default setup, and are trialling 2.5: you may like to ask
(in a new thread) about more convenient ways of doing it. Otherwise you
might like to tell what you are up to (in a new thread) so that your
problem can be diagnosed correctly and cured :-)

HTH,
John

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


Re: Access to variable from external imported module

2006-11-24 Thread jim-on-linux
On Friday 24 November 2006 13:01, jim-on-linux 
wrote:
> On Friday 24 November 2006 03:30, John Machin
>
> wrote:
> > jim-on-linux wrote:
> > > GinTon,
> > >
> > > I think this is what you want.
> > >
> > >
> > > class Kdoi:
> >
> > Is that a typo?
>
>No, it's a style. life seems to be
> easier to me if one is consistent, all my
> classes begin with K.

Sorry, Kdoi should be Kod



>
> > >def __init__(self) :
> > >self.Fdo()
> >
> > What is all this K and F stuff?
>
>It's my style. life seems to be easier  to
> me if one is consistent all my function begin
> with F.
>
> I started doing things like this when the only
> way to debug was to read each line of code and
> try to figgure out if it was the problem.
> They are my personal sign posts.
>
> > >def Fdo(self):
> > >
> > >
> > >  searchterm = 'help'
> > >  print searchterm #local
> > >
> > >  self.searchterm = searchterm
> > >  print self.searchterm #used inside the
> > > class
> > >
> > >  Kdo.searchterm = searchterm   #
> > >  print Kdo.searchterm #used outside the
> > > class Kdomore()
the line above should be Kdomore(), not class 
Kdomore() (For the technocrats)
> > >
> > >
> > >
> > > class Kdomore(Kdo):
> > >  def __init__(self) :
> > >  self.Fdomore()
> > >
> > >  def Fdomore(self):
> > >  searchterm =  Kdo.searchterm   #
> > >  print searchterm
> >
> > It's not apparent what the print statements
> > are for -- are they part of an attempt to
> > debug your code?
>
> print shows the results wherever a print
> statement turns up the results = 'help' .
> I didn't run the code, and it has it has a
> coding error but if removed, the results should
> be;
>
>searchterm = 'help'
>self.searchterm = 'help'
>Kdo.searchterm = 'help'
>
>Sound silly but many people have trouble
> with getting a variable from here to there in
> their code. This shows that it can be done
>
> > What gives you the idea that this is what the
> > OP wants or needs?
>
> If I remember right,  he refrased  his first
> question and asked a second one.
> Sometimes people don't take the time to write
> correctly, the questions that are really in
> their mind. So I guessed.  If Im wrong, he will
> ignore it.  If I'm right, he will use it.
>
> Also, I have found that other will latch on to
> the ideas presented  in these email responses.
> And they will use them, even though the
> response was not exactly what the original
> emailer wanted.
>
> And, I sometimes I do use print statements to
> debug, I have used other ways but on linux, I
> prefer a print statement.
>
 jim-on-linux
 http://www.inqvista.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Fredrik Lundh
Jim wrote:

> Application abc is designed as a complete module.  The user is to
> script their own functions to work with application abc.

so use execfile() with a prepared namespace:

 namespace = { ...stuff to export to the module ... }
 execfile("directory/module.py", namespace)



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


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Jim
John Machin wrote:
> Jim wrote:
> > Hi,
> >
> > I have created an import module.  And would like to access a function
> > from the main script, e.g.,
> >
> > file abc.py:
> > ###
> > def a():
> > m()
> > return None
> > 
> >
> > file main.py:
> > #
> > from abc import *
> > def m():
> > print 'something'
> > return None
> >
> > a()
> > ##
> >
> > python25.exe main.py
> >
>
> Although there are literally correct answers to your question, the best
> answer is "Don't do that. You would be creating circular references
> between modules, and run the risk of emulating the mythical ooloo bird
> by disappearing up your own fundamental orifice". Some possible
> practical solutions:
>
> 1. Put the m function in a 3rd file/module. Then any other module which
> needs it can import/call.
>
> 2. If you think that's not a good idea, then put it in abc.py (it's not
> used in main.py in your example).
>
> 3. Maybe this will suit what you are really trying to do:
>
>  file abc.py:
>  ###
>  def a(argfunc): # <=
>  argfunc() # <=
>  
>
>  file main.py:
>  #
>  from abc import *
>  def m():
>  print 'something'
>
>  a(m) # <=
>  ##
>
> 4. If you think *that's* not a good idea, then you might like to
> explain at a higher level what you are *really* trying to achieve :-)
> E.g. "Function m is one of n functions in main.py of which abc.py
> may/must call 0, 1, or many because blah blah blah ..."
>
> BTW, "return None" at the very end of a function is redundant. The
> Python compiler generates "return None" automagically (implicitly!?)
> instead of letting you fall off the end of the world. Which book or
> tutorial are you using?
>
> BTW #2: "python25.exe main.py" ?? If you are on Windows, have Python
> 2.4 as your default setup, and are trialling 2.5: you may like to ask
> (in a new thread) about more convenient ways of doing it. Otherwise you
> might like to tell what you are up to (in a new thread) so that your
> problem can be diagnosed correctly and cured :-)
>
> HTH,
> John

BTW#1: I have most of the python books from O'Reilly.  I'm sure that
some of them say that its a good idea to use 'return None'.  However,
most their examples do not us it.  Anyway I find that its useful when
reading my own scripts.

BTW#2: I do not have Python 2.4 installed anymore.  Therefore, it is
not a trialling problem.

I thought that it would be NICE to keep the application and the user's
script separate from each other, being that python is so flexible.
However, there seems to be no end to the problems that occur by doing
this.  So I will abandon this exercise, since it appears not to be a
very good programming practise.

Thanks,
Jim

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


Re: Access to variable from external imported module

2006-11-24 Thread jim-on-linux
On Friday 24 November 2006 13:20, jim-on-linux 
wrote:
> On Friday 24 November 2006 13:01, jim-on-linux
>
> wrote:
> > On Friday 24 November 2006 03:30, John Machin
> >
> > wrote:
> > > jim-on-linux wrote:
> > > > GinTon,
> > > >
> > > > I think this is what you want.
> > > >
> > > >
> > > > class Kdoi:
> > >
> > > Is that a typo?
> >
> >No, it's a style. life seems to be
> > easier to me if one is consistent, all my
> > classes begin with K.
>
> Sorry, Kdoi should be Kod
Sorry again Kdoi should be Kdo 
(Haste makes waste.)
>
> > > >def __init__(self) :
> > > >self.Fdo()
> > >
> > > What is all this K and F stuff?
> >
> >It's my style. life seems to be easier  to
> > me if one is consistent all my function begin
> > with F.
> >
> > I started doing things like this when the
> > only way to debug was to read each line of
> > code and try to figgure out if it was the
> > problem. They are my personal sign posts.
> >
> > > >def Fdo(self):
> > > >
> > > >
> > > >  searchterm = 'help'
> > > >  print searchterm #local
> > > >
> > > >  self.searchterm = searchterm
> > > >  print self.searchterm #used inside
> > > > the class
> > > >
> > > >  Kdo.searchterm = searchterm   #
> > > >  print Kdo.searchterm #used outside
> > > > the class Kdomore()
>
> the line above should be Kdomore(), not class
> Kdomore() (For the technocrats)
>
> > > > class Kdomore(Kdo):
> > > >  def __init__(self) :
> > > >  self.Fdomore()
> > > >
> > > >  def Fdomore(self):
> > > >  searchterm =  Kdo.searchterm   #
> > > >  print searchterm
> > >
> > > It's not apparent what the print statements
> > > are for -- are they part of an attempt to
> > > debug your code?
> >
> > print shows the results wherever a print
> > statement turns up the results = 'help' .
> > I didn't run the code, and it has it has a
> > coding error but if removed, the results
> > should be;
> >
> >searchterm = 'help'
> >self.searchterm = 'help'
> >Kdo.searchterm = 'help'
> >
> >Sound silly but many people have trouble
> > with getting a variable from here to there in
> > their code. This shows that it can be done
> >
> > > What gives you the idea that this is what
> > > the OP wants or needs?
> >
> > If I remember right,  he refrased  his first
> > question and asked a second one.
> > Sometimes people don't take the time to write
> > correctly, the questions that are really in
> > their mind. So I guessed.  If Im wrong, he
> > will ignore it.  If I'm right, he will use
> > it.
> >
> > Also, I have found that other will latch on
> > to the ideas presented  in these email
> > responses. And they will use them, even
> > though the response was not exactly what the
> > original emailer wanted.
> >
> > And, I sometimes I do use print statements to
> > debug, I have used other ways but on linux, I
> > prefer a print statement.
>
 jim-on-linux
 http://www.inqvista.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I access a main frunction from an import module?

2006-11-24 Thread Steve
This is an interesting question.  It almost looks like a case of
event-driven programming, where main is the plug-in and abc is the
framework.
http://eventdrivenpgm.sourceforge.net/

So how about something like this:

## abc.py 

#
# an "abstract" function.
# It should be over-ridden in the calling program
#
def m():
raise AssertionError("You should have over-ridden abstract function
m()")

def a():
m()
return None


### main.py 
import abc  # "instantiate" the framework

# define our our "concrete" function m
def m():
print 'something'
return None

#---
# override the "abstract" function abc.m()
# with our own "concrete" function m().
# Comment out this line and see what happens.
#---
abc.m = m

# invoke the a() function in the abc framework
abc.a()

#

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


Re: Access to variable from external imported module

2006-11-24 Thread John Machin

jim-on-linux wrote:
> On Friday 24 November 2006 03:30, John Machin
> wrote:
> > jim-on-linux wrote:
> > > GinTon,
> > >
> > > I think this is what you want.
> > >
> > >
> > > class Kdoi:
> >
> > Is that a typo?
>No, it's a style. life seems to be easier
> to me if one is consistent, all my classes begin
> with K.

and end with "i"?

> >
> > >def __init__(self) :
> > >self.Fdo()
> >
> > What is all this K and F stuff?
> >
>It's my style. life seems to be easier  to me
> if one is consistent all my function begin with
> F.

You left out a word; the correct way of phrasing that is: "All my
function _are_ begin with F" :-)

This appears to be a variation on "Hungarian notation"; google that for
opinions pro & con.

In a certain vernacular, it would be called "an effed concept" :-)

>
> I started doing things like this when the only way
> to debug was to read each line of code and try to
> figgure out if it was the problem.

When was that? Even years ago, there were slightly better ways. For
example, my first boss' boss was an enthusiastic coder and debugger and
also a workaholic. Colleagues who lived along the same railway line as
he and were foolish enough not to hide behind a newspaper could have
their morning or evening reverie disturbed by a cry of "Glad you're
here! I'll hold the listing, you hold the dump!". I get the impression
that debugging techniques have moved along a little bit since then. :-)

> They are my personal sign posts.
> > >def Fdo(self):
> > >
>
> > >  searchterm = 'help'
> > >  print searchterm #local
> > >
> > >  self.searchterm = searchterm
> > >  print self.searchterm #used inside the
> > > class
> > >
> > >  Kdo.searchterm = searchterm   #
> > >  print Kdo.searchterm #used outside the
> > > class Kdomore()
> > >
> > >
> > >
> > > class Kdomore(Kdo):
> > >  def __init__(self) :
> > >  self.Fdomore()
> > >
> > >  def Fdomore(self):
> > >  searchterm =  Kdo.searchterm   #
> > >  print searchterm
> >
> > It's not apparent what the print statements are
> > for -- are they part of an attempt to debug
> > your code?
> >
> print shows the results wherever a print statement
> turns up the results = 'help' .
> I didn't run the code, and it has it has a coding
> error

I noticed.

> but if removed, the results should be;
>
>searchterm = 'help'
>self.searchterm = 'help'
>Kdo.searchterm = 'help'

No, the result would be
help
help
help

Plug in a text-to-speech module and a phone dialer and you're done ;-)

>
>Sound silly but many people have trouble with
> getting a variable from here to there in their
> code. This shows that it can be done
>
> > What gives you the idea that this is what the
> > OP wants or needs?
>
> If I remember right,  he refrased  his first
> question and asked a second one.
> Sometimes people don't take the time to write
> correctly, the questions that are really in their
> mind. So I guessed.  If Im wrong, he will ignore
> it.  If I'm right, he will use it.

With luck. Kindly consider another possibility: that you are wrong (or
just marching to the beat of your own tambourine) and he (or she) is a
newbie & will use it :-)

[snip]

HTH,
John

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


cron job times out

2006-11-24 Thread Nikola Skoric
Hello,

I have a few lines of code retrieving a web page and saving some 
variables from it to a log. And everything works nice from command line. 
but, when I make a cron job, I get an error:

Your "cron" job on fly
cd $HOME/bin/ ; python newartlog.py ; cd

produced the following output:

Traceback (most recent call last):
  File "newartlog.py", line 11, in ?
response = urllib2.urlopen(req)
  File "/usr/local/lib/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
  File "/usr/local/lib/python2.4/urllib2.py", line 358, in open
response = self._open(req, data)
  File "/usr/local/lib/python2.4/urllib2.py", line 376, in _open
'_open', req)
  File "/usr/local/lib/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
  File "/usr/local/lib/python2.4/urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.4/urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: 

It seems that the connection timed out. But, every time I execute the 
script from the command line, everything goes fine. And every time he 
cron job triggers, it times out. How come?

-- 
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams" 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand Python objects

2006-11-24 Thread Aahz
In article <[EMAIL PROTECTED]>,
Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:
>Aahz a écrit :
>> In article <[EMAIL PROTECTED]>,
>> Ben Finney  <[EMAIL PROTECTED]> wrote:
>>> 
>>>Typically, classes are created as a subclass of another class. The
>>>top-level basic type in Python is 'object', so if your class doesn't
>>>make sense deriving from anything else, derive from 'object'.
>>>
>>>   class Point(object):
>>>   pass
>>>
>>>Defining a class with *no* superclass is not recommended. If you don't
>>>yet understand the difference between the above style (called a
>>>"new-style" class) and the style you presented, you should always
>>>derive from a superclass ('object' or something more specific) until
>>>you encounter a situation where that causes a problem.
>> 
>> Side note: I disagree with the above advice, but it's Thanksgiving and I
>> don't have enough room on the margin for the proof.  I think classic
>> classes are just fine.
>
>Don't see it as a religious point please, but I fail to understand why 
>you seem so in love with old-style classes ? new-style classes are the 
>"official" Python object model since 2.2 (which is a few years ago now), 
>and the last mandatory use of them (exceptions...) disappeared with the 
>2.5. AFAIK, everything you do with old-style classes can be done with 
>new-style ones. FWIW, old-style classes support is now only for backward 
>compat. So *why* insisting on using them ?

There's a big difference between saying "always use old-style classes"
and "classic classes are just fine".  So I'm certainly not "in love with"
or "insisting" on using classic classes.  Mostly what I'm saying is that
I think it's kinda gross and grotesque for newcomers to be told to use

class Point(object):
pass

instead of

class Point:
pass

You are also wrong about new-style classes being the "official" object
model -- the tutorial doesn't even mention them yet!  I also think that
new-style classes should be avoided in Python 2.2 because of the subtle
differences that were introduced in 2.3 -- and 2.2 is still in active
use.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles:  boring syntax, unsurprising semantics,
few automatic coercions, etc etc.  But that's one of the things I like
about it."  --Tim Peters on Python, 16 Sep 1993
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How do I access a main frunction from an import module?

2006-11-24 Thread John Machin

Jim wrote:
> John Machin wrote:
> > Jim wrote:
> > > Hi,
> > >
> > > I have created an import module.  And would like to access a function
> > > from the main script, e.g.,
> > >
> > > file abc.py:
> > > ###
> > > def a():
> > > m()
> > > return None
> > > 
> > >
> > > file main.py:
> > > #
> > > from abc import *
> > > def m():
> > > print 'something'
> > > return None
> > >
> > > a()
> > > ##
> > >
> > > python25.exe main.py
> > >
> >
> > Although there are literally correct answers to your question, the best
> > answer is "Don't do that. You would be creating circular references
> > between modules, and run the risk of emulating the mythical ooloo bird
> > by disappearing up your own fundamental orifice". Some possible
> > practical solutions:
> >
> > 1. Put the m function in a 3rd file/module. Then any other module which
> > needs it can import/call.
> >
> > 2. If you think that's not a good idea, then put it in abc.py (it's not
> > used in main.py in your example).
> >
> > 3. Maybe this will suit what you are really trying to do:
> >
> >  file abc.py:
> >  ###
> >  def a(argfunc): # <=
> >  argfunc() # <=
> >  
> >
> >  file main.py:
> >  #
> >  from abc import *
> >  def m():
> >  print 'something'
> >
> >  a(m) # <=
> >  ##
> >
> > 4. If you think *that's* not a good idea, then you might like to
> > explain at a higher level what you are *really* trying to achieve :-)
> > E.g. "Function m is one of n functions in main.py of which abc.py
> > may/must call 0, 1, or many because blah blah blah ..."
> >
> > BTW, "return None" at the very end of a function is redundant. The
> > Python compiler generates "return None" automagically (implicitly!?)
> > instead of letting you fall off the end of the world. Which book or
> > tutorial are you using?
> >
> > BTW #2: "python25.exe main.py" ?? If you are on Windows, have Python
> > 2.4 as your default setup, and are trialling 2.5: you may like to ask
> > (in a new thread) about more convenient ways of doing it. Otherwise you
> > might like to tell what you are up to (in a new thread) so that your
> > problem can be diagnosed correctly and cured :-)
> >
> > HTH,
> > John
>
> BTW#1: I have most of the python books from O'Reilly.  I'm sure that
> some of them say that its a good idea to use 'return None'.

Instead of "return None", consider using "return for refund" ;-)

> However,
> most their examples do not us it.  Anyway I find that its useful when
> reading my own scripts.
>
> BTW#2: I do not have Python 2.4 installed anymore.  Therefore, it is
> not a trialling problem.

Looks like it *was* a trialling problem, with weird residual effects.
The point was that it's a very strange practice to (a) name the
executable "python25.exe" [standard installation would produce
C:\Python25\python.exe] (b) want/need to use ".exe" when invoking it.

>
> I thought that it would be NICE to keep the application and the user's
> script separate from each other, being that python is so flexible.

Most other people think that that's a very nice idea too; there was
just no clue in your original posting about what you were really trying
to do.

> However, there seems to be no end to the problems that occur by doing
> this.  So I will abandon this exercise, since it appears not to be a
> very good programming practise.

So what about my suggestion 3? I got the impression from your reply to
Bjoern that it was a good fit for your case. The functions are in what
we now know to be the user's script, and the app calls them. What
problems?

Cheers,
John

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


Re: SQLite3__Python2.3-SQLite__Problem

2006-11-24 Thread Cousin Stanley

>   
>  SQLite3 data bases created via the command line
>  and those created using the python2.3-sqlite package
>  version 1.0.1-2 from within a Python program 
>  are  not  compatible with each other  
>   
>  If I create an SQLite3 data base from the command line
>  and populate it with data, then I cannot use that db
>  from Python  
>   
>  If I create an SQLite3 data base from within Python
>  and populate it with data, then I cannot use that db
>  from the command line  
>  

   This problem is occuring under Debian GNU/Linux Sarge 
   using Python 2.3 

   This morning for a sanity check on myself
   I installed SQLite3 and PySQLite2 on a Win2K box
   running ActiveState Python 2.4 

   The only things that I had to change in the Python code
   for creating tables, inserting data, and querying the db
   that I'm also using under Debian were the import lines 

 from  import sqlite

 to .. from pysqlite2 import dbapi2 as DB

   Using this setup under Win2K everything works as expected  

   That is SQLite3 data bases created either via the sqlite3 
   command line or from within Python are 100% transparent,
   and no errors are produced  

   I'm now off to look for a version of PySQLite2
   that is built for Debian Sarge and Python 2.3 
   to see if that might help to rectify the problem 
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


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


Re: Pydev configuration

2006-11-24 Thread tool69
Sébastien Boisgérault a écrit :
> Hi,
> 
> Did anyone managed to change the code font family/size
> in Pydev (Python Editor Plugin for Eclipse) ? I found how
> to change the color mapping (Windows/Preference/Pydev)
> but did not found the font setting.
> 
> Cheers,
> 
> SB
> 
Salut Sébastien,

Preferences/General/Appearence/Colors&Fonts/ in the right menu choose 
Basic/Text Font

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


Re: SQLite3__Python2.3-SQLite__Problem

2006-11-24 Thread John Machin
Cousin Stanley wrote:
> It's been almost 2 years since I've done anything
>   with Python and SQLite and I'm having some problems
>   that I don't recall from my last usage 
>
>   It seems that SQLite3 data bases created at the command line
>   and those created using the sqlite module from within Python
>   are no longer compatible with each other using the setup that
>   I now have 
>
>   I thought I remembered that the data bases created either way
>   were always 100% transparent with each other and that I could
>   use an SQLite3 data base either from the command line or from
>   within Python without any problems at all 

My guess is that 2 years ago you were using sqlite 2, not 3.

>
>   I did a fair amount of Google-izing looking for related problems
>   but didn't have much success 
>

In that case your googler is absolutely rooted and should be replaced
immediately.

With mine, google("file is encrypted or is not a database") produces as
first hit (would you believe!?)
http://wiki.rubyonrails.org/rails/pages/HowtoUseSQLite
which contains the text:

"""
Q: SQLite::Exceptions::\DatabaseException file is encrypted or is not a
database.

A: It seems that sqlite databases created with version 2 do not work
with sqlite version 3 and vice versa.
"""

IOW sqlite is a candidate for nomination to the "We Could Have Given A
Much More Helpful Error Message" Hall of Illfame :-)

Alternatively, you could get it straight from the the horse's mouth, at
http://www.sqlite.org/version3.html

"""The format used by SQLite database files has been completely
revised. The old version 2.1 format and the new 3.0 format are
incompatible with one another. Version 2.8 of SQLite will not read a
version 3.0 database files and version 3.0 of SQLite will not read a
version 2.8 database file."""

According to http://www.sqlite.org/oldnews.html, the first non-beta
version of 3.0 was released in September 2004. You appear to have a 3.2
version of the sqlite3 command-line utility. So far, so good. However,
I would be very suspicious of an sqlite that came with Python 2.3 --
it's probably sqlite version 2.something

>From your 2nd message:

> I'm now off to look for a version of PySQLite2
> that is built for Debian Sarge and Python 2.3
> to see if that might help to rectify the problem 

Sounds like a good idea. Change it to read "that has been built
*recently*" and it sounds like an even better idea :-)

On Windows, with Python 2.4 (just like your trial):

| >>> from pysqlite2 import dbapi2 as DB
| >>> DB.version # version of pysqlite2
| '2.3.2'
| >>> DB.sqlite_version # This is the one that matters!
| '3.3.6'

Try extracting sqlite_version from your Linux setup.

Aside: with Python 2.5:
| >>> import sys; sys.version
| '2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]'
| >>> import sqlite3; sqlite3.sqlite_version
| '3.3.4' # time warp?

As you are discovering with Debian, one of the downsides of having
3rd-party goodies bundled in instead of downloading and installing them
yourself is that thay can become frozen in time -- not quite as bad as
the ruins of Pompeii; although Python 2.3 is getting close :-)

HTH,
John

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


Re: SQLite3__Python2.3-SQLite__Problem

2006-11-24 Thread Jonathan Ballet
Le Fri, 24 Nov 2006 13:18:14 -0600,
Cousin Stanley <[EMAIL PROTECTED]> a écrit :
> 
>This problem is occuring under Debian GNU/Linux Sarge 
>using Python 2.3 
> 

Hi,

if you look at
http://packages.debian.org/stable/python/python2.3-sqlite,
you will see that the python2.3-sqlite package is built against
SQLite 2. This is why you have a "file is encrypted or is not a
database" message, since databases created with SQLite 2.x are not
file-compatible with SQLite 3.x file.


So, if you can find a Python binding for SQLite 3, go for it, but,
unless you are building it from scratch (I mean, not from a Debian
package), it might be difficult to find.

Otherwise, use the sqlite command line tool (not sqlite3), which is
built against SQLite 2.x.
If you go for this solution, it's easy to migrate from a 2.x to a 3.x
database, something like :
$ echo ".dump" sqlite database.db.2x | sqlite3 database.db.3x
(you will have to change the Python accordingly, of course ;)

Hope it helps,

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


Re: Active State and Komodo...

2006-11-24 Thread John Machin

Steve Thompson wrote:
> Hello all,
>
> I was wondering the differnced there were betwee Active State's python and
> the open source version of python. Would I have to unistall my opend souce
> python? Additonally, how does Active State's Komodo IDE vs. the eric3 IDE
> unler SuSE Linux v. 10.i?
>
> Addionally, is the eric IDE (version 3) an acceptible IDE or are there
> more easy and more productive IDE's for perl?
>
> I'm urining Gnome v. 12.2.2 and Eric v 3.8.1

I'm not sure which to recommend: a spelling checker or a catheter :-)

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


Re: Pydev configuration

2006-11-24 Thread Sébastien Boisgérault


On Nov 24, 9:42 pm, tool69 <[EMAIL PROTECTED]> wrote:
> Sébastien Boisgérault a écrit :> Hi,
>
> > Did anyone managed to change the code font family/size
> > in Pydev (Python Editor Plugin for Eclipse) ? I found how
> > to change the color mapping (Windows/Preference/Pydev)
> > but did not found the font setting.
>
> > Cheers,
>
> > SBSalut Sébastien,
>
> Preferences/General/Appearence/Colors&Fonts/ in the right menu choose
> Basic/Text Font

Ah ... Thanks a lot ! I had tweaked in the neighbourhood of this
option
but it was unclear for me that "Text Font" did also refer to Python
code.

'Bitsream Vera Sans Mono', here I come ;)

Cheers

SB

> 6TooL9

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


Re: How good is CORBA?

2006-11-24 Thread Piet van Oostrum
> "Chris Mellon" <[EMAIL PROTECTED]> (CM) wrote:

>CM> FYI: Ice is available under the GPL, so if by "pay" you mean "pay
>CM> money" that's not your only option. You can also get a commercial
>CM> license, similiar to Qt.

>CM> I like Ice a lot, it's got hardly any of the ramp up time and learning
>CM> curve that CORBA does, and it's extremely efficent. If GPL or cash are
>CM> acceptable licensing options to you, then I encourage you to use it
>CM> before you head to CORBA.

OmniORB's author did some benchmarking and it appeared that omniORB was
faster than Ice.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Active State and Komodo...

2006-11-24 Thread hg
John Machin wrote:
> Steve Thompson wrote:
>> Hello all,
>>
>> I was wondering the differnced there were betwee Active State's python and
>> the open source version of python. Would I have to unistall my opend souce
>> python? Additonally, how does Active State's Komodo IDE vs. the eric3 IDE
>> unler SuSE Linux v. 10.i?
>>
>> Addionally, is the eric IDE (version 3) an acceptible IDE or are there
>> more easy and more productive IDE's for perl?
>>
>> I'm urining Gnome v. 12.2.2 and Eric v 3.8.1
> 
> I'm not sure which to recommend: a spelling checker or a catheter :-)
> 

You _are_ bad !

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


Re: Access to variable from external imported module

2006-11-24 Thread jim-on-linux
On Friday 24 November 2006 13:41, John Machin 
wrote:
> jim-on-linux wrote:
> > On Friday 24 November 2006 03:30, John Machin
> >
> > wrote:
> > > jim-on-linux wrote:
> > > > GinTon,
> > > >
> > > > I think this is what you want.
> > > >
> > > >
> > > > class Kdoi:
> > >
> > > Is that a typo?
> >
> >No, it's a style. life seems to be
> > easier to me if one is consistent, all my
> > classes begin with K.
>
> and end with "i"?
>
> > > >def __init__(self) :
> > > >self.Fdo()
> > >
> > > What is all this K and F stuff?
> >
> >It's my style. life seems to be easier  to
> > me if one is consistent all my function begin
> > with F.
>
> You left out a word; the correct way of
> phrasing that is: "All my function _are_ begin
> with F" :-)

No, for Non-Hungrian programmers it's "all-ah me" 
Functions gona begin witha F, not Func. anda 
"all-ah-me" classes gona begin witha K, not Klas.
Anda only me gona Know the Fdiff cause me codea is 
not opena. Anda I finda that it savea me time 
causea I doa thisa way fora a longa time.

Whena I gonna hava to changea maybe I willa.
 
>
> This appears to be a variation on "Hungarian
> notation"; google that for opinions pro & con.
>
> In a certain vernacular, it would be called "an
> effed concept" :-)
>
> > I started doing things like this when the
> > only way to debug was to read each line of
> > code and try to figgure out if it was the
> > problem.
>
> When was that?
That was when bill gates just left Harvard,
basic was brand new, and 4k of memory was 
installed free when you bought a computer, 
(TRS80), my first,. Assemble was the alternative 
to Basic and you had to backup on tape because 
floppies didn't exist. And, most people on this 
site wern't even a gleem in their fathers eye.

> Even years ago, there were 
> slightly better ways. For example, my first
> boss' boss was an enthusiastic coder and
> debugger and also a workaholic. Colleagues who
> lived along the same railway line as he and
> were foolish enough not to hide behind a
> newspaper could have their morning or evening
> reverie disturbed by a cry of "Glad you're
> here! I'll hold the listing, you hold the
> dump!". I get the impression that debugging
> techniques have moved along a little bit since
> then. :-)
>
> > They are my personal sign posts.
> >
> > > >def Fdo(self):
> > > >
> > > >
> > > >  searchterm = 'help'
> > > >  print searchterm #local
> > > >
> > > >  self.searchterm = searchterm
> > > >  print self.searchterm #used inside
> > > > the class
> > > >
> > > >  Kdo.searchterm = searchterm   #
> > > >  print Kdo.searchterm #used outside
> > > > the class Kdomore()
> > > >
> > > >
> > > >
> > > > class Kdomore(Kdo):
> > > >  def __init__(self) :
> > > >  self.Fdomore()
> > > >
> > > >  def Fdomore(self):
> > > >  searchterm =  Kdo.searchterm   #
> > > >  print searchterm
> > >
> > > It's not apparent what the print statements
> > > are for -- are they part of an attempt to
> > > debug your code?
> >
> > print shows the results wherever a print
> > statement turns up the results = 'help' .
> > I didn't run the code, and it has it has a
> > coding error
>
> I noticed.
>
> > but if removed, the results should be;
> >
> >searchterm = 'help'
> >self.searchterm = 'help'
> >Kdo.searchterm = 'help'

Correct but when writing one must be clear.

Would it be better for me to write, your question
above was Is that a typo?

Or is it better if I were to write, your 
question above, "Is that a typo?", 
is a legimate question, but not clear.

So, to be clear one might write is "Kdoi" 
correct?. 

A clear response would be, it is not "Kdoi", it is 
"Kdo".  

But that's not correct either, it is Kdo.  

If one runs the code I don't expect the user to 
look for "help", I think we will see help and 
will THINK that the results are correct.

THINK is also incorrect, it should be written. 
think, or should it?

 
> No, the result would be
> help
> help
> help
>
> Plug in a text-to-speech module and a phone
> dialer and you're done ;-)
>
> >Sound silly but many people have trouble
> > with getting a variable from here to there in
> > their code. This shows that it can be done
> >
> > > What gives you the idea that this is what
> > > the OP wants or needs?
> >
> > If I remember right,  he refrased  his first
> > question and asked a second one.
> > Sometimes people don't take the time to write
> > correctly, the questions that are really in
> > their mind. So I guessed.  If Im wrong, he
> > will ignore it.  If I'm right, he will use
> > it.
>
> With luck. Kindly consider another possibility:
> that you are wrong (or just marching to the
> beat of your own tambourine) and he (or she) is
> a newbie & will use it :-)
>

"Because he being of course judge of that tendency 
will make his opinions the rule of judgment, and 
approve or condemn the sentiments of others only 
as they shall square with or differ from his own…"
Th

Re: synching with os.walk()

2006-11-24 Thread Antoine De Groote
Andre Meyer wrote:
> Hi all
> 
> os.walk() is a nice generator for performing actions on all files in a 
> directory and subdirectories. However, how can one use os.walk() for 
> walking through two hierarchies at once? I want to synchronise two 
> directories (just backup for now), but cannot see how I can traverse a 
> second one. I do this now with os.listdir() recursively, which works 
> fine, but I am afraid that recursion can become inefficient for large 
> hierarchies.
> 
> thanks for your help
> André
> 

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/191017
might be what you are looking for, or at least a starting point...

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

Installing CVXOPT

2006-11-24 Thread [EMAIL PROTECTED]
hi,

how can I install and start using CVXOPT. I have python 2.5 version
installed. what else do i need to download and install for CVXOPT.

thanks
amit

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


Re: Python popenX() slowness on AIX?

2006-11-24 Thread Stefaan A Eeckels
On 24 Nov 2006 09:03:41 -0800
[EMAIL PROTECTED] wrote:

> Stefaan A Eeckels wrote:
> > On 21 Nov 2006 13:02:14 -0800
> > [EMAIL PROTECTED] wrote:
> >
> > > The fact that it does this in Python code instead of C is the main
> > > cause of the slowness.  So, unless Python is changed to do this
> > > in C, it's always going to be slow on AIX :-(
> >
> > I guess that the reason it's slow is that there are many
> > descriptors to try and close. Reducing them using ulimit -n could
> > improve the speed.
> >
> > AIX has a fcntl command to close all open file descriptors from a
> > descriptor onwards:
> >
> > fcntl(3, F_CLOSEM);
> >
> > This of course should be used instead of the loop:
> >
> > 10 happens to be the value of F_CLOSEM (from /usr/include/fcntl.h).
> > I've currently no access to an AIX system with Python, but it could
> > be worth trying.
> 
> Yes, very much worth it.  F_CLOSEM is _so_ much better than the loop,
> even in C.   Using your brilliant suggestion, I now have a simple
> patch to the python source that implements it for any OS that happens
> to have the fcntl F_CLOSEM option.   

The *BSDs and Solaris have "closefrom(3)" which does the same as
F_CLOSEM in AIX. As with AIX, the speedup is dramatic when there are a
lot of file descriptors to try and close.

> It is below in its entirety.  I believe I got the try: stuff correct,
> but since I'm new to Python, I'd appreciate any comments.

I'm no great Python specialist myself. I'll leave it to those better
qualified to comment.

> I have another patch to implement my os.rclose(x,y) method, which
> would improve the speed of popenX() for the OSes that don't have
> F_CLOSEM, by doing the close() loop in C instead of Python,  but I
> don't know if it would be as likely to be accepted as this probably
> would be.
> 
> Now, where do I send my proposed patch for consideration?

The README file in the Python distribution has the following to say:

Patches and contributions
-

To submit a patch or other contribution, please use the Python Patch
Manager at http://sourceforge.net/patch/?group_id=5470.  Guidelines
for patch submission may be found at http://www.python.org/patches/.

Take care,

-- 
Stefaan A Eeckels
-- 
Never explain by malice what can be adequately explained by stupidity.
However:
Sufficiently advanced stupidity is indistinguishable from malice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access to variable from external imported module

2006-11-24 Thread Steven D'Aprano
On Fri, 24 Nov 2006 16:56:58 -0500, jim-on-linux wrote:

> Correct but when writing one must be clear.

[jaw drops]

Given the number of typos your posts include, the mock accent, the
nonsensical sentences, the annoying hard-to-read coding conventions, and
the sheer number of grammatical errors in your sentences, do you have any
idea of the irony of that statement?

No, I imagine you don't.

Oh, and don't flatter yourself that you're the Old Man of Programming,
compared to all the young whipper snappers on this list who, quote,
"wern't even a gleem in their fathers eye". Many of us have been around
quite a while, some of us even remember that there was a computer market
before Bill Gates went dumpster-diving for source-code for a BASIC
interpreter, and even if we weren't, there is nothing to be proud of using
1970s programming style in 2000s programming languages.


-- 
Steven.

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


  1   2   >