Re: how to operate the excel by python?

2005-06-10 Thread alex23
ÒÊÃÉɽÈË wrote:
> i want to compare the content in excel,but i don't know whick module to use!
> can you help me?

I noticed a package on PyPi today that might be useful to you:

http://www.python.org/pypi/xlrd/0.3a1

The homepage is a little brief, so I clipped their example from the
README:

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
for rx in range(sh.nrows):
print sh.row(rx)

I haven't had cause to use it myself, however.

-alex23

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


dedTUNIA: Gegen kreisrunden Haarausfall - Against circular loss of hair - Contre Alopécie Areata

2005-06-10 Thread dedTUNIA NEWS
GO: www.dedTUNIA.com

Betroffen von Alopecia Areata: dedTUNIA hilft auch Ihnen

Affected by Alopecia Areata: dedTUNIA can help you too !

Affecté par l´Alopécie Areata: dedTUNIA peut vous aider !

Website in: Deutsch - English - Francais

GO: www.dedTUNIA.com

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

Sending mail from 'current user' in Python

2005-06-10 Thread Leo Breebaart
I am writing a utility in Python and I'd like to add a
command-line option "--mailto " that will cause an
e-mail summary to be sent to  when the utility finishes
running.

My first thought was to use smtplib.sendmail(), and basically
this works like a charm, except that this function expects a
valid 'sender' address as a parameter.

Every single smtplib example I've found so far shows a hardcoded
'sender' address, but as my utility can be run by any user on any
system I am looking for a way to obtain or create a valid default
value.

I can get the username info (at least on Unix) via the 'pwd'
module, but that still leaves me with the domainname, or rather
the mailname, and I have not been able to spot a way of finding
that from within Python. (I could try opening /etc/mailname by
hand, but how standard is that filename/location?)

I've also tried opening a pipe to sendmail, and feeding the
message to that instead. This too works great (and does give an
appropriate default 'From'), but that also turns my problem into
the problem of finding the location of the sendmail program,
which doesn't seem like much of an improvement, portability-wise.

Finally, if at all possible I'd also like to get this working on
Windows, so I'd rather stick with the standard smtplib if I can.

Does anybody here have any thoughts on this?

-- 
Leo Breebaart  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Developers Handbook

2005-06-10 Thread wooks
If I had posted or invited the group to look at my full list of items
rather than just the python book link then I could see where you are
coming from.

If my intention was to "spam" this NG then the complaints as they were
phrased would  only have served to make me more determined.

Maybe we will all learn something from each other.

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


Re: how to export data from ZODB to text files

2005-06-10 Thread Josef Meile
Hi Lucasz,

> Thank you so much. I will ask our Plone administrator to test your
> script and I will write about result here.
You are wellcome. I think it is one of the easiest way of doing it.

> I thought also about Python script like
> 
> 
>  //connect to database 
>  >>> from ZODB import FileStorage, DB
>  >>> storage = FileStorage.FileStorage('Data.fs') 
>  >>> db = DB(storage)
>  >>> conn = db.open()
>  >>> dbroot = conn.root()
> 
>  //here should be interation for DB which saves attributes output in
> to file
> 
> 
> I'm not able to write the second part, but I think that this shouldn`t
> be a problem for experienced Python developer. 
> 
> How complex will be script like above?
I have to say it would be interesting to do something like that with
ZODB. Specially if you only have the Data.fs and don't have access to
the original Plone site. But I don't know how to do it. You may ask in
the ZODB list:

http://lists.zope.org/mailman/listinfo/zodb-dev

Regards,
Josef

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread greg
David M. Cooke wrote:

>>To solve that, I would suggest a fourth category of "arbitrary
>>ordering", but that's probably Py3k material.
> 
> We've got that: use hash().
> [1+2j, 3+4j].sort(key=hash)

What about objects that are not hashable?

The purpose of arbitrary ordering would be to provide
an ordering for all objects, whatever they might be.

Greg

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread Robert Kern
greg wrote:
> David M. Cooke wrote:
> 
>>>To solve that, I would suggest a fourth category of "arbitrary
>>>ordering", but that's probably Py3k material.
>>
>>We've got that: use hash().
>>[1+2j, 3+4j].sort(key=hash)
> 
> What about objects that are not hashable?
> 
> The purpose of arbitrary ordering would be to provide
> an ordering for all objects, whatever they might be.

How about id(), then?

And so the circle is completed...

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: ANN: Python for Maemo released!

2005-06-10 Thread Carl Friedrich Bolz
[snip Python port announcement]

> No reptiles were harmed in the making of these crafts.

+1 QOTW
-- 
http://mail.python.org/mailman/listinfo/python-list


os.system

2005-06-10 Thread Austin
My code is "  os.system("NET SEND computer hihi") "
i use this funtion on Windows server 2003.
it's ok.

But the same code running on Windows XP SP2, it shows the command window
twice.
How do i remove the command window?




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


Re: how to export data from ZODB to text files

2005-06-10 Thread Josef Meile
Hi again,

> I thought also about Python script like
> 
> 
>  //connect to database 
>  >>> from ZODB import FileStorage, DB
>  >>> storage = FileStorage.FileStorage('Data.fs') 
>  >>> db = DB(storage)
>  >>> conn = db.open()
>  >>> dbroot = conn.root()
I just found an information that may be useful for you:

* ZODB for Python Programmers By Michael Pelletier:
   http://www.informit.com/articles/article.asp?p=23413&rl=1

* A Simple ZODB viewer in wxPython:
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012

The first link contains some useful examples and explanations. The
second one could help you to see how your zodb is organized. In the
links that Peter post, there is also an useful powerpoint presentation.

According to the first link, the ZODB is a persistent dictionary that
you can access like:

 >>> db = DB(storage)
 >>> connection = db.open()
 >>> root = connection.root()

If I'm not wrong, you could see what objects are in root of your zodb by
doing:

 >>> print root.keys()

After that you could get your plone site by doing:

 >>> ploneSite = root['ploneFolder']

Where if I'm not wrong, "ploneFolder" may be a key in the root
dictionary. Then if plone is like CMF, it must have a "portal_catalog"
instance in it, so, you can get it by:

 >>> catalog = getattr(ploneSite,'portal_catalog',None)

If at this point catalog = None, then you have to print the objects in
the plone site by doing:

 >>> print ploneSite.objectIds()

Once you find the catalog object, you could try the script I post before
from the command line.

I haven't tested this, but I hope it helps.

Regards,
Josef Meile

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


Re: Python Developers Handbook

2005-06-10 Thread Andrew Dalke
wooks wrote:
> If I had posted or invited the group to look at my full list of items
> rather than just the python book link then I could see where you are
> coming from.

Take a look at http://www.templetons.com/brad/spamterm.html
for some of the first spams and reactions thereof.

There's a 30+ year history of posts which one person thinks
is relevant or important and others find off-topic, crass,
and rude.  A rough sort of social norms - called netiquette -
have come from that experience.

> If my intention was to "spam" this NG then the complaints as they were
> phrased would  only have served to make me more determined.

The intention is to prevent it from happening in the future.

If your intention is indeed to spam the group then there
are mechanisms to stop you, including such lovely terms as
killfiles and cancelbots.  Too much of it and you might find
your account suspended.  Or have you not wondered why few
spams make it here?

If your intention is to continue posting then it's a
warning of sorts that as in every community there are social
forms to follow, and often good reasons for those forms.

Terry backed up his response explaining not only the
convention for what you were doing, but also mentioned
(briefly) why he responded in the way he did.


I personally found your original posting blunt.  I thought
it was a virus or spam.  You see, I don't do eBay and
whenever I see that term in my mail in a URL it's either
a spam or a phishing attack.  So I ignored it.  If you
really wanted to sell it then following Terry's advice
and holding to social forms would have been better for
your auction.  There's little incentive for anyone to
follow that link without knowing more about it.

> Maybe we will all learn something from each other.

Hopefully you, but not likely the others involved.  As
I said, this sort of thing has a long history and for
anyone who's been doing this for years (like me) there's
little new to learn on the topic.  

To give an idea of the history, there's even an RFC
on netiquette from 10 years ago:
  http://www.faqs.org/rfcs/rfc1855.html

The directly relevant part is

- Advertising is welcomed on some lists and Newsgroups, and abhorred
  on others!  This is another example of knowing your audience
  before you post.  Unsolicited advertising which is completely
  off-topic will most certainly guarantee that you get a lot of
  hate mail.

Most assuredly, what Terry sent you is *not* hate mail.


Andrew
[EMAIL PROTECTED]

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


Re: Start application & continue after app exits

2005-06-10 Thread Guy Lateur
This may be getting somewhat OT, but I'd like to dig a little deeper into 
this.

First of all, security (as in some other proces reading/disclosing the data) 
is not an issue in this case. The thing is, though, a user could run the 
script twice, not having closed Word after the first time. So I guess I need 
unique filenames. Am I right in assuming "tmpFile = 
tempfile.NamedTemporaryFile()" does that automatically?

More generally speaking, I'm not sure it's a question of windows vs linux. I 
often have files open in UltraEdit, which I can then change in some other 
proces. When I reactivate UEdit, it updates (or closes) the file. So maybe 
it loads the file in memory and then closes it, and then opens it again for 
writing. Or something..

To be honest, I don't really understand what it means to have the same file 
open for writing by several processes. You don't want to modify data which 
is already being modified by someone else, do you? I mean, how do you 
determine what changes to apply first, and to what version? Or is the file 
just constantly being overwritten on a first-come-first-served basis?

I may well be completely braindead, here..


g



> All this without having "the file is in use" errors, because well... only 
> windows has those :-)
>
> Oh, and btw: you'll notice that gVim is smart enough to notice that the 
> file is no longer there, or that it is there but is more recent than his 
> working copy (if you re-edited with gedit, for example).
>
> -- 
> Renato
> 
> Usi Fedora? Fai un salto da noi:
> http://www.fedoraitalia.org 


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


Re: Python as CGI on IIS and Windows 2003 Server

2005-06-10 Thread lothar . sch
jean-marc schrieb:
> Some bits are coming back to me: the problems stemmed from adresses -
> getting the root of IIS was different so accessing files didn't work
> the same way.

thanks for that.
you are right, IIS versions are different.
Wich kind of adresses do you mean, http-adresses or paths in file
systems to root of IIS or to pythonscripts below IIS' root?

Unfortunately I couldn't find a way to solve the problem.


regards
Lothar

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


Problem in generated files with makepy and Microsoft ADO

2005-06-10 Thread Martin Stettner
Hi,

when trying to generate the wrapper classes for Microsofts ADO Library 
(Version 2.8) with makepy, I run into the following problem. Here's what I 
do (I use ActiveState Python 2.4.1.245)

1.) Running makepy, selecting "Microsoft ActiveX Data Object 2.8"

2.) Starting PythonWin IDE

3.) When I type the following

import win32com.client.Dispatch
rs = win32com.client.Dispatch("ADODB.Recordset")

I get this error

Traceback (most recent call last):
  File "", line 1, in ?
  File 
"C:\Programme\Python24\Lib\site-packages\win32com\client\__init__.py", line 
96, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, 
UnicodeToString, clsctx)
  File 
"C:\Programme\Python24\Lib\site-packages\win32com\client\__init__.py", line 
38, in __WrapDispatch
klass = gencache.GetClassForCLSID(resultCLSID)
  File 
"C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 
184, in GetClassForCLSID
mod = GetModuleForCLSID(clsid)
  File 
"C:\Programme\Python24\Lib\site-packages\win32com\client\gencache.py", line 
245, in GetModuleForCLSID
makepy.GenerateChildFromTypeLibSpec(sub_mod, info)
  File "C:\Programme\Python24\lib\site-packages\win32com\client\makepy.py", 
line 307, in GenerateChildFromTypeLibSpec
__import__("win32com.gen_py." + dir_name + "." + child)
  File 
"C:\Programme\Python24\lib\site-packages\win32com\gen_py\2A75196C-D9EB-4129-B803-931327F72D5Cx0x2x8\_Recordset.py",
 
line 55
def Collect(self, Index=defaultNamedNotOptArg):
  return self._ApplyTypes_(-8, 2, (12, 0), ((12, 1),), 'Collect', 
None,Index)
   ^
SyntaxError: invalid syntax

The Line containing the error reads as follows (in the generated 
_Recordset.py file)

 # The method Collect is actually a property, but must be used as a method 
to correctly pass the arguments
 def Collect(self, Index=defaultNamedNotOptArg):
  return self._ApplyTypes_(-8, 2, (12, 0), ((12, 1),), 'Collect', 
None,Index)

Strangely, if I delete the comment line, everything runs fine! I've noticed 
a similar problem with the Properties.py file when I was using the adodbapi 
module: There I had to delete the generated line

from win32com.client import Dispatch

which also seems perfectly correct to me.

I cannot see any error in the code. As I would like to deploy my application 
without having my customer to edit this line manually I would appreciate any 
hint (compiler bug? Bug in the ADO type library?)!

Thanks in advance

Martin 


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


Re: DB API 2.0 and transactions

2005-06-10 Thread Magnus Lycka
You might have spotted a fairly nasty bug there!

Christopher J. Bottaro wrote:
> Hi,
> Why is there no support for explicit transactions in the DB API?  I mean
> like transaction() to start the trans and commit() and rollback() would end
> the trans or something.

To quote from Date & Darwen "A Guide to the SQL Standard, 4th ed.":

"An SQL-transaction is initiated when the relevant SQL-agent executes
a 'transaction-initiating' SQL statement (...) and the SQL-agent does
not already have an SQL transaction in progress. Note, therefore, that
(...) SQL-transactions can't be nested. Note too that transaction
initiation is always implicit--there is no explicit 'BEGIN TRANSACTION'
statement."

The Python DB-API standard matches the SQL standard, and that seems
reasonable.

> This gets weird when using the Python DB API to interact with Postgres
> because a transaction gets started in 3 places:  connection, commit,
> rollback.

That's not how it's supposed to work! Are you sure that you don't
implicitly start transactions by SELECTs etc?

PostgreSQL violates the SQL standards by running in autocommit mode
unless you explicitly perform its non-standard BEGIN command. If you
are right about the behaviour you describe, the PostgreSQL binding
for Python that you use may have taken the easy route, and performs
a "BEGIN" on connect and after every commit or rollback.

If so, this is a serious bug, and should be reported as one. The correct
thing to do is to insert the BEGIN just before the first SQL statement
that is affecting transactions. Of course, this means that the binding
needs to keep track of transaction state, and this makes it a little
bit more complicated. You'd need something like this in the binding:

class connection:
 def __init__(...):
 ...
 self.inTxn = False

 def commit(...):
 ...
 self.inTxn = False

 def rollback(...):
 ...
 self.inTxn = False

 def execute(...):
 ...
 if not self.inTxn:
 perform the BEGIN command against the backend
 self.inTxn = True
 ...

Actually, this isn't perfect either, because not all SQL commands
(should) initate transactions, but it's a lot closer to what we want.

This bug has implications far beyond timestamps. Imagine two transaction
running with isolation level set to e.g. serializable. Transaction A
updates the AMOUNT column in various rows of table X, and transaction
B calculates the sum of all AMOUNTS.

Lets say they run over time like this, with | marking begin and >
commit (N.B. ASCII art, you need a fixed font):

...|--A-->...|--A-->
...|-B->.|-B->..

This works as expected...but imagine transactions implicitly
begin too early:

|-A-->|-A-->|---
|B->|--B->|-

This will cause the aggregations in B to show "delayed" results.
Not at all what one might expect...


For more about isolation levels, see e.g. here:
http://pgsqld.active-venture.com/transaction-iso.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in generated files with makepy and Microsoft ADO

2005-06-10 Thread Martin Stettner
"Martin Stettner" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> Hi,
>
> when trying to generate the wrapper classes for Microsofts ADO Library 
> [bigsnip...]
> Martin
Ok, I found some references to similar bugs at

http://www.python.org/sf/1163244,
http://www.python.org/sf/1089395 and
http://www.python.org/sf/1101726.
It seems that Python 2.4.1 has problems with mbcs encodint. I'll try to 
install the actual version of the pywin32 package (build 204) which seems to 
implement a workaround.cuMartin 


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


Re: without shell

2005-06-10 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sun, 12 Jun 2005, km wrote:

> hi all,
> 
> can any linux command be invoked/  executed without using shell (bash) ?
> what abt security concerns ? 

To answer your question fast, yes it is possible. Just pull every "bad"
block from the OS, and put inside some replacement of your own. 

But it all depends on what exactly you are going to achieve...

1. Disabling rootkits/shellcodes.

Without shell (i.e. bash/sh), you loose lots of functionality and you
don't get as much in exchange. If what you want really is to disable
execution of rootkits, shellcodes etc, then you need to disable almost
every interesting program: perl, python, awk, sh, emacs, vi, web browsers
with javascript, java, any compiler or interpreter that is installed, and
possibly much more but they don't come to my mind right now. After doing
so, you get an os that cannot boot past running /sbin/init and is "secure"
because it is useless and can be as well turned off.

Sure, you can replace/rename all those programs to have functionality and
security but this will not protect your computer for too long. It all
depends on how much someone wants to get to you. If there is one such
person, the above mentioned steps will not help. It also requires much of
work and in the result, you will have an incompatible OS i.e., no
compatibility beyond some libraries and kernel stuff. I'm not even sure if
it is possible to have full KDE/GNOME without shells. The same with X -
its startup runs through few shell scripts before the real /usr/bin/X11/X
is exec'd.

There are better ways of securing Linux with less work and IMHO the
resulting OS is much better than anything without shells, etc. at all.
Google is your master.

www.nsa.gov/selinux/
www.lids.org/
www.openwall.com/

2. Running some minimal, barebone Linux with carefully carved 
functionality.

You can replace /sbin/init with your own program and make it do whatever
you need. Link it statically and you should not even need libraries, just
one file and a kernel.

Again, sometimes you can get similar or better results without sacrificing
the whole OS, and with less work. But this subject is quite broad and so
there is not much more to say.

> regards,
> KM

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **

-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQqlqSBETUsyL9vbiEQLVHwCfX3X0IyZLBq3k1uYJElNh1BUOFdIAoKaL
ZH5Eqxq2EnN+XpDT9K79FNsK
=Jusy
-END PGP SIGNATURE-


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


Re: without shell

2005-06-10 Thread Tomasz Rola
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Sun, 12 Jun 2005, km wrote:

> hi all,
> 
> can any linux command be invoked/  executed without using shell (bash) ?
> what abt security concerns ? 

Ops, I missed the word "command" when reading your mail for the first
time, and this changes some parts of my previous answer and makes it
shorter:

There is an execve system call. You don't need neither sh, nor the libc to
run programs. It's described in section 2 of manpages. The rest of the
answer you can get from my previous post.

Sorry if I went a bit offtopic in my previous mail. Shouldn't watch tv and
write mails at the same time.

> regards,
> KM

Regards,
Tomasz Rola

- --
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[EMAIL PROTECTED] **

-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBQqlr0RETUsyL9vbiEQIocwCfVh1SsT+RegTaxvNjlsCl8FYupe8AoLH5
qci3LXS1w8bq1ZqH7EKL1HuT
=0WoY
-END PGP SIGNATURE-


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


Re: Python Developers Handbook

2005-06-10 Thread beliavsky
wooks wrote:
> I thought that posting a link that contained the word ebay and a
> subject title of Python Developers Handbook conveyed all the relevant
> information and didn't want to patronise the NG.
>
> I have had 110 hits on the item but seem to have upset 3 people.

This statement shows a misunderstanding of Usenet. Maybe the majority
of comp.lang.python readers agree with Terry Reedy but did not want to
clog the newsgroup with ditto messages.

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


Re: Abstract and concrete syntax

2005-06-10 Thread Mandus
As someone who like to do functional style programming, but without a
lot of training in that dept., I miss what you ask for from time to
time.

I don't want to go to much into this discussion, just comment on a tiny
little bit:

Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde:
[snip]
>
> set_callback(obj,
>  lambda x: (if a:
>2
>  else:
>3)
>
[snip]

You can do stuff like this: lambda x: x and 2 or 3

Of course, you are still quite limited in what you can do, but it have
solved some of my problems...

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating HTML from python

2005-06-10 Thread =?ISO-8859-1?Q?Walter_D=F6rwald?=
Cappy2112 wrote:
> I looked at HTMLGen a while ago- I didn't see what the advantage was.
> I wrote soem code similar to the example above, to generate a page..
> It worked out fine.
> 
> However, I want to add HTML ouput to many of my other python programs,
> and I don't want to re-write this for each program. So some higher
> level of abastraction is needed, but I don't know how just yet.
> 
> HTMLGen is no longer maintained, so I don't know what the best choice
> is.

If you want an alternative to HTMLGen that is still maintained, you 
might want to try XIST (http://www.livinglogic.de/Python/xist)

A few simple examples can be found here:
http://www.livinglogic.de/Python/xist/Examples.html

Bye,
Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


python create WMI instances

2005-06-10 Thread Marc Wyburn
Hi all, I am struggling with a vb - python code conversion.  I'm using
WMI to create printers on remote machines using (in VB);

set oPrinter = oService.Get("Win32_Printer").SpawnInstance_

oPrinter.DriverName = strDriver
oPrinter.PortName   = strPort
oPrinter.DeviceID   = strPrinter
oPrinter.Put_(kFlagCreateOnly)

In python I have logged onto the WMI service on the remote machine and
I can run things like c.new.AddPrinterConnection so I know that I am
connected and working OK.  I don't get any errors when I create a new
object with SpawnInstance_ but when I try to set the value of
oPrinter.Drivername I get an error saying that the Drivername object
doesn't exist.  Does anyone know how to set the values of the object
using either the method above or with the WMI module?  I think the WMI
module only allows access to modify methods such ADDPrinterConnection
or Create (from Win32_Service).

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


Re: different time tuple format

2005-06-10 Thread Magnus Lycka
Maksim Kasimov wrote:
> hi all, sorry if i'm reposting
> 
> why time.strptime and time.localtime returns tuple with different DST (9 
> item of the tuple)?

I've been bitten by the quirks in the time modules so many times
that I would advice against using it for any date handling. It's
ok for time measurement as long as you understand the differences
between time.clock and time.time on your particular platform. You
should be aware that it's just a thin wrapper around the c libs,
and they seem to disagree wildly among platforms on how things
should be done. On NT 4 for instance, the C time libs was a few
weeks off concerning when DST starts in Europe (but the win32 API
was correct), time zone names vary among platforms etc. There is
an inverse of localtime() in mktime(), but no inverse of gmtime()
etc. Yuk!

I would suggest that you either update Python to 2.4 (or 2.3) and
use the datetime module, or that you get mxDateTime if you are
stuck with 2.2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Developers Handbook

2005-06-10 Thread wooks




> Most assuredly, what Terry sent you is *not* hate mail.

It was not taken as hate mail. I think Lucas got it spot on.

Thank you for the long lecture on netiquette which I didn't really
need.

Anybody who has read and understood the book "How to win friends and
influence people" would understand what I meant (yes I do own it and no
I am not selling it on ebay).

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


match groups: optional groups not accessible

2005-06-10 Thread david . reitter
Why does the following result in an IndexError?
I try to match an optional group, and then access it via its group
name. The group happens to not participate in the match, but is
obviously defined in the pattern.
The documentation says that, at least for numbered groups, "If a group
is contained in a part of the pattern that did not match, the
corresponding result is None.".
So I would expect None rather than an IndexError, which is (only?)
supposed to occur "If a string argument is not used as a group name in
the pattern".

I would expect named groups and numbered groups to be behave the same
way.
Where's my mistake?

>>> import re
>>> m = re.match('(?Pmaybe)?yes', "yes")
>>> m.group(1)
>>> m.group('maybe')
Traceback (most recent call last):
  File "", line 1, in ?
IndexError: no such group

PS.: Please cc your reply to my e-mail address.

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


Re: Exe file

2005-06-10 Thread Philip Seeger
For easier distribution. Otherwise the client computer had to have Python 
installed.

Philip

"Peter Hansen" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> Philip Seeger wrote:
>> I'm sorry for that newbie question but how can I compile a program (a .py 
>> file) to an executable file?
>
> To save you what might be much wasted time on a wild goose chase, could 
> you please tell us why you want to do this?  (performance, protection from 
> prying eyes, easier distribution, or some other reason?)
>
> -Peter 


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


