Re: COM and Threads

2006-10-13 Thread Teja

Roger Upole wrote:

 Teja [EMAIL PROTECTED] wrote:
 
  Roger Upole wrote:
 
  Teja [EMAIL PROTECTED] wrote:
  I have an application which uses COM 's Dispatch to create a COM based
   object. Now I need to upgrade the application to a threaded one. But
   its giving an error that COM and threads wont go together. Specifically
   its an attribute error at the point where COM object is invoked. Any
   pointers please??
  
 
  An actual traceback would help.
  At a guess, when using COM in a thread
  you need to call pythoncom.CoInitialize and
  CoUninitialize yourself.
 
   Roger
 
  Actually Roger, this is the scenario
 
  I create a COM object at the beginnning of the main thread. In the sub
  thread, I need to access the same instance of the COM object. If it
  were a normal object ie. not a COM obj, i was able to do it. But if it
  were a COM object, its giving an attribute error? Should I pass a COM
  object to the thread. If so How? Please let me know ASAP... Thnks
 

 To pass COM objects between threads, usually they'll need to be marshaled
 using pythoncom.CoMarshalInterThreadInterfaceInStream, and unmarshaled
 with pythoncom.CoGetInterfaceAndReleaseStream.

  Roger

I really appreciate your quick replyCan u please let me know how to
do marshalling and unmarshalling or any good refrences to do it.
Because i tried to do it. I got some errors ans so I left it...

Thnks again...

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


always raise syntax error!

2006-10-13 Thread daniel
I'm not quite new to this language, but such error has never happened
so frequently before. I have no idea what to do about it, because
there's actually no syntax error at all !!

I'm using python 2.4.3 on windows, with gvim..
I realize this might because of the tab and space, so I use listchars
in vim to all my tabs and trailing spaces visible, make sure they are
used consistently, but python still raise syntax error, no further
description, and just make no sense to me.

anyone heard of such issue or the like before?
many thanks

daniel

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


Re: Starting out.

2006-10-13 Thread [EMAIL PROTECTED]

Richard Jones wrote:
 Tim Chase wrote:
  typed with just the top-row of keys
  '^[qwertyuiop]*$'

 The longest being typewriter :)

Maybe you should say amongst the longest

pepperwort
perpetuity
perruquier
pirouetter
proprietor
repertoire
typewriter

But even that would be wrong.

rupturewort

 
 
 
 hey, look, it's Friday

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


Re: always raise syntax error!

2006-10-13 Thread Steven D'Aprano
On Thu, 12 Oct 2006 23:25:58 -0700, daniel wrote:

 I'm not quite new to this language, but such error has never happened
 so frequently before. I have no idea what to do about it, because
 there's actually no syntax error at all !!

Looking into my crystal ball, I see that you are correct, there is no
syntax error -- because there is no code! There might not even be a
computer. It is all an illusion brought on by lack of fresh air.

Or maybe not -- my crystal ball is notoriously unreliable. 

How about you post the FULL traceback of the error, so we can see for
ourselves if there is a syntax error or not?

e.g.

 x{4} = 5
  File stdin, line 1
x{4} = 5
 ^
SyntaxError: invalid syntax



-- 
Steven 

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


How to print the CDATA of .xml file?

2006-10-13 Thread Kevien Lee
Hi,
 Recently ,I just turn to Python from C#.However ,as a dynamic language .
Python and C# was so different.

Now ,I want to get some record from an XML file,The format of the XML file as follow:
...
Doc rID=T1  DName![CDATA[Release Truck]]/DName Res![CDATA[Res18]]/Res

 DT rID=T2 NodeArgs eType=Table icon=2 nRep=5 filter=False  Disp![CDATA[Run-Time Data]]/Disp
 BtmPane vType=Table Path![CDATA[Default.xls]]/Path /BtmPane /NodeArgs /DT

 NodeArgs eType=StartTest icon=1 nRep=4 status=Failed  Disp![CDATA[Test Release Truck Summary]]/Disp
 /NodeArgs

/Doc


when iuse the minidom to parase the XML file,it would ignored the section of ![CDATA[...]
the code is:

_document=minidom.parse(filePath)
_documnetList=_document.getElementsByTagName(NodeArgs)
for _argNode in _documnetList: 
 print _argNode.nodeValue,_argNode.localName

when it run. The nodeValue of the CDATA Sectionis always None,Is my code error?
and how should i do when i want to get the value of the in the CDATA section?


 

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

Re: Standard Forth versus Python: a case study

2006-10-13 Thread Fredrik Lundh
Gabriel Genellina wrote:

 At Thursday 12/10/2006 17:44, [EMAIL PROTECTED] wrote:
 
fun median {
 var x = 0.
  while( *p++) {
if( (*p)  x) x = *p.
  }
  return x.
}

 clearly, i've forgotten the definition of the median of a list.
 to that i plead faulty memory.
 
 That explains all. Finding the median in an efficient way (that is, 
 without sorting the data first) isn't trivial, so your claim of I can 
 do that using only one temp variable was a bit surprising...
 BTW, the median is the value which sits just in the middle of the list 
 when ordered: median(3,5,12,1,2)=median(1,2,3,5,12) = 3

note that both his proposals does indeed find the median if given a list 
of zeros, though.  maybe they just used lousy sample data in that stat 
class he took?

/F

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


OT: What's up with the starship?

2006-10-13 Thread Thomas Heller
I cannot connect to starship.python.net: neither http, nor can I login 
interactively with ssl (and the host key seems to have changed as well).

Does anyone know more?

Thanks,
Thomas

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


Re: COM and Threads

2006-10-13 Thread Roger Upole

Teja [EMAIL PROTECTED] wrote:

 Roger Upole wrote:

 Teja [EMAIL PROTECTED] wrote:
 
  Roger Upole wrote:
 
  Teja [EMAIL PROTECTED] wrote:
  I have an application which uses COM 's Dispatch to create a COM based
   object. Now I need to upgrade the application to a threaded one. But
   its giving an error that COM and threads wont go together. Specifically
   its an attribute error at the point where COM object is invoked. Any
   pointers please??
  
 
  An actual traceback would help.
  At a guess, when using COM in a thread
  you need to call pythoncom.CoInitialize and
  CoUninitialize yourself.
 
   Roger
 
  Actually Roger, this is the scenario
 
  I create a COM object at the beginnning of the main thread. In the sub
  thread, I need to access the same instance of the COM object. If it
  were a normal object ie. not a COM obj, i was able to do it. But if it
  were a COM object, its giving an attribute error? Should I pass a COM
  object to the thread. If so How? Please let me know ASAP... Thnks
 

 To pass COM objects between threads, usually they'll need to be marshaled
 using pythoncom.CoMarshalInterThreadInterfaceInStream, and unmarshaled
 with pythoncom.CoGetInterfaceAndReleaseStream.

  Roger

 I really appreciate your quick replyCan u please let me know how to
 do marshalling and unmarshalling or any good refrences to do it.
 Because i tried to do it. I got some errors ans so I left it...

 Thnks again...


Here's a simple example using Internet Explorer.

import win32com.client, pythoncom, thread
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1

def nav(istream, dest):
pythoncom.CoInitialize()
d=pythoncom.CoGetInterfaceAndReleaseStream(istream, pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
my_ie.Navigate(dest)
pythoncom.CoUninitialize()

s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,ie)
thread.start_new_thread(nav, (s, 'www.google.com'))

  Roger


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


Python Best Practice References

2006-10-13 Thread Wijaya Edward

Can anybody suggest any references (links, books, etc)about this?
I'm thinking of something similar with D.Conway's Perl Best Practice.
 
-- Edward WIJAYA
SINGAPORE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


File read-write mode: problem appending after reading

2006-10-13 Thread Frederic Rentsch
Hi all,

   Working with read and write operations on a file I stumbled on a 
complication when writes fail following a read to the end.

  f = file ('T:/z', 'r+b')
  f.write ('abcdefg')
  f.tell ()
30L
  f.seek (0)
  f.read ()
'abcdefg'
  f.flush ()  # Calling or not makes no difference
  f.write ('abcdefg')

Traceback (most recent call last):
  File pyshell#62, line 1, in -toplevel-
f.write ('abcdefg')
IOError: (0, 'Error')

Flushing doesn't help. I found two work arounds:

  f.read ()
'abcdefg'
  f.read ()   # Workaround 1: A second read (returning an empty string)
''
  f.write ('abcdefg')
(No error)

  f.read ()
'abcdefg'
  f.seek (f.tell ())   # Workaround 2: Setting the cursor (to where 
it is!)
  f.write ('abcdefg')
(No error)

I found no problem with writing into the file. So it looks like it has 
to do with the cursor which a read puts past the end, unless it is past 
the end, in which case it goes back to the end. Is there a less kludgy 
alternative to fseek (ftell ())?

Frederic

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


Re: Pickling an instance of a class containing a dict doesn't work

2006-10-13 Thread Marco Lierfeld
Peter Otten wrote:

 Chances are you have inadvertently created an /instance/ attribute
 build_steps which was then saved:
 
 s = subproject()
 # ...
 s.configuration[name] = my dinner # modifies the class attribute
 s.build_steps = [hunt, kill, cook] # creates an instance attribute

Yes, now I see. That's the way I filled the dict and the list.

Thank you for the explanation :)

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


Re: Wing IDE 2.1.3 released

2006-10-13 Thread Hendrik van Rooyen
 Wingware Announce [EMAIL PROTECTED] wrote:

8---

 * Professional quality code editor
 * Visual Studio, VI/Vim, Emacs, and Brief key bindings

Can I copy paste columns as in Brief? 
Do the Brief Macros work?
100% ?

- Hendrik

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


Efficiently iterating over part of a list

2006-10-13 Thread Steven D'Aprano
If I want to iterate over part of the list, the normal Python idiom is to
do something like this:

alist = range(50)
# first item is special
x = alist[0]
# iterate over the rest of the list
for item in alist[1:]
x = item

The important thing to notice is that alist[1:] makes a copy. What if the
list has millions of items and duplicating it is expensive? What do people
do in that case?

Are there better or more Pythonic alternatives to this obvious C-like
idiom?

for i in range(1, len(alist)):
x = alist[i]


-- 
Steven D'Aprano 

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


Re: COM and Threads

2006-10-13 Thread Teja

