distutils.core.setup --install-script option in Python 2.6 ?

2009-11-05 Thread j vickroy

Hello,

I have just upgraded from Python 2.5 to 2.6 and am unable to locate any 
trace of the --install-script option, in release 2.6.4 (MS Windows XP), 
for distutils.core.setup.  I also have been unable to locate any mention 
of it on-line.


My v2.5 setup.py scripts are failing with the falling error:

error: option --install-script not recognized

I apologize for missing something obvious here, but I am stuck.

Thanks in advance for your feedback.

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


parse a string (Cadence Allegro Netlist) to dictionary

2009-11-05 Thread Leland
Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
 '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
 C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_logic.cy2305(CHIPS)':
 'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_resistors.resistor(CHIPS)':
 'A': CDS_PINID='A';

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


Re: parse a string (Cadence Allegro Netlist) to dictionary

2009-11-05 Thread Emile van Sebille

On 11/5/2009 12:02 PM Leland said...

Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
 '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
 C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_logic.cy2305(CHIPS)':
 'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_resistors.resistor(CHIPS)':
 'A': CDS_PINID='A';

Thanks,
Leland


This does it, but not very elegantly...

mydict = dict( (kk[0].replace("'",""),",".join(kk[1:]))
for kk in [ [ [ jj for jj in ii.split("\n") if jj.strip() ][0]
for ii in txt.split("_NAME")[1:] ] ])

Emile

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


2to3 ParseError with UTF-8 BOM

2009-11-05 Thread Farshid
I'm using Python 2.6.2 and when I run the 2to3 script on a file that
contains a UTF-8 BOM I get the following error:

RefactoringTool: Can't parse : ParseError: bad token:
type=55, value='\xef', context=('', (1, 0))

If I remove the BOM then it works fine. Is this expected behavior or a
bug in the 2to3 script?

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


Re: elementtree XML() unicode

2009-11-05 Thread John Machin
On Nov 5, 12:35 am, Stefan Behnel  wrote:
> John Machin, 04.11.2009 02:56:
>
> > On Nov 4, 12:14 pm, Kee Nethery wrote:
> >> The reason I am confused is that getResponse2 is classified as an  
> >> "str" in the Komodo IDE. I want to make sure I don't lose the non-
> >> ASCII characters coming from the URL.
>
> > str is all about 8-bit bytes.
>
> True in Py2.x, false in Py3.

And the context was 2.x.

> What you mean is the "bytes" type, which, sadly, was named "str" in Python 
> 2.x.

What you mean is the "bytes" concept.

> The problem the OP ran into was due to the fact that Python 2.x handled
> "ASCII characters in a unicode string" <-> "ASCII encoded byte string"
> conversion behind the scenes, which lead to all sorts of trouble to loads
> of people, and was finally discarded in Python 3.0.

What you describe is the symptom. The problems are (1) 2.X ET expects
a str object but the OP supplied a unicode object, and (2) 2.X ET
didn't check that, so it accidentally "worked" provided the contents
were ASCII-only, and otherwise gave a novice-mystifying error message.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3

2009-11-05 Thread Terry Reedy

Steven D'Aprano wrote:

I've played around with 3.0, and I've read the What's New for 3.1 (and am 
installing 3.1 now), and while the changes look nice, I'm not sure that 
they're nice enough to deal with the pain of 2to3 migration.


I am in a different position since I did not have current code that 
would need migrating.


So how about that, 3.1 fans? What are the most compelling reasons for you 
that convinced you to change?


I am writing a book on algorithms that uses a subset of 3.1 as the 
algorithm language. It it simply cleaner and easier to explain to people 
not already familiar with the quirks of 2.x. One small but 
important-to-me example. I do not need to put 'from __future__ import 
integerdivision' (or whatever the incantation is) as the top of files. 
Hence I do not need to waste energy (mime and readers) explaining 
furture imports and the specifics of the old versus new meaning of int/int.


While I initially resisted the text==unicode change, I now see it as 
essential to the future of Python as a world algorithm language.


I admit that I am more bothered about the leftover quirks (to me -- 
sludge) in 2.x than most.


Unless you are the author/maintainer of an essential library, I have no 
opinion as to what you do with old code, or even what you use for new code.


I do care about people trying to disparage or sabotage 3.x.

Terry Jan Reedy

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


Re: Python 3

2009-11-05 Thread geremy condra
On Thu, Nov 5, 2009 at 5:31 PM, Terry Reedy  wrote:
> Steven D'Aprano wrote:
>
>> I've played around with 3.0, and I've read the What's New for 3.1 (and am
>> installing 3.1 now), and while the changes look nice, I'm not sure that
>> they're nice enough to deal with the pain of 2to3 migration.
>
> I am in a different position since I did not have current code that would
> need migrating.
>
>> So how about that, 3.1 fans? What are the most compelling reasons for you
>> that convinced you to change?
>
> I am writing a book on algorithms that uses a subset of 3.1 as the algorithm
> language. It it simply cleaner and easier to explain to people not already
> familiar with the quirks of 2.x. One small but important-to-me example. I do
> not need to put 'from __future__ import integerdivision' (or whatever the
> incantation is) as the top of files. Hence I do not need to waste energy
> (mime and readers) explaining furture imports and the specifics of the old
> versus new meaning of int/int.

I agree. Most of my code is primarily mathematical, and while I personally
see the move away from functional programming techniques as a minor
misstep, the cleanliness of it all more than makes up for that.

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


Re: Clean PyQt selection comboBox

2009-11-05 Thread Threader Slash
> -- Original message --
> From: MRAB 
> To: [email protected]
> Date: Thu, 05 Nov 2009 15:37:49 +
> Subject: Re: Clean PyQt selection comboBox
> Threader Slash wrote:
>
>> Hello Everybody, 8)
>>
>> I am using Qt and need to build a selection comboBox -- e.g.:
>> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG.
>>
>> The problem is - after one choice was made, and the code run, for the next
>> time the user select a different choice, both, the present and all past
>> choices run. See what I mean: ;(
>>
>> Code:
>>
>> selected color - blue
>> we are on runBlue
>>
>> selected color - red
>> we are on runBlue
>> we are on runRed
>>
>>
>> Here is the code:
>>
>> .
>> QtCore.QObject.connect(self.selectComboBox,
>>  QtCore.SIGNAL("currentIndexChanged(QString)"),
>>  self.combo_activateInput)   .
>>
>> def combo_activateInput(self):
>>color=unicode(self.selectComboBox.currentText())
>>if(color == "blue"):
>>print "selected color - blue"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runBlue)
>>
>>if(color == "red"):
>>print "selected color - red"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runRed)  if(color
>> == "yellow"):
>>
>>print "selected color - yellow"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runYellow)
>>del color .
>>
>> def combo_runBlue(self):
>>print "we are on runBlue"
>>
>> def combo_runRed(self):
>>print "we are on runRed"
>>
>> def combo_runYellow(self):
>>print "we are on runYellow"
>>
>> I run "del color" to clean the content returned by
>> selectComboBox.currentText, but it didn't clean the content indeed.
>>
>>  "del color" doesn't "clean the content", it just says "forget this
> name", in this case "forget the local variable called 'color'".
>
>  So, any suggestion? All comments and suggestions are highly appreciated.
>> :D :D :D
>>
>>  The ".connect" method connects something each time it's called. If you
> call it multiple times then multiple things will be connected.
>
> Try using ".disconnect" to disconnect what you no longer want connected.
>
> -- --
>

Thanks Man! You saved the day. It solved the problem...

def combo_runBlue(self):
print "we are on runBlue"
QtCore.QObject.disconnect(self.okButton, QtCore.SIGNAL("clicked()"),
self.combo_runBlue)

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


Re: Looking for portable what to determine directory where extensions are installed?

2009-11-05 Thread Gabriel Genellina
En Thu, 05 Nov 2009 14:20:28 -0300, Tom Epperly   
escribió:


I work on a language interoperability tool, Babel  
https://computation.llnl.gov/casc/components/components.html; and I need  
a portable way to determine the directory where Python extension modules  
are installed by distutils (i.e., lib or lib64) to resolve this issue:  
https://www.cca-forum.org/bugs/babel/issue670


The distutils SIG is probably a better place to ask:
http://www.python.org/community/sigs/current/distutils-sig/

--
Gabriel Genellina

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


Need help dumping exif data in canon raw files

2009-11-05 Thread Nuff Nuff
So I've looked at all sorts of things,  gone through as many different
things as I can find,  but I fear python just can't do it.

I just need to be able to extract the exif info from a canon CR2
file.  The info from canon suggest that it's just the same as a tiff,
but anytime I try to get PIL to open one,  it says that it tastes
bad.  And canon don't seem to be all that forthcoming on the details.

Ideally I'd be able to update the file with new exif info too,  but
that would just be a bonus.

Right now I just want to open a file (say /home/nuffi/IMG_0001.CR2 or
d:\pic\IMG_0001.CR2) and print out all the exif info attached to the
file.

Is it impossible in Python?

TIA!

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


Re: PiCloud Beta Release

2009-11-05 Thread Jacob Shaw
On Nov 1, 5:13 pm, Ken Elkabany  wrote:
> Hello,
>
> PiCloud has just released a Python library, cloud, which allows you to
> easily offload the execution of a function to a cluster of servers
> running on Amazon Web Services. As a beta product, we are currently
> free to all users who sign up with beta code "PYTHONLIST". To
> register, go tohttp://www.picloud.com
>
> Full service description:
> PiCloud is a cloud-computing platform that integrates into the Python
> Programming Language. It enables you to leverage the compute power of
> Amazon Web Services without having to manage, maintain, or configure
> virtual servers.
>
> PiCloud integrates seamlessly into your existing code base through a
> custom Python library, cloud. To offload the execution of a function
> to the cloud, all you must do is pass your desired function into the
> cloud library. PiCloud will then run the function on its
> high-performance and automatically-scaling cluster. We quickly scale
> our server capacity, both up and down, to meet your computational
> needs, and only charge you for the resources you actually consume.
> Getting on the cloud has never been this easy!
>
> PiCloud improves the full cycle of software development and
> deployment. Functions that are run on PiCloud have their resource
> usage monitored, performance analyzed, and errors traced; we further
> aggregate all your functions to give you a bird's eye view of your
> service. Through these introspective capabilities, PiCloud enables you
> to develop faster, easier, and smarter.
>
> Common use cases for our platform:
> * Crawling the web
> * Manipulating images and videos
> * Generating charts and graphs
> * Statistical/Mathematical analysis of data sets
> * Real-time data processing
>
> Cheers,
>
> Ken Elkabany
> PiCloud, Inc.

Wow, amazing service.  I used PiCloud for some scraping work, and my
script ran about 10x as fast.

Some questions though:
1) I have another project which uses a custom python extension written
in C++.  Is there a way to use it on PiCloud?
2) I noticed you guys only support python 2.5 and 2.6.  Will there be
3.1 support eventually?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help dumping exif data in canon raw files

2009-11-05 Thread Paul Rubin
Nuff Nuff  writes:
> I just need to be able to extract the exif info from a canon CR2
> file.  The info from canon suggest that it's just the same as a tiff,
> but anytime I try to get PIL to open one,  it says that it tastes
> bad.  And canon don't seem to be all that forthcoming on the details.

CR2 is a hardware-specific raw format and PIL should not be expected
to understand it.  Try a websearch for dcraw.c to find a decoder for it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do you use python?

2009-11-05 Thread Simon Forman
On Sat, Oct 31, 2009 at 2:11 AM, sk  wrote:
> What would be your answer if this question is asked to you in an
> interview?
>
> a modified version might be:
> "Where would you use python over C/C++/Java?"
>
> (because my resume says I know C/C++/Java)?


Mark Miller has some adages posted on his homepage. [1]  One of my
favorites is this:

"A Computer's Perspective on Moore's Law:
Humans are getting more expensive at an exponential rate."

Python saves you human-time.

Python allows you to write software that runs, is readable, can be
maintained and modified easily, etc...  far better than any other
language I've ever used.

You can write working code, and read and understand already-written
code /faster/ in Python than any other language I've ever used.


Use Python.  I would use C (to write Python extensions) only where
profiling had shown a definite hotspot, and then only when there were
no better algorithmic choices available.  I would never use C++ or
Java.


(N.B. I've managed to be gainfully, and blissfully, employed
programming in Python for about six years now.  I've passed on
otherwise interesting jobs because the folks involved were using
something other than Python.)

I'm actually working at a startup at the moment that originally hired
me to "do python" and then decided to use PHP because more of the team
(two out of three) knew it and didn't know python.  I figured "what
the heck, it's been awhile, and it will look good on my resume" so I
have stuck with them.

PHP isn't as horrible as I remembered, but it's still horrible.
/Everything/ is horrible compared to Python.  WTF is wrong with
people?  (Disclaimer: Smalltalk and LISP are not horrible... *grin*)

Anyway, I wouldn't say all that in an interview, heh, but that's my $0.02.

My strong advice to you or any programmer is, don't bother
interviewing with a company that's not already committed to using
Python as their main language (modulo extraordinary circumstances.)

[1] http://www.caplet.com/adages.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list to table

2009-11-05 Thread Alf P. Steinbach

* Jon Clements:


I read the OP as homework (I'm thinking Scott did as well),


Sorry. Need to recalibrate that neural network. Back-propagation initiated... 
Done! :-)




however,
your code would be much nicer re-written using collections.defaultdict
(int)... which I don't think is giving anything away...


Thanks!

This sent me searching everywhere, because the documentation of '+=' and other 
"augmented assignment statements" says


  "The target is only evaluated once.",

like in C++, which implies a kind of reference to mutable object.

I couldn't immediately see how subscription could apparently return a reference 
to mutable int object in Python in a way so that it worked transparently (the 
idiom in C++).


However, it worked to replace collections.defaultdict with a class overriding 
__getitem__ and __setitem__, so I guess that's how it works, that in this case 
'+=' is simply translated like 'x += n' -> 'temp = x; x = temp + n'.


Is this a correct understanding, and if so, what exactly does the documentation 
mean for the general case?


E.g.

def foo():
print( "foo" )
d = dict(); d[43] = 666
return d

def bar():
print( "bar" )
return 43;

foo()[bar()] += 1

produces

  foo
  bar

so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but evidently 
more like 'a = foo(); i = bar(); a.__setitem__(i, a.__getitem__(i) + 1)'?


If so, is this behavior defined anywhere?

I did find discussion (end of §6.2 of the language reference) of the case where 
the target is an attibute reference, with this example:


class A:
x = 3# class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3

:-)


Cheers, & thanks,

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


Re: parse a string (Cadence Allegro Netlist) to dictionary

2009-11-05 Thread metal
On 11月6日, 上午4时02分, Leland  wrote:
> Hi,
>
> I always use readline(), strip(), split() and so on to parse a string.
> Is there some elegant way to parse the following string into a
> dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?
>
> NET_NAME
> '50MHZ_CLK_SRC'
>  '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
>  C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
> NODE_NAME U122 2
>  '@TEST_LIB.TEST(SCH_1):page92_i...@inf_logic.cy2305(CHIPS)':
>  'CLK2': CDS_PINID='CLK2';
> NODE_NAME R1395 1
>  '@TEST_LIB.TEST(SCH_1):page92_i...@inf_resistors.resistor(CHIPS)':
>  'A': CDS_PINID='A';
>
> Thanks,
> Leland

not very elegantly too.

x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s)
"""
print {x[0]: x[1:]}
>>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']}
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: join , split question

2009-11-05 Thread metal
On 11月4日, 下午5时39分, elca  wrote:
> Hello,
> i have some text file list such like following format.
> i want to change text format to other format.
>  i was upload it pastebin sitehttp://elca.pastebin.com/d71261168
>
> if anyone help ,much appreciate thanks in advance
> --
> View this message in 
> context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html
> Sent from the Python - python-list mailing list archive at Nabble.com.

s = """uji708
uhodih
utus29
agamu4
azi340
ekon62
"""

from itertools import cycle
for i, x in zip(cycle(range(3)), s.splitlines()):
print x + ',',
if i == 2:
print

"""
uji708, uhodih, utus29,
agamu4, azi340, ekon62,
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse a string (Cadence Allegro Netlist) to dictionary

2009-11-05 Thread Rhodri James

On Thu, 05 Nov 2009 20:02:53 -, Leland  wrote:


Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
 '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
 C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_logic.cy2305(CHIPS)':
 'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
 '@TEST_LIB.TEST(SCH_1):page92_i...@inf_resistors.resistor(CHIPS)':
 'A': CDS_PINID='A';


Here's an inelegant way:

 CODE 

results = {}
net_name_next = False
net_name = None
node_names = []
for line in sourcefile:
  line = line.strip()
  if line.startswith('NET_NAME'):
if net_name is not None:
  results[net_name] = ", ".join(node_names)
net_name = None
node_names = []
net_name_next = True
  elif net_name_next:
net_name = line.strip("'")
net_name_next = False
  elif line.startswith('NODE_NAME'):
node_names.append("{1}.{2}".format(*line.split()))

# Last time through
if net_name is not None:
  results[net_name] = ", ".join(node_names)

 END CODE 

If you're prepared to allow the dictionary values to be lists rather than  
strings, we can squash that down:


 CODE 

results = {None: []}
net_name = None
for line in sourcefile:
  line = line.strip()
  if line.startswith('NET_NAME'):
net_name = sourcefile.next().strip(" \t\n'")
results[net_name] = []
  elif line.startswith('NODE_NAME'):
results[net_name].append("{1}.{2}".format(*line.split()))
del results[None]

 END CODE 

If you can guarantee that you won't meet a NODE_NAME before you see a  
NET_NAME then you can lose the messing about with results[None].  Having  
spent today picking up the pieces from an assumption that's rotted after  
several years, I'm not feeling that brave.  A slightly less messy version  
of that would be:



 CODE 

results = {}
entry = []
for line in sourcefile:
  line = line.strip()
  if line.startswith('NET_NAME'):
entry = []
results[sourcefile.next().strip(" \t\n'")] = entry
  elif line.startswith('NODE_NAME'):
entry.append("{1}.{2}".format(*line.split()))

 END CODE 

I'm a little dubious about doing mutable magic like this without copious  
comments, though.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: join , split question

2009-11-05 Thread metal
On 11月6日, 上午8时34分, metal  wrote:
> On 11月4日, 下午5时39分, elca  wrote:
>
> > Hello,
> > i have some text file list such like following format.
> > i want to change text format to other format.
> >  i was upload it pastebin sitehttp://elca.pastebin.com/d71261168
>
> > if anyone help ,much appreciate thanks in advance
> > --
> > View this message in 
> > context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html
> > Sent from the Python - python-list mailing list archive at Nabble.com.
>
> s = """uji708
> uhodih
> utus29
> agamu4
> azi340
> ekon62
> """
>
> from itertools import cycle
> for i, x in zip(cycle(range(3)), s.splitlines()):
>     print x + ',',
>     if i == 2:
>         print
>
> """
> uji708, uhodih, utus29,
> agamu4, azi340, ekon62,
> """

yet another version, a little evil

s = """uji708
uhodih
utus29
agamu4
azi340
ekon62
"""

from itertools import *
print '\n'.join(','.join(x for i, x in g) for k, g in groupby(enumerate
(s.splitlines()), lambda (i, x): i/3))
"""
uji708,uhodih,utus29
agamu4,azi340,ekon62
"""
-- 
http://mail.python.org/mailman/listinfo/python-list


2to3 on Mac - unknown encoding: mbcs

2009-11-05 Thread Skip Montanaro

I tried naively running 2to3 over the SpamBayes source code on my Mac
and got this traceback:

Traceback (most recent call last):
  File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py", line 
281, in find_cookie
codec = lookup(encoding)
LookupError: unknown encoding: mbcs

SpamBayes does have several files which contain the "mbcs" coding
cookie:

./windows/py2exe/gen_py/addin-designer.py
./windows/py2exe/gen_py/office-9.py
./windows/py2exe/gen_py/outlook-9.py

After a little hunting I came across the docs for the codecs module,
which for "mbcs" states:

Windows only: Encode operand according to the ANSI codepage (CP_ACP)

Is there something I can use to replace the mbcs coding cookies which
will allow 2to3 to process these Windows-specific files?

Thanks,

-- 
Skip Montanaro - [email protected] - http://www.smontanaro.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Freezing python files into executables

2009-11-05 Thread Aahz
In article ,
Mike Driscoll   wrote:
>
>Something that you might want to try in the future is GUI2Exe, which
>allows you to play with a whole slew of freezing modules:

Does GUI2Exe work from just the command-line?  I spent a fair amount of
time getting rid of the Mac GUI .pkg creator and I sure don't want to
introduce more GUI into our ant build process.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: join , split question

2009-11-05 Thread elca



Jon Clements-2 wrote:
> 
> On Nov 5, 2:08 pm, Bruno Desthuilliers  [email protected]> wrote:
>> Stuart Murray-Smith a écrit :
>>
>> >>> Hello, i have some text file list such like following format.
>> >>> i want to change text format to other format.
>> >>>  i was upload it pastebin site
>> >>>http://elca.pastebin.com/d71261168
>>
>> >> Dead link.
>>
>> >> With what ?
>>
>> >http://elca.pastebin.com/d4d57929a
>>
>> Yeah, fine. And where's the code you or the OP (if not the same person)
>> have problems with ?
> 
> I'd certainly be curious to see it, especially with the pagecheck()
> line 22 @ http://elca.pastebin.com/f5c69fe41
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
thanks all!
i was resolved :)

-- 
View this message in context: 
http://old.nabble.com/join-%2C-split-question-tp26193334p26225646.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


futures - a new package for asynchronous execution

2009-11-05 Thread Brian Quinlan

Hey all,

I recently implemented a package that I'd like to have include in the  
Python 3.x standard library (and maybe Python 2.x) and I'd love to  
have the feedback of this list.


The basic idea is to implement an asynchronous execution method  
patterned heavily on java.util.concurrent (but less lame because  
Python has functions as first-class objects).  Here is a fairly  
advanced example:


import futures
import functools
import urllib.request

URLS = [
   'http://www.foxnews.com/',
   'http://www.cnn.com/',
   'http://europe.wsj.com/',
   'http://www.bbc.co.uk/',
   'http://some-made-up-domain.com/']

def load_url(url, timeout):
   return urllib.request.urlopen(url, timeout=timeout).read()

# Use a thread pool with 5 threads to download the URLs. Using a pool
# of processes would involve changing the initialization to:
#   with futures.ProcessPoolExecutor(max_processes=5) as executor
with futures.ThreadPoolExecutor(max_threads=5) as executor:
   future_list = executor.run_to_futures(
   [functools.partial(load_url, url, 30) for url in URLS])

# Check the results of each future.
for url, future in zip(URLS, future_list):
   if future.exception() is not None:
   print('%r generated an exception: %s' % (url,  
future.exception()))

   else:
   print('%r page is %d bytes' % (url, len(future.result(

In this example, executor.run_to_futures() returns only when every url  
has been retrieved but it is possible to return immediately, on the  
first completion or on the first failure depending on the desired work  
pattern.


The complete docs are here:
http://sweetapp.com/futures/

A draft PEP is here:
http://code.google.com/p/pythonfutures/source/browse/trunk/PEP.txt

And the code is here:
http://pypi.python.org/pypi/futures3/

All feedback appreciated!

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


Re: 2to3 ParseError with UTF-8 BOM

2009-11-05 Thread Benjamin Peterson
Farshid  gmail.com> writes:
> If I remove the BOM then it works fine. Is this expected behavior or a
> bug in the 2to3 script?

Try the 2to3 distributed in Python 3.1.




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


Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)?

2009-11-05 Thread Peng Yu
I looked though the os.path manual. I don't find a function that can
test if a path is in a directory or its sub-directory (recursively).

For example, /a/b/c/d is in /a its sub-directory (recursively). Could
somebody let me know if such function is available somewhere?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)?

2009-11-05 Thread Chris Rebert
On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu  wrote:
> I looked though the os.path manual. I don't find a function that can
> test if a path is in a directory or its sub-directory (recursively).
>
> For example, /a/b/c/d is in /a its sub-directory (recursively). Could
> somebody let me know if such function is available somewhere?

Couldn't you just canonicalize the paths using os.path.abspath() and
friends and then do subdirectory.startswith(parent_directory) [as
strings]?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Peng Yu
Suppose I have a list of strings, A. I want to compute the list (call
it B) of strings that are elements of A but doesn't match a regex. I
could use a for loop to do so. In a functional language, there is way
to do so without using the for loop.

I'm wondering what is the best way to compute B in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Chris Rebert
On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu  wrote:
> Suppose I have a list of strings, A. I want to compute the list (call
> it B) of strings that are elements of A but doesn't match a regex. I
> could use a for loop to do so. In a functional language, there is way
> to do so without using the for loop.
>
> I'm wondering what is the best way to compute B in python.

Since this sounds rather homework-y, I'll only give you a pointer:
http://docs.python.org/tutorial/datastructures.html#list-comprehensions

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils.core.setup --install-script option in Python 2.6 ?

2009-11-05 Thread Gabriel Genellina
En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy   
escribió:


I have just upgraded from Python 2.5 to 2.6 and am unable to locate any  
trace of the --install-script option, in release 2.6.4 (MS Windows XP),  
for distutils.core.setup.  I also have been unable to locate any mention  
of it on-line.


Do you mean this option?
http://docs.python.org/distutils/builtdist.html#the-postinstallation-script
Probably the distutils SIG is a better place to ask:
http://www.python.org/community/sigs/current/distutils-sig/

--
Gabriel Genellina

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


ctypes exception in callback handlind

2009-11-05 Thread Gordon
This post concerns the situation where Python code calls C code via
ctypes, the C code then calls a callback back into Python code which
in turn raises an exception.

Currently as I understand things when the callback finishes and
control is returning to C land ctypes will catch and print the
exception and then return normally back to C.
The standard way of doing something meaningful with the exception is
to catch it in the callback, set a global flag, somehow encourage the
C code to unwind back to the original Python call and there check the
flag and re-raise the exception.

My current problems involves a non recoverable error being raised in
the callback. The intermediate C code is not at all setup to deal with
a failure like this and I can't find a way to "somehow encourage the C
code to unwind".
For extra giggles I can't just hit sys.exit as this stack got invoked
as a callback out of a third party python library that needs to do
some clean up. All of which leaves me wishing that ctypes would
propgate the exception back to the python calling context for me.

One approach I can think of that I would like to get some feedback on
is the following:
Create a new ctypes calling convention that does a setjmp on entry.
When using that calling convention if an exception is raised by a call
back, catch it and store it somewhere, longjmp back to the setjmp
point and re-raise it.

I appreciate that this will generally leave the intervening C code in
an undefined state and as such would definitely have to be an optional
feature.

I realize that I could in theory do this myself by wrapping each of
the C calls with a wrapper that does the setjmp work, but there are
quite a few of them.

So any comments or suggestions?

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


Re: What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Peng Yu
On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert  wrote:
> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu  wrote:
>> Suppose I have a list of strings, A. I want to compute the list (call
>> it B) of strings that are elements of A but doesn't match a regex. I
>> could use a for loop to do so. In a functional language, there is way
>> to do so without using the for loop.
>>
>> I'm wondering what is the best way to compute B in python.
>
> Since this sounds rather homework-y, I'll only give you a pointer:
> http://docs.python.org/tutorial/datastructures.html#list-comprehensions

Now, I want to in-place delete elements in A that matches the regex. I
know that I need to use del. But I'm not sure how to use the
functional style programming for this problem. Would you please let me
know?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list to table

2009-11-05 Thread Gabriel Genellina
En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach   
escribió:

* Jon Clements:


This sent me searching everywhere, because the documentation of '+=' and  
other "augmented assignment statements" says


   "The target is only evaluated once.",

like in C++, which implies a kind of reference to mutable object.


Not exactly. For an augmented assignment, the target (left side) may be an  
identifier, an atttribute reference, or a subscription/slicing. In the  
first case, the comment simply does not apply (there is a single one  
opportunity to evaluate the target).


a += some(expression) means: evaluate "a", evaluate some(expression),  
perform the operation +=, bind the resulting object to the name "a".


a.attr += some(expression) means: evaluate "a", ask it for its attribute  
"attr", evaluate some(expression), perform the operation +=, ask the  
(already known) object "a" to store the resulting object as its attribute  
"attr".


a[index] += some(expression) performs a similar sequence of steps; "a" is  
evaluated only once, then it is asked to retrieve its element at [index],  
the computation is performed, and finally the (already known) object "a"  
is asked to store the result at [index].


"The target is only evaluated once." means that it is NOT reevaluated  
before the final result is stored. Same applies to "index" above, although  
this is not explicited. Perhaps it is more clear with a longer expression:  
a[b+c].c[d(e[f])].h += 1 computes the a[b+c].c[d(e[f])] part only once.


I couldn't immediately see how subscription could apparently return a  
reference to mutable int object in Python in a way so that it worked  
transparently (the idiom in C++).


It does not. It perform first a "getitem" operation followed by a  
"setitem" to store the result. A normal dictionary would fail when asked  
for an inexistent item; a defaultdict creates and returns a default value  
in such case.


py> import collections
py> d = collections.defaultdict(int)
py> d['a'] += 1
py> d['a'] += 1
py> d['a']
2
py> d['b']
0

note: int() returns 0; defaultdict(lambda: 0) could have been used.

However, it worked to replace collections.defaultdict with a class  
overriding __getitem__ and __setitem__, so I guess that's how it works,  
that in this case '+=' is simply translated like 'x += n' -> 'temp = x;  
x = temp + n'.


Is this a correct understanding, and if so, what exactly does the  
documentation mean for the general case?


If x is a simple name, the only difference between x += n and x = x+n is  
the method invoked to perform the operation (__iadd__ vs __add__ in  
arbitrary objects). Both x and n are evaluated only once - and this is not  
an optimization, nor a shortcut, simply there is no need to do otherwise  
(please make sure you understand this).


From the docs for the operator module: "Many operations have an “in-place”  
version. The following functions provide a more primitive access to  
in-place operators than the usual syntax does; for example, the statement  
x += y is equivalent to x = operator.iadd(x, y). Another way to put it is  
to say that z = operator.iadd(x, y) is equivalent to the compound  
statement z = x; z += y."

http://docs.python.org/library/operator.html


foo()[bar()] += 1

so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but  
evidently more like 'a = foo(); i = bar(); a.__setitem__(i,  
a.__getitem__(i) + 1)'?


Yes, something like that.


If so, is this behavior defined anywhere?


Isn't the description at  
http://docs.python.org/reference/simple_stmts.html#assignment-statements  
enough? It goes to some detail describing, e.g., what a.x = 1 means. The  
next section explains what a.x += 1 means in terms of the former case.


I did find discussion (end of §6.2 of the language reference) of the  
case where the target is an attibute reference, with this example:


class A:
 x = 3# class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3


Do you want to discuss this example?

--
Gabriel Genellina

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


Re: 2to3 on Mac - unknown encoding: mbcs

2009-11-05 Thread Gabriel Genellina
En Thu, 05 Nov 2009 22:50:57 -0300, Skip Montanaro   
escribió:



I tried naively running 2to3 over the SpamBayes source code on my Mac
and got this traceback:

Traceback (most recent call last):
  File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py",  
line 281, in find_cookie

codec = lookup(encoding)
LookupError: unknown encoding: mbcs

SpamBayes does have several files which contain the "mbcs" coding
cookie:

./windows/py2exe/gen_py/addin-designer.py
./windows/py2exe/gen_py/office-9.py
./windows/py2exe/gen_py/outlook-9.py

After a little hunting I came across the docs for the codecs module,
which for "mbcs" states:

Windows only: Encode operand according to the ANSI codepage (CP_ACP)

Is there something I can use to replace the mbcs coding cookies which
will allow 2to3 to process these Windows-specific files?


Using mbcs as the source encoding declaration is evil (and stupid too).  
mbcs means "whatever encoding is currently configured in Windows", it is  
not a specific encoding.
You have to guess which encoding those files are in. windows-1252 (almost  
the same as latin-1) is the one used in "Western Europe", which covers an  
area much broader than its name.


Good luck,

--
Gabriel Genellina

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


Re: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)?

2009-11-05 Thread Gabriel Genellina
En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert   
escribió:

On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu  wrote:



I looked though the os.path manual. I don't find a function that can
test if a path is in a directory or its sub-directory (recursively).

For example, /a/b/c/d is in /a its sub-directory (recursively). Could
somebody let me know if such function is available somewhere?


Couldn't you just canonicalize the paths using os.path.abspath() and
friends and then do subdirectory.startswith(parent_directory) [as
strings]?


Beware of directories starting with the same letters.
I'd canonicalize, split the strings on os.sep, and compare the resulting  
lists up to the shortest one.


--
Gabriel Genellina

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


listing an object's methods/attributes?

2009-11-05 Thread Robert P. J. Day

  getting back into python after a long hiatus and "diving" into
python 3 (http://www.diveintopython3.org/), but i can't remember how
to list an object's full set of methods or attributes.  how does that
go again?

rday
--


Robert P. J. Day   Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:  http://crashcourse.ca
Twitter:   http://twitter.com/rpjday

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


Re: disable image loading to speed up webpage load

2009-11-05 Thread Tim Roberts
elca  wrote:
>
>im using win32com 's webbrowser module.

Win32com does not have a webbrowser module.  Do you mean you are using
Internet Explorer via win32com?

>i have some question about it..
>is it possible to disable image loading to speed up webpage load?

If you are using IE, then you need to tell IE to disable image loading.  I
don't know a way to do that through the IE COM interface.
-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes exception in callback handlind

2009-11-05 Thread Gabriel Genellina

En Fri, 06 Nov 2009 01:57:18 -0300, Gordon  escribió:


This post concerns the situation where Python code calls C code via
ctypes, the C code then calls a callback back into Python code which
in turn raises an exception.


I'd ask in a ctypes specific list: 

--
Gabriel Genellina

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


Re: What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Chris Rebert
On Thu, Nov 5, 2009 at 9:23 PM, Peng Yu  wrote:
> On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert  wrote:
>> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu  wrote:
>>> Suppose I have a list of strings, A. I want to compute the list (call
>>> it B) of strings that are elements of A but doesn't match a regex. I
>>> could use a for loop to do so. In a functional language, there is way
>>> to do so without using the for loop.
>>>
>>> I'm wondering what is the best way to compute B in python.
>>
>> Since this sounds rather homework-y, I'll only give you a pointer:
>> http://docs.python.org/tutorial/datastructures.html#list-comprehensions
>
> Now, I want to in-place delete elements in A that matches the regex. I
> know that I need to use del. But I'm not sure how to use the
> functional style programming for this problem. Would you please let me
> know?

Deletion is an imperative operation which has no direct equivalent in
functional languages, so your question is nonsensical.
To do it functionally, instead of deleting, you simply build a new
list that omits the undesired elements.
See also the built-in function filter().

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Gabriel Genellina

En Fri, 06 Nov 2009 02:23:12 -0300, Peng Yu  escribió:

On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert  wrote:

On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu  wrote:



Suppose I have a list of strings, A. I want to compute the list (call
it B) of strings that are elements of A but doesn't match a regex. I
could use a for loop to do so. In a functional language, there is way
to do so without using the for loop.

I'm wondering what is the best way to compute B in python.


Since this sounds rather homework-y, I'll only give you a pointer:
http://docs.python.org/tutorial/datastructures.html#list-comprehensions


Now, I want to in-place delete elements in A that matches the regex. I
know that I need to use del. But I'm not sure how to use the
functional style programming for this problem. Would you please let me
know?


Functional and del don't mix. What about:

B = [item for item in A if regex.match(item) is None]
B = filter(lambda item: regex.match(item) is None, A)

--
Gabriel Genellina

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


Re: listing an object's methods/attributes?

2009-11-05 Thread Gabriel Genellina
En Fri, 06 Nov 2009 03:48:48 -0300, Robert P. J. Day  
 escribió:



  getting back into python after a long hiatus and "diving" into
python 3 (http://www.diveintopython3.org/), but i can't remember how
to list an object's full set of methods or attributes.  how does that
go again?


Try dir(the_object), vars(the_object), help(the_object), see(the_object) -  
this last one a hidden gem from http://github.com/inky/see (see is "dir  
for humans")


--
Gabriel Genellina

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


Re: list to table

2009-11-05 Thread Alf P. Steinbach

* Gabriel Genellina:
En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach  
escribió:



[snip]
 From the docs for the operator module: "Many operations have an 
“in-place” version. The following functions provide a more primitive 
access to in-place operators than the usual syntax does; for example, 
the statement x += y is equivalent to x = operator.iadd(x, y). Another 
way to put it is to say that z = operator.iadd(x, y) is equivalent to 
the compound statement z = x; z += y."

http://docs.python.org/library/operator.html


Thanks!



foo()[bar()] += 1

so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but 
evidently more like 'a = foo(); i = bar(); a.__setitem__(i, 
a.__getitem__(i) + 1)'?


Yes, something like that.


If so, is this behavior defined anywhere?


Isn't the description at 
http://docs.python.org/reference/simple_stmts.html#assignment-statements 
enough? It goes to some detail describing, e.g., what a.x = 1 means. The 
next section explains what a.x += 1 means in terms of the former case.


No, it wasn't exactly enough for me, coming most recently from a C++ background.

One reason was as mentioned that the C++ standard has essentially the /same 
wording/ about "only evaluated once" but with a more strict meaning; in C++, 
with the built-in += operator


   a()[foo()] += 1;

not only avoids calling a() and foo() twice, it also avoids doing the internal 
indexing twice, while in python the internal indexing, locating that item, is 
performed first in __getitem__ and then in __setitem__ (unless that is optimized 
away at lower level by caching last access, but that in itself has overhead).


Another reason was that §6.2 does explicitly discuss attribute references as 
targets, but not subscription as target. It would have been more clear to me if 
all (four?) possible target forms were discussed. Happily you did now discuss 
that in the part that I snipped above, but would've been nice, and easier for 
for an other-language-thinking person :-), if it was in documentation.



I did find discussion (end of §6.2 of the language reference) of the 
case where the target is an attibute reference, with this example:


class A:
 x = 3# class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3


Do you want to discuss this example?


Thanks but no, it's OK, I understand it.


Cheers,

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


Re: What is the best way to delete strings in a string list that that match certain pattern?

2009-11-05 Thread Lie Ryan

Peng Yu wrote:

Suppose I have a list of strings, A. I want to compute the list (call
it B) of strings that are elements of A but doesn't match a regex. I
could use a for loop to do so. In a functional language, there is way
to do so without using the for loop.


In functional language, there is no looping, so that argument is kind of 
pointless. The looping construct in many functional language is a syntax 
sugar for recursion.


In python, instead of explicit loop, you can use either:
  map(pattern.match, list_of_strs)
or
  [pattern.match(mystr) for mystr in list_of_strs]

or if you want to be wicked evil, you can write a recursive function as 
such:


def multimatcher(list_of_strs, index=0):
return [] if index >= len(list_of_strs) else (
multimatcher(
list_of_strs[index + 1]
).append(
pattern.match(list_of_strs[index])
)
)
--
http://mail.python.org/mailman/listinfo/python-list