Re: EOFError not getting raised

2005-06-10 Thread [EMAIL PROTECTED]
See http://docs.python.org/lib/module-exceptions.html: EOFError gets
raised when input() or raw_input() hit an EOF condition without reading
data.

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


Re: Python Developers Handbook

2005-06-10 Thread wooks


[EMAIL PROTECTED] wrote:
> wooks wrote:
> > I thought that posting a link that contained the word ebay and a
> > subject title of Python Developers Handbook conveyed all the relevant
> > information and didn't want to patronise the NG.
> >
> > I have had 110 hits on the item but seem to have upset 3 people.
>
> This statement shows a misunderstanding of Usenet. Maybe the majority
> of comp.lang.python readers agree with Terry Reedy but did not want to
> clog the newsgroup with ditto messages.

Your understanding of Usenet is that a post has to "appeal" (for the
want of a better word) to the majority of the NG readership.

Look over a hundred people took a look (and the hits are steadily
going up whether despite or because of this thread). I am not going to
posit either way as to whether that amounts to vindication  but it does
suggsest that I have not comitted the heinous crime against netiquette
that some people are making out.

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


Re: Any way to not create .pyc files?

2005-06-10 Thread Peter Hansen
Terry Hancock wrote:
> The user with write access would run the script, causing the pyc files
> to be generated for that interpreter.  Then a normal user, running an
> older Python tries to load the modules.  Since a .pyc file exists, it gets
> used instead, but *oops* it's for a later version of the interpreter and
> stuff breaks.
> 
> A better solution than getting rid of the pyc files would be to put good
> ones there --- use the version of python that users are expected to be
> using and generate them.  If you delete the pyc files, you create an
> unnecessary drag on performance and the hazard remains to mess you
> up again.  If the pyc files are generated, though, I *think* they will be
> used and work for both the expected python and (fingers crossed) the
> later version.

Sorry Terry, but both assumptions are wrong.  Different versions of 
Python store different "magic numbers" in the .pyc files, and they will 
not use a .pyc file with a wrong number.  I believe you'll actually get 
an error about "bad magic number" if you do manage to force a bad .pyc 
to be loaded (probably by having no matching .py from which to 
recompile).  If the .py does exist, it will be recompiled and the newly 
generated bytecode will be used, whether or not the .pyc file can be 
written to cache it for next time.

Your suggestion about pre-generating the .pyc files (using compileall) 
is a good one in general for this sort of setup (shared libraries), 
though it really won't help if there are different versions of Python in 
use.  (If that's true, nothing will really help except perhaps PEP304 
and the time machine.  Well, having the two versions use two different 
copies of the library files would help, but the OP doesn't think there 
are different versions in use.)

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


Re: os.system

2005-06-10 Thread Thomas Guettler
Am Fri, 10 Jun 2005 17:10:23 +0800 schrieb Austin:

> My code is "  os.system("NET SEND computer hihi") "
> i use this funtion on Windows server 2003.
> it's ok.
> 
> But the same code running on Windows XP SP2, it shows the command window
> twice.
> How do i remove the command window?

Hi,

You can remove the command window which comes
from python if you use ".pyw" as extension.
This is not an answer why the system method
opens a second window, but maybe it helps, too.

 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Exe file

2005-06-10 Thread Peter Hansen
Philip Seeger wrote:
>>>I'm sorry for that newbie question but how can I compile a program (a .py 
>>>file) to an executable file?
...
> For easier distribution. Otherwise the client computer had to have Python 
> installed.

In that case, and since you appear to be running on Windows (judging by 
the headers in your post), look for "py2exe".  You may also want to use 
InnoSetup or another free installer, since py2exe does the packaging you 
want but doesn't bundle the files all together for easy installation.

Py2exe plus InnoSetup is a very widely used and appreciated combo.

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


Re: match groups: optional groups not accessible

2005-06-10 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Why does the following result in an IndexError?
> I try to match an optional group, and then access it via its group
> name. The group happens to not participate in the match, but is
> obviously defined in the pattern.
> 
m = re.match('(?Pmaybe)?yes', "yes")

Uh, don't you need to actually *group* the first "yes" part, with 
parentheses, to make it a group?  Otherwise you aren't going to be 
treating it as other than text-between-groups-that-can-be-skipped.

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


Re: match groups: optional groups not accessible

2005-06-10 Thread Duncan Booth
david.reitter wrote:

> So I would expect None rather than an IndexError, which is (only?)
> supposed to occur "If a string argument is not used as a group name in
> the pattern".
That is exactly what does happen.

> 
> I would expect named groups and numbered groups to be behave the same
> way.
> Where's my mistake?
Using 'maybe' as a group name when the only group in the pattern is called 
'm'.

> 
 import re
 m = re.match('(?Pmaybe)?yes', "yes")
 m.group(1)
 m.group('maybe')
> Traceback (most recent call last):
>   File "", line 1, in ?
> IndexError: no such group
> 

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


RE: python create WMI instances

2005-06-10 Thread Tim Golden
[Marc Wyburn]
| 
| Hi all, I am struggling with a vb - python code conversion.  I'm using
| WMI to create printers on remote machines using (in VB);
| 
| set oPrinter = oService.Get("Win32_Printer").SpawnInstance_
| 
| oPrinter.DriverName = strDriver
| oPrinter.PortName   = strPort
| oPrinter.DeviceID   = strPrinter
| oPrinter.Put_(kFlagCreateOnly)
| 
| In python I have logged onto the WMI service on the remote machine and
| I can run things like c.new.AddPrinterConnection so I know that I am
| connected and working OK.  I don't get any errors when I create a new
| object with SpawnInstance_ but when I try to set the value of
| oPrinter.Drivername I get an error saying that the Drivername object
| doesn't exist.  Does anyone know how to set the values of the object
| using either the method above or with the WMI module?  I think the WMI
| module only allows access to modify methods such ADDPrinterConnection
| or Create (from Win32_Service).

Not sure if I can help here or not, but just in case...

As far as I understand you, the fact that you're creating
on a remote machine is just an incidental, ie you'd have
the same problem doing this locally.

Part of the problem is that when VB does something
like:

oPrinter.DriverName = strDriver

what's really happening behind the scenes is something
like:

oPrinter.Properties_ ("DriverName").Value = strDriver

Now you can do that in Python. (In fact, that's what
the wmi module does when it overrides __setattr__, followed
by a Put_). So if you want to translate code fairly literally, 
then carry on as you were, but substitute the latter code for 
the former.

Having said that, the wmi module *can* create new instances
of classes. The problem is that I had/have little knowledge
of how WMI works in this area, so what I've done may not
be right. The method you're looking for is .new (aliased
as .new_instance_of) and if you use help on that method, 
you'll get this:

new(self, wmi_class) unbound wmi.WMI method
Create a new , typically something like
Win32_Process, eg:

c = wmi.WMI ("remote_machine")
for p in c.Win32_Process (name="notepad.exe"): print p
c.new ("Win32_Process").Create (CommandLine="notepad.exe")
for p in c.Win32_Process (name="notepad.exe"): print p
p.Terminate ()
for p in c.Win32_Process (name="notepad.exe"): print p

Now this example works, but I notice from the code
that what I did to make it work was to remove the
SpawnInstance_ which I had, and replace it by an
instance retrieval. ie I just do a Get on the class.

I'll try to find some examples around of what you're
doing which, up till now, I've not really needed to
do. Meanwhile, I hope the above info is of some use.

Feel free to respond with questions or comments. This
can only get clearer!

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


python bytecode grammar

2005-06-10 Thread M1st0
where I can find the grammar of python bytecode ? ( better if is in BCF
).

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


SMTP Test Rig ( SMTPRIG.PY v1.0 )

2005-06-10 Thread Tim Williams
After a few posts recently,  I have put together an SMTP test rig that will
receive emails and either store them to a file,  write them to a console, or
both.

Does anyone have any suggestions on where I can get it hosted  as a utility
for general public use?

TIA

Tim

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


Re: python bytecode grammar

2005-06-10 Thread Diez B. Roggisch
M1st0 wrote:
> where I can find the grammar of python bytecode ? ( better if is in BCF
> ).

There is no grammar for bytecodes - the are like assembly instructions. 
And what's BCF supposed to mean - BNF is a form for grammars, BCF I 
never heard of.

And besides that: tell us what you're after, we might help and suggest 
other ways than creating/manipulating bytecode, as this is considered a 
implementation detail that is not supposed to work across 
implementations (like jython) and is subject to unannounced changes 
between major revisions of python.

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


re: howto send html mails using smtplib

2005-06-10 Thread Tim Williams
"Philippe C. Martin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>  I have the following problem:
> 1) I can use smtplib to send text messages
> 2) I can generate html
> 3) I want to email the html and want it to be seen by the email client as
> html.
>
> However, when I receive the message, the email client displays it as text
> (code hereunder) - I assume it has to do with the MIMEText call but since
I
> cannot see any MIMEhtml .


I suspect you need one of the following lines.

msg.replace_header('Content-Type', 'text/html')

msg.add_header('Content-Type', 'text/html')


HTH :)

-- 

=
Tim Williams


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


Re: SMTP Test Rig ( SMTPRIG.PY v1.0 )

2005-06-10 Thread Martin Franklin
Tim Williams wrote:
> After a few posts recently,  I have put together an SMTP test rig that will
> receive emails and either store them to a file,  write them to a console, or
> both.
> 
> Does anyone have any suggestions on where I can get it hosted  as a utility
> for general public use?
> 
> TIA
> 
> Tim
> 


Python cookbook perhaps?

http://aspn.activestate.com/ASPN/Python/Cookbook/

Martin

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


Re: Is pyton for me?

2005-06-10 Thread Kent Johnson
Andrew Dalke wrote:
> import subprocess
> def gensky(hour):
>   subprocess.check_call(["gensky", "3", "21", str(hour)],
>stdout = open("sky%d.rad" % (hour,), "w"))
> 
> 
> The main differences here are:
>  - the original code didn't check the return value of os.system().
> It should do this because, for example, the gensky program might
> not be on the path.  The check_call does that test for me.

Where do you find check_call()? It's not in the docs and I get
 >>> import subprocess
 >>> subprocess.check_call
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'check_call'

with Python 2.4.1.

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


Re: programmnig advise needed

2005-06-10 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I am writing a Python program that needs to read XML files and contruct
> a tree object from the XML file (using wxTree).
> The XML however is not an hiearchical XML file. It contains 
> and  tags. The  tags link the elements
> together.

