[Tutor] Tutor Digest, Vol 19, Issue 82

sanjay sinha sanju_nic at yahoo.com
Tue Sep 27 06:51:52 CEST 2005


Hi
I am sanju sinha just started python from the last one month . I have gone through all basic programming of with python and also use Tkinter for window . I want to know from you all experience person in python that weather i move to wx or tkinter is sufficient for GUI programming.
thank you
sanju

tutor-request at python.org wrote:
Send Tutor mailing list submissions to
tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-request at python.org

You can reach the person managing the list at
tutor-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

1. Re: Problem with BeautifulSoup (Kent Johnson)
2. wxPython problem (?yvind)
3. script question (Chris Hallman)
4. Re: script question (Kent Johnson)
5. Re: wxPython problem (Franz Steinhäusler)
6. Re: wxPython problem (?yvind)
7. Re: script question (Christopher Arndt)
8. Re: wxPython problem (Franz Steinhäusler)
9. Re: Challenge [was Re: Why won't it enter the quiz?]
(Nathan Pinno)


----------------------------------------------------------------------

Message: 1
Date: Mon, 26 Sep 2005 06:09:07 -0400
From: Kent Johnson 
Subject: Re: [Tutor] Problem with BeautifulSoup
Cc: Python Tutor list 
Message-ID: <4337C8C3.5020701 at tds.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Bernard Lebel wrote:
> Hi grouchy,
> 
> I seem to have found the problem. Somehow, it seems BeautifulSoup
> doesn't like nested tags of the same name.

This seems to be a feature of BS. It seems a bit of a misfeature when applied to XML but anyway...you can configure BS with a set of tags which can be nested, then it will properly parse your data. Here is a short program that shows how:

xml = '''



1



'''

import BeautifulSoup

class NestingParser(BeautifulSoup.BeautifulStoneSoup):
NESTABLE_TAGS = BeautifulSoup.buildTagMap([], 'parameter')

soup = NestingParser(xml)
print soup.prettify()


Kent



------------------------------

Message: 2
Date: Mon, 26 Sep 2005 13:41:32 +0200 (CEST)
From: ?yvind 

Subject: [Tutor] wxPython problem
To: tutor at python.org
Message-ID: <38850.193.71.38.142.1127734892.squirrel at mail.sporck.net>
Content-Type: text/plain;charset=iso-8859-1

Hello.

I have been reading the
http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
running the program there. (Enclosed below).

When I run it, it works fine. But, when I run it again, I get the error
PyNoAppError: The wx.App object must be created first! I assume I have
killed the object and have to create it again. But how would I do that?
reload(MainWindow) does not work. Any suggestions?

Thanks in advance.


-----
import os
import wx
ID_ABOUT=101
ID_EXIT=110
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),

style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
# method
self.OnAbout
wx.EVT_MENU(self, ID_EXIT, self.OnExit) # attach the menu-event
ID_EXIT to the
# method
self.OnExit
self.Show(True)
def OnAbout(self,e):
d= wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True) # Close the frame.
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no



------------------------------

Message: 3
Date: Mon, 26 Sep 2005 07:56:32 -0400
From: Chris Hallman 
Subject: [Tutor] script question
To: tutor at python.org
Message-ID: <9f68812f05092604563052918f at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I needed a script that takes command line arguments, searches an ini file
for a match to the arguments and then executes a Windows executable. This is
my first script using python so I wanted to make sure I made the most of the
language. I took bits and pieces from different tutorials and examples
online. The script is executed in this manner:


python search_interface.py device interface interface_name "is down -
00:00:00 01/01/06"


Here is the script:

import ConfigParser, string, sys
section = sys.argv[1]
port = sys.argv[3]
INI=ConfigParser.ConfigParser()
INI.read("interfaces.ini")
passwordentries=[p for p in INI.options(section)]
passwordlist=[INI.get(section, pw) for pw in passwordentries]
print passwordlist
for i in passwordlist:
if i == port:
os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + " " +
sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])


I'd like to know if there is a more efficient way to do this and if there is
a way to have these functions performed with the least amount of time
possible (the ini file could grow quite large).



Thanks!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050926/42fb29b6/attachment-0001.htm

------------------------------

Message: 4
Date: Mon, 26 Sep 2005 08:13:38 -0400
From: Kent Johnson 
Subject: Re: [Tutor] script question
Cc: tutor at python.org
Message-ID: <4337E5F2.2050807 at tds.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Chris Hallman wrote:
> The script is executed in this 
> manner:
> 
> python search_interface.py device interface interface_name "is down - 
> 00:00:00 01/01/06"
> 
> Here is the script:
> 
> import ConfigParser, string, sys
> section = sys.argv[1]
> port = sys.argv[3]
> INI=ConfigParser.ConfigParser()

Generally all caps names are used for constants, it would be more idiomatic to use ini.

> INI.read("interfaces.ini")
> passwordentries=[p for p in INI.options(section)]

This could just be 
passwordentries = INI.options(section), which is already a list. But even better, see below...

> passwordlist=[INI.get(section, pw) for pw in passwordentries]

The above two lines can be replaced with
passwordlist = [value for name, value in INI.items(section)]
which just accesses the section once.

Kent