Roger Upole wrote:
 Teja [EMAIL PROTECTED] wrote:
 
  Roger Upole wrote:
 
  Teja [EMAIL PROTECTED] wrote:
  
   Roger Upole wrote:
  
   Teja [EMAIL PROTECTED] wrote:
   I have an application which uses COM 's Dispatch to create a COM based
object. Now I need to upgrade the application to a threaded one. But
its giving an error that COM and threads wont go together. 
Specifically
its an attribute error at the point where COM object is invoked. Any
pointers please??
   
  
   An actual traceback would help.
   At a guess, when using COM in a thread
   you need to call pythoncom.CoInitialize and
   CoUninitialize yourself.
  
Roger
  
   Actually Roger, this is the scenario
  
   I create a COM object at the beginnning of the main thread. In the sub
   thread, I need to access the same instance of the COM object. If it
   were a normal object ie. not a COM obj, i was able to do it. But if it
   were a COM object, its giving an attribute error? Should I pass a COM
   object to the thread. If so How? Please let me know ASAP... Thnks
  
 
  To pass COM objects between threads, usually they'll need to be marshaled
  using pythoncom.CoMarshalInterThreadInterfaceInStream, and unmarshaled
  with pythoncom.CoGetInterfaceAndReleaseStream.
 
   Roger
 
  I really appreciate your quick replyCan u please let me know how to
  do marshalling and unmarshalling or any good refrences to do it.
  Because i tried to do it. I got some errors ans so I left it...
 
  Thnks again...
 

 Here's a simple example using Internet Explorer.

 import win32com.client, pythoncom, thread
 ie=win32com.client.Dispatch('internetexplorer.application')
 ie.Visible=1

 def nav(istream, dest):
 pythoncom.CoInitialize()
 d=pythoncom.CoGetInterfaceAndReleaseStream(istream, 
 pythoncom.IID_IDispatch)
 my_ie=win32com.client.Dispatch(d)
 my_ie.Navigate(dest)
 pythoncom.CoUninitialize()

 s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,ie)
 thread.start_new_thread(nav, (s, 'www.google.com'))

   Roger

Thnks a lot Roger, Its working gr8..Now, once the thread is started
with start_new_thread, is there any way to terminate it upon user's
request. I have explored and found out that there is no thread.kill().
So wht to do now?

Teja

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


A question about call Wincvs

2006-10-13 Thread Kevien Lee
Hi,
In the Wincvs,if want to get commitable file list in local file list,it could click flat mode-show commitable 
But ,if i want to through command line ,how show it do?
Is there any CVS lib?

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

Re: Efficiently iterating over part of a list

2006-10-13 Thread James Stroud
Steven D'Aprano wrote:
 If I want to iterate over part of the list, the normal Python idiom is to
 do something like this:
 
 alist = range(50)
 # first item is special
 x = alist[0]
 # iterate over the rest of the list
 for item in alist[1:]
 x = item
 
 The important thing to notice is that alist[1:] makes a copy. What if the
 list has millions of items and duplicating it is expensive? What do people
 do in that case?
 
 Are there better or more Pythonic alternatives to this obvious C-like
 idiom?
 
 for i in range(1, len(alist)):
 x = alist[i]
 
 

I think this is a job for iterators:

listiter = iter(alist)

first_item_is_special = listiter.next()

for not_special_item in listiter:
   do_stuff_with(not_special_item)


Other solutions might involve enumerators:

special = [i for i in xrange(50) if not i%13]

for i,item in alist:
   if i in special:
 do_something_special_with(item)
   else:
 do_other_stuff_with(item)

James


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


Re: Efficiently iterating over part of a list

2006-10-13 Thread James Stroud
James Stroud wrote:
 Steven D'Aprano wrote:
 If I want to iterate over part of the list, the normal Python idiom is to
 do something like this:

 alist = range(50)
 # first item is special
 x = alist[0]
 # iterate over the rest of the list
 for item in alist[1:]
 x = item

 The important thing to notice is that alist[1:] makes a copy. What if the
 list has millions of items and duplicating it is expensive? What do 
 people
 do in that case?

 Are there better or more Pythonic alternatives to this obvious C-like
 idiom?

 for i in range(1, len(alist)):
 x = alist[i]


 
 I think this is a job for iterators:
 
 listiter = iter(alist)
 
 first_item_is_special = listiter.next()
 
 for not_special_item in listiter:
   do_stuff_with(not_special_item)
 
 
 Other solutions might involve enumerators:
 
 special = [i for i in xrange(50) if not i%13]
 
 for i,item in alist:
   if i in special:
 do_something_special_with(item)
   else:
 do_other_stuff_with(item)
 
 James
 
 
 James

I mean

for i,item in enumerate(alist):
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File read-write mode: problem appending after reading

2006-10-13 Thread Tim Peters
[Frederic Rentsch]
Working with read and write operations on a file I stumbled on a
 complication when writes fail following a read to the end.

   f = file ('T:/z', 'r+b')
   f.write ('abcdefg')
   f.tell ()
 30L
   f.seek (0)
   f.read ()
 'abcdefg'
   f.flush ()  # Calling or not makes no difference
   f.write ('abcdefg')

Nothing is defined about what happens at this point, and this is
inherited from C.  In standard C, if you want to read following a
write, or write following a read, on the same stream, you must perform
a file-positioning operation (typically a seek) between them.

 Traceback (most recent call last):
   File pyshell#62, line 1, in -toplevel-
 f.write ('abcdefg')
 IOError: (0, 'Error')

That's one possible result.  Since nothing is defined, any other
outcome is also a possible result ;-)

 Flushing doesn't help.

Right, and because flush() is not a file-positioning operation.

 I found two work arounds:

   f.read ()
 'abcdefg'
   f.read ()   # Workaround 1: A second read (returning an empty string)
 ''
   f.write ('abcdefg')
 (No error)

Purely an accident; may or may not work the next time you try it, or
on another platform; etc.

   f.read ()
 'abcdefg'
   f.seek (f.tell ())   # Workaround 2: Setting the cursor (to where it is!)

That's a correct approach.  f.seek(0, 1) (seek 0 bytes from the
current position) is a little easier to spell.

   f.write ('abcdefg')
 (No error)

 I found no problem with writing into the file. So it looks like it has
 to do with the cursor which a read puts past the end, unless it is past
 the end, in which case it goes back to the end. Is there a less kludgy
 alternative to fseek (ftell ())?

As above, you need to seek when switching from reading to writing, or
from writing to reading.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficiently iterating over part of a list

2006-10-13 Thread Ziga Seilnacht
Steven D'Aprano wrote:
[snip]
 The important thing to notice is that alist[1:] makes a copy. What if the
 list has millions of items and duplicating it is expensive? What do people
 do in that case?

 Are there better or more Pythonic alternatives to this obvious C-like
 idiom?

 for i in range(1, len(alist)):
 x = alist[i]


for x in itertools.islice(alist, 1, len(alist)):


HTH
Ziga

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


Re: Efficiently iterating over part of a list

2006-10-13 Thread Peter Otten
Steven D'Aprano wrote:

 Are there better or more Pythonic alternatives to this obvious C-like
 idiom?
 
 for i in range(1, len(alist)):
 x = alist[i]

For small start values you can use itertools.islice(), e. g:

for x in islice(alist, 1, None):
# use x

You'd have to time at what point the C-like idiom (which I would have no
qualms using throughout) becomes faster.

Peter

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


Freeware link/html checker (validator) for mod_python site

2006-10-13 Thread durumdara
Hi !

Sorry for non-pythonic subject, but if I not find good solution, I will 
write a  routine for this in python... :-)))

My mod_py site is growing quickly. It have many pages, many of them are 
dynamic.
I want to check the links, and if possible, validate the html.

I search freeware tools in the net, but I found only HTML Link 
Validator that meet the requirements.
This utility can check the whole site, and it handle the circular 
references - but it's not free, and it not check the whole site... :-(

Some other utilites can check one URL (CSE HTML validator lite, html 
kit, Firefox check page links, Firefox validate HTML, Firefox 
webdeveloper extension),
but not entire site...

Do you knows about a good local site checker application that can do 
validation/link checking in one ?

Is anybody have an experience in this theme ?

Important thing: the OS is Windows XP.

Thanks for your help:
dd




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


Using SVN with Python and .pyc files

2006-10-13 Thread James Stroud
Hello All,

I have been moving to managing a lot of my code with SVN and I have 
found it to work extremely well. However, I'm not exactly sure how to 
deal with all of the .pyc files that get created every time I test a 
project or package. How do people manage this? Do you run a script to 
find files with the .pyc extension and delete those before every commit, 
or is there a more elegant way? It seems like a lot of wasted bandwidth 
an memory on the server side to constantly be dealing with these files 
that contain no real information.

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


Re: pygtk dynamic table

2006-10-13 Thread Antoon Pardon
On 2006-10-12, JyotiC [EMAIL PROTECTED] wrote:
 hi,

 i am making a gui, which looks like excel sheets.
 i want to give the user the facility of adding rows/columns at the run
 time.
 there is some initial size, but that can be increased any time during
 the executation of the code.

 what i have tried, is that i am using table.
 so when ever user increase the size, i destroy the original table and
 make a new one with the increased size.

 is there a better way to do this ?

What about the resize method?

http://www.pygtk.org//docs/pygtk/class-gtktable.html#method-gtktable--resize

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


Re: always raise syntax error!

2006-10-13 Thread daniel
thank you so much for the reply.

I finally re-type all the codes where python would raise syntax error,
then fixed. I did not examine every single word of my old codes though,
 there might be some parenthesis not matching somewhere, I guess.

