Re: How to write python plug-ins for your own python program?

2005-03-03 Thread hemanth
Andre wrote:
> Mark Rowe <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
> > On Mar 3, 2005, at 9:33 PM, Simon Wittber wrote:
> >
> > >> You mean like 'import'? :)
> > >
> > > That's how I would do it. It's the simplest thing, that works.
> > >
> > > exec("import %s as plugin" % pluginName)
> > > plugin.someMethod()
> > >
> > > where pluginName is the name of the python file, minus the ".py"
> > > extension.
> >
> > A better method would be something along the lines of:
> >
> > plugin = __import__(pluginName)
> > plugin.someMethod()
> >
> > This avoids the potential security problem that `exec' poses as
well as
> > the need to parse + interpret the string.
> >
> What happens if you have:
> .def someMethod():
> .import os
> .rm * # or whatever other evil thing you might thing of
>
> Andre


Some time back I remember discussions on plugin risks in
Leo (leo.sf.net). The conclusion was someone can always harm
your system by writing a nasty plugin. Hence you should always
use plugins from sources you can trust. I don't know if there
is any alternative way in Python to have safe third party
plugins.

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


ANN: gdmodule 0.54

2005-03-03 Thread Chris Gonnerman
Announcing the release of version 0.54 of the gdmodule for Python.
gdmodule is the "standard" module providing access to Thomas
Boutell's GD "Graphics Drawing" library.  This release includes many
bugfixes, and paves the way for another update in the near future to
support the newest GD versions.
Thanks to Greg Hewgill, Christopher Stone, Matti Jagula, Sadruddin 
Rejeb, and Betty Li for assisting in this release, either in terms
of reporting bugs or actually providing patches.

Due to the constant change in the GD library API, I keep all the old 
versions of gdmodule on my website alongside the current version.
You can download gdmodule from:

   http://newcenturycomputers.net/projects/gdmodule.html
--
Chris Gonnerman

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


Re: Text To Speech with pyTTS

2005-03-03 Thread Peter
I released a new version of the Windows installer for Python 2.3 that
includes the missing _TTSFast.pyd file.


Peter Hansen wrote:
> Mike P. wrote:
> > I was wondering if anyone has had any luck with the python text to
speech
> > (pyTTS) module available on Sourceforge:
> > http://sourceforge.net/projects/uncassist
>
> I saw the following blog entry by Joey deVilla:
>
http://farm.tucows.com/blog/Platforms/Windows/_archives/2005/1/19/266813.html
>
> and immediately tried it out.  All I did was download the
> PyTTS package for Python (2.4, not 2.3), and install it,
> then ran Joey's sample above.  It worked as advertised.
> This was on Windows XP SP2.
> 
> -Peter

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


Re: Explicit or general importing of namespaces?

2005-03-03 Thread Peter Hansen
Peter Mayne wrote:
Peter Hansen wrote:
and it's still a bad idea in almost all cases anyway
Since I've been playing with PyQt lately...
Is qt not one of the "almost all" cases? From the limited number of 
examples I've seen, it seems to be common to do

from qt import *
This sort of thing seems common amongst large frameworks such
as PyQt or wxPython.  This is unfortunate, IMHO, though it isn't
really a serious concern for most users.
I'm grateful that the most recent versions of wxPython have
abandoned that approach in favour of a nice clean "import wx",
and as far as I can tell the code does not suffer as a result,
and gains substantially in clarity.  Maybe the "qt" module
defines far fewer names than the "wx" module does, but I for
one am glad not to have to worry that I won't accidentally
conflict with the hundreds that are there (in wx), nor to
worry that my code lacks in readability.
Since most of the imported names start with "Q", are called QLabel, 
QSlider, etc, and are generally recognisable in context, this would seem 
to be a reasonable case of namespace pollution.

I'm certainly not arguing with the general premise, just wondering if qt 
is one of the sensible exceptions.
If not sensible, at least fairly widely accepted, not a serious
impediment to effective use, and definitely not without precedent.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Final PyCon Keynote from Google Speaker

2005-03-03 Thread Steve Holden

Dear Python Colleague:

I am happy to say that we have now completed the
PyCon DC 2005 keynote speaker lineup, and that the
final keynote will be given by Greg Stein, an
engineering manager wirh Google's Blogger group,
who will be speaking on "Python at Google"

Greg is also known to many in the open source world
as the chairman of the Apache Foundation, and he is
a significant contributor to Subversion, WebDAV and
Python.

With the opening keynote from a Microsoft speaker,
the second keynote from Guido van Rossum (the
inventor of Python) and the last keynote from
Google, PyCon is beginning to demonstrate just
how significant Python has become in the modern
world of software and Internet services.

I hope you will join me in DC from March 23-25,
and possibly attend the four-day sprint being
held immediately before the conference. Pre-
conference registration is available via

  http://www.python.org//pycon/2005/register.html

This is going to be a great opportunity for all
those with an interest in Python to see just how
far the language has come.


regards
Steve Holden
Chairman, PyCON DC 2005
-- 
PyCon DC 2005: The third Python Community Conference
http://www.pycon.org/   http://www.python.org/pycon/
The scoop on Python implementations and applications
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help

2005-03-03 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
It sounds to me like they just don't have the correct hostname (or
their DNS service is down).  Again, this could be seen from answering
the above questions.
Hmm what can be seen from reading Brian's message is that
it clearly cannot be a simple matter of incorrect hostname,
or an inability to connect at all.  He said they can connect
twice before they get the error.
And unfortunately there are many places where ICMP packets,
including "echo" and "echo response", have been disabled for
security reasons.  The inability to ping does not necessarily
mean anything about the ability to establish TCP sessions.
In the end, however, it does seem unlikely that this has
much to do with Python...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Initializing subclasses of tuple

2005-03-03 Thread Steven Bethard
Nick Coghlan wrote:
Any volunteers out there willing to put some words about __new__ 
together for the main Python docs, please consider posting them on SF :)
Done.
http://sourceforge.net/tracker/?func=detail&aid=1156412&group_id=5470&atid=105470
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: How would you program this?

2005-03-03 Thread engsol
On Thu, 03 Mar 2005 19:32:19 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:

>engsol wrote:
>> I don't fully understand this line of your code:
>> return [(a,b,c) for a in ns for b in ns for c in ns if a + b + c == limit]
>> If  the "if" part is true, does it  'trigger' the return?
>
>This code is basically equivalent to:
>
>lc = []
>for a in ns:
> for b in ns:
> for c in ns:
> if a + b + c == limit:
> lc.append((a, b, c))
>return lc
>
>Does that help?
>
>STeVe

Now it's clearthank you.
Norm B

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


RE: convert a list to a string?

2005-03-03 Thread Anthony Liu
Oh, yes, that's a cool function! I did that before but
have forgotten.

Thanks a lot!

--- Tony Meyer <[EMAIL PROTECTED]> wrote:

> > Suppose I have a list 
> > 
> > myList = ["this", "is", "a", "sample", "list"]
> > 
> > If I don't want to iterate through it and
> concatenate
> > the list elements, how do I easily convert it to a
> > string like
> > 
> > "this is a sample list"
> 
> " ".join(myList)
> 
> =Tony.Meyer
> 
> 





__ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert a list to a string?

2005-03-03 Thread Roy Smith
Anthony Liu <[EMAIL PROTECTED]> wrote:

> Suppose I have a list 
> 
> myList = ["this", "is", "a", "sample", "list"]
> 
> If I don't want to iterate through it and concatenate
> the list elements, how do I easily convert it to a
> string like
> 
> "this is a sample list"

You want:

>>> myList = ["this", "is", "a", "sample", "list"]
>>> " ".join (myList)
'this is a sample list'
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: convert a list to a string?

2005-03-03 Thread Tony Meyer
> Suppose I have a list 
> 
> myList = ["this", "is", "a", "sample", "list"]
> 
> If I don't want to iterate through it and concatenate
> the list elements, how do I easily convert it to a
> string like
> 
> "this is a sample list"

" ".join(myList)

=Tony.Meyer

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


Re: jython question (interesting behavior)

2005-03-03 Thread Kent Johnson
pythonUser_07 wrote:
Is this the correct place to post a jython question?
I posted the following in the jython group, but I figured I'd post here
too:
_
I am assuming that the PythonInterpreter environment is not a unique
environment from within a jvm.
Here is some pseudo code to show what I am talking about
1) create a jython module  file, lets call it "mytest"
   with a simple static class
   class simpleS:
  myVar = "test01"
2) Now set up two interpreter environments from within
   the same jvm
   PythonInterpreter py = new PythonInterpreter()
   PythonInterpreter py1 = new PythonInterpreter()
3) now in both interpreters, import the module
   py.exec("import mytest")
   py1.exec("import mytest")
   Now for both interpreters run
   "print mytest.simpleS.myVar"
4) Now for the crazy part.
   in the py interpreter run
   "mytest.simpleS.myVar = 'test02'
   in py1 look at the value
   "print mytest.simpleS.myVar"
Very interesting behavior.  So it seems that each python interpreter
instance does not act as its own seperate space.
My understanding is that the two PythonInterpreters wrap a single PySystemState which is where the 
modules are cached. So they share the same modules. If you want different behaviour you should give 
them each their own PySystemState.

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


Virus Quarantine Notification

2005-03-03 Thread NetCarrier Virus Filter
Dear python-list@python.org,

Do not reply to this message.
An email message you sent to [EMAIL PROTECTED] with the subject "Returned mail: 
see transcript for details" appears to contain a virus and has been quarantined 
for everyone's safety. If you have any questions, please contact us at [EMAIL 
PROTECTED]


NetCarrier
http://www.netcarrier.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


convert a list to a string?

2005-03-03 Thread Anthony Liu
Suppose I have a list 

myList = ["this", "is", "a", "sample", "list"]

If I don't want to iterate through it and concatenate
the list elements, how do I easily convert it to a
string like

"this is a sample list"

str(myList) will only give you things like

"["this", "is", "a", "sample", "list"]"

That is not what I want.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Grid not getting updated

2005-03-03 Thread Gensek
Thanks. It seems to be working.

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


Re: There's GOT to be a better way!

2005-03-03 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
This would be a good case to use OO design, imo.  The following works
fine.  Simply instantiate the object, call the method, and you can
access (and manipulate) the "module's" variable to your heart's
content.
module.py
class object:
Ouch. Use a different name than 'object', which is the base class of all 
new-style classes.
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: winnt win32process.createProcess with stdout to file ?

2005-03-03 Thread Roger Upole
If it got past the CreateFile call, the problem's not with the log file.
This error from CreateProcess means it can't find your executable.

   Roger

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Roger, I updated the script (below).. but now I get errors...
> many thanks for your help.
>
> import win32process, win32file, win32security, win32con, win32api,
> thread, win32event, win32pipe
>
> cmd = "c:/myexe.exe"
> sa = win32security.SECURITY_ATTRIBUTES()
> sa.bInheritHandle = 1
>
> startInfo = win32process.STARTUPINFO()
> startInfo.dwFlags = win32process.STARTF_USESTDHANDLES
>
> fh = win32file.CreateFile("c:/mylog.log", win32file.GENERIC_WRITE,
> win32file.FILE_SHARE_READ|win32file.FILE_SHARE_WRITE, sa,
> win32file.OPEN_ALWAYS, win32file.FILE_FLAG_SEQUENTIAL_SCAN  , 0)
> startInfo.hStdOutput = fh
> startInfo.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
> startInfo.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)
>
> hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess
> \
> ( None, cmd, sa, sa, 1, win32con.NORMAL_PRIORITY_CLASS, None, None,
> startInfo)
>
>
> ERROR:
> pywintypes.error:(2, 'createProcess', ' the system cannot find the file
> specified.;)
>
> it's strange that it gets this error even though i have the
> win32file.OPEN_ALWAYS flag set..
>
> any suggestions... (soo... close!! )
> thanks, thanks!
> david
> 



== Posted via Newsfeeds.Com - Unlimited-Uncensored-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: Multiline regex help

2005-03-03 Thread Kent Johnson
Steven Bethard wrote:
Kent Johnson wrote:
for line in raw_data:
if line.startswith('RelevantInfo1'):
info1 = raw_data.next().strip()
elif line.startswith('RelevantInfo2'):
info2 = raw_data.next().strip()
elif line.startswith('RelevantInfo3'):
info3 = raw_data.next().strip()
scores.setdefault(info1, {}).setdefault(info3, []).append(info2)
info1 = info2 = info3 = None

Very pretty. =)  I have to say, I hadn't ever used iterators this way 
before, that is, calling their next method from within a for-loop.  I 
like it. =)
I confess I have a nagging suspicion that someone who actually knows something about CPython 
internals will tell me why it's a bad idea...but it sure is handy!

Thanks for opening my mind. ;)
My pleasure :-)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best way to handle a command line argument that includes an escape sequence like \n?

2005-03-03 Thread Joe
Hey no fair changing last names in the middle of a thread :-)

Thanks to BOTH Steve's.


> In fairness it was Steven Bethard's solution that gave you the solution 
> you needed. As long as ytour problem is solved, that's fine, and it 
> appears that you've solved it in a reasonably cross-platform way.
>
> Steve Holden   http://www.holdenweb.com/ 


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


Re: How would you program this?

2005-03-03 Thread Steven Bethard
engsol wrote:
I don't fully understand this line of your code:
return [(a,b,c) for a in ns for b in ns for c in ns if a + b + c == limit]
If  the "if" part is true, does it  'trigger' the return?
This code is basically equivalent to:
lc = []
for a in ns:
for b in ns:
for c in ns:
if a + b + c == limit:
lc.append((a, b, c))
return lc
Does that help?
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: creating .NET clients with python

2005-03-03 Thread Luis M. Gonzalez
At this time, Ironpython is in pre-alpha state, not suitable for
production work.
However, we will have news about it in the next Pycon 2005, which will
be held by the end of March.

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


Re: winnt win32process.createProcess with stdout to file ?

2005-03-03 Thread david . humpherys
Roger, I updated the script (below).. but now I get errors...
many thanks for your help.

import win32process, win32file, win32security, win32con, win32api,
thread, win32event, win32pipe

cmd = "c:/myexe.exe"
sa = win32security.SECURITY_ATTRIBUTES()
sa.bInheritHandle = 1

startInfo = win32process.STARTUPINFO()
startInfo.dwFlags = win32process.STARTF_USESTDHANDLES

fh = win32file.CreateFile("c:/mylog.log", win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ|win32file.FILE_SHARE_WRITE, sa,
win32file.OPEN_ALWAYS, win32file.FILE_FLAG_SEQUENTIAL_SCAN  , 0)
startInfo.hStdOutput = fh
startInfo.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
startInfo.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)

hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess
\
( None, cmd, sa, sa, 1, win32con.NORMAL_PRIORITY_CLASS, None, None,
startInfo)


ERROR:
pywintypes.error:(2, 'createProcess', ' the system cannot find the file
specified.;)

it's strange that it gets this error even though i have the
win32file.OPEN_ALWAYS flag set..

any suggestions... (soo... close!! )
thanks, thanks!
david

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


Re: How to write python plug-ins for your own python program?

2005-03-03 Thread Andre
Mark Rowe <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> On Mar 3, 2005, at 9:33 PM, Simon Wittber wrote:
> 
> >> You mean like 'import'? :)
> >
> > That's how I would do it. It's the simplest thing, that works.
> >
> > exec("import %s as plugin" % pluginName)
> > plugin.someMethod()
> >
> > where pluginName is the name of the python file, minus the ".py" 
> > extension.
> 
> A better method would be something along the lines of:
> 
> plugin = __import__(pluginName)
> plugin.someMethod()
> 
> This avoids the potential security problem that `exec' poses as well as 
> the need to parse + interpret the string.
> 
What happens if you have:
.def someMethod():
.import os
.rm * # or whatever other evil thing you might thing of

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


