ANN: Python training "text movies"

2013-01-12 Thread AK


I don't know what to call these, so for now I'll call them "training
text movies" until I come up with a better name..

I hope these will be helpful, especially to new students of Python.

http://lightbird.net/larks/tmovies.html


I'll be adding more in the next few days...

 - mitya


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


Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread AK

On 2018-05-10 12:43, Virgil Stokes wrote:

Module info:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 
bit (AMD64)]

[...]

I tried first to use Python's built-in datetime module as follows:

from datetime import date, timedelta

  d0 = date(2018,02,01)

This gave the following error:

Syntax Error: invalid token: C:\Users\Virgil Stokes\Desktop\Important 
Notes_Files\CheckProcessingDate_02.py, line 7, pos 17

d0 = date(2018,02,01)

Then I used pip to install the datetime module and the same error 
occurred! However, when I removed the leading 0's no syntax error was 
reported and the correct result was returned.


It is not a datetime problem. It is PY3 compatibility problem.
Try (should work from both PY2 and PY3):

d0 = date(2018,0o2,0o1)

AK
--
https://mail.python.org/mailman/listinfo/python-list


Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread AK

On 2018-05-10 13:52, D'Arcy Cain wrote:

On 2018-05-10 07:39 AM, AK wrote:

Try (should work from both PY2 and PY3):

d0 = date(2018,0o2,0o1)


Bad advice.  Those numbers are decimal, not octal,  You should use
"date(2018,2,1)" here.  Works in PY2, PY3 and for my birthday, Sept 4.


It was only an evidence that it was PY3/PY2 compatibility issue - not a 
solution/correct way.
Of course simple use of decimal constants like date(2018, 2, 1) is most 
correct.


AK
--
https://mail.python.org/mailman/listinfo/python-list


Tkinter question.

2006-06-17 Thread ak
Hi, I'd like to create buttons on the fly that will call the same
function, and the function in question has to know what was the name of
the button that called it. Unless there is a preferred way for doing
this.. Perhaps creating a new function on the fly along with the new
button? Please help.. thanks!

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


Re: Tkinter question.

2006-06-17 Thread ak
Update: I found a way to do what I want with RadioButton with option
indicatoron=0 which creates a bunch of what looks like regular buttons
except that when one is pressed the other one is depressed and the
value of the same variable is changed.

Thanks dear me.

[EMAIL PROTECTED] wrote:
> Hi, I'd like to create buttons on the fly that will call the same
> function, and the function in question has to know what was the name of
> the button that called it. Unless there is a preferred way for doing
> this.. Perhaps creating a new function on the fly along with the new
> button? Please help.. thanks!

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


ANN: Tobu 0.4j

2008-03-24 Thread AK
This is an initial announcement.

Tobu is a freeform database / tagger / PIM and more. It works in both 
Linux and Windows and uses wxPython framework and pysqlite.

Comments, suggestions, feature requests and critique are gladly
appreciated.

Tutorial with links to download page and to graphical overview page is 
located at the following link. It's best to start with graphical 
overview page that shows screenshots of main window and menus with 
thorough explanations of functionality of most items.

http://www.lightbird.net/tobu/



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


urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-01-19 Thread ak
Hi everyone,

I have a problem with urllib2 on this particular url, hosted on an
Oracle HTTP Server

http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=phone&null

which gets 302 redirected to 
https://www.orange.sk/eshop/sk/catalog/post/phones.html,
after setting a cookie through the Set-Cookie header field in the 302
reply. This works fin with firefox.

However, with urllib2 and the following code snippet, it doesn't work



import cookiejar
import urllib2

cookiejar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?
type=post&subtype=phone&null'
req = urllib2.Request(url, None)
s=opener.open(req)


Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
  File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.5/urllib2.py", line 419, in error
result = self._call_chain(*args)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302
return self.parent.open(new)
  File "/usr/lib/python2.5/urllib2.py", line 381, in open
response = self._open(req, data)
  File "/usr/lib/python2.5/urllib2.py", line 399, in _open
'_open', req)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open
return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
r = h.getresponse()
  File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
response.begin()
  File "/usr/lib/python2.5/httplib.py", line 385, in begin
version, status, reason = self._read_status()
  File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine

Trying the redirected url directly doesn't work either (trying with
Firefox will give an HTML error page, as the cookie is not set yet,
but trying with urllib2 gives the same exception as previously,
whereas it should return the HTML error page)
This works correctly on other urls on this website (http(s)://
www.orange.sk).

Am I doing anything wrong or is this a bug in urllib2 ?

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


Re: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-01-19 Thread ak
On Jan 19, 10:00 pm, ak  wrote:
> Hi everyone,
>
> I have a problem with urllib2 on this particular url, hosted on an
> Oracle HTTP Server
>
> http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p...
>
> which gets 302 redirected 
> tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html,
> after setting a cookie through the Set-Cookie header field in the 302
> reply. This works fin with firefox.
>
> However, with urllib2 and the following code snippet, it doesn't work
>
> 
> import cookiejar
> import urllib2
>
> cookiejar = cookielib.LWPCookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?
> type=post&subtype=phone&null'
> req = urllib2.Request(url, None)
> s=opener.open(req)
> 
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.5/urllib2.py", line 387, in open
>     response = meth(req, response)
>   File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
>     'http', request, response, code, msg, hdrs)
>   File "/usr/lib/python2.5/urllib2.py", line 419, in error
>     result = self._call_chain(*args)
>   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302
>     return self.parent.open(new)
>   File "/usr/lib/python2.5/urllib2.py", line 381, in open
>     response = self._open(req, data)
>   File "/usr/lib/python2.5/urllib2.py", line 399, in _open
>     '_open', req)
>   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open
>     return self.do_open(httplib.HTTPSConnection, req)
>   File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
>     r = h.getresponse()
>   File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
>     response.begin()
>   File "/usr/lib/python2.5/httplib.py", line 385, in begin
>     version, status, reason = self._read_status()
>   File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
>     raise BadStatusLine(line)
> httplib.BadStatusLine
>
> Trying the redirected url directly doesn't work either (trying with
> Firefox will give an HTML error page, as the cookie is not set yet,
> but trying with urllib2 gives the same exception as previously,
> whereas it should return the HTML error page)
> This works correctly on other urls on this website (http(s)://www.orange.sk).
>
> Am I doing anything wrong or is this a bug in urllib2 ?
>
> -- ak


Actually, I was wrong on the last point, this does *not* work on
https://www.orange.sk (but does on http://www.orange.sk). IMHO, this
means either urllib2 or the server misimplemented HTTPS.

Here's some output with debuglevel=1 :

>>> opener.open(urllib2.Request('http://www.orange.sk/', None, headers))
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Mon, 19 Jan 2009 21:44:03 GMT
header: Server: Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP-
Server
header: Set-Cookie:
JSESSIONID=0a19055a30d630c427bda71d4e26a37ca604b9f590dc.e3eNaNiRah4Pe3aSch8Sc3yOc40;
path=/web
header: Expires: Mon, 19 Jan 2009 21:44:13 GMT
header: Surrogate-Control: max-age="10"
header: Content-Type: text/html; charset=ISO-8859-2
header: X-Cache: MISS from www.orange.sk
header: Connection: close
header: Transfer-Encoding: chunked
>

>>> opener.open(urllib2.Request('https://www.orange.sk/', None, headers))
reply: ''
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/urllib2.py", line 381, in open
response = self._open(req, data)
  File "/usr/lib/python2.5/urllib2.py", line 399, in _open
'_open', req)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open
return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
r = h.getresponse()
  File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
response.begin()
  File "/usr/lib/python2.5/httplib.py", line 385, in begin
version, status, reason = self._read_status()
  File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine

As you can see the reply from the server seems empty (which results in
the BadStatusLine exception)

Any help greatly appreciated.

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


Re: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-01-21 Thread ak
On Jan 20, 1:14 am, Steven D'Aprano
 wrote:
> On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote:
> > Hi everyone,
>
> > I have a problem with urllib2 on this particular url, hosted on an
> > Oracle HTTP Server
>
> >http://www.orange.sk/eshop/sk/portal/catalog.html?
>
> type=post&subtype=phone&null
>
>
>
> > which gets 302 redirected to
> >https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a
> > cookie through the Set-Cookie header field in the 302 reply. This works
> > fin with firefox.
>
> > However, with urllib2 and the following code snippet, it doesn't work
>
> Looking at the BadStatusLine exception raised, the server response line
> is empty. Looking at the source for httpllib suggests to me that the
> server closed the connection early. Perhaps it doesn't like connections
> from urllib2?
>
> I ran a test pretending to be IE using this code:
>
> cookiejar = cookielib.LWPCookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?'\
>     'type=post&subtype=phone&null'
> agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; " \
>     "NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
> headers = {'User-Agent': agent}
> req = urllib2.Request(url, data=None, headers=headers)
> try:
>     s=opener.open(req)
> except httplib.BadStatusLine, e:
>     print e, e.line
> else:
>     print "Success"
>
> but it failed. So the problem is not as simple as changing the user-agent
> string.
>
> Other than that, I'm stumped.
>
> --
> Steven

