Combinatorics

2008-02-11 Thread Michael Robertson
Where is the python equivalent of:

http://search.cpan.org/~fxn/Algorithm-Combinatorics-0.16/Combinatorics.pm

combinations (with and without repetition)
variations (with and without repetition)
permutations
partitions
derangements
etc

I'm guessing sage has this, but shouldn't something like this be part of 
the standard library (perhaps in C)?  I'd understand if derangements and 
partitions were excluded, but the standard combinatorics (replacement 
on/off, repetition on/off) would be quite nice.  It would also be 
helpful to have a general cartesian product function which combined 
elements from an arbitrary number of lists.

It seems that questions for these algorithms occur too frequently.

Am I wishing on a star?

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


Re: idiom to ask if you are on 32 or 64 bit linux platform?

2008-02-11 Thread Matt Nordhoff
Jon wrote:
> Hello everyone,
> 
> I've got a ctypes wrapper to some code which seems to be different
> when compiled on 32 bit linux compared to 64 bit linux. For the
> windows version I can use sys.platform == 'win32' versus 'linux2' to
> decide whether to get the .dll or .so library to load. Having narrowed
> it down to linux I still need to choose between libKLT32.so and
> libKLT64.so
> 
> Can someone tell me an idiom to choose the right one?
> 
> Thanks!
> 
> Jon

What about the platform module? platform.architecture() should do it.





>>> import platform
>>> platform.architecture()
('32bit', '')

Note that it analyzes an executable (defaulting to the python
interpreter binary), rather than looking in /proc or something. You
might want to do something like that instead. I guess looking at the
python binary is more accurate on a hybrid 32-bit/64-bit system though..
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


idiom to ask if you are on 32 or 64 bit linux platform?

2008-02-11 Thread Jon
Hello everyone,

I've got a ctypes wrapper to some code which seems to be different
when compiled on 32 bit linux compared to 64 bit linux. For the
windows version I can use sys.platform == 'win32' versus 'linux2' to
decide whether to get the .dll or .so library to load. Having narrowed
it down to linux I still need to choose between libKLT32.so and
libKLT64.so

Can someone tell me an idiom to choose the right one?

Thanks!

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread cokofreedom
On Feb 12, 7:16 am, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Erik Max Francis wrote:
> > Jeff Schwab wrote:
>
> >> Erik Max Francis wrote:
> >>> Grant Edwards wrote:
>
>  On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> > Fair enough!
>
>  Dear me, what's Usenet coming to these days...
>
> >>> I know, really.  Sheesh!  Jeff, I won't stand for that!  Argue with
> >>> me!  :-)
>
> >> OK, uh...  You're a poopy-head.
>
> >> Forgive the cliché, but there's already too much road rage on the
> >> information superhighway.  I've had limited access to Usenet for the
> >> last couple of years, and coming back, I find myself shocked at how
> >> many people seem to be mean and argumentative just for the heck of
> >> it.  Was it really always this hostile?  Maybe I've gotten soft in my
> >> old age.
>
> > Note smiley.  Grant and I were joking.
>
> Yes, I understood.
>
> Ahhh, back to that familiar, awkward discomfort...

Hold it, 2, 3 and release...ahhh good times
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mmap and shared memory

2008-02-11 Thread Tim Roberts
Matias Surdi <[EMAIL PROTECTED]> wrote:

>Suppose I've a process P1, which generates itself a lot of data , for 
>example 2Mb.
>Then, I've a process P2 which must access P1 shared memory and, 
>probably, modify this data.
>To accomplish this, I've been digging around python's mmap module, but I 
>can't figure how to use it without files.

So, let it use a temporary file.  What's the harm?  An anonymous mmap
region is still mapped to the swap file.  Might as well give it a name.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a Foothold on the IDLE Debugger

2008-02-11 Thread W. Watson
How about that! Thanks. An odd way to do it, but IDLE is suitably odd with 
respect to its namesake.

BTW, what's with the close and exit options on the File menu? They both dump 
me out of IDLE. Odd. Any idea of whether I can "glue" the File-?Open to a 
particular folder?

Any other similar programs with a better user interface for beginners?

[EMAIL PROTECTED] wrote:
> On Feb 11, 11:15�pm, "W. Watson" <[EMAIL PROTECTED]> wrote:
>> I thought I try to step through some simple Python code I wrote with IDLE
>> using Debug. I'm at the early stages of learning Python. I used the shell to
>> Run, then clicked on Debug->Debugger. That brought up a window with Stack
>> and Locals checked. The buttons Go, Step, etc. are greyed out. How do I
>> proceed?
> 
> IDLE has a debugger? How about that.
> 
> After you start the debugger, go back to your program
> and Run it. Watch the Debugger window.
> 
>> --
>> � � � � � � � � � � � � � Wayne Watson (Nevada City, CA)
>>
>> � � � � � � � � � � � � Web Page: 
> 

-- 
  Wayne Watson (Nevada City, CA)

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

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Erik Max Francis wrote:
> Jeff Schwab wrote:
> 
>> Erik Max Francis wrote:
>>> Grant Edwards wrote:
>>>
 On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Fair enough!

 Dear me, what's Usenet coming to these days...
>>>
>>> I know, really.  Sheesh!  Jeff, I won't stand for that!  Argue with 
>>> me!  :-)
>>
>> OK, uh...  You're a poopy-head.
>>
>> Forgive the cliché, but there's already too much road rage on the 
>> information superhighway.  I've had limited access to Usenet for the 
>> last couple of years, and coming back, I find myself shocked at how 
>> many people seem to be mean and argumentative just for the heck of 
>> it.  Was it really always this hostile?  Maybe I've gotten soft in my 
>> old age.
> 
> Note smiley.  Grant and I were joking.

Yes, I understood.

Ahhh, back to that familiar, awkward discomfort...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a web visitor counter available in Python ...

2008-02-11 Thread W. Watson
PHP. Well, that's a new one on me. Google gave me some idea of what it's 
about, and I found some code on how to do it. It requires yet another 
"programming language", which means finding the editor, etc.

Jon "Fluffy" Saul wrote:
> On Feb 11, 2008 9:21 PM, W. Watson <[EMAIL PROTECTED]> wrote:
>> ... that is free for use without advertising that I can use on my web pages?
>> I have no idea is suitable for this. My knowledge of Python is somewhat
>> minimal at this point. Maybe Java is better choice.
>>
>> --
>>   Wayne Watson (Nevada City, CA)
>>
>> Web Page: 
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> PHP would be the best choice.
> Simple and advanced PHP hit counters can be found with a search of Google.
> "PHP hit counter", etc.
> 

-- 
  Wayne Watson (Nevada City, CA)

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


Re: Getting a Foothold on the IDLE Debugger

2008-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 11:15�pm, "W. Watson" <[EMAIL PROTECTED]> wrote:
> I thought I try to step through some simple Python code I wrote with IDLE
> using Debug. I'm at the early stages of learning Python. I used the shell to
> Run, then clicked on Debug->Debugger. That brought up a window with Stack
> and Locals checked. The buttons Go, Step, etc. are greyed out. How do I
> proceed?

IDLE has a debugger? How about that.

After you start the debugger, go back to your program
and Run it. Watch the Debugger window.

>
> --
> � � � � � � � � � � � � � Wayne Watson (Nevada City, CA)
>
> � � � � � � � � � � � � Web Page: 

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

Getting a Foothold on the IDLE Debugger

2008-02-11 Thread W. Watson
I thought I try to step through some simple Python code I wrote with IDLE 
using Debug. I'm at the early stages of learning Python. I used the shell to 
Run, then clicked on Debug->Debugger. That brought up a window with Stack 
and Locals checked. The buttons Go, Step, etc. are greyed out. How do I 
proceed?

-- 
  Wayne Watson (Nevada City, CA)

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


Possible to tack on random stuff to objects?

2008-02-11 Thread Cruxic
Is it possible to tack on arbitrary attributes to a python object?
For example:

s = 'nice 2 meet you'
s.isFriendly = True

In the above example Python complains on the second line with:

AttributeError: 'str' object has no attribute 'isFriendly'

Is there another way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a web visitor counter available in Python ...

2008-02-11 Thread Matt Nordhoff
W. Watson wrote:
> ... that is free for use without advertising that I can use on my web pages? 
> I have no idea is suitable for this. My knowledge of Python is somewhat 
> minimal at this point. Maybe Java is better choice.

You can analyze your web logs. That's more accurate than a hit counter,
though you can't use it for bragging rights.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I kill CGIHTTPServer ?

2008-02-11 Thread eching
On Feb 11, 10:24 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 11 Feb 2008 04:18:04 -0200, eching <[EMAIL PROTECTED]>
> escribi�:
>
> > I'm running CGIHTTPServer with the serve_forever method and I cannot
> > get the darn thing to stop unless I kill the command prompt its
> > running in.  I searched for similar posts here and found this:
>
> See this thread from last year; it's about XMLRPC but the idea is the 
> same.http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> --
> Gabriel Genellina

That looks about like what I need.  Thanks for the link!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is there a web visitor counter available in Python ...

2008-02-11 Thread Jon "Fluffy" Saul
On Feb 11, 2008 9:21 PM, W. Watson <[EMAIL PROTECTED]> wrote:
> ... that is free for use without advertising that I can use on my web pages?
> I have no idea is suitable for this. My knowledge of Python is somewhat
> minimal at this point. Maybe Java is better choice.
>
> --
>   Wayne Watson (Nevada City, CA)
>
> Web Page: 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
PHP would be the best choice.
Simple and advanced PHP hit counters can be found with a search of Google.
"PHP hit counter", etc.

-- 
Push the envelope. Watch it bend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Jeff Schwab wrote:

> Erik Max Francis wrote:
>> Grant Edwards wrote:
>>
>>> On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
 Fair enough!
>>>
>>> Dear me, what's Usenet coming to these days...
>>
>> I know, really.  Sheesh!  Jeff, I won't stand for that!  Argue with 
>> me!  :-)
> 
> OK, uh...  You're a poopy-head.
> 
> Forgive the cliché, but there's already too much road rage on the 
> information superhighway.  I've had limited access to Usenet for the 
> last couple of years, and coming back, I find myself shocked at how many 
> people seem to be mean and argumentative just for the heck of it.  Was 
> it really always this hostile?  Maybe I've gotten soft in my old age.

Note smiley.  Grant and I were joking.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   Because a bullet has no name / And sees no face
-- Skee-Lo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Erik Max Francis wrote:
> Grant Edwards wrote:
> 
>> On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
>>> Fair enough!
>>
>> Dear me, what's Usenet coming to these days...
> 
> I know, really.  Sheesh!  Jeff, I won't stand for that!  Argue with me!  
> :-)

OK, uh...  You're a poopy-head.

Forgive the cliché, but there's already too much road rage on the 
information superhighway.  I've had limited access to Usenet for the 
last couple of years, and coming back, I find myself shocked at how many 
people seem to be mean and argumentative just for the heck of it.  Was 
it really always this hostile?  Maybe I've gotten soft in my old age.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Grant Edwards wrote:

> On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
>> Fair enough!
> 
> Dear me, what's Usenet coming to these days...

I know, really.  Sheesh!  Jeff, I won't stand for that!  Argue with me!  :-)

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   Because a bullet has no name / And sees no face
-- Skee-Lo
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there a web visitor counter available in Python ...

2008-02-11 Thread W. Watson
... that is free for use without advertising that I can use on my web pages? 
I have no idea is suitable for this. My knowledge of Python is somewhat 
minimal at this point. Maybe Java is better choice.

-- 
  Wayne Watson (Nevada City, CA)

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


Re: OT: Star Wars and parsecs [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Grant Edwards wrote:
> On 2008-02-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
> ? ? ? A Parsec is a fixed value (which, admittedly, presumes
> the culture developed a 360degree circle broken into degrees
> => minutes => seconds... or, at least, some units compatible
> with the concept of an "arc second", like 400 grads of, say,
> 100 "minutes", each of 100 "seconds")
 It also presumes a standard diamter of that circle.
>>> Which is the Earth's orbit. ?So, long, long ago in a galaxy
>>> far, far away did they know about the Earth and decide to use
>>> it as the basis for length in the universe? ?Even before
>>> people on earth defined it? ?
>>>
>>> Or (ominous music builds here, switch to low voice) is it as
>>> some now contend? ?We are the decendents of a long, lost
>>> civilization who colonized Earth and used it as a base for
>>> their operations to the point of adopting it as their own
>>> home?
>>>
>>> ... ?You Betcha!
>>>
>>> :-)
>> How come they spoke English?
> 
> In some of the series, they sure didn't do it very well, but I
> presume they were forced to read what was written.
> 
> If you want to see a movie where the aliens -- at least for
> part of the movie -- speak an alien language (with subtitles),
> there's "Battlefield Earth".  It's amazingly awful. And not in
> a fun, campy, MST3K, way.  It's awful in more of a dull,
> aching, why-didn't-the-dentist-prescribe-better-painkillers
> sort of way.  Sure glad I didn't see that one in a theater...


http://www.theonion.com/content/node/29426
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Star Wars and parsecs [was Re: Why not a Python compiler?]

2008-02-11 Thread Grant Edwards
On 2008-02-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

 ? ? ? A Parsec is a fixed value (which, admittedly, presumes
 the culture developed a 360degree circle broken into degrees
 => minutes => seconds... or, at least, some units compatible
 with the concept of an "arc second", like 400 grads of, say,
 100 "minutes", each of 100 "seconds")
>>
>>> It also presumes a standard diamter of that circle.
>>
>> Which is the Earth's orbit. ?So, long, long ago in a galaxy
>> far, far away did they know about the Earth and decide to use
>> it as the basis for length in the universe? ?Even before
>> people on earth defined it? ?
>>
>> Or (ominous music builds here, switch to low voice) is it as
>> some now contend? ?We are the decendents of a long, lost
>> civilization who colonized Earth and used it as a base for
>> their operations to the point of adopting it as their own
>> home?
>>
>> ... ?You Betcha!
>>
>> :-)
>
> How come they spoke English?

In some of the series, they sure didn't do it very well, but I
presume they were forced to read what was written.

If you want to see a movie where the aliens -- at least for
part of the movie -- speak an alien language (with subtitles),
there's "Battlefield Earth".  It's amazingly awful. And not in
a fun, campy, MST3K, way.  It's awful in more of a dull,
aching, why-didn't-the-dentist-prescribe-better-painkillers
sort of way.  Sure glad I didn't see that one in a theater...

-- 
Grant Edwards   grante Yow!  I'm working under
  at   the direct orders of WAYNE
   visi.comNEWTON to deport consenting
   adults!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Grant Edwards
On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Erik Max Francis wrote:
>> Jeff Schwab wrote:
>> 
>>> So what's the "double mistake?"  My understanding was (1) the misuse 
>>> (ok, vernacular use) of the term "free fall," and (2) the association 
>>> of weight with free-fall velocity ("If I tie an elephant's tail to a 
>>> mouse's, and drop them both into free fall, will the mouse slow the 
>>> elephant down?")
>> 
>> I presume his point was that physicists have a specialized meaning of 
>> "free fall" and, in that context, the answer is wrong.
>> 
>> My point was, and still is, that if this question without further 
>> context is posed to a generally educated laymen, the supposedly wrong
>> answer that was given is actually _correct_.  After all, 
>> [...]

> Fair enough!

Dear me, what's Usenet coming to these days...

-- 
Grant Edwards   grante Yow!  Yow! Are we in the
  at   perfect mood?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn off ZeroDivisionError?

2008-02-11 Thread Neal Becker
Mark Dickinson wrote:

> On Feb 10, 3:10 pm, [EMAIL PROTECTED] wrote:
>> What Python run on a CPU that doesn't handle the nan correctly?
> 
> How about platforms that don't even have nans?  I don't think either
> IBM's hexadecimal floating-point format, or the VAX floating-point
> formats
> support NaNs.  Python doesn't assume IEEE 754 hardware;  though much
> of its code
> could be a lot simpler if it did :-).
> rywhere ;-).
> 
> Mark

So just use it where it's available, and emulate where it's not.

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

Re: Difficulty with "inconsistent use of tabs and spaces in indentation" in file called

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 21:57:00 -0200, ibloom <[EMAIL PROTECTED]> escribió:

> My main problem is, I don't know where to find the file:
>   File "", line 628
>
> As in I don't know what code it is refering to by  ??
> It isn't code that I wrote, its something from python or pyObjC

Mmm, didn't you get my previous post? The call is inside the py2app  
package. Quoting myself:

>> : inconsistent use of tabs and spaces in indentation
>> Traceback (most recent call last):
>>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
>> python2.4/site-packages/py2app/py2app/util.py", line 13, in
>> find_version
>> ast = compiler.parseFile(fn)
>
> Put a print statement just above that line, to see which file triggers  
> the
> error.

In case it wasn't clear, modify the file  
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/py2app/py2app/util.py,
  
around line 13, in the find_version function, adding this print statement:

 print 'about to compile', fn
 ast = compiler.parseFile(fn)

The last line printed (in case there are many) should be the offending  
filename.

Of course you don't have to keep the modified library, this is just to  
detect which file triggers the error. You should report this to the py2app  
developers as well.

-- 
Gabriel Genellina

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Erik Max Francis wrote:
> Jeff Schwab wrote:
> 
>> So what's the "double mistake?"  My understanding was (1) the misuse 
>> (ok, vernacular use) of the term "free fall," and (2) the association 
>> of weight with free-fall velocity ("If I tie an elephant's tail to a 
>> mouse's, and drop them both into free fall, will the mouse slow the 
>> elephant down?")
> 
> I presume his point was that physicists have a specialized meaning of 
> "free fall" and, in that context, the answer is wrong.
> 
> My point was, and still is, that if this question without further 
> context is posed to a generally educated laymen, the supposedly wrong 
> answer that was given is actually _correct_.  After all, surely the 
> technical physics meaning of "free fall" came _after_ a more common term 
> was in use, just as with other terms like "force" or "energy" that have 
> technical meanings in physics, but more abstract or general meanings in 
> the general parlance.  "Free fall" means something specialized to 
> physicists, but it means something more general to non-physicists.
> 
> A lot of these kind of "gotcha" questions intended to trick even 
> reasonable people into demonstrating technical ignorance have precisely 
> the same problem:  The desired technical context is not made clear and 
> so that the supposedly-wrong answer is not only unsurprising, but often 
> arguably correct.  This kind of stuff is little more than a semantic 
> terminology game, rather than revealing any deeper concepts.

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


Re: Difficulty with "inconsistent use of tabs and spaces in indentation" in file called

2008-02-11 Thread Steve Holden
ibloom wrote:
> My main problem is, I don't know where to find the file:
>   File "", line 628
> 
> As in I don't know what code it is refering to by  ??
> It isn't code that I wrote, its something from python or pyObjC
> 
You'll typically see that in code that's being executed from a 
dynamically created string in the code, which is going to make it *very* 
difficult to debug.

 >>> exec "1/0"
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 1, in 
ZeroDivisionError: integer division or modulo by zero
 >>> eval('1/0')
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 1, in 
ZeroDivisionError: integer division or modulo by zero
 >>>

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Jeff Schwab wrote:

> So what's the "double mistake?"  My understanding was (1) the misuse 
> (ok, vernacular use) of the term "free fall," and (2) the association of 
> weight with free-fall velocity ("If I tie an elephant's tail to a 
> mouse's, and drop them both into free fall, will the mouse slow the 
> elephant down?")

I presume his point was that physicists have a specialized meaning of 
"free fall" and, in that context, the answer is wrong.

My point was, and still is, that if this question without further 
context is posed to a generally educated laymen, the supposedly wrong 
answer that was given is actually _correct_.  After all, surely the 
technical physics meaning of "free fall" came _after_ a more common term 
was in use, just as with other terms like "force" or "energy" that have 
technical meanings in physics, but more abstract or general meanings in 
the general parlance.  "Free fall" means something specialized to 
physicists, but it means something more general to non-physicists.

A lot of these kind of "gotcha" questions intended to trick even 
reasonable people into demonstrating technical ignorance have precisely 
the same problem:  The desired technical context is not made clear and 
so that the supposedly-wrong answer is not only unsurprising, but often 
arguably correct.  This kind of stuff is little more than a semantic 
terminology game, rather than revealing any deeper concepts.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   Tell me the truth / I'll take it like a man
-- Chante Moore
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to broad cast ping address.......

2008-02-11 Thread Steve Holden
Gabriel Genellina wrote:
> En Mon, 11 Feb 2008 13:31:56 -0200, Manikandan R <[EMAIL PROTECTED]>  
> escribi�:
> 
>> I am working in Python scripting. I an need to find out all the  
>> device
>> connected in the network. Just I planned to broad cast the ping address  
>> and
>> use the ARP table to get the IP address of the system in the network.  
>> As, I
>> am working in Win XP i am not able to use ping -b command to broad cast.
> 
> The simplest approach is to enumerate and ping each and every address in  
> your subnet and wait for the response, but consider that some hosts may  
> have been configured to not answer (and assuming you don't have a /8  
> network...)
> There is an ICMP library in the Python cookbook  
> http://aspn.activestate.com/ASPN/Python/Cookbook and you can search the  
> Package Index too: http://pypi.python.org
> 
Don't I remember Microsoft withdrawing access to the raw packet driver 
on Windows XP, or was thing something they decided to ruin in Vaster?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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

Re: mmap and shared memory

2008-02-11 Thread Carl Banks
On Feb 11, 6:41 pm, Matias Surdi <[EMAIL PROTECTED]> wrote:
> Suppose I've a process P1, which generates itself a lot of data , for
> example 2Mb.
> Then, I've a process P2 which must access P1 shared memory and,
> probably, modify this data.
> To accomplish this, I've been digging around python's mmap module, but I
> can't figure how to use it without files.
>
> Could anybody explain me how could this be accomplished? An example will
> be very appreciated. Thanks a lot for your help.

In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location), but Python doesn't expose this.

There isn't really as much drawback to using a file as you might
expect, and there are benefits.  If you use an anonymous map the OS
could still write that memory to swap space, which, if your swap space
is fixed and limited, might negatively affect performance for the rest
of the system.


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


Re: AttributeError: 'module' object has no attribute 'letters'

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 21:33:25 -0200, John Machin <[EMAIL PROTECTED]>  
escribió:

> Otherwise run python from the command line with the -v option and find
> where it's getting the interloper string module from.

interloper: my new word of the day. Thanks!

PS: Another way would be to run the script with python -i, and when it  
halts, execute:

import string
print string.__file__

-- 
Gabriel Genellina

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


Re: Sending Python statement over socket in chunks

2008-02-11 Thread Jeffrey Barish
Diez B. Roggisch wrote:

> Stop reinventing the wheel, start using pyro. Then either return the
> list as whole, or if it really is to big, return subsequent slices of it.

I am using Pyro.  Great package.  The problem is getting the chunks to send. 
I am trying to avoid executing the statement, so I have to carve up the
list as source.  Using Pyro to send the chunks once I have them should work
fine.  Note that I am avoiding the use of the term "slice".  It is not
possible to slice the list in the way that we normally do in Python because
it is still in the form of a string.
-- 
Jeffrey Barish

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


Re: Difficulty with "inconsistent use of tabs and spaces in indentation" in file called

2008-02-11 Thread ibloom
My main problem is, I don't know where to find the file:
  File "", line 628

As in I don't know what code it is refering to by  ??
It isn't code that I wrote, its something from python or pyObjC

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


mmap and shared memory

2008-02-11 Thread Matias Surdi
Suppose I've a process P1, which generates itself a lot of data , for 
example 2Mb.
Then, I've a process P2 which must access P1 shared memory and, 
probably, modify this data.
To accomplish this, I've been digging around python's mmap module, but I 
can't figure how to use it without files.

Could anybody explain me how could this be accomplished? An example will 
be very appreciated. Thanks a lot for your help.

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


Re: use 'with' to redirect stdout

2008-02-11 Thread Neal Becker
Thanks!  I understand this better now.  This is really an example of a more
general pattern:

@contextmanager
def rebind_attr(object_, attr, value):
orig = getattr(object_, attr)
setattr(object_, attr, value)
yield
setattr(object_, attr_, orig)


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


Re: AttributeError: 'module' object has no attribute 'letters'

2008-02-11 Thread John Machin
On Feb 12, 9:24 am, black_13 <[EMAIL PROTECTED]> wrote:
> what does this error mean?
> i am trying to use mark hammonds win32 package.
>
> Traceback (most recent call last):
>   File "aui2.py", line 11, in 
> import win32com.client
>   File "C:\Python25\lib\site-packages\win32com\client\__init__.py",
> line 12, in 
> import dynamic, gencache, pythoncom
>   File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",
> line 24, in 
> import build
>   File "C:\Python25\lib\site-packages\win32com\client\build.py", line
> 507, in 
> valid_identifier_chars = string.letters + string.digits + "_"
> AttributeError: 'module' object has no attribute 'letters'
>
>

If you have a file called string.py in the same directory as your
script, move/rename/delete it.
Otherwise run python from the command line with the -v option and find
where it's getting the interloper string module from.

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


Re: Encrypting a short string?

2008-02-11 Thread Paul Rubin
erikcw <[EMAIL PROTECTED]> writes:
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user. 

I think you should use a database to maintain the email addresses
since you already have to maintain the contents and history of the
help ticket anyway.  If the contents of the database is private, then
assign the ticket numbers in an unpredictable sequence--I can tell you
how to do that cryptographically if you want (I've posted code for it
a few times before).  That is to stop users from guessing ticket
numbers that are valid but belong to other users.  If it's a public
database (e.g. a bug tracker for a free software project) or if
accessing a particular ticket needs a user credential associated with
that ticket, then you may as well use sequential numbers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Star Wars and parsecs [was Re: Why not a Python compiler?]

2008-02-11 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> On Feb 8, 2:53?pm, Lou Pecora <[EMAIL PROTECTED]> wrote:
> > In article <[EMAIL PROTECTED]>,
> > ?Grant Edwards <[EMAIL PROTECTED]> wrote:
> >
> > > On 2008-02-08, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> >
> > > > ? ? ? A Parsec is a fixed value (which, admittedly, presumes the culture
> > > > developed a 360degree circle broken into degrees => minutes =>
> > > > seconds... or, at least, some units compatible with the concept of an
> > > > "arc second", like 400 grads of, say, 100 "minutes", each of 100
> > > > "seconds")
> >
> > > It also presumes a standard diamter of that circle.
> >
> > Which is the Earth's orbit. ?So, long, long ago in a galaxy far, far
> > away did they know about the Earth and decide to use it as the basis for
> > length in the universe? ?Even before people on earth defined it? ?
> >
> > Or (ominous music builds here, switch to low voice) is it as some now
> > contend? ?We are the decendents of a long, lost civilization who
> > colonized Earth and used it as a base for their operations to the point
> > of adopting it as their own home?
> >
> > ... ?You Betcha!
> >
> > :-)
> 
> How come they spoke English?


Because they taught it to us.  It's obvious.

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


Re: Difficulty with "inconsistent use of tabs and spaces in indentation" in file called

2008-02-11 Thread [EMAIL PROTECTED]
On Feb 11, 9:34 am, ibloom <[EMAIL PROTECTED]> wrote:
> I've been trying for a couple days to build a program using pyObjC on
> a mac, I'm stuck on this error:
>
> : inconsistent use of tabs and spaces in indentation
> Traceback (most recent call last):
>   File "setup.py", line 59, in ?
>     setup(**setup_options)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/core.py", line 149, in setup
>     dist.run_commands()
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/dist.py", line 946, in run_commands
>     self.run_command(cmd)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/dist.py", line 966, in run_command
>     cmd_obj.run()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 342, in run
>     self.initialize_plist()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 415, in
> initialize_plist
>     plist = self.get_default_plist()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 294, in
> get_default_plist
>     version = find_version(target.script)
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/util.py", line 13, in
> find_version
>     ast = compiler.parseFile(fn)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/compiler/transformer.py", line 48, in parseFile
>     return parse(src)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/compiler/transformer.py", line 52, in parse
>     return Transformer().parsesuite(buf)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/compiler/transformer.py", line 129, in parsesuite
>     return self.transform(parser.suite(text))
>   File "", line 628
>     else:
>     ^
> SyntaxError: invalid syntax
>
> I don't even know which file has the indentation problem.

Maybe none of them do. An indentation error isn't necessarily
due to indentation. I just saw one last Saturday, but I don't
remember what caused it other than it wasn't indentation.
Something was open that wasn't closed properly, such as
matching () or [] or ''. Unfortunately, I can't reproduce it.
Examine the code carefully in the sections before the actual
reported error. You may be seeing a symptom rather than the cause.

>
> Any thoughts.
> Ian Bloom

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Erik Max Francis wrote:
> Jeff Schwab wrote:
> 
>> Erik Max Francis wrote:
>>> Robert Bossy wrote:
 I'm pretty sure we can still hear educated people say that free fall 
 speed depends on the weight of the object without realizing it's a 
 double mistake.
>>>
>>> Well, you have to qualify it better than this, because what you've 
>>> stated in actually correct ... in a viscous fluid.
>>
>> By definition, that's not free fall.
> 
> In a technical physics context.  But he's talking about posing the 
> question to generally educated people, not physicists (since physicists 
> wouldn't make that error).  In popular parlance, "free fall" just means 
> falling freely without restraint (hence "free fall rides," "free 
> falling," etc.).  And in that context, in the Earth's atmosphere, you 
> _will_ reach a terminal speed that is dependent on your mass (among 
> other things).
> 
> So you made precisely my point:  The average person would not follow 
> that the question was being asked was about an abstract (for people 
> stuck on the surface of the Earth) physics principle, but rather would 
> understand the question to be in a context where the supposedly-wrong 
> statement is _actually true_.

So what's the "double mistake?"  My understanding was (1) the misuse 
(ok, vernacular use) of the term "free fall," and (2) the association of 
weight with free-fall velocity ("If I tie an elephant's tail to a 
mouse's, and drop them both into free fall, will the mouse slow the 
elephant down?")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Steven D'Aprano wrote:

> On Mon, 11 Feb 2008 19:54:30 +1300, greg wrote:
> 
>>> Until DeBroglie formulated
>>> its  hypothesis of dual nature of matter (and light): wave and particle
>>> at the  same time.
>> Really it's neither waves nor particles, but something else for which
>> there isn't a good word in everyday English. Physicists seem to have got
>> around that by redefining the word "particle" to mean that new thing.
> 
> I like the term "wavical" to describe that. We're all made of wavicals, 
> it's just that the wave-like fuzziness is usually too small to notice.

It's usually spelled _wavicle_, by the way.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   I woke up this morning / You were the first thing on my mind
-- India Arie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: 'module' object has no attribute 'letters'

2008-02-11 Thread Ben Finney
black_13 <[EMAIL PROTECTED]> writes:

> what does this error mean?
> [...]
> valid_identifier_chars = string.letters + string.digits + "_"
> AttributeError: 'module' object has no attribute 'letters'

It means that you're trying to access the attribute 'letters' on a
module that doesn't have that attribute.

You need to find what the value of 'string' is at that point in the
code. If I had to guess, I would say the person who wrote the above
line was expecting 'string' to be bound to the Python standard library
module 'string'; but that the code you have binds that name to some
other module.

-- 
 \  "War is God's way of teaching geography to Americans."  -- |
  `\   Ambrose Bierce  |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Grant Edwards wrote:

> On 2008-02-09, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote:
>> Quantum mechanics are closely related to philosophy.
> 
> I've never understood that claim.  You can philosophize about
> anything: biology, math, weather, the stars, the moon, and so
> on.  I don't see how QM is any more related to philosophy than
> any other field in science.

It probably comes from reading popularizations that make the really 
silly attempt to join physics to Eastern philosophy and metaphysics, for 
instance, garbage like _The Tao of Physics_.  Modern physics can get 
weird and spooky and counterintuitive, but any real connection made with 
Eastern philosophy is only in the eye of the beholder.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   I woke up this morning / You were the first thing on my mind
-- India Arie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Jeff Schwab wrote:

> Erik Max Francis wrote:
>> Robert Bossy wrote:
>>> I'm pretty sure we can still hear educated people say that free fall 
>>> speed depends on the weight of the object without realizing it's a 
>>> double mistake.
>>
>> Well, you have to qualify it better than this, because what you've 
>> stated in actually correct ... in a viscous fluid.
> 
> By definition, that's not free fall.

In a technical physics context.  But he's talking about posing the 
question to generally educated people, not physicists (since physicists 
wouldn't make that error).  In popular parlance, "free fall" just means 
falling freely without restraint (hence "free fall rides," "free 
falling," etc.).  And in that context, in the Earth's atmosphere, you 
_will_ reach a terminal speed that is dependent on your mass (among 
other things).

So you made precisely my point:  The average person would not follow 
that the question was being asked was about an abstract (for people 
stuck on the surface of the Earth) physics principle, but rather would 
understand the question to be in a context where the supposedly-wrong 
statement is _actually true_.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   I woke up this morning / You were the first thing on my mind
-- India Arie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Better way to do this?

2008-02-11 Thread Carl Banks
On Feb 11, 3:57 pm, imho <[EMAIL PROTECTED]> wrote:
> PRC ha scritto:
>
>
>
> > Hi folks,
>
> > I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
> > 'string2'),(code3, 'string3'),)
>
> > Codes are unique. A dict would probably be the best approach but this
> > is beyond my control.
>
> > Here is an example:
>  pets = ((0,'cat'),(1,'dog'),(2,'mouse'))
>
> > If I am given a value for the code I need to retrieve the string
> > representation. The value is guaranteed to be valid.
>
> > This is what I came up with...
>
>  value=1
>  [ pet for code, pet in pets if value==code ][0]
> > 'dog'
>
> > It does the job, I was just curious if there was a better way to do
> > it.

A listcomp will traverse the whole tuple even if it finds the code
early in the tuple.  It's better just use a for loop and break out as
soon as you find it.

for code,pet in pets:
if value == code:
break
else:
raise ValueError("code %s not found" % value)

As an added bonus, you get a more useful error message if it's not
there (I know what you said, but bugs happen).  If it's too bulky for
you, put it into its own function and call it.


> Can't You first convert the tuple of tuples in a dict, and then
> retrieving the value given a code value ?
>
>  >>> dct = dict(pets)
>  >>> dct[1]
> 'dog'

A linear search might be faster than building a dict if this search is
only to be done once for a given tuple.


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


Re: packing greyscale values

2008-02-11 Thread John Machin
On Feb 11, 9:11 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> jimgardener wrote:
> > hi
> > i am getting value of a pixel of a greyscale image using PIL's
> > image.getdata and need to pack it as an int as below
>
> > ie greyvalues
> > 127 , 56 , 135 , 99 , 102 , 101 , 146 , 112 , 155 , 154 , 112 , 169
>
> > should become
> > -4473925, -8289919, -4144960, -5789785, -5592406, -5658199 ,-3684409,
> > -5131855, -3289651,-3355444, -5131855, -2763307
>
> > (i got these values using java's BufferedImage class..)I would like to
> > know if there is a way to do the conversion in python.(.i need 'these
> > 'for some calculations)
>
> Judging from
>
> >>> hex(0x1 - 4473925)
> '0xffbb'
> >>> 0xbb
>
> 187
>
> -4273925 indeed seems to denote a gray value, but the lighter 187 rather
> than 127. Are you sure the lists you give belong to the same image?
>
> Peter

Let Y = Java-derived numbers (187, etc)
and X = PIL-derived numbers (127, etc)
Y approx = 0.75 * X + 90
What the underlying cause of this relationship is, I have not a clue.

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


AttributeError: 'module' object has no attribute 'letters'

2008-02-11 Thread black_13
what does this error mean?
i am trying to use mark hammonds win32 package.

Traceback (most recent call last):
  File "aui2.py", line 11, in 
import win32com.client
  File "C:\Python25\lib\site-packages\win32com\client\__init__.py",
line 12, in 
import dynamic, gencache, pythoncom
  File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",
line 24, in 
import build
  File "C:\Python25\lib\site-packages\win32com\client\build.py", line
507, in 
valid_identifier_chars = string.letters + string.digits + "_"
AttributeError: 'module' object has no attribute 'letters'

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


Re: which one is more efficient

2008-02-11 Thread Steven D'Aprano
On Mon, 11 Feb 2008 10:41:44 -0500, Steve Holden wrote:

> If the "type" variable really is a type, of course, then the real
> solution is hardly radical: stop using the names of types and start
> using the types:

[snip example using "type(obj) in (type1, type2)"]


But if you're using actual types, you almost certainly want to allow for 
subclasses as well:

isinstance(obj, tuple_of_types)


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


Re: Encrypting a short string?

2008-02-11 Thread Carl Banks
On Feb 11, 4:19 pm, erikcw <[EMAIL PROTECTED]> wrote:
> On Feb 11, 4:07 pm, [EMAIL PROTECTED] wrote:
> > erikcw napisal(a):> But that can't be reversed, right? I'd like to be able 
> > to decrypt the
> > > data instead of having to store the hash in my database...
>
> > In such case it seems you have no choice but to use a symmetric
> > encryption algorithm - in other words, your original method. If the
> > strings are ~20 bytes long (3 DES blocks), then the base64-encoded
> > ciphertext will have 32 characters. In case of AES, that'll be up to
> > 45 characters. Wouldn't such length be acceptable?
>
> > Paul Rubin napisal(a):> 2. What happens if the user edits the subject line?
> > > Under normal security requirements you cannot do this. The ciphertext
> > > has to be longer than the plaintext since you don't want the opponent
> > > to be able to tell whether two plaintexts are the same. Therefore you
> > > have to attach some random padding to each plaintext. Also, you
> > > presumably want the ciphertext to be encoded as printing characters,
> > > while normally you'd treat the input as binary, so there is some
> > > further expansion.
>
> > If what erikcw is looking for is a cryptographically secure protocol,
> > there are more things to be careful about, like authentication or
> > replay attacks. But indeed, I'm wondering now what his use-case is.> I'm 
> > using this encrypted string to identify emails from a
> > > user. (the string will be in the subject line of the email).
>
> > Why not use "From" field to identify emails from a particular user?
>
> > Regards,
> > Marek
>
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user.  So
> cryptographic security isn't really important.  I can't use the from:
> field because a single user could have multiple tickets.

Shouldn't you have a database associating a ticket ID with an email
address (among other things)?


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


Re: Encrypting a short string?

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 19:19:00 -0200, erikcw <[EMAIL PROTECTED]>  
escribió:

> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user.  So
> cryptographic security isn't really important.  I can't use the from:
> field because a single user could have multiple tickets.

And you don't like [bug12345] or even [12345]? To the user, it's a lot  
clear its purpose, and anybody will understand what you mean if you say  
"Please maintain the bug number in the subject line" or similar.

-- 
Gabriel Genellina

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Jeff Schwab
Erik Max Francis wrote:
> Robert Bossy wrote:
>> Grant Edwards wrote:
>>> After repeated attempts at the tasks set for them in the
>>> experiments, the subjects would learn strategies that would
>>> work in a Newtonian world, but the initial intuitive reactions
>>> were very non-Newtonian (regardless of how educated they were
>>> in physics).
>>
>> I'm pretty sure we can still hear educated people say that free fall 
>> speed depends on the weight of the object without realizing it's a 
>> double mistake.
> 
> Well, you have to qualify it better than this, because what you've 
> stated in actually correct ... in a viscous fluid.

By definition, that's not free fall.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Steve Holden wrote:

> Well the history of physics for at least two hundred years has been a 
> migration away from the intuitive. In strict linguistic terms the word 
> "subatomic" is a fine oxymoron. I suspect it's really "turtles all the 
> way down".

Well, hard to say that's been a monotonic pattern.  For instance, 
Aristotelian physics had an awful lot of components that were fairly 
bizarre, counter-intuitive, or even contrary to easily gained 
experience.  The notion of impetus -- where an object throw moves in a 
straight line until it runs out of impetus, then falls straight down -- 
is clearly contrary to everyday experience of watching two people throw 
a ball back and forth from a distance, since the path of the ball is 
clearly curved.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   There is nothing so subject to the inconstancy of fortune as war.
-- Miguel de Cervantes, ca. 1600
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Erik Max Francis
Robert Bossy wrote:
> Grant Edwards wrote:
>> After repeated attempts at the tasks set for them in the
>> experiments, the subjects would learn strategies that would
>> work in a Newtonian world, but the initial intuitive reactions
>> were very non-Newtonian (regardless of how educated they were
>> in physics).
>
> I'm pretty sure we can still hear educated people say that free fall 
> speed depends on the weight of the object without realizing it's a 
> double mistake.

Well, you have to qualify it better than this, because what you've 
stated in actually correct ... in a viscous fluid.  Terminal speed is 
reached when the force due to gravity is equal and opposite to the drag 
force, and the drag force is dependent on the properties of the fluid, 
as well as the size and mass of the object that is falling through it.

It's only when you're dealing with objects falling through vacuum that 
all objects fall at the same rate, and that's because the gravitational 
and inertial masses are identical.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   There is nothing so subject to the inconstancy of fortune as war.
-- Miguel de Cervantes, ca. 1600
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encrypting a short string?

2008-02-11 Thread Martin Marcher
Hi,

On 2/11/08, erikcw <[EMAIL PROTECTED]> wrote:
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user.  So
> cryptographic security isn't really important.  I can't use the from:
> field because a single user could have multiple tickets.

I've always wondered why such systems don't use the Message-ID or
Reference headers - I know they aren't preserved by all mailers but I
think that having this info in the subject line is

a) visually disturbing (subjective)
b) I guess that the risk of a user modifying the subject line is the
same than finding a programm that doesn't to some extent honor the
headers i mentioned...

c) Personally whenever I find a mail that says please keep this in the
subject I delete that number on purpose...


martin
-- 
http://noneisyours.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pure Python Salsa20 Stream Cipher Implementation

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 17:29:49 -0200, Aahz <[EMAIL PROTECTED]> escribió:

> In article <[EMAIL PROTECTED]>,
> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> En Sat, 09 Feb 2008 20:29:58 -0200, Aahz <[EMAIL PROTECTED]>  
>> escribió:
>>> In article <[EMAIL PROTECTED]>,
>>> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
 En Sat, 09 Feb 2008 01:34:30 -0200, <[EMAIL PROTECTED]>
 escribió:
> On 8 Feb., 17:18, Paul Rubin  wrote:
>>
>> I don't understand why a pure python version of salsa20 would be
>> interesting.  Is there some application that uses salsa20, that's
>> worth being able to interoperate with in pure python?
>
> The reason for a pure python is that it would be independent from the
> platform. A C implementation is faster, but you need to compile it  
> for
> every platform. A python implementation doesn't have that problem and
> could be used to fall back upon.

 On most platforms -with a notable exception- there is a C compiler
 available as a standard tool, which is used to compile Python itself.
 distutils can easily compile and install C extensions itself, so most  
 of
 the time "python setup.py install" is the only thing users have to
 execute, exactly the same as if the package were pure Python. With
 setuptools, things may be even easier.
>>>
>>> What about Jython, PyPy, and IronPython?
>>
>> What about them?
>> Do you mean that there should be a Python implementation for each and
>> every imaginable module over there, so it can be used with all of those
>> Python variants? Restricted of course to their minimum common feature  
>> set?
>
>   Is there some reason you're using exaggerated language?  My only
> point is that simply saying "C compiler!  C compiler!" ignores the fact
> that Python itself is multi-platform (and makes you look foolish);
> whether any given module should be written in pure Python needs to be
> decided on a case-by-case basis.

And that's exactly what I said, I don't see the need for a pure Python  
implementation of salsa20 based solely on "you need to compile [the C  
source] on every platform" (cf. quoted text above). That's all, and I  
don't want to argue with you or anyone about this.

-- 
Gabriel Genellina

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


Re: Encrypting a short string?

2008-02-11 Thread erikcw
On Feb 11, 4:07 pm, [EMAIL PROTECTED] wrote:
> erikcw napisal(a):> But that can't be reversed, right? I'd like to be able to 
> decrypt the
> > data instead of having to store the hash in my database...
>
> In such case it seems you have no choice but to use a symmetric
> encryption algorithm - in other words, your original method. If the
> strings are ~20 bytes long (3 DES blocks), then the base64-encoded
> ciphertext will have 32 characters. In case of AES, that'll be up to
> 45 characters. Wouldn't such length be acceptable?
>
> Paul Rubin napisal(a):> 2. What happens if the user edits the subject line?
> > Under normal security requirements you cannot do this. The ciphertext
> > has to be longer than the plaintext since you don't want the opponent
> > to be able to tell whether two plaintexts are the same. Therefore you
> > have to attach some random padding to each plaintext. Also, you
> > presumably want the ciphertext to be encoded as printing characters,
> > while normally you'd treat the input as binary, so there is some
> > further expansion.
>
> If what erikcw is looking for is a cryptographically secure protocol,
> there are more things to be careful about, like authentication or
> replay attacks. But indeed, I'm wondering now what his use-case is.> I'm 
> using this encrypted string to identify emails from a
> > user. (the string will be in the subject line of the email).
>
> Why not use "From" field to identify emails from a particular user?
>
> Regards,
> Marek

In essence what I'm doing is trying to manage tickets for a helpdesk.
I want the ticket identifier to be short enough to fit in the subject
line along with the normal subject chosen by the user.  So
cryptographic security isn't really important.  I can't use the from:
field because a single user could have multiple tickets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encrypting a short string?

2008-02-11 Thread marek . rocki
erikcw napisal(a):
> But that can't be reversed, right? I'd like to be able to decrypt the
> data instead of having to store the hash in my database...
In such case it seems you have no choice but to use a symmetric
encryption algorithm - in other words, your original method. If the
strings are ~20 bytes long (3 DES blocks), then the base64-encoded
ciphertext will have 32 characters. In case of AES, that'll be up to
45 characters. Wouldn't such length be acceptable?

Paul Rubin napisal(a):
> 2. What happens if the user edits the subject line?
> Under normal security requirements you cannot do this. The ciphertext
> has to be longer than the plaintext since you don't want the opponent
> to be able to tell whether two plaintexts are the same. Therefore you
> have to attach some random padding to each plaintext. Also, you
> presumably want the ciphertext to be encoded as printing characters,
> while normally you'd treat the input as binary, so there is some
> further expansion.
If what erikcw is looking for is a cryptographically secure protocol,
there are more things to be careful about, like authentication or
replay attacks. But indeed, I'm wondering now what his use-case is.
> I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).
Why not use "From" field to identify emails from a particular user?

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


Re: Sending Python statement over socket in chunks

2008-02-11 Thread Diez B. Roggisch
Jeffrey Barish schrieb:
> I have a python module that contains an assignment statement binding a long
> list of things to a name:
> 
> list_of_things = [thing1, thing2, ...]
> 
> where each thing instantiates class Thing when executed.  I send this
> statement through a socket to a remote module that executes it.  The
> problem is that it takes too long to send the entire statement. 
> Accordingly, I am thinking of a solution that sends the list in chunks. 
> The client then executes each chunk and reassembles the complete list. 
> Thus, I would first send something like:
> 
> chunk = [thing1, thing2, ... thing10]
> 
> and then
> 
> chunk = [thing11, thing12, ... thing20]
> 
> until all things have been transmitted.  At the client end, I would execute
> each chunk statement and then do
> 
> list_of_things.append(chunk)
> 
> The point of this solution is that I can start doing useful work in the
> client as soon as I receive the first chunk, and the others can arrive in
> the background and be available by the time I need them.
> 
> One way I could implement this solution is to execute the statement for the
> entire list_of_things in the server and then create chunk = [...]
> statements with the lists filled using the repr of the class.  I believe
> that this solution will work, but it seems a shame to execute the
> list_of_things statement in the server rather than have the server stupidly
> handle strings (because executing the statement takes time and because the
> server currently doesn't understand "Thing").  Should I investigate using a
> parser to carve up the list_of_things = [...] statement?  Basically, I just
> need to identify each Thing(...) expression and then count out some number
> of them.  I should be able to do that using re.  Or perhaps I should write
> my own parser using Python string operations as all I need to do is count
> out some number of Things delimited by "Thing(" at one end and "),\nThing("
> at the other (or ")]\n" at the end of the list).  Did I just answer my own
> question?
> 
> Of course, I need to balance the complexity of any alternative solution
> against simply executing the statement on the server.


Stop reinventing the wheel, start using pyro. Then either return the 
list as whole, or if it _really_ is to big, return subsequent slices of it.

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


Re: Better way to do this?

2008-02-11 Thread Tim Chase
> I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
> 'string2'),(code3, 'string3'),)
> 
> Codes are unique. A dict would probably be the best approach but this
> is beyond my control.
> 
> Here is an example:
 pets = ((0,'cat'),(1,'dog'),(2,'mouse'))
> 
> If I am given a value for the code I need to retrieve the string
> representation. The value is guaranteed to be valid.
> 
> This is what I came up with...
> 
 value=1
 [ pet for code, pet in pets if value==code ][0]
> 'dog'

Does anything prevent you from writing that as

  >>> dict(pets)[value]
  'dog'

?

-tkc



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


Re: Better way to do this?

2008-02-11 Thread imho
PRC ha scritto:
> Hi folks,
> 
> I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
> 'string2'),(code3, 'string3'),)
> 
> Codes are unique. A dict would probably be the best approach but this
> is beyond my control.
> 
> Here is an example:
 pets = ((0,'cat'),(1,'dog'),(2,'mouse'))
> 
> If I am given a value for the code I need to retrieve the string
> representation. The value is guaranteed to be valid.
> 
> This is what I came up with...
> 
 value=1
 [ pet for code, pet in pets if value==code ][0]
> 'dog'
> 
> It does the job, I was just curious if there was a better way to do
> it.

Can't You first convert the tuple of tuples in a dict, and then 
retrieving the value given a code value ?

 >>> dct = dict(pets)
 >>> dct[1]
'dog'


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


Python-URL! - weekly Python news and links (Feb 11)

2008-02-11 Thread Gabriel Genellina
QOTW:  "And don't EVER make the mistake that you can design something
better than what you get from ruthless massively parallel trial-and-error
with a feedback cycle. That's giving your intelligence _much_ too much
credit." - Linus Torvalds
http://groups.google.com/group/fa.linux.kernel/msg/52f04d4ab1121c9b

"Bare excepts are BAD ..." - Sidnei da Silva


Defining properties per instance (not class):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/bfc093464dd6ba9/

IronPython vs. CPython comparison:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/339a1c3d6009bc3b/

MultiSingleton (many instances but unique for a given key):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f9e5075d0f4d930d/

Turning ZeroDivisionError off:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3fd33cf86a563d6c/

A common confusion between isinstance/issubclass and
the type/object hierarchy:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6788dfafd9baf3ca/

Why compiling Python to native code is hard (a long thread, with
detours through Star Wars, lost civilizations, the speed of light
and the luminiferous aether...):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8c7c359b600881e0/

Use Python to demonstrate sorting algorithms:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/103e0caa0943afb6/

Loading and using a .NET DLL:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/aec25d106bd6c45c/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://a

Re: Pure Python Salsa20 Stream Cipher Implementation

2008-02-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
Paul Rubin   wrote:
>[EMAIL PROTECTED] (Aahz) writes:
>>
>>   Is there some reason you're using exaggerated language?  My only
>> point is that simply saying "C compiler!  C compiler!" ignores the fact
>> that Python itself is multi-platform (and makes you look foolish);
>> whether any given module should be written in pure Python needs to be
>> decided on a case-by-case basis.
>
>Certainly one of salsa20's main design features is that it's supposed
>to be faster than AES-CTR.  Therefore any implementation other than a
>native C implementation is basically a compatibility fallback.

...or a teaching tool, because code is easier to read in Python.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Topographical sorting

2008-02-11 Thread Frank Niessink
Hi John,

2008/2/11, John <[EMAIL PROTECTED]>:
> Now, on to my problem. Topographical sorting essentially involves removing
> the minimal element in a set (1), and then arbitrarily choosing the next
> minimal element and removing it as well. So, after removing 1, one could
> remove 5, then 2, then 3, then 4, then 6, resulting in the sort of 15234.
> One could also get 123456. There are a number of sorts possible. This is
> where I am currently stuck, attempting to implement an algorithm that finds
> all possible sorts. I have looked at the topographical pseudocode available
> at Wikipedia, but this does not apply - it finds one topographical sort, not
> all.

How about something like this:

def allSorts(set):
result = []
for element in smallestElements(set):
for tail in allSorts(set - element):
result.append([element] + tail)
return result

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


Sending Python statement over socket in chunks

2008-02-11 Thread Jeffrey Barish
I have a python module that contains an assignment statement binding a long
list of things to a name:

list_of_things = [thing1, thing2, ...]

where each thing instantiates class Thing when executed.  I send this
statement through a socket to a remote module that executes it.  The
problem is that it takes too long to send the entire statement. 
Accordingly, I am thinking of a solution that sends the list in chunks. 
The client then executes each chunk and reassembles the complete list. 
Thus, I would first send something like:

chunk = [thing1, thing2, ... thing10]

and then

chunk = [thing11, thing12, ... thing20]

until all things have been transmitted.  At the client end, I would execute
each chunk statement and then do

list_of_things.append(chunk)

The point of this solution is that I can start doing useful work in the
client as soon as I receive the first chunk, and the others can arrive in
the background and be available by the time I need them.

One way I could implement this solution is to execute the statement for the
entire list_of_things in the server and then create chunk = [...]
statements with the lists filled using the repr of the class.  I believe
that this solution will work, but it seems a shame to execute the
list_of_things statement in the server rather than have the server stupidly
handle strings (because executing the statement takes time and because the
server currently doesn't understand "Thing").  Should I investigate using a
parser to carve up the list_of_things = [...] statement?  Basically, I just
need to identify each Thing(...) expression and then count out some number
of them.  I should be able to do that using re.  Or perhaps I should write
my own parser using Python string operations as all I need to do is count
out some number of Things delimited by "Thing(" at one end and "),\nThing("
at the other (or ")]\n" at the end of the list).  Did I just answer my own
question?

Of course, I need to balance the complexity of any alternative solution
against simply executing the statement on the server.
-- 
Jeffrey Barish

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


Re: Better way to do this?

2008-02-11 Thread Diez B. Roggisch
PRC schrieb:
> Hi folks,
> 
> I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
> 'string2'),(code3, 'string3'),)
> 
> Codes are unique. A dict would probably be the best approach but this
> is beyond my control.
> 
> Here is an example:
 pets = ((0,'cat'),(1,'dog'),(2,'mouse'))
> 
> If I am given a value for the code I need to retrieve the string
> representation. The value is guaranteed to be valid.
> 
> This is what I came up with...
> 
 value=1
 [ pet for code, pet in pets if value==code ][0]
> 'dog'
> 
> It does the job, I was just curious if there was a better way to do
> it.
> 

This is linear in the number of elements. It can get better (log_2 n) if 
you can rely on the order of codes as in your given example - then you 
should be able to use the module bisect to find the index quicker.

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


Re: Encrypting a short string?

2008-02-11 Thread Paul Rubin
erikcw <[EMAIL PROTECTED]> writes:
> database.  I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).

1. I hope you're not trying to spam anyone.
2. What happens if the user edits the subject line?

> I'm trying to figure out which approach I should use to encrypt the
> data.  The string will be less than 20 characters long, and I'd like
> the encrypted version to be about the same size.

Under normal security requirements you cannot do this.  The ciphertext
has to be longer than the plaintext since you don't want the opponent
to be able to tell whether two plaintexts are the same.  Therefore you
have to attach some random padding to each plaintext.  Also, you
presumably want the ciphertext to be encoded as printing characters,
while normally you'd treat the input as binary, so there is some
further expansion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Better way to do this?

2008-02-11 Thread PRC
Hi folks,

I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
'string2'),(code3, 'string3'),)

Codes are unique. A dict would probably be the best approach but this
is beyond my control.

Here is an example:
>>>pets = ((0,'cat'),(1,'dog'),(2,'mouse'))

If I am given a value for the code I need to retrieve the string
representation. The value is guaranteed to be valid.

This is what I came up with...

>>>value=1
>>>[ pet for code, pet in pets if value==code ][0]
'dog'

It does the job, I was just curious if there was a better way to do
it.



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


Re: Encrypting a short string?

2008-02-11 Thread erikcw
On Feb 11, 3:07 pm, [EMAIL PROTECTED] wrote:
> erikcw napisal(a):
>
>
>
> > Hi,
>
> > I'm trying to devise a scheme to encrypt/obfuscate a short string that
> > basically contains the user's username and record number from the
> > database.  I'm using this encrypted string to identify emails from a
> > user. (the string will be in the subject line of the email).
>
> > I'm trying to figure out which approach I should use to encrypt the
> > data.  The string will be less than 20 characters long, and I'd like
> > the encrypted version to be about the same size.
>
> > I tried DES in the Crypto module, but the cipher text was to long to
> > be usable in this case.
>
> > Any suggestions?
>
> > Thanks!
>
> How about:
>
> >>> hashlib.sha256("[EMAIL PROTECTED]|2937267834").hexdigest()[:20]
>
> Regards,
> Marek

Thanks Marek,

But that can't be reversed, right?  I'd like to be able to decrypt the
data instead of having to store the hash in my database...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encrypting a short string?

2008-02-11 Thread marek . rocki
erikcw napisal(a):
> Hi,
>
> I'm trying to devise a scheme to encrypt/obfuscate a short string that
> basically contains the user's username and record number from the
> database.  I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).
>
> I'm trying to figure out which approach I should use to encrypt the
> data.  The string will be less than 20 characters long, and I'd like
> the encrypted version to be about the same size.
>
> I tried DES in the Crypto module, but the cipher text was to long to
> be usable in this case.
>
> Any suggestions?
>
> Thanks!

How about:
>>> hashlib.sha256("[EMAIL PROTECTED]|2937267834").hexdigest()[:20]

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


Re: Help with jabber client in wx

2008-02-11 Thread Jarek Zgoda
Astan Chee pisze:

> A quick note, the project started as a google talk client, but it seems
> that xmpppy is flexible enough to support various other/similar XMPP
> servers, but I mainly use with/in google talk
> It is open source and I've included the windows executable as an
> optional download.
> The current problem Im having is that whenever the jabber client
> disconnects or whenever a network error occurs (ISP goes down,etc), the
> client does not reconnect. I've added some code to help this, but it
> still doesnt reconnect properly; or rather, it doesnt detect the
> disconnection properly. What am I doing wrong in the xmpppy
> classes/methods?

If you want to use xmppy, I'd suggest looking at Gajim team
modifications to original source (http://gajim.org/). These guys did a
whole lot of work making xmppy more standards compliant and fixing bugs.

-- 
Jarek Zgoda
http://zgodowie.org/

"We read Knuth so you don't have to" - Tim Peters
-- 
http://mail.python.org/mailman/listinfo/python-list


Encrypting a short string?

2008-02-11 Thread erikcw
Hi,

I'm trying to devise a scheme to encrypt/obfuscate a short string that
basically contains the user's username and record number from the
database.  I'm using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).

I'm trying to figure out which approach I should use to encrypt the
data.  The string will be less than 20 characters long, and I'd like
the encrypted version to be about the same size.

I tried DES in the Crypto module, but the cipher text was to long to
be usable in this case.

Any suggestions?

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


Re: Tkinter equiv for setPalette

2008-02-11 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Helmut Jarausch <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I am to convert an old Perl-Tk script to Python.
> It starts by
> my $MW= new MainWindow;
> $MW->setPalette(background => 'AntiqueWhite1', foreground => 'blue');
> 
> Is there an equivalent for Tkinter? How can I set default colors for
> background and foreground for the whole application (root window and its
> children)

Tkinter widgets have a tk_setPalette method so you can do this:

root = Tkinter.Tk()
root.tk_setPalette(background = 'AntiqueWhite1', foreground = 'blue')

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


Re: Pure Python Salsa20 Stream Cipher Implementation

2008-02-11 Thread Paul Rubin
[EMAIL PROTECTED] (Aahz) writes:
>   Is there some reason you're using exaggerated language?  My only
> point is that simply saying "C compiler!  C compiler!" ignores the fact
> that Python itself is multi-platform (and makes you look foolish);
> whether any given module should be written in pure Python needs to be
> decided on a case-by-case basis.

Certainly one of salsa20's main design features is that it's supposed
to be faster than AES-CTR.  Therefore any implementation other than a
native C implementation is basically a compatibility fallback.
However, it's likely that there's already a JNI wrapper for it that
should(?) make it useable with jython.  I don't know the .net
situation but I'd hope it's similar.  And someone says there's already
a ctypes wrapper.

Overall, though, I just don't see a need for this, it's far more
important to have AES and DES available since those are standard
crypto algorithms, even if pure python implementations are inherently
slow.  If something nonstandard is desired for speed, SHA-OFB seems
to work pretty well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find current working user

2008-02-11 Thread Tim Chase
> Can anyone tell me how to find current working user in windows?

The below should be fairly cross-platform:

>>> import getpass
>>> whoami = getpass.getuser()
>>> print whoami
W: tchase
L: tim

("W:" is the result on my windows box, "L:" is the result on my 
Linux box) which can be used in concert with

>>> import user
>>> print user.home
W: C:\Documents and Settings\tchase
L: /home/tim

or

>>> import os
>>> os.expanduser('~/Desktop')
W: C:\Documents and Settings\tchase/Desktop
L: /home/tim/Desktop

in case you need either of them.

-tkc



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


Re: Pure Python Salsa20 Stream Cipher Implementation

2008-02-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>En Sat, 09 Feb 2008 20:29:58 -0200, Aahz <[EMAIL PROTECTED]> escribió:
>> In article <[EMAIL PROTECTED]>,
>> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>>> En Sat, 09 Feb 2008 01:34:30 -0200, <[EMAIL PROTECTED]>  
>>> escribió:
 On 8 Feb., 17:18, Paul Rubin  wrote:
>
> I don't understand why a pure python version of salsa20 would be
> interesting.  Is there some application that uses salsa20, that's
> worth being able to interoperate with in pure python?

 The reason for a pure python is that it would be independent from the
 platform. A C implementation is faster, but you need to compile it for
 every platform. A python implementation doesn't have that problem and
 could be used to fall back upon.
>>>
>>> On most platforms -with a notable exception- there is a C compiler
>>> available as a standard tool, which is used to compile Python itself.
>>> distutils can easily compile and install C extensions itself, so most of
>>> the time "python setup.py install" is the only thing users have to
>>> execute, exactly the same as if the package were pure Python. With
>>> setuptools, things may be even easier.
>>
>> What about Jython, PyPy, and IronPython?
>
>What about them?
>Do you mean that there should be a Python implementation for each and  
>every imaginable module over there, so it can be used with all of those  
>Python variants? Restricted of course to their minimum common feature set?

  Is there some reason you're using exaggerated language?  My only
point is that simply saying "C compiler!  C compiler!" ignores the fact
that Python itself is multi-platform (and makes you look foolish);
whether any given module should be written in pure Python needs to be
decided on a case-by-case basis.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python equivt of __FILE__ and __LINE__

2008-02-11 Thread thebjorn
On Feb 11, 4:55 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> Bill Davy wrote:
> > Writing a quick and dirty assembler and want to give the user the location
> > of an error.  The "assembly language" is Python.  If the user wants to
> > generat some object code they write something  like:
>
> > Label(LoopLable)
> > Load(R4)
> > Dec()
> > JNZ(LoopLabel)
>
> > I can use Python to do all the expression evalutaion, conversion from Python
> > FP to target FP, include files, macros (done as function definitions).  The
> > functions like Load() generate the approproyte object code.
>
> > So, for example, when a label is defined or referenced, I save the File,Line
> > so if there is not exactly one defintion or no references, I can report the
> > file location(s) to be considered.  In the example, I would want to report
> > that LoopLable is not referenced, and LoopLabel is not defined.
>
> > TIA,
> > Bill
>
> > PSwww.SynectixLtd.comis not relevant
>
> You *can* get at that kind of information: The traceback module has a
> function called "extract_stack" which can give you a pointer to the
> whole execution stack.  From that can be generated all the usual stuff
> you see in a traceback -- including file and line information.  *How*
> you extract that stuff, I'll leave as an exercises for the reader.
> (Meaning I haven't a clue.)
>
> Gary Herron

I think the inspect module might be more useful... the getfile() and
getsourcelines() look promising.

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


Re: how to find current working user

2008-02-11 Thread Chris Mellon
On Feb 11, 2008 12:30 PM, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Mon, 11 Feb 2008 15:21:16 -0200, Praveena Boppudi (c)
> <[EMAIL PROTECTED]> escribi�:
>
> > Can anyone tell me how to find current working user in windows?
>
> If it is just informational, use os.environ['USERNAME']
> Using win32wnet (from the pywin32 package):
>
> py> import win32wnet
> py> win32wnet.WNetGetUser()
> 'gabriel'
>


Using stdlib only:
import getpass;getpass.getuser()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: wxpython file dialog

2008-02-11 Thread Guilherme Polo
2008/2/11, Mike Driscoll <[EMAIL PROTECTED]>:
> On Feb 11, 2008 12:14 PM, Guilherme Polo <[EMAIL PROTECTED]> wrote:
> > 2008/2/11, Mike Driscoll <[EMAIL PROTECTED]>:
> > > On Feb 10, 6:41 am, Janwillem <[EMAIL PROTECTED]> wrote:
> > > > Guilherme Polo wrote:
> > > > > 2008/2/10, Janwillem <[EMAIL PROTECTED]>:
> > > > >> Guilherme Polo wrote:
> > > > >>  > 2008/2/9, Janwillem <[EMAIL PROTECTED]>:
> > > >
> > > >  Is there a way to force the wx.FileDialog to show as default the
> > > > >>  >>  thumbnails vie in stead of list view?
> > > > >>  >>  thanks, janwillem
> > > >
>
> 
>
> > >
> > > What is your application supposed to do? In the meantime, I recommend
> > > looking at this control:
> > >
> > > http://xoomer.alice.it/infinity77/main/ThumbnailCtrl.html
> > >
> > > You can probably get what you need from it. I also highly recommend
> > > posting to the wxPython user's group where you'll get more wx-specific
> > > help. See below:
> > >
> > > http://wxpython.org/maillist.php
> > >
> > > If you download the venerable wxPython Demo from wxPython.org, you can
> > > check out other related widgets such as wx.ImageBrowser or the
> > > wx.BitmapComboBox.
> >
> > wx.ImageBrowser and wx.BitmapComboBox are non-existent widgets. There
> > are demos named like that but the actual widgets are
> > wx.lib.imagebrowser and wx.combo.BitmapComboBox
>
>
> Whoops! My bad! Still, I think the OP might find them useful for
> creating his own custom image dialog.
>
> Cheers,
>
> Mike
>

It is ok ;) I mentioned imagebrowser on my first email, but he needs
to selection several images at once and imagebrowser lacks this right
now. An easy patch fix this, the widget would take another argument to
specify the style of the listbox it uses and it needs to store all the
selected images using listbox.GetSelections() if the user opts for
multiple selection.
I suggest posting this at wx maillist as feature request so you don't
need to wait for me to submit a patch.

>
> >
> > >
> > > HTH
> > >
> > > Mike
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> >
> >
> > --
> > -- Guilherme H. Polo Goncalves
> >
>


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find current working user

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 15:21:16 -0200, Praveena Boppudi (c)  
<[EMAIL PROTECTED]> escribi�:

> Can anyone tell me how to find current working user in windows?

If it is just informational, use os.environ['USERNAME']
Using win32wnet (from the pywin32 package):

py> import win32wnet
py> win32wnet.WNetGetUser()
'gabriel'

-- 
Gabriel Genellina

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

Re: wxpython file dialog

2008-02-11 Thread Mike Driscoll
On Feb 11, 2008 12:14 PM, Guilherme Polo <[EMAIL PROTECTED]> wrote:
> 2008/2/11, Mike Driscoll <[EMAIL PROTECTED]>:
> > On Feb 10, 6:41 am, Janwillem <[EMAIL PROTECTED]> wrote:
> > > Guilherme Polo wrote:
> > > > 2008/2/10, Janwillem <[EMAIL PROTECTED]>:
> > > >> Guilherme Polo wrote:
> > > >>  > 2008/2/9, Janwillem <[EMAIL PROTECTED]>:
> > >
> > >  Is there a way to force the wx.FileDialog to show as default the
> > > >>  >>  thumbnails vie in stead of list view?
> > > >>  >>  thanks, janwillem
> > >



> >
> > What is your application supposed to do? In the meantime, I recommend
> > looking at this control:
> >
> > http://xoomer.alice.it/infinity77/main/ThumbnailCtrl.html
> >
> > You can probably get what you need from it. I also highly recommend
> > posting to the wxPython user's group where you'll get more wx-specific
> > help. See below:
> >
> > http://wxpython.org/maillist.php
> >
> > If you download the venerable wxPython Demo from wxPython.org, you can
> > check out other related widgets such as wx.ImageBrowser or the
> > wx.BitmapComboBox.
>
> wx.ImageBrowser and wx.BitmapComboBox are non-existent widgets. There
> are demos named like that but the actual widgets are
> wx.lib.imagebrowser and wx.combo.BitmapComboBox


Whoops! My bad! Still, I think the OP might find them useful for
creating his own custom image dialog.

Cheers,

Mike


>
> >
> > HTH
> >
> > Mike
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> -- Guilherme H. Polo Goncalves
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython file dialog

2008-02-11 Thread Guilherme Polo
2008/2/11, Mike Driscoll <[EMAIL PROTECTED]>:
> On Feb 10, 6:41 am, Janwillem <[EMAIL PROTECTED]> wrote:
> > Guilherme Polo wrote:
> > > 2008/2/10, Janwillem <[EMAIL PROTECTED]>:
> > >> Guilherme Polo wrote:
> > >>  > 2008/2/9, Janwillem <[EMAIL PROTECTED]>:
> >
> >  Is there a way to force the wx.FileDialog to show as default the
> > >>  >>  thumbnails vie in stead of list view?
> > >>  >>  thanks, janwillem
> >
> > >>  >> --
> > >>  >>  http://mail.python.org/mailman/listinfo/python-list
> >
> > >>> You should be using wx.lib.imagebrowser.ImageDialog instead of
> > >>  > wx.FileDialog for that purpose.
> >
> > >> Thanks for the hint, very neat widget. However, it seems not to support
> > >>  multiple selection. My application selects from a series of low light
> > >>  photographs of the same subject the sharpest one (like BSS on Nikon
> > >>  Coolpix). So I need multiple selection and thumbnails. It works with
> > >>  wx.FileDialog style=FD_MULTIPLE but I have to select thumbnail view
> > >>  every time.
> >
> > >> Janwillem
> > >>  --
> > >>  http://mail.python.org/mailman/listinfo/python-list
> >
> > > Unfortunately that is not possible with imagebrowser because it sets
> > > the listbox for single selection in the code. A patch will fix this.
> > > Now continuing on FileDialog.. I don't have the option to change to
> > > thumbnail view here, I guess you are using Windows, so it is not
> > > cross-platform. imagebrowser is cross-platform because it is all done
> > > by wxPython.
> >
> > The application is meant to become x-platform; prefarably linux osX and
> > win. I use:
> >
> > dialog=wx.FileDialog(None,'Choose picture file',defDir,\
> >  style=wx.OPEN | wx.FD_MULTIPLE,wildcard=wcard)
> >
> > and supposed that the wx dialog would work on linux. I did not yet test
> > this because the app depends on a lib (dll) which I have not yet made to
> > work in Linux (it's pascal and freepascal has a problem I have to dive
> > into).
>
> What is your application supposed to do? In the meantime, I recommend
> looking at this control:
>
> http://xoomer.alice.it/infinity77/main/ThumbnailCtrl.html
>
> You can probably get what you need from it. I also highly recommend
> posting to the wxPython user's group where you'll get more wx-specific
> help. See below:
>
> http://wxpython.org/maillist.php
>
> If you download the venerable wxPython Demo from wxPython.org, you can
> check out other related widgets such as wx.ImageBrowser or the
> wx.BitmapComboBox.

wx.ImageBrowser and wx.BitmapComboBox are non-existent widgets. There
are demos named like that but the actual widgets are
wx.lib.imagebrowser and wx.combo.BitmapComboBox

>
> HTH
>
> Mike
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regarding html source code

2008-02-11 Thread subeen
Another way:

import urllib2

usock = urllib2.urlopen('http://abc.com')
data = usock.read()
usock.close()

print data




On Feb 12, 12:05 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> shashank jain top-posted:
>
>
>
> > On Feb 11, 2008 11:15 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> >> jainshasha wrote:
> >>> well i have create a program which can read out the html source code
> >>> files or any other web page source code files through my program so
> >> Like this?
>
> >>  >>> from lxml import html
> >>  >>> page = html.parse("http://www.google.com";)
> >>  >>> print page.find("//title").text
> >>  Google
>
> >>http://codespeak.net/lxml
>
> > well i would like to know how python can help me in doing this or if u think
> > any other language please help me out
>
> What I showed you was Python code that reads an HTML file. What else do you 
> need?
>
> Stefan

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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 14:05:27 -0200, Grant Edwards <[EMAIL PROTECTED]>  
escribi�:

> On 2008-02-11, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>> Well the history of physics for at least two hundred years has
>> been a migration away from the intuitive.
>
> Starting at least as far back as Newtonian mechanics.  I once
> read a very interesting article about some experiments that
> showed that even simple newtonian physics is counter-intuitive.

The inertia principle is counter-intuitive too, in a real world with  
friction. Things don't just "keep going" when impulse cease to exist;  
everyone knows that a running car eventually stops if the engine stops.  
That it "would" keep moving at the same speed in a straight line is an  
abstraction that people hardly can build from experience.

-- 
Gabriel Genellina

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

Re: regarding html source code

2008-02-11 Thread Stefan Behnel
Hi,

shashank jain top-posted:
> On Feb 11, 2008 11:15 PM, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> 
>> jainshasha wrote:
>>> well i have create a program which can read out the html source code
>>> files or any other web page source code files through my program so
>> Like this?
>>
>>  >>> from lxml import html
>>  >>> page = html.parse("http://www.google.com";)
>>  >>> print page.find("//title").text
>>  Google
>>
>> http://codespeak.net/lxml
>>
> well i would like to know how python can help me in doing this or if u think
> any other language please help me out

What I showed you was Python code that reads an HTML file. What else do you 
need?

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


Re: CSV Reader

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 14:41:54 -0200, Mike P  
<[EMAIL PROTECTED]> escribi�:

> CSV_Data = open(working_CSV)
> data = CSV_Data.readlines()
> flag=False
> for record in data:
> if record.startswith('"Transaction ID"'):
> [...]

Files are already iterable by lines. There is no need to use readlines(),  
and you can avoid the already menctioned potential slowdown problem. Just  
remove the data=CSV_data.readlines() line, and change that for statement  
to be:
for record in CSV_Data:

Reading the style guide may be beneficial:  
http://www.python.org/dev/peps/pep-0008/

-- 
Gabriel Genellina

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

Re: Plotting 3d points

2008-02-11 Thread Rasmus Kjeldsen
Elby skrev:
> Matplotlib as some 3D capabilities too. You can have a look at these
> examples : http://scipy.org/Cookbook/Matplotlib/mplot3D
> 
I got the cookbook examples to work, but where do I read more into what 
i can do with mplot3d (set type of marker, set size of marker etc.)? A 
google search yields nothing useable.

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


Re: regarding html source code

2008-02-11 Thread Stefan Behnel
jainshasha wrote:
> well i have create a program which can read out the html source code
> files or any other web page source code files through my program so

Like this?

  >>> from lxml import html
  >>> page = html.parse("http://www.google.com";)
  >>> print page.find("//title").text
  Google

http://codespeak.net/lxml

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


Re: Difficulty with "inconsistent use of tabs and spaces in indentation" in file called

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 13:34:17 -0200, ibloom <[EMAIL PROTECTED]> escribi�:

> I've been trying for a couple days to build a program using pyObjC on
> a mac, I'm stuck on this error:
>
> : inconsistent use of tabs and spaces in indentation
> Traceback (most recent call last):
>   File "setup.py", line 59, in ?
> setup(**setup_options)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/core.py", line 149, in setup
> dist.run_commands()
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/dist.py", line 946, in run_commands
> self.run_command(cmd)
>   File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
> python2.4/distutils/dist.py", line 966, in run_command
> cmd_obj.run()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 342, in run
> self.initialize_plist()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 415, in
> initialize_plist
> plist = self.get_default_plist()
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/build_app.py", line 294, in
> get_default_plist
> version = find_version(target.script)
>   File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
> python2.4/site-packages/py2app/py2app/util.py", line 13, in
> find_version
> ast = compiler.parseFile(fn)

Put a print statement just above that line, to see which file triggers the  
error.

-- 
Gabriel Genellina

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

regarding html source code

2008-02-11 Thread jainshasha
hello friends

well i want to create a program which can read my html based coding or
any other web page code

so i want to know how python can help me in this regard

so anyone have ay idea about this thing please reply soon

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


Re: How to broad cast ping address.......

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 13:31:56 -0200, Manikandan R <[EMAIL PROTECTED]>  
escribi�:

> I am working in Python scripting. I an need to find out all the  
> device
> connected in the network. Just I planned to broad cast the ping address  
> and
> use the ARP table to get the IP address of the system in the network.  
> As, I
> am working in Win XP i am not able to use ping -b command to broad cast.

The simplest approach is to enumerate and ping each and every address in  
your subnet and wait for the response, but consider that some hosts may  
have been configured to not answer (and assuming you don't have a /8  
network...)
There is an ICMP library in the Python cookbook  
http://aspn.activestate.com/ASPN/Python/Cookbook and you can search the  
Package Index too: http://pypi.python.org

>  I have one more doubt, Is it is possible to see the router table  
> from
> the client system (My system), since router table will have the
> Mac / IP address of all the system in the network. If there is any
> possibilities please mention me.

Do you mean, you have a router device, and you want to ask it for its  
routing tables? This has other problems too: depending on the network  
topology, the router may not even know about some hosts, or they may have  
disconnected and the router didn't notice...

>  Another option I like to try is to see the DNS table but its not
> possible from client system (My sytem), I think so.

If you have a running DNS, surely you can query it. But this doesn't tell  
you about "connected" hosts as you said earlier.

>   I am trying this for more that 2 week, no result from any one.  
> Please
> reply me. Thank's in advance.

More than a Python question, this is a network management question. There  
are a lot of applications that can help; try something based on SNMP  
http://www.snmplink.org

-- 
Gabriel Genellina

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

how to find current working user

2008-02-11 Thread Praveena Boppudi (c)
Hi,
 
Can anyone tell me how to find current working user in windows?
 
Thanks,
Praveena.
-- 
http://mail.python.org/mailman/listinfo/python-list

regarding html source code

2008-02-11 Thread jainshasha
hello friends

well i have create a program which can read out the html source code
files or any other web page source code files through my program so
please guys help me out in this problem that how python can help me in
this regard and if there is any other language through which i can
easily make my program


Thanks in advance

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


python25_d.lib?

2008-02-11 Thread Robert Dailey
Hi,

Currently I'm embedding Python 2.5 into my C++ Visual Studio project.
However, during the link stage it is stating that it cannot find
"python25_d.lib". From what I read in my search through Google on this issue
is that you actually have to build Python yourself to get a debug version of
the library. However, I would rather just link to the release library to
save myself the trouble. It seems as if the python library is utilizing
auto-link in visual studio. What preprocessor directive do I define to
prevent this behavior? If it is not controlled by a preprocessor directive,
what other ways can I make it use the release library? I would rather
explicitly force it to use "python25.lib" in debug builds.

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

Re: wxpython file dialog

2008-02-11 Thread Mike Driscoll
On Feb 10, 6:41 am, Janwillem <[EMAIL PROTECTED]> wrote:
> Guilherme Polo wrote:
> > 2008/2/10, Janwillem <[EMAIL PROTECTED]>:
> >> Guilherme Polo wrote:
> >>  > 2008/2/9, Janwillem <[EMAIL PROTECTED]>:
>
>  Is there a way to force the wx.FileDialog to show as default the
> >>  >>  thumbnails vie in stead of list view?
> >>  >>  thanks, janwillem
>
> >>  >> --
> >>  >>  http://mail.python.org/mailman/listinfo/python-list
>
> >>> You should be using wx.lib.imagebrowser.ImageDialog instead of
> >>  > wx.FileDialog for that purpose.
>
> >> Thanks for the hint, very neat widget. However, it seems not to support
> >>  multiple selection. My application selects from a series of low light
> >>  photographs of the same subject the sharpest one (like BSS on Nikon
> >>  Coolpix). So I need multiple selection and thumbnails. It works with
> >>  wx.FileDialog style=FD_MULTIPLE but I have to select thumbnail view
> >>  every time.
>
> >> Janwillem
> >>  --
> >>  http://mail.python.org/mailman/listinfo/python-list
>
> > Unfortunately that is not possible with imagebrowser because it sets
> > the listbox for single selection in the code. A patch will fix this.
> > Now continuing on FileDialog.. I don't have the option to change to
> > thumbnail view here, I guess you are using Windows, so it is not
> > cross-platform. imagebrowser is cross-platform because it is all done
> > by wxPython.
>
> The application is meant to become x-platform; prefarably linux osX and
> win. I use:
>
> dialog=wx.FileDialog(None,'Choose picture file',defDir,\
>  style=wx.OPEN | wx.FD_MULTIPLE,wildcard=wcard)
>
> and supposed that the wx dialog would work on linux. I did not yet test
> this because the app depends on a lib (dll) which I have not yet made to
> work in Linux (it's pascal and freepascal has a problem I have to dive
> into).

What is your application supposed to do? In the meantime, I recommend
looking at this control:

http://xoomer.alice.it/infinity77/main/ThumbnailCtrl.html

You can probably get what you need from it. I also highly recommend
posting to the wxPython user's group where you'll get more wx-specific
help. See below:

http://wxpython.org/maillist.php

If you download the venerable wxPython Demo from wxPython.org, you can
check out other related widgets such as wx.ImageBrowser or the
wx.BitmapComboBox.

HTH

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


RE: CSV Reader

2008-02-11 Thread Reedick, Andrew
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Mike P
> Sent: Monday, February 11, 2008 11:42 AM
> To: python-list@python.org
> Subject: Re: CSV Reader
> 
> Cheers for the help, the second way looked to be the best in the end,
> and thanks for the boolean idea
> 
> Mike
> 
> 
> 
> working_CSV =  "//filer/common/technical/Research/E2C/Template_CSV/
> DFAExposureToConversionQueryTool.csv"
> 
> save_file = open("//filer/common/technical/Research/E2C/Template_CSV/
> CSV_Data2.csv","w")
> 
> CSV_Data = open(working_CSV)
> data = CSV_Data.readlines()
> flag=False
> for record in data:
> if record.startswith('"Transaction ID"'):
> flag=True
> if flag:
> save_file.write(record)
> save_file.close()


Don't be a pansy.

Use the csv module, or add a check for
record.startswith('TransactionID').  There's no guarantee that csv
columns will be double-quoted.  (Leading whitespace may or may not be
acceptable, too.)  Look at the first piece of sample code in the
documentation for the csv module.  (Section 9.1.5 in python 2.5)  You're
99% of the way to using csv.reader() properly.


Nitpick:  If the boolean check is expensive, then
if not flag and record.startswith(...):
flag = true

Nitpick:  flag is a weak name.  Use something like bPrint, okay2print,
or print_now or anything that's more descriptive.  In larger and/or more
complex programs, meaningful variable names are a must.



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA622


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


Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Dotan Cohen
On 11/02/2008, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2008-02-11, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > Well the history of physics for at least two hundred years has
> > been a migration away from the intuitive.
>
> Starting at least as far back as Newtonian mechanics.  I once
> read a very interesting article about some experiments that
> showed that even simple newtonian physics is counter-intuitive.
> Two of the experiments I remember vividly. One of them showed
> that the human brain expects objects constrained to travel in a
> curved path will continue to travel in a curved path when
> released.  The other showed that the human brain expects that
> when an object is dropped it will land on a spot immediately
> below the drop point -- regardless of whether or not the ojbect
> was in motion horizontally when released.
>
> After repeated attempts at the tasks set for them in the
> experiments, the subjects would learn strategies that would
> work in a Newtonian world, but the initial intuitive reactions
> were very non-Newtonian (regardless of how educated they were
> in physics).
>

I would like to take part in such an experiment.

I should note that movies and such often portray the wrong motion of
objects. Years of that type of conditioning may be responsible for the
non-newtonian expectations of the participants.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Robert Bossy
Grant Edwards wrote:
> On 2008-02-11, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>   
>> Well the history of physics for at least two hundred years has
>> been a migration away from the intuitive.
>> 
>
> Starting at least as far back as Newtonian mechanics.  I once
> read a very interesting article about some experiments that
> showed that even simple newtonian physics is counter-intuitive.
> Two of the experiments I remember vividly. One of them showed
> that the human brain expects objects constrained to travel in a
> curved path will continue to travel in a curved path when
> released.  The other showed that the human brain expects that
> when an object is dropped it will land on a spot immediately
> below the drop point -- regardless of whether or not the ojbect
> was in motion horizontally when released.
>
> After repeated attempts at the tasks set for them in the
> experiments, the subjects would learn strategies that would
> work in a Newtonian world, but the initial intuitive reactions
> were very non-Newtonian (regardless of how educated they were
> in physics).
>   
I'm pretty sure we can still hear educated people say that free fall 
speed depends on the weight of the object without realizing it's a 
double mistake.

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


Re: CSV Reader

2008-02-11 Thread Mike P
Cheers for the help, the second way looked to be the best in the end,
and thanks for the boolean idea

Mike



working_CSV =  "//filer/common/technical/Research/E2C/Template_CSV/
DFAExposureToConversionQueryTool.csv"

save_file = open("//filer/common/technical/Research/E2C/Template_CSV/
CSV_Data2.csv","w")

CSV_Data = open(working_CSV)
data = CSV_Data.readlines()
flag=False
for record in data:
if record.startswith('"Transaction ID"'):
flag=True
if flag:
save_file.write(record)
save_file.close()

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


RE: CSV Reader

2008-02-11 Thread Reedick, Andrew

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Mike P
> Sent: Monday, February 11, 2008 11:10 AM
> To: python-list@python.org
> Subject: Re: CSV Reader
> 
> Hi Larry,
> 
> i'm still getting to grips with python, but rest assured i thinkn it's
> better for me to write hte code for learnign purposes
> 
> My basic file is here, it comes up with a syntax error on the
> startswith line, is this because it is potentially a list?
> My idea was to get the lines number where i can see Transaction ID and
> then write out everything from this point into a new datafile.
> 
> 


>From the docs for reader:  "All data read are returned as strings. No
automatic data type conversion is performed."
Just use print or repr() to see what the row data looks.  Then the
method to check for 'transaction id' should be abundantly clear.

for data in reader:
print data
print repr(data)


> Would a better solution be just to use readlines and search for the
> string with a counter and then write out a file from there?

Yes you could, but the danger is that you get an insanely large file
that blows out your memory or causes the process to swap to disk space
(disk is slow.)
Just loop through the lines and use a boolean flag to determine when to
start printing.


*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


Re: How can I kill CGIHTTPServer ?

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 04:18:04 -0200, eching <[EMAIL PROTECTED]>  
escribi�:

> I'm running CGIHTTPServer with the serve_forever method and I cannot
> get the darn thing to stop unless I kill the command prompt its
> running in.  I searched for similar posts here and found this:

See this thread from last year; it's about XMLRPC but the idea is the same.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/c48f06ef80e07a39

-- 
Gabriel Genellina

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

Re: use 'with' to redirect stdout

2008-02-11 Thread Jean-Paul Calderone
On Mon, 11 Feb 2008 10:37:18 -0500, Neal Becker <[EMAIL PROTECTED]> wrote:
>This will work for stdout:
>
>from __future__ import with_statement
>from contextlib import contextmanager
>import sys
>
>@contextmanager
>def redirect(newfile):
>orig_stdout = sys.stdout
>sys.stdout = newfile
>yield
>sys.stdout = orig_stdout
>
>if __name__ == "__main__":
>with redirect (open('stdout', 'w')):
>print "hello"
>
>print "we're back"
>
>But now, a harder puzzle that I'm stumped on.  Rewrite the above so that it
>doesn't hardcode sys.stdout, ie:
>
>def redirect (newfile, oldfile=None)
>
>where default oldfile is sys.stdout.  This seems much trickier.

You just have to parameterize oldfile.  The simplest way is with an object
and an attribute name.

@contextmanager
def redirect(fileholder, filename, newfile):
orig = getattr(fileholder, filename)
setattr(fileholder, filename, newfile)
yield
setattr(fileholder, filename, orig)

with redirect(sys, 'stdout', open('stdout', 'w')):
...

Note that this really has nothing to do with redirection specifically,
anymore.  It's a general monkey-patching context manager.

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


Re: CSV Reader

2008-02-11 Thread Mike P
Hi Larry,

i'm still getting to grips with python, but rest assured i thinkn it's
better for me to write hte code for learnign purposes

My basic file is here, it comes up with a syntax error on the
startswith line, is this because it is potentially a list?
My idea was to get the lines number where i can see Transaction ID and
then write out everything from this point into a new datafile.

Would a better solution be just to use readlines and search for the
string with a counter and then write out a file from there?

Any help is greatly appreciated

Mike


working_CSV =  "//filer/common/technical/Research/E2C/Template_CSV/
DFAExposureToConversionQueryTool.csv"

import csv
f = file(working_CSV, 'rb')
reader = csv.reader(f)
CSV_lines = ""
for data in reader:
if lines.startswith("Transaction ID")
append.reader.line_num()
# there will only be 1 instance of this title at the start of the CSV
file
writer(Working_csv.csv[, dialect='excel'][, fmtparam])
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >