Re: Windows Services

2005-12-14 Thread alf
Also think through which Windows account will run the service, and what
permissions it will need.  A little up front work here will be
appreciated by the people who have to install your service.

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


attaching debugger to runinng python program

2006-07-13 Thread alf
Hi,

I have a two fold question:
-how to attach the debugger to running multi threaded program
-the objective is to find an infinite loop in one of threads which 
makes the whole thingy going craze (100%CPU)

The program itself is not easy, in fact quite hude and sometimes it 
takes hours to get to that infloop state.

Any insight?

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


Re: attaching debugger to runinng python program

2006-07-14 Thread alf
Bill Pursell wrote:
> Now, in another shell,
> % gdb
> (gdb) attach 54321
>

Thx for the reply. But I wish to debug the python program, not python 
interpreter itself.
-- 
http://mail.python.org/mailman/listinfo/python-list


SocketServer and timers

2006-07-27 Thread alf
Hi,

I have one thread app using SocketServer and use server_forever() as a 
main loop. All works fine, but now I need certain timer checking let's 
say every 1 second something and stopping the main loop. So questions are:
-how to stop serve_forever
-how to implement timers

thx, alf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SocketServer and timers

2006-08-08 Thread alf
[EMAIL PROTECTED] wrote:
> alf wrote:
> 
>>I have one thread app using SocketServer and use server_forever() as a
>>main loop. All works fine, but now I need certain timer checking let's
>>say every 1 second something and stopping the main loop. So questions are:
>>  -how to stop serve_forever
> 
> 
> Override serve_forever() and replace "while 1:" with something like
> "while self.continue_flag:".
> 
> 
>>  -how to implement timers
> 
> 
> You could override get_request(), and use select.select() to wait for
> either the socket to become readable (so the accept() won't block), or
> a timeout to expire. If you are not already, use the threading or
> forking
> mixin so that the request handler won't stop everthing if it blocks.
> 
> 

thx for a suggestion, will try it out ...
-- 
http://mail.python.org/mailman/listinfo/python-list


iterator wrapper

2006-08-11 Thread alf
Hi,

I have a following task: let's say I do have an iterator returning the 
some objects:

 >>i=
 >>i.next()
1
 >>i.next()
'abgfdgdfg'
 >>i.next()



For some reason I need to wrap thos objects with a list. I thought I 
could have a smart lamda or simple function class yielding following result:


 >>i=
 >>i=list_wrapper(i)
 >>i.next()
[1]
 >>i.next()
['abgfdgdfg']
 >>i.next()
[]


What would thesolution?


Thx,

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


Re: iterator wrapper

2006-08-11 Thread alf
Simon Forman wrote:

>class LW(object): # ListWrapper
>>... def __init__(self, i):
>>... self.theiter = i
>>... def next(self):
>>... return [self.theiter.next()]


I hoped one lamda would take care of it but looks like it is a simplest 
choice.

> |>> I = ([n] for n in i)

This is nice but I am iterating thru hude objects (like MBs) so you know ...


Thx for responding ...


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


Re: iterator wrapper

2006-08-12 Thread alf
Simon Forman wrote:
>>
>>>|>> I = ([n] for n in i)
>>
>>This is nice but I am iterating thru hude objects (like MBs) so you know ...
>>
> 
> No, I don't know...  :-)

potentially my source lists are huge - so wanted to avoid unnecessary 
memory allocation


> My friend, I think you've misunderstood.  Observe:
> 
> |>> L = [n for n in range(3)]
> |>> G = (n for n in range(3))
> |>> L
> [0, 1, 2]
> |>> G
> 

well, I am in the python 2.3 word where generator comprehensions seem 
not to work. So I just took it a preallocated list comprehention. still 
wonder if there would be a difference between:

G = (n for n in range(3))  - this creates the huge list there
G = (n for n in xrange(3)) - this (at least to my understanding) 
  does not


> 
> List comprehensions [] create lists, generator comprehensions () create
> generators.
> 


> Generator comprehensions work "just-in-time", pulling items from
> whatever they're iterating over as they themselves are iterated over,
> as I hope this example makes clear:
> 
 >[...]

got it now ... thx or the lesson


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


Re: iterator wrapper

2006-08-12 Thread alf
Paul Rubin wrote:
> alf <[EMAIL PROTECTED]> writes:
> 
>>>|>> I = ([n] for n in i)
>>
>>This is nice but I am iterating thru hude objects (like MBs) so you know ...
> 
> 
> I don't understand the objection-- the above is entirely correct and
> produces the same iterator you'd get from
> 
> def wrap(i):
>for x in i:
>yield [x]
> I = wrap(i)
> 
> You could also use
>  
>import itertools
>I = itertools.imap(lambda x: [x], i)
> 
> which again does the same thing.


I did see [] instead of () :-). this was a source of confusion.


okay, we have 3 functionally equal solution - which is most pythonic :-) 
 seroiusly ...



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


[OT] why cd ripping on Linux is so slow

2006-08-12 Thread alf
Hi,

I try to ip some music CD and later convert it into mp3 for my mp3 
player, but can not get around one problem. ripping from Linux is 
extremely slow  like 0.5x of CD speed.

In contrary, on M$ Windows it takes like a few minutes to have CD ripped 
and compresses into wmf yet I do not knowhow to get pure wavs...

Hope I find someone here helping me with that 


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


Re: [OT] why cd ripping on Linux is so slow

2006-08-12 Thread alf
Patrick Useldinger wrote:
> 
> This is really OT:

yes it is


> and you might be better off looking in Linux forums 
> like http://www.linuxquestions.org/. That said, it's likely that your 
> DMA is not switched on.


thx for the hint and the reference - see hopefully I got to know where 
to find the answer.


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


Re: iterator wrapper

2006-08-12 Thread alf
Simon Forman wrote:

> Yes, you've got it, the xrange() version will not allocate a huge list.
> 
> It's not part of your main question, and I understand that there may be
> reasons why you can't, but consider upgrading to 2.4 (or very soon now
> 2.5...)

upgrade to 2.4 is on the roadmap and will take place soon  the app 
is just too big and must be stable so since all works in 2.3 well we 
stick to it.

there are some parts (related to wx where I noted that 2.4 behaves 
differently so it needs some attention) ...


other reason is there is a number of users using customized python (on 
top of standard install there is wx, twistedmatrix, matplot and a lot of 
small libs/modules == 200MB) so it is kind of pin to migrate that from 
the deployment point of view. Tried to have Python on network drive but 
it is painfully slow. wonder what strategy should I choose while the 
priority is the stable app.

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


MIMEMultipart() and CRLF vs RFC 2046

2006-10-05 Thread alf
Hi,

according to rfc2046, line breaks in MIME are CRLF. However python just 
uses LF like in the following example:


from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

msg = MIMEMultipart()
msg['Subject'] = 'Our family reunion'
msg['From'] = '[EMAIL PROTECTED]'
msg['To'] = '[EMAIL PROTECTED]'
msg.epilogue = ''

msg.attach(MIMEText(''))

print `msg.as_string()`


gives:
'Content-Type: multipart/mixed; 
boundary="===1018679223=="\nMIME-Version: 1.0\nSubject: Our 
family reunion\nFrom: [EMAIL PROTECTED]: 
[EMAIL PROTECTED]: text/plain; 
charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 
7bit\n\n\n--===1018679223==--\n'



Any insight why does it not stick to standard. I also checked parsing 
and it seems to accept both CRLF and LF.

-- 
Thx, alfz1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MIMEMultipart() and CRLF vs RFC 2046

2006-10-06 Thread alf
Gabriel Genellina wrote:
> At Thursday 5/10/2006 18:52, alf wrote:
> 
>> according to rfc2046, line breaks in MIME are CRLF. However python just
>> uses LF like in the following example:
> 
> 
> The comments inside generator.py say CRLF everywhere, but the code 
> simply uses print >>f

they also define NL as '\n\ only.

> You should file a bug report at 
> http://sourceforge.net/tracker/?group_id=5470
done

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


subprocess-how to suppress the stdout

2006-10-26 Thread alf
Hi,
I use subprocess to execute another program but need to suppress its stdout.

I can achieve it by using Popen(...,stdout=subprocess.PIPE,...) but 
wonder where the all stdout actually goes. Is it buffered (to eventually 
fill up)or just discarded?

Or there is a better solution ...

Thx, alf
-- 
http://mail.python.org/mailman/listinfo/python-list


displaying \n-less prompts in a pythonic way

2006-10-26 Thread alf
Hi,

I have a command line program which also does some interaction with the 
user using stdin and stdout.

My requirement is to print prompt so the user can answer in the same 
line. Unfortunately:

  print 'enter command:',


does not really work as the comma is carried over to the following lines 
and the indentation gets messed up.


I can use sys.stdout.write('enter command:') instead but kind of do not 
like sys.stdout.write mixed up with print's statements used to display 
other informations.


Is there a pythonic solution for the problem?

Thx, alf
-- 
http://mail.python.org/mailman/listinfo/python-list


http://tipc.sourceforge.net support

2006-10-26 Thread alf
Hi,

I did my homework and researched the net - can not find the python 
support for TIPC.

Does anybody know if there are plans to implement it?

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


Re: subprocess-how to suppress the stdout

2006-10-26 Thread alf
Fredrik Lundh wrote:
> "alf" <[EMAIL PROTECTED]> wrote:
> 
> 
>>I can achieve it by using Popen(...,stdout=subprocess.PIPE,...) but
>>wonder where the all stdout actually goes. Is it buffered (to eventually
>>fill up)
> 
> 
> it ends up in a pipe buffer, yes.
> 
> 
>>Or there is a better solution ...
> 
> 
> /dev/null is your friend:
> 
> Popen(..., stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT, ...)
> 

I am forced to use win32 :-( plus it needs to be platform independent ...
-- 
http://mail.python.org/mailman/listinfo/python-list


PythonMagic - has any body played with it recently

2006-10-26 Thread alf
Hi,

I downloaded the latest found version and untared it - but can not find 
any information how to install it. I guess it is boost based ...

Has any body played with it recently?
-- 
alf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: displaying \n-less prompts in a pythonic way

2006-10-26 Thread alf
Steve Holden wrote:
> Or use raw_input(), which was designed for such situations:
> 

thx, did not know about that ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Python images processing -recap

2006-11-01 Thread alf
Hi,

I try to summarize what is available in python for graphical images 
processing. So far I found:

-PythonMagic
-PIL
-SDL_image


Are all supported, which is most mature, in which I could perform for 
instance 'Ken Burns effect' or light filling operations. Is there 
anything else?


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


can I import the module twice (under differnet names)

2006-11-01 Thread alf
Hi,

wonder if in the python I could treat modules imorts like classes 
instances. It means I could import it twice or more times under 
different names.

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


need to find out all modules from site-packages

2006-11-01 Thread alf
Hi,

I need to find all modules/lib from the site-packages along with the 
versions. Is there a way to determine physical path to the module?

And is there is a way to identify all potential "importable" modules?

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


Re: Python images processing -recap

2006-11-02 Thread alf
Fredrik Lundh wrote:
> alf wrote:
> 
>> Are all supported, which is most mature, in which I could perform for 
>> instance 'Ken Burns effect' 
> 
> 
> that's a display effect, not an image effect.  you need a display (or 
> animation) library for that.
> 

In fact I want to generate a sequence of BMPs and feed mpeg decoder with it.

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


Re: sound process moduls in python ?

2006-11-06 Thread alf
[EMAIL PROTECTED] wrote:
> Hi,
> 
> When I was talking with my friend, I wanted to share the music I'm 
> listening with
> my friend. I mean, I wanted my friend to hear my music and my own sound .
> 
> I order to achieve this, I think I need to append the output of my sound 
> card to
> the input of the sound card.
> 
> My questions:
> 
> 1. Is my idea possible ?
> 
> 2. Which sound processing module is capable to do this ? The module 
> should at least
> available at Windows platform.
> 
> Thanks !
> 
> xiaojf

try pymedia - there are a lot of examples
-- 
http://mail.python.org/mailman/listinfo/python-list


the most efficient method of adding elements to the list

2006-06-05 Thread alf
Hi,

Would it be .append()? Does it reallocate te list with each apend?

l=[]
for i in xrange(n):
   l.append(i)


Thx, A.
-- 
http://mail.python.org/mailman/listinfo/python-list


dynamic inheritance

2006-06-08 Thread alf
is there any way to tell the class the base class during runtime?

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


Re: dynamic inheritance

2006-06-20 Thread alf
bruno at modulix wrote:
> 
> *But* you'd probably better tell us about the problem you're trying to
> solve. Since in Python, inheritance is mostly about implementation (ie:
>  not needed for subtyping), your problem would probably be best solved
> with composition/delegation, for which Python offers a good support:
> 

I did not think about any particular problem, just thought it would be 
cool to abstract out the base class. In fact you can do that in C++ (to 
some extend) using templates and parameterizing the base class.

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


Re: dynamic inheritance

2006-06-21 Thread alf
Michele Simionato wrote:
> alf wrote:
> Python is ways cooler than C++.

I switched to Python from C++ over year ago and do not see a way back. 
C++ just sucks at each corner.


> This is a sensible use case where you may
> want to change the base class at runtime:

Thx for the example.

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


smtpd and custom MAIL_FROM/RCPT_TO validation

2006-08-25 Thread alf
Hi,

I use smtpd for the SMTP server in my app, but I need a little bit more 
as far as immediate MAIL_FROM/RCPT_TO validation.  Returning from 
process_message is too late SMTP protocol-wise.

The ad hoc solution is to create own SMTPServer2 by deriving from and 
own SMTPChannel2  by deriving SMTPChannel. What bothers me that some 
code duplication  from SMTPServer.__init__ and 
SMTPChannel.smtp_MAIL/RCPT will have to take place.


Is there any way to avoid it. Probably not :-( ...

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


M$ windows python libs installed in arbitrary directories for customized python distributions

2006-08-25 Thread alf
Hi,

for some reason I have to deal with custom python distributions.

It turned out it is quite simple - I just install the python from 
python.org and all the libs needed. Then I take python2n.dll from 
c:\win*\system32 and move directly to PYTHONDIR. Then I can just tar/zip 
the PYTHON dir and distribute around so users do not have to deal with 
dozen of libs and packages.

Small difficulty is a maintenance of such "distribution". Namely when I 
want install a new lib M$ installer just can not find my python 
installations probably due to missing registry entries.

Is there any way to force the actual python site-lib for M$ installers

thx in advance,

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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-27 Thread alf
Fredrik Lundh wrote:
> "alf" <[EMAIL PROTECTED]> wrote:
> 
> 
>>It turned out it is quite simple - I just install the python from
>>python.org and all the libs needed. Then I take python2n.dll from
>>c:\win*\system32 and move directly to PYTHONDIR. Then I can just tar/zip
>>the PYTHON dir and distribute around so users do not have to deal with
>>dozen of libs and packages.
>>
>>Small difficulty is a maintenance of such "distribution". Namely when I
>>want install a new lib M$ installer just can not find my python
>>installations probably due to missing registry entries.
>>
>>Is there any way to force the actual python site-lib for M$ installers
> 
> 
> it's spelled "Windows installers", and code to do the necessary registry 
> updates
> can be found here:
> 
> http://effbot.org/zone/python-register.htm
> 
>  
> 
> 
> 
thx for the hint ...
-- 
http://mail.python.org/mailman/listinfo/python-list


__str__ for large objects, would not c++ iostream be more efficient

2006-08-28 Thread alf
Hi,

is there any way in Python to have iostream like __str__ operator?

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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-28 Thread alf
Martin v. Löwis wrote:
>>it's spelled "Windows installers"
> I want to second this. It was me who created the installer, and I don't
> like to see my name abbreviated as M$ (if you think you should write
> out the name of the MSI creator, please say "Martin's installer" :-).


ok, let me clarify, by M$ I meant Micro$oft.

-- 
alf

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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-29 Thread alf
Fredrik Lundh wrote:
> 
> http://www.catb.org/~esr/faqs/smart-questions.html#writewell
> 
> 

and  means?

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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-30 Thread alf
Robert Kern wrote:
> alf wrote:
> 
>> Fredrik Lundh wrote:
>>
>>> http://www.catb.org/~esr/faqs/smart-questions.html#writewell
>>>
>>> 
>>
>>
>> and  means?
> 
> 
> It's his signature.
> 

The sig is delimited by '-- \n'

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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-31 Thread alf
Georg Brandl wrote:
>>>
>>> It's his signature.
>>>
>>
>> The sig is delimited by '-- \n'
> 
> 
> Yes, and Earth is a disk.
> 

how deep

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread alf
Sybren Stuvel wrote:
> Hi folks,
> 
> Sometimes I have to feed data from an OpenOffice.org spreadsheet into
> some Python program. To make that really easy, I've written a small
> example program that connects to a running OpenOffice.org instance and
> reads the data from the currently opened spreadsheet.
> 
> Check out http://www.stuvel.eu/archive/28/ to see the source and
> requirements. It took a lot of digging in the rather complex OOo API
> documentation, but the end result is just as I like it: clean and
> simple. I hope this helps people out!
> 
> Sybren

thx for sharing the experience. Do you know how to save a OO doc into M$ 
Excel format - I have a Python based server running on Linux box and 
need to produce Excel files.

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


inaccuracy in the time module

2006-09-04 Thread alf
Hi,

can someone explane this:

 >>> from time import *
 >>> timezone
18000


 >>> t=time()
 >>> mktime(gmtime(t))-t
17999.680048942566


why there is a difference?

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


testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread alf
Hi,

I have a reference to certain objects. What is the most pythonic way to 
test for valid reference:

if obj:

if None!=obs:

if obj is not None:

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


Re: inaccuracy in the time module

2006-09-04 Thread alf
Paul Rubin wrote:
> alf <[EMAIL PROTECTED]> writes:
> 
>> >>> t=time()
>> >>> mktime(gmtime(t))-t
>>17999.680048942566
>>why there is a difference?
> 
> 
> time() is a floating point number with fractional seconds.
> gmtime()'s resolution is one second.

thx, got it now. replacing with "t=round(time())" fixes the problem.

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


re.compile().split(): why it produces empty string as a first element of the list

2006-09-26 Thread alf
Hi,
Let's run following:

 >>> re.compile('(\[.*?\])').split('[aa]bb[11]22')
['', '[aa]', 'bb', '[11]', '22']


Why does it return '' as a first element of the list?

Any insight?

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


Re: re.compile().split(): why it produces empty string as a first element of the list

2006-09-26 Thread alf
Fredrik Lundh wrote:
> alf wrote:
> 
>> Let's run following:
>>
>>  >>> re.compile('(\[.*?\])').split('[aa]bb[11]22')
>> ['', '[aa]', 'bb', '[11]', '22']
>>
>> Why does it return '' as a first element of the list?
> 
> 
> because the string starts with a separator.
> 
> 
> 
so is it safe to say that the index of separator in the list is always 
an odd number?

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


where the extra space comes from on the stdout

2006-09-30 Thread alf
Hi,

I can not find out where the extra space comes from. Run following:

import os,sys
while 1:
 print 'Question [Y/[N]]?',
 if sys.stdin.readline().strip() in ('Y','y'):
 #do something
 pass

$ python q.py
Question [Y/[N]]?y
  Question [Y/[N]]?y
  Question [Y/[N]]?y
  Question [Y/[N]]?y
  Question [Y/[N]]?n
  Question [Y/[N]]?
  Question [Y/[N]]?


There is a space evrywhere just before Q

Any insight?

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


More elegant to get a name: o.__class__.__name__

2006-11-30 Thread alf
Hi,
is there a more elegant way to get o.__class__.__name__. For instance I 
would imagine name(o).

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


Re: merits of Lisp vs Python

2006-12-08 Thread alf
Mark Tarver wrote:
> How do you compare Python to Lisp?

A little bit OT but I can not resist it. What always impressed me with 
Lisp is that LOGO (any one remembers) is Lisp based yet designed to 
teach kids programming. I do not know Lisp but used to program a bit in 
LOGO - everything was so  natural ...

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


Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-12-08 Thread alf
alf wrote:
> Hi,
> 
> I have a reference to certain objects. What is the most pythonic way to 
> test for valid reference:
> 
> if obj:
> 
> if None!=obs:
> 
> if obj is not None:
> 
thx for all answers - now "if obj is not None:" in an obvious choice ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where the extra space comes from on the stdout

2006-12-08 Thread alf
Simon Percivall wrote:
> 
> You already got the answer, but as for the rest: It's really easier for
> you if you use raw_input() for your question/input pair instead.
> 

thx, this is what I was looking for, alf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More elegant to get a name: o.__class__.__name__

2006-12-08 Thread alf
alf wrote:
> Hi,
> is there a more elegant way to get o.__class__.__name__. For instance I 
> would imagine name(o).
> 
decided to stick to o.__class__.__name__ for readibility.

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


HTTP & tcl

2006-02-15 Thread alf
Hi

I would like to convert the wctpXml-1.3.py program to Tcl (line by
line).
See http://sourceforge.net/project/showfiles.php?group_id=29217
This program sends pages using WCTP.  I know nothing about Python or
XML but this program is small and seems straightforward and I am sure
that I will be able to figure it out - with a little help ;-)
Currently I am stuck in not being able to identify the Tcl equivalent
of Python's "putrequest", as in:
h = httplib.HTTP("wctp.skytel.com",80)
h.putrequest("POST","/wctp")

Thanks
alf

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


Re: HTTP & tcl

2006-02-17 Thread alf
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Fuzzyman <[EMAIL PROTECTED]> wrote:
> >
> >alf wrote:
> >> Hi
> >>
> >> I would like to convert the wctpXml-1.3.py program to Tcl (line by
> >> line).
> >> See http://sourceforge.net/project/showfiles.php?group_id=29217
> >> This program sends pages using WCTP.  I know nothing about Python or
> >> XML but this program is small and seems straightforward and I am sure
> >> that I will be able to figure it out - with a little help ;-)
> >> Currently I am stuck in not being able to identify the Tcl equivalent
> >> of Python's "putrequest", as in:
> >> h = httplib.HTTP("wctp.skytel.com",80)
> >> h.putrequest("POST","/wctp")
> >>
> >
> >You'll get more help on Tcl syntax in a Tcl group. :-)
> >
> >Of the HTTP object, the Python documentation says :
>   .
>   .
>   .
> >In other words - you're creating an HTTP connection and request. You'll
> >need to find an 'equivalent' library for Tcl and convert the request
> >using hte semantics of whatever library you choose.
>   .
>   .
>   .
> If you don't immediately see what you're after in  http://wiki.tcl.tk/http >, post in comp.lang.tcl, and
> we'll straighten this out.

Hi

I actually did post in comp.lang.tcl.  Please search for "wctp" -- the
3 results are all mine.  Apparently, I am the only person interested in
implementing it in Tcl.
As always, I appreciate your good will and help.

alf.

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


launching default browser

2007-06-08 Thread alf
Hi,

I wonder how to launch from python default Windows browser? In fact I 
have the same question for Linux.

thx in advancve,
-- 
alf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launching default browser

2007-06-09 Thread alf
Laurent Pointal wrote:

> 
> Via webbrowser module
> 
> http://docs.python.org/lib/module-webbrowser.html
> 
thx a lot. Just again Python positively surprises me.



> (note: its in top five in google search for Python + launch + browser...)

so now it will be in top four :-).
-- 
http://mail.python.org/mailman/listinfo/python-list


overriding base class

2007-06-29 Thread alf

Hi,


I want to develop a following lib:

lib space user space

A -> B -> | -> user_class


however A and B are abstrac enough to have following:


user_super_base_class -> | -> A -> B -> | -> user_class

user space  lib space  user spaca



Any idea how to do that?

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


what is wrong with that r"\"

2007-07-03 Thread alf
question without words:

 >>> r"\"
   File "", line 1
 r"\"
^
SyntaxError: EOL while scanning single-quoted string
 >>> r"\ "
'\\ '
-- 
http://mail.python.org/mailman/listinfo/python-list


determining the source code and module based on the class

2007-07-15 Thread alf
Hi,

Let's say I have a class defined somewhere:

class A:
pass



now I import (indirectly) a module defining that class (and in fact 
thousands of others defined in hundreds of modules) where all I have is 
a list of them provided:

l=[A,B,C]


now I need a piece of code which based on the class name can point to 
the module as well as the line number where the given class is defined.

Is it doable in Python?


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


subprocess (spawned by os.system) inherits open TCP/UDP/IP port

2007-07-19 Thread alf

Hi,

I need a help with explaining following behavior. Although it is not 
python issue per say, python helped me to write sample programs and 
originally I encountered the issue using python software. So let's 
assume we have two following programs:



[myhost] ~> cat ss.py
import socket
UDPSock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
UDPSock.bind(("",12345))
import os
os.system('python cc.py')

[myhost] ~> cat cc.py
import time
time.sleep(2036)



then I start master one, do ctrl-Z and bg.

[myhost] ~> python ss.py

Suspended
[myhost] ~> bg
[1]python ss.py &
[myhost] ~> ps
UIDPID  PPID  C STIME TTY  TIME CMD
myuser00  3192  3189  0 14:57 pts/000:00:00 -tcsh
myuser00  3247  3192  0 14:57 pts/000:00:00 python ss.py
myuser00  3248  3247  0 14:57 pts/000:00:00 python cc.py



[myhost] ~> netstat -uanp |grep 12345
(Not all processes could be identified, non-owned process info
  will not be shown, you would have to be root to see it all.)
udp0  0 0.0.0.0:12345   0.0.0.0:* 
 3247/python



As expected netstat indicates process 3247 having port allocated. Then I 
kill the master process and interestingly the child inherits the port open.


[myhost] ~> kill 3247
[myhost] ~> netstat -uanp | grep 12345
(Not all processes could be identified, non-owned process info
  will not be shown, you would have to be root to see it all.)
udp0  0 0.0.0.0:12345   0.0.0.0:* 
 3248/python
[1]  + Terminatedpython ss.py



Why it is happening? I know that os.system uses fork, but still this is 
something unexpected.


Thx, Alf



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


Re: subprocess (spawned by os.system) inherits open TCP/UDP/IP port

2007-07-20 Thread alf
Jean-Paul Calderone wrote:

> 
> You can avoid this, if you like.  Set FD_CLOEXEC on the socket after you
> open it, before you call os.system:
> 
>  old = fcntl.fcntl(s.fileno(), fcntl.F_GETFD)
>  fcntl.fcntl(s.fileno(), fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
> 

thx for responding (I was about to send the question to twisted mailing 
list too ;-).


still would like to find out why it is happening (now FD_CLOEXEC 
narrowed may yahooing/googling searches). While realize that file 
descriptors are shared by forked processes it is still weird why the 
port moves to the child process once parent gets killed. what it the 
parent got multiple subprocesses.

Plus it is kind of unintuitive os.system does not protect from such 
behavoir which is for me more an equivalent of like issuing a ne 
wcommand/ starting a process from the shell.

Thx,

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


which is more pythonic/faster append or +=[]

2007-05-08 Thread alf
two ways of achieving the same effect


l+=[n]

or

l.append(n)


so which is more pythonic/faster?

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


distributing python software in jar like fashion

2007-03-14 Thread alf
Hi,

I have a small app which consist of a few .py files. Is there any way to 
distribute it in jar like fashion as a single file I can just run python 
on. I obviously look for platform independent solution.

Thx in advance, A.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SNMP agent

2007-04-04 Thread alf
alain wrote:
> Hi,
> 
> I have a Python app and i would like to add some SNMP agent
> functionality to it.
> I know it's possible to write a sub-agent with netsnmp but it is in C
> and quite complicated.
> I know of YAPSNMP (a wrapper around NETSNMP) but it doesn't seem to
> support agent writing.
> Any suggestion ?
> 
> Thanks to all in advance
> 
> Alain
> 

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


compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-04 Thread alf
Hi,

I want to add some library but it can not be comipled? Here is an output:


D:\>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]


D:\> python setup.py install
running install
running build
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible
binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin
installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.



Thx for the help, Andy
-- 
http://mail.python.org/mailman/listinfo/python-list


wx and SOAPpy interaction

2007-04-12 Thread alf
Hi,

there is problem when I import (python 2.4) wx and SOAPpy at the same 
time. I narrowed the problem to following (on Linux):

 >>import wx
 >>import pyexpat

Traceback (most recent call last):
   File "", line 1, in ?
ImportError:
/apps/public/python_2.4.4/lib/python2.4/lib-dynload/pyexpat.so:
undefined symbol: XML_StopParser


any insight?

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


Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-12 Thread alf
Alex Martelli wrote:

> I would think this error message is as clear as it can be, and then
> some!  It even gives very practical advice on how to work around the
> problem.  Either install VS2003, if you own it or can purchase it, or
> else install mingw32 (which is free and can be downloaded) and use the
> option which the error message tells you to.
> 

well, instructions were clear enough for me. What is hard to get why it 
could not use free M$ compiler which is presumably produces compatible 
objects and libraries.

In fact I played with msvccompiler.py a little bit, get around registry 
paths and was able to produce .pyo file. Then I hit some runtime lib 
issues. In meantime I found precompiled probstat lib so gave up on 
making msvccompiler.py compatible with VS 2008.

Bottomline - it would be nice to have such support.
-- 
alf
-- 
http://mail.python.org/mailman/listinfo/python-list


where to report bug/get help for wxpython

2007-04-12 Thread alf
Hi,

I have another problem with wxpython - that is the best place to report 
bug - evident memory leak on Linux and win32.

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


Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-14 Thread alf
Martin v. Löwis wrote:
>>well, instructions were clear enough for me. What is hard to get why it
>>could not use free M$ compiler which is presumably produces compatible
>>objects and libraries.
> 
> 
> This presumption is incorrect. The compiler does *not* create compatible
> objects and libraries. It links with msvcr8.dll, whereas Python is
> linked with mscvr71.dll; Microsoft does not support mixing CRTs.
> 

complier is just a compiler. perhaps final linking could be somehow 
tweaked to include msvcrt71 instad of 80.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling modules with VS 2008 for python 2.4 prepared with Visual Studio 2003

2007-04-14 Thread alf
Martin v. Löwis wrote:


> You either would have to create a import library for mscvr71.dll
> by hand, or you have to copy one from VS 2003 (breaking its license).


I wonder if copying the probstat.pyd from internet where I it finnaly 
found is not breaking the license:-). it was my final solution. 
otherwise I would probaly it somehow link. I hardly give up.


> P.S. Why does the subject say "VS 2008", anyway? That product has
> not been released yet, and Microsoft is still hoping that it will
> be called VS 2007.

just a mistake. i am not Microsoft fan. Just happened that python app I 
develop is executed on win32.

thx for all insight
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx and SOAPpy interaction

2007-04-17 Thread alf
Amaury Forgeot d'Arc wrote:
> alf a écrit :
> 
>> Hi,
>>
>> there is problem when I import (python 2.4) wx and SOAPpy at the same 
>> time. I narrowed the problem to following (on Linux):
>>
>>  >>import wx
>>  >>import pyexpat
>>
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> ImportError:
>> /apps/public/python_2.4.4/lib/python2.4/lib-dynload/pyexpat.so:
>> undefined symbol: XML_StopParser
>>
>>
>> any insight?
> 
> 
> It seems that the process is trying to load two versions of the "expat" 
> XML library:
> 
> http://mail.python.org/pipermail/python-list/2006-April/377070.html
> 
> The problem is that wxWidgets embeds its own copy of expat. You may have 
> to recompile either python or wxWidgets so that they use the same expat 
> version.
> 

For the record, on my mandriva 2006 box with wxpython and python 2.4 
installed out of distribution DVD this works fine. Problem is with 
python2.4 installed onsome older version of RedHad server edition.

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


trapping DLL import issues without blocking pop up window

2007-11-01 Thread alf
Hi,

  there is following issue: "import cx_Oracle" on windows pops up a nice 
  'DLL missing' window in case there indeed is no CLI.DLL (or something 
like that). Then the exception is raised.

Catching the exception is obviously not a problem, but the popup 
practically blocks the application and requires user intervention.

There could be a legitimate case where Oracle environment is not 
available  yet the program might want to get around it somehow.


any idea how to prevent those popups.

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


globals accros modules

2007-01-10 Thread alf
Hi,
executing main.py reulsts in following:


[EMAIL PROTECTED] andy]$ python main.py
Traceback (most recent call last):
   File "main.py", line 4, in ?
 amodule.f()
   File "/raid/home/andy/amodule.py", line 3, in f
 print a
NameError: global name 'a' is not defined

How can I have global globals without cyclical import?

A.



amodule.py:
def f():
 global a
 print a

main.py:
import amodule
a=1
amodule.f()


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


Re: globals accros modules

2007-01-11 Thread alf
Gabriel Genellina wrote:
> Change a=1 to amodule.a=1

I have multiple command line programs creating 'a' and amodule using it. 
   Plus some import sequence dependency. So it would not work. Currently 
the solution in amodule is:
import __main__
print __main__.a

> If you find yourself doing tricks with the module globals, think about 
> redesigning your application.

For what I do it is good enough. If I hit the same problem, will 
refactor it.

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


Re: Dlaczego ten destruktor nie dziala

2007-02-05 Thread alf
Sulsa wrote:
> sorry, wrong group.

the group is correct but language wrong, did you find out why the 
exception pops up
-- 
http://mail.python.org/mailman/listinfo/python-list


converting u'11\xa022' to '11\xa022'

2007-02-20 Thread alf
Hi,
is there a more elegant way to do that:

''.join([chr(ord(i)) for i in u'11\xa022' ])

-- 
thx, alf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting u'11\xa022' to '11\xa022'

2007-02-20 Thread alf
Jean-Paul Calderone wrote:
>  u'11\xa022'.encode('charmap')

thx a lot. one more question, once a unicode object is created e.g.

u=unicode('hello', 'iso-8859-1')