Are you sure that you get a tree? As I understand your description,
the XML format could well be used to describe arbitrary directed
graphs, even cyclic ones. This might not be a problem unless someone
tries to expand the entire tree...but you should probably have
some kind of cycle check, or disallow "expand all" in the GUI and
make sure you don't create the nodes before they are expanded.

If you really just permit trees, it's fairly simple, because a
node should just appear as a  in an association once. You
can put those in a set, and check that they aren't already in the
set before you accept the content in a new association. Something
like the following semi-pseudo-code:

nodes = set()

for name, parent in associations:
 if name in nodes:
 raise KeyError, ("%s is already in the tree. "
"Can't put it under %s." % (name, parent)
 nodes.add(name)
 whatever...

If you want to allow arbitrary directed acyclic graphs (DAGs),
you have to work a little more. E.g. if you want to allow things
like:

A
.B
..C
...D
...E
.F
..C
...D
...E

(I know that you said a tree, but I've certainly met clever and
well educated people before who called DAGs trees...)

For DAGs, you might traverse the tree to make sure there are
no cycles, but there are probably better solutions as well. As
I said, if it's really trees you want, this is not a problem.

Actually, another risk is that your document describes several
disjunct structures... Oh well, that's another issue, and you
can always argue how defensive your code needs to be. It obviously
depends on how well you trust your input and the implications
of problems. Anyway, assuming cycle checks, it's easy to find
roots: They are the keys in the dictionary that don't occur as
values. If there's just one, you just have one tree.

To summarize: If you want to describe a tree structure in XML,
it's probably a good idea to use the natural hierarchy of XML
tags to do this. That way the file can't convey a non-tree
structure. If you need to use a construct like you describe
in your XML, this suggests that you need to convey non-tree
structures, and then you probably need to handle those as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: circular import Module

2005-06-10 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
> Hello,
> 
> I have two modules (file1.py and file2.py)
> Is that ok in python (without any weird implication) if my module
> import each other. I mean in module file1.py there exist command import
> file2 and in module file2.py there exist command import file1?

Even if it works, it gives you a hint of a design
problem that might come back and bite you later.

If file1 depends on file2 *and* vice versa, it seems
those two modules are tightly coupled. Perhaps they
should be one module rather than two, or perhaps
some redesign should be made to untangle this cycle.

It happens that old Java programmers make one module
per class when they start using Python. That's more
or less equivalent of never using more than 8.3
characters in filenames in modern operating systems,
or to make a detour on your way to work because there
used to be a fence blocking the shortest way a long
time ago... :)

Due to the cycle, you can never use file1 without
file2 or vice versa. Why do you then want it to be
two different modules instead of one?

As others noted, you can usually fix your cycle problems
by importing in a local scope, but just because you can,
it doesn't mean that you should...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python bytecode grammar

2005-06-10 Thread M1st0
Ops yes is BNF :P Bacus Normal Form if I am not wrong...

However..

I'am tryng to recognizing patterns in a bytecoded file in orderd to
optimize...

But I would like to "parse"  i.e reconstruct it in something like a
tree..
in order to apply rules on a tree recursively.

I have seen  compile.c in the Python dist...

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


re: howto send html mails using smtplib

2005-06-10 Thread Philippe C. Martin
Tim,

You are most correct, replace_header did the trick.

Thanks a bunch.


Philippe



Tim Williams wrote:

> "Philippe C. Martin" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>>  I have the following problem:
>> 1) I can use smtplib to send text messages
>> 2) I can generate html
>> 3) I want to email the html and want it to be seen by the email client as
>> html.
>>
>> However, when I receive the message, the email client displays it as text
>> (code hereunder) - I assume it has to do with the MIMEText call but since
> I
>> cannot see any MIMEhtml .
> 
> 
> I suspect you need one of the following lines.
> 
> msg.replace_header('Content-Type', 'text/html')
> 
> msg.add_header('Content-Type', 'text/html')
> 
> 
> HTH :)
> 

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


[no subject]

2005-06-10 Thread python-list-bounces+archive=mail-archive . com
#! rnews 2612
Newsgroups: comp.lang.python
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp
From: Harry George <[EMAIL PROTECTED]>
Subject: Re: Generating HTML from python
X-Nntp-Posting-Host: cola2.ca.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: <[EMAIL PROTECTED]>
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
Lines: 70
Sender: [EMAIL PROTECTED]
Organization: The Boeing Company
References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Mime-Version: 1.0
Date: Fri, 10 Jun 2005 13:16:36 GMT
Xref: news.xs4all.nl comp.lang.python:381106

"Philippe C. Martin" <[EMAIL PROTECTED]> writes:

> PS: I am looking at the formatter module which seems to be related to HTML
> somehow, but without any code sample I'm a bit lost


As others have noted, if you need any computation at all, it is easier
to write directly in python.

I came to python from perl, where I used CGI.pm.  To get that effect,
I wrote my own CGIpm.py and used it for a while.  
http://www.seanet.com/~hgg9140/comp/index.html

But (at the suggestion of others in this newsgroup), I then tried
writing directly.  The net effect is trivial html generation, with all
the power of python at your fingertips.

Note: 
To save even more time, I made a CGI template that includes this main:

#
if __name__=="__main__":
mystart()
#cgi.print_environ_usage()
#cgi.print_environ()
form = cgi.FieldStorage()
try:
if len(form)==0:
send_form1()
else:
form_name=form['form_name'].value
if form_name=='form1':
recv_form1()
except StandardError, e:
print "\nERROR: %s\n" % e
myend()

To support a stateless world:

1. Each form has a send_xyz and recv_xyz function.  The end of each
recv_xyz decides what send_xyz to do next.

2. mystart and myend handle opening and closing the http and html.
They also handle state save/restore as needed (pickle or database).

> 
> 
> Philippe C. Martin wrote:
> 
> > Hi,
> > 
> > I wish to use an easy way to generate reports from wxPython and feel
> > wxHtmlEasyPrinting could be a good solution.
> > 
> > I now need to generate the HTML wxHtmlEasyPrinting can print: I need to
> > have a title followed by lines of text that do not look too ugly. If
> > possible I would like to use an existing module.
> > 
> > Q1) Is there such a module ?
> > Q2) Is my approach fairly good ?
> > 
> > Regards,
> > 
> > Philippe
> 

-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating HTML from python

2005-06-10 Thread Philippe C. Martin
Thanks


Walter Dörwald wrote:

> Cappy2112 wrote:
>> I looked at HTMLGen a while ago- I didn't see what the advantage was.
>> I wrote soem code similar to the example above, to generate a page..
>> It worked out fine.
>> 
>> However, I want to add HTML ouput to many of my other python programs,
>> and I don't want to re-write this for each program. So some higher
>> level of abastraction is needed, but I don't know how just yet.
>> 
>> HTMLGen is no longer maintained, so I don't know what the best choice
>> is.
> 
> If you want an alternative to HTMLGen that is still maintained, you
> might want to try XIST (http://www.livinglogic.de/Python/xist)
> 
> A few simple examples can be found here:
> http://www.livinglogic.de/Python/xist/Examples.html
> 
> Bye,
> Walter Dörwald

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

unittest and XML output

2005-06-10 Thread James Jeffers
I couldn't find any resource that addresses output from the unittest package 
in python 2.4.x. I can't beleive that there isn't an output formatter/test 
runner for the unittest package.. surely some needed this before.

Is there a working group or package maintainer for these kinds of features?

Thanks in advance,

James 


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


Re: Generating HTML from python

2005-06-10 Thread Philippe C. Martin
PS: Just wanted to add that HTMLGen works very well and outputs html that
wxHtmlEasyPrinting and my email client have not problem reading (I output
student grades, missing assignments, ... in tables).

The one gitch is they do not have any installation program (that I've seen)
for windows.

Regards,

Philippe




Walter Dörwald wrote:

> Cappy2112 wrote:
>> I looked at HTMLGen a while ago- I didn't see what the advantage was.
>> I wrote soem code similar to the example above, to generate a page..
>> It worked out fine.
>> 
>> However, I want to add HTML ouput to many of my other python programs,
>> and I don't want to re-write this for each program. So some higher
>> level of abastraction is needed, but I don't know how just yet.
>> 
>> HTMLGen is no longer maintained, so I don't know what the best choice
>> is.
> 
> If you want an alternative to HTMLGen that is still maintained, you
> might want to try XIST (http://www.livinglogic.de/Python/xist)
> 
> A few simple examples can be found here:
> http://www.livinglogic.de/Python/xist/Examples.html
> 
> Bye,
> Walter Dörwald

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

Re: anygui,anydb, any opinions?

2005-06-10 Thread Thomas Bartkus
"Renato Ramonda" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thomas Bartkus ha scritto:
>
> >>Then download gtk2.6 and glade for windows and then install pygtk and
> >>code away to your satisfaction! :-D
> >>
> >
> >
> > I *will* try that.
>
> On linux you probably have everything installed or a command away, on
> windows use this:
>
> http://gladewin32.sourceforge.net/
>
> choosing the development package (that includes gtk _and_ glade), plus
>
> http://www.pcpm.ucl.ac.be/~gustin/win32_ports/pygtk.html
>
> for pygtk. Just choose the right python version, obviously.

Thank you Renato!

I'm in the thick of it right now.  The challenge is to sort it all out.
wxWidgets<>wxPython<>wxGlade<>Glade<>GTK<>pyGTK<>TKinter<>much more.
This is a complicated soup and the interelationships are not obvious or easy
to sort out.

   > On linux you probably have everything installed or a command away ...
Well! - that's the problem!
I'm not going to live long enough to evaluate everything :-)
Thomas Bartkus



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


IMAP Proxy

2005-06-10 Thread Tarek Ziadé
Hi,

I want to write a small TCP Server in Python to make an IMAP Proxy for
post-processing client requests.

It is not long either complicated but needs to be very robust so...
maybe someone here has already done such a thing I can use or know where
i can get it ?

Cheers,

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


Perl s/ To Python?

2005-06-10 Thread John Abel
Does anyone know of a quick way of performing this:

$testVar =~ s#/mail/.*$##g

The only way I can think of doing it, is:

mailPos = testVar.find( "mail" )
remainder =  testVar[ :mailPos ]

Any ideas would be appreciated.  I'm iterating over a lot of entries, 
and running these lines for each entry.

J


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


Re: MySQLDBAPI

2005-06-10 Thread deelan
Gregory Piñero wrote:
> I didn't see anything about mysql-devel package in the release notes. 

it's there, section "Prerequisites".

> Is that something I can install all to my home directory?

never tried, but sounds hard to do. mysql-devel is a bunch of libs and 
include files tied to mysql. the "_mysql" extension will be complied 
against such files and then wrapped by python code.

HTH.

-- 
deelan, #1 fan of adriana lima!





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


Re: without shell

2005-06-10 Thread Steven D'Aprano
On Sun, 12 Jun 2005 23:16:35 +0530, km wrote:

> hi all,
> 
> can any linux command be invoked/  executed without using shell (bash) ?

py> import os
py> status = os.system("ls")

Prints the output of ls and stores the exit code into status.

py> file_list = os.popen("ls").read()

Stores the output of ls into file_list.

Or see the module "commands".

> what abt security concerns ? 

Yes, there are serious security concerns. You should be *very* careful
about executing strings generated by users. You probably don't want your
program executing something like os.system("rm -rf /").



-- 
Steven.


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


Re: Abstract and concrete syntax

2005-06-10 Thread Kay Schluehr
Mandus schrieb:

> As someone who like to do functional style programming, but without a
> lot of training in that dept., I miss what you ask for from time to
> time.
>
> I don't want to go to much into this discussion, just comment on a tiny
> little bit:
>
> Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde:
> [snip]
> >
> > set_callback(obj,
> >  lambda x: (if a:
> >2
> >  else:
> >3)
> >
> [snip]
>
> You can do stuff like this: lambda x: x and 2 or 3

You can also do this

   lambda x: {True:2,False:3}.get(bool(a))

which is both beautiful and pythonic.

Kay

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


Re: SMTP Test Rig ( SMTPRIG.PY v1.0 )

2005-06-10 Thread dowskimania
Tim Williams wrote:
> After a few posts recently,  I have put together an SMTP test rig that will
> receive emails and either store them to a file,  write them to a console, or
> both.

Sounds interesting.

> Does anyone have any suggestions on where I can get it hosted  as a utility
> for general public use?

You could upload it to the Vaults of Parnassus.
http://www.vex.net/parnassus/
 
> TIA
> 
> Tim

Christian
http://www.dowski.com

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


Re: without shell

2005-06-10 Thread Grant Edwards
On 2005-06-12, km <[EMAIL PROTECTED]> wrote:

> can any linux command be invoked/executed without using shell (bash)?

Yes -- for some values of "linux command".  You can execute
anything that's not a bash internal or a bash script without
using bash.

> what abt security concerns?

What about them?

-- 
Grant Edwards   grante Yow!  I'm young... I'm
  at   HEALTHY... I can HIKE
   visi.comTHRU CAPT GROGAN'S LUMBAR
   REGIONS!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl s/ To Python?

2005-06-10 Thread JZ
Dnia Fri, 10 Jun 2005 14:57:21 +0100, John Abel napisał(a):

> $testVar =~ s#/mail/.*$##g
> 
> The only way I can think of doing it, is:
> 
> mailPos = testVar.find( "mail" )
> remainder =  testVar[ :mailPos ]
> 
> Any ideas would be appreciated.  I'm iterating over a lot of entries, 
> and running these lines for each entry.

import re
testVar = re.compile(r'/mail/.*$').sub('', testVar) 

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


Re: without shell

2005-06-10 Thread Grant Edwards
On 2005-06-10, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Sun, 12 Jun 2005 23:16:35 +0530, km wrote:
>
>> hi all,
>> 
>> can any linux command be invoked/  executed without using shell (bash) ?
>
> py> import os
> py> status = os.system("ls")
>
> Prints the output of ls and stores the exit code into status.

It's done by invoking the user's SHELL and passing the string
"ls" to it.  In the general case, invoking an unknown shell and
passing it a string is fraught with peril.

> py> file_list = os.popen("ls").read()
>
> Stores the output of ls into file_list.

That also executes a shell (same as os.system()), so it's
equally as unreliable and insecure as os.system().  [See the
notes at http://docs.python.org/lib/os-newstreams.html#os-newstreams
that describe popen.]

> Or see the module "commands".
>
>> what abt security concerns ? 
>
> Yes, there are serious security concerns. You should be *very* careful
> about executing strings generated by users. You probably don't want your
> program executing something like os.system("rm -rf /").

You've got also got a much better chance of getting what you
expect if you don't invoke a shell, but use os.spawn*
functions instead.

-- 
Grant Edwards   grante Yow!  I feel partially
  at   hydrogenated!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl s/ To Python?

2005-06-10 Thread John Abel
JZ wrote:

>Dnia Fri, 10 Jun 2005 14:57:21 +0100, John Abel napisał(a):
>
>  
>
>>$testVar =~ s#/mail/.*$##g
>>
>>The only way I can think of doing it, is:
>>
>>mailPos = testVar.find( "mail" )
>>remainder =  testVar[ :mailPos ]
>>
>>Any ideas would be appreciated.  I'm iterating over a lot of entries, 
>>and running these lines for each entry.
>>
>>
>
>import re
>testVar = re.compile(r'/mail/.*$').sub('', testVar) 
>
>--
>JZ
>  
>
That's brill.  Never even thought if using re.  Thank you!

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


Re: without shell

2005-06-10 Thread Mage
Steven D'Aprano wrote:

>On Sun, 12 Jun 2005 23:16:35 +0530, km wrote:
>
>  
>
>>hi all,
>>
>>can any linux command be invoked/  executed without using shell (bash) ?
>>
>>
>
>py> import os
>py> status = os.system("ls")
>
>Prints the output of ls and stores the exit code into status.
>
>py> file_list = os.popen("ls").read()
>
>Stores the output of ls into file_list.
>
>  
>
These commands invoke shell indeed.

   Mage

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


Re: Perl s/ To Python?

2005-06-10 Thread Gary Wilson Jr
John Abel wrote:
> Does anyone know of a quick way of performing this:
> 
> $testVar =~ s#/mail/.*$##g

Use the re (regular expression) module.  Since you are iterating over a lot of
entries, it is good to compile the regular expression outside of the loop.

>>> import re
>>> mailRE = re.compile('/mail/.*$')
>>>
>>> myList = ['/var/mail/joe', '/var/spool/mail/bob']
>>> remainderList = []
>>>
>>> for testVar in myList:
... remainderList.append(mailRE.sub('', testVar))
...
>>> print '\n'.join(remainderList)
/var
/var/spool


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


about accessing mysql

2005-06-10 Thread sinan ,
hi everybody, i have a small mysql connection code

>>> import MySQLdb
>>> db=MySQLdb.Connection(host="localhost",user="root",db="nux")
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line
66, in Connect
return Connection(*args, **kwargs)
  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
156, in __init__
self.autocommit(0)
_mysql_exceptions.OperationalError: (1193, "Unknown system variable
'AUTOCOMMIT'")
>>>

these command works at my computer but when i want to do in my server,
i get these messages as you seen, my both computer and server have
same python, same MySQLdb module and same database with same
priviliges.also how can i connect to remote database? is that work ?
db=MySQLdb.Connection(host="192.168.0.120",user="root",db="nux")
thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: without shell

2005-06-10 Thread Grant Edwards
On 2005-06-10, Mage <[EMAIL PROTECTED]> wrote:

>>py> file_list = os.popen("ls").read()
>>
>>Stores the output of ls into file_list.
>>
> These commands invoke shell indeed.

Under Unix, popen will not invoke a shell if it's passed a
sequence rather than a single string.

-- 
Grant Edwards   grante Yow!  I was in EXCRUCIATING
  at   PAIN until I started
   visi.comreading JACK AND JILL
   Magazine!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dealing with marketing types...

2005-06-10 Thread Will McGugan
flyingfred0 wrote:
> A small software team (developers, leads and even the manager when he's 
> had time) has been using (wx)Python/PostgreSQL for over 2 years and 
> developed a successful 1.0 release of a client/server product.
> 
> A marketing/product manager has brought in additional management and 
> "architecture" experts to propose moving the entire thing to a Java 
> (application server) platform for the next release.  They want a 
> "scalable, enterprise solution" (though they don't really know what that
> means) and are going crazy throwing around the Java buzzwords (not to 
> mention XML).
> 
> The developers (including myself) are growing uneasy; the management is 
> continuing to push their requirements and ignore the engineers.  I think 
> there's still hope, but I'm at a loss for ideas beyond pointing out the 
> success stories of Python and Zope and language comparisons between 
> Python and Java.
> 
> What experiences have those in the Python community had in these kinds 
> of situations?

Marketing types need a bandwagon to jump on. Point out that Google is 
used by Google, ILM and NASA.


Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Basic questions about packages/modules.

2005-06-10 Thread Negroup
Hi, first of all sorry for boring you with a such simple request. I'm
using Python since few days, and I like it even if I'm not yet in
confidence. I'd like to organize my programs in hierarchical
structures, thus I thought that packages could be the solution,
however I have some difficulties understanding their utilization (even
after reading chapter 6 of the tutorial, about modules).

Now an example (silly) to clarify my doubts:

This is the structure:
main.py
importers/
__init__.py (empty)
importer1.py
config/
__init__.py (empty)
parameters.py

main.py
===
from importers import importer1
print importer1.display()

importers/importer1.py
==
from config import parameters
def display():
return '-' * parameters.counter

config/parameters.py

counter = 5


All works fine when I run "python main.py", while I get an error
trying to run "python importers/importer1.py":

Traceback (most recent call last):
  File "importers/importer1.py", line 1, in ?
from config import parameters
ImportError: No module named config

Can you explain why does that happen? It prevents me to test
importer1.py alone.

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


Re: Basic questions about packages/modules.

2005-06-10 Thread John Abel
Negroup wrote:

>Hi, first of all sorry for boring you with a such simple request. I'm
>using Python since few days, and I like it even if I'm not yet in
>confidence. I'd like to organize my programs in hierarchical
>structures, thus I thought that packages could be the solution,
>however I have some difficulties understanding their utilization (even
>after reading chapter 6 of the tutorial, about modules).
>
>Now an example (silly) to clarify my doubts:
>
>This is the structure:
>main.py
>importers/
>__init__.py (empty)
>importer1.py
>config/
>__init__.py (empty)
>parameters.py
>
>main.py
>===
>from importers import importer1
>print importer1.display()
>
>importers/importer1.py
>==
>from config import parameters
>def display():
>return '-' * parameters.counter
>
>config/parameters.py
>
>counter = 5
>
>
>All works fine when I run "python main.py", while I get an error
>trying to run "python importers/importer1.py":
>
>Traceback (most recent call last):
>  File "importers/importer1.py", line 1, in ?
>from config import parameters
>ImportError: No module named config
>
>Can you explain why does that happen? It prevents me to test
>importer1.py alone.
>
>TIA,
>negroup
>  
>
For your code to work, config would have to be a subdirectory under 
importers.  Unless, config had been installed in the site-packages.

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


Re: python bytecode grammar

2005-06-10 Thread Diez B. Roggisch
M1st0 wrote:
> Ops yes is BNF :P Bacus Normal Form if I am not wrong...
> 
> However..
> 
> I'am tryng to recognizing patterns in a bytecoded file in orderd to
> optimize...
> 
> But I would like to "parse"  i.e reconstruct it in something like a
> tree..
> in order to apply rules on a tree recursively.

But bytecode is like assembly - there is no tree-structure. A opcode is 
followed by a number of arguments, and oopcodes are in a seqence.

However the bytecode is _generated_ from the AST somehow. Maybe you can 
work on that. Also take a look at psyco, it already does optimizations 
for numeric calculations.

Besides: I serously doubt you can do much optimization on the 
bytecodelevel itself, as it is very highlevel. The optimization efforts 
like in psyco don't alter bytecode - they replace it

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


Re: IMAP Proxy

2005-06-10 Thread Jp Calderone
On Fri, 10 Jun 2005 15:52:28 +0200, Tarek Ziadé <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I want to write a small TCP Server in Python to make an IMAP Proxy for
>post-processing client requests.
>
>It is not long either complicated but needs to be very robust so...
>maybe someone here has already done such a thing I can use or know where
>i can get it ?

I recommend using Twisted's IMAP4 support for this.  There's a simple proxy in 
the Twisted issue tracker that might be useful to start from:

http://twistedmatrix.com/bugs/issue215

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

Re: Annoying behaviour of the != operator

2005-06-10 Thread Steven D'Aprano
On Thu, 09 Jun 2005 08:10:09 -0400, Dan Sommers wrote:

>>> The main problem is that Python is trying to stick at least three
>>> different concepts onto the same set of operators: equivalence (are
>>> these two objects the same?), ordering (in a sorted list, which comes
>>> first?), and mathematical "size".
[snip]
>>> This gives the wacky world where
>>> "[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't.
> 
> Python inherits that wackiness directly from (often wacky) world of
> Mathematics.
> 
> IMO, the true wackiness is that
> 
> [ AssertionError, (vars, unicode), __name__, apply ].sort( )
> 
> "works," too.  Python refusing to sort my list of complex numbers is a
> Good Thing.

Only if you understand sorting as being related to the mathematical
sense of size, rather than the sense of ordering. The two are not the
same!

If you were to ask, "which is bigger, 1+2j or 3+4j?" then you
are asking a question about mathematical size. There is no unique answer
(although taking the absolute value must surely come close) and the
expression 1+2j > 3+4j is undefined.

But if you ask "which should come first in a list, 1+2j or 3+4j?" then you
are asking about a completely different thing. The usual way of sorting
arbitrary chunks of data within a list is by dictionary order, and in
dictionary order 1+2j comes before 3+4j because 1 comes before 3.

This suggests that perhaps sort needs a keyword argument "style", one of
"dictionary", "numeric" or "datetime", which would modify how sorting
would compare keys.

Perhaps in Python 3.0.


-- 
Steven.



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


Re: IMAP Proxy

2005-06-10 Thread Skip Montanaro

Tarek> I want to write a small TCP Server in Python to make an IMAP
Tarek> Proxy for post-processing client requests.

Tarek> It is not long either complicated but needs to be very robust
Tarek> so...  maybe someone here has already done such a thing I can use
Tarek> or know where i can get it ?

There is an IMAP filter as part of the SpamBayes project that you might find
is a useful starting point:

http://www.spambayes.org/

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


Re: Perl s/ To Python?

2005-06-10 Thread Andreas Kostyrka
I'd consider taking a look at the re module ;)

Andreas

On Fri, Jun 10, 2005 at 02:57:21PM +0100, John Abel wrote:
> Does anyone know of a quick way of performing this:
> 
> $testVar =~ s#/mail/.*$##g
> 
> The only way I can think of doing it, is:
> 
> mailPos = testVar.find( "mail" )
> remainder =  testVar[ :mailPos ]
> 
> Any ideas would be appreciated.  I'm iterating over a lot of entries, 
> and running these lines for each entry.
> 
> J
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread Diez B. Roggisch
sinan , wrote:
> hi everybody, i have a small mysql connection code
> 
> 
import MySQLdb
db=MySQLdb.Connection(host="localhost",user="root",db="nux")
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line
> 66, in Connect
> return Connection(*args, **kwargs)
>   File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> 156, in __init__
> self.autocommit(0)
> _mysql_exceptions.OperationalError: (1193, "Unknown system variable
> 'AUTOCOMMIT'")
> 
> 
> these command works at my computer but when i want to do in my server,
> i get these messages as you seen, my both computer and server have
> same python, same MySQLdb module and same database with same
> priviliges.also how can i connect to remote database? is that work ?
> db=MySQLdb.Connection(host="192.168.0.120",user="root",db="nux")
> thank you.

Are you aware that transactions are a very recent feature of mysql and 
that tables have to be created as InnoDB tables? I don't know much about 
that stuff but can imagine that on your server this has not been done 
properly.

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


Re: Dealing with marketing types...

2005-06-10 Thread Diez B. Roggisch
Will McGugan wrote:
> Marketing types need a bandwagon to jump on. Point out that Google is 
> used by Google, ILM and NASA.

Certainly a true statement - but I've got the sneaky suspicion that the 
first google was supposed to be python.

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


Re: without shell

2005-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2005 14:13:05 +, Grant Edwards wrote:

> On 2005-06-10, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>> On Sun, 12 Jun 2005 23:16:35 +0530, km wrote:
>>
>>> hi all,
>>> 
>>> can any linux command be invoked/  executed without using shell (bash) ?
>>
>> py> import os
>> py> status = os.system("ls")
>>
>> Prints the output of ls and stores the exit code into status.
> 
> It's done by invoking the user's SHELL and passing the string
> "ls" to it.  In the general case, invoking an unknown shell and
> passing it a string is fraught with peril.

Ah... you learn something new every day.

I interpreted the original question as meaning "can Python execute
arbitrary Linux commands without exiting the Python interpretor and
dropping into a shell prompt?".

-- 
Steven.



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


Re: MySQLDBAPI

2005-06-10 Thread Daniel Dittmar
Gregory Piñero wrote:
> Is that something I can install all to my home directory?

If you have a similar Linux distribution at home, simply build the mysql 
extension on that machine and then copy it to the web server.

Otherwise:

You don't have to actually install it. Just make sure that Setup.py 
finds the headers and libs

1a) get the rpm and extract the files

or 1b) compile (but don't install) mysql from sources

2) specify the locations of the header files and the libs to Setup.py or 
patch the module such that the defaults point to your directories. From 
your error message, the current default for the includes seems to be 
/usr/local/mysql/include/mysql

3) You can then delete the directories created in 1a or 1b

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


Re: python bytecode grammar

2005-06-10 Thread M1st0
Ok I tried :).

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


Re: Changing entities

2005-06-10 Thread Daniel
Hi Kent

This isn't work with the following line:
FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)

>>> byter = re.compile(r'SIZE \((\d+) BYTE\)')
>>> s = 'SIZE (1 BYTE)'
>>> byter.sub(r'SIZE(\1)', s)
'SIZE(1)'
>>> byter.sub(r'SIZE(\1)', line)
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>> line
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>>

Any idea? :-p

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


Re: Changing entities

2005-06-10 Thread Daniel
Hi Kent

This isn't work with the following line:
FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)

>>> byter = re.compile(r'SIZE \((\d+) BYTE\)')
>>> s = 'SIZE (1 BYTE)'
>>> byter.sub(r'SIZE(\1)', s)
'SIZE(1)'
>>> byter.sub(r'SIZE(\1)', line)
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>> line
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>>

Any idea? :-p

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread Rocco Moretti
Dan Sommers wrote:
> On Thu, 09 Jun 2005 15:50:42 +1200,
> Greg Ewing <[EMAIL PROTECTED]> wrote:
> 
> 
>>Rocco Moretti wrote:
>>
>>>The main problem is that Python is trying to stick at least three
>>>different concepts onto the same set of operators: equivalence (are
>>>these two objects the same?), ordering (in a sorted list, which comes
>>>first?), and mathematical "size".
> 
>>>This gives the wacky world where
>>>"[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't.
> 
> 
> Python inherits that wackiness directly from (often wacky) world of
> Mathematics.
> 
> IMO, the true wackiness is that
> 
> [ AssertionError, (vars, unicode), __name__, apply ].sort( )
> 
> "works," too.  Python refusing to sort my list of complex numbers is a
> Good Thing.

The "wackyness" I refered to wasn't that a list of complex numbers isn't 
sortable, but the inconsistent behaviour of list sorting. As you 
mentioned, an arbitraty collection of objects in a list is sortable, but 
as soon as you throw a complex number in there, you get an exception.

One way to handle that is to refuse to sort anything that doesn't have a 
"natural" order. But as I understand it, Guido decided that being able 
to sort arbitrary lists is a feature, not a bug. But you can't sort ones 
with complex numbers in them, because you also want '1+3j<3+1j' to raise 
an error.

> Four separate classes of __comparison__ methods in a language that
> doesn't (and can't and shouldn't) preclude or warn about rules regarding
> which methods "conflict" with which other methods?  I do not claim to be
> an expert, but that doesn't seem very Pythonic to me.

What "conflict"? Where are you getting the doesn't/can't/shouldn't 
prescription from?

Which method you use depends on what you want to achieve:

(Hypothetical Scheme)
Object Identity? - use 'is'
Mathematical Ordering? - use '__eq__' & friends
Object Equivalence? - use '__equiv__'
Arbitrary Ordering? (e.g. for list sorting) - use '__order__'

The only caveat is to define sensible defaults for the cases where one 
fuction is not defined. But that shouldn't be too hard.

__eqiv__ -> __eq__ -> is
__order__ -> __lt__/__cmp__

> AIUI, __cmp__ exists for backwards compatibility, and __eq__ and friends
> are flexible enough to cover any possible comparison scheme.

Except if you want the situation where "[1+2j, 3+4j].sort()" works, and 
'1+3j < 3+1j' fails.


I think the issue is you thinking along the lines of Mathematical 
numbers, where the four different comparisons colapse to one. Object 
identity? There is only one 'two' - heck, in pure mathematics, there 
isn't even a 'float two'/'int two' difference. Equivalence *is* 
mathematical equality, and the "arbitrary ordering" is easily defined as 
"true" ordering. It's only when you break away from mathematics do you 
see the divergance in behavior.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread sinan ,
hi,
my table types are MyISAM both local and server, my code can reach to
my locals mysql but cannot reach when running on server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is pyton for me?

2005-06-10 Thread Andrew Dalke
Kent Johnson wrote:
> Where do you find check_call()? It's not in the docs and I get
>  >>> import subprocess
>  >>> subprocess.check_call
> Traceback (most recent call last):
>   File "", line 1, in ?
> AttributeError: 'module' object has no attribute 'check_call'
> 
> with Python 2.4.1.

Interesting.  I got my subprocess.py from CVS.  The CVS log

revision 1.12
date: 2005/01/01 09:36:34;  author: astrand;  state: Exp;  lines: +39 -1
New subprocess utility function: check_call. Closes #1071764.

The bug tracker is
  
http://sourceforge.net/tracker/index.php?func=detail&aid=1071764&group_id=5470&atid=305470

which says it's a 2.5ism.  Oops!  Sorry about that post
from the future.  I didn't realize it.

Andrew
[EMAIL PROTECTED]

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


Re: about accessing mysql

2005-06-10 Thread sinan ,
oh my system is debian - sarge with python 2.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread deelan
sinan , wrote:
(...)
> these command works at my computer but when i want to do in my server,
> i get these messages as you seen, my both computer and server have
> same python, same MySQLdb module and same database with same
> priviliges.also how can i connect to remote database? is that work ?
> db=MySQLdb.Connection(host="192.168.0.120",user="root",db="nux")
> thank you.

in addition to Diez observations please tell us:

1) version of mysql server you are trying to connect
   1a) is the the mysql db been complied to support Innodb tables?
   please issue a "SHOW VARIBLES" command on the mysql console, there
   should be some mention on innodb support somewhere.

2) version of mysqldb you are using

bye.

-- 
deelan, #1 fan of adriana lima!





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


Re: IMAP Proxy

2005-06-10 Thread =?UTF-8?B?VGFyZWsgWmlhZMOp?=
Jp Calderone wrote:

>On Fri, 10 Jun 2005 15:52:28 +0200, Tarek Ziadé <[EMAIL PROTECTED]> wrote:
>  
>
>>Hi,
>>
>>I want to write a small TCP Server in Python to make an IMAP Proxy for
>>post-processing client requests.
>>
>>It is not long either complicated but needs to be very robust so...
>>maybe someone here has already done such a thing I can use or know where
>>i can get it ?
>>
>>
>
>I recommend using Twisted's IMAP4 support for this.  There's a simple proxy in 
>the Twisted issue tracker that might be useful to start from:
>
>http://twistedmatrix.com/bugs/issue215
>
>Jp
>  
>
Ok thanks, looks good

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

Re: Basic questions about packages/modules.

2005-06-10 Thread Kay Schluehr
Negroup schrieb:
> Hi, first of all sorry for boring you with a such simple request. I'm
> using Python since few days, and I like it even if I'm not yet in
> confidence. I'd like to organize my programs in hierarchical
> structures, thus I thought that packages could be the solution,
> however I have some difficulties understanding their utilization (even
> after reading chapter 6 of the tutorial, about modules).
>
> Now an example (silly) to clarify my doubts:
>
> This is the structure:
> main.py
> importers/
> __init__.py (empty)
> importer1.py
> config/
> __init__.py (empty)
> parameters.py
>
> main.py
> ===
> from importers import importer1
> print importer1.display()
>
> importers/importer1.py
> ==
> from config import parameters
> def display():
> return '-' * parameters.counter
>
> config/parameters.py
> 
> counter = 5
>
>
> All works fine when I run "python main.py", while I get an error
> trying to run "python importers/importer1.py":
>
> Traceback (most recent call last):
>   File "importers/importer1.py", line 1, in ?
> from config import parameters
> ImportError: No module named config
>
> Can you explain why does that happen? It prevents me to test
> importer1.py alone.
>
> TIA,
> negroup

mainpackage/
  main.py
  importers/
 __init__.py (empty)
 importer1.py
  config/
 __init__.py (empty)
 parameters.py

If this is the package structure and you run 'python main.py' from
mainpackage the config package is already in the search path. Therefore
importing config in subsequent modules succeeds.

If you run importer1.py on the level of importers config may not be in
the PYTHONPATH and the import fails.

Solution: reference config in the import statement so that the package
can be found.

   from mainpackage.config import parameters

should be suffient if mainpackage is in the PYTHONPATH. But note that
you have to be consistent with your import statements because the
module will be cached in sys. modules using it's import path as key.
Doing both

   from mainpackage.config import parameters

and

   from config import parameters

in different modules leads to reimports and different modules. This may
cause trouble if you compare objects using class information because
the id's of the classes are different. 

Kay

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


Re: about accessing mysql

2005-06-10 Thread sinan ,
i checked innodb support via show variable. they have both same support. 
mysql version is 4.0.24_Debian-5-log
MySQLdb module version is  1.2.1g2
they are same packets in debian.
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP Proxy

2005-06-10 Thread =?ISO-8859-1?Q?Tarek_Ziad=E9?=
Skip Montanaro wrote:

>Tarek> I want to write a small TCP Server in Python to make an IMAP
>Tarek> Proxy for post-processing client requests.
>
>Tarek> It is not long either complicated but needs to be very robust
>Tarek> so...  maybe someone here has already done such a thing I can use
>Tarek> or know where i can get it ?
>
>There is an IMAP filter as part of the SpamBayes project that you might find
>is a useful starting point:
>
>http://www.spambayes.org/
>  
>

Thanks for pointing it out but what I am looking for is more likely to be
a TCP server that is placed on server side as a frontal for the IMAP server
to deal with all incoming queries before it is passed to the real IMAP
server.

The use case is to redirect some search queries to a home made program.

Tarek


>Skip
>  
>

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread George Sakkis
"Rocco Moretti" wrote:

> One way to handle that is to refuse to sort anything that doesn't have a
> "natural" order. But as I understand it, Guido decided that being able
> to sort arbitrary lists is a feature, not a bug.

He has changed his mind since then
(http://mail.python.org/pipermail/python-dev/2004-June/045111.html) but
it was already too late. 

Waiting-for-python-3K'ly yours
George

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread Dan Bishop
Steven D'Aprano wrote:
...
> If you were to ask, "which is bigger, 1+2j or 3+4j?" then you
> are asking a question about mathematical size. There is no unique answer
> (although taking the absolute value must surely come close) and the
> expression 1+2j > 3+4j is undefined.
>
> But if you ask "which should come first in a list, 1+2j or 3+4j?" then you
> are asking about a completely different thing. The usual way of sorting
> arbitrary chunks of data within a list is by dictionary order, and in
> dictionary order 1+2j comes before 3+4j because 1 comes before 3.
>
> This suggests that perhaps sort needs a keyword argument "style", one of
> "dictionary", "numeric" or "datetime", which would modify how sorting
> would compare keys.
>
> Perhaps in Python 3.0.

What's wrong with the Python 2.4 approach of

>>> clist = [7+8j, 3+4j, 1+2j, 5+6j]
>>> clist.sort(key=lambda z: (z.real, z.imag))
>>> clist
[(1+2j), (3+4j), (5+6j), (7+8j)]

?

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


Re: Changing entities

2005-06-10 Thread Kent Johnson
Daniel wrote:
> Hi Kent
> 
> This isn't work with the following line:
> FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
> BYTES)
> 
> 
byter = re.compile(r'SIZE \((\d+) BYTE\)')

Because the string doesn't match the pattern, can you see the difference? Do 
you understand what the regex is looking for?

Another good way to learn about regexes is with the Regex Demo program 
distributed with Python. Look for Tools\Scripts\redemo.py

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


Re: Annoying behaviour of the != operator

2005-06-10 Thread Jp Calderone
On 10 Jun 2005 09:05:53 -0700, Dan Bishop <[EMAIL PROTECTED]> wrote:
>Steven D'Aprano wrote:
>...
>> If you were to ask, "which is bigger, 1+2j or 3+4j?" then you
>> are asking a question about mathematical size. There is no unique answer
>> (although taking the absolute value must surely come close) and the
>> expression 1+2j > 3+4j is undefined.
>>
>> But if you ask "which should come first in a list, 1+2j or 3+4j?" then you
>> are asking about a completely different thing. The usual way of sorting
>> arbitrary chunks of data within a list is by dictionary order, and in
>> dictionary order 1+2j comes before 3+4j because 1 comes before 3.
>>
>> This suggests that perhaps sort needs a keyword argument "style", one of
>> "dictionary", "numeric" or "datetime", which would modify how sorting
>> would compare keys.
>>
>> Perhaps in Python 3.0.
>
>What's wrong with the Python 2.4 approach of
>
 clist = [7+8j, 3+4j, 1+2j, 5+6j]
 clist.sort(key=lambda z: (z.real, z.imag))
 clist
>[(1+2j), (3+4j), (5+6j), (7+8j)]
>

It's not a general solution:

>>> L = [1, 'hello', 2j]
>>> L.sort(key=lambda x: (x.real, x.imag))
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1, in 
AttributeError: 'int' object has no attribute 'real'

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


How to overcome automatic cyrillic-to-/hex convert

2005-06-10 Thread degoor_python
Hi friends,

I am really sorry to bother you with such a simple stupid question but
today it's my second day spent in searching manuals, mail-archives
(I downloaded over 100MB from "python-list"),
etc., and I could not find anything that can solve the matter.

I am from Bulgaria and I use Python (+wxPython+Boa Constructor) as a
front-end to database processing with Firebird. I use Python 2.4.1 over
Windows 98 SE. My keyboard is set as default Bulgarian keyboard (keybg)
so I can write in Bulgarian using win32 application as well in MS DOS
prompt. That should correspond to 'cp1251' (win32) and 'cp855' (DOS
console) encodings.

But when I enter some Bulgarian (actually cyrillic) text as a string,
it
seems that Python automatically converts it to '\x00..\x00 ' and once
converted that way I can't get it back into its original look. The only
way to get it right is using print :

>>> a = 'МАМА' # 'Mam' in Bulgarian
>>> print a
'МАМА'

but

>>> a
'\xcc\xe0\xec\xe0'

It is not such a great problem that the string enters or gets out of
the
database in that look as long as the user doesn't see it. But when it
comes to data visualization I can't expect the user to know what
'\xcc\xe0\xec\xe0' mean, neither can I use (at least as much as I know)
'print' for that job. To visualize data in the base I use table views
created with wxGrid. In the grid instead of 'МАМА' I am getting
'\xcc\xe0\xec\xe0'.

To set the value of a particular cell in the grid I use
wxGrid::SetCellValue :

self.grid1.SetCellValue(row, column, string)

In one of O'Reilly's Python books (Learning Python, chapter 8.3.2)there
is a hint that it is possible to redirect the standard output to a
user-defined object but it is not quite clear how that can be achived
and if that is applicable in my case at all.

Your help is of great need and would be truely appreciated!

Thank you very much!

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

Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Mandus" wrote:

> Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde:
> [snip]
> >
> > set_callback(obj,
> >  lambda x: (if a:
> >2
> >  else:
> >3)
> >
> [snip]
>
> You can do stuff like this: lambda x: x and 2 or 3
>
> Of course, you are still quite limited in what you can do, but it have
> solved some of my problems...

Another case I've found handy to use lambdas and expressions instead of
named functions and statements is for simple properties:

class SomeArray(object):
dimensions = property(
fget = lambda self: (self.x,self.y),
fset = lambda self,(x,y): setattr(self,'x',x) or
  setattr(self,'y',y))

Again, it is quite limited, but properties are also often limited so
it's a useful idiom to know.

George

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


RE: how to operate the excel by python?

2005-06-10 Thread Hughes, Chad O
Here are two scripts that I have had to build for a class that I teach. You 
will either need to write the constants explicitly, or I can email neet the 
constans module that I have built, for the second one to work.  I will copy it 
to the very end.  If you have any questions, just let me know. Here is a simple 
one that allows me to interface with my grade book spreadsheet though the 
command line for taking attendance:

from win32com.client import Dispatch
import time
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open('C:\\Documents and Settings\\My 
Documents\\discrete\\GradeBook.xls')
ws = wb.Worksheets.Item(1)
ws.Activate()
i = 1
while True:
  if ws.Cells(1,i).Text == '':
break
  i += 1
t = time.localtime()
d = '%s/%s/%s'%(t.tm_mon,t.tm_mday,t.tm_year)
ws.Cells(1,i).FormulaR1C1 = d
ws.Cells(2,i).Select()
j = 2
while True:
  name = ws.Cells(j,1).Text
  if name == '':
break
  name = name.split()[1]
  here = int(raw_input('%s here? '%name))
  ws.Cells(j,i).FormulaR1C1 = here
  j += 1
wb.Save() 

The next one is a kluge (spaghetti code), sorry but it is complete.  It builds 
a truth table for evalutating logic expressions:

from win32com.client import Dispatch
>From officecon.xlcon import *
xl = Dispatch('Excel.Application')
binary = False # set this to true to use 0 and 1 instead of False and True
vars = raw_input("Comma seperate the variables:")
headers = raw_input("What other headers do you want, comma seperated?")
headers = headers.split(',')
vars = vars.split(',')
numToAlpha = 'abcdefghijklmnopqrstuvwxyz'
if not xl.Visible:
  xl.Workbooks.Add()
  xl.Worksheets.Add()
  for i in range(3):
sheet = xl.Worksheets.Item(2)
sheet.Delete()
  xl.ActiveWindow.SelectedSheets.Delete
else:
  xl.Worksheets.Add()

sheet = xl.Worksheets.Item(1)
if len(headers[-1]) > 30:
  sheet.name = headers[-1][:27]+'...'
elif headers[-1] == '':
  sheet.name = 'Example'
else:
  sheet.name = headers[-1]

xl.Visible = True  
  
for i in range(len(vars)):
  sheet.Range(numToAlpha[i]+'1').FormulaR1C1 = vars[i]
sheet.Rows("1:1").Select()
xlBottom = -4107
xlCenter = -4108
xl.Selection.NumberFormat = "General"
xl.Selection.HorizontalAlignment = xlCenter
xl.Selection.VerticalAlignment = xlBottom
xl.Selection.Font.name = "Areial"
xl.Selection.Font.FontStyle = "Bold"
xl.Selection.Font.Size = 12

rows = []
number = 2**len(vars)
for i in range(number):
  row = []
  for j in range(len(vars)):
row.append((i%(2**(len(vars)-j)))/(2**(len(vars)-j-1)))
  rows.append(row)
  
for row in range(len(rows)):
  for column in range(len(rows[row])):
if not rows[row][column]:
  if binary:
value = 0
  else:
value = 'TRUE'
else:
  if binary:
value = 1
  else:
value = 'FALSE'
sheet.Range(numToAlpha[column]+`row+2`).FormulaR1C1 = value

for i in range(len(headers)):
  sheet.Range(numToAlpha[i+len(vars)]+'1').FormulaR1C1 = headers[i]
  sheet.Range(numToAlpha[i+len(vars)]+'1').Select()

sheet.Range("A1:"+numToAlpha[len(vars)+len(headers)-1]+`number+1`).Select()
xl.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xl.Selection.Borders(xlDiagonalUp).LineStyle = xlNone

xl.Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
xl.Selection.Borders(xlEdgeLeft).Weight = xlThick
xl.Selection.Borders(xlEdgeLeft).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
xl.Selection.Borders(xlEdgeTop).Weight = xlThick
xl.Selection.Borders(xlEdgeTop).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
xl.Selection.Borders(xlEdgeBottom).Weight = xlThick
xl.Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
xl.Selection.Borders(xlEdgeRight).Weight = xlThick
xl.Selection.Borders(xlEdgeRight).ColorIndex = xlAutomatic


xl.Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
xl.Selection.Borders(xlInsideVertical).Weight = xlThin
xl.Selection.Borders(xlInsideVertical).ColorIndex = xlAutomatic


xl.Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
xl.Selection.Borders(xlInsideHorizontal).Weight = xlThin
xl.Selection.Borders(xlInsideHorizontal).ColorIndex = xlAutomatic

xl.Range("A1:"+numToAlpha[len(vars)+len(headers)-1]+'2').Select()
xl.Selection.Borders(xlInsideHorizontal).Weight = xlThick

xl.Range(numToAlpha[len(vars)-1]+'1:'+numToAlpha[len(vars)]+`number+1`).Select()
xl.Selection.Borders(xlInsideVertical).LineStyle = xlDouble


xl.Range(numToAlpha[len(vars)+len(headers)-1]+'1:'+numToAlpha[len(vars)+len(headers)-1]+`number+1`).Select()
xl.Selection.Borders(xlEdgeLeft).LineStyle = xlDashDotDot
xl.Selection.Interior.ColorIndex = 20
xl.Selection.Interior.Pattern = xlSolid
#xl.Selection.Borders(xlEdgeLeft).Weight = xlThick
#xl.Selection.Borders(xlEdgeTop).Weight = xlThick
#xl.Selection.Borders(xlEdgeBottom).Weight = xlThick
xl.Selection.Borders(xlEdgeRight).Weight = xlThick
#xl.Selection.Borders(xlInsideVertical).Weight = xlThin
#xl.Selec

Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Kay Schluehr" wrote:

> > Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde:
> > [snip]
> > >
> > > set_callback(obj,
> > >  lambda x: (if a:
> > >2
> > >  else:
> > >3)
> > >
> > [snip]
> >
> > You can do stuff like this: lambda x: x and 2 or 3
>
> You can also do this
>
>lambda x: {True:2,False:3}.get(bool(a))
>
> which is both beautiful and pythonic.
>
> Kay

Beauty and 'pythonicity' are in the eye of the beholder; IMO both are
much less obvious than the if/then/else, especially for a beginner or
someone who has never seen these idioms before. I personally don't find
the (ab)use of dictionaries in this case to be more beautiful or
pythonic than the and/or idiom (not to mention the runtime cost of
building a new dictionary every time), but YMMV.

George

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


Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Kay Schluehr" wrote:

> > You can do stuff like this: lambda x: x and 2 or 3
>
> You can also do this
>
>lambda x: {True:2,False:3}.get(bool(a))
>
> which is both beautiful and pythonic.
>
> Kay

Beauty is in the eye of the beholder, and the same holds for
'pythonicity'; IMO both are much less obvious than the if/then/else,
especially for a beginner or someone who has never seen these idioms
before. I personally don't find the (ab)use of dictionaries in this
case to be more beautiful or pythonic than the and/or idiom (not to
mention the runtime cost of building a new dictionary every time), but
YMMV.

George

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


Re: Dealing with marketing types...

2005-06-10 Thread Harald Massa
> They want a 
> "scalable, enterprise solution" (though they don't really know what
> that means) and are going crazy throwing around the Java buzzwords
> (not to mention XML).
> 
There is a very cheap solution: Ryan Tomayko debunkes all these myths.
You can google it up, "astronaut architects" 

There is a cheap solution: on this years EuroPython (www.europython.org)
there will be a special Slot in Social Skills track dealing with
"Selling Python", giving you a Python Sales Pitch and two more excellent
seminars about persuading people. More than that, in Python in Business
Track we will do slots about using Python for real worthy enterprise
apps which scale and are FULLY buzzword-compatible. 

Join us!

Harald Armin Massa
GHUM Harald Massa
perusasion. python. postgresql.


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


Re: match groups: optional groups not accessible

2005-06-10 Thread Peter Hansen
Peter Hansen wrote:
> [EMAIL PROTECTED] wrote:
> 
>> Why does the following result in an IndexError?
>> I try to match an optional group, and then access it via its group
>> name. The group happens to not participate in the match, but is
>> obviously defined in the pattern.
>>
> m = re.match('(?Pmaybe)?yes', "yes")
> 
> Uh, don't you need to actually *group* the first "yes" part, with 
> parentheses, to make it a group?  Otherwise you aren't going to be 
> treating it as other than text-between-groups-that-can-be-skipped.

Oops... from Duncan's reply and a reread I can see I missed the point 
entirely... I obviously thought you were expecting the "yes" to be in a 
group too.  Duh.

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


RE: how to operate the excel by python?

2005-06-10 Thread Hughes, Chad O
Sorry, I meant to spell check but I did not somehow.

Chad

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hughes, Chad O
Sent: Friday, June 10, 2005 10:01 AM
To: python-list@python.org
Subject: RE: how to operate the excel by python?


Here are two scripts that I have had to build for a class that I teach. You 
will either need to write the constants explicitly, or I can email neet the 
constans module that I have built, for the second one to work.  I will copy it 
to the very end.  If you have any questions, just let me know. Here is a simple 
one that allows me to interface with my grade book spreadsheet though the 
command line for taking attendance:

from win32com.client import Dispatch
import time
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open('C:\\Documents and Settings\\My 
Documents\\discrete\\GradeBook.xls')
ws = wb.Worksheets.Item(1)
ws.Activate()
i = 1
while True:
  if ws.Cells(1,i).Text == '':
break
  i += 1
t = time.localtime()
d = '%s/%s/%s'%(t.tm_mon,t.tm_mday,t.tm_year)
ws.Cells(1,i).FormulaR1C1 = d
ws.Cells(2,i).Select()
j = 2
while True:
  name = ws.Cells(j,1).Text
  if name == '':
break
  name = name.split()[1]
  here = int(raw_input('%s here? '%name))
  ws.Cells(j,i).FormulaR1C1 = here
  j += 1
wb.Save() 

The next one is a kluge (spaghetti code), sorry but it is complete.  It builds 
a truth table for evalutating logic expressions:

from win32com.client import Dispatch
>From officecon.xlcon import *
xl = Dispatch('Excel.Application')
binary = False # set this to true to use 0 and 1 instead of False and True vars 
= raw_input("Comma seperate the variables:") headers = raw_input("What other 
headers do you want, comma seperated?") headers = headers.split(',') vars = 
vars.split(',') numToAlpha = 'abcdefghijklmnopqrstuvwxyz' if not xl.Visible:
  xl.Workbooks.Add()
  xl.Worksheets.Add()
  for i in range(3):
sheet = xl.Worksheets.Item(2)
sheet.Delete()
  xl.ActiveWindow.SelectedSheets.Delete
else:
  xl.Worksheets.Add()

sheet = xl.Worksheets.Item(1)
if len(headers[-1]) > 30:
  sheet.name = headers[-1][:27]+'...'
elif headers[-1] == '':
  sheet.name = 'Example'
else:
  sheet.name = headers[-1]

xl.Visible = True  
  
for i in range(len(vars)):
  sheet.Range(numToAlpha[i]+'1').FormulaR1C1 = vars[i]
sheet.Rows("1:1").Select()
xlBottom = -4107
xlCenter = -4108
xl.Selection.NumberFormat = "General" xl.Selection.HorizontalAlignment = 
xlCenter xl.Selection.VerticalAlignment = xlBottom xl.Selection.Font.name = 
"Areial" xl.Selection.Font.FontStyle = "Bold" xl.Selection.Font.Size = 12

rows = []
number = 2**len(vars)
for i in range(number):
  row = []
  for j in range(len(vars)):
row.append((i%(2**(len(vars)-j)))/(2**(len(vars)-j-1)))
  rows.append(row)
  
for row in range(len(rows)):
  for column in range(len(rows[row])):
if not rows[row][column]:
  if binary:
value = 0
  else:
value = 'TRUE'
else:
  if binary:
value = 1
  else:
value = 'FALSE'
sheet.Range(numToAlpha[column]+`row+2`).FormulaR1C1 = value

for i in range(len(headers)):
  sheet.Range(numToAlpha[i+len(vars)]+'1').FormulaR1C1 = headers[i]
  sheet.Range(numToAlpha[i+len(vars)]+'1').Select()

sheet.Range("A1:"+numToAlpha[len(vars)+len(headers)-1]+`number+1`).Select()
xl.Selection.Borders(xlDiagonalDown).LineStyle = xlNone 
xl.Selection.Borders(xlDiagonalUp).LineStyle = xlNone

xl.Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous 
xl.Selection.Borders(xlEdgeLeft).Weight = xlThick 
xl.Selection.Borders(xlEdgeLeft).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeTop).LineStyle = xlContinuous 
xl.Selection.Borders(xlEdgeTop).Weight = xlThick 
xl.Selection.Borders(xlEdgeTop).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous 
xl.Selection.Borders(xlEdgeBottom).Weight = xlThick 
xl.Selection.Borders(xlEdgeBottom).ColorIndex = xlAutomatic


xl.Selection.Borders(xlEdgeRight).LineStyle = xlContinuous 
xl.Selection.Borders(xlEdgeRight).Weight = xlThick 
xl.Selection.Borders(xlEdgeRight).ColorIndex = xlAutomatic


xl.Selection.Borders(xlInsideVertical).LineStyle = xlContinuous 
xl.Selection.Borders(xlInsideVertical).Weight = xlThin 
xl.Selection.Borders(xlInsideVertical).ColorIndex = xlAutomatic


xl.Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous 
xl.Selection.Borders(xlInsideHorizontal).Weight = xlThin 
xl.Selection.Borders(xlInsideHorizontal).ColorIndex = xlAutomatic

xl.Range("A1:"+numToAlpha[len(vars)+len(headers)-1]+'2').Select()
xl.Selection.Borders(xlInsideHorizontal).Weight = xlThick

xl.Range(numToAlpha[len(vars)-1]+'1:'+numToAlpha[len(vars)]+`number+1`).Select()
xl.Selection.Borders(xlInsideVertical).LineStyle = xlDouble


xl.Range(numToAlpha[len(vars)+len(headers)-1]+'1:'+numToAlpha[len(vars)+len(headers)-1]+`number+1`).Select()
xl.Selection.Borders(xlEdgeLeft).LineStyle = xlDashDotDot 
xl.Selection.Interior.ColorIndex = 20 xl.Selectio

Re: Annoying behaviour of the != operator

2005-06-10 Thread Terry Reedy

"Rocco Moretti" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The "wackyness" I refered to wasn't that a list of complex numbers isn't
> sortable, but the inconsistent behaviour of list sorting. As you
> mentioned, an arbitraty collection of objects in a list is sortable, but
> as soon as you throw a complex number in there, you get an exception.

This 'wackyness' is an artifact resulting from Python being 'improved' 
after its original design.  When Guido  added complex numbers as a builtin 
type, he had to decide whethter to make them sortable or not.  There were 
reasons to go either way.  ... and the discussion has continued ever since 
;-)

Terry J. Reedy



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


  1   2   >