Re: comparing values in two sets

2006-05-15 Thread Paul Rubin
Peter Otten <[EMAIL PROTECTED]> writes:
> Here's a variant that does performs only the necessary tests: 
> 
> >>> from itertools import izip
> >>> True not in (a == b for a, b in izip(range(3), range(3)))

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


Re: Compile Python

2006-05-15 Thread Miki
Hello Zoidberg,

> How would one compile python with Visual Studio 2005?
By reading the section "Building on non-UNIX systems" in the README
file (hint: chceck out the "PC" directory)

Miki
http://pythonwise.blogspot.com/

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


Re: Web framework to recommend

2006-05-15 Thread .
Hi Jacky,
if you want make a good experiment, you can use:

LocaWapp - localhost web applications
http://cheeseshop.python.org/pypi/LocaWapp/09

Post here your feedback.
Bye and good work

D.

Jacky ha scritto:

> Hi all,
>
> I just started learning Python and would like to starting writing some
> web-based applications with Python.
>
> I did have pretty much experience with doing so with PHP and Java, but
> Python seems a bit different for me.
>
> Do you guys have some good web framework to recommend? (I don't want to
> use CGI mode)
> 
> Thanks a lot.
> 
> --
> Jacky

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


Re: Web framework to recommend

2006-05-15 Thread jdec

Hi, Jacky

Please find below a link to the tool you're looking for :
http://karrigell.sourceforge.net/

It's small, easy to install and work with, good documented (In english
an in french).
The developper is also very reactive on questions / remarks.

I'm using it since more than 1 year without trouble

Hope you'll enjoy
Regards,Jerome

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


Re: Problem with Tkinter on Mac OS X

2006-05-15 Thread Diez B. Roggisch
Jean Richelle schrieb:
> Hello,
> 
> I installed version 2.4.1 (and I tried also with 2.4.3) of Python under 
> 10.3.9 (and 10.4.6), and I trying to use Tkinter.  For simplicity I'm 
> testing the "hello world" that I found in the documentation.
> I first launch IDLE,  write (cut and paste from the web) the program in 
> an editing window, save it, and then run it. The window with two buttons 
> is displayed in the back of the IDLE window (and I cannot bring it to 
> the front), and there nothing happening when I click either button.
> Did anybody do a fresh install recently and can run program using Tkinter ?

MacOs is somewhat peculiar when it comes to running GUI-apps. What you 
ususally want to (or better have to do) is to cretae a so-called 
application bungle. There are several ways to do so - I frequenmtly code 
PyObjc-Applications and use xcode + the distutils py2app-extension. The 
latter one should work for Tkinter, too.

Then with my MacPython distro, there came a mac-specific IDE that also 
allowed to save a script as application.

I sugegst you read up on the whole subject here:

http://pythonmac.org/wiki/FAQ

and here

http://pythonmac.org/wiki/py2app

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


Re: New tail recursion decorator

2006-05-15 Thread Michele Simionato
Duncan Booth wrote:
> My other problem with this is that the decorator is very fragile although
> this may be fixable

This version should be more robust against exceptions:

class tail_recursive(object):
"""
tail_recursive decorator based on Kay Schluehr's recipe
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
"""
CONTINUE = object() # sentinel

def __init__(self, func):
self.func = func
self.firstcall = True

def __call__(self, *args, **kwd):
try:
if self.firstcall: # start looping
self.firstcall = False
while True:
result = self.func(*args, **kwd)
if result is self.CONTINUE: # update arguments
args, kwd = self.argskwd
else: # last call
break
else: # return the arguments of the tail call
self.argskwd = args, kwd
return self.CONTINUE
except: # reset and re-raise
self.firstcall = True
raise
else: # reset and exit
self.firstcall = True 
return result

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


Unicode to DOS filenames (to call FSUM.exe)

2006-05-15 Thread Christian Stooker
Hi !

Yesterday I got a very interesting bug.
I don't understand, why I got it, because I thinking about this 
function: that is safe.
But I was not.

The code:

import sys,os

UFN=u'%s\\xA\xff'%os.getcwd()
if os.path.exists(UFN):
os.remove(UFN)

f=open(UFN,'w')
f.write('%s\n'%('='*80))
f.close()

import win32api
dfn=win32api.GetShortPathName(UFN)

sys.exit()
###
Commandline: C:\Python24\python.exe G:\SPEEDT~1\Module1.py
Workingdirectory: G:\speedtest
Timeout: 0 ms

Traceback (most recent call last):
  File "G:\SPEEDT~1\Module1.py", line 14, in ?
dfn=win32api.GetShortPathName(UFN)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in 
position 15: ordinal not in range(128)

Process "Pyhton Interpeter" terminated, ExitCode: 0001
###


I want to get the sorter file name to pass it the FSUM.exe. But I got 
this error in every machine.
How to I avoid this error ? I need very safe code for my program.

Thanx for help:
dd


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


RE: Windows Copy Gui

2006-05-15 Thread Tim Golden
[placid]

| Just wondering if anyone knows how to pop up the dialog that windows
| pops up when copying/moving/deleting files from one directory to
| another, in python ?  

http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html#shell

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Tabs versus Spaces in Source Code

2006-05-15 Thread mystilleef
I agree, use tabs.

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


Re: Tabs versus Spaces in Source Code

2006-05-15 Thread Mumia W.
Xah Lee wrote:
> Tabs versus Spaces in Source Code
> 
> Xah Lee, 2006-05-13
> 
> In coding a computer program, there's often the choices of tabs or
> spaces for code indentation. There is a large amount of confusion about
> which is better. It has become what's known as “religious war” —
> a heated fight over trivia. In this essay, i like to explain what is
> the situation behind it, and which is proper.
> 

Thanks Xah. I value your posts. Keep posting. And since your posts 
usually cover broad areas of CS, keep crossposting. Don't go anywhere 
Xah :-)


> Simply put, tabs is proper, and spaces are improper. Why? This may seem
> ridiculously simple given the de facto ball of confusion: the semantics
> of tabs is what indenting is about, while, using spaces to align code
> is a hack.
> 

I wouldn't say that spaces are a hack, but tabs are superior.

> Now, tech geekers may object this simple conclusion because they itch
> to drivel about different editors and so on. The alleged problem
> created by tabs as seen by the industry coders are caused by two
> things: (1) tech geeker's sloppiness and lack of critical thinking
> which lead them to not understanding the semantic purposes of tab and
> space characters. (2) Due to the first reason, they have created and
> propagated a massive none-understanding and mis-use, to the degree that
> many tools (e.g. vi) does not deal with tabs well and using spaces to
> align code has become widely practiced, so that in the end spaces seem
> to be actually better by popularity and seeming simplicity.
> 

Don't forget the laziness of programmers like me who don't put the 
tabbing information in the source file. Vim deals with tabs well IMO, 
but I almost never used to put the right auto-commands in the file to 
get it set up right for other users.

> In short, this is a phenomenon of misunderstanding begetting a snowball
> of misunderstanding, such that it created a cultural milieu to embrace
> this malpractice and kick what is true or proper. Situations like this
> happens a lot in unix. For one non-unix example, is the file name's
> suffix known as “extension”, where the code of file's type became
> part of the file name. (e.g. “.txt”, “.html”, “.jpg”).
> Another well-known example is HTML practices in the industry, where
> badly designed tags from corporation's competitive greed, and stupid
> coding and misunderstanding by coders and their tools are so
> wide-spread such that they force the correct way to the side by the
> eventual standardization caused by sheer quantity of inproper but set
> practice.
> 
> Now, tech geekers may still object, that using tabs requires the
> editors to set their positions, and plain files don't carry that
> information. This is a good question, and the solution is to advance
> the sciences such that your source code in some way embed such
> information. 

Vim does this. We just have to use it.

 > This would be progress. However, this is never thought of
> because the “unix philosophies” already conditioned people to hack
> and be shallow. In this case, many will simply use the character
> intended to separate words for the purpose of indentation or alignment,
> and spread the practice with militant drivels.
> 
> Now, given the already messed up situation of the tabs vs spaces by the
> unixers and unix brain-washing of the coders in the industry... Which
> should we use today? I do not have a good proposition, other than just
> use whichever that works for you but put more critical thinking into
> things to prevent mishaps like this.
> 
> Tabs vs Spaces can be thought of as parameters vs hard-coded values, or
> HTML vs ascii format, or XML/CSS vs HTML 4, or structural vs visual, or
> semantic vs format. In these, it is always easy to convert from the
> former to the latter, but near impossible from the latter to the
> former. And, that is because the former encodes information that is
> lost in the latter. 

Nope. Conversion is relatively easy. I've written programs to do this 
myself, and everyone and his brother has also done this. Virtually every 
programmer's editor that I've ever used can do this, and a great, great 
many independent programs convert tabs to spaces. It's like saying, 
"it's near impossible to write a calculator program." :-)

I bet that someone has a Perl one-liner to do it.

On any Debian system, try a "man expand" and see what you find. Also, 
emacs and vim do it. Perl has a Text::Tabs module. TCL's 
::textutil::(un)?tabify routines do it. The birds do it, and the bees do 
it. Oh wait, that's something else :-)

 > If we look at the issue of tabs vs spaces, indeed,
> it is easy to convert tabs to spaces in a source code, but more
> difficult to convert from spaces to tabs. 

Nope again. It's easy, you just keep track of the virtual character 
position as you decide whether to write a space or a tab. Computers do 
the "counting" thing fairly well.

 > Because, tabs as indentation
> actually contains the semantic inf

Re: Starting/launching eric3

2006-05-15 Thread Michele Petrazzo
Byte wrote:
> OK, now I've managed to get it working, but when I run it the eric3
> splash screen pops up, and then it says (in terminal):
> 
> [EMAIL PROTECTED]:~$ eric3
> Traceback (most recent call last):
>   File "/usr/lib/site-python/eric3/eric3.py", line 147, in ?
> main()
>   File "/usr/lib/site-python/eric3/eric3.py", line 132, in main
> mw = UserInterface(loc, splash)
>   File "/usr/lib/site-python/eric3/UI/UserInterface.py", line 265, in
> __init__
> self.sbv = SBVviewer(dbs, self.sbvDock, 1)
>   File "/usr/lib/site-python/eric3/UI/SBVviewer.py", line 75, in
> __init__
> self.stackComboBox.sizePolicy().hasHeightForWidth()))
> TypeError: argument 1 of QSizePolicy() has an invalid type
> Segmentation fault
> [EMAIL PROTECTED]:~$
> 
> Its not ment to do that... how to make it work right??

Just happen on my costumer ubuntu (and an old eric3 release).
I have solve it downloading the last (3.9.x if I remember correctly)
from eric3 home and overwrite the site-packages/eric directory. Now all
work great.


> 
>  -- /usr/bin/byte
> 

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


Re: Windows Copy Gui

2006-05-15 Thread placid

Tim Golden wrote:
> [placid]
>
> | Just wondering if anyone knows how to pop up the dialog that windows
> | pops up when copying/moving/deleting files from one directory to
> | another, in python ?
>
> http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html#shell

thanks, thats what i was after

>
> TJG
>
> 
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> 

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


Re: retain values between fun calls

2006-05-15 Thread bruno at modulix
Gary Wessle wrote:
> Hi
> 
> the second argument in the functions below suppose to retain its value
> between function calls, the first does, the second does not and I
> would like to know why it doesn't? 

Fisrt thing to remember is that function's default args are eval'd only
once - when the def block is eval'd, which is usually at import time.

> # it does
> def f(a, L=[]):
> L.append(a)

