itools 0.20.0 released

2007-12-20 Thread J. David Ibáñez

itools is a Python library, it groups a number of packages into a single
meta-package for easier development and deployment:

  itools.catalog  itools.i18n itools.uri
  itools.csv  itools.ical itools.vfs
  itools.datatypesitools.odf  itools.web
  itools.gettext  itools.pdf  itools.workflow
  itools.git  itools.rest itools.xliff
  itools.handlers itools.rss  itools.xml
  itools.html itools.stl
  itools.http itools.tmx

The most visible change in this major release is that itools.cms has
been moved out of itools and is now distributed as a separate package,
named ikaaro.

Also in the code reorganization category: itools.xhtml has been merged
into itools.html.  And the itools.schemas package has been removed,
since we do the same thing in a different way.

The most important change is the architecture overhaul of the handlers
package.  From a functional point of view, the big news is the database
layer that has been included, which provides atomic transactions for
the file system.  But the changes go well beyond that, read the
documentation to learn how things work now.

Other packages that have seen more or less important API improvements
or changes include itools.catalog, itools.csv, itools.datatypes,
itools.rss, itools.vfs and itools.web.  There have been also many
naming normalizations.  Check the upgrade notes for further details.

The numbering scheme has changed, we have jumped from the 0.16 to the
0.20 version, and future major releases will be numbered 0.30, 0.40,
0.50, etc.  (This change is to define an implicit relationship with
the numbering scheme of ikaaro.)


Resources
-

Download
http://download.ikaaro.org/itools/itools-0.20.0.tar.gz
http://download.ikaaro.org/itools/itools-0.20.0.win32-py2.5.exe
http://download.ikaaro.org/itools/itools-0.20.0.win32-py2.4.exe

Home
http://www.ikaaro.org/itools

Mailing list
http://mail.ikaaro.org/mailman/listinfo/itools

Bug Tracker
http://bugs.ikaaro.org/



-- 
J. David Ibáñez
Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45
9 rue Darwin, 75018 Paris  Fax +33 (0)1 53 28 27 88
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: New+old-style multiple inheritance

2007-12-20 Thread Bruno Desthuilliers
Jonathan Gardner a écrit :
 On Dec 18, 7:08 am, [EMAIL PROTECTED]
(snip)
 Monkey patching is definitely unpythonic.  You must be a Ruby guy.

Strange enough, I learned monkey-patching with Python, years before I 
first heard of a language named Ruby.

 Why
 don't you try doing something else to get the behavior you want,
 something more explicit?
 

 From experience, monkey-patching is sometimes the very best solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem untaring python2.5

2007-12-20 Thread Shane Geiger
You might want to try an all-python implementation for sanity testing. 

I haven't tested this snippet much.  I am not sure it handles nested
files all that well. 



import tarfile
tar = tarfile.open(TarTest.tar.gz2, r:gz) #  other options:
r:bz2, and ??
file_list = tar.getnames()

import os
os.mkdir('new_dir')
# write the files out to new files
for fname in tar.getnames():
# extract/decompress the data of each file
data = tar.extractfile(fname).read()
# optionally change the filename
new_file = new_dir/ + fname
print File %s written! % new_file
# write the decompressed data to a file
fout = open(new_file, w)
fout.write(data)
fout.close()

# done, close the tar file ...
tar.close()



 On Dec 19, 12:16 pm, [EMAIL PROTECTED] wrote:
   
 Hello,

 It is not possible to give sharp hints without more relevant
 information like:
 - What is your platform?
 - Which version of python?
 - What is the version of: $tar--version (GNUtar, other proprietarytar, 
 according to my personal experience, AIXtarmay fail)
 - Is your disk full or do you have the correct permissions with your
 current user?

 ++

 Sam
 

 Hi Sam ,
 I am using windows server 2003, python2.5.1 and version 1.16 of tar

 and as per disk full issues i dont think that my systems hard disk is
 full

   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


Re: Where best to put local modules?

2007-12-20 Thread tinnews
Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Wed, 19 Dec 2007 14:02:20 -0300, [EMAIL PROTECTED] escribi?:
 
  I'm just beginning to create some python modules for my own use and
  I'm wondering where to put them.  Initially I have put them in
  $HOME/bin and I have set PYTHONPATH to point to them there.  It all
  seems to be OK but I was wondering if I might be storing up problems
  for the future by putting python modules in with my odds and sods of
  shell scripts etc. (and with my python 'main' scripts).
 
  Would I be better off putting the modules somewhere else, e.g.
  somewhere like $HOME/lib/python?
 
 Try lib/pythonX.X/site-packages, which is already on sys.path so you don't  
 have to set PYTHONPATH
 
That's fine if it happens to be your own system and you have root
access, however I was actually meaning on a system where I just have a
shell account.

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


Re: New+old-style multiple inheritance

2007-12-20 Thread Robert Kern
Bruno Desthuilliers wrote:
 Jonathan Gardner a écrit :
 On Dec 18, 7:08 am, [EMAIL PROTECTED]
 (snip)
 Monkey patching is definitely unpythonic.  You must be a Ruby guy.
 
 Strange enough, I learned monkey-patching with Python, years before I 
 first heard of a language named Ruby.

Indeed. I believe the term started at Zope Corp.

Ah, Wikipedia supports my recollection:

  http://en.wikipedia.org/wiki/Monkey_patch

(And I swear that it did so before I checked it.)

It looks like some Ruby folks have taken to calling the practice duck
punching, which has a certain charm of its own.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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

Re: Static linking of python and pyqt

2007-12-20 Thread BlueBird
On Dec 19, 1:26 pm, Markus Dahlbokum [EMAIL PROTECTED] wrote:
   I just want the qt libs linked to the interpreter without accessing them
   by a module. I tried the configure option '--with-libs='lib ...''. The
   make did fine but the executable is too small and the qt symbols are not
   known by it. How can I just link qt statically?

  Why do you want to do this? If qt isn't actually *used* in Python (as
  you don't include the pyqt modules), what effect do you expect from
  such linking?

  I think it linked just fine - it just didn't include any symbols,
  because none were needed. That is the correct, expected behavior.
  It all worked fine.

  Regards,
  Martin

 I need an environment that can be delivered to our customers without
 installing python, qt and pyqt. We want to provide the complete package.
 In order to do so I need to link at least python and qt. How can this be done?

 Of course a complete package with python, qt and pyqt would be the best
 solution but there seem to be even more complications that way. If you can
 help me with this I would be very grateful.

If it's for windows, py2exe works like a charm for this kind of setup.

For windows + linux, you might one to try one of:
http://www.freehackers.org/Packaging_a_python_program


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


Re: pop3_ssl Attachment problem

2007-12-20 Thread Chris
On Dec 20, 9:22 am, los117 [EMAIL PROTECTED] wrote:
 I am trying to fetch email from gmail, but what I am really interested
 is the attachment.
 I manage to access the gmail server and get the messege but the
 attachment came as text:

 --=_Part_5286_15861975.1197955173158
 Content-Type: audio/mpeg; name=Dire Straits - 12 - Calling Elvis.mp3
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_fabzd5l20
 Content-Disposition: attachment;
  filename=Dire Straits - 12 - Calling Elvis.mp3

 //
 ugbAAP8AAA...

 how do i manage to get the file? I google for a while now, but I am a
 bit lost of ideas. Sorry for the noobish and the english. thanks =D

the base64 string you started quoting is the attachment.
from base64 import decodestring
fout = open( filename_from_email,
'w' ).write( decodestring( string_you_parsed_from_the_email ) )

also look at the email module, there are some functions to get the
payload of the email for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where best to put local modules?

2007-12-20 Thread tinnews
Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] a écrit :
  I'm just beginning to create some python modules for my own use and
  I'm wondering where to put them.  Initially I have put them in
  $HOME/bin and I have set PYTHONPATH to point to them there.  It all
  seems to be OK but I was wondering if I might be storing up problems
  for the future by putting python modules in with my odds and sods of
  shell scripts etc. (and with my python 'main' scripts).
  
  Would I be better off putting the modules somewhere else, e.g.
  somewhere like $HOME/lib/python?
  
 
 If you're on a shared system and don't have admin access, this last 
 solution is probably the best - pure modules have nothing to do in a 
 bin/ directory indeed. Now if it's your own computer, why not just put 
 them in /path/to/python/libs/site-packages ?

There's one of each, a system where I have a shell account but not
root access and my home system.

There is a disadvantage of putting stuff in the site-packages directory
isn't there? If/when I upgrade the system the python modules I have added
will effectively not be visible to the upgraded system.  I know I can
copy them across to the new site-packages but it's just one more chore
when upgrading.  If they were in $HOME/lib/python this issue wouldn't
arise because /home stays the same across upgrades.

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


Question about email-handling modules

2007-12-20 Thread Robert Latest
Hello,

I'm new to Python but have lots of programming experience in C, C++ and 
Perl. Browsing through the docs, the email handling modules caught my eye 
because I'd always wanted to write a script to handle my huge, ancient, and 
partially corrupted email archives.

Of course I know that this kind of project shouldn't be tackled by a 
beginner in a language, but I still thought I'd give it a spin. 

So I wrote the stuff at the bottom. It lists senders, subjects and 
addressees of all messages in an mbox.

Things that I don't understand:

1. Why can I get the 'subject' and 'from' header field unsig the [] 
notation, but not 'to'? When I print Message.keys I get a list of all header 
fields of the message, including 'to'. What's the difference between 
message['to'] and message.get('to')?

2. Why can't I call the get_payload() method on the message? What I get is 
this cryptic error: AttributeError: Message instance has no attribute 
'get_payload'. I'm trying to call a method here, not an attribute. It makes 
no difference if I put parentheses after get_payload or not. I looked into 
the email/Message module and found get_payload defined there. 

I don't want to waste your time by requesting that you pick apart my silly 
example. But maybe you can give me a pointer in the right direction. This is 
python 2.4 on a Debian box.

---

#!/usr/bin/python
import mailbox
import email  # doesn't make a difference
from email import Message # neither does this

mbox = file(mail.old/friends)

for message in mailbox.UnixMailbox(mbox):
subject = message['subject']
frm = message['from']
#to = message['to'] # this throws a Key Error
to = message.get('to'); # ...but this works
print frm, writes about, subject, to, to
#print message.get_payload() # this doesn't work

--

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


Re: Question about email-handling modules

2007-12-20 Thread Matt Nordhoff
Robert Latest wrote:
 Hello,
 
 I'm new to Python but have lots of programming experience in C, C++ and 
 Perl. Browsing through the docs, the email handling modules caught my eye 
 because I'd always wanted to write a script to handle my huge, ancient, and 
 partially corrupted email archives.
 
 Of course I know that this kind of project shouldn't be tackled by a 
 beginner in a language, but I still thought I'd give it a spin. 
 
 So I wrote the stuff at the bottom. It lists senders, subjects and 
 addressees of all messages in an mbox.
 
 Things that I don't understand:
 
 1. Why can I get the 'subject' and 'from' header field unsig the [] 
 notation, but not 'to'? When I print Message.keys I get a list of all header 
 fields of the message, including 'to'. What's the difference between 
 message['to'] and message.get('to')?

