Re: Turkic I and re

2011-09-16 Thread Thomas Rachel

Am 15.09.2011 15:16 schrieb Alan Plum:


The Turkish 'I' is a peculiarity that will probably haunt us programmers
until hell freezes over.


That's why it would have been nice if the Unicode guys had defined "both 
Turkish i-s" at separate codepoints.


Then one could have the three pairs
I, i ("normal")
I (other one), ı

and

İ, i (the other one).

But alas, they haven't.


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


Re: Comparisons of computation timing

2011-09-16 Thread Steven D'Aprano
Akand Islam wrote:

> I have run my codes (written in Python) in my Notebook (3 GB Ram, Dual-
> core CPU T4500 @ 2.3 GHz) and in my lab machine (11.57 GB Ram, i7-920
> CPU @ 2.67 GHz). However, I have found execution time in Notebook
> 250.3 seconds, and in Lab machine 333.2 seconds. How is it possible?
> Good configuration machine performs slower??? I reran the codes, same
> finding whatsoever. I run Windows 7 in my laptop, and Ubuntu 11.04 in
> lab machine. Both are 64 bit. When I ran my simulation in Notebook, I
> also did some other stuffs; however for the case of lab machine I did
> nothing other than running simulation only.

In a modern, multi-processing operating system like Windows, Mac OS or
Linux, you can *never* run only the simulation. There are always other
processes running. Even if you have no other applications running, the
system itself could have dozens or hundreds of processes running in the
background. On one of my Linux systems, a desktop running about four
applications, I have over two hundred processes:

[steve@orac ~]$ ps aux | wc -l
218

Without knowing more about the two systems, and the code you ran, it is
impossible to say why one is faster than the other. Your question is like
this:

"I drove from home to work with an old Toyota, and it took twenty minutes.
Then the next day, I borrowed my cousin's brand new Ferrari, and the same
journey took thirty minutes. How is this possible?"

On the Ubuntu machine, what does "ulimit -a" report? How does that compare
to the Window machine? Where there any cron jobs running at the time? Did
your Ubuntu system decide that this was a good time to download a whole lot
of system updates? Can you use the "nice" command to run at a higher
priority? Is your code limited by CPU, memory or disk I/O? Which desktop
environment is your Ubuntu system running, Gnome, Unity, KDE, Ratpoison, or
something else?

There could be dozens of factors that make a difference to speed.


> About the codes: Basically it simply solves some non-linear equations
> using "fsolve" along with some other calculations.

What is "fsolve"?



> I will appreciate if some one discusses about possible reasons? For
> fair comparisons, in both machines I ran exactly the same codes. My
> codes are not parallelized, is this the main reason i7 processes show
> slower performance?

Don't believe hardware manufacturer's advertising. These days, chip speed is
not so important. Cache misses are MUCH more critical: a slow chip with a
big cache will out-perform a fast chip with a small cache nearly always.



-- 
Steven

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


Re: Turkic I and re

2011-09-16 Thread Steven D'Aprano
Thomas Rachel wrote:

> Am 15.09.2011 15:16 schrieb Alan Plum:
> 
>> The Turkish 'I' is a peculiarity that will probably haunt us programmers
>> until hell freezes over.


Meh, I don't think it's much more peculiar that any other diacritic issue.
If I'm German or English, I probably want ö and O to match during
case-insensitive comparisons, so that Zöe and ZOE match. If I'm Icelandic,
I don't. I don't really see why Turkic gets singled out.


> That's why it would have been nice if the Unicode guys had defined "both
> Turkish i-s" at separate codepoints.
> 
> Then one could have the three pairs
> I, i ("normal")
> I (other one), ı
> 
> and
> 
> İ, i (the other one).

And then people will say, "How can I match both sorts of dotless uppercase I
but not dotted I when I'm doing comparisons?"



-- 
Steven

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


Re: Comparisons of computation timing

2011-09-16 Thread Nizamov Shawkat
> About the codes: Basically it simply solves some non-linear equations
> using "fsolve" along with some other calculations.
>

Looks like you are using some third party libraries like numpy/scipy.
Do these libraries have the same version on both platforms?
What about python interpreter versions - are they the same?

Best regards,
Shavkat Nizamov
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Turkic I and re

2011-09-16 Thread John-John Tedro
On Fri, Sep 16, 2011 at 7:25 AM, Steven D'Aprano <
[email protected]> wrote:

> Thomas Rachel wrote:
>
> > Am 15.09.2011 15:16 schrieb Alan Plum:
> >
> >> The Turkish 'I' is a peculiarity that will probably haunt us programmers
> >> until hell freezes over.
>
>
> Meh, I don't think it's much more peculiar that any other diacritic issue.
> If I'm German or English, I probably want ö and O to match during
> case-insensitive comparisons, so that Zöe and ZOE match. If I'm Icelandic,
> I don't. I don't really see why Turkic gets singled out.
>
>
> > That's why it would have been nice if the Unicode guys had defined "both
> > Turkish i-s" at separate codepoints.
> >
> > Then one could have the three pairs
> > I, i ("normal")
> > I (other one), ı
> >
> > and
> >
> > İ, i (the other one).
>
> And then people will say, "How can I match both sorts of dotless uppercase
> I
> but not dotted I when I'm doing comparisons?"
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Yeah, it's more probable that language conventions and functions grow around
characters that look right.

No one except developers care what specific codepoint they have, so soon you
would have a mish-mash of special rules converting between each special
case.

P.S. Sorry Steven, i missed clicking "reply to all".

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


parse html:what is the meaning of "//"?

2011-09-16 Thread alias
code1:
import lxml.html
import urllib
down='http://finance.yahoo.com/q/op?s=C+Options'
content=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(content)
table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
tds=table.xpath("tr[@valign='top']//td")
for  td  in tds:
print  td.text_content()

what i get is :
Call Options
Expire at close Friday, September 16, 2011
these are waht i want.

code2
import lxml.html
 import urllib
 down='http://finance.yahoo.com/q/op?s=C+Options'
 content=urllib.urlopen(down).read()
 root=lxml.html.document_fromstring(content)
 table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
 tds=table.xpath("//tr[@valign='top']//td")
 for  td  in tds:
 print  td.text_content()

what i get is :
N/A
N/A
2
114
48.00
C110917P00048000
16.75
 0.00
N/A
N/A
0
23
50.00
C110917P0005
23.16
 0.00
N/A
N/A
115
2,411
   
   
   
Highlighted options are in-the-money.
(omit  something)
there is only one difference between   code1 and code2  :
in code1 is :   tds=table.xpath("tr[@valign='top']//td")
in code2 is:   tds=table.xpath("//tr[@valign='top']//td")

i want to know  why  the  "//"  make output  different?-- 
http://mail.python.org/mailman/listinfo/python-list


why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread keobox
Hello,
I'm writing a little supervisor of some python scripts.
To check if the scrips are running I'm using the ps -o pid,fname
command on both RH Linux and solaris 10.
All the scripts are launched using "python script.py" command, they
are not launched with exec permissions.

I don't know why the fname of the python interpreter changes across
platforms.

I saw a "isapytho" in some solaris 10 platforms.
I saw "python2." in some Linux platforms.
On most platforms the value is "python".
Why?

Ok, I know that I can easily work around the problem by not using
"fname" and parse the ps output in another way, but I don't understand
how is possible that the combination of ps and python behaves so
badly.
Any idea?

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


Re: parse html:what is the meaning of "//"?

2011-09-16 Thread Kev Dwyer
alias wrote:


>
>
>
> Highlighted options are in-the-money.
> (omit  something)
> there is only one difference between   code1 and code2  :
> in code1 is :   tds=table.xpath("tr[@valign='top']//td")
> in code2 is:   tds=table.xpath("//tr[@valign='top']//td")
> 
> i want to know  why  the  "//"  make output  different?


This is an XPATH question, not really Python-related.

See http://www.w3schools.com/xpath/xpath_syntax.asp

Cheers,

Kev

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


Re: parse html:what is the meaning of "//"?

2011-09-16 Thread Stefan Behnel

alias, 16.09.2011 08:39:

code1:
import lxml.html
import urllib
down='http://finance.yahoo.com/q/op?s=C+Options'
content=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(content)


I see this quite often, but many people don't know that this can be 
simplified to


import lxml.html
url = 'http://finance.yahoo.com/q/op?s=C+Options'
root = lxml.html.parse(url).getroot()

which is less code, but substantially more efficient.



table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
tds=table.xpath("tr[@valign='top']//td")
for  td  in tds:
 print  td.text_content()

what i get is :
Call Options
Expire at close Friday, September 16, 2011
these are waht i want.

code2
import lxml.html
  import urllib
  down='http://finance.yahoo.com/q/op?s=C+Options'
  content=urllib.urlopen(down).read()
  root=lxml.html.document_fromstring(content)
  table = root.xpath("//table[@class='yfnc_mod_table_title1']")[0]
  tds=table.xpath("//tr[@valign='top']//td")


Here, you are looking for all "tr" tags in the table recursively, instead 
of taking just the ones that are direct children of the "table" tag.


That's what "//" is there for, it's a recursive subtree selector. You might 
want to read up on XPath expressions.




what i get is :
N/A
N/A
2
114
48.00
C110917P00048000
16.75
  0.00
N/A
N/A
0
23
50.00
C110917P0005
23.16
  0.00
N/A
N/A
115
2,411


Highlighted options are in-the-money.


I don't see any highlighting in your text above, and I don't know what you 
mean by "in-the-money".


Stefan

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


Re: why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread Steven D'Aprano
keobox wrote:

> Hello,
> I'm writing a little supervisor of some python scripts.
> To check if the scrips are running I'm using the ps -o pid,fname
> command on both RH Linux and solaris 10.
> All the scripts are launched using "python script.py" command, they
> are not launched with exec permissions.
> 
> I don't know why the fname of the python interpreter changes across
> platforms.

Ask the person who built the system, or the people who made the
distribution. They are free to name the Python executable anything they
like.



-- 
Steven

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


Fwd: why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread Yaşar Arabacı
-- Yönlendirilmiş ileti --
Kimden: Yaşar Arabacı 
Tarih: 16 Eylül 2011 14:33
Konu: Re: why ps/fname of a python interpreter changes across platforms?
Kime: Steven D'Aprano 


For example, in arch linux, I had 3 different interpreters named python,
python26 and python27 because some of the applications needed one, and some
needed others. That might be the reason.


2011/9/16 Steven D'Aprano 

> keobox wrote:
>
> > Hello,
> > I'm writing a little supervisor of some python scripts.
> > To check if the scrips are running I'm using the ps -o pid,fname
> > command on both RH Linux and solaris 10.
> > All the scripts are launched using "python script.py" command, they
> > are not launched with exec permissions.
> >
> > I don't know why the fname of the python interpreter changes across
> > platforms.
>
> Ask the person who built the system, or the people who made the
> distribution. They are free to name the Python executable anything they
> like.
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://yasar.serveblog.net/




-- 
http://yasar.serveblog.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse html:what is the meaning of "//"?

2011-09-16 Thread Miki Tebeka
As a side note, it's way easier to get this data using YQL. See for example:

http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=SELECT%20*%20FROM%20yahoo.finance.options%20WHERE%20symbol%3D%27C%27%20AND%20expiration%3D%272011-09%27

Which gives you the data in JSON format.

(See link at bottom for API URL)
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange Python internal error

2011-09-16 Thread JKPeck
We have a user on Windows with Python 2.6 who gets this error message when 
executing an import statement.
from extension import Template, Syntax, processcmd 
SystemError: ..\Objects\listobject.c:169: bad argument to internal function

The module can be imported directly via
import extension
with no problem.  And large numbers of other users execute this same code with 
no problem.

Does anybody have a clue as to how this might arise?

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

From recruiting-simplifies+bnccipclbizhxcvmm3zbboeoqb...@googlegroups.com Fri 
Sep 16 06:17:14 2011
Return-path: 

Envelope-to: [email protected]
Delivery-date: Fri, 16 Sep 2011 06:17:14 -0700
Received: from exprod5mx247.postini.com ([64.18.0.167] helo=psmtp.com)
by mail-archive.com with esmtp (Exim 4.69)
(envelope-from 
)
id 1R4YI6-0005d2-4V
for [email protected]; Fri, 16 Sep 2011 06:17:14 -0700
Received: from mail-pz0-f56.google.com ([209.85.210.56]) (using TLSv1) by 
exprod5mx247.postini.com ([64.18.4.10]) with SMTP;
Fri, 16 Sep 2011 06:17:11 PDT
Received: by pzk34 with SMTP id 34sf574262pzk.1
for ; Fri, 16 Sep 2011 06:17:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlegroups.com; s=beta;
h=x-beenthere:received-spf:from:to:subject:date:message-id
 :mime-version:x-mailer:thread-index:x-cr-hashedpuzzle:x-cr-puzzleid
 :x-original-sender:x-original-authentication-results:precedence
 :mailing-list:list-id:x-google-group-id:list-post:list-help
 :list-archive:sender:list-unsubscribe:content-type:content-language;
bh=WcpZY9CO+G6LAH58OuCK1KKVtzk+QE5vOdtuFO/hCVs=;
b=uAxG1f4Ox9cc/HCZ8XhGxWqGUe8bJx8WnHgsBgDTHVnSY7pKue09fyG5dH0fq6CUTt
 kNCmZBzLPbhGE49WVOTmUV7MsOl5vApYJNpgZQ3k9Qk2s8I4q17PMmZgyo6+HUNYvKV2
 +cgoHlGGmPgyiW3pib14aaHSn4vkgFCySXWWE=
Received: by 10.68.36.225 with SMTP id t1mr412493pbj.2.1316178991245;
Fri, 16 Sep 2011 06:16:31 -0700 (PDT)
X-BeenThere: [email protected]
Received: by 10.68.158.84 with SMTP id ws20ls1421899pbb.4.gmail; Fri, 16 Sep
 2011 06:16:30 -0700 (PDT)
Received: by 10.68.58.168 with SMTP id s8mr1028899pbq.15.1316178990185;
Fri, 16 Sep 2011 06:16:30 -0700 (PDT)
Received: by 10.68.58.168 with SMTP id s8mr1028884pbq.15.1316178990055;
Fri, 16 Sep 2011 06:16:30 -0700 (PDT)
Received: from mail-pz0-f43.google.com (mail-pz0-f43.google.com [209.85.210.43])
by gmr-mx.google.com with ESMTPS id 
j4si14655506pbi.2.2011.09.16.06.16.29
(version=TLSv1/SSLv3 cipher=OTHER);
Fri, 16 Sep 2011 06:16:30 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.210.43 is neither permitted nor 
denied by best guess record for domain of [email protected]) 
client-ip=209.85.210.43;
Received: by mail-pz0-f43.google.com with SMTP id 13so1805922pzd.2
for ; Fri, 16 Sep 2011 06:16:29 -0700 (PDT)
Received: by 10.68.0.36 with SMTP id 4mr2098046pbb.382.1316178989168;
Fri, 16 Sep 2011 06:16:29 -0700 (PDT)
Received: from DellPC ([113.193.45.201])
by mx.google.com with ESMTPS id e8sm33010136pbc.8.2011.09.16.06.16.12
(version=SSLv3 cipher=OTHER);
Fri, 16 Sep 2011 06:16:27 -0700 (PDT)
From: "Mike Vaz" 
To: 
Subject: Recruiting-Simplifies Very Urgent Requirement For A QA  Tester With
 Healthcare Experience
Date: Fri, 16 Sep 2011 08:16:09 -0500
Message-ID: <00fc01cc7472$d6dc0920$84941b60$@com>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 12.0
Thread-Index: AcxzKftZ7CRMRgJsTjyI5WWpCpCzEgABHlhQACN3r2AALZqaIA==
x-cr-hashedpuzzle: J/c= 3I8= Akfw CBhK DSF+ DW1b ERG3 Ebfb GWMT GwsQ G+E6 HBLJ 
Hc/o HhGE JPiV 
K1YD;1;bQBpAGsAZQBAAGsAdABlAGsAcgBlAHMAbwB1AHIAYwBpAG4AZwAuAGMAbwBtAA==;Sosha1_v1;7;{E9D7BFD9-C5DF-4FF8-AFBB-A097F8E324D8};bQBpAGsAZQBAAGsAdABlAGsAcgBlAHMAbwB1AHIAYwBpAG4AZwAuAGMAbwBtAA==;Fri,
 16 Sep 2011 13:16:07 
GMT;VgBlAHIAeQAgAFUAcgBnAGUAbgB0ACAAUgBlAHEAdQBpAHIAZQBtAGUAbgB0ACAARgBvAHIAIABBACAAUQBBACAAIABUAGUAcwB0AGUAcgAgAFcAaQB0AGgAIABIAGUAYQBsAHQAaABjAGEAcgBlACAARQB4AHAAZQByAGkAZQBuAGMAZQA=
x-cr-puzzleid: {E9D7BFD9-C5DF-4FF8-AFBB-A097F8E324D8}
X-Original-Sender: [email protected]
X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com:
 209.85.210.43 is neither permitted nor denied by best guess record for domain
 of [email protected]) [email protected]
Precedence: list
Mailing-list: list [email protected]; contact 
[email protected]
List-ID: 
X-Google-Group-Id: 541384909353
List-Post: ,
 
List-Help: , 

List-Archive: 
Sender: [email protected]
Li

Re: Turkic I and re

2011-09-16 Thread Oktay Safak
Well, I'm a self taught Turkish python coder. I was bitten by this first 
in Python 2.3 and asked the group about it then. You can find the 
correspondence by googling "unicode bug in turkish characters? 
" 
There are a couple of posts with that topic line but they don't come out 
in one thread. So check them all.


Anyway, to summarize, Martin v.Löwis answered my question back then and 
suggested some locale settings but the problem seems to be with Windows 
actually. His method worked on Linux, but not on windows. He said that 
Python delegates uppercasing of strings to the operating system on 
Windows, and Windows is broken there. What he said was:


"Python delegates the toupper call to the operating system. It does not,
in itself, include a database of lower/upper case conversions for all 
locales.


So there is nothing we can do about that; ask Microsoft."

So I ended up not asking Microsoft of course, but using [iİ] in re and writing 
a couple of utility functions upper_tr(), lower_tr() and title_tr() etc to use 
in my own projects. But of course when foreign language names etc. are mixed in 
a text it blows but I can't see a way to avoid it when that's the case.

I hope this helps,


Oktay Safak



Thomas Rachel wrote:

Am 15.09.2011 15:16 schrieb Alan Plum:


The Turkish 'I' is a peculiarity that will probably haunt us programmers
until hell freezes over.


That's why it would have been nice if the Unicode guys had defined 
"both Turkish i-s" at separate codepoints.


Then one could have the three pairs
I, i ("normal")
I (other one), ı

and

İ, i (the other one).

But alas, they haven't.


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


Re: parse html:what is the meaning of "//"?

2011-09-16 Thread 守株待兔
through  the  following code,i get the content of webpage,
 import lxml.html
 url = 'http://finance.yahoo.com/q/op?s=C+Options'
 root = lxml.html.parse(url).getroot() 

with your method ,how can i get the content of webpage  in my python program?

-- Original --
From:  "Miki Tebeka";
Date:  Fri, Sep 16, 2011 09:08 PM
To:  "python-list"; 
Cc:  "python-list"; 
Subject:  Re: parse  html:what is the meaning of "//"?

 
As a side note, it's way easier to get this data using YQL. See for example:

http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=SELECT%20*%20FROM%20yahoo.finance.options%20WHERE%20symbol%3D%27C%27%20AND%20expiration%3D%272011-09%27

Which gives you the data in JSON format.

(See link at bottom for API URL)
-- 
http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Different class 'str' between v3.

2011-09-16 Thread Vincent Vande Vyvre


  
  
Testing the following code, I've differend return with python 3.1.2
and 3.2.2

---
# -*- coding: utf-8 -*-
import os
  import sys
  import platform
print('\nPython version: ', sys.version.split()[0])
  print(platform.platform())
paths = ['/home/vincent/image.jpg', '/home/vincent/àéèîö.jpg']
for path in paths:
  print('\nPath: {0}, Type: {1}'.format(path, type(path)))
  if not os.path.exists(path) or not os.path.isfile(path):
  print('File not found: {0}'.format(path))
  else:
  print('File exists')
--

My pc ubuntu:

  
  vincent@tiemoko:~/Python/oqapy/devel$ python3
  string_2.py
Python version: 3.1.2
  Linux-2.6.32-33-generic-i686-with-Ubuntu-10.04-lucid
Path: /home/vincent/image.jpg, Type: 
  File exists
Path: /home/vincent/
àéèîö.jpg, Type: 
  File exists
  vincent@tiemoko:~/Python/oqapy/devel$
  -
Second pc:


[vincent@myhost ~]$ python string_2.py

Python version:  3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5

Path: /home/vincent/image.jpg, Type: 
File exists
Traceback (most recent call last):
  File "string_2.py", line 13, in 
    print('\nPath: {0}, Type: {1}'.format(path, type(path)))
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 21-25: ordinal not in range(128)
[vincent@myhost ~]$
--

I never had problem with unicode and python3.

Thanks for all advices.
-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: Cancel or timeout a long running regular expression

2011-09-16 Thread Nobody
On Thu, 15 Sep 2011 14:54:57 -0400, Terry Reedy wrote:

>> I was thinking there might be a technique I could use to evaluate
>> regular expressions in a thread or another process launched via
>> multiprocessing module and then kill the thread/process after a
>> specified timeout period.
> 
> Only solution I remember ever seen posted. I wonder if there are any 
> heuristics for detecting exponential time re's.

Exponential growth results from non-determinism, i.e. if there are
multiple transitions for a given character from a given state.

Common patterns include:

...(a...)?a...
...(a...)*a...
...(a...)+a...

with a choice between matching the "a" at the start of the bracketed
pattern or the "a" following it.

(xxxa...|xxxb...|xxxc...)

with a choice between branches which cannot be resolved until more data
has been read.

For re.search (as opposed to re.match):

axxxa...

When axxx has been read, a following "a" gives a choice between
continuing the existing match with the second "a", or aborting and
matching against the first "a". For patterns which contain many copies of
the initial character, each copy creates another branch.

Also, using back-references in a regexp [sic] can be a significant
performance killer, as it rules out the use of a DFA (which, IIRC, Python
doesn't do anyhow) and can require brute-forcing many combinations. A
particularly bad case is:

(a*)\1

matching against "...".

If the performance issue is with re.match/re.search rather than with
re.compile, one option is to use ctypes to access libc's regexp functions.
Those are likely to provide better searching throughput at the expense of
potentially increased compilation time.

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


Re: create a directory structure

2011-09-16 Thread Andrea Crotti
After some research, I think that paste-script is the best choice in 
this case.


I can define templates and I'll get my directory structure nicely 
populated for me.

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


Re: why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread Duncan Booth
keobox  wrote:

> I don't know why the fname of the python interpreter changes across
> platforms.
> 
> I saw a "isapytho" in some solaris 10 platforms.
> I saw "python2." in some Linux platforms.
> On most platforms the value is "python".
> Why?
> 
It shows you part of the name of the program that is running.

On a typical Linux system you could run python using the default 
interpreter 'python', or you could be explicit about the version you want 
to run and use 'python2.4', 'python2.5', 'python2.6', 'python2.7', 
'python3.2' (all of these are available on the system in from of me). Of 
course 4 of those will be truncated to 'python2.' if you only look at the 
first 8 characters (which is what your command does) but you also get 
'python' and 'python3.'

That's why there's a lot of variation. I have no idea why it has a strange 
name on Solaris, maybe someone compiled their own private version.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


pyzmail-0.9.9 mail library to read, compose and send emails easily, support for py3k

2011-09-16 Thread aspineux
Now pyzmail include support for python 3.2 and above

pyzmail is a high level mail library for Python. It provides functions
and classes that help to read, compose and send emails. pyzmail exists
because their is no reasons that handling mails with Python would be
more difficult than with popular mail clients like Outlook or
Thunderbird. pyzmail hide the difficulties of the MIME structure and
MIME encoding/decoding. It also hide the problem of the
internationalized header encoding/decoding.

The library contains lot of sample and is very well documented.

http://www.magiksys.net/pyzmail/

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


Re: Strange Python internal error

2011-09-16 Thread Miki Tebeka
Try to narrow it down:
from extension import Template
from extension import Syntax
from extension import processcmd 

Which one fails? What is this "extension" package?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing matplotlib-users discussion group?

2011-09-16 Thread Martin Schöön
On 2011-09-15, John Ladasky  wrote:
> Hate to bump this, but... I found Sourceforge's IRC, and tried to ask
> for help there, and it doesn't look like I can get any help until
> business hours tomorrow.  Anyone?

No help really but I 'joined' Sourceforge about a year ago and
had no problems whatsoever.

Could it be some anti-robot filter that's gotten overly picky?

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


RE: ImportError: cannot import name dns

2011-09-16 Thread Prasad, Ramit
NOTE: This is all speculation on my part. I am hoping someone on the list will 
give us more concrete details.

1. check for "dns" in sys.modules (initially not found)
2. create new empty module, add it to sys.modules as "dns"
3. execute dns.py in new module namespace (executes "from foo import udp") 
It has not yet added anything defined in dns because it is still on import 
statement

4. check for "udp" in sys.modules (not found)
5. create new empty module, add it to sys.modules as "udp"
6. execute udp.py in new module namespace (executes "from foo import dns") 
Cannot do this because dns is still not defined even though it the name is in 
sys.modules and since we are still in the middle of the first statement 
defining dns, it raises an error.


7. check for "dns" in sys.modules (found!)
8. done executing udp.py
9. done executing dns.py

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



-Original Message-
From: Jack Bates [mailto:[email protected]] 
Sent: Wednesday, September 14, 2011 11:22 AM
To: Prasad, Ramit
Cc: [email protected]
Subject: Re: ImportError: cannot import name dns

> It is a circular dependency. Dns will try to import udp which will in turn 
> import dns (again) in an endless cycle; instead an ImportError is raised.
>
> Circular dependency is a Bad Thing.

According to this documentation:

http://docs.python.org/reference/simple_stmts.html#grammar-token-import_stmt

http://effbot.org/zone/import-confusion.htm

 - I thought Python would do something like:

So I'd expect attempting to access symbols from "dns" while executing
udp.py to fail, because dns.py isn't done executing at this point.
However I don't attempt to access any symbols from "dns" - so I don't
expect this ImportError

What is my mistake?
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


strange results

2011-09-16 Thread Fig
I am having a problem with a graphics program that I created.
Actually, I don't know if it is the program or a bug in Python. The
code for the program is as follows;

from gasp import *

begin_graphics(width=640, height=480, title='Houses at Night',
background=color.BLACK)

def draw_house(x, y):
a = (x, y  + 100)
b = (x +50, y +140)
c = (x +100, y + 100)
Box((x, y), 100, 100, filled=True, color=color.BLUE)# the
house
Box((x + 35, y), 30, 50, filled=True, color=color.GREEN)#
the door
Circle((x + 62, y + 16), 1, filled=True, color=color.GOLD)
# the door knob
Box((x + 20, y + 60), 20, 20, filled=True,
color=color.YELLOW)# the left window
Line((x + 20, y + 71), (x + 40, y + 71),
color=color.ORANGE)# horizontal line (left window)
Line((x + 29, y + 60), (x + 29, y + 80),
color=color.ORANGE)# vertical line (left window)
Box((x + 60, y + 60), 20, 20, filled=True,
color=color.YELLOW)# the right window
Line((x + 60, y + 71), (x + 80, y + 71),
color=color.ORANGE)# horizontal line (right window)
Line((x + 69, y + 60), (x + 69, y + 80),
color=color.ORANGE)# vertical line (right window)
Polygon([a, b, c], filled=True, color=color.RED)# the roof

draw_house(20, 20)
draw_house(270, 20)
draw_house(520, 20)
draw_house(145, 180)
draw_house(395, 180)
draw_house(270, 340)

update_when('key_pressed')
end_graphics()
ends here, but it


When I run the program, I do not get any error messages but there are
parts of the 'draw_house' function missing on the canvas. Each call to
'draw_house has different things missing, they are not all the exact
same. There are some parts that show in one call to 'draw_house' that
do not show in others and visa versa. Does anyone have any idea what
may be going on?
-- 
http://mail.python.org/mailman/listinfo/python-list


unexpected results

2011-09-16 Thread Fig
I am having a problem when I run a graphics program that I created. I
do not get an error when I run the program, there are just some weird
things going on. I do not know if it is the program causing the
problem or a bug in Python. Here is the code for the program:


from gasp import *

begin_graphics(width=640, height=480, title='Houses at Night',
background=color.BLACK)

def draw_house(x, y):# function for drawing a house
a = (x, y  + 100)# 'a' coordinate for Polygon
b = (x +50, y +140)# 'b' coordinate for Polygon
c = (x +100, y + 100)# 'c' coordinate for Polygon
Box((x, y), 100, 100, filled=True, color=color.BLUE)# the
house
Box((x + 35, y), 30, 50, filled=True, color=color.GREEN)#
the door
Circle((x + 62, y + 16), 1, filled=True, color=color.GOLD)
# the door knob
Box((x + 20, y + 60), 20, 20, filled=True,
color=color.YELLOW)# the left window
Line((x + 20, y + 71), (x + 40, y + 71),
color=color.ORANGE)# horizontal line (left window)
Line((x + 29, y + 60), (x + 29, y + 80),
color=color.ORANGE)# vertical line (left window)
Box((x + 60, y + 60), 20, 20, filled=True,
color=color.YELLOW)# the right window
Line((x + 60, y + 71), (x + 80, y + 71),
color=color.ORANGE)# horizontal line (right window)
Line((x + 69, y + 60), (x + 69, y + 80),
color=color.ORANGE)# vertical line (right window)
Polygon([a, b, c], filled=True, color=color.RED)# the roof

draw_house(20, 20)
draw_house(270, 20)
draw_house(520, 20)
draw_house(145, 180)
draw_house(395, 180)
draw_house(270, 340)

update_when('key_pressed')
end_graphics()



The program launches just fine, bringing up the gasp window like it
should. The problem is that almost all of the calls to 'draw_house'
are different. Some features will show up in one house but not in
another and visa versa. Does anyone have any idea what the problem may
be?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected results

2011-09-16 Thread Fig
Sorry, Everyone. I got an error when posting the first post and did'nt
come in to see if it had actually posted before I tried another post.


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


Using tuples to eliminate multiple dict values

2011-09-16 Thread Benshep
I need a dictionary that returns the same value for multiple keys.

i.e.

(1)   >>> dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }
(2)   >>>dict[1]
(3)   'text'

I cant figure out what i need on line 2 to make this scenario work. Is
there a simple way to check if the a number is present in the key and
then return the value?

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


Re: Using tuples to eliminate multiple dict values

2011-09-16 Thread MRAB

On 16/09/2011 19:47, Benshep wrote:

I need a dictionary that returns the same value for multiple keys.

i.e.

(1)>>>  dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }


That will create a dict with 2 keys, both of which are tuples.


(2)>>>dict[1]
(3)   'text'

I cant figure out what i need on line 2 to make this scenario work. Is
there a simple way to check if the a number is present in the key and
then return the value?


If you want multiple keys, then you must provide them separately:

my_dict = {1: 'text', 2: 'text', 3: 'text', 5: 'other text', 6 : 'other 
text', 7: 'other text'}


or use 'for' to iterate through the keys for each value:

my_dict = dict([(k, 'text') for k in (1, 2, 3)] + [(k, 'other text') for 
k in (5, 6, 7)])


or something similar.
--
http://mail.python.org/mailman/listinfo/python-list


way to calculate 2**1000 without expanding it?

2011-09-16 Thread zombie
Hi guys,
 i am writing a program to sum up the digits of a number 2**1000?
Is there a way/formula to do it without expanding it?

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


Re: Using tuples to eliminate multiple dict values

2011-09-16 Thread Benshep
thanks,

I had a feeling that may be the way to go and my data just changed so
it will work better that way.

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


RE: Using tuples to eliminate multiple dict values

2011-09-16 Thread Prasad, Ramit
-Original Message-
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
Benshep
Sent: Friday, September 16, 2011 1:48 PM
To: [email protected]
Subject: Using tuples to eliminate multiple dict values

I need a dictionary that returns the same value for multiple keys.

i.e.

(1)   >>> dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }
(2)   >>>dict[1]
(3)   'text'

I cant figure out what i need on line 2 to make this scenario work. Is
there a simple way to check if the a number is present in the key and
then return the value?

Thanks


I think I must be missing something. Can you not do the following?

>>> d = { 1:'text', 2:'text', 3:'text', 5:'other text', 6:'other text', 
>>> 7:'other text' }
>>> d[1]
'text'



If you are they need to share the same value you can also do something like 
this.

>>> t1 = [ 'text' ]
>>> t2 = [ 'other text' ]
>>> d = { 1:t1, 2:t1, 3:t1, 5:t2, 6:t2, 7:t2 }
>>> d[1]
['text']
>>> d[1][0]='new text'
>>> d[2][0]
'new text'
>>> d
{1: ['new text'], 2: ['new text'], 3: ['new text'], 5: ['other text'], 6: 
['other text'], 7: ['other text']}


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Ian Kelly
On Fri, Sep 16, 2011 at 1:21 PM, zombie  wrote:
> Hi guys,
>         i am writing a program to sum up the digits of a number 2**1000?
> Is there a way/formula to do it without expanding it?

Possibly, but why worry about it?  It's only around 300 digits.

Since this sounds like homework, I won't post the one-liner I used to
do it the brute-force way, but I will note that it takes about 200
microseconds to run on my laptop.

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


RE: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Prasad, Ramit
>> Hi guys,
>> i am writing a program to sum up the digits of a number 2**1000?
>> Is there a way/formula to do it without expanding it?

>Since this sounds like homework, I won't post the one-liner I used to
>do it the brute-force way, but I will note that it takes about 200
>microseconds to run on my laptop.

If you happen to be new to Python, I will say I used these functions to create 
a one liner (in alphabetical order).

Int
Lambda
Map
Reduce
Str


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
On 16 September 2011 21:06, Ian Kelly  wrote:
> On Fri, Sep 16, 2011 at 1:21 PM, zombie  
> wrote:
>> Hi guys,
>>         i am writing a program to sum up the digits of a number 2**1000?
>> Is there a way/formula to do it without expanding it?
>
> Possibly, but why worry about it?  It's only around 300 digits.
>
> Since this sounds like homework, I won't post the one-liner I used to
> do it the brute-force way, but I will note that it takes about 200
> microseconds to run on my laptop.

Ah go on, let's make a codegolf contest out of it.
My entry:

>>> sum(map(int,str(2**1000)))
1366

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


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Ian Kelly
On Fri, Sep 16, 2011 at 2:17 PM, Arnaud Delobelle  wrote:
> Ah go on, let's make a codegolf contest out of it.
> My entry:
>
 sum(map(int,str(2**1000)))
> 1366

That is exactly what mine was.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Gary Herron

On 09/16/2011 01:17 PM, Arnaud Delobelle wrote:

On 16 September 2011 21:06, Ian Kelly  wrote:

On Fri, Sep 16, 2011 at 1:21 PM, zombie  wrote:

Hi guys,
 i am writing a program to sum up the digits of a number 2**1000?
Is there a way/formula to do it without expanding it?

Possibly, but why worry about it?  It's only around 300 digits.

Since this sounds like homework, I won't post the one-liner I used to
do it the brute-force way, but I will note that it takes about 200
microseconds to run on my laptop.

Ah go on, let's make a codegolf contest out of it.
My entry:


sum(map(int,str(2**1000)))

1366



Here's another one-liner using a generator instead of map:

sum(int(c) for c in str(2**1000))

Gary Herron



--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Why do closures do this?

2011-09-16 Thread John Nagle

On 8/27/2011 9:19 PM, Terry Reedy wrote:

On 8/27/2011 11:45 PM, John O'Hagan wrote:

Somewhat apropos of the recent "function principle" thread, I was
recently surprised by this:

funcs=[]
for n in range(3):
def f():
return n
funcs.append(f)



The last expression, IMO surprisingly, is [2,2,2], not [0,1,2].


   That's correct behavior, because a closure captures the binding of
a nonlocal variable, not its value.  There is only one "n" for all
iterations.

   If you create a local variable within the closed function:

   def f()
   localn = n
   return(localn)

there's a copy of "localn" for each iteration, and you're returning
it.

Try this in PyPy, which tries not to box numbers, and see what happens
there.  This is one of those Python features which complicates
optimization.  For performance, an implementation should handle numbers
as machine numbers, not objects.  (Creating an object to hold a
machine primitive like an int, float, or bool is called "boxing' the
number.)  CPython always carries around a full
CObject for ordinary numbers, which is why CPython numeric performance
is so bad.  PyPy tries not to do that, although there are rare
cases when it has to, like this one.

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


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
On 16 September 2011 21:20, Ian Kelly  wrote:
> On Fri, Sep 16, 2011 at 2:17 PM, Arnaud Delobelle  wrote:
>> Ah go on, let's make a codegolf contest out of it.
>> My entry:
>>
> sum(map(int,str(2**1000)))
>> 1366
>
> That is exactly what mine was.
>

Slightly longer:

>>> eval("+".join(str(2**1000)))
1366

This looks like a winner but I cheated (the result depends on the
state of the interpreter):

>>> eval("+".join(`2**1000`))
1366

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


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Stefan Krah
Gary Herron  wrote:
 i am writing a program to sum up the digits of a number 2**1000?
 Is there a way/formula to do it without expanding it?
>
> Here's another one-liner using a generator instead of map:
>
> sum(int(c) for c in str(2**1000))

The OP did not specify the base:

>>> bin(2**1000).count('1')
1


Or just:

>>> print(1)
1


Stefan Krah


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


RE: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Prasad, Ramit
>>> sum(map(int,str(2**1000)))
*smacks face* Gah, forgot about sum.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


create a directory structure

2011-09-16 Thread Andrea Crotti
I would like to write a program which creates a directory structure and 
fills in a few templated fields some values passed in as arguments.


So for example
create_struct.py

might create
base_dir:
|_ sub_dir1:
   |_ sub_file1
...

It's quite simple in theory, but I would also like to make it very 
easily maintanable, for example with a nice representation of the 
structure (an INI file maybe).


Any ideas/advise on how to make it easy to write and to maintain?
--
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Arnaud Delobelle
On 16 September 2011 20:21, zombie  wrote:
> Hi guys,
>         i am writing a program to sum up the digits of a number 2**1000?
> Is there a way/formula to do it without expanding it?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

In base 2, the answer is 1 :)

Hopefully-helpfully-but-not-so-sure'ly yours,

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


Re: Cancel or timeout a long running regular expression

2011-09-16 Thread Terry Reedy

On 9/16/2011 9:57 AM, Nobody wrote:

I wonder if there are any
heuristics for detecting exponential time re's.


Exponential growth results from non-determinism, i.e. if there are
multiple transitions for a given character from a given state.

Common patterns include:

...(a...)?a...
...(a...)*a...
...(a...)+a...

with a choice between matching the "a" at the start of the bracketed
pattern or the "a" following it.

(xxxa...|xxxb...|xxxc...)

with a choice between branches which cannot be resolved until more data
has been read.

For re.search (as opposed to re.match):

axxxa...

When axxx has been read, a following "a" gives a choice between
continuing the existing match with the second "a", or aborting and
matching against the first "a". For patterns which contain many copies of
the initial character, each copy creates another branch.

Also, using back-references in a regexp [sic] can be a significant
performance killer, as it rules out the use of a DFA (which, IIRC, Python
doesn't do anyhow) and can require brute-forcing many combinations. A
particularly bad case is:

(a*)\1

matching against "...".

If the performance issue is with re.match/re.search rather than with
re.compile, one option is to use ctypes to access libc's regexp functions.
Those are likely to provide better searching throughput at the expense of
potentially increased compilation time.


Now, can you write that as a heuristic *algorithm* def 
dangerous_re(some_re):?


--
Terry Jan Reedy

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


Re: parse html:what is the meaning of "//"?

2011-09-16 Thread Terry Reedy

On 9/16/2011 7:02 AM, Stefan Behnel wrote:


0.00
N/A
N/A
115
2,411


Highlighted options are in-the-money.


I don't see any highlighting in your text above,


Gone with the ascii conversion.


and I don't know what you mean by "in-the-money".


If a stock sells now for $20, an option to buy it for $19 is 
in-the-money and has definite value while an option to buy it for $21 is 
not, but is out-of-the-money and only has value according to one's 
subjective estimate of the likelihood of a rise above $21 before the 
option expires.


--
Terry Jan Reedy

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


Code Review

2011-09-16 Thread Emeka
Hello All,

While learning Python I put together another Text Twist. I would want
somebody to go through it and comment.
https://github.com/janus/Text-Twist

-- 

Regards,
Emeka
*


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


Re: Different class 'str' between v3.

2011-09-16 Thread Terry Reedy

On 9/16/2011 9:52 AM, Vincent Vande Vyvre wrote:

Testing the following code, I've differend return with python 3.1.2 and
3.2.2


running on two different machines with two different versions of Linux.

I get


# -*- coding: utf-8 -*-

import os
import sys
import platform

print('\nPython version: ', sys.version.split()[0])
print(platform.platform())

paths = ['/home/vincent/image.jpg', '/home/vincent/àéèîö.jpg']

for path in paths:
print('\nPath: {0}, Type: {1}'.format(path, type(path)))
if not os.path.exists(path) or not os.path.isfile(path):
print('File not found: {0}'.format(path))
else:
print('File exists')


I get

Python version:  3.2.2rc1
Windows-7-6.1.7601-SP1

Path: /home/vincent/image.jpg, Type: 
File not found: /home/vincent/image.jpg

Path: /home/vincent/àéèîö.jpg, Type: 
File not found: /home/vincent/àéèîö.jpg

so


[vincent@myhost ~]$ python string_2.py

Python version: 3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5

Path: /home/vincent/image.jpg, Type: 
File exists
Traceback (most recent call last):
File "string_2.py", line 13, in 
print('\nPath: {0}, Type: {1}'.format(path, type(path)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position
21-25: ordinal not in range(128)


is not specific to 3.2.2 in general. Try the two Python versions on the 
same machine. Or try the test suite on each. See the test module doc for 
how.


--
Terry Jan Reedy


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


Re: strange results

2011-09-16 Thread Fig
I took out all of the color commands that were in the shape functions
and all of the features to the 'draw_house' function showed showed up.
I started putting the color commands back into the shape functions and
have no problems with some of them but when I put the color command
back into others, some of the features start to disappear. As far as I
can see, all of the code is right but I'm just a beginner so I am not
for sure. Can anyone tell me why this is doing what it is.

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


Re: Using tuples to eliminate multiple dict values

2011-09-16 Thread Chris Angelico
On Sat, Sep 17, 2011 at 4:47 AM, Benshep  wrote:
> (1)   >>> dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }
>

As I understand it, you're looking for a simple syntax for what MRAB posted:
> my_dict = {1: 'text', 2: 'text', 3: 'text', 5: 'other text', 6 : 'other 
> text', 7: 'other text'}

Since your first line of code is syntactically legal, you could do a
simple check afterwards to translate it:

my_dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }
for k in list(my_dict.keys()):
if isinstance(k,tuple):
val=my_dict.pop(k)
for i in k: my_dict[i]=val

Tested in Python 3.2; in Python 2, the list() call is superfluous,
everything else should work fine.

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


Re: Different class 'str' between v3.

2011-09-16 Thread Ian Kelly
On Fri, Sep 16, 2011 at 7:52 AM, Vincent Vande Vyvre
 wrote:
> [vincent@myhost ~]$ python string_2.py
>
> Python version:  3.2.2
> Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5
>
> Path: /home/vincent/image.jpg, Type: 
> File exists
> Traceback (most recent call last):
>   File "string_2.py", line 13, in 
>     print('\nPath: {0}, Type: {1}'.format(path, type(path)))
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 21-25:
> ordinal not in range(128)

This looks like a terminal encoding issue on the second PC.  Your
terminal is probably not using a unicode encoding, and so it is unable
to print a unicode string.

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


Re: Using tuples to eliminate multiple dict values

2011-09-16 Thread Tim Chase

On 09/16/11 13:47, Benshep wrote:

I need a dictionary that returns the same value for multiple keys.

i.e.

(1)>>>  dict = { (1,2,3) : 'text' , (5,6,7) : 'other text' }
(2)>>>dict[1]
(3)   'text'

I cant figure out what i need on line 2 to make this scenario work. Is
there a simple way to check if the a number is present in the key and
then return the value?


You could use something like

 d = dict(
   (k,v)
   for keys in (
 ((1,2,3), 'text'),
 ((5,6,7), 'other text'),
 )
   for k in keys
   )

which seems to do what you want with minimal redundancy of 
declarations.


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


setuptools: getting data files to be installed

2011-09-16 Thread Paul Paterson
I'm having a problem using setuptools to create a distribution for a project 
that includes data files. I can get the data files to be included in the zipped 
package file (*.tar.gz) but when I easy_install the package the data files are 
not installed. (Ubuntu 11.04, Python2.7).

I'm trying to use easy_install because the project is a game with dependencies 
and so it would be nice for easy_install to handle all that for people.


My setup.py file is below at the end of the post. 

I create the zip with,

> python setup.py egg_info
...
> python setup.py sdist

Then the dist/tacman-0.1.tar.gz includes my data files as identified in the 
MANIFEST.in file.

But when I do,

> sudo easy_install dist/tacman-0.1.tar.gz

... the python modules appear in 
/usr/local/lib/python27/dist-packages/tacman-0.1-py2.7.egg but the data files 
are nowhere to be seen. I tried locating them using pkg_resources but that 
didn't help. Some Googling suggested /usr/share as a location but they weren't 
there either.

Am I looking in the right place or did they just not get installed?

The whole distribution file is at http://perpetualpyramid.com/tacman-0.1.tar.gz 
in case that helps. The file is bit large because it is a game and the zip 
includes the music and graphics.

Thanks for any help and pointers.

Paul

--- setup.py ---

from setuptools import setup, find_packages

import game.common

setup(name='tacman',
  version=game.common.version,
  scripts=['tacman.py'], 
  entry_points = {
'console_scripts' : [
'tacman = tacman.tacman',
]
  },
  description='A tactical, turn-based clone on PACMAN',
  author='Paul Paterson',
  author_email='[email protected]',
  url='http://www.perpetualpyramid/tacman.html',
  download_url=('http://perpetualpyramid.com/tacman-%s.tar.gz' % 
game.common.version),

  include_package_data=True,
  zip_safe=False,
  
  packages=[
'serge', 'serge.blocks', 'serge.tools', 'serge.tools.template', 'game',
  ],
  package_dir={'':'.'},

  classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU Library or Lesser General Public 
License (LGPL)",
"Operating System :: OS Independent",
"Topic :: Games/Entertainment",
"Topic :: Games/Entertainment :: Puzzle Games",
],
   install_requires=[
 'pygame', 'networkx',
   ],
   long_description='''\
TACMAN
--

A turn-based, tactical version of PACMAN.

Play a PACMAN clone where the action is turn based. You move and then the 
ghosts move. The turn-based action adds additional tactical elements to the
game and allows you to plan ahead and outwit the ghosts!

Requires: Python 2.6+, pygame 1.9+, networkx

''',
 )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Steven D'Aprano
Arnaud Delobelle wrote:

> Ah go on, let's make a codegolf contest out of it.
> My entry:
> 
 sum(map(int,str(2**1000)))
> 1366


Time for some obfuscated Python!

b = (16,13624)
for i in range(23, 42, 3):
b = (b[0]*b[0], b[1]+1024)

for j in range(12345, 8929, -7):
b = (b[0]+b[0], b[1]-3)

while b > (0,9876):
b = tuple((lambda a,b: map(lambda a,b:a+b, a,b))
((lambda a,b: map(lambda a,b:a*b, a,b))
(b,(0,1)), (lambda a,b: map(lambda a,b:a-b, a,b))
(divmod(b[0],10),(0,64

print b[1]



-- 
Steven

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


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Grant Edwards
On 2011-09-16, Gary Herron  wrote:
> On 09/16/2011 01:17 PM, Arnaud Delobelle wrote:
>> On 16 September 2011 21:06, Ian Kelly  wrote:
>>> On Fri, Sep 16, 2011 at 1:21 PM, zombie  
>>> wrote:
 Hi guys,
  i am writing a program to sum up the digits of a number 2**1000?
 Is there a way/formula to do it without expanding it?
>>> Possibly, but why worry about it?  It's only around 300 digits.
>>>
>>> Since this sounds like homework, I won't post the one-liner I used to
>>> do it the brute-force way, but I will note that it takes about 200
>>> microseconds to run on my laptop.
>> Ah go on, let's make a codegolf contest out of it.
>> My entry:
>>
> sum(map(int,str(2**1000)))
>> 1366
>>
>
> Here's another one-liner using a generator instead of map:
>
>  sum(int(c) for c in str(2**1000))

Just in case you can't spare the 3KB required for the list of integers
that map creates. :)

In this case it doesn't matter, but it's not hard to find problems
where the difference between the memory requirements for a generator
and a map/list-comprehension are significant enough to worry about.

-- 
Grant

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


Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Ian Kelly
On Fri, Sep 16, 2011 at 8:19 PM, Grant Edwards  wrote:
>> Here's another one-liner using a generator instead of map:
>>
>>      sum(int(c) for c in str(2**1000))
>
> Just in case you can't spare the 3KB required for the list of integers
> that map creates. :)
>
> In this case it doesn't matter, but it's not hard to find problems
> where the difference between the memory requirements for a generator
> and a map/list-comprehension are significant enough to worry about.

Unless otherwise specified, I generally assume that code on this list
is for Python 3, and map in Python 3 returns an iterator.

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


Re: Different class 'str' between v3.

2011-09-16 Thread Vincent Vande Vyvre


  
  
Le 17/09/11 01:28, Ian Kelly a écrit :

  On Fri, Sep 16, 2011 at 7:52 AM, Vincent Vande Vyvre
 wrote:

  
[vincent@myhost ~]$ python string_2.py

Python version:  3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5

Path: /home/vincent/image.jpg, Type: 
File exists
Traceback (most recent call last):
  File "string_2.py", line 13, in 
    print('\nPath: {0}, Type: {1}'.format(path, type(path)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 21-25:
ordinal not in range(128)

  
  
This looks like a terminal encoding issue on the second PC.  Your
terminal is probably not using a unicode encoding, and so it is unable
to print a unicode string.

Cheers,
Ian



Ok, my example is in a terminal but the problem is the same in a
graphical application wich use PyQt

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: Different class 'str' between v3.

2011-09-16 Thread Vincent Vande Vyvre


  
  
Le 17/09/11 05:28, Vincent Vande Vyvre a écrit :

  
  
  Le 17/09/11 01:28, Ian Kelly a écrit :
  
On Fri, Sep 16, 2011 at 7:52 AM, Vincent Vande Vyvre
 wrote:


  [vincent@myhost ~]$ python string_2.py

Python version:  3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5

Path: /home/vincent/image.jpg, Type: 
File exists
Traceback (most recent call last):
  File "string_2.py", line 13, in 
    print('\nPath: {0}, Type: {1}'.format(path, type(path)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 21-25:
ordinal not in range(128)


This looks like a terminal encoding issue on the second PC.  Your
terminal is probably not using a unicode encoding, and so it is unable
to print a unicode string.

Cheers,
Ian


  
  Ok, my example is in a terminal but the problem is the same in a
  graphical application wich use PyQt
  

The problem was in the config of Archlinux himself.

Solved in /etc/rc.conf

Thanks
-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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