Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread Laurent Pointal
John Salerno a écrit :
...
> I do, however, think the docs are pretty good, although I sometimes find
> myself just wishing that a function definition was simply laid out in an
> easy to read format that included all of its parameters, so I would know
> exactly what to pass to it (I guess help() is good for this though).


http://www.limsi.fr/Individu/pointal/python/pqrc/


A+

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


Re: Newbie wxpython staticbitmap help please

2006-06-16 Thread jean-michel bain-cornu
Hi,
janama a écrit :
> jean-michel bain-cornu wrote:
>> Why won't you write it yourself using the demo ?
>> It's clear and well documented.
>> Regards,
>> jm
> 
> Hi, have been just trying for 5 hours with the timer demo in wx, i just
> havnt clicked with how to tie it in together,
> 
> I know (think) i need the following features from the timer demo ,
> where you can periodically call a function using the wx.timer
> 
> self.Bind(wx.EVT_TIMER, self.OnTest1Timer)
> #---(bind to the frame ?)
Bind to any method
> 
> self.Bind(wx.EVT_BUTTON, self.OnTest3Start, t3b1)
> #---(this binds to a button, how do i bind to my application on load or
> startup instead ?)
???
> 
> def OnTest1Timer(self, evt):
> self.log.write("got EVT_TIMER event\n")
> #---(dont think i need the logging?)
You don't need of course, it's just for demo information.
> 
> def OnTest3Start(self, evt):
> self.t3 = NotifyTimer(self.log)
> self.t3.Start(1000)
> self.log.write("NotifyTimer timer started\n")
> self.t3b2.Enable()
> 
> #---(the Start i guess i will work if i remap the button event to an on
> load type? event?
> 
> def OnTest3Stop(self, evt):
> self.t3.Stop()
> self.log.write("NotifyTimer timer stoped\n")
> del self.t3
> self.t3b2.Disable()
> #---(Guess i wont need to stop the timer, as i want it to trigger the
> 'refreshing' of the StaticBitmaps ?)
> 
> # When deriving from wx.Timer you must provide a Notify method
> # that will be called when the timer expires.
> class NotifyTimer(wx.Timer):
> def __init__(self, log):
> wx.Timer.__init__(self)
> self.log = log
> 
> def Notify(self):
> self.log.write("got NotifyTimer event\n")
> #---(dont know if i need this if i dont want to use this log feature)?
> 
> 
>  Im sorry if this all seems really amatuerish, i have genuially tried
> hard to get my head around it , but i get error after error in boa.
Boa is well done for editing, simple objects generation, also for 
learning, but not for complex operation. It's not a good idea to use it 
for your present need.
> Somewhone couldnt append a timer and perhaps help to refresh the
> StaticBitmaps described, with the code, in first post). I will be able
> to see and learn greatly from this.
> 
> Maybe some advice on where to find lists of the methods used in
> wxpython
> For example it took me hours to find methods ? like
In the help file, there is an alphabetic classes list, with (quite) all 
the methods.
> 
> StaticBitmap.SetImage("imageName")
> 
> Is there any good lists of these methods, properties etc for wxpython
> controls?
See before. This is the best, and also the demo (and also the sources).
> 
> Any good wxpython ide/editors that can "intellisense" them?  boa,
> komodo, stani's arnt working with "intellisensing" wx for me, (maybe i
> cant configure them though)
The best is probably boa, because it have got a debugger, with a 
separate process launched for testing.
> 
> Thanks for any help with any of this
> 
> Regards
> 
All what you have to do is :
 def __init__(self, parent):
 self._init_ctrls(parent)
 self.t1 = wx.Timer(self)
 self.t1.Start(2000) # 2 seconds
 self.Bind(wx.EVT_TIMER, self.OnTest1Timer)

 def OnTest1Timer(self, evt):
 if os.path.isfile('App1.py'):
 i = wx.Image('image.jpg',wx.BITMAP_TYPE_JPEG)
 b1 = wx.BitmapFromImage(i)
 self.staticBitmap1.SetBitmap(b1)
And you can continue to use Boa as usual.
Hope you'll enjoy,
jm
Ps: tested on xp, pretty sure it works also on linux.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-16 Thread Michele Simionato
Fredrik Lundh wrote:
> BartlebyScrivener wrote:
>
> > Emacs must be dying if this thread could get all the way to 20 with
> > nobody arguing with the vi folks.
>
> hints: 1) editor wars are so last century. 2) emacs has already won.
>
> 

Yep, there is no much point about arguing for Emacs since everything is
already
explained here:  http://www.dina.kvl.dk/~abraham/religion


 Michele Simionato

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread Ant

John Salerno wrote:
> Larry Bates wrote:
>
> > Nope, no Java knowledge necessary.  Jython just compiles Python code
> > to java bytecode instead of python bytecode.  Once it is in java bytecode
> > the JVM doesn't know where it came from.
>
> Well that's good to know. I guess there's not much of a point in writing
> pure Python code with Jython, but at least now I know it works that way!

That's right - but it's very useful for scripting Java (for example in
jEdit) as you have access not only to the Python library, but to the
Java API (which you just use as if they were Python modules).

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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread meyer
Martin,

thanks for the tip, I wasn't fully aware of that. OTOH, though GCC
might be a theoretical alternative, it isn't a practical one for many
situations:

* In a professional environment, it opens up another can of potential
problems, where one would rather like to stay with one single
compiler/build system.
* I suppose Python's distutils have to be tweaked to work with GCC
* The Makefiles/build system will need to be changed to work with the
GCC toolchain
* The different semantics of GCC and Microsoft C often need rewriting
some of the code
* There is no support for MFC/ATL in GCC
* The code created by the Windows GCC is not as good as the one created
by the Microsoft compiler


Markus

Martin v. Löwis wrote:
> [EMAIL PROTECTED] wrote:
> > the problem is not the ABI, but the runtime libraries. From what you're
> > saying, it looks like we will have to standardize on VS2003. As I said,
> > we need to buy VS anyway because of the MFC support. On the other hand,
> > I really worry about all those people that want to build open source
> > extensions for Python 2.5. It is really possible that there will be no
> > legal, free way to do that soon if you don't have an old installation
> > of the 2003 toolkit lying around somewhere...
>
> As others have pointed out already: This is not true. You can build
> Python extensions with GCC just fine; gcc provides an import library
> for msvcr71.dll.
>
> It might be possible to integrate an msvcr71.dll import library
> with VS 2005, in which case you could use VS 2005 to create Python
> extensions as well.
> 
> Regards,
> Martin

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


Re: urllib2 problem with ports.

2006-06-16 Thread Ant

Fredrik Lundh wrote:

> check your proxy configuration.  most likely, your new machine is set up
> to route all requests via a remote proxy.

Here's me looking like a fool :-) The parts of the machine (eg Firefox,
GAIM etc) that I'd set up use a direct connection - it looks like the
guy who'd had the machine before me used a proxy with IE...

> (on windows, you'll find the proxy configuration under "Internet
> Options" - "Connections" - "LAN Settings".  before you do anything else,
> make sure "Bypass proxy server for local addresses" is checked)

Interestingly the "Bypass proxy server for local addresses" was
checked. Anyway, I've changed it to a direct connection, and all seems
well. Thanks.

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread Ant

> > Vim is great if you have a good memory... Otherwise you end up trawling
> > through the help to find out how to do stuff that would in another IDE
> > be just a few menu clicks away.
>
> Mental memory (the painful kind of memory) rapidly turns into muscle
> memory (the fun kind of memory) and all of those mind boggling
> keystrokes begin to feel like an artistic expression reminiscent of
> playing the piano.

That's probably true. I still have a long way to go to get the most out
of vim though, because it takes a certain amount of mental memory to be
able to use the keystrokes often enough to turn them into muscle
memory...

I tend to use gvim on my PC if I'm also working on my server via ssh -
that way it doesn't matter if I type a few ESC :w's or :dd's. Otherwise
I tend to use jEdit.

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


Re: BeautifulSoup error

2006-06-16 Thread Slawomir Nowaczyk
On Fri, 16 Jun 2006 15:20:48 +1000
Ben Finney <[EMAIL PROTECTED]> wrote:

#> > >>> soup = BeautifulSoup()
#> > >>> soup.feed(port)
#> > Traceback (most recent call last):
#> >   File "", line 1, in ?
#> >   File "/usr/lib/python2.3/sgmllib.py", line 94, in feed
#> > self.rawdata = self.rawdata + data
#> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb8 in position 565: 
ordinal not in range(128)
#> > >>>
#> 
#> Uses the default Python text encoding, 'ascii', when it needs to
#> decode the data in 'port' to Unicode. Some of the data in that
#> object makes no sense in the 'ascii' encoding, so it barfs.

In other words, this works for me:

>>> soup.feed( unicode(port,"iso-8859-1") )

-- 
 Best wishes,
   Slawomir Nowaczyk
 ( [EMAIL PROTECTED] )

^[:wq! Crap! Thought I was in vi.

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


Re: list of polynomial functions

2006-06-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Tim Chase
wrote:

> My understanding is that the lambda-defined functions are not 
> called until the actual application thereof, with the
> 
>   mypolys = make_polys(8)
>   mypolys[5](2) #the lambda call happens here, no?

Yes, that's right.

> 's original statement read like a koan...there was more in it 
> than I was getting out of it.  There seem to be several concepts 
> I've not yet wrapped my head around.  My understanding (likely 
> wrong) was that "lambda" was sort of like defining a function 
> inline, along the lines of
> 
>   def f(x):
>   return x+5
> 
> being somewhat equiv to
> 
>   k = lambda x: x+5
> 
> you could then do
> 
>   >>> f(20)
>   25
>   >>> j = f
>   >>> j(20)
>   25
>   >>> k(20)
>   25
>   >>> j = k
>   >>> j(20)
>   25
> 
> There does seem to be some subtle difference, as
> 
>   >>> f
>   
>   >>> k
>at 0xb7d8c0d4>
> 
> "k" clearly knows it's a  just as "f" knows its an "f" 
> (whether asked for by the aliased name or not).

That understanding is mostly correct.  Just that there's no subtile
difference.  `k` doesn't know it's a lambda function, it's just an
ordinary function at this point which happens to have the name ''.
That's somewhat unusual but it behaves like any ``def``-ed function.

> [lightbulb begins to go on...sorta]
> 
> However, in the OP's example, slightly modified, it seems that 
> polys, even when it doesn't exist in the calling scope, it 
> doesn't matter.
> 
>  >>> def mp(n):
> ... p = lambda x: 1
> ... polys = [p]
> ... for i in range(n):
> ... polys.append(lambda x: polys[i](x)*x)
> ... return polys
> ...
>  >>> f = mp(5)
>  >>> polys
> Traceback (most recent call last):
>File "", line 1, in ?
> NameError: name 'polys' is not defined
>  >>> for p in f: print p(3)
> ...
> 1
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 5, in 
> :
> :
> :
> 
> I'm curious why the very first attempt to call p(3) doesn't bomb 
> out with the NameError that "polys" wasn't defined before it even 
> got to the point of attempting to call it.

Well, because `polys` does not exist in the module scope.  But it exists
in the local scope of the functions in `f`.

An example:

 In [2]:def outer(a):
.2.:b = 42
.2.:def inner(c):
.2.:print a, b, c
.2.:print locals()
.2.:
.2.:return inner
.2.:

 In [3]:f = outer(1)

 In [4]:f(2)
 1 42 2
 {'a': 1, 'c': 2, 'b': 42}

If `outer` returns `inner` the inner function still has a reference to the
locals of the enclosing function.  So they won't go away if the outer
function returns.  `a` and `b` are looked up when `f` is called.  That's a
problem if you create more than one function in `outer` and use a name
from outer's locals that changes:

 In [7]:def pitfall():
.7.:functions = list()
.7.:for i in range(3):
.7.:functions.append(lambda: i)
.7.:print 'pitfall: i=%d' % i
.7.:return functions
.7.:

 In [8]:for function in pitfall():
.8.:print function()
.8.:
 pitfall: i=2
 2
 2
 2

At the time the list with the functions is returned `i` is 2.  So if you
call any of the functions it looks up this `i`.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Pycrypto

2006-06-16 Thread luca72
Hello
I have to make an easy operation but reading the pycrypto doc. a never
see AES example
I have to cript this key 'ea523a664dabaa4476d31226a1e3bab0' with the
AES.
Can you help me for make it with pycrypto

Regards Luca

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


Extracting values from text file

2006-06-16 Thread Preben Randhol
Hi

A short newbie question. I would like to extract some values from a
given text file directly into python variables. Can this be done simply
by either standard library or other libraries? Some pointers where to
get started would be much appreciated.

An example text file:
---
Some text that can span some lines.

  Apples 34
  56 Ducks

Some more text.

  0.5 g butter

-
What I first though was if there was possible to make a filter such as:

  Apples (apples)
  (ducks) Ducks
  (butter) g butter

The data can be put in a hash table.

Or maybe there are better ways? I generally want something that is
flexible so one can easily make a filter settings if the text file
format changes.

Thanks in advance

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


pyHook equivalent on Linux ? (mouse and keyboard events without focus)

2006-06-16 Thread learner404
Hello,

I have a Windows Pyhon-Tk app which need to capture mouse end keyboard
events even when the app is not in focus.

On Windows so far I've used the excellent PyHook which does the job
perfectly:

" The pyHook library wraps the low-level mouse and keyboard hooks in
the Windows Hooking API for use in Python applications."
http://www.cs.unc.edu/~parente/tech/tr08.shtml

Is there something similar on Linux (I'm using Ubuntu/Kubuntu) ?

Should I go down down to the Windows Manager ? Can my Python-Tkinter
app communicate with KDE or Gnome to know and use these events ?

Any suggestions/leads would me much appreciated. :)

learner404

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread Sergei Organov
John Salerno <[EMAIL PROTECTED]> writes:
> I know there's a request for a good IDE at least once a week on the ng, 
> but hopefully this question is a little different. I'm looking for 
> suggestions for a good cross-platform text editor (which the features 
> for coding, such as syntax highlighting, etc.) but not a full IDE with 
> all the fancy jazz (GUI developer, UML diagrams, etc.).
>
> Ideally, it would be something I could even put on a flash drive and 
> move from computer to computer, but this isn't necessary. Just something 
> I can immediately use in either Windows or Linux (or Mac, if
> necessary).

These days one can put entire OS to a flash drive, not only an editor.

[...]

> And naturally there are Emacs and Vim, but I just don't know if I need 
> to invest *that* much time into learning one of them (probably Vim, 
> since I hear it's lighter and faster).

>From this thread you can easily see that people that never look for
another editor are either Emacs or Vim users. I think you have two
options here: either spend some time to master one of them, or spend the
rest of your life looking for a good editor ;)

[I compose this reply in XEmacs, yes]

-- 
Sergei.

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Torben Ægidius Mogensen
Raffael Cavallaro <[EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com> writes:

> On 2006-06-14 16:36:52 -0400, Pascal Bourguignon <[EMAIL PROTECTED]> said:
> 
> > In lisp, all lists are homogenous: lists of T.
> 
> CL-USER 123 > (loop for elt in (list #\c 1 2.0d0 (/ 2 3)) collect
> (type-of elt))
> (CHARACTER FIXNUM DOUBLE-FLOAT RATIO)
> 
> i.e., "heterogenous" in the common lisp sense: having different
> dynamic types, not in the H-M sense in which all lisp values are of
> the single union type T.

What's the difference?  Dynamically types values _are_ all members of
a single tagged union type.  The main difference is that the tages
aren't always visible and that there are only a fixed, predefined
number of them.

Torben

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


getting umask without changing it

2006-06-16 Thread Faik Uygur
Is there a python way of getting the current umask without changing it?
os.umask changes it, and i dont want to use os.system("umask")

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Torben Ægidius Mogensen
Pascal Costanza <[EMAIL PROTECTED]> writes:

> Torben Ægidius Mogensen wrote:
> 
> > On a similar note, is a statically typed langauge more or less
> > expressive than a dynamically typed language?  Some would say less, as
> > you can write programs in a dynamically typed language that you can't
> > compile in a statically typed language (without a lot of encoding),
> > whereas the converse isn't true.
> 
> It's important to get the levels right here: A programming language
> with a rich static type system is more expressive at the type level,
> but less expressive at the base level (for some useful notion of
> expressiveness ;).
> 
> > However, I think this is misleading,
> > as it ignores the feedback issue: It takes longer for the average
> > programmer to get the program working in the dynamically typed
> > language.
> 
> This doesn't seem to capture what I hear from Haskell programmers who
> say that it typically takes quite a while to convince the Haskell
> compiler to accept their programs. (They perceive this to be
> worthwhile because of some benefits wrt correctness they claim to get
> in return.)

That's the point: Bugs that in dynamically typed languages would
require testing to find are found by the compiler in a statically
typed language.  So whil eit may take onger to get a program thatgets
past the compiler, it takes less time to get a program that works.

Torben

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


Re: Extracting values from text file

2006-06-16 Thread MTD
list.txt is a file that contains the following lines:
Apples 34
Bananas 10
Oranges 56

>>> file = open("list.txt","r")
>>> mystring = file.read()
>>> mystring
'Apples 34 \nBananas 10\nOranges 56 '
>>> mylist = mystring.split('\n')
>>> mylist
['Apples 34 ', 'Bananas 10', 'Oranges 56 ']
>>> mydict = {}
>>> for el in mylist:
... l = el.split()
... mydict[l[0]] = l[1]
...
>>> mydict
{'Apples': '34', 'Oranges': '56', 'Bananas': '10'}
>>> mydict["Apples"]
'34'
>>> mydict["Oranges"]
'56'

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


Re: Extracting values from text file

2006-06-16 Thread bearophileHUGS
First try, probably there are better ways to do it, and it's far from
resilient, it breaks in lot of different ways (example: more than one
number in one line, number with text on both sides of the line, etc.)
I have divided the data munging in many lines so I can see what's
happening, and you can fix/modify the code quikly.

Bye,
bearophile


data1 = """
 Some text that can span some lines.
More text
  Apples 34
  56 Ducks

Some more text.

  0.5 g butter
"""

import re
# Separate lines in a list
data2 = data1.split("\n")
print data2, "\n"

# clear lines from trailing and leading spaces, newlines, etc.
data3 = map(str.strip, data2)
print data3, "\n"

# remove blank lines after the stripping
data4 = filter(None, data3)
print data4, "\n"

# create a list of (lines, numbers) of only the lines with a number
inside
patt1 = re.compile("\d+\.?\d*") # No scientific notation
data5 = [(line, n) for line in data4 for n in patt1.findall(line)]
print data5, "\n"

# remove the number from the lines, and strip such lines
data6 = [(line.replace(num, "").strip(), num) for line, num in data5]
print data6, "\n"

def nconv(num):
"To convert a number to an int, and if not possible to a float"
try:
result = int(num)
except ValueError:
result = float(num)
return result

# convert the number strings into ints or floats
data7 = [(line, nconv(num)) for line, num in data6]
print data7, "\n"

# build the final dict of (line: number)
result = dict(data7)
print result, "\n"

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Joachim Durchholz
Raffael Cavallaro schrieb:
> On 2006-06-14 15:04:34 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:
> 
>> Um... heterogenous lists are not necessarily a sign of expressiveness. 
>> The vast majority of cases can be transformed to homogenous lists 
>> (though these might then contain closures or OO objects).
>>
>> As to references to nonexistent functions - heck, I never missed 
>> these, not even in languages without type inference :-)
>>
>> [[snipped - doesn't seem to relate to your answer]]
> 
> This is a typical static type advocate's response when told that users 
> of dynamically typed languages don't want their hands tied by a type 
> checking compiler:
> 
> "*I* don't find those features expressive so *you* shouldn't want them."

And this is a typical dynamic type advocate's response when told that 
static typing has different needs:

"*I* don't see the usefulness of static typing so *you* shouldn't want 
it, either."

No ad hominem arguments, please. If you find my position undefendable, 
give counterexamples.
Give a heterogenous list that would to too awkward to live in a 
statically-typed language.
Give a case of calling nonexistent functions that's useful.
You'll get your point across far better that way.

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


Noob script needs some input: CVS PatchMaker

2006-06-16 Thread Holger
I needed a tool for extracting patches from CVS based on the log
messages. I.e. we mark our fixes and features with a "Bugdb XYZ"
And sometimes you need to move a fix/feature to another branch or maybe
you just want to inspect exactly what changes were related to a
specific bugdb issue.

Now I've searched hi and low for this and I now it's out there
somewhere bleeding obvious - can't imagine I'm the first to have this
thought. I just haven't been able to find it...
Well, that was an excellent opportunity to get some python practice, so
below is my first shot at the problem.

Any feedback on what would be "the pythonic way" to do this would be
much appreciated!

Usage:
cd myproject
patchmaker 

Ouput is a diff of involved files+revs


Thank you,
/Holger
--
#!/usr/bin/env python
# Copyright 2006 Holger Lindeberg Bille

import sys, re, os
import popen2

workingfile = re.compile("^Working file: *(.*)$")
revision= re.compile("^revision *(.*)$")
fileend =
re.compile("^===")
details = re.compile("^date: *")
entryend= re.compile("^")
branches= re.compile("^branches:( *(.*);)*")

class LogEntry:
def __init__(self):
self.rev = 0
self.prevrev = 0
self.text = []

def setName(self, name):
self.name = name

def read(self, file):
done = 0
for line in file:
regx = details.search(line)
if regx:
pass
else:
if entryend.search(line):
break
else:
if fileend.search(line):
done = 1
break
else:
self.text.append(line.strip())
return done

def GuessPrevRev(self):
pass

def filter(self, filter):
found = 0
for line in self.text:
if filter.search(line):
found = 1
break
return found

def calcPrevRev(self):
# todo: get this from CVS instead of guessing
self.rev = "1.1"
self.prevrev = "1.1"
ver = self.name.split(".")
n = int(ver.pop()) - 1
while len(ver) >= 1:
if n >= 1:
ver.append(str(n))
self.prevrev = ".".join(ver)
self.rev = self.name
break
else:
ver.pop() # throw this away
n = int(ver.pop())

def patchDump(self, file):
cmd = "cvs -q diff -u -b -r %s -r %s %s" % (self.prevrev,
self.rev, file)
# print cmd
outp, inp = popen2.popen2(cmd)
for line in outp:
print line,
outp.close()
inp.close()

def dump(self):
print "--"
print "rev = %s" % self.name
for line in self.text:
print line


class FileLog:
def __init__(self):
self.revs = []

def setName(self, name):
self.name = name

def read(self, file):
for line in file:
regx = revision.search(line)
if regx:
rev = LogEntry()
rev.setName(regx.group(1))
done = rev.read(file)
self.revs.append(rev)
if done:
break

def filter(self, filter):
found = 0
newrevs = []
for rev in self.revs:
if rev.filter(filter):
found = 1
newrevs.append(rev)
self.revs = newrevs
return found

def calcPrevRev(self):
for rev in self.revs:
rev.calcPrevRev()

def patchDump(self):
for rev in self.revs:
rev.patchDump(self.name)

def dump(self):
print "File = %s" % self.name
print "No. of revs %d" % len(self.revs)
for rev in self.revs:
rev.dump()
print "==="



class LogDB:
def __init__(self):
self.flogs = []

def read(self):
outp, inp = popen2.popen2('cvs -q log -N')
found = 0
for line in outp:
regx = workingfile.search(line)
if regx:
flog = FileLog()
flog.setName(regx.group(1))
flog.read(outp)
self.flogs.append(flog)
outp.close()
inp.close()

def filter(self, filter):
newflogs = []
for flog in self.flogs:
if flog.filter(filter):
newflogs.append(flog)
self.flogs = newflogs

def calcPrevRev(self):
for flog in self.flogs:
flog.calcPrevRev()

def patchDump(self):
for flog in self.flogs:
flog.patchDump()

Re: Extracting values from text file

2006-06-16 Thread MTD
P.S.

>>> file.close()

MTD wrote:
> list.txt is a file that contains the following lines:
> Apples 34
> Bananas 10
> Oranges 56
>
> >>> file = open("list.txt","r")
> >>> mystring = file.read()
> >>> mystring
> 'Apples 34 \nBananas 10\nOranges 56 '
> >>> mylist = mystring.split('\n')
> >>> mylist
> ['Apples 34 ', 'Bananas 10', 'Oranges 56 ']
> >>> mydict = {}
> >>> for el in mylist:
> ...   l = el.split()
> ...   mydict[l[0]] = l[1]
> ...
> >>> mydict
> {'Apples': '34', 'Oranges': '56', 'Bananas': '10'}
> >>> mydict["Apples"]
> '34'
> >>> mydict["Oranges"]
> '56'

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


Re: getting umask without changing it

2006-06-16 Thread Fredrik Lundh
Faik Uygur wrote:

> Is there a python way of getting the current umask without changing it?
> os.umask changes it, and i dont want to use os.system("umask")

just call os.umask twice:

current_mask = os.umask(0)
os.umask(current_mask)

 



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


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread Ant
> No, I learned it because Perl was too dirty and Java to complicated.
> Now it is part of my daily job.

Ditto. I was fed up of writing, compiling and running a java
application just in order to do a quick script. I'd used perl, but
quite frankly perl's a ridiculous language. Ruby looked promising, but
perl had already poisoned my mind against the syntax... Python was
clean, object oriented if you want it, and mature.

> > Also, how did you go about learning it?
>
> Programming, reading this newsgroup, reading the python cookbook,
> reading python source files of the standard library.

> > Are there still some things you feel you need to learn or improve?

I feel like I've got a pretty good grasp of the core language now, but
there's always something that pops up in the group that I find I've not
dabbled in (such as the itertools, which I discovered on the group last
week(?) and have been using to great effect already!).

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Pascal Costanza
Torben Ægidius Mogensen wrote:
> Raffael Cavallaro <[EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com> writes:
> 
>> On 2006-06-14 16:36:52 -0400, Pascal Bourguignon <[EMAIL PROTECTED]> said:
>>
>>> In lisp, all lists are homogenous: lists of T.
>> CL-USER 123 > (loop for elt in (list #\c 1 2.0d0 (/ 2 3)) collect
>> (type-of elt))
>> (CHARACTER FIXNUM DOUBLE-FLOAT RATIO)
>>
>> i.e., "heterogenous" in the common lisp sense: having different
>> dynamic types, not in the H-M sense in which all lisp values are of
>> the single union type T.
> 
> What's the difference?  Dynamically types values _are_ all members of
> a single tagged union type.

Yes, but that's mostly a meaningless statement in a dynamically typed 
language. In a dynamically typed language, you typically don't care 
about the static types.

> The main difference is that the tages
> aren't always visible and that there are only a fixed, predefined
> number of them.

Depending on the language, the number of "tags" is not fixed.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pb console Effbot

2006-06-16 Thread Fredrik Lundh
"Méta-MCI" wrote:

> I installed the Console of EFFBOT (http://effbot.org/downloads/#console).
> It functions well. It's a very fun/friendly tool.
>
> Except a detail: when I send (by console.write()) more than 53200 characters, 
> it does not occur 
> anything.
> I circumvented the problem, with a loop which sends ranges of 5 
> characters.
>
> But, I would like to know if somebody already encountered this problem.

it's probably some (undocumented) limitation in the Windows Console API
(possibly combined with some sloppy error checking in console.write).

I'll add it to the TODO list...

 



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

Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Pascal Costanza
Torben Ægidius Mogensen wrote:
> Pascal Costanza <[EMAIL PROTECTED]> writes:
> 
>> Torben Ægidius Mogensen wrote:
>>
>>> On a similar note, is a statically typed langauge more or less
>>> expressive than a dynamically typed language?  Some would say less, as
>>> you can write programs in a dynamically typed language that you can't
>>> compile in a statically typed language (without a lot of encoding),
>>> whereas the converse isn't true.
>> It's important to get the levels right here: A programming language
>> with a rich static type system is more expressive at the type level,
>> but less expressive at the base level (for some useful notion of
>> expressiveness ;).
>>
>>> However, I think this is misleading,
>>> as it ignores the feedback issue: It takes longer for the average
>>> programmer to get the program working in the dynamically typed
>>> language.
>> This doesn't seem to capture what I hear from Haskell programmers who
>> say that it typically takes quite a while to convince the Haskell
>> compiler to accept their programs. (They perceive this to be
>> worthwhile because of some benefits wrt correctness they claim to get
>> in return.)
> 
> That's the point: Bugs that in dynamically typed languages would
> require testing to find are found by the compiler in a statically
> typed language.

Yes. However, unfortunately statically typed languages also reject 
programs that don't have such bugs. It's a tradeoff whether you want to 
spend time to deal with them or not.

> So whil eit may take onger to get a program thatgets
> past the compiler, it takes less time to get a program that works.

That's incorrect. See http://haskell.org/papers/NSWC/jfp.ps - especially 
Figure 3.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-16 Thread mystilleef
On linux, I recommend Scribes. It's simple, slim and sleek, yet
powerful.

Features:

Automatic completion
Automatic bracket completion and smart insertion
Snippets (ala TextMate)
Bookmarks
Syntax highlight for more than 30 languages
Launches faster than any IDE out their
Has no learning curve.
Features your typical text processing operations you'll find in
VIM/Emacs.
Remembers window position and size.
Sexy interface that actually adheres to human interface guidlines
And many more...

The next version will even feature remote editing.

website: ( http://scribes.sourceforge.net/ )
Flash Demo: ( http://scribes.sourceforge.net/snippets.htm )
GIF Demo: ( http://www.minds.may.ie/~dez/images/blog/scribes.html )




John Salerno wrote:
> I know there's a request for a good IDE at least once a week on the ng,
> but hopefully this question is a little different. I'm looking for
> suggestions for a good cross-platform text editor (which the features
> for coding, such as syntax highlighting, etc.) but not a full IDE with
> all the fancy jazz (GUI developer, UML diagrams, etc.).
>
> Ideally, it would be something I could even put on a flash drive and
> move from computer to computer, but this isn't necessary. Just something
> I can immediately use in either Windows or Linux (or Mac, if necessary).
>
> Based on another thread, I tried out Scite, but no matter what I do it
> doesn't seem to remember the window size and position, or any options I
> choose (like showing line numbers). It seems to always reset itself each
> time I open it.
>
> And naturally there are Emacs and Vim, but I just don't know if I need
> to invest *that* much time into learning one of them (probably Vim,
> since I hear it's lighter and faster).
>
> I've tried a few others, like TextPad and Crimson, and right now I use
> UltraEdit, which I love actually, except for minor issues here and
> there. But it'd be nice to make the move, as much as possible, to free,
> open-source, cross-platform software.
>
> Thanks for any suggestions, and again I'm sorry if this feels like the
> same question as usual (it's just that in my case, I'm not looking for
> something like SPE, Komodo, Eric3, etc. right now).

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Sacha

"Joachim Durchholz" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Raffael Cavallaro schrieb:
>> On 2006-06-14 15:04:34 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:
>>
>>> Um... heterogenous lists are not necessarily a sign of expressiveness. 
>>> The vast majority of cases can be transformed to homogenous lists 
>>> (though these might then contain closures or OO objects).
>>>
>>> As to references to nonexistent functions - heck, I never missed these, 
>>> not even in languages without type inference :-)
>>>
>>> [[snipped - doesn't seem to relate to your answer]]
>>
> Give a heterogenous list that would to too awkward to live in a 
> statically-typed language.

Many lists are heterogenous, even in statically typed languages.
For instance lisp code are lists, with several kinds of atoms and 
sub-lists..
A car dealer will sell cars, trucks and equipment..
In a statically typed language you would need to type the list on a common 
ancestor...
What would then be the point of statical typing , as you stilll need to type 
check
each element in order to process that list ? Sure you can do this in a 
statically-typed
language, you just need to make sure some relevant ancestor exists. In my 
experience
you'll end up with the base object-class more often than not, and that's 
what i call
dynamic typing.

> Give a case of calling nonexistent functions that's useful.

I might want to test some other parts of my program before writing this 
function.
Or maybe will my program compile that function depending on user input.
As long as i get a warning for calling a non-existing function, everything 
is fine.

Sacha 


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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread Antoon Pardon
Op 2006-06-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> [EMAIL PROTECTED] wrote:
>
>> I'm not sure how that backs the point you made. Infact, you're saying
>> that people accepted that Python 2.4 was compiled with VS2003 because
>> VC6 could not longer be bought. How is that different from the current
>> situation where the VS2003 toolkit cannot longer be downloaded and it
>> is at least becoming increasingly difficult to buy versions of VS2003?
>> You also seem to imply that there is a large group of people that want
>> you to stay with VS2003 for compiling Python 2.5.
>
> what part of "Python 2.4 is built with VC2003 and everyone who's ever 
> built Windows stuff for Python 2.4 already has it" do you have trouble 
> understanding ?

What about new people who would be interested in building Window stuff
for Python? If I understand the situation correctly, people who
want to take up, writing C-extentions on windows now, may not be able to
do so, because they can't find a compatible compilor for the moment.

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


Re: getting umask without changing it

2006-06-16 Thread Faik Uygur
Cuma 16 Haziran 2006 12:48 tarihinde, Fredrik Lundh şunları yazmıştı: 
> Faik Uygur wrote:
> > Is there a python way of getting the current umask without changing it?
> > os.umask changes it, and i dont want to use os.system("umask")
>
> just call os.umask twice:
> current_mask = os.umask(0)

This is not atomic. At this point i changed all the running python threads' 
umask and i don't want to change current umask. I just want to get it.

> os.umask(current_mask)

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

Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Hendrik Maryns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Sacha schreef:
> "Joachim Durchholz" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Raffael Cavallaro schrieb:
>>> On 2006-06-14 15:04:34 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:
>>>
 Um... heterogenous lists are not necessarily a sign of expressiveness. 
 The vast majority of cases can be transformed to homogenous lists 
 (though these might then contain closures or OO objects).

 As to references to nonexistent functions - heck, I never missed these, 
 not even in languages without type inference :-)

 [[snipped - doesn't seem to relate to your answer]]
>> Give a heterogenous list that would to too awkward to live in a 
>> statically-typed language.
> 
> Many lists are heterogenous, even in statically typed languages.
> For instance lisp code are lists, with several kinds of atoms and 
> sub-lists..
> A car dealer will sell cars, trucks and equipment..
> In a statically typed language you would need to type the list on a common 
> ancestor...
> What would then be the point of statical typing , as you stilll need to type 
> check
> each element in order to process that list ? Sure you can do this in a 
> statically-typed
> language, you just need to make sure some relevant ancestor exists. In my 
> experience
> you'll end up with the base object-class more often than not, and that's 
> what i call
> dynamic typing.

In my experience you won’t.  I almost never have a List (Java),
and when I have one, I start thinking on how I can improve the code to
get rid of it.

H.
- --
Hendrik Maryns

==
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEkofme+7xMGD3itQRAo0XAJ9DiG228ZKMLX8JH+u9X+6YGEHwgQCdH/Jn
kC/F/b5rbmUvUzKYIv8agis=
=iuV0
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: getting umask without changing it

2006-06-16 Thread Fredrik Lundh
Faik Uygur wrote:
> This is not atomic. At this point i changed all the running python threads'
> umask and i don't want to change current umask. I just want to get it.

afaik, there's no atomic API for this.  just a unified get/set function:

http://www.opengroup.org/pubs/online/7908799/xsh/umask.html

 



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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Rob Thorpe
Torben Ægidius Mogensen wrote:
> Pascal Costanza <[EMAIL PROTECTED]> writes:
>
> > Torben Ægidius Mogensen wrote:
> >
> > > On a similar note, is a statically typed langauge more or less
> > > expressive than a dynamically typed language?  Some would say less, as
> > > you can write programs in a dynamically typed language that you can't
> > > compile in a statically typed language (without a lot of encoding),
> > > whereas the converse isn't true.
> >
> > It's important to get the levels right here: A programming language
> > with a rich static type system is more expressive at the type level,
> > but less expressive at the base level (for some useful notion of
> > expressiveness ;).
> >
> > > However, I think this is misleading,
> > > as it ignores the feedback issue: It takes longer for the average
> > > programmer to get the program working in the dynamically typed
> > > language.
> >
> > This doesn't seem to capture what I hear from Haskell programmers who
> > say that it typically takes quite a while to convince the Haskell
> > compiler to accept their programs. (They perceive this to be
> > worthwhile because of some benefits wrt correctness they claim to get
> > in return.)
>
> That's the point: Bugs that in dynamically typed languages would
> require testing to find are found by the compiler in a statically
> typed language.  So whil eit may take onger to get a program thatgets
> past the compiler, it takes less time to get a program that works.

In my experience the opposite is true for many programs.
Having to actually know the precise type of every variable while
writing the program is not necessary, it's a detail often not relevant
to the core problem. The language should be able to take care of
itself.

In complex routines it can be useful for the programmer to give types
and for the compiler to issue errors when they are contradicted.  But
for most routines it's just an unnecessary chore that the compiler
forces on the programmer.

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


Re: Newbie wxpython staticbitmap help please

2006-06-16 Thread janama
Thanks Jean this now makes sense, really appreciate your time and
effort mate.

def __init__(self, parent):
self._init_ctrls(parent)
self.t1 = wx.Timer(self)
self.t1.Start(2000) # 2 seconds
self.Bind(wx.EVT_TIMER, self.OnTest1Timer)

self.OnTest1Timer(self)

def OnTest1Timer(self, evt):

if os.path.isfile('images/page1.txt'):
  print "ok file present"
  i = wx.Image('images/pageGreen.png',wx.BITMAP_TYPE_PNG)
  b1 = wx.BitmapFromImage(i)
  self.staticBitmap1.SetBitmap(b1)
else:
  print "ok file present"
  i = wx.Image('images/pageGrey.png',wx.BITMAP_TYPE_PNG)
  b1 = wx.BitmapFromImage(i)
  self.staticBitmap1.SetBitmap(b1)

The above works a treat,

thanks again Jean

janama

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


Re: getting umask without changing it

2006-06-16 Thread Faik Uygur
Cuma 16 Haziran 2006 13:41 tarihinde, Fredrik Lundh şunları yazmıştı: 
> afaik, there's no atomic API for this.  just a unified get/set function:
>
>     http://www.opengroup.org/pubs/online/7908799/xsh/umask.html

Oops. :( Thanks for the help.

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

Re: BeautifulSoup error

2006-06-16 Thread William Xu
Ben Finney <[EMAIL PROTECTED]> writes:

> William Xu <[EMAIL PROTECTED]> writes:
>
>> >>> import urllib
>> >>> from BeautifulSoup import BeautifulSoup
>> >>> url = 'http://www.google.com'
>> >>> port = urllib.urlopen(url).read()
>
> Gets the data from the HTTP response. (I'm not sure why you call this
> "port".) The data is HTML text encoded to a string of bytes according
> to the character encoding specified in the response header fields.

i thought we can read and write to a port, like port in scheme. :-)

[...]

> Get the character encoding specified in the HTTP response, and decode
> the data to Unicode from that encoding.

How can i do this? i'm afraid i can't figure it out in the manual..

-- 
William

I just uploaded xtoolplaces-1.6. It fixes all bugs but one: It still
coredumps instead of doing something useful.  The upstream author's
e-mail address bounces, Redhat doesn't provide it and I never used it.
-- Sven Rudolph <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup error

2006-06-16 Thread Ben Finney
Slawomir Nowaczyk <[EMAIL PROTECTED]> writes:

> >>> soup.feed( unicode(port,"iso-8859-1") )

Sure, once you have the encoding name. Visit a different URL, you may
get a different encoding which should be used.

-- 
 \   "I believe in making the world safe for our children, but not |
  `\our children's children, because I don't think children should |
_o__)  be having sex."  -- Jack Handey |
Ben Finney

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


Unimporting modules, memory leak?

2006-06-16 Thread Antonio Arauzo Azofra

Hello everybody,

Probably, this is being too demanding for Python, but it may be
useful to unimport modules to work with dynamic code (though not the
best, one example is [2]). In fact, it is supposed to be possible[1],
but I have detected it usually leaks memory.

When unimported in Linux, the simple C module attached (has no
functions, just the structure) leaks two memory pages

To see the test you can just put the files in a directory and:
python setupmod1.py install --install-lib .
python testMemory.py

Its output follows. First, the memory used before import. Second memory
used after the import. Third the number of references to that object is
checked before using del. Finally the memory used after unimporting.

-- Testing mod1 --
Mem. used: 1242 (gc: 0 )
Mem. used: 1244 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1244 (gc: 0 )
-- Testing bigModule --
Mem. used: 1244 (gc: 0 )
Mem. used: 2686 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1244 (gc: 0 )
-- Testing random --
Mem. used: 1244 (gc: 0 )
Mem. used: 1256 (gc: 0 )
Check refs (should be = 2): 2
Mem. used: 1256 (gc: 57 )

Unimporting attached "bigmodule.py" there are no memory leaks.
Unimporting python's random module it leaks some pages, but garbage
collector admit it can not free them.

If a module with the same name that the unimported module is imported,
the pages are reused. While, if this same module is loaded with another
name, they are not freed, and the program grows with each module
imported/unimported

Is this a Python bug? A Linux bug? Am i missing some way of freeing that
memory used by C module?

[1] http://mail.python.org/pipermail/python-list/1999-May/002669.html
[2] http://ax5.com/antonio/orangesnns
--
All the best,
Antonio Arauzo Azofra



def funcion_de_prueba(a,b):
  print a,b

big_list = []
for i in xrange(1000):
big_list.append(1000 * 'bg')



from distutils.core import setup, Extension

module1 = Extension('mod1',
  sources = ['srcmod1.c'])

setup (name = 'OrangeSNNStmp',
 version = '1.0',
 description = 'Function that calls a trained NN',
 ext_modules = [module1])


#include 

static PyMethodDef orangeSnnsTmpMethods[] = {
{NULL, NULL, 0, NULL}/* Sentinel */
};

PyMODINIT_FUNC
initmod1(void)
{
(void) Py_InitModule("mod1", orangeSnnsTmpMethods);
}


#
# Test memory comsumption importing and unimporting modules
#
import gc, os, sys

def printMemoryUse():
  rgc = gc.collect()
  f = open("/proc/" + str(os.getpid()) + "/statm")
  totalMemorySize = f.readline().split()[0]
  f.close()
  print "Mem. used:", totalMemorySize, "(gc:", rgc, ")"

def testImport(moduleName):
  print "-- Testing", moduleName, "--"
  printMemoryUse()

  module = __import__(moduleName, globals(), locals())
  printMemoryUse()

  del sys.modules[moduleName]
  print "Check refs (should be = 2):", sys.getrefcount(module)
  del module
  printMemoryUse()


testImport("mod1")
testImport("bigModule")
testImport("random")








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

Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Torben Ægidius Mogensen
Pascal Costanza <[EMAIL PROTECTED]> writes:

> Torben Ægidius Mogensen wrote:

> > So while it may take longer to get a program that gets
> > past the compiler, it takes less time to get a program that works.
> 
> That's incorrect. See http://haskell.org/papers/NSWC/jfp.ps -
> especially Figure 3.

There are many other differences between these languages than static
vs. dynamic types, and some of these differences are likely to be more
significant.  What you need to test is langauges with similar features
and syntax, except one is statically typed and the other dynamically
typed.

And since these languages would be quite similar, you can use the same
test persons: First let one half solve a problem in the statically
typed language and the other half the same problem in the dynamically
typed language, then swap for the next problem.  If you let a dozen
persons each solve half a dozen problems, half in the statically typed
language and half in the dynamically typed language (using different
splits for each problem), you might get a useful figure.

Torben

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


Re: Extracting values from text file

2006-06-16 Thread Ant
> What I first though was if there was possible to make a filter such as:
>
>   Apples (apples)
>   (ducks) Ducks
>   (butter) g butter

Try something like:

import re

text = """> Some text that can span some lines.

   Apples 34
   56 Ducks

 Some more text.

"""

filters = {"apples": re.compile(r"Apples\s+(\d+)"),
 "ducks": re.compile(r"(\d+)\s+Ducks"),
 "butter": re.compile(r"([0-9.]+)\s+g\s+butter")}

out = []

for k,v in filters.iteritems():
matches = v.findall(text)
for match in matches:
out.append((k, match))

print out

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


Re: Pycrypto

2006-06-16 Thread [EMAIL PROTECTED]
luca72 wrote:
> Hello
> I have to make an easy operation but reading the pycrypto doc. a never
> see AES example
> I have to cript this key 'ea523a664dabaa4476d31226a1e3bab0' with the
> AES.
> Can you help me for make it with pycrypto
>
> Regards Luca

You can do this as follows:

py> from Crypto.Cipher import AES
py> # key has to be 16, 24 or 32 bytes for AES
py> crypt = AES.new('abcdefghijklmnop', AES.MODE_ECB)
# we're lucky, the string to encrypt is a multiple of 16 in length
py> txt = 'ea523a664dabaa4476d31226a1e3bab0'
py> c = crypt.encrypt(txt)
py> c
'w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa\xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\xb9'
py> crypt.decrypt(c)
'ea523a664dabaa4476d31226a1e3bab0'

see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
to encrypt data which has not a multiple of length 16 you have to pad
it e.g. with spaces, and then strip the decrypt() result.

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Torben Ægidius Mogensen
"Rob Thorpe" <[EMAIL PROTECTED]> writes:

> Torben Ægidius Mogensen wrote:

> > That's the point: Bugs that in dynamically typed languages would
> > require testing to find are found by the compiler in a statically
> > typed language.  So whil eit may take onger to get a program thatgets
> > past the compiler, it takes less time to get a program that works.
> 
> In my experience the opposite is true for many programs.
> Having to actually know the precise type of every variable while
> writing the program is not necessary, it's a detail often not relevant
> to the core problem. The language should be able to take care of
> itself.
> 
> In complex routines it can be useful for the programmer to give types
> and for the compiler to issue errors when they are contradicted.  But
> for most routines it's just an unnecessary chore that the compiler
> forces on the programmer.

Indeed.  So use a language with type inference.

Torben

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


Re: Pycrypto

2006-06-16 Thread Laszlo Nagy

> You can do this as follows:
>
> py> from Crypto.Cipher import AES
> py> # key has to be 16, 24 or 32 bytes for AES
> py> crypt = AES.new('abcdefghijklmnop', AES.MODE_ECB)
> # we're lucky, the string to encrypt is a multiple of 16 in length
> py> txt = 'ea523a664dabaa4476d31226a1e3bab0'
> py> c = crypt.encrypt(txt)
> py> c
> 'w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa\xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\xb9'
> py> crypt.decrypt(c)
> 'ea523a664dabaa4476d31226a1e3bab0'
>
> see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
> to encrypt data which has not a multiple of length 16 you have to pad
> it e.g. with spaces, and then strip the decrypt() result.
>   
Or use CBC mode? I'm not familiar with pycrypto but I know that CBC mode 
can crypt/decrypt text with any size.

  Laszlo


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


Re: Video capture from webcam on Mac?

2006-06-16 Thread Diez B. Roggisch
Joseph Chase schrieb:
> Is there a cross-platform solution for video capture from a webcam?
> 
> I am aware of the Win32 videocapture library, but am unaware of how to 
> accomplish the same functionality on the Mac side.


You could try and make OpenCV work - it has a part called anygui that 
allows that, and has python-bindings.

Alternatively, you could utilize the ToxicFramework from pyobjc, when 
running on a mac.

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


Re: Video capture from webcam on Mac?

2006-06-16 Thread faulkner
gstreamer has python bindings.
http://gstreamer.net/

Joseph Chase wrote:
> Is there a cross-platform solution for video capture from a webcam?
>
> I am aware of the Win32 videocapture library, but am unaware of how to
> accomplish the same functionality on the Mac side.
> 
> Thanks in advance.

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Dr.Ruud
Torben Ægidius Mogensen schreef:

> Bugs that in dynamically typed languages would
> require testing to find are found by the compiler in a statically
> typed language.  So whil[e ]it may take [l]onger to get a program
that[ ]
> gets past the compiler, it takes less time to get a program that
works.

If it were that simple, I would say: compile time type inference is the
only way to go.

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Re: Pycrypto

2006-06-16 Thread [EMAIL PROTECTED]

Laszlo Nagy wrote:
> > You can do this as follows:
> >
> > py> from Crypto.Cipher import AES
> > py> # key has to be 16, 24 or 32 bytes for AES
> > py> crypt = AES.new('abcdefghijklmnop', AES.MODE_ECB)
> > # we're lucky, the string to encrypt is a multiple of 16 in length
> > py> txt = 'ea523a664dabaa4476d31226a1e3bab0'
> > py> c = crypt.encrypt(txt)
> > py> c
> > 'w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa\xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\xb9'
> > py> crypt.decrypt(c)
> > 'ea523a664dabaa4476d31226a1e3bab0'
> >
> > see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
> > to encrypt data which has not a multiple of length 16 you have to pad
> > it e.g. with spaces, and then strip the decrypt() result.
> >
> Or use CBC mode? I'm not familiar with pycrypto but I know that CBC mode
> can crypt/decrypt text with any size.
>
>   Laszlo

Not in this implementation:
py> from Crypto.Cipher import AES
py> crypt = AES.new('abcdefghijklmnop', AES.MODE_CBC)
py> c = crypt.encrypt('1')
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: Input strings must be a multiple of 16 in length

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


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread André
John Salerno wrote:
> So out of curiosity, I'm just wondering how everyone else came to learn
> it. If you feel like responding, I'll ask my questions for easy quoting:
>
> Did you have to learn it for a job?

No.  My job is purely administrative; I have absolutely no need to do
any programming.  I had done a *small* amount of programming (fortran,
C)  while studying Physics and wrote a few simple Java applets while
teaching Physics.

>
> Or did you just like what you saw and decided to learn it for fun?

More or less. In the summer of 2004 I felt I needed a hobby.  I also
thought I should introduce my kids to something useful about computers.
 I decided to combine both goals.
I started writing an html tutorial for my kids and, while surfing the
net for helpful resources, saw a few independent references to Python.
Curious, I downloaded it just to see what it was like and, after trying
a few things, I decided to forget about the html tutorial and proceeded
to write one on Python for my kids, following more or less a
traditional (boring) approach.

> Also, how did you go about learning it? (i.e., like I described above, I
> started with the main stuff then moved on to the different available
> frameworks)

Having taught Physics for a number of years, I realised that the best
way to learn something is try to prepare to teach it to someone else.
This is what I was trying to do for my kids. But, after spending a
little over a month with Python, I stumbled upon Guido van Robot which
inspired me to change course again and I started working on RUR-PLE.  I
had some ideas as to what RUR-PLE should look like, and just started
building from scratch, first implementing the logic (no GUI) and then
learning what I needed (like wxPython) as I went along.   Being a
newbie sometimes made it difficult to make things work the way I
thought they should.  I'm sure professional programmers/experts would
be horrified if they were to look at the details of the code I wrote.
My excuse: it works ... why break it? ;-)

> Was there any necessity in the specifics you learned, or did you just
> dabble in something (e.g. wxPython) for fun?

Driven by the final goal in mind... The whole adventure has been for
fun!

> Are there still some things you feel you need to learn or improve?

*Lots*.  At the moment, it is webserver stuff for another project
(Crunchy Frog), again designed to make teaching/learning Python more
fun.

> Additional comments/complains here:   :)

Programming in Python is fantastic as a hobby... when I can find the
time.  Since I started 2 years ago, I have gone for a few weeks (and
once for 4 months) at a time without doing any programming.  However,
it is always easy to get back at it.  I don't think I'd be able to say
that with other languages.

I have found members of the Python community to be generally extremely
helpful and generous of their time, in answering my silly questions.

I sometimes wish I had a different job, one which required me to do
programming using Python.

André

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread bruno at modulix
John Salerno wrote:
(snip)
> Based on another thread, I tried out Scite, but no matter what I do it
> doesn't seem to remember the window size and position, or any options I
> choose (like showing line numbers). 

This is in the configuration files. Don't remember which and where, but
I clearly remember having done this.

> 
> And naturally there are Emacs and Vim, but I just don't know if I need
> to invest *that* much time into learning one of them

If you have a lot of file editing to do in a lot of various formats,
then investing time on learning how to effectively use a powerful and
extensible test editor is the WiseThingTodo(tm).

> (probably Vim,
> since I hear it's lighter and faster).

It's a bit faster at startup, yes. Else, I'm not sure it makes a real
difference wrt/ performances and power. It's more a matter of personal
preference than anything else IMHO.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
> I see Eclipse mentioned here a lot. 

If you go for a Mammoth-weight GUI-only Java IDE and have a really
powerful computer, why not ?

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in Python using wxGlade

2006-06-16 Thread diffuser78
Did you paste any code ?

Also the link for the next message is not working .


John Salerno wrote:
> [EMAIL PROTECTED] wrote:
> > I am a newbie. I was looking for some code where I could a list of
> > different items from a file and display it in a list box. Then give a
> > user the capability to select some.
> >
> > Basically, reading and writing to a file and displaying them in
> > different widgets...thats something I am looking for. If anybody can
> > point me to some good example tutorials...I will be greatly helped.
> >
> > Thanks,
> >
> > Every help is appreciated
> >
>
> Have you tried looking at the code in the wxPython demo? In the ListBox
> control demo, it populates a ListBox with items from a list, but you
> could easily translate that into reading from a file, I think. Here's
> the full code in case you don't have the demo:
>
>
> >
> > import  wx
> >
> > #---
> >
> > # This listbox subclass lets you type the starting letters of what you want 
> > to
> > # select, and scrolls the list to the match if it is found.
> > class FindPrefixListBox(wx.ListBox):
> > def __init__(self, parent, id, pos=wx.DefaultPosition, 
> > size=wx.DefaultSize,
> >  choices=[], style=0, validator=wx.DefaultValidator):
> > wx.ListBox.__init__(self, parent, id, pos, size, choices, style, 
> > validator)
> > self.typedText = ''
> > self.log = parent.log
> > self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
> >
> >
> > def FindPrefix(self, prefix):
> > self.log.WriteText('Looking for prefix: %s\n' % prefix)
> >
> > if prefix:
> > prefix = prefix.lower()
> > length = len(prefix)
> >
> > # Changed in 2.5 because ListBox.Number() is no longer 
> > supported.
> > # ListBox.GetCount() is now the appropriate way to go.
> > for x in range(self.GetCount()):
> > text = self.GetString(x)
> > text = text.lower()
> >
> > if text[:length] == prefix:
> > self.log.WriteText('Prefix %s is found.\n' % prefix)
> > return x
> >
> > self.log.WriteText('Prefix %s is not found.\n' % prefix)
> > return -1
> >
> >
> > def OnKey(self, evt):
> > key = evt.GetKeyCode()
> >
> > if key >= 32 and key <= 127:
> > self.typedText = self.typedText + chr(key)
> > item = self.FindPrefix(self.typedText)
> >
> > if item != -1:
> > self.SetSelection(item)
> >
> > elif key == wx.WXK_BACK:   # backspace removes one character and 
> > backs up
> > self.typedText = self.typedText[:-1]
> >
> > if not self.typedText:
> > self.SetSelection(0)
> > else:
> > item = self.FindPrefix(self.typedText)
> >
> > if item != -1:
> > self.SetSelection(item)
> > else:
> > self.typedText = ''
> > evt.Skip()
> >
> > def OnKeyDown(self, evt):
> > pass
> >
> >
> > #---
> >
> > class TestListBox(wx.Panel):
> > def __init__(self, parent, log):
> > self.log = log
> > wx.Panel.__init__(self, parent, -1)
> >
> > sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
> >   'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
> >   'twelve', 'thirteen', 'fourteen']
> >
> > wx.StaticText(self, -1, "This example uses the wx.ListBox 
> > control.", (45, 10))
> > wx.StaticText(self, -1, "Select one:", (15, 50))
> > self.lb1 = wx.ListBox(self, 60, (100, 50), (90, 120), sampleList, 
> > wx.LB_SINGLE)
> > self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
> > self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1)
> > self.lb1.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
> > self.lb1.SetSelection(3)
> > self.lb1.Append("with data", "This one has data");
> > self.lb1.SetClientData(2, "This one has data");
> >
> >
> > wx.StaticText(self, -1, "Select many:", (220, 50))
> > self.lb2 = wx.ListBox(self, 70, (320, 50), (90, 120), sampleList, 
> > wx.LB_EXTENDED)
> > self.Bind(wx.EVT_LISTBOX, self.EvtMultiListBox, self.lb2)
> > self.lb2.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
> > self.lb2.SetSelection(0)
> >
> > sampleList = sampleList + ['test a', 'test aa', 'test aab',
> >'test ab', 'test abc', 'test abcc',
> >'test abcd' ]
> > sampleList.sort()
> > wx.StaticText(self, -1, "Find Prefix:", (15, 250))
> > fp = FindPrefixListBox(self, -1, (100, 250), (90, 120), sampleList, 
> > wx.LB_SINGLE)
> > fp.SetSelection(0)

Re: a good programming text editor (not IDE)

2006-06-16 Thread bruno at modulix
John Salerno wrote:
> Ant wrote:
> 
>> jEdit is for me still the best text editor available. Very extensible
>> with macros (which can be written in Jython with the appropriate plugin
>> installed). 
> 
> 
> I like the idea of being extensible, but of course I can only write in
> Python.

Jython is Python on Java.

> Are there any editors that support that?

Emacs.


Which BTW is just great for python programming  - not only do you have
an embedded interactive python shell - the default one or IPython -  but
much more, you can with a simple keystroke eval either the whole buffer
or a selected block in this embedded shell. Could'nt live without it no
more !-)

(and you have ecb if you want a file/class browser)


But learning other languages might be a good idea too (even if once
spoiled by Python, if can be quite frustrating).

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
> Emacs must be dying if this thread could get all the way to 20 with
> nobody arguing with the vi folks. 

No need to argue. I started with vim, and finally switched to emacs less
than one year later.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pycrypto

2006-06-16 Thread luca72

Thanks

Luca

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


Re: Pycrypto

2006-06-16 Thread Laszlo Nagy

> Not in this implementation:
> py> from Crypto.Cipher import AES
> py> crypt = AES.new('abcdefghijklmnop', AES.MODE_CBC)
> py> c = crypt.encrypt('1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> ValueError: Input strings must be a multiple of 16 in length
>   
This is strange. In theory, any ECB mode cipher can be used to create a 
CBC mode cipher.
AFAIK, CBC creates one encrypted  block, and uses the one byte from the 
plain text to xor it
with the last encrypted byte. Finally it shifts the encrypted block. 
This way each input byte will
have a corresponding output byte, and there is no size limit for the 
plain text.

Frankly, I could write the CBC mode cipher using the (already existing) 
ECB cipher. Why we have this limitation?

  Laszlo


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


Duplex communication with pipes - is possible ?

2006-06-16 Thread Dara Durum
Hi !

I want to create a Process Pool Object.
I can hold started processes, and can communicate with them.

I tryed with many ipc methods, but every of them have bug or other problem.
Sockets are unavailabe (because Windows Firewall hold them).

I think I will use pipe.

The object's pseudocode:
while not Quit:
 CheckProcessOutputs;
 ProcessReceivedData;
 SendDataToSubProcesses;
 if NoMoreData: Quit=1

If I used pipes and subprocess module in Windows, I got big freezes,
and deadlocks.

Main proc:
subprocpipe.write('\n')
subprocpipe.readlines()

Sub proc:
input=sys.stdin.readlines().strip()
print input+'!!!'

It is working. But when I move this client code to cycle, I got deadlock.
while not Quit:
 input=sys.stdin.readlines().strip()
 print input+'!!!'
 Quit=input=='q'

Why ? Why I cannot create cyclic communication with client ?
Subprocess must "staying alive" (don't die), and need to stay in
reuseable state ?

Simply: subprocess pool needed !!!

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


wxPython question

2006-06-16 Thread diffuser78
I tried to follow wxPython Demo examples to understand it better. I
used wxGlade to generate my code from the GUI builder.

When I try to see the code for Menu and Menubar I see a little mismatch
in the way functions are being used.

For example, wxGlade produces code like this

self.Action = wx.Menu()
self.AddComputer = wx.MenuItem(self.Action, wx.NewId(), _("Add
Computer"), "",wx.ITEM_NORMAL)
self.Action.AppendItem(self.AddComputer)
## Code end

and in the demo it is gives as

self.Action = wx.Menu()
Action.append(201, "Add Computer")
# Code end

Can somebody please explain this discrepancy ?

Thanks, every help is appreciated.

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


Re: Pycrypto

2006-06-16 Thread luca72

Excuse me  again,
If the string is not a sting but hex number how i have to proced :

look this page:
http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html

Regards Luca

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


Re: XML, JSON, or what?

2006-06-16 Thread Frank Millman

Alan Kennedy wrote:
> [Frank Millman]
> > I am writing a multi-user accounting/business application, which uses
> > sockets to communicate between server and client. The server contains
> > all the business logic. It has no direct knowledge of the client. I
> > have devised a simple message format to exchange information between
> > the two.
> >
>
> If you're going to mix javascript client and python server, you
> definitely need something cross platform, like XML or JSON.
>
[...]
>
> I'd go with JSON, for simplicity and portability.  If you have any
> specific questions about it, ask.
>

Thanks for the offer. I have just tried it out, and instantly bumped my
head. I think I know the problem, and I don't think there is a simple
answer, but I will ask here first before starting to figure out a way
around it.

My client-server is Python-to-Python. At present, I am using cPickle to
transfer objects between the two. Among other things, I sometimes
transfer a tuple. Using JSON it appears on the other side as a list. As
I sometimes use the tuple as a dictionary key, this fails, as you
obviously cannot use a list as a key.

I am using 'simplejson'. I see there is also something called json-py,
but I have not tried it yet, as I am assuming (maybe wrongly) that it
will have the same problem. My hunch is that javascript/JSON does not
have the concept of a tuple, and therefore the problem is inherent.

Can someone confirm this, or is there an easy workaround?

Thanks

Frank

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


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread Mirco Wahab
Thus spoke John Salerno (on 2006-06-15 15:50):

> Did you have to learn it for a job?

No, I was just interested in things
that are found interesting ;-)

> Or did you just like what you saw and decided to learn it for fun?

I read some remarks, from "both sides", on
the feasibility of a programming language
with 'invisible braces', so I thought
'give it a try'.

> Also, how did you go about learning it? (i.e., like I described above, I 
> started with the main stuff then moved on to the different available 
> frameworks)

Good question: I started with 'Myghty', this is,
as you probably know, a (imho excellent) framework
for developing web applications from components.

'Myghty' is a almost complete port of Perl's 'Mason'
(which is what Amazon and others run at), - what I
knew already smoehow.

I also tried Pylons (base component of MVC system
for web apps), but waved the flag after some time.

> Was there any necessity in the specifics you learned, 
> or did you just  dabble in something (e.g. wxPython) for fun?

Another motivation was to find out something about the
(nowadays) huge amount on SciPy related (software
(http://www.scipy.org/Topical_Software).

> Are there still some things you feel you need to learn or improve?

I came all the way up from Basic/Fortran/x86-Assembler/C/C++
to todays 'lightweight languages' (Dr.Dobbs says they are)
in the the Python/Perl/Ruby-Group.

For my personal taste(!), Python is in the end
'to unspectacular', means: I didn't manage to
learn to be really expressive in it - and to
enjoy that ;-)

But thats a matter of taste, these languages are like
weapons (tools), that you use to express yourself on
the battlefield of your tasks.

And you _have_ to love and praise your sword, otherwise
you won't be able to handle it appropriate - in your
dreadful encounters ...

> Additional comments/complains here:   :)

What I don't like in Python
- easy things are too easy (even beginners can handle that, PIL etc.),
- complicated things are too complicated (I had hard times to remember things),
- invisible braces ;-) (just personal taste)
- no integrated regex support (used to use re's very much, but milage my vary)

Regards

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
>>>Most IDEs are rather weak as text editors compared to emacsen.
> 
> 
> That's true, but even emacs and xemacs don't offer simple automatic
> word wrap (i.e. wrap a line without splitting words or putting an eol
> or hard carriage return at the end of every line). I don't know if vim
> allows this. 

line-wrapping in an IDE ???

> It's something writers just take for granted in non-Unix
> text editors. 

Ah, ok. It's about vim/emacs as a general text editor. Emacs provides
word-wrapping, but true, it split words. I maybe wrong, but I don't
think it would be that hard to make it more word-friendly.

Now I wonder: what the use for line-wrapping at first ? Both emacs and
vim are text *editors*, not text *formatters*. Might be a unix-vs-others
cultural difference, but the general use on unix is to use some markup
(tex/LaTex, html, ReST or any 'structured-text' variant etc) and the
appropriate formater/renderer for presentation stuff.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
(snip)

> Also, it seems to be a minimalist
> language. 

*seems* minimalist, but is really not - have a look at the object model
(metaclasses, descriptors etc), at closures and HOFs and decorators, at
list-comp and generators and (coming in 2.5) coroutines... Definitively
not minimalist in fact !-)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
>>>I'd like something a bit like a module,
>>>but I'd like to make several of them,
>>>and not have them interfere with each other."
> 
> 
> Thank you. I sense what you are saying, but at this point I'd be
> thinking, "Why not just make several modules?" :) 

Because you want an unknown number of the *same* module ?-)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting values from text file

2006-06-16 Thread Paul McGuire
"Preben Randhol" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What I first though was if there was possible to make a filter such as:
>
>   Apples (apples)
>   (ducks) Ducks
>   (butter) g butter
>
> The data can be put in a hash table.
>
> Or maybe there are better ways? I generally want something that is
> flexible so one can easily make a filter settings if the text file
> format changes.
>

Here is a simple filter builder using pyparsing.  Pyparsing runs in two
passes: first, to parse your filter patterns; then to use the generated
grammar to parse some incoming source string.  Pyparsing comes with a
similar EBNF compiler, written by Seo Sanghyeon.  I'm sorry this is not
really a newbie example, but it does allow you to easily construct simple
filters, and the implementation will give you something to chew on... :)

Pyparsing wont be as fast as re's, but I cobbled this filter compiler
together in about 3/4 of an hour, and may serve as a decent prototype for a
more full-featured package.

-- Paul
Pyparsing's home Wiki is at http://pyparsing.wikispaces.com.


-
from pyparsing import *

sourceText = """
  Apples 34
  56 Ducks

Some more text.

  0.5 g butter
"""

patterns = """\
Apples (apples)
(ducks:%) Ducks
(butter:#) g butter"""

def compilePatternList(patternList, openTagChar="(", closeTagChar=")",
greedy=True):
def compileType(s,l,t):
return {
"%" : Word(nums+"-",nums).setName("integer"),
"#" :
Combine(Optional("-")+Word(nums)+"."+Optional(Word(nums))).setName("float"),
"$" : Word(alphas).setName("alphabetic word"),
"*" : Word(printables).setName("char-group")
}[t[0]]
backgroundWord = Word(alphanums).setParseAction(lambda
s,l,t:Literal(t[0]))
matchType = Optional(Suppress(":") + oneOf("% # $
*"),default="*").setParseAction(compileType)
matchPattern = Combine(openTagChar +
   Word(alphas,alphanums).setResultsName("nam") +
   matchType.setResultsName("typ") +
   closeTagChar)
matchPattern.setParseAction(lambda s,l,t:
(t.typ).setResultsName(t.nam) )
patternGrammar = OneOrMore( backgroundWord |
matchPattern ).setParseAction(lambda s,l,t:And([expr for expr in t]))
patterns = []
for p in patternList:
print p,
pattExpr = patternGrammar.parseString(p)[0]
print pattExpr
patterns.append(pattExpr)
altern = (greedy and Or or MatchFirst)
return altern( patterns )

grammar = compilePatternList( patterns.split("\n") )
print grammar

allResults = ParseResults([])
for t,s,e in grammar.scanString(sourceText):
print t
allResults += t
print

print allResults.keys()
for k in allResults.keys():
print k,allResults[k]

-
Prints:
Apples (apples) {"Apples" char-group}
(ducks:%) Ducks {integer "Ducks"}
(butter:#) g butter {float "g" "butter"}
{{"Apples" char-group} ^ {integer "Ducks"} ^ {float "g" "butter"}}
['Apples', '34']
['56', 'Ducks']
['0.5', 'g', 'butter']

['butter', 'apples', 'ducks']
butter 0.5
apples 34
ducks 56


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


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread bruno at modulix
Scott David Daniels wrote:
> BartlebyScrivener wrote:
> 
>>  I am not touching OO, classes, or GUIs until I understand
>> EVERYTHING else. Could take a few years. ;)
> 
> 
> You know how modules separate globals, right?  That is, what you
> write in one module doesn't affect the names in another module.
> What classes (and hence OO) give you is a way of saying, "I'd
> like something a bit like a module, but I'd like to make several
> of them, and not have them interfere with each other."  That is
> the big intuition about objects, the rest is just details.

Another way to put it:

You know what are dicts, right ? That is, containers with keyword-access
to values ? Then you probably have dicts with a known, defined
structure, and functions working on it. What classes (and hence 00)
gives you is a way to associate these functions with the dicts
themselves. That is the big intuition about objects, the rest is just
details.

!-)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread bruno at modulix
BartlebyScrivener wrote:
(snip)
> I am not touching OO, classes, 

You may not be aware of this, but as soon as you're programming in
Python, you *are* using OO. Strings are objects, dicts are objects,
tuples are objects, lists are objects, numbers are objects, and even
functions and modules are objects. Classes are just a way to create your
own object types.

> or GUIs until I understand EVERYTHING

The answer is 42. That's all you need to know.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-16 Thread Tim Chase
> No need to argue. I started with vim, and finally switched to
> emacs less than one year later.

Both are very-much-so good editors.  I made the opposite switch
from emacs to vim in less than a year.  Both are good^Wgreat
editors, so one's decision to use one over the other is more a
matter of working style.  I don't grok LISP, and just never felt
at home in emacs, despite all the power I could see that was
there.  I grok vim (and its similar power/extensibility), so I
migrated to it.  I have to laugh at the whole holy-war thing, as
it's somewhat like arguing about a favorite color.  "But blue is
so better than green!  The sky is blue!"  "Nuh, uh!  Green is far
better than blue!  Grass is green!" (okay, here in Texas, that
doesn't always hold as true...maybe personality #2 should be
arguing for brown instead).

My best friend is an emacs user, and I'm a vimmer...it doesn't
come between us. :)

-tkc




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


Re: a good programming text editor (not IDE)

2006-06-16 Thread Walter Dörwald
[EMAIL PROTECTED] wrote:

> John Salerno wrote:
> [snip]
>> Thanks for any suggestions, and again I'm sorry if this feels like the
>> same question as usual (it's just that in my case, I'm not looking for
>> something like SPE, Komodo, Eric3, etc. right now).
> 
> I was taking a peek at c.l.py to check for replies in another thread
> and couldn't help notice your asking about editors.  Please pardon the
> personal pimping, but have you looked at PyPE (pype.sf.net)?

I tried it out and the first problem I noticed is that on Windows
opening a file from a Samba drive doesn't seem to work, as PyPE converts
the filename to lowercase.

Servus,
   Walter

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


Re: Duplex communication with pipes - is possible ?

2006-06-16 Thread Daniel Dittmar
Dara Durum wrote:
> Hi !
> 
> I want to create a Process Pool Object.
> I can hold started processes, and can communicate with them.
> 
> I tryed with many ipc methods, but every of them have bug or other problem.
> Sockets are unavailabe (because Windows Firewall hold them).
> 
> I think I will use pipe.
> 
> The object's pseudocode:
> while not Quit:
> CheckProcessOutputs;
> ProcessReceivedData;
> SendDataToSubProcesses;
> if NoMoreData: Quit=1
> 
> If I used pipes and subprocess module in Windows, I got big freezes,
> and deadlocks.
> 
> Main proc:
> subprocpipe.write('\n')
> subprocpipe.readlines()
> 
> Sub proc:
> input=sys.stdin.readlines().strip()
> print input+'!!!'
> 
> It is working. But when I move this client code to cycle, I got deadlock.
> while not Quit:
> input=sys.stdin.readlines().strip()
> print input+'!!!'
> Quit=input=='q'
> 
> Why ? Why I cannot create cyclic communication with client ?
> Subprocess must "staying alive" (don't die), and need to stay in
> reuseable state ?
> 
> Simply: subprocess pool needed !!!
> 
> Thanks for help:
> dd

readlines () will try to read until the stream/socket is closed. Try to 
read only one line. This of course means that you cannot sent \n as part 
of the data, you have to escape them somehow.

I'm not sure how the pipe code is searching for the \n. Trying to read 
too much could lead to deadlocks as well. (Although I'm sure that the 
code is written to return fewerbytes than requested if there isn't 
enough data pending in the pipe). A safer variant might be to transfer a 
fixed number of bytes containing the length n of the following data, and 
then n bytes containing the actual data.

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


Re: XML, JSON, or what?

2006-06-16 Thread Daniel Dittmar
> My client-server is Python-to-Python. At present, I am using cPickle to
> transfer objects between the two. Among other things, I sometimes
> transfer a tuple. Using JSON it appears on the other side as a list. As
> I sometimes use the tuple as a dictionary key, this fails, as you
> obviously cannot use a list as a key.
[...]
> Can someone confirm this, or is there an easy workaround?

You can always convert a list to a tuple using the tuple () builtin 
right before  you use it as a key. But you have to be sure that it is a 
list. tuple ("abc") => ('a', 'b', 'c') is probably not what you intend 
to do.

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Pascal Costanza
Torben Ægidius Mogensen wrote:
> Pascal Costanza <[EMAIL PROTECTED]> writes:
> 
>> Torben Ægidius Mogensen wrote:
> 
>>> So while it may take longer to get a program that gets
>>> past the compiler, it takes less time to get a program that works.
>> That's incorrect. See http://haskell.org/papers/NSWC/jfp.ps -
>> especially Figure 3.
> 
> There are many other differences between these languages than static
> vs. dynamic types, and some of these differences are likely to be more
> significant.  What you need to test is langauges with similar features
> and syntax, except one is statically typed and the other dynamically
> typed.
> 
> And since these languages would be quite similar, you can use the same
> test persons: First let one half solve a problem in the statically
> typed language and the other half the same problem in the dynamically
> typed language, then swap for the next problem.  If you let a dozen
> persons each solve half a dozen problems, half in the statically typed
> language and half in the dynamically typed language (using different
> splits for each problem), you might get a useful figure.

...and until then claims about the influence of static type systems on 
the speed with which you can implement working programs are purely 
guesswork. That's the only point I need to make to show that your 
original unqualified statement, namely that it takes less time to get a 
program that works, is incorrect.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pycrypto

2006-06-16 Thread Philippe Martin
Hi,

Look at the bin2ascii module.

Philippe


luca72 wrote:

> 
> Excuse me  again,
> If the string is not a sting but hex number how i have to proced :
> 
> look this page:
> http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html
> 
> Regards Luca

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread genea

Torben Ægidius Mogensen wrote:

> There are several aspects relevant to this issue, some of which are:
>  - Compactness: How much do I have to type to do what I want?
 ..
>  - Naturality: How much effort does it take to convert the concepts of
>my problem into the concepts of the language?
>  - Feedback: Will the language provide sensible feedback when I write
>nonsensical things?
>  - Reuse: How much effort does it take to reuse/change code to solve a
>similar problem?
.

I am fairly new to Haskell, but the compactness of the language and the
way you can express a lot in a very small amount of real estate is very
important.. I used to program back in the 80's in forth a lot okay
I'm a dinosaur!, but "good" definitions were usually very short, and
sweet.  Unicon/Icon that I used {still do!} in the imperative world,
very compact.  I will give an example that covers compact, reusable,
and because of static typing when will give back mis-type info when you
load a new "a or xs" into it to form a new function.
-- what is happening below is a is being replaced with the curried
lambda: ((++) 3) and
-- xs a list: [1..6], so when that definition of f is used it is type
checked to see if the
--  elements in xs match the type of a, so if this were going to be
compiled, it would
-- checked and guaranteed to work.

Prelude> :t f
f :: forall a b. (Show b) => (a -> b) -> [a] -> IO ()
Prelude> let f a xs = putStr $ foldr (++) "\n"  $ map (((++) "\n").
show . a ) xs
Prelude> f ((*) 3) [1..6]
3
6
9
12
15
18
Prelude>

another substitution of parameters.. using the same definition of f
allowed by the the
polymorphic parameters allowed in Haskell add to the versatility and
reusability angle:

Prelude> f sqrt  [0.5,1.0..4]
0.7071067811865476
1.0
1.224744871391589
1.4142135623730951
1.5811388300841898
1.7320508075688772
1.8708286933869707
2.0

Same function 'f" now used with a different type..
[0.5,1.0..4] :: forall a. (Fractional a, Enum a) => [a]

I don't know, but this just makes programming fun, for me anyway, and
if it is fun, it is expressive.. I've heard this statement made about
Ruby and Unicon, to name a few... some would say Python.. but it really
applies to the functional languages too, with all their strict typing,
with the type inference mechanisms, it isn't usually that big a deal..
If you just get into it, and can learn to take some constructive
criticism from your compiler, well hey, it is a really patient
teacher... you might get frustrated at times.. but the compiler will
happily remind you of the same type mis-matches, until you get a handle
on some concept and never once complain...
 Happy Programming to all!
-- gene

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


Re: Pycrypto

2006-06-16 Thread luca72

Hello again i have solve doing this:

from Crypto.Cipher import AES
stri=(chr(int('9b',16))+chr(int('d3',16))+chr(int('2d',16))+chr(int('24',16))+chr(int('af',16))+chr(int('c9',16))+chr(int('e9',16))+chr(int('d7',16))+chr(int('46',16))+chr(int('69',16))+chr(int('71',16))+chr(int('32',16))+chr(int('45',16))+chr(int('5f',16))+chr(int('27',16))+chr(int('0b',16)))
luca = str(stri)
crypt = AES.new(luca, AES.MODE_ECB)
testo=(chr(int('ea',16))+chr(int('52',16))+chr(int('3a',16))+chr(int('66',16))+chr(int('4d',16))+chr(int('ab',16))+chr(int('aa',16))+chr(int('44',16))+chr(int('76',16))+chr(int('d3',16))+chr(int('12',16))+chr(int('26',16))+chr(int('a1',16))+chr(int('e3',16))+chr(int('ba',16))+chr(int('b0',16)))
testo = str(testo)
c = crypt.encrypt(testo)

I don't know if this is the best way , but anyway it work

Regards

Luca

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Raffael Cavallaro
On 2006-06-16 05:22:08 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:

> And this is a typical dynamic type advocate's response when told that 
> static typing has different needs:
> 
> "*I* don't see the usefulness of static typing so *you* shouldn't want 
> it, either."

But I haven't made this sort of argument. I never said you shouldn't 
use static typing if you want to. There are indeed types of software 
where one wants the guarantees provided by static type checks. For 
example, software that controls irreplaceable or very expensive 
equipment such as space craft, or software that can kill people if it 
fails such as software for aircraft or medical devices. The problem for 
static typing advocates is that most software is not of this type.

There is a very large class of software where user inputs are 
unpredictable and/or where input data comes from an untrusted source. 
In these cases run-time checks are going to be needed anyway so the 
advantages of static type checking are greatly reduced - you end up 
doing run-time checks anyway, precisely the thing you were trying to 
avoid by doing static analysis. In software like this it isn't worth 
satisfying a static type checker because you don't get much of the 
benefit anyway
as being able to run and test portions of a program before other parts 
are written (forward references to as yet nonexistent functions).

Ideally one wants a language with switchable typing - static where 
possible and necessary, dynamic elsewhere. To a certain extent this is 
what common lisp does but it requires programmer declarations. Some 
implementations try to move beyond this by doing type inference and 
alerting the programmer to potential static guarantees that the 
programmer could make that would allow the compiler to do a better job.

In effect the argument comes down to which kind of typing one thinks 
should be the default. Dynamic typing advocates think that static 
typing is the wrong default. The notion that static typing can prove 
program correctness is flawed - it can only prove that type constraints 
are not violated but not necessarily that program logic is correct. It 
seems to me that if we set aside that class of software where safety is 
paramount - mostly embedded software such as aircraft and medical 
devices - we are left mostly with efficiency concerns. The 80-20 rule 
suggests that most code doesn't really need the efficiency provided by 
static guarantees. So static typing should be invoked for that small 
portion of a program where efficiency is really needed and that dynamic 
typing should be the default elswhere. This is how common lisp works - 
dynamic typing by default with static guarantees available where one 
needs them.

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


Re: __lt__ slowing the "in" operator even if not called

2006-06-16 Thread Steven Bethard
Emanuele Aina wrote:
> [EMAIL PROTECTED] dettagliò:
> 
>>> Someone can explain me why?
>> The list's __contains__ method is very simple
> 
> [...]
> 
>> So if you define "__lt__" in your object then the type gets a richcmp
>> function and your == test implicit in the 'in' search always incurs the
>> cost of figuring out that "__eq__" is not defined.
> 
> Thank you for the detailed explanation! :)
> 
> Do you think I should report this as a performance bug, maybe with the
> 'wishlist' priority, or I should accept the truth and hope for better
> luck next time? ;)

It certainly wouldn't hurt to report it.  But I suspect it's not ever 
going to get "fixed".  Classes with a __lt__ but no __eq__ really aren't 
that common.

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Raffael Cavallaro
On 2006-06-16 11:29:12 -0400, Raffael Cavallaro 
<[EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com> said:

> In software like this it isn't worth satisfying a static type checker 
> because you don't get much of the benefit 
> anywaytext Dx¤description£text Dx¢fromname
> as being able to run and test portions of a program before other parts 
> are written (forward references to as yet nonexistent functions).

I don't what bizarre key combination I accidentally hit here, but the 
original read:

In software like this it isn't worth satisfying a static type checker 
because you don't get much of the benefit anyway and it means forgoing 
such advantages of dynamic typing as being able to run and test 
portions of a program before other parts are written (forward 
references to as yet nonexistent functions).

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Raffael Cavallaro
On 2006-06-16 05:22:08 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:

> And this is a typical dynamic type advocate's response when told that 
> static typing has different needs:
> 
> "*I* don't see the usefulness of static typing so *you* shouldn't want 
> it, either."

But I haven't made this sort of argument. I never said you shouldn't 
use static typing if you want to. There are indeed types of software 
where one wants the guarantees provided by static type checks. For 
example, software that controls irreplaceable or very expensive 
equipment such as space craft, or software that can kill people if it 
fails such as software for aircraft or medical devices. The problem for 
static typing advocates is that most software is not of this type.

There is a very large class of software where user inputs are 
unpredictable and/or where input data comes from an untrusted source. 
In these cases run-time checks are going to be needed anyway so the 
advantages of static type checking are greatly reduced - you end up 
doing run-time checks anyway, precisely the thing you were trying to 
avoid by doing static analysis. In software like this it isn't worth 
satisfying a static type checker because you don't get much of the 
benefit anyway and it means forgoing such advantages of dynamic typing 
as being able to run and test portions of a program before other parts 
are written (forward references to as yet nonexistent functions).

Ideally one wants a language with switchable typing - static where 
possible and necessary, dynamic elsewhere. To a certain extent this is 
what common lisp does but it requires programmer declarations. Some 
implementations try to move beyond this by doing type inference and 
alerting the programmer to potential static guarantees that the 
programmer could make that would allow the compiler to do a better job.

In effect the argument comes down to which kind of typing one thinks 
should be the default. Dynamic typing advocates think that static 
typing is the wrong default. The notion that static typing can prove 
program correctness is flawed - it can only prove that type constraints 
are not violated but not necessarily that program logic is correct. It 
seems to me that if we set aside that class of software where safety is 
paramount - mostly embedded software such as aircraft and medical 
devices - we are left mostly with efficiency concerns. The 80-20 rule 
suggests that most code doesn't really need the efficiency provided by 
static guarantees. So static typing should be invoked for that small 
portion of a program where efficiency is really needed and that dynamic 
typing should be the default elswhere. This is how common lisp works - 
dynamic typing by default with static guarantees available where one 
needs them.

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


Re: a good programming text editor (not IDE)

2006-06-16 Thread Istvan Albert
Scott David Daniels wrote:

> Surprise, surprise.  One hour is not two weeks.

I wrote:

> pressing Ctrl-1 while editing the source will execute the python on the
> current source *and* it  displays the output in a lower pane as it runs
> *and* it allows me to simultanously edit the file *while* the program
> is running.

yet I'll bet that you could not make Vim do this above ...

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


msvcr71.dll necessary? - Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread robert
[EMAIL PROTECTED] wrote:
> Hi everyone,
> 
> which compiler will Python 2.5 on Windows (Intel) be built with? I
> notice that Python 2.4 apparently has been built with the VS2003
> toolkit compiler, and I read a post from Scott David Daniels [1] where
> he said that probably the VS2003 toolkit will be used for Python 2.5
> again. However, even before the release of Python 2.5, I cannot seem to
> find many retailers around here that still carry Visual Studio 2003 ...

For me the great great problem with Python2.4's lib geometry was that 
the size of distributable app installers swelled suddenly by many megs 
with msvcr71.dll and mfc71 and codecs in core and all. Typically 
installer sizes went from 1.5MB to over 4MB for basic non-trivial apps.
Thats a show stopper still in many situations today - at least for my 
requirements.

See e.g. for an example of magnitudes: 
http://groups.google.de/group/comp.lang.python/msg/edf469a1b3dc3802
Updating to a new expensive compiler problem for extensions was secondary.

Thus I decided so far to stay at Python2.3 for longer time for most 
projects, while I'm using Python2.4+ only for local/web scripts and 
single-installation projects. The little improvements in Python2.4/2.5 
mostly don't justify their monster footprint in memory and installers.


Some questions:

* Is there a fundamental reason that the C-RTL of VC6 (which is 
pre-installed on on all Windows today) is not sufficient for current 
Python and extensions? instable?
In case not: As the short living VS 2003 compiler is now more rare than 
the good old VC6, wouldn't it be better to switch back to VC6 for Py2.5 
or at least to VC6 libs (which are maybe "free" of dev-license as they 
sit on each Windows).
Maybe a suitable policy: the default crtl for Python should better be 
the default library of the OS and not that of a random compiler which is 
currently hip?

* can't the Mingw/gcc be used together with Windows default crt/mfc libs 
for Python2.5 ? - Python getting away the from this MS studio (lib) 
harassment?
( Personally I'd give no cent for that little runtime speed advantage by 
the VS2005 compiler when comparing to a slimness + stable standard + 
freedom )
Together with a clear decision to clean the Python core libs from recent 
habits to "statically" preload OS-kind-of-packages (e.g. codecs, the 
licentious pre-imports in urllib and friends ),  I'd have hope to get 
out of my deadlock on Python2.3.

* how many (serious) python users require to build distributable 
installers (which have carry the python-rtls and non-default crtl's)?
I guess, almost all GUI apps have this requirement? And GUI apps 
probably count more (also in line numbers) than web apps today as more 
and more Delphi, BCPPB, Java, C++/MFC developers switch to Python?


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


Re: a good programming text editor (not IDE)

2006-06-16 Thread josiah . carlson
Walter Dörwald wrote:
> I tried it out and the first problem I noticed is that on Windows
> opening a file from a Samba drive doesn't seem to work, as PyPE converts
> the filename to lowercase.

...Samba is tricky, and I hadn't thought of it before.  Normal Windows
is case-insensitive but case-preserving, and PyPE uses Python's
os.path.normcase(os.path.normpath(os.path.realpath(...))) to do
path/file normalization mapping for open files (keeping the
non-case-normalized filename), so that you can't really make the
mistake of opening the same file twice.  This normally works on
platforms with consistant case handling, but if you are using Samba
running on any non-OSX *nix (whose filename case handling is not like
other *nixes) from Windows, there gets to be a bit of a problem as your
*nix case handling is different from Windows.

I have an idea of what needs to be done, and the fix for it will be in
PyPE 2.4.1, which I plan on releasing by June 30th.

 - Josiah

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Raffael Cavallaro
On 2006-06-16 05:22:08 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said:

> And this is a typical dynamic type advocate's response when told that 
static typing has different needs:
> "*I* don't see the usefulness of static typing so *you* shouldn't 
want it, either."

But I haven't made this sort of argument. I never said you shouldn't 
use static typing if you want to. There are indeed types of software 
where one wants the guarantees provided by static type checks. For 
example, software that controls irreplaceable or very expensive 
equipment such as space craft, or software that can kill people if it 
fails such as software for aircraft or medical devices. The problem for 
static typing advocates is that most software is not of this type.

There is a very large class of software where user inputs are 
unpredictable and/or where input data comes from an untrusted source. 
In these cases run-time checks are going to be needed anyway so the 
advantages of static type checking are greatly reduced - you end up 
doing run-time checks anyway, precisely the thing you were trying to 
avoid by doing static analysis. In software like this it isn't worth 
satisfying a static type checker because you don't get much of the 
benefit anyway and it means forgoing such advantages of dynamic typing 
as being able to run and test portions of a program before other parts 
are written (forward references to as yet nonexistent functions).

Ideally one wants a language with switchable typing - static where 
possible and necessary, dynamic elsewhere. To a certain extent this is 
what common lisp does but it requires programmer declarations. Some 
implementations try to move beyond this by doing type inference and 
alerting the programmer to potential static guarantees that the 
programmer could make that would allow the compiler to do a better job.

In effect the argument comes down to which kind of typing one thinks 
should be the default. Dynamic typing advocates think that static 
typing is the wrong default. The notion that static typing can prove 
program correctness is flawed - it can only prove that type constraints 
are not violated but not necessarily that program logic is correct. It 
seems to me that if we set aside that class of software where safety is 
paramount - mostly embedded software such as aircraft and medical 
devices - we are left mostly with efficiency concerns. The 80-20 rule 
suggests that most code doesn't really need the efficiency provided by 
static guarantees. So static typing should be invoked for that small 
portion of a program where efficiency is really needed and that dynamic 
typing should be the default elswhere. This is how common lisp works - 
dynamic typing by default with static guarantees available where one 
needs them.


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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread sam
I have been using the latest VC.net to compile my SCSIPython extension
dll for Python 2.3, 2.4, and  2.5  without any problems. I just have to
make shure that I link with the correct Python.lib

Sam Schulenburg

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


Re: Pycrypto

2006-06-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, luca72 wrote:

> Hello again i have solve doing this:
> 
> from Crypto.Cipher import AES
> stri=(chr(int('9b',16))+chr(int('d3',16))+chr(int('2d',16))+chr(int('24',16))+chr(int('af',16))+chr(int('c9',16))+chr(int('e9',16))+chr(int('d7',16))+chr(int('46',16))+chr(int('69',16))+chr(int('71',16))+chr(int('32',16))+chr(int('45',16))+chr(int('5f',16))+chr(int('27',16))+chr(int('0b',16)))
> luca = str(stri)
> crypt = AES.new(luca, AES.MODE_ECB)
> testo=(chr(int('ea',16))+chr(int('52',16))+chr(int('3a',16))+chr(int('66',16))+chr(int('4d',16))+chr(int('ab',16))+chr(int('aa',16))+chr(int('44',16))+chr(int('76',16))+chr(int('d3',16))+chr(int('12',16))+chr(int('26',16))+chr(int('a1',16))+chr(int('e3',16))+chr(int('ba',16))+chr(int('b0',16)))
> testo = str(testo)
> c = crypt.encrypt(testo)
> 
> I don't know if this is the best way , but anyway it work

In [26]:import binascii

In [27]:binascii.unhexlify('ea523a664dabaa4476d31226a1e3bab0')
Out[27]:'\xeaR:fM\xab\xaaDv\xd3\x12&\xa1\xe3\xba\xb0'

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Duplex communication with pipes - is possible ?

2006-06-16 Thread alisonken1


> readlines () will try to read until the stream/socket is closed. Try to
> read only one line. This of course means that you cannot sent \n as part
> of the data, you have to escape them somehow.
>


If I remember correctly, if you want to pass '\n' so readline won't
stop, you should be able to escape the escape '\\n', then remove the
extra '\' when actually processing.

Of course, readline will continue to read until buffer filled or a real
'\n' is passed (g).

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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Darren New
Joachim Durchholz wrote:
> Give a heterogenous list that would to too awkward to live in a 
> statically-typed language.

Write a function that takes an arbitrary set of arguments and stores 
them into a structure allocated on the heap.

> Give a case of calling nonexistent functions that's useful.

See the Tcl "unknown" proc, used for interactive command expansion, 
dynamic loading of code on demand, etc.

-- 
   Darren New / San Diego, CA, USA (PST)
 My Bath Fu is strong, as I have
 studied under the Showerin' Monks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonPerl 0.9

2006-06-16 Thread Jim Fulton
Have you looked at PyPerl?

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

I think it was further along.  It might be good to build on.

Jim

On Jun 16, 2006, at 11:37 AM, Bruno Obsomer wrote:

> You love Python, but think Perl can be useful anyway. You can now  
> mix the
> two in a single program with the new Python module:
>   PythonPerl (version 0.9, GPL license)
>
> It is as simple to use as:
 import perl
 perl.addVariable('a', ['foo', 'bar'])
 perl.execute('$b = $a[0]')
 perl.getVariable('b')
> foo
>
> Questions and comments at bobzomer AT gmail.com.
>
> http://ece.fsa.ucl.ac.be/bobsomer/PythonPerl.tgz";>
> PythonPerl 0.9 - simple module to allow the use of Perl inside
> Python. (16-Jun-06)
> -- 
> http://mail.python.org/mailman/listinfo/python-announce-list
>
> Support the Python Software Foundation:
> http://www.python.org/psf/donations.html

--
Jim Fulton  mailto:[EMAIL PROTECTED]Python 
Powered!
CTO (540) 361-1714  
http://www.python.org
Zope Corporationhttp://www.zope.com http://www.zope.org



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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Darren New
Joachim Durchholz wrote:
> Give a heterogenous list that would to too awkward to live in a 
> statically-typed language.

Printf()?

-- 
   Darren New / San Diego, CA, USA (PST)
 My Bath Fu is strong, as I have
 studied under the Showerin' Monks.
-- 
http://mail.python.org/mailman/listinfo/python-list


download file from intranet linux server to windows clients

2006-06-16 Thread Luis P. Mendes
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

I'm building an intranet web server in Linux for around 40 windows
clients with Django.

The problem is that I want to build an excel file based on criteria
entered by the client, that the client must be able do download to his
personal work space.  I use pyExcelerator to create the Excel files.

How can I do it?  Do I need another excel generator?

Client's information about its working directory should be read, but
how?  I could only find the way to read the server environment
variables, where data is processed.

Luis P. Mendes

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEkuY9Hn4UHCY8rB8RAvjYAJ9RSp1llMo6GPJIYAicm8gRSQJ/AwCgrN5Y
3EzU+SGn3Uk/1j1gwl4uBik=
=3330
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


add elements to indexed list locations

2006-06-16 Thread leventyilmaz
Hi,

I have a very simple problem, but do not know an elegant way to
accomplish this.
###
# I have a list of names:
names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']

# and another set of names that I want to insert into
# the names list at some indexed locations:
surnames = { 1: 'kent', 3:'parker', 5:'wayne' }

# The thing I couldn't figure out is, after I insert a
# surname the rest of the indices are not valid.
# That is, the following won't work:
for i, x in surnames.iteritems():
   names.insert(i,surnames[i])
###

I am searching a nice way to do this. For instance, is there a more
robust way to store indices (as some sort of pointers maybe?) 

- Levent

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


Re: MS VC++ Toolkit 2003 installer (VCToolkitSetup.exe)

2006-06-16 Thread Jarek Zgoda
[EMAIL PROTECTED] napisał(a):

> I need to build some Win32 Python extensions. If somebody happens to
> have the Microsoft Visual C++ Toolkit 2003 installer
> (VCToolkitSetup.exe), please kindly contact me off-list at:

I think only Microsoft has enough rights to distribute this.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: add elements to indexed list locations

2006-06-16 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi,
> 
> I have a very simple problem, but do not know an elegant way to
> accomplish this.
> ###
> # I have a list of names:
> names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']
> 
> # and another set of names that I want to insert into
> # the names list at some indexed locations:
> surnames = { 1: 'kent', 3:'parker', 5:'wayne' }
> 
> # The thing I couldn't figure out is, after I insert a
> # surname the rest of the indices are not valid.
> # That is, the following won't work:
> for i, x in surnames.iteritems():
>names.insert(i,surnames[i])
> ###
> 
> I am searching a nice way to do this. For instance, is there a more
> robust way to store indices (as some sort of pointers maybe?) 

Use a dictionary for both of them?

The concept of indices is that they IMPLY a position. So either you work 
in a way that you e.g. add the surnames in a defined order and adjust 
the subsequent indices, or you discard the approach entirely and e.g use 
a map of first to surnames.

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


Re: add elements to indexed list locations

2006-06-16 Thread Alexis Roda
En/na [EMAIL PROTECTED] ha escrit:
> Hi,
> 
> I have a very simple problem, but do not know an elegant way to
> accomplish this.
> ###
> # I have a list of names:
> names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']
> 
> # and another set of names that I want to insert into
> # the names list at some indexed locations:
> surnames = { 1: 'kent', 3:'parker', 5:'wayne' }
> 
> # The thing I couldn't figure out is, after I insert a
> # surname the rest of the indices are not valid.
> # That is, the following won't work:
> for i, x in surnames.iteritems():
>names.insert(i,surnames[i])
> ###

In my previous post I've misunderstood the problem. Here is a valid 
solution:

keys = surnames.keys()
keys.sort()
count = 0
for i in keys :
   names.insert(i + count, surnames[i])
   count = count + 1


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


Re: add elements to indexed list locations

2006-06-16 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
> # I have a list of names:
> names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']
> 
> # and another set of names that I want to insert into
> # the names list at some indexed locations:
> surnames = { 1: 'kent', 3:'parker', 5:'wayne' }
> 
> # The thing I couldn't figure out is, after I insert a
> # surname the rest of the indices are not valid.
> # That is, the following won't work:
> for i, x in surnames.iteritems():
>names.insert(i,surnames[i])

This seems to work (tested only with what you see below)::

 >>> names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']
 >>> surnames = {1:'kent', 3:'parker', 5:'wayne'}
 >>> for index in sorted(surnames, reverse=True):
 ... names.insert(index, surnames[index])
 ...
 >>> names
 ['clark', 'kent', 'super', 'peter', 'parker', 'spider', 'bruce',
 'wayne', 'bat']

I just did the inserts from right to left, that is, starting at the end. 
  That way, after an insert, I don't have to adjust any indices.

You may also find that if you do a lot of inserts into the list, it may 
be more efficient to create a new list, e.g.::

 >>> names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']
 >>> surnames = {1:'kent', 3:'parker', 5:'wayne'}
 >>> new_names = []
 >>> for i, name in enumerate(names):
 ... if i in surnames:
 ... new_names.append(surnames[i])
 ... new_names.append(name)
 ...
 >>> new_names
 ['clark', 'kent', 'super', 'peter', 'parker', 'spider', 'bruce',
 'wayne', 'bat']


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


Opening an editor for interactive use

2006-06-16 Thread Webb
Hi all,

(I am sure there is a recipe somewhere, but I can't find it.)  How does
one open an editor while in the middle of an interactive program, let
the user do some editing and closing, and then capture the text that
was edited?  I am reminded of subversion or CVS when they open an
$EDITOR session for the check-in log entry.

I tried os.popen, but it fired off vim in the background--not useful.
Then I tried os.system, but that only returns the return code (126 in
my case) after you close the editor.  Perhaps I need to write to a file
and read it--shouldn't there be a cleaner way?

Thanks
W

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


Re: BeautifulSoup error

2006-06-16 Thread Serge Orlov
William Xu wrote:
> Hi, all,
>
> This piece of code used to work well. i guess the error occurs after
> some upgrade.
>
> >>> import urllib
> >>> from BeautifulSoup import BeautifulSoup
> >>> url = 'http://www.google.com'
> >>> port = urllib.urlopen(url).read()
> >>> soup = BeautifulSoup()
> >>> soup.feed(port)
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.3/sgmllib.py", line 94, in feed

Look at the traceback: you're not calling BeautifulSoup module! In
fact, there is no feed method in the current BeautifulSoup
documentation. Maybe it used to work well, but now it's definitely
going to fail. As I understand documentation you need to write

soup = BeautifulSoup(port)

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


Cross-site scripting (XSS) defense

2006-06-16 Thread johnzenger
Is there a module (or, better yet, sample code) that scrubs
user-entered text to remove cross-site scripting attacks, while also
allowing a small subset of HTML through?

Contemplated application: a message board that allows people to use
, ,  and so on, but does not allow any javascript,
vbscript, or other nasties.

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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-16 Thread Philip Austin
[EMAIL PROTECTED] writes:

>> This is the .NET 11 SDK, I belive it includes the 2003 compiler (*):
>
> Last time I checked the .NET SDK they had the C# compiler in there, but
> not the C++ optimizing 2003 compiler. Might be wrong though

I just downloaded and installed this, and see a directory called

c:\program files\microsoft visual studio .net 2003\vc7

with bin\cl.exe  and  lib and include directories.  So presumably
I'm good to go?  

I'm following this thread because I'll need to
compile and install some extensions I've written for linux/gcc/python2.4
in our Windows computer lab.   Presuming I succeed in setting up
vc7 correctly, is it as simple as 'python setup.py install' from here?

Thanks, Phil




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


Re: What is Expressiveness in a Computer Language

2006-06-16 Thread Matthias Blume
Darren New <[EMAIL PROTECTED]> writes:

> Joachim Durchholz wrote:
>> Give a heterogenous list that would to too awkward to live in a
>> statically-typed language.
>
> Printf()?

Very good statically typed versions of printf exist.  See, e.g.,
Danvy's unparsing combinators.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem on win xp and run time error

2006-06-16 Thread Michele Petrazzo
Hi list,
just found in this moment that my applications stop to work with win xp
and receive this error:

"""
This application has requested the Runtime to terminate it in an unusual
way. Please contact the application's support team for more information.
"""

(Note that the same application [python source code + py2exe] with
python 2.3.x work well!)

With a little google search I found that this is a win xp sp2 problem
*without* apparently solution :(

http://support.microsoft.com/kb/884538/en-us

I see that the page says:
"""
This problem may occur when you use the /GR and the /MD compiler switches
"""

so my question are: python are compiled with that switches? If yes, can
someone try to compile it without that switches, if it can of course,
and publish the new installer? I'm can't work until microsoft solve that
issue! :(

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


  1   2   >