On dicts, and presumably on Messages too, .get returns a default value
(None, or you can specify another with .get(key, default) if the key
doesn't exist.

I can't say why ['to'] doesn't work when it's in the list of keys, though.

 2. Why can't I call the get_payload() method on the message? What I get is 
 this cryptic error: AttributeError: Message instance has no attribute 
 'get_payload'. I'm trying to call a method here, not an attribute. It makes 
 no difference if I put parentheses after get_payload or not. I looked into 
 the email/Message module and found get_payload defined there. 

Methods are attributes. When you do obj.method(), obj.method and
() are really two separate things: It gets the method attribute of
obj, and then calls it.

 I don't want to waste your time by requesting that you pick apart my silly 
 example. But maybe you can give me a pointer in the right direction. This is 
 python 2.4 on a Debian box.
 
 ---
 
 #!/usr/bin/python
 import mailbox
 import email  # doesn't make a difference
 from email import Message # neither does this
 
 mbox = file(mail.old/friends)
 
 for message in mailbox.UnixMailbox(mbox):
 subject = message['subject']
 frm = message['from']
 #to = message['to'] # this throws a Key Error
 to = message.get('to'); # ...but this works
 print frm, writes about, subject, to, to
 #print message.get_payload() # this doesn't work
 
 --
 
 robert

(Oops, I wrote this like half an hour ago, but I never sent it.)
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More than one interpreter per process?

2007-12-20 Thread sturlamolden
On 19 Des, 08:02, Christian Heimes [EMAIL PROTECTED] wrote:

 No, you can't. Sub-interpreters share a single GIL and other state. Why
 don't you run multiple processes? It's on of the oldest and best working
 ways use the full potential of your system. Lot's of Unix servers like
 postfix, qmail, apache (with some workers) et al. use processes.

Because there is a broken prominent OS that doesn't support fork()?

MPI works with multiple processes, though, and can be used from Python
(mpi4py) even under Windows.




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


Is there *any* real documentation to PyWin32?

2007-12-20 Thread Benoit
I understand that the Win32 has been said to be itself poorly
documented, so perhaps that the documentation that comes with the
modules is of similar quality is no coincidence.  Maybe I'm still too
young in my programming to grasp the good of that documentation, but
for myself, it tells me next to nothing.  Could anyone point me to
anything which may exist that does a better job of explaining the
extensions' use?  I tried to take a look @ Microsoft's documentation,
but it was confusing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem untaring python2.5

2007-12-20 Thread John Machin
On Dec 20, 5:25 pm, abhishek [EMAIL PROTECTED] wrote:
 On Dec 19, 12:16 pm, [EMAIL PROTECTED] wrote:

  Hello,

  It is not possible to give sharp hints without more relevant
  information like:
  - What is your platform?
  - Which version of python?
  - What is the version of: $tar--version (GNUtar, other proprietarytar, 
  according to my personal experience, AIXtarmay fail)
  - Is your disk full or do you have the correct permissions with your
  current user?

  ++

  Sam

 Hi Sam ,
 I am using windows server 2003, python2.5.1 and version 1.16 of tar

 and as per disk full issues i dont think that my systems hard disk is
 full

You didn't answer the question about permissions. You may need to log
on as an admin.

If those /Mac/. files are the only ones that untar complained
about and it unpacked all the other files, then AFAIK you don't have a
problem -- that stuff is Macintosh-specific.

Otherwise I suggest you try another means of unpacking the archive. I
have downloaded the tgz file and unpacked it successfully with 7zip
(http://www.7-zip.org/) -- it should hack the tar.bz2 file also.

HTH,
John


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


Re: Is there *any* real documentation to PyWin32?

2007-12-20 Thread Tim Golden
Benoit wrote:
 I understand that the Win32 has been said to be itself poorly
 documented, so perhaps that the documentation that comes with the
 modules is of similar quality is no coincidence.  Maybe I'm still too
 young in my programming to grasp the good of that documentation, but
 for myself, it tells me next to nothing.  Could anyone point me to
 anything which may exist that does a better job of explaining the
 extensions' use?  I tried to take a look @ Microsoft's documentation,
 but it was confusing.

I think the thing is that, for most of the modules, they're simply
answering the question How do I do x in Python? where x is the
answer to the question How do I do y in Windows?. For example:
How do I send something to a printer in Windows?. If you Google
around a bit with that, you'll end up with things like OpenPrinter,
StartDocPrinter and so on. With a Vb/Delphi/C++ example in hand,
the pywin32 extensions usually make it possible to translate pretty
much directly into Python.

Obviously, the modules are more-or-less hand-coded/generated so
only whatever someone's[*] seen fit to include are included (and
development continues so new things do turn up). The more general
solution is ctypes, standard with Py2.5+, available as an extension
before that. That's even lower level, but does mean that if something
isn't exposed via pywin32 then you can do-it-yourself.

All this isn't really answering your question but is at least
explaining a bit why explaining the extensions' use is perhaps
a trivial task - they're there to expose the Microsoft API in
a slightly more Pythonic layer.

There are a few web pages around with a few hints and recipes, my
own included:

http://timgolden.me.uk/python/win32_how_do_i.html

Ultimately, though, you're at the mercy of the MS API unless
someone's already done the legwork of providing a more Pythonic
wrapper to something.

TJG

[*] And someone here means the selfless small team, mostly consisting
of Mark Hammond and Roger Upole, who've contributed over the years.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to detect if a image file has icc profile embeded?

2007-12-20 Thread hi and hello
On Dec 15, 7:19 pm, has [EMAIL PROTECTED] wrote:
 On 15 Dec, 02:40, hi and hello [EMAIL PROTECTED] wrote:

  thx.

 What OS?

windows xp and linux
-- 
http://mail.python.org/mailman/listinfo/python-list


Valgrind and pexpect

2007-12-20 Thread Salvatore Iovene
Hi,
I'm using the pexpect module to spawn some processes in a testing
environment. pexpect uses, internally, os.execv. What I need to do is
valgrind python and get memory leaks from the spawned children
(assuming that python doesn't leak :)).

Here's a simple testcase:

===
leak.c:
===

#include stdlib.h
#include stdio.h

int main()
{
int *i = (int *) malloc(sizeof(int));
*i = 7;
printf(*i=%d\n, *i);

return 0;
}


===
leak.py:
===
import pexpect
import sys

child = pexpect.spawn('./leak')
child.expect('\*i=');
print 'Done'

===
Valgrind command:
===

valgrind --leak-check=full --trace-children=yes --tool=memcheck
--suppressions=valgrind-python.supp python ./leak.py

==30239== Memcheck, a memory error detector.
==30239== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==30239== Using LibVEX rev 1658, a library for dynamic binary translation.
==30239== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==30239== Using valgrind-3.2.1-Debian, a dynamic binary
instrumentation framework.
==30239== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==30239== For more details, rerun with: -v
==30239==
Done
==30239==
==30239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1092 from 8)
==30239== malloc/free: in use at exit: 702,546 bytes in 140 blocks.
==30239== malloc/free: 2,314 allocs, 2,174 frees, 1,929,320 bytes allocated.
==30239== For counts of detected errors, rerun with: -v
==30239== searching for pointers to 140 not-freed blocks.
==30239== checked 1,069,436 bytes.
==30239==
==30239== LEAK SUMMARY:
==30239==definitely lost: 0 bytes in 0 blocks.
==30239==  possibly lost: 0 bytes in 0 blocks.
==30239==still reachable: 699,710 bytes in 138 blocks.
==30239== suppressed: 2,836 bytes in 2 blocks.
==30239== Reachable blocks (those to which a pointer was found) are not shown.
==30239== To see them, rerun with: --show-reachable=yes



As you can see, the 4 bytes leaked by leak.c are not reported. The
suppression file I've used is taken from:
http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp
and I have uncommented the parts related to PyObject_Free and
PyObject_Realloc, as explained there.

So, does anyone know what the correct way to do this is?

Thanks in advance,
Salvarore.


-- 
Salvatore Iovene
http://www.iovene.com/
Key Fingerprint: 5647 944D D5AD 2E87 00B4  7D54 2864 359D FF20 16D8
-- 
http://mail.python.org/mailman/listinfo/python-list


Hexadecimal list conversion

2007-12-20 Thread Neil Webster
Hi All.

I have a list which is a line from a file:
['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
'\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

This should be in the format:
['381475.502599', '213622.174282']

I've tried a few options using replace (replacing \x00 with ) and
trying to convert from hexademical to decimal.

But nothing has worked.  Can anybody give any tips to help?

Thanks.

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


Re: How to detect if a image file has icc profile embeded?

2007-12-20 Thread has
On 20 Dec, 12:09, hi and hello [EMAIL PROTECTED] wrote:
 On Dec 15, 7:19 pm, has [EMAIL PROTECTED] wrote:

  On 15 Dec, 02:40, hi and hello [EMAIL PROTECTED] wrote:

   thx.

  What OS?

 windows xp and linux

Not my areas of expertise, unfortunately. This might be looking into
though:

http://www.cazabon.com/pyCMS/

HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about email-handling modules

2007-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2007 09:31:10 +, Robert Latest wrote:

 1. Why can I get the 'subject' and 'from' header field unsig the []
 notation, but not 'to'? When I print Message.keys I get a list of all
 header fields of the message, including 'to'. What's the difference
 between message['to'] and message.get('to')?

message['to'] looks up the key 'to', raising an exception if it doesn't 
exist. message.get('to') looks up the key and returns a default value if 
it doesn't exist.

See help(message.get) for more detail.


 2. Why can't I call the get_payload() method on the message? What I get
 is this cryptic error: AttributeError: Message instance has no
 attribute 'get_payload'. I'm trying to call a method here, not an
 attribute. It makes no difference if I put parentheses after get_payload
 or not. I looked into the email/Message module and found get_payload
 defined there.

All methods are attributes (although the opposite is not the case), so if 
a method doesn't exist, you will get an AttributeError.

The email.Message.Message class has a get_payload, but you're not using 
that class. You're using mailbox.UnixMailbox, which returns an instance 
of rfc822.Message which *doesn't* have a get_payload method.

Damned if I can work out how to actually *use* the email module to read 
an mbox mail box. I might have to RTFM :(

http://docs.python.org/lib/module-email.html
http://docs.python.org/lib/module-mailbox.html


*later*

Ah! The Fine Manual is some help after all. Try this:

# copied from http://docs.python.org/lib/mailbox-deprecated.html
import email
import email.Errors
import mailbox
def msgfactory(fp):
try:
return email.message_from_file(fp)
except email.Errors.MessageParseError:
# Don't return None since that will
# stop the mailbox iterator
return ''

fp = file('mymailbox', 'rb')
mbox = mailbox.UnixMailbox(fp, msgfactory)
for message in mbox:
print message.get_payload()



But note that message.get_payload() will return either a string (for 
single part emails) or a list of Messages (for multi-part messages).


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


Re: Hexadecimal list conversion

2007-12-20 Thread Paul Hankin
On Dec 20, 12:30 pm, Neil Webster [EMAIL PROTECTED] wrote:
 Hi All.

 I have a list which is a line from a file:
 ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
 '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

 This should be in the format:
 ['381475.502599', '213622.174282']

 I've tried a few options using replace (replacing \x00 with ) and
 trying to convert from hexademical to decimal.

 But nothing has worked.  Can anybody give any tips to help?

Is your file utf-16 (that would explain why your file has \x00 in
between every character)? If so, use codecs.open to read it, and you
won't get the \x00's (you'll get a unicode string).

Or you can remove them using replace:

a = a.replace('\x00', '')

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


Re: How to generate pdf file from an html page??

2007-12-20 Thread MonkeeSage
On Dec 19, 10:17 am, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2007-12-19, Terry Jones [EMAIL PROTECTED] wrote:



  Grant == Grant Edwards [EMAIL PROTECTED] writes:
 Grant On 2007-12-19, abhishek [EMAIL PROTECTED] wrote:
   Hi everyone, I am trying to generate a PDF printable format file from
   an html page. Is there a way to do this using python. If yes then
   which library and functions are required and if no then reasons why it
   cant be done.

  Here's one way:

  --html2pdf.py-
  #!/usr/bin/python
  import os,sys

  inputFilename,outputFilename = sys.argv[1:3]

  os.system(w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s % 
  (inputFilename,outputFilename))

  Note that this is highly insecure. outputFilename could be passed e.g., as

/tmp/file.pdf; rm -fr /home/abhishek

 Here's a half-assed solution:

 inputFilename = inputFilename.replace(',)
 outputFilename = outputFilename.replace(',)

 os.system(w3m -dump '%s' | a2ps -B --borders=no | ps2pdf - '%s' % 
 (inputFilename,outputFilename))

 As somebody else suggested, building the pipeline by hand
 using the subprocess module is the most bullet-proof method.

 --
 Grant Edwards   grante Yow! I brought my BOWLING
   at   BALL -- and some DRUGS!!
visi.com

This looks a little better for me ... | a2ps -B --borders=0 --
columns=1 -f 10.0 | ...

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


RE: Hexadecimal list conversion

2007-12-20 Thread Andreas Tawn
 Hi All.
 
 I have a list which is a line from a file:
 ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009
 \x009\x00',
 '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\
 x002\x00']
 
 This should be in the format:
 ['381475.502599', '213622.174282']
 
 I've tried a few options using replace (replacing \x00 with ) and
 trying to convert from hexademical to decimal.
 
 But nothing has worked.  Can anybody give any tips to help?
 
 Thanks.

Somthing like:

line =
['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00'
,
'\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

result = [''.join(x.split('\x00')) for x in line]

Cheers,

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


Re: Hexadecimal list conversion

2007-12-20 Thread Gabriel Genellina
En Thu, 20 Dec 2007 09:30:14 -0300, Neil Webster [EMAIL PROTECTED]  
escribi�:

 I have a list which is a line from a file:
 ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
 '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

 This should be in the format:
 ['381475.502599', '213622.174282']

 I've tried a few options using replace (replacing \x00 with ) and
 trying to convert from hexademical to decimal.

The replace works:

py for item in L:
...   print item.replace('\x00','')
...
381475.502599
213622.174282

If you got that from a file, I bet you read it using the wrong encoding.  
Try opening the file using codecs.open(filename, rb,  
encoding=utf-16-be) instead of plain open. When your read it, you'll get  
unicode objects instead of strings, but with the right contents. If you  
wish you can convert to strings using  
line_read.encode(your_system_encoding); if all your data is numeric the  
encoding used is irrelevant and can be omited.

-- 
Gabriel Genellina

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

Re: New to Python Would like debug advice

2007-12-20 Thread Nir
On Dec 17, 9:17 pm, PatrickMinnesota [EMAIL PROTECTED]
wrote:
 Yep, I'm new to the language, it's been a couple of months.

 I opted for gvim and console window for developing on a Windows XP
 box.  I'm not a huge fan of IDEs except for when I need some
 debugging.  I've done my googling and see a bunch of options out there
 for a debugging solution for Python on Windows.

 I've used Eclipse for a few years for Java development and I
 understand there is a Python module for it that might make sense.

 What I'm looking for is advice on what to use todebuggeneral Python
 programs at the source level, some will be graphical.  If the eclipse
 route is the way to go, that's fine, but I'm wondering what other
 options people have good luck with.  Keep in mind I will probably
 continue to use Vi/Emacs and a console window for my main development.

 Thanks.

Try Winpdb (On Linux as well).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-12-20 Thread Nick Craig-Wood
Hendrik van Rooyen [EMAIL PROTECTED] wrote:
  Nick Craig-Wood nic...od.com wrote:
  So you might see longs returned when you expected ints if the result
  was = 0x800.
 
  did you mean 0x8000 ?
 
  ;-)

Yes - well spotted!
-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pypi and easy_install

2007-12-20 Thread Giampaolo Rodola'
On 20 Dic, 04:33, Giampaolo Rodola' [EMAIL PROTECTED] wrote:
 On 20 Dic, 03:47, Istvan Albert [EMAIL PROTECTED] wrote:

  On Dec 19, 9:44 pm, Istvan Albert [EMAIL PROTECTED] wrote:

   On Dec 19, 8:07 pm, Giampaolo Rodola' [EMAIL PROTECTED] wrote:
download_url = 'http://code.google.com/p/pyftpdlib/downloads/list',

  this is from looking at your setup.py here:

 http://pyftpdlib.googlecode.com/svn/trunk/setup.py

 You're right, the setup.py included in the tarball reports an invalid
 download url.
 I fixed the issue in setup.py and used setup.py register for
 uploading the new package on pypi again.
 As you can see from 
 here:http://pypi.python.org/pypi?name=pyftpdlibversion=0.2.0:action=disp...
 ...now the download url is correct, but the problem still remains. :-\

Found the culprit.
That's because my download URL points to
http://pyftpdlib.googlecode.com/files/pyftpdlib_0.2.0.tar.gz, which
is not a valid distutils-generated filename.
A valid filename for pytftpdblib would be pyftpdlib-0.2.0.tar.gz.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about email-handling modules

2007-12-20 Thread tinnews
Steven D'Aprano [EMAIL PROTECTED] wrote:
 On Thu, 20 Dec 2007 09:31:10 +, Robert Latest wrote:
 
[snip most of question and helpful answer]
 
 But note that message.get_payload() will return either a string (for 
 single part emails) or a list of Messages (for multi-part messages).
 
Note also that the mailbox module in python 2.5 is quite unlike the
mailbox module in python 2.4 so code written for the 2.4 mailbox will
be most unlikely to work under 2.5 without at least some changes.

At least that's my experience/understanding.

Also, from the way things currently work in the 2.5 version I think
there will (hopefully) be some more quite significant changes.

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


Re: help displaying pdf thru client/server

2007-12-20 Thread PaulS

PaulS [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Connecting to a Linux server from XP pc using a telnet program, I run a 
 report and convert it to a pdf document(using Reportlab) which I need to 
 display.  The pdf is on the Linux server. Ideas how to display to the pc 
 would be appreciated. thanks, paul

Thanks for the suggestions.  I'll look at twisted first.
paul 


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


Re: .NET and Python Integration Problem and PDF Library (Need Help and Suggestions)

2007-12-20 Thread [EMAIL PROTECTED]
On Dec 18, 7:34 am, Ravi Kumar [EMAIL PROTECTED] wrote:
 Hi.
 First I am explaining the Problem so it would not get messed up. :)

 == PROBLEM 
 I have to integrate a small part in .NET Projects. .NET project is
 actually all Web-based application, user interface is Web-page for
 multiple actions.
 But a backend component of project needs PDF File manipulation.
 Manipuation is limited to splitting pages, removing certain pages,
 joining pages, finding certain text information (Title/Author/No. of
 Pages/Orientation of each page etc), and page orientation maipulation
 (rotating pages clockwise and anticlockwise, on degree parameter,
 left/right/flip etc).
 .NET guys are failing here, so I proposed to do that component in Python.
 But problem is, how to integrate Python in .NET Web Application. I am
 looking on IRONPYTHON, and thats the only point seemed to me. Also, as
 I am not an expert in Python, I have transition from Perl and PHP to
 python. So right now, my applciation architecture would little bit be
 inexperienced and not enterprise ready. But every component in project
 is being worked on Enterprise grade.
 Now,
 I want to integrate Python implementation for PDF works, and that
 would be called from .NET (C#) processes supplying required
 parameters. Since the whole application would be implemented on MS
 Windows Server, so I am bit lacking the freedom of library usage as in
 Linux.

 Also looking for best PDF library which doesn't have any or many
 dependencies and that dependencies can be successfully installed. I
 will also need an XML Library to write down the logs and
 instructions+information for next component which handles Printing.

 =

 Therefore, I am seeking all the precious (even small or one-liner)
 advices from you. Please suggest me every possible things that come in
 your mind. Things on high priorities right now are:

 --
 -=Ravi=-

This isn't a python reply, but for .NET PDF manipulation, you might
look at http://www.pdfbox.org/userguide/dot_net.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about email-handling modules

2007-12-20 Thread Robert Latest
Steven D'Aprano wrote:

 message['to'] looks up the key 'to', raising an exception if it doesn't 
 exist. message.get('to') looks up the key and returns a default value if 
 it doesn't exist.

Ah, so the [] notation got hung up on some message right at the beginning 
and didn't even let the script continue. Makes sense.

 All methods are attributes (although the opposite is not the case), so if 
 a method doesn't exist, you will get an AttributeError.

I see. I've already gathered that Python likes to use different words for 
common things (attribute instead of member or method).

 Damned if I can work out how to actually *use* the email module to read 
 an mbox mail box. I might have to RTFM :(

Yeah, I think I haven't picked the right module to get started with.

 But note that message.get_payload() will return either a string (for 
 single part emails) or a list of Messages (for multi-part messages).

Yes, I did note that.

Thanks for the tips (also to the others who have answered).

Python looks like fun though. Maybe I should try to tackle some other 
problem first.

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


Re: Where best to put local modules?

2007-12-20 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] a écrit :
 I'm just beginning to create some python modules for my own use and
 I'm wondering where to put them.  Initially I have put them in
 $HOME/bin and I have set PYTHONPATH to point to them there.  It all
 seems to be OK but I was wondering if I might be storing up problems
 for the future by putting python modules in with my odds and sods of
 shell scripts etc. (and with my python 'main' scripts).

 Would I be better off putting the modules somewhere else, e.g.
 somewhere like $HOME/lib/python?

 If you're on a shared system and don't have admin access, this last 
 solution is probably the best - pure modules have nothing to do in a 
 bin/ directory indeed. Now if it's your own computer, why not just put 
 them in /path/to/python/libs/site-packages ?
 
 There's one of each, a system where I have a shell account but not
 root access  and my home system.

 There is a disadvantage of putting stuff in the site-packages directory
 isn't there? If/when I upgrade the system the python modules I have added
 will effectively not be visible to the upgraded system.  I know I can
 copy them across to the new site-packages but it's just one more chore
 when upgrading.  If they were in $HOME/lib/python this issue wouldn't
 arise because /home stays the same across upgrades.
 

Yes, true. OTHO, storing modules in your own $HOME/whatever and 
modifying your $PYTHONPATH accordingly won't make the modules available 
to other accounts. Which may or not be a problem (it happened to be one 
for me...).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging pipe IPC

2007-12-20 Thread Jim B. Wilson
Ian Clark wrote:

  import os
  os.system(netcat -l -p 1234 localhost)
 
  HTH,

Nope, but the network theme got me thinking about how one might run 
Python on a remote host.  After a few false starts, Googling remote 
python shell led me to Guido's ripshell.py (not *that* Guido, a 
different one).  Peeking inside, I discovered the module I'm looking for 
was code.  Remember, in my case, communication on stdin and stdout
was all handled by a Pyrex extension.  I'm unsure the code below will 
work in a pure Python application.

For posterity, here is itest.py, the solution to my problem:

### itest.py - allows interactive debugging of a filter
#
#  If stdin and stdout are dedicated to your filter script, but you
#  want to interactively check a few things, try something like this:

from code import interact
import sys

sys.stdout = open(/dev/tty, w)  # Rebind Python's lips
sys.stdin  = open(/dev/tty, r)  #  and Python's ears.

foo = This is a test  # Lay down some history
interact(   # Convenience function from code.
   At your service, Sir!, #   BUG: could be Madam or Miss
   local = locals())#   Teach interpreter some history
print Thank you, Sir! # BUG: ibid.

To check this works:

$ python itest.py /dev/null /dev/full # mother is a deafmute
At your service, Sir!
  foo
'This is a test'
  ^D (not shown)
Thank you, Sir!
$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clearing text on canvas

2007-12-20 Thread [EMAIL PROTECTED]
thanx a lot Peter
dn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hexadecimal list conversion

2007-12-20 Thread Mark T

Gabriel Genellina [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 En Thu, 20 Dec 2007 09:30:14 -0300, Neil Webster [EMAIL PROTECTED] 
 escribi�:

 I have a list which is a line from a file:
 ['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
 '\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

 This should be in the format:
 ['381475.502599', '213622.174282']

 I've tried a few options using replace (replacing \x00 with ) and
 trying to convert from hexademical to decimal.

 The replace works:

 py for item in L:
 ...   print item.replace('\x00','')
 ...
 381475.502599
 213622.174282

 If you got that from a file, I bet you read it using the wrong encoding. 
 Try opening the file using codecs.open(filename, rb, 
 encoding=utf-16-be) instead of plain open. When your read it, you'll get 
 unicode objects instead of strings, but with the right contents. If you 
 wish you can convert to strings using 
 line_read.encode(your_system_encoding); if all your data is numeric the 
 encoding used is irrelevant and can be omited.

 -- 
 Gabriel Genellina


There is an odd number of bytes in each string.  Each begins and ends with 
\x00, so it doesn't look like utf-16-be.  But replace works:

 L=['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00','\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']
 [s.replace('\x00','') for s in L]
['381475.502599', '213622.174282']

-Mark Tolonen

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

Re: 3D plotting with python 2.5 on win32

2007-12-20 Thread anton
Hi Marek,

thanks for the link .. I knew VPython
already by I forgot it ( the last time it was only
python 2.4 compatible) but as I see
they support python 2.5 now ;-)

I will check it and thanks again.

 Anton

 Hi anton,

Have you take a look at vpython? Here's their 
 website:http://www.vpython.org/
 And here is an simple example of how to use 
 it:http://linuxgazette.net/144/john.html

 Hope this helps :-)

 Cheers,

 Marek

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


where is uno?

2007-12-20 Thread johnf
I'm using SUSE 10.3 have installed OpenOffice Python interface from the
distro DVD.  But still I need help because I can't import uno.  And
that's because it's not in my site-packages.  

I read about how to use it and have reviewed code that uses it but no where
did any of the articles explain where to retrieve the actual 'uno' py
package.

Can someone provide a hint?

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


Re: 3D plotting with python 2.5 on win32

2007-12-20 Thread anton
Hi Jason,

I know ctypes, my problem is not PyOpenGL itself,
but during my tests with different python based 3D tools,
some of them depend on PyOpenGL and since PyOPenGL
is only available for python 2.4  the story ends here.

Sorry I don't actually remember exactly what tool it was,
I tried out (or tried to try out) different tools for
doing 3D plotting, but skipped most of them since I did
not get them to work.
(... yes I am a little bit confused since I didnt find
something working out of the box).

Anton



 PyOpenGL isn't abandonware.  Python 2.5 comes with the ctypes module
 [1], so there isn't any need for a binary wrapper module anymore.

 Under 2.5, all pure wrapper binary modules are unnecessary.  They
 can work cross-platform from pure Python, calling directly into the C
 function code.  Trust me, this is an excellent improvement.

 PyOpenGL probably too low-level for what you want, but it isn't dead
 yet.  (It's just pining for the symbol table.)

   --Jason

 [1]http://docs.python.org/lib/module-ctypes.html

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


Re: Hexadecimal list conversion

2007-12-20 Thread Peter Otten
Mark T wrote:

 Gabriel Genellina [EMAIL PROTECTED] wrote in message 

 If you got that from a file, I bet you read it using the wrong
 encoding. Try opening the file using codecs.open(filename, rb,
 encoding=utf-16-be) instead of plain open. 

 There is an odd number of bytes in each string.  Each begins and ends
 with \x00, so it doesn't look like utf-16-be.  

I think Gabriel is right. The OP probably butchered the original structure
with

open(filename).read().split(\n)

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


Re: How to generate pdf file from an html page??

2007-12-20 Thread Grant Edwards
On 2007-12-20, MonkeeSage [EMAIL PROTECTED] wrote:

 This looks a little better for me ... | a2ps -B --borders=0 --
 columns=1 -f 10.0 | ...

Right. I forgot that I've adjusted my a2ps defaults to using a
single column and a readable font size instead of the standard
2-up tiny-font mode.

-- 
Grant Edwards   grante Yow! When you get your
  at   PH.D. will you get able to
   visi.comwork at BURGER KING?
-- 
http://mail.python.org/mailman/listinfo/python-list


Ping Implementation in Python

2007-12-20 Thread Mrown
Hi,
  I was wondering if there was a ping implementation written in
Python.  I'd rather using a Python module that implements ping in a
platform/OS-independent way than rely on the underlying OS, especially
as every OS has a different implementation.  Furthermore, if you're
going to ping a large number of IPs, using a module would probably be
a lot faster.  Any ideas if such a module exists?  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where is uno?

2007-12-20 Thread Carsten Haese
On Thu, 2007-12-20 at 07:44 -0800, johnf wrote:
 I'm using SUSE 10.3 have installed OpenOffice Python interface from the
 distro DVD.  But still I need help because I can't import uno.  And
 that's because it's not in my site-packages.  
 
 I read about how to use it and have reviewed code that uses it but no where
 did any of the articles explain where to retrieve the actual 'uno' py
 package.
 
 Can someone provide a hint?

Find out where the installation placed the uno.py file. It might be
somewhere in /path/to/openoffice/program. Once you've found the actual
location, set the PYTHONPATH environment variable to that location.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Is there *any* real documentation to PyWin32?

2007-12-20 Thread rurpy
On Dec 20, 6:35 am, Benoit [EMAIL PROTECTED] wrote:
 I understand that the Win32 has been said to be itself poorly
 documented, so perhaps that the documentation that comes with the
 modules is of similar quality is no coincidence.  Maybe I'm still too
 young in my programming to grasp the good of that documentation, but
 for myself, it tells me next to nothing.  Could anyone point me to
 anything which may exist that does a better job of explaining the
 extensions' use?  I tried to take a look @ Microsoft's documentation,
 but it was confusing.

There is Mark Hammond's book [1] about python-win32 though I haven't
used it and don't know if it contains anything that would be helpful
to you.
It is rather old now but some claim that is not important. [2]

Personally I consider Python-win32 to be docware -- software that is
sufficiently difficult to use with the included free documentation
that many people will just buy the $$$ documentation.  Numpy is
another prominent example of docware.  A misappropriation of the good-
will value of legitimate open source software.

[1]http://www.amazon.com/Python-Programming-Win32-Windows-Programmers/
dp/1565926218/ref=sr_1_1?ie=UTF8s=booksqid=1198165983sr=1-1
[2]
http://groups.google.com/group/comp.lang.python/browse_thread/thread/e5a1f274ec411cbe/78b1390a6f6d75b2?hl=enlnk=stq=com+win32+(doc+OR+documentation)+group%3Acomp.lang.python#78b1390a6f6d75b2

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


Re: where is uno?

2007-12-20 Thread Zentrader
It's installed by default with Python 2.5 on Ubuntu.  Actually it is a
link to /usr/share/pycentral/python-uno/site-packages/uno.py so first
do a search for uno.py.  If not found post back.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to memoize/cache property access?

2007-12-20 Thread thebjorn
I seem to be writing the following boilerplate/pattern quite
frequently to avoid hitting the database until absolutely necessary,
and to only do it at most once:

class Foo(object):
@property
def expensive(self):
if not hasattr(self, '_expensiv'):
self._expensive = insert expensive db call here
return self._expensive

it's a bit verbose, and it violates the DRY (Don't Repeat Yourself)
principle -- and it has on at least one occasion resulted in really
slow code that produces the correct results (did you spot the typo
above?).

It would have been nice to be able to write

class Foo(object):
@property
def expensive(self):
self.expensive = insert expensive db call here
return self.expensive

but apparently I can't set [that] attribute :-(

I'm contemplating using a decorator to hide the first pattern:

def memprop(fn):
def _fn(self):  # properties only take self
memname = '_' + fn.__name__
if not hasattr(self, memname):
setattr(self, memname, fn(self))
return getattr(self, memname)
return property(fget=_fn, doc=fn.__doc__)

which means I can very simply write

class Foo(object):
@memprop
def expensive(self):
return insert expensive db call here

I'm a bit hesitant to start planting home-grown memprop-s all over the
code-base though, so I'm wondering... does this seem like a reasonable
thing to do? Am I re-inventing the wheel? Is there a better way to
approach this problem?

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


Re: Where best to put local modules?

2007-12-20 Thread tinnews
Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] a écrit :
  Bruno Desthuilliers [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] a écrit :
  I'm just beginning to create some python modules for my own use and
  I'm wondering where to put them.  Initially I have put them in
  $HOME/bin and I have set PYTHONPATH to point to them there.  It all
  seems to be OK but I was wondering if I might be storing up problems
  for the future by putting python modules in with my odds and sods of
  shell scripts etc. (and with my python 'main' scripts).
 
  Would I be better off putting the modules somewhere else, e.g.
  somewhere like $HOME/lib/python?
 
  If you're on a shared system and don't have admin access, this last 
  solution is probably the best - pure modules have nothing to do in a 
  bin/ directory indeed. Now if it's your own computer, why not just put 
  them in /path/to/python/libs/site-packages ?
  
  There's one of each, a system where I have a shell account but not
  root access  and my home system.
 
  There is a disadvantage of putting stuff in the site-packages directory
  isn't there? If/when I upgrade the system the python modules I have added
  will effectively not be visible to the upgraded system.  I know I can
  copy them across to the new site-packages but it's just one more chore
  when upgrading.  If they were in $HOME/lib/python this issue wouldn't
  arise because /home stays the same across upgrades.
  
 Yes, true. OTHO, storing modules in your own $HOME/whatever and 
 modifying your $PYTHONPATH accordingly won't make the modules available 
 to other accounts. Which may or not be a problem (it happened to be one 
 for me...).

Probably not for me.  OK, thanks for all the responses, it seems there
isn't anything of huge consequence that I'm missing so I can just
decide what fits my situation best.

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


Re: Ping Implementation in Python

2007-12-20 Thread Chris Mellon
On Dec 20, 2007 9:41 AM, Mrown [EMAIL PROTECTED] wrote:
 Hi,
   I was wondering if there was a ping implementation written in
 Python.  I'd rather using a Python module that implements ping in a
 platform/OS-independent way than rely on the underlying OS, especially
 as every OS has a different implementation.  Furthermore, if you're
 going to ping a large number of IPs, using a module would probably be
 a lot faster.  Any ideas if such a module exists?  Thanks.


There's no point in having a script that pings things, especially
large numbers of IPs. If you really want to do network scanning other
tools for that already exist.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3D plotting with python 2.5 on win32

2007-12-20 Thread Jason
On Dec 20, 8:48 am, anton [EMAIL PROTECTED] wrote:
 Hi Jason,

 I know ctypes, my problem is not PyOpenGL itself,
 but during my tests with different python based 3D tools,
 some of them depend on PyOpenGL and since PyOPenGL
 is only available for python 2.4  the story ends here.

 Sorry I don't actually remember exactly what tool it was,
 I tried out (or tried to try out) different tools for
 doing 3D plotting, but skipped most of them since I did
 not get them to work.
 (... yes I am a little bit confused since I didnt find
 something working out of the box).

 Anton



  PyOpenGL isn't abandonware.  Python 2.5 comes with the ctypes module
  [1], so there isn't any need for a binary wrapper module anymore.

  Under 2.5, all pure wrapper binary modules are unnecessary.  They
  can work cross-platform from pure Python, calling directly into the C
  function code.  Trust me, this is an excellent improvement.

  PyOpenGL probably too low-level for what you want, but it isn't dead
  yet.  (It's just pining for the symbol table.)

--Jason

  [1]http://docs.python.org/lib/module-ctypes.html

That's just it: PyOpenGL is available for Python 2.5.  Go to http://
pyopengl.sourceforge.net/ctypes/using.html for information about
getting and installing it.

Obviously, I don't know what problems are with the tools you tried.
There may be backward-compatibility problems that I haven't
encountered with PyOpenGL on Python 2.5.

I do hope this helps you, even if only a little bit.

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


Re: Where best to put local modules?

2007-12-20 Thread Zentrader
Wherever it is physically located, I would suggest linking the dir to /
usr/lib/python/site-python (on a Linux system).  AFAIK the sole
purpose of this dir is for the type of thing you are describing.  On
my system it also gets copied when Python is updated.  What
permissions you give the dir is up to you.  Also, you probably want it
somewhere that gets backed up routinely or you may loose your latest
and greatest version if there is a crash, etc..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to memoize/cache property access?

2007-12-20 Thread Duncan Booth
thebjorn [EMAIL PROTECTED] wrote:

 It would have been nice to be able to write
 
 class Foo(object):
 @property
 def expensive(self):
 self.expensive = insert expensive db call here
 return self.expensive
 
 but apparently I can't set [that] attribute :-(

You can set and access it directly in __dict__. How about something along 
these lines:

def cachedproperty(f):
name = f.__name__
def getter(self):
try:
return self.__dict__[name]
except KeyError:
res = self.__dict__[name] = f(self)
return res
return property(getter)

class Foo(object):
@cachedproperty
def expensive(self):
print expensive called
return 42

 f = Foo()
 f.expensive
expensive called
42
 f.expensive
42

It is still calling the getter every time though, so not as fast as a plain 
attribute lookup.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a simple way to parse this string ?

2007-12-20 Thread George Sakkis
On Dec 19, 8:44 pm, Paul McGuire [EMAIL PROTECTED] wrote:

 I think the last thread of this nature also cited a similar tool by
 the effbot, which he describes 
 here:http://www.effbot.org/zone/simple-iterator-parser.htm.
 This parser is about 10X faster than the equivalent pyparsing parser.

Here's the relevant thread: http://preview.tinyurl.com/2aeswn. Note
that the builtin eval() is around 5x faster than this parser, and from
the statement above, 50x faster than the pyparsing solution.

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


Re: How to memoize/cache property access?

2007-12-20 Thread Michele Simionato
On Dec 20, 5:02 pm, thebjorn [EMAIL PROTECTED]
wrote:
 I seem to be writing the following boilerplate/pattern quite
 frequently to avoid hitting the database until absolutely necessary ...

I use the following module:

$ cat cache.py
class cached(property):
'Convert a method into a cached attribute'
def __init__(self, method):
private = '_' + method.__name__
def fget(s):
try:
return getattr(s, private)
except AttributeError:
value = method(s)
setattr(s, private, value)
return value
def fdel(s):
del s.__dict__[private]
super(cached, self).__init__(fget, fdel=fdel)
@staticmethod
def reset(self):
cls = self.__class__
for name in dir(cls):
attr = getattr(cls, name)
if isinstance(attr, cached):
delattr(self, name)

if __name__ == '__main__': # a simple test
import itertools
counter = itertools.count()
class Test(object):
@cached
def foo(self):
return counter.next()
reset = cached.reset

p = Test()
print p.foo
print p.foo
p.reset()
print p.foo
print p.foo
p.reset()
print p.foo

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


Re: Ping Implementation in Python

2007-12-20 Thread Mrown
On Dec 20, 6:13 pm, Chris Mellon [EMAIL PROTECTED] wrote:
 On Dec 20, 2007 9:41 AM, Mrown [EMAIL PROTECTED] wrote:

  Hi,
I was wondering if there was a ping implementation written in
  Python.  I'd rather using a Python module that implements ping in a
  platform/OS-independent way than rely on the underlying OS, especially
  as every OS has a different implementation.  Furthermore, if you're
  going to ping a large number of IPs, using a module would probably be
  a lot faster.  Any ideas if such a module exists?  Thanks.

 There's no point in having a script that pings things, especially
 large numbers of IPs. If you really want to do network scanning other
 tools for that already exist.

Thanks.  Actually, I was more interested in the OS neutral part than
in pinging a large number of IPs.  Instead, I want to ping a number of
IPs (under 10) in an OS/platform independent manner and take the
necessary action depending on the results.  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ping Implementation in Python

2007-12-20 Thread Lorenzo Mainardi
Nel mezzo del cammin di nostra vita, mi ritrovai con Mrown che diceva:

 Hi,
   I was wondering if there was a ping implementation written in
 Python.  I'd rather using a Python module that implements ping in a
 platform/OS-independent way than rely on the underlying OS, especially
 as every OS has a different implementation.  Furthermore, if you're
 going to ping a large number of IPs, using a module would probably be a
 lot faster.  Any ideas if such a module exists?  Thanks.


Get Scapy, it's one of the best tool for this kind of problem, and it's 
Python based

-- 
Le opinioni dei fanatici prescindono dai fatti
python -c print 'bG9ybWF5bmFAZ21haWwuY29t'.decode('base64')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there *any* real documentation to PyWin32?

2007-12-20 Thread kyosohma
On Dec 20, 9:57 am, [EMAIL PROTECTED] wrote:
 On Dec 20, 6:35 am, Benoit [EMAIL PROTECTED] wrote:

  I understand that the Win32 has been said to be itself poorly
  documented, so perhaps that the documentation that comes with the
  modules is of similar quality is no coincidence.  Maybe I'm still too
  young in my programming to grasp the good of that documentation, but
  for myself, it tells me next to nothing.  Could anyone point me to
  anything which may exist that does a better job of explaining the
  extensions' use?  I tried to take a look @ Microsoft's documentation,
  but it was confusing.

 There is Mark Hammond's book [1] about python-win32 though I haven't
 used it and don't know if it contains anything that would be helpful
 to you.
 It is rather old now but some claim that is not important. [2]

 Personally I consider Python-win32 to be docware -- software that is
 sufficiently difficult to use with the included free documentation
 that many people will just buy the $$$ documentation.  Numpy is
 another prominent example of docware.  A misappropriation of the good-
 will value of legitimate open source software.

 [1]http://www.amazon.com/Python-Programming-Win32-Windows-Programmers/
 dp/1565926218/ref=sr_1_1?ie=UTF8s=booksqid=1198165983sr=1-1
 [2]http://groups.google.com/group/comp.lang.python/browse_thread/thread/...

The book of which you speak is still relevant since the Microsoft's
API hasn't changed much. Everything I've tried of their examples has
worked. Unfortunately, it is kind of expensive.

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


Amusement - rotational palindrome generator

2007-12-20 Thread Paul McGuire
Here is some semi-obfuscated Python, to generate rotational
palindromes:

from random import choice

base = sznuoxpqbdMWOINZXSH
rot = dict(zip(base,szunoxdbqpWMOINZXSH))

for i in range(40):
s1 = [choice(base) for j in range(choice((2,3,4)))]
start = (1,2)[rot[s1[-1]]==s1[-1] and choice((True,False))]
s2 = [rot[c] for c in s1[-start::-1]]
print .join(s1+s2)


Enjoy!

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


Re: How to memoize/cache property access?

2007-12-20 Thread thebjorn
On Dec 20, 5:43 pm, Michele Simionato [EMAIL PROTECTED]
wrote:
 On Dec 20, 5:02 pm, thebjorn [EMAIL PROTECTED]
 wrote:

  I seem to be writing the following boilerplate/pattern quite
  frequently to avoid hitting the database until absolutely necessary ...

 I use the following module:
[...]

I love it!  much better name too ;-)

I changed your testcase to include a second cached property (the
naming is in honor of my late professor in Optimization of Functional
Languages class: ...any implementation that calls bomb_moscow is per
definition wrong, even if the program produces the correct result...
-- it was a while ago ;-)

if __name__ == '__main__': # a simple test
import itertools
counter = itertools.count()
class Test(object):
@cached
def foo(self):
return counter.next()

@cached
def bomb_moscow(self):
print 'fire missiles'
return counter.next()

reset = cached.reset

it didn't start WWIII, but I had to protect attribute deletion to get
it to run:

def fdel(s):
if private in s.__dict__:
del s.__dict__[private]

I'm a bit ambivalent about the reset functionality. While it's a
wonderful demonstration of a staticmethod, the very few times I've
felt the need to freshen-up the object, I've always felt it was best
to create it again from scratch. Do you have many uses of it in your
code?

-- bjorn

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


Python; jump to a concrete line

2007-12-20 Thread Horacius ReX
Hi, sorry but after looking for information, I still did not get how,
when reading a text file in python, can one jump to a concrete line
and then read the different data (separated by spaces). In each line
there is different number of columns so sometimes i get kind of index
out error. Is there a better way to read the different data on each
row and avoiding to know the exact number of columns ?

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


Re: How to memoize/cache property access?

2007-12-20 Thread Michele Simionato
On Dec 20, 6:40 pm, thebjorn
 I'm a bit ambivalent about the reset functionality. While it's a
 wonderful demonstration of a staticmethod, the very few times I've
 felt the need to freshen-up the object, I've always felt it was best
 to create it again from scratch. Do you have many uses of it in your
 code?

My use case is for web applications where the configuration
parameters are stored in a database. If you change them,
you can re-read them by resetting the configuration object
(you may have a reset button in the administrator Web user
interface) without restarting the application.

 Michele Simionato

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


Re: Python; jump to a concrete line

2007-12-20 Thread Chris
On Dec 20, 7:56 pm, Horacius ReX [EMAIL PROTECTED] wrote:
 Hi, sorry but after looking for information, I still did not get how,
 when reading a text file in python, can one jump to a concrete line
 and then read the different data (separated by spaces). In each line
 there is different number of columns so sometimes i get kind of index
 out error. Is there a better way to read the different data on each
 row and avoiding to know the exact number of columns ?

 Thanks

If you are working with a file that is of a fixed length you can use
the .seek() function
ie. 500 characters per line, and a newline character is an additional
one then for the 10th line you would do:

file_input.seek(5010, 0)
file_input.readline()

If it is not a fixed length file you can do:

line_to_seek = 9 # for the 10th line, you need to look for num9 as
counting starts @ 0
for (i, line) in enumerate(file_input):
if i == line_to_seek:
 process the line

As for combatting the issue of lack of data on a line, do something
like:

line_contents = line.split(' ')
if len( line_contents ) = required_elements:
 do something
else:
 print 'failed'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3D plotting with python 2.5 on win32

2007-12-20 Thread Peter Wang
On Dec 19, 8:15 am, anton [EMAIL PROTECTED] wrote:
 Hi,

 I would like to know if some of you knows a
  - working
  - actual
  - out of the box (for me: binaries available)
 Package/Lib to do 3D plotting out of the box.
 There is MayaVi from enthon but you need to use their python (2.4.3),
 all other stuff need picking sources etc.

Hi Anton,

You actually don't need to use the enthon installer (and definitely
not the 2.4.3-based one) in order to get MayaVi.  You will need to
have setuptools installed.  Then, you should run:

easy_install -f http://code.enthought.com/enstaller/eggs/windows/xp
VTK enthought.mayavi[nonets]

It's important to include [nonets] so that you will get scipy and
numpy as well.

Here are some links for getting started with MayaVI:
Mayavi Cookbook: http://scipy.org/Cookbook/MayaVi
MLab: http://www.scipy.org/Cookbook/MayaVi/mlab

From your posts it sounds like you really want to use something like
MLab.


On a side note, we are almost done putting together an updated one-
click installer of python + packages for scientific computing.  This
will be based on Python 2.5, will include most of what was included in
the 2.4.3-based installer, and will be available for multiple
platforms.


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


xml-filter with XMLFilterBase() and XMLGenerator() shuffles attributes

2007-12-20 Thread Dmitry Teslenko
Hello!
I've made a trivial xml filter to modify some attributes on-the-fly:

...
from __future__ import with_statement
import os
import sys

from xml import sax
from xml.sax import saxutils

class ReIdFilter(saxutils.XMLFilterBase):
def __init__(self, upstream, downstream):
saxutils.XMLFilterBase.__init__(self, upstream)

self.__downstream = downstream
return

def startElement(self, name, attrs):
self.__downstream.startElement(name, attrs)
return

def startElementNS(self, name, qname, attrs):
self.__downstream.startElementNS(name, qname, attrs)
return

def endElement(self, name):
self.__downstream.endElement(name)
return

def endElementNS(self, name, qname):
self.__downstream.endElementNS(name, qname)
return

def processingInstruction(self, target, body):
self.__downstream.processingInstruction(target, body)
return

def comment(self, body):
self.__downstream.comment(body)
return

def characters(self, text):
self.__downstream.characters(text)
return

def ignorableWhitespace(self, ws):
self.__downstream.ignorableWhitespace(ws)
return

...
with open(some_file_path, 'w') as f:
parser = sax.make_parser()
downstream_handler = saxutils.XMLGenerator(f, 'cp1251')
filter_handler = ReIdFilter(parser, downstream_handler)
filter_handler.parse(file_path)

I want prevent it from shuffling attributes, i.e. preserve original
file's attribute order. Is there any ContentHandler.features*
responsible for that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python; jump to a concrete line

2007-12-20 Thread Russell Blau
Horacius ReX [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi, sorry but after looking for information, I still did not get how,
 when reading a text file in python, can one jump to a concrete line
 and then read the different data (separated by spaces). In each line
 there is different number of columns so sometimes i get kind of index
 out error. Is there a better way to read the different data on each
 row and avoiding to know the exact number of columns ?

Have you considered using the file.readlines() method?

Russ



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


Re: Problem untaring python2.5

2007-12-20 Thread Florian Diesch
abhishek [EMAIL PROTECTED] wrote:

 Hi everyone , i am not able to untar python 2.5 source code using 
 tar -xvzf  . Is it a problem with my system settings or python 2.5
 itself.

 When i tried to do it it resulted in following errors --

 tar: Skipping to next header
 Python-2.5/Mac/Resources/app/Resources/English.lproj/Documentation/ide/
 new_window_made.gif
 tar: Python-2.5/Mac/Resources/app/Resources/English.lproj/
 Documentation/ide/new_window_made.gif: Cannot open: No such file or
 directory

tar can't write the unpacked files because the directory they belong to
doesn't exist. Most likely that's because tar can't create the
directory either.

Do you have write permission for the directory where you want to unpack
to? Can you create the directory Python-2.5 by hand (mkdir Python-2.5)?




   Florian
-- 
http://www.florian-diesch.de/
---
**  Hi! I'm a signature virus! Copy me into your signature, please!  **
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pydoc - how to generate documentation for an entire package?

2007-12-20 Thread Florian Diesch
kirillrd [EMAIL PROTECTED] wrote:

 On Nov 20, 4:28 pm, Jens [EMAIL PROTECTED] wrote:
 On 20 Nov., 08:19, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

  On Mon, 19 Nov 2007 10:50:28 -0800, Jens wrote:
   Generating documentation form code is a nice thing, but this pydoc.py
   is driving me insane - isn't there are better way?

  Epydoc!?

  Ciao,
  Marc 'BlackJack' Rintsch

 Thanks! Epydoc looks promising - shame about the user interface
 though :-(

 There is also happydoc , much less features , but still nice :-)

I like apydia http://apydia.ematia.de/


   Florian
-- 
http://www.florian-diesch.de/
---
**  Hi! I'm a signature virus! Copy me into your signature, please!  **
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Passing by reference

2007-12-20 Thread MartinRinehart
Is the following correct?

x = some string

x is a reference to some string

foo(x)

Reference is passed to function.

In foo:
x +=  change

Strings are immutable, so x in foo() now points to a different string
than x outside foo().
Right?

Back outside foo.

x = [some string]

x is a reference to a list whose first element is a reference to a
string.

foo(x)

Within foo:

x[0] +=  other

Another string is created, the first element of x is modified to point
to the new string and back outside foo(), x[0] will point to the new
string.

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


How to make this Python code print blocks of text?

2007-12-20 Thread chriswilliams


This code prints output in rows like this:
**
**
**
How to make print in blocks like this?
* * **
* * **
* * *

start= int (raw_input(StartTable?))
upperlimit= int (raw_input (FinalTable?))
cycle= start
while cycle = upperlimit:
...table= cycle
...counter= 0
...while counter  10:
..counter= counter + 1
..print table, X, counter, =, counter * table
...cycle= cycle + 1

The program prints multyply tables like this
4 X1 = 4
4 X2 = 8
5 X 1= 5
5 X 2= 10
6 X1= 6
6 X2= 12
etc.


And needs to print like this:
4 X1 = 4.5 X 1= 5.. 6 X 1= 1
4 X2 = 8. 5 x 2=10. 6 X 2= 12

Thanks in advance for any help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python; jump to a concrete line

2007-12-20 Thread Chris
On Dec 20, 8:13 pm, Russell Blau [EMAIL PROTECTED] wrote:
 Horacius ReX [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

  Hi, sorry but after looking for information, I still did not get how,
  when reading a text file in python, can one jump to a concrete line
  and then read the different data (separated by spaces). In each line
  there is different number of columns so sometimes i get kind of index
  out error. Is there a better way to read the different data on each
  row and avoiding to know the exact number of columns ?

 Have you considered using the file.readlines() method?

 Russ

.readlines() will hog some resources on large files.
file.read().splitlines()[ line_to_seek ]
might be the fastest way for small files, but also will swell for
larger ones.
Also, one line way to get what you want:
[a for (i,a) in enumerate(input_file) if i == line_to_seek]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make this Python code print blocks of text?

2007-12-20 Thread Chris
On Dec 20, 9:00 pm, chriswilliams [EMAIL PROTECTED] wrote:
 This code prints output in rows like this:
 **
 **
 **
 How to make print in blocks like this?
 * * **
 * * **
 * * *

 start= int (raw_input(StartTable?))
 upperlimit= int (raw_input (FinalTable?))
 cycle= start
 while cycle = upperlimit:
 ...table= cycle
 ...counter= 0
 ...while counter  10:
 ..counter= counter + 1
 ..print table, X, counter, =, counter * table
 ...cycle= cycle + 1

 The program prints multyply tables like this
 4 X1 = 4
 4 X2 = 8
 5 X 1= 5
 5 X 2= 10
 6 X1= 6
 6 X2= 12
 etc.

 And needs to print like this:
 4 X1 = 4.5 X 1= 5.. 6 X 1= 1
 4 X2 = 8. 5 x 2=10. 6 X 2= 12

 Thanks in advance for any help

The reason for it printing on multiple lines is because the print
statement adds a newline character to the end of the existing line.
You can get around this by throwing times table into a list and then
joining them.

for x in xrange(start, (upperlimit+1)):
print '...'.join(['%i X %i = %i'%(x, j, (x*j)) for j in
xrange(1,11)])

Some things to remember, rather use iterators than creating them
yourself with integer variables and incrementing them.  Also the
easier syntax for incrementing counters yourself is 'counter += 1'
instead of the uglier 'counter = counter + 1'.
For the string you are printing, look into string formatting rather
than dumping things like 'print table, X, counter, =, counter *
table' as print '%i X %i = %i' % (table, counter, (table*counter))
is so much neater and easier to comprehend especially if you end up
with a long ass string all muddled together.

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


Re: Ping Implementation in Python

2007-12-20 Thread Roger Miller
On Dec 20, 5:41 am, Mrown [EMAIL PROTECTED] wrote:
 Hi,
   I was wondering if there was a ping implementation written in
 Python.

http://www.gnist.org/~lars/code/ping/ping.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Accessing Visuall C++ DLL with Python

2007-12-20 Thread Murray, John
I recently obtained USB device. Other users of the device apparently use
C or C++ to access it. I am more comfortable with Python and have used
it for other USB devices on a Windows system. I'm more of a hacker than
a programmer especially when it comes to Windows. The manufacturor
supplies xxx.h, xxx.lib and xxx.dll generated using Microsoft Visual
C++. Are all DLLs made equal? Does the manufacturor need to generate a
specific dll for Python?

 

Thanks,

John

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

Re: Python; jump to a concrete line

2007-12-20 Thread Rob Wolfe
Horacius ReX [EMAIL PROTECTED] writes:

 Hi, sorry but after looking for information, I still did not get how,
 when reading a text file in python, can one jump to a concrete line
 and then read the different data (separated by spaces). In each line
 there is different number of columns so sometimes i get kind of index
 out error. Is there a better way to read the different data on each
 row and avoiding to know the exact number of columns ?

Consider using linecache:
http://docs.python.org/lib/module-linecache.html

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


Re: Hexadecimal list conversion

2007-12-20 Thread John Machin
On Dec 21, 2:51 am, Peter Otten [EMAIL PROTECTED] wrote:
 Mark T wrote:
  Gabriel Genellina [EMAIL PROTECTED] wrote in message
  If you got that from a file, I bet you read it using the wrong
  encoding. Try opening the file using codecs.open(filename, rb,
  encoding=utf-16-be) instead of plain open.
  There is an odd number of bytes in each string.  Each begins and ends
  with \x00, so it doesn't look like utf-16-be.

 I think Gabriel is right. The OP probably butchered the original structure
 with

 open(filename).read().split(\n)

Or he's read the file normally and then done
line = lineZAP
where ZAP is one of [:-1], .rstrip(), .rstrip(\n), etc

However that accounts only for the rightmost trailing \x00. Looks like
each line has been chainsawed with .split(,) or whatever the
original field separator was.

If Gabriel's instructions don't work for the OP, the OP should show
us an unambiguous representation of the first few bytes of the
original file, instead of leaving it to guesswork:

print repr(open(the_file, rb).read()[:200])
-- 
http://mail.python.org/mailman/listinfo/python-list


readlines() reading incorrect number of lines?

2007-12-20 Thread Wojciech Gryc
Hi,

I'm currently using Python to deal with a fairly large text file (800
MB), which I know has about 85,000 lines of text. I can confirm this
because (1) I built the file myself, and (2) running a basic Java
program to count lines yields a number in that range.

However, when I use Python's various methods -- readline(),
readlines(), or xreadlines() and loop through the lines of the file,
the line program exits at 16,000 lines. No error output or anything --
it seems the end of the loop was reached, and the code was executed
successfully.

I'm baffled and confused, and would be grateful for any advice as to
what I'm doing wrong, or why this may be happening.

Thank you,
Wojciech Gryc
-- 
http://mail.python.org/mailman/listinfo/python-list


Regex Matching on Readline()

2007-12-20 Thread jwwest
Anyone have any trouble pattern matching on lines returned by
readline? Here's an example:

string = Accounting - General
pat = .+\s-

Should match on Accounting -. However, if I read that string in from
a file it will not match. In fact, I can't get anything to match
except .*.

I'm almost certain that it has something to do with the characters
that python returns from readline(). If I have this in a file:

Accounting - General

And do a:

line = f.readline()
print line

I get:

A c c o u n t i n g  -  G e n e r a l

Not sure why, I'm a nub at Python so any help is appreciated. They
look like spaces to me, but aren't (I've tried matching on spacs too)


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


Re: Passing by reference

2007-12-20 Thread Ben Finney
[EMAIL PROTECTED] writes:

 Is the following correct?
 
 [lots of references to references]

All good so far.

 x[0] +=  other
 
 Another string is created, the first element of x is modified to point
 to the new string and back outside foo(), x[0] will point to the new
 string.

Change these to talk about references again and it'll be true also:

Another string is created, the first element of x now refers to
the new string and back outside foo(), x is still a reference to
the same list (so its first element is a reference to the same
string).

 Right?

Right. In Python, all names, and all elements of container objects,
are references to the corresponding objects. Python has no concept of
pointers in the style of C-like languages.

-- 
 \I fly Air Bizarre. You buy a combination one-way round-trip |
  `\ticket. Leave any Monday, and they bring you back the previous |
_o__)  Friday. That way you still have the weekend.  -- Steven Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing by reference

2007-12-20 Thread John Machin
On Dec 21, 5:57 am, [EMAIL PROTECTED] wrote:
 Is the following correct?

 x = some string

 x is a reference to some string

 foo(x)

 Reference is passed to function.

 In foo:
 x +=  change

 Strings are immutable, so x in foo() now points to a different string
 than x outside foo().
 Right?

 Back outside foo.

 x = [some string]

 x is a reference to a list whose first element is a reference to a
 string.

 foo(x)

 Within foo:

 x[0] +=  other

 Another string is created, the first element of x is modified to point

Somewhat colloquial/abbreviated. x is a reference. It does not have
elements. You mean ... the first element of the list to which x
refers is modified 

 to the new string and back outside foo(), x[0] will point to the new
 string.

 Right?

Close enough.

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


Re: Regex Matching on Readline()

2007-12-20 Thread John Machin
On Dec 21, 6:50 am, jwwest [EMAIL PROTECTED] wrote:
 Anyone have any trouble pattern matching on lines returned by
 readline? Here's an example:

 string = Accounting - General
 pat = .+\s-

 Should match on Accounting -. However, if I read that string in from
 a file it will not match. In fact, I can't get anything to match
 except .*.

 I'm almost certain that it has something to do with the characters
 that python returns from readline(). If I have this in a file:

 Accounting - General

 And do a:

 line = f.readline()
 print line

 I get:

 A c c o u n t i n g  -  G e n e r a l

 Not sure why, I'm a nub at Python so any help is appreciated. They
 look like spaces to me, but aren't (I've tried matching on spacs too)

 - james

To find out what the pseudo-spaces are, do this:

print repr(open(the_file, rb).read()[:100])

and show us (copy/paste) what you get.

Also, tell us what platform you are running Python on, and how the
file was created (by what software, on what platform).

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


Re: Regex Matching on Readline()

2007-12-20 Thread jwwest
On Dec 20, 2:13 pm, John Machin [EMAIL PROTECTED] wrote:
 On Dec 21, 6:50 am, jwwest [EMAIL PROTECTED] wrote:



  Anyone have any trouble pattern matching on lines returned by
  readline? Here's an example:

  string = Accounting - General
  pat = .+\s-

  Should match on Accounting -. However, if I read that string in from
  a file it will not match. In fact, I can't get anything to match
  except .*.

  I'm almost certain that it has something to do with the characters
  that python returns from readline(). If I have this in a file:

  Accounting - General

  And do a:

  line = f.readline()
  print line

  I get:

  A c c o u n t i n g  -  G e n e r a l

  Not sure why, I'm a nub at Python so any help is appreciated. They
  look like spaces to me, but aren't (I've tried matching on spacs too)

  - james

 To find out what the pseudo-spaces are, do this:

 print repr(open(the_file, rb).read()[:100])

 and show us (copy/paste) what you get.

 Also, tell us what platform you are running Python on, and how the
 file was created (by what software, on what platform).

Here's my output:
'A\x00c\x00c\x00o\x00u\x00n\x00t\x00i\x00n\x00g\x00 \x00-\x00 \x00G
\x00e\x00n\x00e\x00r\x00a\x00l\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00
\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00
\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00'

I'm running Python on Windows. The file was initially created as
output from SQL Management Studio. I've re-saved it using TextPad
which tells me it's Unicode and PC formatted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml-filter with XMLFilterBase() and XMLGenerator() shuffles attributes

2007-12-20 Thread infidel
 def startElement(self, name, attrs):
 self.__downstream.startElement(name, attrs)
 return

 I want prevent it from shuffling attributes, i.e. preserve original
 file's attribute order. Is there any ContentHandler.features*
 responsible for that?

I suspect not.  attrs is a dictionary which does not maintain order,
and XML attributes are unordered to begin with.  Is there any reason
other than aesthetics that you want the order preserved?  It shouldn't
matter to any upstream consumer of the filtered XML.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readlines() reading incorrect number of lines?

2007-12-20 Thread John Machin
On Dec 21, 6:48 am, Wojciech Gryc [EMAIL PROTECTED] wrote:
 Hi,

 I'm currently using Python to deal with a fairly large text file (800
 MB), which I know has about 85,000 lines of text. I can confirm this
 because (1) I built the file myself, and (2) running a basic Java
 program to count lines yields a number in that range.

 However, when I use Python's various methods -- readline(),
 readlines(), or xreadlines() and loop through the lines of the file,
 the line program exits at 16,000 lines. No error output or anything --
 it seems the end of the loop was reached, and the code was executed
 successfully.

 I'm baffled and confused, and would be grateful for any advice as to
 what I'm doing wrong, or why this may be happening.

What platform, what version of python?

One possibility: you are running this on Windows and the file contains
Ctrl-Z aka chr(26) aka '\x1a'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Using ctypes with lib not found via ldconfig

2007-12-20 Thread Cylops
I'd like to use ctypes for my Linux app, but the libraries i want to
use it on aren't in a standard location, and can't be found via ldconfig.
They aren't in any of the directories listed in /etc/ld.so.conf, and they
won't be. Our IT dept. controls this, and won't make them normally
accessible for me.

So, how do i steer ctypes towards these libs? Let's say this is one of
them:

/home/me/otherLibs/libgaak.so.6

tia,
eric
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readlines() reading incorrect number of lines?

2007-12-20 Thread Wojciech Gryc
Hi,

Python 2.5, on Windows XP. Actually, I think you may be right about
\x1a -- there's a few lines that definitely have some strange
character sequences, so this would make sense... Would you happen to
know how I can actually fix this (e.g. replace the character)? Since
Python doesn't see the rest of the file, I don't even know how to get
to it to fix the problem... Due to the nature of the data I'm working
with, manual editing is also not an option.

Thanks,
Wojciech

On Dec 20, 3:30 pm, John Machin [EMAIL PROTECTED] wrote:
 On Dec 21, 6:48 am, Wojciech Gryc [EMAIL PROTECTED] wrote:

  Hi,

  I'm currently using Python to deal with a fairly large text file (800
  MB), which I know has about 85,000 lines of text. I can confirm this
  because (1) I built the file myself, and (2) running a basic Java
  program to count lines yields a number in that range.

  However, when I use Python's various methods -- readline(),
  readlines(), or xreadlines() and loop through the lines of the file,
  the line program exits at 16,000 lines. No error output or anything --
  it seems the end of the loop was reached, and the code was executed
  successfully.

  I'm baffled and confused, and would be grateful for any advice as to
  what I'm doing wrong, or why this may be happening.

 What platform, what version of python?

 One possibility: you are running this on Windows and the file contains
 Ctrl-Z aka chr(26) aka '\x1a'.

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


Re: Regex Matching on Readline()

2007-12-20 Thread John Machin
On Dec 21, 7:21 am, jwwest [EMAIL PROTECTED] wrote:
 On Dec 20, 2:13 pm, John Machin [EMAIL PROTECTED] wrote:



  On Dec 21, 6:50 am, jwwest [EMAIL PROTECTED] wrote:

   Anyone have any trouble pattern matching on lines returned by
   readline? Here's an example:

   string = Accounting - General
   pat = .+\s-

   Should match on Accounting -. However, if I read that string in from
   a file it will not match. In fact, I can't get anything to match
   except .*.

   I'm almost certain that it has something to do with the characters
   that python returns from readline(). If I have this in a file:

   Accounting - General

   And do a:

   line = f.readline()
   print line

   I get:

   A c c o u n t i n g  -  G e n e r a l

   Not sure why, I'm a nub at Python so any help is appreciated. They
   look like spaces to me, but aren't (I've tried matching on spacs too)

   - james

  To find out what the pseudo-spaces are, do this:

  print repr(open(the_file, rb).read()[:100])

  and show us (copy/paste) what you get.

  Also, tell us what platform you are running Python on, and how the
  file was created (by what software, on what platform).

 Here's my output:
 'A\x00c\x00c\x00o\x00u\x00n\x00t\x00i\x00n\x00g\x00 \x00-\x00 \x00G
 \x00e\x00n\x00e\x00r\x00a\x00l\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00
 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00
 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00'

 I'm running Python on Windows. The file was initially created as
 output from SQL Management Studio. I've re-saved it using TextPad
 which tells me it's Unicode and PC formatted.

Unicode means utf16.

Try this:

import codecs
f = codecs.open(the_file, r, encoding=utf16le)
for uline in f:
line = uline.encode('cp1252') # or some other encoding if my guess
isn't correct
# proceed as usual

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


Re: Connecting to SQL database

2007-12-20 Thread bill ramsay
On Fri, 14 Dec 2007 23:35:00 -0300, Gabriel Genellina
[EMAIL PROTECTED] wrote:

En Fri, 14 Dec 2007 23:24:24 -0300, Unknown [EMAIL PROTECTED]  
escribió:

 I have successfully connected to SQL2000 and MSDEE databases in the
 past,  however I have to move to SQL2005 and SQLEXPRESS databases now.

 Conn.ConnectionString = Provider=SQLNCLI;Server=10.1.1.2;
 Database=csrctest;Uid=bill;Pwd=bill

Look for the right spelling at http://www.connectionstrings.com/


looks like my spelling is ok,  any other ideas?

thanks for the suggestion above.

kind regards

bill

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


Re: readlines() reading incorrect number of lines?

2007-12-20 Thread John Machin
On Dec 21, 7:41 am, Wojciech Gryc [EMAIL PROTECTED] wrote:
 Hi,

 Python 2.5, on Windows XP. Actually, I think you may be right about
 \x1a -- there's a few lines that definitely have some strange
 character sequences, so this would make sense... Would you happen to
 know how I can actually fix this (e.g. replace the character)? Since
 Python doesn't see the rest of the file, I don't even know how to get
 to it to fix the problem... Due to the nature of the data I'm working
 with, manual editing is also not an option.


Please don't top-post.

Quick hack to remove all occurrences of '\x1a' (untested):

fin = open('old_file', 'rb') # note b BINARY
fout = open('new_file', 'wb')
blksz = 1024 * 1024
while True:
blk = fin.read(blksz)
if not blk: break
fout.write(blk.replace('\x1a', ''))
fout.close()
fin.close()

You may however want to investigate the strange character sequences
that have somehow appeared in your file after you built it
yourself :-)

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


Re: Passing by reference

2007-12-20 Thread MartinRinehart
... the first element of the list to which x refers is a reference to
the new string and back outside foo, the first element of the list to
which x refers will be a reference to the new string.

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


Re: Connecting to SQL database

2007-12-20 Thread kyosohma
On Dec 14, 8:24 pm, bill ramsay [EMAIL PROTECTED] wrote:
 Hi

 I have successfully connected to SQL2000 and MSDEE databases in the
 past,  however I have to move to SQL2005 and SQLEXPRESS databases now.

 I've tried the following but with no luck [this is what i used in the
 earlier incarnation except the Provider resource was SQLOLEDB.1]

 Conn = Dispatch('ADODB.Connection')
 Conn.ConnectionString = Provider=SQLNCLI;Server=10.1.1.2;
 Database=csrctest;Uid=bill;Pwd=bill
 print Conn.ConnectionString

 try:
 print 'trying to open'
 Conn.Open()

 etc.

 All I ever get to is the trying to openline,  then it times out.

 I have tried all of the following combinations too:

 Provider=SQLNCLI;Server=localhost;Database=csrctest;Uid=bill;Pwd=bill;

 Provider=SQLNCLI;Server=localhost\SQLEXPRESS;Database=csrctest;Uid=bill;Pwd=bill;

 The SQLEXPRESS database for testing purposes is on my home PC
 [10.1.1.2]

 Any clues s to where I am going wrong?

 Look forward to hearing from someone,  anyone!!

 Kind regards

 Bill

What Python module are you using? At first I thought you were using
the adodb module for Python, but your syntax doesn't look right for
that one.

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


Re: readlines() reading incorrect number of lines?

2007-12-20 Thread Steven D'Aprano
[Fixing top-posting.]

On Thu, 20 Dec 2007 12:41:44 -0800, Wojciech Gryc wrote:

 On Dec 20, 3:30 pm, John Machin [EMAIL PROTECTED] wrote:
[snip]
  However, when I use Python's various methods -- readline(),
  readlines(), or xreadlines() and loop through the lines of the file,
  the line program exits at 16,000 lines. No error output or anything
  -- it seems the end of the loop was reached, and the code was
  executed successfully.
...
 One possibility: you are running this on Windows and the file contains
 Ctrl-Z aka chr(26) aka '\x1a'.
 
 Hi,
 
 Python 2.5, on Windows XP. Actually, I think you may be right about \x1a
 -- there's a few lines that definitely have some strange character
 sequences, so this would make sense... Would you happen to know how I
 can actually fix this (e.g. replace the character)? Since Python doesn't
 see the rest of the file, I don't even know how to get to it to fix the
 problem... Due to the nature of the data I'm working with, manual
 editing is also not an option.
 
 Thanks,
 Wojciech
 


Open the file in binary mode:

open(filename, 'rb')


and Windows should do no special handling of Ctrl-Z characters.



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


Re: Connecting to SQL database

2007-12-20 Thread kyosohma
On Dec 14, 8:24 pm, bill ramsay [EMAIL PROTECTED] wrote:
 Hi

 I have successfully connected to SQL2000 and MSDEE databases in the
 past,  however I have to move to SQL2005 and SQLEXPRESS databases now.

 I've tried the following but with no luck [this is what i used in the
 earlier incarnation except the Provider resource was SQLOLEDB.1]

 Conn = Dispatch('ADODB.Connection')
 Conn.ConnectionString = Provider=SQLNCLI;Server=10.1.1.2;
 Database=csrctest;Uid=bill;Pwd=bill
 print Conn.ConnectionString

 try:
 print 'trying to open'
 Conn.Open()

 etc.

 All I ever get to is the trying to openline,  then it times out.

 I have tried all of the following combinations too:

 Provider=SQLNCLI;Server=localhost;Database=csrctest;Uid=bill;Pwd=bill;

 Provider=SQLNCLI;Server=localhost\SQLEXPRESS;Database=csrctest;Uid=bill;Pwd=bill;

 The SQLEXPRESS database for testing purposes is on my home PC
 [10.1.1.2]

 Any clues s to where I am going wrong?

 Look forward to hearing from someone,  anyone!!

 Kind regards

 Bill

You might try pymssql:

http://pymssql.sourceforge.net/

I've only used it with MSSQL2000, but according to the website, it
should work with 2005 too.

If you wrapped your database interface with SQLObject or SQLAlchemy,
then (as I understand it) the sql connector module can be swapped out
with little to no work. I hope to move to one of those sooner or
later:

http://www.sqlobject.org/
http://www.sqlalchemy.org/

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


Re: Using ctypes with lib not found via ldconfig

2007-12-20 Thread Jean-Paul Calderone
On 20 Dec 2007 20:36:20 GMT, Cylops [EMAIL PROTECTED] wrote:
I'd like to use ctypes for my Linux app, but the libraries i want to
use it on aren't in a standard location, and can't be found via ldconfig.
They aren't in any of the directories listed in /etc/ld.so.conf, and they
won't be. Our IT dept. controls this, and won't make them normally
accessible for me.

So, how do i steer ctypes towards these libs? Let's say this is one of
them:

/home/me/otherLibs/libgaak.so.6


This generally works by setting the LD_LIBRARY_PATH environment variable.

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


Re: Hexadecimal list conversion

2007-12-20 Thread Gabriel Genellina
En Thu, 20 Dec 2007 12:51:33 -0300, Peter Otten [EMAIL PROTECTED]  
escribió:

 Mark T wrote:

 Gabriel Genellina [EMAIL PROTECTED] wrote in message

 If you got that from a file, I bet you read it using the wrong
 encoding. Try opening the file using codecs.open(filename, rb,
 encoding=utf-16-be) instead of plain open.

 There is an odd number of bytes in each string.  Each begins and ends
 with \x00, so it doesn't look like utf-16-be.

 I think Gabriel is right. The OP probably butchered the original  
 structure
 with

 open(filename).read().split(\n)

Sure! I take bets on this too.

-- 
Gabriel Genellina

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


wxPython FileDialog, select folder

2007-12-20 Thread SMALLp
How can i select folder either with wx.FileDialog or with any other. I 
managed to fine only how to open files but I need to select folder to 
get files from all sub folders.

Thanks in advance!

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


Is this a bug in int()?

2007-12-20 Thread MartinRinehart
int('0x', 16)
0

I'm working on a tokenizer and I'm thinking about returning a
MALFORMED_NUMBER token (1.2E, .5E+)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython FileDialog, select folder

2007-12-20 Thread Chris Mellon
On Dec 20, 2007 3:19 PM, SMALLp [EMAIL PROTECTED] wrote:
 How can i select folder either with wx.FileDialog or with any other. I
 managed to fine only how to open files but I need to select folder to
 get files from all sub folders.



There's a separate dialog, wx.DirDialog.
-- 
http://mail.python.org/mailman/listinfo/python-list


Need to open an Url and display it in a window created using Python win extensions

2007-12-20 Thread shaik_saleem
I'm pretty new to Python and I've been searching all over the place to
find a solution for this.
I have a html page with some javascript in it and I need to load this
page in my own window (which I will create using PythonWin). The
reason for this is to have capability to control the window properties
and at the same time have access to click on the submit buttons in
the webpage.e


So basically, I will open a wepage as shown below -

import win32com.client
import win32api
import win32gui

ie = win32com.client.Dispatch( InternetExplorer.Application )
ie.Visible = 1
ie.Navigate(http://www.microsoft.com/;)

And then I need to display it in a window that I will create as shown
below -
hwnd = CreateWindowEx(...)

I will be so grateful if anyone can give me some pointers on how to go
about this.

Thank you for reading
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using ctypes with lib not found via ldconfig

2007-12-20 Thread Sam
Hello,

May be I misunderstand your problem, but is it not possible do link it
as follow?

import ctypes

libgaak = ctypes.CDLL(/home/me/otherLibs/libgaak.so.6)

Kind regards.

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


Re: Passing by reference

2007-12-20 Thread Michael Sparks
[EMAIL PROTECTED] wrote:

 ... the first element of the list to which x refers is a reference to
 the new string and back outside foo, the first element of the list to
 which x refers will be a reference to the new string.

I'd rephrase that as:
   * Both the global context and the inside of foo see the same list
   * They can therefore both update the list
   * If a new string is put in the first element of the list, the can
 both see the same new string.

 Right?

You know you can get python to answer your question - yes? Might be slightly
more illuminating than twisting round english... :-)

OK, you're passing in a string in a list. You have 2 obvious ways of doing
that - either as an argument:

def foo(y):
y[0] +=  other
print id(y[0])

... or as a global: (which of course you wouldn't do :-)

def bar():
global x
x[0] +=  another
print id(x[0])

So let's see what happens.

 x = [some string]  # create container with string
 x[0]  # Check that looks good  it does
'some string'
 id(x[0])  # What's the id of that string??
3082578144L
 foo(x)# OK, foo thinks the new string has the following id
3082534160
 x[0]  # Yep, our x[0] has updated, as expected.
'some string other'
 id(x[0])  # Not only that the string has the same id.
3082534160L
 bar() # Update the global var, next line is new id
3082543416
 x[0]  # Check the value's updated as expected
'some string other another'
 id(x[0])  # Note that the id is the same as the output from bar
3082543416L

Does that perhaps answer your question more precisely ?


Michael.




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


RE: xml-filter with XMLFilterBase() and XMLGenerator() shuffles attributes

2007-12-20 Thread Brian Smith
  I want prevent it from shuffling attributes, i.e. preserve original 
  file's attribute order. Is there any ContentHandler.features* 
  responsible for that?
 
 I suspect not.  attrs is a dictionary which does not maintain 
 order, and XML attributes are unordered to begin with.  Is 
 there any reason other than aesthetics that you want the 
 order preserved?  It shouldn't matter to any upstream 
 consumer of the filtered XML.

I had the same requirements. I also had the requirement to preserve
namespace prefixes. Luckily, for my application I was able to use the
XML_STRING property to handle my requirements. Otherwise, if you drop
down to using PyExpat (not SAX) then you can do what you want. If you
want to keep using SAX, then you need to use a non-default Python SAX
implementation or use one of the Java SAX parsers that have this option.


BTW, I have never been able to get XMLGenerator to work; it seems really
buggy regarding namespaces. I had to write my own version of it.

- Brian

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


Re: Is this a bug in int()?

2007-12-20 Thread Duncan Booth
[EMAIL PROTECTED] wrote under the subject line Is this a 
bug in int()?:
int('0x', 16)
 0
 
I think it is a general problem in the tokenizer, not just the 'int' 
constructor. The syntax for integers says:

   hexinteger ::= 0 (x | X) hexdigit+ 

but 0x appears to be accepted in source code as an integer.

If I were you, I'd try reporting it as a bug.

 I'm working on a tokenizer and I'm thinking about returning a
 MALFORMED_NUMBER token (1.2E, .5E+)
 
Why would you return a token rather than throwing an exception?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting to SQL database

2007-12-20 Thread thebjorn
On Dec 20, 10:01 pm, bill ramsay [EMAIL PROTECTED] wrote:
 On Fri, 14 Dec 2007 23:35:00 -0300, Gabriel Genellina

 [EMAIL PROTECTED] wrote:
 En Fri, 14 Dec 2007 23:24:24 -0300, Unknown [EMAIL PROTECTED]
 escribió:

  I have successfully connected to SQL2000 and MSDEE databases in the
  past,  however I have to move to SQL2005 and SQLEXPRESS databases now.

  Conn.ConnectionString = Provider=SQLNCLI;Server=10.1.1.2;
  Database=csrctest;Uid=bill;Pwd=bill

 Look for the right spelling athttp://www.connectionstrings.com/

 looks like my spelling is ok,  any other ideas?

 thanks for the suggestion above.

 kind regards

 bill

This is working for me to the internal network (I'm using adodbapi,
but the connection string should be the same)

  'Provider=sqloledb;Data Source=dbserv;Initial Catalog=ndb;User
Id=foo;Password=bar;'

I just tested, and this works well too

  'Provider=SQLNCLI;Data Source=dbserv;Initial Catalog=ndb;User
Id=foo;Password=bar;'

and to my local instance (Hermes is my machine)

  'Provider=SQLNCLI;Data Source=HERMES\\SQLEXPRESS;Initial
Catalog=;User Id=sa;Password=pw666;'

Can you connect to the server using SqlServer Management Studio? Can
you create an odbc connection to the server? Unlike 2000, SqlServer
2005 has tcp/ip connections turned off by default, so you might want
to check that with the SqlServer Surface Area Configuration tool.

Externally we're still running 2000, so I don't know how connecting
over the interweb differs.

When you've figured out how to connect, and if you're open to a
suggestion, you might want to try out the adodbapi package (http://
adodbapi.sourceforge.net/). It is a thin wrapper over ADO, and works
quite well. Then you'll get to use the Python db-api v.2.0 syntax,
which is oodles less typing than straight ADO.

-- bjorn

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


  1   2   3   >