is there any way to find:
1-original encoding of u
2-list of supported encodings?

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


templatetaizing exceptions

2007-11-12 Thread alf
Hi,

I have a few places in the code where I use:

try:
code_block
except A:
exception_handling


the code block is different each time while exception_handling the same.

What would be the best technique to abstract that out?


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


Re: templatetaizing exceptions

2007-11-13 Thread alf
david wrote:
> On Tue, 13 Nov 2007 06:17:26 -0300, Gabriel Genellina wrote:
> 
>> A function?
>>
>>  try:
>>  code_block
>>  except A:
>>  handle_exception()
> 
> maybe
> 
 def handle(f, *args, **kw):
> ... try:
> ... return f(*args, **kw)
> ... except A:
> ... handle_exception()
> 
 def doSomething():
> ...code_block
> ...
 handle(doSomething)
> 
> cheers

thx - this might work ...

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


why it is invalid syntax?

2007-11-21 Thread alf
Hi,

I wonder why it is an invalid syntax:


 >>> if 1: if 1: if 1: print 1
   File "", line 1
 if 1: if 1: if 1: print 1


or

 >>> if 1: for i in range(10): print i
   File "", line 1
 if 1: for i in range(10): print i

I would expect one could nest :


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


Re: how django discovers changed sources

2008-01-17 Thread alf
Jeff wrote:
> That is the behavior of the development server.  When you are writing
> your application, you don't want to have to manually restart the
> server every time you change a file.  On apache it obviously doesn't
> do that.

thx for clarification, but still I am curious how it is done under the 
hood. it really impressed me ...
-- 
http://mail.python.org/mailman/listinfo/python-list


how django discovers changed sources

2008-01-17 Thread alf
hi,

I started playing with django and accidentally discovered that it 
restarts the server once a source file is touched.

does it use some python's feature or just scans for changs on its one? 
sources?

any idea?

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


Re: how django discovers changed sources

2008-01-17 Thread alf
Jeff wrote:
> On Jan 17, 2:51 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>> 2008/1/17, alf <[EMAIL PROTECTED]>:> Jeff wrote:
>>>> That is the behavior of the development server.  When you are writing
>>>> your application, you don't want to have to manually restart the
>>>> server every time you change a file.  On apache it obviously doesn't
>>>> do that.
>>> thx for clarification, but still I am curious how it is done under the
>>> hood. it really impressed me ...
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>> It checks if modification time on registered files have changed since last 
>> check
>>
>> --
>> -- Guilherme H. Polo Goncalves
> 
> django.utils.autoreload provides the functionality.

thx for the reference,

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


auto import

2008-01-20 Thread alf
Hi,

is there any way to tweak __import__ so it imports module with another 
arbitrary selected module included?

For instance I have my mylibs.py module. Then when I import a 
oneofhundredssmallmodules.py module from other place the mylibs.py is 
automatically imported without a explicit import. The effect is the same 
like below:

module oneofhundredssmallmodules.py:
import * from mylibs


In my software I hundreds of small modules constituting certain custom 
scripts. I need an ability to dynamically control what is imported into 
  them before custom code kicks in.


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


reloading the module imported as 'from ... import ...'

2009-08-09 Thread AlF

Hi,

what is the best way to reload the module imported using 'from ... 
import ...'


Is following a way to do so?


>>> from email.charset import Charset
>>> reload(email.charset)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'email' is not defined
>>>
>>>
>>> import email.charset
>>> reload(email.charset)
Probably it works but I do not like it as I end up with two namespaces 
for the symbol Charset: email.charset.Charset and Charset


Thx,
A.
--
http://mail.python.org/mailman/listinfo/python-list


Re: reloading the module imported as 'from ... import ...'

2009-08-09 Thread AlF

Steven D'Aprano wrote:

On Sun, 09 Aug 2009 20:43:41 -0700, AlF wrote:


Hi,

what is the best way to reload the module imported using 'from ...
import ...'



Have you tried "from ... import ..." again?



I have not because of an assumption that "import" imports the module 
just once. In fact this still works that way:


here is a terminal 1:

$ cat > a.py
a=1
$ cat > a.py
a=2
$


and terminal 2:

>>> from a import a
>>> a
1
>>> a
1
>>> from a import a
>>> a
1
>>>

In spite of changing a.py in fly, the imported a is still 1


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


Req. for comments section "Basic Data" in intro book

2009-11-28 Thread Alf P. Steinbach
I added a section on "basic data" to ch 2 of my writings, an introduction to 
programming (with Python as main language).


The intended reader is someone who is intelligent and wants to learn programming 
but knows little or nothing about it.


As before it would be nice with feedback on this.


  Format: PDF
  http://preview.tinyurl.com/ProgrammingBookP3>


Current contents:

1  Getting started.1
1.1  Python variants, implementations and distributions. 1
1.2  Download and install a Python implementation.   2
1.3  Test-drive the Python interpreter.  2
1.4  Create and run a Python console program.4
1.5  Syntax highlighting and programmers' editors.   6
1.6  Create and run a Python GUI program.7
1.7  About compilation.  9
1.8  About  standalone Windows programs & other kinds.   10
1.9  Browse the local documentation. 11
EOT 12

2  Basic concepts. 1
2.1  Super-basic concept: why programming is not DWIM.   1
2.2  Reported errors.4
2.2.1  Case-sensitity. 4
2.2.2  Syntax / compilation errors.4
2.2.3  Runtime errors / crashes.   5
2.3  A programming exploration tool: turtle graphics.6
2.4  Naming things.  8
2.4.1  Naming actions: routines.   8
2.4.2  Naming data part I: variables.  11
2.4.3  Naming data part II: routine arguments. 13
2.5  Controlling the flow of execution.  14
2.5.1  Repeating actions automatically: loops. 14
2.5.2  Basic comparisions & boolean values.16
2.5.3  Interlude I: a function graph program / about types.17
2.5.4  Automated action choices.   21
2.5.5  Value-producing (function-like) routines.   23
2.5.6  Interlude II: a graph with zeroes marked / about program structure. 26
2.5.7  Dynamically nested actions: recursive routines. 28
2.6  Basic data. 36
2.6.1  Basic fundamental types / strings & concatenation.  36
2.6.2  Indexing and single characters (+ vaguely about sequences in general). 39
2.6.3  Interlude III: a ROT-13 encryption/decryption program, refactoring. 40
2.6.4  Attributes, methods, objects.   43
2.6.5  Doc strings.44
2.6.6  Interlude IV: attribute names as strings, listing str attributes. 45
2.6.7  References. 46
EOT 49

The section on "References", 2.6.7, is about references in Python, it's not a 
list of references. :-)



Cheers,

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


Re: Creating a local variable scope.

2009-11-29 Thread Alf P. Steinbach

* markolopa:


On 18 Sep, 10:36, "markol...@gmail.com"  wrote:

On Sep 11, 7:36 pm, Johan Grönqvist  wrote:

I find several places in my code where I would like tohavea variable
scope that is smaller than the enclosing function/class/module definition.

This is one of the single major frustrations I have with Python and an
important source of bugs for me. Here is a typical situation


Here is another bug that I just got. Twenty minutes lost to find it...

class ValueColumn(AbstractColumn):
def __init__(self, name, header, domain_names):
if type(domain_names) != tuple:
raise ValueError('a tuple of domain names must be given')
for name in domain_names:
if type(name) != str:
raise ValueError('a tuple of domain names must be
given')
self.domain_names = domain_names
super(ValueColumn, self).__init__(name, header)

The upper class was initialized with the wrong name, because the for
loop to check
domain_names used "name" which is also the argument to be passed.

If is an old thread but I am reopening to present real situation where
this Python
"feature" bothers me...


I think if one could somehow declare names as const (final, readonly, whatever) 
then that would cover the above plus much more.



Cheers,

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


Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Alf P. Steinbach

* Esmail:

Ok, this is somewhat unexpected:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.


 >>> -3**2
-9

 >>> x = -3

 >>> x**2
9
 >>>

I would have expected the same result in both cases.

Initially I would have expected -3**2 to yield 9, but I can accept
that ** binds tighter than the unary -, but shouldn't the results
be consistent regardless if I use a literal or a variable?


It is.

>>> -3**2
-9
>>> x = 3
>>> -x**2
-9
>>>

:-)


I guess you expect your expression "x**2" to somehow be evaluated as "-3**2". 
But x doesn't contain text, it contains an integer value that presumably (I 
don't know) is represented in the binary number system, so it's evaluated as 
"(-3)**2". If x contained text and was evaluated as such, pure text replacement, 
then you should be able to write 2 x and have that evaluated as "2 -x"...



Cheers & hth.,

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


Re: Creating a local variable scope.

2009-11-30 Thread Alf P. Steinbach

* Jean-Michel Pichavant:

Steven D'Aprano wrote:

On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote:

 

I think if one could somehow declare names as const (final, readonly,
whatever) then that would cover the above plus much more.



Having real constants is one feature that I miss. Because Python 
doesn't have constants, I find I've lost the discipline to avoid 
"magic numbers" (and strings) in my code.



  
I don't get you, this can be easily avoid with a strong naming 
convention. I mean, despite they are not really constants, you can still 
use variables to name your numbers and string, to give the reader a 
usefull hint on the meaning of your code. Yet it is still a matter of 
discipline, it is sometimes very tempting to put the string directly 
(unlike numbers string can be meaningful sometimes)


It may be surprising how many things turn out to be readonly.

Consider the OP's code:



class ValueColumn(AbstractColumn):
def __init__(self, name, header, domain_names):
if type(domain_names) != tuple:
raise ValueError('a tuple of domain names must be given')
for name in domain_names:
if type(name) != str:
raise ValueError('a tuple of domain names must be given')
self.domain_names = domain_names
super(ValueColumn, self).__init__(name, header)



Here the arguments should ideally be read only names, which would have cought 
the bug of reusing 'name' in the for loop.


But you really wouldn't code this as



class ValueColumn(AbstractColumn):
def __init__(SELF, NAME, HEADER, DOMAIN_NAMES):
if type(DOMAIN_NAMES) != tuple:
raise ValueError('a tuple of domain names must be given')
for name in DOMAIN_NAMES:
# Argh, at this point 'name' is readonly, but cannot express that.
if type(name) != str:
raise ValueError('a tuple of domain names must be given')
SELF.domain_names = domain_names
super(ValueColumn, SELF).__init__(NAME, HEADER)



Or, at least I wouldn't do that.

It's ugly.

And you have to /change the names/ as the readonly-ness changes.


Cheers,

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


Re: Req. for comments section "Basic Data" in intro book

2009-11-30 Thread Alf P. Steinbach

* Alf P. Steinbach:
I added a section on "basic data" to ch 2 of my writings, an 
introduction to programming (with Python as main language).


The intended reader is someone who is intelligent and wants to learn 
programming but knows little or nothing about it.


As before it would be nice with feedback on this.


  Format: PDF
  http://preview.tinyurl.com/ProgrammingBookP3>


Current contents:

1  Getting started.1
1.1  Python variants, implementations and distributions. 1
1.2  Download and install a Python implementation.   2
1.3  Test-drive the Python interpreter.  2
1.4  Create and run a Python console program.4
1.5  Syntax highlighting and programmers' editors.   6
1.6  Create and run a Python GUI program.7
1.7  About compilation.  9
1.8  About  standalone Windows programs & other kinds.   10
1.9  Browse the local documentation. 11
EOT 12

2  Basic concepts. 1
2.1  Super-basic concept: why programming is not DWIM.   1
2.2  Reported errors.4
2.2.1  Case-sensitity. 4
2.2.2  Syntax / compilation errors.4
2.2.3  Runtime errors / crashes.   5
2.3  A programming exploration tool: turtle graphics.6
2.4  Naming things.  8
2.4.1  Naming actions: routines.   8
2.4.2  Naming data part I: variables.  11
2.4.3  Naming data part II: routine arguments. 13
2.5  Controlling the flow of execution.  14
2.5.1  Repeating actions automatically: loops. 14
2.5.2  Basic comparisions & boolean values.16
2.5.3  Interlude I: a function graph program / about types.17
2.5.4  Automated action choices.   21
2.5.5  Value-producing (function-like) routines.   23
2.5.6  Interlude II: a graph with zeroes marked / about program 
structure. 26

2.5.7  Dynamically nested actions: recursive routines. 28
2.6  Basic data. 36
2.6.1  Basic fundamental types / strings & concatenation.  36
2.6.2  Indexing and single characters (+ vaguely about sequences in 
general). 39
2.6.3  Interlude III: a ROT-13 encryption/decryption program, 
refactoring. 40

2.6.4  Attributes, methods, objects.   43
2.6.5  Doc strings.44
2.6.6  Interlude IV: attribute names as strings, listing str attributes. 45
2.6.7  References. 46
EOT 49

The section on "References", 2.6.7, is about references in Python, it's 
not a list of references. :-)


Based on feedback I received in private communications I've improved (I hope) 
the wording in various places, and expanded a bit on the last section.


I've placed the latest version also in Google Docs, without yet removing the 
original  --  the file names are the same but they have different dates.


Comments welcome.


Cheers,

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


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Alf P. Steinbach

* Edward Cherlin:

On Sun, Nov 29, 2009 at 11:34, Brian Blais  wrote:


After a bit of playing, I realized that I couldn't think of many exaples
which use turtle with conditional structures (if- and while- statements),


Repeat is used much more often. but of course we can provide examples
of any behavior you like. I like to use the turtle to generate
sequences, where I can use a conditional to stop when the turtle would
go off the screen. Fibonacci numbers, for example, or exponentials.
Similarly for spirals of various types. Simple cases like those are
easy to do in TA, while more complex sequences could use Python. There
are several fractal examples using loops provided with Sugar on a
Stick, including variations on Siepinksi constructions, and the Koch
Snowflake.


In ch 2 of

  http://preview.tinyurl.com/ProgrammingBookP3>

I use a turtle-generated spiral as the first example of a while loop.

I haven't got that far yet with that chapter, but I halfway plan on including a 
turtle graphics solve-a-maze example, which would/will be an example of 
conditionals with the turtle as a kind of actor making decisions.




or
functions that return values, as opposed to "procedures" like:
def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


Plotting a graph. Some examples of that in ch 2 of aforementioned URL.


Cheers & hth.,

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


Formatting logically nested actions -- Pythonic way?

2009-12-03 Thread Alf P. Steinbach

Hi.

I discovered with tkinter the registration of widgets with layout managers 
(tkinter "geometry" managers, e.g. calls to pack()) needs to be done very 
hierarchically.


And this leads to hierarchical code, which would be nice to indicate by 
indenting, but oops, indenting in Python is syntactically significant...


So first I thought of one routine per widget creation & layout registration, but 
that was very ugly and verbose. Then thought of simply using semicolons but I 
didn't even try that, because I imagined the sheer ugliness. Then I sort of 
landed on the solution below, but although using the language to define a kind 
of special purpose mini-language is common in C++ and Lisp I haven't seen so 
much of that in Python examples, and so I wonder whether this is Pythonic or 
perhaps so extremely un-Pythonic (unconventional) that it's scary  --  I mean, 
calls that do nothing whatsoever, but I think of *visual structure* as very 
important here and IMHO (disregarding Pythonicity issues) worth the overhead...



import tkinter as tk
import contextlib

@contextlib.contextmanager
def this( object ):
yield object

window = tk.Tk()
window.title( "Picture presentation test" )

with this( tk.Frame() ) as display_area:
pic = tk.PhotoImage( file = "lightbulb_off.gif" )
with this( tk.Label( display_area, image = pic ) ) as pic_display:
pic_display.pack( side = "left" )
with this( tk.Frame( display_area, width = 500 ) ) as interaction_area:
with this( tk.Label( interaction_area ) ) as status_line:
status_line.config( text = "The switch is OFF" )
status_line.pack( anchor = "w" )
with this( tk.Button( interaction_area ) ) as toggle_button:
toggle_button.config( text = " Toggle it " )
toggle_button.pack( anchor = "w" )
interaction_area.pack( side = "left" )
    display_area.place( relx = 0.5, rely = 0.5, anchor = "center" ) # Centered

window.mainloop()



Cheers,

- Alf

PS: I see a non-functional width specification in there. Just forgot to remove 
that. And better with code as-is straight from editor than fixing up manually!

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


Are routine objects guaranteed mutable & with dictionary?

2009-12-04 Thread Alf P. Steinbach

Is this guaranteed to work in Python 3.x?


>>> def foo(): pass
...
>>> foo.blah = 222
>>> foo.blah
222
>>> _


Cheers,

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


Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-04 Thread Alf P. Steinbach

* Marco Mariani:

Alf P. Steinbach wrote:



Is this guaranteed to work in Python 3.x?


 >>> def foo(): pass

 >>> foo.blah = 222
 >>> foo.blah
222
 >>> _


I don't see why it shouldn't work.


For example,

  (42).blah = 666

The question is what guarantees or absence thereof the language specification, 
PEPs, intentions, whatever gives/has.




BTW, it's a function, not a "routine"


Wikipedia is your friend, http://en.wikipedia.org/wiki/Subroutine>.