Re: How would you program this?

2005-03-03 Thread engsol
On Thu, 3 Mar 2005 15:32:36 -0500, Bill Mill <[EMAIL PROTECTED]> wrote:

>On Thu, 03 Mar 2005 10:52:23 -0800, engsol <[EMAIL PROTECTED]> wrote:
>> 
>> The diagonal constraint is interestingit seems to affect the number of
>> solutions. One surprise, (not being a math major), was that when I let the
>> brute force run (forever, it seemed), but without the diagonal 
>> qualification(s),
>> there was maybe 100 solutions. The reson it was a surprise it that years
>> ago a programmer used the row-sum, col-sum method to detect and correct
>> data errors. He swore it was robust, and 100% reliable. Seems that that
>> isn't the case.
>
>I think that it probably is a decent gut-check for data errors, for
>the simple reason that changing one number requires, at a minimum,
>three other changes in order to maintain both the row and column sums.
>If you have at least a decent data fidelity rate, that is unlikely to
>happen, and even if it does, very very unlikely to happen in such a
>way that the row and column sums are maintained; especially as the
>number of rows and columns grows.
>
>Better to just do a crc or a hash of the data though.
>
>Peace
>Bill Mill
>bill.mill at gmail.com

You make a good point Bill, and are entirely correct. 
I never liked that programmer, and was too hasty in 
condeming his work...shame on meI was unfair.

BTW, I ran the code you suggested, (I like your approach), after
correcting the A cell value (should have 5 vice 3 as I posted). There seems
to be 16 solutions, one of which agrees with the puzzle author.

I don't fully understand this line of your code:
return [(a,b,c) for a in ns for b in ns for c in ns if a + b + c == limit]
If  the "if" part is true, does it  'trigger' the return?
Norm B

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


BayPIGgies: March 10, 7:30pm (FINAL MEETING AT STANFORD)

2005-03-03 Thread Aahz
WARNING: the last meeting of BayPIGgies at Stanford is currently
scheduled for March.  Our host, Danny Yoo, is leaving Stanford, and we
need to find a new location.  If you wish to assist with the search,
please join the BayPIGgies mailing list.

Meanwhile, let's all give hearty thanks to Danny for helping us find a
stable meeting location for so long!


The next meeting of BayPIGgies will be Thurs, March 10 at 7:30pm.

Donovan Preston will lead a discussion about using Python with OS X,
including integrating with PyObjC and GNUStep.

BayPIGgies meetings are in Stanford, California.  For more information
and directions, see http://www.baypiggies.net/


Before the meeting, we may meet at 6pm for dinner in downtown Palo Alto.
Discussion of dinner plans is handled on the BayPIGgies mailing list.


Advance notice: The April 14 meeting agenda has not been set.  Please
send e-mail to [EMAIL PROTECTED] if you want to suggest an
agenda -- and a meeting place!
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death."  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter absorb chars

2005-03-03 Thread phil
Jeff Epler wrote:
On Wed, Mar 02, 2005 at 04:58:03PM -0600, phil wrote:
Sorry for the repost, but moderator
jeld the last one,
We saw both posts.

In a Tkinter entry field (or Pmw entry)
how could I eat charactres?
create a binding on the widget for the particular character you want to
treat specially.  If you want to suppress that character, return the
string "break" from the binding.  Example:
from Tkinter import *
t = Tkinter.Tk()
e = Tkinter.Entry(t); e.pack()
e.bind("x", lambda event: "break")
Jeff
Thanks, that helps.
But after noticing an'&' I want to 'disappear'
All characters form the field. But I need to process
those characters in the event handler.
I've already bound ' to inputevent.
Are you saying if I just do:  return 'break' from
inputevent the characters will never see light?
I'll try it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Explicit or general importing of namespaces?

2005-03-03 Thread Peter Mayne
Peter Hansen wrote:
In general, unless the names being imported are *guaranteed*
never to be rebound, it is a very bad idea to use "import *",
and it's still a bad idea in almost all cases anyway, for
reasons already given by others.
Since I've been playing with PyQt lately...
Is qt not one of the "almost all" cases? From the limited number of 
examples I've seen, it seems to be common to do

from qt import *
Since most of the imported names start with "Q", are called QLabel, 
QSlider, etc, and are generally recognisable in context, this would seem 
to be a reasonable case of namespace pollution.

I'm certainly not arguing with the general premise, just wondering if qt 
is one of the sensible exceptions.

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


Re: creating .NET clients with python

2005-03-03 Thread yaipa
> >> Can anyone confirm if there is a python library that
> >> can allow me to create .NET clients in python.

Sorry, the term 'clients' throws me in this case.

PythonNet allows you to call .Net, but not the other way 'round.
So, IronPython would be it if that is what you want to do.

Cheers,

  --Alan

Guy Robinson wrote:
> Thanks Alan,
>
> Are you saying I can create python .net clients with PythonNet. My
understanding
> is I can only use .net clients from python not the other way around.
>
> Do you have an example showing creating a .net client in python?
>
> regards,
>
> Guy
>
> yaipa wrote:
> > Guy,
> >
> > I can tell you that pythonNet is quite far along, rel 1, Beta 4
> > actually.
> >
> > here is a c.l.p link to the three major releases.
> >
> >
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ddfc68767901007c/445f2052948d93e2?q=pythonnet&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fgroup%3Dcomp.lang.python%26q%3Dpythonnet%26qt_g%3D1%26searchnow%3DSearch+this+group%26&_doneTitle=Back+to+Search&&d#445f2052948d93e2
> >
> > Cheers,
> >
> >   --Alan
> >
> >
> > Guy Robinson wrote:
> >
> >>Hello,
> >>
> >>Can anyone confirm if there is a python library that can allow me
to
> >
> > create .NET
> >
> >>clients in python.
> >>
> >>My understanding is both IronPython and python for .NET can't
create
> >
> > python .net
> > 
> >>clients?
> >>
> >>Regards,
> >>
> >>Guy
> > 
> >

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


Re: Need help

2005-03-03 Thread [EMAIL PROTECTED]
I doubt it's a hardware issue... If these people have any knowledge of
computers, they would try connecting to other places to see if it gives
them the same error.  It sounds obvious, but have them ping your DNS
alias as well as your IP address.

If they can't get anywhere else, then it's a local hardware issue to
them.  If they can, run a traceroute program from them to you (or
vica-verca if you can) to see where the connection is halting.  It may
be a hardware issue local to you.  Do you have other clients with the
same problem?  Can you ping them from your server?  These are all
questions you should be using to troubleshoot.

If you can ping to/from client/server then this certainly isn't a
network hardware issue.  And if it was connecting, but blocking a
specific port then your ICMP response would say that rather than "timed
out."  My suggestion to you is get an answer to these questions and
post back here.  You should have done this before ever even thinking
about looking at the source code.  If you did, you should have posted
the results.

It sounds to me like they just don't have the correct hostname (or
their DNS service is down).  Again, this could be seen from answering
the above questions.

G/L

Jay

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


Re: jython question (interesting behavior)

2005-03-03 Thread pythonUser_07
Hmm, now that I think about this, maybe it's not so crazy.

It would be the equivalent of modifying a static variable in the same
JVM.  Sorry to bother.

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


Re: winnt win32process.createProcess with stdout to file ?

2005-03-03 Thread Roger Upole
You'll need to pass security attributes with inherit=True
to CreateProcess also, and the file has to be opened with sharing.
(win32file.FILE_SHARE_READ|win32file.FILE_SHARE_WRITE)
Also, you shouldn't have FILE_FLAG_OVERLAPPED set if you're
not passing an overlapped object into CreateFile.

   hth
  Roger


<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> os:winnt
> python2.3.2
>
> I have a exe that dumps info to the command line.  I want to run this
> process and  capture the stdout into a file.  I think i'm close... any
> help appreciated.
>
> dh
> --
> import win32process, win32file, win32security, win32con, win32api,
> thread, win32event, win32pipe
>
> cmd = "c:/myexe.exe"
> sa = win32security.SECURITY_ATTRIBUTES()
> sa.bInheritHandle = 1
>
> startInfo = win32process.STARTUPINFO()
> startInfo.dwFlags = win32process.STARTF_USESTDHANDLES
>
> fh = win32file.CreateFile("c:/mylog.log", win32file.GENERIC_WRITE, 0,
> sa, win32file.OPEN_EXISTING, win32file.FILE_FLAG_SEQUENTIAL_SCAN |
> win32file.FILE_FLAG_OVERLAPPED , 0)
> startInfo.hStdOutput = fh
> startInfo.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
> startInfo.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)
>
> hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess
> \
> ( None, cmd, None, None, 1, win32con.NORMAL_PRIORITY_CLASS, None, None,
> startInfo)
> 



== Posted via Newsfeeds.Com - Unlimited-Uncensored-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: There's GOT to be a better way!

2005-03-03 Thread [EMAIL PROTECTED]
This would be a good case to use OO design, imo.  The following works
fine.  Simply instantiate the object, call the method, and you can
access (and manipulate) the "module's" variable to your heart's
content.

module.py
class object:
def __init__(self):
self.test = 1
def A(self):
for x in range(10): self.B()

def B(self):
self.test = self.test + 1

main.py
from module import object

MyObj = object()
print MyObj.test
MyObj.A()
print MyObj.test

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


jython question (interesting behavior)

2005-03-03 Thread pythonUser_07
Is this the correct place to post a jython question?

I posted the following in the jython group, but I figured I'd post here
too:
_
I am assuming that the PythonInterpreter environment is not a unique
environment from within a jvm.

Here is some pseudo code to show what I am talking about
1) create a jython module  file, lets call it "mytest"
   with a simple static class
   class simpleS:
  myVar = "test01"
2) Now set up two interpreter environments from within
   the same jvm
   PythonInterpreter py = new PythonInterpreter()
   PythonInterpreter py1 = new PythonInterpreter()
3) now in both interpreters, import the module
   py.exec("import mytest")
   py1.exec("import mytest")
   Now for both interpreters run
   "print mytest.simpleS.myVar"
4) Now for the crazy part.
   in the py interpreter run
   "mytest.simpleS.myVar = 'test02'
   in py1 look at the value
   "print mytest.simpleS.myVar"

Very interesting behavior.  So it seems that each python interpreter
instance does not act as its own seperate space.

Maybe I just have not gotten there yet with the docs.  I did notice
something about the initialize() function associated with the
interpreter which is only supposed to be run once.

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


Re: There's GOT to be a better way!

2005-03-03 Thread Earl Eiland
On Thu, 2005-03-03 at 16:46, Steven Bethard wrote:
> Earl Eiland wrote:
> > module.py
> > def A():
> > test = 1
> > for x in range(10): B()
> > 
> > def B():
> > test = test + 1
> > 
> > 
> > main.py
> > import module
> > module.A()
> > 
> > This will fail, unless test is passed and returned.
> 
> (Sorry if this sent twice.  It wasn't appearing for me the first time.)
> 
> You can use global here, though I wouldn't advise it.
> 
> -- module.py --
> def A():
>  global test
>  test = 1
>  for x in range(10):
>  B()
> def B():
>  global test
>  test = test + 1
> ---
> 
> py> import module
> py> module.A()
> py> module.test
> 11
> 
> This looks like it might be simpler with a class, e.g.:
> 
> -- module.py --
> class A(object):
>  def __init__(self):
>  self.test = 1
>  for x in range(10):
>  self.B()
>  def B(self):
>  self.test += 1
> ---
> 
> py> import module
> py> a = module.A()
> py> a.test
> 11
> 
> STeVe

Guess I'm just gonna have to break down and figure out how to work with
classes!

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


Re: There's GOT to be a better way!

2005-03-03 Thread Earl Eiland
On Thu, 2005-03-03 at 16:43, Steve Holden wrote:
> Earl Eiland wrote:
> > On Thu, 2005-03-03 at 15:11, Steve Holden wrote:
> > 
> >>Earl Eiland wrote:
> >>
> >>>I'm writing my first program where I call custom modules.  The 'global'
> >>>command doesn't seem to apply, so how do I change a variable internally
> >>>in a module without passing it down n layers, and then back out again?
> >>>
> >>
> >>You are correct in assuming that global isn't what you want - it really 
> >>means "global to the module namespace in which it appears".
> >>
> >>However, if two separate pieces of code can both reference the same 
> >>module then one can set an attribute in the module and the other can 
> >>reference it. Don't forget that when you import a module its name 
> >>becomes global within the importing module. Since a module is just a 
> >>glorified namespace, anything that can reference the module can read 
> >>and/or set that module's attributes.
> >>
> >>a.py:
> >>
> >>import something
> >>something.x = "A value"
> >>
> >>b.py:
> >>
> >>import something
> >>print something.x
> >>
> >>will print "A value" as long as a is imported before b.
> > 
> > Right.  That part I figured out.  How does one function in an imported
> > module access a variable in the same module?
> > 
> > module.py
> > def A():
>  global test
> > test = 1
> > for x in range(10): B()
> > 
> > def B():
>  global test
> > test = test + 1
> > 
> > 
> > main.py
> > import module
> > module.A()
>  print module.test
> > 
> > 
> > This will fail, unless test is passed and returned.
> > 
I thought I tried that, and it didn't work.  I must have made some other
mistake.

Thanks.

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


Re: There's GOT to be a better way!

2005-03-03 Thread Steven Bethard
Earl Eiland wrote:
module.py
def A():
test = 1
for x in range(10): B()

def B():
test = test + 1
main.py
import module
module.A()
This will fail, unless test is passed and returned.
(Sorry if this sent twice.  It wasn't appearing for me the first time.)
You can use global here, though I wouldn't advise it.
-- module.py --
def A():
global test
test = 1
for x in range(10):
B()
def B():
global test
test = test + 1
---
py> import module
py> module.A()
py> module.test
11
This looks like it might be simpler with a class, e.g.:
-- module.py --
class A(object):
def __init__(self):
self.test = 1
for x in range(10):
self.B()
def B(self):
self.test += 1
---
py> import module
py> a = module.A()
py> a.test
11
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: winnt win32process.createProcess with stdout to file ?

2005-03-03 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
os:winnt
python2.3.2
I have a exe that dumps info to the command line.  I want to run this
process and  capture the stdout into a file.  I think i'm close... any
help appreciated.
Use the standard "subprocess" module that comes in Python2.4.
Or, if you can't upgrade for some reason, it sounds to me
like os.popen() will do what you want... that's the older
standard technique.
No need to resort to lots of win32 stuff.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: There's GOT to be a better way!

2005-03-03 Thread Steve Holden
Earl Eiland wrote:
On Thu, 2005-03-03 at 15:11, Steve Holden wrote:
Earl Eiland wrote:
I'm writing my first program where I call custom modules.  The 'global'
command doesn't seem to apply, so how do I change a variable internally
in a module without passing it down n layers, and then back out again?
You are correct in assuming that global isn't what you want - it really 
means "global to the module namespace in which it appears".

However, if two separate pieces of code can both reference the same 
module then one can set an attribute in the module and the other can 
reference it. Don't forget that when you import a module its name 
becomes global within the importing module. Since a module is just a 
glorified namespace, anything that can reference the module can read 
and/or set that module's attributes.

a.py:
import something
something.x = "A value"
b.py:
import something
print something.x
will print "A value" as long as a is imported before b.
Right.  That part I figured out.  How does one function in an imported
module access a variable in the same module?
module.py
def A():
global test
test = 1
for x in range(10): B()

def B():
global test
test = test + 1
main.py
import module
module.A()
print module.test

This will fail, unless test is passed and returned.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie, help with pythonpath

2005-03-03 Thread Peter Hansen
Eduardo Suarez wrote:
In order not to make a mess my system, i have installed a packaged 
called pygtkglext in /usr/local/pygtkglext instead of /usr/local (using 
the --prefix in ./configure).

Hence, i have the directories
/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gtkgl
/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gdkgl
with the python packages i have compiled.
I'm trying to set the python path variable so i can use them, but i 
haven't got it. Any hint?

I have also installed the gtk package in:
/usr/lib/python2.3/site-packages/gtk-2.0/gtk
Is there a way to make it work?
Yes, with the easiest way of explaining it to you being this:
"please read the comments at the top of the site.py file in
the standard library and use the techniques it suggests".
I think the online documentation for the site module also
covers this stuff, but I don't recall verifying that yet...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: file.getvalue() with _ or other characters

2005-03-03 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
I did this but don't work:
It is quite possible I misunderstood the problem you
were having.  I am familiar with a problem with StringIO
whereby if you call close() on it, you can no longer call
getvalue() afterwards.  Perhaps that's not the problem
you were seeing.
Can you clarify your comment "But then the _ characters are
away. is it possible to keep that character in file.getvalue()"?
Please show actual (small!) examples of the sort of input
you are dealing with, and the output which you are getting
(if any).
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows bat file question

2005-03-03 Thread Peter Hansen
Duncan Booth wrote:
Peter Hansen wrote:
This should make it work:
 python %0.bat %*
Only, among other issues, if you type the full path to the
batch file, or if it's in the current directory.  This
approach fails if you put the batch file in a directory
somewhere along your path.

The simplest fix, assuming we aren't talking Win9x is probably:
 python "%~f0" %*
Wow.  The myriad things that get slipped into these little
operating systems while you aren't looking.  Windows XP's command
shell begins to border on being marginally acceptable for some
limited types of scripting.
Unfortunately, Google makes it hard to search for such things,
but after a while I was able to dig up this master reference:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx
Thanks, Duncan!
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Gordon McMillan installer and Python 2.4

2005-03-03 Thread Peter Hansen
Richie Hindle wrote:
[Svein]
According to the command line help for cx_Freeze and py2exe, they
cannot pack my program with additional installation files into one
self-extracting .exe file (which is what I want to do).
[Peter]
On the other hand, there are readily available utilities that
will do what you are asking for, independent of Python and py2exe
and everything else.  Standalone single-file packagers.
InnoSetup is the most popular free single-file-installer generator for
Windows.  NSIS is probably second.
I'm not sure now, but I *think* the OP actually wanted one
of those beasties which will literally *run* from a single
EXE file, not just install from one in the usual way.
The only ones of which I'm aware are usually called something
like "self-executing zip files" and they -- invisibly to the
user -- will temporarily extract themselves into a temporary
folder, run the main exe, and then (optionally) clean up
completely after the application exits, removing all temporary
files.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: creating .NET clients with python

2005-03-03 Thread Guy Robinson
Thanks Alan,
Are you saying I can create python .net clients with PythonNet. My understanding 
is I can only use .net clients from python not the other way around.

Do you have an example showing creating a .net client in python?
regards,
Guy
yaipa wrote:
Guy,
I can tell you that pythonNet is quite far along, rel 1, Beta 4
actually.
here is a c.l.p link to the three major releases.
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ddfc68767901007c/445f2052948d93e2?q=pythonnet&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fgroup%3Dcomp.lang.python%26q%3Dpythonnet%26qt_g%3D1%26searchnow%3DSearch+this+group%26&_doneTitle=Back+to+Search&&d#445f2052948d93e2
Cheers,
  --Alan
Guy Robinson wrote:
Hello,
Can anyone confirm if there is a python library that can allow me to
create .NET
clients in python.
My understanding is both IronPython and python for .NET can't create
python .net 

clients?
Regards,
Guy

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


Re: creating .NET clients with python

2005-03-03 Thread yaipa
Guy,

I can tell you that pythonNet is quite far along, rel 1, Beta 4
actually.

here is a c.l.p link to the three major releases.

http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ddfc68767901007c/445f2052948d93e2?q=pythonnet&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fgroup%3Dcomp.lang.python%26q%3Dpythonnet%26qt_g%3D1%26searchnow%3DSearch+this+group%26&_doneTitle=Back+to+Search&&d#445f2052948d93e2

Cheers,

  --Alan


Guy Robinson wrote:
> Hello,
>
> Can anyone confirm if there is a python library that can allow me to
create .NET
> clients in python.
>
> My understanding is both IronPython and python for .NET can't create
python .net 
> clients?
> 
> Regards,
> 
> Guy

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


Re: There's GOT to be a better way!

2005-03-03 Thread Earl Eiland
On Thu, 2005-03-03 at 15:11, Steve Holden wrote:
> Earl Eiland wrote:
> > I'm writing my first program where I call custom modules.  The 'global'
> > command doesn't seem to apply, so how do I change a variable internally
> > in a module without passing it down n layers, and then back out again?
> > 
> You are correct in assuming that global isn't what you want - it really 
> means "global to the module namespace in which it appears".
> 
> However, if two separate pieces of code can both reference the same 
> module then one can set an attribute in the module and the other can 
> reference it. Don't forget that when you import a module its name 
> becomes global within the importing module. Since a module is just a 
> glorified namespace, anything that can reference the module can read 
> and/or set that module's attributes.
> 
> a.py:
> 
> import something
> something.x = "A value"
> 
> b.py:
> 
> import something
> print something.x
> 
> will print "A value" as long as a is imported before b.
Right.  That part I figured out.  How does one function in an imported
module access a variable in the same module?

module.py
def A():
test = 1
for x in range(10): B()

def B():
test = test + 1


main.py
import module
module.A()


This will fail, unless test is passed and returned.

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


Re: Help- Recursion v. Iter Speed comparison

2005-03-03 Thread Robert Kern
actuary77 wrote:
Robert Kern wrote:
actuary77 wrote:
#
#  non-generator
#
def f1(afunc,aseed,n):
values = [afunc(aseed)]
for i in range(n-1):
values.append(afunc(values[-1]))
return values[-1]
_b=time()
for _i in range(0,100):
_y = f1(myfunc,seed,n)

Why do you do this? The whole point of this approach was to keep the 
intermediate results instead of recomputing them every time!

The point is to get some meaningful results when "timing" the function.
No, they're not meaningful. You're taking an intrinsically linear 
algorithm and making it quadratic. That's never a good thing. The 
function I gave you does exactly the same thing as the function you have 
here plus the loop, but it does it faster. You asked for faster ways of 
doing the task; I gave you one.

And why do you prepend underscores everywhere? It's bad Python style.

I prepend underscore to differentiate local,private variables vs. global 
variables.  Do not want to create a conflict.  It is my understanding 
that this is the Python style for local v. global variables.
It isn't.
Just use non-obfuscated variable names. There are cases where you want a 
leading underscore, but you haven't hit one, yet.

--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: binutils "strings" like functionality?

2005-03-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, cjl wrote:

> I am working on a little script that needs to pull the strings out of a
> binary file, and then manipulate them with python.
> 
> The command line utility "strings" (part of binutils) has exactly the
> functionality I need, but I was thinking about trying to implement this
> in pure python.
> 
> I did some reading on opening and reading binary files, etc., and was
> just wondering if people think this is possible, or worth my time (as a
> learning exercise), or if something like this already exists.

If you find it interesting and challenging go ahead and try it.  It is
possible and with the help of the 're' and 'mmap' modules it should be
quite easy to filter strings out of files without the need to load them
into memory at once.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with recursion

2005-03-03 Thread Steve Holden
vegetax wrote:
How can i use a counter inside the recursive function?
This code gives me the error 'local variable 'c' referenced before
assignment'
I really don't think it does. I'd believe "local variable 'COUNTER' 
referenced before assignment".

Rule one: always copy and paste the traceback ...
I presume you want a count of the directories you have traversed?
 #!/usr/bin/python
 from os import listdir
 from os.path import isdir,join,basename
 import HTMLgen
 
 dirpath = '/devel/python/html/test'
 COUNTER = 0 

 def rec(f):
   global COUNTER
 res = []
 COUNTER += 1 
 for ele in listdir(f):
 res.append(ele)
 ele = join(f,ele)
 if isdir(ele):
res.append(rec(ele))
 return res
 
 print HTMLgen.List(rec(dirpath))


regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Kent Johnson wrote:
for line in raw_data:
if line.startswith('RelevantInfo1'):
info1 = raw_data.next().strip()
elif line.startswith('RelevantInfo2'):
info2 = raw_data.next().strip()
elif line.startswith('RelevantInfo3'):
info3 = raw_data.next().strip()
scores.setdefault(info1, {}).setdefault(info3, []).append(info2)
info1 = info2 = info3 = None
Very pretty. =)  I have to say, I hadn't ever used iterators this way 
before, that is, calling their next method from within a for-loop.  I 
like it. =)

Thanks for opening my mind. ;)
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


winnt win32process.createProcess with stdout to file ?

2005-03-03 Thread david . humpherys
os:winnt
python2.3.2

I have a exe that dumps info to the command line.  I want to run this
process and  capture the stdout into a file.  I think i'm close... any
help appreciated.

dh
--
import win32process, win32file, win32security, win32con, win32api,
thread, win32event, win32pipe

cmd = "c:/myexe.exe"
sa = win32security.SECURITY_ATTRIBUTES()
sa.bInheritHandle = 1

startInfo = win32process.STARTUPINFO()
startInfo.dwFlags = win32process.STARTF_USESTDHANDLES

fh = win32file.CreateFile("c:/mylog.log", win32file.GENERIC_WRITE, 0,
sa, win32file.OPEN_EXISTING, win32file.FILE_FLAG_SEQUENTIAL_SCAN |
win32file.FILE_FLAG_OVERLAPPED , 0)
startInfo.hStdOutput = fh
startInfo.hStdError = win32api.GetStdHandle(win32api.STD_ERROR_HANDLE)
startInfo.hStdInput = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)

hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess
\
( None, cmd, None, None, 1, win32con.NORMAL_PRIORITY_CLASS, None, None,
startInfo)

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


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread Steve Holden
Gary Nutbeam wrote:
I count zpt as xml because page templates can operate in html or xml mode.
This is not a troll. It is a lot of work in Zope to create interfaces to
relational data for anything more than simple data models. 

It's a lot less work in Maypole or Rails, but I don't want to go back to
writing in Perl, or needing to learn Ruby.
I do like Formulator but the documentation on it is weak. I don't want to
have to go rooting around in the source code or spending hours on weeding
through mailing lists for answers. I still have to screw around and glue
formulator to the data with python, zpt, and zsql methods. Archetypes seems
a lot closer to a fix, but there are problems with SQLStorage representing
anything more than simple relationships reliably.
It would be nice to have an object database that is ACID compliant.
Have you looked at Caché? You can download a fully-functional version to 
play with, though it's got a fairly steep learning curve for 
non-relational use:

  http://www.intersystems.com/cache/
  InterSystems Caché: Post-relational Database
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Call variable as a function

2005-03-03 Thread Steve Holden
Chmouel Boudjnah wrote:
Steve Holden wrote:
But it depends how you are creating the reference to the function. The 
above is required if all you have is a string, but it would also be 
possible to set the variable to the function rather than the 
function's name
 >>> var = test
 >>> var()
hello
 >>>
Hope this helps.

Thanks man it does help.
Then it might help even more to realize that you can use lists and 
dictionaries of functions as well:

>>> def f1(x):
...   return x*2
...
>>> def f2(x):
...   return "This is an %s" % x
...
>>> def f3(x):
...   return "%s:%s" % (x, x)
...
>>> fl = [f1, f2, f3]
>>> for s in ("bigstring", "tiny"):
...   for i in range(len(fl)):
... print fl[i](s)
...
bigstringbigstring
This is an bigstring
bigstring:bigstring
tinytiny
This is an tiny
tiny:tiny
>>>
regards
 Steve
--
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help- Recursion v. Iter Speed comparison

2005-03-03 Thread actuary77
Robert Kern wrote:
actuary77 wrote:
#
#  non-generator
#
def f1(afunc,aseed,n):
values = [afunc(aseed)]
for i in range(n-1):
values.append(afunc(values[-1]))
return values[-1]
_b=time()
for _i in range(0,100):
_y = f1(myfunc,seed,n)

Why do you do this? The whole point of this approach was to keep the 
intermediate results instead of recomputing them every time!

The point is to get some meaningful results when "timing" the function.

And why do you prepend underscores everywhere? It's bad Python style.
I prepend underscore to differentiate local,private variables vs. global 
variables.  Do not want to create a conflict.  It is my understanding 
that this is the Python style for local v. global variables.



_e=time()
_t=_e-_b
print "f1 result: %r time: %f\n" % (_y,_t*1.)
#
#  generator
#
def f2(afunc,aseed,n):
v = myfunc(aseed)
print v
for i in range(n):
yield v
v = afunc(v)
def f2gen(i):
for _i in range(1,n-1):
f2(myfunc,seed,n)
return f2(myfunc,seed,n)
_b=time()
for _i in range(0,cnt):
_y = f2gen(_i)
_e=time()
_t=_e-_b
print "f2gen result: %r time: %f\n" % (_y,_t*1.)
==>
rec result: 10.0050488 time: 47669.999599
f1 result: 10.0049988 time: 399.999619
f2gen result:  time: 30739.998817
I don't know how to get the generator to work correcly, I understand 
that the yield preserves the state of the funcion every time it is 
called. So in order to have myfunc called 50 times, the generator must 
be called 50 times, but it refuses to return a value.  PEP 255 isn't 
helping me.

No, the generator call creates a generator object which you iterate over.
  for value in f2(myfunc, seed, n):
  print value
If you absolutely need a list:
  list(f2(myfunc, seed, n))
Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe

2005-03-03 Thread D H
[EMAIL PROTECTED] wrote:
I'm a newbie at programmin. I've downloaded Python and am going through
"How to think like a computer scientist". I've also downloaded py2exe
and I don't really know how to use it. For one what is the disutil?
thanks for the help yall.
You'll get better help for beginner questions on the python-tutor list:
http://mail.python.org/mailman/listinfo/tutor
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with recursion

2005-03-03 Thread vegetax

How can i use a counter inside the recursive function?
This code gives me the error 'local variable 'c' referenced before
assignment'

 #!/usr/bin/python
 from os import listdir
 from os.path import isdir,join,basename
 import HTMLgen
 
 dirpath = '/devel/python/html/test'
 COUNTER = 0 

 def rec(f):
 res = []
 COUNTER += 1 
 for ele in listdir(f):
 res.append(ele)
 ele = join(f,ele)
 if isdir(ele):
res.append(rec(ele))
 return res
 
 print HTMLgen.List(rec(dirpath))


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


Re: newbie, help with pythonpath

2005-03-03 Thread Chmouel Boudjnah
Eduardo Suarez wrote:
I'm trying to set the python path variable so i can use them, but i 
haven't got it. Any hint?
sys.path.append('/usr/blah/blah/blah/directory')
--
http://mail.python.org/mailman/listinfo/python-list


Re: There's GOT to be a better way!

2005-03-03 Thread Steve Holden
Earl Eiland wrote:
I'm writing my first program where I call custom modules.  The 'global'
command doesn't seem to apply, so how do I change a variable internally
in a module without passing it down n layers, and then back out again?
You are correct in assuming that global isn't what you want - it really 
means "global to the module namespace in which it appears".

However, if two separate pieces of code can both reference the same 
module then one can set an attribute in the module and the other can 
reference it. Don't forget that when you import a module its name 
becomes global within the importing module. Since a module is just a 
glorified namespace, anything that can reference the module can read 
and/or set that module's attributes.

a.py:
import something
something.x = "A value"
b.py:
import something
print something.x
will print "A value" as long as a is imported before b.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: yield_all needed in Python

2005-03-03 Thread Jeremy Bowers
On Thu, 03 Mar 2005 20:47:42 +, Paul Moore wrote:
> This can probably be tidied up and improved, but it may be a
> reasonable workaround for something like the original example.

This is why even though in some sense I'd love to see yield *expr, I can't
imagine it's going to get into the language itself; it's too easy to do it
yourself, or provide a library function to do it (which would A: Be a lot
easier if we had some sort of "iterable" interface support and B: Be a
great demonstration of something useful that really needs protocol support
to come off right, because isinstance(something, GeneratorType) isn't
sufficient in general).

Abstractly I like the star syntax, but concretely I'm not a big fan of
adding something to the language that can be done right now with a fairly
short function/generator and hardly even any extra keystrokes to invoke it
when done right, and that overrides my abstract appreciation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread Gary Nutbeam
Thanks for the feedback. I should have been more specific though and
mentioned this has done on Linux (client and server).

D H wrote:

> Gary Nutbeam wrote:
> 
>> I've noticed that the Perl camp has a very nice web/database environment
>> called Maypole. Ruby has the Rails environment which on the surface seems
>> similar to Maypole. I can't find anything in Python that ties a database
>> to a web interface anywhere near as well as Ruby on Rails or Maypole.
>> 
>> I see the behemoth Zope having the best web/database integration, but
>> unfortunately I don't want to spent weeks writing xml for the interface.
>> 
>> Does anyone know of something similar to Rails or Maypole in Python?
> 
> 
> Check out Castle on Rails for .NET/Mono.  It is still in early
> development, but you can use it with C#, VB, or boo, and I'm sure
> eventually with IronPython as well.

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


Re: Call variable as a function

2005-03-03 Thread Steve Holden
Chmouel Boudjnah wrote:
Hey,
It's look simple for most of the people here but i can't figure out to 
that.

If i have :
def test():
print "foo"
and:
var = "test"
how do i call function test from var, kind of ${$var} in some others 
languages (or eval())

There's always a way:
>>> def test():
...   print "hello"
...
>>> var = "test"
>>> eval("%s()" % var)
hello
But it depends how you are creating the reference to the function. The 
above is required if all you have is a string, but it would also be 
possible to set the variable to the function rather than the function's 
name:

>>> var = test
>>> var()
hello
>>>
Hope this helps.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread Gary Nutbeam
I count zpt as xml because page templates can operate in html or xml mode.
This is not a troll. It is a lot of work in Zope to create interfaces to
relational data for anything more than simple data models. 

It's a lot less work in Maypole or Rails, but I don't want to go back to
writing in Perl, or needing to learn Ruby.

I do like Formulator but the documentation on it is weak. I don't want to
have to go rooting around in the source code or spending hours on weeding
through mailing lists for answers. I still have to screw around and glue
formulator to the data with python, zpt, and zsql methods. Archetypes seems
a lot closer to a fix, but there are problems with SQLStorage representing
anything more than simple relationships reliably.

It would be nice to have an object database that is ACID compliant.

Bruno Desthuilliers wrote:

> 
> Is this a troll ? I wrote several Zope apps, and I don't remember having
> written a single ligne of xml. Unless you count ZPT for XML ?

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


Re: problem with recursion

2005-03-03 Thread vegetax
Alexander Zatvornitskiy wrote:

> ?? vegetax!
> 
> 03 ? 2005 ? 13:54, vegetax ? ? ?? ? All ?:
> 
>  v> I need this in order to print a directory tree with htmlgen library
>  v> which uses nested lists to represent trees.
> As you see from output of your code, you simply add items to the only
> list. Try this:
>  v> def rec(f):
> res=[]
>  v> print f
>  v> for ele in listdir(f):
>  v>   ele=join(f,ele)
>  v>   if isdir(ele):
>  v>   # append the directory name
>  v>   res.append(basename(ele))
>   res+=[ rec(ele) ]
>  v>   else:
>  v> res.append(basename(ele))
> return res
> 
> print rec(dirpath)
> 
> 
> 
> Alexander, [EMAIL PROTECTED]

Thanks it works!

Kent Johnson wrote:

>The problem is that you are always appending individual names to the same
>list. If you make rec() 
>return a list and append that to the current list you get what you want:

>#!/usr/bin/python
>from os import listdir
>from os.path import isdir,join,basename

>dirpath  = '/tmp/test/'

>def rec(f):
> res = []
> for ele in listdir(f):
>res.append(ele)
>ele = join(f,ele)
>if isdir(ele):
>res.append(rec(ele))
>return res
>
>print rec(dirpath)

Thanks that works too!

I realy have to improve my recursion skills =(
Anyway having the directory :

+root 
  +doc1
lesson1
lesson2
+doc3
  lesson3 
  +doc2
lesson4
lesson5

With the code : 


#!/usr/bin/python
from os import listdir
from os.path import isdir,join,basename
import HTMLgen

dirpath = '/devel/python/html/test'

def rec(f):
res = []
for ele in listdir(f):
res.append(ele)
ele = join(f,ele)
if isdir(ele):
res.append(rec(ele))
return res

print HTMLgen.List(rec(dirpath))

  
Gives me the espected output as a HTML representation of the tree:


doc1

lesson1.html
lesson2.html
doc3

lesson3.html


doc2

lesson5.html
lesson4.html

.tmp3.py.swp



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


Re: py2exe

2005-03-03 Thread Andrew Dalke
> On 3 Mar 2005 11:06:58 -0800, [EMAIL PROTECTED] wrote:
>> How did we ever live without Google?

On Thu, 03 Mar 2005 21:48:27 +0100, BOOGIEMAN wrote:
> We used Yahoo (and still using it)

Altavista.  Lycos.

Veronica on gopher.  Archie on telnet.

Lists of anonymous ftp sites (like
  http://thproxy.jinr.ru/file-archive/doc/ftp/ftpsites.lst
), a good memory and lots of free time.

Usenet archives.

Word of mouth.

Andrew
[EMAIL PROTECTED]

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


There's GOT to be a better way!

2005-03-03 Thread Earl Eiland
I'm writing my first program where I call custom modules.  The 'global'
command doesn't seem to apply, so how do I change a variable internally
in a module without passing it down n layers, and then back out again?

Earl

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


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread D H
Gary Nutbeam wrote:
I've noticed that the Perl camp has a very nice web/database environment
called Maypole. Ruby has the Rails environment which on the surface seems
similar to Maypole. I can't find anything in Python that ties a database
to a web interface anywhere near as well as Ruby on Rails or Maypole.
I see the behemoth Zope having the best web/database integration, but
unfortunately I don't want to spent weeks writing xml for the interface.
Does anyone know of something similar to Rails or Maypole in Python?

Check out Castle on Rails for .NET/Mono.  It is still in early 
development, but you can use it with C#, VB, or boo, and I'm sure 
eventually with IronPython as well.
--
http://mail.python.org/mailman/listinfo/python-list


newbie, help with pythonpath

2005-03-03 Thread Eduardo Suarez
Hi all,
In order not to make a mess my system, i have installed a packaged 
called pygtkglext in /usr/local/pygtkglext instead of /usr/local (using 
the --prefix in ./configure).

Hence, i have the directories
/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gtkgl
/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gdkgl
with the python packages i have compiled.
I'm trying to set the python path variable so i can use them, but i 
haven't got it. Any hint?

I have also installed the gtk package in:
/usr/lib/python2.3/site-packages/gtk-2.0/gtk
Is there a way to make it work?
Thanks a lot,
-Eduardo
--
http://mail.python.org/mailman/listinfo/python-list


Call variable as a function

2005-03-03 Thread Chmouel Boudjnah
Hey,
It's look simple for most of the people here but i can't figure out to that.
If i have :
def test():
print "foo"
and:
var = "test"
how do i call function test from var, kind of ${$var} in some others 
languages (or eval())

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


Re: creating .NET clients with python

2005-03-03 Thread D H
Guy Robinson wrote:
Hello,
Can anyone confirm if there is a python library that can allow me to 
create .NET clients in python.

My understanding is both IronPython and python for .NET can't create 
python .net clients?
Correct, although IronPython may work one day.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 3 Mar 2005 12:26:37 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
> Have a look at "martel", part of biopython. The world of bioinformatics is 
> filled with files with structure like this.
>
> http://www.biopython.org/docs/api/public/Martel-module.html
>
> James

Thanks for the link. Steve and Kent have provided me with nice solutions but
I will check this out anyways for future referenced.

Take care.

-- 
You may easily play a joke on a man who likes to argue -- agree with him.
-- Ed Howe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 16:25:39 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Here is another attempt. I'm still not sure I understand what form you want 
> the data in. I made a 
> dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] 
> you get a list of all 
> the RelevantInfo2 values for Relevant1='10/11/04' and Relevant2='60'.
>
> The parser is a simple-minded state machine that will misbehave if the input 
> does not have entries 
> in the order Relevant1, Relevant2, Relevant3 (with as many intervening lines 
> as you like).
>
> All three values are available when Relevant3 is detected so you could do 
> something else with them 
> if you want.
>
> HTH
> Kent
>
> import cStringIO
>
> raw_data = '''Gibberish
> 53
> MoreGarbage
[mass snippage]
> 60
> Lalala'''
> raw_data = cStringIO.StringIO(raw_data)
>
> scores = {}
> info1 = info2 = info3 = None
>
> for line in raw_data:
>  if line.startswith('RelevantInfo1'):
>  info1 = raw_data.next().strip()
>  elif line.startswith('RelevantInfo2'):
>  info2 = raw_data.next().strip()
>  elif line.startswith('RelevantInfo3'):
>  info3 = raw_data.next().strip()
>  scores.setdefault(info1, {}).setdefault(info3, []).append(info2)
>  info1 = info2 = info3 = None
>
> print scores
> print scores['10/11/04']['60']
> print scores['10/10/04']['23']
>
> ## prints:
> {'10/10/04': {'44': ['33'], '23': ['22', '22']}, '10/11/04': {'60': ['45']}}
> ['45']
> ['22', '22']

Thank you so much. Your solution and Steve's both give me what I'm looking
for. I appreciate both of your incredibly quick replies!

Take care.

-- 
You worry too much about your job.  Stop it.  You are not paid enough to worry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 13:45:31 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
> I think if you use the non-greedy .*? instead of the greedy .*, you'll 
> get this behavior.  For example:
>
> py> s = """\
> ... Gibberish
> ... 53
> ... MoreGarbage
> [snip a whole bunch of stuff]
> ... RelevantInfo3
> ... 60
> ... Lalala
> ... """
> py> import re
> py> m = re.compile(r"""^RelevantInfo1\n([^\n]*)
> ....*?
> ...^RelevantInfo2\n([^\n]*)
> ....*?
> ...^RelevantInfo3\n([^\n]*)""",
> ...re.DOTALL | re.MULTILINE | re.VERBOSE)
> py> score = {}
> py> for info1, info2, info3 in m.findall(s):
> ... score.setdefault(info1, {})[info3] = info2
> ...
> py> score
> {'10/10/04': {'44': '33', '23': '22'}, '10/11/04': {'60': '45'}}
>
> If you might have multiple info2 values for the same (info1, info3) 
> pair, you can try something like:
>
> py> score = {}
> py> for info1, info2, info3 in m.findall(s):
> ... score.setdefault(info1, {}).setdefault(info3, []).append(info2)
> ...
> py> score
> {'10/10/04': {'44': ['33'], '23': ['22']}, '10/11/04': {'60': ['45']}}
>
Perfect! Thank you so much. This is the behaviour I'm looking for. I will
fiddle around with this some more tonight but the rest should be okay.

Take care.

-- 
Of course power tools and alcohol don't mix.  Everyone knows power
tools aren't soluble in alcohol...
-- Crazy Nigel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread Bruno Desthuilliers
Gary Nutbeam a écrit :
I've noticed that the Perl camp has a very nice web/database environment
called Maypole. Ruby has the Rails environment which on the surface seems
similar to Maypole. I can't find anything in Python that ties a database
to a web interface anywhere near as well as Ruby on Rails or Maypole.
I see the behemoth Zope having the best web/database integration, but
unfortunately I don't want to spent weeks writing xml for the interface.
Is this a troll ? I wrote several Zope apps, and I don't remember having 
written a single ligne of xml. Unless you count ZPT for XML ?

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


Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Here is another attempt. I'm still not sure I understand what form you want the data in. I made a 
dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] you get a list of all 
the RelevantInfo2 values for Relevant1='10/11/04' and Relevant2='60'.

The parser is a simple-minded state machine that will misbehave if the input does not have entries 
in the order Relevant1, Relevant2, Relevant3 (with as many intervening lines as you like).

All three values are available when Relevant3 is detected so you could do something else with them 
if you want.

HTH
Kent
import cStringIO
raw_data = '''Gibberish
53
MoreGarbage
12
RelevantInfo1
10/10/04
NothingImportant
ThisDoesNotMatter
44
RelevantInfo2
22
BlahBlah
343
RelevantInfo3
23
Hubris
Crap
34
Gibberish
53
MoreGarbage
12
RelevantInfo1
10/10/04
NothingImportant
ThisDoesNotMatter
44
RelevantInfo2
22
BlahBlah
343
RelevantInfo3
23
Hubris
Crap
34
SecondSetofGarbage
2423
YouGetThePicture
342342
RelevantInfo1
10/10/04
HoHum
343
MoreStuffNotNeeded
232
RelevantInfo2
33
RelevantInfo3
44
sdfsdf
RelevantInfo1
10/11/04
InsertBoringFillerHere
43234
Stuff
MoreStuff
RelevantInfo2
45
ExcitingIsntIt
324234
RelevantInfo3
60
Lalala'''
raw_data = cStringIO.StringIO(raw_data)
scores = {}
info1 = info2 = info3 = None
for line in raw_data:
if line.startswith('RelevantInfo1'):
info1 = raw_data.next().strip()
elif line.startswith('RelevantInfo2'):
info2 = raw_data.next().strip()
elif line.startswith('RelevantInfo3'):
info3 = raw_data.next().strip()
scores.setdefault(info1, {}).setdefault(info3, []).append(info2)
info1 = info2 = info3 = None
print scores
print scores['10/11/04']['60']
print scores['10/10/04']['23']
## prints:
{'10/10/04': {'44': ['33'], '23': ['22', '22']}, '10/11/04': {'60': ['45']}}
['45']
['22', '22']
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe

2005-03-03 Thread Steve Holden
BOOGIEMAN wrote:
On 3 Mar 2005 11:06:58 -0800, [EMAIL PROTECTED] wrote:

How did we ever live without Google?

We used Yahoo (and still using it)
Even before Yahoo used Google themselves?
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: binutils "strings" like functionality?

2005-03-03 Thread cjl
David M. Cooke wrote:

> Are you sure it's monkey/chicken/dog/cat, and not
> monkey\chicken\dog\cat? The later one will print monkey\\chicken...
> because of the repr() call.
>
> Also, you probably want it as [\x20-\x7e] (the DEL character \x7f
> isn't printable). You're also missing tabs (\t).
>
> The GNU binutils string utility looks for \t or [\x20-\x7e].

Yeah, it is "monkey\chicken\dog\cat", thank you for pointing that out.

I started snooping throught the sourcecode for 'strings' in binutils to
see what it matches against, but I don't really know how to program, so
you just saved me even more time. Thanks again!

-CJL

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


Re: Gordon McMillan installer and Python 2.4

2005-03-03 Thread Martin Bless
On 2 Mar 2005 15:29:21 -0800, [EMAIL PROTECTED] (Svein Brekke) wrote:

>Thank you Gordon McMillan for a very nice freeze tool for python.

Yes, thanks a lot.

>Recently I upgraded to python 2.4, and on my system any .exe file
>generated by the installer crashes immediately after startup.

Yes, I can confirm this observation. The same on my machine: any .exe
crashes immediately. I too have the feeling the McMillan installer has
benefits (I justed started playing with installers). But py2exe seems
to work better at the moment.

mb - Martin

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


creating .NET clients with python

2005-03-03 Thread Guy Robinson
Hello,
Can anyone confirm if there is a python library that can allow me to create .NET 
clients in python.

My understanding is both IronPython and python for .NET can't create python .net 
clients?

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


Re: binutils "strings" like functionality?

2005-03-03 Thread David M. Cooke
"cjl" <[EMAIL PROTECTED]> writes:

> Fredrik Lundh wrote:
>
>> something like this could work:
>>
>> import re
>>
>> text = open(file, "rb").read()
>>
>> for m in re.finditer("([\x20-\x7f]{4,})[\n\0]", text):
>> print m.start(), repr(m.group(1))
>
> Hey...that worked. I actually modified:
>
> for m in re.finditer("([\x20-\x7f]{4,})[\n\0]", text):
>
> to
>
> for m in re.finditer("([\x20-\x7f]{4,})", text):
>
> and now the output is nearly identical to 'strings'. One problem
> exists, in that if the binary file contains a string
> "monkey/chicken/dog/cat" it is printed as "mokey//chicken//dog//cat",
> and I don't know enough to figure out where the extra "/" is coming
> from.

Are you sure it's monkey/chicken/dog/cat, and not
monkey\chicken\dog\cat? The later one will print monkey\\chicken...
because of the repr() call.

Also, you probably want it as [\x20-\x7e] (the DEL character \x7f
isn't printable). You're also missing tabs (\t).

The GNU binutils string utility looks for \t or [\x20-\x7e].

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe

2005-03-03 Thread BOOGIEMAN
On 3 Mar 2005 11:06:58 -0800, [EMAIL PROTECTED] wrote:

> How did we ever live without Google?

We used Yahoo (and still using it)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yield_all needed in Python

2005-03-03 Thread Paul Moore
Skip Montanaro <[EMAIL PROTECTED]> writes:

> Doug>def foogen(arg1):
>
> Doug>   def foogen1(arg2):
> Doug>  # Some code here
>
> Doug>   # Some code here
> Doug>   yield_all foogen1(arg3)
> Doug>   # Some code here
> Doug>   yield_all foogen1(arg4)
> Doug>   # Some code here
> Doug>   yield_all foogen1(arg5)
> Doug>   # Some code here
> Doug>   yield_all foogen1(arg6)
>
> If this idea advances I'd rather see extra syntactic sugar introduced to
> complement the current yield statement instead of adding a new keyword.

You can work around the need for something like yield_all, or
explicit loops, by defining an "iflatten" generator, which yields
every element of its (iterable) argument, unless the element is a
generator, in which case we recurse into it:

>>> from types import GeneratorType
>>> def iflatten(it):
... it = iter(it)
... for val in it:
... if isinstance(val, GeneratorType):
... for v2 in iflatten(val):
... yield v2
... else:
... yield val

To take this one step further, you can define an @iflattened
decorator (yes, it needs a better name...)

>>> def iflattened(f):
... def wrapper(*args, **kw):
... for val in iflatten(f(*args, **kw)):
... yield val
... return wrapper

Now, we can do things like:

>>> @iflattened
... def t():
... def g1():
... yield 'a'
... yield 'b'
... yield 'c'
... def g2():
... yield 'd'
... yield 'e'
... yield 'f'
... yield g1()
... yield 1
... yield g2()
...
>>> list(t())
['a', 'b', 'c', 1, 'd', 'e', 'f']

This can probably be tidied up and improved, but it may be a
reasonable workaround for something like the original example.

Paul.
-- 
The most effective way to get information from usenet is not to ask
a question; it is to post incorrect information.  -- Aahz's Law
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Yatima wrote:
On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
A possible solution, using the re module:
py> s = """\
... Gibberish
... 53
... MoreGarbage
... 12
... RelevantInfo1
... 10/10/04
... NothingImportant
... ThisDoesNotMatter
... 44
... RelevantInfo2
... 22
... BlahBlah
... 343
... RelevantInfo3
... 23
... Hubris
... Crap
... 34
... """
py> import re
py> m = re.compile(r"""^RelevantInfo1\n([^\n]*)
....*
...^RelevantInfo2\n([^\n]*)
....*
...^RelevantInfo3\n([^\n]*)""",
...re.DOTALL | re.MULTILINE | re.VERBOSE)
py> score = {}
py> for info1, info2, info3 in m.findall(s):
... score.setdefault(info1, {})[info3] = info2
...
py> score
{'10/10/04': {'23': '22'}}
Note that I use DOTALL to allow .* to cross line boundaries, MULTILINE 
to have ^ apply at the start of each line, and VERBOSE to allow me to 
write the re in a more readable form.

If I didn't get your dict update quite right, hopefully you can see how 
to fix it!

Thanks! That was very helpful. Unfortunately, I wasn't completely clear when
describing the problem. Is there anyway to extract multiple scores from the
same file and from multiple files
I think if you use the non-greedy .*? instead of the greedy .*, you'll 
get this behavior.  For example:

py> s = """\
... Gibberish
... 53
... MoreGarbage
[snip a whole bunch of stuff]
... RelevantInfo3
... 60
... Lalala
... """
py> import re
py> m = re.compile(r"""^RelevantInfo1\n([^\n]*)
....*?
...^RelevantInfo2\n([^\n]*)
....*?
...^RelevantInfo3\n([^\n]*)""",
...re.DOTALL | re.MULTILINE | re.VERBOSE)
py> score = {}
py> for info1, info2, info3 in m.findall(s):
... score.setdefault(info1, {})[info3] = info2
...
py> score
{'10/10/04': {'44': '33', '23': '22'}, '10/11/04': {'60': '45'}}
If you might have multiple info2 values for the same (info1, info3) 
pair, you can try something like:

py> score = {}
py> for info1, info2, info3 in m.findall(s):
... score.setdefault(info1, {}).setdefault(info3, []).append(info2)
...
py> score
{'10/10/04': {'44': ['33'], '23': ['22']}, '10/11/04': {'60': ['45']}}
HTH,
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: How would you program this?

2005-03-03 Thread Bill Mill
On Thu, 03 Mar 2005 10:52:23 -0800, engsol <[EMAIL PROTECTED]> wrote:
> 
> The diagonal constraint is interestingit seems to affect the number of
> solutions. One surprise, (not being a math major), was that when I let the
> brute force run (forever, it seemed), but without the diagonal 
> qualification(s),
> there was maybe 100 solutions. The reson it was a surprise it that years
> ago a programmer used the row-sum, col-sum method to detect and correct
> data errors. He swore it was robust, and 100% reliable. Seems that that
> isn't the case.

I think that it probably is a decent gut-check for data errors, for
the simple reason that changing one number requires, at a minimum,
three other changes in order to maintain both the row and column sums.
If you have at least a decent data fidelity rate, that is unlikely to
happen, and even if it does, very very unlikely to happen in such a
way that the row and column sums are maintained; especially as the
number of rows and columns grows.

Better to just do a crc or a hash of the data though.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread James Stroud
I found the original paper for Martel:

http://www.dalkescientific.com/Martel/ipc9/

On Thursday 03 March 2005 12:26 pm, James Stroud wrote:
> Have a look at "martel", part of biopython. The world of bioinformatics is
> filled with files with structure like this.
>
> http://www.biopython.org/docs/api/public/Martel-module.html
>
> James
>
> On Thursday 03 March 2005 12:03 pm, Yatima wrote:

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 07:14:50 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> Here is a way to create a list of [RelevantInfo, value] pairs:
> import cStringIO
>
> raw_data = '''Gibberish
> 53
> MoreGarbage
> 12
> RelevantInfo1
> 10/10/04
> NothingImportant
> ThisDoesNotMatter
> 44
> RelevantInfo2
> 22
> BlahBlah
> 343
> RelevantInfo3
> 23
> Hubris
> Crap
> 34'''
> raw_data = cStringIO.StringIO(raw_data)
>
> data = []
> for line in raw_data:
>  if line.startswith('RelevantInfo'):
>  key = line.strip()
>  value = raw_data.next().strip()
>  data.append([key, value])
>
> print data
>

Thank you. This isn't exactly what I'm looking for (I wasn't clear in
describing the problem -- please see my reply to Steve for a, hopefully,
better explanation) but it does give me a few ideas.
>
>> 
>> Score[RelevantInfo1][RelevantInfo3] = 22 # The value from RelevantInfo2
>
> I'm not sure what you mean by this. Do you want to build a Score dictionary 
> as well?

Sure... Uhhh.. I think. Okay, what I want is some kind of awk-like
associative array because the raw data files will have repeats for certain
field vaues such that there would be, for example, multiple RelevantInfo2's
and RelevantInfo3's for the same RelevantInfo1 (i.e. on the same date). To
make matters more exciting, there will be multiple RelevantInfo1's (dates)
for the same RelevantInfo3 (e.g. a subject ID). RelevantInfo2 will be the
value for all unique combinations of RelevantInfo1 and RelevantInfo3. There
will be multiple occurrences of these fields in the same file (original data
sample was not very good for this reason) and multiple files as well. The
interesting three fields will always be repeated in the same order although
the amount of irrelevant data in between may vary. So:

RelevantInfo1
10/10/04

RelevantInfo2
12

RelevantInfo3
43

RelevantInfo1
10/10/04<- The same as the first occurrence of RelevantInfo1

RelevantInfo2
22

RelevantInfo3
25

RelevantInfo1
10/11/04

RelevantInfo2
34

RelevantInfo3
28

RelevantInfo1
10/12/04

RelevantInfo2
98

RelevantInfo3
25<- The same as the second occurrence of RelevantInfo3
...

Sorry for the long and tedious "data" example.

There will be missing values for some combinations of RelevantInfo1 and
RelevantInfo3 so hopefully that won't be an issue.

Thanks again for your reply.

Take care.

-- 
"I figured there was this holocaust, right, and the only ones left alive were
 Donna Reed, Ozzie and Harriet, and the Cleavers."
-- Wil Wheaton explains why everyone in "Star Trek: The Next Generation" 
is so nice
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex help

2005-03-03 Thread James Stroud
Have a look at "martel", part of biopython. The world of bioinformatics is 
filled with files with structure like this.

http://www.biopython.org/docs/api/public/Martel-module.html

James

On Thursday 03 March 2005 12:03 pm, Yatima wrote:
> On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard 
<[EMAIL PROTECTED]> wrote:
> > A possible solution, using the re module:
> >
> > py> s = """\
> > ... Gibberish
> > ... 53
> > ... MoreGarbage
> > ... 12
> > ... RelevantInfo1
> > ... 10/10/04
> > ... NothingImportant
> > ... ThisDoesNotMatter
> > ... 44
> > ... RelevantInfo2
> > ... 22
> > ... BlahBlah
> > ... 343
> > ... RelevantInfo3
> > ... 23
> > ... Hubris
> > ... Crap
> > ... 34
> > ... """
> > py> import re
> > py> m = re.compile(r"""^RelevantInfo1\n([^\n]*)
> > ....*
> > ...^RelevantInfo2\n([^\n]*)
> > ....*
> > ...^RelevantInfo3\n([^\n]*)""",
> > ...re.DOTALL | re.MULTILINE | re.VERBOSE)
> > py> score = {}
> > py> for info1, info2, info3 in m.findall(s):
> > ... score.setdefault(info1, {})[info3] = info2
> > ...
> > py> score
> > {'10/10/04': {'23': '22'}}
> >
> > Note that I use DOTALL to allow .* to cross line boundaries, MULTILINE
> > to have ^ apply at the start of each line, and VERBOSE to allow me to
> > write the re in a more readable form.
> >
> > If I didn't get your dict update quite right, hopefully you can see how
> > to fix it!
>
> Thanks! That was very helpful. Unfortunately, I wasn't completely clear
> when describing the problem. Is there anyway to extract multiple scores
> from the same file and from multiple files (I will probably use the
> "fileinput" module to deal with multiple files). So, if I've got say:
>
> Gibberish
> 53
> MoreGarbage
> 12
> RelevantInfo1
> 10/10/04
> NothingImportant
> ThisDoesNotMatter
> 44
> RelevantInfo2
> 22
> BlahBlah
> 343
> RelevantInfo3
> 23
> Hubris
> Crap
> 34
>
> SecondSetofGarbage
> 2423
> YouGetThePicture
> 342342
> RelevantInfo1
> 10/10/04
> HoHum
> 343
> MoreStuffNotNeeded
> 232
> RelevantInfo2
> 33
> RelevantInfo3
> 44
> sdfsdf
> RelevantInfo1
> 10/11/04
> InsertBoringFillerHere
> 43234
> Stuff
> MoreStuff
> RelevantInfo2
> 45
> ExcitingIsntIt
> 324234
> RelevantInfo3
> 60
> Lalala
>
> Sorry for the long and painful example input. Notice that the first two
> "RelevantInfo1" fields have the same info but that the RelevantInfo2 and
> RelevantInfo3 fields have different info. Also, there will be cases where
> RelevantInfo3 might be the same with a different RelevantInfo2. What, I'm
> hoping for is something along then lines of being able to organize it like
> so (don't worry about the format of the output -- I'll deal with that
> later; "RelevantInfo" shortened to "Info" for readability):
>
> Info1[0],   Info[1],Info[2]
> ... Info3[0]Info2[Info1[0],Info3[0]]Info2[Info1[1],Info3[1]]...
> Info3[1]Info2[Info1[0],Info3[1]]...
> Info3[2]Info2[Info1[0],Info3[2]]...
> ...
>
> I don't really care if it's a list, dictionary, array etc.
>
> Thanks again for your help. The multiline option in the re module is very
> useful.
>
> Take care.
>
> --
> Clarke's Conclusion:
>   Never let your sense of morals interfere with doing the right thing.

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write python plug-ins for your own python program?

2005-03-03 Thread Andrew Dalke
Mark Rowe wrote:
> A better method would be something along the lines of:
> 
> plugin = __import__(pluginName)
> plugin.someMethod()

In the one time I did a plugin architecture I found that


state = ... set up intial state for my program ...
  ...
plugin = __import__(pluginName)
plugin.someMethod(state)


was useful because it gave the plugin a way to modify
the program state, rather than changing global variables.

Andrew
[EMAIL PROTECTED]

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


Re: Gordon McMillan installer and Python 2.4

2005-03-03 Thread Svein Brekke
> > According to the command line help for cx_Freeze and py2exe, they
> > cannot pack my program with additional installation files into one
> > self-extracting .exe file (which is what I want to do).
> > 
> > Am I wrong on this?
> 
> As far as py2exe goes, no, you're not wrong.
> 
> On the other hand, there are readily available utilities that
> will do what you are asking for, independent of Python and py2exe
> and everything else.  Standalone single-file packagers.

Beeing able to use python to specify the installers behaviour (like
checking what files to install on different systems, decrypting
archives, etc.) is for me very attractive. AND, I have functional and
well tested version on python 2.3. Hence, the  best options seems at
the moment to be: keep using python 2.3.

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


Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
> A possible solution, using the re module:
>
> py> s = """\
> ... Gibberish
> ... 53
> ... MoreGarbage
> ... 12
> ... RelevantInfo1
> ... 10/10/04
> ... NothingImportant
> ... ThisDoesNotMatter
> ... 44
> ... RelevantInfo2
> ... 22
> ... BlahBlah
> ... 343
> ... RelevantInfo3
> ... 23
> ... Hubris
> ... Crap
> ... 34
> ... """
> py> import re
> py> m = re.compile(r"""^RelevantInfo1\n([^\n]*)
> ....*
> ...^RelevantInfo2\n([^\n]*)
> ....*
> ...^RelevantInfo3\n([^\n]*)""",
> ...re.DOTALL | re.MULTILINE | re.VERBOSE)
> py> score = {}
> py> for info1, info2, info3 in m.findall(s):
> ... score.setdefault(info1, {})[info3] = info2
> ...
> py> score
> {'10/10/04': {'23': '22'}}
>
> Note that I use DOTALL to allow .* to cross line boundaries, MULTILINE 
> to have ^ apply at the start of each line, and VERBOSE to allow me to 
> write the re in a more readable form.
>
> If I didn't get your dict update quite right, hopefully you can see how 
> to fix it!

Thanks! That was very helpful. Unfortunately, I wasn't completely clear when
describing the problem. Is there anyway to extract multiple scores from the
same file and from multiple files (I will probably use the "fileinput"
module to deal with multiple files). So, if I've got say:

Gibberish
53
MoreGarbage
12
RelevantInfo1
10/10/04
NothingImportant
ThisDoesNotMatter
44
RelevantInfo2
22
BlahBlah
343
RelevantInfo3
23
Hubris
Crap
34

SecondSetofGarbage
2423
YouGetThePicture
342342
RelevantInfo1
10/10/04
HoHum
343
MoreStuffNotNeeded
232
RelevantInfo2
33
RelevantInfo3
44
sdfsdf
RelevantInfo1
10/11/04
InsertBoringFillerHere
43234
Stuff
MoreStuff
RelevantInfo2
45
ExcitingIsntIt
324234
RelevantInfo3
60
Lalala

Sorry for the long and painful example input. Notice that the first two
"RelevantInfo1" fields have the same info but that the RelevantInfo2 and
RelevantInfo3 fields have different info. Also, there will be cases where
RelevantInfo3 might be the same with a different RelevantInfo2. What, I'm
hoping for is something along then lines of being able to organize it like
so (don't worry about the format of the output -- I'll deal with that
later; "RelevantInfo" shortened to "Info" for readability):

Info1[0],   Info[1],Info[2] ...
Info3[0]Info2[Info1[0],Info3[0]]Info2[Info1[1],Info3[1]]...
Info3[1]Info2[Info1[0],Info3[1]]...
Info3[2]Info2[Info1[0],Info3[2]]...
...

I don't really care if it's a list, dictionary, array etc. 

Thanks again for your help. The multiline option in the re module is very
useful. 

Take care.

-- 
Clarke's Conclusion:
Never let your sense of morals interfere with doing the right thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: greedy match wanted

2005-03-03 Thread Paul McGuire
This is very similar to some common problems in developing pyparsing
grammars.  One of my early attempts at parsing CORBA IDL listed the
valid parameter passing mechanisms as ('in' | 'out' | 'inout').  As you
can imagine, I never successfully matched an 'inout', since the 'in'
match came first.  (Pyparsing offers an alternative greedy alternation
operator '^', which tests all alternatives and then selects the longest
match - however, '^' can have performance issues.)  Of course, the
simplest recourse is just to change the definition to ('inout' | 'in' |
'out'), but I wanted to provide a more general mechanism (since I was
getting e-mails from pyparsing users also having this same problem).
The simplest approach is to just sort the list by order, longest to
shortest, but this removes any option the developer may want to try to
front-load the list with options that are expected to occur more
frequently (for example, if defining a list of potential relational
operators, forcing ('=' | '<' | '>' | '<=' | '>=' | '!=') to become
('<=' | '>='| '!=' | '=' | '<' | '>') may cause unnecessary tests of
infrequently used operators).

I ended up adding the oneOf helper to pyparsing, which takes a single
string of space-delimited literals, and then returns a list of literals
separated by '|' operators, with literals minimally reordered, that is,
only reorderded if a longer literal masks some shorter literal.  Also,
accidental duplicates are stripped. Here is the implementation of oneOf
('|' operators generate a MatchFirst object):

.def oneOf( strs, caseless=False ):
."""Helper to quickly define a set of alternative Literals, and
makes sure to do
.   longest-first testing when there is a conflict, regardless of
the input order,
.   but returns a MatchFirst for best performance.
."""
.if caseless:
.isequal = ( lambda a,b: a.upper() == b.upper() )
.parseElementClass = CaselessLiteral
.else:
.isequal = ( lambda a,b: a == b )
.parseElementClass = Literal
.
.symbols = strs.split()
.i = 0
.while i < len(symbols)-1:
.cur = symbols[i]
.for j,other in enumerate(symbols[i+1:]):
.if ( isequal(other, cur) ):
.del symbols[i+j+1]
.break
.elif ( isequal(other[:len(cur)],cur) ):
.del symbols[i+j+1]
.symbols.insert(i,other)
.cur = other
.break
.else:
.i += 1
.
.return MatchFirst( [ parseElementClass(sym) for sym in symbols ] )
.

You could pre-process your regex with something similar, so you can
avoid having to do this (error-prone) checking yourself.

-- Paul

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


problem with recursion

2005-03-03 Thread Alexander Zatvornitskiy
Привет vegetax!

03 марта 2005 в 13:54, vegetax в своем письме к All писал:

 v> I need this in order to print a directory tree with htmlgen library
 v> which uses nested lists to represent trees.
As you see from output of your code, you simply add items to the only list. Try
this:
 v> def rec(f):
res=[]
 v> print f
 v> for ele in listdir(f):
 v>   ele=join(f,ele)
 v>   if isdir(ele):
 v>   # append the directory name
 v>   res.append(basename(ele))
  res+=[ rec(ele) ]
 v>   else:
 v> res.append(basename(ele))
return res

print rec(dirpath)



Alexander, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How would you program this?

2005-03-03 Thread pwalessi1
very nice.

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


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread Gary Nutbeam
Two out of three on the home made approach I was thinking about. 

Quixote, Cheetah and SQLObject.

Thanks for the link. I'm perusing it now.

deelan wrote:

> Gary Nutbeam wrote:
> (...)
>> Does anyone know of something similar to Rails or Maypole in Python?
> 
> you may want to take a look at subway:
> 
> 
> it glues together cherrypy2, sqlobject
> and cheetah using an MVC approach.
> 
> HTH,
> deelan.

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


Re: Need help running external program

2005-03-03 Thread Rigga
Thanks to all for your help it is now working, I rant he code through a
debugger and found that the input file I was using to create my list of
addresses to wget had newlines in them and were therefore breaking my
command line.

All your advice has been appreciated.

RiGGa

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


Re: problem with recursion

2005-03-03 Thread Kent Johnson
vegetax wrote:
I am trying to make convert a directory "tree" in a list of list, but cant
find the algoritm =( ,for example a directory tree like :
#!/usr/bin/python
from os import listdir
from os.path import isdir,join,basename
dirpath  = '/tmp/test/'
res = []
def rec(f):
print f
for ele in listdir(f):
ele = join(f,ele)
if isdir(ele):
# append the directory name  
  res.append(basename(ele))
rec(ele)
else :
res.append(basename(ele))

rec(dirpath)
print res
The problem is that you are always appending individual names to the same list. If you make rec() 
return a list and append that to the current list you get what you want:

#!/usr/bin/python
from os import listdir
from os.path import isdir,join,basename
dirpath  = '/tmp/test/'
def rec(f):
res = []
for ele in listdir(f):
res.append(ele)
ele = join(f,ele)
if isdir(ele):
res.append(rec(ele))
return res
print rec(dirpath)
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: binutils "strings" like functionality?

2005-03-03 Thread cjl
Fredrik Lundh wrote:

> something like this could work:
>
> import re
>
> text = open(file, "rb").read()
>
> for m in re.finditer("([\x20-\x7f]{4,})[\n\0]", text):
> print m.start(), repr(m.group(1))


Hey...that worked. I actually modified:

for m in re.finditer("([\x20-\x7f]{4,})[\n\0]", text):

to

for m in re.finditer("([\x20-\x7f]{4,})", text):

and now the output is nearly identical to 'strings'. One problem
exists, in that if the binary file contains a string
"monkey/chicken/dog/cat" it is printed as "mokey//chicken//dog//cat",
and I don't know enough to figure out where the extra "/" is coming
from.

Help?

-CJL

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


SOLVED: passing lists

2005-03-03 Thread Earl Eiland
It turns out that the function call was passing arguments in a different
order than they were being received.  Thanks, everyone, for your help.

earl

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


Re: Need help

2005-03-03 Thread brian
Got code from the 3rd party, maybe someone can see something wrong with
it:

def sendDataHTTP( url, postData ):
 # url format: http://www.blah.com/notrealurl

 # postData is either a dictionary or list of dictionaries
 # that contain the data that you want to post.

 responseList = []
 urlList = urlparse.urlparse( url )
 host = urlList[1]
 scriptPath = urlList[2]
 if not type( postData ) == list: postData = [ postData ]
 headers = { "Content-type": "application/x-www-form-urlencoded",
 "Accept": "text/plain" }
 conn = httplib.HTTPConnection( host )

 for thisDict in postData:
 params = urllib.urlencode( thisDict )
 conn.request("POST", scriptPath, params, headers )
 response = conn.getresponse()
 responseList.append( (response.status,response.reason) )
 conn.close()
 return responseList

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


Re: Grid not getting updated

2005-03-03 Thread Steve Holden
Gensek wrote:
I have a wxPython program, and it has a loop. I want to be able to
break the loop by pushing a button. But it doesn't react to events
until the loop finishes, which is sort of pointless.
What's the best way to get it to work? Do I need threads? Or is there a
more convenient way?
You should call the application's Yield() method now and again inside 
your loop. This allows the window display system to catch up with the 
changes to data structures that your algorithms make (I know it looks 
like the methods you call change the windows, but that actually happens 
separately), and when Yield() returns the window display should be fully 
up to date.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How would you program this?

2005-03-03 Thread engsol
On Thu, 3 Mar 2005 14:57:13 -, "Duncan Smith" <[EMAIL PROTECTED]> wrote:

>
>"engsol" <[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
>> There is a number puzzle which appears in the daily paper.
>> Because I'm between Python projects, I thought it might be
>> fun to write a program to solve it20 minute job, max.
>>
>> On closer inspection, it became apparent that it's not a
>> simple thing to program. How would you approach it?
>>
>> The puzzle: a 4 x 4 grid. The rows are summed (and given), the
>> cols are summed (and given), and the two diagonals are summed,
>> and given. In addition, 4 clues are given, but none of the 4 are in
>> the same row or col.
>>
>> Example from today's paper:...solution time is 8 minutes, 1 second,
>> so they say.
>>
>> The set of allowable numbers  is 1 thru 9
>>
>> Rows:
>> 3 + B + C + D = 22
>> E + F + 8 + H = 26
>> I + J + K + 8 = 31
>> M + 7 + O + P = 25
>>
>> Col sums:
>> 24, 18, 31, 31
>>
>> Diag sums:
>> 3 + F + K + P = 24
>> M + J + 8 + D = 24
>>
>>
>>
>> The first impulse is to just brute force it with nested for loops,
>> but the calculator shows the possible combinations are
>> 9^12 = 5,159,780,352, which would take much too long.
>>
>> Another approach would be to inspect each square and determine
>> what the range of reasonable numbers would be. For example,
>>
>> if A + 9 + C + D = 14, then A, C, D can only have a value of 1 or 2 or 3,
>> which would greatly reduce the for loop range of A, C and D.
>> While useful, it's still a manual task.
>>
>> I can't help but think there's a better way. If you have a real Python
>> project, this isn't worth your time, but if a student, it might be a good
>> exercise to think how you'd do it.
>> Norm B
>
>This sort of thing actually is a real Python project for me.  Unfortunately
>you don't generally (in practice) end up with constraints on diagonals in
>contingency tables, so my code can't solve this particular problem.  You
>might be interested in checking out the shuttle algorithm (Fienberg and
>Dobra), and seeing if you can tweak it to handle more general constraints.
>
>Duncan
>

The diagonal constraint is interestingit seems to affect the number of
solutions. One surprise, (not being a math major), was that when I let the
brute force run (forever, it seemed), but without the diagonal qualification(s),
there was maybe 100 solutions. The reson it was a surprise it that years
ago a programmer used the row-sum, col-sum method to detect and correct
data errors. He swore it was robust, and 100% reliable. Seems that that
isn't the case.
Norm B
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-03 Thread deelan
Gary Nutbeam wrote:
(...)
Does anyone know of something similar to Rails or Maypole in Python?
you may want to take a look at subway:

it glues together cherrypy2, sqlobject
and cheetah using an MVC approach.
HTH,
deelan.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >