Twisted vs POS (Plain-old sockets)

2006-09-03 Thread Darren Kirby
Hey all,I have a (FOSS) project here that I am about to start that requires TCP networking support, and in fact, will require me to design and implement a (text based) protocol from scratch.I have been playing with Twisted today and managed to get a simple 
client/server talking to each other. However, the twisted framework does seem very complex, and includes many, many, features I will never need. The docs seem a little lacking (or perhaps just confusing) as well. Twisted's good 
points are that it will save me from having to write many things from scratch, asynchronous networking being the biggie.I guess I am wondering if given the fact I need a custom protocol, and need to talk TCP/IP should I stick with twisted or just use plain old sockets and 
build it myself? Is there a third option I should consider? Have others found themselves in this situation? Thoughts? Comments? I am really just fishing for opinions here...If it makes a difference: Depending on performance parts of this app may well 
end up as a prototype for a final (...alternative?) C++ implementation.Thanks for consideration, -d-- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."- Dennis Ritchie and Ken Thompson, June 1972
-- 
http://mail.python.org/mailman/listinfo/python-list

User defined functions through Automation in Excel 2003

2006-09-03 Thread jpgreenwald
Hi all,

Im trying to create user defined functions (ones that you can use in
the cells of excel) in python.  I know that its a ...dumb... thing to
do since its a lot easier in other languages (vb,c#, vc..etc) but Im
stuck on seeing if I can get this to work.  Currently I have written a
simple script:

class jtest:
_public_methods_ = ['Add2']
_reg_clsid_ = "{27A888AA-B5DB-44BE-BBA7-DECF3A1DF861}"
_reg_progid_ = "jtest.Excel"

def Add2(x, y):
return x+y

and compiled it to a dll with py2exe and created the registry entry in

HKCR\CLSID\{xxxGUIDxxx}\Programmable\

so that excel can pick it up and it loads no problem when selecting it
from the automation add-in menu.  However thats all it does.  I cant
seem to be able to call the function or do anything with it.  Im sure
there is a lot more thats needed than what im doing but documentation
is scarce.  Thanks for any help or insight that can be offered.

-Jesse

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


Re: CONSTRUCT -

2006-09-03 Thread Georg Brandl
lazaridis_com wrote:
> I would like to fulfill the following task:
> 
> The construct:
> 
> if __name__ == '__main__':
> 
> should be changed to something like:
> 
> if identifier.name == '__main__':
> 
> The term "identifier" should be selected based on the meaning of the
> __double-underscore-enclosure__ of the entities.
> 
> -
> 
> What I would need to know is:
> 
> a) what would be the correct term for "identifier"?

import sys
class _identifier:
def __getattr__(self, name):
return sys._getframe(1).f_globals['__%s__' % name]
identifier = _identifier()

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


Re: python loops

2006-09-03 Thread Fredrik Lundh
Tim Roberts wrote:

> xrange used to be better.  As I understand it, that's no longer
 > the case.

for short ranges, range is faster in some Python versions, xrange is 
faster in some (including 2.4).  the difference is usually very small 
(the same number of objects are created in both cases).

for long ranges, especially when it's likely that you won't actually 
need all the values, xrange is better.

if you *need* a list, range is better.

in python 3.0, range will return an iterator, and xrange will disappear. 
  if you need a list in 3.0, you will have to do list(range(N)).



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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Sybren Stuvel wrote:
> Tor Erik enlightened us with:
>> The reason is that my application does about 16 connects and data
>> transfers per second, to the same 16 remote hosts. After approx 200
>> secs there are 4000 sockets waiting to be garbage collected by the
>> OS.
> 
> Which OS are we talking about?

Windows XP

> 
>> At this point is seems that connect loops and starts using the same
>> local addresses it used 4000 connections ago, resulting in an
>> "Address already in use" exception.
> 
> After how many seconds does this happen?

200 seconds approx

> 
>> My question is if there are any other methods of solving this? Maybe
>> a socket option of some sort...
> 
> If I'm correct (please correct me if I'm not), on Linux you can use
> 'sysctl -w net.ipv4.tcp_fin_timeout=X' to set the time between closing
> the socket and releasing it to be reused. You can also check the
> SO_REUSEADDR argument to the setsockopt function. Read 'man 7 socket'
> for more info.

I've read about SO_REUSEADDR. As far as I understand, this is what 
SO_REUSEADDR is for:

1. Allow a listening socket to bind itself to its well-known port even 
if previously established connections use it as their local port. 
Setting this option should be done between calls to socket and bind, and 
hence is only usable for listening sockets, not client sockets like mine.

2. Allow multiple servers on the same host with different ip-adresses to 
listen to the same port.

I've tried setting this option, but could not see any notable changes...

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


Re: overriding character escapes during file input

2006-09-03 Thread John Machin

John Machin wrote:
> David J Birnbaum wrote:
> > Dear Python-list,
> >
> > I need to read a Unicode (utf-8) file that contains text like:
> > > blah \fR40\fC blah
> > I get my input and then process it with something like:
> > > inputFile = codecs.open(sys.argv[1],'r', 'utf-8')
> > >
> > > for line in inputFile:
> > When Python encounters the "\f" substring in an input line, it wants to
> > treat it as an escape sequence representing a form-feed control
> > character,
>
> Even if it were as sentient as "wanting" to muck about with the input,
> it doesn't. Those escape sequences are interpreted by the compiler, and
> in other functions (e.g. re.compile) but *not* when reading a text
> file.
>
> Example:
> |>>> guff = r"blah \fR40\fC blah"
> |>>> print repr(guff)
> 'blah \\fR40\\fC blah'
> |>>> # above is ASCII so it is automatically also UTF8
>
> Comment: It contains backslash followed by 'f' ...
>
> |... fname = "guff.utf8"
> |>>> f = open(fname, "w")
> |>>> f.write(guff)
> |>>> f.close()
> |>>> import codecs
> |>>> f = codecs.open(fname,'r', 'utf-8')
> |>>> guff2 = f.read()
> |>>> print guff2 == guff
> |True
> No interpretation of the r"\f" has been done.
>
> > which means that it gets interpreted as (or, from my
> > perspective, translated to) "\x0c". Were I entering this string myself
> > within my program code, I could use a raw string (r"\f") to avoid this
> > translation, but I don't know how to do this when I am reading a line
> > from a file.
>
> What I suggest you do is:
>print repr(open('yourfile', 'r').read()
> [or at least one of the offending lines]
> and inspect it closely. You may find (1) that the file has formfeeds in
> it or (2) it has r"\f" in in it and you were mistaken about the
> interpretation or (3) something else.
>
> If you maintain (3) is the case, then make up a small example file,
> show a dump of it using print repr(.) as above, plus the (short)
> code where you decode it and dump the result.
=
On 3/09/2006 3:53 PM, David J Birnbaum wrote in e-mail:
> Dear John,
>
> Thank you for the quick response. Ultimately I need to remap the "f" in
> "\f" to something else, so I worked around the problem by doing the
> remapping first, and I'm now getting the desired result.
>

Please reply on-list.

How could you read the file to remap an "f" if you were getting '\0x0C'
when you tried to read it? Are we to assume that it was case (2) i.e.
not a Python problem?

Cheers,
John

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


Re: python loops

2006-09-03 Thread Fredrik Lundh
Nicko wrote:

> There's a huge difference between not being profligate with resources
> and premature optimisation. In the case of the idiom "for i in
> range(x):..." there absolutely no utility whatsoever in creating and
> recording the list of objects. Unless it makes a difference to code
> structure or maintainability, I think that not creating stacks of
> objects you don't need is basic code hygiene and not freakish premature
> optimisation.

for short lists, both objects create the *same* number of objects.

if you cannot refrain from pulling arguments out of your ass, you not 
really the right person to talk about hygiene.



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


Re: Problem loading true-type font with PIL - "solved"

2006-09-03 Thread Fredrik Lundh
Christian Stapfer wrote:

> Problem "solved" by rudely installing PIL 1.1.5 for Windows and
> Python 2.4 from http://www.pythonware.com/products/pil/
> right on top of my existing "Python Enthought Edition--Python
> 2.4.3 for Windows". This might have destroyed the consistency
> of the overall installation, of course. I'm well punished
> for installing Enthought Python 2.4.3: Next time I will again
> install all packages that I need myself, as I did for Python
> 2.3, instead of using a prepackaged distribution like Enthought
> Python.

Since the truetype extension is quite popular, and from what I'm told 
worked just fine in earlier Enthought releases, this is probably just an 
accidental omission.  I'm sure the Enthought people will fix this if you 
report it to them.



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


Re: How to run Python file?

2006-09-03 Thread Steve Holden
mistral wrote:
> I have installed ActivePython
> http://www.activestate.com/Products/ActivePython/
> How I can run Python file, test.py?
> 
Sheesh, you must have had ten replies and nobody bothered to point you 
to the frequently-asked questions ... kids today!

   http://www.python.org/doc/faq/windows.html

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: Find the best price on gas in your local area for FREE....

2006-09-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> I hate cars and would perfer not to be harrased by those who support
> irans energy policy..
> 
> http://www.dexrow.com
> [EMAIL PROTECTED] wrote:
> 
>>Visit the web site below to see where you can buy the cheapest gas in
>>your local area.  Just punch in your zip code and all the work is done
>>for you.  No Cost!   Absolutely FREE info.
>>
>>http://redacted
> 
> 

Great. So thanks to your intemperate response Google now contains two 
copies of that link instead of the original one. Perhaps you'd like to 
add links to other things you dislike?

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: python loops

2006-09-03 Thread Nicko
Fredrik Lundh wrote:
> Nicko wrote:
>
> > ... In the case of the idiom "for i in
> > range(x):..." there absolutely no utility whatsoever in creating and
> > recording the list of objects.
>
> for short lists, both objects create the *same* number of objects.

This is true for long lists too, if you iterate over the full range,
but what I wrote was "creating and recording". The range() function
generates a variable-sized, potentially large object and retains all of
the items in the range while xrange() generates a fairly small, fixed
sized object and only hangs on to one item at a time.  Furthermore,
it's not at all uncommon for loops to be terminated early. With range()
you incur the cost of creating all the objects, and a list large enough
to hold them, irrespective of if you are going to use them.

> if you cannot refrain from pulling arguments out of your ass, you not
> really the right person to talk about hygiene.

I'm impressed but your mature argument. Clearly, in the face of such
compelling reasoning, I shall have to concede that we should all
generate our range lists up front.

Nicko

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


Re: Problem loading true-type font with PIL - "solved"

2006-09-03 Thread Robert Kern
Fredrik Lundh wrote:
> Christian Stapfer wrote:
> 
>> Problem "solved" by rudely installing PIL 1.1.5 for Windows and
>> Python 2.4 from http://www.pythonware.com/products/pil/
>> right on top of my existing "Python Enthought Edition--Python
>> 2.4.3 for Windows". This might have destroyed the consistency
>> of the overall installation, of course. I'm well punished
>> for installing Enthought Python 2.4.3: Next time I will again
>> install all packages that I need myself, as I did for Python
>> 2.3, instead of using a prepackaged distribution like Enthought
>> Python.
> 
> Since the truetype extension is quite popular, and from what I'm told 
> worked just fine in earlier Enthought releases, this is probably just an 
> accidental omission.  I'm sure the Enthought people will fix this if you 
> report it to them.

https://svn.enthought.com/enthought/ticket/864

The person who builds the Enthought Edition releases is out on vacation this 
week, so a new release will probably wait until he comes back. In the meantime, 
installing Fredrik's binaries on top of ours should work just fine.

-- 
Robert Kern

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

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


ftputil protection

2006-09-03 Thread vedran_dekovic
Hi,
For people who using ftputil:

Have ftputil any protection(SSL..) or any other protection?









 THANKS

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


Re: CONSTRUCT -

2006-09-03 Thread Fredrik Lundh
Simon Forman wrote:

> I'm sorry, your post makes very little sense.

you're somewhat new here, right ? ;-)



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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread keegan . csmith
> I've read about SO_REUSEADDR. As far as I understand, this is what
> SO_REUSEADDR is for:
...
> I've tried setting this option, but could not see any notable changes...

I was having a similiar problem as you, where as soon as my program
exited, it would get started up again, but could not bind to the same
address.
So i added the follow straight after I create my server object:
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

And it worked. Note that my program was running on Linux, so this might
be a windows issue.

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Fredrik Lundh
Tor Erik wrote:

> The reason is that my application does about 16 connects and data 
> transfers per second, to the same 16 remote hosts. After approx 200 secs 
> there are 4000 sockets waiting to be garbage collected by the OS.

what does "netstat" say about these sockets ?



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


Re: Tkinter listbox and ftputil

2006-09-03 Thread Hendrik van Rooyen
 <[EMAIL PROTECTED]> wrote by email:

Please keep it on the list...

| Hi,
| Hi and Thanks for all your help,everything work.But I have one
| question,in string I am "new",and I don't know how to exactly split:
|
| example:
|
| '-rw-r--r--   1 [EMAIL PROTECTED]
| v-programs.byethost31.com 2376 Aug 28 08:48 sun.gif'
|
|
| in new entry must write just filename:  sun.gif not:
|
| '-rw-r--r--   1 [EMAIL PROTECTED]
| v-programs.byethost31.com 2376 Aug 28 08:48 sun.gif'
|
|  so can you help to I split:
|
| '-rw-r--r--   1 [EMAIL PROTECTED]
| v-programs.byethost31.com 2376 Aug 28 08:48 sun.gif'   from that
| import just: sun.gif
|
|   THANK
| YOU!!

IDLE 1.1.3   No Subprocess 
>>> NameOfString = '-rw-r--r--   1 [EMAIL PROTECTED]
v-programs.byethost31.com 2376 Aug 28 08:48 sun.gif'
>>> NameOfList = NameOfString.split()
>>> print NameOfList[:]
['-rw-r--r--', '1', '[EMAIL PROTECTED]',
'v-programs.byethost31.com', '2376', 'Aug', '28', '08:48', 'sun.gif']
>>> print NameOfList[-1]
sun.gif
>>>

That should see you on yer way... - Have you read the tutorial?

You should also learn to use the interactive interpreter - it is your friend...

- Hendrik



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


Re: IndentationError: expected an indented block

2006-09-03 Thread Hendrik van Rooyen
 "Georg Brandl" <[EMAIL PROTECTED]> Wrote:


| [EMAIL PROTECTED] wrote:
| > Hendrik van Rooyen wrote:
| >> <[EMAIL PROTECTED]> Wrote:
| >>
| >>
| >> |
| >> | Haha. How can I fix this!
| >> |
| >> |
| >> |
| >>
| >> Use either tabs, or spaces, but not both
| >>
| >> - Hendrik
| > 
| > Haha. I know. I just find it silly that a language insists on
| > indentation. I'd long known it but just was reminded of it when I
| > messed a little with the interpreter.
| 
| Let me tell you that we've had far better trolls.
| 
| Georg

 *grin* - I can't complain, having trolled myself...

- Hendrik


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


Re: Problem loading true-type font with PIL - "solved"

2006-09-03 Thread Christian Stapfer
Robert Kern wrote:
> Fredrik Lundh wrote:
>> Christian Stapfer wrote:
>>
>>> Problem "solved" by rudely installing PIL 1.1.5 for Windows and
>>> Python 2.4 from http://www.pythonware.com/products/pil/
>>> right on top of my existing "Python Enthought Edition--Python
>>> 2.4.3 for Windows". This might have destroyed the consistency
>>> of the overall installation, of course. I'm well punished
>>> for installing Enthought Python 2.4.3: Next time I will again
>>> install all packages that I need myself, as I did for Python
>>> 2.3, instead of using a prepackaged distribution like Enthought
>>> Python.
>>
>> Since the truetype extension is quite popular, and from what I'm told
>> worked just fine in earlier Enthought releases, this is probably just an
>> accidental omission.  I'm sure the Enthought people will fix this if you
>> report it to them.
>
> https://svn.enthought.com/enthought/ticket/864
>
> The person who builds the Enthought Edition releases is out on vacation
> this week, so a new release will probably wait until he comes back. In the
> meantime, installing Fredrik's binaries on top of ours should work just
> fine.

Great! - if it does. (Your words in God's ear...) Sorry about leaving out
some details about the release I installed. Maybe the following helps?

C:\Python24\Enthought\Doc>python
Python 2.4.3 - Enthought Edition 1.0.0 (#69, Aug  2 2006, 12:09:59) [MSC
v.1310 32 bit (Intel)] on win32

Perhaps not. Since I have already deleted the Windows installer, and do not
know of any other way to get Enthought-specific version info, this is all I 
can
offer at the moment... (I had downloaded the installer from
http://code.enthought.com/enthon/
on August 31, around 06:00 GMT. I suppose this means that it was
enthon-python2.4-1.0.0.exe, but cannot verify anymore whether it was this
specific installer that I used - or not.)

Best regards and thanks for your reply,
Christian Stapfer

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


Re: OO on python real life tutorial?

2006-09-03 Thread Claudio Grondi
Patrick Thomson wrote:
>>I personally don't like wxPython because the way it works is very
>>counter intuitive for me and appear to me somehow non-Pythonic
> 
> 
> While Claudio has a point (wxPython is a C++ library at heart), I
> believe that wxPython is the best solution for Python GUI's out there.
> TK may be a lot easier, but with a little practice wxPython becomes
> very clear, and the skills you learn therein will be applicable to
> almost any other GUI toolkit out there (Swing and SWT were far, far
> easier to learn thanks to my wxPython experience.) After all, GvR said
> that "wxPython is the best and most mature cross-platform GUI toolkit,
> given a number of constraints. The only reason wxPython isn't the
> standard Python GUI toolkit is that Tkinter was there first."
> 
> The Wax toolkit (http://zephyrfalcon.org/labs/wax.html) attempts to
> solve the problems inherent with wxPython and make it more pythonic.
> I've never used it, so I don't know if it succeeds.
> 
> 
>>wxPython is like programming in Microsoft Visual Basic or Visual C++ :
>>some love it, some don't.
> 
> 
> Though that is true, I don't think that the analogy holds up at all.
> The power of wxPython lies in its attractiveness across all platforms
> and the freedom that it gives you; VB and VC++ lock you in what
> Microsoft want you to do. (To be fair, that isn't a Bad Thing by
> definition.)
> 
> 
>>>I want to switch to wxpython because I don't like Tk too much. It is
>>>difficult sometimes to have full control of the widgets (i.e. focus
>>>sequence). Why do you think wxwidget is not suitable for low-medium
>>>size projects? Could you give me some practical examples of this?
> 
> 
> I respectfully disagree with Grondi's opinions; a list of notable
> wxPython projects (http://wiki.wxpython.org/index.cgi/wxPythonPit_Apps)
> showcases projects both small and expansive.
What I can't understand here is, with which of my opinions you disagree 
as one line below of my posting (you are responding to) I write: "I 
haven't said, that it is not suitable [for low-medium
size projects]." ...

By the way: why is it so hard to develop a wxPython application which 
runs with any wxPython version? Are the subsequent wxPython versions by 
definition not compatible or do only the quirks change from release to 
release being shifted between the problem zones?

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


Building Python with non-traditional paths

2006-09-03 Thread djbclark
Is there a clean way to build Python under a non-traditional path,
linking with other software that is under non-traditional paths, on
unix?

I maintain a build of Python [1] that is part of a self-contained
bundle of software [2] to run bcfg2 [3].

The major problem I am having is getting the build to link to the
openssl libraries, which are installed under /usr/local/lib/bcfg2/lib;
I tried (on GNU/Linux):

LDFLAGS="-L/usr/local/lib/bcfg2/lib
-Wl,-rpath,/usr/local/lib/bcfg2/lib"
CPPFLAGS="-I/usr/local/lib/bcfg2/include"

but that didn't work. The only thing I could do to get it to work
(sometimes) was to edit the setup.py file directly before the
./configure; make; make install like this:

cat setup.py \
| sed s:\/usr\/local\/:\/usr\/local\/lib\/bcfg2\/:g \
| sed
s:\/usr\/local\/lib\/bcfg2\/ssl\/include:\/usr\/local\/lib\/bcfg2\/include:g
\
| sed
s:\/usr\/contrib\/ssl\/include\/:\/usr\/local\/lib\/bcfg2\/include\/openssl\/:g
\
| sed
s:\/usr\/local\/lib\/bcfg2\/ssl\/lib:\/usr\/local\/lib\/bcfg2\/lib:g \
> setup.py.bcfg2
mv setup.py.bcfg2 setup.py

However that is rather ugly, and modifies the source which I'd rather
not do. Is there a better/cleaner way?

[1] Complete build spec for Python for Bcfg2
http://www.bcfg2.org/browser/trunk/bcfg2/encap/src/encap-profiles/bcfg2-python-2.4.3.ep

[2] Bcfg2 Encap Packages - Overview
http://www.bcfg2.org/wiki/EncapPackages

[3] Bcfg2 - Provides a declarative interface to system configuration
http://www.bcfg2.org

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Steve Holden
[EMAIL PROTECTED] wrote:
>>I've read about SO_REUSEADDR. As far as I understand, this is what
>>SO_REUSEADDR is for:
> 
> 
> 
>>I've tried setting this option, but could not see any notable changes...
> 
> 
> I was having a similiar problem as you, where as soon as my program
> exited, it would get started up again, but could not bind to the same
> address.
> So i added the follow straight after I create my server object:
> server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> 
> And it worked. Note that my program was running on Linux, so this might
> be a windows issue.
> 
... and note also that your program was apprently a server, while the OP 
was reporting an error on a client program that presumably asks for an 
ephemeral port rather than a specifically-numbered one.

Since there are roughly 64,000 ports, the real question seems to be why 
his client runs out after about 4,000.

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: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Fredrik Lundh wrote:
> Tor Erik wrote:
> 
>> The reason is that my application does about 16 connects and data 
>> transfers per second, to the same 16 remote hosts. After approx 200 
>> secs there are 4000 sockets waiting to be garbage collected by the OS.
> 
> what does "netstat" say about these sockets ?
> 
> 
> 

They are in the TIME_WAIT state... The msn library has an article on how 
to solve this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/BTS06CoreDocs/html/6987640c-1d80-4fbf-b43a-021fc8ba06a4.asp

Summing up one could either:

1. Increase the upper range of ephemeral ports that are dynamically 
allocated to client TCP/IP socket connections:

set registry key: 
KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort
to a new DWORD value... (5000 - 65534)
The default in XP is 3976 -> http://support.microsoft.com/kb/Q149532

or

2. Reduce the client TCP/IP socket connection timeout value from the 
default value of 240 seconds

set registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTimedWaitDelay
to a new DWORD value (30 - 300)

The TCP RFC (RFC 793) recommends a value of 2*msl(Maximum Segment 
Lifetime). The general consensus about the value of msn seems to be 1-2 
minutes, depending on the underlying network... (2*2 min = 2*120 sec = 
240 sec)


I do not want to alter my registry, so I'm currently testing an idea 
where I let the client connect and send its content, appended with my 
own "magic" EOF byte-sequence. When the server receives this EOF, it 
takes care to close the connection. This should eliminate the problem as 
it is the peer closing the connection that enters the TIME_WAIT state...

I will report my experiences...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python loops

2006-09-03 Thread Steve Holden
Nicko wrote:
> Fredrik Lundh wrote:
> 
>>Nicko wrote:
>>
>>
>>>... In the case of the idiom "for i in
>>>range(x):..." there absolutely no utility whatsoever in creating and
>>>recording the list of objects.
>>
>>for short lists, both objects create the *same* number of objects.
> 
> 
> This is true for long lists too, if you iterate over the full range,
> but what I wrote was "creating and recording". The range() function
> generates a variable-sized, potentially large object and retains all of
> the items in the range while xrange() generates a fairly small, fixed
> sized object and only hangs on to one item at a time.  Furthermore,
> it's not at all uncommon for loops to be terminated early. With range()
> you incur the cost of creating all the objects, and a list large enough
> to hold them, irrespective of if you are going to use them.
> 
> 
>>if you cannot refrain from pulling arguments out of your ass, you not
>>really the right person to talk about hygiene.
> 
> 
> I'm impressed but your mature argument. Clearly, in the face of such
> compelling reasoning, I shall have to concede that we should all
> generate our range lists up front.
> 
I'm impressed that you think any of this will be news to the effbot, 
whose sagacity is exceeded only by his irritability in the face of 
ignorance.

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: How to run Python file?

2006-09-03 Thread mistral

Steve Holden писал(а):

> mistral wrote:
> > I have installed ActivePython
> > http://www.activestate.com/Products/ActivePython/
> > How I can run Python file, test.py?

> Sheesh, you must have had ten replies and nobody bothered to point you
> to the frequently-asked questions ... kids today!

>http://www.python.org/doc/faq/windows.html

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

Really, looks its clear and straightforward Python FAQ. 

thanks.

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

Re: How to run Python file?

2006-09-03 Thread bearophileHUGS
mistral:
> I have installed ActivePython
> http://www.activestate.com/Products/ActivePython/
> How I can run Python file, test.py?

Running Python scripts is easy. Load the test.py from the ActivePython
and run it.
Otherwise you can just click on the file, otherwise you can open a
shell in the dir where your py file is, and you can enter its name (so
you can see its textual output). Tell us what happens and
errors/problems you have.

Bye,
bearophile

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


Re: User defined functions through Automation in Excel 2003

2006-09-03 Thread jpgreenwald
Ive been looking more into this subject and now have a few things to
add.  Im using some c# code that works in doing what I want (adds the
function into excel):

using System;
using System.Runtime.InteropServices;

namespace jtest {
[ClassInterface(ClassInterfaceType.AutoDual)]
public class test{
public test(){
}
public double Add2(double x, double y) {
return v1 + v2;
}
}
}

I messed arround with it and without
"[ClassInterface(ClassInterfaceType.AutoDual)]" the same thing happens
that happened in python;  the dll would load but the function is not
usuable.  So reading some more I was *thinking* that it was the early
bound calls allowed by the AutoDual Interface that I cant seem to easy
replicate in python.  Now I was *thinking* again that the only way to
replicate that would be to use a typelib but I do not know how to
generate that using a idl file I dont know how to create.  Again I was
*thinking* that if I had a typelib I could use makepy and then gencache
so when I use py2exe the typelib would be used and early bound calls
would be used.

Am I completely Insane and following a completely wrong thought process
here?  If not, how do I make a idl file (then use midl.exe ?), and then
make a tbl?  Thanks again for your thought.

-Jesse

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Tor Erik
Tor Erik wrote:
> Fredrik Lundh wrote:
>> Tor Erik wrote:
>>
>>> The reason is that my application does about 16 connects and data 
>>> transfers per second, to the same 16 remote hosts. After approx 200 
>>> secs there are 4000 sockets waiting to be garbage collected by the OS.
>>
>> what does "netstat" say about these sockets ?
>>
>> 
>>
> 
> They are in the TIME_WAIT state... The msn library has an article on how 
> to solve this:
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/BTS06CoreDocs/html/6987640c-1d80-4fbf-b43a-021fc8ba06a4.asp
>  
> 
> 
> Summing up one could either:
> 
> 1. Increase the upper range of ephemeral ports that are dynamically 
> allocated to client TCP/IP socket connections:
> 
> set registry key: 
> KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort
>  
> 
> to a new DWORD value... (5000 - 65534)
> The default in XP is 3976 -> http://support.microsoft.com/kb/Q149532
> 
> or
> 
> 2. Reduce the client TCP/IP socket connection timeout value from the 
> default value of 240 seconds
> 
> set registry key:
> HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTimedWaitDelay
>  
> 
> to a new DWORD value (30 - 300)
> 
> The TCP RFC (RFC 793) recommends a value of 2*msl(Maximum Segment 
> Lifetime). The general consensus about the value of msn seems to be 1-2 
> minutes, depending on the underlying network... (2*2 min = 2*120 sec = 
> 240 sec)
> 
> 
> I do not want to alter my registry, so I'm currently testing an idea 
> where I let the client connect and send its content, appended with my 
> own "magic" EOF byte-sequence. When the server receives this EOF, it 
> takes care to close the connection. This should eliminate the problem as 
> it is the peer closing the connection that enters the TIME_WAIT state...
> 
> I will report my experiences...

Well...  my idea does not work as expected. Even though the server 
(remote host) calls socket.close(), it is the client that executes 
TIME_WAIT. My guess is that the subtrates below socket closes the 
connection at the peer calling connect regardless of where socket.close 
is called.

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Steve Holden
Tor Erik wrote:
> Tor Erik wrote:
> 
>>Fredrik Lundh wrote:
>>
>>>Tor Erik wrote:
>>>
>>>
The reason is that my application does about 16 connects and data 
transfers per second, to the same 16 remote hosts. After approx 200 
secs there are 4000 sockets waiting to be garbage collected by the OS.
>>>
>>>what does "netstat" say about these sockets ?
>>>
>>>
>>>
>>They are in the TIME_WAIT state... The msn library has an article on how 
>>to solve this:
>>
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/BTS06CoreDocs/html/6987640c-1d80-4fbf-b43a-021fc8ba06a4.asp
>> 
>>
>>
>>Summing up one could either:
>>
>>1. Increase the upper range of ephemeral ports that are dynamically 
>>allocated to client TCP/IP socket connections:
>>
>>set registry key: 
>>KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort
>> 
>>
>>to a new DWORD value... (5000 - 65534)
>>The default in XP is 3976 -> http://support.microsoft.com/kb/Q149532
>>
>>or
>>
>>2. Reduce the client TCP/IP socket connection timeout value from the 
>>default value of 240 seconds
>>
>>set registry key:
>>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTimedWaitDelay
>> 
>>
>>to a new DWORD value (30 - 300)
>>
>>The TCP RFC (RFC 793) recommends a value of 2*msl(Maximum Segment 
>>Lifetime). The general consensus about the value of msn seems to be 1-2 
>>minutes, depending on the underlying network... (2*2 min = 2*120 sec = 
>>240 sec)
>>
>>
>>I do not want to alter my registry, so I'm currently testing an idea 
>>where I let the client connect and send its content, appended with my 
>>own "magic" EOF byte-sequence. When the server receives this EOF, it 
>>takes care to close the connection. This should eliminate the problem as 
>>it is the peer closing the connection that enters the TIME_WAIT state...
>>
>>I will report my experiences...
> 
> 
> Well...  my idea does not work as expected. Even though the server 
> (remote host) calls socket.close(), it is the client that executes 
> TIME_WAIT. My guess is that the subtrates below socket closes the 
> connection at the peer calling connect regardless of where socket.close 
> is called.
> 
> Thoughts anyone?

Yes, it's the transport layer that puts the socket into the TIME_WAIT state.

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: OO on python real life tutorial?

2006-09-03 Thread bearophileHUGS
Patrick Thomson:
> After all, GvR said that
> "wxPython is the best and most mature cross-platform GUI toolkit,
> given a number of constraints. The only reason wxPython isn't the
> standard Python GUI toolkit is that Tkinter was there first."
>
> The Wax toolkit (http://zephyrfalcon.org/labs/wax.html) attempts to
> solve the problems inherent with wxPython and make it more pythonic.

Wax is quite nice. A complete and improved (made even simpler and
cleaner, copying other ideas from Tkinter too) Wax may be good to
replace/mount side by side Tkinter in future (3.0?) Python
distributions. Often it's a work of designing easy to use APIs.

Bye,
bearophile

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


Pmw installation problem

2006-09-03 Thread vedran_dekovic
Hi,
When I download Pmw,and .py files copy to lib,then in python shell
I write:

>>>import Pmw
Traceback (most recent call last):
  File "", line 1, in -toplevel-
import Pmw
ImportError: No module named Pmw









Regards,

Vedran,Croatia

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


Re: Pmw installation problem

2006-09-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> When I download Pmw,and .py files copy to lib,then in python shell
> I write:

where did you copy what files?  you're supposed to place the *entire* 
Pmw directory somewhere on your path (e.g. under site-packages).  see

 http://pmw.sourceforge.net/doc/starting.html



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


Re: Python-list Digest, Vol 36, Issue 33

2006-09-03 Thread David J Birnbaum
Dear John (cc python-list),
>> You may find (1) that the file has formfeeds in
>> it or (2) it has r"\f" in in it and you were mistaken about the
>> interpretation or (3) something else.
>> 
> ...
>   
>> Thank you for the quick response. Ultimately I need to remap the "f" in
>> "\f" to something else, so I worked around the problem by doing the
>> remapping first, and I'm now getting the desired result.
>> 
>
> Please reply on-list.
>
> How could you read the file to remap an "f" if you were getting '\0x0C'
> when you tried to read it? Are we to assume that it was case (2) i.e.
> not a Python problem?
>   
Possibly more than anyone else on-list cares to see, but it was case 
(3): I had misdiagnosed the input. The match was failing because I was 
reading the line improperly (when I remapped the "f" I was ... er ... 
inexplicably surprised when I couldn't find it, although it turned out 
to be there when I looked for the remapped value instead of for the 
original "f"). When I tried to troubleshoot it in an interpreter window, 
I misread the results, which is what prompted my inquiry on the list. 
Here's the intepreter diagnosis:

 >>> string1 = "blah \fR40\fC blah"
 >>> string1
'blah \x0cR40\x0cC blah'
 >>> string2 = "blah \\fR40\\fC blah"
 >>> string2
'blah \\fR40\\fC blah'

If I create a file that consists of:



Hi, there
blah \fR40\fC blah
Hi, there


And then a python script that reads:

import codecs
import re
file = open("test1.xml", "r")
nePat = re.compile("f.")
for line in file:
print line
print nePat.sub("TEST", line)
   
the relevant line comes out as:

blah TEST40TEST blah

which is what I want. That is, the script was, indeed, reading the 
character string correctly, as you suggested, and the substitution that 
I ran into during my test in the interpreter window was a red herring. 
Thanks again for the advice to look more closely.

Best,

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


Re: Python style: to check or not to check args and data members

2006-09-03 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
>>I've rarely encoutered "silent" data corruption with Python - FWIW, I
>>once had such a problem, but with a lower-level statically typed
>>language (integer overflow), and I was a very newbie programmer by that
>>time. Usually, one *very quickly* notices when something goes wrong.
> 
> 
> The same thing can happen in Python, and the resulting bugs can be
> pretty subtle.  I noticed the following example as the result of
> another thread, which was about how to sort an 85 gigabyte file.
> Try to put a slice interface on a file-based object and you can
> hit strange integer-overflow bugs once the file gets larger than 2GB:
> 
> Python 2.3.4 (#1, Feb  2 2005, 12:11:53) 
> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print slice(0, 3**33)
> slice(0, 555906056623L, None) # OK ...
> 
> So we expect slicing with large args to work properly.  But then:
> 
> >>> class A:
> ...   def __getitem__(self, s):
> ... print s
> ... 
> >>> a = A()
> >>> a[0:3**33]
> slice(0, 2147483647, None)# oops
> >>> 

Looks like a Python bug, not a programmer error. And BTW, it doesn't 
happens with >=2.4.1

Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on 
linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> print slice(0, 3**33)
slice(0, 555906056623L, None)
 >>> class A(object):
... def __getitem__(self, s):
... print s
...
 >>> A()[0:3**33]
slice(0, 555906056623L, None)
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python GUI/tk

2006-09-03 Thread [EMAIL PROTECTED]
Hi,

I am making a GUI with the help of python.In the program, when "ADD"
button is pressed new frames build up and when you press "delete"
button those frames will be destroyed . My problem is that these frames
only get destroyed in Tk but the data structure associated with it (in
Python) doesn't change.


#!/usr/bin/python
from Tkinter import*

class Frame_1(LabelFrame):
def __init__(self,master):
LabelFrame.__init__(self,master)
self.configure(text="Frame1")
self.grid()

def control_buttons(self,frame):
Button( self, text = "Add", command = frame.add_button ).grid(
)
Button( self, text = "Read", command = frame.read_button
).grid()

class Frame_2(LabelFrame):
def __init__(self,master):
LabelFrame.__init__(self,master)
self.configure(text ="Frame2")
self.grid()
self.sub_frame = []

def add_button(self):
new_frame = Frame_2_1(self)
   # new_frame.grid()
new_frame.populate()
self.sub_frame.append(new_frame)
  #  print self.sub_frame

def read_button(self):
print "#"*10
for sub_frame in self.sub_frame :
print "-"*30
print "band:"+ sub_frame.band.get()
print "channel:" + sub_frame.channel.get()

class Frame_2_1(LabelFrame):
def __init__(self,tkmaster):
LabelFrame.__init__(self,tkmaster)
self.configure(text ="DEFAULT")
self.grid()

def populate(self):
self.band = StringVar()
self.band.set("900")
option = OptionMenu(self, self.band,"900","1800","1900"
).grid()

self.channel = StringVar()
self.channel.set("CS 1")
option = OptionMenu(self,self.channel,"CS 1","CS 2","CS 3","CS
4").grid( )

global temp
temp= temp+1
Button(self,text = "Remove"+ str(temp),command=
self.delete_frame).grid()


def delete_frame(self):
self.destroy()

root = Tk()
temp=-1
# Create frame 1
frame_1 =  Frame_1(root)
# Create frame 2
frame_2 = Frame_2(root)

frame_1.control_buttons(frame_2)
root.mainloop()
--

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


regex matching rst code block?

2006-09-03 Thread Edward K. Ream
Here is a little regular expression puzzle.  I wish a regex that matches an 
rst code block, that is,



'::' followed by a group of lines all indented by at least as much as the 
first non-blank line following the '::'



My guess is that this is not possible.  Can anyone prove me wrong :-)



Edward


Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: Pmw installation problem

2006-09-03 Thread vedran_dekovic

Fredrik Lundh je napisao/la:
> [EMAIL PROTECTED] wrote:
>
> > When I download Pmw,and .py files copy to lib,then in python shell
> > I write:
>
> where did you copy what files?  you're supposed to place the *entire*
> Pmw directory somewhere on your path (e.g. under site-packages).  see
>
>  http://pmw.sourceforge.net/doc/starting.html
> 
> 


All files (.py),I was copy in lib

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


Re: Pmw installation problem

2006-09-03 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

>> where did you copy what files?  you're supposed to place the *entire*
>> Pmw directory somewhere on your path (e.g. under site-packages).  see
>>
>>  http://pmw.sourceforge.net/doc/starting.html
 >
> All files (.py),I was copy in lib

have you tried copying the Pmw *directory* instead ?



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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread alf
Sybren Stuvel wrote:
> Hi folks,
> 
> Sometimes I have to feed data from an OpenOffice.org spreadsheet into
> some Python program. To make that really easy, I've written a small
> example program that connects to a running OpenOffice.org instance and
> reads the data from the currently opened spreadsheet.
> 
> Check out http://www.stuvel.eu/archive/28/ to see the source and
> requirements. It took a lot of digging in the rather complex OOo API
> documentation, but the end result is just as I like it: clean and
> simple. I hope this helps people out!
> 
> Sybren

thx for sharing the experience. Do you know how to save a OO doc into M$ 
Excel format - I have a Python based server running on Linux box and 
need to produce Excel files.

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Alex Martelli
Steve Holden <[EMAIL PROTECTED]> wrote:
   ...
> >>set registry key: 
>
>>KEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\M
axUserPort
> >>
> >>to a new DWORD value... (5000 - 65534)
> >>The default in XP is 3976 -> http://support.microsoft.com/kb/Q149532

I wonder why (performance under RAM-costrained conditions? but then why
not have this vary depending on available RAM -- complications?)

> Yes, it's the transport layer that puts the socket into the TIME_WAIT state.

Yes, there's a good explanation at
 (though one
should really study Stevens' "TCP-IP Illustrated" for better
understanding in depth).  Playing with SO_LINGER and/or the MSL is not
recommended unless you're operating only on a network that you entirely
control (particularly in terms of round-trip times and router behavior).

As debated at
, you may be able to have your clients go into CLOSE_WAIT (instead of
TIME_WAIT) by playing around with "who closes the socket first", and
CLOSE_WAIT might be more transient than the 2*MSL (240 seconds...)
needed for TIME_WAIT on possibly-unreliable networks.  But it's far from
sure that this would gain you much.

Reflecting on the OP's use case, since all connections are forever being
made to the same 16 servers, why not tweak thinks a bit to hold those
connections open for longer periods of time, using a connection for many
send/receive "transactions" instead of opening and closing such
connections all of the time?  That might well work better...


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


Re: Twisted vs POS (Plain-old sockets)

2006-09-03 Thread Jean-Paul Calderone
On Sun, 3 Sep 2006 00:19:17 -0700, Darren Kirby <[EMAIL PROTECTED]> wrote:
>Hey all,
>
>I have a (FOSS) project here that I am about to start that requires TCP
>networking support, and in fact, will require me to design and implement a
>(text based) protocol from scratch.

I'm sorry.

>
>I have been playing with Twisted today and managed to get a simple
>client/server talking to each other. However, the twisted framework does
>seem
>very complex, and includes many, many, features I will never need. The docs
>seem a little lacking (or perhaps just confusing) as well. Twisted's good
>points are that it will save me from having to write many things from
>scratch, asynchronous networking being the biggie.

If there are features you don't need, then don't use them.  What does their
existence cost you?  Are you going to use the sunaudio module from the
standard library?  If not, is this an argument in favor of using C++ instead
of Python?

As for documentation, many people say it is lacking, but perhaps one person
in a thousand points out _how_ or _where_ it is lacking.  Unfortunately it
is difficult to improve things (or even determine if they really are lacking)
with this level of feedback.

Keep in mind that in addition to the online documentation, there is a Twisted
book, an extremely helpful twisted mailing list (with years of archives
online), and an IRC channel populated at nearly all hours of the day with
people who can answer Twisted questions.

>
>I guess I am wondering if given the fact I need a custom protocol, and need
>to
>talk TCP/IP should I stick with twisted or just use plain old sockets and
>build it myself?

Talking to the TCP/IP stack is surprisingly difficult to get right.  Since
it is extremely unlikely that you actually _care_ about all of the random,
stupid differences between different TCP implementations, you should use
Twisted, since it does its best to hide these differences and instead
present a uniform API.

If you use bare sockets, you will need to learn many of these quirks yourself,
frequently through a bug report from a user, since many of them are
undocumented.

>Is there a third option I should consider? Have others
>found
>themselves in this situation? Thoughts? Comments? I am really just fishing
>for opinions here...

Twisted is great.  It will speed up your development time and reduce the
amount of defects you need to deal with.  It will 

>
>If it makes a difference: Depending on performance parts of this app may
>well
>end up as a prototype for a final (...alternative?) C++ implementation.
>
>Thanks for consideration,

Hope this helps,

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


Re: CONSTRUCT -

2006-09-03 Thread lazaridis_com
Georg Brandl wrote:
> lazaridis_com wrote:
> > I would like to fulfill the following task:
> >
> > The construct:
> >
> > if __name__ == '__main__':
> >
> > should be changed to something like:
> >
> > if identifier.name == '__main__':
> >
> > The term "identifier" should be selected based on the meaning of the
> > __double-underscore-enclosure__ of the entities.
...

> import sys
> class _identifier:
> def __getattr__(self, name):
> return sys._getframe(1).f_globals['__%s__' % name]
> identifier = _identifier()

ok, I understand.

this one would work with modules.

but how would look a more general solution, which would work with
objects too?
 
.

--
http://lazaridis.com

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


Re: regex matching rst code block?

2006-09-03 Thread Peter Otten
Edward K. Ream wrote:

> Here is a little regular expression puzzle.  I wish a regex that matches
> an rst code block, that is,

> '::' followed by a group of lines all indented by at least as much as the
> first non-blank line following the '::'
 
> My guess is that this is not possible.  Can anyone prove me wrong :-)

Try

r"(::\s*\n(\s*\n)*((\s+).*?\n)(((\4).*?\n)|(\s*\n))*)"

Probably buggy and too complicated, but you didn't post a good test suite...

Peter

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


Re: CONSTRUCT - Module Attributes and Execution Environment

2006-09-03 Thread lazaridis_com

lazaridis_com wrote:
> lazaridis_com wrote:
> > I would like to change the construct:
> >
> > if __name__ == '__main__':
> ...
>
> Is there a standard way / naming to wrap "__name__" and other similar
> attributes to an encapsulating class?
...

see follow-up thread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/37905d66ae0e37c4

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


pdf to hhp for boa-constructor help

2006-09-03 Thread [EMAIL PROTECTED]
 Is there a way to convert from .pdf to hhp so that I can add help
files to boa constructor..  adding html to it would also be helpfull

http://www.dexrow.com

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


str.isspace()

2006-09-03 Thread bearophileHUGS
Are you using the str.isspace() method? I don't use it, so if most
people don't uses it, then it may be removed from Py 3.0.

I usually need to know if a string contains some non-spaces (not space
class chars). To do it I use something like:

if aline.strip(): ...

If you really need str.isspace() you may use (but so far I have never
had to do this):

if txt and not txt.strip(): ...

Bye,
bearophile

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


Re: Help with autotools

2006-09-03 Thread pavel . starek
Jonh Wendell wrote:
> Hi all! I need help with autotools stuff..
>
> My directory structure:
>
> project_name
>   src
> main.py
> others.py
>   data
> ui.glade
> images.png
>   po
> translations.po
>
> I'd like to do something like that:
>
> The files in "src" should be installed at: $prefix/lib/project_name
> The files in "data" should be installed at: $prefix/share/project_name
>
> At $prefix/bin should be create a slink:
>  $prefix/bin/project_name -> $prefix/lib/project_name/main.py
>
> The listen (http://listengnome.free.fr/) does this, but it doesn't use
> autotools...
>
> Can anyone help me?
> I've tried a lot to make this work, but with no success...
>
> Thanks,
> --
> Jonh Wendell Santana
> Analista de Sistemas
>
> http://www.bani.com.br
> MSN: [EMAIL PROTECTED]
> GTalk/Jabber: [EMAIL PROTECTED]
> Linux User #114432

Hi,

in listen project Makefile is shown how to make this thing. URL for SVN
view of Makefile for listen 0.4.3 is:

http://svn.sourceforge.net/viewvc/listengnome/releases/0.4.x/0.4.3/Makefile?view=markup

Cheers, Pavel

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


Re: regex matching rst code block?

2006-09-03 Thread Edward K. Ream
> Why not convert the reStructuredText to XML and parse that?

Because the problem arises for the jEdit syntax colorer whose most powerful 
pattern matcher is a regex.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html
 


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


Re: regex matching rst code block?

2006-09-03 Thread Edward K. Ream
>  r"(::\s*\n(\s*\n)*((\s+).*?\n)(((\4).*?\n)|(\s*\n))*)"

Thanks for this.  I'll try it out.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html
 


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


Re: Python style: to check or not to check args and data members

2006-09-03 Thread Jean-Paul Calderone
On Sun, 03 Sep 2006 16:29:11 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> 
wrote:
>Paul Rubin a écrit :
>> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
>>
>>>I've rarely encoutered "silent" data corruption with Python - FWIW, I
>>>once had such a problem, but with a lower-level statically typed
>>>language (integer overflow), and I was a very newbie programmer by that
>>>time. Usually, one *very quickly* notices when something goes wrong.
>>
>>
>> The same thing can happen in Python, and the resulting bugs can be
>> pretty subtle.  I noticed the following example as the result of
>> another thread, which was about how to sort an 85 gigabyte file.
>> Try to put a slice interface on a file-based object and you can
>> hit strange integer-overflow bugs once the file gets larger than 2GB:
>>
>> Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
>> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> print slice(0, 3**33)
>> slice(0, 555906056623L, None) # OK ...
>>
>> So we expect slicing with large args to work properly.  But then:
>>
>> >>> class A:
>> ...   def __getitem__(self, s):
>> ... print s
>> ...
>> >>> a = A()
>> >>> a[0:3**33]
>> slice(0, 2147483647, None)# oops
>> >>>
>
>Looks like a Python bug, not a programmer error. And BTW, it doesn't
>happens with >=2.4.1
>
>Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
>[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on
>linux2
>Type "help", "copyright", "credits" or "license" for more information.
> >>> print slice(0, 3**33)
>slice(0, 555906056623L, None)
> >>> class A(object):
>... def __getitem__(self, s):
>... print s
>...
> >>> A()[0:3**33]
>slice(0, 555906056623L, None)
> >>>

Note that it _does_ happen with current [EMAIL PROTECTED]:

Python 2.6a0 (trunk:51698M, Sep  3 2006, 12:40:55) 
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> slice(0, 3 ** 33)
slice(0, 555906056623L, None)
>>> class x:
... def __getitem__(self, idx): print idx
... 
>>> x()[:3**33]
slice(0, 2147483647, None)
>>> 

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

Re: Broadcast server

2006-09-03 Thread Michael
[EMAIL PROTECTED] wrote:

>   It sounds very interesting and i will definitely take a deeper look
> but i was more considering something simpler as a learning exercise
> more that finding a package that should already do what i want to
> achieve.

The bulk of this post dissects (roughly) how Kamaelia handles this
internally since I figure that might also be useful if you're after
this as a learning exercise :-) (It should hopefully be clear enough
for this to be useful) At minimum it might go some way to explain why
people generally tend to suggest using an existing framework :-)

> I want to find the basic guidelines to write that kind of client/server
> architecture and make some tests of different solutions(socket+select
> or socket+thread or mix of them)

I think if you're doing socket & select it sounds easy/simple until you
start dealing with all the cases you need to to do it properly. You're
probably best looking at the python cookbook for a good initial starting
point.

> Your project seems very great and will try to read in to learn.

Kamaelia *might* still be useful here in some respects, since despite being
*effectively* event based, due to the use of generators code tends to look
linear.

The low level structure of the server breaks down as follows:

(I'm spending a bit of time here since it might be of general interest,
sorry if it isn't)

   * Kamaelia.Internet.TCPServer is a simple component that sits waiting for
 a user to connect. 

 It makes the server port, adds any user socket options, makes it non
 blocking, binds it to the requested (if any) host and either to a user
 defined or random port number. (latter is for testing)

 It then registers the socket with the piece of code that's taking care
 of select handling, and sits to wait for any notifications of activity
 on the socket. (Which would mean for something acting as a server a new
 connection).

 It then performs a socket accept, and creates an object to handle the
 raw (now connected) socket - a connected socket adaptor. It then
 registers that socket and object with the piece of code that's taking
 care of select handling. (So that the select handling can tell the
 piece of code handling the raw socket to do some work on the socket)

 code: http://tinyurl.com/pocm8

   * Kamaelia.Internet.ConnectedSocketAdaptor is actually more complicated
 than you might expect. The reason is because the socket is
 non-blocking, and where-ever you would normally block you have
 to maintain some sort of buffering in case the action fails.
 This is more a symptom of non-blocking behaviour than it is about
 Kamaelia.

 Anyhow the basics of this is to take any data that is to be sent to the
 socket, and add that to a sending queue.  (this data will generally
 come from the code handling the protocol)

 Then if the select handling code has said that we can send/should data,
 we take data from the send queue and send as much as we can until our
 sending fails (after all, we're non-blocking, so we expect it to fail).

 Then if the select handling code has said that there's data ready to
 receive the component reads from the socket until an error (again we
 expect an error due to non-blocking behaviour). This data is then
 passed on to a location where a protocol handler can expect to take the
 data and do what it likes with it.

 The bulk of the code for the CSA actually revolves around resends, and
 the necessary error handling. (It's also one of the oldest bits of code
 in Kamaelia so possibly a little horrid to look at!)

 code: http://tinyurl.com/nj8lk

   * Kamaelia.Internet.Selector is also slightly more complex than you might
 think. This is because whilst you tell select "let me know whenever any
 of these sockets is ready for (reading|writing|exceptional)", it
 actually cares about what you do *after* it's given you an answer. 

 For example if you don't read from all the things that are ready to
 read, or don't write to all the things that are ready to write or
 (worse) try asking it to do things with regard to closed or invalid
 sockets, then you're just asking for trouble.

 There's lots of ways round this and you can do something like:
 looping:
 (readables, writeables, excepts) = select( ...)
 for readable in readables:
 read from readable and do something
 for writable in writeables:
 write to writeables and do something
 for exceptional in excepts:
 handle exceptional

 However then you add new problems - what about if you want to do a
 database request as result of one? Render a image for another? Wait for
 keyboard press? etc.

 As a result that's why we use explicit message passing, though many
 people use a reactor (or sometimes a pro-actor) pattern to handle
 events. (i

Re: str.isspace()

2006-09-03 Thread Jean-Paul Calderone
On 3 Sep 2006 09:20:49 -0700, [EMAIL PROTECTED] wrote:
>Are you using the str.isspace() method? I don't use it, so if most
>people don't uses it, then it may be removed from Py 3.0.
>
>I usually need to know if a string contains some non-spaces (not space
>class chars). To do it I use something like:
>
>if aline.strip(): ...
>
>If you really need str.isspace() you may use (but so far I have never
>had to do this):
>
>if txt and not txt.strip(): ...
>
>Bye,
>bearophile
>

Great idea.

By the way, are you using division?  I don't use it, so if most people
don't use it, then it may be removed from Py 3.0.

If you really need division, you may use:

  x * (y ** -1)

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


Re: str.isspace()

2006-09-03 Thread forman . simon
[EMAIL PROTECTED] wrote:
> Are you using the str.isspace() method? I don't use it, so if most
> people don't uses it, then it may be removed from Py 3.0.
>
> I usually need to know if a string contains some non-spaces (not space
> class chars). To do it I use something like:
>
> if aline.strip(): ...
>
> If you really need str.isspace() you may use (but so far I have never
> had to do this):
>
> if txt and not txt.strip(): ...
>
> Bye,
> bearophile

A quick check of code in my homedir showed that I've used it about 60
times (that's just in my own code, not work related code.)

In favor of removing it:
 * TOOWTDI

In favor of keeping it:

 * isspace() returns a Boolean, strip() returns a (newly-allocated)
string that's then just thrown away.

 * it's more obvious, "is space?" is exactly what I'm thinking when I
reach for isspace(),  it's never occurred to me to use strip() for this
task.  Compare:
if offset >= len(line) or line[offset].isspace():
if offset >= len(line) or line[offset].strip():

 * it's "symetrical" with the rest of the isfoo() string methods.
IMHO, it would be odd if it wasn't there.

My $0.02


Peace,
~Simon

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


Re: Python style: to check or not to check args and data members

2006-09-03 Thread Alex Martelli
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
   ...
> > >>> class A(object):

note that A is new-style...

> >>> class x:

...while x is old-style.

Here's a small script to explore the problem...:

import sys

class oldstyle:
def __getitem__(self, index): print index,

class newstyle(object, oldstyle): pass

s = slice(0, 3**33)

print sys.version[:5]
print 'slice:', s
print 'old:',
oldstyle()[s]
oldstyle()[:3**33]
print
print 'new:',
newstyle()[s]
newstyle()[:3**33]
print

Running this on 2.3.5, 2.4.3, 2.5c1, 2.6a0, the results are ALWAYS:

2.5c1
slice: slice(0, 555906056623L, None)
old: slice(0, 555906056623L, None) slice(0, 2147483647, None)
slice(None, 555906056623L, 1)
new: slice(0, 555906056623L, None) slice(None, 555906056623L,
None) slice(None, 555906056623L, 1)

[[except for the version ID, of course, which changes across runs;-)]]

So: no difference across Python releases -- bug systematically there
when slicing oldstyle classes, but only when slicing them with
NON-extended slice syntax (all is fine when slicing with extended syntax
OR when passing a slice object directly; indeed, dis.dis shows that
using extended syntax builds the slice then passes it, while slicing
without a step uses the SLICE+2 opcode instead).

If you add a (deprecated, I believe) __getslice__ method, you'll see the
same bug appear in newstyle classes too (again, for non-extended slicing
syntax only).

A look at ceval.c shows that apply_slice (called by SLICE+2 &c) uses
_PyEval_SliceIndex and PySequence_GetSlice if the LHO has sq_slice in
tp_as_sequence, otherwise PySlice_New and PyObject_GetItem.  And the
relevant signature is...:

_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)

(int instead of Py_ssize_t in older versions of Python), so of course
the "detour" through this function MUST truncate the value (to 32 or 64
bits depending on the platform).

The reason the bug shows up in classic classes even without an explicit
__getslice__ is of course that a classic class ``has all the slots''
(from the C-level viewpoint;-) -- only way to allow the per-instance
behavior of classic-instances...


My inclination here would be to let the bug persist, just adding an
explanation of it in the documentation about why one should NOT use
classic classes and should NOT define __getslice__.  Any fix might
perhaps provoke wrong behavior in old programs that define and use
__getslice__ and/or classic classes and "count" on the truncation; the
workaround is easy (only use fully-supported features of the language,
i.e. newstyle classes and __getitem__ for slicing).  But I guess we can
(and probably should) move this debate to python-dev;-).


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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Felipe Almeida Lessa
2006/9/3, Alex Martelli <[EMAIL PROTECTED]>:
> Reflecting on the OP's use case, since all connections are forever being
> made to the same 16 servers, why not tweak thinks a bit to hold those
> connections open for longer periods of time, using a connection for many
> send/receive "transactions" instead of opening and closing such
> connections all of the time?  That might well work better...

Connecting to 16 differente servers per second gives a very poor
performance, right? There's some overhead in creating TCP connections,
even on fast networks and computers. Am I right?

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


Re: str.isspace()

2006-09-03 Thread George Sakkis
Jean-Paul Calderone wrote:

> On 3 Sep 2006 09:20:49 -0700, [EMAIL PROTECTED] wrote:
> >Are you using the str.isspace() method? I don't use it, so if most
> >people don't uses it, then it may be removed from Py 3.0.
> >
> >I usually need to know if a string contains some non-spaces (not space
> >class chars). To do it I use something like:
> >
> >if aline.strip(): ...
> >
> >If you really need str.isspace() you may use (but so far I have never
> >had to do this):
> >
> >if txt and not txt.strip(): ...
> >
> >Bye,
> >bearophile
> >
>
> Great idea.
>
> By the way, are you using division?  I don't use it, so if most people
> don't use it, then it may be removed from Py 3.0.
>
> If you really need division, you may use:
> 
>   x * (y ** -1)
> 
> Bye,
> Jean-Paul

LOL... well said.

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


Setting custom folder icon in OS X?

2006-09-03 Thread Jet Jaguar
I'm trying to find a way to set a custom folder icon in OS X.  I
thought that Applescript would be able to do it, but apparently it
can't.  Is there anything in the Macintosh libraries of Python that
will allow me to take an image file (e.g., jpeg, png, tiff, etc.) and
set it as the icon for a folder?

Kevin D. Smith

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread Sybren Stuvel
Hi folks,

I just noticed I still had the "no archive" header on, which is rather
stupid. If I want to make life easier for people, the information I
posted in this thread should be archived! Here is a small summary:

Get data from an OpenOffice.org spreadsheet with a Python script. It
works on the currently opened spreadsheet, so you can just as well
open an Excel sheet in OpenOffice.org and get the data from that.
http://www.stuvel.eu/archive/28/getting-data-from-an-openofficeorg-spreadsheet

Saving the currently opened OpenOffice.org spreadsheet to an Excel
sheet with just a few lines of Python code. There are still people
that favour MS Office and request Excel output from software. This is
easily done with OpenOffice.org and Python:
http://www.stuvel.eu/archive/29/ooo-spreadsheet-to-excel-with-python

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


Re: pysqlite - simple problem

2006-09-03 Thread rdrink
Dennis Lee Bieber wrote:

>   That is probably the worst way to "fix" the problem -- as in the
> future, you may end up trying that method for something that may need to
> be quoted or escaped.
>
>   cur.execute(template, (arg1,) )
>
> allows the DB-API spec to properly convert the argument to the string
> format (quoted or escaped) as needed.

Thank you Dennis, point taken.
I will upgrade to pysqlite2 as soon as possible.

>the "pyformat" parameter style means that you're supposed to use "%s"
>instead of "?" for the placeholders:
>
> cur.execute("INSERT INTO foo (id) VALUES (%s)", (num,))

Thanks Fredrick, that seems so obvious now!

> (I'm sure this is mentioned in the fine manual, btw ;-)

... I guess I have must have missed it ;-)

>while string formatting works, and is safe for simple cases like this,
>it can quickly turn into a performance and security problem.  better
>avoid it for anything other than command-line tinkering and throw-away
>scripts.

You are both right about the perils of a non-standard approach, which
could easily break. Fortunately in this case this is a private project,
so no worry there.
-
And while you are both being so helpful, May I ask anyother stupid
question?...
One of the columns of my table contains a rather large list of numbers
e.g. [12345, 76543, 89786, ... ] sometimes up to 500 entries long.
And when I defined my table I set this column to text.
But the problem with that approach is of course then that it gets
returned as a string (which just happens to look like a list!) and I
can't iter over it. However I can use rsplit(','), with the exception
of the leading and trailing '[' ']', and I could fix that too... but
that's not the point... the real question is: Is there a way to have
python interperate the string "[ a,b,c ]" as a list? (and yes I have be
reading up on typing)...
OR
Is there a better way to store this in sqlite, ala a BLOB or encoded?

Thanks
Robb

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


Re: Client-side TCP socket receiving "Address already in use" upon connect

2006-09-03 Thread Alex Martelli
Felipe Almeida Lessa <[EMAIL PROTECTED]> wrote:

> 2006/9/3, Alex Martelli <[EMAIL PROTECTED]>:
> > Reflecting on the OP's use case, since all connections are forever being
> > made to the same 16 servers, why not tweak thinks a bit to hold those
> > connections open for longer periods of time, using a connection for many
> > send/receive "transactions" instead of opening and closing such
> > connections all of the time?  That might well work better...
> 
> Connecting to 16 differente servers per second gives a very poor
> performance, right? There's some overhead in creating TCP connections,
> even on fast networks and computers. Am I right?

There is some overhead, yes, but 16 connections per second are few
enough that I wouldn't expect that to be material (on networks with low
latency -- it might be different if you have "long fat pipes", networks
with huge bandwidth and thus "fast" but with high latency -- several
aspects of TCP/IP don't work all that well with those).

For example, try tweaking examples 1 and 2 for chapter 19 of "Python in
a Nutshell" (you can freely download the zipfile w/all examples from
) and do
some experiments.  I ran the unmodified server on an iBook G4, and on a
Macbook Pro I ran a client that looped 100 times, connecting, sending
'ciao', receiving the response, and printing a timestamp and the
response just received -- with the two laptops, sitting next to each
other, connected via Ethernet (just 100 mbps on the iBook, thus the
gigabit ethernet on the MBP wasn't really being used well;-) through a
direct cable (using ifconfig by hand to make a tiny 192.168.1/24 LAN
there;-).  The 100 iterations, all together, took a bit more than half a
second (and, of course, one could try tweaking the asyncore or Twisted
examples from the same chapter to let many connections happen at once,
rather than having them "in sequence" as I just did - and many other
such small but interesting experiments).  As a further data point, I
then reran the same experiment after removing the Ethernet cable, so
that the laptops were now connecting through wi-fi (802.11g, 54mbps, the
router being an Airport Express -- everything in the same room, within a
radius of 2 meters, excellent signal reception of course;-): ran in this
way, the 100 iterations took a total of over 2 seconds.


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


data structure

2006-09-03 Thread noro
Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
i need to make a tree like data structure (not necessry a binary tree).


i would like each node to access his sons in a dicionary kind of why,
for example: if  ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
-
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
"
ROOT={'factory1':FACTORY,'facory2':FACTORY,'linux':OS,'windows':OS}
FACTORY={'manager':EMPLOEY,'worker':EMPLOEY,'office':BUILDING,'..}
OS={'ver':VERSION,'problems':LIST,}
"
i started bulding the class NODE as an extention of  "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an
object.

i'll appreciate any comment
amit

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


Re: Broadcast server

2006-09-03 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> Yes but before going deeper ( too deep ) i would like to play with a
> toy python example. Basically what i want to study first is a socket or
> socket+select server and 5 clients that get time updated from the
> server.
> 
> Don't really know how to keep hot connections without blocking the
> server ? If someone can show me a quick and dirty example of the
> client/server i'll apprciate it a lot.

Download the zipfile with the examples from Python in a Nutshell (freely
available at
) and look
at the examples for chapter 19 -- several sample servers and clients for
a trivial "echo" protocol that progress from a server that's only able
to deal with one client at a time, to multithreaded ones, to ones
implemented with the better scalability of asynchronous socket handling,
via select, asyncore, asynchat, and Twisted (there are also UDP clients
and servers for an otherwise perfectly analogous task).

I strongly recommend asynchronous socket handling, by far the best
scalable and best performing approach to network programming.  Doing it
all by yourself with the select module is quite the learning experience,
although in real-life I'd always recommend Twisted instead (it's an
extremely rich framework, normally used at vastly higher semantics
level, but in the mentioned examples I show instead how to use it at
nearly the same semantics level as asyncore &c).


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


Re: Timeline for Python?

2006-09-03 Thread Aahz
In article <[EMAIL PROTECTED]>,
crystalattice <[EMAIL PROTECTED]> wrote:
>
>I'd write for 2.4, even though 2.5 should be coming out "shortly".
>There aren't many significant changes to the whole language between 2.4
>and 2.5.  Probably the best thing is write for 2.4 and have a sidenote
>stating where 2.5 operates differently.

Speaking as the co-author of _Python for Dummies_:

That's bad advice -- there are three Python books already out (or out
within the next couple of weeks) that target 2.5: _Python in a Nutshell_,
_Core Python_, and _Python for Dummies_.  _Python for Dummies_ had an
edit cycle after 2.5b1, so there should be little difference between that
and the released version.  A book scheduled for publication a year from
now should absolutely target 2.5 or risk looking dated.

There are in fact a lot of new features in 2.5: conditional expressions;
relative imports; unified try/except/finally; generators getting send(),
throw(), and close(); the with statement.  That doesn't even include
critical library features such as sqlite and ElementTree.

OTOH, I do agree that any book written should include diferences between
2.5 and earlier versions for the benefit of people needing to target
earlier or multiple versions.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

I support the RKAB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Managing database tables through web-forms (automatically)

2006-09-03 Thread Daniel Nogradi
> >> Check out Django, it has a great database API and on the fly
> >> auto-generated admin.
> >
> > Just gone over the tutorial, really amazing, exactly what I need.
>
> That's exactly the response I had when I met with Django :)
>

Anyone with Django experience: how well does it do with respect to upgrades?

Suppose you have some version of python, mod_python, apache, sqlite,
pysqlite, Django and of course your application using all of these.
Then if you upgrade any one piece in this list how will the whole
thing continue to work from the point of view of your app and Django
(so I'm supposing that the only bottle neck can be your app and
Django, so if the upgrading of, say, sqlite breaks, say, pysqlite that
doesn't count)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data structure

2006-09-03 Thread Jason
noro wrote:
> Hello again.
>
> I have a task i need to do and i can't seem to find an elegent
> solution.
> i need to make a tree like data structure (not necessry a binary tree).
>
>
> i would like each node to access his sons in a dicionary kind of why,
> for example: if  ROOT node has the name 'A' and 'AA', 'AB' are his
> sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
> left to right shows the route from the root to the node) then
> ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
> 'ABA' node.
>
> the tree does not have to be symmarical and every node link to
> different number of nodes. two nodes can have the same name if they are
> in a different location in the tree. so ROOT['factory1]['manager'] and
> ROOT['factory2']['manager'] can be in the same tree and point to
> different objects.
>
> all up to now i can manage.
> -
> my problem is this: i would like to find a way to easly construct the
> tree by giving some simple template, somthing similer to:
> "
> ROOT={'factory1':FACTORY,'facory2':FACTORY,'linux':OS,'windows':OS}
> FACTORY={'manager':EMPLOEY,'worker':EMPLOEY,'office':BUILDING,'..}
> OS={'ver':VERSION,'problems':LIST,}
> "
> i started bulding the class NODE as an extention of  "dict" with the
> keys are the childern names and the items are the next node reference.
> the proablem was that as you can see from the above example 'factory1'
> and 'factory2' point to the same object. i would like to have 2
> different objects of FACTORY. making FACTORY a template and not an
> object.
>
> i'll appreciate any comment
> amit

You can make a shallow copy of a dictionary using the dictionary's copy
method.  To make a completely new copy, use the deepcopy function in
the copy module.  Please see the copy module's documentation on the
limits and differences between deep copies and shallow copies.
(http://docs.python.org/lib/module-copy.html)

 --Jason

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


Re: Syntax suggestion.

2006-09-03 Thread samir
Saluton!

Simon Forman wrote:
>But think of all the curly braces around code blocks that you've never
had to type!  ;-)

That's why I left java to jython!

Eirikur Hallgrimsson wrote:
>This actually exists.
>The language which omits punctuation not actually required to resolve
ambiguity is called Ruby.
>Ruby is subject to a lot of love/hate over this.

It's late, now I talk Python HSSSHSSHS HSSHSS HS :)

I think that Ruby is a good scripting language for game engines but not
as good as Python to do some serious scientific processes (or, at least
Ruby doesn't have all the necessary "batteries").

Talking of games, "Blade of Darkness" was scripted entirely in Python
(1.5 I think)
:)

Sybren Stuvel wrote:
> But how would you discern between a function reference and a function
> call?

That would be a problem with two solutions:
1- If the function doesn't have any parameters, it will be called with
the empty parentheses (just like usual!);
2- to indicate that this is a function call, we would be adding a $ at
the end of the statement.

Gxis la reskribo
Samir

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


sqlite 'ownership' problems

2006-09-03 Thread rdrink
I will try to keep this as suscinct as possible as it might be an
obvious Q.
I am just getting into Py/sqlite (with a fair amount of PHP/MySQL
background), and am posting this as much for the other noobs as
myself
I started learning sqlite by tinkered around at the command line:
creating db's, tables, populating them. etc. All fine.
Then I moved to Python.. and immediately noticed that for a db I had
created at the cmnd-line, e.g. 'test.db' with a table 'foo', I would
get the error "_sqlite.DatabaseError: no such table: foo". My suspition
was that this is a "feature" of sqlite ('flat file' vs. a dynamic db in
MySQL) where sqlite is 'sensetive' to who creates it... Which seems to
be borne out by that fact that I have since written one Py script (in
IDLE) which creates and populates a db, and another that can retrieve
the data. But...

Now I have moved on to Blender (w/Python), and seem to be up against
the same problem, same error.
(And yes I could prolly just run the whole thing within Blender/Py. But
then why use a database? The whole point is to do my mass calculations
(which take about 20 minutes) in IDLE, stuff all that into a database.
and then just access that data via Py/sqlite.)

I suspect that the answer lies within using sqlites "network"
abilities... but as a noob I don't even know where to start... So
advice/examples would be greatly appreciated.

rd

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


Re: sqlite 'ownership' problems

2006-09-03 Thread Jean-Paul Calderone
On 3 Sep 2006 14:38:51 -0700, rdrink <[EMAIL PROTECTED]> wrote:
>I will try to keep this as suscinct as possible as it might be an
>obvious Q.
>I am just getting into Py/sqlite (with a fair amount of PHP/MySQL
>background), and am posting this as much for the other noobs as
>myself
>I started learning sqlite by tinkered around at the command line:
>creating db's, tables, populating them. etc. All fine.
>Then I moved to Python.. and immediately noticed that for a db I had
>created at the cmnd-line, e.g. 'test.db' with a table 'foo', I would
>get the error "_sqlite.DatabaseError: no such table: foo". My suspition
>was that this is a "feature" of sqlite ('flat file' vs. a dynamic db in
>MySQL) where sqlite is 'sensetive' to who creates it... Which seems to
>be borne out by that fact that I have since written one Py script (in
>IDLE) which creates and populates a db, and another that can retrieve
>the data. But...

Just make sure everyone who should be able to read and write the database
has read and write permissions on the database file.  Nothing more is
necessary.

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


Re: CONSTRUCT -

2006-09-03 Thread lazaridis_com

Simon Forman wrote:
> lazaridis_com wrote:
> > I would like to fulfill the following task:
> >
> > The construct:
> >
> > if __name__ == '__main__':
> >
> > should be changed to something like:
> >
> > if identifier.name == '__main__':
...

> > Context:
> > http://case.lazaridis.com/wiki/Lang
> > http://case.lazaridis.com/ticket/6
>
> I'm sorry, you post makes very little sense.  If all you want to do is
> implement a less "ugly" verision of "if __name__ == '__main__':", a
> quick search on google should turn up several ways.

this happend already within another thread/ticket:

http://case.lazaridis.com/changeset/45

this here is aboute the underscores in "__name__".

-

search engines are full of information, but when looking for standard
constructs and ways to do something, I rely on feedback from domain
experts.

some search-engine hits:

http://aspn.activestate.com/ASPN/Mail/Message/python-list/830424
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496930
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496920

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread John Machin
Sybren Stuvel wrote:
> Hi folks,
>
> Sometimes I have to feed data from an OpenOffice.org spreadsheet into
> some Python program. To make that really easy, I've written a small
> example program that connects to a running OpenOffice.org instance and
> reads the data from the currently opened spreadsheet.
>
> Check out http://www.stuvel.eu/archive/28/ to see the source and
> requirements. It took a lot of digging in the rather complex OOo API
> documentation, but the end result is just as I like it: clean and
> simple. I hope this helps people out!
>

Suppose one has over a hundred spreadsheets (real-life example: budgets
from an organisation's reporting centres) ... manually opening each in
OOo Calc is less than appealing, and not very robust.

With the 2nd example (alf's question: copy OOo Calc file to Excel xls
file), I don't see any advantage at all over the manual procedure (1)
start OOo Calc (2) open Calc file (3) File > Save As > select Microsoft
Excel 97 etc format > ... what am I missing? Your solution requires (1)
edit script to change name of output file; save script (where?) (2)
start OOo Calc with magic-spell on the command line (3) open calc file
(4) run script.

How does one write a script that can be in control e.g. script starts
OOo (if necessary), and extracts some data from all spreadsheet files
in a given directory (while one is at lunch)? 

Cheers,
John

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread Sybren Stuvel
John Machin enlightened us with:
> Suppose one has over a hundred spreadsheets (real-life example:
> budgets from an organisation's reporting centres) ... manually
> opening each in OOo Calc is less than appealing, and not very
> robust.

True. There are functions that can load files as well. Combined with
the glob module, this could automatically handle all files in a
certain directory.

> With the 2nd example (alf's question: copy OOo Calc file to Excel
> xls file), I don't see any advantage at all over the manual
> procedure (1) start OOo Calc (2) open Calc file (3) File > Save As >
> select Microsoft Excel 97 etc format > ... what am I missing? Your
> solution requires (1) edit script to change name of output file;
> save script (where?) (2) start OOo Calc with magic-spell on the
> command line (3) open calc file (4) run script.

It's just a demonstration of the file saving process. Indeed, the
saving not all that useful, but someone requested it and I wrote it.

> How does one write a script that can be in control e.g. script
> starts OOo (if necessary),

That's easily done with a system call or the subprocess or popen2
modules.

> and extracts some data from all spreadsheet files in a given
> directory (while one is at lunch)? 

Just add a few lines to load the file instead of picking the currently
opened one. Do you want me to do more digging and extend the code? I'm
willing to do that, but only if it makes you happy :)

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


Re: sqlite 'ownership' problems

2006-09-03 Thread Istvan Albert
rdrink wrote:

> created at the cmnd-line, e.g. 'test.db' with a table 'foo', I would
> get the error "_sqlite.DatabaseError: no such table: foo". My suspition
> was that this is a "feature" of sqlite ('flat file' vs. a dynamic db in
> MySQL) where sqlite is 'sensetive' to who creates it...

Most likely you do not operate on the same database file.  Connecting
to a sqlite database will create the underlying database file if it
does not exist at the path you've specified. 

i.

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread John Machin
Sybren Stuvel wrote:
> John Machin enlightened us with:
> > Suppose one has over a hundred spreadsheets (real-life example:
> > budgets from an organisation's reporting centres) ... manually
> > opening each in OOo Calc is less than appealing, and not very
> > robust.
>
> True. There are functions that can load files as well. Combined with
> the glob module, this could automatically handle all files in a
> certain directory.
>
> > With the 2nd example (alf's question: copy OOo Calc file to Excel
> > xls file), I don't see any advantage at all over the manual
> > procedure (1) start OOo Calc (2) open Calc file (3) File > Save As >
> > select Microsoft Excel 97 etc format > ... what am I missing? Your
> > solution requires (1) edit script to change name of output file;
> > save script (where?) (2) start OOo Calc with magic-spell on the
> > command line (3) open calc file (4) run script.
>
> It's just a demonstration of the file saving process. Indeed, the
> saving not all that useful, but someone requested it and I wrote it.

Other possible responses: (1) suggest the obvious(?)
less-labour-intensive no-script method (2) show how to automate it
robustly.

>
> > How does one write a script that can be in control e.g. script
> > starts OOo (if necessary),
>
> That's easily done with a system call or the subprocess or popen2
> modules.
>
> > and extracts some data from all spreadsheet files in a given
> > directory (while one is at lunch)?
>
> Just add a few lines to load the file instead of picking the currently
> opened one. Do you want me to do more digging and extend the code? I'm
> willing to do that, but only if it makes you happy :)

Firstly, let me say that you are highly commended for wading so far
into the OOo docs and producing two pieces of code that actually do
something. I've opened up the docs two or three times, said "Waaahht
the " and closed them rapidly.

I don't "want" you to do anything. However the interests of
evangelising/spreading the use of OOo software might be advanced were
you to go the extra step or two and post a recipe for simple data
extraction from a named file, rather than the currently open file. Add
a few hints like what are the types of the data that you get back
(especially how dates are distinguished from numbers, if at all) and
you'll be a hero :-)

Cheers,
John

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


Re: FYI: getting data from an OpenOffice.org spreadsheet

2006-09-03 Thread Sybren Stuvel
John Machin enlightened us with:
> Firstly, let me say that you are highly commended for wading so far
> into the OOo docs and producing two pieces of code that actually do
> something. I've opened up the docs two or three times, said "Waaahht
> the " and closed them rapidly.

Thanks. I had the same response, except that I had the gut feeling
that in the end things were going to be easy ;-)

> I don't "want" you to do anything. However the interests of
> evangelising/spreading the use of OOo software might be advanced
> were you to go the extra step or two and post a recipe for simple
> data extraction from a named file, rather than the currently open
> file. Add a few hints like what are the types of the data that you
> get back (especially how dates are distinguished from numbers, if at
> all) and you'll be a hero :-)

Sounds very tempting. I'll see what I can come up with, and write a
proper article on my website. Don't count on it being finished soon,
though, because this week is going to be very busy for me, and after
that I'll be on a two-week holiday.

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


Exception EOFError.

2006-09-03 Thread Dr. Pastor
Python 2.5b3 on Windows XP.

(exception EOFError
Raised when one of the built-in functions (input() or
raw_input()) hits an end-of-file condition (EOF) without reading any data.)

For me, raw_input (hit enter) returns an empty string!
(>>> x=raw_input()

 >>> x
''
 >>> )

Any confirmation?
Regards.

== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get a filename's extension

2006-09-03 Thread SuperGh0d
Hello all,

I am new to python and I am having some difficulty obtaining the
extension of a file. I was looking at the re.match module but I am
completely overwhelmed by regular expressions. Is there an easier way
to get the extension for a file name like:

this.is.my.file.avi

I would just like to pull out the 'avi'

your help is greatly appreciated! :)

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


Re: how to get a filename's extension

2006-09-03 Thread limodou
On 3 Sep 2006 17:46:32 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I am new to python and I am having some difficulty obtaining the
> extension of a file. I was looking at the re.match module but I am
> completely overwhelmed by regular expressions. Is there an easier way
> to get the extension for a file name like:
>
> this.is.my.file.avi
>
> I would just like to pull out the 'avi'
>
> your help is greatly appreciated! :)
>
>>> import os
>>> os.path.splitext('this.is.my.file.avi')
('this.is.my.file', '.avi')

-- 
I like python!
My Blog: http://www.donews.net/limodou
UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad
UliPad Maillist: http://groups.google.com/group/ulipad
-- 
http://mail.python.org/mailman/listinfo/python-list


Python newbie with a problem writing files

2006-09-03 Thread John Jones
Hi All,

I have been driven insane by this error. I have this small program, shown 
below, which runs great until it gets to writing the data out to the file. I am 
running an install of Python 2.4. Yes, feedparser is functioning fine (I put in 
print feed_title statements as tests - but have since removed them). I am 
missing something obvious.

Thanks
JJ 

Code: 

import feedparser
from xml.sax import saxutils

feed_number=200

feed_list = open("feed_listing.conf","r")
for each_feed in feed_list:
data=feedparser.parse(each_feed)
feed_title=data.entries[0].title
xml_output=open("xml_data\\feed" + str(feed_number) + ".xml", "w")
xml_output.write = (feed_title)
xml_output.close()
feed_number+=1

Error Message:

Traceback (most recent call last):
  File "C:/My_Blogroll/JJ_Blogroll2", line 11, in ?
xml_output.write = (feed_title)
AttributeError: 'file' object attribute 'write' is read-only

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


Re: Python newbie with a problem writing files

2006-09-03 Thread limodou
On 9/4/06, John Jones <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I have been driven insane by this error. I have this small program, shown 
> below, which runs great until it gets to writing the data out to the file. I 
> am running an install of Python 2.4. Yes, feedparser is functioning fine (I 
> put in print feed_title statements as tests - but have since removed them). I 
> am missing something obvious.
>
> Thanks
> JJ
>
> Code:
>
> import feedparser
> from xml.sax import saxutils
>
> feed_number=200
>
> feed_list = open("feed_listing.conf","r")
> for each_feed in feed_list:
> data=feedparser.parse(each_feed)
> feed_title=data.entries[0].title
> xml_output=open("xml_data\\feed" + str(feed_number) + ".xml", "w")
> xml_output.write = (feed_title)

Maybe there is a extra '=', if it should be:

xml_output.write(feed_title)

?

> xml_output.close()
> feed_number+=1
>
> Error Message:
>
> Traceback (most recent call last):
>   File "C:/My_Blogroll/JJ_Blogroll2", line 11, in ?
> xml_output.write = (feed_title)
> AttributeError: 'file' object attribute 'write' is read-only
>

-- 
I like python!
My Blog: http://www.donews.net/limodou
UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad
UliPad Maillist: http://groups.google.com/group/ulipad
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Syntax suggestion.

2006-09-03 Thread Alex Martelli
samir <[EMAIL PROTECTED]> wrote:

> > But how would you discern between a function reference and a function
> > call?
> 
> That would be a problem with two solutions:
> 1- If the function doesn't have any parameters, it will be called with
> the empty parentheses (just like usual!);
> 2- to indicate that this is a function call, we would be adding a $ at
> the end of the statement.

What a mess it would be to disambiguate statements such as

x = foo bar baz bat

is it x = (foo, bar, baz, bat)
or x = foo(bar, baz, bat)
or x = foo(bar(baz), bat)
or x = foo(bar, baz(bat))
or x = foo(bar(baz, bat))
or ... [even ignoring the possibility that one or more of these might be
functions callable without arguments...!!!]...

iPython has some heuristics that may be reasonable for the commandline
(and are, in any case, at least simple), but in practice I find that I
go back to using the good old interactive Python interpreter rather than
putting up with even those simple heuristics.


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


Python newbie with a problem writing files

2006-09-03 Thread John J. Jones








Doh!!! You are right. It was staring me in the face. I
shouldn’t have that ‘=’ sign at all!! I removed it and it
works!! Now I just have to put in a routine to remove non-ascii characters from
the data before writing it and all will be golden.  

 

Thanks

JJ






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

Re: Timeline for Python?

2006-09-03 Thread Ray
Sebastian Bassi wrote:
> Hello all,
>
> I am working on a Python book, since it could be completed in about a
> year (writing time + edition + publishing) or more, I would like to
> know what version to target since I don't want to release a book that
> will be outdated just after is printed.
> I use 2.4 for everyday work but most webservers still carry 2.2 (and
> most programs runs w/o any modification, since I don't tend to use new
> features), but publishers know that people like to buy lasted version
> books.

But also there are a lot of books about 2.2 already--I've got quite a
number of them and if I really have to go down to 2.2 I can always
return back to them. For new books definitely 2.5--how can you possibly
target something that will have an alpha *probably* released sometime
in 2007? And may be released in 2008 or even 2009? Your book may be
obsolete the moment it comes out if you're targeting an alpha.

> So, if the book is published in October 2007, should feature Python 3
> or Python 2.5?
> I did read http://www.python.org/dev/peps/pep-3000/ but I still not
> sure about timeline.

>From the document, looks like even BDFL ain't sure, just a general
estimate of sometime in 2007 and release in maybe 2008 if we're lucky
:)

>
> Best regards,
> SB.
>
> --
> Bioinformatics news: http://www.bioinformatica.info
> Lriser: http://www.linspire.com/lraiser_success.php?serial=318

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


Re: Timeline for Python?

2006-09-03 Thread Ray

crystalattice wrote:
> I'd write for 2.4, even though 2.5 should be coming out "shortly".
> There aren't many significant changes to the whole language between 2.4
> and 2.5.  Probably the best thing is write for 2.4 and have a sidenote
> stating where 2.5 operates differently.

Python in a Nutshell 2nd edition already covers 2.5. Now if I can get
my hands on a copy... for some reason it's always out of stock!
:(

>
> The Python 3 timeline is almost a moving target right now; personally,
> I don't think it will be out before next winter.  Maybe a beta but I
> doubt the full version.

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


Re: newbe question about removing items from one file to another file

2006-09-03 Thread [EMAIL PROTECTED]

Simon Forman wrote:
> [EMAIL PROTECTED] wrote:
> > Anthra Norell wrote:
> > > Dexter,
> > >
> > > I looked at the format specification. It contains an example:
> > >
> > > ---
> > >
> > > ;
> > >   ; test.csd - a Csound structured data file
> > >
> > > 
> > >   -W -d -o tone.wav
> > > 
> > >
> > > ;optional section
> > >   Before 4.10  ;these two statements check for
> > >   After 4.08   ;   Csound version 4.09
> > > 
> > >
> > > 
> > >   ; originally tone.orc
> > >   sr = 44100
> > >   kr = 4410
> > >   ksmps = 10
> > >   nchnls = 1
> > >   instr   1
> > >   a1 oscil p4, p5, 1 ; simple oscillator
> > >  out a1
> > > endin
> > > 
> > >
> > > 
> > >   ; originally tone.sco
> > >   f1 0 8192 10 1
> > >   i1 0 1 2 1000 ;play one second of one kHz tone
> > >   e
> > > 
> > >
> > > 
> > >
> > > -
> > >
> > > If I understand correctly you want to write the instruments block to a 
> > > file (from  to )? Right? Or
> > > each block to its own file in case there are several?. You want your code 
> > > to generate the file names? Can you confirm this or
> > > explain it differently?
> > >
> > > Regards
> > >
> > > Frederic
> > >
> > >
> > > - Original Message -
> > > From: <[EMAIL PROTECTED]>
> > > Newsgroups: comp.lang.python
> > > To: 
> > > Sent: Monday, August 28, 2006 10:48 AM
> > > Subject: Re: newbe question about removing items from one file to another 
> > > file
> > >
> > >
> > > >
> > > > Anthra Norell wrote:
> > > > > Eric,
> > > > >Having played around with problems of this kind for quite some 
> > > > > time I find them challenging even if I don't really have time
> > > to
> > > > > get sidetracked. Your description of the problem makes it all the 
> > > > > more challenging, because its 'expressionist' quality adds the
> > > > > challenge of guessing what you mean.
> > > > >I'd like to take a look at your data, if you would post a segment 
> > > > > on which to operate, the same data the way it should look
> > > in
> > > > > the end. In most cases this is pretty self-explanatory. Explain the 
> > > > > points that might not be obvious to a reader who knows
> > > nothing
> > > > > about your mission.
> > > > >
> > > > > Frederic
> > > > >
> > > > > - Original Message -
> > > > > From: <[EMAIL PROTECTED]>
> > > > > Newsgroups: comp.lang.python
> > > > > To: 
> > > > > Sent: Sunday, August 27, 2006 11:35 PM
> > > > > Subject: newbe question about removing items from one file to another 
> > > > > file
> > > > >
> > > > >
> > > > > > def simplecsdtoorc(filename):
> > > > > > file = open(filename,"r")
> > > > > > alllines = file.read_until("")
> > > > > > pattern1 = re.compile(" > > > > > orcfilename = filename[-3:] + "orc"
> > > > > > for line in alllines:
> > > > > > if not pattern1
> > > > > >  print >>orcfilename, line
> > > > > >
> > > > > > I am pretty sure my code isn't close to what I want.  I need to be 
> > > > > > able
> > > > > > to skip html like commands from  to  and to key 
> > > > > > on
> > > > > > another word in adition to  to end the routine
> > > > > >
> > > > > > I was also looking at se 2.2 beta but didn't see any easy way to 
> > > > > > use it
> > > > > > for this or for that matter search and replace where I could just 
> > > > > > add
> > > > > > it as a menu item and not worry about it.
> > > > > >
> > > > > > thanks for any help in advance
> > > > > >
> > > > > > --
> > > > > > http://mail.python.org/mailman/listinfo/python-list
> > > >
> > > > sorry about that this is a link to a discription of the format
> > > > http://kevindumpscore.com/docs/csound-manual/commandunifile.html
> > > > It is possible to have more than one instr defined in an .csd file so I
> > > > would need to look for that string also if I want to seperate the
> > > > instruments out.
> > > >
> > > > http://www.dexrow.com
> > > >
> > > > --
> > > > http://mail.python.org/mailman/listinfo/python-list
> >
> > I need to take it between the blocks only I also need to make sure I
> > only take one instrument
> > defined in this example with the code instr   1 I also need the code
> >
> > 
> > >   ; originally tone.orc
> > >   sr = 44100
> > >   kr = 4410
> > >   ksmps = 10
> > >   nchnls = 1
> >
> > regardless of what instrument I take.  The function would have to
> > except the instrument number as an argument
> >
> > http://www.dexrow.com
>
> Using BeautifulSoup and the interactive interpreter, I figured out the
> following script in about 15 minutes:
>
> # s is a string containing the example file from above.
>
> from BeautifulSoup import BeautifulStoneSoup
>
> soup = BeautifulStoneSoup(s)
> csin = soup.contents[0].contents[5]
> lines = csin.string.splitlines()
>
> print csin.string
>
> It prints:
>
>   ; originally tone.orc
>   sr = 44100
>   kr = 4410
>   ksmps = 10
>   nchnls = 1
>   instr   1
>   a1 oscil p4, p5, 1 ; simple oscillator
>

Re: newbe question about removing items from one file to another file

2006-09-03 Thread [EMAIL PROTECTED]

Anthra Norell wrote:
> Dexter,
>
> I looked at the format specification. It contains an example:
>
> ---
>
> ;
>   ; test.csd - a Csound structured data file
>
> 
>   -W -d -o tone.wav
> 
>
> ;optional section
>   Before 4.10  ;these two statements check for
>   After 4.08   ;   Csound version 4.09
> 
>
> 
>   ; originally tone.orc
>   sr = 44100
>   kr = 4410
>   ksmps = 10
>   nchnls = 1
>   instr   1
>   a1 oscil p4, p5, 1 ; simple oscillator
>  out a1
> endin
> 
>
> 
>   ; originally tone.sco
>   f1 0 8192 10 1
>   i1 0 1 2 1000 ;play one second of one kHz tone
>   e
> 
>
> 
>
> -
>
> If I understand correctly you want to write the instruments block to a file 
> (from  to )? Right? Or
> each block to its own file in case there are several?. You want your code to 
> generate the file names? Can you confirm this or
> explain it differently?
>
> Regards
>
> Frederic
>
>
> - Original Message -
> From: <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Monday, August 28, 2006 10:48 AM
> Subject: Re: newbe question about removing items from one file to another file
>
>
> >
> > Anthra Norell wrote:
> > > Eric,
> > >Having played around with problems of this kind for quite some time I 
> > > find them challenging even if I don't really have time
> to
> > > get sidetracked. Your description of the problem makes it all the more 
> > > challenging, because its 'expressionist' quality adds the
> > > challenge of guessing what you mean.
> > >I'd like to take a look at your data, if you would post a segment on 
> > > which to operate, the same data the way it should look
> in
> > > the end. In most cases this is pretty self-explanatory. Explain the 
> > > points that might not be obvious to a reader who knows
> nothing
> > > about your mission.
> > >
> > > Frederic
> > >
> > > - Original Message -
> > > From: <[EMAIL PROTECTED]>
> > > Newsgroups: comp.lang.python
> > > To: 
> > > Sent: Sunday, August 27, 2006 11:35 PM
> > > Subject: newbe question about removing items from one file to another file
> > >
> > >
> > > > def simplecsdtoorc(filename):
> > > > file = open(filename,"r")
> > > > alllines = file.read_until("")
> > > > pattern1 = re.compile(" > > > orcfilename = filename[-3:] + "orc"
> > > > for line in alllines:
> > > > if not pattern1
> > > >  print >>orcfilename, line
> > > >
> > > > I am pretty sure my code isn't close to what I want.  I need to be able
> > > > to skip html like commands from  to  and to key on
> > > > another word in adition to  to end the routine
> > > >
> > > > I was also looking at se 2.2 beta but didn't see any easy way to use it
> > > > for this or for that matter search and replace where I could just add
> > > > it as a menu item and not worry about it.
> > > >
> > > > thanks for any help in advance
> > > >
> > > > --
> > > > http://mail.python.org/mailman/listinfo/python-list
> >
> > sorry about that this is a link to a discription of the format
> > http://kevindumpscore.com/docs/csound-manual/commandunifile.html
> > It is possible to have more than one instr defined in an .csd file so I
> > would need to look for that string also if I want to seperate the
> > instruments out.
> >
> > http://www.dexrow.com
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list

sorry I responded to the wrong post...  I was having trouble figuring
out the buitiful soup download

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


Re: newbe question about removing items from one file to another file

2006-09-03 Thread [EMAIL PROTECTED]

Anthra Norell wrote:
> Dexter,
>
> Here's a function that screens out all instrument blocks and puts them into a 
> dictionary keyed on the instrument number:
>
> 
>
> def get_instruments (file_name):
>
>INSIDE  = 1
>OUTSIDE = 0
>
>f = file (file_name, 'ra')
>state = OUTSIDE
>instruments = {}
>instrument_segment = ''
>
>for line in f:
>   if state == OUTSIDE:
>  if line.startswith (' state = INSIDE
> instrument_segment += line
>   else:
>  instrument_segment += line
>  if line.lstrip ().startswith ('instr'):
> instrument_number = line.split () [1]
>  elif line.startswith (' instruments [instrument_number] = instrument_segment
> instrument_segment = ''
> state = OUTSIDE
>
>f.close ()
>return instruments
>
> 
>
> You have received good advice on using parsers: "beautiful soup" or 
> "pyparse". These are powerful tools capable of doing complicated
> extractions. Yours is not a complicated extraction. Simon tried it with 
> "beautiful soup". That seems simple enough, though he finds
> the data by index leaving open where he gets the index from. There's surely a 
> way to get the data by name.
>   Contrary to the parser the function will miss if tags take liberties 
> with upper-lower case letters as they are probably
> allowed by the specification. A regular expression might have to be used, if 
> they do.
>  From your description I haven't been able to infer what the final format 
> of your data is supposed to be. So I cannot tell you
> how to go on from here. You'll find out. If not, just keep asking.
>
> The SE solution which you said couldn't work out would be the following. It 
> makes the same dictionary the function makes and it is
> case-insensitive:
>
> 
>
> >>> Instrument_Segment_Filter = SE.SE (' 
> >>> "~(?i)(.|\n)*?~==\n\n"  ')
> >>> instrument_segments= Instrument_Segment_Filter ('file_name', '')
> >>> print instrument_segments
> (... see all instrument segments ...)
> >>> Instrument_Number = SE.SE (' ~instr.*~==\n')
> >>> instruments ={}
> >>> for segment in instrument_segments.split ('\n\n'):
> if segment:
>instr_line = Instrument_Number (segment)
>instrument_number = instr_line.split ()[1]
>instruments [instrument_number] = segment
>
> --
>
> (If you're on Windows and the CRs bother you, take them out with an 
> additional definition when you make your
> Instrument_Block_Filter: (13)=  or  "\r=")
>
>
> Regards
>
> Frederic
>
>
> - Original Message -
> From: <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Wednesday, August 30, 2006 1:51 AM
> Subject: Re: newbe question about removing items from one file to another file
>
>
> >
> > Anthra Norell wrote:
> > > Dexter,
> > >
> > > I looked at the format specification. It contains an example:
> > >
> > > ---
> > >
> > > ;
> > >   ; test.csd - a Csound structured data file
> > >
> > > 
> > >   -W -d -o tone.wav
> > > 
> > >
> ...
> etc.

I cut and pasted this..  It seems to be crashing my program.. I am not
sure that I have all the right imports..  seems to be fine when I go to
an older version of the file...  I uploaded it onto source forge.

https://sourceforge.net/project/showfiles.php?group_id=156455&package_id=201306&release_id=444362
http://www.dexrow.com

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


Re: Python newbie with a problem writing files

2006-09-03 Thread Mike Kent

> feed_list = open("feed_listing.conf","r")

What could it be about the above line that means "Open this file for
READ ONLY"?

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


Re: Python newbie with a problem writing files

2006-09-03 Thread Tim Chase
>> feed_list = open("feed_listing.conf","r")
> 
> What could it be about the above line that means "Open this file for
> READ ONLY"?

Oooh, oooh, I know!  If you rot13 the file-name, it comes back as 
"srrq_yvfgvat.pbas".  The double "r"s in the file-name instruct 
python to open the file as "really read-only".  And the .pbas 
means you need to be opening the file with python-basic, not python.

:)

-tkc




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


Re: Exception EOFError.

2006-09-03 Thread Dr. Pastor
Thank you Sir.

Dr. Pastor wrote:
> Python 2.5b3 on Windows XP.
> 
> (exception EOFError
> Raised when one of the built-in functions (input() or
> raw_input()) hits an end-of-file condition (EOF) without reading any data.)
> 
> For me, raw_input (hit enter) returns an empty string!
> (>>> x=raw_input()
> 
>  >>> x
> ''
>  >>> )
> 
> Any confirmation?
> Regards.
> 
> == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
> News==
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
> Newsgroups
> = East and West-Coast Server Farms - Total Privacy via Encryption =

== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python newbie with a problem writing files

2006-09-03 Thread John Machin
Mike Kent wrote:
> > feed_list = open("feed_listing.conf","r")
>
> What could it be about the above line that means "Open this file for
> READ ONLY"?

That's his *INPUT* file. The error referred to his *OUTPUT* file, and
in any case the complain was that the "write" attribute was read-only,
*NOT* the ferschlugginer file itself.

"Sheesh!" * 2

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


What does mod_python.publisher handler do?

2006-09-03 Thread yaru22
I was reading Chapter 6.1 in mod_python manual at www.python.org.

The manual simply says:

The publisher handler is a good way to avoid writing your own handlers
and focus on rapid application development.

I still don't understand what this publisher handler is for.

Can someone elaborate the above phrase with some examples please?

Thanks in advance.

Regards,
Brian

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


python-database

2006-09-03 Thread sridhar
is there any way to call stored procedures from python as in java?

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


Re: python-database

2006-09-03 Thread Cliff Wells
On Sun, 2006-09-03 at 21:30 -0700, sridhar wrote:
> is there any way to call stored procedures from python as in java?

I mostly use PostgreSQL, so perhaps it's different for some other
databases, but calling stored procedures doesn't require any special
support from the language or driver.  Usually you simply SELECT from the
stored procedure.

Also, you might be interested to know that with PostgreSQL you can also
*write* stored procedures in Python which I consider a huge plus.

Regards,
Cliff

-- 

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


Re: What does mod_python.publisher handler do?

2006-09-03 Thread Steve Holden
yaru22 wrote:
> I was reading Chapter 6.1 in mod_python manual at www.python.org.
> 
> The manual simply says:
> 
> The publisher handler is a good way to avoid writing your own handlers
> and focus on rapid application development.
> 
> I still don't understand what this publisher handler is for.
> 
> Can someone elaborate the above phrase with some examples please?
> 
> Thanks in advance.
> 
I think perhaps your reading of the documentation has been a little less 
than assiduous. Does


 http://www.modpython.org/live/current/doc-html/hand-pub.html

make it any clearer? There the examples show you exactly how to use the 
handler, and the point of providing it is to allow you to use mod_python 
without going to the trouble of writing your own handler.

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