Cheers & hth.,

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


Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-05 Thread Alf P. Steinbach

* Raymond Hettinger:

On Dec 4, 2:03 am, "Alf P. Steinbach"  wrote:

Is this guaranteed to work in Python 3.x?

 >>> def foo(): pass
...
 >>> foo.blah = 222
 >>> foo.blah
222


Yes, function attributes are guaranteed to be writable:
http://www.python.org/dev/peps/pep-0232/


Thanks to all, especially you and Terry.

To quote a suspected bot once rampaging the Microsoft groups, "my question has 
been answered!" :-)


Thread morphing:

Regarding my terminology, "routine" instead "function" that everybody except you 
remarked on, it is of course intentional. After all, my main language is C++. 
And nobody (well, very few) would accuse me of not knowing my C++. :-)


I use the term "routine" because I think the terminology influences what we can 
easily think of and what we therefore tend to use and/or discuss. In that 
respect I think people need to be educated to use more language independent, or 
Eiffel-like, or just historically original, terminology, because


  * "function" is misleading in itself (due to the hijacking of this term in
mathematics), and

  * it gets worse when you can't reasonably talk about "co-functions" or
"function-like functions". :-)

The devolution of terminology has been so severe that now even the Wikipedia 
article on this subject confounds the general concept of "routine" with the far 
more specialized term "sub-routine", which is just one kind of routine. It is of 
course OK with me that there is a default meaning, and that there are several 
different context dependendent meanings. I'm just mentioning this as an example 
that the terminology effectively constrains one's thinking, to the degree that 
even a moderately long encyclopedia article on the subject fails to mention or 
focus on the important aspects. Perhaps modern programmers should be forced to 
study Donald Knuth's TAOCP. Or something.



Cheers,

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


Re: Can't print Chinese to HTTP

2009-12-05 Thread Alf P. Steinbach

* Lie Ryan:

On 12/5/2009 2:57 PM, Gnarlodious wrote:

On Dec 1, 3:06 pm, Terry Reedy wrote:

def print(s): return sys.stdout.buffer.write(s.encode('utf-8'))


Here is a better solution that lets me send any string to the
function:

def print(html): return sys.stdout.buffer.write(("Content-type:text/
plain;charset=utf-8\n\n"+html).encode('utf-8'))


No, that's wrong. You're serving HTML with Content-type:text/plain, it 
should've been text/html or application/xhtml+xml (though technically 
correct some older browsers have problems with the latter).



Why this changed in Python 3 I do not know, nor why it was nowhere to
be found on the internet.

Can anyone explain it?


Python 3's str() is what was Python 2's unicode().
Python 2's str() turned into Python 3's bytes().

Python 3's print() now takes a unicode string, which is the regular string.

Because of the switch to unicode str, a simple print('晉') should've 
worked flawlessly if your terminal can accept the character, but the 
problem is your terminal does not.


The correct fix is to fix your terminal's encoding.

In Windows, due to the prompt's poor support for Unicode, the only real 
solution is to switch to a better terminal.


A bit off-topic perhaps, but that last is a misconception. Windows' [cmd.exe] 
does have poor support for UTF-8, in short it Does Not Work in Windows XP, and 
probably does not work in Vista or Windows7 either. However, Windows console 
windows have full support for the Basic Multilingual Plane of Unicode: they're 
pure Unicode beasts.


Thus, the problem is an interaction between two systems that Do Not Work: the 
[cmd.exe] program's practically non-existing support for UTF-8 (codepage 65001), 
and the very unfortunate confusion of stream i/o and interactive i/o in *nix, 
which has ended up as a "feature" (it's more like a design bug) in a lot of 
programming languages stemming from *nix origins, and that includes Python.


Windows' "terminal", its console window support, is INNOCENT... :-)

In Windows, as opposed to *nix, interactive character i/o is separated at the 
API level. There is integration with stream i/o, but the interactive i/o can be 
accessed separately. This is the "console function" API.


So for interactive console i/o one solution could be some Python module for 
interactive console i/o, on Windows internally using the Windows console 
function API, which is fully Unicode (based on UCS-2, i.e. the BMP).


Cheers,

- Alf



Another workaround is to use a real file:

import sys
f = open('afile.html', 'w', encoding='utf-8')
print("晉", file=f)
sys.stdout = f
print("晉")

or slightly better is to rewrap the buffer with io.TextIOWrapper:
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
print("晉")

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


Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-05 Thread Alf P. Steinbach

* Steven D'Aprano:

On Sat, 05 Dec 2009 11:26:34 +0100, Alf P. Steinbach wrote:


Regarding my terminology, "routine" instead "function" that everybody
except you remarked on, it is of course intentional. [...]


I think you failed to realise that your use of the term was ambiguous. It 
wasn't clear that you were using "routine" as a noun, it seemed like you 
were using it as an adjective, that is, "routine objects" meaning 
"ordinary, common objects one would use routinely".


Your second example was:

(42).blah = 666

(which of course fails, because ints are immutable and you cannot add 
attributes to them). It isn't surprising that we failed to realise you 
were talking about callable objects when exactly 50% of your examples 
were not callable objects.


One example and one counter example. I can't think of why anyone should lump 
these together as examples of the same thing.



Given the context, I think we were completely 
justified in thinking that you meant routine in the sense of commonly 
used.


Bah.



I use the term "routine" because I think the terminology influences what
we can easily think of and what we therefore tend to use and/or discuss.
In that respect I think people need to be educated to use more language
independent, or Eiffel-like, or just historically original, terminology,
because

   * "function" is misleading in itself (due to the hijacking of this
   term in mathematics), and


"Function" in the mathematical sense dates back to Leibniz and Johann 
Bernoulli in the late seventeenth century. I'm not sure, but I think that 
may have pre-dated computers by a couple of years *wink*


Yes, that was my point. Wink.



http://www.gap-system.org/~history/HistTopics/Functions.html



   * it gets worse when you can't reasonably talk about "co-functions"
   or "function-like functions". :-)


"Co-function" is specifically a mathematical term, from trigonometry. 
Sine and cosine are co-functions, because they are related via 
complementary angles: the sine of an angle is equal to the cosine of the 
complementary angle.


That's the only definition Google has found:
http://www.google.co.uk/search?q=define%3Aco-function&ie=UTF-8&oe=UTF-8

Webster's dictionary agrees this is the only definition:
http://www.merriam-webster.com/dictionary/Cofunction

So I have no idea what you think a co-function (or cofunction) is, or why 
you can't talk about it.


Right. That was my point. Wink. Heh heh. :-) Try substituting "routine". That 
is, s/function/routine/g.



As for "function-like functions", I can't think why you would want to use 
that term!


See above. ;-)


If something is a function, it's obviously function-like, in 
the same way that cats are cat-like and chairs are chair-like.


Right, that was my point.

Including that with the C/Python terminology it isn't.


If you want to talk about "function-like objects", or "function-like 
data", or "things that behave like functions but aren't actually 
functions", that is reasonable. We have names for such things: functor 
(from C++, different from functors in Haskell), or callable, or 
(verbosely, in Python) "any object with a __call__ method". But function-

like functions? That would just be a function.


Right.



The devolution of terminology has been so severe that now even the
Wikipedia article on this subject confounds the general concept of
"routine" with the far more specialized term "sub-routine", which is
just one kind of routine.


I'm not sure how to reply to that, since I'm not sure what you think a 
"routine" is in computing.


See the Wikipedia article and allow for some confusion on the part of the 
authors. Or, if you have TAOCP handy, look it up there. However, you may 
disregard Donald Knuth's definition of "reel time" :-), I'm not invoking him as 
an authority on terminology, just a handy accessible source for the general 
meaning of "routine" (disclaimer: haven't looked it up for this posting, so I 
can't guarantee that you'll find it, although as I recall in volume I).



In my experience (which dates back to the early 80s), "routine" has never 
been anything but a generic term without any specific technical meaning. 
That is, one might talk about the "print routines" without caring whether 
they are external programs (say, printer drivers) or internal sub-
routines (functions, procedures, co-routines, methods, or even just a 
chunk of code you GOTO).


Well, my experience is perhaps a bit longer, but not much. And you're on the 
right track. It's a more general term, *and* it has context dependent meanings.




It is of course OK with me that there is a
default meani

Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-06 Thread Alf P. Steinbach

* Dennis Lee Bieber:

On Sat, 05 Dec 2009 11:26:34 +0100, "Alf P. Steinbach" 
declaimed the following in gmane.comp.python.general:

The devolution of terminology has been so severe that now even the Wikipedia 
article on this subject confounds the general concept of "routine" with the far 
more specialized term "sub-routine", which is just one kind of routine. It is of 


