how to finish a while loop...

2008-02-19 Thread icarus
Hi all, i'm new to python.  Learning on my own how to ask a user to
finish a loop or not.
For some reason, it behaves as infinite loop although I changed its
condition.  Please tell me what I'm doing wrong. Thanks in advance.


condition = True

while ( condition ):

try:
integer_one = int ( raw_input( "Please enter an
integer: " ) )
integer_two = int ( raw_input( "Please enter the
second integer: " ) )
division = integer_one / integer_two

except( ZeroDivisionError ):
print "\nDivision by zero detected"
except( ValueError ):
print "\nYou didn't enter an integer"
else:
print "The result is", division
answer = raw_input("Do you want to try again (yes or
no)? ")
if answer == 'yes':
condition
elif answer == 'no':
condition = False

print "Good bye, you don't want to continue"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to finish a while loop...

2008-02-19 Thread icarus
> To the original poster what environment are you running this in?
Linux.  Xubuntu if that matters.

> When I put your program in notepad and run it from the windows command
> prompt it works.
yeah yeah...same here.
After I got the tip that it actually worked, I went into the eclipse
directory where the program lives, ran it there from the shell, and it
worked.  Meaning, I didn't modify anything on the file itself (by
accident or on purpose).

> But when I paste it into eclipse and run it
> eclipse's console, it doesn't work because answer seems to have a
> stray '\r' carriage return (CR) and therefore the comparison to 'no'
> fails.
  I get no 'compile' errors there.
  I get regular execution but it just doesn't change the
condition to False at the very end.
  Therefore it loops forever.  I used other values like zeros
and ones to make sure I could print the values when the interpreter
got down to that line.  Everything checked.  Just didn't change the
condition on the main loop.

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


Re: how to finish a while loop...

2008-02-19 Thread icarus
> That code works. Maybe you fixed it while you were mailing it =)
>
> --
> -- Guilherme H. Polo Goncalves


This is weird mate.
I'm using eclipse 3.2 with the pydev plugin.  There it loops forever -
from the eclipse console.
Two hours of trying, changing the code...finally gave up.

Then I got your reply.  Opened up a regular console and executed it
from there.
And voilait works! Well, after this I'm going back to the old
trusty shell.

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


global variables: to be or not to be

2008-02-22 Thread icarus
I've read 'global variables' are bad.  The ones that are defined as
'global' inside a function/method.

The argument that pops up every now and then is that they are hard to
keep track of.  I don't know Python well enough to argue with that.
Just started learning it a few days ago, so I won't get into
philosophical questions such as "why this? Why not that?".  I'll take
it as it is, just like I take 1 + 1 = 2 for granted.

So..."global variables taste bad.  Avoid them."

But how do I get around it? How do I update and access a variable
anytime I want? Any easy-to-follow examples? Thanks in advance.








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


Flash interface for a python program

2008-03-06 Thread icarus
Is it possible to call an external python program, through a Flash
interface?

Meaning, I create a Flash window with a button.  When I press that
button, it automagically invokes the external python program.  Is that
possible? Any books/online tutorials you can recommend
me?

I guess I'm looking for alternatives in the area of GUI development.

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


broken ncurses on python 3.0

2008-12-10 Thread icarus
OS: win32, python 3.0

I've been trying to run some curses demos and I get this:

C:\Python\Lib\curses>python textpad.py
Traceback (most recent call last):
  File "textpad.py", line 3, in 
import curses
  File "C:\Python\lib\curses\__init__.py", line 15, in 
from _curses import *
ImportError: No module named _curses

The C:\Python\include does not have the curses.h header.
Reinstalling from the x86 msi binary doesn't do it.

Any ideas on how to get this working? maybe it's just the w32 version
that missed ncurses

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


optparse options

2009-05-19 Thread icarus
Why do I need to put two options for this script to print the path?

if I just specify the option and argument...
$ python 

wxpython ms-dos black window popping up in background

2008-09-09 Thread icarus
platform: windows xp professional, python 2.5, wxpython

When I double-check on my program file test.py (for simplicity I'll be
using this code below), I see the window just fine.  But the ms-dos
black window pops up in the background. On Linux, no issues at all.

How can I get rid of that ms-dos black window in the background?
something I need to add to my code? a setting to adjust in windows?
thanks in advance.


#!/usr/bin/python
import wx

appwx = wx.App()

frame = wx.Frame(None, -1, 'test.py')
frame.Show()

appwx.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython ms-dos black window popping up in background

2008-09-09 Thread icarus
Oh ok. Thanks. In windows xp I just renamed the file extension to .pyw
That did it.

one more question...

how do I create a pythonw standalone executable that works on w32,
linux, mac, etc..?

My intent is to have the process transparent to the user. He wouldn't
even know the app was written in python. All he knows that when he
double-clicks on it, the application pops up without the DOS black
screen in the background (for w32 users.)






On Sep 9, 10:49 am, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> You need to have the script be run by pythonw.exe as opposed to python.exe
> pythonw.exe suppresses the DOS box from coming up and should be used
> for running GUI applications such as yours.
>
> Regards,
> Chris
>
>
>
> On Tue, Sep 9, 2008 at 1:33 PM, icarus <[EMAIL PROTECTED]> wrote:
> > platform: windows xp professional, python 2.5, wxpython
>
> > When I double-check on my program file test.py (for simplicity I'll be
> > using this code below), I see the window just fine.  But the ms-dos
> > black window pops up in the background. On Linux, no issues at all.
>
> > How can I get rid of that ms-dos black window in the background?
> > something I need to add to my code? a setting to adjust in windows?
> > thanks in advance.
>
> > #!/usr/bin/python
> > import wx
>
> > appwx = wx.App()
>
> > frame = wx.Frame(None, -1, 'test.py')
> > frame.Show()
>
> > appwx.MainLoop()
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
> Follow the path of the Iguana...http://rebertia.com

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


getting global variables from dictionary

2008-09-26 Thread icarus
global_vars.py has the global variables
set_var.py changes one of the values on the global variables (don't
close it or terminate)
get_var.py retrieves the recently value changed (triggered right after
set_var.py above)

Problem: get_var.py retrieves the old value, the built-in one but not
the recently changed value in set_var.py.

What am I doing wrong?

global_vars.py---
#!/usr/bin/python

class Variables :
def __init__(self) :
self.var_dict = {"username": "original username"}


---set_var.py ---
#!/usr/bin/python

import time
import global_vars

global_vars.Variables().var_dict["username"] = "new username"
time.sleep(10)   #give enough time to trigger get_var.py


---get_var.py ---
#!/usr/bin/python
import global_vars
print global_vars.Variables().var_dict.get("username")
--
http://mail.python.org/mailman/listinfo/python-list


Problems with using queue in Tkinter application

2009-07-03 Thread Icarus
I'm working on a serial protocol analyzer in python.  We have an
application written by someone else in MFC but we need something that
is cross platform.  I intended to implement the GUI portion in Tkinter
but am having trouble.

The idea is that I will read messages from the serial port and output
them to a Tkinter Text object initially.  Eventually it will have
other functionality but that's it for the short term.  I've written
this little test app to experiment with putting things on the GUI via
a Queue which is polled by the Tkinter loop.

On some machines this code works fine and I get whatever I type in
displayed in the Text widget.  On others I get errors like this as
soon as I start it running.

error in background error handler:
out of stack space (infinite loop?)
while executing
"::tcl::Bgerror {out of stack space (infinite loop?)} {-code 1 -level
0 -errorcode NONE -errorinfo {out of stack space (infinite loop?)
while execu..."


I don't understand why on some machines it works exactly as expected
and on others it acts the same way Tkinter does when I call functions
directly from outside the Tkinter thread.  Does anyone have any
suggestions?  The full code as appended below.  Thanks in advance.

[code]

import Queue

class functionQueue:

def __init__(self, root = None, timeout = 250):

self.functionQueue = Queue.Queue()
self.root = root
self.timeout = timeout

if(self.root):
self.pop_function(root)


def pop_function(self, root = None):

try:
funcArgList = self.functionQueue.get(block = False)
except Queue.Empty:
pass
else:
try:
funcArgList[0](*funcArgList[1])
except:
try:
print "Failed to call function", funcArgList[0]
except:
print "Failed to call function"

if(root):
root.after(self.timeout, lambda: self.pop_function
(self.root))

def add_function(self, function, argList):

try:
self.functionQueue.put([function, argList])
except:
pass


if( __name__ == '__main__'):

import Tkinter
import thread

text = Tkinter.Text()
text.pack()

myQueue = functionQueue(text, 50)

def gui_loop():
try:
text.mainloop()
except:
import os
os._exit(1)

thread.start_new_thread(text.mainloop, ())

while(True):
usrInput = raw_input()

if(usrInput == "-1"):
import os
os._exit(0)

myQueue.add_function(text.insert, ['end', usrInput + "\n"])
myQueue.add_function(text.see, ['end'])

[/code]

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


Re: Problems with using queue in Tkinter application

2009-07-04 Thread Icarus
On Jul 4, 3:21 am, Peter Otten <[email protected]> wrote:
> Icarus wrote:
> > I'm working on a serial protocol analyzer in python.  We have an
> > application written by someone else in MFC but we need something that
> > is cross platform.  I intended to implement the GUI portion in Tkinter
> > but am having trouble.
>
> > The idea is that I will read messages from the serial port and output
> > them to a Tkinter Text object initially.  Eventually it will have
> > other functionality but that's it for the short term.  I've written
> > this little test app to experiment with putting things on the GUI via
> > a Queue which is polled by the Tkinter loop.
>
> > On some machines this code works fine and I get whatever I type in
> > displayed in the Text widget.  On others I get errors like this as
> > soon as I start it running.
>
> > error in background error handler:
> > out of stack space (infinite loop?)
> >     while executing
> > "::tcl::Bgerror {out of stack space (infinite loop?)} {-code 1 -level
> > 0 -errorcode NONE -errorinfo {out of stack space (infinite loop?)
> >     while execu..."
>
> > I don't understand why on some machines it works exactly as expected
> > and on others it acts the same way Tkinter does when I call functions
> > directly from outside the Tkinter thread.  Does anyone have any
> > suggestions?  The full code as appended below.  Thanks in advance.
>
> > [code]
>
> > import Queue
>
> > class functionQueue:
>
> >     def __init__(self, root = None, timeout = 250):
>
> >         self.functionQueue = Queue.Queue()
> >         self.root = root
> >         self.timeout = timeout
>
> >         if(self.root):
> >             self.pop_function(root)
>
> >     def pop_function(self, root = None):
>
> >         try:
> >             funcArgList = self.functionQueue.get(block = False)
> >         except Queue.Empty:
> >             pass
> >         else:
> >             try:
> >                 funcArgList[0](*funcArgList[1])
> >             except:
> >                 try:
> >                     print "Failed to call function", funcArgList[0]
> >                 except:
> >                     print "Failed to call function"
>
> >         if(root):
> >             root.after(self.timeout, lambda: self.pop_function
> > (self.root))
>
> >     def add_function(self, function, argList):
>
> >         try:
> >             self.functionQueue.put([function, argList])
> >         except:
> >             pass
>
> > if( __name__ == '__main__'):
>
> >     import Tkinter
> >     import thread
>
> >     text = Tkinter.Text()
> >     text.pack()
>
> >     myQueue = functionQueue(text, 50)
>
> >     def gui_loop():
> >         try:
> >             text.mainloop()
> >         except:
> >             import os
> >             os._exit(1)
>
> >     thread.start_new_thread(text.mainloop, ())
>
> >     while(True):
> >         usrInput = raw_input()
>
> >         if(usrInput == "-1"):
> >             import os
> >             os._exit(0)
>
> >         myQueue.add_function(text.insert, ['end', usrInput + "\n"])
> >         myQueue.add_function(text.see, ['end'])
>
> > [/code]
>
> I can make it work over here by putting the UI into the main thread, as
> suggested byhttp://effbot.org/zone/tkinter-threads.htm:
>
> import Queue
> import Tkinter
> import threading
>
> class FunctionQueue:
>     # unchanged
>
> def input_loop():
>     while True:
>         try:
>             usrInput = raw_input()
>         except EOFError:
>             break
>         myQueue.add_function(text.insert, ['end', usrInput + "\n"])
>         myQueue.add_function(text.see, ['end'])
>     myQueue.add_function(text.quit, [])
>
> if __name__ == '__main__':
>     text = Tkinter.Text()
>     text.pack()
>
>     myQueue = FunctionQueue(text, 50)
>     threading.Thread(target=input_loop).start()
>     text.mainloop()
>
> Peter

Peter, thanks for the suggestion.  I tried your code exactly on my box
and I still get the same results.  As soon as I run the script and
every time I click on the Text box I get tcl::Bgerror ... just like I
mentioned above.  I'm fairly certain that I'm not calling Tkinter
functions from any other thread but it's acting as though I am as soon
as I create the input thread.
If I comment out the input loop thread everything is fine but of
course that's not terribly useful as a logging box.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with using queue in Tkinter application

2009-07-05 Thread Icarus
On Jul 4, 11:24 am, Peter Otten <[email protected]> wrote:
> Icarus wrote:
> > On Jul 4, 3:21 am, Peter Otten <[email protected]> wrote:
> >> Icarus wrote:
> >> > I'm working on a serial protocol analyzer in python.  We have an
> >> > application written by someone else in MFC but we need something that
> >> > is cross platform.  I intended to implement the GUI portion in Tkinter
> >> > but am having trouble.
>
> >> > The idea is that I will read messages from the serial port and output
> >> > them to a Tkinter Text object initially.  Eventually it will have
> >> > other functionality but that's it for the short term.  I've written
> >> > this little test app to experiment with putting things on the GUI via
> >> > a Queue which is polled by the Tkinter loop.
>
> >> > On some machines this code works fine and I get whatever I type in
> >> > displayed in the Text widget.  On others I get errors like this as
> >> > soon as I start it running.
>
> >> > error in background error handler:
> >> > out of stack space (infinite loop?)
> >> > while executing
> >> > "::tcl::Bgerror {out of stack space (infinite loop?)} {-code 1 -level
> >> > 0 -errorcode NONE -errorinfo {out of stack space (infinite loop?)
> >> > while execu..."
>
> >> > I don't understand why on some machines it works exactly as expected
> >> > and on others it acts the same way Tkinter does when I call functions
> >> > directly from outside the Tkinter thread.  Does anyone have any
> >> > suggestions?  The full code as appended below.  Thanks in advance.
>
> >> > [code]
>
> >> > import Queue
>
> >> > class functionQueue:
>
> >> > def __init__(self, root = None, timeout = 250):
>
> >> > self.functionQueue = Queue.Queue()
> >> > self.root = root
> >> > self.timeout = timeout
>
> >> > if(self.root):
> >> > self.pop_function(root)
>
> >> > def pop_function(self, root = None):
>
> >> > try:
> >> > funcArgList = self.functionQueue.get(block = False)
> >> > except Queue.Empty:
> >> > pass
> >> > else:
> >> > try:
> >> > funcArgList[0](*funcArgList[1])
> >> > except:
> >> > try:
> >> > print "Failed to call function", funcArgList[0]
> >> > except:
> >> > print "Failed to call function"
>
> >> > if(root):
> >> > root.after(self.timeout, lambda: self.pop_function
> >> > (self.root))
>
> >> > def add_function(self, function, argList):
>
> >> > try:
> >> > self.functionQueue.put([function, argList])
> >> > except:
> >> > pass
>
> >> > if( __name__ == '__main__'):
>
> >> > import Tkinter
> >> > import thread
>
> >> > text = Tkinter.Text()
> >> > text.pack()
>
> >> > myQueue = functionQueue(text, 50)
>
> >> > def gui_loop():
> >> > try:
> >> > text.mainloop()
> >> > except:
> >> > import os
> >> > os._exit(1)
>
> >> > thread.start_new_thread(text.mainloop, ())
>
> >> > while(True):
> >> > usrInput = raw_input()
>
> >> > if(usrInput == "-1"):
> >> > import os
> >> > os._exit(0)
>
> >> > myQueue.add_function(text.insert, ['end', usrInput + "\n"])
> >> > myQueue.add_function(text.see, ['end'])
>
> >> > [/code]
>
> >> I can make it work over here by putting the UI into the main thread, as
> >> suggested byhttp://effbot.org/zone/tkinter-threads.htm:
>
> >> import Queue
> >> import Tkinter
> >> import threading
>
> >> class FunctionQueue:
> >> # unchanged
>
> >> def input_loop():
> >> while True:
> >> try:
> >> usrInput = raw_input()
> >> except EOFError:
> >> break
> >> myQueue.add_function(text.insert, ['end', usrInput + "\n"])
> >> myQueue.add_function(text.see, ['end'])
> >> myQueue.add_function(text.quit, [])
>
> >> if __name__ == '__main__':
> >> text = Tkinter.Text()
> >> text.pack()
>
> >> myQueue = FunctionQueue(text, 50)
> >> threading.Thread(target=input_loop).start()
> >> text.mainloop()
>
> >> Peter
>
> > Peter, thanks for the suggestion.  I tried your code exactly on my box
> > and I still get the same results.  As soon as I run the script and
> > every time I click on the Text box I get tcl::Bgerror ... just like I
> > mentioned above.  I'm fairly certain that I'm not calling Tkinter
> > functions from any other thread but it's acting as though I am as soon
> > as I create the input thread.
> > If I comment out the input loop thread everything is fine but of
> > course that's not terribly useful as a logging box.
>
> http://bugs.python.org/issue3835
>
> Could tcl have been built without thread support on the failing machines?
>
> Peter

You had it Peter.  I tried the "import pydoc pydoc.gui()" in the bug
report you referenced and the same thing described there occurred.
After recompiling tcl/tk with --threads-enabled and replacing the
slackware default packages with those everything is working as I
expected.  Thanks for the help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Icarus Sparry
On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote:

> Xah Lee  writes:
> 
>> problem with find xargs is that they spawn grep for each file, which
>> becomes too slow to be usable.
> 
> find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever
> 
> will call grep with a list of filenames given by find, only a single
> grep process will run.
> 
> //Petter

This is getting off-topic for the listed newsgroups and into 
comp.unix.shell (although the question was originally posed in a MS 
windows context).

The 'modern' way to do this is
find . -maxdepth 2 -name '*.html' -exec grep whatever {} +

The key thing which makes this 'modern' is the '+' at the end of the 
command, rather than '\;'. This causes find to execute the grep once per 
group of files, rather than once per file.

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


Re: How to Write grep in Emacs Lisp (tutorial)

2011-02-08 Thread Icarus Sparry
On Tue, 08 Feb 2011 14:30:53 -0800, Xah Lee wrote:

> On Feb 8, 9:32 am, Icarus Sparry  wrote:
[snip]
>> The 'modern' way to do this is
>> find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
>>
>> The key thing which makes this 'modern' is the '+' at the end of the
>> command, rather than '\;'. This causes find to execute the grep once
>> per group of files, rather than once per file.
> 
> Nice. When was the + introduced?

Years ago! The posix spec for find lists it in the page which has a 
copyright of 2001-2004.

http://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html

Using google, I have come up with this reference from 2001

https://www.opengroup.org/sophocles/show_mail.tpl?
CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=3067

in which David Korn reports writing the code in 1987.
-- 
http://mail.python.org/mailman/listinfo/python-list