Re: Documenting builtin methods

2013-07-11 Thread Chris Angelico
On Thu, Jul 11, 2013 at 4:06 PM, Steven D'Aprano  wrote:
> I think the right solution here is the trivial:
>
> def exhaust(it):
> """Doc string here."""
> deque(maxlen=0).extend(it)
>
>
> which will be fast enough for all but the tightest inner loops. But if
> you really care about optimizing this:
>
>
> def factory():
> eatit = deque(maxlen=0).extend
> def exhaust_iter(it):
> """Doc string goes here"""
> eatit(it)
> return exhaust_iter
>
> exhaust_it = factory()
> del factory
>
>
> which will be about as efficient as you can get while still having a
> custom docstring.

Surely no reason to go for the factory function:

def exhaust(it,eatit=deque(maxlen=0).extend):
eatit(it)

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


Re: Documenting builtin methods

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 17:06:39 +1000, Chris Angelico wrote:

> On Thu, Jul 11, 2013 at 4:06 PM, Steven D'Aprano 
> wrote:
>> I think the right solution here is the trivial:
>>
>> def exhaust(it):
>> """Doc string here."""
>> deque(maxlen=0).extend(it)
>>
>>
>> which will be fast enough for all but the tightest inner loops. But if
>> you really care about optimizing this:
>>
>>
>> def factory():
>> eatit = deque(maxlen=0).extend
>> def exhaust_iter(it):
>> """Doc string goes here"""
>> eatit(it)
>> return exhaust_iter
>>
>> exhaust_it = factory()
>> del factory
>>
>>
>> which will be about as efficient as you can get while still having a
>> custom docstring.
> 
> Surely no reason to go for the factory function:
> 
> def exhaust(it,eatit=deque(maxlen=0).extend):
>   eatit(it)

Now you have the function accept a second argument, which is public, just 
to hold a purely internal reference to something that you don't want the 
caller to replace.


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


Re: Documenting builtin methods

2013-07-11 Thread Chris Angelico
On Thu, Jul 11, 2013 at 5:15 PM, Steven D'Aprano  wrote:
> On Thu, 11 Jul 2013 17:06:39 +1000, Chris Angelico wrote:
>
>> On Thu, Jul 11, 2013 at 4:06 PM, Steven D'Aprano 
>> wrote:
>>> I think the right solution here is the trivial:
>>>
>>> def exhaust(it):
>>> """Doc string here."""
>>> deque(maxlen=0).extend(it)
>>>
>>>
>>> which will be fast enough for all but the tightest inner loops. But if
>>> you really care about optimizing this:
>>>
>>>
>>> def factory():
>>> eatit = deque(maxlen=0).extend
>>> def exhaust_iter(it):
>>> """Doc string goes here"""
>>> eatit(it)
>>> return exhaust_iter
>>>
>>> exhaust_it = factory()
>>> del factory
>>>
>>>
>>> which will be about as efficient as you can get while still having a
>>> custom docstring.
>>
>> Surely no reason to go for the factory function:
>>
>> def exhaust(it,eatit=deque(maxlen=0).extend):
>>   eatit(it)
>
> Now you have the function accept a second argument, which is public, just
> to hold a purely internal reference to something that you don't want the
> caller to replace.

True, but doesn't that happen fairly often with default args? Usually
it's in the "int=int" notation to snapshot for performance.

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


Re: Stack Overflow moder ator “animuson”

2013-07-11 Thread CM
On Wednesday, July 10, 2013 11:01:26 AM UTC-4, Steven D'Aprano wrote:
> Mats, I fear you have misunderstood. If the Python Secret Underground 
> existed, which it most certainly does not, it would absolutely not have 
> the power to censor people's emails or cut them off in the middle of
> 

*That's* the Python Secret Underground's special power?  That's it?!  Cutting 
people off in the middle of an email?  I mean how lame can 

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


Mypy

2013-07-11 Thread Steven D'Aprano
Things are certainly heating up in the alternate Python compiler field. 
Mypy is a new, experimental, implementation of Python 3 with optional 
static typing and aiming for efficient compilation to machine code.

http://www.mypy-lang.org/index.html




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


Re: Mypy

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 09:08, "Steven D'Aprano"  wrote:
>
> Things are certainly heating up in the alternate Python compiler field.
> Mypy is a new, experimental, implementation of Python 3 with optional
> static typing and aiming for efficient compilation to machine code.
>
> http://www.mypy-lang.org/index.html
>

Guido tweeted that yesterday. It seems interesting. Although I'm not
comfortable using a subset of the language.

They seem to want to kill the GIL. This could get much more popular when
they do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documenting builtin methods

2013-07-11 Thread Ben Finney
Joshua Landau  writes:

> On 11 July 2013 05:13, Joshua Landau  wrote:
> > 
>
> Ah, I get it. It is easy to misread my post as "I have this
> exhaust_iter" and it's obvious it doesn't work because why else would
> I post here what do I do HALP!

Right. Just because you think there's one obvious interpretation of your
cry for help, doesn't mean there's *only* one obvious interpretation.

It's best to be explicit: describe what behaviour you're seeing, and
what behaviour you're expecting to see.