Here, you are modifying the (list) object bound to local name L.

> return L
> print f('a')
> print f('b')
> 
> 
> # it does not
> def f(a, b=1):
> b = a + b

And here, you are *rebinding* the local name b to another object.
Understand that modifying an object in-place and rebinding a name are
two really different operations...

> return b
> print f(1)
> print f(2)

> and how to make it so it does?

The Q&D solution is to wrap :

def f(a, b = [1])
  b[0] = b[0] + a
  return b[0]

But this is really a hack - it's ok for a throw-away script, but may not
be the best thing to do in a more serious piece of software.

The clean solution to maintain state between calls is to use a custom
class - hopefully, Python is OO enough to let you write your own callables:

class MyFunc(object):
  def __init__(self, initstate=1):
self._state = default
  def __call__(self, a):
 self._state += a
 return self._state

f = MyFunc(1)
print f(1)
print f(2)

HTH

-- 
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: Decorator

2006-05-15 Thread Michele Simionato
I will shamelessly plug in my own decorator module:
http://www.phyast.pitt.edu/~micheles/python/decorator.zip and
http://www.phyast.pitt.edu/~micheles/python/documentation.html

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


Re: Web framework to recommend

2006-05-15 Thread Sybren Stuvel
Jacky enlightened us with:
> I just started learning Python and would like to starting writing
> some web-based applications with Python.

You could check out my web framework, the UnrealTower Engine. It uses
Cheetah as template engine, it's fast and small - it doesn't get in
your way.

http://www.unrealtower.org/engine

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any plans to make pprint() a builtin?

2006-05-15 Thread Ant
Considering that the current:

import pprint
pprint.pprint(x)

is hardly lengthy, I can't see how either of the alternatives proposed
are any better.

> python.pprint.pprint(x)

6 characters shorter, but considerably more keystrokes if you are using
pprint more than once. Is it worth adding the 'python' builtin to save
an import statement?

> import py
> py.std.pprint.pprint(x)

Longer, messy, and what's the actual point? Wouldn't:

import pprint as pp
pp.pprint(x)

be better, standard *and* shorter?

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


Re: comparing values in two sets

2006-05-15 Thread Gerard Flanagan
John Salerno wrote:
> I'd like to compare the values in two different sets to test if any of
> the positions in either set share the same value (e.g., if the third
> element of each set is an 'a', then the test fails).
>
> I have this:
>
> def test_sets(original_set, trans_letters):
>  for pair in zip(original_set, trans_letters):
>  if pair[0] == pair[1]:
>  return False
>  return True
>
>
> zip() was the first thing I thought of, but I was wondering if there's
> some other way to do it, perhaps a builtin that actually does this kind
> of testing.
>
> Thanks.

'enumerate' is another possibility:

s1 = 'abcd'
s2 = ''
s3 = 'zbzz'
s4 = 'zzbz'

def are_itemwise_different( L1, L2 ):
#if len(L1) != len(L2): return True
for idx, value in enumerate(L1):
if value == L2[idx]:
return False
return True

#after Peter Otten
def are_itemwise_different( L1, L2 ):
#if len(L1) != len(L2): return True
return True not in ( value == L2[idx] for idx, value in
enumerate(L1) )

assert are_itemwise_different(s1,s2)
assert not are_itemwise_different(s1,s3)
assert are_itemwise_different(s1,s4)

def itemwise_intersect( L1, L2 ):
#if len(L1) != len(L2): raise
for idx, value in enumerate(L1):
if value == L2[idx]:
yield value

assert list(itemwise_intersect(s1,s2)) == []
assert list(itemwise_intersect(s1,s3)) == ['b']
assert list(itemwise_intersect(s1,s4)) == []  

Gerard

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


Re: Web framework to recommend

2006-05-15 Thread bruno at modulix
Jacky wrote:
> Hi all,
> 
> I just started learning Python and would like to starting writing some
> web-based applications with Python.
> 
> I did have pretty much experience with doing so with PHP and Java, but
> Python seems a bit different for me.
> 
> Do you guys have some good web framework to recommend? (I don't want to
> use CGI mode)

There's quite a lot of (good) web frameworks for Python, and choosing
the right one depends a lot on specific requirements you didn't express...


-- 
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: Web framework to recommend

2006-05-15 Thread BLeAm
Hi Jacky,

Even though Turbogears and Django are focused from many people,
and I'm not so sure whether this the best or not,
but let's check at http://spyce.sourceforge.net,
you can embed Python script into the page just like JPS,ASP,PHP.

Hope this help.

Cheers!

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


Making all string literals Unicode

2006-05-15 Thread Richie Hindle
Hi,

Am I imagining it, or is there a switch or an environment variable to
make Python treat all string literals as unicode?  I seem to recall
seeing it mentioned somewhere, but now I can't find it anywhere.

Thanks,

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible constant assignment operators ":=" and "::=" for Python

2006-05-15 Thread Piet van Oostrum
> Edward Elliott <[EMAIL PROTECTED]> (EE) wrote:

>EE> Piet van Oostrum wrote:
 [EMAIL PROTECTED] (T) wrote:
>>> 
>T> As you can see, the "constant" A can be modified this easily. But if
>T> there were an intuitive mechanism to declare a symbol to be immutable,
>T> then there won't be this problem.
>>> 
>>> Mutability is not a property of symbols but of values. So it doesn't make
>>> sense to declare an identifier to be immutable. And mutability is tied to
>>> the object's type, not to individual instances.

>EE> I think he meant immutable binding, not immutable symbol. So
>EE> rebinding/overshadowing a "constant" A would raise an error, but
>EE> mutating the underlying object A refers to would not (unless it too
>EE> were immutable).

The way I understood it was that he meant both.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


List and order

2006-05-15 Thread Nic
Hello,
I'm using the NetworkX Python package (https://networkx.lanl.gov/).
Through this package I wrote the following code:

import networkx as NX
G=NX.Graph()
G.add_edge(1,2)
G.add_edge(2,3)
G.add_edge(3,4)
ddeg=G.degree(with_labels=True)
for (u,v) in G.edges():
print ddeg[u],ddeg[v]

As result, I have:

12
22
21

I'd like to order the numbers included in the couples in a decrescent way:

12
12
22

And then to write the couples on a single line, always in a decrescent way:
12 12 22

I'm not able to do this operation. Can you help me please?
Thanks a bunch,
Nic 


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


Re: Making all string literals Unicode

2006-05-15 Thread Thomas Heller
Richie Hindle wrote:
> Hi,
> 
> Am I imagining it, or is there a switch or an environment variable to
> make Python treat all string literals as unicode?  I seem to recall
> seeing it mentioned somewhere, but now I can't find it anywhere.
> 
> Thanks,
> 
python -U

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


Re: Web framework to recommend

2006-05-15 Thread Jacky
Hi all,

Thanks all of you for your recommendations, I'll check them out one by one.

Besides, I'd like to say more about what I want to do.  Since I'm 
planning to write something for "backend", I might not focus very much 
on the layout (HTML template) yet.  Instead, I'd like to receive inputs 
in XML format and then output XML after processing (or maybe I should 
use web services, perhaps?).

Of course, I will write a complete web application in my other projects 
(such as those I wrote with PRADO and JSF), so all recommendations are 
welcomed :)

Thank you!


Best Wishes,

Jacky




Jacky wrote:
> Hi all,
> 
> I just started learning Python and would like to starting writing some 
> web-based applications with Python.
> 
> I did have pretty much experience with doing so with PHP and Java, but 
> Python seems a bit different for me.
> 
> Do you guys have some good web framework to recommend? (I don't want to 
> use CGI mode)
> 
> Thanks a lot.
> 
> -- 
> Jacky
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework to recommend

2006-05-15 Thread bruno at modulix
Jacky wrote:
> Hi all,
> 
> Thanks all of you for your recommendations, I'll check them out one by one.
> 
> Besides, I'd like to say more about what I want to do.  Since I'm
> planning to write something for "backend", I might not focus very much
> on the layout (HTML template) yet.  Instead, I'd like to receive inputs
> in XML format and then output XML after processing (or maybe I should
> use web services, perhaps?).
>
> Of course, I will write a complete web application in my other projects
> (such as those I wrote with PRADO and JSF), so all recommendations are
> welcomed :)

You might want to have a look at Turbogears.



> Thank you!
> 
> 
(snip)

-- 
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


[ANN] pykill32 0.2

2006-05-15 Thread Manlio Perillo
pykill32 is a small library that enable developers and users on Windows
2000/XP to send signals to a Python process.

It emulates the POSIX kill.
There is also a script, kill.py, with a minimal emulation of POSIX kill(1).

And a simple dumpbin.py script that list all modules (DLL) loaded by a
process.

pykill32 works by creating a thread on the *remote* process
(CreateRemoteThread) that calls the raise procedure from the MSVCR71 module.

It just works fine for Twisted processes.


The library can be found on:
http://developer.berlios.de/projects/pykill32/

and via SVN:
http://svn.berlios.de/svnroot/repos/pykill32/trunk


Regards  Manlio Perillo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do you run database scripts/where are DBs 'located'?

2006-05-15 Thread NoNickName
Gerard Flanagan wrote:

> Interactive SQL tutorial:  http://www.sqlcourse.com/  ;
> http://sqlcourse2.com/
>
> Indirectly helpful maybe:
> http://initd.org/tracker/pysqlite/wiki/basicintro
>
> HTH
>
> Gerard

There's also the TechBookReport SQL tutorial - which is geared to MySQL
(and, shudder, Access). Take a look at
http://www.techbookreport.com/sql-tut1.html

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


Re: A critic of Guido's blog on Python's lambda

2006-05-15 Thread Ben


Nothing you have described sounds that complicated, and you never come
up with concrete objections to other peoples code (apart that it took
10 years to write in Lisp, so it must be really hard)

