Re: Line by line execution of python code

2006-07-13 Thread mkPyVS
Try this... slightly more complex but get's the job done-> added some
wait state in the user program/thread so it didn't kill the output
stream... Enjoy

import thread, sys, time

def someUserProgram(mutexRef):
while 1:
mutexRef.acquire()
print "I am a user program"
mutexRef.release()
time.sleep(1)

class main:
def __init__(self):
self.mutex = thread.allocate_lock()
self.someProgram = None

def mainProgram(self,someUserProgram):

self.someProgram = someUserProgram
self.executeOneStatement(self.someProgram)

inval = ''
while not inval == 'q':
inval = sys.stdin.readline().strip()
print "Doing some stuff here"
thread.exit()

def executeOneStatement(self,program):
thread.start_new(program, (self.mutex,))



l = main()

l.mainProgram(someUserProgram)
Justin Powell wrote:
> Hi, I'm looking for suggestions on how to accomplish something in python.  If
> this is the wrong list for such things, I appologize and please disregard the
> rest.
>
> My application needs to allow users to create scripts which will be executed
> in a statement-by-statement fashion.  Here's a little pseudo-code:
>
> def someUserProgram():
>   while 1:
>   print "I am a user program"
>
> def mainProgram():
>   someProgram = someUserProgram
>   while 1:
>   print "Doing some stuff here"
>   executeOneStatement(someProgram)
>
> def executeOneStatement(program):
>   # What goes in here?
>
> I would expect the output to look like this:
>
> Doing some stuff here
> Doing some stuff here
> I am a sub program
> Doing some stuff here
> Doing some stuff here
> I am a sub program
> etc.
>
> It's possible to use generators to accomplish this, but unfortunately a
> state-ment by statement executing would require that every other statement is
> a yield.  That would either force the users to put in a yield after every
> statement, or require a mechanism that parses the source and inserts yield
> statement before execution.  Neither of these are really satisfactory
>
> The other methods I've considered for doing this cleanly (subclassing the
> debugger, or the interactive interpreter) seem to revolve around sys.settrace
> and a callback trace function. I couldn't figure out a way to use this
> mechanism to resume the main loop from the trace function, and then also
> resume the user program the next time around, without the call stack just
> spiraling out of control.
>
> Anybody have a solution to this?  I've done a bit of searching, looking
> through python docs and sources and so forth, and I'm pretty stumped at this
> point.
>
> Thanks.
>
> __
> 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: What's the best IDE?

2006-10-25 Thread mkPyVS
I perform python development for cross platform firmware integration
and analysis on a daily basis and the IDE I use and recommend is Komodo
from ActiveState. Our worldwide development group (30) has recently all
purchased the professional version as it integrates with several
version control systems, has a built-in python debugger, a
mutli-language/package GUI builder, and in-line code
lookup/auto-complete functionality. There are a few nice-to-haves which
aren't available such as: C (++, # or otherwise) auto-complete and
alternate py-documentation viewer but the pros far outweighed the cons
for our development team.
http://www.activestate.com/Products/Komodo/?tn=1

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


Re: Flight search automation

2006-06-23 Thread mkPyVS
Is there an http page redirect call to the client once the java
releases it's wait que?

George Sakkis wrote:
> I'm trying to use mechanize to fill in a "find a flight" form and then
> get back the results, but I'm not sure how to make it wait until the
> results page appears; the response after submitting the form is the
> "please wait while we are searching for your flights" page. Any ideas ?
> 
> George

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


Re: Flight search automation

2006-06-23 Thread mkPyVS
If you look at the <> generated HTML @Travelocity

**Snippet
function on_load()
{
  var finurl = "AirSearch.do?SEQ=11510863338485232006";
  window.location.replace(finurl);
**
It is basically a re-direct.. you should be able to re-request an HTTP
to the base path from the original query w/ your new URL for the
session result.
Base URL= http://travel.travelocity.com/flights
So now you would request
http://travel.travelocity.com/flights/AirSearch.do?SEQ=11510863338485232006

George Sakkis wrote:
> mkPyVS wrote:
>
> > Is there an http page redirect call to the client once the java
> > releases it's wait que?
>
> Sorry, I've no idea.. not even sure if they use java or whether this
> matters. Can you guess by trying, say, http://www.travelocity.com/ ?
> Expedia and Orbitz have also a waiting page, hopefully I can figure
> them out once I have one working.
>
> George
>
> > George Sakkis wrote:
> > > I'm trying to use mechanize to fill in a "find a flight" form and then
> > > get back the results, but I'm not sure how to make it wait until the
> > > results page appears; the response after submitting the form is the
> > > "please wait while we are searching for your flights" page. Any ideas ?
> > > 
> > > George

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


Resizing listbook's listview pane

2007-05-22 Thread mkPyVS
I'm having an issue I need help with. I want to resize the listview
control in a listbook but have been unsuccessfull through setting the
columnWidth of the 0'th column and trying to retrieve the listbooks
sizer return's None Ideas?

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

Mike

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

Mike

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

Mike

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 9:04 am, [EMAIL PROTECTED] wrote:
> Which Python gui toolkit are you using? Tkinter, wxPython, pyQT? Are
> you wanting the resize to happen programmatically, when the user
> changes the app's size, both or what?
>
> More details would be helpful.
>
> Mike

Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 9:04 am, [EMAIL PROTECTED] wrote:
> Which Python gui toolkit are you using? Tkinter, wxPython, pyQT? Are
> you wanting the resize to happen programmatically, when the user
> changes the app's size, both or what?
>
> More details would be helpful.
>
> Mike

Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 9:04 am, [EMAIL PROTECTED] wrote:
> Which Python gui toolkit are you using? Tkinter, wxPython, pyQT? Are
> you wanting the resize to happen programmatically, when the user
> changes the app's size, both or what?
>
> More details would be helpful.
>
> Mike

Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 9:04 am, [EMAIL PROTECTED] wrote:
> Which Python gui toolkit are you using? Tkinter, wxPython, pyQT? Are
> you wanting the resize to happen programmatically, when the user
> changes the app's size, both or what?
>
> More details would be helpful.
>
> Mike

Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 9:04 am, [EMAIL PROTECTED] wrote:
> Which Python gui toolkit are you using? Tkinter, wxPython, pyQT? Are
> you wanting the resize to happen programmatically, when the user
> changes the app's size, both or what?
>
> More details would be helpful.
>
> Mike

Sorry, copied from wxpython submit as well.. I'm using wxpython 2.8...
Primariy I want the resize to happen programatically during object
creation/post creation... I can worry about app size changes later.

Thanks,

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 1:47 pm, [EMAIL PROTECTED] wrote:
> Wow! You sure like to post a lot! Sheesh! I subscribe to the wxPython
> user's group and I don't see your post anywhere.

Yeah sorry.. google groups was giving me repeated errors on post...
frustration clicking took over and viola... 17 posts- my apologies.

>
> I can't find much documentation for this control either. The demo
> seems to have a way to change the size of one of the panels using the
> method "SetSize" though. I recommend trying the wxPython group again
> though.
>
> Mike

Neither can I. I've tried to use SetSize on the listview object but to
no avail... I'm trying to down-size the content frame as it's min-size
in the sizer may be what is causing the listview to be pushed to it's
minsize. .
Thx,
Mike

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


Re: Resizing listbook's listview pane

2007-05-23 Thread mkPyVS
On May 23, 10:44 pm, mkPyVS <[EMAIL PROTECTED]> wrote:

So the issue was that the min-size of the content panel actually
limits the size of the listview control. Once the minsize attribute is
modified in the listbook panels the listview can then be resized to be
wider on callback or with a custom sizer... Now on to figure out how
to change the displayed text width.

Thanks,
Mike

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


Re: regular expression dictionary search

2007-08-20 Thread mkPyVS
On Aug 20, 9:35 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/env python
>
> import re
>
> patterns = { 'sho.' : 6, '.ilk' : 8, '.an.' : 78 }
>
> def returnCode(aWord):
> for k in patterns:
> p = "^%s$" % k
> regex = re.compile(p)
> if re.match(regex, aWord):
> return patterns[k]
>
> if __name__ == "__main__":
>
> print "The return for 'fred' : %s" % returnCode('fred')
> print "The return for 'silk' : %s" % returnCode('silk')
> print "The return for 'silky' : %s" % returnCode('silky')
> print "The return for 'hand' : %s" % returnCode('hand')
> print "The return for 'strand' : %s" % returnCode('strand')
> print "The return for 'bank' : %s" % returnCode('bank')
>
> Note: If a word matches more than one pattern, only one will be returned.
>
> I'm not sure if I'm doing the patterns thing properly -- if anyone
> could instruct me on whether it would be proper to declare it in the
> function, or use a global declaration, please let me know. However, it
> runs properly as far as I tested it.
>
> Shawn

I think global/local declaration should in part depend on the scope of
your usage. Are you going to re-use the function over and over again
in multiple modules? Does it need any state collecting statistics? If
so I would recommend you upgrade your function to a class then define
"patterns" as a static class level variable. Then the initialization
cost is eaten only for creation of the class (most often) the 1st
time.

As a side note unless you are searching large buffers it is possibly
more costly to compile into a re object then do a match with it as
opposed to let the match object perform a compile a function level
itself- if you use the class option above I would recommend storing
the re.compiled versions of your patterns in the dictionary
(everything is an object!) rather than the string repr and issuing a
compile.

mkPyVS

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


Re: Optimization problem

2007-03-18 Thread mkPyVS
I would suggest taking a look at the python package networkx. It is a
wonderfully created path optimization and presentation package which
has a fair amount of extensabilty.

Basic lowest cost path solutions should be able to solve your
algorithmic needs here in polynomial time (Typically N**P time..
compute time through path to the number of nodes power) which is
typically adequate for most functional needs ( < 1 sec for 20 nodes)
and presents a simple solution path unless the path you present has
many loop options or path costs which are mal-formed. Good Luck,

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


Re: Memory testing in Python

2007-03-30 Thread mkPyVS
>While I have a great deal of interest in memory management,
>my general reaction to your question as you've posed it is,
>"Don't; concentrate for now on good Python style."

I agree but for monitoring...

I've had good luck with executing a popen to grab and parse output
from ps -Af and pass it your own process ID as the search. It adds
overhead to the cpu exec time but it is much less than 1sec so you
won't see it.

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


Re: Indentifying the LAST occurrence of an item in a list

2007-04-05 Thread mkPyVS
Not sure below is better but it hacks at larger chunks (excuse the 10
second coding)
m = [2,9,1,5,6,3,1,1,9,2]
f = 1
temp = m
location = m.index(f)
gloc = location
temp = m[location:]
while 1:
   print(temp)
   try:
  location = temp.index(f) + 1
  gloc += location
   except:
  break
   temp = temp[location:]
#Remove the last 0th element
gloc -= 1
print("Last location = %d" % gloc)

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


Re: Indentifying the LAST occurrence of an item in a list

2007-04-06 Thread mkPyVS
On Apr 5, 6:37 pm, "John Machin" <[EMAIL PROTECTED]> wrote:
>>> help(list.index)
> Help on method_descriptor:
>
> index(...)
> L.index(value, [start, [stop]]) -> integer -- return first index
> of value
>
> I look forward to your next version.

Great point! I was assuming the temp variable space was static but the
pointer to the start of the list was moving-> shame on me (what
language is this now ;)!

Couldn't resist the temptation to just collect all of the locations as
I traversed

m = [2,9,1,5,6,3,1,1,9,2]
f = 1#What we're looking for
location = 0 #Start at beginning of list
fIndexs = []
while 1:
   try:
  location = m.index(f,location) + 1
  fIndexs.append(location-1)
   except ValueError:
  break

print("Last location = %d" % fIndexs[-1])
print("All Items = %s" % fIndexs)

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


Re: is this data structure build-in or I'll have to write my own class?

2008-02-20 Thread mkPyVS
On Feb 20, 12:07 pm, thebjorn <[EMAIL PROTECTED]>
wrote:
> On Feb 20, 3:32 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Feb 20, 2008 8:15 AM, Larry Bates <[EMAIL PROTECTED]> wrote:
>
> > > Jorge Vargas wrote:
> > > > I need a data structure that will let me do:
>
> > > > - attribute access (or index)
> > > > - maintain the order (for iter and print)
> > > > - be mutable.
>
> [...]
>
> > > Sounds like a good time to learn ElementTree (included in Python 2.5 but
> > > available for earlier versions).
>
> > I am using ET, to fetch the data from the XML, after that I want a
> > plain python object. for the rest of the program.
>
> Ok, you just lost me... Why do you thin ET is not appropriate (*)?  It
> fits all your requirements, is optimized for representing hierarchical
> data (especially xml), it is fast, it is well tested, it has a
> community of users, it is included in the standard library, etc., etc.
>
> ...maybe I didn't grok what you meant by "plain python object"?
>
> -- bjorn
>
> (*) I just had a flashback to the movie ET -- the scene when he's in
> the closet ;-)

This isn't so optimal but I think accomplishes what you desire to some
extent... I *think* there is some hidden gem in inheriting from dict
or an mapping type that is cleaner than what I've shown below though.

class dum_struct:
   def __init__(self,keyList,valList):
  self.__orderedKeys = keyList
  self.__orderedValList = valList
   def __getattr__(self,name):
  return self.__orderedValList[self.__orderedKeys.index(name)]


keys = ['foo','baz']
vals = ['bar','bal']

m = dum_struct(keys,vals)

print m.foo
-- 
http://mail.python.org/mailman/listinfo/python-list