-- 
 \   “We must respect the other fellow's religion, but only in the |
  `\   sense and to the extent that we respect his theory that his |
_o__) wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney

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


Re: Concurrent writes to the same file

2013-07-11 Thread Nobody
On Wed, 10 Jul 2013 22:57:09 -0600, Jason Friedman wrote:

> Other than using a database, what are my options for allowing two processes
> to edit the same file at the same time?  When I say same time, I can accept
> delays.

What do you mean by "edit"? Overwriting bytes and appending bytes are
simple enough, but inserting or deleting bytes such that subsequent bytes
change their offsets is harder.

> I considered lock files,

Well, you shouldn't have, unless you're targeting a platform which doesn't
support file locks (are there any left?).

> but I cannot conceive of how I avoid race conditions.

By using locks. E.g. fcntl.lockf() or msvcrt.locking().

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


ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread F.R.

Hi all,

I haven't been able to get up to speed with XML. I do examples from the 
tutorials and experiment with variations. Time and time again I fail 
with errors messages I can't make sense of. Here's the latest one. The 
url is "http://finance.yahoo.com/q?s=XIDEQ&ql=0";. Ubuntu 12.04 LTS, 
Python 2.7.3 (default, Aug  1 2012, 05:16:07) [GCC 4.6.3]


>>> import xml.etree.ElementTree as ET
>>> tree = ET.parse('q?s=XIDEQ')  # output of wget 
http://finance.yahoo.com/q?s=XIDEQ&ql=0

Traceback (most recent call last):
  File "", line 1, in 
tree = ET.parse('q?s=XIDEQ')
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
tree.parse(source, parser)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
self._raiseerror(v)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in 
_raiseerror

raise err
ParseError: mismatched tag: line 9, column 2

Below first nine lines. The line numbers and the following space are 
hand-edited in. Three dots stand for sections cut out to fit long lines. 
Line 6 is a bunch of "meta" statements, all of which I show on a 
separate line each in order to preserve the angled brackets. On all 
lines the angled brackets have been preserved. The mismatched character 
is the slash of the closing tag . What could be wrong with it? 
And if it is, what about fault tolerance?


1 
2 
3 
4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance
5 

  
  
  
  
  
  content="http://l.yimg.com/a/p/fi/31/09/00.jpg";>

  http://finance.yahoo.com/q?s=XIDEQ";>
  href="http://finance.yahoo.com/q?s=XIDEQ";>

8 http://l.yimg.com/zz/ . . . type="text/css">
9 
   ^
Mismatch!

Thanks for suggestions

Frederic

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


Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 10:04, "F.R."  wrote:
>
> Hi all,
>
> I haven't been able to get up to speed with XML. I do examples from the
tutorials and experiment with variations. Time and time again I fail with
errors messages I can't make sense of. Here's the latest one. The url is "
http://finance.yahoo.com/q?s=XIDEQ&ql=0";. Ubuntu 12.04 LTS, Python 2.7.3
(default, Aug  1 2012, 05:16:07) [GCC 4.6.3]
>
> >>> import xml.etree.ElementTree as ET
> >>> tree = ET.parse('q?s=XIDEQ')  # output of wget
http://finance.yahoo.com/q?s=XIDEQ&ql=0
> Traceback (most recent call last):
>   File "", line 1, in 
> tree = ET.parse('q?s=XIDEQ')
>   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
> tree.parse(source, parser)
>   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
> parser.feed(data)
>   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
> self._raiseerror(v)
>   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in
_raiseerror
> raise err
> ParseError: mismatched tag: line 9, column 2
>
> Below first nine lines. The line numbers and the following space are
hand-edited in. Three dots stand for sections cut out to fit long lines.
Line 6 is a bunch of "meta" statements, all of which I show on a separate
line each in order to preserve the angled brackets. On all lines the angled
brackets have been preserved. The mismatched character is the slash of the
closing tag . What could be wrong with it? And if it is, what about
fault tolerance?
>
> 1 
> 2 
> 3 
> 4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance
> 5 
>   
>   
>   
>   
>   
>   http://l.yimg.com/a/p/fi/31/09/00.jpg
">
>   http://finance.yahoo.com/q?s=XIDEQ";>
>   http://finance.yahoo.com/q?s=XIDEQ";>
> 8 http://l.yimg.com/zz/ . . .
type="text/css">
> 9 
>^
> Mismatch!
>
> Thanks for suggestions
>
> Frederic

That is not XML. It is HTML. You get a mismatched tag because the 
tag doesn't need closing in HTML, but in XML every single tag needs closing.

Use an HTML parser. I strongly recommend  BeautifulSoup but I think etree
has an HTML parser too. I am not sure..
-- 
http://mail.python.org/mailman/listinfo/python-list


Kivy for Python 3.3

2013-07-11 Thread fronagzen
Hello, first time poster here, and general newbie to Python.

I'm looking to write a program in Python, (and have in fact written most of it 
by now,) and am trying to put together a GUI for it. Kivy looks very nice, 
particularly with the fact that it's supposed to be compatible with most 
platforms (including Android, which I would like to be able to use my program 
on in addition to running it on my desktop) with minimal hassle. However, its 
current iteration is Python 2.7 only, and I've only learned Python 3.3.

I suppose I could learn Python 2.7, but I don't really want to. (Nor rewrite my 
program.) I could wait for the next release of Kivy, but who knows when that 
will be?

In any case, it's apparently possible to pull and compile the development 
version of Kivy for 3.3: 
https://groups.google.com/forum/#!topic/kivy-dev/pRp_02jaJww/discussion, 
however, I haven't succeeded in getting it to work. I'm on a Windows machine, 
and after a good deal of wrangling, I'm getting:

C:\Users\[SNIP]\Desktop\kivy-py3>python setup.py build_ext --inplace 
--compiler=mi
ngw32
[INFO  ] Kivy v1.8.0-dev
Windows platform detected, force GLEW usage.
running build_ext
Build configuration is:
 * use_mesagl = False
 * use_x11 = False
 * use_rpi = False
 * use_opengl_es2 = True
 * use_opengl_debug = False
 * use_sdl = False
 * use_ios = False
 * use_glew = True
Generate config.h
Generate config.pxi
cythoning kivy\properties.pyx to kivy\properties.c
building 'kivy.properties' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python33\include -IC:\Pytho
n33\include -c kivy\properties.c -o build\temp.win32-3.3\Release\kivy\properties
.o
writing build\temp.win32-3.3\Release\kivy\properties.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-3.3\Release\kivy\pr
operties.o build\temp.win32-3.3\Release\kivy\properties.def -LC:\Python33\libs -
LC:\Python33\PCbuild -lm -lpython33 -lmsvcr100 -o C:\Users\Lung\Desktop\kivy-py3
\kivy\properties.pyd
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot fin
d -lmsvcr100
collect2: ld returned 1 exit status
 error: command 'gcc' failed with exit status 1

I also tried to compile it with an Ubuntu virtual machine, but I failed hard on 
that since I'm not a native Linux user. Would anyone be able to help, either by 
suggesting how I can fix the above error, or, perhaps, by helping me compile 
Kivy?

(I did post this on the Kivy group, but I've not gotten any response there... 
The group's a bit dead.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread fronagzen
Actually, I don't think etree has a HTML parser. And I would counter-recommend 
lxml if speed is an issue: BeautifulSoup takes a long time to parse a large 
document.

On Thursday, July 11, 2013 5:08:04 PM UTC+8, Fábio Santos wrote:
> On 11 Jul 2013 10:04, "F.R."  wrote:
> 
> >
> 
> > Hi all,
> 
> >
> 
> > I haven't been able to get up to speed with XML. I do examples from the 
> > tutorials and experiment with variations. Time and time again I fail with 
> > errors messages I can't make sense of. Here's the latest one. The url is 
> > "http://finance.yahoo.com/q?s=XIDEQ&ql=0";. Ubuntu 12.04 LTS, Python 2.7.3 
> > (default, Aug  1 2012, 05:16:07) [GCC 4.6.3]
> 
> 
> >
> 
> > >>> import xml.etree.ElementTree as ET
> 
> > >>> tree = ET.parse('q?s=XIDEQ')  # output of wget 
> > >>> http://finance.yahoo.com/q?s=XIDEQ&ql=0
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> >     tree = ET.parse('q?s=XIDEQ')
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
> 
> >     tree.parse(source, parser)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
> 
> >     parser.feed(data)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
> 
> >     self._raiseerror(v)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in 
> > _raiseerror
> 
> >     raise err
> 
> > ParseError: mismatched tag: line 9, column 2
> 
> >
> 
> > Below first nine lines. The line numbers and the following space are 
> > hand-edited in. Three dots stand for sections cut out to fit long lines. 
> > Line 6 is a bunch of "meta" statements, all of which I show on a separate 
> > line each in order to preserve the angled brackets. On all lines the angled 
> > brackets have been preserved. The mismatched character is the slash of the 
> > closing tag . What could be wrong with it? And if it is, what about 
> > fault tolerance?
> 
> 
> >
> 
> > 1 
> 
> > 2 
> 
> > 3 
> 
> > 4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance
> 
> > 5 
> 
> >   
> 
> >   
> 
> >   
> 
> >   
> 
> >   
> 
> >   http://l.yimg.com/a/p/fi/31/09/00.jpg";>
> 
> >   http://finance.yahoo.com/q?s=XIDEQ";>
> 
> >    > href="http://finance.yahoo.com/q?s=XIDEQ";>
> 
> > 8 http://l.yimg.com/zz/ . . . type="text/css">
> 
> > 9 
> 
> >    ^
> 
> >     Mismatch!
> 
> >
> 
> > Thanks for suggestions
> 
> >
> 
> > Frederic
> 
> That is not XML. It is HTML. You get a mismatched tag because the  tag 
> doesn't need closing in HTML, but in XML every single tag needs closing.
> 
> Use an HTML parser. I strongly recommend  BeautifulSoup but I think etree has 
> an HTML parser too. I am not sure..

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


Re: Stack Overflow moderator “animuson”

2013-07-11 Thread Michael Torrie
On 07/10/2013 02:43 AM, Mats Peterson wrote:
> I fear you don’t even know what a regular expression is. Then this will
> of course not affect you.

Hmm, and your stack exchange posts had a similar tone, hmm?

I for one have never ready any of your posts on this forum before, so it
looks like you've come here solely to troll.  Perhaps your time would be
better spent contributing a faster regex engine to the Python standard
library.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to clean up socket connection to printer

2013-07-11 Thread loial
Replies to questions :

1. Does the printer accept connections again after some time? 

Yes, bit seems to vary how long that takes

2. Does the printer accept connections if you close and re-open the 
Python interpreter?

Not after a Connection reset error. The script exits after trapping the 
"Connection reset by peer" error and it is only when a new instance of the 
script is kicked off that the "Connection refused" issue is encountered.
 
3. Is there actually a limit to the number of concurrent connections? In 
other words, what happens when you try to create a second connection 
without closing the first? 

I get the Connction refused error in that scenerio too, but as my script exits 
after detecting the "Connection reset by peer error" there is only ever one 
instance of my script running(and therefore one attempt to connect) at a time, 
Which is why I am wondering whether the connection is closed properly by my 
code when the script exits afer the "Connection reset by peer" error. Or is it 
the printer not cleaning up the connection.?



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


Re: How to clean up socket connection to printer

2013-07-11 Thread Chris Angelico
On Thu, Jul 11, 2013 at 7:28 PM, loial  wrote:
> Replies to questions :
>
> 1. Does the printer accept connections again after some time?
>
> Yes, bit seems to vary how long that takes
>
> 2. Does the printer accept connections if you close and re-open the
> Python interpreter?
>
> Not after a Connection reset error. The script exits after trapping the 
> "Connection reset by peer" error and it is only when a new instance of the 
> script is kicked off that the "Connection refused" issue is encountered.
>

What's the network between you and the printer like? Are you, for
instance, going through an el cheapo NAT router? I've had some routers
that have a tendency to just randomly dump their NAT mappings (or so
it seems), which results in all manner of fun.

The "connection reset" error most likely means that you thought you
had a connection but the printer (or a router along the way, shouldn't
happen but see above) thought it didn't. You won't actually get the
error until you try to send some more data [1], which can result in
the variance in time. In fact, if the printer is indeed rebooting (as
per Ulrich's suggestion), you could get immediate success (reset,
reconnect, succeed), or you could get a delay of anything up to the
time it takes to reboot (if you "got in" straight after it went down).
What's the longest you've ever seen it take from conn reset to able to
connect again?

It's almost [2] certainly not that you're failing to properly close
the connection, though. I'd be inclined to simply code in a retry loop
(NOT instant, chances are you'll get some fast failures and you don't
want to spin; a progressive back-off delay is usually appropriate
here) and treat the failures as uninteresting.

ChrisA

[1] Unless you're using TCP keepalive, which you probably aren't.
[2] Insane stuff can be done, but hardware is presumed sane until
proven otherwise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 10:24,  wrote:
>
> Actually, I don't think etree has a HTML parser. And I would
counter-recommend lxml if speed is an issue: BeautifulSoup takes a long
time to parse a large document.
>
> On Thursday, July 11, 2013 5:08:04 PM UTC+8, Fábio Santos wrote:
> >
> > Use an HTML parser. I strongly recommend  BeautifulSoup but I think
etree has an HTML parser too. I am not sure..

I meant lxml. My apologies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread F.R.

On 07/11/2013 10:59 AM, F.R. wrote:

Hi all,

I haven't been able to get up to speed with XML. I do examples from 
the tutorials and experiment with variations. Time and time again I 
fail with errors messages I can't make sense of. Here's the latest 
one. The url is "http://finance.yahoo.com/q?s=XIDEQ&ql=0";. Ubuntu 
12.04 LTS, Python 2.7.3 (default, Aug  1 2012, 05:16:07) [GCC 4.6.3]


>>> import xml.etree.ElementTree as ET
>>> tree = ET.parse('q?s=XIDEQ')  # output of wget 
http://finance.yahoo.com/q?s=XIDEQ&ql=0

Traceback (most recent call last):
  File "", line 1, in 
tree = ET.parse('q?s=XIDEQ')
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
tree.parse(source, parser)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
self._raiseerror(v)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in 
_raiseerror

raise err
ParseError: mismatched tag: line 9, column 2

Below first nine lines. The line numbers and the following space are 
hand-edited in. Three dots stand for sections cut out to fit long 
lines. Line 6 is a bunch of "meta" statements, all of which I show on 
a separate line each in order to preserve the angled brackets. On all 
lines the angled brackets have been preserved. The mismatched 
character is the slash of the closing tag . What could be wrong 
with it? And if it is, what about fault tolerance?


1 
2 
3 

4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance
5 

  
  
  
  
  
  content="http://l.yimg.com/a/p/fi/31/09/00.jpg";>

  http://finance.yahoo.com/q?s=XIDEQ";>
  href="http://finance.yahoo.com/q?s=XIDEQ";>
8 http://l.yimg.com/zz/ . . . 
type="text/css">

9 
   ^
Mismatch!

Thanks for suggestions

Frederic


Thank you all!

I was a little apprehensive it could be a silly mistake. And so it was. 
I have BeautifulSoup somewhere. Having had no urgent need for it I 
remember shirking the learning curve.


lxml seems to be a package with these components (from help (lxml)):

PACKAGE CONTENTS
ElementInclude
_elementpath
builder
cssselect
doctestcompare
etree
html (package)
isoschematron (package)
objectify
pyclasslookup
sax
usedoctest

I would start with "from lxml import html" and see what comes out.

Break time now. Thanks again!

Frederic

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


Re: Kivy for Python 3.3

2013-07-11 Thread Ian Foote

On 11/07/13 10:09, fronag...@gmail.com wrote:

Hello, first time poster here, and general newbie to Python.

I'm looking to write a program in Python, (and have in fact written most of it 
by now,) and am trying to put together a GUI for it. Kivy looks very nice, 
particularly with the fact that it's supposed to be compatible with most 
platforms (including Android, which I would like to be able to use my program 
on in addition to running it on my desktop) with minimal hassle. However, its 
current iteration is Python 2.7 only, and I've only learned Python 3.3.

I suppose I could learn Python 2.7, but I don't really want to. (Nor rewrite my 
program.) I could wait for the next release of Kivy, but who knows when that 
will be?

In any case, it's apparently possible to pull and compile the development 
version of Kivy for 3.3: 
https://groups.google.com/forum/#!topic/kivy-dev/pRp_02jaJww/discussion, 
however, I haven't succeeded in getting it to work. I'm on a Windows machine, 
and after a good deal of wrangling, I'm getting:

C:\Users\[SNIP]\Desktop\kivy-py3>python setup.py build_ext --inplace 
--compiler=mi
ngw32
[INFO  ] Kivy v1.8.0-dev
Windows platform detected, force GLEW usage.
running build_ext
Build configuration is:
  * use_mesagl = False
  * use_x11 = False
  * use_rpi = False
  * use_opengl_es2 = True
  * use_opengl_debug = False
  * use_sdl = False
  * use_ios = False
  * use_glew = True
Generate config.h
Generate config.pxi
cythoning kivy\properties.pyx to kivy\properties.c
building 'kivy.properties' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python33\include -IC:\Pytho
n33\include -c kivy\properties.c -o build\temp.win32-3.3\Release\kivy\properties
.o
writing build\temp.win32-3.3\Release\kivy\properties.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-3.3\Release\kivy\pr
operties.o build\temp.win32-3.3\Release\kivy\properties.def -LC:\Python33\libs -
LC:\Python33\PCbuild -lm -lpython33 -lmsvcr100 -o C:\Users\Lung\Desktop\kivy-py3
\kivy\properties.pyd
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot fin
d -lmsvcr100
collect2: ld returned 1 exit status
  error: command 'gcc' failed with exit status 1

I also tried to compile it with an Ubuntu virtual machine, but I failed hard on 
that since I'm not a native Linux user. Would anyone be able to help, either by 
suggesting how I can fix the above error, or, perhaps, by helping me compile 
Kivy?

(I did post this on the Kivy group, but I've not gotten any response there... 
The group's a bit dead.)



Hi

Have you tried asking on the kivy irc channel? (#kivy on freenode, or 
http://webchat.freenode.net/?nick=kvuser.&channels=kivy&uio=d4)


The channel is fairly active, though you might have to wait a bit for a 
response.


I'm not a Windows user myself, so unfortunately I can't help with the 
issue directly.


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


Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread fronagzen
On Thursday, July 11, 2013 8:25:13 PM UTC+8, F.R. wrote:
> On 07/11/2013 10:59 AM, F.R. wrote:
> 
> > Hi all,
> 
> >
> 
> > I haven't been able to get up to speed with XML. I do examples from 
> 
> > the tutorials and experiment with variations. Time and time again I 
> 
> > fail with errors messages I can't make sense of. Here's the latest 
> 
> > one. The url is "http://finance.yahoo.com/q?s=XIDEQ&ql=0";. Ubuntu 
> 
> > 12.04 LTS, Python 2.7.3 (default, Aug  1 2012, 05:16:07) [GCC 4.6.3]
> 
> >
> 
> > >>> import xml.etree.ElementTree as ET
> 
> > >>> tree = ET.parse('q?s=XIDEQ')  # output of wget 
> 
> > http://finance.yahoo.com/q?s=XIDEQ&ql=0
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> > tree = ET.parse('q?s=XIDEQ')
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse
> 
> > tree.parse(source, parser)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
> 
> > parser.feed(data)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
> 
> > self._raiseerror(v)
> 
> >   File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in 
> 
> > _raiseerror
> 
> > raise err
> 
> > ParseError: mismatched tag: line 9, column 2
> 
> >
> 
> > Below first nine lines. The line numbers and the following space are 
> 
> > hand-edited in. Three dots stand for sections cut out to fit long 
> 
> > lines. Line 6 is a bunch of "meta" statements, all of which I show on 
> 
> > a separate line each in order to preserve the angled brackets. On all 
> 
> > lines the angled brackets have been preserved. The mismatched 
> 
> > character is the slash of the closing tag . What could be wrong 
> 
> > with it? And if it is, what about fault tolerance?
> 
> >
> 
> > 1 
> 
> > 2 
> 
> > 3 
> 
> > 4 XIDEQ: Summary for EXIDE TECH NEW- Yahoo! Finance
> 
> > 5 
> 
> >   
> 
> >   
> 
> >   
> 
> >   
> 
> >   
> 
> >
> > content="http://l.yimg.com/a/p/fi/31/09/00.jpg";>
> 
> >   http://finance.yahoo.com/q?s=XIDEQ";>
> 
> >
> > href="http://finance.yahoo.com/q?s=XIDEQ";>
> 
> > 8 http://l.yimg.com/zz/ . . . 
> 
> > type="text/css">
> 
> > 9 
> 
> >^
> 
> > Mismatch!
> 
> >
> 
> > Thanks for suggestions
> 
> >
> 
> > Frederic
> 
> >
> 
> Thank you all!
> 
> 
> 
> I was a little apprehensive it could be a silly mistake. And so it was. 
> 
> I have BeautifulSoup somewhere. Having had no urgent need for it I 
> 
> remember shirking the learning curve.
> 
> 
> 
> lxml seems to be a package with these components (from help (lxml)):
> 
> 
> 
> PACKAGE CONTENTS
> 
>  ElementInclude
> 
>  _elementpath
> 
>  builder
> 
>  cssselect
> 
>  doctestcompare
> 
>  etree
> 
>  html (package)
> 
>  isoschematron (package)
> 
>  objectify
> 
>  pyclasslookup
> 
>  sax
> 
>  usedoctest
> 
> 
> 
> I would start with "from lxml import html" and see what comes out.
> 
> 
> 
> Break time now. Thanks again!
> 
> 
> 
> Frederic

from lxml.html import parse
from lxml.etree import ElementTree
root = parse(target_url).getroot()

This'll get you the root node of the element tree parsed from the URL. The lxml 
html parser, conveniently enough, can combine in the actual web page access. If 
you want to control things like socket timeout, though, you'll have to use 
urllib to request the URL and then feed that to the parser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kivy for Python 3.3

2013-07-11 Thread Paul Kölle

Am 11.07.2013 11:09, schrieb fronag...@gmail.com:

Hello, first time poster here, and general newbie to Python.

I'm looking to write a program in Python, (and have in fact written
most of it by now,) and am trying to put together a GUI for it. Kivy
looks very nice, particularly with the fact that it's supposed to be
compatible with most platforms (including Android, which I would like
to be able to use my program on in addition to running it on my
desktop) with minimal hassle. However, its current iteration is
Python 2.7 only, and I've only learned Python 3.3.

[ snipp ]

C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe:
cannot fin d -lmsvcr100 collect2: ld returned 1 exit status error:
command 'gcc' failed with exit status 1


It might help copying msvcr100.dll (from MS VC++ Redistributable 
Package) to c:\python33\libs (or wherever your python install is). See 
http://bugs.python.org/issue15315 msg191106


hth
 Paul


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


Re: Kivy for Python 3.3

2013-07-11 Thread Ulrich Eckhardt

Welcome to Python!

Am 11.07.2013 11:09, schrieb fronag...@gmail.com:

I'm looking to write a program in Python, (and have in fact written
most of it by now,) and am trying to put together a GUI for it. Kivy
looks very nice, particularly with the fact that it's supposed to be
compatible with most platforms (including Android, which I would like
to be able to use my program on in addition to running it on my
desktop) with minimal hassle. However, its current iteration is
Python 2.7 only, and I've only learned Python 3.3.


Last I looked, which was half a year ago, there was some Python 3 
porting of Kivy underway, as you found yourself. If I were you, I would 
get on IRC (I think it was #kivy on irc.freenode.net) and try to contact 
the people there about the state of the Python 3 port. Just have some 
patience, there aren't hundreds of people (yet), so getting an answer 
could take some time.



C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe:
cannot fin d -lmsvcr100 collect2: ld returned 1 exit status error:
command 'gcc' failed with exit status 1


'msvcr100' is the C runtime of MS Visual C++, I'm not sure if it is 
required for building Python modules on MS Windows. Just removing it 
from the commandline (or makefile) should tell you already. 
Alternatively, ask The Internet(R), http://bugs.python.org/issue15315 
could be an answer. ;)


Good luck!

Uli

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


Callable or not callable, that is the question!

2013-07-11 Thread Ulrich Eckhardt

Hello!

I just stumbled over a case where Python (2.7 and 3.3 on MS Windows) 
fail to detect that an object is a function, using the callable() 
builtin function. Investigating, I found out that the object was indeed 
not callable, but in a way that was very unexpected to me:


class X:
@staticmethod
def example():
pass
test1 = example
test2 = [example,]

X.example() # OK
X.test1() # OK
X.test2[0]() # TypeError: 'staticmethod' object is not callable


Bug or feature?


Thanks!

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-11 Thread wxjmfauth
Le lundi 8 juillet 2013 19:52:17 UTC+2, Chris Angelico a écrit :
> On Tue, Jul 9, 2013 at 3:31 AM,   wrote:
> 
> > Unfortunately (as probably I told you before) I will never pass to
> 
> > Python 3...  Guido should not always listen only to gurus like him...
> 
> > I don't like Python as before...starting from OOP and ending with codecs
> 
> > like utf-8. Regarding OOP, much appreciated expecially by experts, he
> 
> > could use python 2 for hiding the complexities of OOP (improving, as an
> 
> > effect, object's code hiding) moving classes and objects to
> 
> > imported methods, leaving in this way the programming style to the
> 
> > well known old style: sequential programming and functions.
> 
> > About utf-8... the same solution: keep utf-8 but for the non experts, add
> 
> > methods to convert to solutions which use the range 128-255 of only one
> 
> > byte (I do not give a damn about chinese and "similia"!...)
> 
> > I know that is a lost battle (in italian "una battaglia persa")!
> 
> 
> 
> Well, there won't be a Python 2.8, so you really should consider
> 
> moving at some point. Python 3.3 is already way better than 2.7 in
> 
> many ways, 3.4 will improve on 3.3, and the future is pretty clear.
> 
> But nobody's forcing you, and 2.7.x will continue to get
> 
> bugfix/security releases for a while. (Personally, I'd be happy if
> 
> everyone moved off the 2.3/2.4 releases. It's not too hard supporting
> 
> 2.6+ or 2.7+.)
> 
> 
> 
> The thing is, you're thinking about UTF-8, but you should be thinking
> 
> about Unicode. I recommend you read these articles:
> 
> 
> 
> http://www.joelonsoftware.com/articles/Unicode.html
> 
> http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/
> 
> 
> 
> So long as you are thinking about different groups of characters as
> 
> different, and wanting a solution that maps characters down into the
> 
> <256 range, you will never be able to cleanly internationalize. With
> 
> Python 3.3+, you can ignore the differences between ASCII, BMP, and
> 
> SMP characters; they're all just "characters". Everything works
> 
> perfectly with Unicode.
> 

---

Just to stick with this funny character ẞ, a ucs-2 char
in the Flexible String Representation nomenclature.

It seems to me that, when one needs more than ten bytes
to encode it, 

>>> sys.getsizeof('a')
26
>>> sys.getsizeof('ẞ')
40

this is far away from the perfection.

BTW, for a modern language, is not ucs2 considered
as obsolete since many, many years?

jmf



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


Re: hex dump w/ or w/out utf-8 chars

2013-07-11 Thread Chris Angelico
On Thu, Jul 11, 2013 at 11:18 PM,   wrote:
> Just to stick with this funny character ẞ, a ucs-2 char
> in the Flexible String Representation nomenclature.
>
> It seems to me that, when one needs more than ten bytes
> to encode it,
>
 sys.getsizeof('a')
> 26
 sys.getsizeof('ẞ')
> 40
>
> this is far away from the perfection.

Better comparison is to see how much space is used by one copy of it,
and how much by two copies:

>>> sys.getsizeof('aa')-sys.getsizeof('a')
1
>>> sys.getsizeof('ẞẞ')-sys.getsizeof('ẞ')
2

String objects have overhead. Big deal.

> BTW, for a modern language, is not ucs2 considered
> as obsolete since many, many years?

Clearly. And similarly, the 16-bit integer has been completely
obsoleted, as there is no reason anyone should ever bother to use it.
Same with the float type - everyone uses double or better these days,
right?

http://www.postgresql.org/docs/current/static/datatype-numeric.html
http://www.cplusplus.com/doc/tutorial/variables/

Nope, nobody uses small integers any more, they're clearly completely obsolete.

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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Roy Smith
In article <2fdf282e-fd28-4ba3-8c83-ce120...@googlegroups.com>,
 jus...@zeusedit.com wrote:

> On Wednesday, July 10, 2013 2:17:12 PM UTC+10, Xue Fuqiao wrote:
> 
> > * It is especially handy for selecting and deleting text.
> 
> When coding I never use a mouse to select text regions or to delete text.
> 
> These operations I do using just the keyboard.

For good typists, there is high overhead to getting your hands oriented 
on the keyboard (that's why the F and J keys have little bumps).  So, 
any time you move your hand from the keyboard to the mouse, you pay a 
price.

The worst thing is to constantly be alternating between mouse actions 
and keyboard actions.  You spend all your time getting your fingers 
hands re-oriented.  That's slow.  This is why I never understood the 
attraction of something like xemacs, where you use the mouse to make 
text selections and run commands out of menus.  It means you have to 
keep switching hand modes.  I use emacs in non-window mode, which means 
my hands never leave the keyboard.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Callable or not callable, that is the question!

2013-07-11 Thread Peter Otten
Ulrich Eckhardt wrote:

> Hello!
> 
> I just stumbled over a case where Python (2.7 and 3.3 on MS Windows)
> fail to detect that an object is a function, using the callable()
> builtin function. Investigating, I found out that the object was indeed
> not callable, but in a way that was very unexpected to me:
> 
>  class X:
>  @staticmethod
>  def example():
>  pass
>  test1 = example
>  test2 = [example,]
> 
>  X.example() # OK
>  X.test1() # OK
>  X.test2[0]() # TypeError: 'staticmethod' object is not callable

Slightly modified example:

>>> @staticmethod
... def example(): return 42
... 
>>> class X:
... example = example
... 
>>> X.example()
42
>>> example()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'staticmethod' object is not callable

When you access an attribute its __get__() method is implicitly called. This 
is part of the descriptor protocol:

>>> X.example

>>> example

>>> example.__get__(X)


While it would be easy to make staticmethod callable

>>> class Staticmethod(staticmethod):
... def __call__(self, *args, **kw):
... return self.__func__(*args, **kw)
... 
>>> @Staticmethod
... def foo(): return "bar"
... 
>>> foo()
'bar'
>>> X.baz = foo
>>> X.baz()
'bar'

I see no clear advantage over the current situation.

> Bug or feature?

No bug. Missing feature if you come up with a convincing use-case.

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


Re: Callable or not callable, that is the question!

2013-07-11 Thread Jason Swails
On Thu, Jul 11, 2013 at 9:05 AM, Ulrich Eckhardt <
ulrich.eckha...@dominolaser.com> wrote:

> Hello!
>
> I just stumbled over a case where Python (2.7 and 3.3 on MS Windows) fail
> to detect that an object is a function, using the callable() builtin
> function. Investigating, I found out that the object was indeed not
> callable, but in a way that was very unexpected to me:
>
> class X:
> @staticmethod
> def example():
> pass
> test1 = example
> test2 = [example,]
>
> X.example() # OK
> X.test1() # OK
> X.test2[0]() # TypeError: 'staticmethod' object is not callable
>

Interestingly, you can actually use this approach to 'fake' staticmethod
before staticmethod was even introduced.  By accessing example from inside
the test2 class attribute list, there is no instance bound to that method
(even if an instance was used to access it).

Using Python 3.3:

Python 3.3.2 (default, Jun  3 2013, 08:29:09)
[GCC 4.5.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class X:
... def example(): pass
... test = example,
...
>>> X.test[0]()
>>>

Using Python 2.0 (pre-staticmethod):

Python 2.0.1 (#1, Aug 28 2012, 20:25:41)
[GCC 4.5.3] on linux3
Type "copyright", "credits" or "license" for more information.
>>> class X:
... def example(): pass
... test = example,
...
>>> X.test[0]()
>>> staticmethod
Traceback (most recent call last):
  File "", line 1, in ?
NameError: There is no variable named 'staticmethod'

Once you change test into an instance attribute, you get back to the
expected behavior

Python 3.3.2 (default, Jun  3 2013, 08:29:09)
[GCC 4.5.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class X:
... def example(self): pass
... test = example,
...
>>> inst = X()
>>> inst.example()
>>> inst.test[0]()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: example() missing 1 required positional argument: 'self'
>>> inst.test = inst.example,
>>> inst.test[0]()
>>>

All the best,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kivy for Python 3.3

2013-07-11 Thread fronagzen
On Thursday, July 11, 2013 9:17:07 PM UTC+8, Paul Kölle wrote:
> Am 11.07.2013 11:09, schrieb fronag...@gmail.com:
> 
> > Hello, first time poster here, and general newbie to Python.
> 
> >
> 
> > I'm looking to write a program in Python, (and have in fact written
> 
> > most of it by now,) and am trying to put together a GUI for it. Kivy
> 
> > looks very nice, particularly with the fact that it's supposed to be
> 
> > compatible with most platforms (including Android, which I would like
> 
> > to be able to use my program on in addition to running it on my
> 
> > desktop) with minimal hassle. However, its current iteration is
> 
> > Python 2.7 only, and I've only learned Python 3.3.
> 
> [ snipp ]
> 
> > C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe:
> 
> > cannot fin d -lmsvcr100 collect2: ld returned 1 exit status error:
> 
> > command 'gcc' failed with exit status 1
> 
> 
> 
> It might help copying msvcr100.dll (from MS VC++ Redistributable 
> 
> Package) to c:\python33\libs (or wherever your python install is). See 
> 
> http://bugs.python.org/issue15315 msg191106
> 
> 
> 
> hth
> 
>   Paul

Thanks for the response, and I swear that I did try googling the error, but 
didn't find anything. Oh well. Anyway, it seems that adding msvcr100.dll to my 
python3.3\libs has done something. I'm getting a different file not found 
message now:


C:\Users\[SNIP]\Desktop\kivy-py3>python setup.py build_ext --inplace
[INFO  ] Kivy v1.8.0-dev
Windows platform detected, force GLEW usage.
running build_ext
Build configpython setup.py build_ext --inplace --compiler
=mingw32
[INFO  ] Kivy v1.8.0-dev
Windows platform detected, force GLEW usage.
running build_ext
Build configuration is:
 * use_glew = True
 * use_ios = False
 * use_opengl_debug = False
 * use_opengl_es2 = True
 * use_rpi = False
 * use_mesagl = False
 * use_x11 = False
 * use_sdl = False
Generate config.h
Generate config.pxi
skipping 'kivy\graphics\vertex_instructions.c' Cython extension (up-to-date)
building 'kivy.graphics.vertex_instructions' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python33\include -IC:\Python33\include
-c kivy\graphics\vertex_instructions.c -o build\temp.win32-3.3\Release\kivy\grap
hics\vertex_instructions.o
In file included from kivy\graphics\vertex_instructions.c:314:0:
kivy\graphics\/gl_redirect.h:8:22: fatal error: GL/glew.h: No such file or direc
tory
compilation terminated.
 error: command 'gcc' failed with exit status 1

Working on the reasoning that sticking the missing file into the python3.3\libs 
file worked, I tried adding the glew files (glew32.dll, glew32.lib, GL\glew and 
GL\wglew.h) there, however, it doesn't seem to have made a difference. And this 
I googled this before asking. Doesn't seem to be much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Oportunidade: Estagiário (Wanna-be-developer) - RJ

2013-07-11 Thread zughumancapital
Arpex Capital seleciona para uma de suas startups: 
Estagiário (Wanna-be-developer)
Objetivo geral da Posição:
Se divertir programando, resolvendo problemas e aprendendo coisas novas.
Pré-requisitos:
Conhecimento de Ruby on Rails ou Python ou Node.js ou Angular.js, conhecimento 
UNIX e vontade de aprender o que não souber e for necessário. Também é 
importante que tenha github ou alguma forma de conferir projetos antigos já 
realizados para que possamos avaliar.
 Se não usar Windows (ou seja, usar Mac ou Linux), é um mega plus.
Ultra plus: usar Vim, Emacs ou SublimeText como editores de texto e/ou estar 
disposto a mudar para um melhor.
Deveres:
Ser obcecado em entender e resolver problemas: procuramos alguém que durma mal 
se tiver um problema a ser resolvido, e que acorde pensando nele. 
Ter MUITA vontade de aprender e crescer, assim como gostar de novas 
tecnologias. NÃO procuramos alguém que esteja preso a tecnologias específicas 
e/ou pouco aberto a mudanças. Não existe "bala de prata" no nosso mundo.
Formação:
Não importa. Se souber programar e for autodidata, tá valendo.
Principais Competências a serem observadas:
Capacidade de aprender rápido.
Buscamos os melhores desenvolvedores do Brasil. Não importa a linguagem. 
Queremos os nerds, não estamos preocupados e nem nos interessamos naqueles que 
querem parecer que são os melhores, queremos os que são os melhores de fato. 
Amamos os que amam programar e que programam desde a adolescência ou infância. 
Estamos aqui para ter o melhor time do Brasil!
Bolsa Auxílio + Vale Refeição + Vale Transporte
Local de Trabalho: Centro/RJ
Os interessados deverão enviar o CV para kgar...@arpexcapital.com.br, 
mencionando no assunto  Estagiário (Wanna-be-developer). 


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


Re: xslice idea | a generator slice

2013-07-11 Thread Russel Walker
...oh and here is the class I made for it.

class xslice(object):
'''
xslice(seq, start, stop, step) -> generator slice
'''

def __init__(self, seq, *stop):
if len(stop) > 3:
raise TypeError("xslice takes at most 4 arguments")
elif len(stop) < 0:
raise TypeError("xslice requires atleast 2 arguments")
else:
start, stop, step = (((0,) + stop[:2])[-2:] +  # start, stop
 (stop[2:] + (1,))[:1])# step
stop = min(stop, len(seq))
self._ind = iter(xrange(start, stop, step))
self._seq = seq

def __iter__(self):
return self

def next(self):
return self._seq[self._ind.next()]



Although now that I think about it, it probably should've just been a simple 
generator function.
-- 
http://mail.python.org/mailman/listinfo/python-list


xslice idea | a generator slice

2013-07-11 Thread Russel Walker
Just some dribble, nothing major.

I like using slices but I also noticed that a slice expression returns a new 
sequence.

I sometimes find myself using them in a for loop like this:


seq = range(10)
for even in seq[::2]:
print even


(That's just for an example) But wouldn't it be a bit of a waste if the slice 
expression returns a whole new list just when all you want to do in this case 
is iterate over it once?

I suppose you could get around that will a little more code like:


seq = range(10)
for x in xrange(0, len(seq), 2):
print seq[x]


But it would be nice there was a way to iterate over a 'slice' of sorts, that 
would act as a generator.

So I tried my handle at a little class called xslice (the x from xrange to 
indicate its a generator (although I'm not sure if that's technically correct)).

With it, instead of the above example you can do:


seq = range(10)
for even in xslice(seq, 0, len(seq), 2):
print even


It would be more or less like using xrange. I know the syntax is not that much 
of an improvement over just using exrange and retrieving items by index, but 
it's the concept I'm looking at.

Do you think this or something like be a builtin in the future?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: psutil 1.0.0 released

2013-07-11 Thread Giampaolo Rodola'
> Congratulations on the 1.0.0 release!

Thanks a lot. =)

>   Btw. any change you can put up a prebuilt installer for a 64-bit built
> with Python 3.3? You have one for Python 3.2
> (http://code.google.com/p/psutil/downloads/list), but the version for Python
> 3.3 is not there.

Unfortunately I'm having troubles with Visual Studio 64-bit I still
haven't managed to fix.
Hope I will get around that soon.

--- Giampaolo

http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
http://code.google.com/p/pysendfile/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 15:54, Russel Walker  wrote:
> ...oh and here is the class I made for it.
>
> class xslice(object):
> '''
> xslice(seq, start, stop, step) -> generator slice
> '''
>
> def __init__(self, seq, *stop):

Wouldn't it be better if it has the same signature(s) as itertools.islice?

> if len(stop) > 3:
> raise TypeError("xslice takes at most 4 arguments")
> elif len(stop) < 0:

How would len(stop) be negative?

> raise TypeError("xslice requires atleast 2 arguments")
> else:
> start, stop, step = (((0,) + stop[:2])[-2:] +  # start, stop
>  (stop[2:] + (1,))[:1])# step
> stop = min(stop, len(seq))
> self._ind = iter(xrange(start, stop, step))
> self._seq = seq
>
> def __iter__(self):
> return self
>
> def next(self):
> return self._seq[self._ind.next()]
>
>
>
> Although now that I think about it, it probably should've just been a simple 
> generator function.

Or you can use itertools.imap:

def xslice(sequence, start_or_stop, *args):
indices = xrange(*slice(start_or_stop, *args).indices(len(sequence)))
return imap(sequence.__getitem__, indices)


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


Re: ANN: psutil 1.0.0 released

2013-07-11 Thread 88888 Dihedral
Giampaolo Rodola'於 2013年7月11日星期四UTC+8下午11時02分01秒寫道:
> > Congratulations on the 1.0.0 release!
> 
> 
> 
> Thanks a lot. =)
> 
> 
> 
> >   Btw. any change you can put up a prebuilt installer for a 64-bit built
> 
> > with Python 3.3? You have one for Python 3.2
> 
> > (http://code.google.com/p/psutil/downloads/list), but the version for Python
> 
> > 3.3 is not there.
> 
> 
> 
> Unfortunately I'm having troubles with Visual Studio 64-bit I still
> 
> haven't managed to fix.
> 
> Hope I will get around that soon.
> 
> 
> 
> --- Giampaolo
> 
> 
> 
> http://code.google.com/p/pyftpdlib/
> 
> http://code.google.com/p/psutil/
> 
> http://code.google.com/p/pysendfile/

Do you plan to install 8 or 16 G BYTES DRAM?
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
How do I get the OS System Font Directory(Cross-Platform) in python?

Need a simple script for
Windows, Linux, Mac, etc..

Or using wxPython.

I can't seem to find anything that works, and I don't want to hard-code paths.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Paul Rudin
Roy Smith  writes:

>  This is why I never understood the attraction of something like
> xemacs, where you use the mouse to make text selections and run
> commands out of menus.

Menus are good for learning the functionality, and you have them just as
much in Gnu emacs as in xemacs. You can even use them absent a windowing
system! Text selection with a mouse is a different thing. Sometimes it's
more convenient, sometimes it's not.

But I agree with your general point - it's often quicker to keep your
hands in position, which is where knowing keybinds for everything
scores.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris “Kwpolska” Warrick
On Thu, Jul 11, 2013 at 5:32 PM, Metallicow  wrote:
> How do I get the OS System Font Directory(Cross-Platform) in python?
>
> Need a simple script for
> Windows, Linux, Mac, etc..
>
> Or using wxPython.
>
> I can't seem to find anything that works, and I don't want to hard-code paths.
> --
> http://mail.python.org/mailman/listinfo/python-list

Why do you want the paths to the fonts?  You do not need them 99.9% of
the time.  So, what *exactly* are you trying to accomplish?
--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Chris Angelico
On Fri, Jul 12, 2013 at 1:42 AM, Paul Rudin  wrote:
> Text selection with a mouse is a different thing. Sometimes it's
> more convenient, sometimes it's not.

As screens get larger and the amount of text on them increases, it's
likely to get more and more useful to use a mouse... but personally, I
still find the switch-to-mouse operation so clunky on anything except
a Thinkpad that I'll use the keyboard even if it's a bit slower. (Why
are Thinkpads different? Because the mouse, which is excellent, is
right under my fingers, between G/H/B. It's less hassle to move to the
mouse than, say, to hit Backspace, which I do quite a bit while
typing. Effectively, I can touch-type the mouse. A HUGE advantage.)

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


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
For a portable font install tool.

Finding if a particular font exists,
useful when testing apps in virtual environent,
rendering text from a font,
Font file manipulations,
etc..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Concurrent writes to the same file

2013-07-11 Thread Neal Becker
Dave Angel wrote:

> On 07/11/2013 12:57 AM, Jason Friedman wrote:
>> Other than using a database, what are my options for allowing two processes
>> to edit the same file at the same time?  When I say same time, I can accept
>> delays.  I considered lock files, but I cannot conceive of how I avoid race
>> conditions.
>>
> 
> In general, no.  That's what a database is for.
> 
> Now, you presumably have some reason to avoid database, but in its stead
> you have to specify some other limitations.  To start with, what do you
> mean by "the same time"?  If each process can modify the entire file,
> then there's no point in one process reading the file at all until it
> has the lock.  So the mechanism would be
>1) wait till you can acquire the lock
>2) open the file, read it, modify it, flush and close
>3) release the lock
> 
> To come up with an appropriate lock, it'd be nice to start by specifying
> the entire environment.  Which Python, which OS?  Are the two processes
> on the same CPU, what's the file system, and is it locally mounted?
> 
> 
> 
> 

You can use a seperate server process to do file I/O, taking multiple inputs 
from clients.  Like syslogd.

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


Re: Wedding Planning Shortcuts

2013-07-11 Thread Alister
On Wed, 10 Jul 2013 23:42:14 -0700, fletcherbenjiaa wrote:

> A wedding is truly a labor of love for most engaged couples, and it's
> natural to feel a bit wary of the wedding planning process. However, it
> doesn't have to be so intimidating or cumbersome. Sure there are lots of
> details in even the smallest wedding, but most brides have months (and
> sometimes years) until the big day. And even though procrastination can
> sneak in here and there, you have time to get done what you need to plan
> the wedding of your dreams.
> 
> 
> 
> 
> -
> wedding planners uk

so where can i download this python module?



-- 
Send some filthy mail.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris “Kwpolska” Warrick
On Thu, Jul 11, 2013 at 08:54:17AM -0700, Metallicow wrote:
> For a portable font install tool.
> 
> Finding if a particular font exists,
> useful when testing apps in virtual environent,
> rendering text from a font,
> Font file manipulations,
> etc..
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Then do a nice little `if` checking the user’s OS.

http://docs.python.org/2/library/sys.html#sys.platform hints what to use,
and you need to do:

if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
FONTDIRS = [os.path.join(os.environ['WINDIR'], 'Fonts')
elif sys.platform.startswith('darwin'):
# [see below and devise it yourself]
else: # linux, *bsd and everything else
# [see below, commit suicide and develop this bit]

Windows:
The easiest of those three, all the fonts are in %WINDIR%/Fonts.
In Python: os.path.join(os.environ['WINDIR'], 'Fonts')

Mac OS X:
http://support.apple.com/kb/ht2435 (and not all of them are
guaranteed to exist).  `os.expanduser()` may be useful for
that first one.

Linux, and everything else running that fancy open stuff (eg. *BSD):
Hardcore.  You just need to parse a nice tiny 155-line XML file.

It’s /etc/fonts/fonts.conf, and it has some  tags.
Some of them may have a `prefix="xdg"` attribute which makes you
prepend the value with $XDG_DATA_HOME (~/.local/share if that is
empty).  You also need `os.expanduser()`.

Oh: and you need to go recursively through them, as subdirectories
are also checked for fonts (and it probably goes further)

-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html


pgpyE7rGDxSU2.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: psutil 1.0.0 released

2013-07-11 Thread Dotan Cohen
Thanks, this looks really nice. I was duplicating some of this for my
CLI-based webserver control panel:
https://github.com/dotancohen/burton

As soon as I integrate psutil into Burton I'll add it to the README
and such. How would you like me to mention attribution exactly?

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 8:52 AM, Russel Walker  wrote:
> Just some dribble, nothing major.
>
> I like using slices but I also noticed that a slice expression returns a new 
> sequence.
>
> I sometimes find myself using them in a for loop like this:
>
>
> seq = range(10)
> for even in seq[::2]:
> print even
>
>
> (That's just for an example) But wouldn't it be a bit of a waste if the slice 
> expression returns a whole new list just when all you want to do in this case 
> is iterate over it once?
>
> I suppose you could get around that will a little more code like:
>
>
> seq = range(10)
> for x in xrange(0, len(seq), 2):
> print seq[x]
>
>
> But it would be nice there was a way to iterate over a 'slice' of sorts, that 
> would act as a generator.

That would be the itertools.islice function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xslice idea | a generator slice

2013-07-11 Thread Russel Walker
> > def __init__(self, seq, *stop):
> 
> 
> 
> Wouldn't it be better if it has the same signature(s) as itertools.islice?

That's actually what I was going for, except I was modeling it after range, but 
that was the only way I knew to implement it.


> > if len(stop) > 3:
> 
> > raise TypeError("xslice takes at most 4 arguments")
> 
> > elif len(stop) < 0:
> 
> 
> 
> How would len(stop) be negative?


Yes, that should've been len(stop) < 1.


> Or you can use itertools.imap:
> 
> 
> 
> def xslice(sequence, start_or_stop, *args):
> 
> indices = xrange(*slice(start_or_stop, *args).indices(len(sequence)))
> 
> return imap(sequence.__getitem__, indices)
> 
> 
> 
> 
> 
> Oscar


I like the way you did that with imap, although I still like my parameter 
implementation.

To confess, this is the second time I've made the mistake of trying to 
implement generator like functionality of a builtin when there already is on in 
itertools. Need to start studying that module abit more I think. I'm looking at 
the docs now and I see there are actually a couple of isomethings().

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


Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 17:21, Russel Walker  wrote:
> To confess, this is the second time I've made the mistake of trying to 
> implement generator like functionality of a builtin when there already is on 
> in itertools. Need to start studying that module abit more I think. I'm 
> looking at the docs now and I see there are actually a couple of 
> isomethings().

Your xslice (or mine) would still be better than islice when the step
size is large; islice has to iterate over all the skipped elements
which could be wasteful if the input is indexable. Also islice doesn't
support negative values for start, stop or step which xslice does.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
@ Chris “Kwpolska” Warrick
Thanks, that is a start anyway. 
a Pure-Python way was what I was wanting, not win32api stuff.

"C:\Windows\Fonts"
The windows path proves valid. Works on XP, Vista, 7. Not sure about win8...?

Don't have a mac handy, but the link should be enough to help write some code 
before testing. I don't own a mac, but IIRC macs come with python installed, so 
a trip to the apple shop might be in order.

As far as linux goes, basically Ubuntu/Kubuntu(dirivs), Mandriva/Mageia, Mint, 
and some of the more popular distros is all I am really looking for. Checking 
for these is VirtualBox shouldn't be too hard with your instructions and 
platform.linux_distribution()

Thanks again.
Here is the 'Open Font License 1.1 (OFL 1.1)' Fonts I will be using.
http://sourceforge.net/projects/sourcecodepro.adobe/
http://sourceforge.net/projects/sourcesans.adobe/

Also found these links that might help with pathing.
http://www.fontation.com/feature/
http://www.yearbooks.biz/?event=FAQ.Detail&faq=3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Nobody
On Thu, 11 Jul 2013 08:32:34 -0700, Metallicow wrote:

> How do I get the OS System Font Directory(Cross-Platform) in python?

What makes you think the system *has* a system font directory?

In the traditional X11 model, the only program which needs fonts is the X
server, and that can be configured to get its fonts from a font server
rather than from a local directory. Even if it doesn't use a font server,
the font directory will be on the system running the X server, not the one
running the client.

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


Re: Mypy

2013-07-11 Thread Stefan Behnel
Fábio Santos, 11.07.2013 10:16:
> Guido tweeted that yesterday. It seems interesting. Although I'm not
> comfortable using a subset of the language.
> 
> They seem to want to kill the GIL. This could get much more popular when
> they do.

Then don't forget to also take a look at Cython.

Stefan


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


Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 10:34 AM, Oscar Benjamin
 wrote:
> On 11 July 2013 17:21, Russel Walker  wrote:
>> To confess, this is the second time I've made the mistake of trying to 
>> implement generator like functionality of a builtin when there already is on 
>> in itertools. Need to start studying that module abit more I think. I'm 
>> looking at the docs now and I see there are actually a couple of 
>> isomethings().
>
> Your xslice (or mine) would still be better than islice when the step
> size is large; islice has to iterate over all the skipped elements
> which could be wasteful if the input is indexable. Also islice doesn't
> support negative values for start, stop or step which xslice does.

Ah, that's an interesting point.  Of course the corollary to that is
that xslice requires a sequence, not just an iterable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
On Thursday, July 11, 2013 12:47:01 PM UTC-5, Nobody wrote:
> 
> What makes you think the system *has* a system font directory?

Way back when I was kid, I remember a computer that had two colors and 1 
built-in font and no mouse. Heck the keyboard was even attached in front a tube 
screen box. 
Wow... those were the days. And to think I hated that thing...

If the OS doesn't *have* a dedicated system fonts dir that is accessable by the 
user, then I am not that much interested in dealing with it. Rendering a font 
from a other location will eventually be worked in, but that isn't the problem 
at hand.

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


Re: the general development using Python

2013-07-11 Thread CM
On Wednesday, July 10, 2013 7:57:11 PM UTC-4, Joshua Landau wrote:

> Yeah, but why keep shipping the Python interpreter? If you choose the 
> installer route, you don't have to keep shipping it -- it's only
> downloaded if you need it. If not, then you don't download it again.

I admit that not necessarily shipping the Python interpreter is much more 
efficient if your client base is expected to be a lot of people who already 
have Python and a lot of the common libraries (like wxPython).  I have a fair 
number of Python 3rd party libraries already on my computer, so for me, it is 
preferable to just download the .py files the developer has made.  

For some of the things I have thought about doing, though, the majority of the 
clients would never even have heard of Python other than Monty or the 
constrictor.  



> But I still think my way is better. Perhaps I'm just too pragmatic 
> about these things. This was triggered by the OP's original request --
> he sounds very much like he doesn't actually want this -- and it seems
> to have stuck. I don't know if being pragmatic is a bad thing, though.

I'll definitely think about the business angle of doing it the way you suggest. 
 For example, for consulting work where the end user is a technical worker who 
just need a script to automate some processes, and you expect to be providing a 
number of scripts over time in this way, a good way to install and setup a 
Python + GUI toolkit + other likely necessary libraries would be great.  For 
more "product sales to the mass populous", I'm less sure.
 
> In the end, something like this is best solved with a bit of A/B
> testing¹. Sit a couple of your audience down, give them the best
> implementation of each strategy (starting from the website) for some
> trivialised module and see what they think. If it turns out that being
> pragmatic does have compromises, I'm not going to argue with the data.
> I'd still be grumpy, though.

Makes sense.  I'm dubious about the full validity of A/B testing data without 
large data sets, but yes, at least one would be getting a feel for it.  I can 
also see what other projects/businesses are doing.

Thanks for the input!

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-11 Thread wxjmfauth
Le jeudi 11 juillet 2013 20:42:26 UTC+2, wxjm...@gmail.com a écrit :
> Le jeudi 11 juillet 2013 15:32:00 UTC+2, Chris Angelico a écrit :
> 
> > On Thu, Jul 11, 2013 at 11:18 PM,   wrote:
> 
> > 
> 
> > > Just to stick with this funny character ẞ, a ucs-2 char
> 
> > 
> 
> > > in the Flexible String Representation nomenclature.
> 
> > 
> 
> > >
> 
> > 
> 
> > > It seems to me that, when one needs more than ten bytes
> 
> > 
> 
> > > to encode it,
> 
> > 
> 
> > >
> 
> > 
> 
> >  sys.getsizeof('a')
> 
> > 
> 
> > > 26
> 
> > 
> 
> >  sys.getsizeof('ẞ')
> 
> > 
> 
> > > 40
> 
> > 
> 
> > >
> 
> > 
> 
> > > this is far away from the perfection.
> 
> > 
> 
> > 
> 
> > 
> 
> > Better comparison is to see how much space is used by one copy of it,
> 
> > 
> 
> > and how much by two copies:
> 
> > 
> 
> > 
> 
> > 
> 
> > >>> sys.getsizeof('aa')-sys.getsizeof('a')
> 
> > 
> 
> > 1
> 
> > 
> 
> > >>> sys.getsizeof('ẞẞ')-sys.getsizeof('ẞ')
> 
> > 
> 
> > 2
> 
> > 
> 
> > 
> 
> > 
> 
> > String objects have overhead. Big deal.
> 
> > 
> 
> > 
> 
> > 
> 
> > > BTW, for a modern language, is not ucs2 considered
> 
> > 
> 
> > > as obsolete since many, many years?
> 
> > 
> 
> > 
> 
> > 
> 
> > Clearly. And similarly, the 16-bit integer has been completely
> 
> > 
> 
> > obsoleted, as there is no reason anyone should ever bother to use it.
> 
> > 
> 
> > Same with the float type - everyone uses double or better these days,
> 
> > 
> 
> > right?
> 
> > 
> 
> > 
> 
> > 
> 
> > http://www.postgresql.org/docs/current/static/datatype-numeric.html
> 
> > 
> 
> > http://www.cplusplus.com/doc/tutorial/variables/
> 
> > 
> 
> > 
> 
> > 
> 
> > Nope, nobody uses small integers any more, they're clearly completely 
> > obsolete.
> 
> > 
> 
> > 
> 
> > 
> 
> 
> 
> Sure there is some overhead because a str is a class.
> 
> It still remain that a "ẞ" weights 14 bytes more than
> 
> an "a".
> 
> 
> 
> In "aẞ", the ẞ weights 6 bytes.
> 
> 
> 
> >>> sys.getsizeof('a')
> 
> 26
> 
> >>> sys.getsizeof('aẞ')
> 
> 42
> 
> 
> 
> and in "aẞẞ", the ẞ weights 2 bytes
> 
> 
> 
> sys.getsizeof('aẞẞ')
> 
> 
> 
> And what to say about this "ucs4" char/string '\U0001d11e' which
> 
> is weighting 18 bytes more than an "a".
> 
> 
> 
> >>> sys.getsizeof('\U0001d11e')
> 
> 44
> 
> 
> 
> A total absurdity. How does is come? Very simple, once you
> 
> split Unicode in subsets, not only you have to handle these
> 
> subsets, you have to create "markers" to differentiate them.
> 
> Not only, you produce "markers", you have to handle the
> 
> mess generated by these "markers". Hiding this markers
> 
> in the everhead of the class does not mean that they should
> 
> not be counted as part of the coding scheme. BTW, since
> 
> when a serious coding scheme need an extermal marker?
> 
> 
> 
> 
> 
> 
> 
> >>> sys.getsizeof('aa') - sys.getsizeof('a')
> 
> 1
> 
> 
> 
> Shortly, if my algebra is still correct:
> 
> 
> 
> (overhead + marker + 2*'a') - (overhead + marker + 'a')
> 
> = (overhead + marker + 2*'a') - overhead - marker - 'a'
> 
> = overhead - overhead + marker - marker + 2*'a' - 'a'
> 
> = 0 + 0 + 'a'
> 
> = 1
> 
> 
> 
> The "marker" has magically disappeared.
> 
> 
> 
> jmf

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-11 Thread wxjmfauth
Le jeudi 11 juillet 2013 15:32:00 UTC+2, Chris Angelico a écrit :
> On Thu, Jul 11, 2013 at 11:18 PM,   wrote:
> 
> > Just to stick with this funny character ẞ, a ucs-2 char
> 
> > in the Flexible String Representation nomenclature.
> 
> >
> 
> > It seems to me that, when one needs more than ten bytes
> 
> > to encode it,
> 
> >
> 
>  sys.getsizeof('a')
> 
> > 26
> 
>  sys.getsizeof('ẞ')
> 
> > 40
> 
> >
> 
> > this is far away from the perfection.
> 
> 
> 
> Better comparison is to see how much space is used by one copy of it,
> 
> and how much by two copies:
> 
> 
> 
> >>> sys.getsizeof('aa')-sys.getsizeof('a')
> 
> 1
> 
> >>> sys.getsizeof('ẞẞ')-sys.getsizeof('ẞ')
> 
> 2
> 
> 
> 
> String objects have overhead. Big deal.
> 
> 
> 
> > BTW, for a modern language, is not ucs2 considered
> 
> > as obsolete since many, many years?
> 
> 
> 
> Clearly. And similarly, the 16-bit integer has been completely
> 
> obsoleted, as there is no reason anyone should ever bother to use it.
> 
> Same with the float type - everyone uses double or better these days,
> 
> right?
> 
> 
> 
> http://www.postgresql.org/docs/current/static/datatype-numeric.html
> 
> http://www.cplusplus.com/doc/tutorial/variables/
> 
> 
> 
> Nope, nobody uses small integers any more, they're clearly completely 
> obsolete.
> 
> 
> 

Sure there is some overhead because a str is a class.
It still remain that a "ẞ" weights 14 bytes more than
an "a".

In "aẞ", the ẞ weights 6 bytes.

>>> sys.getsizeof('a')
26
>>> sys.getsizeof('aẞ')
42

and in "aẞẞ", the ẞ weights 2 bytes

sys.getsizeof('aẞẞ')

And what to say about this "ucs4" char/string '\U0001d11e' which
is weighting 18 bytes more than an "a".

>>> sys.getsizeof('\U0001d11e')
44

A total absurdity. How does is come? Very simple, once you
split Unicode in subsets, not only you have to handle these
subsets, you have to create "markers" to differentiate them.
Not only, you produce "markers", you have to handle the
mess generated by these "markers". Hiding this markers
in the everhead of the class does not mean that they should
not be counted as part of the coding scheme. BTW, since
when a serious coding scheme need an extermal marker?



>>> sys.getsizeof('aa') - sys.getsizeof('a')
1

Shortly, if my algebra is still correct:

(overhead + marker + 2*'a') - (overhead + marker + 'a')
= (overhead + marker + 2*'a') - overhead - marker - 'a')
= overhead - overhead + marker - marker + 2*'a' - 'a'
= 0 + 0 + 'a'
= 1

The "marker" has magically disappeared.

jmf


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


Re: xslice idea | a generator slice

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 17:38, "Oscar Benjamin"  wrote:
>
> On 11 July 2013 17:21, Russel Walker  wrote:
> > To confess, this is the second time I've made the mistake of trying to
implement generator like functionality of a builtin when there already is
on in itertools. Need to start studying that module abit more I think. I'm
looking at the docs now and I see there are actually a couple of
isomethings().
>
> Your xslice (or mine) would still be better than islice when the step
> size is large; islice has to iterate over all the skipped elements
> which could be wasteful if the input is indexable. Also islice doesn't
> support negative values for start, stop or step which xslice does.

Isn't all of itertools implemented in C? If we are not using a python-level
and not-so-fast __getitem__ I would wager the C version is a lot faster.

And if the input is indexable could I assume that it is not too large to
have around in memory and thus any speed increase in looping over it would
be tiny?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 1:58 PM, Fábio Santos  wrote:
> Isn't all of itertools implemented in C? If we are not using a python-level
> and not-so-fast __getitem__ I would wager the C version is a lot faster.
>
> And if the input is indexable could I assume that it is not too large to
> have around in memory and thus any speed increase in looping over it would
> be tiny?

Oscar's version which is an imap of an xrange is also effectively
implemented in C.  Only the setup is in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documenting builtin methods

2013-07-11 Thread Joshua Landau
On 11 July 2013 07:06, Steven D'Aprano  wrote:
>
> But really, I'm having trouble understanding what sort of application
> would have "run an iterator to exhaustion without doing anything with the
> values" as the performance bottleneck :-)

Definitely not this one. Heck, there's even no real reason something
as appropriately-named as "exhaust_iter" needs documentation.

Largely I was asking because I'd felt I'd missed something more
obvious; it seems there was not. I'm also doing some more functools
stuff than usual -- this method also applies to functions generated
with, say, functools.partial I had guessed. Only it does not, as you
show below -- and functools.partial objects allow you to ineffectively
set .__doc__ anyway.

I also feel that:

def factory():
eatit = deque(maxlen=0).extend
def exhaust_iter(it):
"""Doc string goes here"""
eatit(it)
return exhaust_iter

exhaust_it = factory()
del factory

is a very unobvious way to change a docstring and hides what I'm doing
very effectively. Chris Angelico's method is a fair bit better in this
regard, but I'm not sure it's worth it in this case. One
recommendation with Chris's method is to make it keyword-only (with
"*") which should keep the interface a touch cleaner.

>> exhaust_iter.__doc__ = "Exhaust an iterator efficiently [...]"
>>
>> Obviously it does not work.
>
> Even if it did work, it would not do what you hope. Because __doc__ is a
> dunder attribute (double leading and trailing underscores), help()
> currently looks it up on the class, not the instance:

I'd not considered that, and it seems to have doomed me from the start.
-- 
http://mail.python.org/mailman/listinfo/python-list


Casting classes WAS: Documenting builtin methods

2013-07-11 Thread Mark Janssen
A user was wondering why they can't change a docstring in a module's class.

This made me think: why not have a casting operator ("reciprocal"?) to
transform a bonafide class into a mere carcass of a class which can
then modified and reanimated back into its own type with the type
function?  Such that "type(reciprocal(myClass))==myClass"...

reciprocal(myClass) returns a writeable, nonproxy class.__dict__
(perhaps also a list of its bases and name)

Just a thought to consider...

MarkJ
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Scripting Language for Embedded Work?

2013-07-11 Thread David T . Ashley
On Tue, 09 Jul 2013 21:44:48 -0400, Dave Angel 
wrote:

>On 07/09/2013 09:29 PM, David T. Ashley wrote:
>> We develop embedded software for 32-bit micros using Windows as the
>> development platform.
>>
>> We are seeking a general purpose scripting language to automate
>> certain tasks, like cleaning out certain directories of certain types
>> of files in preparation for ZIP'ing, generating certain source files
>> automatically, etc.
>>
>> Selection criteria:
>>
>> a)Should be able to compile the script interpreter as a monolithic
>> executable (no .DLL dependencies, etc.) for easy versioning and
>> distribution of the script interpreter.
>
>Oh, I thought you were going to run this on Windows.  You're just 
>developing it on Windows, and you want to cross-compile to target some 
>other platform?  Which?

Sorry, I wasn't very complete.

The scripts would run on Windows 7 only, but because they may generate
part of the source code for the embedded system, we have to be careful
about versioning the interpreter, and a monolithic executable makes
that simpler.

>>  (Note that I'm not asking
>> that the script be a single executable, just the interpreter.  To run
>> a script you'd need both the script and the interpreter.  The script
>> would be a text file, and the interpreter would be a single .EXE.)
>
>If you're also constraining your "program" to a single text file, you 
>don't want Python.  It uses modules, imported from your script to do 
>much of the work.
>
>>
>> b)Should be extensible, in that one could add commands or library
>> functions to the script interpreter in C (for efficiency), and the
>> whole script interpreter could again consist of a single executable
>> with no other dependencies.  (Note that I'm not asking that the script
>> be a single executable, just the interpreter.  To run a script you'd
>> need both the script and the interpreter.  The script would be a text
>> file, and the interpreter would be a single .EXE.)
>
>And that's supposed to HELP efficiency??

Did I ever claim I wanted efficiency?

>> c)Should be able to spawn compilers and capture the output, do file
>> I/O, and all the other minor expected stuff.
>>
>> d)Graphical capability would be nice.
>>
>> I know that Tcl/Tk would do all of the above,

I was able to do this with Tcl/Tk years ago.

>I doubt it.
>
>> but what about Python?
>> Any other alternatives?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Scripting Language for Embedded Work?

2013-07-11 Thread David T . Ashley
On Wed, 10 Jul 2013 14:38:51 -0500, Johann Hibschman
 wrote:

>David T. Ashley  writes:
>
>> We develop embedded software for 32-bit micros using Windows as the
>> development platform.
>...
>> I know that Tcl/Tk would do all of the above, but what about Python?
>> Any other alternatives?
>
>Given that list, I'd say just use Tcl and be done.  You could force the
>square peg of python into that round hole, but I doubt it'd be worth the
>effort.

I tend to agree with you.  I'm not sure how go monolithic with Python.

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


Re: Casting classes WAS: Documenting builtin methods

2013-07-11 Thread Christian Heimes
Am 12.07.2013 02:23, schrieb Mark Janssen:
> A user was wondering why they can't change a docstring in a module's class.

For CPython builtin types (classes) and function have read-only doc
strings for multiple reasons. Internally the doc strings are stored as
constant C string literals. The __doc__ attribute is implemented as
descriptor that turns the const char *tp_doc member into a Python
string. const char* are ... constant. :)

All types and builtins are shared across all subinterpreters of Python.
The types and their doc strings are identical. Most people are not aware
of the subinterpreter feature. Subinterpreters run in different threads
of the same process but are isolated from each other. Mutable type and
builtin doc strings would break the isolation. You could share
information between subinterpreters by e.g. setting the doc string of
the int type. We don't want that.

Heap types (classes defined with Python code) are not shared. The same
goes to modules, even the sys module.

Christian

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


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Christian Heimes
Am 11.07.2013 19:19, schrieb Metallicow:
> @ Chris “Kwpolska” Warrick
> Thanks, that is a start anyway. 
> a Pure-Python way was what I was wanting, not win32api stuff.
> 
> "C:\Windows\Fonts"
> The windows path proves valid. Works on XP, Vista, 7. Not sure about win8?

That's the wrong way to do it. You have to use the proper Windows API to
get to the font directory. It's SHGetKnownFolderPath() with
FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.

See http://bugs.python.org/issue1763

Christian

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


Re: Callable or not callable, that is the question!

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 15:05:59 +0200, Ulrich Eckhardt wrote:

> Hello!
> 
> I just stumbled over a case where Python (2.7 and 3.3 on MS Windows)
> fail to detect that an object is a function, using the callable()
> builtin function. Investigating, I found out that the object was indeed
> not callable, but in a way that was very unexpected to me:
[...]
>  X.test2[0]() # TypeError: 'staticmethod' object is not callable
> 
> 
> Bug or feature?

In my opinion, a bug. I thought I had actually submitted it to the bug 
tracker, but apparently I was a shameful slacker and did not. However 
there was a discussion in this thread:

http://mail.python.org/pipermail/python-dev/2011-March/109090.html


Here's a simpler demonstration of the issue:

assert callable(staticmethod(lambda: None))


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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 09:45:33 -0400, Roy Smith wrote:

> In article <2fdf282e-fd28-4ba3-8c83-ce120...@googlegroups.com>,
>  jus...@zeusedit.com wrote:
> 
>> On Wednesday, July 10, 2013 2:17:12 PM UTC+10, Xue Fuqiao wrote:
>> 
>> > * It is especially handy for selecting and deleting text.
>> 
>> When coding I never use a mouse to select text regions or to delete
>> text.
>> 
>> These operations I do using just the keyboard.
> 
> For good typists, there is high overhead to getting your hands oriented
> on the keyboard (that's why the F and J keys have little bumps).  So,
> any time you move your hand from the keyboard to the mouse, you pay a
> price.
> 
> The worst thing is to constantly be alternating between mouse actions
> and keyboard actions.  You spend all your time getting your fingers
> hands re-oriented.  That's slow.

Big deal. I am utterly unconvinced that raw typing speed is even close to 
a bottleneck when programming. Data entry and transcribing from (say) 
dictated text, yes. Coding, not unless you are a one-fingered hunt-and-
peek typist. The bottleneck is not typing speed but thinking speed: 
thinking about program design and APIs, thinking about data structures 
and algorithms, debugging, etc.

Programming is normally done in spurts of typing followed by longer 
periods of thinking, testing, debugging. Micro-optimizing for the 
fraction of a second it takes to re-orient your hand on the keyboard is 
silly -- even if it is an optimization, not a pessimization (and I remain 
unconvinced) -- it's utterly trivial. Who cares that you saved 0.1 of a 
second by not moving your hand off the keyboard when you then sit there 
for 20 minutes staring into space thinking about your program design?

Keyboard commands for yanking an entire line beat the mouse, but for 
moving the cursor around to arbitrary positions, or copying arbitrary 
pieces of text, a mouse is much faster. But either way, who cares? Typing 
speed is only rarely the bottleneck, let alone micro-optimizations like 
these.

The difference between a 60 wpm typist and a 90 wpm typist is normally 
that the 90 wpm typist can introduce bugs 50% faster :-) I'm joking, of 
course, but typing *accuracy* is far more important than typing speed.


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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Chris Angelico
On Fri, Jul 12, 2013 at 12:39 PM, Steven D'Aprano
 wrote:
> Big deal. I am utterly unconvinced that raw typing speed is even close to
> a bottleneck when programming. Data entry and transcribing from (say)
> dictated text, yes. Coding, not unless you are a one-fingered hunt-and-
> peek typist. The bottleneck is not typing speed but thinking speed:
> thinking about program design and APIs, thinking about data structures
> and algorithms, debugging, etc.
>
> Programming is normally done in spurts of typing followed by longer
> periods of thinking, testing, debugging.

That's true, but it's still important to be able to type quickly. You
spend a minute or two figuring what you need to be doing, then want to
see the result as quickly as possible. The plan is in your brain; you
need to transfer it into code, save it, compile it if you need to,
deploy it to your test-box if you need to, trigger its execution, and
see its output. That's a roughly linear process, so any time saved in
any step is an overall saving, and the shorter the total time from
brain to output, the more smoothly your debugging/tinkering will be.
That's why I've spent time developing systems at work that reduce the
times required. With a single keystroke (F7 in SciTE), I can save,
compile (for the one or two components that actually get compiled),
and deploy to test-box, and a quick SIGHUP via Upstart does the rest.
I can try two or three iterations of something without "losing" what
my brain's holding onto - more if it's a trivial edit. Poor typing
speed, or replacing the F7 whack with a button click that demands a
mouse, would damage that.

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 11:42:26 -0700, wxjmfauth wrote:

> And what to say about this "ucs4" char/string '\U0001d11e' which is
> weighting 18 bytes more than an "a".
> 
 sys.getsizeof('\U0001d11e')
> 44
> 
> A total absurdity. 


You should stick to Python 3.1 and 3.2 then:

py> print(sys.version)
3.1.3 (r313:86834, Nov 28 2010, 11:28:10)
[GCC 4.4.5]
py> sys.getsizeof('\U0001d11e')
36
py> sys.getsizeof('a')
36


Now all your strings will be just as heavy, every single variable name 
and attribute name will use four times as much memory. Happy now?


> How does is come? Very simple, once you split Unicode
> in subsets, not only you have to handle these subsets, you have to
> create "markers" to differentiate them. Not only, you produce "markers",
> you have to handle the mess generated by these "markers". Hiding this
> markers in the everhead of the class does not mean that they should not
> be counted as part of the coding scheme. BTW, since when a serious
> coding scheme need an extermal marker?

Since always.

How do you think that (say) a C compiler can tell the difference between 
the long 1199876496 and the float 67923.125? They both have exactly the 
same four bytes:

py> import struct
py> struct.pack('f', 67923.125)
b'\x90\xa9\x84G'
py> struct.pack('l', 1199876496)
b'\x90\xa9\x84G'


*Everything* in a computer is bytes. The only way to tell them apart is 
by external markers.



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


Re: Documenting builtin methods

2013-07-11 Thread alex23

On 12/07/2013 9:11 AM, Joshua Landau wrote:

I also feel that:

def factory():
 eatit = deque(maxlen=0).extend
 def exhaust_iter(it):
 """Doc string goes here"""
 eatit(it)
 return exhaust_iter

exhaust_it = factory()
del factory

is a very unobvious way to change a docstring and hides what I'm doing
very effectively.


My last post seems to have been eaten by either Thunderbird or the 
EternalSeptember servers, but it contained an erroneous claim that the 
straight function version performed as well as the factory one. However, 
in the interim a co-worker has come up with a slightly faster variant:


from functools import partial
from collections import deque

class exhaust_it(partial):
"""custom doc string"""

exhaust_it = exhaust_it(deque(maxlen=0).extend)

Shadowing the class name with the partial instance will ensure it has 
the same name when accessed via help(), and it's a simple way to avoid 
needing to clean up the namespace, as well.

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


python2.6 epoll.modify failed to unregister events ?

2013-07-11 Thread Ziliang Chen
Hi Guys,
I have encountered an epoll issues. On the server side, I use epoll.poll() to 
wait  for events, when there is a socket which has EPOLLIN/EPOLLUP events, I 
first try to read the socket (I did this coz it says EPOLLIN ready, I might 
think it has some data in its recv queue). After reading 0 length data, the 
code thinks the peer shutdown its socket, so it notifies the epoll that it 
doesn't care any events for this socket anymore by calling epoll.modify(sock, 
0). But this call seems failed to function, coz when I did another round of 
epoll.poll(), the socket is still ready for EPOLLUP. My understanding for epoll 
Linux interface is that it should work if we pass no events when calling 
epoll_ctl.


Steps to reproduce this problem. Open up two consoles, one for client, one for 
server. Input the following code in the two consoles by the following order.
---

Server 
---
>>> import socket
>>> accept_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> accept_socket.setblocking(False)
>>> accept_socket.bind(('10.5.6.10', ))
>>> accept_socket.listen(socket.SOMAXCONN)
>>> import select
>>> ep = select.epoll()
>>> ep.register(accept_socket.fileno(), select.EPOLLIN)

client
---
>>> import socket
>>> st = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> st.connect(('10.5.6.10', ))


Server

>>> ep.poll()
[(4, 1)]
>>> sock, peer_addr = accept_socket.accept()
>>> ep.register(sock, select.EPOLLIN)

Client
---
>>> st.send('ahello')
6


Server
---
>>> ep.poll()
[(6, 1)]
>>> sock.recv(1024)
'ahello'
>>> sock.shutdown(socket.SHUT_WR)


Client
---
>>> st.recv(1024)
''
>>> st.shutdown(socket.SHUT_WR)



Server

>>> ep.poll()
[(6, 17)]
>>> sock.recv(1024)
''
>>> ep.modify(sock, 0) <= I am saying, i don't care any events for the sock
>>> ep.poll()   <= but epoll still return the event for this sock
[(6, 16)]
>>> ep.poll()
[(6, 16)]
>>> ep.modify(sock, 0)
>>> ep.poll()
[(6, 16)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Scripting Language for Embedded Work?

2013-07-11 Thread Stefan Behnel
David T. Ashley, 12.07.2013 03:19:
> On Wed, 10 Jul 2013 14:38:51 -0500, Johann Hibschman wrote:
> 
>> David T. Ashley writes:
>>
>>> We develop embedded software for 32-bit micros using Windows as the
>>> development platform.
>> ...
>>> I know that Tcl/Tk would do all of the above, but what about Python?
>>> Any other alternatives?
>>
>> Given that list, I'd say just use Tcl and be done.  You could force the
>> square peg of python into that round hole, but I doubt it'd be worth the
>> effort.
> 
> I tend to agree with you.  I'm not sure how go monolithic with Python.

PyRun? py2exe? Just to name two.

Stefan


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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Steven D'Aprano
On Fri, 12 Jul 2013 01:50:17 +1000, Chris Angelico wrote:

> On Fri, Jul 12, 2013 at 1:42 AM, Paul Rudin 
> wrote:
>> Text selection with a mouse is a different thing. Sometimes it's more
>> convenient, sometimes it's not.
> 
> As screens get larger and the amount of text on them increases, it's
> likely to get more and more useful to use a mouse... but personally, I
> still find the switch-to-mouse operation so clunky on anything except a
> Thinkpad that I'll use the keyboard even if it's a bit slower. (Why are
> Thinkpads different? Because the mouse, which is excellent, is right
> under my fingers, between G/H/B. 

You mean those horrible nipple things? 

E. E. Damn things get the tactile feedback *completely* wrong. 
They're even worse than those awful little mousepads that you stroke.

Frankly, nothing comes even close to a real mouse for feedback and ease 
of use. Maybe a stylus. But that's it.


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


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
On Thursday, July 11, 2013 8:27:04 PM UTC-5, Christian Heimes wrote:
> Am 11.07.2013 19:19, schrieb Metallicow:
> 
> > @ Chris �Kwpolska� Warrick
> 
> > Thanks, that is a start anyway. 
> 
> > a Pure-Python way was what I was wanting, not win32api stuff.
> 
> > 
> 
> > "C:\Windows\Fonts"
> 
> > The windows path proves valid. Works on XP, Vista, 7. Not sure about 
> > win8?
> 
> 
> 
> That's the wrong way to do it. You have to use the proper Windows API to
> 
> get to the font directory. It's SHGetKnownFolderPath() with
> 
> FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.
> 
> 
> 
> See http://bugs.python.org/issue1763
> 
> 
> 
> Christian

typo'd instead of copy/pasted. What I meant was... Chris's code...

>>> FONTDIRS = os.path.join(os.environ['WINDIR'], 'Fonts') 
'C:\\WINDOWS\\Fonts'

returned valid as returned string. Forgot to add >>> part.
Is there any way to edit posts? Don't see an edit linky anywhere.
Is there something wrong with using os.environ...?
win32api stuff is another dependency. Is it really needed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Chris Angelico
On Fri, Jul 12, 2013 at 2:24 PM, Steven D'Aprano
 wrote:
> On Fri, 12 Jul 2013 01:50:17 +1000, Chris Angelico wrote:
>
>> On Fri, Jul 12, 2013 at 1:42 AM, Paul Rudin 
>> wrote:
>>> Text selection with a mouse is a different thing. Sometimes it's more
>>> convenient, sometimes it's not.
>>
>> As screens get larger and the amount of text on them increases, it's
>> likely to get more and more useful to use a mouse... but personally, I
>> still find the switch-to-mouse operation so clunky on anything except a
>> Thinkpad that I'll use the keyboard even if it's a bit slower. (Why are
>> Thinkpads different? Because the mouse, which is excellent, is right
>> under my fingers, between G/H/B.
>
> You mean those horrible nipple things?
>
> E. E. Damn things get the tactile feedback *completely* wrong.
> They're even worse than those awful little mousepads that you stroke.
>
> Frankly, nothing comes even close to a real mouse for feedback and ease
> of use. Maybe a stylus. But that's it.

I would guess that you used a Dell one. They're far FAR worse. We have
Dell laptops at work and I use external mice with them all. The IBM
trackpoint is far better. I can game with a trackpoint, but when I
built a Windows 7 desktop box for Alice, I had to go buy a high
precision mouse just to be able to game properly.

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


Re: Concurrent writes to the same file

2013-07-11 Thread Jason Friedman
>
> https://bitbucket.org/cameron_simpson/css/src/374f650025f156554a986fb3fd472003d2a2519a/lib/python/cs/fileutils.py?at=default#cl-408
>
> That looks like it will do the trick for me, thank you Cameron.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris Angelico
On Fri, Jul 12, 2013 at 2:24 PM, Metallicow  wrote:
> On Thursday, July 11, 2013 8:27:04 PM UTC-5, Christian Heimes wrote:
>> Am 11.07.2013 19:19, schrieb Metallicow:
>>
>> > @ Chris �Kwpolska� Warrick
>>
>> > Thanks, that is a start anyway.
>>
>> > a Pure-Python way was what I was wanting, not win32api stuff.
>>
>> >
>>
>> > "C:\Windows\Fonts"
>>
>> > The windows path proves valid. Works on XP, Vista, 7. Not sure about 
>> > win8?
>>
>>
>>
>> That's the wrong way to do it. You have to use the proper Windows API to
>>
>> get to the font directory. It's SHGetKnownFolderPath() with
>>
>> FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.
>>
>>
>>
>> See http://bugs.python.org/issue1763
>>
>>
>>
>> Christian
>
> typo'd instead of copy/pasted. What I meant was... Chris's code...
>
 FONTDIRS = os.path.join(os.environ['WINDIR'], 'Fonts')
> 'C:\\WINDOWS\\Fonts'
>
> returned valid as returned string. Forgot to add >>> part.
> Is there any way to edit posts? Don't see an edit linky anywhere.
> Is there something wrong with using os.environ...?
> win32api stuff is another dependency. Is it really needed?

No, you fundamentally cannot edit posts. This is a Usenet newsgroup
and a mailing list; once your post is sent, it gets carried by lots of
different servers separately. Just send a followup, same as you did
there.

Since you seem to be using Google Groups, please read this to learn
how to avoid antagonizing a significant proportion of the list's best
responders:

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

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


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 21:24:00 -0700, Metallicow wrote:

> Forgot to add >>> part. Is there any way to edit posts? 

Not unless thousands of people give you access to their computer so you 
can edit the emails in their inboxes.

When you send a post to a public mailing list, its out their on fifty 
thousand computers and a dozen public archives. No, you can't change your 
mind and edit what you've already said.


> Don't see an edit linky anywhere. Is there something
> wrong with using os.environ...? win32api stuff is another dependency. Is
> it really needed?

If you want to do it the right way, yes.

In principle, any Windows machine could set the font directory to any 
valid directory. The only way to be sure you have got the right one is to 
ask Windows for the font directory, and that requires win32api.

If you intend for this to be usable everywhere, my approach would be this:

1) You need a separate function for each platform you intend to support. 
At the very least, you should support Windows (2000, XP, Vista, 7 and 8), 
OS-X (Mac), Linux. You should also strongly consider supporting Android, 
FreeBSD, OpenBSD, and Solaris. If you intend running under older versions 
of Python, you should also consider supporting Windows CE. You might even 
like to support iOS.

2) Some of these (Windows, probably Mac and iOS) will require a call to 
the OS to find the current directory. That means a win32api or equivalent 
call.

3) If win32api is not available, you might like to fall back on a 
heuristic to guess the right directory. But remember that is only a 
little bit better than hard-coding a directory.

4) For Linux and Free- and OpenBSD, there is no standard font directory. 
You may be able to make a call to the GUI toolkit to ask what it thinks 
the font directory (or directories!) is, but there are many different 
toolkits, and they can all be active at the same time. E.g. I might run a 
Gnome app and a KDE app both under XFCE, plus OpenOffice, and all three 
might disagree as to what fonts I have available.

The standard way to locate fonts in Linux is to look at two files, 
/etc/fonts/fonts.conf and /etc/fonts/local.conf, which list the locations 
you should check. Either, or both, files may be missing. Standard 
locations include: 

/usr/share/fonts
/usr/local/share/fonts
/home//.fonts
/usr/X11R6/lib/X11/fonts
/usr/share/X11/fonts/Type1
/usr/share/X11/fonts/OTF

And of course, applications like OpenOffice might keep their own, 
private, font directory, just because.

5) Now that you have a function for each OS you support, you can create a 
master function that detects the OS and calls the appropriate one. Now at 
last you have a simple function get_font_directory() that works 
everywhere.

Now that you see how complex it is to write this "simple" function, are 
you surprised that one doesn't yet exist?


:-)



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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-11 Thread Eric S. Johansson
On Fri, 12 Jul 2013 00:24:26 -0400, Steven D'Aprano  
 wrote:



Frankly, nothing comes even close to a real mouse for feedback and ease
of use. Maybe a stylus. But that's it.


before tremors, I would agree with you. Stylus is amazingly good tool for  
user interaction in a GUI. After tremors, not so much. For example, when  
you sweep across the pad, you keep your mouse tip up, over and use  
feedback from your mouse pointer to tell you when to touch down. My  
tremors caused mouse clicks on tablet at about a 2 Hz rate. You can just  
imagine it, hearing me move the stylus across the pad going: Tap tap tap  
tap tap tap tap. Yeah, sucks to be me. A high-resolution mouse is  
similarly problematic because I can make a gross motion to another part of  
the screen. hitting a small target on a high-resolution screen is not easy  
in the least and usually takes longer than the gross positioning across  
the screen. What I would love is a mouse interface that uses a mouse  
motion for a small range but a force vector like Mr. eraser head for  
longer-range movement. Not exactly sure how the mouse would behave but  
that's a very rough idea what would work well with my hands.

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


Re: Best Scripting Language for Embedded Work?

2013-07-11 Thread Christian Gollwitzer

Hi David,

Am 12.07.13 03:18, schrieb David T. Ashley:

On Wed, 10 Jul 2013 09:03:54 +0200, Christian Gollwitzer
 wrote:

>

Robert's answer made me hesitate - what exactly is your platform? Are
you writing the scripts for the embedded platform, or for Windows, or
does the embedded controller run Windows RT or something like this?


Writing the scripts to run on Windows 7, but the scripts assist in
building the software for an embedded system.  Because the embedded
system may be safety-related, it makes sense to be careful about how
the script interpreter is versioned, and a single monolithic
executable makes this easier.


I see. In your situation, I'd also keep the sources to the interpreter 
in your backup. Who knows if you might need them to get it running on 
some future Windows system.




Python has similar capabilities, look for pyinstaller or py2exe.


Sorry, I miscommunicated.  I don't need to embed the script in the
.EXE.  I just want the interpreter to be a single .EXE, so it is
easier to ensure that every software developer has the same version of
the interpreter or that we are using the correct earlier version if an
older product needs to rebuilt in the future.


I understand. But nothing prevents you to wrap a simple script loader 
main script; something like


execfile(argv[1])

would do it in Python. pyinstaller has a single-file wrapping mode, 
where you get the analogue of a starpack in Tcl.


But I still think Tcl/Tk is a much better fit. For one thing, 
pyinstaller makes huge executables. I did this on Linux to wrap a 
program with matplotlib and Tkinter; I ended up with ~100MB in size. 
That's because pyinstaller pulled in a lot of system libraries, among 
them QT, wxWidgets etc. Without them, the program did not run despite it 
used only Tkinter. In contrast, a starpack wish with just Tcl&Tk is 
around 2MB in size.


Second, Tcl/Tk is much nicer to use interactively. Consider an 
interactive environment, which woud not include the "ls" command. In 
Tcl, you can define


proc ls {args} {
if {[length $args] == 0} { set args * }
puts [join [glob -nocomplain {*}$args] \n]
}

and then, the following commands all work as expected

ls
ls *.jpg
ls *.txt *.jpg

The analogue in Python would look like this

import glob
def ls(*args):
for pat in args if len(args)>0 else ('*'):
print '\n'.join(glob.glob(pat))

but using it is ugly and inconvenient compared to the shellish way in Tcl:

ls()
ls('*.txt')
ls('*.jpg', '*.txt')

Of course this is a contrived example, because all interactive 
environments already provide ls. But I usually extend my Tcl with 
similar commands and then just use tkcon to enter them on-the-fly.


I also think that for your use case, you will not need to write C 
extensions. A standard starpack gives you many things out of the box, 
like looking into ZIP files. Even creating them is just two pages of 
code. I would suggest that you put together a couple of packages, put 
them in a lib/ folder, have your main.tcl something like


lappend auto_path [file join [file dirname [info script]] lib]
package require tkcon
tkcon show

and bake that together using sdx into a starpack. Then you have a single 
interpreter, with an interactive console, and you can extend this by Tcl 
modules and still have a single executable.


For example, you can get some inspiration from kbs.tcl, which contains a 
rather complete make system. It usually builds tclkits, but you can rip 
the build system off and write your own dependencies with it. Make a 
package out of it, and then your scripts would just package require 
make, to get things done which are best describe by a dependency graph.



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