> print passwordlist
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + 
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])
> 
> 
> I'd like to know if there is a more efficient way to do this and if 
> there is a way to have these functions performed with the least amount 
> of time possible (the ini file could grow quite large).
> 
> 
> 
> Thanks!!
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



------------------------------

Message: 5
Date: Mon, 26 Sep 2005 14:04:39 +0200
From: Franz Steinhäusler 
Subject: Re: [Tutor] wxPython problem
To: tutor at python.org
Message-ID: 
Content-Type: text/plain; charset=ISO-8859-1

On Mon, 26 Sep 2005 13:41:32 +0200 (CEST), ?yvind 
wrote:

>Hello.
>
>I have been reading the
>http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
>running the program there. (Enclosed below).
>
>When I run it, it works fine. But, when I run it again, I get the error
>PyNoAppError: The wx.App object must be created first! I assume I have
>killed the object and have to create it again. But how would I do that?
>reload(MainWindow) does not work. Any suggestions?
>
>Thanks in advance.


Hi,

Windows? Linux? wxPyVersion?

This sounds familiar to me, but I can't
remember exactly.

how do you run it?
in command prompt?
from a python shell (Idle, Pycrust)?

--
Franz Steinhaeusler



------------------------------

Message: 6
Date: Mon, 26 Sep 2005 14:32:53 +0200 (CEST)
From: ?yvind 

Subject: Re: [Tutor] wxPython problem
To: tutor at python.org
Message-ID: <13974.193.71.38.142.1127737973.squirrel at mail.sporck.net>
Content-Type: text/plain;charset=iso-8859-1

Sorry... Forgot all about that.

Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.

I run it in ActiveStates Interactive Window, which is IDLE (I think).

Thanks in advance







<--

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no



------------------------------

Message: 7
Date: Mon, 26 Sep 2005 13:56:25 +0100
From: Christopher Arndt 
Subject: Re: [Tutor] script question
To: Tutor at python.org
Message-ID: <4337EFF9.6030604 at web.de>
Content-Type: text/plain; charset=ISO-8859-1

Chris Hallman schrieb:
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])

1) The last line can be also expressed as:

os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(sys.argv[1:5]),))

sys.argv is a list of strings (from which we're only using elements 1-4), which
you can concatenate with the join() method of strings. Then use the '%' string
operator to add it to the command string.

If your command line arguments might contain spaces, you should quote them like
this:

os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(['"%s"' % x for x
in sys.argv[1:5]]),))

You'll find more information about these methods and operators in the standard
library docs section 2.3.

2) I also used a raw string (r'') to avoid having to use double backslashes in
windows paths all the time.

3) Assuming that sys.argv[3] (port) will only match one password in
passwordlist, you can also shorten the for/if construction to:

if port in passwordlist:
os.system(...)

because you're not actually using any of the information from the ini file in
your command line.

4) As to your question regarding efficiency of the script, unfortunately the
ConfigParser module parses the whole INI file unconditionally. You could look
for other third-party configuration file parsers that might do this more
efficiently, but I can not help you there. Start looking a the Cheese shop
(www.python.org/pypi)

Chris


------------------------------

Message: 8
Date: Mon, 26 Sep 2005 14:57:35 +0200
From: Franz Steinhäusler 
Subject: Re: [Tutor] wxPython problem
To: tutor at python.org
Message-ID: 
Content-Type: text/plain; charset=ISO-8859-1

On Mon, 26 Sep 2005 14:32:53 +0200 (CEST), ?yvind 
wrote:

>Sorry... Forgot all about that.
>
>Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.
>
>I run it in ActiveStates Interactive Window, which is IDLE (I think).
>
>Thanks in advance
>
>

Aha, I thought something similar.

It is always a problem to run 2 different 
or competing GUI's the same time.

IDLE with wxPython or Active State Python (they
use the win32 extensions)

The best possibility is to use an IDE, which fits
to the GUI.

Pycrust as shell,
Editor and IDE's: DrPython, spe, Boa Constructor,...
or simply use SciTE as editor and with F5, you can
start your typed in Program and on the right you
have an output pane (With DrPython, you have these
possibilities and many more).

--
Franz Steinhaeusler



------------------------------

Message: 9
Date: Mon, 26 Sep 2005 11:34:46 -0600
From: "Nathan Pinno" 
Subject: Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]
To: "bob" 
Cc: tutor at python.org
Message-ID: 
Content-Type: text/plain; charset="iso-8859-1"

Bob,

I did what you suggested. Take another look, and tell me if you were a potential customer, would you purchase something?

Why not take the challenge? It's not like I'm asking much.

Nathan Pinno
----- Original Message ----- 
From: bob 
To: Nathan Pinno 
Cc: tutor at python.org 
Sent: Thursday, September 22, 2005 10:08 PM
Subject: Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]


At 06:42 PM 9/22/2005, Nathan Pinno wrote:

The URL is http://zoffee.tripod.com/purchasecomprogs.htm

[snip]

At your invitation I visited the site. I personally would not purchase anything listed there due to insufficient information. I don't know what I'm getting!

I suggest you dedicate a page to each program with at least one screenshot and explanation of what the program does. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050926/137d647c/attachment.html

------------------------------

_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 19, Issue 82
*************************************


		
---------------------------------
Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050926/6769b0ba/attachment.html


More information about the Tutor mailing list