Why are you running a SoC project for PyCells if you dislike the
language so much. People who do like Python can implement it if they
need it (which I haven't seen any good examples that they do)

Please don't force a student to create a macro system just to port a
system to Python, as it won't really be python then. Use Pythonic
methodology instead. There are already plenty of ways to hide
complicated functionality, just not necessarily the way you want to do
it.

Cheers,
Ben

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


please help me is sms with python

2006-05-15 Thread huda ahmed
hi 
please i need your help .

how can i send sms from pc(windows xp)
to mobile symbian 60 6630 by python

i need your help please
i hope you answer me as fast as u can

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


Re: Python Translation of C# DES Encryption

2006-05-15 Thread Andreas Pauley
Edward Elliott wrote:

>You need to find the exact algorithm the DESCryptoServiceProvider uses.  
>CBC and CTR are common modes with IVs.  Besides mode of operation, there's
>the issue of how it pads the data (in the cipher, not base64).  There could
>also be differences in things like the key scheduling routines, but that's
>less likely.  Until you know exactly what the original code does, your only
>option is trial and error.
>
>  
>
I read some of the C# documentation on DESCryptoServiceProvider, but it 
was completely useless for
my purpose. The documentation basically only tells you how to use the 
class, not what it does.

I managed to *decrypt* a string encrypted by the C# method using CBC 
mode, as suggested by Gary (thanks).
The python CBC encryption results in a different encrypted string, but 
decrypting both these strings
returns the original plaintext value.

As for padding, the C# method uses characters '\x01' to '\x07' for padding.
If there are 3 padding characters needed (eg with a password of 5 
chars), then three '\x03' chars will be used.
Similarly, a 2-char password will be padded with '\x06' * 6

Regards,
Andreas Pauley

_
This e-mail contains official information from Quality Business Consultants 
(Pty) Ltd and is intended for use by the addressee only.
Important notice: Important restrictions, qualifications and disclaimers ("the 
Disclaimer") apply to this email.
To read this click on the following address: http://www.qbcon.com/disclaimer
The Disclaimer forms part of the content of this email in terms of section 11 
of the Electronic Communications and Transactions Act, 25 of 2002. If you are 
unable to access the Disclaimer, send a blank e-mail to [EMAIL PROTECTED] and 
we will send you a copy of the Disclaimer.

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


How to organise classes and modules

2006-05-15 Thread Alex
Hi, this is my first mail to the list so please correct me if Ive done
anything wrong.

What Im trying to figure out is a good way to organise my code. One
class per .py file is a system I like, keeps stuff apart. If I do
that, I usually name the .py file to the same as the class in it.

File: Foo.py
***
class Foo:
 def __init__(self):
  pass
 def bar(self):
  print 'hello world'



Now, in my other module, I want to include this class. I tried these two ways:

>>> import Foo
>>> Foo.Foo.bar()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unbound method bar() must be called with Foo instance as
first argument (got nothing instead)

Some unbound method error. Have I missunderstood something or am I on
the right track here?

I did this to, almost the same thing:

>>> from Foo import Foo
>>> Foo.bar()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unbound method bar() must be called with Foo instance as
first argument (got nothing instead)

One thing that I tried that worked ok was this:

>>> import Foo
>>> instance=Foo.Foo()
>>> instance.bar()
hello world

But in my opinion, this is very ugly. Especially if the class names
are long, like my module/class TileDataBaseManager. But is this the
"right" way in python?

Another (ugly) way that Ive considered is the following. Break it out
of the class, save the functions in a file alone, import the file and
treat it like a class:

File: Foo2.py
***
def bar(self):
 print 'hello world'



>>> import Foo2
>>> Foo2.bar()
hello world

Very clean from the outside. I would like something like this. But,
here, I loose the __init__ function. I have to call it manually that
is, which s not good. Also, maybe the biggest drawback, its no longer
in a class. Maybe its not that important in python but from what Ive
learned (in c++) object orientation is something to strive for.

So, to sum it up, I have one class in one file, both with the same
name. How do I store/import/handle it in a nice, clean and python-like
manner?

Thank you very much in advance.
/ Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework to recommend

2006-05-15 Thread Miki
Hello Jacky,

I found CherryPy + Cheeta a good solution.
See (shameless plug)
http://www.unixreview.com/documents/s=10075/ur0604h/

Miki
http://pythonwise.blogspot.com

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


Re: Unicode to DOS filenames (to call FSUM.exe)

2006-05-15 Thread John Machin
According to my reading of the source, the function you have called
expects an 8-bit string.

static PyObject *
PyGetShortPathName(PyObject * self, PyObject * args)
{
char *path;
if (!PyArg_ParseTuple(args, "s:GetShortPathName", &path))

If it is given Unicode, PyArg_ParseTuple will attempt to encode it
using the default encoding (ascii). Splat.

Looks like you need a GetShortPathNameW() but it's not implemented.
Raise it as an issue on the pywin32 sourceforge bug register. Tell Mark
I sent you :-)

It may be possible to fake up your default encoding to say cp1252 BUT
take the advice of anyone who screams "Don't do that!" and in any case
this wouldn't help you with a Russian, Chinese, etc etc filename.

Another thought: try using ctypes.

Hope some of this helps,
John

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


Re: please help me is sms with python

2006-05-15 Thread Diez B. Roggisch
huda ahmed wrote:

> hi 
> please i need your help .
> 
> how can i send sms from pc(windows xp)
> to mobile symbian 60 6630 by python
> 
> i need your help please
> i hope you answer me as fast as u can
> 
> thanks in advance..

Attach a Mobile to your computer using USB/Bluetooth, open it with a
terminal program and use these AT-commands.

http://www.cellular.co.za/hayesat.htm#SMS Command Set

You can do that in python too, by opening the COM-port the handset is
attached to and issuing the commands yourself.

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


Re: comparing values in two sets

2006-05-15 Thread Gerard Flanagan

Gerard Flanagan wrote:
> John Salerno wrote:
> > I'd like to compare the values in two different sets to test if any of
> > the positions in either set share the same value (e.g., if the third
> > element of each set is an 'a', then the test fails).
> >
> > I have this:
> >
> > def test_sets(original_set, trans_letters):
> >  for pair in zip(original_set, trans_letters):
> >  if pair[0] == pair[1]:
> >  return False
> >  return True
> >
> >
> > zip() was the first thing I thought of, but I was wondering if there's
> > some other way to do it, perhaps a builtin that actually does this kind
> > of testing.
> >
> > Thanks.
>
> 'enumerate' is another possibility:
>
> s1 = 'abcd'
> s2 = ''
> s3 = 'zbzz'
> s4 = 'zzbz'
>
> def are_itemwise_different( L1, L2 ):
> #if len(L1) != len(L2): return True
> for idx, value in enumerate(L1):
> if value == L2[idx]:
> return False
> return True
>
> #after Peter Otten
> def are_itemwise_different( L1, L2 ):
> return True not in ( val == L2[idx] for idx, val in enumerate(L1) )
>
> assert are_itemwise_different(s1,s2)
> assert not are_itemwise_different(s1,s3)
> assert are_itemwise_different(s1,s4)
>

s1 = 'abcd'
s2 = ''
s3 = 'zbzz'
s4 = 'zzbz'
s5 = 'xbxx'

def itemwise_intersect( L1, L2 ):
return [value for idx, value in set(enumerate(L1)) &
set(enumerate(L2))]

assert itemwise_intersect(s1,s2) == []
assert itemwise_intersect(s1,s3) == ['b']
assert itemwise_intersect(s1,s4) == []

def itemwise_intersect( *args ):
s = set(enumerate(args[0]))
for t in ( set(enumerate(X)) for X in args[1:]):
s.intersection_update(t)
return [val for i,val in s]

assert itemwise_intersect(s1,s3,s5) == ['b']   

Gerard

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


Re: How to organise classes and modules

2006-05-15 Thread Ilkka Poutanen

On 2006-05-15, Alex <[EMAIL PROTECTED]> wrote:
 import Foo
 Foo.Foo.bar()
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: unbound method bar() must be called with Foo instance as
> first argument (got nothing instead)
>
> ...
>
> One thing that I tried that worked ok was this:
>
 import Foo
 instance=Foo.Foo()
 instance.bar()
> hello world
>
> But in my opinion, this is very ugly. Especially if the class names

Are you sure you understand object-oriented programming? Reading the
Python tutorial[1] and re-reading the above error messages should clue
you in to what you're doing wrong. To put it simply, the whole point of
classes is that you create instances of them, each having their own
internal state, and then invoke their methods to accomplish whatever it
is that you want your program to accomplish.

1. http://docs.python.org/tut/


-- 
Ilkka Poutanen [http://ipo.iki.fi/]
And unto this, Conan;
-- 
http://mail.python.org/mailman/listinfo/python-list


Two ZSI questions

2006-05-15 Thread robin . diederen
Hi,

I'm currently developing a SOAP client for the Zimbra collaboration
suite (www.zimbra.com). I'm writing a WSDL and using ZSI's "wsdl2py.py"
to export it to Python code. There are two things I can't get to work
and I cannot find any documentation on.

1. The Zimbra framework requires messages to be formed like this:

robin

How do I get the 'by="name"' part in the method tag? The "name" is
variable; other values, like
"id" etc...
I'd like to define this in the WSDL; but I can't find how. Also, I
can't find wether ZSI supports such constructs...

2. I need to attach headers to my SOAP requests. How do I put the
headers in the SOAP message, using the WSDL? If I get the headers in,
will I (from the client) code need to invoke them  manually?

Examples are welcome of course :)

Thanks, Robin

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


Re: List of lists of lists of lists...

2006-05-15 Thread Ángel Gutiérrez Rodríguez
bruno at modulix wrote:

> for N:
>   mylist = [mylist]
> 
Right that!

> I'm afraid I don't understand. Could you forgive my stupidity and
> re-explain this a bit more clearly ?
> 
No need to. Former solution worked fine. Thanks!
-- 
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Química Física y Analítica 
Universidad de Oviedo - c/Julián Clavería 8 33006 - Oviedo 
Asturias - Spain
E-mail: [EMAIL PROTECTED] Telf.: +34-985103687
-- 
http://mail.python.org/mailman/listinfo/python-list

[ANN] PyYAML-3.02: YAML parser and emitter for Python

2006-05-15 Thread Kirill Simonov

 Announcing PyYAML-3.02


A new bug-fix release of PyYAML is now available:

http://pyyaml.org/wiki/PyYAML


Changes
===

* Fix win32 installer.  Apparently bdist_wininst does not work well under
  Linux.
* Fix a bug in add_path_resolver.
* Add the yaml-highlight example.  Try to run on a color terminal:
  `python yaml_hl.py http://pyyaml.org/wiki/PyYAML
PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation

TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.02.tar.gz
ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.02.zip
Windows installer: http://pyyaml.org/download/pyyaml/PyYAML-3.02.win32.exe

PyYAML SVN repository: http://svn.pyyaml.org/pyyaml
Submit a bug report: http://pyyaml.org/newticket?component=pyyaml

YAML homepage: http://yaml.org/
YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core


About PyYAML


YAML is a data serialization format designed for human readability and
interaction with scripting languages.  PyYAML is a YAML parser and
emitter for Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
support, capable extension API, and sensible error messages.  PyYAML
supports standard YAML tags and provides Python-specific tags that allow
to represent an arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance.


Example
===

>>> import yaml

>>> yaml.load("""
... name: PyYAML
... description: YAML parser and emitter for Python
... homepage: http://pyyaml.org/wiki/PyYAML
... keywords: [YAML, serialization, configuration, persistance, pickle]
... """)
{'keywords': ['YAML', 'serialization', 'configuration', 'persistance',
'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description':
'YAML parser and emitter for Python', 'name': 'PyYAML'}

>>> print yaml.dump(_)
name: PyYAML
homepage: http://pyyaml.org/wiki/PyYAML
description: YAML parser and emitter for Python
keywords: [YAML, serialization, configuration, persistance, pickle]


Copyright
=

The PyYAML module is written by Kirill Simonov <[EMAIL PROTECTED]>.

PyYAML is released under the MIT license.


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


Re: Unicode to DOS filenames (to call FSUM.exe)

2006-05-15 Thread DurumDara
John Machin írta:
> According to my reading of the source, the function you have called
> expects an 8-bit string.
> 
> static PyObject *
> PyGetShortPathName(PyObject * self, PyObject * args)
> {
>   char *path;
>   if (!PyArg_ParseTuple(args, "s:GetShortPathName", &path))
> 
> If it is given Unicode, PyArg_ParseTuple will attempt to encode it
> using the default encoding (ascii). Splat.
>
> Looks like you need a GetShortPathNameW() but it's not implemented.
> Raise it as an issue on the pywin32 sourceforge bug register. Tell Mark
> I sent you :-)
>
> It may be possible to fake up your default encoding to say cp1252 BUT
> take the advice of anyone who screams "Don't do that!" and in any case
> this wouldn't help you with a Russian, Chinese, etc etc filename.
>
> Another thought: try using ctypes.
>   

Hi !

I trying with that, but I get error, because the result is unicode 
too... :-(((

from ctypes import windll, create_unicode_buffer, sizeof, WinError
buf=create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(UFN,buf,sizeof(buf)):
name=buf.value
print [name]

##
Commandline: C:\Python24\python.exe G:\SPEEDT~1\Module1.py
Workingdirectory: G:\speedtest
Timeout: 0 ms

[u'G:\\SPEEDT~1\\xA\xff']

Process "Pyhton Interpeter" terminated, ExitCode: 
##

 Can I do anything with this unicoded filename ? My code must be universal !

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


Re: List of lists of lists of lists...

2006-05-15 Thread Ángel Gutiérrez Rodríguez
Robert Kern wrote:
> James Stroud wrote:
> http://numeric.scipy.org
> 
Thanks! That's anotehr solution, yes!
-- 
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Química Física y Analítica 
Universidad de Oviedo - c/Julián Clavería 8 33006 - Oviedo 
Asturias - Spain
E-mail: [EMAIL PROTECTED] Telf.: +34-985103687
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to organise classes and modules

2006-05-15 Thread bruno at modulix
Alex wrote:
> Hi, this is my first mail to the list so please correct me if Ive done
> anything wrong.
> 
> What Im trying to figure out is a good way to organise my code. One
> class per .py file is a system I like, keeps stuff apart. If I do
> that, I usually name the .py file to the same as the class in it.

First point is that Python doesn't force you to put everything in
classes - if you just need a function, well, make it a function !-)

Also, the common pattern is to put closely related
classes/functions/constants in a same module, and closely related
modules in the same package. Since Python uses a "one file == one
module" scheme, the Javaish "one class per file" idiom leads to overly
complicated imports. And the most common naming scheme for modules is
'alllowercase'.



> File: Foo.py
> ***
> class Foo:
> def __init__(self):
>  pass
> def bar(self):
>  print 'hello world'
> 
> 
> 
> Now, in my other module, I want to include this class. I tried these two
> ways:
> 
 import Foo
 Foo.Foo.bar()
>
> Traceback (most recent call last):
>  File "", line 1, in ?
> TypeError: unbound method bar() must be called with Foo instance as
> first argument (got nothing instead)
> 
> Some unbound method error. Have I missunderstood something 

Yes:
1/ you usually need to instanciate the class to call an instance method
1/ in this case, bar doesn't need to be a method, since it doesn't
depend on the instance it's called on - a plain old function would be a
better fit.

> or am I on
> the right track here?
> 
> I did this to, almost the same thing:
> 
 from Foo import Foo
 Foo.bar()
> 
> Traceback (most recent call last):
>  File "", line 1, in ?
> TypeError: unbound method bar() must be called with Foo instance as
> first argument (got nothing instead)
> 
> One thing that I tried that worked ok was this:
> 
 import Foo
 instance=Foo.Foo()
 instance.bar()
> 
> hello world
> 
> But in my opinion, this is very ugly.

Nope, it's just OO at work.

> Especially if the class names
> are long, like my module/class TileDataBaseManager. But is this the
> "right" way in python?

If you want to import a class from a module and create an instance of
that class, yes.

> Another (ugly) way that Ive considered is the following. Break it out
> of the class,

Which would be a sensible thing to do given the current implementation
of bar().

> save the functions in a file alone,

Nothing prevent you from putting many functions in a same module, you
know...

> import the file

s/file/module/

> and
> treat it like a class:

???

> File: Foo2.py
> ***
> def bar(self):
> print 'hello world'
> 
> 
> 
 import Foo2
 Foo2.bar()
> 
> hello world

You don't "treat it like a class", you're just using the normal
namespace resolution mechanism. Modules are namespaces, classes are
namespaces, objects (class instances) are namespaces, and the dot is the
 lookup operator (ie : somenamespacename.somename means 'retrieve what's
actually bound to name 'somename' in namespace 'somenamespacename').

> Very clean from the outside. I would like something like this. But,
> here, I loose the __init__ function. 

Which in the given implementation is just doing nothing.

Ok, I understand that this is just example code. The rule here is:
- if you need per-instance state management, use a class (that you of
course need to instanciate - else you can't have per-instance state !-)
- if you don't need per-instance state management, use a plain function.

> I have to call it manually that
> is, which s not good. Also, maybe the biggest drawback, its no longer
> in a class.

def MyFunc():
  pass

print MyFunc.__class__.__name__

Python function's are instances of the function class.

> Maybe its not that important in python but from what Ive
> learned (in c++) object orientation is something to strive for.

print "object orientation".find("class")

Being OO doesn't mean using classes. And FWIW, there quite enough
procedural Java code around to prove that using classes doesn't mean
doing OO !-) 

> So, to sum it up, I have one class in one file, both with the same
> name. How do I store/import/handle it in a nice, clean and python-like
> manner?

Quit the Javaish "one-class-per-file" idiom, don't bother using classes
when plain old function will do, and you'll be on track...

FWIW, Python's standard lib is open-source, so why not have a look at
the source code to see how it is organized ?

HTH
-- 
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: Unicode to DOS filenames (to call FSUM.exe)

2006-05-15 Thread DurumDara
John Machin írta:
> Looks like you need a GetShortPathNameW() but it's not implemented.
> Raise it as an issue on the pywin32 sourceforge bug register. Tell Mark
> I sent you :-)
> Another thought: try using ctypes.
>   

Hi !

It seems to be I found a solution. A little tricky, but it is working:
#
import sys,os
from sys import argv as sysargv

UFN=u'%s\\xA\xff'%os.getcwd()
if os.path.exists(UFN):
 os.remove(UFN)

f=open(UFN,'w')
f.write('%s\n'%('='*80))
f.close()

from ctypes import windll, create_unicode_buffer, sizeof, WinError
buf=create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(UFN,buf,sizeof(buf)):
 fname=buf.value
 #import win32api
 #dfn=win32api.GetShortPathName(name)
 #print dfn
else:
 raise
shortpath,filename=os.path.split(fname)

import win32file
filedatas=win32file.FindFilesW(fname)
fd=filedatas[0]
shortfilename=fd[9] or fd[8]

shortfilepath=os.path.join(shortpath,shortfilename)

print [UFN]
print shortfilepath

f=open(shortfilepath,'r')
print f.read()

sys.exit()

But I don't understand: why the shortpathw not convert the filename too 
(like dir) ?


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


Re: How to organise classes and modules

2006-05-15 Thread Diez B. Roggisch
> Some unbound method error. Have I missunderstood something or am I on
> the right track here?

You misunderstood that you'd have to create an instance first before
invoking a method on that very instance. That is the same in C++, btw.

> But in my opinion, this is very ugly. Especially if the class names
> are long, like my module/class TileDataBaseManager. But is this the
> "right" way in python?

I'm not sure what you mean by ugly. If you mean by ugly that you have to
instantiate an object before using it - that is the way it works in _all_
OO languages. 

If you mean that you find it ugly to have long modulenames that are the same
as the class-name - yes it is ugly - but that is utterly your personal
decision to do so. In python, modules usually contain several classes, and
the module name groups them by function and has a name related to that
function. So most of the times one writes

import module

o = module.Class()

Which is not ugly - IMHO at least :) Especially not more ugly than using C++
namespaces, isn't it? And that is what a module essentially is: a
namespace. 


> Very clean from the outside. I would like something like this. But,
> here, I loose the __init__ function. I have to call it manually that
> is, which s not good. Also, maybe the biggest drawback, its no longer
> in a class. Maybe its not that important in python but from what Ive
> learned (in c++) object orientation is something to strive for.

You seem to have some troubles with OO in general and with the way python
does it. So I think it is kind of funny if you claim it is something to
strive for. OO is no silver bullet - if you have something that can be
dealt with using a function, it's perfectly good design to use one. Having
objects just for the sake of it introduces all sorts of problems, related
to unnecessary state, unclear implementation smeared over  several methods
an the like.

> So, to sum it up, I have one class in one file, both with the same
> name. How do I store/import/handle it in a nice, clean and python-like
> manner?

Group classes that belong to the same domain in one module. Import that,
possibly using an alias like

import MyLongDescriptiveModuleName as mn

don't fall for the temptation to use

from MyLongDescriptiveModuleName import *

as it will cause only more headache!

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


Re: please help me is sms with python

2006-05-15 Thread [EMAIL PROTECTED]
Yet another option:
Use web-service provided by your mobile operator
(by means of cookielib, urllib2, etc).

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


Re: List and order

2006-05-15 Thread Nic
Hello Miki,

Many thanks for the support.
I tried to insert and execute the code, but the following error happens:

Traceback (most recent call last):
  File "grafodna.py", line 10, in ?
edges.sort(key = lambda u, v: (ddeg(u), ddeg(v)))
TypeError: () takes exactly 2 arguments (1 given)

Do you know how is it possible to delete it?
Thanks.

Nic

"Miki" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]
> Hello Nic,
>
> Python lists has a very powerfull buid-in "sort".
>
> edges = list(G.edges())
> edges.sort(key = lambda u, v: (ddeg(u), ddeg(v)))
> for u, v in edges:
>print u,v,  # Note the training comma to avoid newline
> print
>
> HTH,
> Miki
> http://pythonwise.blogspot.com
> 


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


RE: Formmating excel cells with PyExcelerator or COM

2006-05-15 Thread Tim Golden
[Mauricio Tellez]

| Hi, I just want that a number like 1234.123 appear in excel 
| as 1,234.12
| In excel I just select some cells, then right click on them 
| and select "Cell Formatting" then select Number, and check 
| "Use thounsands separator" and 2 decimal places. I can't find 
| how to do this with PyExcelerator neither with COM. Any clue? 

Nearly always, a good starting point for doing this
kind of thing with COM (obviously doesn't apply for
PyExcelerator) is to record a Macro in Excel itself
which does what you want, and then to translate the
code that macro uses into Python -- usually trivial.

Here, I stuck a number into Excel, applied formatting
as you described, and the result was:

Selection.NumberFormat = "#,##0.00"

Obviously you have to do whatever you need around
that to apply the formatting to the range of values
you're interested in, but a (negligible) working
example might be:


import win32com.client

xl = win32com.client.gencache.EnsureDispatch ("Excel.Application")
xl.Visible = 1
wb = xl.Workbooks.Add ()
ws = wb.ActiveSheet

range = ws.Range (ws.Cells (1, 1), ws.Cells (1, 3))
range.Value = [1234, 2345, 3456]
range.NumberFormat = "#,##0.00"



TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Large Dictionaries

2006-05-15 Thread Chris Foote
Hi all.

I have the need to store a large (10M) number of keys in a hash table,
based on a tuple of (long_integer, integer).  The standard python
dictionary works well for small numbers of keys, but starts to
perform badly for me inserting roughly 5M keys:

# keys   dictionary  metakit   (both using psyco)
--   --  ---
1M8.8s 22.2s
2M   24.0s 43.7s
5M  115.3s105.4s

Has anyone written a fast hash module which is more optimal for
large datasets ?

p.s. Disk-based DBs are out of the question because most
key lookups will result in a miss, and lookup time is
critical for this application.

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


Re: please help me is sms with python

2006-05-15 Thread [EMAIL PROTECTED]
Yet another option:
Use Python high level API for Symbian
(http://opensource.nokia.com/projects/pythonfors60/)
to write simple server which listen to desktop client (both in Python).
Server (phone side): accept requests, send SMS using mobile phone
capability
Client (desktop): send requests,  specify phone number, message to
send.
Use any suitable connection between the phone and computer.

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


Re: Large Dictionaries

2006-05-15 Thread Richie Hindle

[Chris]
> Has anyone written a fast hash module which is more optimal for
> large datasets ?

PyJudy might be what you're looking for, though I've never used it:

  http://www.dalkescientific.com/Python/PyJudy.html

"Judy's key benefits are scalability, high performance, and memory
efficiency. A Judy array is extensible and can scale up to a very large
number of elements, bounded only by machine memory." ... "PyJudy arrays
are similar to Python dictionaries and sets."

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List and order

2006-05-15 Thread Peter Otten
Nic wrote:

> I tried to insert and execute the code, but the following error happens:
> 
> Traceback (most recent call last):
>   File "grafodna.py", line 10, in ?
> edges.sort(key = lambda u, v: (ddeg(u), ddeg(v)))
> TypeError: () takes exactly 2 arguments (1 given)
> 
> Do you know how is it possible to delete it?

Note that 

lambda a, b: ...

takes two arguments while

lambda (a, b): ...

takes one argument which must be a sequence (list, string, generator,...) of
two items.

So the above should probably be 

edges = list(G.edges())
edges.sort(key=lambda (u, v): (ddeg[u], ddeg[v]))
for u, v in edges:
print ddeg[u], ddeg[v],
print


Here's how I would do it:

edges = [(ddeg[u], ddeg[v]) for u, v in G.edges()]
edges.sort()
for a, b in edges:
print a, b,
print

(all untested)

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


Re: Large Dictionaries

2006-05-15 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Chris Foote <[EMAIL PROTECTED]> 
wrote:

> Hi all.
> 
> I have the need to store a large (10M) number of keys in a hash table,
> based on a tuple of (long_integer, integer).  The standard python
> dictionary works well for small numbers of keys, but starts to
> perform badly for me inserting roughly 5M keys:
> 
> # keys   dictionary  metakit   (both using psyco)
> --   --  ---
> 1M8.8s 22.2s
> 2M   24.0s 43.7s
> 5M  115.3s105.4s

Are those clock times or CPU times?

How much memory is your process using and how much is available on your 
machine?

I'm guessing a integer takes 4 bytes and a long integer takes roughly one 
byte per two decimal digits.  Plus a few more bytes to bundle them up into 
a tuple.  You've probably got something like 20 bytes per key, so 5M of 
them is 100 meg just for the keys.

To get reasonable hashing performance, the hash table needs to be maybe 
half full, and figure a hash key is 4 bytes, so that's another 40 meg for 
the hash table itself.

Plus whatever the values stored in the dictionary take up.  Even if you're 
not storing any values (i.e., there's probably 4 bytes for a null pointer 
(or reference to None), so that's another 40 meg.

These are all vague guesses, based on what I think are probably 
conservative estimates of what various objects must take up in memory, but 
you see where this is going.  We're already up to 180 meg.  I wonder if the 
whole problem is that you're just paging yourself to death.  A few minutes 
watching your system memory performance with ps or top while your program 
is running might give you some idea if this is the case.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to install pyTrix?

2006-05-15 Thread Peter Otten
DeepBlue wrote:

> can any1 please tell me how to install pyTrix?

Just putting the module into your site-packages directory might be
sufficient.

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


Re: Large Dictionaries

2006-05-15 Thread Claudio Grondi
Chris Foote wrote:
> Hi all.
> 
> I have the need to store a large (10M) number of keys in a hash table,
> based on a tuple of (long_integer, integer).  The standard python
> dictionary works well for small numbers of keys, but starts to
> perform badly for me inserting roughly 5M keys:
> 
> # keys   dictionary  metakit   (both using psyco)
> --   --  ---
> 1M8.8s 22.2s
> 2M   24.0s 43.7s
> 5M  115.3s105.4s
> 
> Has anyone written a fast hash module which is more optimal for
> large datasets ?
> 
> p.s. Disk-based DBs are out of the question because most
> key lookups will result in a miss, and lookup time is
> critical for this application.
> 
> Cheers,
> Chris
Python Bindings (\Python24\Lib\bsddb vers. 4.3.0) and the DLL for 
BerkeleyDB (\Python24\DLLs\_bsddb.pyd vers. 4.2.52) are included in the 
standard Python 2.4 distribution.

"Berkeley DB was  20 times faster  than other databases.  It has the 
operational speed of  a main memory database, the startup and  shut down 
speed of a  disk-resident database, and does not have the  overhead  of 
a client-server inter-process communication."
Ray  Van Tassle,  Senior  Staff Engineer, Motorola

Please let me/us know if it is what you are looking for.

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


Web development with python.

2006-05-15 Thread j . paston . cooper
Is Plone analoguous to ASP.NET? Is it a python web developing platform?
I am confused on what Turbogears is aswell because of the lack of
documentation for it.

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


Re: Web development with python.

2006-05-15 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Is Plone analoguous to ASP.NET? Is it a python web developing platform?

No, if anything ZOPE is analogous to ASP.NET. Plone is an CMS (Conetent
Management System) application written on top of ZOPE.

> I am confused on what Turbogears is aswell because of the lack of
> documentation for it.

TurboGears is also like ASP.NET

Diez


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


Re: How to organise classes and modules

2006-05-15 Thread Alex
On 5/15/06, bruno at modulix <[EMAIL PROTECTED]> wrote:
> Alex wrote:
> > Hi, this is my first mail to the list so please correct me if Ive done
> > anything wrong.
> >
> > What Im trying to figure out is a good way to organise my code. One
> > class per .py file is a system I like, keeps stuff apart. If I do
> > that, I usually name the .py file to the same as the class in it.
>
> First point is that Python doesn't force you to put everything in
> classes - if you just need a function, well, make it a function !-)
>
> Also, the common pattern is to put closely related
> classes/functions/constants in a same module, and closely related
> modules in the same package. Since Python uses a "one file == one
> module" scheme, the Javaish "one class per file" idiom leads to overly
> complicated imports. And the most common naming scheme for modules is
> 'alllowercase'.
>
>
>
> > File: Foo.py
> > ***
> > class Foo:
> > def __init__(self):
> >  pass
> > def bar(self):
> >  print 'hello world'
> >
> > 
> >
> > Now, in my other module, I want to include this class. I tried these two
> > ways:
> >
>  import Foo
>  Foo.Foo.bar()
> >
> > Traceback (most recent call last):
> >  File "", line 1, in ?
> > TypeError: unbound method bar() must be called with Foo instance as
> > first argument (got nothing instead)
> >
> > Some unbound method error. Have I missunderstood something
>
> Yes:
> 1/ you usually need to instanciate the class to call an instance method
> 1/ in this case, bar doesn't need to be a method, since it doesn't
> depend on the instance it's called on - a plain old function would be a
> better fit.
>
> > or am I on
> > the right track here?
> >
> > I did this to, almost the same thing:
> >
>  from Foo import Foo
>  Foo.bar()
> >
> > Traceback (most recent call last):
> >  File "", line 1, in ?
> > TypeError: unbound method bar() must be called with Foo instance as
> > first argument (got nothing instead)
> >
> > One thing that I tried that worked ok was this:
> >
>  import Foo
>  instance=Foo.Foo()
>  instance.bar()
> >
> > hello world
> >
> > But in my opinion, this is very ugly.
>
> Nope, it's just OO at work.
>
> > Especially if the class names
> > are long, like my module/class TileDataBaseManager. But is this the
> > "right" way in python?
>
> If you want to import a class from a module and create an instance of
> that class, yes.
>
> > Another (ugly) way that Ive considered is the following. Break it out
> > of the class,
>
> Which would be a sensible thing to do given the current implementation
> of bar().
>
> > save the functions in a file alone,
>
> Nothing prevent you from putting many functions in a same module, you
> know...
>
> > import the file
>
> s/file/module/
>
> > and
> > treat it like a class:
>
> ???
>
> > File: Foo2.py
> > ***
> > def bar(self):
> > print 'hello world'
> >
> > 
> >
>  import Foo2
>  Foo2.bar()
> >
> > hello world
>
> You don't "treat it like a class", you're just using the normal
> namespace resolution mechanism. Modules are namespaces, classes are
> namespaces, objects (class instances) are namespaces, and the dot is the
>  lookup operator (ie : somenamespacename.somename means 'retrieve what's
> actually bound to name 'somename' in namespace 'somenamespacename').
>
> > Very clean from the outside. I would like something like this. But,
> > here, I loose the __init__ function.
>
> Which in the given implementation is just doing nothing.
>
> Ok, I understand that this is just example code. The rule here is:
> - if you need per-instance state management, use a class (that you of
> course need to instanciate - else you can't have per-instance state !-)
> - if you don't need per-instance state management, use a plain function.
>
> > I have to call it manually that
> > is, which s not good. Also, maybe the biggest drawback, its no longer
> > in a class.
>
> def MyFunc():
>   pass
>
> print MyFunc.__class__.__name__
>
> Python function's are instances of the function class.
>
> > Maybe its not that important in python but from what Ive
> > learned (in c++) object orientation is something to strive for.
>
> print "object orientation".find("class")
>
> Being OO doesn't mean using classes. And FWIW, there quite enough
> procedural Java code around to prove that using classes doesn't mean
> doing OO !-) 
>
> > So, to sum it up, I have one class in one file, both with the same
> > name. How do I store/import/handle it in a nice, clean and python-like
> > manner?
>
> Quit the Javaish "one-class-per-file" idiom, don't bother using classes
> when plain old function will do, and you'll be on track...
>
> FWIW, Python's standard lib is open-source, so why not have a look at
> the source code to see how it is organized ?
>
> HTH
> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in 

Re: Web development with python.

2006-05-15 Thread Ilkka Poutanen
On 2006-05-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Is Plone analoguous to ASP.NET? Is it a python web developing platform?

Plone is analoguous to something line Kentico CMS[1]. Plone runs on Zope
which is an application server, being to Python sort of what IIS is to
ASP.NET, I think. Don't take my word for it.

You might want to read the introductory documentation[1][2] for Zope and
Plone.

1. http://www.kentico.com/
2. http://plone.org/about/plone/
3. http://www.zope.org/WhatIsZope


-- 
Ilkka Poutanen [http://ipo.iki.fi/]
And unto this, Conan;
-- 
http://mail.python.org/mailman/listinfo/python-list


Decrypt DES by password

2006-05-15 Thread Thomas Dybdahl Ahle
Hi, I've got some DES encrypted data, for which I know the password.
The problem is that I have to generate an 8byte key from the password.
I use python-crypto-2.0.1.

I also know, that the C# way to do the decryption is:
PasswordDeriveBytes bytes1 = new
PasswordDeriveBytes("passwordString", null);
byte[] array1 = new byte[8];
byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1);

DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider();
FileStream fs = new FileStream("fileNameString", FileMode.Open,
FileAccess.Read); CryptoStream cs = new CryptoStream(fs,
provider1.CreateEncryptor(array2, array1), CryptoStreamMode.Read);

Anybody know how to do this in python?

-- 
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

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


Re: unzip zip files

2006-05-15 Thread DataSmash
Thanks!
I ended up using the "-d" parameter.
I did try the zipfile module but I couldn't figure it out, nor could I
find any examples using it.
I also didn't have any luck changing the working dircectory and making
it work.

import subprocess, os

# Get all the zip files in the current directory.
for zip in os.listdir(''):
if zip.endswith(".zip"):

# Remove the first 3 and the last 4 characters
# e.g. usa12345.zip becomes 12345
zipBase = zip[3:-4]

# Make directory for unzipping
os.mkdir(zipBase)

# Make system call "unzip"
print "\n unzip -d", zipBase, zip
subprocess.Popen(["unzip", "-d", zipBase, zip]).wait()

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


RE: How to pass variables between scripts?

2006-05-15 Thread Gross, Dorit (SDRN)
> >
> > #! /usr/local/bin/python
> > # test_exec.py
> >
> > import os, sys, glob
> >
> > fileList = glob.glob('/data/*.ZIP')
> >
> > for f in fileList:
> > try: 
> > globvars = {'infile' : f}
> > locvars = {}
> > execfile('/scripts/second.py', globvars(), locvars)
> > except IOError:
> > exit(0)
> > print locvars
> >
> >
> 
> You are calling the dictionary globvars as a function then the error. 
> The fixed line is:
> 
> execfile('/scripts/second.py', globvars, locvars)
> 
> 
> 
> What you want is the function globals().
> Try putting this line in second.py:
> 
> print globals()['infile']
> 
> Using the dictionary returned by globals() you can make second.py to 
> read the contents of testexec.py's globvars dictionary.
> locvars is populated with the local variables of second.py 
> and that is 
> what you want.
> 

Marcelo, thank you! Passing the variables with dictonaries and function
globals() works fine if no other functions are defined in 'second.py'. Now
'second.py' contains further functions and a "if __name__ = __main__"
statement and in this case it seems that 'second.py' is not fully executed
from 'test_exec.py'. For the sole purpose of testing, 'second.py' looks like
this at the moment:

#! /usr/local/bin/python
# second.py

import os, sys

global zipfile
print 'Read from globals: ' + globals()['infile']
zipfile = globals()['infile']
print 'Read from zipfile: ' + zipfile

if __name__ == '__main__':

print 'Hello'
print globals()['infile']
print zipfile


Calling test_exec.py results into this output:

 ./test_exec.py 
Read from globals: /data/S0012230_0010.ZIP
Read from zipfile: /data/S0012230_0010.ZIP


It seems that the commands within the main are not executed when calling
test_exec.py!?! Is there a way to make it running?

Regards and thank you again, 
Dorit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending mail with attachment...

2006-05-15 Thread Marcelo Ramos
Merrigan escribió:
> Hi,
>
> I have now eventually finished my newbie-backup script and I'm very
> proud of the way it functions...
>
> Anyways, I am looking for an easy way to use smtplib to send an email
> with the output log of the script to multiple accounts. I need to use
> it with a smtp server, and cannot pipe it directly to sendmail.
>
> I have tried about 50 different ways that I have googled for in the
> last 6 hours, but none of them work, I keep on getting errors.
>
> The script runs on a Linux system.
>
> Thanks for any help.
>
>   

I have a python script in production doing what you want using smtplib 
and it works perfectly. Send us your code and the errors you are getting.


Regards.

-- 
Marcelo Ramos
Fedora Core 5 | 2.6.16
Socio UYLUG Nro 125

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


Re: Iterating generator from C

2006-05-15 Thread Christian Tismer
Sven Suursoho wrote:
> Hi,
> 
> 
> I am working on project that has embedded python interpreter to run  
> user-specified python procedures. Those procedures might return any  
> iterable object with set of result data -- basically everything for which  
> iter() returns valid object (list, tuple, dict, iterator etc)
> 
> It works ok, except generator under Python 2.4 with debugging enabled (see  
> http://sourceforge.net/tracker/index.php?func=detail&aid=1483133&group_id=5470&atid=105470).
> 
> Is there any way to rewrite following program to handle returned generator  
> without hitting this bug?

I found this bug as well, and I think the fix should be
back-ported.
This problem can only show up when you are comiling a C
extension, anyway.
Why don't you just apply the fix and compile your own?
It is just a wrong assertion, anyway.

ciao - chris

-- 
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


pythoncom and IDispatch

2006-05-15 Thread fraca7
Hello. I got a little problem while using pythoncom to automate IE; for 
some reason, changing the 'selectedIndex' on an instance of 
IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a 
bug in mshtml).

So, I tried to get the 'onchange' event handler and call it myself. 
According to the docs, this is a simple IDispatch implementation and 
calling Invoke() should do the trick; I actually have a working example 
of this in Delphi.

But I can't manage to get it work in Python; the following code


 idisp = pythoncom.WrapObject(elt.onchange)
 idisp.Invoke(pythoncom.DISPID_VALUE,
  0x400, # LOCALE_USER_DEFAULT
  pythoncom.DISPATCH_METHOD,
  False)

fails with an AttributeError:

Traceback (most recent call last): 

   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
283, in _
Invoke_ 

 return self._invoke_(dispid, lcid, wFlags, args) 

   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
288, in _
invoke_ 

 return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, 
None)
   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
581, in _
invokeex_ 

 return func(*args) 

   File "ietest.py", line 44, in OnDocumentComplete 

 self.deleg.onDocumentComplete(Dispatch(disp), url) 

   File "ietest.py", line 122, in onDocumentComplete 

 self.current.onDocumentComplete(self, browser, url) 

   File "ietest.py", line 141, in onDocumentComplete 

 sink.nextStep() 

   File "ietest.py", line 96, in nextStep 

 self.current.onStart(self) 

   File "ietest.py", line 191, in onStart 

 False) 

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Python 
COM Serve
r Internal Error', 'Unexpected Python Error: exceptions.AttributeError: 
_Invoke_
', None, 0, -2147467259), None) 


Did I miss something ?

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


keyword help in Pythonwin interpreter

2006-05-15 Thread BartlebyScrivener
Using ActivePython 2.4.3 on Windows XP

While in the Pythonwin IDE, if I seek keyword help by issuing the
following command:

>>>help ('while')

I get:

Sorry, topic and keyword documentation is not available because the
Python HTML documentation files could not be found.  If you have
installed them, please set the environment variable PYTHONDOCS to
indicate their location.

My PYTHONDOCS variable is set to:

c:\python24\Doc\Python-Docs-2.4.2\ref

which appears to be correct (ie the help html files are installed
there).

Searching this group, I found someone else complaining about the same
behavior with no clear resolution.

http://tinyurl.com/pblev

Any advice?

rick

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


Re: Iterating generator from C

2006-05-15 Thread Sven Suursoho
Mon, 15 May 2006 16:53:12 +0300, Christian Tismer <[EMAIL PROTECTED]>:

>>   I am working on project that has embedded python interpreter to run   
>> user-specified python procedures. Those procedures might return any   
>> iterable object with set of result data -- basically everything for  
>> which  iter() returns valid object (list, tuple, dict, iterator etc)
>>  It works ok, except generator under Python 2.4 with debugging enabled  
>> (see  
>> http://sourceforge.net/tracker/index.php?func=detail&aid=1483133&group_id=5470&atid=105470).
>>  Is there any way to rewrite following program to handle returned  
>> generator  without hitting this bug?
>
> I found this bug as well, and I think the fix should be
> back-ported.
> This problem can only show up when you are comiling a C
> extension, anyway.
> Why don't you just apply the fix and compile your own?
> It is just a wrong assertion, anyway.

Unfortunately, this is not an option because I can't control used  
environment: I'm trying to improve PostgreSQL's stored procedure language  
PL/Python and this software can be used everywhere.

At first I tried to block using generators if Py_DEBUG is defined. But  
this wouldn't work because of another, overlapping bug in Fedora Core 4's  
RPM packaging system (didn't check other versions) -- it disables Py_DEBUG  
but strips -DNDEBUG from compiler's command-line i.e. no Py_DEBUG and  
still active asserts().

See:
http://archives.postgresql.org/pgsql-patches/2006-05/msg00042.php
http://archives.postgresql.org/pgsql-patches/2006-05/msg00105.php


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


Re: Web development with python.

2006-05-15 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> Is Plone analoguous to ASP.NET? 

Certainly not.

> Is it a python web developing platform?

No, it's a CMS. FWIW, it's written in bold on the project's home page:
"""
Plone: A user-friendly and powerful open source Content Management System
"""
(http://www.plone.org)

FWIW, it's based on Zope, which is a Python-based web application server

> I am confused on what Turbogears is aswell

A Python web MVC framework.

> because of the lack of
> documentation for it.

I think there's at least enough informations on the turbogears website
to understand that it's a framework for doing web applications :

"""
TurboGears is the rapid web development megaframework
"""
(http://www.turbogears.org/index.html)

"""
Create great web apps faster
"""
(http://www.turbogears.org/about/index.html)


HTH
-- 
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: Tabs versus Spaces in Source Code

2006-05-15 Thread Harry George
Edward Elliott <[EMAIL PROTECTED]> writes:

> Eli Gottlieb wrote:
> 
> > Actually, spaces are better for indenting code.  The exact amount of
> > space taken up by one space character will always (or at least tend to
> > be) the same, while every combination of keyboard driver, operating
> > system, text editor, content/file format, and character encoding all
> > change precisely what the tab key does.
> 
> What you see as tabs' weakness is their strength.  They encode '1 level of
> indentation', not a fixed width.  Of course tabs are rendered differently
> by different editors -- that's the point.  If you like indentation to be 2
> or 3 or 7 chars wide, you can view your preference without forcing it on
> the rest of the world.  It's a logical rather than a fixed encoding.
> 
> 

[snip]

This has been discussed repeatedly, and the answer is "If you only
work alone, never use anyone else's code and no one ever uses your
codes, then do as you please.  Otherwise use tab-is-4-spaces."

When you do Agile Programming with people using emacs, vim, nedit,
xedit, wordpad, eclipse, and who knows what else, the 4-spaces rule is
necessary for survival.

The reason is simple: People get confused, and accidentally get the
wrong tab indents when they move among editors or among settings on
the same editor.  In most languages this is an irritation, requiring
some cleanup.  In Python it is a disaster requiring re-inventing the
coded algorithms.


-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedding python in package using autoconf

2006-05-15 Thread Hallvard B Furuseth
I want to use Python as an extension language in a package
which uses autoconf.  That means its and Python's autoconf
#defines can conflict, so I can't safely #include both
 and the package's own include files:-(

Do anyone have a safe way to #include at least 
without ?  E.g. copy the files (and 's
PyAPI_FUNC/PyAPI_DATA) and rename the autoconf macros - and
fail compilation if that wouldn't work?

Currently I have two sets of source files - one set which
only #includes Python.h and one set which only #includes
the package's files.
They communicate through a single .h file with a bunch of
enums for various functions and struct members, and wrapper
functions to use these by their enum value.  It has a few
cheats like declaring "struct _object;" (that's PyObject)
to make life simpler, but it's still rather tedious.

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


taking qoutes in arguments

2006-05-15 Thread Lee Caine
hi all,

Im new to python and am in need of a little help

Im attempting to write a program that finds and replaces text in all files in a given directory.

example of running the program with arguments

>python far.py /home/lee/Documents/ find replace

I have managed to get it all working apart from one thing, if the find
or replace arguments contain quotes e.g( content="somat" ),  it
doesnt work, so I print the string and it shows as content=somat,
without the quotes.

So i tryed this...

>python far.py /home/lee/Documents content=\"somat\" content=\"somat else\"

and this works, but I would like a way of not having to do this when i run the program

any help would be greatly appreciated.

thanks Lee.

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

Re: please help me is sms with python

2006-05-15 Thread Paul Boddie
Diez B. Roggisch wrote:
>
> Attach a Mobile to your computer using USB/Bluetooth, open it with a
> terminal program and use these AT-commands.
>
> http://www.cellular.co.za/hayesat.htm#SMS Command Set
>
> You can do that in python too, by opening the COM-port the handset is
> attached to and issuing the commands yourself.

See the t616hack distribution for help on reading and writing messages,
although I haven't bothered to implement message sending just yet - it
shouldn't be as hard as implementing message writing, however.

http://www.python.org/pypi/t616hack

Nelson Minar did the original work by getting COM port communications
working using PySerial and a Bluetooth dongle. I've since extended that
work to use Bluetooth sockets, which are somewhat more convenient. Only
certain Sony Ericsson telephones are known to work, but I imagine that
other models provide similar command sets.

With respect to the original query, it may be the case that the
questioner was thinking of certain Internet gateways which accept
requests and relay messages to the telephone network. Certain software
packages like smssend may be the solution in that context.

Paul

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


Re: keyword help in Pythonwin interpreter

2006-05-15 Thread BartlebyScrivener
I should add that if I type:

>>>help ('sys')

It works fine. So it's finding the module documentation, but not the
keyword or topic.

Thanks

rick

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


Re: any plans to make pprint() a builtin?

2006-05-15 Thread John Salerno
Ant wrote:
> Considering that the current:
> 
> import pprint
> pprint.pprint(x)
> 
> is hardly lengthy, I can't see how either of the alternatives proposed
> are any better.
> 
>> python.pprint.pprint(x)
> 
> 6 characters shorter, but considerably more keystrokes if you are using
> pprint more than once. Is it worth adding the 'python' builtin to save
> an import statement?
> 
>> import py
>> py.std.pprint.pprint(x)
> 
> Longer, messy, and what's the actual point? Wouldn't:
> 
> import pprint as pp
> pp.pprint(x)
> 
> be better, standard *and* shorter?
> 

I guess the idea is that you can use the import py statement to access 
many other modules as well, without importing them all separately.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keyword help in Pythonwin interpreter

2006-05-15 Thread Peter Otten
BartlebyScrivener wrote:

> Using ActivePython 2.4.3 on Windows XP
> 
> While in the Pythonwin IDE, if I seek keyword help by issuing the
> following command:
> 
help ('while')
> 
> I get:
> 
> Sorry, topic and keyword documentation is not available because the
> Python HTML documentation files could not be found.  If you have
> installed them, please set the environment variable PYTHONDOCS to
> indicate their location.
> 
> My PYTHONDOCS variable is set to:
> 
> c:\python24\Doc\Python-Docs-2.4.2\ref
> 
> which appears to be correct (ie the help html files are installed
> there).
> 
> Searching this group, I found someone else complaining about the same
> behavior with no clear resolution.
> 
> http://tinyurl.com/pblev
> 
> Any advice?

Check if

http://groups.google.com/group/comp.lang.python/msg/991f1d19a36b8dda

applies.

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


Re: Making all string literals Unicode

2006-05-15 Thread Richie Hindle

[Richie]
> is there a switch or an environment variable to
> make Python treat all string literals as unicode?

[Thomas]
> python -U

Ah!  Thanks.

(I see it's deliberately omitted from the documentation because pieces
of the standard library don't work with it, which is quite reasonable
and explains why I couldn't find it.)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: count items in generator

2006-05-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
>Cameron Laird <[EMAIL PROTECTED]> wrote:
>
>> In article <[EMAIL PROTECTED]>,
>> Alex Martelli <[EMAIL PROTECTED]> wrote:
>>   .
>>   .
>>   .
>> >My preference would be (with the original definition for
>> >words_of_the_file) to code
>> >
>> >   numwords = sum(1 for w in words_of_the_file(thefilepath))
>>   .
>>   .
>>   .
>> There are times when 
>> 
>> numwords = len(list(words_of_the_file(thefilepath))
>> 
>> will be advantageous.
>
>Can you please give some examples?  None comes readily to mind...
.
.
.
Maybe in an alternative universe where Python style emphasizes
functional expressions.  This thread--or at least the follow-ups
to my rather frivolous observation--illustrate how distinct is
Python's direction.

If we could neglect memory impact, and procedural side-effects,
then, sure, I'd argue for my len(list(...)) formulation, on the
expressive grounds that it doesn't require the two "magic tokens"
'1' and 'w'.  Does category theory have a term for formulas of
the sort that introduce a free variable only to ignore (discard,
...) it?  There certainly are times when that's apt ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keyword help in Pythonwin interpreter

2006-05-15 Thread BartlebyScrivener
Peter,

>>> import pydoc
>>> pydoc.help.docdir

yields no result for me

But adding the "break" into the pydoc module didn't work either.

Mmm.

I'll toy with this later. Thanks for pointing me to the right spot in
the module.

rick

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


Re: How to organise classes and modules

2006-05-15 Thread bruno at modulix
Alex wrote:
> On 5/15/06, bruno at modulix <[EMAIL PROTECTED]> wrote:
> 
(snip)
> 
> Thanks for taking your time to help me out. :) You have cleared out
> many of my doubts. BTW, should I post "thank you" stuff here 

Ain't that what you just did ?-)

> or does
> it just clutter? 

Nope, 'thank you' are always welcomes - eventually, take time to snip
irrelevant material (no use to repost 100+ lines just to add 'thank you'
at the bottom).

> I tried sending an email to your personal email
> listed (the one from which you send that mail to the list), but I got
> this error:
> 
> PERM_FAILURE: DNS Error: Domain name not found

hint : have a look at my signature.

> So I guess the entire list will have to be thanked for the help. :
> )

indeed.

-- 
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: Iterating generator from C

2006-05-15 Thread Christian Tismer
Sven Suursoho wrote:

>>>  Is there any way to rewrite following program to handle returned 
>>> generator  without hitting this bug?

The only way I can think of getting around this is to make
sure that there is always a running python frame.
This would be possible if you can control how the
extension is called.

> Unfortunately, this is not an option because I can't control used 
> environment: I'm trying to improve PostgreSQL's stored procedure 
> language PL/Python and this software can be used everywhere.

Then there is no other way than to report the bug, get the
fix back-ported and nagging the PL/Python maintainers
to update things after the fix.
Also a test should be added which is probably missing since a while.

I'd put a warning somewhere that generators are broken in
debug mode, file an issue as well, but avoid trying to hack
around this. It would make the bug even more resistent :-)

ciao - chris
-- 
Christian Tismer :^)   
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


saving file permission denied on windows

2006-05-15 Thread zombek
I'm making a small program which takes a folder with images and
generates optimized normal-sized images and thumbnails using Python
Imaging Lbrary (PIL). The problem is here:

os.mkdir(self.output)

img = Image.open(os.path.join(self.dir,file))
img = img.resize(self.imgSize)
# and here comes the error
img.save(self.output, "JPEG", optimize=1)

IOError: [Errno 13] Permission Denied
"D:\\Szymek\\python\\pythumb\\images\\proba"

I don't know what's going on, I didn't have any problems with it in the
past. I tried to save it to a pre-made directory but the effect is the
same, so I don't think it's connected with os.mkdir.

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


Re: saving file permission denied on windows

2006-05-15 Thread defcon8
Have you checked the persmissions to the folder? You can look from the
properties of the folder to see.

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


Re: saving file permission denied on windows

2006-05-15 Thread zombek
The permission is OK I guess... I don't see anything about permission
there, but I tried to save to maany other catalogs even to C:\ and
D:\ and it raised the same error

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


Re: count items in generator

2006-05-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Alex Martelli <[EMAIL PROTECTED]> wrote:
.
.
.
>I'd be a bit worried about having len(x) change x's state into an
>unusable one. Yes, it happens in other cases (if y in x:), but adding
>more such problematic cases doesn't seem advisable to me anyway -- I'd
>evaluate this proposal as a -0, even taking into account the potential
>optimizations to be garnered by having some iterables expose __len__
>(e.g., a genexp such as (f(x) fox x in foo), without an if-clause, might
>be optimized to delegate __len__ to foo -- again, there may be semantic
>alterations lurking that make this optimization a bit iffy).
>
>
>Alex

Quite so.  My proposal isn't at all serious; I'm doing this largely
for practice in thinking about functionalism and its complement in
Python.  However, maybe I should take this one step farther:  while
I think your caution about "attractive nuisance" is perfect, what is
the precise nuisance here?  Is there ever a time when a developer
would be tempted to evaluate len() on an iterable even though there's
another approach that does NOT impact the iterable's state?  On the
other hand, maybe all we're doing is observing that expanding the
domain of len() means we give up guarantees on its finiteness, and
that's simply not worth doing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Test professionalism (was: count items in generator)

2006-05-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote:
.
.
.
>That's exactly my point. Assuming your test coverage is good, such an
>error would be caught by the MemoryError. An infinite loop should also
>be caught by timing out the tests, but that's much more dependent on the
>test harness.
>
>Tim Delaney

Gulp.  OK, you've got me curious:  how many people habitually frame
their unit tests with resource constraints?  I think I take testing
seriously, and certainly also am involved with resource limits often,
but I confess I've never aimed to write all my tests in terms of
bounds on time (and presumably memory and ...).  You've got me
thinking, Tim.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] PyYAML-3.02: YAML parser and emitter for Python

2006-05-15 Thread Scott David Daniels
Kirill Simonov wrote:
> 
>  Announcing PyYAML-3.02
> 
> 
> A new bug-fix release of PyYAML is now available:
> 
> http://pyyaml.org/wiki/PyYAML

Another fix provided for Python 2.5 and friends.

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding yesterday's date with datetime

2006-05-15 Thread Thierry Lam
Is there an easy way to determine the yesterday's date(year-month-day)
from the python datetime library if I know today's date?

Thanks
Thierry

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


py on windows Mobile 5.0?

2006-05-15 Thread Bell, Kevin
Does anyone know if/how to go about using python on a windows mobile 5.0
PDA?

Kevin


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


Re: List and order

2006-05-15 Thread Nic
Many thanks.
Both the cases are OK.
The only problem is that from:
12
22
21
In spite of writing
12 12 22
it writes
12 21 22
Do you know how is it possible to delete also this last trouble?
Thanks a bunch,
Nic

"Peter Otten" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]
> Nic wrote:
>
>> I tried to insert and execute the code, but the following error happens:
>>
>> Traceback (most recent call last):
>>   File "grafodna.py", line 10, in ?
>> edges.sort(key = lambda u, v: (ddeg(u), ddeg(v)))
>> TypeError: () takes exactly 2 arguments (1 given)
>>
>> Do you know how is it possible to delete it?
>
> Note that
>
> lambda a, b: ...
>
> takes two arguments while
>
> lambda (a, b): ...
>
> takes one argument which must be a sequence (list, string, generator,...) 
> of
> two items.
>
> So the above should probably be
>
> edges = list(G.edges())
> edges.sort(key=lambda (u, v): (ddeg[u], ddeg[v]))
> for u, v in edges:
>print ddeg[u], ddeg[v],
> print
>
>
> Here's how I would do it:
>
> edges = [(ddeg[u], ddeg[v]) for u, v in G.edges()]
> edges.sort()
> for a, b in edges:
>print a, b,
> print
>
> (all untested)
>
> Peter 


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


Re: Finding yesterday's date with datetime

2006-05-15 Thread [EMAIL PROTECTED]
Try something like this...

HTH.  A.


from datetime import *

d1 = datetime( year=2006, month=5, day=15)
d2 = datetime.now()

for d in [d1,d2]:
yest = d - timedelta(days =1 )

print "%s -> %s" % (d, yest)

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


help with perl2python regular expressions

2006-05-15 Thread Lance Hoffmeyer
Hey all,

I am trying to convert some old perl scripts I have to python.
Here is a snippit of the regex I used in perl.  I am trying to
figure out the equivalent code in python.  Can someone help?

my $file =$Word->ActiveDocument->Content->Text;
$file =~ /TABLE\s+1.*?JCP.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;
my $P05A008 = $1;

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


Re: List and order

2006-05-15 Thread Peter Otten
Nic wrote:

> The only problem is that from:
> 12
> 22
> 21
> In spite of writing
> 12 12 22
> it writes
> 12 21 22
> Do you know how is it possible to delete also this last trouble?

I thought that the two 12 were a typo, but it seems you want to reorder the
nodes inside an edge, too. Here's a fix that normalizes the edge before
sorting the list of edges:

edges = [sorted((ddeg[u], ddeg[v])) for u, v in G.edges()]
edges.sort()
for a, b in edges:
print a, b,
print

Peter


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


Re: py on windows Mobile 5.0?

2006-05-15 Thread Gonzalo Monzón
Bell, Kevin escribió:

>Does anyone know if/how to go about using python on a windows mobile 5.0
>PDA?
>
>Kevin
>
>
>  
>
Hi Bell,

Yes, there's PythonCE (Python 2.4.3 port) for Windows CE / ARM, and 
seems to run with mobile 5.  Please search in the pythonce mail list and 
you'll got the answers about how to go. I attach here the last revision 
announcement in the maillist (May 1, 2006):

A new bug fix release of Python for Windows CE is available. Download it 
here:

http://sourceforge.net/project/showfiles.php?group_id=104228

The release notes are linked from this page, but a direct link is:

http://sourceforge.net/project/shownotes.php?release_id=413801&group_id=104228


Luke
___
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce



Regards,
Gonzalo Monzón
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-15 Thread Peter Decker
On 5/15/06, Chris Klaiber <[EMAIL PROTECTED]> wrote:

> The problem comes when the author prefers a smaller tab width than what my
> editor is set to. Sure, I could change it for that file, but what if I'm
> reading a whole directory? Sure, I could change the default setting in my
> editor, but what if I'm browsing multiple projects in the same day? Sure, I
> could find a way to set the tab width based on the directory I'm currently
> in, but by now I'm annoyed and simply replacing tabs with spaces is a far
> simpler solution that requires zero configuration on my part.

Funny, I was going to say that the problem is when the author prefers
a font with a differntly-sized space. Some of us got rid of editing in
fixed-width fonts when we left Fortran.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Dictionaries

2006-05-15 Thread Aahz
In article <[EMAIL PROTECTED]>,
Roy Smith  <[EMAIL PROTECTED]> wrote:
>In article <[EMAIL PROTECTED]>, Chris Foote <[EMAIL PROTECTED]> 
>wrote:
>> 
>> I have the need to store a large (10M) number of keys in a hash table,
>> based on a tuple of (long_integer, integer).  The standard python
>> dictionary works well for small numbers of keys, but starts to
>> perform badly for me inserting roughly 5M keys:
>> 
>> # keys   dictionary  metakit   (both using psyco)
>> --   --  ---
>> 1M8.8s 22.2s
>> 2M   24.0s 43.7s
>> 5M  115.3s105.4s
>
>Are those clock times or CPU times?

And what are these times measuring?  Don't forget that adding keys
requires resizing the dict, which is a moderately expensive operation.
Once the dict is constructed, lookup times should be quite good.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding yesterday's date with datetime

2006-05-15 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>,
 "Thierry Lam" <[EMAIL PROTECTED]> wrote:

> Is there an easy way to determine the yesterday's date(year-month-day)
> from the python datetime library if I know today's date?

from datetime import datetime, timedelta

today = datetime.today()
yesterday = today - timedelta(1)

# See the .month, .day, and .year fields of yesterday

Cheers,
-M

-- 
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tabs versus Spaces in Source Code

2006-05-15 Thread Edward Elliott
Harry George wrote:

> This has been discussed repeatedly, and the answer is "If you only
> work alone, never use anyone else's code and no one ever uses your
> codes, then do as you please. 

The answer is "Do what works best for your project".  Smart people can agree
on and use whatever convention they want without trouble.  The key is
consistency.

> Otherwise use tab-is-4-spaces." 

Tab is not 4 spaces.  Tab is 1 level of indentation.  The confusion that
tabs equals some fixed width, or can/should be set to some fixed width, is
the entire problem hampering their use.  It implies that conversion between
tabs and spaces is straightforward when it is not.  They are not comparable
entities.
 
> When you do Agile Programming with people using emacs, vim, nedit,
> xedit, wordpad, eclipse, and who knows what else, the 4-spaces rule is
> necessary for survival.

IOW reward programmers for being sloppy and using poor tools.  Anyone who
programs in wordpad/xedit has far bigger problems than worrying about tabs
vs spaces (as do projects who let people program in wordpad/xedit). 
Editors which are designed for programming handle tabs and spaces cleanly.

> The reason is simple: People get confused, and accidentally get the
> wrong tab indents when they move among editors or among settings on
> the same editor.  

Sounds like PEBCAK to me. :) If everyone uses tabs for indent, then it
doesn't matter if Joe's vim showed them as 3 spaces while Mary's emacs
showed them at 6.  You can't get the 'wrong tab indents' when everything is
a tab indent.  Mixing tabs and spaces is where you get problems.

> In most languages this is an irritation, requiring 
> some cleanup.  In Python it is a disaster requiring re-inventing the
> coded algorithms.

Use the -tt flag to the Python interpreter and you'll catch inconsistencies
immediately.  Voila, no disaster.  Again, you're not complaining about
using tabs, you're complaining about mixing tabs and spaces.  I completely
agree with you that the latter is way too much hassle to even attempt.

All I'm saying is that using tabs on their own is perfectly viable and a bit
cleaner.  I'm not trying to force that preference on anyone else, just get
everyone to recognize that one is just as rational and salubrious as the
other.

-- 
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Vancouver Python Workshop

2006-05-15 Thread Brian Quinlan
Vancouver Python Workshop
=

Building on the huge success of the 2004 Vancouver Python Workshop, the
Vancouver Python and Zope User Group is pleased to announce the 2006
Vancouver Python Workshop.

The conference will begin with keynote addresses on August 4st. Further
talks (and tutorials for beginners) will take place on August 5th and
6th. The Vancouver Python Workshop is a community organized conference
designed for both the beginner and for the experienced Python programmer
with:

  * tutorials for beginning programmers
  * advanced lectures for Python experts
  * case studies of Python in action
  * after-hours social events
  * informative keynote speakers
  * tracks on multimedia, Web development, education and more


More information see: http://www.vanpyz.org/conference/
or contact Brian Quinlan at: [EMAIL PROTECTED]

Vancouver
=

In addition to the opportunity to learn and socialize with fellow
Pythonistas, the Vancouver Python Workshop also gives visitors the
opportunity to visit one of the most extraordinary cities in the world
(1). For more information about traveling to Vancouver, see:

http://www.vanpyz.org/conference/vancouver.html
http://www.tourismvancouver.com
http://en.wikipedia.org/wiki/Vancouver

Important dates
===

Talk proposals accepted: May 15th to June 15th
Early registration (discounted): May 22nd to June 30th
Normal registration: from July 1st
Keynotes: August 4th
Conference and tutorial dates: August 5th and 6th

(1) http://news.bbc.co.uk/2/hi/business/2299119.stm

Cheers,
Brian





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


Re: A critic of Guido's blog on Python's lambda

2006-05-15 Thread Ken Tilton


Ben wrote:
> 
> Nothing you have described sounds that complicated, and you never come
> up with concrete objections to other peoples code (apart that it took
> 10 years to write in Lisp, so it must be really hard)

Oh, now I have to spend an hour dissecting any code you people toss-off 
that does no more than pick the low-hanging fruit? I do not spend enough 
time on Usenet already? :)

> 
> Why are you running a SoC project for PyCells...

You do not even know what Cells are and have not taken the trouble to 
understand, so i will save my breath. Pythonistas will love PyCells, I 
promise. Please recall that it is not just me, there is a ton of prior 
and current art.

> if you dislike the
> language so much.

There is a difference between disliking a language and thinking PyCells 
might end up persuading folks that macros and/or true lambda might be 
worth the trouble to extend the language.

Try to think a little more precisely, OK? Thx.

> People who do like Python can implement it if they
> need it (which I haven't seen any good examples that they do)
> 
> Please don't force a student to create a macro system just to port a
> system to Python,

You are getting hysterical, sit down, breathe. I asked a question, 
because (unlike you) I can see where this is going. But as you say...

> There are already plenty of ways to hide
> complicated functionality,

I know. And that is why the mentor is a Pythonista, not me. I made a 
simple inquiry as to the options available should Python have trouble 
hiding the wiring. just looking ahead a little (as are the student and 
mentor). Something wrong with thinking ahead a few moves?

You on the other hand have made up your mind about something you admit 
you do not understand, have now ascribed to me a half dozen sentiments I 
do not hold, and are feeling absolutely miserable because you think this 
is a flamewar.

No, we are just discussing language synatx and how it impacts language 
semantics, which has led inadvertently to a few of us starting an SoC 
project to put together a Python version of a very successful dataflow 
hack I did for Lisp.

I use it every day, and it just plain makes me smile. I wrote more code 
than you can imagine Before Cells, and have now used them intensively 
and in more ways than you can imagince since. Even if the wiring cannot 
be hidden, the productivity win will be trememndous. Note that this 
translates ineluctably to "programming will be more fun".

Even you will love them.

:)

kenny

-- 
Cells: http://common-lisp.net/project/cells/

"Have you ever been in a relationship?"
Attorney for Mary Winkler, confessed killer of her
minister husband, when asked if the couple had
marital problems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Large Dictionaries

2006-05-15 Thread Roy Smith
Aahz <[EMAIL PROTECTED]> wrote:
> Don't forget that adding keys requires resizing the dict, which is a
> moderately expensive operation.

My guess would be that each resize grows the table by a constant
factor, which IIRC, works out to amortized O(n).  It's not as good as
creating the dict the right size in the first place, but it's really
not that bad.  Somewhat more troubling is that it can lead to memory
fragmentation problems.

I don't understand why Python doesn't have a way to give a size hint
when creating a dict.  It seems so obvious to be able to say "d = dict
(size=10*1000*1000)" if you know beforehand that's how many keys
you're going to add.

Looking at the docs, I'm astounded to discover that you can indeed do
exactly that, but you get {size:1000}.  I am befuddled as to why
people thought creating a dict by keyword would be a useful thing to
do, but left out (and, indeed, eliminated the chance to add the syntax
later) the obviously useful ability to hint at the size.  I suppose we
could still add:

d = {}
d.reserve (10*1000*1000)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: saving file permission denied on windows

2006-05-15 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> I'm making a small program which takes a folder with images and
> generates optimized normal-sized images and thumbnails using Python
> Imaging Lbrary (PIL). The problem is here:
> 
> os.mkdir(self.output)
> 
> img = Image.open(os.path.join(self.dir,file))
> img = img.resize(self.imgSize)
> # and here comes the error
> img.save(self.output, "JPEG", optimize=1)
> 
> IOError: [Errno 13] Permission Denied
> "D:\\Szymek\\python\\pythumb\\images\\proba"
> 
> I don't know what's going on, I didn't have any problems with it in the
> past. I tried to save it to a pre-made directory but the effect is the
> same, so I don't think it's connected with os.mkdir.
> 
I think you have a logic problem.

You can't save to a folder name, you must save to a file.  Note
that O/S is saying that permission is denied to the folder name
stored in self.output:

"D:\\Szymek\\python\\pythumb\\images\\proba"

You most likely meant:

img.save(os.path.join(self.output, file), "JPEG", optimize=1)

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


  1   2   >