Thanks a lot for confirming this. I also tried with different headers,
including putting *exactly* the same headers as firefox (including
Connection:keep-alive by modifying httplib), it still doesn't work.
The only possible explanation for me is that python's httplib doesn't
handle SSL/TLS 'properly' (not necessarly in the sense of the TLS
spec, but in the sense that every other browser can connect properly
to this website and httplib can't)

If anyone knows an Oracle HTTPS server to confirm this on another
server, it would be nice...
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-03-01 Thread ak
which website have you tested it on ?
My tests were basically on https://www.orange.sk and http://www.orange.sk
(the first fails, and not the second one, which led me to think
there's a bug in python's SSL implementation for this particular web
server) (Oracle) with python 2.5



On Feb 19, 1:57 pm, O Peng  wrote:
> I'm running into a similar problem with the BadStatusLine.
> The source code for httplib.py in the problem is as follows:
>
> class HTTPResponse:
>     ...
>     def _read_status(self):
>         line = self.fp.readline()
>         ...
>         if not line:
>             # Presumably, the server closed the connection before
>             # sending a valid response.
>             raise BadStatusLine(line)
>
> However, I found that right before the 'raise BadStatusLine(line)'
> when I ran the following:
>
> restOfResponse = self.fp.read()
> print restOfResponse
>
> restOfResponse is NOT empty.  In fact, when I run self.fp.read() at
> the beginning of the begin() function, it is not empty at all.
> This leads me to believe there is a bug with the self.fp.readline()
> (socket._fileobject.readline()) function.  For me it only fails
> sometimes.
>
> This behavior is only observed on Windows, Python 2.5.  Running it on
> Mac OS X, Python 2.5 yielded no problems.
>
> On Jan 19, 3:48 pm, ak  wrote:
>
> > On Jan 19, 10:00 pm, ak  wrote:
>
> > > Hi everyone,
>
> > > I have a problem withurllib2on this particular url, hosted on an
> > > Oracle HTTP Server
>
> > >http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p...
>
> > > which gets 302 redirected 
> > > tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html,
> > > after setting a cookie through the Set-Cookie header field in the 302
> > > reply. This works fin with firefox.
>
> > > However, withurllib2and the following code snippet, it doesn't work
>
> > > 
> > > import cookiejar
> > > importurllib2
>
> > > cookiejar = cookielib.LWPCookieJar()
> > > opener =urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> > > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?
> > > type=post&subtype=phone&null'
> > > req =urllib2.Request(url, None)
> > > s=opener.open(req)
> > > 
>
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > >   File "/usr/lib/python2.5/urllib2.py", line 387, in open
> > >     response = meth(req, response)
> > >   File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
> > >     'http', request, response, code, msg, hdrs)
> > >   File "/usr/lib/python2.5/urllib2.py", line 419, in error
> > >     result = self._call_chain(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
> > >     result = func(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302
> > >     return self.parent.open(new)
> > >   File "/usr/lib/python2.5/urllib2.py", line 381, in open
> > >     response = self._open(req, data)
> > >   File "/usr/lib/python2.5/urllib2.py", line 399, in _open
> > >     '_open', req)
> > >   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
> > >     result = func(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open
> > >     return self.do_open(httplib.HTTPSConnection, req)
> > >   File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
> > >     r = h.getresponse()
> > >   File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
> > >     response.begin()
> > >   File "/usr/lib/python2.5/httplib.py", line 385, in begin
> > >     version, status, reason = self._read_status()
> > >   File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
> > >     raise BadStatusLine(line)
> > > httplib.BadStatusLine
>
> > > Trying the redirected url directly doesn't work either (trying with
> > > Firefox will give an HTML error page, as the cookie is not set yet,
> > > but trying withurllib2gives the same exception as previously,
> > > whereas it should return the HTML error page)
> > > This works correctly on other urls on this website 
> > > (http(s)://www.orange.sk).
>
> > > Am I doing anything wrong or is this a bug inurllib2?
>
&

Re: What do you think of ShowMeDo

2009-05-01 Thread AK

Ben Finney wrote:

Astley Le Jasper  writes:


I've just stumbled over this (http://showmedo.com/) and being the very
visual person I am, it seems like it could be a good way to learn
about python. However, before I smack down $60, I wondered if anyone
had any opinions on it. My gut feel is that it could be pretty good.


I commend you on your prudence.

The site makes a big deal about helping people with free software. But
their videos are in non-free formats, with Flash being the only option I
could see.

The content appears only to play *in* a browser (I couldn't find any
download links to watch the video offline), making it a pain for anyone
without extremely fast internet.

They require Yet Another Bloody Site-specific Authentication, instead of
allowing login with an existing OpenID as provided by any of the
hundreds of millions of accounts people already have.

Those barriers are enough that I haven't yet *seen* any of their content
to know if it's worth paying for.



I'd like to defend showmedo a bit here.

First, re: UI. If I go to the front page and see something in the 
'incoming tutorials' section on the right that interests me, and

click on it, (let's say, python beginners - file i/o), I get to
the page that indeed does not start showing a video right away,
but that makes sense because most topics contain a number of collections 
of videos, since you don't know which of these a visitor wants to see, 
you have to show him the choices. On this page I immediately see a 
'video tutorials' section on the left, where you can either click on 
title or the image thumbnail. On the next page I see a thumbnail that 
has a 'play' arrow overlayed on it and 'click to play' in bold font. 
It's the most noticeable item on the page. If you click on that, it 
brings up a video screen that - here I have to agree this is one click 
too many - you have to again click to start the video, however, in my 
experience, this is very common on sites that embed video players, I'd 
say about 60-70% of them will ask you to make that extra click to start 
playing. That video player screen has a play arrow overlayed over it and 
also common video controls on the bottom, so it's really a no-brainer to 
click on the play arrow in the center or on the play arrow on one of the 
controls.


All of this took me no more than 4-5 seconds to get to the video. I did 
visit the site before but when I was on my first visit, it did not take 
any longer than that, either.


So, if using these videos saves me more than 4-5 seconds of learning 
time, I'm already ahead.


Secondly, in regard to use of flash videos: if you have a slow 
connection you can pause the video and wait for it to buffer fully. I 
haven't worked with free alternatives to flash so I can't comment on 
that, it's a matter of how mature are the free/open tools to do the same 
thing as flash authoring software and how easy it is to install them on 
  firefox and IE. If they're hard to install on IE, it seems reasonable 
to  me to use flash, because otherwise you'll seem too elite and 
exclusive and push away too many well-meaning people.


Re: site specific auth. You don't need that to watch videos. You need it
for some other things like downloading them--as I mentioned above, you 
can prebuffer video if you have a slower connection, so downloading them 
is not really crucial. Even if you do want to set up an account, it 
should not take longer than a couple of minutes. The way I think about 
this is I try to look at the benefit provided by the site and the cost 
of using the site: some of these videos are very good and I'm sure that 
they saved me many hours of slower book learning, therefore spending 2
minutes on registration would be well worth it (although I did not 
register because I had no need for that). They could set up the OpenID 
thing but with limited time I think it's more useful to create new 
content rather than work on such non-essential niceties (although I 
really don't know how much effort it is to add OpenID support...)


All in all, nothing in this world is 100% perfect and this site provides
great content for free (well, most of it), and it's obvious that 
creators spent hundreds of hours of their time to make this available to 
community and paid content will only probably recoup the hosting fees if 
that. So, how about a little kudos where it's due? A bit less nitpicking 
and a bit more appreciation?


Just my humble opinion, that's all. (I'm not connected to the site in 
any way, I did watch a few dozen videos some time ago).


-ak (rainy)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with sys.stout.flush()

2009-05-23 Thread AK

Joel Ross wrote:

Rhodri James wrote:

On Sat, 23 May 2009 18:19:11 +0100, Joel Ross  wrote:


Now I can move onto next one.


Except that you still have the interesting issue that your environment
isn't responding to '\r' correctly, which worries me rather.  Or did
you never test that?

Yeah I gave the "\r" a go and it kept printing out on a new line I will 
look into it.


Thanks for the heads up


What happens when you run this little program:

import time, sys

print "ONE",
sys.stdout.flush()
time.sleep(0.5)
print "\rTWO",
sys.stdout.flush()
time.sleep(0.5)


The idea is that it should print ONE, flush it, sleep .5 sec so 
that you can see 'ONE', then return to start of line, print TWO, 
flush it so you can read it, and sleep another 0.5 sec.


NOTE comma after print statement.

Does that work for you?

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


Python-by-example - new online guide to Python Standard Library

2008-04-01 Thread AK
Hello,

I find that I learn easier when I go from specific examples to a more 
general explanation of function's utility and I made a reference guide 
that will eventually document all functions, classes and methods in 
Python's Standard Library. For now, I covered about 20 most important 
modules. I will be adding more modules and eventually I'll cover 
everything. Here's my progress so far, let me know if this is useful;
I'll be glad to hear comments/suggestions/etc:

http://www.lightbird.net/py-by-example/

-- 
  -ak
   Tobu | http://www.lightbird.net/tobu/ | Freeform DB / Tagger / PIM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-02 Thread AK
Terry Reedy wrote:
> "AK" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
> || I'll be glad to hear comments/suggestions/etc:
> |
> | http://www.lightbird.net/py-by-example/
> 
> Using - as the example/return delimiter does not work.
> If you do not want to substantially lengthen the document by going to
> 
>>>> sqrt(9)
> 3
> 
> then use Python's a comment symbol.
> 
> sqrt(9) # 3
> -or-
> sqrt(9) # returns 3 (but I think I prefer the first)
> 
> which clearly is not an arithmetic expression and which can be 
> cut-and-pasted into the interactive interpreter.  This also works nicely 
> for invalid examples.
> 
> sqrt(-9) # raises ValueError
> 
> Terry Jan Reedy
> 
> 
> 
> 
> 
> 
> 

Thanks to everybody who replied, I will implement the change as per 
Terry's advice. I'm still considering whether to use the standard 
interpreter syntax, i.e. >>> ... \n result; my reason for not doing that 
is that I will often have a whole screen of function / result lines and 
if I were to add a new line for the result, that'd make two pages out of 
one, which I think is a bit too much. In current docs there are not so 
many examples, so that space is not multiplied quite so much, and using 
  interactive interpreter way of showing result is not nearly as much of 
a problem. However, I'm still thinking this over and it seems that 
almost everyone wants to see it done in that way, I might still go for 
two lines. I'll also be posting updates as the work progresses..

thx,

-- 
  -ak
   Tobu | http://www.lightbird.net/tobu/ | Freeform DB / Tagger / PIM
   Python-by-Example | http://www.lightbird.net/py-by-example/ | Guide 
to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-02 Thread AK
CM wrote:
> On Apr 2, 2:50 pm, AK <[EMAIL PROTECTED]> wrote:
>> Terry Reedy wrote:
>>> "AK" <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
>>> || I'll be glad to hear comments/suggestions/etc:
>>> |
>>> |http://www.lightbird.net/py-by-example/
>>> Using - as the example/return delimiter does not work.
>>> If you do not want to substantially lengthen the document by going to
>>>>>> sqrt(9)
>>> 3
>>> then use Python's a comment symbol.
>>> sqrt(9) # 3
>>> -or-
>>> sqrt(9) # returns 3 (but I think I prefer the first)
>>> which clearly is not an arithmetic expression and which can be
>>> cut-and-pasted into the interactive interpreter.  This also works nicely
>>> for invalid examples.
>>> sqrt(-9) # raises ValueError
>>> Terry Jan Reedy
>> Thanks to everybody who replied, I will implement the change as per
>> Terry's advice. I'm still considering whether to use the standard
>> interpreter syntax, i.e. >>> ... \n result; my reason for not doing that
>> is that I will often have a whole screen of function / result lines and
>> if I were to add a new line for the result, that'd make two pages out of
>> one, which I think is a bit too much. In current docs there are not so
>> many examples, so that space is not multiplied quite so much, and using
>>   interactive interpreter way of showing result is not nearly as much of
>> a problem. However, I'm still thinking this over and it seems that
>> almost everyone wants to see it done in that way, I might still go for
>> two lines. I'll also be posting updates as the work progresses..
>>
>> thx,
>>
>> --
>>   -ak
>>Tobu |http://www.lightbird.net/tobu/| Freeform DB / Tagger / PIM
>>Python-by-Example |http://www.lightbird.net/py-by-example/| Guide
>> to LibRef
> 
> You should also change the look of the page to be more high-contrast.
> The grayish text in a gray box and the light green text...all too
> subtle to see.  Not easy for well-sighted people let alone those with
> poorer vision.  Try make things visually very obvious, bolded headers,
> etc.  If so, and with the change of showing the result not with an "-"
> symbol, it will be much stronger.  Thank you for doing it.

Okay, will do. In fact this is the second time in as many days that I 
get a comment on my proposed designs to use more contrasted text vs. 
background (in fact, for the other design about 3-4 people mentioned 
this topic). I really had no idea many people have trouble with that. To 
me, less contrasted text looks smoother and more aesthetically pleasing 
to the eye, unless I have to read 3 pages or more of condensed text. I 
also do eye excercises religiously every day:-), so this may train the 
eyes to see small details better, but I design for other people to use, 
therefore I will of course try to make it as easy to read for as many 
people as possible.. Thanks for the comment! I will update the site 
tomorrow morning with all the changes..


-- 
  -ak
   Tobu | http://www.lightbird.net/tobu/ | Freeform DB / Tagger / PIM
   Python-by-Example | http://www.lightbird.net/py-by-example/ | Guide 
to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-03 Thread AK
AK wrote:
> Hello,
> 
> I find that I learn easier when I go from specific examples to a more 
> general explanation of function's utility and I made a reference guide 
> that will eventually document all functions, classes and methods in 
> Python's Standard Library. For now, I covered about 20 most important 
> modules. I will be adding more modules and eventually I'll cover 
> everything. Here's my progress so far, let me know if this is useful;
> I'll be glad to hear comments/suggestions/etc:
> 
> http://www.lightbird.net/py-by-example/
> 

I uploaded an updated site incorporating most of the suggestions I 
received and fixing some errors along the way. I will be adding more 
examples to modules that are already covered and will try to add more 
modules during the following week. Thanks again to all who posted advice 
and comments!

-- 
  -ak
   Tobu | http://www.lightbird.net/tobu/ | Freeform DB / Tagger / PIM
   Python-by-Example | http://www.lightbird.net/py-by-example/ | Guide 
to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-03 Thread AK
AK wrote:
> 
> I uploaded an updated site incorporating most of the suggestions I 
> received and fixing some errors along the way. I will be adding more 
> examples to modules that are already covered and will try to add more 
> modules during the following week. Thanks again to all who posted advice 
> and comments!
> 

I also mapped the site to a subdomain so that it's easier to access 
quickly: http://pbe.lightbird.net/ where 'pbe' stands for 
'Python-by-Example'.

-- 
   -ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-04 Thread AK
shurik wrote:
> that's great! thanks for putting this together. what about the inspect
> module? and particularly getsource :)
> 

Glad you like it! I will add every module eventually, but I'll put 
inspect up on top of todo list.

-- 
   -ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-05 Thread AK
ivan wrote:
> Very cool.
> Have you thought about making a printable version that doesn't wrap
> any lines that shouldn't be and has page breaks at good spots?
> 
> --
> ivan

Hi ivan, I will work on that after I finalize modules that are already 
there. I think this would be better than having people print out the 
guide and then either have print out again in a couple of weeks or stuck 
with using a very outdated guide. So, I think it will be one to three
weeks at most before printable version is available..

Glad you like Python by Example!

thx,

-- 
   -ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN]: Python-by-Example updates

2008-04-11 Thread AK
Python-by-Example is a guide to LibRef, aiming to give examples
for all functions, classes, modules, etc. Right now examples
for functions in some of the most important modules are
included.

Over the last week, I've added examples for the following
modules: re special characters, inspect, shutil, tempfile,
traceback. I've also got many comments (thanks!) on formatting &
colors and fixed them; I've also made the guide more suitable
for printing, although it's not perfect still (no pagebreaks),
that will be fixed later when I add more examples.

Here's the location of Python-by-Example:

http://pbe.lightbird.net/

thanks,

-- 
   -ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN]: Python-by-Example updates

2008-04-12 Thread AK
Méta-MCI (MVP) wrote:
> Hi!
> Good!  Thanks.
> I found a bad link, for  "traceback module"
> @-salutations
> 
> Michel Claveau
> 

You're right! I forgot to upload that file, it's fixed now -
thanks for noticing!

-- 
   -ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN]: Python-by-Example updates

2008-04-12 Thread AK
Max Erickson wrote:
> AK <[EMAIL PROTECTED]> wrote:
> 
>> Python-by-Example is a guide to LibRef, aiming to give examples
>> for all functions, classes, modules, etc. Right now examples
>> for functions in some of the most important modules are
>> included.
>>
>> http://pbe.lightbird.net/
>>
>> thanks,
>>
> 
> The second set of examples on the page for decimal doesn't look quite 
> right.
> 
> The first couple of lines:
> 
> getcontext().prec = 6   # Decimal('3.0')
> Decimal("3.0")  # Decimal('3.1415926535')
> 
> I would assume that the " = 6" isn't getting processed correctly.
> 
> 
> max
> 

That block of examples was completely mis-formatted.. it should
really be like this:

getcontext().prec = 6
Decimal('3.0') # Decimal("3.0") [precision will be
# applied after an operation, e.g. addition]
Decimal('3.1415926535')# Decimal("3.1415926535")
Decimal('3.1415926535') + Decimal('2.7182818285')   # Decimal("5.85987")

I fixed it now, thanks for the report!

-- 
ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Tobu-0.5.0

2008-04-13 Thread AK
Tobu 0.5.0 is now available.

Tobu is something between a freeform information organizer and a database.

Changes since last version were:

Added multiple undo/redo, toolbar icon for list recent; Fixed loading a 
previously selected item from listing, disabled closing of last 
remaining tab, fixed panes disappearing when dragged all the way down or 
up, fixed removing of favorites, changed last used tag to pop to the top 
of recently used tags, fixed tab key deleting tags when they are 
selected, set exact match in filter dropdown to highlight ahead of 
inexact matches, fixed replacing file name when dragged and dropped 
instead of appending to old filename, removed 'new copy' icon from 
toolbar, fixed gvim not saving changes in linux when set as external 
editor - see note in tutorial, fixed saved views / saved templates 
interfering with each other, automatic windows installer was added.

Tobu's homepage is here:

http://tobu.lightbird.net

-- 
ak
Tobu | http://tobu.lightbird.net/ | Freeform DB / Tagger / PIM
Python-by-Example | http://pbe.lightbird.net/ | Guide to LibRef
-- 
http://mail.python.org/mailman/listinfo/python-list


Create video with text?

2009-11-11 Thread AK
Hi, what would be the best python package (or a framework that can be 
scripted in python) that can make a video with text moving around, 
jumping, zooming in/out and various other text effects? See the 
following link for an example:



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


Socket error 98 "Address already in use"

2010-06-17 Thread AK
Hi, I'm trying to make a little mp3 server / client and I'm running into
a problem with the Socket error 98 "Address already in use". The error
doesn't happen right away, I can send 3-4 commands, disconnecting and
reconnecting and they work fine and then I get this error and the client
can no longer connect, although the client side doesn't get any errors.
Here's the relevant code:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
try: self.player(conn, addr)
except: pass
conn.close()
s.close()
del s


.. and on client:


HOST = ''
PORT = 50025
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect((HOST, PORT))


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


Re: Socket error 98 "Address already in use"

2010-06-17 Thread AK
On 06/17/2010 07:21 PM, AK wrote:
> Hi, I'm trying to make a little mp3 server / client and I'm running into
> a problem with the Socket error 98 "Address already in use". The error
> doesn't happen right away, I can send 3-4 commands, disconnecting and
> reconnecting and they work fine and then I get this error and the client
> can no longer connect, although the client side doesn't get any errors.
> Here's the relevant code:
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> s.bind((HOST, PORT))
> s.listen(1)
> conn, addr = s.accept()
> try: self.player(conn, addr)
> except: pass
> conn.close()
> s.close()
> del s
> 
> 
> .. and on client:
> 
> 
> HOST = ''
> PORT = 50025
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> s.connect((HOST, PORT))
> 
> 
> Thanks! -ak


I forgot to add that I'm on Ubuntu 9.10 and using python 2.6. -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket error 98 "Address already in use"

2010-06-17 Thread AK
On 06/17/2010 08:19 PM, Grant Edwards wrote:
> On 2010-06-17, AK  wrote:
>> Hi, I'm trying to make a little mp3 server / client and I'm running into
>> a problem with the Socket error 98 "Address already in use". The error
>> doesn't happen right away, I can send 3-4 commands, disconnecting and
>> reconnecting and they work fine and then I get this error and the client
>> can no longer connect, although the client side doesn't get any errors.
>> Here's the relevant code:
>>
>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>> s.bind((HOST, PORT))
>> s.listen(1)
>> conn, addr = s.accept()
>> try: self.player(conn, addr)
>> except: pass
>> conn.close()
>> s.close()
>> del s
> 
> Always, always, always: post the traceback.

Here it is:

Traceback (most recent call last):
  File "./vimp3_player.py", line 112, in 
Player().main()
  File "./vimp3_player.py", line 35, in main
self.listen()
  File "./vimp3_player.py", line 41, in listen
s.bind((HOST, PORT))
  File "", line 1, in bind
socket.error: [Errno 98] Address already in use


> 
> If that's your server code, I don't see how you can disconnect and
> reconnect.  That code only accepts a single connection, then it's done.

It's in a while 1: loop. self.player() just takes in a single command
and then returns.

> 
> Also always: post minim but real code the shows the problem.

It'd be a bit difficult to separate it, I was hoping this is a known
issue and this description would be enough, but if that turns out not to
be the case I'll make a minimal working example.

Thanks for the reply! -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket error 98 "Address already in use"

2010-06-17 Thread AK
On 06/17/2010 08:59 PM, Grant Edwards wrote:
> On 2010-06-18, AK  wrote:
> 
>> Here it is:
>>
>> Traceback (most recent call last):
>>   File "./vimp3_player.py", line 112, in 
>> Player().main()
>>   File "./vimp3_player.py", line 35, in main
>> self.listen()
>>   File "./vimp3_player.py", line 41, in listen
>> s.bind((HOST, PORT))
>>   File "", line 1, in bind
>> socket.error: [Errno 98] Address already in use
> 
> Setting the SO_REUSEADDR option should prevent that, and in my
> experience it always does.  What OS are you using?
> 
> Is there some reason you want to rebind each time?  Why not just loop
> around the conn,addr = accept()  con.close() section?

That solved it! Thanks!@ Interesting that closing and rebinding caused
this but not right away but after 3-4 connections. My OS is Ubuntu, by
the way. Thanks again, -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Tutorial

2010-08-13 Thread AK

Hello,

I plan to make a new python tutorial and I'd like to collaborate with
someone on it. I'm thinking of a slightly different approach than
existing tutorials: the idea is that readers will learn from examples,
going from small but complete and useful scripts to larger programs,
similar to Django by Example:

http://lightbird.net/dbe/

If you are interested and have a few years of experience with Python,
drop me an email and we'll discuss this further...

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


79 chars or more?

2010-08-16 Thread AK

As monitors are getting bigger, is there a general change in opinion on
the 79 chars limit in source files? I've experimented with 98 characters
per line and I find it quite a bit more comfortable to work with that
length, even though sometimes I have to edit files in 80 width
terminals, it's still easier to adapt to some inconvenience when that
happens than the other way around, since about 95% of time or more, I do
use wider editor window or terminal.

Is going over 79 still a terrible thing to do?  -andrei
--
http://mail.python.org/mailman/listinfo/python-list


Re: 79 chars or more?

2010-08-16 Thread AK

On 08/16/2010 10:42 PM, James Mills wrote:

On Tue, Aug 17, 2010 at 12:35 PM, AK  wrote:

As monitors are getting bigger, is there a general change in opinion on
the 79 chars limit in source files? I've experimented with 98 characters
per line and I find it quite a bit more comfortable to work with that
length, even though sometimes I have to edit files in 80 width
terminals, it's still easier to adapt to some inconvenience when that
happens than the other way around, since about 95% of time or more, I do
use wider editor window or terminal.

Is going over 79 still a terrible thing to do?  -andrei


My personal opinion (despite monitors being wider) is
the horizontal scrolling isn't worth it. Stick to a 80-char width.


But.. why horizontal scrolling, isn't autowrap much better than that?

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


Re: 79 chars or more?

2010-08-16 Thread AK

On 08/16/2010 11:51 PM, Steven D'Aprano wrote:

On Mon, 16 Aug 2010 22:35:49 -0400, AK wrote:


As monitors are getting bigger, is there a general change in opinion on
the 79 chars limit in source files? I've experimented with 98 characters
per line and I find it quite a bit more comfortable to work with that
length, even though sometimes I have to edit files in 80 width
terminals, it's still easier to adapt to some inconvenience when that
happens than the other way around, since about 95% of time or more, I do
use wider editor window or terminal.

Is going over 79 still a terrible thing to do?  -andrei


For your own code, you are free to do anything you like :)

But if you want to submit code to the Python standard library, you have
to restrict lines to 79 characters. This is no different from any other
project -- you need to stick to the project's coding conventions.


There are still good reasons to stick with 79 chars, even on large screen
monitors. People with poor vision will appreciate being able to increase
the font size. Others might like to have two windows side-by-side, each
showing 79 characters. Some people don't have wide monitors.


There's no doubt that there are pro's and con's, but to be fair, it's
not like code becomes unreadable over 79 chars - the difference is that
when your terminal is 80 chars, it's less convenient for you to read
code that's wider and when your terminal is wider, it's less convenient
to read code that's 79 chars.

I guess I'm just curious what percentage of people prefer 79chars - is
it 5/95% or 15/85% or 50/50? -andrei








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


Re: 79 chars or more?

2010-08-16 Thread AK

On 08/17/2010 12:26 AM, James Mills wrote:

On Tue, Aug 17, 2010 at 2:12 PM, AK  wrote:

There's no doubt that there are pro's and con's, but to be fair, it's
not like code becomes unreadable over 79 chars - the difference is that
when your terminal is 80 chars, it's less convenient for you to read
code that's wider and when your terminal is wider, it's less convenient
to read code that's 79 chars.


I guess there are two-sides to the coin here so to speak. See I'm
vision impaired
so I prefer a 79 char width in my own projects and expect those that work
with me to use the same standards (stick to project standards as Steven says).

The other side is this... I'm of the opinion that if you're writing a
line of code
that's excessively long (>80char or say>100chars), then you might want to
reconsider what you're doing :) (It might be wrong).


I stay away from ugly cramped one-liners; I mostly run over 79 when I
have a few `and` and `or` clauses or long strings. I've also noticed
something interesting: going from 79 to 99 affects a relatively large
number of lines, but going over 99 (i.e. 99 to 132) is much, much rarer.

By the way, the reason I asked is that we're working on a python
tutorial and I realized that even though I'm used to 99, I wasn't sure
if it's ok to teach that to new users or not..

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


Re: 79 chars or more?

2010-08-17 Thread AK

On 08/17/2010 10:28 AM, Stefan Schwarzer wrote:

Hi Neil,

On 2010-08-17 14:42, Neil Cerutti wrote:

On 2010-08-17, Michael Torrie  wrote:

In general if I find myself consistently going longer than 75
or 80 characters, I need to refactor my code to make it more
manageable.  If I have to scroll up five pages to find the
beginning of a block, that normally means my code could be
simplified and improved.


Looking through my code, the split-up lines almost always include
string literals or elimination of meaningless temporary
variables, e.g.:

 self.expiration_date = translate_date(find(response,
 'MPNExpirationDate').text, '%Y-%m-%d', '%m%d%Y')


I'd probably reformat this to

   self.expiration_date = translate_date(
 find(response, 'MPNExpirationDate').text,
 '%Y-%m-%d', '%m%d%Y')

or even

   self.expiration_date = translate_date(
 find(response, 'MPNExpirationDate').text,
 '%Y-%m-%d',
 '%m%d%Y')

for consistency.

This not only limits the width but also makes the nesting of
the calls more visible.

Stefan


Doesn't this create the problem of functions growing too long to fit in
a screen? I think it's very useful to try to keep function size low
enough so that you can view the whole function without having to scroll
up and down. (even though that's not always possible) -ak
--
http://mail.python.org/mailman/listinfo/python-list


Re: 79 chars or more?

2010-08-17 Thread AK

On 08/17/2010 12:21 PM, Stefan Schwarzer wrote:

On 2010-08-17 17:44, AK wrote:

On 08/17/2010 10:28 AM, Stefan Schwarzer wrote:

I'd probably reformat this to

self.expiration_date = translate_date(
  find(response, 'MPNExpirationDate').text,
  '%Y-%m-%d', '%m%d%Y')

or even

self.expiration_date = translate_date(
  find(response, 'MPNExpirationDate').text,
  '%Y-%m-%d',
  '%m%d%Y')

for consistency.

This not only limits the width but also makes the nesting of
the calls more visible.


Doesn't this create the problem of functions growing too long to fit in
a screen? I think it's very useful to try to keep function size low
enough so that you can view the whole function without having to scroll
up and down. (even though that's not always possible) -ak


I think I'd extract some part of the function into a new
function then. In my opinion, the reasoning is similar to
the case, "Can't I use two spaces per indentation level?
That way I don't run so easily into the right margin if I
have more than five indentations in a function." ;-)


I think to some extent it's a matter of taste. I bet most people would
agree that on the balance, 2-space indentations makes code much less
readable, despite saving a bit of space.

But let me ask you, would you really prefer to have:


self.expiration_date = translate_date(
  find(response, 'MPNExpirationDate').text,
  '%Y-%m-%d', '%m%d%Y')


(or the 4-line version of this above), even when it necessitates
creation of a new function, rather than have this code on two lines?

After all, I think it's a matter of balance between readability,
expressiveness and succinctness. If I split a function in two, that
still means that understanding the functionality of the code will
require scrolling around and looking at the second function. I guess
what I'm trying to say that we shouldn't just care about readability of
lines but also readability of functions and blocks of functionality
(that may include several functions that accomplish a single "task".)

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


Re: 79 chars or more?

2010-08-17 Thread AK

On 08/17/2010 03:32 PM, Stefan Schwarzer wrote:

Hi Andrei,

On 2010-08-17 18:43, AK wrote:

But let me ask you, would you really prefer to have:


 self.expiration_date = translate_date(
   find(response, 'MPNExpirationDate').text,
   '%Y-%m-%d', '%m%d%Y')


(or the 4-line version of this above), even when it necessitates
creation of a new function, rather than have this code on two lines?


Given that the reformatted code is three lines and the
former code two lines, I probably wouldn't change anything
but the formatting as shown. :)


After all, I think it's a matter of balance between readability,
expressiveness and succinctness. If I split a function in two, that
still means that understanding the functionality of the code will
require scrolling around and looking at the second function. I guess
what I'm trying to say that we shouldn't just care about readability of
lines but also readability of functions and blocks of functionality
(that may include several functions that accomplish a single "task".)


I think you're right here; you should keep the overall
readability or (maintainability on the whole) in mind.

I agree with Neil that good refactoring can _improve_ the
understandability of the code, and it won't necessarily
require you to look up the code of the extracted
function or method.


I can certainly agree with that - although this sort of refactoring 
(when I do it) is driven by the logic of the code rather than the need 
to spread a long line over several lines :-). -andrei

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


Re: 79 chars or more?

2010-08-18 Thread AK

On 08/18/2010 05:11 AM, Stefan Schwarzer wrote:

Hi Lie,

On 2010-08-18 12:02, Lie Ryan wrote:

On 08/17/10 12:59, AK wrote:

On 08/16/2010 10:42 PM, James Mills wrote:

My personal opinion (despite monitors being wider) is
the horizontal scrolling isn't worth it. Stick to a 80-char width.


But.. why horizontal scrolling, isn't autowrap much better than that?


Do you seriously use autowrapper when writing code?


I think he means wrapping on the screen, not actually
inserting line breaks.

Stefan


Yes, exactly (:set wrap in Vim). -andrei
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python "why" questions

2010-08-18 Thread AK

On 08/17/2010 10:15 PM, Russ P. wrote:

On Aug 7, 5:54 am, "D'Arcy J.M. Cain"  wrote:


Would said beginner also be surprised that a newborn baby is zero years
old or would it be more natural to call them a one year old?  Zero
based counting is perfectly natural.


You're confusing continuous and discrete variables. Time is a
continuous variable, but a list index is discrete.

Take a look at any numbered list, such as the top ten football teams
or the top ten software companies. Have you ever seen such a list
start with zero? If so, where? I sure haven't.

When I studied linear algebra way back, vector and matrix indices also
always started with one, and I assume they still do.

The convention of starting with zero may have had some slight
performance advantage in the early days of computing, but the huge
potential for error that it introduced made it a poor choice in the
long run, at least for high-level languages.


I have to agree, there's innumerable number of examples where sequential
number of an item in a series is counted starting with one. Second loaf
of bread; third day of vacation, first cup of tea today, first gray
hair, 50th anniversary, 2nd century AD, and approximately a gazillion
other examples.

Contrast this with _one_ example that was repeated in this thread of
there being ground floor, 1st floor, 2nd, and so on. However! Consider
that ground floor is kind of different from the other floors. It's the
floor that's not built up over ground, but is already there -- in case
of the most primitive dwelling, you can put some sawdust over the
ground, put a few boards overhead and it's a "home", although probably
not a "house". But does it really have what can be officially called a
"floor"?

On a more practical angle, ground floors usually have the lobby,
receptionists, storefronts and stores, etc; while 1st floor and up are
business/residential.

I think different numbering from pretty much all other things out there
gives you a hint that the ground floor is a different animal.

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


Re: Python "why" questions

2010-08-18 Thread AK

On 08/17/2010 10:15 PM, Russ P. wrote:

On Aug 7, 5:54 am, "D'Arcy J.M. Cain"  wrote:


Would said beginner also be surprised that a newborn baby is zero years
old or would it be more natural to call them a one year old?  Zero
based counting is perfectly natural.


You're confusing continuous and discrete variables. Time is a
continuous variable, but a list index is discrete.

Take a look at any numbered list, such as the top ten football teams
or the top ten software companies. Have you ever seen such a list
start with zero? If so, where? I sure haven't.

When I studied linear algebra way back, vector and matrix indices also
always started with one, and I assume they still do.

The convention of starting with zero may have had some slight
performance advantage in the early days of computing, but the huge
potential for error that it introduced made it a poor choice in the
long run, at least for high-level languages.


Besides that, the way things are now, it's almost an Abbot & Costello
routine:

- How many folders are there?
- 5
- Ok, give me the fourth one.
- Here.
- No, that's the last one!
- That's what you said!
- No, I said, fourth one!
- That's what I did!
- How many are there in all?
- I already said, five!
- You gave me the last one!!
- Just like you said - fourth
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python "why" questions

2010-08-19 Thread AK

On 08/19/2010 02:04 PM, Steven D'Aprano wrote:

On Tue, 17 Aug 2010 19:15:54 -0700, Russ P. wrote:


The convention of starting with zero may have had some slight
performance advantage in the early days of computing, but the huge
potential for error that it introduced made it a poor choice in the long
run, at least for high-level languages.


People keep saying this, but it's actually the opposite. Signpost errors
and off-by-one errors are more common in languages that count from one.

A simple example: Using zero-based indexing, suppose you want to indent
the string "spam" so it starts at column 4. How many spaces to you
prepend?

0123456789
 spam


Doesn't it start at column 5 as shown?

Anyway, it's far more common, I think, to iterate over a sequence and
say "my list is 12 items long. I need to check if I'm on 12th item and
do something special. Doh, I mean, 11th item." In my view, this is far,
far more common, especially for people new to programming, and isn't one
of Python mottos "programming for everybody"? In other words, starting
with 0 leads to implicit error every time you simply pause and think
"at which item am I now and how many items have I got so far?" which are
the two most basic questions involved in iteration.

I'm not saying that 1-th indexing is necessarily better in programming
than 0-th indexing, all things considered. It's an arguable question, it
depends on what kind of operations are more common, and I can't know
this for everyone.

I am saying that it is much more natural for people new to programming
and outside of programming to count from 1, and I imagine the reason for
this is simply that it's most useful in vast majority of real usage
people deal with.

It's just annoying that people bring up, for example, ground floor/
first floor as proof that both are equally natural. (I don't mean you, I
know you said you agree that 1-th indexing is more intuitive). -ak
--
http://mail.python.org/mailman/listinfo/python-list


How to 'de-slashify' a string?

2009-08-22 Thread AK
Hi, if I have a string '\\303\\266', how can I convert it to '\303\266' 
in a general way?


The problem I'm running into is that I'm connecting with pygresql to a 
postgres database and when I get fields that are of 'char' type, I get 
them in unicode, but when I get fields of 'byte' type, I get the text 
with quoted slashes, e.g. '\303' becomes '\\303' and so on.


I saw posts online to do

cursor.execute("set client-encoding to unicode")

before running queries but this command causes an error.

So I think I need a way to de-quote the slashes or alternatively
some way to tell pygresql not to quote slashes for 'byte' fields.

Any help, hints, etc appreciated..

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


Re: How to 'de-slashify' a string?

2009-08-22 Thread AK

Steven D'Aprano wrote:

On Sat, 22 Aug 2009 04:20:23 -0400, AK wrote:


Hi, if I have a string '\\303\\266', how can I convert it to '\303\266'
in a general way?


It's not clear what you mean.

Do you mean you have a string '\\303\\266', that is:

backslash backslash three zero three backslash backslash two six six

If so, then the simplest way is:


s = r'\\303\\266'  # note the raw string
len(s)

10

print s

\\303\\266

print s.replace('', '\\')

\303\266


Another possibility:


s = '\\303\\266'  # this is not a raw string
len(s)

8

print s

\303\266

So s is:
backslash three zero three backslash two six six

and you don't need to do any more.


Well, I need the string itself to become '\303\266', not to print
that way. In other words, when I do 'print s', it should display
unicode characters if my term is set to show them, instead of
showing \303\266.





The problem I'm running into is that I'm connecting with pygresql to a
postgres database and when I get fields that are of 'char' type, I get
them in unicode, but when I get fields of 'byte' type, I get the text
with quoted slashes, e.g. '\303' becomes '\\303' and so on.


Is pygresql quoting the backslash, or do you just think it is quoting the 
backslashes? How do you know? E.g. if you have '\\303', what is the 
length of that? 4 or 5?


Length is 4, and I need it to be length of 1. E.g.:

>>> s = '\303'
>>> s
'\xc3'
>>> x = '\\303'
>>> x
'\\303'
>>> len(x)
4
>>> len(s)
1


What I get from pygresql is x, what I need is s. Either by asking 
pygresql to do this or convert it afterwards. I can't do 
replace('\\303', '\303') because it can be any unicode character.








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


Re: How to 'de-slashify' a string?

2009-08-22 Thread AK

Vlastimil Brom wrote:

2009/8/22 AK :

Steven D'Aprano wrote:

On Sat, 22 Aug 2009 04:20:23 -0400, AK wrote:


Hi, if I have a string '\\303\\266', how can I convert it to '\303\266'
in a general way?

It's not clear what you mean.

Do you mean you have a string '\\303\\266', that is:

backslash backslash three zero three backslash backslash two six six

If so, then the simplest way is:


s = r'\\303\\266'  # note the raw string
len(s)

10

print s

\\303\\266

print s.replace('', '\\')

\303\266


Another possibility:


s = '\\303\\266'  # this is not a raw string
len(s)

8

print s

\303\266

So s is:
backslash three zero three backslash two six six

and you don't need to do any more.

Well, I need the string itself to become '\303\266', not to print
that way. In other words, when I do 'print s', it should display
unicode characters if my term is set to show them, instead of
showing \303\266.




The problem I'm running into is that I'm connecting with pygresql to a
postgres database and when I get fields that are of 'char' type, I get
them in unicode, but when I get fields of 'byte' type, I get the text
with quoted slashes, e.g. '\303' becomes '\\303' and so on.

Is pygresql quoting the backslash, or do you just think it is quoting the
backslashes? How do you know? E.g. if you have '\\303', what is the length
of that? 4 or 5?

Length is 4, and I need it to be length of 1. E.g.:


s = '\303'
s

'\xc3'

x = '\\303'
x

'\\303'

len(x)

4

len(s)

1


What I get from pygresql is x, what I need is s. Either by asking pygresql
to do this or convert it afterwards. I can't do replace('\\303', '\303')
because it can be any unicode character.





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




Hi,
do you mean something like


u"\u0303"

u'\u0303'

print u"\u0303"

̃
̃ (dec.: 771)  (hex.: 0x303)   ̃ COMBINING TILDE (Mark, Nonspacing)
?

vbr


Yes, something like that except that it starts out as '\\303\\266', and 
it's good enough for me if it turns into '\303\266', in fact that's 
rendered as one unicode char. In other words, when you do:


>>> print "\\303\\266"
'\303\266'

I need that result to become a python string, i.e. the slashes need to
be converted from literal slashes to escape slashes.




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


Re: How to 'de-slashify' a string?

2009-08-22 Thread AK

Vlastimil Brom wrote:

2009/8/22 AK :

Vlastimil Brom wrote:

2009/8/22 AK :

Steven D'Aprano wrote:

On Sat, 22 Aug 2009 04:20:23 -0400, AK wrote:


Hi, if I have a string '\\303\\266', how can I convert it to '\303\266'
in a general way?

It's not clear what you mean.

Do you mean you have a string '\\303\\266', that is:

backslash backslash three zero three backslash backslash two six six

If so, then the simplest way is:


s = r'\\303\\266'  # note the raw string
len(s)

10

print s

\\303\\266

print s.replace('', '\\')

\303\266


Another possibility:


s = '\\303\\266'  # this is not a raw string
len(s)

8

print s

\303\266

So s is:
backslash three zero three backslash two six six

and you don't need to do any more.

Well, I need the string itself to become '\303\266', not to print
that way. In other words, when I do 'print s', it should display
unicode characters if my term is set to show them, instead of
showing \303\266.


The problem I'm running into is that I'm connecting with pygresql to a
postgres database and when I get fields that are of 'char' type, I get
them in unicode, but when I get fields of 'byte' type, I get the text
with quoted slashes, e.g. '\303' becomes '\\303' and so on.

Is pygresql quoting the backslash, or do you just think it is quoting
the
backslashes? How do you know? E.g. if you have '\\303', what is the
length
of that? 4 or 5?

Length is 4, and I need it to be length of 1. E.g.:


s = '\303'
s

'\xc3'

x = '\\303'
x

'\\303'

len(x)

4

len(s)

1


What I get from pygresql is x, what I need is s. Either by asking
pygresql
to do this or convert it afterwards. I can't do replace('\\303', '\303')
because it can be any unicode character.

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



Hi,
do you mean something like


u"\u0303"

u'\u0303'

print u"\u0303"

̃
   ̃ (dec.: 771)  (hex.: 0x303)   ̃ COMBINING TILDE (Mark, Nonspacing)
?

vbr

Yes, something like that except that it starts out as '\\303\\266', and it's
good enough for me if it turns into '\303\266', in fact that's rendered as
one unicode char. In other words, when you do:


print "\\303\\266"

'\303\266'

I need that result to become a python string, i.e. the slashes need to
be converted from literal slashes to escape slashes.




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



Not sure, whether it is the right way of handling the such text data, but maybe:


decoded = '\\303\\266'.decode("string_escape")
decoded

'\xc3\xb6'

print decoded

ö

print '\303\266'

ö

It might be an IDLE issue, but it still isn't one unicode glyph.

I guess, you have to ensure, that the input data is valid and the
right encoding is used.

hth
  vbr


Actually, this works perfectly for me. It prints out as one character in
gnome-terminal and also when I write it to a text file, and open it as
utf-8 format in gnumeric, it also shows up properly.

Thanks to all who helped! -AK
--
http://mail.python.org/mailman/listinfo/python-list


Re: Too much code - slicing

2010-09-16 Thread AK

On 09/16/2010 03:47 PM, Benjamin Kaplan wrote:

On Thu, Sep 16, 2010 at 3:35 PM, DataSmash  wrote:

I need to create a simple utility to remove characters from either the
right or left side of directories.
This works, but there has to be a better way.  I tried to use a
variable inside the brackets but I can't get
that to work.  Can anyone think of a way to do this with less code?
Thanks!

import os

dirs = filter(os.path.isdir, os.listdir(''))
for dir in dirs:

# Left side



The int() type will convert a string to an int for you. So all you
need to do is check the side and slice accordingly.

if side=='l':
 code = dir[int(num):]
else :
 code = dir[:-1*int(num)]


I also like this construct that works, I think, since 2.6:

code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]

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


Re: Too much code - slicing

2010-09-18 Thread AK

On 09/18/2010 06:56 PM, Seebs wrote:

On 2010-09-18, Steven D'Aprano  wrote:

On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote:

On Thu, 16 Sep 2010 16:20:33 -0400 AK  wrote:

I also like this construct that works, I think, since 2.6:



code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]



I wonder when this construct will finally start to look good.



It looks good to me. It follows a common English idiom:



"What are you doing tonight?"
"I'll be going to the movies, if I finish work early, otherwise I'll stay
home and watch a DVD."


I hate that idiom in English, too.  If you're going to give me a forking
conditional, I want to know about it early.

Basically, I can handle
do x if y
pretty well, but
do x if y else z
always breaks my parser.

So in English, I might say "I'll go to the store if I have time", but
I'd rarely use "I'll go to the store if I have time, otherwise I'll send
the house elf"; instead, I'd say "If I have time, I'll go to the store,
otherwise I'll send the house elf."

-s


I actually find the shorter version slightly more readable than full
version. I think in English you'd say it in one sentence and that to me
feels like it should vaguely correspond to one line in code (perhaps
split over more than one line but that'd be due to long var names or
complex operations, not inherently).

The longer version may be like saying "I'll go to the store. If I have
time. If I don't have time. I will send the house elf."

It's a bit more readable to me because I can tell at a glance that a
single variable gets assigned a value based on a condition. With a
longer version it looks like something more complicated it going on, and
the eye has to look at all four lines and jump to another ident level.

By the way, it also looks far more readable in an editor where if and
else would be highlighted vs. all in plain colour.

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


Re: Too much code - slicing

2010-09-18 Thread AK

On 09/18/2010 07:38 PM, Seebs wrote:

On 2010-09-18, AK  wrote:

On 09/18/2010 06:56 PM, Seebs wrote:

Basically, I can handle
do x if y
pretty well, but
do x if y else z
always breaks my parser.



So in English, I might say "I'll go to the store if I have time", but
I'd rarely use "I'll go to the store if I have time, otherwise I'll send
the house elf"; instead, I'd say "If I have time, I'll go to the store,
otherwise I'll send the house elf."



I actually find the shorter version slightly more readable than full
version. I think in English you'd say it in one sentence and that to me
feels like it should vaguely correspond to one line in code (perhaps
split over more than one line but that'd be due to long var names or
complex operations, not inherently).


I dunno, it always breaks my parser.  The condition ends up between
the two dependents, and that doesn't work for me.  I can have conditions
which are leading or trailing, but not infix.


It's a bit more readable to me because I can tell at a glance that a
single variable gets assigned a value based on a condition. With a
longer version it looks like something more complicated it going on, and
the eye has to look at all four lines and jump to another ident level.


Ahh!  I see.  There's several variants that could be discussed.

if condition:
x = y
else:
x = z

x = y if condition else z

And then the one I'm used to from other languages:

x = if condition then y else z

The other thing, from my point of view, is an ambiguity with a common
idiom I'm used to, again from other languages:

x = y if condition

If !condition, then nothing happens to x.  So far as I can tell, that's
a syntax error in Python -- I can't use postfix if to modify a sentence,
because it's an expression thing.


By the way, it also looks far more readable in an editor where if and
else would be highlighted vs. all in plain colour.


I use syntax coloring in programming languages precisely as often, and
for precisely the same reasons, that I use it when writing in English.
Which is to say, if such a feature exists, I turn it off immediately
because it consistently distracts me from following the actual meaning
of code.  Syntax is the least part of the meaning of code; giving extra
weight to syntax is pretty disruptive, IMHO.


Funny that you should say that, because I thought quite a few times that
it would be really awesome if some texts in English had syntax
highlighting. Obviously, not Brothers Karamazov, but something like a
tutorial, or a manual, or an online article. If key words were
highlighted, I'd be able to quickly glance over parts that are not
useful to me at the time, and find the interesting bits.

For instance, in the above paragraph I'd highlight 'awesome', 'English',
'syntax highlighting', 'tutorial', 'manual', 'online article',
'quickly glance over', 'not useful', 'find', 'interesting bits'.

It'd be like speed reading, except real!

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


Re: Too much code - slicing

2010-09-18 Thread AK

On 09/18/2010 08:35 PM, Seebs wrote:

On 2010-09-19, AK  wrote:

Funny that you should say that, because I thought quite a few times that
it would be really awesome if some texts in English had syntax
highlighting. Obviously, not Brothers Karamazov, but something like a
tutorial, or a manual, or an online article. If key words were
highlighted, I'd be able to quickly glance over parts that are not
useful to me at the time, and find the interesting bits.


That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting.


In case of programming, the effect is similar. I find that it allows me
to look quickly through code, scanning for something specific, e.g. the
next function, the next if/else block. If I'm looking for a print
statement, for example, I can quickly scan a whole screenful, looking
for a first highlighted long word (all the other highlighted keywords
will usually be if, else, and for). On the other hand, if I know I'm
looking for a variable, my eyes will filter out all the highlighted text
- strings and keywords. English is of course much less formal so you
have to understand the text to do useful highlighting. Anyway, I find it
very odd that anyone would not find it extremely useful (in code)!



Which people often do -- notice that I did it twice in that paragraph.  But
that's the point -- you need to know what it *means* to make sensible
decisions about what to highlight.  Syntax highlighting is precisely the
opposite, highlighting things for reasons that have nothing to do with
their semantic content.  It distracts from the actual meaning of the
code.


I'm not always looking for meaning *immediately*. If I know there's a
single print statement in a function, I don't need to understand its
meaning to know that's the one print statement I need. (Or, if there's
two, I might know that I need the first one or at least I'll have 2
lines to look at instead of 75).



In short, syntax highlighting would be like writing:

FUNNY *that* _you_ *should* /say/ *that*.


It'd be like speed reading, except real!


I don't understand this.  So far as I know, the phrase "speed reading"
refers to various methods of reading much faster than most people read,
and is real but not exceptionally interesting.


Afaik the idea is that you can read a novel at the speed of half a page
a second or so and understand it to the same extent as people who'd read
at a normal rate. Woody Allen joke: "I learned speed reading and
read War&Peace"; - it involves Russia.

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


Re: Too much code - slicing

2010-09-18 Thread AK

On 09/18/2010 09:08 PM, Dennis Lee Bieber wrote:

On Sat, 18 Sep 2010 20:00:32 -0400, AK  declaimed
the following in gmane.comp.python.general:



Funny that you should say that, because I thought quite a few times that
it would be really awesome if some texts in English had syntax
highlighting. Obviously, not Brothers Karamazov, but something like a
tutorial, or a manual, or an online article. If key words were
highlighted, I'd be able to quickly glance over parts that are not
useful to me at the time, and find the interesting bits.

For instance, in the above paragraph I'd highlight 'awesome', 'English',
'syntax highlighting', 'tutorial', 'manual', 'online article',
'quickly glance over', 'not useful', 'find', 'interesting bits'.



Syntax highlighting is more likely to identify: be, if, had, but,
like, or, were, are, not, and. That is, the (relatively) fixed
connectors between arbitrary nouns and concepts.

  be  if  had.
not, but  like, or. If
  were  are not, and


Yes, I didn't mean that it's exactly the same, of course. Python being
much more formal than English means automatic syntax highlight can be
useful, as obviously many people find it; although this gave me an
interesting idea: if you had a long text that you wished to read
quickly, it might be more efficient to do syntax highlight of all verbs,
quickly scan through the text, then syntax highlight of all nouns, do
another quick scan, and then turn off syntax highlight and concentrate
on the parts that you did not understand while scanning. Is there a
program that'd do something like that?

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


Re: Too much code - slicing

2010-09-18 Thread AK

On 09/18/2010 10:12 PM, Seebs wrote:

On 2010-09-19, AK  wrote:

On 09/18/2010 08:35 PM, Seebs wrote:

 News flash:  Not all people think the same way.  Film at 11.  :)


I've tried to use syntax coloring editors, and I've always found that
they end up making me slower and less accurate at reading things,
because what they're highlighting isn't waht what I need to know.


The way I see it, it's not meant to tell you something, it's
punctuation, it's as if you'd argue against periods and spaces at the
end of sentencesBecause the next sentence is capitalized anyway, so you
already know the last sentence ended. In the same way, in many cases
other punctuation is not absolutely necessary for understanding.

The other thing is of course that it helps you not to name your
variables using keywords and spot misspelled keywords.

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/18/2010 11:28 PM, Steven D'Aprano wrote:

On Sat, 18 Sep 2010 21:58:58 -0400, AK wrote:


I don't understand this.  So far as I know, the phrase "speed reading"
refers to various methods of reading much faster than most people read,
and is real but not exceptionally interesting.


Afaik the idea is that you can read a novel at the speed of half a page
a second or so and understand it to the same extent as people who'd read
at a normal rate. Woody Allen joke: "I learned speed reading and read
War&Peace"; - it involves Russia.


My wife can read scarily fast. It's very something to watch her reading
pages as fast as she can turn them, and a few years ago she read the
entire Harry Potter series (to date) in one afternoon, and could gives a
blow-by-blow account of the plots, including a detailed critique of the
writing style and characters. But then, she feels that reading the Potter
series is a chore to be completed as fast as possible, rather than a
pleasure to be savored. She'll sometimes drag a new Terry Pratchett or
Stephen King novel out for as much as two days.




That's pretty impressive. I used to get somewhat close to that speed
when, years ago, I'd read a lot of trashy scifi. The way it would work
is that I'd sense in advance that there's a passage where the hero with
his team is going through a desert area and I'd know that a 30-40 page
section will be punctuated by two battles and one friendly encounter. I
would be able to read at different speeds depending on what's going on,
slowing down a bit where a twist is presented or a crucial plot point is
revealed, both would be telegraphed well in advance. In other spots, I'd
be able to scan a few words at the top of page, a few in the middle and
at the bottom and I'd know what's going on, generally.

I would also be able to give a detailed account of the plot and writing
style and characters but this would be entirely due to predictability of
writing and following tropes. Interestingly, I've also read LoTR in the
same way when I was younger because I was interested in battles and
skipped the dull parts.

I tried a few times to read Potter book 3 but couldn't bear it.. spoiled
too much by Barrie and Grahame.

When I was reading The book of the new sun, though, I could stop and
read a single sentence a few times over and reflect on it for a minute.

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/19/2010 03:31 AM, Seebs wrote:

On 2010-09-19, Steven D'Aprano  wrote:

Define "unbalanced".


I'm not sure that's the word I'd use.  I'm not even sure what it would mean
here.


Putting aside the over-use of punctuation, The C syntax feels unbalanced
to me. You have:



condition IF true-clause ELSE false-clause



so both clauses follow the test, that is, they're on the same side: ?--


Yes.

Just like:
if condition:
foo
else:
bar

The condition is the primary, the clauses are secondary to it.


To me, the problem with C ternary is, why is true condition first and
false second? It could just as well be the other way around. With if and
else, the meaning is direct, x if y else z, or if y: x; else: z.



It may be balanced, but it requires you to reevaluate what you're reading
after you've already read something that seemed to have a clear meaning.

Basically, think of what happens as I read each symbol:

x = x + 1 if condition else x - 1

Up through the '1', I have a perfectly ordinary assignment of a value.
The, suddenly, it retroactively turns out that I have misunderstood
everything I've been reading.  I am actually reading a conditional, and
the things I've been seeing which looked like they were definitely
part of the flow of evaluation may in fact be completely skipped.


That's absolutely not how I read code. For example, if you have a line
like:

 x = x + 1 a...@#$!@$asfa...@#$!@$#adfas...@#

Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is
this?".

I would read it like "there's something wrong at the end of line",
before I even see it as an assignment.

That's where syntax highlighting comes in, as well. What I see, at the
same time (i.e. not in sequence):

.. = .. if .. else ..

The second thing I see is what variable is being assigned to. Of couse,
this might change if I'm looking for that particular variable, then I
might see:

x 

or

x = 





Consider the following lovely hypothetical syntax:

foo
bar
baz
if condition else:
blah
blah
blah

And there, at least you have some cue that you're about to see something
happen.


After some time getting used to it, I'd end up seeing this as:

 .
 .
 .
 if .. else:
 .
 .
 .

at first and then processing everything else. Again, syntax highlighting
would help here. The only issue is that it'd be hard to separate the
beginning from other code, for me that'd be the primary reason why this
is not a good construct.

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/19/2010 03:36 AM, Seebs wrote:

On 2010-09-19, Steven D'Aprano  wrote:

I'm not entirely sure I agree with you here... you can't ignore syntax in
order to understand the meaning of code.


No, but the syntax should be invisible.  When I read English, I don't have
to think about nouns and verbs and such unless something is very badly
written.  The syntax is handled automatically at a lower level without
conscious intervention, as it should be.  Calling my conscious attention
to it is disruptive.


The interesting thing is that syntax highlight for me *is* handled at a
lower level. What you're describing is exactly the same as when I try a
highlight scheme with colours that are too strong, or have a background.
I would rather use no highlighting at all than a theme with garish
colours.

When I read code, I filter out colours when I don't need them and filter
out non-coloured text when I'm looking for a particular structure. So,
with x = y if a else z, I might see . = . if . else . and then
immediately see x . y . a . z, already with knowledge of what is the
structure surrounding vars.


Punctuation is very different from highlighting, IMHO.  That said, I
find punctuation very effective at being small and discrete, clearly not
words, and easy to pick out.  Color cues are not nearly as good at
being inobtrusive but automatically parsed.


Seems like the difference of how you process colours vs. how I do, for
me they work precisely in the same way as punctuation might, but adding
an additional layer which may be used but never gets in the way.

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/19/2010 02:21 PM, Seebs wrote:

On 2010-09-19, AK  wrote:

On 09/19/2010 03:31 AM, Seebs wrote:

Just like:
if condition:
foo
else:
bar



The condition is the primary, the clauses are secondary to it.



To me, the problem with C ternary is, why is true condition first and
false second? It could just as well be the other way around.


Again, look at the long-form "if/else" above; it's always "if a then b
otherwise c".


Because that's what 'if' and 'else' mean. I have no problem with '?'
separating condition from possible outcomes.. The most natural reading
of that construct is that depending on condition, there are two possible
outcomes, separated by a ':' and you have to remember that first outcome
corresponds to true condition. x = y if a else z is much more pythonic
because 'else' is explicitly saying what happens on false condition.
Explicit is better than implicit.




That's absolutely not how I read code. For example, if you have a line
like:



   x = x + 1 a...@#$!@$asfa...@#$!@$#adfas...@#



Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is
this?".


Not for something that big and visible.  But the if/else stuff is
just ordinary blocks of text.


Not with syntax highlighting they're not ;) Seriously though, my guess
is even without syntax highlighting I'd still prefer it because I do
enough look-ahead and in 95% of cases the first 'if' is close enough to
the beginning of the line. In fact, most often plain assignments will be
much shorter than this construct so you can figure it out by combination
of line length and the 'if' keyword.

It still has the advantage over the more verbose version that I
mentioned before: you can see immediately that there's an assignment to
a single variable, and the logic flows like a single sentence in a
natural language.




That's where syntax highlighting comes in, as well.


So basically, if we use syntax highlighting to make up for the legibility
problems of a given syntax, then the syntax is okay, but people who don't
use syntax highlighting to make up for its legibility problems are wrong.


That's not really true, it merely makes a given syntax easier to read
even when it's already a preferable syntax. It's like this, if someone
gives you five dollars for nothing, and then later gives you three
dollars, you don't complain that the latter amount is less than former :).



I see.

This does seem self-contained; you like syntax highlighting because you
like constructs which are hard to read without it.  You like those constructs
because they let you show off syntax highlighting.


Well, you're exaggerating this out of all proportion just to prove a
point. I like syntax highlighting in all of python and, in fact, in all
languages I've used. Even in crontab files! This is a single construct I
can think of, which, being already very readable, explicit, and
succinct, *on top of that*, gains even more in readability due to syntax
highlight.

So, as you can see, I'd like syntax highlight just fine if this
construct was not present in Python, and in fact I did. Conversely, I'd
prefer it to the longer version if there was no syntax highlight at all.




After some time getting used to it, I'd end up seeing this as:



   .
   .
   .
   if .. else:
   .
   .
   .



at first and then processing everything else.


Assuming that the if/else was on the same page.  :)


I'll concede you one point in this case: if the statement 'x = .. if ..
else .. ' is split over two pages, I would at least seriously consider
the 'if: .. else: ' version. ;)

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/19/2010 07:18 PM, Gregory Ewing wrote:

AK wrote:


Afaik the idea is that you can read a novel at the speed of half a page
a second or so and understand it to the same extent as people who'd read
at a normal rate.


I've never understood why anyone would *want* to read a
novel that fast, though. For me at least, reading a novel
is something done for pleasure, so reading it at ten times
normal speed would waste 90% of the benefit.



One definite advantage would be that if, say, it takes you 70 pages of a
given novel to figure out whether you like it enough to continue, you'd
want to read those pages in 2 minutes rather than an hour.
Unfortunately, beginning of a novel is where I have to read at the
slowest rate because I'm not used to author's style and pacing yet
and I don't want to miss something crucial.

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


Re: Too much code - slicing

2010-09-19 Thread AK

On 09/19/2010 10:32 PM, John Bokma wrote:

AK  writes:


On 09/19/2010 07:18 PM, Gregory Ewing wrote:

AK wrote:


Afaik the idea is that you can read a novel at the speed of half a page
a second or so and understand it to the same extent as people who'd read
at a normal rate.


I've never understood why anyone would *want* to read a
novel that fast, though. For me at least, reading a novel
is something done for pleasure, so reading it at ten times
normal speed would waste 90% of the benefit.



One definite advantage would be that if, say, it takes you 70 pages of a
given novel to figure out whether you like it enough to continue, you'd
want to read those pages in 2 minutes rather than an hour.


Heh, to me speed reading those 70 pages in a very short while,
concluding that it's a good book, and start over again would be quite
the spoiler. Do you fast forward movies as well?


I honestly doubt it would be a spoiler if it's a good book. Generally I
find that poor books rely on twists and turns while better ones rely on
the fabric of story-telling. Aside from that, though, it's a very
interesting question - I'll try to think of good books and see if they'd
be spoiled by peeking in the first 70 pages.. Starting with children's
books, Peter Pan and Wind in the Willows, I think, would not be. Don
quixote would not be. Crime and punishment - maybe if you get as far as
the murder? Same author's the Devils, I would say you can read the last
70 pages and it'd be just as good :). -ak
--
http://mail.python.org/mailman/listinfo/python-list


Unittest: how to pass information to TestCase classes?

2010-10-26 Thread AK

Hi, I have a question about unittest: let's say I create a temp dir for
my tests, then use loadTestsFromNames() to load my tests from packages
and modules they're in, then use TextTestRunner.run() to run the tests,
how can I pass information to TestCase instances, e.g. the location of
the temp dir I created?

The dir has to be created just once, before any tests run, and then
multiple packages and multiple modules in them are imported and run.

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


Re: Skeletal animation

2009-10-04 Thread AK Eric
Building on what others have said and giving a +1 to Carl:
I work daily in Maya doing character setup and rigging.  As far as
doing it straight in Python, again, like others, take a look at PyGame
or Blender.  I think the main question is:  Do you want skeletal
animation, or do you want skeletal animation specifically in Python?
While Python is heavily used in Blender, I'm not sure how much of the
foundation it actually makes.  Take a look ta this PyGame:
http://www.pygame.org/project-StickyPy-1248-2254.html
Of course PyGame is just a wrapper for SDL
Joints and skeletons are abstract concepts that sure, you could do
with Python.  The question is how you want to render that to the
screen, and that's where the other apps come in.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple audio

2009-10-21 Thread AK Eric
Yep, you can run it without any kind of GUI to my knowledge.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 Global Variables

2009-10-29 Thread AK Eric
> 2/ in Python, "global" really means "module-level" - there's nothing
> like a "true" global namespace.

Isn't that __main__?


import __main__
__main__.foo = "asdfasdf"

print foo
# asdfasdf

Not advocating, but it does serve the purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 Global Variables

2009-10-29 Thread AK Eric
> Good that you're not advocating it, because IMHO it's bad practice to
> have circular import dependencies.  By using the __main__ alias, you
> avoid the worst problems, but that just means the others are more subtle.

I figured I'd get that kind of response, not that it's incorrect ;)
Great power\great responsibility\etc.

As I understand it, when you enter Python statements at the
interactive prompt, it's adding the result directly to ___main___
(which for lack of a better term I like to call 'universal' scope...
rolls off the tongue better than 'doubleunderscore main
doubleunderscore'):

>>> foo = 23
>>> import __main__
>>> print __main__.foo
23

While this might not be the most common way of working for most people
(I'm guessing most folks are in a nice cozy IDE), people working this
way are mucking about in the 'universal' scope without (possibly) even
knowing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 Global Variables

2009-10-30 Thread AK Eric
> > It isn't a neat trick anymore once you realize the name '__main__'
> > isn't special.
>
> > Replace __main__ with foo, or config, or whatever, and you get the
> > same results. Ok, there is a catch: a file with that name must exist,
> > at least an empty one...

True.  I do feel a bit less special now :-P  And again, I think there
is a difference from saying you *can* work a certain way, and you
*should* work a certain way.  Making a 'global module' you import and
muck with = good.  Other ways discussed = bad (for the most part).
But I think it's important to understand the underlying system
especially when one is first learning:  I hand a heck of a time having
someone explain this stuff to me when I was learning the basics (and
I'm still figuring it out, even from this thread) and now that I get
how it works (I uh... think) it makes me a stronger scripter.  The
common thought seemed to be "you shouldn't do it that way, so I'm not
going to explain it to you" which I've always found quite
frustrating.  And along those lines...

Should we start talking about how you can add stuff to __builtin__ and
then it really is exposed to everything? (right, unless I'm missing
some other Python idiom?)  Again, *not advocating* in standard
practice, but I think it's important to understand how it works.
(ducks incoming flak)

#-
# moduleA.py
import __builtin__
__builtin__.spam = 42
__builtins__["ham"] = 24

#-
# moduleB.py
# This will fail if moduleA isn't executed first
print spam, ham

>>> import moduleA
>>> import moduleB
42 24

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


Re: How can module determine its own path?

2009-10-30 Thread AK Eric

> > How can a module determine the path of the file that defines it?
> > (Note that this is, in the general case, different from sys.argv[0].)
>
> __file__

Also:

import inspect
print inspect.getsourcefile(lambda:None)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can a module know the module that imported it?

2009-11-12 Thread AK Eric
so:

# moduleA.py
import moduleB

# moduleB.py
import sys
stuff = sys._getframe(1).f_locals
print stuff

Prints:

{'__builtins__': ,
'__file__': 'C:\\Documents and SettingsMy Documents\
\python\\moduleA.py',
'__name__': '__main__',
'__doc__': None}

Looks like you could query stuff['__file__'] to pull what you're
after.
?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can a module know the module that imported it?

2009-11-12 Thread AK Eric
On Nov 12, 10:10 am, Ethan Furman  wrote:
> AK Eric wrote:
> > so:
>
> > # moduleA.py
> > import moduleB
>
> > # moduleB.py
> > import sys
> > stuff = sys._getframe(1).f_locals
> > print stuff
>
> > Prints:
>
> > {'__builtins__': ,
> > '__file__': 'C:\\Documents and SettingsMy Documents\
> > \python\\moduleA.py',
> > '__name__': '__main__',
> > '__doc__': None}
>
> > Looks like you could query stuff['__file__'] to pull what you're
> > after.
> > ?
>
> The leading _ in _getframe indicates a private function to sys (aka
> implementation detail); in other words, something that could easily
> change between one Python version and the next.
>
> I'm using the inspect module (for the moment, at least), and my question
> boils down to:  Will it work correctly on all versions of Python in the
> 2.x range?  3.x range?
>

Good point, I totally missed that.  Someone had passed that solution
to me at one point and I was so excited I kind of looked that over :P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread AK Eric
On Nov 12, 11:31 am, Terry Reedy  wrote:
> Alf P. Steinbach wrote:
> > One reaction to  >http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle
> > graphics may be off-putting to some readers because it is associated
> > with children's learning.
>
> > What do you think?
>
> I just started using the module for simple plots.
> I am not a child.
> You cannot please everyone.

I used Turtle back on the Apple in the early 80's... so I personally
have very positive feelings towards it ;)  To each their own eh?
-- 
http://mail.python.org/mailman/listinfo/python-list


Query screen resolution?

2009-08-28 Thread AK Eric
Thought this would be easy, maybe I'm missing something :)  Trying to
query the x,y resolution of my screen.  I've seen this available
through http://python.net/crew/mhammond/win32/ :

from win32api import GetSystemMetrics
print "width =", GetSystemMetrics (0)
print "height =",GetSystemMetrics (1)

But I was hoping for something built-in, and something non-OS
specific.  Is that available?  Would be nice to detect for multiple
monitors as well, but I'm probably asking too much :)

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