well, I would say, the reason why I could not position the error code
may partly due to the ambiguous message that python provides. the lines
that python pointed to contains no error,  I think the error codes must
be too far away from there. anyway, I hope python would make more
detailed error messages, like c++ compilers do. such as: missing ; or
( not matching...etc.

tks again..

daniel

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


Re: Using SVN with Python and .pyc files

2006-10-13 Thread Roel Schroeven
James Stroud schreef:
 I have been moving to managing a lot of my code with SVN and I have 
 found it to work extremely well. However, I'm not exactly sure how to 
 deal with all of the .pyc files that get created every time I test a 
 project or package. How do people manage this? Do you run a script to 
 find files with the .pyc extension and delete those before every commit, 
 or is there a more elegant way? It seems like a lot of wasted bandwidth 
 an memory on the server side to constantly be dealing with these files 
 that contain no real information.

You can instruct SVN to ignore the *.pyc files. What you need to do that 
is the svn:ignore property on the directory containing the files, IIRC. 
Check the docs for details. The online book at 
http://svnbook.red-bean.com/ should tell you all you need. Look 
especially at 
http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.ignore


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Using SVN with Python and .pyc files

2006-10-13 Thread Duncan Booth
James Stroud [EMAIL PROTECTED] wrote:

 I have been moving to managing a lot of my code with SVN and I have 
 found it to work extremely well. However, I'm not exactly sure how to 
 deal with all of the .pyc files that get created every time I test a 
 project or package. How do people manage this? Do you run a script to 
 find files with the .pyc extension and delete those before every commit, 
 or is there a more elegant way? It seems like a lot of wasted bandwidth 
 an memory on the server side to constantly be dealing with these files 
 that contain no real information.

You use svn:ignore to ignore files you don't want version controlled.

See:
http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.ignore
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Freeware link/html checker (validator) for mod_python site

2006-10-13 Thread Fredrik Lundh
durumdara [EMAIL PROTECTED] wrote:

 Sorry for non-pythonic subject, but if I not find good solution, I will
 write a  routine for this in python... :-)))

in your Python installation (or source) directory, do

$ cd Tools/webchecker

and then write

$ python webchecker.py -x http://yoursite

(use --help to get a man page)

/F 



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


Re: Sending binary pickled data through TCP

2006-10-13 Thread Nick Craig-Wood
Paul Rubin http wrote:
  As for the network representation, DJB proposes this format:
  http://cr.yp.to/proto/netstrings.txt

Netstrings are cool and you'll find some python implementations if you
search.

But it is basically number:string,, ie 12:hello world!,

Or you could use escaping which is what I usually do.  This has the
advantage that you don't need to know how long the data is in advance.

Eg, these are from a scheme which uses \t to seperate arguments and
\r or \n to seperate transactions.  These are then escaped in the
actual data using these functions

def escape(s):
This escapes the string passed in, changing CR, LF, TAB and \\ into
\\r, \\n, \\t and 
s = s.replace(\\, )
s = s.replace(\r, \\r)
s = s.replace(\n, \\n)
s = s.replace(\t, \\t)
return s

def unescape(s, _unescape_mapping = string.maketrans('tnr','\t\n\r'), 
_unescape_re = re.compile(r'\\([(rnt\\)])')):
This unescapes the string passed in, changing \\r, \\n, \\t and 
\\any_char into
CR, LF, TAB and any_char
def _translate(m):
return m.group(1).translate(_unescape_mapping)
return _unescape_re.sub(_translate, s)

(These functions have been through the optimisation mill which is why
they may not look immediately like how you might first think of
writing them!)

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


Re: Using SVN with Python and .pyc files

2006-10-13 Thread Gregor Horvath
James Stroud schrieb:

 project or package. How do people manage this? Do you run a script to
 find files with the .pyc extension and delete those before every commit,
 or is there a more elegant way? It seems like a lot of wasted bandwidth
 an memory on the server side to constantly be dealing with these files
 that contain no real information.

in /etc/subversion/config

global-ignores = *.pyc *~ #*#

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-13 Thread Bruno Desthuilliers
Peter Maas wrote:
 Bruno Desthuilliers wrote:
 Peter Maas wrote:
 [...]
 a reference implementation for web programming as part of the standard
 library, 
 wsgiref is part of the 2.5 stdlib.
 
 Yes, but it's not an implementation. Think of something like Tomcat for
 the Java Servlet Specification.
 
Then I'd vote for paste.

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


Re: Efficiently iterating over part of a list

2006-10-13 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote:

 The important thing to notice is that alist[1:] makes a copy. What if
 the list has millions of items and duplicating it is expensive? What
 do people do in that case?

I think you are worrying prematurely.

On my system slicing one element off the front of a 10,000,000 element list 
takes 440mS. The same operation on 1,000,000 elements taks 41mS. Iterating 
through the sliced list:

for x in r[1:]:
   y = x+1

takes 1.8s and 157mS respectively, so the slicing is only a quarter of the 
time for even this minimal loop. As soon as you do anything much inside the 
loop you can forget the slice cost.

Remember that copying the list never copies the elements in the list, it 
just copies pointers and bumps ref counts. Copying a list even if it has 
millions of items is not usually expensive compared with the costs of 
manipulating all the items in the list.

So the first thing you do is not to worry about this until you know it is 
an issue. Once you know for a fact that it is a problem, then you can look 
at optimising it with fancy lazy slicing techniques, but not before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-13 Thread Bruno Desthuilliers
Fredrik Lundh wrote:
 Paul Boddie wrote:
 
 Meanwhile, the Web programming standardisation scene remains
 stagnant.
 
 Aw, come on.  The Python web programming standardisation wars are over, for 
 now.
 There's Django, and there's TurboGears, 

And there's Pylons...

 and there's Zope 2/3, all with slightly different
 approaches, and slightly different target audiences.  Unless you're doing 
 really odd things,
 one of these will be more than good enough for your application.
 
 (as for WSGI, it's plumbing. You can of course build fun things from spare 
 parts and
 plumbing, and there are really interesting things going on in certain 
 research labs, as usual,
 but if you want turn-key stuff, pick one of the big three.)
 
 /F 
 
 
 


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


Re: Python component model

2006-10-13 Thread Fredrik Lundh
Bruno Desthuilliers wrote:

 Meanwhile, the Web programming standardisation scene remains
 stagnant.

 Aw, come on.  The Python web programming standardisation wars are over, for 
 now.
 There's Django, and there's TurboGears,

 And there's Pylons...

and a zillion other more or less interesting research projects.  I don't see 
any traces
of the kind of ecosystems and market awareness that exist for Zope, Django, and
TurboGears (or for that matter, Rails and Mason), for any other Python web pro-
gramming tool.

/F 



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


Re: Using SVN with Python and .pyc files

2006-10-13 Thread James Stroud
Everyone wrote:
[something helpful]

Thank you to everyone for your responses.

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


Re: Python Best Practice References

2006-10-13 Thread James Stroud
Wijaya Edward wrote:
 Can anybody suggest any references (links, books, etc)about this?
 I'm thinking of something similar with D.Conway's Perl Best Practice.
  
 -- Edward WIJAYA
 SINGAPORE
 
  Institute For Infocomm Research - Disclaimer -
 This email is confidential and may be privileged.  If you are not the 
 intended recipient, please delete it and notify us immediately. Please do not 
 copy or use it for any purpose, or disclose its contents to any other person. 
 Thank you.
 

By all means, please start here:

http://www.python.org/doc/essays/styleguide.html

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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-13 Thread Diez B. Roggisch
Wijaya Edward schrieb:
 Hi,
  
 Some recent webapps like Kiko http://www.kiko.com/ , Google's gadget 
 http://www.google.com/ig/directory?hl=en , and spreadsheets 
 http://spreadsheets.google.com  to name a few, 
 have this functionality. 
 
 I wonder how can this funcitonalities be implemented in Python. 
 Do you guys have any experience with it?
 Any Python module that support that?

There is mochikit, a javascript library that makes coding in javascript 
suck less.

And there is the pypy javascript backend.

But real python - no.

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


Re: How to print the CDATA of .xml file?

2006-10-13 Thread Fredrik Lundh
Kevien Lee wrote:

 when i use the minidom to parase the XML file,it would ignored the section
 of ![CDATA[...]
 the code is:

 _document=minidom.parse(filePath)
 _documnetList=_document.getElementsByTagName(NodeArgs)
 for _argNode in _documnetList:
print _argNode.nodeValue,_argNode.localName

 when it run. The nodeValue of the CDATA Section  is  always None,Is my code
 error?

here's one way to do it, under Python 2.5:

import xml.etree.ElementTree as ET

tree = ET.parse(filename)

for elem in tree.findall(.//NodeArgs):
print elem.findtext(Disp)
print elem.findtext(BtmPane/Path)

/F 



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


Re: 3D Vector Type Line-Drawing Program

2006-10-13 Thread Fabian Braennstroem
Hi,

I am not sure, if that is, what your looking for, but
with 'salome' you able to produce 3D drawings with an GUI or
using a python script. Take a look at:

http://www.salome-platform.org/home/presentation/geom/

* Scott David Daniels [EMAIL PROTECTED] wrote:
 Ron Adam wrote:
 Scott David Daniels wrote:
 Ron Adam wrote:
 ... Is there a way to have the display show a wire frame image instead of 
 shaded shapes?
 You can draw the edges as lines.
 
 Is there a setting for this?, or are you suggesting reading the 
 coordinates and creating curve objects for the edges?
 Nope, you'd have to make a poly line which was the wire frame, but it
 would then rotate and such with the rest of the model.  Essentially
 you would, for each primitive, have a wire-frame and a volumetric
 version, and keep one of the two visible (with the other invisible)
 at all times.

 Is there an easy way to convert a display to something that can be 
 printed?

 You can generate POV-ray source.  This is not a system for creating
 beautiful pictures, but rather a great 3-D sketch pad.

 Now POV-ray _will_ create beautiful pictures, but the texturing,
 shading, and lighting control that POV-ray gives you exceeds that
 of VPython.  You could use VPython to get you model built and view-
 point placed, and the tweak the POV-ray code to get pretty output.

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


Greetings!
 Fabian

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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-13 Thread Fredrik Lundh
Diez B. Roggisch wrote:

 There is mochikit, a javascript library that makes coding in javascript
 suck less.

and which is written by an experienced Python programmer, so it also
makes your JavaScript look and feel a little more Pythonic.

(not that JavaScript itself is that unpythonic, really, but some of the API:s
suck pretty badly).

/F 



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


Re: What value should be passed to make a function use the default argument value?

2006-10-13 Thread Antoon Pardon
On 2006-10-12, Magnus Lycka [EMAIL PROTECTED] wrote:
 Antoon Pardon wrote:
 Well maybe he didn't intend that, but how is the reader of the
 documentation to know that? The reader can only go by how
 things are documented. If those are not entirely consistent
 with the intend of the programmer, that is not the readers
 fault.

 I don't think I ever assumed that it was right to call functions
 with keyword arguments if they weren't defined with keyword
 parameters,

I'm not sure I follow here. AFAICS, you can't define keyword
parameters. You can give default values to parameters but
this is orthogonal to calling a function with keywords.

If we somehow want to seperate parameters in those that
can be used with a keyword and those that don't it has
to be something different than providing a default value
to that parameter.

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


Re: Adding Worksheets to an Excel Workbook

2006-10-13 Thread Fabian Braennstroem
Hi Wesley,

* wesley chun [EMAIL PROTECTED] wrote:
 just a small OT question coming from a linux openoffice
 system...

 Does there exist something similar for powerpoint? Would be
 nice, if anybody can direct me to more examples...


 fabian,

 see below for a PP example.  you mentioned you were coming from a
 linux OOo system... are you trying to do COM stuff with OOo?  i'm not
 familiar with it, but since they do support
 some level of VB-like scripting, i don't believe it's out of the question.

 one thing that i did forget to mention in my earlier message is that i
 use static dispatch for these apps.  if you did not go and run the
 makepy utility, you would have to use dynamic dispatch, start your
 apps with win32com.client.Dispatch(), or, using the same import
 statement as below, win32.Dispatch().



 anyway, here is pretty much the same script as i sent earlier but for
 PowerPoint instead of Excel (the book has small examples for each of
 Excel, Word, PowerPoint, and Outlook):

 # based on ppoint.pyw in Core Python Programming, 2nd ed

 from time import sleep
 import win32com.client as win32

 def ppoint():
 ppoint = win32.gencache.EnsureDispatch('PowerPoint.Application')
 pres = ppoint.Presentations.Add()
 ppoint.Visible = True

 s1 = pres.Slides.Add(1, win32.constants.ppLayoutText)
 sleep(1)
 s1a = s1.Shapes[0].TextFrame.TextRange
 s1a.Text = 'Python-to-PowerPoint Demo'
 sleep(1)
 s1b = s1.Shapes[1].TextFrame.TextRange
 for i in range(3, 8):
 s1b.InsertAfter(Line %d\r\n % i)
 sleep(1)
 s1b.InsertAfter(\r\nTh-th-th-that's all folks!)

 sleep(5)
 pres.Close()
 ppoint.Quit()

 if __name__=='__main__':
 ppoint()

Thanks! I am not able to try it out yet, but as soon as I
get access to my windows machine, I'll give it a try.


Greetings!
 Fabian

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


Re: SOAPpy and callback

2006-10-13 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
 Hello,
 
 I'm trying to find how to use a callback in a SOAP client using SOAPpy.
 Does SOAPpy have to manage it, or does Python include some API to do
 it?

I've never seen any callback mentioned in SOAP. Are you sure this is 
possible with any SOAP implementation, at least standard-wise?

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


Big speed boost in os.walk in Python 2.5

2006-10-13 Thread looping
Hi,
I noticed a big speed improvement in some of my script that use os.walk
and I write a small script to check it:
import os
for path, dirs, files in os.walk('D:\\FILES\\'):
pass

Results on Windows XP after some run to fill the disk cache (with
~59000 files and ~3500 folders):
Python 2.4.3 : 45s
Python 2.5 : 10s

Very nice, but somewhat strange...
Is Python 2.4.3 os.walk buggy ???
Is this results only valid in Windows or *nix system show the same
difference ?
The profiler show that most of time is spend in ntpath.isdir and this
function is *a lot* faster in Python 2.5.
Maybe this improvement could be backported in Python 2.4 branch for the
next release ?


Python 2.4.3
 604295 function calls (587634 primitive calls) in 48.629 CPU
seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
625540.2640.0000.2640.000 :0(append)
10.0010.001   48.593   48.593 :0(execfile)
660740.1970.0000.1970.000 :0(len)
 35215.2190.0015.2190.001 :0(listdir)
10.0360.0360.0360.036 :0(setprofile)
62554   38.8120.001   38.8120.001 :0(stat)
10.0000.000   48.593   48.593 string:1(?)
660740.2180.0000.2180.000 ntpath.py:116(splitdrive)
 35200.0090.0000.0090.000 ntpath.py:246(islink)
625540.7670.000   40.1370.001 ntpath.py:268(isdir)
660740.4330.0000.6500.000 ntpath.py:51(isabs)
660740.8800.0001.7260.000 ntpath.py:59(join)
20183/35221.2170.000   48.5730.014 os.py:211(walk)
10.0000.000   48.629   48.629
profile:0(execfile('test.py'))
00.000 0.000  profile:0(profiler)
625540.1740.0000.1740.000 stat.py:29(S_IFMT)
625540.3850.0000.5590.000 stat.py:45(S_ISDIR)
10.0190.019   48.592   48.592 test.py:1(?)


Python 2.5:
 604295 function calls (587634 primitive calls) in 17.386 CPU
seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
625540.2470.0000.2470.000 :0(append)
10.0010.001   17.315   17.315 :0(execfile)
660740.1680.0000.1680.000 :0(len)
 35215.2870.0025.2870.002 :0(listdir)
10.0710.0710.0710.071 :0(setprofile)
625547.8120.0007.8120.000 :0(stat)
10.0000.000   17.315   17.315 string:1(module)
660740.1860.0000.1860.000 ntpath.py:116(splitdrive)
 35200.0090.0000.0090.000 ntpath.py:245(islink)
625540.7120.0009.0130.000 ntpath.py:267(isdir)
660740.3940.0000.5810.000 ntpath.py:51(isabs)
660740.8150.0001.5640.000 ntpath.py:59(join)
20183/35221.1760.000   17.2960.005 os.py:218(walk)
10.0000.000   17.386   17.386
profile:0(execfile('test.py'))
00.000 0.000  profile:0(profiler)
625540.1590.0000.1590.000 stat.py:29(S_IFMT)
625540.3310.0000.4890.000 stat.py:45(S_ISDIR)
10.0180.018   17.314   17.314 test.py:1(module)

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


Re: operator overloading + - / * = etc...

2006-10-13 Thread Piet van Oostrum
 Fredrik Lundh [EMAIL PROTECTED] (FL) wrote:

FL Piet van Oostrum wrote:
 The official Python documentation (language reference manual) talks a lot
 about variables. So it seems silly to say that Python doesn't have
 variables.

FL the language reference mostly uses the term variables when discussing
FL local variables and instance variables, and is (usually) careful to talk
FL about names when talking about binding behaviour.

Mostly yes, but not exclusively. E.g.
  If a name is bound in a block, it is a local variable of that block. If a
  name is bound at the module level, it is a global variable. (The
  variables of the module code block are local and global.) If a variable
  is used in a code block but not defined there, it is a free variable. 

There are also other uses of variable for things at the module level. And
the word `variable(s)' occurs 80 times in the language reference manual.

FL for example, the description of the assignment statement:

FL   http://www.python.org/doc/2.4.3/ref/assignment.html

FL only uses variable twice, in a note that discussing a given code
FL example. the more formal parts of that page consistently use the term
FL name.

FL it's often a good idea to be a bit careful when discussing detailed
FL behaviour, especially in contexts where the audience may associate
FL variables with small areas of memory.

It is interesting that the word 'variable' is nowhere defined in the
manual. What one imagines with the word `variable' depends on one's
programming background, I guess, and that could certainly give a wrong
impression. 
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Thread termination

2006-10-13 Thread Teja
Hi all,

Does any one know how to terminate or kill a thread that is started
with start_new_thread() in the middle of its execution?

Any pointers?

Thanks in advance

Teja.

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


Re: How to print the CDATA of .xml file?

2006-10-13 Thread Kevien Lee

-- Forwarded message --From:Fredrik Lundh [EMAIL PROTECTED]To:python-list@python.org
Date:Fri, 13 Oct 2006 11:03:45 +0200Subject:Re: How to print the CDATA of .xml file?Kevien Lee wrote: when i use the minidom to parase the XML file,it would ignored the section of ![CDATA[...]
 the code is: _document=minidom.parse(filePath) _documnetList=_document.getElementsByTagName(NodeArgs) for _argNode in _documnetList:  print _argNode.nodeValue,_argNode.localName
 when it run. The nodeValue of the CDATA Section is always None,Is my code error?here's one way to do it, under Python 2.5: import xml.etree.ElementTree as ET tree = ET.parse
(filename) for elem in tree.findall(.//NodeArgs):   print elem.findtext(Disp)   print elem.findtext(BtmPane/Path)/F


use Python 2.5 is easy and good, but is there any others way under version 2.4?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Linting python code...

2006-10-13 Thread Joel Rosdahl
[EMAIL PROTECTED] writes:

 Christoph On Tuesday 10 October 2006 14:06, Andrew Markebo wrote:
  Are there any python-code linter out there

 Christoph PyLint (http://www.logilab.org/projects/pylint)
 Christoph PyChecker (http://pychecker.sf.net)

 New kid on the block:

 PyFlakes http://divmod.org/trac/wiki/DivmodPyflakes

 It doesn't do nearly as much as the other two but doesn't import the
 modules, so it can be used in places the others can't.

I thought PyLint doesn't import modules either. Am I mistaken?

-- 
Regards,
Joel Rosdahl [EMAIL PROTECTED]
Key BB845E97; fingerprint 9F4B D780 6EF4 5700 778D  8B22 0064 F9FF BB84 5E97
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-13 Thread Paul Boddie
Steve Holden wrote:
 Paul Boddie wrote:

  I'm not at the cutting edge here: 20j and 20k are the commands (replace
  20 with another suitable amount) which help me jump around in my editor
  of choice. The other commands which may be more effective just aren't
  in my working set.
 
 You *might* find CTRL/U and CTRL/D helpful ...

Sure, even Page Up and Page Down work on decent distributions. But
there's a huge collection of other commands waiting to be discovered
too. I may never know them all, however. ;-)

Paul

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


Re: Linting python code...

2006-10-13 Thread Paul Boddie
Joel Rosdahl wrote:
 [EMAIL PROTECTED] writes:
 

[PyLint, PyChecker]

  New kid on the block:
 
  PyFlakes http://divmod.org/trac/wiki/DivmodPyflakes
 
  It doesn't do nearly as much as the other two but doesn't import the
  modules, so it can be used in places the others can't.

 I thought PyLint doesn't import modules either. Am I mistaken?

My impression was that PyLint only inspects the AST (using the astng
package), whereas PyChecker can be asked to do only that, or to
actually import the modules as well.

Paul

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


Re: Thread termination

2006-10-13 Thread Aidan Steele
G'day,As far as my understanding pertains, the thread dies
shortly after the function returns (ends). You can call return
anywhere within the function and kill the thread in the middle of its
execution.On 13 Oct 2006 02:38:28 -0700, Teja [EMAIL PROTECTED] wrote:
Hi all,Does any one know how to terminate or kill a thread that is startedwith start_new_thread() in the middle of its execution?Any pointers?Thanks in advanceTeja.--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Thread termination

2006-10-13 Thread Stefan Schukat
Reading from your last posts you are using COM objects. Therefore you
should not kill the thread since this
would lead to reference leaks. So there are only two ways left:

1. Program a specific interpreter and not use python.exe which
implements an access to PyThreadState_SetAsyncExc
2. Check in the separate thread at specific times a variable which is
set in the main thread.

Both need the try finally construct in the threadfunction to release COM
objects in the right way.
I.e., (taking the source from Roger):


def ThreadFunction(istream, dest):
  pythoncom.CoInitialize() // Initialize COM Runtime for this thread
try:
d=pythoncom.CoGetInterfaceAndReleaseStream(istream,
pythoncom.IID_IDispatch)
my_ie=win32com.client.Dispatch(d)
my_ie.Navigate(dest)
finally:
my_ie = None  // Release COM object
  pythoncom.CoUninitialize() // Release COM Runtime for this
thread


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


Re: Click and Drag Functionality in Web Apps with Python

2006-10-13 Thread Diez B. Roggisch
Fredrik Lundh schrieb:
 Diez B. Roggisch wrote:
 
 There is mochikit, a javascript library that makes coding in javascript
 suck less.
 
 and which is written by an experienced Python programmer, so it also
 makes your JavaScript look and feel a little more Pythonic.
 
 (not that JavaScript itself is that unpythonic, really, but some of the API:s
 suck pretty badly).


I pretty much like the language, yes. But the environment it is deployed 
in suck pretty hard, especially when they stem from a north-western US 
state.

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


Re: Thread termination

2006-10-13 Thread Diez B. Roggisch
Teja schrieb:
 Hi all,
 
 Does any one know how to terminate or kill a thread that is started
 with start_new_thread() in the middle of its execution?
 
 Any pointers?

This has been discussed a bazillion times in this NG. The short answer 
is: no.

For  the long answer: do some googling :)

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


Re: Python component model

2006-10-13 Thread Paul Rubin
Fredrik Lundh [EMAIL PROTECTED] writes:
 and a zillion other more or less interesting research projects.  I don't see 
 any traces
 of the kind of ecosystems and market awareness that exist for Zope, Django, 
 and
 TurboGears (or for that matter, Rails and Mason), for any other Python web 
 pro-
 gramming tool.

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


Re: Efficiently iterating over part of a list

2006-10-13 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes:
 for i in range(1, len(alist)):
 x = alist[i]

a2 = iter(alist)
a2.next()  # throw away first element
for x in a2:
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to print the CDATA of .xml file?

2006-10-13 Thread Fredrik Lundh
Kevien Lee wrote:

   import xml.etree.ElementTree as ET

 use Python 2.5 is easy and good, but is there any others  way under
 version 2.4?

the ET API is available for 1.5.2 and newer:

http://effbot.org/zone/element-index.htm

/F 



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


Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread శ్రీనివాస
Hai friends,
Can any one tell me how can i remove a character from a unocode text.
కల్‌హార is a Telugu word in Unicode. Here i want to
remove '' but not replace with a zero width char. And one more thing,
if any whitespaces are there before and after '' char, the text should
be kept as it is. Please tell me how can i workout this with regular
expressions.

Thanks and regards
Srinivasa Raju Datla

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

Re: SOAPpy and callback

2006-10-13 Thread fabien . benard
SOAP standard doesn't provide any callback, and it looks like SOAPpy
doesn't too.
I remember using callbacks with Javascript and SOAP in Web pages. I was
just wondering if there could be the same with Python.

Thanks for your answer.

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


Re: Freeware link/html checker (validator) for mod_python site

2006-10-13 Thread durumdara




Hi !

Very good !!! Thank you very much !
If I can "link it" with a w3c html checker, it will be very good...

Interesting that it is also say "bad link" to site
http://www.druk-ker.hu/. The HTML link validator do it same.

dd

Fredrik Lundh rta:

  "durumdara" [EMAIL PROTECTED] wrote:

  
  
Sorry for non-pythonic subject, but if I not find good solution, I will
write a  routine for this in python... :-)))

  
  
in your Python installation (or source) directory, do

$ cd Tools/webchecker

and then write

$ python webchecker.py -x http://yoursite

(use --help to get a man page)

/F 



  




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

Re: 3D Vector Type Line-Drawing Program

2006-10-13 Thread Kjell Magne Fauske
 I'm looking for a program to do line-drawings in 3d, with output to
 postscript or svg or pdf, etc. I would like to describe a scene with
 certain 1-3d elements oriented in 3d space with dashed or colored lines
 and filled or transparent surfaces (or maybe semitransparent).


For high quality line drawings using Python you have PyX [1].
Unfortunately it does not come with a 3D library. You probably have too
look elsewere for 3D vector drawings.  Some places to look are:

- Asymptote [2]
- Sketch [3]. A small, simple system for producing line drawings of
two- or three-dimensional solid objects and scenes. Sketch generates
PSTricks code for LaTeX.

Both Asymptote and Sketch requires TeX/LaTeX for typesetting labels and
such. Sketch is probably the closest to what you are looking for. See
[4] for an example of what kind of graphics it can create.

[1] http://pyx.sourceforge.net/
[2] http://asymptote.sourceforge.net/
[3] http://www.frontiernet.net/~eugene.ressler/
[4] http://www.fauskes.net/nb/threedill/

Regards,
Kjell Magne Fauske

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


Re: Insert characters into string based on re ?

2006-10-13 Thread harvey . thomas

Matt wrote:
 I am attempting to reformat a string, inserting newlines before certain
 phrases. For example, in formatting SQL, I want to start a new line at
 each JOIN condition. Noting that strings are immutable, I thought it
 best to spllit the string at the key points, then join with '\n'.

 Regexps can seem the best way to identify the points in the string
 ('LEFT.*JOIN' to cover 'LEFT OUTER JOIN' and 'LEFT JOIN'), since I need
 to identify multiple locationg in the string. However, the re.split
 method returns the list without the split phrases, and re.findall does
 not seem useful for this operation.

 Suggestions?

I think that re.sub is a more appropriate method rather than split and
join

trivial example (non SQL):

 addnlre = re.compile('LEFT\s.*?\s*JOIN|RIGHT\s.*?\s*JOIN', re.DOTALL + 
 re.IGNORECASE).sub
 addnlre(lambda x: x.group() + '\n', '... LEFT JOIN x RIGHT OUTER join y')
'... LEFT JOIN\n x RIGHT OUTER join\n y'

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


Re: Python component model

2006-10-13 Thread Bruno Desthuilliers
Fredrik Lundh wrote:
 Bruno Desthuilliers wrote:
 
 Meanwhile, the Web programming standardisation scene remains
 stagnant.
 Aw, come on.  The Python web programming standardisation wars are over, for 
 now.
 There's Django, and there's TurboGears,
 And there's Pylons...
 
 and a zillion other more or less interesting research projects. 

I don't think Pylons qualifies as a research project. FWIW, I
mentionned it because, while (yet) less buzzworded than Django and TG,
it's really in the same category - but using the wsgi stack approach
instead of the monolithic one. And MHO is that it could really become
the next big thing in Python's web programming ecosystem.

 I don't see any traces
 of the kind of ecosystems and market awareness that exist for Zope, Django, 
 and
 TurboGears (or for that matter, Rails and Mason), for any other Python web 
 pro-
 gramming tool.

Yes, true.

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


Re: What value should be passed to make a function use the default argument value?

2006-10-13 Thread Steve Holden
Antoon Pardon wrote:
 On 2006-10-12, Magnus Lycka [EMAIL PROTECTED] wrote:
 
Antoon Pardon wrote:

Well maybe he didn't intend that, but how is the reader of the
documentation to know that? The reader can only go by how
things are documented. If those are not entirely consistent
with the intend of the programmer, that is not the readers
fault.

I don't think I ever assumed that it was right to call functions
with keyword arguments if they weren't defined with keyword
parameters,
 
 
 I'm not sure I follow here. AFAICS, you can't define keyword
 parameters. You can give default values to parameters but
 this is orthogonal to calling a function with keywords.
 
Yup, that's a point that the documentation doesn't make stringly enough.

 If we somehow want to seperate parameters in those that
 can be used with a keyword and those that don't it has
 to be something different than providing a default value
 to that parameter.
 
Indeed.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: SOAPpy and callback

2006-10-13 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
 SOAP standard doesn't provide any callback, and it looks like SOAPpy
 doesn't too.
 I remember using callbacks with Javascript and SOAP in Web pages. I was
 just wondering if there could be the same with Python.

How that? I seriously doubt that, it would mean that the server would be 
able to issue an request on its own to the browser - a technical 
impossibility in current browser implementations.

Just because you used a callback inside a js-soap-implementation that 
works with deferreds or something similar doesn't mean that the soap 
itself knew callbacks.

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


Re: OT: What's up with the starship?

2006-10-13 Thread Steve Holden
Thomas Heller wrote:
 I cannot connect to starship.python.net: neither http, nor can I login 
 interactively with ssl (and the host key seems to have changed as well).
 
 Does anyone know more?
 
Nope. I got a mailing list reminder as usual at the start of the month, 
but I can confirm that I can't log in with my SSH private key, and that 
the system fingerprint has changed. Maybe some crew member can tell us 
what gives.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread harvey . thomas

శ్రీనివాస wrote:
 Hai friends,
 Can any one tell me how can i remove a character from a unocode text.
 కల్‌హార is a Telugu word in Unicode. Here i want to
 remove '' but not replace with a zero width char. And one more thing,
 if any whitespaces are there before and after '' char, the text should
 be kept as it is. Please tell me how can i workout this with regular
 expressions.

 Thanks and regards
 Srinivasa Raju Datla

Don't know anything about Telugu, but is this the approach you want?

 x=u'\xfe\xff  \xfe\xff \xfe\xff\xfe\xff'
 noampre = re.compile('(?!\s)(?!\s)', re.UNICODE).sub
 noampre('', x)
u'\xfe\xff  \xfe\xff \xfe\xff\xfe\xff'

The regular expression has negative look behind and look ahead
assertions to check that there is no whitespace surrounding the ''
character. Each match then found is then  replaced with the empty string

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

Re: Python Best Practice References

2006-10-13 Thread Steve Holden
James Stroud wrote:
 Wijaya Edward wrote:
 
Can anybody suggest any references (links, books, etc)about this?
I'm thinking of something similar with D.Conway's Perl Best Practice.
 
-- Edward WIJAYA
SINGAPORE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the 
intended recipient, please delete it and notify us immediately. Please do not 
copy or use it for any purpose, or disclose its contents to any other person. 
Thank you.

 
 
 By all means, please start here:
 
 http://www.python.org/doc/essays/styleguide.html
 
Nowadays I suspect PEP 8, derived from that essay, would be considered 
more authoritative.

   http://www.python.org/dev/peps/pep-0008/

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread Sybren Stuvel
శ్రీనివాస enlightened us with:
 Can any one tell me how can i remove a character from a unocode
 text.  కల్200cహార is a Telugu word in Unicode. Here i want to
 remove '' but not replace with a zero width char. And one more
 thing, if any whitespaces are there before and after '' char, the
 text should be kept as it is.

So basically, you want to match 200c and replace it with 200c,
but only if it's not surrounded by whitespace, right?

r(?!\s)\x200c(?!\s) should match. I'm sure you'll be able to take
it from there.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Insert characters into string based on re ?

2006-10-13 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

 
 Matt wrote:
 I am attempting to reformat a string, inserting newlines before
 certain phrases. For example, in formatting SQL, I want to start a
 new line at each JOIN condition. Noting that strings are immutable, I
 thought it best to spllit the string at the key points, then join
 with '\n'. 
 
 I think that re.sub is a more appropriate method rather than split and
 join
 
 trivial example (non SQL):
 
 addnlre = re.compile('LEFT\s.*?\s*JOIN|RIGHT\s.*?\s*JOIN',
 re.DOTALL + re.IGNORECASE).sub addnlre(lambda x: x.group() + '\n',
 '... LEFT JOIN x RIGHT OUTER join y') 
 '... LEFT JOIN\n x RIGHT OUTER join\n y'
 
 
Quite apart from the original requirement being to insert newlines before 
rather than after the phrase, I wouldn't have said re.sub was appropriate.

 addnlre(lambda x: x.group() + '\n',
 select * from whatever where action in ['user left site', 'user joined 
site'])
select * from whatever where action in ['user left site', 'user join\ned 
site']

or with the newline before the pattern:

 addnlre(lambda x: '\n'+x.group(),
 select * from whatever where action in ['user left site', 'user joined 
site'])
select * from whatever where action in ['user \nleft site', 'user joined 
site']

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


Re: Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread Leo Kislov


On Oct 13, 4:44 am, [EMAIL PROTECTED] wrote:
 శ్రీనివాస wrote:
  Hai friends,
  Can any one tell me how can i remove a character from a unocode text.
  కల్‌హార is a Telugu word in Unicode. Here i want to
  remove '' but not replace with a zero width char. And one more thing,
  if any whitespaces are there before and after '' char, the text should
  be kept as it is. Please tell me how can i workout this with regular
  expressions.

  Thanks and regards
  Srinivasa Raju DatlaDon't know anything about Telugu, but is this the 
  approach you want?

  x=u'\xfe\xff  \xfe\xff \xfe\xff\xfe\xff'
  noampre = re.compile('(?!\s)(?!\s)', re.UNICODE).sub
  noampre('', x)

He wants to replace  with zero width joiner so the last call should be
noampre(u\u200D, x)

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

Re: Need a Regular expression to remove a char for Unicode text

2006-10-13 Thread Leo Kislov
On Oct 13, 4:55 am, Leo Kislov [EMAIL PROTECTED] wrote:
 On Oct 13, 4:44 am, [EMAIL PROTECTED] wrote:

  శ్రీనివాస wrote:
   Hai friends,
   Can any one tell me how can i remove a character from a unocode text.
   కల్‌హార is a Telugu word in Unicode. Here i want to
   remove '' but not replace with a zero width char. And one more thing,
   if any whitespaces are there before and after '' char, the text should
   be kept as it is. Please tell me how can i workout this with regular
   expressions.

   Thanks and regards
   Srinivasa Raju DatlaDon't know anything about Telugu, but is this the 
   approach you want?

   x=u'\xfe\xff  \xfe\xff \xfe\xff\xfe\xff'
   noampre = re.compile('(?!\s)(?!\s)', re.UNICODE).sub
   noampre('', x)

 He wants to replace  with zero width joiner so the last call should be
 noampre(u\u200D, x)

Pardon my poor reading comprehension, OP doesn't want zero width
joiner. Though I'm confused why he mentioned it at all.

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

Re: Sending binary pickled data through TCP

2006-10-13 Thread MRAB

David Hirschfield wrote:
 I have a pair of programs which trade python data back and forth by
 pickling up lists of objects on one side (using
 pickle.HIGHEST_PROTOCOL), and sending that data over a TCP socket
 connection to the receiver, who unpickles the data and uses it.

 So far this has been working fine, but I now need a way of separating
 multiple chunks of pickled binary data in the stream being sent back and
 forth.

 Questions:

 Is it safe to do what I'm doing? I didn't think there was anything
 fundamentally wrong with sending binary pickled data, especially in the
 closed, safe environment these programs operate under...but maybe I'm
 making a poor assumption?

 I was going to separate the chunks of pickled data with some well-formed
 string, but couldn't that string potentially randomly appear in the
 pickled data? Do I just pick an extremely
 unlikely-to-be-randomly-generated string as the separator? Is there some
 string that will definitely NEVER show up in pickled binary data?

 I thought about base64 encoding the data, and then decoding on the
 opposite side (like what xmlrpclib does), but that turns out to be a
 very expensive operation, which I want to avoid, speed is of the essence
 in this situation.

 Is there a reliable way to determine the byte count of some pickled
 binary data? Can I rely on len(pickled data) == bytes?

Instead of communicating directly with the TCP socket, you could talk
to it via an object which precedes each chunk with a byte count, and if
you're working with multiple streams of picked data, then each chunk
could also have an identifier which specified which stream it belonged
to.

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


Re: Appropriate way to quit Tkinter

2006-10-13 Thread Neil Cerutti
On 2006-10-13, mzdude [EMAIL PROTECTED] wrote:

 Fredrik Lundh wrote:
 [snip]
 works for me.  are you perhaps running this under some kind of
 IDE that keeps the process running even after the program has
 terminated?

 It works the same way if I run from IDLE or from the DOS
 command prompt.

I had some fun trying to run Tkinter from from the Python
embedded in Vim. My advice: Do not do that.

-- 
Neil Cerutti
The majority of time, it seems to be one thing or the other.
--Ron Mercer
-- 
http://mail.python.org/mailman/listinfo/python-list


Cannot force configure/setup.py to pick up location of readline (SFWrline) on Solaris 10

2006-10-13 Thread Chris Miles
On a standard Solaris 10 installation with Sun-supplied open-source 
packages installed (like SFWrline for readline libs) I cannot seem to 
force Python configure/setup.py to build with readline support.

SFWrline installs readline in /opt/sfw/lib  /opt/sfw/include

(This is all attempted with Python-2.4.3 on Solaris 10 06/06 i386)

With this configure:
./configure --prefix=/opt/python-2.4.3 --enable-shared 
CPPFLAGS=-I/opt/sfw/include CFLAGS=-I/opt/sfw/include LDFLAGS=-L/opt/sfw/lib

The resulting output includes:
...
checking for rl_callback_handler_install in -lreadline... yes
checking for rl_pre_input_hook in -lreadline... yes
checking for rl_completion_matches in -lreadline... yes
...


and config.log contains:
...
ac_cv_lib_readline_rl_callback_handler_install=yes
ac_cv_lib_readline_rl_completion_matches=yes
ac_cv_lib_readline_rl_pre_input_hook=yes
...


However, make doesn't build a readline module and I think this is 
because setup.py is not taking the custom *FLAGS into account.  Even if 
I export them as environment variables, I get no readline module.

How do I force the build to use the custom paths?

And/or: can we teach configure/setup.py to include /opt/sfw/ when on 
Solaris, as this is the standard location for Sun's supplied open-source 
packages (ie: on the Companion disc) ?

btw: an answer to this is not to install other 3rd party readline 
packages such as from sunfreeware.com or blastwave, as that should not 
be necessary when Sun supply the packages themselves (and some 
organisations will not allow those packages).

Cheers,
Chris

-- 
http://chrismiles.info/

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


Re: prefix search on a large file

2006-10-13 Thread js
I did the test the way you suggested. It took not so long to realize
stupid mistakes I made. Thank you.

The following is the result of test with timeit(number=1)
using fresh copy of the list  for every iteration

0.331462860107
0.19401717186
0.186257839203
0.0762069225311

I tried my recursive-function to fix up my big-messed-list.
It stops immediately because of 'RuntimeError: maximum recursion limit exceeded'

I hope this trial-and-errors getting me good place...

anyway, thank you.

On 10/13/06, Peter Otten [EMAIL PROTECTED] wrote:
 js  wrote:

  By eliminating list cloning, my function got much faster than before.
  I really appreciate you, John.
 
  def prefixdel_recursively2(alist):
  if len(alist)  2:
  return alist
 
  first = alist.pop(0)
  unneeded = [no for no, line in enumerate(alist) if
  line.startswith(first)] adjust=0
  for i in unneeded:
  del alist[i+adjust]
  adjust -= 1
 
  return [first] + prefixdel_recursively(alist)
 
 
  process stime
  prefixdel_stupidly : 11.9247150421
  prefixdel_recursively   : 14.6975700855
  prefixdel_recursively2 : 0.408113956451
  prefixdel_by_john: 7.60227012634

 Those are suspicious results. Time it again with number=1, or a fresh copy
 of the data for every iteration.

 I also have my doubts whether sorting by length is a good idea. To take it
 to the extreme: what if your data file contains an empty line?

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

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


Re: Cannot force configure/setup.py to pick up location of readline (SFWrline) on Solaris 10

2006-10-13 Thread skip

Chris However, make doesn't build a readline module and I think this is
Chris because setup.py is not taking the custom *FLAGS into account.
Chris Even if I export them as environment variables, I get no readline
Chris module.

Try 

./python setup.py build_ext --help

There are a couple flags you can give to the build_ext command that direct
to the appropriate include and library directories.

It would be nice if distutils could be persuaded to listen to *FLAGS, but it
doesn't.  Maybe someone reading this would like to make it so.

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


edit a torrent file with python

2006-10-13 Thread di0rz`
hi,
I am looking for a python script to edit .torrent files
if anybody know one thx

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


Re: Converting MSWord Docs to PDF

2006-10-13 Thread Theerasak Photha
On 11 Oct 2006 02:10:38 -0700, Ant [EMAIL PROTECTED] wrote:

 Theerasak Photha wrote:
  On 10/11/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 ...
  (La)TeX is the king of document processing, and does PDF.

 Except that the OP want's to print Word documents as PDF. LaTeX is
 good, granted, but just try converting LaTeX documents to Word or vice
 versa...

Oh. But can't you just render Word documents to PostScript? And then
ps2pdf will pick up the rest of the slack. It might not even need
Python.

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


Re: Where is Python in the scheme of things?

2006-10-13 Thread Theerasak Photha
On 10/12/06, Magnus Lycka [EMAIL PROTECTED] wrote:

 I feel much more productive in bash than in most Windows apps.
 (I still like to have several terminal windows though.)

Perhaps you have used GNU screen. It's on my definitive list of winners.

(As an added bonus, using screen via SSH or---heaven forfend---telnet
will save you the bandwidth of having a million sessions open.)

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


Re: operator overloading + - / * = etc...

2006-10-13 Thread Bruno Desthuilliers
Terry Reedy wrote:
 Bruno Desthuilliers [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 Terry Reedy wrote:
 Bruno Desthuilliers [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 The current namespace object, of course.
 Implementing a namespace as a Python object (ie, dict) is completely
 optional and implementation dependent.  For CPython, the local namespace 
 of
 a function is generally *not* done that way.
 I know this, and that's not the point here. The op's question seemed to
 imply that the hypothetical __assign__ method should belong to the rhs
 object, which is obviously not the case - it must of course belongs to
 the lhs 'object'.
 
 And my point is that in general there is no lhs object for the method to 
 belong to.

nitpicking
Mmm... Of course, there's always something that's being used as a
namespace. But yes, this something may not be directly accessible as a
Python object.
/nitpicking.



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


Re: SOAPpy and callback

2006-10-13 Thread Paul McGuire
Diez B. Roggisch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 [EMAIL PROTECTED] schrieb:
 Hello,

 I'm trying to find how to use a callback in a SOAP client using SOAPpy.
 Does SOAPpy have to manage it, or does Python include some API to do
 it?

 I've never seen any callback mentioned in SOAP. Are you sure this is 
 possible with any SOAP implementation, at least standard-wise?

 Diez

This is most definitely possible, in fact it is the basis for a new 
asynchronous data collection standard for semiconductor equipment, Interface 
A (replacing the ancient SECS/GEM interface, originally designed to work 
over RS-232).  However, it is a major pain to implement.

As you suggest, you cannot do this from a simple browser or pure SOAP 
client.  To support SOAP callbacks, the client must also itself be a SOAP 
server.  The client sends its own callback server's URL to the primary 
server, and when callbacks are needed, they are sent to that callback URL. 
This really does get quite tricky, though.  For one thing, the vagaries of 
network identification make it unsure whether the URL composed by the client 
for its callback is meaningful/accessible to the server.

In addition, if you are considering implementing this over the untrusted 
internet, you should use SSL authentication both ways (although this further 
complicates your client).

-- Paul


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


Re: Starting out.

2006-10-13 Thread Ahmer
Thanks Paddy. That post pretty much cleared up everything for me.

On Oct 13, 12:46 am, Paddy [EMAIL PROTECTED] wrote:
 Ahmer wrote:
  Hi all!

  I am a 15 year old High School Sophomore. I would like to start
  programming in Python. In school, we are learning Java (5) and I like
  to use the Eclipse IDE, I also am learning PHP as well.

  What are some ways to get started (books, sites, etc.)? I am usually on
  linux, but I have a windows box and am planning on getting a mac.Pydev 
  gives you a Python mode for Eclipse:
  http://pydev.sourceforge.net/
 The Python tutorial is a good way to learn Python:
  http://docs.python.org/tut/
 Some pointers on writing Python for Java programmers:
  http://www.ferg.org/projects/python_java_side-by-side.html
 I guess you are new to both Java and Python, but if you know Java and
 were starting Python, the following points out that certain idioms of
 Java do not translate well to Python:
  http://dirtsimple.org/2004/12/python-is-not-java.html

 And finally: Lets 'big-up' Python:
  http://www.paulgraham.com/pypar.html

 I hope you enjoy Python.
 All the best,  Paddy.

 P.S. maybe your High school might be interested in teaching Python as a
 first language rather than Java?
  http://www.oreilly.com/pub/a/oreilly/frank/elkner_0300.html

 http://www.python.org/workshops/2000-01/proceedings/papers/elkner/pyY...

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


Loops Control with Python

2006-10-13 Thread Wijaya Edward

Can we make loops control in Python?
What I mean is that whether we can control
which loops to exit/skip at the given scope.
 
For example in Perl we can do something like:
 
OUT:
foreach my $s1 ( 0 ...100) {
   
IN:
foreach my $s2 (@array) {

  if ($s1 == $s2) {
 next OUT;
  }
  else {
  last IN; 
  } 
 
 }
}
 
How can we implement that construct with Python?
 
-- 
Edward WIJAYA
SINGAPORE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


Re: sufficiently pythonic code for testing type of function

2006-10-13 Thread Theerasak Photha
On 10/11/06, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 Theerasak Photha wrote:
  On 10/11/06, Fredrik Lundh [EMAIL PROTECTED] wrote:
 
  can be a lot better than a 30-level traceback that ends with a line
  looking something like
 
   fnut.index(gah)
 
  Despite long experience with Perl, I am not a big follower of the
  goose_level: blah method of error reporting...
 
  also, checking for __method__ is, in general, not the right way to check
  if an object implements a given interface.
 
  I had a vague feeling it might not be a Right Thing(tm).
  flame-proof-underwearI kind of miss
  responds_to?/flame-proof-underwear

 getattr(obj, name[,default]) is your friend. Remember that methods are
 just callable attributes.

I am familiar with getattr from the Introspection material in Dive
into Python of course.

Earlier in the thread we decided that using getattr is the Wrong
Way(tm) to decide whether an object has such and such operation
(respond_to?) because implementation details can hide this.

So I learned the best thing to do is Suck It And See (an electrical
joke, not a penis joke, BION) aka EAFP.

I just found out Ruby isn't much better in this regard:

class Foo
  def self.method_missing(meth, *args)
puts meth
  end
end

Foo.bar()
puts Foo.respond_to?(:bar)

===
bar
false

WTF?

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


Re: Starting out.

2006-10-13 Thread Ahmer
From what I can see Python and PHP have VERY simillar syntax (sorry if
I offended anyone but I am a n00b.)

On Oct 13, 12:54 am, [EMAIL PROTECTED] wrote:
 Ahmer wrote:
  Hi all!

  I am a 15 year old High School Sophomore. I would like to start
  programming in Python. In school, we are learning Java (5) and I like
  to use the Eclipse IDE, I also am learning PHP as well.

  What are some ways to get started (books, sites, etc.)? I am usually on
  linux, but I have a windows box and am planning on getting a mac.Generally 
  good choices. I don't prefer PHP, however. For somebody who
 is learning programming, it encourages sloppy programming.

 I would suggest that you use PyDev (http://pydev.sourceforge.net/), a
 Python plugin for Eclipse, for Python programming. It is a helpful
 environment, especially for somebody already using Eclipse.

 For resources, I suggest you take a look 
 athttp://wiki.python.org/moin/BeginnersGuide/NonProgrammerswhich is for
 non-programmers. If you feel like checking other resources, more are
 linked tohttp://wiki.python.org/moin/BeginnersGuide.
 
 Best luck,
 
 k

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


Best IDE?

2006-10-13 Thread Ahmer
What do you guys use?
Why?
What do you like and hate about it?
What platform(s) is it avalable on?
How much does it cost?
etc.

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


Line algorithim for python and numeric

2006-10-13 Thread bcdonovan
Hi everyone,

  I'm wondering if anyone knows of a way to extract data from a numeric
array along a line. I have a gridded dataset which I would like to be
able to choose two points and extract a 1-d array of the data values
along the line between the two points. Any ideas?

Thanks,
Brian

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


Re: Best IDE?

2006-10-13 Thread Theerasak Photha
On 13 Oct 2006 07:29:09 -0700, Ahmer [EMAIL PROTECTED] wrote:
 What do you guys use?
 Why?
 What do you like and hate about it?
 What platform(s) is it avalable on?
 How much does it cost?
 etc.

I use GNU Emacs 22 and a screen session.

Advantages:

* Comprehensive, comprehensive, comprehensive...tags support,
Subversion integration, syntax highlighting, sophisticated
indentation, whatever I want basically
* Resource-light, contrary to the preconceived opinions some have of Emacs
* Keyboard-oriented; ergonomic and fast (Xfce is set up to switch
desktops by key as well)
* Available on any major platform that you would want to use Python on
* And it's free

Disadvantages:

* No UI builder...for this you can use Glade or maybe Boa Constructor
* Not many else...none other that I can think of right now, actually

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


Re: Best IDE?

2006-10-13 Thread Bernard
IDE : SPE (Stani's python editor) : http://stani.be/python/spe/blog/
Why?: because this IDE is not complicated. it ships with a debugger, a
gui designer, a source code checker and a regex console.
Like: obviously everything
Hate: sometimes it doesn't start on windows 2000
Platform: Windows, Linux, Mac
cost: free but I'll donate some money because I like it

Ahmer wrote:
 What do you guys use?
 Why?
 What do you like and hate about it?
 What platform(s) is it avalable on?
 How much does it cost?
 etc.

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


Re: Best IDE?

2006-10-13 Thread BartlebyScrivener
Ahmer wrote:
 What do you guys use?
 Why?

http://tinyurl.com/ybg6p5

rd

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


Re: Line algorithim for python and numeric

2006-10-13 Thread Theerasak Photha
On 13 Oct 2006 07:33:17 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi everyone,

   I'm wondering if anyone knows of a way to extract data from a numeric
 array along a line. I have a gridded dataset which I would like to be
 able to choose two points and extract a 1-d array of the data values
 along the line between the two points. Any ideas?

Are these all 45 degree lines or what?

If not, you'll have to use trigonometry and approximate the closest
matching cell. (Don't worry, Python has maths functions!! :))

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


Re: Best IDE?

2006-10-13 Thread Theerasak Photha
On 13 Oct 2006 07:37:07 -0700, Bernard [EMAIL PROTECTED] wrote:
 IDE : SPE (Stani's python editor) : http://stani.be/python/spe/blog/
 Why?: because this IDE is not complicated. it ships with a debugger, a
 gui designer, a source code checker and a regex console.
 Like: obviously everything
 Hate: sometimes it doesn't start on windows 2000
 Platform: Windows, Linux, Mac
 cost: free but I'll donate some money because I like it

Will definitely give it a look.

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


Re: Python Newbie question

2006-10-13 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Is it possible to combine or bundle separate .exe files into the
 compiled python .exe when using py2exe? If possible, how would that be
 described within setup.py . and how/where would I specify such .exe
 should be ran first in the pre-compiled scripts? My goal is to get the
 total package down to as few files as possible, so I appreciate
 understanding how I could do this. The .exe is some low-level commands
 that was compiled in a separate language but I hope this little
 .exe can be included gracefully. Thank you for your expertise! :) AMYMC
 
Do this with the installer instead of with py2exe.  Take a look at
Inno Setup (http://www.jrsoftware.org/isinfo.php).  With it you can put
as many files (.exe or otherwise) and have supporting .exe's run in any
order you wish (after installation).  This was you have only 1 file
(setup.exe) that needs to be distributed.  Doesn't really matter ho
many files it installs when it runs, that's all hidden from the user
anyway.

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


Re: edit a torrent file with python

2006-10-13 Thread Iain King

di0rz` wrote:
 hi,
 I am looking for a python script to edit .torrent files
 if anybody know one thx

Not sure exactly what you are looking for, but the original bittorrent
client is written in Python, so you could grab a copy of it and check
the code.

Iain

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


Re: always raise syntax error!

2006-10-13 Thread Larry Bates
daniel wrote:
 thank you so much for the reply.
 
 I finally re-type all the codes where python would raise syntax error,
 then fixed. I did not examine every single word of my old codes though,
  there might be some parenthesis not matching somewhere, I guess.
 
 well, I would say, the reason why I could not position the error code
 may partly due to the ambiguous message that python provides. the lines
 that python pointed to contains no error,  I think the error codes must
 be too far away from there. anyway, I hope python would make more
 detailed error messages, like c++ compilers do. such as: missing ; or
 ( not matching...etc.
 
 tks again..
 
 daniel
 
What Steve is trying to tell you is that you need to copy/paste your
code (with the full traceback) in future messages.  We are not mind
readers out here.

Occassionally I will have phantom syntax errors that seem to be
attributable to non-printing characters in a line.  Other times the
error is in fact far above the place pointed to by the syntax error.
Start by commenting out large chunks of code with triple quotes and
slowly work towards the lines with a problem.

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


Re: Problems with Python 2.5 installer.

2006-10-13 Thread paw
  Could this happen if c:\python does not exists and creating it fails for
  some reason, or if permissions are incorrect?

 Are you installing it as a normal user or as an Administrator? I have
 occasionally had problems (not when installing Python) as a normal
 user not being allowed to create a folder at the C:\ level.

 I'd suggest this;
 (1) log on as as administrator (i.e. with full rights)
 (2) do an all users installation
 (3) You haven't come up with a good reason for doing otherwise, so read
 my lips: *** use the default installation folder C:\Python25 *** you'll
 be happy you did, when Python 2.6 comes out and you want to have both
 installed.

It turns out the domain admin took away my local admin rights
mistakenly.  Once I got those back everything worked fine.

The only 'logic' for my not installing to a directory with the version
is that I don't keep more than one version of Python on my system at
any given time.  When the new version comes out and is stable I remove
the old one, this forces me to check any programs against the latest
version.

Thanks for all of the help,

Wayne

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


Re: Line algorithim for python and numeric

2006-10-13 Thread Tim Chase
   I'm wondering if anyone knows of a way to extract data from a numeric
 array along a line. I have a gridded dataset which I would like to be
 able to choose two points and extract a 1-d array of the data values
 along the line between the two points. Any ideas?
 
 Are these all 45 degree lines or what?
 
 If not, you'll have to use trigonometry and approximate the closest
 matching cell. (Don't worry, Python has maths functions!! :))


There are a couple of optimal/easy cases where the run is 
horizontal, vertical, or as you describe, 45-degrees (where 
x_step = y_step or x_step = -y_step)

Any other set of arbitrary points, and you will have to specify 
the behavior a little more finely.

You can use something like Bresenham's algorithm to march either 
over or up and over to just pick out the one point at each 
step that falls closest to the actual line along the run. 
There's also the Wu Anti-aliasing line algorithm which takes 
something akin to Bresenham's algorithm and then samples the 
potential points to yield an anti-aliased result which averages 
the two potential  data-points (traditionally colors, but they 
could really be any average-able data values).

I'm not sure I've seen either of them implemented in Python 
before (though actually *looking* for them might increase those 
odds ;-)

http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm

has details and a pseudo-code implementation (which shouldn't be 
too far from the Python code).  It's also got links to stuff on 
Bresenham's.

-tkc


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


Re: Converting MSWord Docs to PDF

2006-10-13 Thread Grant Edwards
On 2006-10-13, Theerasak Photha [EMAIL PROTECTED] wrote:
 On 11 Oct 2006 02:10:38 -0700, Ant [EMAIL PROTECTED] wrote:

 Theerasak Photha wrote:
  On 10/11/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 ...
  (La)TeX is the king of document processing, and does PDF.

 Except that the OP want's to print Word documents as PDF.
 LaTeX is good, granted, but just try converting LaTeX
 documents to Word or vice versa...

OpenOffice will print directly to PDF, and it does a fair job
of opening MS Word documents.  I don't know if you can control
OOo directly from Python or print from the command line (OOo
doesn't seem to have a man page).

 Oh. But can't you just render Word documents to PostScript?

Yes.

 And then ps2pdf will pick up the rest of the slack.

Yes. 

That's how the various free PDF printer drivers for Windows work.

 It might not even need Python.

Not unless you're trying to automate the process somehow.

-- 
Grant Edwards   grante Yow!  I wish I was a
  at   sex-starved manicurist
   visi.comfound dead in the Bronx!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-13 Thread val bykoski
Peter Wang wrote:
 Edward,
 
 This isn't in response to any specific one of the 100+ posts on this
 thread, but I justed wanted to encourage you to continue your
 investigation into Python component models and maybe looking for some
 common ground between them.  Frequently the individual developers are
 too heads-down on working on their own things to do a broad survey, so
 I think this would be very useful indeed.
 
 I wouldn't have felt it necessary to post this except for the large
 number of posts along the lines of foo.dict is introspective enough
 for me!.  I think you might have an easier time evangelizing the
 principle of component-oriented programming (or event-based, or
 reactive, or whatever) if you separated it from the notions of RAD UI
 development.  There is a very large difference between writing
 components and writing objects, and it seems that most people arguing
 python doesn't need components don't see this distinction.
 
 For me, it's the difference between writing live objects and dead
 objects.  Live objects not only encapsulate implementations of an
 interface with some state, but they also encapsulate handling of
 events, i.e. responses to changes in their environment.  Dead objects
 have methods but there has to be a function somewhere that knows which
 dead object to call with what parameters at exactly the right time.
 (The only mechanism for managing this complexity is to create ever more
 functions at ever higher levels of abstraction, or to have a
 proliferation of nebulously-defined manager objects.)  IMHO once you
 cross this chasm and are able to model your problem domain with live
 objects that go off and automatically respond to the runtime
 environment and Do the Right Thing, it's very hard to go back to a dead
 object mindset.  I can understand, however, that until one makes this
 leap, it might seem like an academic and useless distinction.
 
 -peter
 
Excellent post, Peter.  Thanks for great clarification. Looking from a
physicist' perspective, im always trying to compare/evaluate languages
from the physical reality/dynamics angle.  So, the run-time
space/dynamics is the only one that matches the natural always-runtime
objects - atoms, molecules, EM fields, biological cells(?).  It is the
*reactive* world with event/forces-driven dynamics.  Seemingly, there is
nothing beyond that, including biology.

The essential feature of that runtime world is the persistence or (in
physical terms) the built-in memory/storage mechanism (soft degrees of
freedom), so that an event (and response to it) changes the object.  The
persistence is obvious in biology, but also is very important in
(bio)molecular dynamics.   From that physics/QM angle, a generic
(always-live) object  which learns the environment (by building *and
updating* its responses) seems to be a quite adequate representation for
a real physical object.  But this seems to be already available in
Python, right?

The Enthought' Traits that describes (physical) properties and their
dynamics seems to be a critically important component of that vision,
and i admire the Enthought' people vision and practical efforts.  Keep
on and good luck!
run-time-ly, y'rs

Val
Air Force Research Lab
Hanscom AFB, MA
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best IDE?

2006-10-13 Thread Grant Edwards
On 2006-10-13, Ahmer [EMAIL PROTECTED] wrote:

 What do you guys use?

jed along with bash et. al.

 Why?

Because it's efficient and it's what I use for all other
languages.

 What do you like and hate about it?

If there was something I hated about it, I wouldn't use it.

 What platform(s) is it avalable on?

Unix/Linux and Win32.

 How much does it cost?

Nothing.

 etc.

42

-- 
Grant Edwards   grante Yow!  I'd like TRAINED
  at   SEALS and a CONVERTIBLE on
   visi.commy doorstep by NOON!!
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >