newbie SWIG typemap question

2006-02-12 Thread Syrinx
Hi everyone.  I'm new to SWIG, and I'm trying to wrap a C library for
Python.

I have a function that is declared similarly to this:

double *foo(int x);

The function returns a pointer to an array of 7 double values.  I want
to return a 7-tuple to Python.  I've been trying variations of the
following typemap, but I get a segmentation fault when I try it.
(It's been awhile since I've done any C, so it may be an obvious C
error, I'm not sure.)

Can anyone tell me what's wrong, or just show me how to accomplish
what I'm after?  I'd appreciate it a lot.  Thank you.

%typemap(python, out) double* {
int i;
PyObject *o = PyTuple_New(7);
for(i = 0; i < 7; i++) {
PyObject *o2 = PyFloat_FromDouble((double)$1[i]);
PyTuple_SET_ITEM(o, i, o2);
}
$result = o;
} 

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


Wanted Python and C developer Urgently

2006-02-12 Thread Rozario, Sophia_Diana
Hi, I am posting a couple of requirements in my organization. Any one 
interested can reply me directly.
Maestro Software Developer
We are seeking experienced software professionals to design and develop new 
components as well as to enhance and maintain Maestro, a best-of-breed 
computational chemistry graphical interface. Maestro is the unifying graphical 
interface for all of our simulation products. 
The ideal candidate will have at least 3 years of industry experience using C 
and C++, with a solid understanding of object-oriented design and programming. 
Experience in creating graphical user interfaces using Motif or a similar API 
and X Windows is required. You must have more than 3 years of industry 
experience with developing applications and significant development experience 
under UNIX (any version ok, but Linux or IRIX preferred). Frequent interactions 
with the firm's geographically dispersed groups make exceptional written and 
oral communication skills essential.
An interest in creating and working on scientific user-interfaces is a plus, as 
is experience with any of the following:
*   Motif/Lesstif (or any similar variant). 
*   OpenGL. 
*   Development experience with any or all of Linux, IRIX, or 
Windows. 
*   For Windows 2000 or XP, in particular, experience using MS 
VC++. 
*   Familiarity with UNIX build tools such as make. 
*   Fortran (77 and/or 90). 
Senior Python Developer
Our Maestro product, the unifying graphical interface for all of our simulation 
products, includes and is supported by a suite of Python productivity and 
workflow tools. These tools range from small independent applications to larger 
applications needing tight integration with one or more Schrödinger products 
and utilities, and they allow for a high degree of customizability, increase 
user productivity and maximally leverage all Schrödinger products by creating 
novel, highly effective workflows. 
We are currently seeking an experienced Python developer to design and develop 
additional Python tools, and to enhance and maintain the existing 
infrastructure. The ideal candidate will have a Bachelor's degree in 
Engineering or Science and will possess a sound knowledge of Python and C. 
Experience with maintaining or extending Python wrappers as well as some 
knowledge of Python internals are a must. Good written and oral communication 
skills are essential. 
Knowledge of Swig or C++ is a plus, as is experience with creating graphical 
user interfaces, especially using interpreted or scripted languages, though 
candidates with GUI experience using compiled languages will also be 
considered. 
Python Developer
Our Maestro product, the unifying graphical interface for all of our simulation 
products, includes and is supported by a suite of Python productivity and 
workflow tools. These tools range from small independent applications to larger 
applications needing tight integration with one or more Schrödinger products 
and utilities, and they allow for a high degree of customizability, increase 
user productivity and maximally leverage all Schrödinger products by creating 
novel, highly effective workflows. 
We are currently seeking an experienced software developer to design and 
develop additional Python tools, and to enhance and maintain the existing 
tools. The ideal candidate will have experience with and a solid understanding 
of Python or other scripted and interpreted languages. You must have a Master's 
degree in Physics or Chemistry with a good understanding of computational 
chemistry software and the associated workflows. You must have the ability to 
work well with scientists and developers within our Schrödinger team to create 
the tools required by our customers and for our workflows. Frequent 
interactions with the firm's geographically dispersed groups make exceptional 
written and oral communication skills essential. 
Knowledge of Python, Tk, Tkinter, Pmw is a plus, as is experience in creating 
graphical user interfaces and cross-platform development.
Systems Software Engineer, Job Control
We are seeking software developers with solid experience in system and network 
programming for both Windows and Unix to assist in the development and 
maintenance of the job control middleware used by our computational chemistry 
products. 
The ideal candidate will have a minimum of two years experience in system and 
network programming for both Windows and Unix systems, and be fluent in both 
Perl and C. You must have significant experience with Python programming. A 
Bachelor's or Master's degree in Computer Science or an equivalent academic 
background is required. Frequent interactions with the firm's geographically 
dispersed groups make exceptional written and oral communication skills 
essential.
Significant experience with any of the following is a plus:
*   Commercial software development 
*   Cross

Re: how do you pronounce 'tuple'?

2006-02-12 Thread [EMAIL PROTECTED]
Grant Edwards wrote:
> On 2006-02-13, John Salerno <[EMAIL PROTECTED]> wrote:
>
> > I know it comes from the suffix -tuple, which makes me think
> > it's pronounced as 'toople', but I've seen (at m-w.com) that
> > the first pronunciation option is 'tuhple', so I wasn't sure.
> > Maybe it's both, but which is most prevalent?
>
> In my expereince, the latter.  I don't think I've ever heard
> the other pronounciation.

I used to pronounce it toople.  But the people that taught me Python
found it both comical and confusing.  At first they thought I meant a 2
element tuple.  So they wondered if a 3 element tuple was a threeple,
etc.  After much harrassing, I changed my wayward ways and pronounced
it tuhple to fit in with the cool Python guys. ;-)

Then we went to hear Guido speak about Python 2.2 at a ZPUG meeting in
Washington, DC.  When he said toople I almost fell out of my chair
laughing, particularly because the people who taught me to say it the
"right" way were with me.  When I looked over, they just hung their
head in shame.

I work with Guido now and I'm conflicted.  I'm still conditioned to say
tuhple.  Whenever he says toople, I just get a smile on my face.  I
think most of the PythonLabs guys pronounce it toople.

n

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


Re: ordered sets operations on lists..

2006-02-12 Thread Kay Schluehr
Bengt Richter wrote:

> Perhaps newbies should be advised that
>
> [x for x in l1 if x in set(l2)]

But the resulting list is a representative of bag not a set ( contains
multiple occurrences of  elements ):

>>> [x for x in [3, 3] if s in Set([3])]
[3,3]

Same with Raymonds solution:

>>> filter(Set([3]).__contains__, [3,3]) 
[3, 3]

Kay

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


Re: Slightly OT: Ranking noise

2006-02-12 Thread Fredrik Lundh
Kay Schluehr wrote:

> For those people who use google groups to access comp.lang.python may
> enjoy now looking at contentess shiny yellow stars - shining brighter
> than anything else on the site. The only pattern I've found are one or
> two shiny yellow stars for many newbie postings. According to the
> staring semantics the plebs tries to inform me that those are mostly
> irrelevant. I slightly disagree but don't want to give 5 stars anyway.
> The other funny discovery I made is that some part of the mobocracy
> thinks that Alex Martelli is average.

he's lucky:

http://www.flickr.com/photos/effbot/98878478/





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


Re: ordered sets operations on lists..

2006-02-12 Thread Brett Cannon
On 2/12/06, Felipe Almeida Lessa <[EMAIL PROTECTED]> wrote:
> Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu:
> > Given that Python 2.4 doesn't even perform simple constant folding for
> > arithmetic expressions
> > [snip]
>
> May I ask why doesn't it perform such optimization? Is there any special
> difficulties in doing so with the Python compiler?

It does in 2.5 thanks to Raymond Hettinger:

>>> import dis
[18110 refs]
>>> def simple(): print 1+2
...
[18136 refs]
>>> dis.dis(simple)
  1   0 LOAD_CONST   3 (3)
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST   0 (None)
  8 RETURN_VALUE
[18635 refs]
>>>

Simple, low-hanging fruit like this are covered by the peephole
optimizer already.  Anything more complex, though, is difficult thanks
to things being so dynamic and thus not easy to guarantee to be
correct between compile-time and run-time.

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

Re: how do you pronounce 'tuple'?

2006-02-12 Thread Erik Max Francis
John Salerno wrote:

> Yes, silly question, but it keeps me up at night.  :)
> 
> I know it comes from the suffix -tuple, which makes me think it's 
> pronounced as 'toople', but I've seen (at m-w.com) that the first 
> pronunciation option is 'tuhple', so I wasn't sure. Maybe it's both, but 
> which is most prevalent?
> 
> Thanks! Now time to go back to reading the chapter on tuples...

I believe both is right.  Those who come from a pure mathematics 
background are more likely to pronounce it _toople_.  Those who have 
encountered it in the wild are more likely to pronounce it _tuhple_.  I 
had enough of an understanding of mathematics to recognize where it came 
from when I encountered it in Python, but I pronounce it the latter way.

Even in mathematics, a tuple, or formally an n-tuple, makes more sense 
to me pronounced the latter if you list out the various pronounciations 
for large n, seems me the _uhs_ outweigh the _oos_.  (There's quadruple 
on one side, but then quintuple, sextuple, septuple, heptuple, octuple, 
etc., etc., etc.)

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   We are victims of our circumstance.
   -- Sade Adu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python very slow compared to C

2006-02-12 Thread bonono

PA wrote:
> On Feb 13, 2006, at 06:44, [EMAIL PROTECTED] wrote:
>
> > And if we use market penetration as measure, Perl seems to be easier
> > for people ?
>
> Perl: Shell scripts/awk/sed are not enough like programming languages.
>
> Python: Perl is a kludge.
>
> "What Languages Fix"
> http://www.paulgraham.com/fix.html
>
> Cheers

Where is the entry for Lua and Haskell, both I found very interesting.

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


Re: Is python very slow compared to C

2006-02-12 Thread PA

On Feb 13, 2006, at 06:44, [EMAIL PROTECTED] wrote:

> And if we use market penetration as measure, Perl seems to be easier
> for people ?

Perl: Shell scripts/awk/sed are not enough like programming languages.

Python: Perl is a kludge.

"What Languages Fix"
http://www.paulgraham.com/fix.html

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/

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


Slightly OT: Ranking noise

2006-02-12 Thread Kay Schluehr
For those people who use google groups to access comp.lang.python may
enjoy now looking at contentess shiny yellow stars - shining brighter
than anything else on the site. The only pattern I've found are one or
two shiny yellow stars for many newbie postings. According to the
staring semantics the plebs tries to inform me that those are mostly
irrelevant. I slightly disagree but don't want to give 5 stars anyway.
The other funny discovery I made is that some part of the mobocracy
thinks that Alex Martelli is average. My question: does anybody know
whether this post-infantile nonsense and site-noise that captures at
least my attention is anyhow customizable?

5 stars from me for a helpfull answer,
*kisses* Kay

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


Re: Newbie