Well, if this were a FORTRAN IV text from the mid-70s you'd be
talking about

function subprograms
and
subroutine subprograms


It's in that direction yes, but the distinction that you mention, which is 
essentially the same as Pascal 'function' versus 'procedure', or Visual Basic 
'function' versus 'sub', is just a distinction of two variants of subroutines.


Up above there is the more general concept of a routine, where there are more 
possibilites than just subroutines; Python generators are one example.


As I mentioned earlier, in Eiffel, which is a more modern language than Fortran, 
routines are still called routines. And specialized terms include "routine". So 
it's not like that language independent terminology has been phased out in 
general; it's mostly only in the C syntax family (e.g. Python operators come 
mostly from C) that "function" is, misleadingly and with associated severe 
constraints, used as a general term.



Cheers,

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


Re: Are routine objects guaranteed mutable & with dictionary?

2009-12-06 Thread Alf P. Steinbach

* MRAB:

Alf P. Steinbach wrote:
 > * Dennis Lee Bieber:
 >> On Sat, 05 Dec 2009 11:26:34 +0100, "Alf P. Steinbach"
 >>  declaimed the following in
 >> gmane.comp.python.general:
 >>
 >>> The devolution of terminology has been so severe that now even the
 >>> Wikipedia article on this subject confounds the general concept of
 >>> "routine" with the far more specialized term "sub-routine", which
 >>> is just one kind of routine. It is of
 >>
 >> Well, if this were a FORTRAN IV text from the mid-70s you'd be
 >> talking about
 >>
 >> function subprograms
 >> and
 >> subroutine subprograms
 >
 > It's in that direction yes, but the distinction that you mention,
 > which is essentially the same as Pascal 'function' versus
 > 'procedure', or Visual Basic 'function' versus 'sub', is just a
 > distinction of two variants of subroutines.
 >
 > Up above there is the more general concept of a routine, where there
 > are more possibilites than just subroutines; Python generators are
 > one example.
 >
 > As I mentioned earlier, in Eiffel, which is a more modern language
 > than Fortran, routines are still called routines. And specialized
 > terms include "routine". So it's not like that language independent
 > terminology has been phased out in general; it's mostly only in the C
 > syntax family (e.g. Python operators come mostly from C) that
 > "function" is, misleadingly and with associated severe constraints,
 > used as a general term.
 >
In C there were originally only functions; if you didn't specify a
return type then it would default to 'int' ('void' was a later
addition).

In Python there are only functions; if you don't explicitly return a
value then None is returned.

The distinction between functions and procedures can be helpful in
deciding whether something is Pythonic (for example, in the use of list
comprehensions), but in reality they are all still functions.


I'm sorry, but, first, looking at ways to emulate a syntax, thinking about 
whether something looks like mathematical functions, the eye-candy, is pretty 
irrelevant, at least IMO. To see that it is irrelevant you might consider how 
that works in assembly language. Or you might consider that a call of a C++ 
'void' routine can be used in C++ expressions. I think that even by your mainly 
visual syntax criterion that must be difficult to think of as a "function". 
Another way of looking at it is that the information conveyed by a result 
restricted to N=1 possible significant values, such as Python None or C 
arbitrary value (all possible return values of a non-result-producing routine to 
be treated as the same), is log(N)/log(2) = log(1)/whatever = 0, i.e., the 
routine then produces zero information via its expression result.


Second, what's discussed isn't the distinction between various kinds of 
subroutines, so that wrt. to the earlier thread it's at best a detail.


Although I think that the distinction that you and Dennis raise *is* a useful 
discussion! :-)



Cheers & hth.,

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


More stuff added to ch 2 of my programming intro

2009-12-09 Thread Alf P. Steinbach

  Format: PDF
  http://preview.tinyurl.com/ProgrammingBookP3>

The new stuff, section 2.7, is about programs as simulations and handling data, 
focusing on modeling things. It includes some Python GUI programming. The plan 
is to discuss containers like lists and dictionaries in perhaps two more 
subsections of 2.7, but I'm not quite sure about how to approach that or exactly 
how much to cover, since the intent of ch 2 is to introduce mostly general 
concepts and enable the reader to try out (more or less) interesting things.



Cheers,

- Alf

PS: comments welcome!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Newbies

2009-12-09 Thread Alf P. Steinbach

* rm:

Here is a new tutorial that may be a good starting point for learning
Python.

http://www.themaemo.com/python-for-newbies/


Looks nice.

I have two comments: (1) what is "the N900"?, and (2) the naming convention, 
using 'Num' for a variable and 'clsAddress' for a class, is opposite of the 
usual Python convention where one'd write 'num' and 'Address'.


Shameless plug for my own writings, an introduction to /programming/ for 
newbies, using Python  --  this work is progressing slowly but steadily:


  http://preview.tinyurl.com/ProgrammingBookP3>

which is in Google Docs; a table of contents available as text file (it's not 
complete wrt. to latest stuff I added) and also in the PDF files themselves.


Comments very welcome! :-)


Cheers,

- Alf

PS: The last three or four paragraphs in ch 2 were sort of negative so I've 
replaced them with one single short much more upbeat paragraph. Working...

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


Re: Python for Newbies

2009-12-09 Thread Alf P. Steinbach

* rm:

On Dec 9, 9:46 pm, "Alf P. Steinbach"  wrote:

* rm:


Here is a new tutorial that may be a good starting point for learning
Python.
http://www.themaemo.com/python-for-newbies/

Looks nice.

I have two comments: (1) what is "the N900"?, and (2) the naming convention,
using 'Num' for a variable and 'clsAddress' for a class, is opposite of the
usual Python convention where one'd write 'num' and 'Address'.

Shameless plug for my own writings, an introduction to /programming/ for
newbies, using Python  --  this work is progressing slowly but steadily:

   http://preview.tinyurl.com/ProgrammingBookP3>

which is in Google Docs; a table of contents available as text file (it's not
complete wrt. to latest stuff I added) and also in the PDF files themselves.

Comments very welcome! :-)

Cheers,

- Alf

PS: The last three or four paragraphs in ch 2 were sort of negative so I've
replaced them with one single short much more upbeat paragraph. Working...


One of the reasons I started writing this tutorial was because I found
the lot of existing tutorials lacking in their approachability by
people new to programming.  Just about all of them were either not
comprehensive enough, or seemed written by geniuses for geniuses. I
hope you will allow me to quote a little excerpt from your tutorial
that makes my point quite eloquently:

"I have to use as-yet-unexplained language features in order to
present examples that do relevant things, because it would be too much
to explain the language features & concepts here.  These features are
explained in later chapters, so for now you can just adopt a very
casual attitude, hey, it works!"

Don't get me wrong, your approach probably works for a certain type of
people.  But there are a lot of us that find this approach very
difficult to follow.  The approach of this tutorial is gradually
introduce new concepts so that the student can follow along at a
logical and pleasant pace.


Well, we agree on that. :-)

You just quoted the above a little out of context. It's about the code examples 
in ch 1. Ch 1 is /not/ about programming: it's about tool usage, getting 
started, and next to nothing about the language or programming is discussed.


So from my POV as author that criticism is like criticizing a bus driver for not 
explaining the technical workings of the bus when he's taking potential new bus 
drivers on a tour of the bus routes they may/will be driving later.


Of course if the potential new drivers expect to be educated about the bus' 
technical stuff on that tour, just ignoring or not registering the up-front 
information about the tour, then they may grumble about only being shown some 
scenery, and what's this all about places and distances and routes?


So, I think you read that with wrong expectations.



 Yes, it has a disadvantage.  The examples
can't be too elaborate.


But here we disagree somewhat.

If you look at ch 2 you'll see that with Python examples can be quite impressive 
without using more than just the tiniest little subset of the language.


That is, when one has room to discuss things (difficult in an web based tutorial 
like yours, or like my once-upon-a-time C++ tutorial, but now I do have that 
room for discussion and guidance!) then a student's first examples do not need 
to be text only or dry academic. :-)




 But, the purpose of tutorial, to teach the
language, is better accomplished this way.  If I was teaching a group
of people the English language, I would not go about doing so with a
George Gordon Byron poem.


Oh, I think you should!

Especially considering that his daughter Augusta Ada was the world's first 
programmer and could be suspected of having an affair with Augustus de Morgan 
(who together with George Boole invented boolean logic, they published their 
works in the same week, and anyway was Augusta's private math tutor).


Or perhaps start more easy, with Augustus de Morgan's infamous recursive fleas 
poem (ah, one may suspect some connection to Lord Byron there)!



Cheers,

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


  1   2   3   4   5   6   7   >