2006-02-12 Thread mcbooczech
For me (I am newbie as well) was following link very useful:
http://benyoonline.com/pqr/PQR2.4.html

Good luck with Python

Petr Jakes

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


Python 3000 deat !? Is true division ever coming ?

2006-02-12 Thread seb . haase
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2  to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I'm using Python as "Matlab replacement" and would
generally like 5/2 ==2.5

So, I was contemplating to default all my modules/scripts to start with
"from __future__ import division"
but if it is never coming (in this decade, that is)  then it would be a
waste of time just confuse everybody !!

Thanks,
Sebastian Haase

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


how to create a movie ?

2006-02-12 Thread seb . haase
Hi,
I have a series of images (either from numarray or from PIL)
After googling if read something about pyMedia...

Can I create an AVI movie from my images with that ? How about
quicktime ? 

Thanks,
Sebastian Haase

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


Re: Is python very slow compared to C

2006-02-12 Thread bonono

Steven D'Aprano wrote:
> [EMAIL PROTECTED] wrote:
>
> > I can speak the same about Python if I view it from a prototype based
> > perspective, where one get them for free in Lua but need to implement
> > them in Python.
>
> Sure. And if you need prototypes, then all else being
> equal that would be a disadvantage of Python compared
> to Lua.
>
> On the other hand, I'd suggest that far more
> programmers are familiar with classes than prototypes,
> regardless of any objective advantages or disadvantages
> of one over the other. Perhaps that's one of the
> reasons why Lua is lacking the market penetration of
> Python: programmers may look at it and say "No classes?
> Prototyping? WTF is that? I don't have time to learn
> something so different, better stick to languages which
> have a smaller learning curve."

The "=" operator in Python is also quite different from many language
people had experience like C or VB etc. And using the same argument,
everyone may still be programming in COBOL now.

And if we use market penetration as measure, Perl seems to be easier
for people ?

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


Re: Is python very slow compared to C

2006-02-12 Thread Steve Holden
Steven D'Aprano wrote:
> [EMAIL PROTECTED] wrote:
> 
> 
>>I can speak the same about Python if I view it from a prototype based
>>perspective, where one get them for free in Lua but need to implement
>>them in Python.
> 
> 
> Sure. And if you need prototypes, then all else being 
> equal that would be a disadvantage of Python compared 
> to Lua.
> 
> On the other hand, I'd suggest that far more 
> programmers are familiar with classes than prototypes, 
> regardless of any objective advantages or disadvantages 
> of one over the other. Perhaps that's one of the 
> reasons why Lua is lacking the market penetration of 
> Python: programmers may look at it and say "No classes? 
> Prototyping? WTF is that? I don't have time to learn 
> something so different, better stick to languages which 
> have a smaller learning curve."
> 
> 
> 
Or perhaps they'll see that Self demonstrated the advantages and 
disadvantages of the prototyping approach long ago.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote:

> I can speak the same about Python if I view it from a prototype based
> perspective, where one get them for free in Lua but need to implement
> them in Python.

Sure. And if you need prototypes, then all else being 
equal that would be a disadvantage of Python compared 
to Lua.

On the other hand, I'd suggest that far more 
programmers are familiar with classes than prototypes, 
regardless of any objective advantages or disadvantages 
of one over the other. Perhaps that's one of the 
reasons why Lua is lacking the market penetration of 
Python: programmers may look at it and say "No classes? 
Prototyping? WTF is that? I don't have time to learn 
something so different, better stick to languages which 
have a smaller learning curve."



-- 
Steven.

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


Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Felipe Almeida Lessa wrote:
> Em Dom, 2006-02-12 às 23:51 -0500, Steve Holden escreveu:
> 
>>The basic answer is that so far no developer has felt it worthwhile to 
>>expend time on adding these optimizations.
> 
> 
> I always thought these small optimizations could lead Python to be
> faster overall. I remember about this every time I see CPython vs.
> IronPython benchmarks (.NET and Mono do some nice optimizations at
> compile and run times).
> 
Indeed it is true that on some benchmarks IronPython is faster than 
CPython. I suspect this was helped by the fact that IronPython is Jim's 
third implementation of Python (I believe he was familiar with CPython 
before he started on Jython, formerly known as JPython).

The fact remains that until someone writes the code it can't be included 
in the implementation. Performance optimization, unfortunately, doesn't 
have the same glamorous cachet as more esoteric language features.
> 
>>>Also, IIRC Psyco does optimize these constant expressions. Or am I
>>>wrong?
>>>
>>
>>Psyco does some very advanced things, but it does them all at run-time. 
>>Unless I misunderstand (not unheard of), there are no circumstances 
>>under which Psyco will improve run-time for a piece of code that is only 
>>executed once.
> 
> 
> Sorry, I think I should have been clearer. Yes, Psyco only helps at
> runtime (when the function is called), but those constant folds only
> practically help on parts of the code that are called many times anyway,
> right?
> 
Right. Technically constant folding is a win for a single execution, but 
only if you don't take the slightly-increased compile time into account :-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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

RE: ordered sets operations on lists..

2006-02-12 Thread Delaney, Timothy (Tim)
Delaney, Timothy (Tim) wrote:

> Adding such optimisations to Python may improve it's benchmark scores,
  

Blegh! Time to give myself a good kicking!

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


Re: ordered sets operations on lists..

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 23:51 -0500, Steve Holden escreveu:
> The basic answer is that so far no developer has felt it worthwhile to 
> expend time on adding these optimizations.

I always thought these small optimizations could lead Python to be
faster overall. I remember about this every time I see CPython vs.
IronPython benchmarks (.NET and Mono do some nice optimizations at
compile and run times).

> > Also, IIRC Psyco does optimize these constant expressions. Or am I
> > wrong?
> > 
> Psyco does some very advanced things, but it does them all at run-time. 
> Unless I misunderstand (not unheard of), there are no circumstances 
> under which Psyco will improve run-time for a piece of code that is only 
> executed once.

Sorry, I think I should have been clearer. Yes, Psyco only helps at
runtime (when the function is called), but those constant folds only
practically help on parts of the code that are called many times anyway,
right?

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

RE: ordered sets operations on lists..

2006-02-12 Thread Delaney, Timothy (Tim)
Steve Holden wrote:

> The basic answer is that so far no developer has felt it worthwhile to
> expend time on adding these optimizations.

Mainly because it's rare to find such constructs in anything except
contrived examples ... Nearly every time you use a literal, it's being
added to (subtracted from, etc) a non-literal.

Adding such optimisations to Python may improve it's benchmark scores,
but that's about it. The real gains are to be found in reducing function
call overhead, attribute access, etc - and as a result there has been
considerable effort expended in those areas.

FWIW, there are some of us who do occasionally do bytecode
optimisations, but we know it's just a bit of fun. I've yet to do any
bytecode manipulation that's significantly improved performance. You're
best of leaving such things to Pysco, and concentrating on algorithmic
improvements.

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


Re: Newbie

2006-02-12 Thread bonono

LittlePython wrote:
> I am very new to python. I have been studying it for only a month or so. I
> have been using vbscript for about 2-3 yrs and only recently been using it
> rather heavily the past 9 months or so. I am new very new to oop. My main
> use will be administrative scripting into the win3k, XP, AD domain,
> 55exchange and 2003exchange environments. I like to incorp wxpython (GUI)
> into my scripts instead of HTA's that I have been using with VBS. I am also
> finding myself being tasked with jobs that are outside the scope of VBS.
> Well that's a lot to learn and I have a feeling that to many I am just
> another member of  "The Ministry of STUPID Questions"
>
Out of curiosity, why python ? The new VB.Net seems to be a very
interesting one language wise and given that you have a VB experience,
it seems to be a natural one to try.

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


Re: how do you pronounce 'tuple'?

2006-02-12 Thread Markus Wankus
John Salerno wrote:
> Yes, silly question, but it keeps me up at night.  :)
> 
> I know it comes from the suffix -tuple, which makes me think it's 
> pronounced as 'toople', but I've seen (at m-w.com) that the first 
> pronunciation option is 'tuhple', so I wasn't sure. Maybe it's both, but 
> which is most prevalent?
> 
> Thanks! Now time to go back to reading the chapter on tuples...

I'm not sure, but I think it is pronounced "ménage à trois".

M.

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


Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Felipe Almeida Lessa wrote:
> Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu:
> 
>>Given that Python 2.4 doesn't even perform simple constant folding for 
>>arithmetic expressions
>>[snip]
> 
> 
> May I ask why doesn't it perform such optimization? Is there any special
> difficulties in doing so with the Python compiler?
> 
As well to ask why the sky is blue, and has those little white things in 
it (unless you live in Arizona) :-)

The basic answer is that so far no developer has felt it worthwhile to 
expend time on adding these optimizations.

> Also, IIRC Psyco does optimize these constant expressions. Or am I
> wrong?
> 
Psyco does some very advanced things, but it does them all at run-time. 
Unless I misunderstand (not unheard of), there are no circumstances 
under which Psyco will improve run-time for a piece of code that is only 
executed once.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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

Re: ordered sets operations on lists..

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu:
> Given that Python 2.4 doesn't even perform simple constant folding for 
> arithmetic expressions
> [snip]

May I ask why doesn't it perform such optimization? Is there any special
difficulties in doing so with the Python compiler?

Also, IIRC Psyco does optimize these constant expressions. Or am I
wrong?

Cheers,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: how do you pronounce 'tuple'?

2006-02-12 Thread Grant Edwards
On 2006-02-13, John Salerno <[EMAIL PROTECTED]> wrote:

> I know it comes from the suffix -tuple, which makes me think
> it's pronounced as 'toople', but I've seen (at m-w.com) that
> the first pronunciation option is 'tuhple', so I wasn't sure.
> Maybe it's both, but which is most prevalent?

In my expereince, the latter.  I don't think I've ever heard
the other pronounciation.

-- 
Grant Edwards   grante Yow!  Isn't this my STOP?!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you pronounce 'tuple'?

2006-02-12 Thread Steve Holden
John Salerno wrote:
> Yes, silly question, but it keeps me up at night.  :)
> 
Silly you!

> I know it comes from the suffix -tuple, which makes me think it's 
> pronounced as 'toople', but I've seen (at m-w.com) that the first 
> pronunciation option is 'tuhple', so I wasn't sure. Maybe it's both, but 
> which is most prevalent?
> 
No suffix involved, tuples have a respectable mathematical history going 
back centuries.

> Thanks! Now time to go back to reading the chapter on tuples...

"Tyoople", "toople" or "tupple" depending on who you are, where you grew 
up and who you are speaking to. As with so many Usenet questions, 
there's no right answer, only 314 wrong ones :-)

I teach on both sides of the Atlantic, and have learned to draw a mental 
breath before trying to pronounce the word "router". Americans find the 
British pronunciation ("rooter") hilarious, despite the fact they tell 
me I drive on "Root 66" to get to DC. The Brits are politer, and only 
snigger behind my back when I pronounce it as Americans do, to rhyme 
with "outer".

except-that-there's-no-"t"-in-American-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: ordered sets operations on lists..

2006-02-12 Thread Steve Holden
Alex Martelli wrote:
> Bengt Richter <[EMAIL PROTECTED]> wrote:
>...
> 
>>>Personally, I'd always use (depending on guesses regarding lengths of
>>>lists) [x for x in l1 if x in l2] or the setified equivalent, of course.
>>>
>>
>>Perhaps newbies should be advised that
>>
>>[x for x in l1 if x in set(l2)]
>>
>>is not a (well) setified equivalent? I could see them being tempted.
> 
> 
> You mean, newbies should be advised that Python does NOT hoist any
> computations whatsoever from the body of a loop (including LCs and
> genexps), so if you want anything hoisted you need to hoist it yourself?
> Yes, it is a point worth making, since the lack of hoisting is a
> frequent cause of performance loss.
> 
Of course now 2.5 is planning to include the AST parser there's fruitful 
ground for optimization studies that will perform hoisting automatically 
(should anyone be looking for a project ;-)

Given that Python 2.4 doesn't even perform simple constant folding for 
arithmetic expressions

  >>> dis.dis(compile("print 1+2", '', 'exec'))
   1   0 LOAD_CONST   0 (1)
   3 LOAD_CONST   1 (2)
   6 BINARY_ADD
   7 PRINT_ITEM
   8 PRINT_NEWLINE
   9 LOAD_CONST   2 (None)
  12 RETURN_VALUE

even hoisting could be seen as an "advanced" optimization.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Newbie

2006-02-12 Thread Steve Holden
LittlePython wrote:
> I am very new to python. I have been studying it for only a month or so. I
> have been using vbscript for about 2-3 yrs and only recently been using it
> rather heavily the past 9 months or so. I am new very new to oop. My main
> use will be administrative scripting into the win3k, XP, AD domain,
> 55exchange and 2003exchange environments. I like to incorp wxpython (GUI)
> into my scripts instead of HTA's that I have been using with VBS. I am also
> finding myself being tasked with jobs that are outside the scope of VBS.
> Well that's a lot to learn and I have a feeling that to many I am just
> another member of  "The Ministry of STUPID Questions"
> 
Realizing that you are potentially asking dumb questions, lus the fact 
that you've been playing with Python for a month already, puts you way 
ahead of the game. Ask away, and welcome to comp.lang.python.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Jython socket typecasting problems

2006-02-12 Thread Steve Holden
Diez B. Roggisch wrote:
>>This is the code section of my server class (I cut this from a Python
>>example):
>>def establishConnection(self):
>>self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>self.socket.connect((self.host, self.port))
>>Do I have to use explicit typecasting? How can this be achieved?
> 
> 
> There is no such thing as explicit casting in python. You can coerce 
> values to values of another type - e.g. float("1.0"), and there are some 
> "magic" methods to support that (for that example __float__)
> 
> However, that doesn't seem to be your problem. You just pass the wrong 
> arguments, which makes the jython wrapping punke on you as only certain 
> types can be dealt with.
> 
> To me this looks as if you are supposed to do it like this:
> 
> self.socket.connect(self.host, self.port)
> 
> Note the missing parentheses.
> 
"""connect(address)
 Connect to a remote socket at address. (The format of address 
depends on the address family -- see above.) Note: This method has 
historically accepted a pair of parameters for AF_INET addresses instead 
of only a tuple. This was never intentional and is no longer available 
in Python 2.0 and later. """

So if Jython 2.1 is conformant it should indeed require a single 
argument which is an (IPAddress, port) tuple.

It might be that the OP can't, for some reason associate with the local 
environment, resolve "localhost" to an IP address. What happens if 
"127.0.0.1" is substituted?

Irrespective of that, it does seem that the error message is at best 
misleading and at most just plain wrong. There's aproject to bring 
Jython up to a more recent specification, but it will take time ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


how do you pronounce 'tuple'?

2006-02-12 Thread John Salerno
Yes, silly question, but it keeps me up at night.  :)

I know it comes from the suffix -tuple, which makes me think it's 
pronounced as 'toople', but I've seen (at m-w.com) that the first 
pronunciation option is 'tuhple', so I wasn't sure. Maybe it's both, but 
which is most prevalent?

Thanks! Now time to go back to reading the chapter on tuples...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
mwt <[EMAIL PROTECTED]> wrote:
   ...
> import urllib
> 
> def download_file(filename, URL):
> f = urllib.urlretrieve(URL, filename, reporthook=my_report_hook)

If you wanted to DO anything with the results, you'd probably want to
assign to
f, m = ...
not just f.  This way, f is the filename, m a message object useful for
metadata (e.g., content type).

Otherwise looks fine.


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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
So, I just put this little chunk to the test, which does give you
feedback about what's going on with a file download. Interesting that
with urlretrieve, you don't do all the file opening and closing stuff.

Works fine:

--
import urllib

def download_file(filename, URL):
f = urllib.urlretrieve(URL, filename, reporthook=my_report_hook)

def my_report_hook(block_count, block_size, total_size):
total_kb = total_size/1024
print "%d kb of %d kb downloaded" %(block_count *
(block_size/1024),total_kb )

if __name__ == "__main__":
   download_file("test_zip.zip","http://blah.com/blah.zip";)

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
mwt <[EMAIL PROTECTED]> wrote:

> Thanks for the explanation. That is exactly what I'm looking for. In a
> way, it's kind of neat that urlopen just *does* it, no questions asked,
> but I'd like to just know the basics, which is what it sounds like
> urlretrieve covers. Excellent. Now, let's see what I can whip up with
> that. 

Yes, I entirely understand your mindset, because mine is so similar: I
prefer using higher-level "just works" abstractions, BUT also want to
understand what's going on "below"... "just in case"!-)

> -- just bought "cookbook" and "nutshell" moments ago btw

Nice coincidence, and thanks!-)


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


Re: Questions for BitTorrent's Author, Bram Cohen

2006-02-12 Thread Alex Martelli
Steve Holden <[EMAIL PROTECTED]> wrote:

> Bram Cohen will be a keynoter at this year's PyCon, and has asked that
> the presentation be in the form of an interview.
> 
> I'd like the questions to be representative of as broad a cross-section
> of the Python community as possible. If you have a question you'd like
> to hear Bram answer please let me know and I'll try to include them.

OK, let me start this with a provocatory question...:

"Why Python?  For the prototype, sure.  But now that the protocol and
feature set have stabilized, surely you can get leaner and faster code
by redoing it all in C, can't you?"


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


Re: Is Forth for real?

2006-02-12 Thread Elizabeth D Rather
"Cameron Laird" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In article <[EMAIL PROTECTED]>,
> Steven D'Aprano  <[EMAIL PROTECTED]> wrote:
> .
> .
> .
>>on the web for each language. By comparison, even Forth gives 13 million
>>plus hits, and who uses Forth?
> .
> .
> .
> The programmers of, among other things, the FedEx bar-code reader,
> the Sun boot loader, and parts of the Space Shuttle.

We have several thousand customers, although we don't hear from them enough 
to know how active they are.  Most of them are doing embedded systems (such 
as the FedEx package tracker), although there are also quite a few doing 
Windows apps.

A lot of our embedded work is for aerospace and government customers, plus a 
number in the private sector.  All the DirecTV uplink antennas are 
controlled by one of our systems made by VertexRSI, 
http://www.tripointglobal.com/vertexrsi.html.  Another really neat customer 
is Sunrise Systems, http://www.sunrisesystems.com/index.htm.  They make 
moving displays, and are working on one for one of the rebuilt World Trade 
Center bldgs, one to be installed in Switzerland next month, and something 
for Disney World.

Open Firmware has already been mentioned, and I should add that IBM's 
high-end servers also use it.  I teach Forth courses there once or twice a 
year, and have trained a couple hundred engineers in IBM alone.

You can get more info on our web site www.forth.com, including a link to a 
paper presenting a history of Forth.

Cheers,
Elizabeth

-- 
==
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018  Fax: +1 310-978-9454
Hawthorne, CA 90250
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
== 

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt

>It isn't written in C, but get your hands on wget. It
>is probably already on your Linux distro, but if not,
>check it out here:

>http://www.gnu.org/software/wget/wget.html

Thanks. I'm checking it out.

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


Re: Questions for BitTorrent's Author, Bram Cohen

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 20:10 -0500, Steve Holden escreveu:
> I'd like the questions to be representative of as broad a cross-section 
> of the Python community as possible. If you have a question you'd like 
> to hear Bram answer please let me know and I'll try to include them.

Something I think lots of people want to know: why Python, and not
anything else?

> regards
>   Steve

Cheers,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: Python equivilant to msgbox()

2006-02-12 Thread André
Kent Johnson wrote:
> LittlePython wrote:
> > Is there an equivalent to a msgbox() or wscript.echo (via wcsript) . I
> > would like to call this instead of print (to the screen) . I would like
> > to write a simple script that is not an event drive gui but calls input
> > boxes, message boxes, or maybe even a file open browser box as well?
>
> Take a look at EasyGUI:
> http://www.ferg.org/easygui/
>
> Kent
It's also possible to something like that with wxPython.  Try:
import wx
app = wx.PySimpleApp()
dlg = wx.TextEntryDialog(None, 'Enter value', 'Title', '')
if dlg.ShowModal() == wx.ID_OK:
val = dlg.GetValue()  # this line should be indented
dlg.Destroy()
print "you have entered %s" % val

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


Re: Is python very slow compared to C

2006-02-12 Thread bonono

Steven D'Aprano wrote:
> > Programming in Lua
> > Object-Oriented Programming
> > http://www.lua.org/pil/16.html
>
> Did you actually bother to read the page you linked to? It describes how
> you can emulate object-like behaviour for Lua tables. The following page
> is even more explicit: "Lua does not have the concept of class".
>
> That means that the object-oriented framework, which you get for free in
> Python, has to be at least partially handled by the programmer in Lua.
> Perhaps Lua makes it easy to do, but it is still something that doesn't
> need to be done in Python because it is already there.

Lua does not have a concept of class doesn't mean it doesn't have the
concept/framework of OO. It seems to be using a prototype based OO
framework similar to javascript. So one can have features like
inheritance without "class".

I can speak the same about Python if I view it from a prototype based
perspective, where one get them for free in Lua but need to implement
them in Python.

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
Thanks for the explanation. That is exactly what I'm looking for. In a
way, it's kind of neat that urlopen just *does* it, no questions asked,
but I'd like to just know the basics, which is what it sounds like
urlretrieve covers. Excellent. Now, let's see what I can whip up with
that. 

-- just bought "cookbook" and "nutshell" moments ago btw

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Steven D'Aprano
mwt wrote:

> Pardon my ignorance here, but could you give me an example of what
> would constitute file that is unreasonably or dangerously large? I'm
> running python on a ubuntu box with about a gig of ram.

1GB of RAM plus (say) 2GB of virtual memory = 3GB in total.

Your OS and other running processes might be using 
(say) 1GB. So 2GB might be the absolute limit.

Of course your mileage will vary, and in practice your 
machine will probably start slowing down long before 
that limit.


> Also, do you know of any online examples of the kind of robust,
> real-world code you're describing? 

It isn't written in C, but get your hands on wget. It 
is probably already on your Linux distro, but if not, 
check it out here:

http://www.gnu.org/software/wget/wget.html



-- 
Steven.

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


Questions for BitTorrent's Author, Bram Cohen

2006-02-12 Thread Steve Holden
Hi:

Bram Cohen will be a keynoter at this year's PyCon, and has asked that 
the presentation be in the form of an interview.

I'd like the questions to be representative of as broad a cross-section 
of the Python community as possible. If you have a question you'd like 
to hear Bram answer please let me know and I'll try to include them.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Python equivilant to msgbox()

2006-02-12 Thread LittlePython
That is exactly what I was look for .. thx


"Kent Johnson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> LittlePython wrote:
> > Is there an equivalent to a msgbox() or wscript.echo (via wcsript) . I
> > would like to call this instead of print (to the screen) . I would like
> > to write a simple script that is not an event drive gui but calls input
> > boxes, message boxes, or maybe even a file open browser box as well?
>
> Take a look at EasyGUI:
> http://www.ferg.org/easygui/
>
> Kent


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


Re: Python equivilant to msgbox()

2006-02-12 Thread Andre Burgaud
Hi,
 
If you target Windows, you may try ctypes http://starship.python.net/crew/theller/ctypes/:
 
>>> from ctypes import *>>> windll.user32.MessageBoxA(None, "MessageBox Text", "MessageBox Caption", 0)1>>>
 
 
or win32api http://starship.python.net/crew/mhammond/win32/:
>>> import win32api>>> win32api.MessageBox(0, "Text", "Title")1>>>
 
Regards,
 
Andre
http://www.burgaud.com/
 
On 2/12/06, LittlePython <[EMAIL PROTECTED]> wrote:

Is there an equivalent to a msgbox() or wscript.echo (via wcsript) . I would like to call this instead of print (to the screen) . I would like to write a simple script that is not an event drive gui but calls input boxes, message boxes, or maybe even a file open browser box as well? 
--http://mail.python.org/mailman/listinfo/python-list

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

Re: Python equivilant to msgbox()

2006-02-12 Thread Kent Johnson
LittlePython wrote:
> Is there an equivalent to a msgbox() or wscript.echo (via wcsript) . I 
> would like to call this instead of print (to the screen) . I would like 
> to write a simple script that is not an event drive gui but calls input 
> boxes, message boxes, or maybe even a file open browser box as well?

Take a look at EasyGUI:
http://www.ferg.org/easygui/

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


Python equivilant to msgbox()

2006-02-12 Thread LittlePython



Is there an equivalent to a msgbox() or 
wscript.echo (via wcsript) . I would like to call this instead of print (to the 
screen) . I would like to write a simple script that is not an event drive gui 
but calls input boxes, message boxes, or maybe even a file open browser box as 
well? 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Yet another GUI toolkit question...

2006-02-12 Thread John J. Lee
Kevin Walzer <[EMAIL PROTECTED]> writes:
[...]
> Commercial Qt is a little out of my price range.

Commercial *PyQt* (including a license for Qt for use only with PyQt)
is $400 (USD) per developer (plus an extra $300/year if you want
upgrades).  That's compared to Qt license for use *with C++* varying
from $1690 to $6260.  So PyQt is 4-15 times cheaper than old-fashioned
C++ Qt!

http://www.thekompany.com/products/blackadder/


Apparently you get mxODBC in that price, too.  And the Blackadder
development environment itself, of course, though personally I
wouldn't use it.

PyQt 4 now seems to exist, though not as a stable release yet, so I
imagine it'll be a bit longer untill there's a release of Blackadder
that supports Qt 4.  I recall the PyQt 2 --> PyQt 3 upgrade as being
fairly painless (in terms of code changes), though.


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


Re: by reference

2006-02-12 Thread dirvine
Yes I did

I was trying to do something like (pseudo code)

write:
get files in path
for each filename get size, type
create dic called filename assign size:xx,type:y
pickle to file

read:
open pickled file
read dict name and contents (hoping unpickling file gives me the dict
name as it was saved, which may not be true)
do stuff with file


and thats it. My prog is a bit more complex than this but this is the
general idea basically read files -> create dicts of files one at a
time, very similar to bittorrent in that take a file smash to bits and
store links to bits in a big file.

Many thanls
David

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


Re: Tracking down memory leaks?

2006-02-12 Thread John J. Lee
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sun, 12 Feb 2006 05:11:02 -0800, MKoool wrote:
[...]
> I may be mistaken, and if so I will welcome the correction, but Python
> does not return memory to the operating system until it terminates.
> 
> Objects return memory to Python when they are garbage collected, but not
> the OS.
[...]

http://groups.google.com/group/comp.lang.python/browse_frm/thread/ce5c44915f43d6d/2bea1c569a65e13e


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


Re: Tracking down memory leaks?

2006-02-12 Thread MKoool
> How big is the file you are reading in? If it is (say) 400 MB, then it is
> hardly surprising that you will be using 500MB of RAM. If the file is 25K,
> that's another story.

Actually, I am downloading the matrix data from a file on a server on
the net using urllib2, and then I am running several basic stats on it
using some functions that i get from matplotlib.  Most are statistical
functions I run on standard vectors, such as standard deviation, mean,
median, etc.  I do then loop through various matrix items, and then
based on a set of criteria, I attempt to perform a sort of linear
regression model using a few loops on the vectors.

> How are you storing your data while you are processing it? I'd be looking
> for hidden duplicates.

I am storing basically everything as a set of vectors.  For example, I
would have one vector for my X-axis, time.  The other variables are the
number of units sold and the total aggregate revenue from selling all
units.

I am wondering if it's actually urllib2 that is messing me up.  It
could be matplotlib as well, although I doubt it since I do not use
matplotlib unless the statistical significance test I produce indicates
a high level of strength (very rare), indicating to me that the company
has a "winning" product.

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


Re: Need a bit of help with a list..

2006-02-12 Thread Alex Martelli
rh0dium <[EMAIL PROTECTED]> wrote:
   ...
> Why doesn't this work as expected..  I expect that the the lines within
> the sections will get modified - permanently.  It is modifying them
> during the first section but they never get saved to the new values..
> Can anyone help me and even better explain why it's not working..
> 
> for section in self.sections:
> nidx = 0
> for line in self.sections[section]:

>From this constuct I assume self.sections is a dict, in which case there
may be better way to loop over the values in the dict; but that's an
aside and does not affect your stated problem.  Rather, said problem is
already shown in the next couple lines:

> if re.match(r"^.*\+$",line):
> line = line[:-1]

A simple assignment _to a bare name_ (here, 'line') only ever affects
that NAME itself - nothing else, and in particular not the object to
which the name used to be bound before you re-bound it, not other names
(or locations within a container) bound to the same object, and so on.

To affect some item, say the i-th one, of self.sections[section], you
will need to assign something to self.sections[section][i].  You may
give another and nicer name to the whole objects self.sections[section],
but you will still need to assign to whatevername[i] to rebind the i-th
item -- assign to an indexing, not to a bare name.

There's another problem later in this inner loop:

> del self.sections[section][nidx+1]

...don't alter the container you're directly looping on, for example by
deleting some of its items: that will alter the semantics of the loop in
way you most definitely don't want. I don't think it's biting you here,
but in most cases it will indeed bite, and painfully.

I would suggest restructuring your whole first nested loop, correcting
other strangeness (which is innocuous) as we go, such as the strange re
and the separate and identical increments of nidx along an if and an
else branch.  For example, trying to stay as close as feasible to your
original code, we might have:

for lines in self.sections.itervalues():
nidx = 0
while nidxhttp://mail.python.org/mailman/listinfo/python-list


Need a bit of help with a list..

2006-02-12 Thread rh0dium
Hi all,


Why doesn't this work as expected..  I expect that the the lines within
the sections will get modified - permanently.  It is modifying them
during the first section but they never get saved to the new values..
Can anyone help me and even better explain why it's not working..

for section in self.sections:
nidx = 0
for line in self.sections[section]:
if re.match(r"^.*\+$",line):
line = line[:-1]
line = line + " " + self.sections[section][nidx+1]
print nidx, "+ found -total lines",
len(self.sections[section]), line
del self.sections[section][nidx+1]
nidx += 1
else:
nidx += 1

for secs in self.sections:
print " %s" % secs
for line in self.sections[secs]:
 print "  %s" % line

self.section[foo]=["Param_Set primitive:rdv_AIO_reg50_top_IPTOP
id:chip_top_pads!reg50ma +",
"VDD18:VDD1_CR18 VDD33:VDD1_CR33 VSSA:VSSCORE", "Param_Set
instance:chip_top_pads!PAD_3APAD:PIN_VTRIP_IN + ", " RC:RC_5A
VDDCR:VDD1_CR18 VDDIO:VDD1_IO33 VSSCR:VSSCORE +"," VDDIO5:VDD1_IO5A
VDDIO5DIV2:VDD1_IO5DIV2A VSSIO:VSS_IO"]

Many thanks!!

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


Re: Clearing the screen

2006-02-12 Thread Fredrik Lundh
"mwt" wrote:

> Arrgghh... Is there any way to edit posts on this thing?

are you aware that you're posting to a usenet newsgroup?

> The os.system("clear") doesn't work at all in a module.

works for me (as long as I'm running the code on a platform that
has a clear command).  in what way does it fail for you?





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


Re: How to invoke a tkinter menu *itself*

2006-02-12 Thread James Stroud
Edward K. Ream wrote:
> Hi,
> 
> 
> 
> I've spent a pleasant hour or so trying to bring up a top-level Tk menu at 
> the same spot as it would appear if I had actually clicked the menu.  That 
> is, I want to bring up a menu from the keyboard.
> 
> 
> 
> The problem is computing the x and y args to menu.post.  menu.winfo_x and 
> menu.winfo_rootx are always 0, presumably be cause the menu isn't packed.
> 
> 
> 
> And I haven't been able to use menu.invoke(??) to invoke the menu *itself*. 
> One would think this would be a basic Tk functionality.
> 
> 
> 
> Any ideas?  Thanks.
> 
> 
> 
> Edward
> 
> 
> 
> P.S. Here is my best so far. (It must be run from Leo for the Leo magic to 
> work.)
> 
> 
> 
> import tkFont
> 
> name = 'File' # The menu to be invoked.
> 
> # A list of all of Leo's menus.
> 
> menus = ('File','Edit','Outline','Plugins','Cmds','Window','Help')
> 
> 
> 
> # Compute the *approximate* x offsets of each menu.
> 
> offsets = {} ; n = 0
> 
> for z in menus:
> 
> menu = c.frame.menu.getMenu(z)
> 
> fontName = menu.cget('font')
> 
> font = tkFont.Font(font=fontName)
> 
> offsets[z] = n
> 
> # A total hack: sorta works on windows.
> 
> n += font.measure(z+' '*4)+1
> 
> 
> 
> top = c.frame.top # Leo magic.
> 
> topx,topy = top.winfo_rootx(),top.winfo_rooty()
> 
> menu = c.frame.menu.getMenu(name) # Leo magic.
> 
> menu.post(topx+offsets.get(name,0),topy)
> 
> 
> 
> EKR
> 
> Edward K. Ream   email:  [EMAIL PROTECTED]
> Leo: http://webpages.charter.net/edreamleo/front.html
> 
> 
> 
> 

Its not obvious what you want to do. If you are going to have a menu at 
all, I think you application would be better served to always have the 
toplevel menu displayed, otherwise, things can get jumpy if the window 
is always repacking. If you want the main menu to be "contextual" you 
can make two different menuas andplay with toplevel.config(menu=onemenu) 
and toplevel.config(menu=anothermenu), etc. If you just want to forget 
the menu, you can toplevel.config(menu=""), you can bring it back again 
with toplevel.config(menu=somemenu), etc. This will be jumpy. If you 
want a menu that pops up on top of a window, you might have to make 
another window with your menu of choice. Or do you want to just bring 
down a cascade menu?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another n00b: Removing the space in "print 'text', var"

2006-02-12 Thread Felipe Almeida Lessa
Em Dom, 2006-02-12 às 22:11 +, HappyHippy escreveu:
> More of a minor niggle than anything but how would I remove the 
> aforementioned space?
> 
> eg.
> strName = 'World'
> print 'Hello', strName, ', how are you today?'
> 
> comes out as "Hello World , how are you today?"

strname = 'World'
print 'Hello %s, how are you today?' % strname

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: Another n00b: Removing the space in "print 'text', var"

2006-02-12 Thread Alex Martelli
HappyHippy <[EMAIL PROTECTED]> wrote:

> More of a minor niggle than anything but how would I remove the 
> aforementioned space?
> 
> eg.
> strName = 'World'
> print 'Hello', strName, ', how are you today?'
> 
> comes out as "Hello World , how are you today?"
> 
> Have googled, and worked my way through the first 7 chapters of Byte of
> Python, but to no avail...

Use string formatting:

print 'Hello %s, how are you today?' % strName


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


Re: Another n00b: Removing the space in "print 'text', var"

2006-02-12 Thread Fredrik Lundh
"HappyHippy" wrote:

> More of a minor niggle than anything but how would I remove the
> aforementioned space?
>
> eg.
> strName = 'World'
> print 'Hello', strName, ', how are you today?'
>
> comes out as "Hello World , how are you today?"
>
> Have googled, and worked my way through the first 7 chapters of Byte of
> Python, but to no avail...

you can concatenate the strings before passing them to print:

text = 'Hello' + strName + ', how are you today?'
print text

or do the same on one line

print 'Hello' + strName + ', how are you today?'

or use string formatting (the % operator), or write to the special sys.stdout
file object (output to files is discussed in chapter 12).





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


Re: Determining an operating system's default browser

2006-02-12 Thread Paul Boddie
Jorgen Grahn wrote:
> On 11 Feb 2006 11:44:29 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
> >
> > Indeed. Thanks for reminding me about mailcap/metamail - I used them in
>
> And thanks for mentioning the real name of that mechanism!

Happy memories! ;-)

[...]

> > import mailcap
>
> I guess I shouldn't be surprised that there is a standard module
> for that ... ;-)

It's another stop on the standard library mystery tour!

[...]

> > Sadly, when considering my KDE desktop's default browser, inquiring the
> > application for HTML files yields Mozilla Firefox from my mailcap file.
>
> Yes, but that's only because you haven't configured your mailcap, right?
> Which might be a real problem -- most people don't touch their .mailcaps,
> especially those who use KDE or Gnome.

Going by the following discussion, they abandoned interoperability with
mailcap and went with their own cocktail of new inventions:

https://listman.redhat.com/archives/xdg-list/2003-April/msg9.html

The above message is where the mailcap-related arguing begins. It boils
over here:

https://listman.redhat.com/archives/xdg-list/2003-April/msg00031.html

> Also, sometimes you want a GUI browser to open, and sometimes you want a
> console-based one like lynx or w3m.  I guess most people who use mailcap do
> so because they use console-based mail readers, and thus want the HTML stuff
> appear inside the same terminal.  Another reason this might be unsuitable
> for the OP.
>
> So, while I called it "The One Correct Way" above, I admit it might not be a
> very good way ;-)

If there's one "correct" way, it would seem that the xdg people are
always interested in making at least one other "correct" way.
Nevertheless, in defence of the desktop module, its purpose is merely
to "open" things in the context of the current desktop: correct or
standards compliant file type identification doesn't necessarily enter
the picture. ;-)

Still, in the supported environments, desktop.open should do what the
user would expect, given the preference those environments typically
have for their "new and improved" way of doing things involving
configuration dialogues that the user might well have seen (and
probably closed very quickly in horror). Sadly, it doesn't seem to
involve mailcap files, however.

Paul

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


Another n00b: Removing the space in "print 'text', var"

2006-02-12 Thread HappyHippy
More of a minor niggle than anything but how would I remove the 
aforementioned space?

eg.
strName = 'World'
print 'Hello', strName, ', how are you today?'

comes out as "Hello World , how are you today?"

Have googled, and worked my way through the first 7 chapters of Byte of 
Python, but to no avail...

TIA

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


Re: PEP 353: Using ssize_t as the index type

2006-02-12 Thread Martin v. Löwis
Tony Nelson wrote:
> Minor typo:  "too"

Thanks, fixed.

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


Re: Netstat in python. Does it's possible?

2006-02-12 Thread Martin v. Löwis
Jorgen Grahn wrote:
> I was thinking mostly about /proc, /sys and related file systems. I have a
> feeling parts of them they change quite frequently under Linux, and of
> course under other Unices they may look completely different, or be absent.
> 
> Like Mr Laird said elsewhere, the best thing might be to popen() netstat
> and parse its output.

Hmm. And the netstat output cannot change, and is identical across all
systems?

I agree that the format of the proc file system is different across
systems (or other systems don't use netstat at all), however, on all
systems I'm aware of, there is a certain committment to keeping the
proc file system stable for applications (on Solaris more so than
on Linux).

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


Re: Single-file executables

2006-02-12 Thread Martin v. Löwis
Thomas Heller wrote:
> I wonder if anyone is actually using freeze on Windows, with scripts 
> that use, say, pywin32 and wxPython.

Interesting question. I've never done so myself (only on Linux and
Solaris), and given the relatively small interest in having a static
Python library on Windows, I guess the answer is no (or: everybody
doing that has managed to deal with the build process themselves).

I would probably go for a mingw static build if I had to attempt this.

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Alex Martelli
mwt <[EMAIL PROTECTED]> wrote:
   ...
> The process is pretty opaque, however. This downloads and writes the
> file with no feedback whatsoever. You don't see how many bytes you've
> downloaded already, etc. Especially the "g = f.read()" step just sits
> there while downloading a large file, presenting a pregnant, blinking
> cursor.
> 
> So my question is, what is a good way to go about coding this kind of
> basic feedback? Also, since my testing has only *worked* with this

You may use urlretrieve instead of urlopen: urlretrieve accepts an
optional argument named reporthook, and calls it once in a while ("zero
or more times"...;-) with three arguments block_count (number of blocks
downloaded so far), block_size (size of each block in bytes), file_size
(total size of the file in bytes if known, otherwise -1).  The
reporthook function (or other callable) may display a progress bar or
whatever you like best.

urlretrieve saves what's downloading to a disk file (you may specify a
filename, or let it pick an appropriate temporary filename) and returns
two things, the filename where it's downloaded the data and a
mimetools.Message instance whose headers have metadata (such as content
type information).

If that doesn't fit your needs well, you may study the sources of
urllib.py in your Python's library source directory, to see exactly what
it's doing and code your own modified version.


Alex

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


Re: python and webcam

2006-02-12 Thread dfaber
Hi again,
 I've tried a the Sane interface from PIL and I get the following
error, when I run the demo_pil.py from the Sane directory.

SANE version: (16777231, 1, 0, 15)
Available devices= [('v4l:/dev/video0', 'Noname', 'Logitech QuickCam
Pro 3000', 'virtual device')]
Traceback (most recent call last):
  File "/PyWebcam/demo_pil.py", line 17, in ?
s.br_x=320. ; s.br_y=240.
  File "/usr/lib/python2.4/site-packages/sane.py", line 150, in
__setattr__
raise AttributeError, 'Inactive option: '+key
AttributeError: Inactive option: br_x


Next, I looked at v4l support for python with absolutely no
documentation. I tried to build the modules and I get the following
error:

 python setup.py build
running build
running build_ext
building 'v4l' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -mtune=pentium4
-fasynchronous-unwind-tables -D_GN U_SOURCE -fPIC -fPIC
-I/usr/include/python2.4 -c v4l.c -o build/temp.linux-i686- 2.4/v4l.o
v4l.c: In function 'v4l_getImage':
v4l.c:890: warning: pointer targets in assignment differ in signedness
v4l.c: In function 'initv4l':
v4l.c:1585: error: 'VIDEO_AUDIO_BALANCE' undeclared (first use in
this function)
v4l.c:1585: error: (Each undeclared identifier is reported only once
v4l.c:1585: error: for each function it appears in.)
error: command 'gcc' failed with exit status 1


I also looked at libfg http://antonym.org/libfg and I get the following
errors again:
---
python setup.py build
running build
running build_ext
building 'fg' extension
gcc -pthread -shared build/temp.linux-i686-2.4/fgmodule.o -L. -lfg -o
build/lib.linux-i686-2.4/fg.so
/usr/bin/ld: cannot find -lfg
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

I google-ed extensively have so far found only these three packages.
Any ideas why I get these error messages?

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
Pardon my ignorance here, but could you give me an example of what
would constitute file that is unreasonably or dangerously large? I'm
running python on a ubuntu box with about a gig of ram.

Also, do you know of any online examples of the kind of robust,
real-world code you're describing? 

Thanks.

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


Re: Is Forth for real?

2006-02-12 Thread Daniel Ciesinger
Steven D'Aprano schrieb:
> On Sun, 12 Feb 2006 17:08:02 +, Cameron Laird wrote:
> 
> 
>>In article <[EMAIL PROTECTED]>,
>>Steven D'Aprano  <[EMAIL PROTECTED]> wrote:
>>
>>>on the web for each language. By comparison, even Forth gives 13 million
>>>plus hits, and who uses Forth?

13m hits for forth as in "set forth", "firth of forth" etc.
.
>>The programmers of, among other things, the FedEx bar-code reader,
>>the Sun boot loader, and parts of the Space Shuttle.
> 
> You missed Apple's boot loader.

And LOTs of small tools, scripts, analyzers written in Forth, because it 
has such a nice "evaluate", beating e.g. JavaScript "evaluate" by a 
speed advantage around 1000 or more...
You can feed that with a datastream such as

123.50 MONITOR Rx 03 DC 0A 0D
124.00 COMMS   Tx 01 A5

...and convert such stuff into XML, SVG or any representation you like.
Very useful (and fast) e.g. for automotive applications.

> I love Forth. I'm no good at thinking at that low count-the-bytes level,
> but if I was, I'd much prefer to use Forth than C or assembly. I've got a
> bunch of Forth books here, and when I'm bored I read them for
> entertainment, and dream. I love the fact that Forth is still in use. But
> I'm under no illusions that there are millions of Forth developers getting
> paid to write in Forth.

Maybe a few hundred - and then some thousands who write their utils in 
Forth during their paid time...

Daniel

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


Re: Determining an operating system's default browser

2006-02-12 Thread Jorgen Grahn
On 11 Feb 2006 11:44:29 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
> Jorgen Grahn wrote:
...
>> On my machines, there is One Correct Way of doing these things, and that's
>> to look in the MIME support/configuration files (~/.mailcap, and so on),
>> first for the user, then system-wide. Something there might tell you what
>> program should handle text/html content.
>
> Indeed. Thanks for reminding me about mailcap/metamail - I used them in

And thanks for mentioning the real name of that mechanism!

...
> import mailcap

I guess I shouldn't be surprised that there is a standard module
for that ... ;-)

...
> Sadly, when considering my KDE desktop's default browser, inquiring the
> application for HTML files yields Mozilla Firefox from my mailcap file.

Yes, but that's only because you haven't configured your mailcap, right?
Which might be a real problem -- most people don't touch their .mailcaps,
especially those who use KDE or Gnome.

Also, sometimes you want a GUI browser to open, and sometimes you want a
console-based one like lynx or w3m.  I guess most people who use mailcap do
so because they use console-based mail readers, and thus want the HTML stuff
appear inside the same terminal.  Another reason this might be unsuitable
for the OP.

So, while I called it "The One Correct Way" above, I admit it might not be a
very good way ;-)

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and webcam

2006-02-12 Thread Terry Reedy

"dfaber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
> I have Logitech webcam and I need to grab images on Fedora Core 4 (not
> my favorite distro). Are there any python modules available for doing
> this? Any hints or suggestions would be welcome.

If is one of their ball cameras (or other shape)b with a USB connection, 
then I would expect that you access it through the TWAIN protocol.  (I 
don't know how to do that from python, but wish I did!).  If it is a truly 
web-ready camera with a built-in server and ethernet connection, then you 
access it via an http request to its inet address.



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


Re: Single-file executables

2006-02-12 Thread Thomas Heller
Martin v. Löwis wrote:
> Kevin Walzer wrote:
>> The apps I've seen created by py2exe aren't single-file at all, the
>>  install folder is full of files besides the main program. I'm 
>> looking for a solution that stuffs all libraries, scripts, and the
>>  Python runtime into one file.

Usually the bundle=1 option in py2exe can create a single file exe, but it also
allows to have a separate shared library.zip file, which is useful if you need 
more than
one exe-file.  With python 2.4, MSVCR71.dll is still required and not bundled.  
There are 
technical reasons ('booting' the exe) and maybe legal reasons for that.


> For full control, and truly single-binary executables, I recommend to
> use freeze itself. It takes a bit more work, but also gives better 
> results.


I wonder if anyone is actually using freeze on Windows, with scripts that use,
say, pywin32 and wxPython.

I've said it before, and say it again: Creating real single-file exes or dlls
was a non-goal for py2exe.  The goal was to be able to create in-process COM
servers which provide a python interpreter that is totally isolated from 
possible
other interpreters running in the same process.

py2exe simulates a statically linked python interpreter together with statically
linked extension modules.  So, it is very similar to what freeze creates.

Thomas

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


Re: Small newbie question

2006-02-12 Thread Astan Chee


Byte wrote:

>How would I do this: Write a program that simply outputs a ramdom (in
>this case) name of (for this example) a Linux distibution. Heres the
>code ive tryed:
>
>from random import uniform
>from time import sleep
>
>x = 2
>while x < 5:
>x = uniform(1, 5)
>if x >= 1 <= 1.999: print 'SuSE'
>elif x >= 2 <= 2.999: print 'Ubuntu'
>elif x >= 3 <= 3.999: print 'Mandriva'
>elif x >= 4 <= 4.999: print 'Fedora'
>sleep(2)
>  
>
But replace your if statement with this (which is similar), does work:
if 1 <= x <= 1.999: print 'SuSE'
elif 2 <= x <= 2.999: print 'Ubuntu'
elif 3 <= x <= 3.999: print 'Mandriva'
elif 4 <= x <= 4.999: print 'Fedora'

>It dosnt work: only keep printing SuSE. Please help,
>
>Thanks in advance,
> -- /usr/bin/byte
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tracking down memory leaks?

2006-02-12 Thread Robert
MKoool wrote:

> I have an application with one function called "compute", which given a
> filename, goes through that file and performs various statistical
> analyses.  It uses arrays extensively and loops alot.  it prints the
> results of it's statistical significance tests to standard out.  Since
> the compute function returns and I think no variables of global scope
> are being used, I would think that when it does, all memory returns
> back to the operating system.
> 
> Instead, what I see is that every iteration uses several megs more.
> For example, python uses 52 megs when starting out, it goes through
> several iterations and I'm suddenly using more than 500 megs of ram.
> 
> Does anyone have any pointers on how to figure out what I'm doing
> wrong?
> 

if gc.collect() doesn't help:

maybe objects of extension libs are not freed correctly.

And Python has a real skeleton in the cupboard:

a known problem with python object/libs when classes with __del__ are 
involved ( Once suffered myself from such tremendous "unexplainable" 
memory blow up until I found this "del gc.garbage[:]" remedy:


garbage
 A list of objects which the collector found to be unreachable but 
could not be freed (uncollectable objects). By default, this list 
contains only objects with __del__() methods.3.1Objects that have 
__del__() methods and are part of a reference cycle cause the entire 
reference cycle to be uncollectable, including objects not necessarily 
in the cycle but reachable only from it. Python doesn't collect such 
cycles automatically because, in general, it isn't possible for Python 
to guess a safe order in which to run the __del__() methods. If you know 
a safe order, you can force the issue by examining the garbage list, and 
explicitly breaking cycles due to your objects within the list. Note 
that these objects are kept alive even so by virtue of being in the 
garbage list, so they should be removed from garbage too. For example, 
after breaking cycles, do del gc.garbage[:] to empty the list. It's 
generally better to avoid the issue by not creating cycles containing 
objects with __del__() methods, and garbage can be examined in that case 
to verify that no such cycles are being created.


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


Re: python and webcam

2006-02-12 Thread dfaber
Thank you for your help. I will look around for v4l modules too.

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


Re: Netstat in python. Does it's possible?

2006-02-12 Thread Jorgen Grahn
On Sun, 12 Feb 2006 01:04:14 +0100, Martin v. Löwis <[EMAIL PROTECTED]> wrote:
> Jorgen Grahn wrote:
>> There might still be a problem for people doing things like this: netstat
>> might use unstable or non-public APIs to find the things it lists. This is
>> fine because it's typically your OS vendor who have to handle that (ship
>> another netstat when the /proc or /sys file system layout changes, etc).
>
> Right. However, on Unix, there aren't really that much "non-public"
> APIs. If you can figure out what the system call number is, and you
> have /usr/include/sys, you can typically come up with a way to call
> this API.

I was thinking mostly about /proc, /sys and related file systems. I have a
feeling parts of them they change quite frequently under Linux, and of
course under other Unices they may look completely different, or be absent.

Like Mr Laird said elsewhere, the best thing might be to popen() netstat
and parse its output.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super(...).__init__() vs Base.__init__(self)

2006-02-12 Thread Jan Niklas Fingerle
Steven Bethard <[EMAIL PROTECTED]> wrote:
> Jan Niklas Fingerle wrote:
> > Steven Bethard <[EMAIL PROTECTED]> wrote:
> >> Personally, I'd call the lack of the super calls in threading.Thread and 
> >> Base bugs.  
> > 
> > It can't be a bug since it wasn't a bug before super was introduced and
> > you don't wan't to break working Python-2.x-code. 
> 
> Just because there wasn't a bugfix available at the time doesn't mean it 
> wasn't a bug. ;) 

Yes, but it isn't a bug. 

> The threading.Thread class does not properly call 
> sibling constructors in multiple inheritance. > This should either be 
> fixed in the implementation (by introducing a call to super) 

This would break existing code as shown in http://fuhm.org/super-harmful/
(look out for "Subclasses must use super if their superclasses do").
And as much as I agree with GvR that the word "harmful" is inappropriate
(http://mail.python.org/pipermail/python-dev/2005-January/050656.html),
I agree with both, that super is a part of your class's interface that
you might use or not. You just have to document it, whether you use
super, or not. Or to quote GvR: "Super is intended for use that are 
designed with method cooperation in mind [...]". That's isn't "always".

The best pratices (see any of the two URLs above) obviously show, that
using super comes at some cost. This is OK, if you really have to
support cooperative method calling. But I wouldn't want to pay it "just
in case".

> or fixed in 
> the documentation 

This is true, but this or the other way round: You have to document,
that you're using super(), or that you don't do it. 

> (by indicating that threading.Thread does not support 
> multiple inheritance in its __init__() method).

It *does* support multiple inheritance, it just doesn't support diamond
shape inheritance (not counting object). 

> I've used diamond inheritance exactly once, and all the classes under 
> that hierarchy were under my control, so they all used super properly. 

And this is, what super() is meant for. I, for my part, won't use 
super() until I really need it, but when the time comes I will 
worship an extra hour at my Guido-van-Rossum-shrine. ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and webcam

2006-02-12 Thread Fredrik Lundh
"dfaber" <[EMAIL PROTECTED]> wrote:

> It is a  Win32 Python Extension. I am looking for something that work
> on Linux.

here's one:

http://antonym.org/libfg

(for more alternatives, google for "python webcam linux" or some
variation thereof)





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


Re: python and webcam

2006-02-12 Thread dfaber
It is a  Win32 Python Extension. I am looking for something that work
on Linux.

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


[ANN] svnmock 0.3 released

2006-02-12 Thread Collin Winter
Hello all,

Version 0.3 of `svnmock`, a package for testing Python applications
that use Subversion's Python bindings, has been released. `svnmock`
emulates the entire suite of Python bindings, allowing developers to
ensure that their application is calling the expected API functions
with the expected arguments. In addition, `svnmock` provides
facilities for simulating error conditions that would otherwise be
difficult or impossible to test against.

Last but not least, `svnmock` includes support for tracing API calls,
allowing for quick debugging without the need to mock up an entire
application.

`svnmock` is compatible with all releases of Subversion, including the
just-released 1.3.0.

Where to get it:
#

functional is available at

http://oakwinter.com/code/svnmock/

and from the Python Package Index at

http://cheeseshop.python.org/pypi/svnmock

Source tarballs are available, as are Python Eggs for Python 2.4 and 2.5.

Release Notes


The 0.3 release is primarily a refinement release. Certain parts of
the package have been made much easier to use for the vast majority of
use cases.

A full tutorial and reference manual is available at
http://oakwinter.com/code/svnmock/.

As always, feedback welcome!

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


Re: is there a better way?

2006-02-12 Thread drrngrvy

Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] a écrit :
> > Problem:
> >
> > You have a list of unknown length,
>
> This doesn't exist in Python:
>len(alist)
>
> > such as this: list > [X,X,X,O,O,O,O].  You want to extract all and only the 
> > X's.
>
> braindead solution - relying on zeros being zeros or any other False value:
> all_xxx
> >  You know
> > the X's are all up front and you know that the item after the last X is
> > an O, or that the list ends with an X.  There are never O's between
> > X's.
> >
>
> Then it *may* be possible to optimize - but code will break as soon as
> this rule change. So is there a real need for optimisation ? (hint: dont
> guess, profile)
>
>
> FWIW, I've collected all suggestions here (and perhaps some others) and
> hacked a Q&D benchmark. Usage is:
>
> python test_lists.py [repeat [list_size [xcount]]
>
> where:
> * repeat is the number of iteration, default to 1000
> * list_size is the size of the list, default to 100
> * xcount is the number or non-zero values in the list, default is random
>
> I've run it a few times, and it seems that in most cases,
>   *  the bisect-like approach (Alex Martelli / Karl Friedrich Bolz) is
> the winner
>   * the while/pop approach of the OP (slightly rewritten...) is really wrong
>
> FWIW, one of the dummiest possible approach IMHO
> (ie filter(None, alist)) behaves quite correctly wrt some other
> 'optimized' approachs - and is still safe if the rules about the
> composition of the list changes... Could it be that no optimization is
> sometime the best optimisation ?-)
>
>
> # test_lists.py
> from itertools import takewhile
> from timeit import Timer
> from random import randint
>
> def get_list(size, xcount=None):
>  if xcount is None:
>  xcount  else:
>  assert xcount < zcount  return [1] * xcount + [0] * zcount
>
> def with_while(alist):
>  res  while alist and alist[0]:
>  res.append(alist.pop(0))
>  return res
>
> def with_for(alist):
>  res  for x in alist:
>  if not x: break
>  res.append(x)
>  return res
>
> def with_filter(alist):
>  return filter(None, alist)
>
> def with_comprehension(alist):
>  return [x for x in alist if x]
>
> def with_takewhile(alist):
>  return list(takewhile(lambda x: x!=0, alist))
>
> def with_slice_try(alist):
>  try:
>  return alist[:alist.index(0)]
>  except ValueError:
>  return alist[:]
>
> def with_slice_safe(alist):
>  alist.append(0)
>  return alist[:alist.index(0)]
>
> def with_delslice_safe(alist):
>  alist.append(0)
>  del alist[alist.index(0):]
>  return alist
>
> def with_sect(alist):
>  low  high  while low < high:
>  mid  if alist[mid] = 0:
>  high  else:
>  low  return alist[:low]
>
> _candidates if n.startswith('with_') and callable(o)]
>
> def run_test(repeat00, list_size='100', xcount='None'):
>  global _candidate
>
>  print """
> params :
>   * repeat : %s
>   * list_size : %s
>   * xcounts : %s
> """  % (repeat, list_size, xcount)
>  results  for n in _candidates:
>  stm, stp  'from __main__ import %s, get_list' % 
> n)
>  results[n]
>  sorted_resultsfor n, time in 
> results.items()])
>  for _, result in sorted_results:
>  print "%s : %s" % result
>
>
> def main(args):
>  try:
>  repeat  except:
>  repeat  try:
>  list_size  except:
>  list_size  try:
>  xcount  except:
>  xcount
>  run_test(repeat, list_size, xcount)
>
> if __name__ = '__main__':
>  import sys
>  main(sys.argv[1:])
> 
> 
> HTH

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


Re: super(...).__init__() vs Base.__init__(self)

2006-02-12 Thread Jan Niklas Fingerle
Tony Nelson <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
>  Jan Niklas Fingerle <[EMAIL PROTECTED]> wrote:
> 
> > ...Super is a good tool to use, when dealing with
> > diamond shape inheritance. In any other case I would use the direct
> > calls to the base classes. In fact, i've yet to find a non-textbook-case
> > where I really need diamond shape inheritance. ...
> 
> As long as you don't use multiple inheritance with new-style classes, 
> you'll be fine.

OK, I should have written: "... diamond shape inheritance where the base
class's methods have to be called cooperatively ..."

In other words: In almost every real world example of diamond shape
inheritance where the base class is "only" object we don't have a
problem, because you don't have to call object's __init__, yet it causes
no harm if you call it twice - and __init__ is the *the* method you most
commonly would use "super()" for.

So, yes, "no multiple inheritance" is sufficient, but not nessecary to
live happily without ever using "super()".

Nothing against super where it's appropiate. But don't optimize for
("real") diamond shape inheritance, before you really need it...

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


Re: python and webcam

2006-02-12 Thread Philippe Bouige
In article <[EMAIL PROTECTED]>, 
 dfaber wrote:

> I have Logitech webcam and I need to grab images on Fedora Core 4 (not
>my favorite distro). Are there any python modules available for doing
>this? Any hints or suggestions would be welcome. 

You can try this :
 
http://videocapture.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mental Abuse

2006-02-12 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
> My abuser has been using the medical device to harass me the last 4-5
> years. I have no idea what type of a device is being used on me. I
> believe the device is only available to licensed pharmacist(s). I am
> not very familiar with the intend usage of the device.

Can you say paranoid-schizophrenic?   I knew you could...

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


Re: Small newbie question

2006-02-12 Thread Paul Rubin
> while x < 5:
> x = uniform(1, 5)
> if x >= 1 <= 1.999: print 'SuSE'
> ...
> It dosnt work: only keep printing SuSE. Please help,

Try this:

 x = 27.6
 if x >= 1 <= 1.999: print 'SuSE'

It prints 'SuSE' because the test is written incorrectly.  You want:

if 1 <= x <= 1.999: print 'SuSE'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small newbie question

2006-02-12 Thread Byte
Great stuff, thanks:

 -- /usr/bin/byte

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


Re: Small newbie question

2006-02-12 Thread Tim Parkin
Byte wrote:
> How would I do this: Write a program that simply outputs a ramdom (in
> this case) name of (for this example) a Linux distibution. Heres the
> code ive tryed:
> 
> from random import uniform
> from time import sleep
> 
> x = 2
> while x < 5:
> x = uniform(1, 5)
> if x >= 1 <= 1.999: print 'SuSE'
> elif x >= 2 <= 2.999: print 'Ubuntu'
> elif x >= 3 <= 3.999: print 'Mandriva'
> elif x >= 4 <= 4.999: print 'Fedora'
> sleep(2)
> 
> It dosnt work: only keep printing SuSE. Please help,
> 
> Thanks in advance,
>  -- /usr/bin/byte
> 


import random
dist = ['suse','ubuntu','mandriva','fedora']
random.choice(dist)

is that ok?

Tim Parkin

[1] http://www.python.org/doc/lib/module-random.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Ruby/Python Continuations: Turning a block callback into a read()-method ?

2006-02-12 Thread Robert
After failing on a yield/iterator-continuation problem in Python (see
below) I tried the Ruby (1.8.2) language first time on that construct:
The example tries to convert a block callback interface
(Net::FTP.retrbinary) into a read()-like iterator function in order to
virtualize the existing FTP class as kind of file system.  4 bytes max
per read in this first simple test below. But it fails on the second
continuation with ThreadError after this second continuation really
executing!? Any ideas how to make this work/correct?

(The question is not about the specific FTP example as it - e.g. about a
rewrite of FTP/retrbinary or use of OS tricks, real threads with polling
etc... - but about the continuation language trick to get the execution
flow right in order to turn any callback interface into an "enslaved
callable iterator". Python can do such things in simple situations with
yield-generator functions/iter.next()... But Python obviously fails by a
hair when there is a function-context barrier for "yield". Ruby's
block-yield-mechanism seems to not at all have the power of real
generator-continuation as in Python, but in principle only to be that 
what a normal callback would be in Python. Yet "callcc" seemes to be 
promising - I thought so far :-(  )

=== Ruby callcc Pattern : execution fails with ThreadError!? ===
require 'net/ftp'
module Net

class FTPFile
   def initialize(ftp,path)
  @ftp = ftp
  @path=path
  @flag=true
  @iter=nil
   end
   def read
  if @iter
 puts "@iter.call"
 @iter.call
  else
 puts "RETR "[EMAIL PROTECTED]
 @ftp.retrbinary("RETR "[EMAIL PROTECTED],4) do |block|
print "CALLBACK ",block,"\n"
callcc{|@iter| @flag=true}
if @flag
   @flag=false
   return block
end
 end
  end
   end
end

end

ftp = Net::FTP.new("localhost",'user','pass')
ff  = Net::FTPFile.new(ftp,'data.txt')
puts ff.read()
puts ff.read()

=== Output/Error 

vs:~/test$ ruby ftpfile.rb
RETR data.txt
CALLBACK robe
robe
@iter.call
CALLBACK rt

/usr/lib/ruby/1.8/monitor.rb:259:in `mon_check_owner': current thread
not owner (ThreadError)
 from /usr/lib/ruby/1.8/monitor.rb:211:in `mon_exit'
 from /usr/lib/ruby/1.8/monitor.rb:231:in `synchronize'
 from /usr/lib/ruby/1.8/net/ftp.rb:399:in `retrbinary'
 from ftpfile.rb:17:in `read'
 from ftpfile.rb:33
vs:~/test$

===  Python Pattern : I cannot write down the idea because of a barrier ===

 I tried a pattern like:
 
 def open(self,ftppath,mode='rb'):
 class FTPFile:
 ...
 def iter_retr()
 ...
 def callback(blk):
 how-to-yield-from-here-as-iter_retr blk???
 self.ftp.retrbinary("RETR %s" % self.relpath,callback)
 def read(self, bytes=-1):
 ...
 self.buf+=self.iter.next()
 ...
 ...
 

=


Robert

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


Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Paul Rubin
"mwt" <[EMAIL PROTECTED]> writes:
> f =  urllib.urlopen("http://www.python.org/blah/blah.zip";)
> g = f.read()   # ...

> So my question is, what is a good way to go about coding this kind of
> basic feedback? Also, since my testing has only *worked* with this
> code, I'm curious if it will throw a visibile error if something goes
> wrong with the download.

One obvious type of failure is running out of memory if the file is
too large.  Python can be fairly hosed (VM thrashing etc.) by the time
that happens.  Normally you shouldn't read a potentially big file of
unknown size all in one gulp like that.  You'd instead say something
like

   while True:
  block = f.read(4096)   # read a 4k block from the file
  if len(block) == 0:
 break   # end of file
  # do something with the block

Your "do something with..." could involve updating a status display 
or something, saying how much has been read so far.
-- 
http://mail.python.org/mailman/listinfo/python-list


Downloading Large Files -- Feedback?

2006-02-12 Thread mwt
This code works fine to download files from the web and write them to
the local drive:

import urllib
f =  urllib.urlopen("http://www.python.org/blah/blah.zip";)
g = f.read()
file = open("blah.zip", "wb")
file.write(g)
file.close()

The process is pretty opaque, however. This downloads and writes the
file with no feedback whatsoever. You don't see how many bytes you've
downloaded already, etc. Especially the "g = f.read()" step just sits
there while downloading a large file, presenting a pregnant, blinking
cursor.

So my question is, what is a good way to go about coding this kind of
basic feedback? Also, since my testing has only *worked* with this
code, I'm curious if it will throw a visibile error if something goes
wrong with the download.

Thanks for any pointers. I'm busily Googling away.

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


Re: Single-file executables

2006-02-12 Thread Ravi Teja
As Peter later pointed out, that is a licencing issue rather than a
tool issue. After browsing through the PyInstaller documentation, I
came across a curious snippet.

"On Windows, this provides support for doing in-process COM servers. It
is not generalized. However, embedders can follow the same model to
build a special purpose DLL so the Python support in their app is
hidden. You will need to write your own dll, but thanks to Allan Green
for refactoring the C code and making that a managable task."

I am assuming that this means it makes it easy to expose my Python code
as a plain dll. Just what I was looking for. I don't see any more
elaboration on this. Anyone tried this?

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


Re: PEP 353: Using ssize_t as the index type

2006-02-12 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
 ...
> Discussion
> ==
> 
> Why not size_t
> --
> 
> An initial attempt to implement this feature tried to use
> size_t. It quickly turned out that this cannot work: Python
> uses negative indices in many places (to indicate counting
> from the end). Even in places where size_t would be usable,
> to many reformulations of code where necessary, e.g. in ...
  ^-
|
Minor typo:  "too"

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list

Small newbie question

2006-02-12 Thread Byte
How would I do this: Write a program that simply outputs a ramdom (in
this case) name of (for this example) a Linux distibution. Heres the
code ive tryed:

from random import uniform
from time import sleep

x = 2
while x < 5:
x = uniform(1, 5)
if x >= 1 <= 1.999: print 'SuSE'
elif x >= 2 <= 2.999: print 'Ubuntu'
elif x >= 3 <= 3.999: print 'Mandriva'
elif x >= 4 <= 4.999: print 'Fedora'
sleep(2)

It dosnt work: only keep printing SuSE. Please help,

Thanks in advance,
 -- /usr/bin/byte

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


Re: Tracking down memory leaks?

2006-02-12 Thread Rene Pijlman
malv:
>Is there any way for making Python return memory no longer needed to
>the OS? Cases may arise where you indeed need a big memory block
>temporarily without being able to split it up into smaller chunks.

That's not really necessary. On any decent OS it's just unused address
space, that doesn't consume any physical memory.

And when your process runs out of address space, you should program more
carefully :-)

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-12 Thread Alex Martelli
Bengt Richter <[EMAIL PROTECTED]> wrote:
   ...
> >Personally, I'd always use (depending on guesses regarding lengths of
> >lists) [x for x in l1 if x in l2] or the setified equivalent, of course.
> >
> Perhaps newbies should be advised that
> 
> [x for x in l1 if x in set(l2)]
> 
> is not a (well) setified equivalent? I could see them being tempted.

You mean, newbies should be advised that Python does NOT hoist any
computations whatsoever from the body of a loop (including LCs and
genexps), so if you want anything hoisted you need to hoist it yourself?
Yes, it is a point worth making, since the lack of hoisting is a
frequent cause of performance loss.


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


python and webcam

2006-02-12 Thread dfaber
Hi,
 I have Logitech webcam and I need to grab images on Fedora Core 4 (not
my favorite distro). Are there any python modules available for doing
this? Any hints or suggestions would be welcome. 

Thanks.

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


Re: ordered sets operations on lists..

2006-02-12 Thread Bengt Richter
On Sat, 11 Feb 2006 10:24:04 -0800, [EMAIL PROTECTED] (Alex Martelli) wrote:

>Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>   ...
>> The intersection step is unnecessary, so the answer can be simplified a
>> bit:
>> 
>> >>> filter(set(l2).__contains__, l1)
>> [5, 3]
>> >>> filter(set(l1).__contains__, l2)
>> [3, 5]
>
>...and if one has time to waste, "setification" being only an
>optimization, it can also be removed: filter(l2.__contains__, l1) etc
>(very slow for long lists, of course).
>
>Personally, I'd always use (depending on guesses regarding lengths of
>lists) [x for x in l1 if x in l2] or the setified equivalent, of course.
>
Perhaps newbies should be advised that

[x for x in l1 if x in set(l2)]

is not a (well) setified equivalent? I could see them being tempted.

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


Re: Is python very slow compared to C

2006-02-12 Thread malv
That's why Microsoft is bringing IronPython on board to have something
more decent available with .NET

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


Re: Tracking down memory leaks?

2006-02-12 Thread malv
Hi Steven,

Is there any way for making Python return memory no longer needed to
the OS? Cases may arise where you indeed need a big memory block
temporarily without being able to split it up into smaller chunks.
Thank you.
malv

Steven D'Aprano wrote:

> Objects return memory to Python when they are garbage collected, but not
> the OS.

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


Re: Too Many if Statements?

2006-02-12 Thread Bengt Richter
On Sat, 11 Feb 2006 15:40:49 -0500, "Terry Reedy" <[EMAIL PROTECTED]> wrote:

>
>"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
>news:[EMAIL PROTECTED]
>> Clearly it would be a good idea to remove whatever problem is causing
>> the error,
>
>The problem (see my post of the com_backpatch code) is writing a compound 
>statement (here a for loop) with a body so large as to require a jump of 
>more than 64K bytes in the compiled bytecode (ie, from the test at the top 
>of the loop to the code that follows after the loop).  Until the jump limit 
>is raised (likely a long wait ;-), the OP must factor some of the code out 
>of the loop.
>
Easy example:

 >>> def test(n):
 ... while True:
 ... try: co = compile('if x:\n'+ n*' a=1\n','','exec')
 ... except Exception,e: break
 ... n += 1
 ... print 'Stopped at n=%s due to %s: %s'%(n, e.__class__.__name__,e)
 ...

get an idea of where to start that:

 >>> import dis
 >>> n=3
 >>> dis.dis(  compile('if x:\n'+ n*' a=1\n','','exec'))
   1   0 LOAD_NAME0 (x)
   3 JUMP_IF_FALSE   22 (to 28)
   6 POP_TOP

   2   7 LOAD_CONST   0 (1)
  10 STORE_NAME   1 (a)

   3  13 LOAD_CONST   0 (1)
  16 STORE_NAME   1 (a)

   4  19 LOAD_CONST   0 (1)
  22 STORE_NAME   1 (a)
  25 JUMP_FORWARD 1 (to 29)
 >>   28 POP_TOP
 >>   29 LOAD_CONST   1 (None)
  32 RETURN_VALUE
 >>> (2**16-7)/(13-7)
 10921

back off 1

 >>> test(10920)
 Stopped at n=10922 due to SystemError: com_backpatch: offset too large

Decided to test the exact 65536 jump with code chunks of 16 byte-codes and one
chunk at the end to make 16 with the last JUMP_FORWARD.

 >>> n=4095
 >>> dis.dis(  compile('if x:\n'+ n*' a=1+2,4  \n'+' x=0,x','','exec'))
 Traceback (most recent call last):
   File "", line 1, in ?
 SystemError: com_backpatch: offset too large
 >>> n=4094
 >>> dis.dis(  compile('if x:\n'+ n*' a=1+2,4  \n'+' x=0,x','','exec'))
   1   0 LOAD_NAME0 (x)
   3 JUMP_IF_FALSE65520 (to 65526)
   6 POP_TOP

   2   7 LOAD_CONST   0 (1)
  10 LOAD_CONST   1 (2)
  13 BINARY_ADD
  14 LOAD_CONST   2 (4)
  17 BUILD_TUPLE  2
  20 STORE_NAME   1 (a)

   3  23 LOAD_CONST   0 (1)

So the corner case of 2**16 is ok. Believe it or not, I once discovered a 
compiler
error based on optimizing a 2**16-involving loop condition as if it were 0 and 
the
loop didn't execute! IIRC, I bumped into it processing an array of records with 
a stride of
exactly 2**n and it thought it could calculate a 16-bit number of strides for 
end of loop.
No good for arraysize/stridesize==2**16 ;-)

If the OP really HAD to, he could always (untested) break

if cond:
too
large
else:
two
large,also
into
if cond:
too
else:
two
if cond:
large
else:
large,also

but that reads gawdawfully. (So, I imagine, does about any code hitting the 
offset limit ;-)

If it's a matter of too many elifs, the OP could break that more readably, e.g. 
(untested)

done=True
if cond:
   bla
elif c2:
   bla 2
...
elif c456:
   bla456
else:
done=False

more, done = not done,True
if more and c457:
bla c457
elif c458:
bla458
...
elif c1012:
bla1012
else:
done = False

more, done = not done,True
... etc

But the OP should find another approach I think,
because this is still disgusting code ;-)

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


Re: Too Many if Statements?

2006-02-12 Thread slogging_away
Now that I know the root cause of the problem, I can write around it as
suggested by Steve Holden and Terry Reedy, (and others).  In fact, it
has helped me in a way as I am thinking not in terms of the easiest
solution, (read; the first one that comes to mind),  but more effcient
and cleaner ways to write a section of code to accomplish the same
objective. The key was identifying the root cause which was provided by
the error message seen only at the command line level and by
contibutors to this post.

Thanks again for everyone's suggestions and expertise.

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


Re: Is python very slow compared to C

2006-02-12 Thread Michael Tobis
> Read his post again. He didn't ask a specific question at all, and he 
> certainly didn't mention execution speed.

agreed

> He asked a vague, meaningless question about whether Python was "slow 
> compared to C".

No, that is both wrong and gratuitously harsh. He had heard vague
meaningless complaints about whether Python was "slow compared to C"
and asked us to "pinpoint the issue", i.e., to determine in what sense
the allegation might be true. That is a precise and meaningful question
and being asked in a commendable fashion.

mt

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


Re: Can I get the 8bit-string representation of any unicode string

2006-02-12 Thread wanghz
Hi,

I see.  Thank you for your help!


Regards,
hongzheng

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote
>
> > I may misunderstood it.  I will think about it carefully.
> >
> > By the way, does python has a interface, just like iconv in libc for
> > C/C++?  Or, how can I convert a string from a encoding into another
> > one?
>
> if b is an 8-bit string containing an encoded unicode string,
>
> u = b.decode(encoding)
>
> or
>
> u = unicode(b, encoding)
>
> gives you a unicode string.  to encode the unicode string back to another
> byte string, use the encode method.
> 
> b = u.encode(encoding)
> 
> 

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


  1   2   >