From kauphlyn@speakeasy.org Sat Sep 1 00:53:13 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Fri, 31 Aug 2001 16:53:13 -0700 (PDT) Subject: [Tutor] help with web programming Message-ID: Hello Pythoneers, I am writing a script which grabs a webpage and then returns a list of a certain type of link. The each link is then appended to my main url to collect the associated pages. It works fine for the first 10 or so links and then it breaks. (The list of valid links has about 85 items in it.) Here is the script: import urllib import re sUrl = 'http://mydomain.com/' sCmd = 'cmd' sUrlcmd = sUrl+sCmd lCmds = [] tupU = urllib.urlretrieve(sUrlcmd) #get main page fTmp = open(tupU[0]) #open source file for main page sTmp = fTmp.read() lTmpHrefs = re.findall(r'href="(.*?)"', sTmp) #filter source for hrefs for item in lTmpHrefs: if item[0:3] == sCmd: lCmds.append(item) #make list of special hrefs for cmd in lCmds: tupTmp = urllib.urlretrieve(sUrl+cmd) #retrieve source of special links print tupTmp[0] #print location of source files ----------------------------------------------------- Here is the result: C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-21 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-22 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-24 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-25 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-26 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-27 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-28 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-29 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-30 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-31 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-32 C:\DOCUME~1\DANIEL~1.SEA\LOCALS~1\Temp\~1204-33 Traceback (most recent call last): File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript exec codeObject in __main__.__dict__ File "C:\daniel\test.py", line 28, in ? File "C:\Python21\lib\urllib.py", line 78, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "C:\Python21\lib\urllib.py", line 208, in retrieve fp = self.open(url, data) File "C:\Python21\lib\urllib.py", line 176, in open return getattr(self, name)(url) File "C:\Python21\lib\urllib.py", line 290, in open_http errcode, errmsg, headers = h.getreply() File "C:\Python21\lib\httplib.py", line 705, in getreply response = self._conn.getresponse() File "C:\Python21\lib\httplib.py", line 559, in getresponse response.begin() File "C:\Python21\lib\httplib.py", line 117, in begin line = self.fp.readline() File "C:\Python21\lib\socket.py", line 233, in readline new = self._sock.recv(self._rbufsize) IOError: [Errno socket error] (10054, 'Connection reset by peer') ------ Can anyone out there help me interprit this error? Any help at all will be appreciated! Thanks, Daniel From ignacio@openservices.net Sat Sep 1 00:57:37 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 31 Aug 2001 19:57:37 -0400 (EDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: On Fri, 31 Aug 2001, Daniel Coughlin wrote: > IOError: [Errno socket error] (10054, 'Connection reset by peer') That means that the other side cut you off. Reconnect and try again from where you were. -- Ignacio Vazquez-Abrams From kauphlyn@speakeasy.org Sat Sep 1 01:11:06 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Fri, 31 Aug 2001 17:11:06 -0700 (PDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: I changed the code include a function with a try-except IOError, and which also removes the already done commands from the list and it appears to do the trick! Thank You, Daniel On Fri, 31 Aug 2001, Ignacio Vazquez-Abrams wrote: > On Fri, 31 Aug 2001, Daniel Coughlin wrote: > > > IOError: [Errno socket error] (10054, 'Connection reset by peer') > > That means that the other side cut you off. Reconnect and try again from where > you were. > > -- > Ignacio Vazquez-Abrams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From ignacio@openservices.net Sat Sep 1 01:18:54 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 31 Aug 2001 20:18:54 -0400 (EDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: On Fri, 31 Aug 2001, Daniel Coughlin wrote: > I changed the code include a function with > a try-except IOError, and which also removes the already done commands from the > list and > it appears to do the trick! > > Thank You, > Daniel Maybe so, but I would narrow down the except to the specific error (10054, 'Connection reset by peer'). IOError is fairly common, and you wouldn't want to try to reconnect if the connection is rejected in the first place. -- Ignacio Vazquez-Abrams From kauphlyn@speakeasy.org Sat Sep 1 05:07:31 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Fri, 31 Aug 2001 21:07:31 -0700 (PDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: Hmmmm, it might be somekind of security setting, I suppose. I am using this script for web testing on a private network, but I will consult with my System Admistrator (knowing him it probably is a security setting) to find out more. Thanks for the tip. Daniel On Fri, 31 Aug 2001, Ignacio Vazquez-Abrams wrote: > > Maybe so, but I would narrow down the except to the specific error (10054, > 'Connection reset by peer'). IOError is fairly common, and you wouldn't want > to try to reconnect if the connection is rejected in the first place. > > -- > Ignacio Vazquez-Abrams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From ignacio@openservices.net Sat Sep 1 05:19:18 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 1 Sep 2001 00:19:18 -0400 (EDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: On Fri, 31 Aug 2001, Daniel Coughlin wrote: > Hmmmm, it might be somekind of security setting, I suppose. I am using this > script for web testing on a private network, but I will consult with my > System Admistrator (knowing him it probably is a security setting) to find out > more. Thanks for the tip. > > Daniel You misunderstood what I said (don't worry, you're about the fifth today...). What I meant was to tune your exception to catch IOError #10054 exclusively: --- try: ... except IOError: if sys.exc_info()[1].errno!=10054: raise ... --- -- Ignacio Vazquez-Abrams From smt@pacific.net.hk Sat Sep 1 05:45:47 2001 From: smt@pacific.net.hk (Kenneth Tsang) Date: Sat, 1 Sep 2001 12:45:47 +0800 Subject: [Tutor] wxPython GUI builder Message-ID: <006001c132a0$f8408a60$a800a8c0@orange> This is a multi-part message in MIME format. ------=_NextPart_000_005D_01C132E4.05FEEE10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I am looking for a tools for quick prototype building, and I am into = Python 2-3 weeks ago, which I found it totally amazing. I am now trying = to build a applications for multiple GUI platforms, speciafically = Solaris, Linux and Windows, which I found that wxPython is quite a good = choice. But one thing I would like to know is that if there is any GUI = builder out there that can speed up the development of UI? rather than = just using layout constraints and boxer? Please advice, thanks. cheers, Kenneth -- Kenneth Tsang email: smt@pacific.net.hk tel: +852 9468 4772 ------=_NextPart_000_005D_01C132E4.05FEEE10 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi, I am looking for a tools for quick = prototype=20 building, and I am into Python 2-3 weeks ago, which I found it totally = amazing.=20 I am now trying to build a applications for multiple GUI platforms,=20 speciafically Solaris, Linux and Windows, which I found that wxPython is = quite a=20 good choice. But one thing I would like to know is that if there is any = GUI=20 builder out there that can speed up the development of UI? rather than = just=20 using layout constraints and boxer? Please advice, thanks.
 
cheers, Kenneth
--
Kenneth = Tsang
email: smt@pacific.net.hk tel: +852 9468 = 4772
------=_NextPart_000_005D_01C132E4.05FEEE10-- From sheila@thinkspot.net Sat Sep 1 05:52:15 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 31 Aug 2001 21:52:15 -0700 Subject: [Tutor] wxPython GUI builder In-Reply-To: <006001c132a0$f8408a60$a800a8c0@orange> References: <006001c132a0$f8408a60$a800a8c0@orange> Message-ID: <7C5CB43530@kserver.org> On Sat, 1 Sep 2001 12:45:47 +0800, "Kenneth Tsang" wrote about [Tutor] wxPython GUI builder: :Hi, I am looking for a tools for quick prototype building, and I am into Python 2-3 weeks ago, which I found it totally amazing. I am now trying to build a applications for multiple GUI platforms, speciafically Solaris, Linux and Windows, which I found that wxPython is quite a good choice. But one thing I would like to know is that if there is any GUI builder out there that can speed up the development of UI? rather than just using layout constraints and boxer? Please advice, thanks. : :cheers, Kenneth You might try searching for Boa Constructor at SourceForge.net. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From kauphlyn@speakeasy.org Sat Sep 1 06:00:11 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Fri, 31 Aug 2001 22:00:11 -0700 (PDT) Subject: [Tutor] help with web programming In-Reply-To: Message-ID: Ha ha. I understand now! By the way, thanks for the code to fine tune the exception handling. Before now, I knew nothing about the sys module. Usually I am about as discriminating as except StandardError: yadda yadda On Sat, 1 Sep 2001, Ignacio Vazquez-Abrams wrote: > > You misunderstood what I said (don't worry, you're about the fifth today...). > > What I meant was to tune your exception to catch IOError #10054 exclusively: > > --- > try: > ... > except IOError: > if sys.exc_info()[1].errno!=10054: > raise > ... > --- > > -- > Ignacio Vazquez-Abrams > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From wmperry@swbell.net Sat Sep 1 06:32:47 2001 From: wmperry@swbell.net (William Perry) Date: Sat, 01 Sep 2001 00:32:47 -0500 Subject: [Tutor] what am I missing? Message-ID: <200109010032470650.1835B8D1@mail.swbell.net> --Boundary_(ID_P8sBd2dCsRzUVW8uFdJHiw) Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7BIT More Newby ignorance: 3 weeks and ?? different permutations of this and I just can't seem to get the widgets and the functions to play nice and share. I've been following the stdout capture thread and that may be another way to go with this but I'm thinking that understanding WHY I can't make this work might be more useful in understanding Python/Tkinter/programming for future projects. This is a stripped down trial version, search (if it worked) would take a user supplied search term and apply it to a .txt file and send the results to the display. I've got it running in a command line version but can't seem to wrap it in Tkinter. Actually, if I open the search entry widget at run time it works, I'd like to call the search from a button on the frame. I left most of the most recent failures in commented out from Tkinter import * from ScrolledText import * def doSearch(event): sTerm=StringVar() #print 'HERE' box=Toplevel() label=Label(box, text='Enter term').pack() entry=Entry(box) Button(box, text='Look For', command=search).pack() entry.pack() entry.focus() display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH) #sTerm=entry.get #search(sTerm) #print sTerm def quit(): root.quit() def search(): sTerm=StringVar() sTerm=box.entry.get() #produces attribute error as below print sTerm #root.insert(END, sTerm) ############## #lbox.insert(END, sTerm) # doesn't work #fr.lbox.insert(END, sTerm) ################ display.insert(sTerm) #pass root=Tk() fr=Frame(root) button=Button(fr) button['text']= 'Search' button.bind('', doSearch) button.pack() lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH) #root.insert(END, 'Word') # doesn't work Button(fr, text='QUIT', command=quit).pack() fr.pack() root.mainloop() Error produced when the ' Look For ' button is pressed Exception in Tkinter callback Traceback (most recent call last): File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__ return apply(self.func, args) File "C:\WINDOWS\Desktop\Programing\getdata.py", line 31, in search sTerm=box.entry.get() NameError: global name 'box' is not defined Thanks.. Bill Perry --Boundary_(ID_P8sBd2dCsRzUVW8uFdJHiw) Content-type: text/html; charset=us-ascii Content-transfer-encoding: 7BIT
More Newby ignorance:
 
3 weeks and ?? different permutations of this and I just can't seem to get the widgets and the functions to play nice and share.
I've been following the stdout capture thread and that may be another way to go with this but I'm thinking that understanding WHY I can't make this work might be more useful in understanding Python/Tkinter/programming for future projects.
 
This is a stripped down trial version, search (if it worked) would take a user supplied search term and apply it to a .txt file and send the results to the display. I've got it running in a command line version but can't seem to wrap it in Tkinter. Actually, if I open the search entry widget at run time it works, I'd like to call the search from a button on the frame. 
 
I left most of the most recent failures in commented out
 
 
 
from Tkinter import *
from ScrolledText import *
 
def doSearch(event):
    sTerm=StringVar()
    #print 'HERE'
    box=Toplevel()
   
    label=Label(box, text='Enter term').pack()
    entry=Entry(box)
    Button(box, text='Look For', command=search).pack()
    entry.pack()
    entry.focus()
    display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH)
   
   
  
    #sTerm=entry.get
    #search(sTerm)
    #print sTerm
 
def quit():
    root.quit()
 
def search():
    sTerm=StringVar()
    sTerm=box.entry.get()  #produces attribute error as below
    print sTerm
    #root.insert(END, sTerm)   ##############
    #lbox.insert(END, sTerm)   # doesn't work
    #fr.lbox.insert(END, sTerm) ################
    display.insert(sTerm)
    #pass       
   
 
 
 

root=Tk()
fr=Frame(root)
button=Button(fr)
button['text']= 'Search'
button.bind('<Button-1>', doSearch)
button.pack()
 
lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH)
#root.insert(END, 'Word') # doesn't work
Button(fr, text='QUIT', command=quit).pack()
fr.pack()
 
root.mainloop()
 
 
Error produced when the ' Look For ' button is pressed
 
Exception in Tkinter callback
Traceback (most recent call last):
  File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__
    return apply(self.func, args)
  File "C:\WINDOWS\Desktop\Programing\getdata.py", line 31, in search
    sTerm=box.entry.get()
NameError: global name 'box' is not defined

Thanks..
Bill Perry
 
 
--Boundary_(ID_P8sBd2dCsRzUVW8uFdJHiw)-- From ignacio@openservices.net Sat Sep 1 07:07:00 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 1 Sep 2001 02:07:00 -0400 (EDT) Subject: [Tutor] what am I missing? In-Reply-To: <200109010032470650.1835B8D1@mail.swbell.net> Message-ID: On Sat, 1 Sep 2001, William Perry wrote: Whoops. > from Tkinter import * > from ScrolledText import * box=None > def doSearch(event): global box > sTerm=StringVar() > #print 'HERE' > box=Toplevel() > > label=Label(box, text='Enter term').pack() > entry=Entry(box) > Button(box, text='Look For', command=search).pack() > entry.pack() > entry.focus() > display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH) > > > > #sTerm=entry.get > #search(sTerm) > #print sTerm > > def quit(): > root.quit() > > def search(): global box > sTerm=StringVar() > sTerm=box.entry.get() #produces attribute error as below > print sTerm > #root.insert(END, sTerm) ############## > #lbox.insert(END, sTerm) # doesn't work > #fr.lbox.insert(END, sTerm) ################ > display.insert(sTerm) > #pass > > > > > > root=Tk() > fr=Frame(root) > button=Button(fr) > button['text']= 'Search' > button.bind('', doSearch) > button.pack() > > lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH) > #root.insert(END, 'Word') # doesn't work > Button(fr, text='QUIT', command=quit).pack() > fr.pack() > > root.mainloop() > > > Error produced when the ' Look For ' button is pressed > > Exception in Tkinter callback > Traceback (most recent call last): > File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__ > return apply(self.func, args) > File "C:\WINDOWS\Desktop\Programing\getdata.py", line 31, in search > sTerm=box.entry.get() > NameError: global name 'box' is not defined > > > Thanks.. > Bill Perry > > -- Ignacio Vazquez-Abrams From sheila@thinkspot.net Sat Sep 1 07:27:16 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 31 Aug 2001 23:27:16 -0700 Subject: [Tutor] what am I missing? In-Reply-To: References: <200109010032470650.1835B8D1@mail.swbell.net> Message-ID: I really don't know as I care for just throwing in a "global" everywhere, to solve this scoping problem. Sometimes you can't do it any other way, but this one could be solved in other ways (it seems to me). To William: The problem you were having with the error message about the "global box", was that your code first mentions this statement: box = Toplevel() inside the doSearch function. Because you mention it inside that function, then (barring use of the "global" keyword), the other parts of your code can't see it. They can't see inside of the other functions to see what they are doing. So when your search() function tries to do something to the "box", it gets confused, because it doesn't know where it came from. Putting the phrase "global box" in there, tells the function to look outside itself, to a "box" object that all parts of the program are allowed to access. Ignacio has shown you one possible solution. By declaring the identifier "box" to be a global, this means ALL parts of your code have access to it and can see it. Other possibilities: Declare the box inside your main code, but create it hidden, and pass it as a parameter to the functions. OR: Write a class, that is a box object, that subclasses a Toplevel, and give it its own "search" method functions. The book Programming Python shows a lot about how to effectively use classes with Tkinter objects and subclass them. I've found it to be a really neat approach to the problem. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Sat, 1 Sep 2001 02:07:00 -0400 (EDT), Ignacio Vazquez-Abrams wrote about Re: [Tutor] what am I missing?: :On Sat, 1 Sep 2001, William Perry wrote: : :Whoops. : :> from Tkinter import * :> from ScrolledText import * : :box=None : :> def doSearch(event): : : global box : :> sTerm=StringVar() :> #print 'HERE' :> box=Toplevel() :> :> label=Label(box, text='Enter term').pack() :> entry=Entry(box) :> Button(box, text='Look For', command=search).pack() :> entry.pack() :> entry.focus() :> display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH) :> :> :> :> #sTerm=entry.get :> #search(sTerm) :> #print sTerm :> :> def quit(): :> root.quit() :> :> def search(): : : global box : :> sTerm=StringVar() :> sTerm=box.entry.get() #produces attribute error as below :> print sTerm :> #root.insert(END, sTerm) ############## :> #lbox.insert(END, sTerm) # doesn't work :> #fr.lbox.insert(END, sTerm) ################ :> display.insert(sTerm) :> #pass :> :> :> :> :> :> root=Tk() :> fr=Frame(root) :> button=Button(fr) :> button['text']= 'Search' :> button.bind('', doSearch) :> button.pack() :> :> lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH) :> #root.insert(END, 'Word') # doesn't work :> Button(fr, text='QUIT', command=quit).pack() :> fr.pack() :> :> root.mainloop() :> :> :> Error produced when the ' Look For ' button is pressed :> :> Exception in Tkinter callback :> Traceback (most recent call last): :> File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__ :> return apply(self.func, args) :> File "C:\WINDOWS\Desktop\Programing\getdata.py", line 31, in search :> sTerm=box.entry.get() :> NameError: global name 'box' is not defined :> :> :> Thanks.. :> Bill Perry :> :> From dyoo@hkn.eecs.berkeley.edu Sat Sep 1 10:24:19 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 1 Sep 2001 02:24:19 -0700 (PDT) Subject: [Tutor] Re: Pythonica (symbolic algebra) In-Reply-To: Message-ID: On Thu, 30 Aug 2001, Joseph J. Strout wrote: > At 1:42 PM -0500 8/30/01, Christopher Smith wrote: > > >It looks like you had made some significant progress > >on Python and provided some useful tools (I am using > >the patched editor, for example). Thank you. > > Quite happy to have contributed; Python is great (as is the community). > > >Do you have a list of errors that have been reported for Pythonica? > > Sorry, I don't. > > >I passed along your comments to the tutor and mac lists. Hello! Have you had a chance to look at: http://hkn.eecs.berkeley.edu/~dyoo/python/pythonica/ I've been playing around with the Pythonica code, mostly to learn how to use the Spark parser generator tools. I think the parser bug with "2*3+2^2/3" is fixed, although I'm sure I've introduced new bugs everywhere... *grin* I'd like to get your input on the changes I've made; do they look ok? From dsh8290@rit.edu Sat Sep 1 14:15:57 2001 From: dsh8290@rit.edu (dman) Date: Sat, 1 Sep 2001 09:15:57 -0400 Subject: [Tutor] wxPython GUI builder In-Reply-To: <006001c132a0$f8408a60$a800a8c0@orange>; from smt@pacific.net.hk on Sat, Sep 01, 2001 at 12:45:47PM +0800 References: <006001c132a0$f8408a60$a800a8c0@orange> Message-ID: <20010901091557.G13154@harmony.cs.rit.edu> On Sat, Sep 01, 2001 at 12:45:47PM +0800, Kenneth Tsang wrote: [ want RAD GUI builder for cross-platform deployment ] For wxPython ther is Boa Constructor (free) or wxDesigner (demo is free, small fee for registered version). For GTK+ (PyGTK) there is glade, and the accompanying 'libglade' library. wxPython looks pretty good and will give you close to native LnF in the end result. I really like PyGTK and find it easy to get things to look right. The neat thing about using a glade/libglade combo is you don't actually generate any code -- the GUI is built dynamically at runtime from the glade project file. You can even change the arrangement of stuff without rebuilding the code (more significant with compiled languages like C or C++). (BTW gtk, pygtk, glade, and libglade have all been ported to windows.) HTH, -D From alan.gauld@bt.com Sat Sep 1 14:59:17 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 14:59:17 +0100 Subject: [OT] BASIC Factoid (was Re: [Tutor] Functions !) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BEFE@mbtlipnt02.btlabs.bt.co.uk> > > From: Bruce Sass [SMTP:bsass@freenet.edmonton.ab.ca] > > 2K on the ZX81, unless you bought one of the RAM expanders > (16, 32 and 64k sizes). > > It was *definitely* only 1K on mine. I ended up getting a 16K > Ram pack, but if I typed too hard, it would wobble, > and the ZX81 would crash. I believe the export version(Timex) did have 2K RAM but the original only had 1K. The RAM packs became available about 6 months- 1 year later (Jan 1982?) in 4K and 16K versions. I've never heard of 32K or 64K versions but it wouldn't surprise me. By 1984 I had moved to an AMSTRAD PCW8256 running CP/M Plus - ah the joys of MASM, DR Pascal and Logo, real computing at last! ;-) Alan G From alan.gauld@bt.com Sat Sep 1 15:05:31 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 15:05:31 +0100 Subject: [Tutor] Did someone ask me a question? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BEFF@mbtlipnt02.btlabs.bt.co.uk> Someone sent me mail last week from my web tutor asking for some help with a project. Unfortunaely it got deleted by mistake in the middle of a mail storm. All I recall is it involved reading passwords. If you are out there please resend the mail, I did mean to reply honest... Alan Gauld BT computing partners Tel : 0141 220 8795 Fax : 0141 248 1284 From alan.gauld@bt.com Sat Sep 1 15:30:45 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 15:30:45 +0100 Subject: [Tutor] Why I'm learning Python (OT and long) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF00@mbtlipnt02.btlabs.bt.co.uk> > wondered how do people learn all this stuff about how the operating > systems work, and file locking and sockets and servers and ... Gradually ;-) Seriously you learn it as you need it. Although my Elect Eng degree included intro programming which included file handling and dynamic data structures and some program design and validation. I also did a course on Assembler programming which included stuff on serial comms and I/O details. Then my final year project required some networking stuff and also included a course on OS design - so threading, scheduling, and yes, file locking. Then I left college and my first project was a multi processor PBX using a real time OS and designed using state machines. My next project had a big database under it so I had to learn SQL. I moved onto a billing project and came across COBOL and the joys of batch processing. You get the idea? Its taken a long combination of school and many projects. And still I feel like a "Jack of all trades but a master of none"! And things like crypto and hard core graphics programming are still on my "must take time to learn" list... One of the great things about the IT industry is you never really "know it all" and even when you think you might be getting close along comes something like the Web to add a whole new dimension! Accept that you'll never know it all and just enjoy the learning experience. It makes for an easier life! Alan G From alan.gauld@bt.com Sat Sep 1 15:58:04 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 15:58:04 +0100 Subject: [Tutor] Why I'm learning Python (OT and long) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF02@mbtlipnt02.btlabs.bt.co.uk> > > Here's some code I was looking at today that I COMPLETELY DON'T GET: > > Don't worry too much about it --- neither does the author. > > """ There are actually two versions of crypt() out there. The > older one uses DES encryption, and the newer one uses an MD5 I once spent a short project building a hardware encryption board to go in a PC. The chip implemented an alternative to DES (which can't be used in the UK except for Finance or Defense) and I was privvy to the code and the DES algorithms(which are public). It was some f the most convoluted, self referential, highly recursive code I've ever seen. It put me of crypto stuff for years! Its only in the last 2 years when I've gotten dragged into IT Security issues at work that I've dared to start considering looking at that stuff again! For now I use the libraries that other folks write and just trust them to get it right... Alan g From alan.gauld@bt.com Sat Sep 1 17:02:24 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 17:02:24 +0100 Subject: [Tutor] Re: How to change Windows Environment Variable Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF03@mbtlipnt02.btlabs.bt.co.uk> > > How to change environment variable on Windows NT or 2000 by python? > > Private Declare Function SetEnvironmentVariable Lib "kernel32" _ > > Alias "SetEnvironmentVariableA" (ByVal lpName As String, _ > > ByVal lpValue As String) As Long The SetEnvronmentVariable function only changes the value *in the current process*. Thus is a fairly pointless function. You might as well just set a global variable! This is true in most OSs in that the program gets a copy of the environment which it holds in memory, thus changing the value only affects the local program. Howeever on Windows some of the API functions use env var settings so it does make sense(very occasionally) to change the local copy. Maybe because its usually a bad idea Python doesn't offer a function to do it. But just maybe, the return value of the get versuion is a pointer to the actual memory space instead of a copy - in which case you can try modifying it - but beware of overwriting an adjacent value... In short, be very sure you need to do this. If so then proceed with caution. If you really do want it then as Ignacio says writing your own as part of win32api might be the best route. Alan G. From alan.gauld@bt.com Sat Sep 1 17:55:49 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 1 Sep 2001 17:55:49 +0100 Subject: [Tutor] what am I missing? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF04@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C13306.F3731370 Content-type: text/plain; charset="ISO-8859-1" from Tkinter import * from ScrolledText import * def doSearch(event): sTerm=StringVar() This is never used , might as well delete it! box=Toplevel() You define box here, inside doSearch, so its not visible anywhere else in the program. IMHO you are better to create your GUI el;ements either as members of a class or, if your not happy with OO yet as global variables - ie outside of any function. label=Label(box, text='Enter term').pack() entry=Entry(box) Button(box, text='Look For', command=search).pack() entry.pack() entry.focus() display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH) def quit(): root.quit() def search(): sTerm=StringVar() Not sure why you are using StrinGVar() here, you don't seem to use the 'magical' properties of StringVar, so a normal string would suffice... sTerm=box.entry.get() #produces attribute error as below especially since you now replace the StringVar with a string - or you would if your function could see box. display.insert(sTerm) Similarly this won't work coz display is a name only known to the doSearch function. Your problems are not really to do with Tlinter but with your understanding of Pythons naming rules. Try looking at my chapter on namespaces to see if that helps: http://www.crosswinds.net/~agauld /tutname.htm root=Tk() fr=Frame(root) button=Button(fr) button['text']= 'Search' button.bind('', doSearch) button.pack() Why not just: Button(fr, text='Search', command=doSearch).pack() As you do below...? lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH) #root.insert(END, 'Word') # doesn't work Button(fr, text='QUIT', command=quit).pack() fr.pack() root.mainloop() So what the program does is create a window with 2 buttons and a text area. When you press the Sarch button it creates a dialog with a label, entry, text area and button. When you hit the dialog button it calls search which has no knowledge of the dialog you created only the original window(which is global in scope. But Search tries to read the value in the dialog. You either need to pass the entry and display widgets to the search fnction or make them globally available. HTH, Alan G ------_=_NextPart_001_01C13306.F3731370 Content-type: text/html; charset="ISO-8859-1"
from Tkinter import *
from ScrolledText import *
 
def doSearch(event):
    sTerm=StringVar() 
This is never used , might as well delete it!

    box=Toplevel()
     
You define box here, inside doSearch, so its not visible
anywhere else in the program. IMHO you are better to
create your GUI el;ements either as members of a class or,
if your not happy with OO yet as global variables
- ie outside of any function.
 
    label=Label(box, text='Enter term').pack()
    entry=Entry(box)
    Button(box, text='Look For', command=search).pack() 
    entry.pack()
    entry.focus()
    display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH)
   
def quit():
    root.quit()
def search():
    sTerm=StringVar() 
Not sure why you are using StrinGVar() here, you don't
seem to use the 'magical' properties of StringVar,
so a normal string would suffice...

    sTerm=box.entry.get()  #produces attribute error as below 
 
especially since you now replace the StringVar with a string
- or you would if your function could see box.
 
    display.insert(sTerm)
Similarly this won't work coz display is a name only known
to the doSearch function. 
 
Your problems are not really to do with Tlinter but with your understanding of Pythons naming rules. Try looking at my chapter on namespaces to see if that helps:
 
 
 root=Tk()
fr=Frame(root)
button=Button(fr)
button['text']= 'Search'
button.bind('<Button-1>', doSearch)
button.pack()
 
Why not just:
 
Button(fr, text='Search', command=doSearch).pack()
 
As you do below...?
 
lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH)
#root.insert(END, 'Word') # doesn't work
Button(fr, text='QUIT', command=quit).pack()
fr.pack()
 
root.mainloop()
 
So what the program does is create a window with 2 buttons and
a text area. When you press the Sarch button it creates a dialog
with a label, entry, text area and button.
 
When you hit the dialog button it calls search which has no
knowledge of the dialog you created only the original
window(which is global in scope. But Search tries to
read the value in the dialog. You either need to pass the
entry and display widgets to the search fnction or make
them globally available.
 
HTH,
 
Alan G
------_=_NextPart_001_01C13306.F3731370-- From dsh8290@rit.edu Sat Sep 1 21:26:33 2001 From: dsh8290@rit.edu (dman) Date: Sat, 1 Sep 2001 16:26:33 -0400 Subject: [Tutor] Re: How to change Windows Environment Variable In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF03@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Sat, Sep 01, 2001 at 05:02:24PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF03@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010901162633.D13398@harmony.cs.rit.edu> On Sat, Sep 01, 2001 at 05:02:24PM +0100, alan.gauld@bt.com wrote: | > > How to change environment variable on Windows NT or 2000 by python? | > > Private Declare Function SetEnvironmentVariable Lib "kernel32" _ | > > Alias "SetEnvironmentVariableA" (ByVal lpName As String, _ | > > ByVal lpValue As String) As Long | | The SetEnvronmentVariable function only changes the value | *in the current process*. Thus is a fairly pointless function. | You might as well just set a global variable! True, unless for some reason you need to tweak the environment. Maybe you are embedding a 3rd party app/lib that checks the environment for config stuff. | Maybe because its usually a bad idea Python doesn't offer a | function to do it. But just maybe, the return value of the get See os.putenv(). | versuion is a pointer to the actual memory space instead of a | copy - in which case you can try modifying it - but beware of | overwriting an adjacent value... Python strings are immutable and the os.environment dictionary is just a python view of the environment. Changing may or may not (probably not) have the desired effect. HTH, -D From wmperry@swbell.net Sat Sep 1 23:31:58 2001 From: wmperry@swbell.net (William Perry) Date: Sat, 01 Sep 2001 17:31:58 -0500 Subject: [Tutor] what am I missing? In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF04@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF04@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <200109011731580230.018977E3@mail.swbell.net> --Boundary_(ID_Yr8NzmNZIMaKfOzSFSgd/g) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT I was treating StringVar() as if it were a global. over the couse of repeated attempts to get this working i stuck it several places in an effort to see if/how it worked. The problem as i understood it was a namespace issue preventing the thing from working. I have the search as a class as well. (weak OOP but i'm trying) so I'm sucessful on calling the class method from the root button now. I need to send or capture the output to the display. it's printing to the stdout window I'm just one of those folks that has to USE it to understand it (I did BTW work your tutorial early on and it was quite helpful. Maybe a re-read is in order?) *********** REPLY SEPARATOR *********** On 9/1/01 at 5:55 PM alan.gauld@bt.com wrote: from Tkinter import * from ScrolledText import * def doSearch(event): sTerm=StringVar() This is never used , might as well delete it! box=Toplevel() You define box here, inside doSearch, so its not visible anywhere else in the program. IMHO you are better to create your GUI el;ements either as members of a class or, if your not happy with OO yet as global variables - ie outside of any function. label=Label(box, text='Enter term').pack() entry=Entry(box) Button(box, text='Look For', command=search).pack() entry.pack() entry.focus() display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH) def quit(): root.quit() def search(): sTerm=StringVar() Not sure why you are using StrinGVar() here, you don't seem to use the 'magical' properties of StringVar, so a normal string would suffice... sTerm=box.entry.get() #produces attribute error as below especially since you now replace the StringVar with a string - or you would if your function could see box. display.insert(sTerm) Similarly this won't work coz display is a name only known to the doSearch function. Your problems are not really to do with Tlinter but with your understanding of Pythons naming rules. Try looking at my chapter on namespaces to see if that helps: http://www.crosswinds.net/~agauld/tutname.htm I'll look at it, all help is apprecated root=Tk() fr=Frame(root) button=Button(fr) button['text']= 'Search' button.bind('', doSearch) button.pack() Why not just: Button(fr, text='Search', command=doSearch).pack() As you do below...? Teach Yourself Python 24 uses the above method, Programming Python the below. I tried several books to get an understanding. Depending on where I was looking it's inconsistant. I plan to clean it up when it works. lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH) #root.insert(END, 'Word') # doesn't work Button(fr, text='QUIT', command=quit).pack() fr.pack() root.mainloop() So what the program does is create a window with 2 buttons and a text area. When you press the Sarch button it creates a dialog with a label, entry, text area and button. When you hit the dialog button it calls search which has no knowledge of the dialog you created only the original window(which is global in scope. But Search tries to read the value in the dialog. You either need to pass the entry and display widgets to the search fnction or make them globally available. HTH, Alan G --Boundary_(ID_Yr8NzmNZIMaKfOzSFSgd/g) Content-type: text/html; charset=us-ascii Content-transfer-encoding: 7BIT
I was treating StringVar() as if it were a global. over the couse of repeated attempts to get this working i stuck it several places in an effort to see if/how it worked. The problem as  i understood it was a namespace issue preventing the thing from working. I have the search as a class as well. (weak OOP but i'm trying) so I'm sucessful on calling the class method from the root button now. I need to send or capture the output to the display. it's printing to the stdout window 
 
I'm just one of those folks that has to USE it to understand it (I did BTW work your tutorial early on and it was quite helpful. Maybe a re-read is in order?)
 
 

*********** REPLY SEPARATOR ***********

On 9/1/01 at 5:55 PM alan.gauld@bt.com wrote:
from Tkinter import *
from ScrolledText import *
 
def doSearch(event):
    sTerm=StringVar() This is never used , might as well delete it!

    box=Toplevel()
     
You define box here, inside doSearch, so its not visible
anywhere else in the program. IMHO you are better to
create your GUI el;ements either as members of a class or,
if your not happy with OO yet as global variables
- ie outside of any function.
 
    label=Label(box, text='Enter term').pack()
    entry=Entry(box)
    Button(box, text='Look For', command=search).pack() 
    entry.pack()
    entry.focus()
    display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH)
   
def quit():
    root.quit()
def search():
    sTerm=StringVar() 
Not sure why you are using StrinGVar() here, you don't
seem to use the 'magical' properties of StringVar,
so a normal string would suffice...

    sTerm=box.entry.get()  #produces attribute error as below 
 
especially since you now replace the StringVar with a string
- or you would if your function could see box.

    display.insert(sTerm)
Similarly this won't work coz display is a name only known
to the doSearch function. 
 
Your problems are not really to do with Tlinter but with your understanding of Pythons naming rules. Try looking at my chapter on namespaces to see if that helps:
 
http://www.crosswinds.net/~agauld/tutname.htm  I'll look at it, all help is apprecated
 
 root=Tk()
fr=Frame(root)
button=Button(fr)
button['text']= 'Search'
button.bind('<Button-1>', doSearch)
button.pack()
 
Why not just:
 
Button(fr, text='Search', command=doSearch).pack()
 
As you do below...?
 
Teach Yourself Python 24 uses the above method, Programming Python the below. I tried several books to get an understanding. Depending on where I was looking it's inconsistant. I plan to clean it up when it works.
 
lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH)
#root.insert(END, 'Word') # doesn't work
Button(fr, text='QUIT', command=quit).pack()
fr.pack()
 
root.mainloop()
 
So what the program does is create a window with 2 buttons and
a text area. When you press the Sarch button it creates a dialog
with a label, entry, text area and button.
 
When you hit the dialog button it calls search which has no
knowledge of the dialog you created only the original
window(which is global in scope. But Search tries to
read the value in the dialog. You either need to pass the
entry and display widgets to the search fnction or make
them globally available.
 
HTH,
 
Alan G
--Boundary_(ID_Yr8NzmNZIMaKfOzSFSgd/g)-- From dyoo@hkn.eecs.berkeley.edu Sun Sep 2 07:24:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 1 Sep 2001 23:24:33 -0700 (PDT) Subject: [Tutor] Why I'm learning Python (OT and long) In-Reply-To: <20010831120115.H10562@harmony.cs.rit.edu> Message-ID: On Fri, 31 Aug 2001, dman wrote: > On Thu, Aug 30, 2001 at 10:27:42AM -0400, Bill Tolbert wrote: > | I spent some time reading Useless Python last night and went to bed > | totally depressed. I feel that even Useless is above my skill level. So, > | what follows is the story of why I'm trying to learn Python. Perhaps some > | will understand; some may be in a similar situation; some may want to send > | me money. Maybe it can become an installment for the soapbox on Useless. > [...] > > As Javier said, you learn it little by little. You read docs, you > experiement, and practice and you end up knowing the stuff that is > interesting to you. None of us know everything. In fact, computers > and software are so complex nowadays that nobody can ever know > everything about any given system, and certainly not everything about > all (or even several) systems. Also, source code can be somewhat deceptive: it's like a distillation of hours of research, hapless experimentation, wrong turns, and uninformed misdirection, all into a dense, syrupy concoction. What we end up is something short and sweet, but it can mask the roundabout way we cooked it. And if swallowed too quickly, we can gag! This same sort of dilation happens with math proofs, books, emails, or anything else written down. I guess I'm trying to say: don't worry if you read something that doesn't make sense initially: take it slow, one sip at a time. It takes some time to sample new things. Now if only I could properly use a Bodum plunger coffee machine, I'll be very happy. *grin* From kev@sat.net Sun Sep 2 12:58:18 2001 From: kev@sat.net (Kevin McCormick) Date: Sun, 02 Sep 2001 06:58:18 -0500 Subject: [Tutor] wxPython GUI builder References: <006001c132a0$f8408a60$a800a8c0@orange> <20010901091557.G13154@harmony.cs.rit.edu> Message-ID: <3B921EDA.95AE81@sat.net> dman wrote: > > On Sat, Sep 01, 2001 at 12:45:47PM +0800, Kenneth Tsang wrote: > > [ want RAD GUI builder for cross-platform deployment ] > > For wxPython ther is Boa Constructor (free) or wxDesigner (demo is > free, small fee for registered version). > > For GTK+ (PyGTK) there is glade, and the accompanying 'libglade' > library. > > wxPython looks pretty good and will give you close to native LnF in > the end result. I really like PyGTK and find it easy to get things to > look right. The neat thing about using a glade/libglade combo is you > don't actually generate any code -- the GUI is built dynamically at > runtime from the glade project file. You can even change the > arrangement of stuff without rebuilding the code (more significant > with compiled languages like C or C++). (BTW gtk, pygtk, glade, and > libglade have all been ported to windows.) > > HTH, > -D > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor On the subject of PyGTK and Glade, I am a complete newbie. I have been trying some things with Tkinter, but GTK apps are definitely more slick looking and I would like to get started with that. However, I have always had trouble getting things like that set up (I have BlackAdder beta, but have never taken the time to figure it out). I really don't know where to begin or even how to load the component libraries. I use Linux Mandrake 7.2 (waiting for 8.1) with Python 2.0. Would some users of PyGTK talk about their setup and sources of help for beginners? From ajaya@ncoretech.com Sun Sep 2 15:32:15 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Sun, 2 Sep 2001 20:02:15 +0530 Subject: [Tutor] How to install Pmw for python Tkinter programming Message-ID: <000101c133bc$10add320$6501a8c0@ncoretech.com> Hi, I am just learning Tkinter programming. I came across some book wich is using Pmw. But when I try to import Pmw python is giving exception like this Traceback (innermost last): File "", line 1, in ? import Pmw ImportError: No module named Pmw I've downloaded python2.0 version from www.python.org. I am using in windows NT system. Please give me some idea what need to install to get Pmw module. another question is book is telling me that there is extensive documentation. From where I could get this. Thanks and Regards, Ajaya From ski100mph@hotmail.com Sun Sep 2 15:33:51 2001 From: ski100mph@hotmail.com (David de-Beger) Date: Sun, 2 Sep 2001 15:33:51 +0100 Subject: [Tutor] (no subject) Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0017_01C133C4.AB30E740 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ------=_NextPart_000_0017_01C133C4.AB30E740 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
------=_NextPart_000_0017_01C133C4.AB30E740-- From sheila@thinkspot.net Sun Sep 2 17:01:15 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 02 Sep 2001 09:01:15 -0700 Subject: [Tutor] How to install Pmw for python Tkinter programming In-Reply-To: <000101c133bc$10add320$6501a8c0@ncoretech.com> References: <000101c133bc$10add320$6501a8c0@ncoretech.com> Message-ID: <806720D286D@kserver.org> On Sun, 2 Sep 2001 20:02:15 +0530, "Ajaya Babu" wrote about [Tutor] How to install Pmw for python Tkinter programming: : Please give me some idea what need to install to get Pmw module. : :another question is book is telling me that there is extensive :documentation. From where I could get this. go here: http://pmw.sourceforge.net/ download the files and follow the directions in the distribution for installation. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From urnerk@qwest.net Sun Sep 2 14:04:08 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 2 Sep 2001 09:04:08 -0400 Subject: [Tutor] How to install Pmw for python Tkinter programming In-Reply-To: <000101c133bc$10add320$6501a8c0@ncoretech.com> References: <000101c133bc$10add320$6501a8c0@ncoretech.com> Message-ID: <01090209040801.04129@ktu> > I've downloaded python2.0 version from www.python.org. I am using in > windows NT system. Please give me some idea what need to install to get Pmw > module. > http://pmw.sourceforge.net/ Both module and docs. Kirby From dyoo@hkn.eecs.berkeley.edu Sun Sep 2 20:38:01 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 2 Sep 2001 12:38:01 -0700 (PDT) Subject: [Tutor] How to install Pmw for python Tkinter programming In-Reply-To: <000101c133bc$10add320$6501a8c0@ncoretech.com> Message-ID: On Sun, 2 Sep 2001, Ajaya Babu wrote: > I am just learning Tkinter programming. I came across some book wich > is using Pmw. But when I try to import Pmw python is giving exception Ah, are you talking about "Python and Tkinter Programming", by John Grayson? If so, be aware that that book does go a bit fast, so please feel free to ask us questions if the going goes rough. > Traceback (innermost last): > File "", line 1, in ? > import Pmw > ImportError: No module named Pmw Python Megawidgets (Pmw) is an addon to Tkinter --- it provides more widgets to play with, and Grayson uses them a lot in his book. You can download Pmw from the Pmw website here: http://pmw.sourceforge.net You should be able to use Winzip to unzip the files into C:\Program Files\Python\Pmw and that should do it. > another question is book is telling me that there is extensive > documentation. From where I could get this. Do you mean documentation on Pmw, or documentation overall about Python? Good luck to you! From dyoo@hkn.eecs.berkeley.edu Sun Sep 2 23:50:59 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 2 Sep 2001 15:50:59 -0700 (PDT) Subject: [Tutor] wxPython GUI builder In-Reply-To: <3B921EDA.95AE81@sat.net> Message-ID: On Sun, 2 Sep 2001, Kevin McCormick wrote: > On the subject of PyGTK and Glade, I am a complete newbie. I have > been trying some things with Tkinter, but GTK apps are definitely more > slick looking and I would like to get started with that. However, I > have always had trouble getting things like that set up (I have > BlackAdder beta, but have never taken the time to figure it out). I > really don't know where to begin or even how to load the component > libraries. I use Linux Mandrake 7.2 (waiting for 8.1) with Python > 2.0. > > Would some users of PyGTK talk about their setup and sources of help > for beginners? Deirdre wrote a "Ten Minutes Total Idiots Guide to Using Gnome/Gtk+ & Glade with Python." http://www.baypiggies.org/10mintig.html (As of this writing, I wasn't able to connect to baypiggies.org though... *sob*) Not quite sure about the title, but the content is very good. Here are links to other introductions: http://linuxfocus.org/English/July2000/article160.shtml http://laguna.fmedic.unam.mx/~daniel/pygtutorial/pygtutorial/ I'm very excited to hear that they've ported PyGtk and Glade to Windows. Can anyone point out where to look for this? Is it fairly stable? From sullivan@fotoasia.com Sun Sep 2 15:11:43 2001 From: sullivan@fotoasia.com (FotoAsia) Date: Sun, 02 Sep 2001 14:11:43 GMT Subject: [Tutor] Something to brighten your day! Message-ID: <99943890803@202.157.153.2> FotoAsia Newsletter 2001 September
=09This is a HTML document=2E If you are unable to view this page,= copy this link http://www=2Efotoasia=2Ecom/email/HTML/newsletter/ne= wsletter_200109=2Ehtml
=09into your web browser to view our complete range of= Inspirational Posters=2E
=09=09 =09=09 =09=09 =09=09 =09 =09 =09=09 =09=09 =09=09 =09 =09 =09=09 =09=09 =09 =09 =09=09 =09 =09 =09 =09 =09 =09 =09 =09=09 =09 =09 =09=09 =09=09 =09 =09 =09 =09 =09 =09 =09=09 =09 =09 =09=09 =09
=09=09=09 =09=09=09 =09=09=09 =09=09=09
  =09
 
From dsh8290@rit.edu Mon Sep 3 03:23:53 2001 From: dsh8290@rit.edu (dman) Date: Sun, 2 Sep 2001 22:23:53 -0400 Subject: [Tutor] wxPython GUI builder In-Reply-To: <3B921EDA.95AE81@sat.net>; from kev@sat.net on Sun, Sep 02, 2001 at 06:58:18AM -0500 References: <006001c132a0$f8408a60$a800a8c0@orange> <20010901091557.G13154@harmony.cs.rit.edu> <3B921EDA.95AE81@sat.net> Message-ID: <20010902222353.A14093@harmony.cs.rit.edu> On Sun, Sep 02, 2001 at 06:58:18AM -0500, Kevin McCormick wrote: | dman wrote: [..] | > For GTK+ (PyGTK) there is glade, and the accompanying 'libglade' | > library. | On the subject of PyGTK and Glade, I am a complete newbie. I have been | trying some things with Tkinter, but GTK apps are definitely more slick | looking and I would like to get started with that. However, I have | always had trouble getting things like that set up (I have BlackAdder | beta, but have never taken the time to figure it out). I really don't | know where to begin or even how to load the component libraries. I use | Linux Mandrake 7.2 (waiting for 8.1) with Python 2.0. Oh, good, I was afraid you were about to say you were using windows. I haven't actually used pygtk on windows, but I know that binaries exist. Frequently setting up stuff on windows is much harder than unices. | Would some users of PyGTK talk about their setup and sources of help for | beginners? When I was using RH I simply installed the RPMs. Now that I am using Debian I simply use apt-get to download and install the necessary DEBs. Could you give an example of what you are trying to do and why it doesn't work? If I get some spare time soon, then I could refresh myself on the GTK+ API and give you a "hello world" program that should work. On my system I can 'import gtk' and 'window = gtk.GtkWindow() ; window.show()" (but I don't remember how to make it actually visible -- I probably need to put something in it and make it bigger than 0x0) -D From dsh8290@rit.edu Mon Sep 3 03:25:43 2001 From: dsh8290@rit.edu (dman) Date: Sun, 2 Sep 2001 22:25:43 -0400 Subject: [Tutor] wxPython GUI builder In-Reply-To: ; from dyoo@hkn.eecs.berkeley.edu on Sun, Sep 02, 2001 at 03:50:59PM -0700 References: <3B921EDA.95AE81@sat.net> Message-ID: <20010902222542.B14093@harmony.cs.rit.edu> On Sun, Sep 02, 2001 at 03:50:59PM -0700, Danny Yoo wrote: | I'm very excited to hear that they've ported PyGtk and Glade to Windows. | Can anyone point out where to look for this? Is it fairly stable? It's stable enough to run the GIMP with. The GIMP crashes sometimes, but really works very well (unless you have a certain version of MS's mouse driver on an NT system -- then no plugins (or script-fu) will work). For Glib/GTK+ for windows see the GimpWin page http://www.gimp.org/~tml/gimp/win32/ for PyGTK and Glade and related stuff see http://hans.breuer.org/ports/default.htm Enjoy :-). -D From ajaya@ncoretech.com Mon Sep 3 06:52:38 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Mon, 3 Sep 2001 11:22:38 +0530 Subject: [Tutor] How to install Pmw for python Tkinter programming In-Reply-To: Message-ID: <000001c1343c$a4373c50$6501a8c0@ncoretech.com> Thanks for all your help, :Ah, are you talking about "Python and Tkinter Programming", by John :Grayson? If so, be aware that that book does go a bit fast, so please :feel free to ask us questions if the going goes rough. exactly..., Ya this book is fast.. :Python Megawidgets (Pmw) is an addon to Tkinter --- it provides more :widgets to play with, and Grayson uses them a lot in his book. You can :download Pmw from the Pmw website here: : http://pmw.sourceforge.net :You should be able to use Winzip to unzip the files into : C:\Program Files\Python\Pmw :and that should do it. Thanks allot I am able to fix this problem. Now I am able to use Pmw. :Do you mean documentation on Pmw, or documentation overall about Python? I've python documentation. I was asking Pmw documentation. I got in the link that you specified. Good luck to you! Thanks and Regards, Ajaya Babu From lonetwin@yahoo.com Mon Sep 3 08:28:15 2001 From: lonetwin@yahoo.com (lonetwin) Date: Mon, 3 Sep 2001 00:28:15 -0700 (PDT) Subject: [Tutor] mail server stress Message-ID: <20010903072815.9798.qmail@web20704.mail.yahoo.com> Hi all you good people, One quick question, does anyone know about a mail server stress/load test application/module written in python ?? This seems like just the thing that is likely to be written in python, well if there isn't any helpful tips/comments on what I should be thinking if I decide to write something of my own ??? Peace Steve __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com From ajaya@ncoretech.com Mon Sep 3 08:26:48 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Mon, 3 Sep 2001 12:56:48 +0530 Subject: [Tutor] What **something means in Python! Message-ID: <000601c13449$cc04ad00$6501a8c0@ncoretech.com> Hi All, I am sutdying Python and Tkinter programming by Grayson. I came across this fraction of code class Key(Button): def __init__(self, master, font=('arial', 8, 'bold'), fg='white',width=5, borderwidth=5, **kw): kw['font'] = font kw['fg'] = fg kw['width'] = width kw['borderwidth'] = borderwidth apply(Button.__init__, (self, master), kw) self.pack(side=LEFT, expand=NO, fill=NONE) Here I understand Key in inherited the properties of the Button. But I've doubt on the argument **k I really not able to understand this. What that ** represent. Secondly I understand he is passing that kw as a dictionary to the apply function. But I confused with **. can any one give comments on this. Thanks and Regards, Ajaya Babu From hnowak@cuci.nl Mon Sep 3 09:20:15 2001 From: hnowak@cuci.nl (Hans Nowak) Date: Mon, 3 Sep 2001 10:20:15 +0200 Subject: [Tutor] What **something means in Python! Message-ID: <3B95971F@twigger.nl> >===== Original Message From "Ajaya Babu" ===== >Hi All, > >I am sutdying Python and Tkinter programming by Grayson. I came across this >fraction of code > >class Key(Button): > def __init__(self, master, font=('arial', 8, 'bold'), > fg='white',width=5, borderwidth=5, **kw): > kw['font'] = font > kw['fg'] = fg > kw['width'] = width > kw['borderwidth'] = borderwidth > apply(Button.__init__, (self, master), kw) > self.pack(side=LEFT, expand=NO, fill=NONE) > >Here I understand Key in inherited the properties of the Button. But I've >doubt on the argument **k I really not able to understand this. What that ** >represent. It's a so-called keyword argument. Here's an example of their usage. >>> def snarl(**kw): print kw Now snarl can be called with arbitrary arguments of the form key=value: >>> snarl(animal="penguin", age=28, food="pizza") {'animal': 'penguin', 'age': 28, 'food': 'pizza'} Since kw is a dictionary inside the function body, you can inspect it and use it like any other dictionary. >Secondly I understand he is passing that kw as a dictionary to the apply >function. But I confused with **. can any one give comments on this. He is passing the dict with keyword arguments to the Button.__init__ constructor, using apply. In more recent versions of Python (starting with 2.1, or 2.0, I'm not sure) you can pass the arguments with a different syntax: >>> class Foo: def __init__(self, a, **kw): print "foo:", a, kw >>> class Bar(Foo): def __init__(self, a, b, **kw): self.b = b Foo.__init__(self, a, **kw) # !!! # equivalent of apply(Foo.__init__, (self, a), kw) >>> f = Foo(3, name="Eric") foo: 3 {'name': 'Eric'} >>> b = Bar(42, 10, sport="golf") foo: 42 {'sport': 'golf'} HTH, --Hans Nowak From alan.gauld@bt.com Mon Sep 3 11:36:03 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 3 Sep 2001 11:36:03 +0100 Subject: [Tutor] How to install Pmw for python Tkinter programming Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF08@mbtlipnt02.btlabs.bt.co.uk> > I am just learning Tkinter programming. I came across some > book wich is using Pmw. PMW is an add on to Tkinter that you can download and install. See the Tkinter section of the Python web site for links. > another question is book is telling me that there is extensive > documentation. From where I could get this. Well, assuming its Graysons book that pretty extensive in its own right! However the Tkinter section of the web site has lots of other links. Fred Lundh's tutor and reference are both pretty good - he keeps threatening to bring them out as a book but it hasn't happened yet.... Also, once you get the hang of the conversion there are several books on native Tk which translate easily to Tkinter (eg. I use Tcl/Tk in a nutshell from O'Reilly as my main resource for Tkinter programming) However saying that Tkinter is well documented is only relative to other Python GUI toolkits - pyGTK, Qt, wxPython etc. If somebody wrote a really good book on either wxPython (even wxWindows!) or pyGTK I might consider moving to those. But Tkinter does most of what I need in Python GUI programming so I'll stick with it for now. Alan G From abhiramkushwah@rediffmail.com Mon Sep 3 12:02:07 2001 From: abhiramkushwah@rediffmail.com (Abhiram Singh Kushwah) Date: 3 Sep 2001 11:02:07 -0000 Subject: [Tutor] Can I tell me anyone about [x.lower() for x in lst] Message-ID: <20010903110207.2986.qmail@mailweb26.rediffmail.com> Hi All, Can I tell me anyone about the following code: >>> import string >>> lst =3D3D ['ONE', 'TWO', 'THREE'] >>> newlst =3D3D [x.lower() for x in lst] File "", line 1 newlst =3D3D [x.lower() for x in lst] I am using python1.5 on Red Hat Linux 7.1. Does the facility "[x.lower() for x in lst]" not = available in python1.5 ? Thanks in advance! Abhiram = From scarblac@pino.selwerd.nl Mon Sep 3 11:59:35 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 3 Sep 2001 12:59:35 +0200 Subject: [Tutor] Can I tell me anyone about [x.lower() for x in lst] In-Reply-To: <20010903110207.2986.qmail@mailweb26.rediffmail.com>; from abhiramkushwah@rediffmail.com on Mon, Sep 03, 2001 at 11:02:07AM -0000 References: <20010903110207.2986.qmail@mailweb26.rediffmail.com> Message-ID: <20010903125935.A26015@pino.selwerd.nl> On 0, Abhiram Singh Kushwah wrote: > Hi All, > > Can I tell me anyone about the following code: > > >>> import string > >>> lst = ['ONE', 'TWO', 'THREE'] > >>> newlst = [x.lower() for x in lst] > File "", line 1 > newlst = [x.lower() for x in lst] > > I am using python1.5 on Red Hat Linux 7.1. > Does the facility "[x.lower() for x in lst]" not > available in python1.5 ? No, these are list comprehensions, they were new in 2.0, which is almost a year old now. -- Remco Gerlich From abhiramkushwah@rediffmail.com Mon Sep 3 12:38:28 2001 From: abhiramkushwah@rediffmail.com (Abhiram Singh Kushwah) Date: 3 Sep 2001 11:38:28 -0000 Subject: [Tutor] Can anyone tell me where is being used python in India? Message-ID: <20010903113828.30091.qmail@mailweb25.rediffmail.com> Hi All, I am indian and am learning python But I am afraid for = job in India.I can't go to abroad because I'm poor in = english. So, can anyone tell me where is being used python = programming in India and in which company? = Thanks in advance! Abhiram = From alan.gauld@bt.com Mon Sep 3 12:34:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 3 Sep 2001 12:34:25 +0100 Subject: [Tutor] Can I tell me anyone about [x.lower() for x in lst] Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF0B@mbtlipnt02.btlabs.bt.co.uk> > >>> lst =3D ['ONE', 'TWO', 'THREE'] > >>> newlst =3D [x.lower() for x in lst] > File "", line 1 > newlst =3D [x.lower() for x in lst] > > I am using python1.5 on Red Hat Linux 7.1. > Does the facility "[x.lower() for x in lst]" not > available in python1.5 ? Correct. List comprehensions were introduced in version 2.0. The equivalent code for 1.5 is: lst = ['ONE', 'TWO', 'THREE'] newlst = map(string.lower, lst) OR without a functional approach: lst = ['ONE', 'TWO', 'THREE'] newlst = [] for x in lst: newlst.append(string.lower(x)) Alan g From GADGILP@INFOTECH.ICICI.com Mon Sep 3 13:03:48 2001 From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH) Date: Mon, 3 Sep 2001 17:33:48 +0530 Subject: [Tutor] Can anyone tell me where is being used python in Indi a? Message-ID: This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C13470.7D7A67C0 Content-Type: text/plain; charset="iso-8859-1" hi, The only mention I saw was in, TOI ascent by tata infotech, arround 1 1/2 years back. I havnt been checking recruitment ads much lately, so don't know the latest... /prasad. > -----Original Message----- > From: Abhiram Singh Kushwah [mailto:abhiramkushwah@rediffmail.com] > Sent: Monday, September 03, 2001 5:08 PM > To: tutor@python.org > Subject: [Tutor] Can anyone tell me where is being used > python in India? > > > Hi All, > > I am indian and am learning python But I am afraid for > job in India.I can't go to abroad because I'm poor in > english. > > So, can anyone tell me where is being used python > programming in India and in which company? > > > > Thanks in advance! > Abhiram > > > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > . -- "This e-mail message may contain confidential, proprietary or legally privileged information. It should not be used by anyone who is not the original intended recipient. If you have erroneously received this message, please delete it immediately and notify the sender. The recipient acknowledges that ICICI or its subsidiaries and associated companies (including ICICI Bank) "ICICI Group", are unable to exercise control or ensure or guarantee the integrity of/over the contents of the information contained in e-mail transmissions and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of ICICI Group. Before opening any attachments please check them for viruses and defects." ------_=_NextPart_001_01C13470.7D7A67C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: [Tutor] Can anyone tell me where is being used python in India?<= /TITLE> </HEAD> <BODY> <P><FONT SIZE=3D2>hi,</FONT> </P> <P><FONT SIZE=3D2>The only mention I saw was in, TOI ascent by tata infotec= h,</FONT> <BR><FONT SIZE=3D2>arround 1 1/2 years back. I havnt been checking recruitm= ent ads</FONT> <BR><FONT SIZE=3D2>much lately, so don't know the latest...</FONT> </P> <P><FONT SIZE=3D2>/prasad.</FONT> </P> <P><FONT SIZE=3D2>> -----Original Message-----</FONT> <BR><FONT SIZE=3D2>> From: Abhiram Singh Kushwah [<A HREF=3D"mailto:abhi= ramkushwah@rediffmail.com">mailto:abhiramkushwah@rediffmail.com</A>]</FONT> <BR><FONT SIZE=3D2>> Sent: Monday, September 03, 2001 5:08 PM</FONT> <BR><FONT SIZE=3D2>> To: tutor@python.org</FONT> <BR><FONT SIZE=3D2>> Subject: [Tutor] Can anyone tell me where is being = used </FONT> <BR><FONT SIZE=3D2>> python in India?</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> Hi All,</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> I am indian and am learning python But I am afraid = for </FONT> <BR><FONT SIZE=3D2>> job in India.I can't go to abroad because I'm poor = in </FONT> <BR><FONT SIZE=3D2>> english.</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> So, can anyone tell me where is being used python <= /FONT> <BR><FONT SIZE=3D2>> programming in India and in which company? </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> Thanks in advance!</FONT> <BR><FONT SIZE=3D2>> Abhiram</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>>  </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> _______________________________________________</FO= NT> <BR><FONT SIZE=3D2>> Tutor maillist  -  Tutor@python.org</FONT> <BR><FONT SIZE=3D2>> <A HREF=3D"http://mail.python.org/mailman/listinfo/= tutor" TARGET=3D"_blank">http://mail.python.org/mailman/listinfo/tutor</A><= /FONT> <BR><FONT SIZE=3D2>> </FONT> </P> <BR> <P><B><FONT SIZE=3D2>.. </FONT></B> </P> <P> <FONT FACE=3D"Zurich BT" SIZE=3D1 COLOR=3D"#0000ff"><P>"This e-mail message= may contain confidential, proprietary or legally privileged information. I= t should not be used by anyone who is not the original intended recipient. = If you have erroneously received this message, please delete it immediately= and notify the sender. The recipient acknowledges that ICICI or its subsid= iaries and associated companies (including ICICI Bank) "ICICI Group", are u= nable to exercise control or ensure or guarantee the integrity of/over the = contents of the information contained in e-mail transmissions and further a= cknowledges that any views expressed in this message are those of the indiv= idual sender and no binding nature of the message shall be implied or assum= ed unless the sender does so expressly with due authority of ICICI Group. B= efore opening any attachments please check them for viruses and defects."</= P> </FONT> </BODY> </HTML> ------_=_NextPart_001_01C13470.7D7A67C0-- From m_konermann@gmx.de Mon Sep 3 13:45:28 2001 From: m_konermann@gmx.de (Marcus Konermann) Date: Mon, 03 Sep 2001 14:45:28 +0200 Subject: [Tutor] I Need Help on Extension Python with C Message-ID: <3B937B68.6090606@gmx.de> Hello ! I search for I-Net pages or literature on help for Extension of Python with a C program. I`ve got different .cc files and .h Files and i develop a GUI with python´s Tkinter and now i search for a solution on binding the c progam into the Tkinter GUI. I already looked on python.org or different other links like parnassus, but i did´nt find a good solution for my problem. So, thanks a lot for any help Marcus From kev@sat.net Mon Sep 3 14:26:47 2001 From: kev@sat.net (Kevin McCormick) Date: Mon, 03 Sep 2001 08:26:47 -0500 Subject: [Tutor] wxPython GUI builder References: <006001c132a0$f8408a60$a800a8c0@orange> <20010901091557.G13154@harmony.cs.rit.edu> <3B921EDA.95AE81@sat.net> <20010902222353.A14093@harmony.cs.rit.edu> Message-ID: <3B938517.7DECFD11@sat.net> dman wrote: > > On Sun, Sep 02, 2001 at 06:58:18AM -0500, Kevin McCormick wrote: > | dman wrote: > [..] > | > For GTK+ (PyGTK) there is glade, and the accompanying 'libglade' > | > library. > > | On the subject of PyGTK and Glade, I am a complete newbie. I have been > | trying some things with Tkinter, but GTK apps are definitely more slick > | looking and I would like to get started with that. However, I have > | always had trouble getting things like that set up (I have BlackAdder > | beta, but have never taken the time to figure it out). I really don't > | know where to begin or even how to load the component libraries. I use > | Linux Mandrake 7.2 (waiting for 8.1) with Python 2.0. > > Oh, good, I was afraid you were about to say you were using windows. > I haven't actually used pygtk on windows, but I know that binaries > exist. Frequently setting up stuff on windows is much harder than > unices. > > | Would some users of PyGTK talk about their setup and sources of help for > | beginners? > > When I was using RH I simply installed the RPMs. Now that I am using > Debian I simply use apt-get to download and install the necessary > DEBs. > > Could you give an example of what you are trying to do and why it > doesn't work? > > If I get some spare time soon, then I could refresh myself on the GTK+ > API and give you a "hello world" program that should work. On my > system I can 'import gtk' and 'window = gtk.GtkWindow() ; > window.show()" (but I don't remember how to make it actually visible > -- I probably need to put something in it and make it bigger than 0x0) > > -D > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor Thanks for your response. The links that were provided by Danny Yoo look like pretty nice introductions, so I don't need to impose. An example of what I am doing: I am working on a program that displays charts of stock market daily price data. I have a subscription for update service from msodata (www.msodata.com), but they have no Linux utility stuff. At the time I thought they would have some or I could use my windows, but now I have deleted windows and they don't. However, they seem friendly enough and would probably (I haven't asked) use a Linux utility (download updates) if they had one. Anyway, it has been fairly interesting and easy to code it this far, but the Tkinter GUI stuff has me stopped. I can display a nice PMW scrolled canvas, but I do not see how to incorporate that into a larger program, which would have a menu, download utility, database queries, and the chart. What excites me about this is that Python offers an easy way to experiment with functions so that over time one could develop some really good (or really bad) analysis tools. [which commercial programs do after you waste $$ and months learning their arcane syntax, only to be screwed by some change in the data/version/connection] Also, Python would allow for easy collaboration if this project attracted any interest. I would like to get this to a point of being functional, with a good architecture, and then see what happens. (At least it would be useful to me.) The long and short of pyGTK is that, while I would prefer Tkinter for its universality, perhaps pyGTK is more amenable to my project, and probably just as universal. From dyoo@hkn.eecs.berkeley.edu Mon Sep 3 20:23:20 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 3 Sep 2001 12:23:20 -0700 (PDT) Subject: [Tutor] Can I tell me anyone about [x.lower() for x in lst] In-Reply-To: <20010903125935.A26015@pino.selwerd.nl> Message-ID: <Pine.LNX.4.21.0109031218460.14433-100000@hkn.eecs.berkeley.edu> On Mon, 3 Sep 2001, Remco Gerlich wrote: > On 0, Abhiram Singh Kushwah <abhiramkushwah@rediffmail.com> wrote: > > Hi All, > > > > Can I tell me anyone about the following code: > > > > >>> import string > > >>> lst = ['ONE', 'TWO', 'THREE'] > > >>> newlst = [x.lower() for x in lst] > > File "<stdin>", line 1 > > newlst = [x.lower() for x in lst] > > > > I am using python1.5 on Red Hat Linux 7.1. > > Does the facility "[x.lower() for x in lst]" not > > available in python1.5 ? > > No, these are list comprehensions, they were new in 2.0, which is > almost a year old now. Hi Abhiram, welcome! If you can't upgrade to the newest 2.1.1 at: http://python.org/2.1.1/ you can still do a similar thing to your list by using the map() function: ### >>> import string >>> lst = ['ONE', 'TWO', 'THREE'] >>> newlst = map(string.lower, lst) >>> newlst ['one', 'two', 'three'] ### Still, we recommend upgrading your Python if you can, because there's been quite a few bugfixes and improvements made to the language. List comprehensions and string methods are very fun to work with, and I'd hate to think that you'd miss them! If you have more questions, please feel free to ask! From lonetwin@yahoo.com Tue Sep 4 04:29:29 2001 From: lonetwin@yahoo.com (lonetwin) Date: Mon, 3 Sep 2001 20:29:29 -0700 (PDT) Subject: [Tutor] Can anyone tell me where is being used python in India? In-Reply-To: <20010903113828.30091.qmail@mailweb25.rediffmail.com> Message-ID: <20010904032929.22440.qmail@web20703.mail.yahoo.com> Hey there, Don't be too worried Abhi, there are plenty of places in India that use python, I was working for one such place in Pune called CyberQuest Systems, Indiatimes.com I believe also uses python. You would almost certainly find python being used wherever Linux is being used in India.....an' believe me Linux *is* being used at *plenty* of places (Banglore has many of such places). I'm working at b'bay now, and I'm mainly scripting in python. Hope that's enough to make happy :) Peace Steve --- Abhiram Singh Kushwah <abhiramkushwah@rediffmail.com> wrote: > Hi All, > > I am indian and am learning python But I am afraid > for > job in India.I can't go to abroad because I'm poor > in > english. > > So, can anyone tell me where is being used python > programming in India and in which company? > > > > Thanks in advance! > Abhiram > > > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com From lonetwin@yahoo.com Tue Sep 4 08:24:15 2001 From: lonetwin@yahoo.com (lonetwin) Date: Tue, 4 Sep 2001 00:24:15 -0700 (PDT) Subject: [Tutor] Re: from prompt to file in windows In-Reply-To: <20010904052959.19491.qmail@mailFA9.rediffmail.com> Message-ID: <20010904072415.82111.qmail@web20701.mail.yahoo.com> Hi all, Maybe someone could help kumud .... --- kumud joseph <kumudjk@rediffmail.com> wrote: > hi steve, > its me kumud again . i've done few things in > python such as basic programming , little bit of > visual python,tkinter , and some of the numpy...but > my basic problem is that i m not able to save any of > my programmes through the python prompt used in > windows .. so do help me ... > ---kumud Hi kumud, Well, I can't really answer your question, b'cos my experience with python is limited to linux. Though, if you uses the IDLE interface, you can simply save to a file (methinks!! I use a simple mark & paste in vi [many thanks for that feature in gpm]), so I'm forwarding this mail to the tutor list too....I still don't know if you are on the list, are you ?? if you aren't, you might want to join it, it's pretty helpful like I said in my last mail. Peace Steve __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com From alan.gauld@bt.com Tue Sep 4 11:55:04 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 4 Sep 2001 11:55:04 +0100 Subject: [Tutor] Can anyone tell me where is being used python in Indi a? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF13@mbtlipnt02.btlabs.bt.co.uk> > I am indian and am learning python But I am afraid for > job in India.I can't go to abroad because I'm poor in > english. Hi, I don't know of specific examples but given that India is the second biggest software development area in the world, I'm sure somebody is using it! I know we use a lot of Indian contractors and they nearly all have either Perl or Tcl skills, I wouldn't be surprised if they knew Python too - we just don't ask them for that... Alan G. From alan.gauld@bt.com Tue Sep 4 12:01:46 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 4 Sep 2001 12:01:46 +0100 Subject: [Tutor] I Need Help on Extension Python with C Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF14@mbtlipnt02.btlabs.bt.co.uk> > I search for I-Net pages or literature on help for Extension=20 > of Python with a C program.=20 There are several ways to do this depending on what=20 exactly you want to achieve:=20 1) You could embed a Python interpreter in your C application.=20 2) You could turn your C application into Python modules. 3) You could make your C application into a server (using sockets or maybe XML-RPC) Others??? It depends how complete the C app is, what kind of interface etc. > develop a GUI with python=B4s Tkinter and now i search for a=20 > solution on binding the c progam into the Tkinter GUI. If you go the client server route you can just call the server=20 functions and format up the data you receive back for=20 presentation in Tkinter. If you embed Python you can get the C program to call your=20 Tkinter script with parameters. Umm, what then? Not sure=20 I haven't done any embedding! But I think you can communicate=20 with the Tk objects from the C using pyXXXX type C calls. Ask somebody else on that one :-) Alan g From abhiramkushwah@rediffmail.com Tue Sep 4 12:23:54 2001 From: abhiramkushwah@rediffmail.com (Abhiram Singh Kushwah) Date: 4 Sep 2001 11:23:54 -0000 Subject: [Tutor] Can anyone tell me where is being used python in Indi a? Message-ID: <20010904112354.10627.qmail@mailweb13.rediffmail.com> Hi, Thanks for your rsponse.I've found that Python is being = used in many companies in India as CISCO,TATAINFOTECH, IIPL etc. I'm very glad to know this. With Regards, Abhiram On Tue, 04 Sep 2001 alan.gauld@bt.com wrote : >> I am indian and am learning python But I am afraid = >for = >> job in India.I can't go to abroad because I'm poor = in = >> english. > >Hi, I don't know of specific examples but given that = >India = >is the second biggest software development area in the = >world, = >I'm sure somebody is using it! I know we use a lot of = >Indian = >contractors and they nearly all have either Perl or = Tcl = >skills, = >I wouldn't be surprised if they knew Python too - we = >just = >don't ask them for that... > >Alan G. = From ajaya@ncoretech.com Tue Sep 4 13:08:51 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 4 Sep 2001 17:38:51 +0530 Subject: [Tutor] How to disable Resizing in Tkinter. Message-ID: <000e01c1353a$61833a90$6501a8c0@ncoretech.com> Dear All, I have one problem. I am developing GUI using Tkinter. I've this problem I've a fixed layout. If i try to maximize and resize it is looking ugly. So I would like to disable the resizing option. can any one kindly suggest some thig to fix this problem. Thanks ana Regards, Ajaya babu From pythonpython@hotmail.com Tue Sep 4 14:04:40 2001 From: pythonpython@hotmail.com (HY) Date: Tue, 4 Sep 2001 22:04:40 +0900 Subject: [Tutor] How to use Python's Regular Expression to process Japanese or Chinese characters? Message-ID: <OE27cZi71mrvoGdKO8F0000786e@hotmail.com> This is a multi-part message in MIME format. ------=_NextPart_000_0025_01C1358D.986C9BC0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi there, Does anyone know how to use Regular Expression to process Japanese or = Chinese characters? Is there a tutorial/book on this? For example, how can I represent a Japanese or Chinese character? I = don't think "/w" works. Thanks a lot. Hy ------=_NextPart_000_0025_01C1358D.986C9BC0 Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312"> <META content=3D"MSHTML 5.50.4134.100" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial>Hi there,</FONT></DIV> <DIV><FONT face=3DArial></FONT> </DIV> <DIV><FONT face=3DArial>Does anyone know how to use Regular Expression = to process=20 Japanese or Chinese characters?</FONT></DIV> <DIV><FONT face=3DArial>Is there a tutorial/book on this?</FONT></DIV> <DIV><FONT face=3DArial></FONT> </DIV> <DIV><FONT face=3DArial>For example, how can I represent a Japanese or = Chinese=20 character? I don't think "/w" works.</FONT></DIV> <DIV><FONT face=3DArial></FONT> </DIV> <DIV><FONT face=3DArial>Thanks a lot.</FONT></DIV> <DIV><FONT face=3DArial></FONT> </DIV> <DIV><FONT face=3DArial>Hy</FONT></DIV></BODY></HTML> ------=_NextPart_000_0025_01C1358D.986C9BC0-- From bill_tolbert@bigfoot.com Tue Sep 4 14:53:29 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Tue, 4 Sep 2001 09:53:29 -0400 (EDT) Subject: [Tutor] Why I'm learning Python (OT and long) In-Reply-To: <5.1.0.14.0.20010830185646.029d2bc0@mail> Message-ID: <Pine.GSO.4.21L1.0109040946090.4800-100000@sunny> Thanks to all for the encouragement. You guys are great. I guess I've only been at this about 5 years now. If I stick with it I may know something by the time I retire.... Bill From urnerk@qwest.net Tue Sep 4 13:37:00 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 4 Sep 2001 08:37:00 -0400 Subject: [Tutor] Re: from prompt to file in windows In-Reply-To: <20010904072415.82111.qmail@web20701.mail.yahoo.com> References: <20010904072415.82111.qmail@web20701.mail.yahoo.com> Message-ID: <01090408370001.03466@ktu> Yes Kumud, on Windows the best shell for Python straight out of the download is IDLE, a graphical shell. You go File | New Window and write your Python code there. Then Save. Then, back at the shell window, go 'import mynewmodule' (no quotes) and your new code will either (a) be imported or (b) give you some error messages. Or you can Save and go Ctrl-F5 and have your program execute right there and then. When writing for import (i.e. internal use), vs. exporting a script, you'll develop a slightly different psychology. You'll invoke individual classes and functions that you've written as tools, maybe gluing them together in short ad hoc functions you actually write in the IDLE shell window (easily done). These ad hoc functions, if used often, might eventually be worth migrating to the module itself (just cut and paste). IDLE has limitations in that Tkinter programs, when quit, often make the whole of IDLE quit, because it's a Tkinter program and doesn't run your stuff as a separate process. The VPython modifications to IDLE seem to get around this, and the IDLE fork project might eventually get around this problem as well. You can still write Tk programs in IDLE, but boot/test them in a DOS Python shell open in another window. In any case, for non-Tkinter programming, I highly recommend IDLE over using any DOS box shell. Your program is automatically color coded and so forth. You can get other editors that do this, but IDLE is more than an editor, it's a shell, so you can execute an expression directly, as you would in the DOS shell. Note: all of the above applies to Linux as well. You have the option of installing IDLE from /Tools after you compile a new version, simply by copying it to the apppropriate subdirectory (e.g. to /usr/lib/python2.0/site-packages/idle/idle.py or maybe to /usr/local/lib/python2.2/site-packages/idle/idle.py). Chances are, if you're a long-time *nixer, you've picked up Vi or Emacs or something (Windows versions of these also available), and you might frown on IDLE's program editor (you might not though -- not everyone is that fanatical about their text editor). On other hand, if you're new to both Python *and* Linux, then using IDLE, over trying to master a new editor (and/or typing everything in some Xterm window running Python in shell mode) will probably give you more immediate satisfaction. Kirby On Tuesday 04 September 2001 03:24, lonetwin wrote: > Hi all, > Maybe someone could help kumud .... > > --- kumud joseph <kumudjk@rediffmail.com> wrote: > > hi steve, > > its me kumud again . i've done few things in > > python such as basic programming , little bit of > > visual python,tkinter , and some of the numpy...but > > my basic problem is that i m not able to save any of > > my programmes through the python prompt used in > > windows .. so do help me ... > > ---kumud From alan.gauld@bt.com Tue Sep 4 17:16:47 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 4 Sep 2001 17:16:47 +0100 Subject: [Tutor] How to disable Resizing in Tkinter. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF1A@mbtlipnt02.btlabs.bt.co.uk> > I've a fixed layout. If i try to maximize and resize it is > looking ugly. This is a common problem with GuUIs but Tkinter usually handles it better than most. It depenfds to some extent which layout manager you use - grid often causes problems IME. > I would like to disable the resizing option. > can any one kindly suggest some thig to fix this problem. I guess that there's probablty Window Manager messages that you can trap. Check the docs for the WM_XXX messages. Alan G From alan.gauld@bt.com Tue Sep 4 17:18:17 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 4 Sep 2001 17:18:17 +0100 Subject: [Tutor] Why I'm learning Python (OT and long) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF1B@mbtlipnt02.btlabs.bt.co.uk> > only been at this about 5 years now. If I stick with it I may know > something by the time I retire.... I've been at it for over 25 years, I figure the same thing ;-) Alan G From lkvam@venix.com Tue Sep 4 17:25:30 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Tue, 04 Sep 2001 12:25:30 -0400 Subject: [Tutor] Re: from prompt to file in windows References: <20010904072415.82111.qmail@web20701.mail.yahoo.com> Message-ID: <3B95007A.3F76869B@venix.com> I've been reasonably happy using pythonwin. Active State provides a Python release with bundled Windows support (COM, etc.). http://aspn.activestate.com/ASPN/Downloads/ActivePython/ Your python directory will contain a pythonwin directory. This, in turn, contains pythonwin.exe. The pythonwin program provides a script editor and an interactive Python window. It is covered in the Mark Hammond & Andy Robinson book "Python Programming on Win32". IDLE is certainly preferred as a cross-platform choice. Pythonwin is only available in windows. lonetwin wrote: > > Hi all, > Maybe someone could help kumud .... > > --- kumud joseph <kumudjk@rediffmail.com> wrote: > > hi steve, > > its me kumud again . i've done few things in > > python such as basic programming , little bit of > > visual python,tkinter , and some of the numpy...but > > my basic problem is that i m not able to save any of > > my programmes through the python prompt used in > > windows .. so do help me ... > > ---kumud > > Hi kumud, > Well, I can't really answer your question, b'cos > my experience with python is limited to linux. Though, > if you uses the IDLE interface, you can simply save to > a file (methinks!! I use a simple mark & paste in vi > [many thanks for that feature in gpm]), so I'm > forwarding this mail to the tutor list too....I still > don't know if you are on the list, are you ?? if you > aren't, you might want to join it, it's pretty helpful > like I said in my last mail. > > Peace > Steve > > __________________________________________________ > Do You Yahoo!? > Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger > http://im.yahoo.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From alan.gauld@bt.com Tue Sep 4 17:28:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 4 Sep 2001 17:28:25 +0100 Subject: [Tutor] Re: from prompt to file in windows Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF1C@mbtlipnt02.btlabs.bt.co.uk> > Yes Kumud, on Windows the best shell for Python straight out > of the download is IDLE, a graphical shell. Depends. If you got the ActiveState Python you might prefer Pythonwin - but it's for Windows only. The folding editor features of Pythonwin are a powerful inducement :-) (You also get Pythonwin if you install the winall package) > You go File | New Window and write your Python code there. This is the important bit for IDLE or Pythonwin. Don't try to save the session from the Python >>> prompt (you can but then need to edit out all the '>>>' bits and the responses. I sometimes do this if prototyping at the prompt... its faster than retyping it all! > IDLE has limitations in that Tkinter programs Pythonwin does strange things with Tkinter too. Which is really weird since its not a Tk app! > IDLE over using any DOS box shell. Your program is automatically > color coded and so forth. You can get other editors that do this, > but IDLE is more than an editor, it's a shell, so you can execute > an expression directly, as you would in the DOS shell. The advantage of the editor/DOS box approach is that you can be sure that the running program does exactly what it will when you run it for real. In IDLE etc you can never be quite certain it'll be the same. (Incidentally the Pythonwin editor is available as a standalone app - Scite I recommend it as an alternative to vim for Windows users.) Alan G (Who likes IDLE too but felt the opposition deserved a plug :-) From ajaya@ncoretech.com Tue Sep 4 17:40:25 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 4 Sep 2001 22:10:25 +0530 Subject: [Tutor] Intresting problem with GUI and Threads, Message-ID: <000001c13560$4cfc9a00$6501a8c0@ncoretech.com> Hi All, I am using Python2.0 I've some intresting problem with python Tkinter programming. I've GUI class with which I can create the GUI then I've a pipe callass with which I will be receiving commnads from remote system. Now any Event that takes place at GUI should go the remote system using same pipe. so I've designed like this class GUI(Frame): --GUI Suite class Processor self.gui = GUI() self.pipe = TcpIpPipe() start WorkerThread def WorkerThread() EventQ = a.GetEventQ() self.pipe.SendEventQToRemoteSystem(EventQ) in this implementation I've a problem when I close the GUI. Python is hanging some times...may be because it try to call a.GetEvent() wich is actually deleted..., How to solve this problem. Any comments on implemention or any suggestion to improve the implementation welcome. Thanks and Regards, Ajaya From srichter@cbu.edu Tue Sep 4 18:12:02 2001 From: srichter@cbu.edu (Stephan Richter) Date: Tue, 04 Sep 2001 12:12:02 -0500 Subject: [Tutor] Python Tool for converting TeX to GIF Message-ID: <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Hello everyone, does anyone know about a tool in Python that will convert TeX to GIFs? I mean, it could use some other Unix commands too. I need it for a Web Site, where someone, can type a math expression using TEX and it is then converted, so it can be displayed. I could really use any hint, since I was out of luck searching through the Web. Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management From rbl@hal.cwru.edu Tue Sep 4 18:15:52 2001 From: rbl@hal.cwru.edu (Robin B. Lake) Date: Tue, 4 Sep 2001 13:15:52 -0400 (EDT) Subject: [Tutor] Matrix Read-in and Inversion Message-ID: <200109041715.NAA00203@hal.cwru.edu> I have a 100 x 150 matrix which I want to invert using the Generalized Inverse capability of MathPy. How might I read this dataset in from either a comma-separated file or an Excel spreadsheet. I'm on a Mac G3, OS 8.6. Thanks, Robin Lake lake@cwru.edu From Blake.Garretson@dana.com Tue Sep 4 18:28:23 2001 From: Blake.Garretson@dana.com (Blake.Garretson@dana.com) Date: Tue, 4 Sep 2001 13:28:23 -0400 Subject: [Tutor] How to disable Resizing in Tkinter. Message-ID: <OF8DB8B642.56CC55E0-ON85256ABD.005F7C45@dana.com> If you created your window with the command: root = Tk() then the following line will disable resizing: root.resizable(0,0) This tells the window that it it can't be resized in the x or y direction. -Blake Garretson >From: "Ajaya Babu" <ajaya@ncoretech.com>: >Dear All, > >I have one problem. I am developing GUI using Tkinter. I've this problem > >I've a fixed layout. If i try to maximize and resize it is looking ugly. So >I would like to disable the resizing option. > >can any one kindly suggest some thig to fix this problem. > >Thanks ana Regards, >Ajaya babu From ignacio@openservices.net Tue Sep 4 18:48:51 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 4 Sep 2001 13:48:51 -0400 (EDT) Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Message-ID: <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservices.net> On Tue, 4 Sep 2001, Stephan Richter wrote: > Hello everyone, > > does anyone know about a tool in Python that will convert TeX to GIFs? I > mean, it could use some other Unix commands too. > > I need it for a Web Site, where someone, can type a math expression using > TEX and it is then converted, so it can be displayed. > > I could really use any hint, since I was out of luck searching through the Web. > > Regards, > Stephan > > -- > Stephan Richter > CBU - Physics and Chemistry Student > Web2k - Web Design/Development & Technical Project Management There's textogif: http://www.fourmilab.ch/webtools/textogif/textogif.html but it has a lot of requirements. I couldn't find anything else for TeX -> GIF. You can also have a look at MathML. There are only a couple of browsers that support it, but there are some MathML -> GIF converters out there. -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From dsh8290@rit.edu Tue Sep 4 19:17:14 2001 From: dsh8290@rit.edu (dman) Date: Tue, 4 Sep 2001 14:17:14 -0400 Subject: [Tutor] wxPython GUI builder In-Reply-To: <3B938517.7DECFD11@sat.net>; from kev@sat.net on Mon, Sep 03, 2001 at 08:26:47AM -0500 References: <006001c132a0$f8408a60$a800a8c0@orange> <20010901091557.G13154@harmony.cs.rit.edu> <3B921EDA.95AE81@sat.net> <20010902222353.A14093@harmony.cs.rit.edu> <3B938517.7DECFD11@sat.net> Message-ID: <20010904141714.G17060@harmony.cs.rit.edu> On Mon, Sep 03, 2001 at 08:26:47AM -0500, Kevin McCormick wrote: | dman wrote: ... | > Could you give an example of what you are trying to do and why it | > doesn't work? ... | An example of what I am doing: [long story :-)] By "example of what you are trying to do" I meant, could you post some code and the console output when you try and run it. Seeing the error messages you get would help to figure out what your problem is and how to solve it :-). Have you gotten it to work over the weekend? -D From dsh8290@rit.edu Tue Sep 4 19:19:33 2001 From: dsh8290@rit.edu (dman) Date: Tue, 4 Sep 2001 14:19:33 -0400 Subject: [Tutor] mail server stress In-Reply-To: <20010903072815.9798.qmail@web20704.mail.yahoo.com>; from lonetwin@yahoo.com on Mon, Sep 03, 2001 at 12:28:15AM -0700 References: <20010903072815.9798.qmail@web20704.mail.yahoo.com> Message-ID: <20010904141933.H17060@harmony.cs.rit.edu> On Mon, Sep 03, 2001 at 12:28:15AM -0700, lonetwin wrote: | Hi all you good people, | One quick question, does anyone know about a mail | server stress/load test application/module written in I don't know of any (written in any language). | python ?? This seems like just the thing that is | likely to be written in python, well if there isn't | any helpful tips/comments on what I should be thinking | if I decide to write something of my own ??? I think you should get several machines and have each of them try sending mail messages as fast as they can at the same time. Also vary the messages from being proper to being incorrect in various ways. Also try messing up the SMTP communication to see how the server handles it if something went wrong during a real-world transfer. -D From cwebster@unlv.edu Tue Sep 4 20:47:13 2001 From: cwebster@unlv.edu (Corran Webster) Date: Tue, 4 Sep 2001 12:47:13 -0700 Subject: [Tutor] Matrix Read-in and Inversion In-Reply-To: <200109041715.NAA00203@hal.cwru.edu> References: <200109041715.NAA00203@hal.cwru.edu> Message-ID: <f05100e0eb7badd6e45ab@[192.168.0.4]> At 1:15 PM -0400 4/9/01, Robin B. Lake wrote: >I have a 100 x 150 matrix which I want to invert using the Generalized >Inverse capability of MathPy. > >How might I read this dataset in from either a comma-separated file or >an Excel spreadsheet. I'm on a Mac G3, OS 8.6. Something like the following should work for comma-separated, assuming each matrix row is on a line by itself and the numbers are floats (warning, untested code): import Numeric # open the file f = open("filename") # read data into a list of lists data = [] for line in f.readlines(): linedata = [] # split the line at each comma for value in line.split(","): linedata.append(float(value)) data.append(linedata) f.close() # convert to numpy array a = Numeric.array(data) In a python version with list comprehensions (2.0 or better), this can be compressed considerably: import Numeric f = open("filename") a = Numeric.array([[float(value) for value in line.split(",")] for line in f.readlines()]) f.close() Regards, Corran From shalehperry@home.com Tue Sep 4 20:49:43 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Tue, 04 Sep 2001 12:49:43 -0700 (PDT) Subject: [Tutor] Matrix Read-in and Inversion In-Reply-To: <200109041715.NAA00203@hal.cwru.edu> Message-ID: <XFMail.20010904124943.shalehperry@home.com> On 04-Sep-2001 Robin B. Lake wrote: > I have a 100 x 150 matrix which I want to invert using the Generalized > Inverse capability of MathPy. > > How might I read this dataset in from either a comma-separated file or > an Excel spreadsheet. I'm on a Mac G3, OS 8.6. > csv's are easy, just use string.split. From scott@zenplex.com Tue Sep 4 21:36:54 2001 From: scott@zenplex.com (Scott Comboni) Date: 04 Sep 2001 16:36:54 -0400 Subject: [Tutor] Database connectivity tools for MS-SQL Message-ID: <999635814.1408.20.camel@scoot> Hello All, Is anyone in the group aware of a package that allows python to connect to a MS-SQL server? Remote Client running Linux/Python2.1 Thanks Scott From rick@niof.net Tue Sep 4 21:53:26 2001 From: rick@niof.net (Rick Pasotto) Date: Tue, 4 Sep 2001 16:53:26 -0400 Subject: [Tutor] Matrix Read-in and Inversion In-Reply-To: <XFMail.20010904124943.shalehperry@home.com> References: <200109041715.NAA00203@hal.cwru.edu> <XFMail.20010904124943.shalehperry@home.com> Message-ID: <20010904165325.A844@tc.niof.net> On Tue, Sep 04, 2001 at 12:49:43PM -0700, Sean 'Shaleh' Perry wrote: > > On 04-Sep-2001 Robin B. Lake wrote: > > I have a 100 x 150 matrix which I want to invert using the > > Generalized Inverse capability of MathPy. > > > > How might I read this dataset in from either a comma-separated file > > or an Excel spreadsheet. I'm on a Mac G3, OS 8.6. > > csv's are easy, just use string.split. Not if a quote delimited field has a comma within it. -- The demands of the socialists raise another question, which I have often addressed to them, and to which, as far as I know, they have never replied. Since the natural inclinations of mankind are so evil that its liberty must be taken away, how is it that the inclinations of the socialists are good? Are not the legislators and their agents part of the human race? Do they believe themselves moulded from another clay than the rest of mankind? -- Frédéric Bastiat (1801-1850) Rick Pasotto rickp@telocity.com http://www.niof.net From brian@dorseys.org Tue Sep 4 22:12:58 2001 From: brian@dorseys.org (Brian Dorsey) Date: Tue, 4 Sep 2001 14:12:58 -0700 Subject: [Tutor] Reading CSVs Was:Matrix Read-in and Inversion In-Reply-To: <20010904165325.A844@tc.niof.net>; from rick@niof.net on Tue, Sep 04, 2001 at 04:53:26PM -0400 References: <200109041715.NAA00203@hal.cwru.edu> <XFMail.20010904124943.shalehperry@home.com> <20010904165325.A844@tc.niof.net> Message-ID: <20010904141258.B594@dorseys.org> On Tue, Sep 04, 2001 at 04:53:26PM -0400, Rick Pasotto wrote: > On Tue, Sep 04, 2001 at 12:49:43PM -0700, Sean 'Shaleh' Perry wrote: > > > > On 04-Sep-2001 Robin B. Lake wrote: > > > I have a 100 x 150 matrix which I want to invert using the > > > Generalized Inverse capability of MathPy. > > > > > > How might I read this dataset in from either a comma-separated file > > > or an Excel spreadsheet. I'm on a Mac G3, OS 8.6. > > > > csv's are easy, just use string.split. > > Not if a quote delimited field has a comma within it. > I've found the CSV module at the following address quite useful for dealing withoccasionally quoted CSV files (especially from Excell). http://object-craft.com.au/projects/csv/ Take care, -Brian From brian@dorseys.org Tue Sep 4 22:16:26 2001 From: brian@dorseys.org (Brian Dorsey) Date: Tue, 4 Sep 2001 14:16:26 -0700 Subject: [Tutor] Database connectivity tools for MS-SQL In-Reply-To: <999635814.1408.20.camel@scoot>; from scott@zenplex.com on Tue, Sep 04, 2001 at 04:36:54PM -0400 References: <999635814.1408.20.camel@scoot> Message-ID: <20010904141626.C594@dorseys.org> On Tue, Sep 04, 2001 at 04:36:54PM -0400, Scott Comboni wrote: > Hello All, > Is anyone in the group aware of a package that allows python to connect > to a MS-SQL server? Remote Client running Linux/Python2.1 > Thanks Scott > Looks like it's time for my second Object-Craft plug for the day. They have a SQL-Server python module at: http://www.object-craft.com.au/projects/mssql/ I've used it successfully with a windows client and the page claims it works from Linux with Sybase libraries. I also found the author of the module to be quite responsive and helpful. Take care, -Brian From jerryl@europa.com Tue Sep 4 22:24:15 2001 From: jerryl@europa.com (Jerry Lake) Date: Tue, 4 Sep 2001 14:24:15 -0700 Subject: [Tutor] date function In-Reply-To: <20010904141258.B594@dorseys.org> Message-ID: <000201c13587$f39a0920$0103670a@europa.com> Does python have a date function ? I didn't stumble across it in the docs. if so, where can I read about it. Regards, Jerry Lake Interface Engineering Technician From mbc2@netdoor.com Tue Sep 4 22:37:26 2001 From: mbc2@netdoor.com (Brad Chandler) Date: Tue, 4 Sep 2001 16:37:26 -0500 Subject: [Tutor] Database connectivity tools for MS-SQL References: <999635814.1408.20.camel@scoot> Message-ID: <003d01c13589$cae0b400$111c0d0a@spb.state.ms.us> There is an ODBC module included in the Python distribution. I've used it to connect to MS-SQL Server from Windows95. I'm not sure how that would work from Linux. Here's how I use it: import dbi, odbc mydb=odbc.odbc("ODBCdatasource/username/password") cursor = mydb.cursor() cursor.execute("select * from table1") result = cursor.fetchall() for x in result: print x cursor.close() mydb.close() cursor = None mydb = None ----- Original Message ----- From: "Scott Comboni" <scott@zenplex.com> To: <tutor@python.org> Sent: Tuesday, September 04, 2001 3:36 PM Subject: [Tutor] Database connectivity tools for MS-SQL > Hello All, > Is anyone in the group aware of a package that allows python to connect > to a MS-SQL server? Remote Client running Linux/Python2.1 > Thanks Scott > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From rob@jam.rr.com Tue Sep 4 22:32:03 2001 From: rob@jam.rr.com (Rob Andrews) Date: Tue, 04 Sep 2001 16:32:03 -0500 Subject: [Tutor] date function References: <000201c13587$f39a0920$0103670a@europa.com> Message-ID: <3B954853.8323614B@jam.rr.com> Jerry Lake wrote: > > Does python have a date function ? > I didn't stumble across it in the > docs. if so, where can I read about it. > > Regards, > > Jerry Lake > Interface Engineering Technician > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor There's a "batteries included" time module: http://www.python.org/doc/current/lib/module-time.html Rob -- A {} is a terrible thing to waste. Useless Python! http://www.lowerstandard.com/python From ak@silmarill.org Tue Sep 4 22:31:31 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Tue, 04 Sep 2001 17:31:31 -0400 Subject: [Tutor] date function In-Reply-To: <000201c13587$f39a0920$0103670a@europa.com> References: <20010904141258.B594@dorseys.org> <000201c13587$f39a0920$0103670a@europa.com> Message-ID: <20010904173131.A18868@sill.silmarill.org> On Tue, Sep 04, 2001 at 02:24:15PM -0700, Jerry Lake wrote: > Does python have a date function ? > I didn't stumble across it in the > docs. if so, where can I read about it. Certainly - it's in time module, since time and date are kind of related. It'd probably be useful to have a date module too that would be another name for time.. There's also MxDateTime that should have more goods for date manipulations. Here's an example of usage of time module: >>> import time >>> time.localtime() (2001, 9, 4, 17, 29, 48, 1, 247, 1) >>> time.ctime(time.time()) 'Tue Sep 4 17:30:03 2001' Plain time.ctime() does the same in later versions but not in 1.5 iirc. [snip] - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From urnerk@qwest.net Tue Sep 4 20:05:46 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 4 Sep 2001 15:05:46 -0400 Subject: [Tutor] Database connectivity tools for MS-SQL In-Reply-To: <999635814.1408.20.camel@scoot> References: <999635814.1408.20.camel@scoot> Message-ID: <01090415054604.03466@ktu> On Tuesday 04 September 2001 04:36, Scott Comboni wrote: > Hello All, > Is anyone in the group aware of a package that allows python to connect > to a MS-SQL server? Remote Client running Linux/Python2.1 > Thanks Scott > MS-SQL is ODBC-compliant, and there are ODBC modules for Python, so, yes, you can make your Python app a client of MS-SQL. I think the ODBC stuff is stashed with the win32all package. Is that over at the ActivePython site? Kirby From srichter@cbu.edu Tue Sep 4 23:06:44 2001 From: srichter@cbu.edu (Stephan Richter) Date: Tue, 04 Sep 2001 17:06:44 -0500 Subject: [Tutor] date function In-Reply-To: <000201c13587$f39a0920$0103670a@europa.com> References: <20010904141258.B594@dorseys.org> Message-ID: <5.1.0.14.2.20010904170618.037c4680@mail.cbu.edu> At 02:24 PM 9/4/2001 -0700, Jerry Lake wrote: >Does python have a date function ? >I didn't stumble across it in the >docs. if so, where can I read about it. Look also at mxDateTime. It is very nice. Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management From urnerk@qwest.net Tue Sep 4 20:12:20 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 4 Sep 2001 15:12:20 -0400 Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> References: <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Message-ID: <01090415122005.03466@ktu> On Tuesday 04 September 2001 01:12, Stephan Richter wrote: > Hello everyone, > > does anyone know about a tool in Python that will convert TeX to GIFs? I > mean, it could use some other Unix commands too. > > I need it for a Web Site, where someone, can type a math expression using > TEX and it is then converted, so it can be displayed. > > I could really use any hint, since I was out of luck searching through the > Web. > > Regards, > Stephan > Off-hand, I wouldn't think there'd be such a thing as a Python module, but ya never know. The best way I know is to display the TeX in any quality reader, and use a screen grabber to get the GIF content. The web is moving the MathML, an XML, for displaying math stuff. The Amaya browser is starting to build that in. There might be a TeX-to-ML conversion package out there, or in the works. But you want GIFs.... (In Windows, MathCad used to save screen-based math to lots of little JPEGs. Now it has a "Save as MathML option" -- just thought I'd mention a best-seller as indicative of current trends). Kirby From urnerk@qwest.net Tue Sep 4 20:14:12 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 4 Sep 2001 15:14:12 -0400 Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservices.net> References: <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservices.net> Message-ID: <01090415141206.03466@ktu> On Tuesday 04 September 2001 01:48, Ignacio Vazquez-Abrams wrote: > There's textogif: > > http://www.fourmilab.ch/webtools/textogif/textogif.html > > but it has a lot of requirements. I couldn't find anything else for TeX -> > GIF. Ah! You've broadened my mind. Once again, live and learn... (doesn't mean there's a Python version, but at least someone has done it in Perl -- why not go with that, hey?). Kirby From urnerk@qwest.net Tue Sep 4 20:27:22 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 4 Sep 2001 15:27:22 -0400 Subject: [Tutor] Re: from prompt to file in windows In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF1C@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF1C@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <01090415272207.03466@ktu> On Tuesday 04 September 2001 12:28, alan.gauld@bt.com wrote: > The advantage of the editor/DOS box approach is that you > can be sure that the running program does exactly what it > will when you run it for real. In IDLE etc you can never > be quite certain it'll be the same. > True. But in my own case, much of what I do "for real" in Python I do from within IDLE, i.e. IDLE is where my programs were written and from whence they're most comfortably run. IDLE is as real as it needs to get, a lot of the time. IDLE can be the command window of choice, similar to the command window I'm accustomed to from Visual FoxPro (historically my bread and butter language). > (Incidentally the Pythonwin editor is available as a > standalone app - Scite I recommend it as an alternative > to vim for Windows users.) Yes, I've used this too. But I like having a shell that I can also write code in. In IDLE (and I presume Pythonwin, which I've used in the past), I can arrow up to a previously written function (in the shell, not in a file), hit enter, and the whole thing transfers to the current command line, where I can re-edit it (not practical for super long programs, but nifty when I just want 10 lines of code to do something -- often the case). > Alan G > (Who likes IDLE too but felt the opposition deserved a plug :-) > Sure. I was mostly pointing to IDLE because it's included in the native distros coming directly from python.org, and it's not Windows- specific (I recommend it to Linux users too -- maybe with bigger fonts than you get natively). I also always recommend that newcomers to Python download the most up-to-date versions if possible, as that's one of the benefits of not having invested a ton in some pet project that will break if you migrate to 2.x (e.g. Zope). When you're still just getting your feet wet is a great time to play with the latest alpha. Sometimes the ActivePython stuff lags behind a bit, no? (I had to teach VI about the new "yield" key word, and still haven't bothered to teach Emacs how to color-code properly). Kirby From lonetwin@yahoo.com Wed Sep 5 04:59:37 2001 From: lonetwin@yahoo.com (lonetwin) Date: Tue, 4 Sep 2001 20:59:37 -0700 (PDT) Subject: [Tutor] mail server stress In-Reply-To: <20010904141933.H17060@harmony.cs.rit.edu> Message-ID: <20010905035937.33871.qmail@web20701.mail.yahoo.com> Hey dman --- dman <dsh8290@rit.edu> wrote: > On Mon, Sep 03, 2001 at 12:28:15AM -0700, lonetwin > wrote: > | Hi all you good people, > | One quick question, does anyone know about a mail > | server stress/load test application/module written > | in > > I don't know of any (written in any language). Well there are quite a few such applications, but most of them are commercial, written in c/c++. of these a number of them are windows applications. A quick search at freshmeat [keyword 'stress'] served up smpop, which looks pretty good, maybe I'll write something like that up in python (smpop's written in C) also a google search led me to Netscape's Mailstone and the mozzila equivalent mstone, but those were for stressing the Netscape Messaging server. I have yet to look at those....today 'also' is gonna be a nice long day :) > | python ?? This seems like just the thing that is > | likely to be written in python, well if there > | isn't > | any helpful tips/comments on what I should be > | thinking > | if I decide to write something of my own ??? > > I think you should get several machines and have > each of them try > sending mail messages as fast as they can at the > same time. Also vary > the messages from being proper to being incorrect in > various ways. > Also try messing up the SMTP communication to see > how the server > handles it if something went wrong during a > real-world transfer. > > -D Hey thanx try that too .... Peace Steve __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com From chikitychina@home.com Wed Sep 5 05:21:34 2001 From: chikitychina@home.com (Pablo Manzanera) Date: Wed, 05 Sep 2001 00:21:34 -0400 Subject: [Tutor] Running python scripts without installing python Message-ID: <3B95A84E.672BE63E@home.com> Hey all, Just a quick question for all you Windows Pythoners... What is the best way to run python scripts on Windows machines that do not have Python installed? Thanks in advance Pablo Manzanera From wheelege@tsn.cc Wed Sep 5 05:33:15 2001 From: wheelege@tsn.cc (wheelege) Date: Wed, 5 Sep 2001 14:33:15 +1000 Subject: [Tutor] Running python scripts without installing python References: <3B95A84E.672BE63E@home.com> Message-ID: <018e01c135c3$e2041de0$61a616ca@ACE> Hey Pablo, Your looking at using something that makes and exe, no? I think you should look into py2exe - I've had quite a bit of experience with it and it works with alot of things (tkinter, for example). The url for that is http://starship.python.net/crew/theller/py2exe/. Another one I hear people mentioning is Gordon Macmillian's Installer - I don't have a URL for that. Although I'm sure google would. Good luck, Glen. > Hey all, > > Just a quick question for all you Windows Pythoners... > > What is the best way to run python scripts on Windows machines that do > not have Python installed? > > > > Thanks in advance > > Pablo Manzanera From srichter@cbu.edu Wed Sep 5 06:21:41 2001 From: srichter@cbu.edu (Stephan Richter) Date: Wed, 05 Sep 2001 00:21:41 -0500 Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservi ces.net> References: <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Message-ID: <5.1.0.14.2.20010904155655.037c0228@mail.cbu.edu> >There's textogif: > > http://www.fourmilab.ch/webtools/textogif/textogif.html > >but it has a lot of requirements. I couldn't find anything else for TeX -> >GIF. Yeah, I had seen this one before. But I figured out that the script can be written quickly (see code below) in Python. I really do not like it. The code is ugly and some features are not working, but it is a proof of concept which I will turn into a class now... ;-) >You can also have a look at MathML. There are only a couple of browsers that >support it, but there are some MathML -> GIF converters out there. I am just not one of the XML fans and the professors using this tool know Latex already. Regards, Stephan Code for tex2gif.py import sys, getopt, string usage = ''' Usage: $COMNAME [options...] file.tex Description: $COMNAME converts a *.tex file into one GIF image file. Current Version is ${VERSION_MAJOR}.${VERSION_MINOR} Options : -p --detail_ratio [default = ${DETAIL_DEFAULT}] -d --dpi pix_per_inch [default = ${DPI_DEFAULT}] -m --margin margin_width [default = ${MARGIN_DEFAULT}] -r --rotate angle [default = ${ROTATE_DEFAULT} (counterclockwise in deg)] -t --transparent colorname [default no transparent color set] --usage | --help : show this message ''' command = ''' latex %(file)s.tex; dvips -q -f %(file)s.dvi > %(file)s.ps gs -sDEVICE=ppmraw \ -sOutputFile=- \ -g%(xSize)sx%(ySize)s \ -r%(workDPI)s \ -q -dNOPAUSE %(file)s.ps < /dev/null | \ pnmscale %(reductionRatio)s | \ pnmcrop -white | \ pnmmargin -white %(margin)s | \ ppmquant 256 | \ ppmtogif -interlace %(transparentOption)s - \ > %(file)s.gif rm -f %(file)s.log %(file)s.aux %(file)s.dvi %(file)s.ps ''' detailRatio = 3.0 dpi = 78 margin = 1 rotate = 0 transparent = 2 xSizeInch = 12 ySizeInch = 12 file = '' opts, args = getopt.getopt(sys.argv[1:], 'p:d:m:r:t:h:u', ['detail_ratio=', 'dpi=', 'margin=', 'rotate=', 'transparent=', 'usage', 'help']) file = string.split(args[0], '.')[0] for opt, arg in opts: if opt in ('-h', '--help', '-u', '--usage'): print usage sys.exit() if opt in ("-p", "--detail_ratio"): detailRatio = float(arg) if opt in ("-d", "--dpi"): dpi = float(arg) if opt in ("-m", "--margin"): margin = float(arg) if opt in ("-r", "--rotate"): rotate = int(arg) if opt in ("-t", "--transparent"): transparent = int(arg) def tex2gif(): fillIn = globals() fillIn['workDPI'] = detailRatio*dpi fillIn['reductionRatio'] = 1.0/detailRatio fillIn['xSize'] = int(fillIn['workDPI'] * xSizeInch) fillIn['ySize'] = int(fillIn['workDPI'] * ySizeInch) fillIn['transparentOption'] = '' import popen2 print popen2.popen2(command %fillIn)[0].read() tex2gif() -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management From urnerk@qwest.net Wed Sep 5 07:04:08 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 04 Sep 2001 23:04:08 -0700 Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <5.1.0.14.2.20010904155655.037c0228@mail.cbu.edu> References: <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservi ces.net> <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Message-ID: <4.2.0.58.20010904230002.00bd1e20@pop3.norton.antivirus> "Stephan Richter" <srichter@cbu.edu> posted: >tex2gif() OK, I get it. Somehow I was thinking Python would be doing the TeX-to-GIF processing, i.e. using PIL or something like that, but the necessary tools are already provided in this case with gs, dvi etc. and Python's job is really just to build the requisite command lines and pass 'em out to the Unix shell. It's acting trully as a scripting language here -- in its element (and in competition with Perl). Thanks for posting your code. Interesting to read. Kirby From dyoo@hkn.eecs.berkeley.edu Wed Sep 5 08:22:04 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 5 Sep 2001 00:22:04 -0700 (PDT) Subject: [Tutor] [Python-Help] FW: new page for Newbies (fwd) Message-ID: <Pine.LNX.4.21.0109050021470.15965-100000@hkn.eecs.berkeley.edu> ---------- Forwarded message ---------- Date: Wed, 5 Sep 2001 00:35:31 -0400 From: Tim Peters <tim.one@home.com> To: PythonHelp <python-help@python.org> Subject: [Python-Help] FW: new page for Newbies FYI, in case you missed it elsewhere. -----Original Message----- From: python-list-admin@python.org [mailto:python-list-admin@python.org]On Behalf Of Guido van Rossum Sent: Tuesday, September 04, 2001 11:35 PM To: python-announce@python.org; python-list@python.org; python-dev@python.org Subject: new page for Newbies I finally broke down and created a new page collecting the most important resources for newbies (people who are new at programming): http://www.python.org/doc/Newbies.html We get several emails per day from people asking how to get started, so I figured this definitely serves a need. Please help us making this a better resource -- send your ideas for making the page more effective to webmaster@python.org. (Note: more effective could mean removing information as well as adding!) Please add this URL to other collections of links about Python. --Guido van Rossum (home page: http://www.python.org/~guido/) -- http://mail.python.org/mailman/listinfo/python-list _______________________________________________ Python-Help maillist - Python-Help@python.org http://mail.python.org/mailman/listinfo/python-help From tzuming@sanbi.ac.za Wed Sep 5 11:37:50 2001 From: tzuming@sanbi.ac.za (Tzu-Ming Chern) Date: Wed, 5 Sep 2001 12:37:50 +0200 (SAST) Subject: [Tutor] Sorting ranges Message-ID: <Pine.BSF.4.21.0109051235230.47492-100000@fling.sanbi.ac.za> Hi, does anyone know how to sort ranges in ascending order? Eg. 780=>1014 range 1 771=>1014 range 2 29=>214 range 3 226=>426 range 4 I would like my output to look like this: 29=>214 226=>426 771=>1014 780=>1014 With thanks, tzuming ****************************************************************************** Tzu-Ming Chern South African National Bioinformatics Institute University of Western Cape PO box X17 Bellville Cape Town South Africa Tel#:27-21-959-3908/3645 Fax:27-21-959-2512 Email:tzuming@fling.sanbi.ac.za ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ From GADGILP@INFOTECH.ICICI.com Wed Sep 5 12:49:10 2001 From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH) Date: Wed, 5 Sep 2001 17:19:10 +0530 Subject: [Tutor] [OT] what every programmer should know ? - a DDJ article related. .. Message-ID: <E1B786DCFA6ED511A0390008C7289E476352E0@ICICIBACK3> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C13600.C67EE770 Content-Type: text/plain; charset="iso-8859-1" hello, A recent post abt being lost in programming world, reminded me of an article my friend had forwarded to me earlier. It was something published in Dr Dobbs Journal. It did help me quite a bit. So I thaught I should post it here. Pl. excuse me for OT post. I guess copyright etc will prevent me from mailing the article. Fortunately I could find the article on net. Check out the link, http://www.developercareers.com/ddj/articles/1997/9719/9719l/9719l.htm /prasad . -- "This e-mail message may contain confidential, proprietary or legally privileged information. It should not be used by anyone who is not the original intended recipient. If you have erroneously received this message, please delete it immediately and notify the sender. The recipient acknowledges that ICICI or its subsidiaries and associated companies (including ICICI Bank) "ICICI Group", are unable to exercise control or ensure or guarantee the integrity of/over the contents of the information contained in e-mail transmissions and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of ICICI Group. Before opening any attachments please check them for viruses and defects." ------_=_NextPart_001_01C13600.C67EE770 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Diso-8859-= 1"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 5.5.2653.12"> <TITLE>[OT] what every programmer should know ? - a DDJ article related...<= /TITLE> </HEAD> <BODY> <P><FONT SIZE=3D2>hello,</FONT> </P> <P><FONT SIZE=3D2>A recent post abt being lost in programming world, remind= ed me of an</FONT> <BR><FONT SIZE=3D2>article my friend had forwarded to me earlier. It was so= mething </FONT> <BR><FONT SIZE=3D2>published in Dr Dobbs Journal. It did help me quite a bi= t. So I thaught </FONT> <BR><FONT SIZE=3D2>I should post it here. Pl. excuse me for OT post.</FONT> </P> <P><FONT SIZE=3D2>I guess copyright etc will prevent me from mailing the ar= ticle. Fortunately </FONT> <BR><FONT SIZE=3D2>I could find the article on net.</FONT> </P> <P><FONT SIZE=3D2>Check out the link,</FONT> </P> <P><FONT SIZE=3D2><A HREF=3D"http://www.developercareers.com/ddj/articles/1= 997/9719/9719l/9719l.htm" TARGET=3D"_blank">http://www.developercareers.com= /ddj/articles/1997/9719/9719l/9719l.htm</A></FONT> </P> <P><FONT SIZE=3D2>/prasad</FONT> </P> <BR> <P><B><FONT SIZE=3D2>.. </FONT></B> </P> <P> <FONT FACE=3D"Zurich BT" SIZE=3D1 COLOR=3D"#0000ff"><P>"This e-mail message= may contain confidential, proprietary or legally privileged information. I= t should not be used by anyone who is not the original intended recipient. = If you have erroneously received this message, please delete it immediately= and notify the sender. The recipient acknowledges that ICICI or its subsid= iaries and associated companies (including ICICI Bank) "ICICI Group", are u= nable to exercise control or ensure or guarantee the integrity of/over the = contents of the information contained in e-mail transmissions and further a= cknowledges that any views expressed in this message are those of the indiv= idual sender and no binding nature of the message shall be implied or assum= ed unless the sender does so expressly with due authority of ICICI Group. B= efore opening any attachments please check them for viruses and defects."</= P> </FONT> </BODY> </HTML> ------_=_NextPart_001_01C13600.C67EE770-- From csmith@blakeschool.org Wed Sep 5 13:04:50 2001 From: csmith@blakeschool.org (Christopher Smith) Date: Wed, 05 Sep 2001 07:04:50 -0500 Subject: [Tutor] Re: Sorting ranges In-Reply-To: <E15ebEs-0005U5-00@mail.python.org> References: <E15ebEs-0005U5-00@mail.python.org> Message-ID: <fc.004c4b6b007a08973b9aca00f1d021f0.7a089b@blakeschool.org> tzuming wrote: > >does anyone know how to sort ranges in ascending order? Eg. > >780=>1014 range 1 >771=>1014 range 2 >29=>214 range 3 >226=>426 range 4 > >I would like my output to look like this: > >29=>214 >226=>426 >771=>1014 >780=>1014 > Just create a list of these ranges and sort them: >>> r1=range(780,1015) >>> r2=range(771,1015) >>> r3=range(29,215) >>> r4=range(226,427) >>> all=[r1,r2,r3,r4] #here is the list of ranges >>> all.sort() #here we sort them >>> for a in all: ... print a[0:2],'...' ... [29, 30] ... [226, 227] ... [771, 772] ... [780, 781] ... >>> /c From srichter@cbu.edu Wed Sep 5 13:33:51 2001 From: srichter@cbu.edu (Stephan Richter) Date: Wed, 05 Sep 2001 07:33:51 -0500 Subject: [Tutor] Python Tool for converting TeX to GIF In-Reply-To: <4.2.0.58.20010904230002.00bd1e20@pop3.norton.antivirus> References: <5.1.0.14.2.20010904155655.037c0228@mail.cbu.edu> <Pine.LNX.4.33.0109041344550.726-100000@terbidium.openservi ces.net> <5.1.0.14.2.20010904120831.0349fd60@mail.cbu.edu> Message-ID: <5.1.0.14.2.20010905072822.037d5670@mail.cbu.edu> >It's acting trully as a scripting language here -- in >its element (and in competition with Perl). In fact this is almost the same idea of the Perl tex2gif version. Most of the code (the commands) I got from a shell script called ps2gif. Do it is really a mix of a lot of things. :-) In the beginning I wanted to let PIL handle the PS2GIF conversion, but there was no anti-aliasing support, so I went with the GS solution. BTW, I was able abstract it all a little and make a class. I incorporated it all into Zope and I can now generate on the fly GIFs on any Web Site. This is truly nice for science. Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management From kev@sat.net Wed Sep 5 13:49:23 2001 From: kev@sat.net (Kevin McCormick) Date: Wed, 05 Sep 2001 07:49:23 -0500 Subject: [Tutor] wxPython GUI builder References: <006001c132a0$f8408a60$a800a8c0@orange> <20010901091557.G13154@harmony.cs.rit.edu> <3B921EDA.95AE81@sat.net> <20010902222353.A14093@harmony.cs.rit.edu> <3B938517.7DECFD11@sat.net> <20010904141714.G17060@harmony.cs.rit.edu> Message-ID: <3B961F53.FAE4B43B@sat.net> dman wrote: > > On Mon, Sep 03, 2001 at 08:26:47AM -0500, Kevin McCormick wrote: > | dman wrote: > ... > | > Could you give an example of what you are trying to do and why it > | > doesn't work? > ... > | An example of what I am doing: > [long story :-)] > > By "example of what you are trying to do" I meant, could you post some > code and the console output when you try and run it. Seeing the error > messages you get would help to figure out what your problem is and how > to solve it :-). > > Have you gotten it to work over the weekend? > > -D > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor Thanks for the response. It works and I don't have output errors. So my problem is in knowing how to structure Tk widget classes into a program. I was thinking that I should make a menu class which imports all the widget classes, so that the menu functions would have "import dialogwidget" as their first line. I'll try that. From dsh8290@rit.edu Wed Sep 5 15:51:59 2001 From: dsh8290@rit.edu (dman) Date: Wed, 5 Sep 2001 10:51:59 -0400 Subject: [Tutor] Running python scripts without installing python In-Reply-To: <3B95A84E.672BE63E@home.com>; from chikitychina@home.com on Wed, Sep 05, 2001 at 12:21:34AM -0400 References: <3B95A84E.672BE63E@home.com> Message-ID: <20010905105159.D17823@harmony.cs.rit.edu> On Wed, Sep 05, 2001 at 12:21:34AM -0400, Pablo Manzanera wrote: | Hey all, | | Just a quick question for all you Windows Pythoners... | | What is the best way to run python scripts on Windows machines that do | not have Python installed? Install python. *grin* There are some tools ('py2exe' and Gordon MacMillan's 'installer') that will take your python source and pack it up with the interpreter to try and make it easier for your end users to install python *and* your program, but the long and short of it is you need a python interpreter to interpret python code. HTH, -D From alan.gauld@bt.com Wed Sep 5 15:59:03 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 5 Sep 2001 15:59:03 +0100 Subject: [Tutor] Matrix Read-in and Inversion Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF22@mbtlipnt02.btlabs.bt.co.uk> > csv's are easy, just use string.split. Careful, that won't work for string fields containing embedded commas. You need to split out quoted foelds first then split the remaining fields by commas... There are a few other niceties that can trip you up with CSV too but quoted fields are the worst and most common nasty. Alan G From jeff@ccvcorp.com Wed Sep 5 17:24:25 2001 From: jeff@ccvcorp.com (Jeff Shannon) Date: Wed, 05 Sep 2001 09:24:25 -0700 Subject: [Tutor] Sorting ranges References: <E15ebEt-0005UH-00@mail.python.org> Message-ID: <3B9651B9.D8C15541@ccvcorp.com> > does anyone know how to sort ranges in ascending order? Eg. .... How are you storing your ranges, and how do you want them sorted? If you're storing them as a tuple of (start,end), or as a list of either [start,end] or full range (i.e., the result of range(start,end) ), then you should be able to put all of them in a list sort that--list.sort() will sort by the value of the first item. In other words, >>> myranges = [ (780,1014), (771,1014), (29,214), (226,426) ] >>> myranges.sort() >>> print myranges [(29, 214), (226, 426), (771, 1014), (780, 1014)] >>> myranges = [ range(780,1014), range(771,1014), range(29,214), range(226,426) ] >>> myranges.sort() >>> for r in myranges: print r[0], r[-1] ... 29 213 226 425 771 1013 780 1013 >>> Jeff Shannon Technician/Programmer Credit International From Charlie@begeistert.org Wed Sep 5 18:40:23 2001 From: Charlie@begeistert.org (Charlie Clark) Date: Wed, 05 Sep 2001 19:40:23 +0200 Subject: [Tutor] Help with cookies Message-ID: <999711623_PM_BeOS.Charlie@begeistert.org> Dear Python gurus and those who want to become such, I need to be able to pass a cookie in a url request. I know what the cookie should contain and inspection of the cookie module and documentation indicates that handling cookies should be straightforward but the example does not include sending one in an url request. Has anyone experience of this and ideas on how this might be done. Many thanx Charlie (bashing his head on a brick wall again) From python.tutorial@jarava.org Wed Sep 5 18:55:02 2001 From: python.tutorial@jarava.org (Javier JJ) Date: Wed, 5 Sep 2001 19:55:02 +0200 Subject: [Tutor] Why I'm learning Python (OT and long) References: <Pine.GSO.4.21L1.0109040946090.4800-100000@sunny> Message-ID: <010a01c13633$e6171930$0124a8c0@uno> ----- Mensaje original ----- De: "Bill Tolbert" <bill_tolbert@bigfoot.com> Para: <tutor@python.org> Enviado: martes, 04 de septiembre de 2001 15:53 Asunto: Re: [Tutor] Why I'm learning Python (OT and long) > Thanks to all for the encouragement. You guys are great. I guess I've > only been at this about 5 years now. If I stick with it I may know > something by the time I retire.... > > Bill > Hey!! With a bit of luck, at the speed that things change in the computing world, what you learn may get to be obsolete by the time you retire <sigh> (looking at the DR-DOS box and MS-DOS manuals sitting on a corner, together with the CP/M disks :-)) Javier ---- He who laughs last is S-L-O-W. From deliberatus@my995internet.com Wed Sep 5 19:36:01 2001 From: deliberatus@my995internet.com (Kirk Bailey) Date: Wed, 05 Sep 2001 14:36:01 -0400 Subject: [Tutor] subscribe Message-ID: <3B967091.AF251B7D@my995internet.com> subscribe -- -Kirk D Bailey end _ __ _ _ ____ ____ _ _ | |/ /(_) _ __ | | __ | _ \ | __ ) __ _ (_)| | ___ _ _ | ' / | || '__|| |/ / | | | | | _ \ / _` || || | / _ \| | | | | . \ | || | | < | |_| |_ | |_) || (_| || || || __/| |_| | |_|\_\|_||_| |_|\_\ |____/(_) |____/ \__,_||_||_| \___| \__, | |___/ http://www.howlermonkey.net http://www.tampabaydevival.org ____ _ _ _ / ___| ___ _ __ ___ _ _ | || |_ (_) _ __ __ _ | | / _ \ | '_ \ / __|| | | || || __|| || '_ \ / _` | | |___| (_) || | | |\__ \| |_| || || |_ | || | | || (_| | \____|\___/ |_| |_||___/ \__,_||_| \__||_||_| |_| \__, | |___/ mailto:deliberatus@howlermonkey.net mailto:deliberatus@my995internet.com _____ _ _ _ ____ _ |_ _|| |__ ___ _ _ __ _ | |__ | |_ | __ ) ___ _ __ ___ | |__ ___ _ __ | | | '_ \ / _ \ | | | | / _` || '_ \ | __|| _ \ / _ \ | '_ ` _ \ | '_ \ / _ \| '__| | | | | | || (_) || |_| || (_| || | | || |_ | |_) || (_) || | | | | || |_) || __/| | |_| |_| |_| \___/ \__,_| \__, ||_| |_| \__||____/ \___/ |_| |_| |_||_.__/ \___||_| |___/ From dyoo@hkn.eecs.berkeley.edu Wed Sep 5 19:40:38 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 5 Sep 2001 11:40:38 -0700 (PDT) Subject: [Tutor] Help with cookies In-Reply-To: <999711623_PM_BeOS.Charlie@begeistert.org> Message-ID: <Pine.LNX.4.21.0109051132170.24366-100000@hkn.eecs.berkeley.edu> On Wed, 5 Sep 2001, Charlie Clark wrote: > I need to be able to pass a cookie in a url request. I know what the > cookie should contain and inspection of the cookie module and > documentation indicates that handling cookies should be > straightforward but the example does not include sending one in an url > request. Has anyone experience of this and ideas on how this might be > done. I have a silly example of one here: http://hkn.eecs.berkeley.edu/~dyoo/python/cookiecounter.py The important thing is that we send off the cookie before any of the other headers: otherwise, the browser will ignore the cookie. I think that the RFC says something to this effect here: http://home.netscape.com/newsref/std/cookie_spec.html There should be some other examples of cookies on Useless Python. http://www.lowerstandard.com/python/pythonsource.html Hmmm... it might be nice if we had a small searching facility for Useless Python --- it's getting big! *grin* From jerryl@europa.com Wed Sep 5 19:53:32 2001 From: jerryl@europa.com (Jerry Lake) Date: Wed, 5 Sep 2001 11:53:32 -0700 Subject: [Tutor] OverFlowError In-Reply-To: <Pine.LNX.4.21.0109051132170.24366-100000@hkn.eecs.berkeley.edu> Message-ID: <000001c1363c$10993be0$0103670a@europa.com> in my python2.1 install on win98 I'm having a problem generating numbers past approx. 500,000,000,000 I keep getting an OverFlowError, what if anything can I do to increase this value just in case I need to raise 9 to the 11th power ;) Regards, Jerry Lake Interface Engineering Technician From dyoo@hkn.eecs.berkeley.edu Wed Sep 5 19:52:51 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 5 Sep 2001 11:52:51 -0700 (PDT) Subject: [Tutor] Sorting ranges In-Reply-To: <Pine.BSF.4.21.0109051235230.47492-100000@fling.sanbi.ac.za> Message-ID: <Pine.LNX.4.21.0109051144510.24366-100000@hkn.eecs.berkeley.edu> On Wed, 5 Sep 2001, Tzu-Ming Chern wrote: > does anyone know how to sort ranges in ascending order? Eg. > > 780=>1014 range 1 > 771=>1014 range 2 > 29=>214 range 3 > 226=>426 range 4 > > I would like my output to look like this: > > 29=>214 > 226=>426 > 771=>1014 > 780=>1014 Hello! I'm guessing that: ### 29=>214 226=>426 771=>1014 780=>1014 ### is a sample of what a user can type into your program, since '=>' is not part of Python syntax. Can you explain a little more what you mean by "range"? The reason I'm asking is because Python uses the word "range" to mean a sequence of numbers: ### >>> range(0, 10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ### so that might be causing some language confusion --- what we think of "ranges" might be different from what you're thinking of. Do you mean "pairs of numbers" instead? That is, are you trying to sort: ### [(780, 1014), (771, 1014), (29, 214), (226, 426)] ### Just want to make sure we understand the problem better. From ak@silmarill.org Wed Sep 5 20:01:53 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Wed, 05 Sep 2001 15:01:53 -0400 Subject: [Tutor] OverFlowError In-Reply-To: <000001c1363c$10993be0$0103670a@europa.com> References: <Pine.LNX.4.21.0109051132170.24366-100000@hkn.eecs.berkeley.edu> <000001c1363c$10993be0$0103670a@europa.com> Message-ID: <20010905150153.A23360@sill.silmarill.org> On Wed, Sep 05, 2001 at 11:53:32AM -0700, Jerry Lake wrote: > in my python2.1 install on win98 > I'm having a problem generating numbers > past approx. 500,000,000,000 > I keep getting an OverFlowError, what if > anything can I do to increase this value > just in case I need to raise 9 to the 11th power ;) > > Regards, > > Jerry Lake > Interface Engineering Technician I haven't used it myself, but I think NumPy can do that (you can google for it). > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From ignacio@openservices.net Wed Sep 5 20:07:24 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 5 Sep 2001 15:07:24 -0400 (EDT) Subject: [Tutor] OverFlowError In-Reply-To: <000001c1363c$10993be0$0103670a@europa.com> Message-ID: <Pine.LNX.4.33.0109051505460.726-100000@terbidium.openservices.net> On Wed, 5 Sep 2001, Jerry Lake wrote: > in my python2.1 install on win98 > I'm having a problem generating numbers > past approx. 500,000,000,000 > I keep getting an OverFlowError, what if > anything can I do to increase this value > just in case I need to raise 9 to the 11th power ;) > > Regards, > > Jerry Lake > Interface Engineering Technician Use long integers like 2L or 516L or 28364543610936237528791274591817364136L. I'd tell you what their maximum value is, but your hard drive would fill up, your computer would melt, and your brain would explode ;) -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From fallen@leveltwo.com Thu Sep 6 00:10:55 2001 From: fallen@leveltwo.com (Fred Allen) Date: Wed, 5 Sep 2001 16:10:55 -0700 Subject: [Tutor] Browser-based Python Interpreter Message-ID: <4BB02C541824D311921600902765DB7B44583B@LTISERVER> I would like to find a Python interpreter that is adapted to operate independently via a browser, e.g. IE5.0. To be clearer, I mean a Python facility akin to the “Java Runtime Environment.” It seems I've encountered references to such facilities several times, but, now, cannot find them. With thanks in advance for any's efforts, I am, Respectfully, Fred Allen From dsh8290@rit.edu Thu Sep 6 01:26:41 2001 From: dsh8290@rit.edu (dman) Date: Wed, 5 Sep 2001 20:26:41 -0400 Subject: [Tutor] Browser-based Python Interpreter In-Reply-To: <4BB02C541824D311921600902765DB7B44583B@LTISERVER>; from fallen@leveltwo.com on Wed, Sep 05, 2001 at 04:10:55PM -0700 References: <4BB02C541824D311921600902765DB7B44583B@LTISERVER> Message-ID: <20010905202641.D18539@harmony.cs.rit.edu> On Wed, Sep 05, 2001 at 04:10:55PM -0700, Fred Allen wrote: | I would like to find a Python interpreter that is adapted to operate | independently via a browser, e.g. IE5.0. To be clearer, I mean a Python | facility akin to the Java Runtime Environment. It seems I've | encountered references to such facilities several times, but, now, | cannot find them. With thanks in advance for any's efforts, I am, I'm not sure exactly what you mean by that -- the "Java Runtime Environment" is a fancy way of saying "Java interpreter". It is no different than the python interpreter, except that it interprets java bytcodes, not python source and bytecodes. If you are looking for a way to write "java applets" in Python then that is a little different. The only special thing about Java is that IE, Netscape, etc, have Java interpreters built in to them and the <applet> tag is specified. You could do the same thing with python, but first you would need to convince web browser developers to include a python interpreter and you would need to convince end-users to upgrade. Instead of that you can use Jython. Jython is a python interpreter that is written in Java so it runs in a JVM. It is a little bit more restrictive -- you can't use any C extension modules, but it provides immediate access to all Java libraries. You can write (in python) a subclass of java.applet.Applet and compile the source to java bytecode which your users can download and run in the JVM already bundled with their web browser. -D From pythonpython@hotmail.com Thu Sep 6 07:38:43 2001 From: pythonpython@hotmail.com (HY) Date: Thu, 6 Sep 2001 15:38:43 +0900 Subject: [Tutor] What is the best way to count the number of lines in a huge file? Message-ID: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> What is the best way to count the number of lines in a huge file? Say, I have a file which is 15MB in size. I used: file=open("data.txt","r") n=0 for line in file.xreadlines(): n+=0 print n Is there a better/simpler way to do it? Thanks a lot. Hy From ignacio@openservices.net Thu Sep 6 07:50:04 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 02:50:04 -0400 (EDT) Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> Message-ID: <Pine.LNX.4.33.0109060247030.27144-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, HY wrote: > What is the best way to count the number of lines in a huge file? > Say, I have a file which is 15MB in size. > I used: > > file=open("data.txt","r") > n=0 > for line in file.xreadlines(): > n+=0 > print n > > Is there a better/simpler way to do it? > > Thanks a lot. > > Hy a=None n=0 while not a=='': a=file.read(262144) # season to taste n+=a.count('\n') -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From ppathiyi@cisco.com Thu Sep 6 08:06:38 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Thu, 6 Sep 2001 12:36:38 +0530 Subject: [Tutor] What is the best way to count the number of lines in a huge file? References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> Message-ID: <068001c136a2$793c95a0$37ef87c0@ppathiyipc> Hi, May be you can execute the Unix "wc -l" command using the popen2 command. stdout, stdin = popen2.popen2("wc -l <filename>") print stdout.read() -Praveen. ----- Original Message ----- From: "HY" <pythonpython@hotmail.com> To: <Tutor@python.org> Sent: Thursday, September 06, 2001 12:08 PM Subject: [Tutor] What is the best way to count the number of lines in a huge file? > What is the best way to count the number of lines in a huge file? > Say, I have a file which is 15MB in size. > I used: > > file=open("data.txt","r") > n=0 > for line in file.xreadlines(): > n+=0 > print n > > Is there a better/simpler way to do it? > > Thanks a lot. > > Hy > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From pythonpython@hotmail.com Thu Sep 6 08:28:42 2001 From: pythonpython@hotmail.com (HY) Date: Thu, 6 Sep 2001 16:28:42 +0900 Subject: [Tutor] What is the best way to count the number of lines in a huge file? References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> <068001c136a2$793c95a0$37ef87c0@ppathiyipc> Message-ID: <OE26m9t0CI76rOJhKPc000064e2@hotmail.com> Thanks for your respond. Great idea! What if I want to use it on both Unix and Windows? Is there a platform independent way to do it? Hy ----- Original Message ----- From: "Praveen Pathiyil" <ppathiyi@cisco.com> To: "HY" <pythonpython@hotmail.com>; <Tutor@python.org> Sent: Thursday, September 06, 2001 4:06 PM Subject: Re: [Tutor] What is the best way to count the number of lines in a huge file? > Hi, > > May be you can execute the Unix "wc -l" command using the popen2 command. > > stdout, stdin = popen2.popen2("wc -l <filename>") > print stdout.read() > > -Praveen. > > ----- Original Message ----- > From: "HY" <pythonpython@hotmail.com> > To: <Tutor@python.org> > Sent: Thursday, September 06, 2001 12:08 PM > Subject: [Tutor] What is the best way to count the number of lines in a huge > file? > > > > What is the best way to count the number of lines in a huge file? > > Say, I have a file which is 15MB in size. > > I used: > > > > file=open("data.txt","r") > > n=0 > > for line in file.xreadlines(): > > n+=0 > > print n > > > > Is there a better/simpler way to do it? > > > > Thanks a lot. > > > > Hy > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From scarblac@pino.selwerd.nl Thu Sep 6 09:25:17 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 6 Sep 2001 10:25:17 +0200 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com>; from pythonpython@hotmail.com on Thu, Sep 06, 2001 at 03:38:43PM +0900 References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> Message-ID: <20010906102516.A30764@pino.selwerd.nl> On 0, HY <pythonpython@hotmail.com> wrote: > What is the best way to count the number of lines in a huge file? > Say, I have a file which is 15MB in size. That's not huge :) On new PCs I'd just read it all in and count the \n's, but I'll assume here that we can't do that. > I used: > > file=open("data.txt","r") > n=0 > for line in file.xreadlines(): > n+=0 > print n > > Is there a better/simpler way to do it? Well, this one works and is quite simple. Look no further unless its performance is unacceptable. I like Ignacio's solution best: read the file in chunks of acceptable size, and count the '\n' characters. Don't see how it can be more efficient than that. -- Remco Gerlich From dsh8290@rit.edu Thu Sep 6 14:00:56 2001 From: dsh8290@rit.edu (dman) Date: Thu, 6 Sep 2001 09:00:56 -0400 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <Pine.LNX.4.33.0109060247030.27144-100000@terbidium.openservices.net>; from ignacio@openservices.net on Thu, Sep 06, 2001 at 02:50:04AM -0400 References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> <Pine.LNX.4.33.0109060247030.27144-100000@terbidium.openservices.net> Message-ID: <20010906090056.A20827@harmony.cs.rit.edu> On Thu, Sep 06, 2001 at 02:50:04AM -0400, Ignacio Vazquez-Abrams wrote: | On Thu, 6 Sep 2001, HY wrote: | | > What is the best way to count the number of lines in a huge file? | > Say, I have a file which is 15MB in size. | > I used: | > | > file=open("data.txt","r") | > n=0 | > for line in file.xreadlines(): | > n+=0 | > print n | > | > Is there a better/simpler way to do it? | > | > Thanks a lot. | > | > Hy | | a=None | n=0 | while not a=='': | a=file.read(262144) # season to taste | n+=a.count('\n') Just beware of Mac's. You won't find a single \n in a Mac text file because they use \r instead. FYI in case you have to deal with a text file that came from a Mac. -D From ignacio@openservices.net Thu Sep 6 14:07:08 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 09:07:08 -0400 (EDT) Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <20010906090056.A20827@harmony.cs.rit.edu> Message-ID: <Pine.LNX.4.33.0109060905590.17605-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, dman wrote: > On Thu, Sep 06, 2001 at 02:50:04AM -0400, Ignacio Vazquez-Abrams wrote: > | On Thu, 6 Sep 2001, HY wrote: > | > | > What is the best way to count the number of lines in a huge file? > | > Say, I have a file which is 15MB in size. > | > I used: > | > > | > file=open("data.txt","r") > | > n=0 > | > for line in file.xreadlines(): > | > n+=0 > | > print n > | > > | > Is there a better/simpler way to do it? > | > > | > Thanks a lot. > | > > | > Hy > | > | a=None > | n=0 > | while not a=='': > | a=file.read(262144) # season to taste > | n+=a.count('\n') > > Just beware of Mac's. You won't find a single \n in a Mac text file > because they use \r instead. FYI in case you have to deal with a text > file that came from a Mac. > > -D Fair enough: --- a=None n=0 while not a='': a=file.read(262144) n+=a.count(os.linesep) --- -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From alan.gauld@bt.com Thu Sep 6 14:48:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 6 Sep 2001 14:48:25 +0100 Subject: [Tutor] Sorting ranges Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20F6E69F0@mbtlipnt02.btlabs.bt.co.uk> > does anyone know how to sort ranges in ascending order? Nope, not even without Python. What happens if the ranges overlap? What if one range is a subset of another? Eg. > 780=>1014 range 1 > 771=>1014 range 2 > I would like my output to look like this: > 771=>1014 > 780=>1014 OK, This implies you want the size of the first element to be the determining factor in which case you could define your own comparison function (__cmp__() I guess?) and just compare range1[0] with range2[0]... You can then pass that as an extra parameter to the standard cmp function if I recall correctly. Theres definitely a way of doing that once you know how to write the __cmp__ bit. Alan g From alan.gauld@bt.com Thu Sep 6 15:10:20 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 6 Sep 2001 15:10:20 +0100 Subject: [Tutor] Browser-based Python Interpreter Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF25@mbtlipnt02.btlabs.bt.co.uk> > facility akin to the "Java Runtime Environment." There are only two options that I know of: 1) Grail, an unmaintained web browser written entirely(?) in Python with an embedded interpreter. 2) Use Jython and compile to classes. This produced standard java applets that you can reference and run pretty much as any other Java applet. But you write them in Python. THe 3rd option is not quite the same which is (on Windows at least) to install the Active Scripting support for Python and this then allows you to embed Python in a web page in the same way as Javascript. Personally I'd go the Jython route, not least because there's a bigger support community! Alan g From alan.gauld@bt.com Thu Sep 6 15:13:47 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 6 Sep 2001 15:13:47 +0100 Subject: [Tutor] What is the best way to count the number of lines in a huge file? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF26@mbtlipnt02.btlabs.bt.co.uk> > What is the best way to count the number of lines in a huge file? If on *nix try: import os print os.popen("wc -l bigfile.txt") > file=open("data.txt","r") > n=0 > for line in file.xreadlines(): > n+=0 assuming you mean n+=1 thats about the best I can think of. Alan G From scarblac@pino.selwerd.nl Thu Sep 6 15:22:22 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 6 Sep 2001 16:22:22 +0200 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <20010906090056.A20827@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, Sep 06, 2001 at 09:00:56AM -0400 References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> <Pine.LNX.4.33.0109060247030.27144-100000@terbidium.openservices.net> <20010906090056.A20827@harmony.cs.rit.edu> Message-ID: <20010906162222.A31346@pino.selwerd.nl> On 0, dman <dsh8290@rit.edu> wrote: > On Thu, Sep 06, 2001 at 02:50:04AM -0400, Ignacio Vazquez-Abrams wrote: > | On Thu, 6 Sep 2001, HY wrote: > | > | > What is the best way to count the number of lines in a huge file? > | > Say, I have a file which is 15MB in size. > | > I used: > | > > | > file=open("data.txt","r") > | > n=0 > | > for line in file.xreadlines(): > | > n+=0 > | > print n > | > > | > Is there a better/simpler way to do it? > | > > | > Thanks a lot. > | > > | > Hy > | > | a=None > | n=0 > | while not a=='': > | a=file.read(262144) # season to taste > | n+=a.count('\n') > > Just beware of Mac's. You won't find a single \n in a Mac text file > because they use \r instead. FYI in case you have to deal with a text > file that came from a Mac. If the file is opened in text mode, then that is Python's problem (actually the C library's), not yours. From the Python side it all looks like \n, whatever the system. -- Remco Gerlich From xiaowp@chinaren.com Thu Sep 6 15:27:54 2001 From: xiaowp@chinaren.com (xiaowp) Date: Thu, 6 Sep 2001 22:27:54 +0800 (CST) Subject: [Tutor] How to use Chinese in pygtk. Message-ID: <5586162.999786474998.JavaMail.qmailuser@mlapp1.chinaren.com> Hello all, I'm writing a test tool in python and I select pygtk to buil the UI. Now, I have a question about internationalization: how can I display Chinese on pygtk's label? Thanks ahead! Best Regards, Gary ======================= xiaowp@chinaren.com 2001-09-06 ======================== _________________________________________________________ æœç‹é—ªç”µé‚®ä»¶ï¼Œå’±ä»¬ä¸è¦é’±ï¼ http://mail.sohu.com From sheila@thinkspot.net Thu Sep 6 15:39:05 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 07:39:05 -0700 Subject: [Tutor] How to use Chinese in pygtk. In-Reply-To: <5586162.999786474998.JavaMail.qmailuser@mlapp1.chinaren.com> References: <5586162.999786474998.JavaMail.qmailuser@mlapp1.chinaren.com> Message-ID: <27EDFE95A75@kserver.org> On Thu, 6 Sep 2001 22:27:54 +0800 (CST), xiaowp <xiaowp@chinaren.com> wrote about [Tutor] How to use Chinese in pygtk.: :Hello all, : I'm writing a test tool in python and I select pygtk to buil the UI. :Now, I have a question about internationalization: how can I display :Chinese on pygtk's label? : Thanks ahead! I recently was trying to do the same thing with some French letters. Are you planning to use Unicode? I found, here: http://www.unicode.org/charts/ That the latin-1 shows, for example, Ç with a code of 00C7 In Python, I can do this: >>> print '\xC7' Ç >>> To get the character displayed. So, find the Unicode codings for the characters you want, and print them like above?? I haven't worked with the Chinese charset, only a few simple French letters, so I'm not sure this is 100% applicable for your case. But maybe it will get you started in the right direction? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From rob@jam.rr.com Thu Sep 6 15:48:34 2001 From: rob@jam.rr.com (Rob) Date: Thu, 06 Sep 2001 09:48:34 -0500 Subject: [Tutor] Browser-based Python Interpreter References: <4BB02C541824D311921600902765DB7B44583B@LTISERVER> <20010905202641.D18539@harmony.cs.rit.edu> Message-ID: <3B978CC2.3020802@jam.rr.com> dman wrote: > On Wed, Sep 05, 2001 at 04:10:55PM -0700, Fred Allen wrote: | I > would like to find a Python interpreter that is adapted to operate | > independently via a browser, e.g. IE5.0. To be clearer, I mean a > Python | facility akin to the Java Runtime Environment. It seems > I've | encountered references to such facilities several times, > but, now, | cannot find them. With thanks in advance for any's > efforts, I am, > > I'm not sure exactly what you mean by that -- the "Java Runtime Environment" > is a fancy way of saying "Java interpreter". It is no different > than the python interpreter, except that it interprets java bytcodes, > not python source and bytecodes. > > If you are looking for a way to write "java applets" in Python then that > is a little different. The only special thing about Java is that IE, > Netscape, etc, have Java interpreters built in to them and the <applet> > tag is specified. You could do the same thing with python, but > first you would need to convince web browser developers to include a > python interpreter and you would need to convince end-users to upgrade. > Instead of that you can use Jython. Jython is a python interpreter > that is written in Java so it runs in a JVM. It is a little bit > more restrictive -- you can't use any C extension modules, but it > provides immediate access to all Java libraries. You can write (in > python) a subclass of java.applet.Applet and compile the source to java > bytecode which your users can download and run in the JVM already bundled > with their web browser. > > -D > > Although it's probably not even close to what you have in mind, I've seen that at least one of the projects known as Python Server Pages even allows you to make an interactive Python interpreter available via browser. With a clever bit of security, this could be a mighty handy thing to have around. Uselessly, Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From jeff@ccvcorp.com Thu Sep 6 17:31:58 2001 From: jeff@ccvcorp.com (Jeff Shannon) Date: Thu, 06 Sep 2001 09:31:58 -0700 Subject: [Tutor] Browser-based Python Interpreter References: <E15f1ae-0000JA-00@mail.python.org> Message-ID: <3B97A4FE.A97729C8@ccvcorp.com> > > facility akin to the "Java Runtime Environment." ... > THe 3rd option is not quite the same which is (on Windows > at least) to install the Active Scripting support for > Python and this then allows you to embed Python in a > web page in the same way as Javascript. Note that ActiveScript support is not only specific to Windows, it's specific to MSIE--Netscape does not (afaik) use the ActiveScripting engine. This also requires that every *client* have a Python interpreter installed, and set up to support ActiveScripting. This *should* be done automatically when installing ActiveState's ActivePython distribution, *or* when installing the win32all package on top of some other python distribution. It's actually pretty nice, but it doesn't work so well for WWW purposes, since it's so platform/browser specific. It can be great if you're on a small intranet where you *know* what your clients are, however. I've used it to write a "hypertext application" to automatically interact with a vendor's web scripts, using python as my scripting language (it's *so* much nicer than trying to do it all in VB! <wink>) Jeff Shannon Technician/Programmer Credit International From sheila@thinkspot.net Thu Sep 6 20:25:21 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 12:25:21 -0700 Subject: [Tutor] Unpickleable object error Message-ID: <384C2C017D0@kserver.org> OK, so I'm happy as a clam, shelving away my objects into a database hash file. I have this type of object: class user: def __init__(self, id, passwd, email, mssgList, lastmssg, caller = None): self.lockfile = MutexFile.MutexFile('userdb.lck') self.myfilename = 'users' self.id = id self.passwd = passwd self.email = email self.mssgList = mssgList self.lasmssg = lastmssg And another class, called mssgBoard, has this method: def addUser(self, user): user.lockfile.flock('LOCK_EX') userdb = shelve.open(user.myfilename, 'c') if not userdb.has_key(user.id): userdb[user.id] = user userdb.close() user.lockfile.flock('LOCK_UN') And I'm running my script, and debugging it, and (it's a cgi script) I get the typical 500 Internal Server error, and when I check my log files, this is the error message: Premature end of script headers: e:/apache/cgi-bin/pibby/init.py Traceback (most recent call last): File "e:\apache\cgi-bin\pibby\init.py", line 20, in ? mainBoard.addUser(admin) File "e:\apache\cgi-bin\pibby\pbbclass.py", line 34, in addUser userdb[user.id] = user File "E:\PYTHON\PYTHON21\lib\shelve.py", line 76, in __setitem__ p.dump(value) cPickle.UnpickleableError: Cannot pickle <type 'PyHANDLE'> objects So, I'm thinking either I can't pickle/shelve this data class, as I have defined it, or else I really don't know what the problem is. Does anyone have any suggestions on how to proceed? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From ignacio@openservices.net Thu Sep 6 20:44:19 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 15:44:19 -0400 (EDT) Subject: [Tutor] Unpickleable object error In-Reply-To: <384C2C017D0@kserver.org> Message-ID: <Pine.LNX.4.33.0109061541570.25741-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, Sheila King wrote: > class user: > def __init__(self, id, passwd, email, mssgList, lastmssg, caller = None): > self.lockfile = MutexFile.MutexFile('userdb.lck') > self.myfilename = 'users' > self.id = id > self.passwd = passwd > self.email = email > self.mssgList = mssgList > self.lasmssg = lastmssg > > [snip] > > So, I'm thinking either I can't pickle/shelve this data class, as I have defined > it, or else I really don't know what the problem is. > > Does anyone have any suggestions on how to proceed? I don't think that it likes that MutexFile.MutexFile object in user. Try pulling it out of there and putting it somewhere else in the code. -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From sheila@thinkspot.net Thu Sep 6 21:00:22 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 13:00:22 -0700 Subject: [Tutor] Unpickleable object error In-Reply-To: <Pine.LNX.4.33.0109061541570.25741-100000@terbidium.openservices.net> References: <384C2C017D0@kserver.org> <Pine.LNX.4.33.0109061541570.25741-100000@terbidium.openservices.net> Message-ID: <3A4DDDB66F7@kserver.org> On Thu, 6 Sep 2001 15:44:19 -0400 (EDT), Ignacio Vazquez-Abrams <ignacio@openservices.net> wrote about Re: [Tutor] Unpickleable object error: :I don't think that it likes that MutexFile.MutexFile object in user. Try :pulling it out of there and putting it somewhere else in the code. I don't think that is the problem, because before I introduced the user class, I was running this code without any problem (this is only a snippet of the code, of course): class mssgBoard: def __init__(self, dict=None, caller=None): self.lockfile = MutexFile.MutexFile('main.lck') self.myfilename = 'mainboard' if caller == 'init': try: self.lockfile.flock('LOCK_EX') db = shelve.open(self.myfilename, 'n') db['title'] = dict['title'].value db['adminID'] = dict['adminID'].value db['smtpserver'] = dict['smtpserver'].value db['exitURL'] = dict['exitURL'].value db['adminEmail'] = dict['email'].value db['threads'] = [] db.close() self.lockfile.flock('LOCK_UN') except KeyError, e: print header('Error in Message Board Init') print body('missing keys') Notice that it also has a MutexFile object, and it caused no problems in shelving that object. Code runs fine when I comment out the addUser function and the call to it. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Thu Sep 6 21:09:00 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 13:09:00 -0700 Subject: [Tutor] Unpickleable object error In-Reply-To: <384C2C017D0@kserver.org> References: <384C2C017D0@kserver.org> Message-ID: <3ACC07A6D45@kserver.org> On Thu, 06 Sep 2001 12:25:21 -0700, Sheila King <sheila@thinkspot.net> wrote about [Tutor] Unpickleable object error: :So, I'm thinking either I can't pickle/shelve this data class, as I have defined :it, or else I really don't know what the problem is. : :Does anyone have any suggestions on how to proceed? You know what...I just went back, removed the comments on the addUser function, and I caught a small spelling error in the user.__init__ function. Namely: self.lasmssg = lastmssg should have been self.lastmssg = lastmssg ^ (missing "t") And I can't see why that would have made any difference (as I never refer to it anywhere in the code, yet...) Anyhow, the code just ran without error, and just created the users database for me. I don't know why it worked now and not before. Go figure. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From vdbroekw@wxs.nl Thu Sep 6 22:21:21 2001 From: vdbroekw@wxs.nl (Walter van den Broek) Date: Thu, 06 Sep 2001 23:21:21 +0200 Subject: [Tutor] input problem ? Message-ID: <3B97E8D1.4E5BD86E@wxs.nl> Hi, Complete newbie here. >From a lot of patients we get data to obtain a diagnosis. To make it easier and more accurate i planned to put the obtained scores in a program to verify the diagnoses. >From the first two questions at least one has to have a score>4. If that is the case from the other 7 questions at least 4 have to score higher than four to become diagnosed as being severely depressed. I tried the following code to accomplish it, but became slightly "depressed" At first with the first two questions it worked well, appending the other questions delivered error messages Traceback (innermost last): File "<string>", line 1, in ? SyntaxError: can't assign to operator (dsm4.py, line 10) And this is the code: import string vraag_234 = input ( "Wat is de score bij vraag 234? ") vraag_326 = input ("Wat is de score bij vraag 326? ") vraag_317-321 = input ("Wat is de score bij vraag 317-321?") vraag_272-315 = input ("Wat is de score bij vraag 272-315?") vraag_334-343 = input ("Wat is de score bij vraag 334-343?") vraag_315 = input ("Wat is de score bij vraag 315?") vraag_240-242 = input ("Wat is de score bij vraag 240-242?") vraag_325 = input ("Wat is de score bij vraag 325?") vraag_246-250 = input ("Wat is de score bij vraag 246-250?") if (vraag_234 > 4) or (vraag_326 > 4): print "Er kan sprake zijn van een depressie volgens DSM IV criteria" else: print "Er kan geen sprake zijn van een depressie volgens DSM IV criteria" List = [] if (vraag_317-321 > 4): List.append if (vraag_272-315 > 4): List.append if (vraag_334-343 > 4): List.append if (vraag_315 > 4 ): List.append if (vraag_240-242 > 4): List.append if (vraag_325 > 4): List.append if (vraag_246-250 > 4): List.append len(List) if len(List) > 4: print "Er is sprake van de depressieve stoornis volgens DSM IV criteria" else: print "Er is geen sprake van een depressieve stoornis volgens DSM IV criteria" Is there to much input?, should i make functions? >From the last 7 questions i decided to create a list of scores, append was usede if the score was higher than 4, so if i have more then 4 positive results (scores higher than 4) the diagnoses is confirmed Maybe a difficult try out but to me it is very usefull if it works Thanks, willing to learn Walter -- W.W. van den Broek vandenbroek@psyd.azr.nl URL: http://home.planet.nl/~vdbroekw Private email: vdbroekw@wxs.nl From sheila@thinkspot.net Thu Sep 6 21:12:26 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 13:12:26 -0700 Subject: [Tutor] Unpickleable object error Message-ID: <3AFE6A015F2@kserver.org> On Thu, 06 Sep 2001 13:09:00 -0700, Sheila King <sheila@thinkspot.net> wrote about Re: [Tutor] Unpickleable object error: :Anyhow, the code just ran without error, and just created the users :database for me. : :I don't know why it worked now and not before. Go figure. Argh! I take it back. Sorry, it's not working. (I had some indentation problem when I ran it this last time, and made it appear to work, when in fact it did not.) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From koen@behindthesofa.dhs.org Thu Sep 6 21:22:21 2001 From: koen@behindthesofa.dhs.org (Koen Bossers) Date: Thu, 06 Sep 2001 22:22:21 +0200 Subject: [Tutor] input problem ? References: <3B97E8D1.4E5BD86E@wxs.nl> Message-ID: <3B97DAFD.90901@behindthesofa.dhs.org> Walter van den Broek wrote: >Hi, >Complete newbie here. >>From a lot of patients we get data to obtain a diagnosis. >To make it easier and more accurate i planned to put the obtained scores >in a program to verify the diagnoses. >>From the first two questions at least one has to have a score>4. >If that is the case from the other 7 questions at least 4 have to score >higher than four to become diagnosed as being severely depressed. >I tried the following code to accomplish it, but became slightly >"depressed" >At first with the first two questions it worked well, appending the >other questions delivered error messages >Traceback (innermost last): > File "<string>", line 1, in ? >SyntaxError: can't assign to operator (dsm4.py, line 10) >And this is the code: >import string >vraag_234 = input ( "Wat is de score bij vraag 234? ") >vraag_326 = input ("Wat is de score bij vraag 326? ") >vraag_317-321 = input ("Wat is de score bij vraag 317-321?") >vraag_272-315 = input ("Wat is de score bij vraag 272-315?") >vraag_334-343 = input ("Wat is de score bij vraag 334-343?") >vraag_315 = input ("Wat is de score bij vraag 315?") > Change vraag_number-number to vraag_number_number (minus symbol cannot be used in keywords!) Cheers, Koen From ignacio@openservices.net Thu Sep 6 21:31:19 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 16:31:19 -0400 (EDT) Subject: [Tutor] Unpickleable object error In-Reply-To: <3A4DDDB66F7@kserver.org> Message-ID: <Pine.LNX.4.33.0109061629010.25741-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, Sheila King wrote: > class mssgBoard: > def __init__(self, dict=None, caller=None): > self.lockfile = MutexFile.MutexFile('main.lck') > self.myfilename = 'mainboard' > if caller == 'init': > try: > self.lockfile.flock('LOCK_EX') > db = shelve.open(self.myfilename, 'n') > db['title'] = dict['title'].value > db['adminID'] = dict['adminID'].value > db['smtpserver'] = dict['smtpserver'].value > db['exitURL'] = dict['exitURL'].value > db['adminEmail'] = dict['email'].value > db['threads'] = [] > db.close() > self.lockfile.flock('LOCK_UN') > except KeyError, e: > print header('Error in Message Board Init') > print body('missing keys') > > Notice that it also has a MutexFile object, and it caused no problems in > shelving that object. Right, but in this case it is not trying to shelve the MutexFile, whereas in the previous snippet it is. -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From sheila@thinkspot.net Thu Sep 6 21:56:04 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 06 Sep 2001 13:56:04 -0700 Subject: [Tutor] Unpickleable object error In-Reply-To: <Pine.LNX.4.33.0109061629010.25741-100000@terbidium.openservices.net> References: <3A4DDDB66F7@kserver.org> <Pine.LNX.4.33.0109061629010.25741-100000@terbidium.openservices.net> Message-ID: <3D7BD1843AE@kserver.org> On Thu, 6 Sep 2001 16:31:19 -0400 (EDT), Ignacio Vazquez-Abrams <ignacio@openservices.net> wrote about Re: [Tutor] Unpickleable object error: :Right, but in this case it is not trying to shelve the MutexFile, whereas in :the previous snippet it is. OK, good point. I removed the MutexFile from the object's data attributes, and you are correct: Now I can shelve it. I have a work around. I made it an attribute of the class, and not of an instance of the class. Thanks, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dyoo@hkn.eecs.berkeley.edu Thu Sep 6 22:06:54 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 6 Sep 2001 14:06:54 -0700 (PDT) Subject: [Tutor] Unpickleable object error In-Reply-To: <384C2C017D0@kserver.org> Message-ID: <Pine.LNX.4.21.0109061358180.19043-100000@hkn.eecs.berkeley.edu> On Thu, 6 Sep 2001, Sheila King wrote: > def __init__(self, id, passwd, email, mssgList, lastmssg, caller = None): > self.lockfile = MutexFile.MutexFile('userdb.lck') > self.myfilename = 'users' > self.id = id > self.passwd = passwd > self.email = email > self.mssgList = mssgList > self.lasmssg = lastmssg [some text cut] > Traceback (most recent call last): > File "e:\apache\cgi-bin\pibby\init.py", line 20, in ? > mainBoard.addUser(admin) > File "e:\apache\cgi-bin\pibby\pbbclass.py", line 34, in addUser > userdb[user.id] = user > File "E:\PYTHON\PYTHON21\lib\shelve.py", line 76, in __setitem__ > p.dump(value) > cPickle.UnpickleableError: Cannot pickle <type 'PyHANDLE'> objects I suspect it might have to do with the MutexFile object --- the error about a PyHANDLE sounds really specific to a Win32 thing: http://aspn.activestate.com/ASPN/Python/Reference/Products /ActivePython/PythonWin32Extensions/PyHANDLE.html and since you mentioned earlier that MutexFile tries to do things uniformly on Windows and Unix, that implies that MutexFile could be the source of the pickle bug. How are you implementing MutexFile? Can you check to see if you can pickle a MutexFile? If not, you may need to tell pickle not to touch your self.lockfile --- that is, you might need to give pickle some specific instructions when pickling/unpickling a MutexFile. Take a look at: http://www.python.org/doc/lib/module-pickle.html In particular, you might need to define __getstate__() and __setstate__() methods in either MutexFile or your userfile class to take this into account. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu Sep 6 22:10:31 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 6 Sep 2001 14:10:31 -0700 (PDT) Subject: [Tutor] How to use Chinese in pygtk. In-Reply-To: <5586162.999786474998.JavaMail.qmailuser@mlapp1.chinaren.com> Message-ID: <Pine.LNX.4.21.0109061407440.19043-100000@hkn.eecs.berkeley.edu> On Thu, 6 Sep 2001, xiaowp wrote: > Hello all, > I'm writing a test tool in python and I select pygtk to buil the UI. > Now, I have a question about internationalization: how can I display > Chinese on pygtk's label? According to the pygtk mailing list: http://www.daa.com.au/pipermail/pygtk/2000-November/000523.html Pygtk might not support Unicode yet; you may need to double check with the pygtk folks to see if this has been amended yet. You can ask them at: http://www.daa.com.au/mailman/listinfo/pygtk If you find out that you can get Chinese working in PyGtk, please tell us. Good luck to you! From dsh8290@rit.edu Thu Sep 6 22:11:23 2001 From: dsh8290@rit.edu (dman) Date: Thu, 6 Sep 2001 17:11:23 -0400 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <Pine.LNX.4.33.0109060905590.17605-100000@terbidium.openservices.net>; from ignacio@openservices.net on Thu, Sep 06, 2001 at 09:07:08AM -0400 References: <20010906090056.A20827@harmony.cs.rit.edu> <Pine.LNX.4.33.0109060905590.17605-100000@terbidium.openservices.net> Message-ID: <20010906171123.C22153@harmony.cs.rit.edu> On Thu, Sep 06, 2001 at 09:07:08AM -0400, Ignacio Vazquez-Abrams wrote: | On Thu, 6 Sep 2001, dman wrote: | > On Thu, Sep 06, 2001 at 02:50:04AM -0400, Ignacio Vazquez-Abrams wrote: | > | On Thu, 6 Sep 2001, HY wrote: <major snipage> | > | a=None | > | n=0 | > | while not a=='': | > | a=file.read(262144) # season to taste | > | n+=a.count('\n') | > | > Just beware of Mac's. You won't find a single \n in a Mac text file | > because they use \r instead. FYI in case you have to deal with a text | > file that came from a Mac. | | Fair enough: | | --- | a=None | n=0 | while not a='': | a=file.read(262144) | n+=a.count(os.linesep) | --- The only problem with this is it only (truly properly) counts the lines of files that were created with the same OS as the one counting. You'd probably want to use a regex to search for "\r\n|\r|\n", but it all depends on the source(s) of the files you want to count. Make your script "good enough", not "perfect according to some misty definition". :-). -D From tjenkins@devis.com Thu Sep 6 22:14:34 2001 From: tjenkins@devis.com (Tom Jenkins) Date: Thu, 06 Sep 2001 17:14:34 -0400 Subject: [Tutor] input problem ? References: <3B97E8D1.4E5BD86E@wxs.nl> Message-ID: <3B97E73A.3040306@devis.com> Hi Walter, Couple of problems here which are easily fixable... Walter van den Broek wrote: > Hi, > Complete newbie here. > From a lot of patients we get data to obtain a diagnosis. > To make it easier and more accurate i planned to put the obtained scores > in a program to verify the diagnoses. > From the first two questions at least one has to have a score>4. > If that is the case from the other 7 questions at least 4 have to score > higher than four to become diagnosed as being severely depressed. > I tried the following code to accomplish it, but became slightly > "depressed" > At first with the first two questions it worked well, appending the > other questions delivered error messages > Traceback (innermost last): > File "<string>", line 1, in ? > SyntaxError: can't assign to operator (dsm4.py, line 10) > And this is the code: > import string > vraag_234 = input ( "Wat is de score bij vraag 234? ") > vraag_326 = input ("Wat is de score bij vraag 326? ") > vraag_317-321 = input ("Wat is de score bij vraag 317-321?") > vraag_272-315 = input ("Wat is de score bij vraag 272-315?") > vraag_334-343 = input ("Wat is de score bij vraag 334-343?") > vraag_315 = input ("Wat is de score bij vraag 315?") > vraag_240-242 = input ("Wat is de score bij vraag 240-242?") > vraag_325 = input ("Wat is de score bij vraag 325?") > vraag_246-250 = input ("Wat is de score bij vraag 246-250?") > change the '-' to '_' in these variables... > if (vraag_234 > 4) or (vraag_326 > 4): > print "Er kan sprake zijn van een depressie volgens DSM IV criteria" > > else: > print "Er kan geen sprake zijn van een depressie volgens DSM IV > criteria" > > > > List = [] > if (vraag_317-321 > 4): > List.append > if (vraag_272-315 > 4): > List.append > if (vraag_334-343 > 4): > List.append > if (vraag_315 > 4 ): > List.append > if (vraag_240-242 > 4): > List.append > if (vraag_325 > 4): > List.append > if (vraag_246-250 > 4): > List.append > len(List) > if len(List) > 4: > print "Er is sprake van de depressieve stoornis volgens DSM IV > criteria" > > else: > print "Er is geen sprake van een depressieve stoornis volgens DSM IV > criteria" > Here you really don't need a list; you are counting the number of answers that are "positive results" (ie > 4). so lets just keep a running count... count = 0 if (vraag_317_321 > 4): count = count + 1 if (vraag_272_315 > 4): count = count + 1 if (vraag_334_343 > 4): count = count + 1 if (vraag_315 > 4 ): count = count + 1 if (vraag_240_242 > 4): count = count + 1 if (vraag_325 > 4): count = count + 1 if (vraag_246_250 > 4): count = count + 1 if count > 4: print "Er is sprake van de depressieve stoornis volgens DSM IV criteria" else: print "Er is geen sprake van een depressieve stoornis volgens DSM IV criteria" -- Tom Jenkins devIS - Development Infostructure http://www.devis.com From dsh8290@rit.edu Thu Sep 6 22:15:17 2001 From: dsh8290@rit.edu (dman) Date: Thu, 6 Sep 2001 17:15:17 -0400 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <20010906162222.A31346@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Sep 06, 2001 at 04:22:22PM +0200 References: <OE40E2q4x1s0h6F1nub00009dc9@hotmail.com> <Pine.LNX.4.33.0109060247030.27144-100000@terbidium.openservices.net> <20010906090056.A20827@harmony.cs.rit.edu> <"from dsh8290"@rit.edu> <20010906162222.A31346@pino.selwerd.nl> Message-ID: <20010906171517.D22153@harmony.cs.rit.edu> On Thu, Sep 06, 2001 at 04:22:22PM +0200, Remco Gerlich wrote: | On 0, dman <dsh8290@rit.edu> wrote: | > On Thu, Sep 06, 2001 at 02:50:04AM -0400, Ignacio Vazquez-Abrams wrote: | > | On Thu, 6 Sep 2001, HY wrote: <major snippage> | > | a=None | > | n=0 | > | while not a=='': | > | a=file.read(262144) # season to taste | > | n+=a.count('\n') | > | > Just beware of Mac's. You won't find a single \n in a Mac text file | > because they use \r instead. FYI in case you have to deal with a text | > file that came from a Mac. | | If the file is opened in text mode, then that is Python's problem (actually | the C library's), not yours. From the Python side it all looks like \n, | whatever the system. That's cool -- lines always end properly in python :-). Although I don't think that will work on a unix box -- "text" mode is no different from "binary" mode. I don't think this theory works on a windows box either, when opening a mac file. My reasoning is that I had to tweak an HTML file recently. I opened the file (first on the FreeBS web host) using vim -- it reported "noeol" and everything was on one huge line. I got the same effect when I copied it to my win2k workstation and opened it with vim. I used a little bit of substitution (I was going to use python which is why I copied the file to my windows box, but then I learned how to use vim's subsitute strings properly) to replace all \r with \n and make the file a "proper" (unix) text file. -D From bill_tolbert@bigfoot.com Thu Sep 6 22:20:56 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Thu, 6 Sep 2001 17:20:56 -0400 (EDT) Subject: [Tutor] sending stdout to a text box Message-ID: <Pine.GSO.4.21L1.0109061711520.10065-100000@sunny> Well, a week has gone by and I've got to give this thing another try. I have a script which works well; it sends messages to the console when run from a prompt. How can I catch this and route it to a text box in tkinter? I've read about the textvariable and StringVar() option but I can't get it to work. Text boxes don't support textvariable and I can't get the stdout to redirect to anything useful. Can someone help? Here's the code: #Adapted from TKTextDemo.py by Martin Stevens, budgester@budgester.com #Shamelessly lifted from Useless Python (www.lowerstandard.com/python) from Tkinter import * class App: ## Create GUI def __init__(self, master): frame = Frame(master) frame.pack() self.t = StringVar() # this line doesn't work #self.text_box = Text(frame, textvariable=self.t) self.text_box = Text(frame) self.text_box.pack() # this call to dobackup works but no redirect of stdout self.dobackup = Button(frame, text="Do Backup", command=self.backup) self.dobackup.pack(side=TOP) def backup(self): import ICAREBackup #self.t = sys.stdout #sys.stdout = self.t self.text_box.insert(END, sys.stdout) ICAREBackup.ICAREBackup() root = Tk() app = App(root) root.mainloop() =-=-=-=-=-=-=-=-= Bill Tolbert From ignacio@openservices.net Thu Sep 6 22:26:00 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 17:26:00 -0400 (EDT) Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <20010906171123.C22153@harmony.cs.rit.edu> Message-ID: <Pine.LNX.4.33.0109061723440.25741-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, dman wrote: > On Thu, Sep 06, 2001 at 09:07:08AM -0400, Ignacio Vazquez-Abrams wrote: > | Fair enough: > | > | --- > | a=None > | n=0 > | while not a='': > | a=file.read(262144) > | n+=a.count(os.linesep) > | --- > > The only problem with this is it only (truly properly) counts the > lines of files that were created with the same OS as the one > counting. > > You'd probably want to use a regex to search for "\r\n|\r|\n", but it > all depends on the source(s) of the files you want to count. > > Make your script "good enough", not "perfect according to some misty > definition". :-). > > -D Even using that RE (and in fact, of using the given code on Windows) is that the \r\n may straddle a 256k boundary, losing one line in the code, and gaining one with the RE. -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From dsh8290@rit.edu Thu Sep 6 22:33:18 2001 From: dsh8290@rit.edu (dman) Date: Thu, 6 Sep 2001 17:33:18 -0400 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <Pine.LNX.4.33.0109061723440.25741-100000@terbidium.openservices.net>; from ignacio@openservices.net on Thu, Sep 06, 2001 at 05:26:00PM -0400 References: <20010906171123.C22153@harmony.cs.rit.edu> <Pine.LNX.4.33.0109061723440.25741-100000@terbidium.openservices.net> Message-ID: <20010906173318.F22153@harmony.cs.rit.edu> On Thu, Sep 06, 2001 at 05:26:00PM -0400, Ignacio Vazquez-Abrams wrote: | On Thu, 6 Sep 2001, dman wrote: | > On Thu, Sep 06, 2001 at 09:07:08AM -0400, Ignacio Vazquez-Abrams wrote: | > | Fair enough: | > | | > | --- | > | a=None | > | n=0 | > | while not a='': | > | a=file.read(262144) | > | n+=a.count(os.linesep) | > | --- | > | > The only problem with this is it only (truly properly) counts the | > lines of files that were created with the same OS as the one | > counting. | > | > You'd probably want to use a regex to search for "\r\n|\r|\n", but it | > all depends on the source(s) of the files you want to count. | > | > Make your script "good enough", not "perfect according to some misty | > definition". :-). | | Even using that RE (and in fact, of using the given code on Windows) is that | the \r\n may straddle a 256k boundary, losing one line in the code, and | gaining one with the RE. Heh. I didn't even know windows had a 256k boundary. I always though that putting an extra character in the file was a bad idea ... (it also breaks ftell() and fseek()). Ken Thompson and Dennis Ritchie had more foresight than most ;-). A more robust technique would be to scout the file's contents first and determine whether it is *nix, 'doze or mac format and then search only for that particular line terminator. My regex would allow for a combination of line separators in a single file, which isn't a good idea. -D From ignacio@openservices.net Thu Sep 6 22:39:44 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 6 Sep 2001 17:39:44 -0400 (EDT) Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <20010906173318.F22153@harmony.cs.rit.edu> Message-ID: <Pine.LNX.4.33.0109061738230.25741-100000@terbidium.openservices.net> On Thu, 6 Sep 2001, dman wrote: > Heh. I didn't even know windows had a 256k boundary. I always though ? I meant the parameter passed to file.read() in my code (262144B=256KiB). -- Ignacio Vazquez-Abrams <ignacio@openservices.net> From alan.gauld@bt.com Thu Sep 6 22:37:35 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 6 Sep 2001 22:37:35 +0100 Subject: [Tutor] Browser-based Python Interpreter Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF2E@mbtlipnt02.btlabs.bt.co.uk> AG> > THe 3rd option is not quite the same which is (on Windows AG> > at least) to install the Active Scripting support for > JS> requires that every *client* have a JS> Python interpreter installed, and set up to support JS> ActiveScripting. Good catch. I actually meant to explain that in my message but somewhere between thought and email it got lost. The option is fine on an intranet where the environment is controlled, on the internet you really do need to go with Jython. Alan G From alan.gauld@bt.com Thu Sep 6 23:12:02 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 6 Sep 2001 23:12:02 +0100 Subject: [Tutor] input problem ? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF2F@mbtlipnt02.btlabs.bt.co.uk> Walter, Others have dealt with the errors you got, here are a couple of other things to consider. > vraag_234 = input ( "Wat is de score bij vraag 234? ") Use raw_input() rather than input() - it's safer should you get a knowledgable and rogue user. You need to convert the raw_input to an int thus: vraag_317-321 = int(raw_input ("Wat is de score bij vraag 317-321?")) Also to save code and make the program easier to extend you could store the questions and responses in a dictionary: vraag = {'317-321':["Wat is de score bij vraag 317-321?", 4, None], '234':["Wat is de score bij vraag 234? ", 4, None], etc... } Here we use the question number as a key and store the question, the compared value(weight) and a place marker(None) for the input result. Thus to access the question we can do: vraag['234'][0] To access the weighting value: vraag['234'][1] and to store a value: vraag['234'][2] = 42 To ask the questions you can then just loop over the keys: for q in vraag.keys(): # vraag[q] is the dictionary item, # 2 is the value field and 0 the question text vraag[q][2] = int(raw_input(vraag[q][0])) The advantage here is that you can add new questions to the dictionary or change the weighting values without changing the actual code structure. Combining that with the earlier tip about using a count value you can then later do: for q in vraag.keys(): # compare value and weighting if vraag[q][2] > vraag[q][1]: count = count + 1 > if (vraag_234 > 4) or (vraag_326 > 4): This doesn't change much: if (vraag['234'][2] > vraag['234'][1]) or (vraag['326'][2] > vraag['326'][1]): > print "Er kan sprake zijn van een depressie ..." > Is there to much input?, should i make functions? You could do it in functions too but if you use a dictionary the code shrinks to the point where its not so important. Structuring the data to suit the problem can often save an awful lot of repetitive coding. OTOH you might find the complexity of using indexes too difficult to track, in which case a function might be better. Finally, in your original code you used something like this: List = [] if (vraag_317-321 > 4): List.append That won't do anything to the list since List.append is not being executed - its simply the name of a function. You need to add parentheses - and put something inside them! eg. List.append(1) > Maybe a difficult try out but to me it is very usefull if it works For a first attempt its very good, my first programs in a new language are usually much less ambitious! :-) Alan G From dsh8290@rit.edu Thu Sep 6 23:15:14 2001 From: dsh8290@rit.edu (dman) Date: Thu, 6 Sep 2001 18:15:14 -0400 Subject: [Tutor] What is the best way to count the number of lines in a huge file? In-Reply-To: <Pine.LNX.4.33.0109061738230.25741-100000@terbidium.openservices.net>; from ignacio@openservices.net on Thu, Sep 06, 2001 at 05:39:44PM -0400 References: <20010906173318.F22153@harmony.cs.rit.edu> <Pine.LNX.4.33.0109061738230.25741-100000@terbidium.openservices.net> Message-ID: <20010906181514.A22356@harmony.cs.rit.edu> On Thu, Sep 06, 2001 at 05:39:44PM -0400, Ignacio Vazquez-Abrams wrote: | On Thu, 6 Sep 2001, dman wrote: | > Heh. I didn't even know windows had a 256k boundary. I always though | | ? | | I meant the parameter passed to file.read() in my code (262144B=256KiB). Oh, right. Searching for a sequence of characters in an stream of bytes is problematic unless you have some sort of structure within which to work (IOW that boundary thing). -D From GADGILP@INFOTECH.ICICI.com Fri Sep 7 06:45:48 2001 From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH) Date: Fri, 7 Sep 2001 11:15:48 +0530 Subject: [Tutor] Browser-based Python Interpreter Message-ID: <E1B786DCFA6ED511A0390008C7289E47635411@ICICIBACK3> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C13760.58908960 Content-Type: text/plain; charset="iso-8859-1" hello, there was a mail abt NT related automation and somebody mentioned WSH. I have installed it. Alan mentions about "Active Scripting support for Python". Is there another component that I need to install after WSH so that I can proceed ? I need to be able to start and stop server daemons using a script on NT and havn't coded on win/COM env earlier. /prasad > -----Original Message----- > From: alan.gauld@bt.com [mailto:alan.gauld@bt.com] > Sent: Friday, September 07, 2001 3:08 AM > To: jeff@ccvcorp.com; tutor@python.org > Subject: RE: [Tutor] Browser-based Python Interpreter > > > AG> > THe 3rd option is not quite the same which is (on Windows > AG> > at least) to install the Active Scripting support for > > > JS> requires that every *client* have a > JS> Python interpreter installed, and set up to support > JS> ActiveScripting. > > Good catch. I actually meant to explain that in my message > but somewhere between thought and email it got lost. The option > is fine on an intranet where the environment is controlled, > on the internet you really do need to go with Jython. > > Alan G > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > . -- "This e-mail message may contain confidential, proprietary or legally privileged information. It should not be used by anyone who is not the original intended recipient. If you have erroneously received this message, please delete it immediately and notify the sender. The recipient acknowledges that ICICI or its subsidiaries and associated companies (including ICICI Bank) "ICICI Group", are unable to exercise control or ensure or guarantee the integrity of/over the contents of the information contained in e-mail transmissions and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of ICICI Group. Before opening any attachments please check them for viruses and defects." ------_=_NextPart_001_01C13760.58908960 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Diso-8859-= 1"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 5.5.2653.12"> <TITLE>RE: [Tutor] Browser-based Python Interpreter

hello,

there was a mail abt NT related automation and somebody m= entioned WSH.
I have installed it. Alan mentions about "Active Sc= ripting support for
Python". Is there another component that I need to = install after WSH
so that I can proceed ?

I need to be able to start and stop server daemons using = a script on NT
and havn't coded on win/COM env earlier.

/prasad

> -----Original Message-----
> From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
> Sent: Friday, September 07, 2001 3:08 AM
> To: jeff@ccvcorp.com; tutor@python.org
> Subject: RE: [Tutor] Browser-based Python Interpret= er
>
>
> AG> > THe 3rd option is not quite the same wh= ich is (on Windows
> AG> > at least) to install the Active Scripti= ng support for
> >
> JS> requires that every *client* have a
> JS> Python interpreter installed, and set up to = support
> JS> ActiveScripting. 
>
> Good catch. I actually meant to explain that in my = message
> but somewhere between thought and email it got lost= . The option
> is fine on an intranet where the environment is con= trolled,
> on the internet you really do need to go with Jytho= n.
>
> Alan G
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor<= /FONT>
>


..

"This e-mail message= may contain confidential, proprietary or legally privileged information. I= t should not be used by anyone who is not the original intended recipient. = If you have erroneously received this message, please delete it immediately= and notify the sender. The recipient acknowledges that ICICI or its subsid= iaries and associated companies (including ICICI Bank) "ICICI Group", are u= nable to exercise control or ensure or guarantee the integrity of/over the = contents of the information contained in e-mail transmissions and further a= cknowledges that any views expressed in this message are those of the indiv= idual sender and no binding nature of the message shall be implied or assum= ed unless the sender does so expressly with due authority of ICICI Group. B= efore opening any attachments please check them for viruses and defects." ------_=_NextPart_001_01C13760.58908960-- From ajaya@ncoretech.com Fri Sep 7 08:18:29 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Fri, 7 Sep 2001 12:48:29 +0530 Subject: [Tutor] Running Python GUI on Windows and Linux...problems encountered in Windows. Message-ID: <000201c1376d$4c3f14d0$6501a8c0@ncoretech.com> This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C1379B.65F750D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, I've a problem specific to windows. I've developed a simple GUI using python. My amin is to test with both linux and windows. I've two threads for it. One for GUI and another for processing. But when I tested with windows it started hanging...can any one give comments on implementation. I am jsut attaching my file here with: from Tkinter import * import string import Pmw from time import sleep import thread import sys class Key(Button): def __init__(self, master, font=('arial', 8, 'bold'), fg='white', width=3, bd=3, **kw): kw['font'] = font kw['fg'] = fg kw['width'] = width kw['bd'] = bd apply(Button.__init__, (self, master), kw) self.pack(side=LEFT, expand=YES, fill=BOTH) class MenuBar(Frame): def __init__(self, master, Menus, relief=RAISED, **kw): kw['relief'] = relief apply(Frame.__init__, (self, master), kw) self.pack(side=TOP, expand=YES, fill=BOTH) for x in Menus: cmdbutn, cmdlist = x CommandButton(self, cmdlist, text=cmdbutn) class CommandButton(Menubutton): def __init__(self, MenuBar, commandlist, **kw): apply(Menubutton.__init__, (self, MenuBar), kw) self.pack(side=LEFT, padx="2m") self.menu = Menu(self) for x in commandlist: L, C, S = x self.menu.add_command(label=L, command=C, state=S) self['menu'] = self.menu class PhoneLabel(Frame): def __init__(self, master, text): Frame.__init__(self, master, bg='gray40') self.pack(side=LEFT, expand=YES, fill=BOTH) Label(self, text=text, fg='steelblue1', font=("arail", 10, "bold"), width=5, bg='gray40').pack(side=LEFT, expand=YES, fill=BOTH) class VirtualHandSet(Frame): def __init__(self, parent=None): Frame.__init__(self, bg='gray40') self.pack(expand=YES, fill=BOTH) self.master.title('Virtual Hand Set') self.master.iconname('VHS') self.EventQ = [] self.current = '' self.BuildVirtualHandSet() def EvalAction(self, action): self.EventQ.append(action) def EvalKey(self, key): self.display.insert(END, key) self.current = self.current + key def GetEventQ(self): return self.EventQ def GetDigitMap(self): return self.current def ConfigMenu(self): print 'This is not implemented yet' def __del__(self): sys.exit(0) def BuildVirtualHandSet(self): FUN = 1 KEY = 0 KC1 = 'gray30' #Dark Keys KC2 = 'gray50' #Light Keys KC3 = 'steelblue1' #Light Blue Keys KC4 = 'steelblue' #Dark Blue Keys OnOffBD = 10 FunBD = 3 KeyBD = 3 Keys = [ [('ON/OFF', '', FUN, 'OnOff', OnOffBD), ], ('Flash', '', FUN, 'Flash', FunBD), ('Mute', '', FUN, 'Mute', FunBD), ('R', '', FUN, 'Redial', FunBD) ], [ ('1', 'abc', KEY, '1', KeyBD), ('2', 'def', KEY, '2', KeyBD), ('3', 'ghi', KEY, '3', KeyBD), ], [ ('4', 'jkl', KEY, '4', KeyBD), ('5', 'mno', KEY, '5', KeyBD), ('6', 'pqr', KEY, '6', KeyBD) ], [ ('7', 'stu', KEY, '7', KeyBD), ('8', 'vwx', KEY, '8', KeyBD), ('9', 'yz', KEY, '9', KeyBD) ], [ ('*', '', KEY, '*', KeyBD), ('0', '', KEY, '0', KeyBD), ('#', '', KEY, '#', KeyBD) ] ] MenuItems = [ ('Config', [('IP Parameters', self.ConfigMenu, DISABLED), ('Layout', self.ConfigMenu, DISABLED) ] ) ] MenuBar(self, MenuItems,relief=RAISED, bd=1) self.display = Pmw.ScrolledText(self, hscrollmode='dynamic', vscrollmode='dynamic', hull_relief='sunken', hull_background='gray40', hull_borderwidth=3, text_background='honeydew4', text_width=20, text_foreground='black', text_height=3, text_padx=10, text_pady=10, text_relief='groove', text_font=('arial', 12, 'bold')) self.display.pack(side=TOP, expand=YES, fill=BOTH) for row in Keys: rowa = Frame(self, bg='gray40') rowb = Frame(self, bg='gray40') for p1, p2, ktype, func, bd in row: PhoneLabel(rowa, text=p2) if ktype == FUN: a = lambda s=self, a=func: s.EvalAction(a) Key(rowb, text=p1, bg=KC4, bd=bd, command=a) else: a = lambda s=self, k=func: s.EvalKey(k) Key(rowb, text=p1, bg=KC1, bd=bd, command=a) rowa.pack(side=TOP, expand=YES, fill=BOTH) rowb.pack(side=TOP, expand=YES, fill=BOTH) class VirtualHandSetProcessor: def __init__(self): self.handset = VirtualHandSet() # self.Pipe = TcpIpPipe() thread.start_new_thread(self.WorkerThread, ()) def WorkerThread(self): while(1): print 'Hello' print self.handset.GetEventQ() sleep(1) if __name__ == '__main__': print "Hello" a = VirtualHandSetProcessor() print "Hello" ------=_NextPart_000_0003_01C1379B.65F750D0 Content-Type: text/plain; name="utils.py" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="utils.py" from Tkinter import * import string import Pmw from time import sleep import thread import sys class Key(Button): def __init__(self, master, font=3D('arial', 8, 'bold'), fg=3D'white', width=3D3, bd=3D3, **kw): kw['font'] =3D font kw['fg'] =3D fg kw['width'] =3D width kw['bd'] =3D bd apply(Button.__init__, (self, master), kw) self.pack(side=3DLEFT, expand=3DYES, fill=3DBOTH) class MenuBar(Frame): def __init__(self, master, Menus, relief=3DRAISED, **kw): kw['relief'] =3D relief apply(Frame.__init__, (self, master), kw) self.pack(side=3DTOP, expand=3DYES, fill=3DBOTH) for x in Menus: cmdbutn, cmdlist =3D x CommandButton(self, cmdlist, text=3Dcmdbutn) =20 =20 class CommandButton(Menubutton): def __init__(self, MenuBar, commandlist, **kw): apply(Menubutton.__init__, (self, MenuBar), kw) self.pack(side=3DLEFT, padx=3D"2m") self.menu =3D Menu(self) for x in commandlist: L, C, S =3D x self.menu.add_command(label=3DL, command=3DC, state=3DS) self['menu'] =3D self.menu =20 class PhoneLabel(Frame): def __init__(self, master, text): Frame.__init__(self, master, bg=3D'gray40') self.pack(side=3DLEFT, expand=3DYES, fill=3DBOTH) Label(self, text=3Dtext, fg=3D'steelblue1', font=3D("arail", 10, = "bold"), width=3D5, bg=3D'gray40').pack(side=3DLEFT, expand=3DYES, = fill=3DBOTH) class VirtualHandSet(Frame): def __init__(self, parent=3DNone): Frame.__init__(self, bg=3D'gray40') self.pack(expand=3DYES, fill=3DBOTH) self.master.title('Virtual Hand Set') self.master.iconname('VHS') self.EventQ =3D [] self.current =3D '' self.BuildVirtualHandSet() =20 def EvalAction(self, action): self.EventQ.append(action) =20 =20 =20 def EvalKey(self, key): self.display.insert(END, key) self.current =3D self.current + key =20 =20 def GetEventQ(self): return self.EventQ def GetDigitMap(self): return self.current def ConfigMenu(self): print 'This is not implemented yet' def __del__(self): sys.exit(0) =20 def BuildVirtualHandSet(self): FUN =3D 1 KEY =3D 0 KC1 =3D 'gray30' #Dark Keys KC2 =3D 'gray50' #Light Keys KC3 =3D 'steelblue1' #Light Blue Keys KC4 =3D 'steelblue' #Dark Blue Keys OnOffBD =3D 10 FunBD =3D 3 KeyBD =3D 3 Keys =3D [ [('ON/OFF', '', FUN, 'OnOff', OnOffBD), ], [=20 ('Flash', '', FUN, 'Flash', FunBD), ('Mute', '', FUN, 'Mute', FunBD), ('R', '', FUN, 'Redial', FunBD) ], [ ('1', 'abc', KEY, '1', KeyBD), ('2', 'def', KEY, '2', KeyBD), ('3', 'ghi', KEY, '3', KeyBD), =20 ], [ ('4', 'jkl', KEY, '4', KeyBD), =20 ('5', 'mno', KEY, '5', KeyBD), ('6', 'pqr', KEY, '6', KeyBD) ], [ ('7', 'stu', KEY, '7', KeyBD), ('8', 'vwx', KEY, '8', KeyBD), ('9', 'yz', KEY, '9', KeyBD) ], [ ('*', '', KEY, '*', KeyBD), ('0', '', KEY, '0', KeyBD), ('#', '', KEY, '#', KeyBD) ] ] MenuItems =3D [ ('Config', [('IP Parameters', self.ConfigMenu, = DISABLED), ('Layout', self.ConfigMenu, DISABLED) = ] =20 ) =20 ] =20 MenuBar(self, MenuItems,relief=3DRAISED, bd=3D1) =20 self.display =3D Pmw.ScrolledText(self, hscrollmode=3D'dynamic', vscrollmode=3D'dynamic', hull_relief=3D'sunken', hull_background=3D'gray40', hull_borderwidth=3D3, text_background=3D'honeydew4', text_width=3D20, text_foreground=3D'black', text_height=3D3, text_padx=3D10, text_pady=3D10, text_relief=3D'groove', text_font=3D('arial', 12, 'bold')) self.display.pack(side=3DTOP, expand=3DYES, fill=3DBOTH) for row in Keys: rowa =3D Frame(self, bg=3D'gray40') rowb =3D Frame(self, bg=3D'gray40') for p1, p2, ktype, func, bd in row: PhoneLabel(rowa, text=3Dp2) if ktype =3D=3D FUN: a =3D lambda s=3Dself, a=3Dfunc: s.EvalAction(a) Key(rowb, text=3Dp1, bg=3DKC4, bd=3Dbd, command=3Da) else: a =3D lambda s=3Dself, k=3Dfunc: s.EvalKey(k) Key(rowb, text=3Dp1, bg=3DKC1, bd=3Dbd, command=3Da) =20 rowa.pack(side=3DTOP, expand=3DYES, fill=3DBOTH) rowb.pack(side=3DTOP, expand=3DYES, fill=3DBOTH) =20 =20 =20 class VirtualHandSetProcessor: def __init__(self): self.handset =3D VirtualHandSet() # self.Pipe =3D TcpIpPipe() thread.start_new_thread(self.WorkerThread, ()) def WorkerThread(self): while(1): print 'Hello' print self.handset.GetEventQ() sleep(1) if __name__ =3D=3D '__main__': print "Hello" a =3D VirtualHandSetProcessor() print "Hello" =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 ------=_NextPart_000_0003_01C1379B.65F750D0-- From wheelege@tsn.cc Fri Sep 7 09:40:56 2001 From: wheelege@tsn.cc (wheelege) Date: Fri, 7 Sep 2001 18:40:56 +1000 Subject: [Tutor] Running Python GUI on Windows and Linux...problems encountered in Windows. References: <000201c1376d$4c3f14d0$6501a8c0@ncoretech.com> Message-ID: <006301c13778$d03f5820$b9a616ca@ACE> Hi, I had similar problems with a tkinter game I developed for the place I work for (pong+arkanoid, networked scores, network multiplayer...etc) and I had hell with this exact error. The way to fix it is to do >zero< GUI calls in any thread other than the main one. This is a little trickier than it sounds, but very possible. > <...> > > > class VirtualHandSetProcessor: > def __init__(self): > self.handset = VirtualHandSet() > # self.Pipe = TcpIpPipe() > thread.start_new_thread(self.WorkerThread, ()) > > def WorkerThread(self): > while(1): > print 'Hello' > print self.handset.GetEventQ() > sleep(1) I didn't use this exact architecture but I think here is where your problem may lie. You have the same instance of a class with two threads - one which is heavy GUI and one which looks like it has only processing. However, with the line 'print self.handset.GetEventQ()' you are accessing a function from an object which is in use by the other main GUI thread, for GUI type calls. This is what I think you need to fix. Perhaps use a dummy object with some attributes (no GUI stuff) and get the while 1 loop to check it's attributes for changes instead of polling the handset object (of the VirtualHandSet class). This would mean that whenever an event occured you would have to append it to the dummy object instead of itself, but this should be only a minor code change. I'll just append this discaimer here - I did not use this exact object structure so I may well be wrong :) > > > > if __name__ == '__main__': > print "Hello" > a = VirtualHandSetProcessor() > print "Hello" > From Charlie@begeistert.org Fri Sep 7 10:17:37 2001 From: Charlie@begeistert.org (Charlie Clark) Date: Fri, 07 Sep 2001 11:17:37 +0200 Subject: [Tutor] Problem with IDLE in Windows Message-ID: <999854257_PM_BeOS.Charlie@begeistert.org> Dear list, can anyone tell me why this line causes problems when I try to edit the file in IDLE under windows? It seems that the ´ is a unicode symbol that causes IDLE to throw a unicode -> ascii error and delete the file. Does this count as a bug? content = "some text" content = content.replace( "'":"´") Any suggestions for an alternative? I need to replace simple apostrophes with something else as they get inserted into an SQL statement which subsequently doesn't work if they are kept. Thanx Charlie From ajaya@ncoretech.com Fri Sep 7 10:17:24 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Fri, 7 Sep 2001 14:47:24 +0530 Subject: [Tutor] Running Python GUI on Windows and Linux...problems encountered in Windows. In-Reply-To: <006301c13778$d03f5820$b9a616ca@ACE> Message-ID: <000801c1377d$e8a63190$6501a8c0@ncoretech.com> Hi Wheelege, Thanks allot for your help, Yes! what exactly you told is the problem. Perhaps...it is not because of the call the the object wich is alredy used in GUI...(may cause problems...yet to test throughly)..self.handset.GetEventQ() But for the movement the print state ment associated with this... > <...> > class VirtualHandSetProcessor: def __init__(self): self.handset = VirtualHandSet() # self.Pipe = TcpIpPipe() thread.start_new_thread(self.WorkerThread, ()) def WorkerThread(self): while(1): ------> #print 'Hello' ------> #print self.handset.GetEventQ() sleep(1) I've tested by commenting this prints and calling a = self.handset.GetEventQ() in the while(1) loop..., now this is working fine.., but as you said there may be problems that I will face later... One more two requests I've..., First thing is I am a C++ programmer...can you suggest some good site or meterial...which gives good information about the python oriented design..., Second one is in the above code I want to disable the maximizing option...., For that I was jut thinking using protocol to register my class methods ...for WM_ messages...but I've very few documents available on it...could you please suggest some reference to document.. Thanks allot for your great help with regards, Ajaya -----Original Message----- From: wheelege [mailto:wheelege@tsn.cc] Sent: Friday, September 07, 2001 2:11 PM To: Ajaya Babu; PythonTutorlist (E-mail) Subject: Re: [Tutor] Running Python GUI on Windows and Linux...problems encountered in Windows. Hi, I had similar problems with a tkinter game I developed for the place I work for (pong+arkanoid, networked scores, network multiplayer...etc) and I had hell with this exact error. The way to fix it is to do >zero< GUI calls in any thread other than the main one. This is a little trickier than it sounds, but very possible. > <...> > > > class VirtualHandSetProcessor: > def __init__(self): > self.handset = VirtualHandSet() > # self.Pipe = TcpIpPipe() > thread.start_new_thread(self.WorkerThread, ()) > > def WorkerThread(self): > while(1): > print 'Hello' > print self.handset.GetEventQ() > sleep(1) I didn't use this exact architecture but I think here is where your problem may lie. You have the same instance of a class with two threads - one which is heavy GUI and one which looks like it has only processing. However, with the line 'print self.handset.GetEventQ()' you are accessing a function from an object which is in use by the other main GUI thread, for GUI type calls. This is what I think you need to fix. Perhaps use a dummy object with some attributes (no GUI stuff) and get the while 1 loop to check it's attributes for changes instead of polling the handset object (of the VirtualHandSet class). This would mean that whenever an event occured you would have to append it to the dummy object instead of itself, but this should be only a minor code change. I'll just append this discaimer here - I did not use this exact object structure so I may well be wrong :) > > > > if __name__ == '__main__': > print "Hello" > a = VirtualHandSetProcessor() > print "Hello" > From ajaya@ncoretech.com Fri Sep 7 11:22:18 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Fri, 7 Sep 2001 15:52:18 +0530 Subject: [Tutor] is there any way to read key configuration..! Message-ID: <000001c13786$f9f9fd60$6501a8c0@ncoretech.com> Hi, Tkinter programming guys..., is there any method to call get Key configureation to read. I want it becasue it gives the flexibility to change relief artribute from RAISED to SUNKEN and vice versa Thanks and Regards, Ajaya From koen@behindthesofa.dhs.org Fri Sep 7 11:36:45 2001 From: koen@behindthesofa.dhs.org (Koen Bossers) Date: Fri, 07 Sep 2001 12:36:45 +0200 Subject: [Tutor] is there any way to read key configuration..! References: <000001c13786$f9f9fd60$6501a8c0@ncoretech.com> Message-ID: <3B98A33D.4070707@behindthesofa.dhs.org> >>> from Tkinter import * >>> root =Tk() >>> label = Label(root, text="Hi there") >>> label.pack() >>> label.cget('relief') 'flat' >>> label.config(relief=SUNKEN) >>> label.cget('relief') 'sunken' Take a good look at http://www.pythonware.com/library/tkinter/introduction/index.htm, Basic Widget Methods. Cheers, Koen Ajaya Babu wrote: >Hi, > >Tkinter programming guys..., is there any method to call get Key >configureation to read. I want it becasue it gives the flexibility to change >relief artribute from RAISED to SUNKEN and vice versa > >Thanks and Regards, >Ajaya > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > From kalle@gnupung.net Fri Sep 7 12:12:27 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Fri, 7 Sep 2001 13:12:27 +0200 Subject: [Tutor] sending stdout to a text box In-Reply-To: ; from bill_tolbert@bigfoot.com on Thu, Sep 06, 2001 at 05:20:56PM -0400 References: Message-ID: <20010907131227.A13160@gandalf> [Bill Tolbert] > I have a script which works well; it sends messages to the console when > run from a prompt. How can I catch this and route it to a text box in > tkinter? Something like this might work: > from Tkinter import * class BogusFile: def __init__(self, text): self.text = text def write(self, s): self.text.insert(END, s) > class App: > > ## Create GUI > > def __init__(self, master): > > frame = Frame(master) > frame.pack() > self.t = StringVar() > # this line doesn't work > #self.text_box = Text(frame, textvariable=self.t) > self.text_box = Text(frame) > self.text_box.pack() > > # this call to dobackup works but no redirect of stdout > self.dobackup = Button(frame, text="Do Backup", > command=self.backup) > > self.dobackup.pack(side=TOP) > > def backup(self): > import ICAREBackup > #self.t = sys.stdout > #sys.stdout = self.t sys.stdout = BogusFile(self.text_box) > ICAREBackup.ICAREBackup() > > root = Tk() > > app = App(root) > > root.mainloop() > Incredibly untested, but might work. Peace, Kalle -- [ kalle@gnupung.net ][ Thought control, brought to you by the WIPO! ] [ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ] From tzuming@sanbi.ac.za Fri Sep 7 12:58:05 2001 From: tzuming@sanbi.ac.za (Tzu-Ming Chern) Date: Fri, 7 Sep 2001 13:58:05 +0200 (SAST) Subject: [Tutor] processing files in a directory Message-ID: Hi, Basically I would like to go into a single directory and a run my other script on those individual files present in the directory. I'm having headaches using perl to try and process these files since I keep overwriting the files. Is there an easier solution? With thanks, tzuming ****************************************************************************** Tzu-Ming Chern South African National Bioinformatics Institute University of Western Cape PO box X17 Bellville Cape Town South Africa Tel#:27-21-959-3908/3645 Fax:27-21-959-2512 Email:tzuming@fling.sanbi.ac.za ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ From Charlie@begeistert.org Fri Sep 7 13:08:05 2001 From: Charlie@begeistert.org (Charlie Clark) Date: Fri, 07 Sep 2001 14:08:05 +0200 Subject: [Tutor] Selection of Plaform specific modules Message-ID: <999864485_PM_BeOS.Charlie@begeistert.org> For some database work I've written the following little function in a tools module def check_platform(): if sys.version.find("MSC") >= 0: base_path = "viven/" from mx.ODBC.Windows import DriverConnect else: base_path = "" return base_path It works fine when I call but it doesn't make the imported module available. What do I need to change this? Charlie From rnd@onego.ru Fri Sep 7 13:22:11 2001 From: rnd@onego.ru (Roman Suzi) Date: Fri, 7 Sep 2001 16:22:11 +0400 (MSD) Subject: [Tutor] processing files in a directory In-Reply-To: Message-ID: On Fri, 7 Sep 2001, Tzu-Ming Chern wrote: > > Hi, > > Basically I would like to import os # go into a single directory and os.chdir("single") # a run my other script on those individual files present in the directory other_script = "other.py" for file in os.listdir("."): # or glob.glob("*") os.system(other_script + " " + file) > I'm having > headaches using perl to try and process these files since I keep > overwriting the files. Is there an easier solution? ??? > With thanks, Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd@onego.ru - From dsh8290@rit.edu Fri Sep 7 14:26:25 2001 From: dsh8290@rit.edu (dman) Date: Fri, 7 Sep 2001 09:26:25 -0400 Subject: [Tutor] Selection of Plaform specific modules In-Reply-To: <999864485_PM_BeOS.Charlie@begeistert.org>; from Charlie@begeistert.org on Fri, Sep 07, 2001 at 02:08:05PM +0200 References: <999864485_PM_BeOS.Charlie@begeistert.org> Message-ID: <20010907092625.E23012@harmony.cs.rit.edu> On Fri, Sep 07, 2001 at 02:08:05PM +0200, Charlie Clark wrote: | For some database work I've written the following little function in a | tools module | | def check_platform(): | if sys.version.find("MSC") >= 0: | base_path = "viven/" | from mx.ODBC.Windows import DriverConnect This line causes the reference to the module to be in the function's local scope. You want it to be in some sort of global scope, or return it from the function and let the client stick it in the global scope. (Since you already have a return value make it a 2-tuple instead) -D From lumbricus@gmx.net Fri Sep 7 11:53:12 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Fri, 7 Sep 2001 12:53:12 +0200 Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: <999854257_PM_BeOS.Charlie@begeistert.org>; from Charlie@begeistert.org on Fri, Sep 07, 2001 at 11:17:37AM +0200 References: <999854257_PM_BeOS.Charlie@begeistert.org> Message-ID: <20010907125312.A1868@Laplace.localdomain> On Fri, Sep 07, 2001 at 11:17:37AM +0200, Charlie Clark wrote: > Dear list, > > can anyone tell me why this line causes problems when I try to edit the > file in IDLE under windows? No sorry! It seems that the ´ is a unicode symbol > that causes IDLE to throw a unicode -> ascii error and delete the file. > Does this count as a bug? > > content = "some text" > content = content.replace( "'":"´") Have you tried "\264"? > > Any suggestions for an alternative? I need to replace simple apostrophes > with something else as they get inserted into an SQL statement which > subsequently doesn't work if they are kept. > > Thanx > > Charlie > HTH,HAND J"o! -- "It's a dog-eat-dog world out there, and I'm wearing Milkbone underware." -- Norm, from _Cheers_ From alan.gauld@bt.com Fri Sep 7 15:26:25 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 7 Sep 2001 15:26:25 +0100 Subject: [Tutor] Browser-based Python Interpreter Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF30@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C137A9.1367B950 Content-type: text/plain; charset="iso-8859-1" there was a mail abt NT related automation and somebody mentioned WSH. I have installed it. Alan mentions about "Active Scripting support for Python". Is there another component that I need to install after WSH so that I can proceed ? Once you have WSH and Python installed you need to also install the winall package(already done if you used the ActiveState Python in the first place) Now you can take either of two routes: 1) Install activeScripting by running a file within the winall package. This allows you to write .pys WSH scripts and run them using wscript.exe or cscript.exe 2) Just use winall's native COM facilities to create the WSH COM objects - this seems to be Mark Hamonds personal favourite method. Using method 1 and stealing an example from Marks Win32 book we get the following example: ######## wshtest.pys ####### WScript.Echo('The script is: ',WScript.SciptName) # Use WSH natively if len(WScript.Arguments): wshell = WScript.CreateObject("WScript.Shell") wshell.Run("notepad.exe " + WScript.Arguments(0)) else: WScript.Echo('No arguments passed') ############################ Run it by entering C:\> cscript wshtest.pys foo bar at a DOS prompt or C:\> wscript wshtest.pys baz to get GUI style messages Doing the same in native Python requires a mix of WSH and raw Python: ######## wshtest.py ######## from win32com.client import Dispatch import sys print 'The script is: ',sys.argv[0] if len(sys.argv) > 1: wshell = Dispatch("WScript.Shell") wshell.Run("notepad.exe "+sys.argv[1]) else: print 'No arguments passed' ############################ HTH, Alan g ------_=_NextPart_001_01C137A9.1367B950 Content-type: text/html; charset="iso-8859-1" RE: [Tutor] Browser-based Python Interpreter

there was a mail abt NT related automation and somebody mentioned WSH.
I have installed it. Alan mentions about "Active Scripting support for
Python". Is there another component that I need to install after WSH
so that I can proceed ?  

Once you have WSH and Python installed you need to
also install the winall package(already done if you
used the ActiveState Python in the first place)
 
Now you can take either of two routes:
 
1) Install activeScripting by running a file within the
   winall package. This allows you to write .pys WSH
   scripts and run them using wscript.exe or cscript.exe
 
2) Just use winall's native COM facilities to create
   the WSH COM objects - this seems to be Mark Hamonds
   personal favourite method.
 
Using method 1 and stealing an example from Marks Win32
book we get the following example:
 
######## wshtest.pys #######
WScript.Echo('The script is: ',WScript.SciptName) # Use WSH natively
if len(WScript.Arguments):
   wshell = WScript.CreateObject("WScript.Shell")
   wshell.Run("notepad.exe " + WScript.Arguments(0))
else:
   WScript.Echo('No arguments passed')
 
############################
 
Run it by entering
C:\> cscript wshtest.pys  foo bar
at a DOS prompt or
C:\> wscript wshtest.pys baz
to get GUI style messages
 
 
Doing the same in native Python requires a mix of WSH
and raw Python:
 
######## wshtest.py ########
from win32com.client import Dispatch
import sys
 
print 'The script is: ',sys.argv[0]

if len(sys.argv) > 1:
   wshell = Dispatch("WScript.Shell")
   wshell.Run("notepad.exe "+sys.argv[1])
else:
   print 'No arguments passed'
############################
 
HTH,
 
Alan g

 

------_=_NextPart_001_01C137A9.1367B950-- From urnerk@qwest.net Fri Sep 7 18:06:51 2001 From: urnerk@qwest.net (Kirby Urner) Date: Fri, 07 Sep 2001 10:06:51 -0700 Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: <999854257_PM_BeOS.Charlie@begeistert.org> Message-ID: <4.2.0.58.20010907100541.00cf3240@pop3.norton.antivirus> > >Does this count as a bug? > >content =3D "some text" >content =3D content.replace( "'":"=B4") I just ran this in IDLE 0.8 in Windows with no problems, except the syntax is , in place of : Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> content =3D "some text" >>> content =3D content.replace( "'":"=B4") SyntaxError: invalid syntax >>> content =3D content.replace( "'","=B4") >>> content 'some text' Kirby From urnerk@qwest.net Fri Sep 7 18:30:27 2001 From: urnerk@qwest.net (Kirby Urner) Date: Fri, 07 Sep 2001 10:30:27 -0700 Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: <4.2.0.58.20010907100541.00cf3240@pop3.norton.antivirus> References: <999854257_PM_BeOS.Charlie@begeistert.org> Message-ID: <4.2.0.58.20010907102751.00cf51d0@pop3.norton.antivirus> > > >>> content =3D content.replace( "'","=B4") > >>> content >'some text' > >Kirby Sorry, this wasn't a good test anyway, because "some text" doesn't have an apostrophe to replace in it, and single- quote is what you get back from __repr__ even if you double quote a string i.e. >>> content =3D "some test" >>> content 'some test' So my little test above does precisely nothing. However: >>> content =3D "some ' test" >>> content.replace("'","`") 'some ` test' The ' was replaced with a `. So is there a problem here? Maybe we're using different versions of Windows Python/IDLE. Kirby From dyoo@hkn.eecs.berkeley.edu Fri Sep 7 18:50:07 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 7 Sep 2001 10:50:07 -0700 (PDT) Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: <999854257_PM_BeOS.Charlie@begeistert.org> Message-ID: On Fri, 7 Sep 2001, Charlie Clark wrote: > can anyone tell me why this line causes problems when I try to edit the= =20 > file in IDLE under windows? It seems that the =B4 is a unicode symbol=20 > that causes IDLE to throw a unicode -> ascii error and delete the file.= =20 > Does this count as a bug? >=20 > content =3D "some text" > content =3D content.replace( "'":"=B4") Under a regular Python (2.1) shell (without IDLE), this works: ### >>> content =3D "some text with a ' quote" >>> content =3D content.replace("'", "") >>> content 'some text with a \xb4 quote ### Can anyone confirm that it's IDLE that's doing something weird? > Any suggestions for an alternative? I need to replace simple > apostrophes with something else as they get inserted into an SQL > statement which subsequently doesn't work if they are kept. Are you using the parameterized style of SQL querying? If so, then you don't need to worry so much about properly quoting things. For example, instead of: ### fname, lname =3D 'Issac', 'Asimov' cursor.execute("""insert into authors (fname, lname) values ('%s', '%s')""" % (fname, lname)) ### we can use: ### fname, lname =3D 'Issac', 'Asimov' cursor.execute("""insert into authors (fname, lname) values (?, ?)""", fname, lname) ### The database handler should then take care of the quoting for you, and should even escape any apostrophies in strings we insert into the database. The topic guide touches on this a little when it talks about "paramstyle": http://python.org/topics/database/DatabaseAPI-2.0.html Hope this helps! From dyoo@hkn.eecs.berkeley.edu Fri Sep 7 18:56:03 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 7 Sep 2001 10:56:03 -0700 (PDT) Subject: [Tutor] processing files in a directory In-Reply-To: Message-ID: On Fri, 7 Sep 2001, Tzu-Ming Chern wrote: > Basically I would like to go into a single directory and a run my > other script on those individual files present in the directory. I'm Using the glob.glob() function will give you a list of files in a specific directory: ### >>> glob.glob('*.txt') ['notes.txt'] ### This works identically to Perl's globbing operator '<>'. > having headaches using perl to try and process these files since I > keep overwriting the files. Is there an easier solution? Hmmm! Can you explain a little more about how you're processing the files? Are you replacing content in each of those files? From rick@niof.net Fri Sep 7 19:09:19 2001 From: rick@niof.net (Rick Pasotto) Date: Fri, 7 Sep 2001 14:09:19 -0400 Subject: [Tutor] using 'mailbox' Message-ID: <20010907140918.D20746@tc.niof.net> What am I overlooking? I have a file in unix mailbox format that I would like to process by changing the body of each message. Using the mailbox module I can get and deal with the headers but I'm not seeing how to deal with the body. -- "The whole aim of practical politics is to keep the populace alarmed -- and thus clamorous to be led to safety -- by menacing it with an endless series of hobgoblins, all of them imaginary." -- H.L. Mencken Rick Pasotto email: rickp@telocity.com web: www.niof.net From sheila@thinkspot.net Fri Sep 7 19:24:17 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 07 Sep 2001 11:24:17 -0700 Subject: [Tutor] using 'mailbox' In-Reply-To: <20010907140918.D20746@tc.niof.net> References: <20010907140918.D20746@tc.niof.net> Message-ID: <870DA1B3A5C@kserver.org> On Fri, 7 Sep 2001 14:09:19 -0400, Rick Pasotto wrote about [Tutor] using 'mailbox': :What am I overlooking? I have a file in unix mailbox format that I would :like to process by changing the body of each message. Using the mailbox :module I can get and deal with the headers but I'm not seeing how to :deal with the body. from the mailbox module docs: "By defaul this is an rfc822.Message object (see the rfc822 module)." The rfc822.Message object is only the headers. You need to read in the message body separately. When an instance of an rfc822.Message has just been read in, the file pointer will be at the beginning of the message body. Read that in, I guess. Alternately, I have some code I've been working on (in very rough form) that subclasses rfc822.Message and will read in separate messages in mbox format (I've used it for such myself, for some utilities I've worked with). If you are interested in that, give me a shout and I'll send you what I have. Also, if you'd just like to see examples how to read in message bodies when working with rfc822.Message, I can give examples of those, also. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From rick@niof.net Fri Sep 7 20:16:54 2001 From: rick@niof.net (Rick Pasotto) Date: Fri, 7 Sep 2001 15:16:54 -0400 Subject: [Tutor] using 'mailbox' In-Reply-To: <870DA1B3A5C@kserver.org> References: <20010907140918.D20746@tc.niof.net> <870DA1B3A5C@kserver.org> Message-ID: <20010907151654.F20746@tc.niof.net> On Fri, Sep 07, 2001 at 11:24:17AM -0700, Sheila King wrote: > On Fri, 7 Sep 2001 14:09:19 -0400, Rick Pasotto wrote > about [Tutor] using 'mailbox': > > :What am I overlooking? I have a file in unix mailbox format that I would > :like to process by changing the body of each message. Using the mailbox > :module I can get and deal with the headers but I'm not seeing how to > :deal with the body. > > from the mailbox module docs: > "By defaul this is an rfc822.Message object (see the rfc822 module)." > > The rfc822.Message object is only the headers. You need to read in the > message body separately. This is what I didn't know how to do. Just figured it out. >>> import mailbox >>> filep = open('mbox') >>> mb = mailbox.UnixMailbox(filep) >>> msg = mb.next() >>> body = msg.fp.readlines() Now msg contains all the headers and body contains the rest of the message. Repeat the last two lines as needed. -- Certain nations seem particularly liable to fall prey to governmental plunder. They are those in which men, lacking faith in their own dignity and capability, would feel themselves lost if they were not governed and administered every step of the way. -- Frédéric Bastiat (1801-1850) Rick Pasotto rickp@telocity.com http://www.niof.net From bill_tolbert@bigfoot.com Fri Sep 7 20:38:59 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Fri, 7 Sep 2001 15:38:59 -0400 (EDT) Subject: [Tutor] using 'mailbox' In-Reply-To: <20010907151654.F20746@tc.niof.net> Message-ID: Here's some sample code that reads a mailbox file and outputs the headers, body, and information about the attachments. It was specifically written to parse a Calypso mailbox archive and stuff the values into a database. Pass in the full name and path of the mailbox file as an argument. Bill # Read a Calypso mailbox in archive format # Tolbert, 10/3/00 import sys import string import cStringIO import cgi, rfc822 import os def IndexMailArchive(archive): mb = open(archive,"r") msg = rfc822.Message(mb) while msg.items(): gFrom = msg.getheader('from') gSub = msg.getheader('subject') gTo = TakeFirstNonBlank(msg.getaddrlist('to')) gCc = TakeFirstNonBlank(msg.getaddrlist('cc')) gBcc = TakeFirstNonBlank(msg.getaddrlist('bcc')) gAttachment = msg.getallmatchingheaders('X-Attachment') gBody = '' # Deal with the body. Just read until you see the next message. # Not sure where I got the "From ???@???" parse = mb.readline() while parse[:12] != "From ???@???": gBody = gBody + parse pos = mb.tell() parse = mb.readline() if pos == mb.tell(): break print "From: ", gFrom print "Subject: ", gSub print "To: ", gTo print "CC: ", gCc print "BCC: ", gBcc print "Body: ", gBody if gAttachment: for i in gAttachment: strAtt = i[14:string.find(i, ';', 14)] strAtt = string.join(string.split(strAtt, '"'), '') strFile = os.path.split(strAtt)[1] print "Attachments: %s, %s" % (strFile, strAtt) print "===========================================" print "" msg = rfc822.Message(mb) mb.close() def TakeFirstNonBlank(addlist): newlist = [] for i,j in addlist: if i: newlist.append(i) else: newlist.append(j) return string.join(string.split(string.join(newlist, "'"), "'"), ", ") if __name__=='__main__': if len(sys.argv)<2: print "Usage:", sys.argv[0], "Full path name for archive is required." else: IndexMailArchive(sys.argv[1]) From lsloan@umich.edu Fri Sep 7 21:33:53 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Fri, 07 Sep 2001 16:33:53 -0400 Subject: [Tutor] trouble running Grail Message-ID: <200109072033.QAA18501@birds.us.itd.umich.edu> I know this isn't a Grail support mailing list, but since I am in the process of learning Python, I thought his might be a good place to ask about this. I'm using a Sun machine running Solaris 2.6 with Python 2.0 installed. I downloaded Grail 0.6 and when I try to run it, I get this error: Traceback (most recent call last): File "grail.py", line 499, in ? main() File "grail.py", line 108, in main app = Application(prefs=prefs, display=display) File "grail.py", line 248, in __init__ self.stylesheet = Stylesheet.Stylesheet(self.prefs) File "/var/tmp/grail-0.6/Stylesheet.py", line 21, in __init__ self.load() File "/var/tmp/grail-0.6/Stylesheet.py", line 45, in load massaged.append((g, c), v % fparms_dict) TypeError: append requires exactly 1 argument; 2 given Why would the Grail author give two arguments to append? Was there an old version of Python that allowed two arguments? -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From urnerk@qwest.net Fri Sep 7 21:41:00 2001 From: urnerk@qwest.net (Kirby Urner) Date: Fri, 07 Sep 2001 13:41:00 -0700 Subject: [Tutor] trouble running Grail In-Reply-To: <200109072033.QAA18501@birds.us.itd.umich.edu> Message-ID: <4.2.0.58.20010907133953.00cf6100@pop3.norton.antivirus> At 04:33 PM 9/7/2001 -0400, you wrote: >List-Id: Discussion for learning programming with Python Before version 2.0 or thereabouts, you could append(a,b,c) -- multi-arg append. But now you can only append 1 arg, and use extend for more. Looks to me that grail.py is stumbling on this backward incompatibility. Kirby From dsh8290@rit.edu Fri Sep 7 22:13:21 2001 From: dsh8290@rit.edu (dman) Date: Fri, 7 Sep 2001 17:13:21 -0400 Subject: [Tutor] trouble running Grail In-Reply-To: <4.2.0.58.20010907133953.00cf6100@pop3.norton.antivirus>; from urnerk@qwest.net on Fri, Sep 07, 2001 at 01:41:00PM -0700 References: <200109072033.QAA18501@birds.us.itd.umich.edu> <4.2.0.58.20010907133953.00cf6100@pop3.norton.antivirus> Message-ID: <20010907171321.B24531@harmony.cs.rit.edu> On Fri, Sep 07, 2001 at 01:41:00PM -0700, Kirby Urner wrote: | At 04:33 PM 9/7/2001 -0400, you wrote: | | >List-Id: Discussion for learning programming with Python | | Before version 2.0 or thereabouts, you could append(a,b,c) | -- multi-arg append. But now you can only append 1 arg, | and use extend for more. Looks to me that grail.py is | stumbling on this backward incompatibility. Actually, it was an implementation accident that was fixed in 2.0. Prior to 2.0 the following were equivalent, but shouldn't have been : l.append( a , b ,c ) l.append( ( a , b , c ) ) a_tuple = ( a , b , c ) l.append( a_tuple ) The solution to that problem is to put parenthesis around the arguments to the append() call so that the tuple grouping is correct. HTH, -D From ignacio@openservices.net Fri Sep 7 22:19:15 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 7 Sep 2001 17:19:15 -0400 (EDT) Subject: [Tutor] trouble running Grail In-Reply-To: <4.2.0.58.20010907133953.00cf6100@pop3.norton.antivirus> Message-ID: On Fri, 7 Sep 2001, Kirby Urner wrote: > Before version 2.0 or thereabouts, you could append(a,b,c) > -- multi-arg append. But now you can only append 1 arg, > and use extend for more. Looks to me that grail.py is > stumbling on this backward incompatibility. Grail is _ancient_. I remember using Grail 0.6 a _looooong_ time ago. -- Ignacio Vazquez-Abrams From dyoo@hkn.eecs.berkeley.edu Sat Sep 8 10:23:02 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 8 Sep 2001 02:23:02 -0700 (PDT) Subject: [Tutor] Help with cookies In-Reply-To: <999717518_PM_BeOS.Charlie@begeistert.org> Message-ID: On Wed, 5 Sep 2001, Charlie Clark wrote: > >I have a silly example of one here: > > > > http://hkn.eecs.berkeley.edu/~dyoo/python/cookiecounter.py > > > >The important thing is that we send off the cookie before any of the > other > >headers: otherwise, the browser will ignore the cookie. I think that > the > >RFC says something to this effect here: > > No, this is the wrong way round. I'm writing HTML-parsers (thanx to your > help) and I need to pass a cookie to the server to get the page I need. > I need some kind of hook into urllib, I think but that's where I'm lost > ;-~ > > page = "http://blah-blah.com" > cookie = "194.175.44.82 / 2137622400 CFID=988743 FALSE ACCEPT" > src = urllib.urlopen(page, cookie) I did some Google hunting, and found: http://webunit.sourceforge.net/ It looks like the folks there have written something to make it easier to deal with cookies. Unfortunately, I have to profess complete ignorance on this subject. Can anyone suggest other alternatives? Best of wishes! From lha2@columbia.edu Sat Sep 8 12:13:52 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Sat, 08 Sep 2001 07:13:52 -0400 Subject: [Tutor] wxpython Message-ID: <3B99FD70.D5F52130@mail.verizon.net> I'd like to look at PythonCard, but it seems that first I must install wxpython. My issue is that the installer for (windows 98) wxpython 2.3.1 for python 2.1 won't recognize my Python 2.1a2. Even if I launch the installer from the directory where Python lives, I get the error, "No installation of Python 2.1 found. Aborting..." Is there a way to get around this? Thanks, LHA From wrong@crosswinds.net Sat Sep 8 14:08:42 2001 From: wrong@crosswinds.net (Charlie Derr) Date: Sat, 8 Sep 2001 09:08:42 -0400 Subject: [Tutor] wxpython In-Reply-To: <3B99FD70.D5F52130@mail.verizon.net> Message-ID: Install Python 2.1.1. If you don't want to remove your 2.1a2 immediately, you can just point the 2.1.1 installer to use a different directory (assuming 2.1a2 is installed at C:\Python21 -- if it's not installed there, that's where you would want to install 2.1.1). ~c ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ Lloyd Hugh Allen ~ Sent: Saturday, September 08, 2001 7:14 AM ~ To: tutor@python.org ~ Subject: [Tutor] wxpython ~ ~ ~ I'd like to look at PythonCard, but it seems that first I must install ~ wxpython. My issue is that the installer for (windows 98) wxpython 2.3.1 ~ for python 2.1 won't recognize my Python 2.1a2. Even if I launch the ~ installer from the directory where Python lives, I get the error, "No ~ installation of Python 2.1 found. Aborting..." ~ ~ Is there a way to get around this? ~ ~ Thanks, ~ LHA ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor From Griesbaum@aol.com Sat Sep 8 14:18:00 2001 From: Griesbaum@aol.com (Griesbaum@aol.com) Date: Sat, 8 Sep 2001 09:18:00 EDT Subject: [Tutor] Learning Python Message-ID: I'm a complete newbie to programming and have heard from Leo Laporte on Tech TV that python is good for people just starting out. Early on in the book I'm having some problems. When I type this line in the book under the heading (Running Module Files) % python spam.py -i eggs -o bacon I get SyntaxError: invalid syntax. Am I reading this correctly in the book? Is the symbol before the python a percentage mark? This seems to be an ongoing problem in the book whenever I type something exactly the way it is in the book I get some type of error message. Is there a better python book to start out with for complete beginners? Is there a better book for complete beginners? From lkvam@venix.com Sat Sep 8 14:56:48 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Sat, 08 Sep 2001 09:56:48 -0400 Subject: [Tutor] Learning Python References: Message-ID: <3B9A23A0.AE6336EA@venix.com> The % is probably a Unix or Linux prompt character. Under Windows/Dos the prompt usually is > You should be typing: python spam.py -i eggs -o bacon Be sure you are doing this from the correct directory. Breaking this down a bit: python starts the pythoin interpreter spam.py python program you want to run -i eggs parameter to the program (maybe input??) -o bacon parameter to the program (maybe output??) Griesbaum@aol.com wrote: > > I'm a complete newbie to programming and have heard from Leo Laporte on Tech > TV that python is good for people just starting out. Early on in the book I'm > having some problems. When I type this line in the book under the heading > (Running Module Files) % python spam.py -i eggs -o bacon I get SyntaxError: > invalid syntax. Am I reading this correctly in the book? Is the symbol before > the python a percentage mark? This seems to be an ongoing problem in the book > whenever I type something exactly the way it is in the book I get some type > of error message. Is there a better python book to start out with for > complete beginners? Is there a better book for complete beginners? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From wrong@crosswinds.net Sat Sep 8 15:00:54 2001 From: wrong@crosswinds.net (Charlie Derr) Date: Sat, 8 Sep 2001 10:00:54 -0400 Subject: [Tutor] Learning Python In-Reply-To: Message-ID: The % represents a command prompt. Probably if you're on a windows machine you have a > instead of a %. In any case you shouldn't type it. If you've got python installed, and your PATH is set properly, and you've created a "spam.py" file (and perhaps an "eggs" file as well?) in the current directory then I assume the following should work for you: python spam.py -i eggs -o bacon I don't have a copy of Learning Python in front of me at the moment, but it's pretty good from what I remember. You may also find http://python.org/doc/Newbies.html helpful. Alan Gauld also has some great stuff at http://www.crosswinds.net/~agauld/. And don't hesitate to come back here and ask more questions as you have them. That's what the list is for :-] ~c ~ -----Original Message----- ~ From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of ~ Griesbaum@aol.com ~ Sent: Saturday, September 08, 2001 9:18 AM ~ To: tutor@python.org ~ Subject: [Tutor] Learning Python ~ ~ ~ I'm a complete newbie to programming and have heard from Leo ~ Laporte on Tech ~ TV that python is good for people just starting out. Early on in ~ the book I'm ~ having some problems. When I type this line in the book under the heading ~ (Running Module Files) % python spam.py -i eggs -o bacon I get ~ SyntaxError: ~ invalid syntax. Am I reading this correctly in the book? Is the ~ symbol before ~ the python a percentage mark? This seems to be an ongoing problem ~ in the book ~ whenever I type something exactly the way it is in the book I get ~ some type ~ of error message. Is there a better python book to start out with for ~ complete beginners? Is there a better book for complete beginners? ~ ~ _______________________________________________ ~ Tutor maillist - Tutor@python.org ~ http://mail.python.org/mailman/listinfo/tutor From lkvam@venix.com Sat Sep 8 15:10:00 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Sat, 08 Sep 2001 10:10:00 -0400 Subject: [Tutor] Learning Python References: Message-ID: <3B9A26B8.13F3CEDA@venix.com> Unfortunately, it is hard to turn the instructions in a book into the exactly correct input your computer expects. Very often the best solution is a knowledgeable friend at your side to help you get started. Griesbaum@aol.com wrote: > > I'm a complete newbie to programming and have heard from Leo Laporte on Tech > TV that python is good for people just starting out. Early on in the book I'm > having some problems. When I type this line in the book under the heading > (Running Module Files) % python spam.py -i eggs -o bacon I get SyntaxError: > invalid syntax. Am I reading this correctly in the book? Is the symbol before > the python a percentage mark? This seems to be an ongoing problem in the book > whenever I type something exactly the way it is in the book I get some type > of error message. Is there a better python book to start out with for > complete beginners? Is there a better book for complete beginners? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From csmith@blakeschool.org Sat Sep 8 15:36:26 2001 From: csmith@blakeschool.org (Christopher Smith) Date: Sat, 08 Sep 2001 09:36:26 -0500 Subject: [Tutor] Re: What is the best way to count the number of lines in a huge file? Message-ID: >On Thu, 6 Sep 2001, dman wrote: > >> On Thu, Sep 06, 2001 at 09:07:08AM -0400, Ignacio Vazquez-Abrams wrote: >> | Fair enough: >> | >> | --- >> | a=None >> | n=0 >> | while not a='': >> | a=file.read(262144) >> | n+=a.count(os.linesep) >> | --- >> >> The only problem with this is it only (truly properly) counts the >> lines of files that were created with the same OS as the one >> counting. >> >> You'd probably want to use a regex to search for "\r\n|\r|\n", but it >> all depends on the source(s) of the files you want to count. >> >> Make your script "good enough", not "perfect according to some misty >> definition". :-). >> >> -D > >Even using that RE (and in fact, of using the given code on Windows) is >that >the \r\n may straddle a 256k boundary, losing one line in the code, and >gaining one with the RE. Fair enough again...how about this to count the number occurances of separators (or anything else) in a file: def countInFile(f,sep): '''Count the number of occurance of sep that occur in f and return a tuple (count,x) where x is 1 if the last chunk read from f did not contain sep. This might be useful if you are counting line endings in f and the last line of f does not have an explicit sep at the end; in this case the calling script should add x to the count.''' # # Notes: # whatever is passed in as f must have a 'read' method # that returns '' when there is no more to read. # make chunksize as large as you can on your system # chunksize=262144 sepl=len(sep) last='' count=0 more=f.read(chunksize) while more: chunk=last+more count+=chunk.count(sep) last=chunk[-sepl:] #there might be a split sep in here if last==sep: #nope, just a whole one that we already counted last='' more=f.read(chunksize) if last<>'': x=1 else: x=0 return count,x /c From uselesspython@yahoo.com Sat Sep 8 16:08:16 2001 From: uselesspython@yahoo.com (Rob) Date: Sat, 08 Sep 2001 10:08:16 -0500 Subject: [Tutor] Learning Python References: Message-ID: <3B9A3460.36C7A739@yahoo.com> Griesbaum@aol.com wrote: > > I'm a complete newbie to programming and have heard from Leo Laporte on Tech > TV that python is good for people just starting out. Early on in the book I'm > having some problems. When I type this line in the book under the heading > (Running Module Files) % python spam.py -i eggs -o bacon I get SyntaxError: > invalid syntax. Am I reading this correctly in the book? Is the symbol before > the python a percentage mark? This seems to be an ongoing problem in the book > whenever I type something exactly the way it is in the book I get some type > of error message. Is there a better python book to start out with for > complete beginners? Is there a better book for complete beginners? > In addition to books (which tend to cost money), there are a number of nifty tutorials out there: http://www.lowerstandard.com/python/tutoriallinks.html *Learning to Program* (the second link from the top) is quite handy, introducing programming concepts using Python and a couple of other languages for comparison, and has a book version focused on Python in particular. *Teach Yourself Python in 24 Hours* is another good book for beginners, as is *Core Python Programming* by Wesley Chun. We're all happy to help answer puzzling questions, so ask away. There are also lots of working examples of newbie and other Python code at Useless Python, so you can find interesting code to play with. Happy Whatever Day It Is, Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From uselesspython@yahoo.com Sat Sep 8 16:10:08 2001 From: uselesspython@yahoo.com (Rob) Date: Sat, 08 Sep 2001 10:10:08 -0500 Subject: [Tutor] Learning Python References: Message-ID: <3B9A34D0.E36A43E7@yahoo.com> Griesbaum@aol.com wrote: > > I'm a complete newbie to programming and have heard from Leo Laporte on Tech > TV that python is good for people just starting out. Yea Leo! I keep telling people he's alright. Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From ignacio@openservices.net Sat Sep 8 16:39:16 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 8 Sep 2001 11:39:16 -0400 (EDT) Subject: [Tutor] Re: What is the best way to count the number of lines in a huge file? In-Reply-To: Message-ID: On Sat, 8 Sep 2001, Christopher Smith wrote: > >Even using that RE (and in fact, of using the given code on Windows) is > >that > >the \r\n may straddle a 256k boundary, losing one line in the code, and > >gaining one with the RE. > > > Fair enough again...how about this to count the number occurances of > separators > (or anything else) in a file: > > def countInFile(f,sep): > '''Count the number of occurance of sep that occur in f and return > a tuple (count,x) where x is 1 if the last chunk read from f did not > contain sep. This might be useful if you are counting line endings > in f and the last line of f does not have an explicit sep at the end; > in this case the calling script should add x to the count.''' > # > # Notes: > # whatever is passed in as f must have a 'read' method > # that returns '' when there is no more to read. > # make chunksize as large as you can on your system > # > chunksize=262144 > sepl=len(sep) > last='' > count=0 > more=f.read(chunksize) > while more: I got chewed out by someone else for writing code this way, so consider yourself chewed out ;) : --- more=None while not more=='': --- > chunk=last+more > count+=chunk.count(sep) > last=chunk[-sepl:] #there might be a split sep in here > if last==sep: #nope, just a whole one that we already counted > last='' > more=f.read(chunksize) > > if last<>'': > x=1 > else: > x=0 > > return count,x Instead of returning a tuple, it might be better to take a third argument (defaulted to 1) that determines whether or not the last line counts if it doesn't end with the seperator. -- Ignacio Vazquez-Abrams From csmith@blakeschool.org Sat Sep 8 18:21:38 2001 From: csmith@blakeschool.org (Christopher Smith) Date: Sat, 08 Sep 2001 12:21:38 -0500 Subject: [Tutor] Re: What is the best way to count the number of lines in a huge file? Message-ID: I just got chewed out by Ignacio for writing more=f.read(stuff) while more process more more=f.read(stuff) and it was suggested that I write # suggestion 1 more=None while not more=='': process more more=f.read(stuff) I consider myself wounded by a friend :-) How to handle this construct in the "one right way" has bothered me and even bothered me as I struggled with what to send in this morning, Ignacio. I thought of two other approaches: # suggestion 2 while 1: more=f.read(stuff) if more=='': break process more # suggestion 2b while 1: more=f.read(stuff) if more<>'': process more else: break and # suggestion 3 more='go' while more<>'': more=f.read(stuff) if more<>'': process more I now consider #2 to be the best; in #1 and #3 you are setting a flag which must be something not equal to the terminating flag, though in both cases you can clearly see that the loop will initiate, there is a chance of making a mistake on the initialization. In addition #3 is a bit repugnant in that you have a test repeated twice (and, for what got me chewed out in the first place, I think this double test is prone to error). I prefer (and wouldn't mind comment) on proposal #2. Here's what it has going for it: -it's obvious the loop will start -it's soon obvious what will stop the loop -the stop condition and request for more data to process occurs only once in the loop -it's better than 2b b/c in 2b the "else" loop is too far away (if the process code is long) -it's better not to use an "else" part to reduce the amount of indentation that must be done. So...here is the updated lineCount incorporating this change and the suggestion that whether or not to count the trailing line is specified as an input option rather than being returned as count information. Thanks for the constructive criticism :-) /c #### def lineCount(f,sep,countTrailer=1): '''Return a count of the number of occurance of sep that occur in f. By default this routine assumes that sep indicates the end of a line and that if the last line doesn't end in sep it should be counted anyway. To get a strict count of the occurances of sep send a 0 for the 3rd argument.''' # # Notes: # whatever is passed in as f must have a 'read' method # that returns '' when there is no more to read. # make chunksize as large as you can on your system # chunksize=262144 sepl=len(sep) last='' count=0 while 1: more=f.read(chunksize) if more=='': break chunk=last+more count+=chunk.count(sep) last=chunk[-sepl:] #there might be a split sep in here if last==sep: #nope, just a whole one that we already counted last='' if last<>'' and countTrailer==1: count+=1 return count From alan.gauld@bt.com Sat Sep 8 18:20:30 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 8 Sep 2001 18:20:30 +0100 Subject: [Tutor] Display standard output in Tk widget Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20F6E7079@mbtlipnt02.btlabs.bt.co.uk> Here's a short script to demonstrate stdout going to a Text widget, as requested by somebody recently. Its very basic but shows the principle... Rob, if you want it for Useless python feel free to grab it... Alan Gauld BT computing partners Tel : 0141 220 8795 Fax : 0141 248 1284 ####################### # File: tkoutput.py # Author: A.J. Gauld # Date: September 2001 # from Tkinter import * import sys class Display(Frame): ''' Demonstrate python interpreter output in Tkinter Text widget type python expression in the entry, hit DoIt and see the results in the text pane.''' def __init__(self,parent=0): Frame.__init__(self,parent) self.entry = Entry(self) self.entry.pack() self.doIt = Button(self,text="DoIt", command=self.onEnter) self.doIt.pack() self.output = Text(self) self.output.pack() sys.stdout = self self.pack() def onEnter(self): print eval(self.entry.get()) def write(self, txt): self.output.insert(END,str(txt)) if __name__ == '__main__': Display().mainloop() From dell2100@prodigy.net Sat Sep 8 19:14:00 2001 From: dell2100@prodigy.net (David L. Lerner) Date: Sat, 8 Sep 2001 14:14:00 -0400 Subject: [Tutor] proper import syntax References: Message-ID: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> Let's say I need to use several different functions from the module 'string'... Do I use 'from string import *', import each function individually, or put 'string.' in front of each function? I've seen it all three ways. Thank you David L. Lerner dell2100@prodigy.net Often, the most striking and innovative solutions come from realizing that your concept of the problem was wrong. Eric Steven Raymond From uselesspython@yahoo.com Sat Sep 8 19:34:58 2001 From: uselesspython@yahoo.com (Rob) Date: Sat, 08 Sep 2001 13:34:58 -0500 Subject: [Tutor] proper import syntax References: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> Message-ID: <3B9A64D2.C70F1EBE@yahoo.com> "David L. Lerner" wrote: > > Let's say I need to use several different functions from the module > 'string'... > > Do I use 'from string import *', import each function individually, or put > 'string.' in front of each function? > > I've seen it all three ways. > > Thank you > This is a great question, and I look forward to seeing the different answers offered. Are you specifically interested in the answer as it would apply to the string module, or as a practice in general? Any time you face this decision for a given module, there are a number of factors to consider. Most of the really interesting problems I've seen people run into seem related to naming conflicts. "import string" imports the module and directly executes the top-level part of the module (but only the first time you import the module), whereas "from string import *" imports each individual module element. "from [some module] import *" is sometimes useful, but you need to exercise some care to make sure you don't use names in your module that are identical to names you import directly this way. Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From lumbricus@gmx.net Sat Sep 8 19:56:15 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Sat, 8 Sep 2001 20:56:15 +0200 Subject: [Tutor] Re: What is the best way to count the number of lines in a huge file? In-Reply-To: ; from csmith@blakeschool.org on Sat, Sep 08, 2001 at 12:21:38PM -0500 References: Message-ID: <20010908205615.A5383@Laplace.localdomain> On Sat, Sep 08, 2001 at 12:21:38PM -0500, Christopher Smith wrote: > I just got chewed out by Ignacio for writing > > I consider myself wounded by a friend :-) How to handle > this construct in the "one right way" has bothered me and > even bothered me as I struggled with what to send in this > morning, Ignacio. I thought of two other approaches: > > # suggestion 2 > while 1: > more=f.read(stuff) > if more=='': > break > process more > How about while 1: more=f.read(stuff) if not more: break process more YMMV HTH,HAND J"o! :-) -- "I suppose you expect me to talk." "No, Mr. Bond. I expect you to die." -- Goldfinger From ak@silmarill.org Sat Sep 8 20:18:57 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Sat, 08 Sep 2001 15:18:57 -0400 Subject: [Tutor] proper import syntax In-Reply-To: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> References: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> Message-ID: <20010908151857.A2333@sill.silmarill.org> On Sat, Sep 08, 2001 at 02:14:00PM -0400, David L. Lerner wrote: > Let's say I need to use several different functions from the module > 'string'... > > Do I use 'from string import *', import each function individually, or put > 'string.' in front of each function? > > I've seen it all three ways. from module import * is the "wrong" way. You only use it from interactive interpreter or very small scripts. There are two problems with it: first, someone reading the code will see a function used but will have no idea where it came from. If you have many such import statements, it can be quite hard to figure out which module the function belongs to; second, you may overshadow variables or functions, for instance if you do from os import * you overshadow open() function that normally opens a file, but os.open() does something different. It can be very confusing - you do the import and suddenly files stop opening with odd errors! Newbies get this problem quite often. The only advantage is that there's least typing involved, of all three ways. from module import func is good if you use func many times and don't want to type module.func every time. However, this comes at a cost: when someone's reading your code he may not immediately see where the function came from, he'll have to look where the import statement is to figure it out. import module; module.func() is the preferred usage in most cases - you do a bit more typing with each invocation but it's the clearest and most explicit. No confusion is possible here. Did I miss anything? - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From ak@silmarill.org Sat Sep 8 20:22:42 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Sat, 08 Sep 2001 15:22:42 -0400 Subject: [Tutor] proper import syntax In-Reply-To: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> References: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> Message-ID: <20010908152242.B2333@sill.silmarill.org> On Sat, Sep 08, 2001 at 02:14:00PM -0400, David L. Lerner wrote: > Let's say I need to use several different functions from the module > 'string'... > > Do I use 'from string import *', import each function individually, or put > 'string.' in front of each function? > > I've seen it all three ways. > Oh yes, I did forget something... If you need to reload module later in the program, like this: reload(module), then you *have* to use import module; module.func() method of usage. In other two, functions get imported, but when you reload the module, functions are still the 'old' ones. You can still do import module as mod and then do reload(mod), though. - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From urnerk@qwest.net Sat Sep 8 20:46:29 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sat, 08 Sep 2001 12:46:29 -0700 Subject: [Tutor] proper import syntax In-Reply-To: <20010908151857.A2333@sill.silmarill.org> References: <000a01c13892$096b6b60$79e1fcd1@prodigy.net> <000a01c13892$096b6b60$79e1fcd1@prodigy.net> Message-ID: <4.2.0.58.20010908123221.00cfa160@pop3.norton.antivirus> > >Did I miss anything? > >- Andrei I think you gave a pretty good answer. When it comes to others reading code, there are always comments and __doc__ strings etc., so you have the ability to give more clues if your think a readership might be appreciative. Sometimes what we're importing are packages, not just modules, as defined by some __init__.py in the package directory. These may be written in such a way that 'from package import *' gives you a small set of classes you'd like to have top-level. If that might be confusing for readers, just say something in comments. Booting to IDLE: >>> dir() ['__builtins__', '__doc__', '__name__'] This shows an initially "empty" shell namespace. Now I bring in a package: >>> from mathobjects import * >>> dir() ['Fraction', 'Matrix', 'Poly', 'Sqmatrix', '__builtins__', '__doc__', '__name__', 'deriv', 'polynomial', 'pyfraction', 'simplematrix'] Some new tools have been added. But it's not clear which of these might be variables, which might be modules etc. If I'm in shell mode and want to do some introspection, I could go: >>> for i in dir(): eval(i) This spits back some useful information about what's in my bag: '__main__' 'i' I see that I've imported some classes and modules. I might further analyze a class: >>> dir(Fraction) ['__abs__', '__add__', '__div__', '__doc__', '__eq__', '__float__', '__gt__', '__init__', '__lt__', '__module__', '__mul__', '__neg__', '__pow__', '__radd__', '__rdiv__', '__repr__', '__rmul__', '__rsub__', '__sub__', 'denom', 'fformat', 'float', 'list', 'mkfract', 'numer', 'recip', 'simplify'] Hmmm.... looks like I can add, subtract Fraction objects. The author (me) doesn't seem to have put in a lot of helpful __doc__ strings, so I'm not sure how to initialize a Fraction object. I can look at the code, if I have Python source (not always the case). ... not disagreeing with anything you typed, just riffing on how a user might probe and prod imported stuff, to figure out what's going on. In this sense, I'm inspired by your excellent model: always try to look at what you're doing from the point of view of some reader who doesn't have the benefit of your intimate knowledge of whatever it is you're doing (good advice for life-at-large, I'd add). Kirby From girishg@india.ti.com Sat Sep 8 21:29:01 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Sun, 09 Sep 2001 01:59:01 +0530 Subject: [Tutor] How do I do this Message-ID: <3B9A7F8D.ADE3EC36@india.ti.com> Hi All, I was trying to get the documentation of all functions in a particular module, as follows: ############################################ #! /usr/bin/env python """Documentation comes like this. this will be the documentation for this file(module) """ import sys, os, string, getopt def main(): for i in dir(getopt): print i, getopt.i.__doc__ # assuming i will be substituted for each of the # modules, functions and we will get __doc__ for # each of these main() ############################################ This does not work. How do I do this? Thanks & Best regards Girish From kalle@gnupung.net Sat Sep 8 21:47:01 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sat, 8 Sep 2001 22:47:01 +0200 Subject: [Tutor] How do I do this In-Reply-To: <3B9A7F8D.ADE3EC36@india.ti.com>; from girishg@india.ti.com on Sun, Sep 09, 2001 at 01:59:01AM +0530 References: <3B9A7F8D.ADE3EC36@india.ti.com> Message-ID: <20010908224701.A21381@gandalf> [Girish Gajwani] > Hi All, > > I was trying to get the documentation of all functions in a > particular module, as follows: > > > ############################################ > #! /usr/bin/env python > > """Documentation comes like this. > > this will be the documentation for this file(module) > > """ > import sys, os, string, getopt > > def main(): > for i in dir(getopt): > print i, getopt.i.__doc__ # assuming i will be substituted for each of the > # modules, functions and we will get __doc__ for > # each of these > main() > > ############################################ > > This does not work. How do I do this? def main(): for i in dir(getopt): try: print i, getattr(getopt, i).__doc__ except AttributeError: print "getopt.%s has no __doc__ attribute" % i seems to work. Peace, Kalle -- [ kalle@gnupung.net ][ Thought control, brought to you by the WIPO! ] [ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ] From dsh8290@rit.edu Sat Sep 8 21:38:19 2001 From: dsh8290@rit.edu (dman) Date: Sat, 08 Sep 2001 16:38:19 -0400 Subject: [Tutor] How do I do this In-Reply-To: <3B9A7F8D.ADE3EC36@india.ti.com> References: <3B9A7F8D.ADE3EC36@india.ti.com> Message-ID: <20010908163819.A21669@hudson> On Sun, Sep 09, 2001 at 01:59:01AM +0530, Girish Gajwani wrote: | Hi All, | | I was trying to get the documentation of all functions in a | particular module, as follows: Take a look at pydoc -- all the hard work has been done for you. | ############################################ | #! /usr/bin/env python | | """Documentation comes like this. | | this will be the documentation for this file(module) | | """ | import sys, os, string, getopt | | def main(): | for i in dir(getopt): | print i, getopt.i.__doc__ # assuming i will be This line is the problem. When you write foo.bar in the source code 'foo' is the name of an object and 'bar' is the name of its member. As you have it here you are printing each object of the getopt module by a *reference* to it ('i'), then trying to get the member of the getopt module *named* i, which probably doesn't exist. Instead try this print i , i.__doc__ HTH, -D From ignacio@openservices.net Sat Sep 8 21:46:31 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 8 Sep 2001 16:46:31 -0400 (EDT) Subject: [Tutor] How do I do this In-Reply-To: <3B9A7F8D.ADE3EC36@india.ti.com> Message-ID: On Sun, 9 Sep 2001, Girish Gajwani wrote: > Hi All, > > I was trying to get the documentation of all functions in a > particular module, as follows: > > [snip] > > This does not work. How do I do this? > > Thanks & Best regards > Girish def getdocs(n): for i in dir(n): try: print '%s: %s' % (i, getattr(n, i).__doc__) print except: print -- Ignacio Vazquez-Abrams From girishg@india.ti.com Sat Sep 8 23:08:59 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Sun, 09 Sep 2001 03:38:59 +0530 Subject: [Tutor] more help required ( __doc__ & dir() ) Message-ID: <3B9A96FB.157538C0@india.ti.com> Hi All, Thanks for a reply to my earlier post. It solved my problem Next, what I wish to do is this: ####################### #! /usr/bin/env python import sys def main(): print dir() # gives [] main() print dir() # gives ['__builtins__', '__doc__', '__name__', 'main', 'sys'] ####################### In the main() function, why am I not able to see the module sys? while i can see it from the outermost level. How do i make it visible to the inner directory level(hope it is clear) Also, I am currently subscribed to the mailing list in digest mode. If I were to switch to individual mail, would I lose the mails in between(i.e., those mails which were supposed to come in the next digest?) TIA, Girish From ignacio@openservices.net Sat Sep 8 23:23:26 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 8 Sep 2001 18:23:26 -0400 (EDT) Subject: [Tutor] more help required ( __doc__ & dir() ) In-Reply-To: <3B9A96FB.157538C0@india.ti.com> Message-ID: On Sun, 9 Sep 2001, Girish Gajwani wrote: > Hi All, > > Thanks for a reply to my earlier post. It solved my problem > > Next, what I wish to do is this: > > [snip] > > In the main() function, why am I not able to see the module > sys? while i can see it from the outermost level. How do i > make it visible to the inner directory level(hope it is > clear) Use globals(). > Also, I am currently subscribed to the mailing list in > digest mode. If I were to switch to individual mail, would I > lose the mails in between(i.e., those mails which were > supposed to come in the next digest?) Stay subscribed to the digest until you're sure that it's safe to unsubscribe. -- Ignacio Vazquez-Abrams From girishg@india.ti.com Sat Sep 8 23:50:42 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Sun, 09 Sep 2001 04:20:42 +0530 Subject: [Tutor] more help required ( __doc__ & dir() ) References: <3B9AA028.F6F9595C@india.ti.com> Message-ID: <3B9AA0C2.7B3E6CE4@india.ti.com> The Use globals() was not very clear to me. regards, Girish > [Tutor] more help required ( __doc__ & dir() ) > > Ignacio Vazquez-Abrams ignacio@openservices.net > Sat, 8 Sep 2001 18:23:26 -0400 (EDT) > > > On Sun, 9 Sep 2001, Girish Gajwani wrote: > > > Hi All, > > > > Thanks for a reply to my earlier post. It solved my problem > > > > Next, what I wish to do is this: > > > > [snip] > > > > In the main() function, why am I not able to see the module > > sys? while i can see it from the outermost level. How do i > > make it visible to the inner directory level(hope it is > > clear) > > Use globals(). > > > Also, I am currently subscribed to the mailing list in > > digest mode. If I were to switch to individual mail, would I > > lose the mails in between(i.e., those mails which were > > supposed to come in the next digest?) > > Stay subscribed to the digest until you're sure that it's safe to unsubscribe. > > -- > Ignacio Vazquez-Abrams From kalle@gnupung.net Sat Sep 8 23:58:51 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sun, 9 Sep 2001 00:58:51 +0200 Subject: OT: Digest to ordinary (Was: [Tutor] more help required ( __doc__ & dir() )) In-Reply-To: <3B9A96FB.157538C0@india.ti.com>; from girishg@india.ti.com on Sun, Sep 09, 2001 at 03:38:59AM +0530 References: <3B9A96FB.157538C0@india.ti.com> Message-ID: <20010909005850.A21805@gandalf> [Girish Gajwani] > Also, I am currently subscribed to the mailing list in > digest mode. If I were to switch to individual mail, would I > lose the mails in between(i.e., those mails which were > supposed to come in the next digest?) I don't think so. I think you will begin receiving individual messages immediately. Peace, Kalle -- [ kalle@gnupung.net ][ Thought control, brought to you by the WIPO! ] [ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ] From uselesspython@yahoo.com Sat Sep 8 23:56:31 2001 From: uselesspython@yahoo.com (Rob) Date: Sat, 08 Sep 2001 17:56:31 -0500 Subject: OT: Digest to ordinary (Was: [Tutor] more help required ( __doc__ & dir() )) References: <3B9A96FB.157538C0@india.ti.com> <20010909005850.A21805@gandalf> Message-ID: <3B9AA21F.29E3BBA9@yahoo.com> Kalle Svensson wrote: > > [Girish Gajwani] > > Also, I am currently subscribed to the mailing list in > > digest mode. If I were to switch to individual mail, would I > > lose the mails in between(i.e., those mails which were > > supposed to come in the next digest?) > > I don't think so. I think you will begin receiving individual messages > immediately. > And you can always check the Tutor Archives the next day just to make sure you didn't miss anything. Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From ignacio@openservices.net Sun Sep 9 00:01:55 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 8 Sep 2001 19:01:55 -0400 (EDT) Subject: [Tutor] more help required ( __doc__ & dir() ) In-Reply-To: <3B9AA0C2.7B3E6CE4@india.ti.com> Message-ID: On Sun, 9 Sep 2001, Girish Gajwani wrote: > The Use globals() was not very clear to me. > > regards, > Girish The globals() function returns the global namespace as a dictionary: --- >>> print globals() {'__doc__': None, '__name__': '__main__', '__builtins__': } >>> --- -- Ignacio Vazquez-Abrams From dsh8290@rit.edu Sun Sep 9 00:51:28 2001 From: dsh8290@rit.edu (dman) Date: Sat, 08 Sep 2001 19:51:28 -0400 Subject: [Tutor] more help required ( __doc__ & dir() ) In-Reply-To: <3B9A96FB.157538C0@india.ti.com> References: <3B9A96FB.157538C0@india.ti.com> Message-ID: <20010908195128.A2514@hudson> On Sun, Sep 09, 2001 at 03:38:59AM +0530, Girish Gajwani wrote: | Hi All, | | Thanks for a reply to my earlier post. It solved my problem | | Next, what I wish to do is this: | | ####################### | #! /usr/bin/env python | | import sys | def main(): | print dir() # gives [] | | main() | print dir() # gives ['__builtins__', '__doc__', | '__name__', 'main', 'sys'] | ####################### | | In the main() function, why am I not able to see the module | sys? while i can see it from the outermost level. How do i | make it visible to the inner directory level(hope it is | clear) >>> print dir.__doc__ dir([object]) -> list of strings Return an alphabetized list of names comprising (some of) the attributes of the given object. Without an argument, the names in the current scope are listed. With an instance argument, only the instance attributes are returned. With a class argument, attributes of the base class are not returned. For other types or arguments, this may list members or methods. >>> Apparently if you don't give an argument to dir() it returns a list of the *current* scope. The second dir is at the module level so the current scope for it is the module. When you are in the function main, the current scope is the local scope of the function. The sys module is in the current module's scope, but not main's local scope. HTH, -D From grimmtoothtoo@yahoo.com Sun Sep 9 03:10:01 2001 From: grimmtoothtoo@yahoo.com (Grimmtooth) Date: Sat, 8 Sep 2001 22:10:01 -0400 Subject: [Tutor] proper import syntax In-Reply-To: <4.2.0.58.20010908123221.00cfa160@pop3.norton.antivirus> Message-ID: > excellent model: always try to look at what you're doing > from the point of view of some reader who doesn't have the > benefit of your intimate knowledge of whatever it is you're > doing (good advice for life-at-large, I'd add). Don't forget yourself! "Any source code you haven't touched in two months might as well been written by a stranger." :-D _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From planets3000@hotmail.com Sun Sep 9 05:11:24 2001 From: planets3000@hotmail.com (Charles Lim) Date: Sun, 9 Sep 2001 12:11:24 +0800 Subject: [Tutor] log Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C13928.8BA66EE0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: base64 RGVhciBTaXIvTWFkYW0sICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg IDkvOS8yMDAxDQoNCg0KSWYgc29tZW9uZSBrbm93cyBob3cgdG8gd3JpdGUgYSBwcm9ncmFtIHRo YXQgY29tcHV0ZXMgbG9nIGJhc2UgMTAgYW5kIG5hdHVyYWwgbG9nIHBsZWFzZSB3cml0ZSBtZSBh IGZldyBleGFtcGxlcyBhbmQgZXhwbGFpbiBob3cgdGhleSB3b3JrLiBUaGFuayB5b3UuDQoNClNp bmNlcmVseSwNCg0KQ2hhcmxlcw0KDQoNCg== ------=_NextPart_000_0005_01C13928.8BA66EE0 Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: base64 PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdi MjMxMiIgaHR0cC1lcXVpdj1Db250ZW50LVR5cGU+DQo8TUVUQSBjb250ZW50PSJNU0hUTUwgNS4w MC4yNjE0LjM1MDAiIG5hbWU9R0VORVJBVE9SPg0KPFNUWUxFPjwvU1RZTEU+DQo8L0hFQUQ+DQo8 Qk9EWSBiZ0NvbG9yPSNmZmZmZmY+DQo8RElWPjxGT05UIHNpemU9Mj5EZWFyIA0KU2lyL01hZGFt LCZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZu YnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNw OyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZu YnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNw OyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyANCjkvOS8yMDAxPC9GT05UPjwvRElWPg0KPERJVj4m bmJzcDs8L0RJVj4NCjxESVY+Jm5ic3A7PC9ESVY+DQo8RElWPjxGT05UIHNpemU9Mj5JZiBzb21l b25lIGtub3dzIGhvdyB0byB3cml0ZSBhIHByb2dyYW0gdGhhdCBjb21wdXRlcyBsb2cgYmFzZSAN CjEwIGFuZCBuYXR1cmFsIGxvZyBwbGVhc2Ugd3JpdGUgbWUgYSBmZXcgZXhhbXBsZXMgYW5kIGV4 cGxhaW4gaG93IHRoZXkgd29yay4gDQpUaGFuayB5b3UuPC9GT05UPjwvRElWPg0KPERJVj4mbmJz cDs8L0RJVj4NCjxESVY+PEZPTlQgc2l6ZT0yPlNpbmNlcmVseSw8L0ZPTlQ+PC9ESVY+DQo8RElW PiZuYnNwOzwvRElWPg0KPERJVj48Rk9OVCBzaXplPTI+Q2hhcmxlczwvRk9OVD48L0RJVj4NCjxE SVY+Jm5ic3A7PC9ESVY+DQo8RElWPiZuYnNwOzwvRElWPjwvQk9EWT48L0hUTUw+DQo= ------=_NextPart_000_0005_01C13928.8BA66EE0-- From planets3000@hotmail.com Sun Sep 9 05:16:10 2001 From: planets3000@hotmail.com (Charles Lim) Date: Sun, 9 Sep 2001 12:16:10 +0800 Subject: [Tutor] log Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C13929.3604A140 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: base64 RGVhciBTaXIvTWFkYW0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg IDkvOS8yMDAxDQoNCklmIHNvbWVvbmUga25vd3MgaG93IHRvIHdyaXRlIHByb2dyYW1zIHRoYXQg Y29tcHV0ZXMgbG9nIGJhc2UgdGVuIGFuZCBuYXR1cmFsIGxvZyBvZiBudW1iZXJzIHBsZWFzZSB3 cml0ZSBtZSBhIGZldyBleGFtcGxlcyBhbmQgZXhwbGFpbiBob3cgdGhleSB3b3JrLiBUaGFuayB5 b3UuDQoNClNpbmNlcmVseSwNCg0KQ2hhcmxlcw0K ------=_NextPart_000_0005_01C13929.3604A140 Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: base64 PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdi MjMxMiIgaHR0cC1lcXVpdj1Db250ZW50LVR5cGU+DQo8TUVUQSBjb250ZW50PSJNU0hUTUwgNS4w MC4yNjE0LjM1MDAiIG5hbWU9R0VORVJBVE9SPg0KPFNUWUxFPjwvU1RZTEU+DQo8L0hFQUQ+DQo8 Qk9EWSBiZ0NvbG9yPSNmZmZmZmY+DQo8RElWPjxGT05UIHNpemU9Mj5EZWFyIA0KU2lyL01hZGFt Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5i c3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7 Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5i c3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7 Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7IA0KOS85LzIwMDE8L0ZPTlQ+PC9ESVY+DQo8 RElWPiZuYnNwOzwvRElWPg0KPERJVj48Rk9OVCBzaXplPTI+SWYgc29tZW9uZSBrbm93cyBob3cg dG8gd3JpdGUgcHJvZ3JhbXMgdGhhdCBjb21wdXRlcyBsb2cgYmFzZSANCnRlbiBhbmQgbmF0dXJh bCBsb2cgb2YgbnVtYmVycyBwbGVhc2Ugd3JpdGUgbWUgYSBmZXcgZXhhbXBsZXMgYW5kIGV4cGxh aW4gaG93IA0KdGhleSB3b3JrLiBUaGFuayB5b3UuPC9GT05UPjwvRElWPg0KPERJVj4mbmJzcDs8 L0RJVj4NCjxESVY+PEZPTlQgc2l6ZT0yPlNpbmNlcmVseSw8L0ZPTlQ+PC9ESVY+DQo8RElWPiZu YnNwOzwvRElWPg0KPERJVj48Rk9OVCBzaXplPTI+Q2hhcmxlczwvRk9OVD48L0RJVj48L0JPRFk+ PC9IVE1MPg0K ------=_NextPart_000_0005_01C13929.3604A140-- From ignacio@openservices.net Sun Sep 9 05:08:47 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 9 Sep 2001 00:08:47 -0400 (EDT) Subject: [Tutor] log In-Reply-To: Message-ID: On Sun, 9 Sep 2001, Charles Lim wrote: > If someone knows how to write a program that computes log base 10 and natural log please write me a few examples and explain how they work. Thank you. Umm, 'import math'? http://www.python.org/doc/current/lib/module-math.html -- Ignacio Vazquez-Abrams From uselesspython@yahoo.com Sun Sep 9 05:09:54 2001 From: uselesspython@yahoo.com (Rob) Date: Sat, 08 Sep 2001 23:09:54 -0500 Subject: [Tutor] log References: Message-ID: <3B9AEB92.908232AD@yahoo.com> > Charles Lim wrote: > > Dear Sir/Madam, 9/9/2001 > > > If someone knows how to write a program that computes log base 10 and > natural log please write me a few examples and explain how they work. > Thank you. > Until someone gives you a better answer than this, here's the link to the math module documentation at python.org. http://www.python.org/doc/current/lib/module-math.html Among many other features, it includes: log(x) Return the natural logarithm of x. log10(x) Return the base-10 logarithm of x. > Sincerely, > > Charles > > Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From dyoo@hkn.eecs.berkeley.edu Sun Sep 9 06:28:31 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 8 Sep 2001 22:28:31 -0700 (PDT) Subject: [Tutor] log In-Reply-To: <3B9AEB92.908232AD@yahoo.com> Message-ID: On Sat, 8 Sep 2001, Rob wrote: > > If someone knows how to write a program that computes log base 10 and > > natural log please write me a few examples and explain how they work. > > Thank you. > > > > Until someone gives you a better answer than this, here's the link to > the math module documentation at python.org. > > http://www.python.org/doc/current/lib/module-math.html > > Among many other features, it includes: > > log(x) > Return the natural logarithm of x. > > log10(x) > Return the base-10 logarithm of x. [Note: this next post is not meant to be a serious response to your question.] I thought it might be fun to try this in a completely Useless manner. *grin* ### """A small program to play around with the Taylor expansion of the natural logarithm. Danny Yoo (dyoo@hkn.eecs.berkeley.edu) In Calculus, we learn that a function f(x) can be approximated using a Taylor expansion. That is, f(x) = \sum_{n>=0} [f^n (c_0) (x - c_0)^n] / (n!) or, in less TeXiee terms: SUM (Nth Derivative of f, applied on c_0) * (x - c_0)**n n>=0 ---------------------------------------------------- n! When we apply this formula to the natural logarithm function, what we get is pretty neat: ln(x) = \sum_{n>=1} [(-1)^{n-1} (x-1)^n] / n This is the Taylor expansion of ln(x), centered on x=1. Of course, this is useless, since we can't add this infinite sum up. This version of log has HORRIBLE accuracy the farther we get from the center of the approximation. """ from __future__ import nested_scopes def log(x, iterations = 1000): result = 0 for n in range(1, iterations+1): result += nth_log_term(n)(x) return result def nth_log_term(n): def func(x): if odd(n): return (float(x-1)**n) / float(n) else: return (-float(x-1)**n) / float(n) return func def odd(x): return x % 2 == 1 ### Let's see it in action: ### >>> log(1) 0.0 ## Well, at least it got that right. >>> log(2) 0.69264743055982225 ## Hmmm. ## How far is this from math.log? >>> math.log(2) 0.69314718055994529 ## Ok, so it's sorta close. >>> log(3) -7.1410087914218761e+297 ## That's way off! ### I don't recommend you use this method for your program. *grin* From nwertz@home.com Sun Sep 9 16:17:05 2001 From: nwertz@home.com (Nick Wertzberger) Date: Sun, 9 Sep 2001 10:17:05 -0500 Subject: [Tutor] i have a major problem Message-ID: every time i try to access a file named snakeoil.txt, i get htis message: Traceback (most recent call last): File "", line 1, in ? data=open("snakeoil.txt") IOError: [Errno 2] No such file or directory: 'snakeoil.txt' how do i fix this PROBLEM!?!?!?!? i am getting really frustrated, the file is in the same folder as the program, and i have made a copy on the mail part of my drive so it would be at the beginning. im using version 2.1.1 here's the code i use #!/usr/bin/python # open file data = open("snakeoil.txt") # read file dump = data.read() print dump, "-- EOF -- EOF --" # clean up data.close() From Charlie@begeistert.org Sun Sep 9 16:22:54 2001 From: Charlie@begeistert.org (Charlie Clark) Date: Sun, 09 Sep 2001 17:22:54 +0200 Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: Message-ID: <1000048974_PM_BeOS.Charlie@begeistert.org> Danny and Kirby both wrote to me about a problem I was having in replacing a single apostrophe. I will post the error in another mail, need to boot windows to generate it but I think replacing a single apostrpohe with an escaped one seems to work fine >### >fname, lname = 'Issac', 'Asimov' >cursor.execute("""insert into authors (fname, lname) > values ('%s', '%s')""" % (fname, lname)) >### > >we can use: > >### >fname, lname = 'Issac', 'Asimov' >cursor.execute("""insert into authors (fname, lname) > values (?, ?)""", fname, lname) >### The thing I'm trying to set up a generalised method to work with data coming from dictionaries with different keys so I need to compose the various parts of the SQL commands (database name, column headings, data values) and carefully put them together. I've managed to do this with eval() but since I put the things into a class I'm getting some strange errors. Here's my code: class Database: def __init__(self, database): self.database = database self.db = DriverConnect('DSN=demo-image;UID=sa;PWD=') self.c = self.db.cursor() def clear_database(self): command = "'DELETE FROM " + self.database + "'" # print command self.c.execute(command) def insert_database(self, items, keys = []): ## default is all keys in items, otherwise list of selected keys if keys == []: keys = items[0].keys() names, values = [], [] # list of keys for formatted printing for key in keys: names.append(key) values.append("' %(" + key + ")s '") insert = ", ".join(values) insert = "\"( " + insert + " )\"%item" names = ", ".join(names) # print "names", names # print insert for item in items: sql = eval(insert) # print insert command = "'INSERT INTO " + self.database + "( " + names + " ) VALUES '" + sql # print command self.c.excecute(command) I've had lots of fun getting this work and learned quite a bit while doing it such as why there is such a thing as self. I think self only exists to give a globally addressable namespace within the class. This is currently generating an attribute error on running from mx.ODBC.Windows import DriverConnect # or equivalent dict = [{'name':'charlie', 'age':'too old'}, {'name':'charlies brother', 'age':'too young'}] d = Database("charlies_database") d.insert_database[dict] # this generates an attribute error It's been very useful to be able to test this in the interactive interpreter but the broken history function is a bit annoying. Charlie From ignacio@openservices.net Sun Sep 9 16:25:13 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 9 Sep 2001 11:25:13 -0400 (EDT) Subject: [Tutor] i have a major problem In-Reply-To: Message-ID: On Sun, 9 Sep 2001, Nick Wertzberger wrote: > every time i try to access a file named snakeoil.txt, i get htis message: > Traceback (most recent call last): > File "", line 1, in ? > data=open("snakeoil.txt") > IOError: [Errno 2] No such file or directory: 'snakeoil.txt' > > how do i fix this PROBLEM!?!?!?!? Are you sure that you're getting the case right? -- Ignacio Vazquez-Abrams From urnerk@qwest.net Sun Sep 9 17:18:32 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 09 Sep 2001 09:18:32 -0700 Subject: [Tutor] Problem with IDLE in Windows In-Reply-To: <1000048974_PM_BeOS.Charlie@begeistert.org> References: Message-ID: <4.2.0.58.20010909091240.00cfcb30@pop3.norton.antivirus> > >d = Database("charlies_database") >d.insert_database[dict] # this generates an attribute error The use of square brackets isn't defined in your object. insert_database is a regular "callable" method, expecting parentheses. If you want to supply your own meaning for square brackets, as if you were trying to set the value of a list or dictionary item, you'd have to define __setitem__ in your class -- but I don't see that this is a priority in your case. Just go: d.insert_database(dict) instead. You may still get an error message, but it should be a different one :-D Kirby PS: didn't understand about escaped apostrophe exactly, as your examples don't include any, but I'm glad you've got that working. From jcosby@mindspring.com Sun Sep 9 18:19:33 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Sun, 9 Sep 2001 10:19:33 -0700 Subject: [Tutor] "Internal Server Error" Message-ID: Can somebody tell me why this works: x = dict.items() x.sort(paircomp) for k, v in x: k = string.replace(k, dir + '/', url) k1 = string.replace(k, url, "") print '' print '', k1, ' ', v, counter(v), 'matches
' print '' But when I modify it slightly, if len(dict) = 0: print '

No matches found

' else: x = dict.items() x.sort(paircomp) for k, v in x: k = string.replace(k, dir + '/', url) k1 = string.replace(k, url, "") print '' print '', k1, ' ', v, counter(v), 'matches
' print '' I get an "internal server error"? Jon Cosby jcosby@mindspring.com www.jcosby.com From ignacio@openservices.net Sun Sep 9 18:25:48 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 9 Sep 2001 13:25:48 -0400 (EDT) Subject: [Tutor] "Internal Server Error" In-Reply-To: Message-ID: On Sun, 9 Sep 2001, Jon Cosby wrote: > Can somebody tell me why this works: > > x = dict.items() > x.sort(paircomp) > for k, v in x: > k = string.replace(k, dir + '/', url) > k1 = string.replace(k, url, "") > print '' > print '', k1, ' ', v, counter(v), 'matches
' > print '' > > > But when I modify it slightly, > > > if len(dict) = 0: ^^^ > print '

No matches found

' > else: > x = dict.items() > x.sort(paircomp) > for k, v in x: > k = string.replace(k, dir + '/', url) > k1 = string.replace(k, url, "") > print '' > print '', k1, ' ', v, counter(v), 'matches
' > print '' > > > I get an "internal server error"? If you try running it manually, you'll get a SyntaxError exception. -- Ignacio Vazquez-Abrams From urnerk@qwest.net Sun Sep 9 18:36:29 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sun, 09 Sep 2001 10:36:29 -0700 Subject: [Tutor] "Internal Server Error" In-Reply-To: Message-ID: <4.2.0.58.20010909103159.00cf9a10@pop3.norton.antivirus> > >if len(dict) = 0: ^ Needs to be: == Difficult to debug when running cgi unless you trap the Python error and display it on the server. One option is to do something like this: ============================== #!/usr/local/bin/python import cgi import sys # include this import traceback # include this sys.stderr = sys.stdout print "Content-Type: text/html\n" try: print """ \n \n Feedback\n \n \n """ except: # trap Python error and display in browser print "\n\n
"
       traceback.print_exc()
       print "\n
" ============================== Kirby From sheila@thinkspot.net Sun Sep 9 18:44:15 2001 From: sheila@thinkspot.net (Sheila King) Date: Sun, 09 Sep 2001 10:44:15 -0700 Subject: [Tutor] i have a major problem In-Reply-To: References: Message-ID: <426CC144F33@kserver.org> On Sun, 9 Sep 2001 10:17:05 -0500, "Nick Wertzberger" wrote about [Tutor] i have a major problem: :every time i try to access a file named snakeoil.txt, i get htis message: :Traceback (most recent call last): : File "", line 1, in ? : data=open("snakeoil.txt") :IOError: [Errno 2] No such file or directory: 'snakeoil.txt' : :how do i fix this PROBLEM!?!?!?!? I've recently been having problems of this type, myself. If python says the file doesn't exist, then you must be doing something wrong, like being in the wrong directory, spelling or case error or something. One thing that I have found to help, is adding a few lines to my script, something like this: >>> import os >>> os.listdir(os.curdir) This will return a list of all the files in the current directory. Sometimes looking at the list of files that Python sees in the current directory can be quite insightful. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From mailgrabber-feedback-1@lb.bcentral.com Sun Sep 9 22:09:28 2001 From: mailgrabber-feedback-1@lb.bcentral.com (Anonymouse) Date: 9 Sep 2001 21:09:28 -0000 Subject: [Tutor] Ïðîäàæà,ïîêóïêà ïðîäóêöèè,ïîèñê ïàðòíåðîâ. Message-ID: <1000069768.79405.qmail@ech> Óâàæàåìûå ãîñïîäà! ×òî òàêîå Èíôîðìàöèÿ ? Èíôîðìàöèÿ – ýòî âëàñòü, áîãàòñòâî, óñïåõ, ïðîöâåòàíèå. Êòî âëàäååò èíôîðìàöèåé, òîò óïðàâëÿåò. ÎÎÎ «ÂÈÝËÜ-Ì» ïðåäëàãàåò Âàì âîñïîëüçîâàòüñÿ òàêîé èíôîðìàöèåé è âçÿòü íà ñåáÿ ïðîáëåìó ïîèñêà íåîáõîäèìîãî Âàì îáîðóäîâàíèÿ, ñûðüÿ, ïðèáîðîâ, ìàòåðèàëîâ è ò. ä., ñëîâîì âñåãî òîãî, áåç ÷åãî íå ìîæåò ñóùåñòâîâàòü Âàøå ïðîèçâîäñòâî, óñïåøíî ïðîöâåòàòü Âàø áèçíåñ. Áëàãîäàðÿ îáøèðíûì ñâÿçÿì ñ âåäóùèìè ïðîèçâîäèòåëÿìè è ïîñòàâùèêàìè íå òîëüêî â Ðîññèè, íî è çà ðóáåæîì, ìû èìååì âîçìîæíîñòü âûïîëíÿòü Âàøè çàêàçû íàèáîëåå ïîëíî è â êðàò÷àéøèå ñðîêè. Ñïåêòð íàøåé äåÿòåëüíîñòè äîâîëüíî øèðîê. Ýòî îáëàñòü ýëåêòðîíèêè, ïðè÷åì íå òîëüêî ïîñòàâêè ïðèáîðîâ, àïïàðàòóðû, íî è ðàçëè÷íûå êîìïëåêòóþùèå êàê îòå÷åñòâåííûõ, òàê è çàðóáåæíûõ ïðîèçâîäèòåëåé ýëåêòðîííîé òåõíèêè. Ýòî òàêèå ôèðìû êàê International Rectifier, Epcos, Bourns, Metex, unit-t è äð. Ýòî îáëàñòü ìåòàëëîâåäåíèÿ- ñâàðî÷íûå ýëåêòðîäû, ìåòàëë-ëèñò, óãîëîê, øâåëëåð, ëåíòà, òðóáû è ò.ä. Ýòî ïîñòàâêè ñòàíêîâ, îáîðóäîâàíèÿ äëÿ ïðîèçâîäñòâà, àïïàðàòû ãàçâîäû, ñâåòèëüíèêè äëÿ îôèñîâ è ïðîìûøëåííûõ ïðåäïðèÿòèé, ëþñòðû, ñâàðî÷íîå îáîðóäîâàíèå è ò.ä. Ýòî îáëàñòü ìåäèöèíû- â íàñòîÿùåå âðåìÿ ìû ïðåäñòàâëÿåì óíèêàëüíîå èçîáðåòåíèå ðóññêîãî ó÷åíîãî-ëþñòðó ×èæåâñêîãî. Ñ ïîëíûì ïåðå÷íåì ïðîäóêöèè, ïîñòàâëÿåìîé íàøåé ôèðìîé,Âû ñìîæåòå îçíàêîìèòüñÿ íà íàøåì ñàéòå â èíòåðíåò: vielm.narod.ru Èíôîðìàöèÿ íà äàííîì ñàéòå áóäåò ïîñòîÿííî îáíîâëÿòüñÿ è ñîâåðøåíñòâîâàòüñÿ. Ìû íå ïðîñòî ïðåäîñòàâëÿåì èíôîðìàöèþ, ãäå ìîæíî äîñòàòü íóæíóþ Âàì ïðîäóêöèþ, ìû ñàìè ïîñòàâèì Âàì çàêàçàííûé òîâàð ïî âûãîäíûì äëÿ Âàñ öåíàì è â îïòèìàëüíî êîðîòêèå ñðîêè. Âàøó ïîòðåáíîñòü â ïðîäóêöèè ïðåäñòàâëåííîé íà íàøåì ñàéòå, Âû ìîæåòå îòïðàâèòü íà íàø ôàêñ: (095) 275-89-94, èëè ïî ýëåêòðîííîé ïî÷òå: tandiv@mail.ru . Ìû æäåì Âàñ è âûðàæàåì óâåðåííîñòü â òîì, ÷òî îáðàòèâøèñü ê íàì, Âû ïîëó÷èòå êâàëèôèöèðîâàííóþ ïîìîùü, âíèìàòåëüíîå îòíîøåíèå ê Âàøèì ïîòðåáíîñòÿì, îïåðàòèâíóþ îáðàáîòêó Âàøåãî çàêàçà. Ïî âñåì âîïðîñàì âû ìîæåòå îáðàùàòüñÿ ïî òåëåôîíàì: 275-89-94, 746-68-78. _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=15131&subid=4F31E628C99B6F48&msgnum=1 From SBrunning@trisystems.co.uk Mon Sep 10 08:45:31 2001 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Mon, 10 Sep 2001 08:45:31 +0100 Subject: [Tutor] trouble running Grail Message-ID: <31575A892FF6D1118F5800600846864D78C0F7@intrepid> > From: Lance E Sloan [SMTP:lsloan@umich.edu] > Why would the Grail author give two arguments to append? Was > there an old version of Python that allowed two arguments? In a word, yes. See for an explanation. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From nidhi@ncoretech.com Mon Sep 10 10:05:20 2001 From: nidhi@ncoretech.com (Sreenidhi.B.G) Date: Mon, 10 Sep 2001 14:35:20 +0530 Subject: [Tutor] need some help Message-ID: <3B9C8250.6B01E6C8@ncoretech.com> Helo, I am working on a small example where in I call my c function, and I'm unable to link to the python library. I'm getting undefined reference to these function calls, - PyArg_ParseTuple and Py_BuildValue. can you please help me link this to python library. We are working on Linux7.1.and we are using python 1.5 regards, -sreenidhi, From ajaya@ncoretech.com Mon Sep 10 12:34:55 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Mon, 10 Sep 2001 17:04:55 +0530 Subject: [Tutor] Windows IDE ..., Problems while executing python code ? Message-ID: <000001c139ec$9e373d90$6501a8c0@ncoretech.com> Hi, I am getting a suprising error with Windows IDE, When I want to test my code on windows to check I jsut run uing Ctrl + F5, but when I have a import statements for the user defined modules ..., python is telling me Import error...like this..., File "C:\Python20\projects\VirtualHandset\utils.py", line 8, in ? from HandSetUtils import * ImportError: No module named HandSetUtils But suprisingly my modules are present there it self. Then I just copied these files to the python installation directory...it started working fine..., then I deleted from python installation directory..., but it started working fine...then I closed all windows ..., this time again it started giving the above problem..., I very much cross checked the name and direcotry..., I tried with setting path variable to solve this problem. But it did not help much..., Can any one suggest some thing to fix this problem. with regards, Ajaya From sendme105@hotmail.com Mon Sep 10 12:38:04 2001 From: sendme105@hotmail.com (James) Date: Mon, 10 Sep 2001 04:38:04 -0700 Subject: [Tutor] Re: Help with cookies References: Message-ID: > Dear Python gurus and those who want to become such, > I need to be able to pass a cookie in a url request. import os, string from urllib import * from mimetools import Message #redefine (override?) urlopen to enable cookie sending def urlopen(url, data=None, headers=None): u = FancyURLopener() if headers: if type(headers) == type({}): headers = headers.items() for kw, val in headers: u.addheader(kw, val) return u.open(url, data) # The following gets the cookie info I need... temppage= urlopen(source_url) headers=temppage.info() cookie = headers.getheader("set-cookie") clist = string.split(cookie, ';') temppage.close() # ...to successfully open the page: page = urlopen(source_url, headers=[('Cookie', clist[0])]) ######## Warning: I'm new to programming. I edited this code entirely from a comp.python post found via google. Let me know if it works. James. From alan.gauld@bt.com Mon Sep 10 13:59:56 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 10 Sep 2001 13:59:56 +0100 Subject: [Tutor] sending stdout to a text box Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF37@mbtlipnt02.btlabs.bt.co.uk> > > run from a prompt. How can I catch this and route it to a > text box in tkinter? I posted a short example of this but it wasn't wondersfully commented. Essentially you make sys.stdout point to an object which has a write() method. (This could be your Tkinter application for example) Now when you call print the output will go to the new object. Thus class MyApp(Frame): def __init__(self): # do stuff here self.display = Text(....) # create our text widget sys.stdout = self # Set stdout here def write(self, s): # provide the necessary write method self.display.insert(END.s) # append the string s to the widget # other methods as usual... def foo(self): print "This is foo" # will appear in text widget Hope thats a little clearer. Alan G. From bill_tolbert@bigfoot.com Mon Sep 10 14:30:46 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Mon, 10 Sep 2001 09:30:46 -0400 (EDT) Subject: [Tutor] sending stdout to a text box In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF37@mbtlipnt02.btlabs.bt.co.uk> Message-ID: Thanks for the reply Alan. Kalle posted a good example too (I'm the one who asked originally). I'm close, but not quite where I want to be. I'm trying to incorporate some utility scripts that use print statements to tell the user what's going on (success, error, busy, etc). I want my gui to consolidate these and just redirect the existing print statements to the text widget on the gui. Output from ICAREBackup goes to BogusFile and on to the text box, but not until ICAREBackup finishes. I was looking for a way to provide immediate feedback. Some of these utilities could run for a very long time, leaving the user confused and ready to reboot without feedback. Output to the shell window is immediate; it doesn't wait until the script finishes. Can I duplicate that immediate feedback? def backup(self): import ICAREBackup sys.stdout = BogusFile(self.text_box) ICAREBackup.stdout = BogusFile(self.text_box) ICAREBackup.ICAREBackup() Thanks guys, Bill On Mon, 10 Sep 2001 alan.gauld@bt.com wrote: > > > run from a prompt. How can I catch this and route it to a > > text box in tkinter? > > I posted a short example of this but it wasn't wondersfully commented. > > > Essentially you make sys.stdout point to an object which has > a write() method. (This could be your Tkinter application for > example) > > Now when you call print the output will go to the new object. > > Thus > > class MyApp(Frame): > def __init__(self): > # do stuff here > self.display = Text(....) # create our text widget > sys.stdout = self # Set stdout here > > def write(self, s): # provide the necessary write method > self.display.insert(END.s) # append the string s to the widget > > # other methods as usual... > def foo(self): > print "This is foo" # will appear in text widget > > Hope thats a little clearer. > > Alan G. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > =-=-=-=-=-=-=-=-= Bill Tolbert From lsloan@umich.edu Mon Sep 10 14:55:54 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Mon, 10 Sep 2001 09:55:54 -0400 Subject: [Tutor] trouble running Grail In-Reply-To: Your message of "Fri, 07 Sep 2001 17:19:15 EDT." Message-ID: <200109101355.JAA00076@birds.us.itd.umich.edu> Ignacio Vazquez-Abrams wrote: > Grail is _ancient_. I remember using Grail 0.6 a _looooong_ time ago. Yes, it is pretty old. But I'm convinced that most of the available web browsers do several things wrong, or at least stupidly. Since I'm getting the hang of Python, Grail sounded like a good browser to poke around in the guts of without feeling tainted afterwards. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From jcosby@mindspring.com Mon Sep 10 18:09:15 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Mon, 10 Sep 2001 10:09:15 -0700 Subject: [Tutor] Lists and removal Message-ID: Sorry, I got careless the first time. I was referring to the Python list operation, not removal from the mailing list. I imagine a lot of people ignored my first message. Let's try this again: I'm doing a Web search that is succesful until I try to configure it to ignore specified directories using the "remove" operation. I'm not getting any error messages, but the script stops when it comes to the function below. I've run the first few lines in the interpreter, and I can't see anything wrong with it. Any ideas? def getFile(text, dir): hits = [] dl = os.listdir(dir) for item in ignore: # List of directories to ignore dl.remove(item) # Works in interpreter, but list comes up empty here text = string.lower(text) for d in dl: d = dir + '\\' + d if os.path.isfile(d): hits.extend(searchtext(d, text)) elif os.path.isdir(d): hits.extend(getFile(text, d)) return hits Jon Cosby jcosby@mindspring.com www.jcosby.com From girishg@india.ti.com Mon Sep 10 18:29:18 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Mon, 10 Sep 2001 22:59:18 +0530 Subject: [Tutor] loading modules dynamically Message-ID: <3B9CF86E.7868D460@india.ti.com> Hi all, I have been trying to load modules dynamically using the __import__ hook , as follows: ####################### #! /usr/bin/env python def my_import(name): mod = __import__(name) print mod print dir(mod) return mod mod = my_import("os") print mod.listdir(".") ####################### My interpretation of the __import__ hook is that it loads the module mentioned & also, aliases it to mod. Is this correct? I could not understand the documentation mentioned in the library reference wrt __import__, hence this question. Also, in what case can the above scene fail? What error checking would I need to add here? Regards Girish From dyoo@hkn.eecs.berkeley.edu Mon Sep 10 23:37:22 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 10 Sep 2001 15:37:22 -0700 (PDT) Subject: [Tutor] loading modules dynamically In-Reply-To: <3B9CF86E.7868D460@india.ti.com> Message-ID: On Mon, 10 Sep 2001, Girish Gajwani wrote: > Hi all, > > I have been trying to load modules dynamically using the > __import__ hook , as follows: > > ####################### > #! /usr/bin/env python > > def my_import(name): > mod = __import__(name) > print mod > print dir(mod) > return mod > > mod = my_import("os") > print mod.listdir(".") > ####################### > > My interpretation of the __import__ hook is that it loads > the module mentioned & also, aliases it to mod. Is this > correct? I could not understand the documentation mentioned > in the library reference wrt __import__, hence this > question. Yes, __import__ does load the module and return it: ### >>> m = __import__('os') >>> m ### Note, though, that importing modules this way doesn't automatically allow us to reference the os module with the name 'os': ### >>> os Traceback (most recent call last): File "", line 1, in ? NameError: name 'os' is not defined ### > Also, in what case can the above scene fail? What error > checking would I need to add here? When Python imports a module, and runs into an error, it will raise an "ImportError". For example: ### >>> m = __import__('skljfflskj') Traceback (most recent call last): File "", line 1, in ? ImportError: No module named skljfflskj ### What we can do is write a small exception handler that checks for this situation. Here's one version of my_import() that checks for ImportErrors: def my_import(name): try: mod = __import__(name) except ImportError: print "Whoops, I don't know about", name return None print mod print dir(mod) return mod HOpe this helps! From jeff@ccvcorp.com Tue Sep 11 01:44:41 2001 From: jeff@ccvcorp.com (Jeff Shannon) Date: Mon, 10 Sep 2001 17:44:41 -0700 Subject: [Tutor] Windows IDE ..., Problems while executing python code ? References: Message-ID: <3B9D5E79.2D1CA1E@ccvcorp.com> > Hi, > > I am getting a suprising error with Windows IDE, When I want to test my code > on windows to check I jsut run uing Ctrl + F5, but when I have a import > statements for the user defined modules ..., python is telling me Import > error...like this..., > > File "C:\Python20\projects\VirtualHandset\utils.py", line 8, in ? > from HandSetUtils import * > ImportError: No module named HandSetUtils > > But suprisingly my modules are present there it self. Then I just copied > these files to the python installation directory...it started working > fine..., then I deleted from python installation directory..., but it > started working fine...then I closed all windows ..., this time again it > started giving the above problem..., You're almost certainly on the right track, in that it's a path problem. Python is not looking in your \projects\* directory for modules, and won't unless you specifically tell it to. When you put your modules into the regular python install dir, then they were found. As for why it worked after you deleted those copies, until you shut down PythonWin (I'm presuming that's what you mean by Windows IDE, but the same would happen with IDLE), you have to know how module imports work. Once Python has loaded a module, further calls to import it simply add a reference to the existing module in memory. Since you'd already imported your modules, the IDE didn't need to find the files to do a second import, so it never noticed that you'd deleted them. However, once you shut down the IDE and restarted it, then the modules were (obviously) no longer in memory and needed to be loaded from the files... and you're back to where you were to start off with. The simplest solution to this whole problem, is to create a text file in your main Python directory (c:\Python20\). The file needs to have the extension .pth (best bet is to name it python.pth). Each line in this file should contain a directory name. Each directory so named (and any subdirectories, IIRC), will be added to Python's search path. So, if you create this file with the single line "C:\Python20\projects", your problem should be solved. If that doesn't work, you *might* need to add another line "C:\Python20\projects\VirtualHandset". Once you have this file, restart your IDE. From then on, you should be set. HTH Jeff Shannon Technician/Programmer Credit International From ajaya@ncoretech.com Tue Sep 11 06:16:35 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 11 Sep 2001 10:46:35 +0530 Subject: [Tutor] How to implement portable message queue betwwen Python application and another application ?? Message-ID: <000001c13a80$ede81780$6501a8c0@ncoretech.com> Hi, I've some doubts regarding desiging portable application on Linux and Windos using python. My requirements are.., I need to send data from Python interface to the C application which is running indipendently. I was thiking of implemenitg using message queue. But since it is different I was thinking some alternative ways of implementing it. What is general way of implementing message queues (for sending messages from python to another application.), I've some idea of implementing using socket pipe (in the same system). But I really don't what are the drawbacks when I implement using sockets rather than using normal approch of sending messages using message ques.., Thanks and Regards, Ajaya From ignacio@openservices.net Tue Sep 11 06:39:59 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 11 Sep 2001 01:39:59 -0400 (EDT) Subject: [Tutor] How to implement portable message queue betwwen Python application and another application ?? In-Reply-To: <000001c13a80$ede81780$6501a8c0@ncoretech.com> Message-ID: On Tue, 11 Sep 2001, Ajaya Babu wrote: > I've some doubts regarding desiging portable application on Linux and Windos > using python. My requirements are.., > > I need to send data from Python interface to the C application which is > running indipendently. I was thiking of implemenitg using message queue. But > since it is different I was thinking some alternative ways of implementing > it. Unix Domain sockets (AF_UNIX) are usable on both Linux and Windows, and is probably the most portable method. -- Ignacio Vazquez-Abrams From r.b.rigilink@chello.nl Tue Sep 11 07:48:48 2001 From: r.b.rigilink@chello.nl (Roeland Rengelink) Date: Tue, 11 Sep 2001 08:48:48 +0200 Subject: [Tutor] Lists and removal References: Message-ID: <3B9DB3D0.CC71D119@chello.nl> Hi Jon, At first sight, what you do looks OK. One idea: If ignore contains items that are not in dl. Then for item in ignore: dl.remove(item) will raise a ValueError. Are you sure that you're not catching this Exception somewhere. If that's not the case some judiously placed print stetements should find the bug For instance: def getFile(text, dir): hits = [] dl = os.listdir(dir) print dl, ignore for item in ignore: print item, dl.index(item) dl.remove(item) print dl text = string.lower(text) for d in dl: d = dir + '\\' + d if os.path.isfile(d): hits.extend(searchtext(d, text)) elif os.path.isdir(d): hits.extend(getFile(text, d)) return hits By the way: this function does two things. it searches for files, and then it searches for text in files. It might be a good idea to rewrite this as (untested) def getFile(dir, ignore=[]): '''recursevly search for files in dir, ignoring files from ignore''' hits = [] dl = os.listdir(dir) for item in ignore: try: dl.remove(item) except ValueError: pass for d in dl: d = os.path.join(dir, d) # platform idependent if os.path.isfile(d): hits.extend([d]) elif os.path.isdir(d): hits.extend(getFile(d)) return hits use with: result = [] for file in getFile(dir, ignore): result.extend(searchtext(file, text)) Hope this helps, Roeland Jon Cosby wrote: > > Sorry, I got careless the first time. I was referring to the Python list > operation, not removal from the mailing list. I imagine a lot of people > ignored my first message. Let's try this again: > > I'm doing a Web search that is succesful until I try to configure it to > ignore specified directories using the "remove" operation. I'm not getting > any error messages, but the script stops when it comes to the function > below. I've run the first few lines in the interpreter, and I can't see > anything wrong with it. Any ideas? > > def getFile(text, dir): > hits = [] > dl = os.listdir(dir) > for item in ignore: # List of directories to ignore > dl.remove(item) # Works in interpreter, but list comes up empty here > text = string.lower(text) > for d in dl: > d = dir + '\\' + d > if os.path.isfile(d): > hits.extend(searchtext(d, text)) > elif os.path.isdir(d): > hits.extend(getFile(text, d)) > return hits > > Jon Cosby > > jcosby@mindspring.com > www.jcosby.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- r.b.rigilink@chello.nl "Half of what I say is nonsense. Unfortunately I don't know which half" From ajaya@ncoretech.com Tue Sep 11 07:46:26 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 11 Sep 2001 12:16:26 +0530 Subject: [Tutor] How to convert integer to binay packed string...,? Message-ID: <000201c13a8d$7b71cd60$6501a8c0@ncoretech.com> Hi All, I've a small doubt, How to convert integers into bytestream in python. What actually I want to do is send integer to another system in the network. But since there is nothing like integer in python...I am just wondering how can i manipulate a integer to a string of two bytes which corresponds to the two binary coded bytes of the integer. My be my doubt is more basic.., But I've tough time from finding documents with regards, Ajaya From ignacio@openservices.net Tue Sep 11 07:52:31 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 11 Sep 2001 02:52:31 -0400 (EDT) Subject: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: <000201c13a8d$7b71cd60$6501a8c0@ncoretech.com> Message-ID: On Tue, 11 Sep 2001, Ajaya Babu wrote: > I've a small doubt, How to convert integers into bytestream in python. What > actually I want to do is send integer to another system in the network. But > since there is nothing like integer in python...I am just wondering how can > i manipulate a integer to a string of two bytes which corresponds to the two > binary coded bytes of the integer. http://www.python.org/doc/current/lib/module-struct.html -- Ignacio Vazquez-Abrams From smt@pacific.net.hk Tue Sep 11 09:40:39 2001 From: smt@pacific.net.hk (Kenneth Tsang) Date: Tue, 11 Sep 2001 16:40:39 +0800 Subject: [Tutor] Accessing database References: Message-ID: <03e301c13a9d$6ff52da0$a800a8c0@orange> Hi, I am working on an applications which need to have database access. Please advise which module I should use (seems there are lot of them, lik= e sql.pyd-which I collect from zope, odbc.pyd-comes with win32 from Mark Hammond's win32extensions...). And would like to see some sample code, if possible. My current development environment win2000 running python win32 extensions installed wxPython installed use for front end development Target database is ODBC based, (currently need to support MSAccess, MSSQL and mySQL) I have been looking around in web sites and different articles and no res= ult yet. Thanks. cheers, Kenneth -- Kenneth Tsang email: smt@pacific.net.hk tel: +852 9468 4772 ----- Original Message ----- From: To: Sent: Tuesday, September 11, 2001 12:01 AM Subject: Tutor digest, Vol 1 #1081 - 13 msgs Send Tutor mailing list submissions to tutor@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@python.org You can reach the person managing the list at tutor-admin@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 IDLE in Windows (Kirby Urner) 2. "Internal Server Error" (Jon Cosby) 3. Re: "Internal Server Error" (Ignacio Vazquez-Abrams) 4. Re: "Internal Server Error" (Kirby Urner) 5. Re: i have a major problem (Sheila King) 6. =CF=F0=EE=E4=E0=E6?=EF=EE=EA=F3=EF=EA?=EF=F0=EE=E4=F3=EA=F6=E8?=EF=EE= =E8=F1?=EF=E0=F0=F2=ED=E5=F0=EE? (Anonymouse) 7. RE: trouble running Grail (Simon Brunning) 8. need some help (Sreenidhi.B.G) 9. Windows IDE ..., Problems while executing python code ? (Ajaya Babu= ) 10. Re: Help with cookies (James) 11. RE: sending stdout to a text box (alan.gauld@bt.com) 12. RE: sending stdout to a text box (Bill Tolbert) 13. Re: trouble running Grail (Lance E Sloan) --__--__-- Message: 1 Date: Sun, 09 Sep 2001 09:18:32 -0700 To: Charlie@begeistert.org From: Kirby Urner Subject: Re: [Tutor] Problem with IDLE in Windows Cc: tutor@python.org > >d =3D Database("charlies_database") >d.insert_database[dict] # this generates an attribute error The use of square brackets isn't defined in your object. insert_database is a regular "callable" method, expecting parentheses. If you want to supply your own meaning for square brackets, as if you were trying to set the value of a list or dictionary item, you'd have to define __setitem__ in your class -- but I don't see that this is a priority in your case. Just go: d.insert_database(dict) instead. You may still get an error message, but it should be a different one :-D Kirby PS: didn't understand about escaped apostrophe exactly, as your examples don't include any, but I'm glad you've got that working. --__--__-- Message: 2 Reply-To: From: "Jon Cosby" To: Date: Sun, 9 Sep 2001 10:19:33 -0700 Subject: [Tutor] "Internal Server Error" Can somebody tell me why this works: x =3D dict.items() x.sort(paircomp) for k, v in x: k =3D string.replace(k, dir + '/', url) k1 =3D string.replace(k, url, "") print '' print '', k1, ' ', v, counter(v), 'matches
' print '' But when I modify it slightly, if len(dict) =3D 0: print '

No matches found

' else: x =3D dict.items() x.sort(paircomp) for k, v in x: k =3D string.replace(k, dir + '/', url) k1 =3D string.replace(k, url, "") print '' print '', k1, ' ', v, counter(v), 'matches
' print '' I get an "internal server error"? Jon Cosby jcosby@mindspring.com www.jcosby.com --__--__-- Message: 3 Date: Sun, 9 Sep 2001 13:25:48 -0400 (EDT) From: Ignacio Vazquez-Abrams To: Subject: Re: [Tutor] "Internal Server Error" On Sun, 9 Sep 2001, Jon Cosby wrote: > Can somebody tell me why this works: > > x =3D dict.items() > x.sort(paircomp) > for k, v in x: > k =3D string.replace(k, dir + '/', url) > k1 =3D string.replace(k, url, "") > print '' > print '', k1, ' ', v, counter(v), 'matches
' > print '' > > > But when I modify it slightly, > > > if len(dict) =3D 0: ^^^ > print '

No matches found

' > else: > x =3D dict.items() > x.sort(paircomp) > for k, v in x: > k =3D string.replace(k, dir + '/', url) > k1 =3D string.replace(k, url, "") > print '' > print '', k1, ' ', v, counter(v), 'matches
' > print '' > > > I get an "internal server error"? If you try running it manually, you'll get a SyntaxError exception. -- Ignacio Vazquez-Abrams --__--__-- Message: 4 Date: Sun, 09 Sep 2001 10:36:29 -0700 To: From: Kirby Urner Subject: Re: [Tutor] "Internal Server Error" Cc: tutor@python.org > >if len(dict) =3D 0: ^ Needs to be: =3D=3D Difficult to debug when running cgi unless you trap the Python error and display it on the server. One option is to do something like this: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D #!/usr/local/bin/python import cgi import sys # include this import traceback # include this sys.stderr =3D sys.stdout print "Content-Type: text/html\n" try: print """ \n \n Feedback\n \n \n """ except: # trap Python error and display in browser print "\n\n
"
       traceback.print_exc()
       print "\n
" =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Kirby --__--__-- Message: 5 From: Sheila King To: "Nick Wertzberger" Cc: tutor@python.org Subject: Re: [Tutor] i have a major problem Date: Sun, 09 Sep 2001 10:44:15 -0700 On Sun, 9 Sep 2001 10:17:05 -0500, "Nick Wertzberger" wrote about [Tutor] i have a major problem: :every time i try to access a file named snakeoil.txt, i get htis message= : :Traceback (most recent call last): : File "", line 1, in ? : data=3Dopen("snakeoil.txt") :IOError: [Errno 2] No such file or directory: 'snakeoil.txt' : :how do i fix this PROBLEM!?!?!?!? I've recently been having problems of this type, myself. If python says the file doesn't exist, then you must be doing something wrong, like being in the wrong directory, spelling or case error or something. One thing that I have found to help, is adding a few lines to my script, something like this: >>> import os >>> os.listdir(os.curdir) This will return a list of all the files in the current directory. Sometimes looking at the list of files that Python sees in the current directory can be quite insightful. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ --__--__-- Message: 6 Date: 9 Sep 2001 21:09:28 -0000 To: List Member Reply-To: mailgrabber-feedback-1@lb.bcentral.com From: "Anonymouse" Subject: [Tutor] =CF=F0=EE=E4=E0=E6?=EF=EE=EA=F3=EF=EA?=EF=F0=EE=E4=F3=EA= =F6=E8?=EF=EE=E8=F1?=EF=E0=F0=F2=ED=E5=F0=EE? =D3=E2=E0=E6=E0=E5=EC=FB?=E3=EE=F1=EF=EE=E4? =D7=F2?=F2=E0=EA=EE?=C8=ED=F4=EE=F0=EC=E0=F6? ? =C8=ED=F4=EE=F0=EC=E0=F6? ?=FD=F2?=E2=EB=E0=F1=F2=FC, =E1=EE=E3=E0=F2=F1=F2= =E2? =F3=F1=EF=E5? =EF=F0=EE=F6=E2=E5=F2=E0=ED=E8? =CA=F2?=E2=EB=E0=E4=E5=E5?=E8=ED=F4=EE=F0=EC=E0=F6=E8=E5? =F2=EE?=F3=EF=F0= =E0=E2=EB=FF=E5=F2. =CE=CE?=AB=C2=C8=DD=CB=DC-=CC=BB =EF=F0=E5=E4=EB=E0=E3=E0=E5=F2 =C2=E0?=E2= =EE=F1=EF=EE=EB=FC=E7=EE=E2=E0=F2=FC=F1=FF =F2=E0=EA=EE?=E8=ED=F4=EE=F0=EC= =E0=F6=E8=E5??=E2=E7=FF=F2=FC =ED=E0 =F1=E5? =EF=F0=EE=E1=EB=E5=EC=F3 =EF=EE=E8=F1=EA=E0 =ED=E5=EE=E1=F5=EE=E4=E8=EC=EE= =E3=EE =C2=E0?=EE=E1=EE=F0=F3=E4=EE=E2=E0=ED?, =F1=FB=F0=FC=FF, =EF=F0=E8= =E1=EE=F0=EE=E2, =EC=E0=F2=E5=F0=E8=E0=EB=EE=E2 ?? ?, =F1=EB=EE=E2=EE=EC =E2=F1=E5=E3?=F2=EE=E3=EE, =E1=E5?=F7=E5=E3=EE =ED=E5= =EC=EE=E6=E5?=F1=F3=F9=E5=F1=F2=E2=EE=E2=E0=F2=FC =C2=E0=F8=E5 =EF=F0=EE= =E8=E7=E2=EE=E4=F1=F2=E2=EE, =F3=F1=EF=E5=F8=ED? =EF=F0=EE=F6=E2=E5=F2=E0=F2=FC =C2=E0?=E1=E8=E7=ED=E5=F1. =C1=EB=E0=E3=EE=E4=E0=F0=FF =EE=E1=F8=E8=F0=ED=FB=EC =F1=E2=FF???=E2=E5=F3= =F9=E8=EC?=EF=F0=EE=E8=E7=E2=EE=E4=E8=F2=E5=EB=FF=EC=E8 ?=EF=EE=F1=F2=E0=E2= =F9=E8=EA=E0=EC=E8 =ED=E5 =F2=EE=EB=FC=EA=EE ? =D0=EE=F1=F1=E8=E8, =ED=EE ?=E7=E0 =F0=F3=E1=E5=E6=EE? =EC=FB =E8=EC=E5=E5= ?=E2=EE=E7=EC=EE=E6=ED=EE=F1=F2?=E2=FB=EF=EE=EB=ED=FF=F2=FC =C2=E0=F8=E8 = =E7=E0=EA=E0=E7=FB =ED=E0=E8=E1=EE=EB=E5=E5 =EF=EE =EB=ED???=EA=F0=E0=F2=F7=E0=E9=F8=E8=E5 =F1=F0=EE=EA? =D1=EF=E5=EA=F2=F0 =ED=E0=F8=E5?=E4=E5=FF=F2=E5=EB=FC=ED=EE=F1=F2?=E4=EE=E2= =EE=EB=FC=ED=EE =F8=E8=F0=EE? =DD=F2?=EE=E1=EB=E0=F1=F2?=FD=EB=E5=EA=F2=F0=EE=ED=E8=EA? =EF=F0=E8= =F7=E5=EC =ED=E5 =F2=EE=EB=FC=EA=EE =EF=EE=F1=F2=E0=E2=EA=E8 =EF=F0=E8=E1= =EE=F0=EE=E2, =E0=EF=EF=E0=F0=E0=F2=F3=F0=FB , =ED=EE ?=F0=E0=E7=EB=E8=F7=ED=FB?=EA=EE=EC=EF=EB=E5=EA=F2=F3=FE=F9=E8?=EA= =E0?=EE=F2=E5=F7=E5=F1=F2=E2=E5=ED=ED=FB? =F2=E0??=E7=E0=F0=F3=E1=E5=E6=ED= =FB=F5 =EF=F0=EE=E8=E7=E2=EE=E4=E8=F2=E5=EB=E5=E9 =FD=EB=E5=EA=F2=F0=EE=ED=ED=EE?=F2=E5=F5=ED=E8=EA? =DD=F2?=F2=E0=EA=E8?=F4= =E8=F0=EC?=EA=E0?International Rectifier, Epcos, Bourns, Metex, unit-t ?=E4=F0. =DD=F2?=EE=E1=EB=E0=F1=F2?=EC=E5=F2=E0=EB=EB=EE=E2=E5=E4=E5=ED?- = =F1=E2=E0=F0=EE=F7=ED=FB?=FD=EB=E5=EA=F2=F0=EE=E4? =EC=E5=F2=E0=EB=EB-=EB= =E8=F1=F2, =F3=E3=EE=EB=EE=EA, =F8=E2 =E5=EB=EB=E5? =EB=E5=ED=F2? =F2=F0=F3=E1???? =DD=F2?=EF=EE=F1=F2=E0=E2=EA=E8 =F1=F2=E0=ED=EA=EE? =EE=E1=EE=F0=F3= =E4=EE=E2=E0=ED? =E4=EB=FF =EF=F0=EE=E8=E7=E2=EE=E4=F1=F2=E2=E0, =E0=EF=EF= =E0=F0=E0=F2=FB =E3=E0=E7=E2=EE=E4? =F1=E2=E5=F2=E8=EB=FC=ED=E8=EA?=E4=EB=FF =EE=F4=E8=F1=EE=E2 ?=EF=F0=EE=EC= =FB=F8=EB=E5=ED=ED=FB=F5 =EF=F0=E5=E4=EF=F0?=F2=E8? =EB=FE=F1=F2=F0=FB, =F1= =E2=E0=F0=EE=F7=ED=EE?=EE=E1=EE=F0=F3=E4=EE=E2=E0=ED =E8=E5 ??? =DD=F2?=EE=E1=EB=E0=F1=F2?=EC=E5=E4=E8=F6=E8=ED=FB- ?=ED=E0=F1=F2= ?=F9=E5?=E2=F0=E5=EC=FF =EC=FB =EF=F0=E5=E4=F1=F2=E0=E2?=E5=EC =F3=ED=E8=EA= =E0=EB=FC=ED=EE=E5 =E8=E7=EE=E1=F0=E5 =F2=E5=ED=E8?=F0=F3=F1=F1=EA=EE=E3=EE =F3=F7=E5=ED=EE=E3?=EB=FE=F1=F2=F0=F3= =D7=E8=E6=E5=E2=F1=EA=EE=E3=EE. ?=EF=EE=EB=ED=FB=EC =EF=E5=F0=E5=F7=ED=E5=EC =EF=F0=EE=E4=F3=EA=F6=E8= ? =EF=EE=F1=F2=E0=E2?=E5=EC=EE=E9 =ED=E0=F8=E5?=F4=E8=F0=EC=EE=E9,=C2=FB = =F1=EC=EE=E6=E5=F2?=EE=E7=ED=E0=EA=EE=EC=E8 =F2=FC? =ED=E0 =ED=E0=F8=E5?=F1=E0=E9=F2??=E8=ED=F2=E5=F0=ED=E5=F2: vielm.narod.ru =C8=ED=F4=EE=F0=EC=E0=F6? =ED=E0 =E4=E0=ED=ED=EE=EC =F1=E0=E9=F2?=E1=F3= =E4=E5?=EF=EE=F1=F2?=ED=ED?=EE=E1=ED=EE=E2=EB=FF=F2=FC? ?=F1=EE=E2=E5=F0=F8= =E5=ED=F1=F2=E2=EE=E2=E0=F2=FC?. =CC=FB =ED=E5 =EF=F0=EE=F1=F2=EE =EF=F0=E5=E4=EE=F1=F2=E0=E2=EB=FF=E5= =EC =E8=ED=F4=EE=F0=EC=E0=F6=E8=FE, =E3=E4?=EC=EE=E6=ED?=E4=EE=F1=F2=E0=F2= ?=ED=F3=E6=ED=F3=FE =C2=E0?=EF=F0=EE=E4=F3=EA =F6=E8? =EC=FB =F1=E0=EC=E8 =EF=EE=F1=F2=E0=E2=E8=EC =C2=E0?=E7=E0=EA=E0=E7= =E0=ED=ED=FB=E9 =F2=EE=E2=E0?=EF=EE =E2=FB=E3=EE=E4=ED=FB=EC =E4=EB=FF =C2= =E0?=F6=E5=ED=E0???=EE=EF=F2=E8=EC=E0=EB=FC =ED=EE =EA=EE=F0=EE=F2=EA=E8=E5 =F1=F0=EE=EA? =C2=E0=F8=F3 =EF=EE=F2=F0=E5=E1=ED=EE=F1=F2?? =EF=F0=EE=E4=F3=EA=F6=E8= ?=EF=F0=E5=E4=F1=F2=E0=E2=EB=E5=ED=ED=EE=E9 =ED=E0 =ED=E0=F8=E5?=F1=E0=E9= =F2? =C2=FB =EC=EE=E6=E5=F2=E5 =EE=F2=EF=F0=E0=E2 =E8=F2?=ED=E0 =ED=E0?=F4=E0=EA=F1: (095) 275-89-94, =E8=EB?=EF=EE =FD=EB= =E5=EA=F2=F0=EE=ED=ED=EE?=EF=EE=F7=F2? tandiv@mail.ru . =CC=FB =E6=E4=E5=EC =C2=E0??=E2=FB=F0=E0=E6=E0=E5=EC =F3=E2=E5=F0=E5=ED= =ED=EE=F1=F2??=F2=EE? =F7=F2?=EE=E1=F0=E0=F2=E8=E2=F8=E8=F1??=ED=E0? =C2=FB= =EF=EE=EB=F3=F7=E8=F2=E5 =EA=E2=E0=EB =E8=F4=E8=F6=E8=F0=EE=E2=E0=ED=ED=F3?=EF=EE=EC=EE=A2=A2, =E2=ED=E8=EC=E0=F2= =E5=EB=FC=ED=EE=E5 =EE=F2=ED=EE=F8=E5=ED=E8??=C2=E0=F8=E8?=EF=EE=F2=F0=E5= =E1=ED=EE=F1=F2=FF? =EE=EF=E5=F0=E0=F2=E8=E2=ED=F3?=EE=E1 =F0=E0=E1=EE=F2=EA?=C2=E0=F8=E5=E3=EE =E7=E0=EA=E0=E7=E0. =CF=EE =E2=F1=E5=EC =E2=EE=EF=F0=EE=F1=E0=EC =E2=FB =EC=EE=E6=E5=F2= =E5 =EE=E1=F0=E0=F9=E0=F2=FC? =EF=EE =F2=E5=EB=E5=F4=EE=ED=E0? 275-89-94, 746-68-78. _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=3D15131&subid= =3D4F31 E628C99B6F48&msgnum=3D1 --__--__-- Message: 7 From: Simon Brunning To: 'Lance E Sloan' , tutor@python.org, python-list@python.org Subject: RE: [Tutor] trouble running Grail Date: Mon, 10 Sep 2001 08:45:31 +0100 > From: Lance E Sloan [SMTP:lsloan@umich.edu] > Why would the Grail author give two arguments to append? Was > there an old version of Python that allowed two arguments? In a word, yes. See = for an explanation. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileg= ed. It is intended solely for the addressee. Access to this email by anyone e= lse is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. --__--__-- Message: 8 Date: Mon, 10 Sep 2001 14:35:20 +0530 From: "Sreenidhi.B.G" Organization: Encore Software Ltd To: tutor@python.org Subject: [Tutor] need some help Helo, I am working on a small example where in I call my c function, and I'm unable to link to the python library. I'm getting undefined reference to these function calls, - PyArg_ParseTuple and Py_BuildValue. can you please help me link this to python library. We are working on Linux7.1.and we are using python 1.5 regards, -sreenidhi, --__--__-- Message: 9 From: "Ajaya Babu" To: "PythonTutorlist (E-mail)" Date: Mon, 10 Sep 2001 17:04:55 +0530 Subject: [Tutor] Windows IDE ..., Problems while executing python code ? Hi, I am getting a suprising error with Windows IDE, When I want to test my c= ode on windows to check I jsut run uing Ctrl + F5, but when I have a import statements for the user defined modules ..., python is telling me Import error...like this..., File "C:\Python20\projects\VirtualHandset\utils.py", line 8, in ? from HandSetUtils import * ImportError: No module named HandSetUtils But suprisingly my modules are present there it self. Then I just copied these files to the python installation directory...it started working fine..., then I deleted from python installation directory..., but it started working fine...then I closed all windows ..., this time again it started giving the above problem..., I very much cross checked the name and direcotry..., I tried with setting path variable to solve this problem. But it did not help much..., Can any one suggest some thing to fix this problem. with regards, Ajaya --__--__-- Message: 10 From: "James" To: Cc: Date: Mon, 10 Sep 2001 04:38:04 -0700 Subject: [Tutor] Re: Help with cookies > Dear Python gurus and those who want to become such, > I need to be able to pass a cookie in a url request. import os, string from urllib import * from mimetools import Message #redefine (override?) urlopen to enable cookie sending def urlopen(url, data=3DNone, headers=3DNone): u =3D FancyURLopener() if headers: if type(headers) =3D=3D type({}): headers =3D headers.items() for kw, val in headers: u.addheader(kw, val) return u.open(url, data) # The following gets the cookie info I need... temppage=3D urlopen(source_url) headers=3Dtemppage.info() cookie =3D headers.getheader("set-cookie") clist =3D string.split(cookie, ';') temppage.close() # ...to successfully open the page: page =3D urlopen(source_url, headers=3D[('Cookie', clist[0])]) ######## Warning: I'm new to programming. I edited this code entirely from a comp.python post found via google. Let me know if it works. James. --__--__-- Message: 11 From: alan.gauld@bt.com To: kalle@gnupung.net, tutor@python.org Subject: RE: [Tutor] sending stdout to a text box Date: Mon, 10 Sep 2001 13:59:56 +0100 > > run from a prompt. How can I catch this and route it to a > text box in tkinter? I posted a short example of this but it wasn't wondersfully commented. Essentially you make sys.stdout point to an object which has a write() method. (This could be your Tkinter application for example) Now when you call print the output will go to the new object. Thus class MyApp(Frame): def __init__(self): # do stuff here self.display =3D Text(....) # create our text widget sys.stdout =3D self # Set stdout here def write(self, s): # provide the necessary write method self.display.insert(END.s) # append the string s to the widget # other methods as usual... def foo(self): print "This is foo" # will appear in text widget Hope thats a little clearer. Alan G. --__--__-- Message: 12 Date: Mon, 10 Sep 2001 09:30:46 -0400 (EDT) From: Bill Tolbert To: tutor@python.org Subject: RE: [Tutor] sending stdout to a text box Thanks for the reply Alan. Kalle posted a good example too (I'm the one who asked originally). I'm close, but not quite where I want to be. I'm trying to incorporate some utility scripts that use print statements to tell the user what's going on (success, error, busy, etc). I want my gui to consolidate these and just redirect the existing print statements to the text widget on the gui. Output from ICAREBackup goes to BogusFile and on to the text box, but not until ICAREBackup finishes. I was looking for a way to provide immediate feedback. Some of these utilities could run for a very long time, leaving the user confused and ready to reboot without feedback. Output to the shell window is immediate; it doesn't wait until the script finishes. Can I duplicate that immediate feedback? def backup(self): import ICAREBackup sys.stdout =3D BogusFile(self.text_box) ICAREBackup.stdout =3D BogusFile(self.text_box) ICAREBackup.ICAREBackup() Thanks guys, Bill On Mon, 10 Sep 2001 alan.gauld@bt.com wrote: > > > run from a prompt. How can I catch this and route it to a > > text box in tkinter? > > I posted a short example of this but it wasn't wondersfully commented. > > > Essentially you make sys.stdout point to an object which has > a write() method. (This could be your Tkinter application for > example) > > Now when you call print the output will go to the new object. > > Thus > > class MyApp(Frame): > def __init__(self): > # do stuff here > self.display =3D Text(....) # create our text widget > sys.stdout =3D self # Set stdout here > > def write(self, s): # provide the necessary write method > self.display.insert(END.s) # append the string s to the widget > > # other methods as usual... > def foo(self): > print "This is foo" # will appear in text widget > > Hope thats a little clearer. > > Alan G. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D Bill Tolbert --__--__-- Message: 13 To: Ignacio Vazquez-Abrams cc: tutor@python.org Subject: Re: [Tutor] trouble running Grail Date: Mon, 10 Sep 2001 09:55:54 -0400 From: Lance E Sloan Ignacio Vazquez-Abrams wrote: > Grail is _ancient_. I remember using Grail 0.6 a _looooong_ time ago. Yes, it is pretty old. But I'm convinced that most of the available web browsers do several things wrong, or at least stupidly. Since I'm getting the hang of Python, Grail sounded like a good browser to poke around in the guts of without feeling tainted afterwards. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Python & Perl CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" --__--__-- _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor End of Tutor Digest From Kerim Borchaev ( WarKiD ) " Hello , Recently I've found a bad thing about PythonWin - even if "insert spaces" option is checked it still uses tabs - in interactive window. It happended a couple of times before but I thought I just don't get Python. So be careful cut'n'pasting code from PW. And if it is a bug someone please report it to ActiveState... Best regards, Kerim mailto:warkid@storm.ru From dsh8290@rit.edu Tue Sep 11 11:22:29 2001 From: dsh8290@rit.edu (dman) Date: Tue, 11 Sep 2001 06:22:29 -0400 Subject: [Tutor] How to implement portable message queue betwwen Python application and another application ?? In-Reply-To: <000001c13a80$ede81780$6501a8c0@ncoretech.com> References: <000001c13a80$ede81780$6501a8c0@ncoretech.com> Message-ID: <20010911062229.A14431@hudson> On Tue, Sep 11, 2001 at 10:46:35AM +0530, Ajaya Babu wrote: | | Hi, | | I've some doubts regarding desiging portable application on Linux and Windos | using python. My requirements are.., | | I need to send data from Python interface to the C application which is | running indipendently. I was thiking of implemenitg using message queue. But | since it is different I was thinking some alternative ways of implementing | it. There are many ways of communicating between distributed object. Some of them include XML-RPC, CORBA, SOAP, COM (MS Windows only). The advantage of using a standard like these is the communication layer has already been implemented for you, you just need to use their interface. You could use some sort of socket and implement your own communication protocol, but I think that would likely be more work for you. -D From dsh8290@rit.edu Tue Sep 11 11:30:53 2001 From: dsh8290@rit.edu (dman) Date: Tue, 11 Sep 2001 06:30:53 -0400 Subject: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: <000201c13a8d$7b71cd60$6501a8c0@ncoretech.com> References: <000201c13a8d$7b71cd60$6501a8c0@ncoretech.com> Message-ID: <20010911063053.B14431@hudson> On Tue, Sep 11, 2001 at 12:16:26PM +0530, Ajaya Babu wrote: | | Hi All, | | I've a small doubt, How to convert integers into bytestream in python. What | actually I want to do is send integer to another system in the network. But | since there is nothing like integer in python...I am just wondering how can | i manipulate a integer to a string of two bytes which corresponds to the two | binary coded bytes of the integer. Ignacio has shown you the struct module (which I just tried out last night, pretty coool), but I want to warn you about the differences between big-endian and little-endian systems. If the two systems you are using have different endianness then you will probably run into problems with the bytes getting reversed. (I haven't done any playing with connecting the two so test it thoroughly if you use the struct module) The most portable easiest way, I think, and quite easy, from the python side anyways, is to simply convert the integer to a string and vice versa. Ex: (with C you'd have to use sprintf() and sscanf()) # send the number an_int = 1234 try : my_socket.write( str( an_int ) ) except IOError : print "Couldn't write to socket!" # receive the number try : raw_data = my_socket.readline() # however you define an # "entity" in your # communication protocol except IOError : print "Couldn't read from socket" sys.exit( 1 ) try : an_int = int( raw_data ) # convert the string to an int except ValueError : print "Invalid data received from socket" sys.exit( 1 ) print "We got %d" % an_int If you use an existing middleware package such as XML-RPC then you won't have to deal with any of this low-level communication details. HTH, -D From alan.gauld@bt.com Tue Sep 11 13:05:27 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 11 Sep 2001 13:05:27 +0100 Subject: [Tutor] sending stdout to a text box Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF3B@mbtlipnt02.btlabs.bt.co.uk> > I'm trying to incorporate some utility scripts that use print Yes thats what my examnple did. All print statements executed by your program after the assignment of stdout will go to the text widget. > until ICAREBackup finishes. I was looking for a way to provide > immediate feedback. Some of these utilities could run for a very long > time, leaving the user confused and ready to reboot without > feedback. Output to the shell window is immediate; it doesn't wait > until the script finishes. Can I duplicate that immediate feedback? Yes, by using the write() method it will put the output onto the screen as it happens. What I illustrated was how to avoid using a temporary file or String buffer(as Danny suggested in an earlier post) > def backup(self): > import ICAREBackup > sys.stdout = BogusFile(self.text_box) Don't need this line if you set it up in __init__ of the Tkinter application as: sys.stdout = self > ICAREBackup.stdout = BogusFile(self.text_box) Don't need this at all I think. > ICAREBackup.ICAREBackup() The print statemewnts in ICAREBackup will call self.write() > > class MyApp(Frame): > > def __init__(self): > > # do stuff here > > self.display = Text(....) # create our text widget > > sys.stdout = self # Set stdout here > > > > def write(self, s): # provide the necessary write method > > self.display.insert(END.s) # append the string s to the widget > > > > # other methods as usual... > > def foo(self): > > print "This is foo" # will appear in text widget def backup(self): ICAREBackup.ICAREBackup() # likewise Alan G. From alan.gauld@bt.com Tue Sep 11 13:10:41 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 11 Sep 2001 13:10:41 +0100 Subject: [Tutor] How to implement portable message queue betwwen Pytho n application and another application ?? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF3C@mbtlipnt02.btlabs.bt.co.uk> > I need to send data from Python interface to the C > application which is running indipendently. So you need a platform indepoendant way of intefacing Python to a C application. There are two easy ways: 1) Use sockets(see below) 2) If you control the C app use text files. Get the C app and Python app to poll the files(In background threads) IMHO 1 is easier 2 is robuster but slower. > What is general way of implementing message queues (for > sending messages from python to another application.), I don't think there is one thats common to both Win32 and Linux. ng > socket pipe (in the same system). But I really don't what are > the drawbacks when I implement using sockets rather than > use normal approch of sending messages using message ques.., I think on Linux sockets are the normal approach! The disadvantages are the need to marshal data in and out of the sockket. Only a problem if you don't own both ends or the interface changes regularly. Alan G From Brmfq@aol.com Tue Sep 11 14:37:01 2001 From: Brmfq@aol.com (Brmfq@aol.com) Date: Tue, 11 Sep 2001 09:37:01 EDT Subject: [Tutor] Getting total of a list (newbie) Message-ID: <68.13f2203d.28cf6d7d@aol.com> Good Day, I'm running Python 1.5.2 on win16 (going to upgrade both soon). I've been working on an exercise of writing a program that reads 100 numbers from the user and prints out the sum. Here's the best I've come up with: num = input("Please enter a number:") tot = [num] while len(tot) < 10: nex = input("Please enter another number: ") tot.append (nex) print 'total of 10 numbers is', tot[0]+tot[1]+tot[2]+tot[3]+tot[4]+tot[5]+tot[6]+tot[7]+tot[8]+tot[9] This works, but it's only for 10 numbers. Could someone please show me a better way? Thanks in advance to anyone who replies. Joe From ignacio@openservices.net Tue Sep 11 14:56:56 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 11 Sep 2001 09:56:56 -0400 (EDT) Subject: [Tutor] Getting total of a list (newbie) In-Reply-To: <68.13f2203d.28cf6d7d@aol.com> Message-ID: On Tue, 11 Sep 2001 Brmfq@aol.com wrote: > I'm running Python 1.5.2 on win16 (going to upgrade both soon). I've been > working on an exercise of writing a program that reads 100 numbers from the > user and prints out the sum. Here's the best I've come up with: > > num = input("Please enter a number:") > tot = [num] > while len(tot) < 10: > nex = input("Please enter another number: ") > tot.append (nex) > print 'total of 10 numbers is', > tot[0]+tot[1]+tot[2]+tot[3]+tot[4]+tot[5]+tot[6]+tot[7]+tot[8]+tot[9] > > This works, but it's only for 10 numbers. Could someone please show me a > better way? Thanks in advance to anyone who replies. This works for an arbitrary list or tuple of numbers: --- import operator print reduce(operator.add, tot) --- -- Ignacio Vazquez-Abrams From ak@silmarill.org Tue Sep 11 17:45:53 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Tue, 11 Sep 2001 12:45:53 -0400 Subject: [Tutor] Getting total of a list (newbie) In-Reply-To: <68.13f2203d.28cf6d7d@aol.com> References: <68.13f2203d.28cf6d7d@aol.com> Message-ID: <20010911124553.A23332@sill.silmarill.org> On Tue, Sep 11, 2001 at 09:37:01AM -0400, Brmfq@aol.com wrote: > Good Day, > > I'm running Python 1.5.2 on win16 (going to upgrade both soon). I've been > working on an exercise of writing a program that reads 100 numbers from the > user and prints out the sum. Here's the best I've come up with: > > num = input("Please enter a number:") > tot = [num] > while len(tot) < 10: > nex = input("Please enter another number: ") > tot.append (nex) > print 'total of 10 numbers is', > tot[0]+tot[1]+tot[2]+tot[3]+tot[4]+tot[5]+tot[6]+tot[7]+tot[8]+tot[9] > > This works, but it's only for 10 numbers. Could someone please show me a > better way? Thanks in advance to anyone who replies. > > Joe total = 0 while 1: ans = raw_input("Enter number: ") if not ans: break total = total + int(ans) print "Total is", total > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From alan.gauld@bt.com Tue Sep 11 17:44:34 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 11 Sep 2001 17:44:34 +0100 Subject: [Tutor] How to implement portable message queue betwwen Pytho n application and another application ?? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF3E@mbtlipnt02.btlabs.bt.co.uk> > | I need to send data from Python interface to the C > | application which is running indipendently. > There are many ways of communicating between distributed object. Some > of them include XML-RPC, CORBA, SOAP, COM (MS Windows only). I assumed from the request that the apps were on a local LAN not distributed widely. Of course assume makes an ass of u and me... > advantage of using a standard like these is the communication layer > has already been implemented for you, you just need to use their > interface. I'm not sure its that simple. For XML-RPC you need a web server available, CORBA needs an orb setting up and IDL defined, SOAP is also http based I think(but am not sure) If those things aren't readily available a simple socket connection is far easier. These protocols are great if you want to publish an API for several clients on different platforms need to communicate but if its a case of a single client talking to acsingle application sockets are much easier to do. > You could use some sort of socket and implement your own > communication protocol, but I think that would likely be > more work for you. I disagree if its not for a published API. OTOH if a public API is the desired end game then yes some of the suggested protocols might be best. XML-RPC and SOAP are both XML based and as such are extremely inefficient in bandwidth usage. > > -D > > > From alan.gauld@bt.com Tue Sep 11 17:50:17 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 11 Sep 2001 17:50:17 +0100 Subject: [Tutor] Getting total of a list (newbie) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF3F@mbtlipnt02.btlabs.bt.co.uk> Probably stating the obvious but.... > > num = input("Please enter a number:") > > tot = [num] > > while len(tot) < 10: > > nex = input("Please enter another number: ") > > tot.append (nex) > > print 'total of 10 numbers is', > > > tot[0]+tot[1]+tot[2]+tot[3]+tot[4]+tot[5]+tot[6]+tot[7]+tot[8]+tot[9] > This works for an arbitrary list or tuple of numbers: > > print reduce(operator.add, tot) Only replaces the summing line not all the input stuff! The input stuff is fine as it is, except you should probably use raw_input() instead of input() - its safer from abuse... An alternative is: total = 0 for item in tot: total = total + item print total Alan g From alan.gauld@bt.com Tue Sep 11 17:51:49 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 11 Sep 2001 17:51:49 +0100 Subject: [Tutor] PythonWin and tabs Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF40@mbtlipnt02.btlabs.bt.co.uk> > Recently I've found a bad thing about PythonWin - even if > "insert spaces" option is checked it still uses tabs - in What version are you using? I had that on the version I downloaded with 1.5.1 but the version that comes with Python 2.0 doesn't do that anymore - at least I've not seen it... Alan G From dyoo@hkn.eecs.berkeley.edu Tue Sep 11 19:05:43 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 11:05:43 -0700 (PDT) Subject: [Tutor] Getting total of a list (newbie) In-Reply-To: <68.13f2203d.28cf6d7d@aol.com> Message-ID: On Tue, 11 Sep 2001 Brmfq@aol.com wrote: > num = input("Please enter a number:") > tot = [num] > while len(tot) < 10: > nex = input("Please enter another number: ") > tot.append (nex) > print 'total of 10 numbers is', > tot[0]+tot[1]+tot[2]+tot[3]+tot[4]+tot[5]+tot[6]+tot[7]+tot[8]+tot[9] > > This works, but it's only for 10 numbers. Could someone please show me > a better way? Thanks in advance to anyone who replies. Hello! Have you learned about functions yet? We can write a sumUp() function that takes in a list, and returns its total: ### def sumUp(numbers): total = 0 for n in numbers: total = total + n return total ### What makes this function so useful is that now we can use it for your program: ### print 'total of 10 numbers is', sumUp(numbers) ### for random, gratuitous summations: ### >>> sumUp(range(10)) 45 ### or even for the definitions of other functions: ### def average(numbers): return sumUp(numbers) / float(len(numbers)) ## float() might be necessary because of possibility ## of integer division (as of Python 2.1.1) ### Only our sumUp() function has to do this "sum" thing. When we make a sumUp() function, we can treat the summing of lists as a new tool that we can fiddle with. As you can tell, I'm something of a function fanatic. *grin* If you have more questions, please feel free to ask. From dyoo@hkn.eecs.berkeley.edu Tue Sep 11 20:03:42 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 12:03:42 -0700 (PDT) Subject: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: <000201c13a8d$7b71cd60$6501a8c0@ncoretech.com> Message-ID: On Tue, 11 Sep 2001, Ajaya Babu wrote: > I've a small doubt, How to convert integers into bytestream in python. > What actually I want to do is send integer to another system in the > network. But since there is nothing like integer in python...I am just > wondering how can Actually, Python Integers are 32-bit integers, and we can do bitwise manipulation with them: ### >>> x = 2 >>> x>>2 0 >>> x<<2 8 >>> 0xffffffff & 0x00002000 8192 ### As Ignacio as mentioned, it sounds like you'll want to look at the "struct" module, a module that deals exclusively with packing things into bytes. Alternatively, you might want to look at the "pickle" module: http://python.org/doc/current/lib/module-pickle.html pickle will allow us to preserve integers into strings --- in effect, it turns things into a bytestream. pickle will "serialize" Python objects into something that we can save, or send! If you're sending something across the network to another Python system, pickle might be useful for you. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Tue Sep 11 20:19:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 12:19:37 -0700 (PDT) Subject: [Tutor] need some help In-Reply-To: <3B9C8250.6B01E6C8@ncoretech.com> Message-ID: On Mon, 10 Sep 2001, Sreenidhi.B.G wrote: > can you please help me link this to python library. We are working on > Linux7.1.and we are using python 1.5 Hello! Have you looked at the example Demos/Embed directory? It comes with the Python source, and is a good example on getting this sort of stuff working. The Makefile, in particular, has the flags you'll want to link to the Python library. You might also look at: http://www.python.org/doc/current/ext/link-reqs.html which explains a little more about the linking requirements. Hope this helps! From girishg@india.ti.com Tue Sep 11 20:44:37 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 12 Sep 2001 01:14:37 +0530 Subject: [Tutor] Non Blocking I/O on stdin Message-ID: <3B9E69A5.ED50F5E3@india.ti.com> Hi, I wish to read the keyboard(stdin) but the read should not be blocking I essentially want to spawn off 2 threads, one of which will constantly be reading from stdin. Just to give it a try, I used the raw_input() & input() functions but neither of them work. Infact they cause the program to quit. Is this due to the non-blocking nature of the thread causing it to quit * baffled * ---------------------- consider this ---------------------- #### DOES NOT WORK #### #! /usr/bin/env python def acc(args): while(1): print "just b4" # comes here str = input() print "just after" # never comes here :( args = 0, # create list of arguments thread.start_new_thread(acc, args) ####################### ---------------------- & consider this now ---------------------- #### THIS WORKS #### #! /usr/bin/env python def acc(args): while(1): print "just b4" # comes here str = input() print "just after" # comes here but still not what i want :( args = 0, # create list of arguments acc(args) ####################### Also please advise on reading the keyboard in non-blocking mode Help wrt the thread module (scheduling, etc) will also be helpful. best regards Girish From uselesspython@yahoo.com Tue Sep 11 20:51:52 2001 From: uselesspython@yahoo.com (Rob) Date: Tue, 11 Sep 2001 14:51:52 -0500 Subject: [Tutor] OT: I hope everyone's okay. Message-ID: <3B9E6B58.D80E0A77@yahoo.com> Everywhere you go, you can find suffering. Today, some of the suffering is particularly obvious, in the U.S. and in many other parts of the world. Just about all my family and friends in known danger spots have removed themselves from danger or missed it entirely, and I feel fortunate for this. I hope the same or better for each of you. Positive wishes for all, Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From girishg@india.ti.com Tue Sep 11 21:01:08 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 12 Sep 2001 01:31:08 +0530 Subject: [Tutor] OT - My Best wishes to you Message-ID: <3B9E6D84.91B25E65@india.ti.com> To all on the list, What happened was bad. I know for I have several friends in US and it is surely hard on their families. My heart goes out to all who were unfortunate to be in the WTO & Pentagon at the time of the crash landings. Peace be to all. All the best. Girish From ignacio@openservices.net Tue Sep 11 21:03:18 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 11 Sep 2001 16:03:18 -0400 (EDT) Subject: [Tutor] Non Blocking I/O on stdin In-Reply-To: <3B9E69A5.ED50F5E3@india.ti.com> Message-ID: On Wed, 12 Sep 2001, Girish Gajwani wrote: > Hi, > > I wish to read the keyboard(stdin) but the read should not > be blocking > > [snip] > > #### DOES NOT WORK #### > > #! /usr/bin/env python > def acc(args): > while(1): > print "just b4" # comes here > str = input() > print "just after" # never comes here :( > > args = 0, # create list of arguments > thread.start_new_thread(acc, args) > ####################### No wonder this doesn't work; if the main thread dies, then all the others die too. > ---------------------- > & consider this now > ---------------------- > > #### THIS WORKS #### > > #! /usr/bin/env python > def acc(args): > while(1): > print "just b4" # comes here > str = input() > print "just after" # comes here but still not what i > want :( > > args = 0, # create list of arguments > acc(args) > ####################### > Also please advise on reading the keyboard in non-blocking > mode > > Help wrt the thread module (scheduling, etc) will also be > helpful. A couple of tips: 1) Use the threading module instead of the thread module. That way your main thread can join a spawned thread and not die immediately. 2) Use the select module in conjunction with sys.stdin instead of input() or raw_input(). -- Ignacio Vazquez-Abrams From jcosby@mindspring.com Mon Sep 10 16:10:26 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Mon, 10 Sep 2001 08:10:26 -0700 Subject: [Tutor] Remove Message-ID: I'm doing a Web search that is succesful until I try to configure it to ignore specified directories using the "remove" operation. I'm not getting any error messages, but the script stops when it comes to the function below. I've run the first few lines in the interpreter, and I can't see anything wrong with it. Any ideas? def getFile(text, dir): hits = [] dl = os.listdir(dir) for item in ignore: # List of directories to ignore dl.remove(item) # Works in interpreter, but list comes up empty here text = string.lower(text) for d in dl: d = dir + '\\' + d if os.path.isfile(d): hits.extend(searchtext(d, text)) elif os.path.isdir(d): hits.extend(getFile(text, d)) return hits Jon Cosby jcosby@mindspring.com www.jcosby.com From lkvam@venix.com Tue Sep 11 23:55:20 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Tue, 11 Sep 2001 18:55:20 -0400 Subject: [Tutor] Remove References: Message-ID: <3B9E9658.543F9386@venix.com> I would add some exception handling and some print statements. If there is too much to print, use a log file. (e.g. print >> logfile, "removed %s" % (item) ) I inserted suggested changes below. Is there a higher level try that is hiding a ValueError??? Jon Cosby wrote: > > I'm doing a Web search that is succesful until I try to configure it to > ignore specified directories using the "remove" operation. I'm not getting > any error messages, but the script stops when it comes to the function > below. I've run the first few lines in the interpreter, and I can't see > anything wrong with it. Any ideas? > > def getFile(text, dir): > hits = [] > dl = os.listdir(dir) > for item in ignore: # List of directories to ignore try: > dl.remove(item) # Works in interpreter, but list comes up empty here print "removed %s" % (item) except ValueError: print "item %s is not present in list" % item raise ValueError > text = string.lower(text) > for d in dl: > d = dir + '\\' + d > if os.path.isfile(d): > hits.extend(searchtext(d, text)) > elif os.path.isdir(d): > hits.extend(getFile(text, d)) > return hits > > Jon Cosby > > jcosby@mindspring.com > www.jcosby.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From dyoo@hkn.eecs.berkeley.edu Wed Sep 12 00:49:24 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 16:49:24 -0700 (PDT) Subject: [Tutor] problem with list remove In-Reply-To: Message-ID: On Mon, 10 Sep 2001, Jon Cosby wrote: > I'm doing a Web search that is succesful until I try to configure it > to ignore specified directories using the "remove" operation. I'm not > getting any error messages, but the script stops when it comes to the By the program stopping, does it seem like the program is going into an infinite loop, or do you mean something else? Hmm... taking a look at getFile() now... > def getFile(text, dir): > hits = [] > dl = os.listdir(dir) > for item in ignore: # List of directories to ignore > dl.remove(item) # Works in interpreter, but list comes up empty here 'ignore' appears to be a global variable of some kind. Where is ignore being defined? Perhaps 'ignore' is a really large list --- I doubt this possibility, but it might be good to put some debugging statement here to see what 'ignore' looks like. > text = string.lower(text) > for d in dl: > d = dir + '\\' + d > if os.path.isfile(d): > hits.extend(searchtext(d, text)) > elif os.path.isdir(d): > hits.extend(getFile(text, d)) > return hits To tell the truth, I don't see anything here that would cause an infinite loop, but I might be overlooking something. Can you tell us more information? Best of wishes to you! From jcosby@mindspring.com Wed Sep 12 01:08:15 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Tue, 11 Sep 2001 17:08:15 -0700 Subject: [Tutor] string.replace Message-ID: Thanks for the help so far. Here's one more that has me stumped. I need a function to strip HTML tags from lines. What I have looks like it should work, but it stops at the first occurence of the tags. I've gone through it step by step, and it's finding all of the tags, but for some reason it's not replacing them. The routine is >>> from string import * >>> def striptabs(line): ... if "<" in line: ... l = find(line, "<", 0) ... m = find(line, ">", l) ... if l and m: ... print "Tag found" # Test ... line = replace(line, line[l:m+1], "") ... striptabs(line) ... else: ... return line ... return line ... >>> f = open("c:\\temp\\test.txt", "r") >>> l = f.readline() >>> l "This is a file. It's is to test for removing HTML tags.\n" >>> striptabs(l) Tag found Tag found Tag found "This is a file. It's is to test for removing HTML tags.\n" >>> As you can see, it is finding all of the tags. Why isn't it replacing them? Jon Cosby jcosby@mindspring.com www.jcosby.com From allan.crooks@btinternet.com Wed Sep 12 01:30:02 2001 From: allan.crooks@btinternet.com (Allan Crooks) Date: Wed, 12 Sep 2001 01:30:02 +0100 Subject: [Tutor] string.replace In-Reply-To: Message-ID: <3B9EBA9A.28981.DEF8E71@localhost> On 11 Sep 2001, at 17:08, Jon Cosby wrote: > >>> def striptabs(line): > ... if "<" in line: > ... l = find(line, "<", 0) > ... m = find(line, ">", l) > ... if l and m: > ... print "Tag found" # Test > ... line = replace(line, line[l:m+1], "") > ... striptabs(line) This line should be "return striptabs(line)". Otherwise it's returning the line which has the first tag removed (it processes the rest of the string, but does nothing with it. > ... else: > ... return line > ... return line Allan. From jcosby@mindspring.com Wed Sep 12 01:37:56 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Tue, 11 Sep 2001 17:37:56 -0700 Subject: [Tutor] problem with list remove In-Reply-To: Message-ID: The problem was in the second loop. Once the list had been removed, "remove" didn't take kindly to removing them a second time. I added the line: for item in ignore: if item in dl: dl.remove(item) Problem gone. Thanks. Jon -----Original Message----- From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Tuesday, September 11, 2001 4:49 PM To: Jon Cosby Cc: tutor@python.org Subject: Re: [Tutor] problem with list remove On Mon, 10 Sep 2001, Jon Cosby wrote: > I'm doing a Web search that is succesful until I try to configure it > to ignore specified directories using the "remove" operation. I'm not > getting any error messages, but the script stops when it comes to the By the program stopping, does it seem like the program is going into an infinite loop, or do you mean something else? Hmm... taking a look at getFile() now... > def getFile(text, dir): > hits = [] > dl = os.listdir(dir) > for item in ignore: # List of directories to ignore > dl.remove(item) # Works in interpreter, but list comes up empty here 'ignore' appears to be a global variable of some kind. Where is ignore being defined? Perhaps 'ignore' is a really large list --- I doubt this possibility, but it might be good to put some debugging statement here to see what 'ignore' looks like. > text = string.lower(text) > for d in dl: > d = dir + '\\' + d > if os.path.isfile(d): > hits.extend(searchtext(d, text)) > elif os.path.isdir(d): > hits.extend(getFile(text, d)) > return hits To tell the truth, I don't see anything here that would cause an infinite loop, but I might be overlooking something. Can you tell us more information? Best of wishes to you! From dyoo@hkn.eecs.berkeley.edu Wed Sep 12 01:55:44 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 17:55:44 -0700 (PDT) Subject: [Tutor] string.replace In-Reply-To: Message-ID: On Tue, 11 Sep 2001, Jon Cosby wrote: > Thanks for the help so far. Here's one more that has me stumped. I > need a function to strip HTML tags from lines. What I have looks like > it should work, but it stops at the first occurence of the tags. I've > gone through it step by step, and it's finding all of the tags, but > for some reason it's not replacing them. The routine is > > > >>> from string import * > >>> def striptabs(line): > ... if "<" in line: > ... l = find(line, "<", 0) > ... m = find(line, ">", l) > ... if l and m: > ... print "Tag found" # Test This has a small bug in it: if string.find()ing is unsuccessfuly, it doesn't return a false value, but instead it returns -1: ### >>> string.find('hello', 'z') -1 ### So your test for tag finding should be: if l >= 0 and m >= 0: instead. The reason it doesn't return a "false" value is because 0 is a perfectly good return value for find: it would mean a match at the very beginning of the string. > ... line = replace(line, line[l:m+1], "") You probably want to include the line above as part of the if-block. We should only be replacing things only if we've found matching braces. > ... striptabs(line) As Allan has pointed out, you'll want to somehow save the rest of the changes done to your line. Either: return striptabs(line) or line = striptabs(line) would be good ways of doing this. It's nice to see that you're taking a recursive approach here to strip tags until there aren't any more; just be careful that you send that result off to the user. When you learn about regular expressions (the re module), you may find them useful toward stripping tags off a line. If you're interested, you can take a look at: http://www.python.org/doc/lib/module-re.html and look for re.sub(). It looks like you may be using Python 1.52. If so, be wary of a similar module called "regex": regex is buggy and should be avoided. I'm off to look at the news; things look grim, but let's do our best to support each other. Best of wishes to you. From ignacio@openservices.net Wed Sep 12 04:52:46 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 11 Sep 2001 23:52:46 -0400 (EDT) Subject: [Tutor] string.replace In-Reply-To: Message-ID: On Tue, 11 Sep 2001, Jon Cosby wrote: > >>> from string import * > >>> def striptabs(line): > ... if "<" in line: > ... l = find(line, "<", 0) > ... m = find(line, ">", l) > ... if l and m: > ... print "Tag found" # Test > ... line = replace(line, line[l:m+1], "") > ... striptabs(line) > ... else: > ... return line > ... return line > ... > >>> f = open("c:\\temp\\test.txt", "r") > >>> l = f.readline() > >>> l > "This is a file. It's is to test for removing > HTML tags.\n" > >>> striptabs(l) > Tag found > Tag found > Tag found > "This is a file. It's is to test for removing HTML > tags.\n" > >>> > > As you can see, it is finding all of the tags. Why isn't it replacing them? Ypur function has a rather large logic error; it's only find the first tag because you only go through the process once. You need to change the if to a while and get rid of the embedded call to stribtabs(). -- Ignacio Vazquez-Abrams From dyoo@hkn.eecs.berkeley.edu Wed Sep 12 05:49:25 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 11 Sep 2001 21:49:25 -0700 (PDT) Subject: [Tutor] string.replace In-Reply-To: Message-ID: On Tue, 11 Sep 2001, Ignacio Vazquez-Abrams wrote: > On Tue, 11 Sep 2001, Jon Cosby wrote: > > > >>> from string import * > > >>> def striptabs(line): > > ... if "<" in line: > > ... l = find(line, "<", 0) > > ... m = find(line, ">", l) > > ... if l and m: > > ... print "Tag found" # Test > > ... line = replace(line, line[l:m+1], "") > > ... striptabs(line) > > ... else: > > ... return line > > ... return line > Ypur function has a rather large logic error; it's only find the first > tag because you only go through the process once. You need to change > the if to a while and get rid of the embedded call to stribtabs(). The recursive striptabs() call is buggy, but's also intentionally recursive: if Jon changes the line from: striptabs(line) to: line = striptabs(line) and corrects a few more logical bugs, the code should work because striptabs should only call itself recursivly if the line still contains tags --- his use of recursion is about the same as if he had used an explicit while loop. I have a corrected version of it below. Jon, don't look if you want to work it out for yourself. ** spoiler space ** ** spoiler space ** Here's a corrected version of Jon's striptabs() function, with some simplifications to the logic: ### from string import find, replace def striptabs(line): l = find(line, "<", 0) m = find(line, ">", l) if l >= 0 and m >= 0: line = replace(line, line[l:m+1], "") line = striptabs(line) return line ### And a small test case: ### >>> striptabs('hello world') 'hello world' >>> striptabs('i have me') 'i have me ### From ignacio@openservices.net Wed Sep 12 05:56:14 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 00:56:14 -0400 (EDT) Subject: [Tutor] string.replace In-Reply-To: Message-ID: > The recursive striptabs() call is buggy, but's also intentionally > recursive: if Jon changes the line from: > > striptabs(line) > > to: > > line = striptabs(line) > > and corrects a few more logical bugs, the code should work because > striptabs should only call itself recursivly if the line still contains > tags --- his use of recursion is about the same as if he had used an > explicit while loop. That's true, but 95-97% of the time iterative constructs are faster than recursive mechanisms, plus by definition they don't cause recursion overflows. Both of those points can be a big advantage if very large documents are being processed. -- Ignacio Vazquez-Abrams From lonetwin Wed Sep 12 06:54:46 2001 From: lonetwin (lonetwin) Date: Wed, 12 Sep 2001 11:24:46 +0530 (IST) Subject: [Tutor] problem with os.chmod() Message-ID: Hi everybody, I've got a problem with the os.chmod() function, it just doesn't seem to do the right thing, let me explain, the code given below, is something that I needed, I'm running this on a linux system, this code changes the permissions of directories and files recursively. I initially used os.chmod() function but it just screws up the permissions, so now I do a os.system() to the chmod command, but I'd like to know what is happening here.... ########################################################### #!/usr/bin/python # chperm.py # Usage: chperm.py import os def chmd(foo, dirname, names): dirmode = 744 flmode = 700 names = [ os.path.join(dirname, x) for x in names ] for fl in names: if os.path.isdir(fl): os.system('chmod %d "%s"' % (dirmode, fl)) # os.chmod(fl, dirmode) # <--- Does not work elif os.path.isfile(fl): os.system('chmod %d "%s"' % (flmode, fl)) # os.chmod(fl, flmode) # <--- Does not work if __name__ == '__main__': os.path.walk(os.sys.argv[1], chmd, None) ########################################################### -- Peace Steve P.S: sincere sympathies to all Americans and all the victims of terrorism on this dark day. From ajaya@ncoretech.com Wed Sep 12 06:51:58 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Wed, 12 Sep 2001 11:21:58 +0530 Subject: [Tutor] OT: I hope everyone's okay. In-Reply-To: <3B9E6B58.D80E0A77@yahoo.com> Message-ID: <000c01c13b4f$0a061330$6501a8c0@ncoretech.com> It is a real deep shok to all of us...,The pictures of fear and pain are still going on my eyes. Just because of some stupid fellow(s)...., innocents..., normal citizens are suffering today, and it is every ware. There is say in Indian Languages "With more cuts dimond become stronger and stroger, and value goes higher and higher" Hope that Mankind goes stronger and stronger. wishing for the best! Ajaya -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Rob Sent: Wednesday, September 12, 2001 1:22 AM To: tutor@python.org Subject: [Tutor] OT: I hope everyone's okay. Everywhere you go, you can find suffering. Today, some of the suffering is particularly obvious, in the U.S. and in many other parts of the world. Just about all my family and friends in known danger spots have removed themselves from danger or missed it entirely, and I feel fortunate for this. I hope the same or better for each of you. Positive wishes for all, Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From ignacio@openservices.net Wed Sep 12 07:00:52 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 02:00:52 -0400 (EDT) Subject: [Tutor] problem with os.chmod() In-Reply-To: Message-ID: On Wed, 12 Sep 2001, lonetwin wrote: > I've got a problem with the os.chmod() function, it just doesn't > seem to do the right thing, let me explain, the code given below, is > something that I needed, I'm running this on a linux system, this code > changes the permissions of directories and files recursively. I initially > used os.chmod() function but it just screws up the permissions, so now I > do a os.system() to the chmod command, but I'd like to know what is > happening here.... The problem is that your permission values are in the wrong radix. Try using octal instead of decimal, e.g., 0700 instead of 700. -- Ignacio Vazquez-Abrams From Python Tutor list" Message-ID: [lonetwin] > I've got a problem with the os.chmod() function > ... > dirmode = 744 > flmode = 700 Those are decimal literals, but arguments to chmod are usually expressed in octal notation. Try dirmode = 0744 flmode = 0700 instead and I bet you'll be happier. > ... > P.S: sincere sympathies to all Americans and all the victims of > terrorism on this dark day. Relax, they didn't get to Python's chmod() implementation yet . hard-to-know-what-they-hoped-to-accomplish-but-the-consequences- won't-please-them-ly y'rs - tim From lonetwin Wed Sep 12 07:21:33 2001 From: lonetwin (lonetwin) Date: Wed, 12 Sep 2001 11:51:33 +0530 (IST) Subject: [Tutor] problem with os.chmod() In-Reply-To: Message-ID: On Wed, 12 Sep 2001, Ignacio Vazquez-Abrams wrote: >On Wed, 12 Sep 2001, lonetwin wrote: > >> I've got a problem with the os.chmod() function, it just doesn't >> seem to do the right thing, let me explain, the code given below, is >> something that I needed, I'm running this on a linux system, this code >> changes the permissions of directories and files recursively. I initially >> used os.chmod() function but it just screws up the permissions, so now I >> do a os.system() to the chmod command, but I'd like to know what is >> happening here.... > >The problem is that your permission values are in the wrong radix. Try using >octal instead of decimal, e.g., 0700 instead of 700. > > Thanx ! that worked, what can I say, I'm slow :) -- Peace Steve From lonetwin Wed Sep 12 08:22:58 2001 From: lonetwin (lonetwin) Date: Wed, 12 Sep 2001 12:52:58 +0530 (IST) Subject: [Tutor] problem with threading module Message-ID: Hi everybody, Could someone please explain this: ########################################################### Python 2.0 (#1, Apr 11 2001, 19:18:08) [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> import thread >>> import threading Traceback (most recent call last): File "", line 1, in ? File "./threading.py", line 12, in ? class TestThread(threading.Thread): AttributeError: Thread >>> ######################################################### the threading module exists, and so does the definition of the Thread class.....I'm just learning about threading, so I'm clue-less right now -- Peace Steve From zhusm@neusoft.com Wed Sep 12 08:16:43 2001 From: zhusm@neusoft.com (=?gb2312?B?16PLs8Px?=) Date: Wed, 12 Sep 2001 15:16:43 +0800 Subject: [Tutor] help me please Message-ID: <00f701c13b5a$e2d26820$4201010a@zhushunmin> ÕâÊÇ MIME ¸ñʽµÄ¾ßÓкܶಿ·ÖÏûÏ¢¡£ --Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ) Content-type: text/plain; charset=gb2312 Content-transfer-encoding: QUOTED-PRINTABLE help me please ,why can't parse the xml on linux. my os is slcakware -linux-7.0 but the below programme have been executed on the windows 2000. the programme is cut from the python doc on the www.python.org. if you can help me .thank u very much. >>> import xml.dom.minidom >>>=20 >>> document =3D """\ =2E.. =2E.. Demo slideshow =2E.. Slide title =2E.. This is a demo =2E.. Of a program for processing slides =2E.. =2E..=20 =2E.. Another demo slide =2E.. It is important =2E.. To have more than =2E.. one slide =2E.. =2E.. =2E.. """ >>>=20 >>> dom =3D xml.dom.minidom.parseString(document) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.0/xml/dom/minidom.py", line 475, in parseStr= ing return _doparse(pulldom.parseString, args, kwargs) File "/usr/lib/python2.0/xml/dom/minidom.py", line 464, in _doparse events =3D apply(func, args, kwargs) File "/usr/lib/python2.0/xml/dom/pulldom.py", line 237, in parseStr= ing parser =3D xml.sax.make_parser() File "/usr/lib/python2.0/xml/sax/__init__.py", line 76, in make_par= ser return _create_parser(parser_name) File "/usr/lib/python2.0/xml/sax/__init__.py", line 101, in _create= _parser return drv_module.create_parser() AttributeError: create_parser >>>=20 >>> space =3D " " >>> def getText(nodelist): =2E.. rc =3D "" =2E.. for node in nodelist: =2E.. if node.nodeType =3D=3D node.TEXT_NODE: =2E.. rc =3D rc + node.data =2E.. return rc =2E..=20 >>> def handleSlideshow(slideshow): =2E.. print "" =2E.. handleSlideshowTitle(slideshow.getElementsByTagName("title"= )[0]) =2E.. slides =3D slideshow.getElementsByTagName("slide") =2E.. handleToc(slides) =2E.. handleSlides(slides) =2E.. print "" =2E..=20 >>> def handleSlides(slides): =2E.. for slide in slides: =2E.. handleSlide(slide) =2E..=20 >>> def handleSlide(slide): =2E.. handleSlideTitle(slide.getElementsByTagName("title")[0]) =2E.. handlePoints(slide.getElementsByTagName("point")) =2E..=20 >>> def handleSlideshowTitle(title): =2E.. print "%s" % getText(title.childNodes) =2E..=20 >>> def handleSlideTitle(title): =2E.. print "

%s

" % getText(title.childNodes) =2E..=20 >>> def handlePoints(points): =2E.. print "
    " =2E.. for point in points: =2E.. handlePoint(point) =2E.. print "
" =2E..=20 >>> def handlePoint(point): =2E.. print "
  • %s
  • " % getText(point.childNodes) =2E..=20 >>> def handleToc(slides): =2E.. for slide in slides: =2E.. title =3D slide.getElementsByTagName("title")[0] =2E.. print "

    %s

    " % getText(title.childNodes) =2E..=20 >>> handleSlideshow(dom) Traceback (most recent call last): File "", line 1, in ? NameError: There is no variable named 'dom' --Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ) Content-type: text/html; charset=gb2312 Content-transfer-encoding: QUOTED-PRINTABLE

     
    help me please ,why can't parse the xml on linux.=
    my os is slcakware -linux-7.0
    but the below programme have been executed on the= windows=20 2000.
    the programme is cut from the python doc on the www.python.org.
    if you can help me .thank u very much.
     
    >>> import xml.dom.minidom
    >>&g= t;=20
    >>> document =3D """\
    ... <slideshow>
    ...= =20 <title>Demo slideshow</title>
    ... <slide><tit= le>Slide=20 title</title>
    ... <point>This is a demo</point><= BR>...=20 <point>Of a program for processing slides</point>
    ...= =20 </slide>
    ...
    ... <slide><title>Another demo= =20 slide</title>
    ... <point>It is important</point>=
    ...=20 <point>To have more than</point>
    ... <point>one= =20 slide</point>
    ... </slide>
    ... </slideshow>...=20 """
    >>>
    >>> dom =3D=20 xml.dom.minidom.parseString(document)
    Traceback (most recent call= =20 last):
      File "<stdin>", line 1, in ?
      File= =20 "/usr/lib/python2.0/xml/dom/minidom.py", line 475, in=20 parseString
        return _doparse(pulldom.parseString= , args,=20 kwargs)
      File "/usr/lib/python2.0/xml/dom/minidom.py", line = 464, in=20 _doparse
        events =3D apply(func, args, kwargs)  File=20 "/usr/lib/python2.0/xml/dom/pulldom.py", line 237, in=20 parseString
        parser =3D xml.sax.make_parser()  File=20 "/usr/lib/python2.0/xml/sax/__init__.py", line 76, in=20 make_parser
        return _create_parser(parser_name)<= BR> =20 File "/usr/lib/python2.0/xml/sax/__init__.py", line 101, in=20 _create_parser
        return=20 drv_module.create_parser()
    AttributeError: create_parser
    >&g= t;>=20
    >>> space =3D " "
    >>> def=20 getText(nodelist):
    ...     rc =3D=20 ""
    ...     for node in=20 nodelist:
    ...         if= =20 node.nodeType =3D=3D=20 node.TEXT_NODE:
    ...        = ;    =20 rc =3D rc + node.data
    ...     return rc
    ...= =20
    >>> def handleSlideshow(slideshow):
    ...  &n= bsp; =20 print "<html>"
    ...    =20 handleSlideshowTitle(slideshow.getElementsByTagName("title")[0])
    .= ..    =20 slides =3D slideshow.getElementsByTagName("slide")
    ...  =   =20 handleToc(slides)
    ...    =20 handleSlides(slides)
    ...     print "</html&= gt;"
    ...=20
    >>> def handleSlides(slides):
    ...   &n= bsp; for=20 slide in slides:
    ...       = =20 handleSlide(slide)
    ...
    >>> def=20 handleSlide(slide):
    ...    =20 handleSlideTitle(slide.getElementsByTagName("title")[0])
    ... =    =20 handlePoints(slide.getElementsByTagName("point"))
    ...
    >>= > def=20 handleSlideshowTitle(title):
    ...     print= =20 "<title>%s</title>" % getText(title.childNodes)
    ...= =20
    >>> def handleSlideTitle(title):
    ...   = ; =20 print "<h2>%s</h2>" % getText(title.childNodes)
    ...= =20
    >>> def handlePoints(points):
    ...   &n= bsp; print=20 "<ul>"
    ...     for point in=20 points:
    ...        =20 handlePoint(point)
    ...     print "</ul>"=
    ...=20
    >>> def handlePoint(point):
    ...   &nbs= p; print=20 "<li>%s</li>" % getText(point.childNodes)
    ...
    >= >>=20 def handleToc(slides):
    ...     for slide in= =20 slides:
    ...         title = =3D=20 slide.getElementsByTagName("title")[0]
    ...    =     =20 print "<p>%s</p>" % getText(title.childNodes)
    ...=20
    >>> handleSlideshow(dom)
    Traceback (most recent call= =20 last):
      File "<stdin>", line 1, in ?
    NameError: The= re is no=20 variable named 'dom'
    --Boundary_(ID_0oq7fIwnhAjEDPKstES2YQ)-- From dyoo@hkn.eecs.berkeley.edu Wed Sep 12 08:21:13 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 12 Sep 2001 00:21:13 -0700 (PDT) Subject: [Tutor] problem with threading module In-Reply-To: Message-ID: On Wed, 12 Sep 2001, lonetwin wrote: > Hi everybody, > Could someone please explain this: > ########################################################### > Python 2.0 (#1, Apr 11 2001, 19:18:08) > [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386 > Type "copyright", "credits" or "license" for more information. > >>> import thread > >>> import threading > Traceback (most recent call last): > File "", line 1, in ? > File "./threading.py", line 12, in ? > class TestThread(threading.Thread): > AttributeError: Thread As a guess: it sounds like you may have called your program "threading.py", or perhaps there's a file called 'threading.py' in your current directory. If so, you might want to either move or rename it, as 'threading' is also the name of the Python module 'threading'. It sounds like Python's getting confused between the official module and the one in your current directory, so they may be conflicting. However, these are wild guesses. Can you give us some more information? From ignacio@openservices.net Wed Sep 12 08:25:08 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 03:25:08 -0400 (EDT) Subject: [Tutor] problem with threading module In-Reply-To: Message-ID: On Wed, 12 Sep 2001, lonetwin wrote: > Hi everybody, > Could someone please explain this: > ########################################################### > Python 2.0 (#1, Apr 11 2001, 19:18:08) > [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386 > Type "copyright", "credits" or "license" for more information. > >>> import thread > >>> import threading > Traceback (most recent call last): > File "", line 1, in ? > File "./threading.py", line 12, in ? > class TestThread(threading.Thread): > AttributeError: Thread > >>> > ######################################################### > the threading module exists, and so does the definition of the Thread > class.....I'm just learning about threading, so I'm clue-less right now You have a local file called threading.py that is masking access to the standard Python module of the same name. -- Ignacio Vazquez-Abrams From alan.gauld@bt.com Wed Sep 12 10:49:55 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 12 Sep 2001 10:49:55 +0100 Subject: [Tutor] string.replace Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF42@mbtlipnt02.btlabs.bt.co.uk> > >>> from string import * > >>> def striptabs(line): > ... if "<" in line: > ... l = find(line, "<", 0) > ... m = find(line, ">", l) > ... if l and m: > ... print "Tag found" # Test > ... line = replace(line, line[l:m+1], "") > ... striptabs(line) return striptabs(line) > ... return line You eren't returning the result to the top level so only the top level actually did anything.... Alan g. From printers@sendme.cz Wed Sep 12 11:13:43 2001 From: printers@sendme.cz (A) Date: Wed, 12 Sep 2001 12:13:43 +0200 Subject: [Tutor] List of lists Message-ID: <3B9F5177.19317.46DDB8@localhost> Hi, How can I create a List of Lists and how I can acess each item in this List. Thank you Ladislav From ignacio@openservices.net Wed Sep 12 11:22:37 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 06:22:37 -0400 (EDT) Subject: [Tutor] List of lists In-Reply-To: <3B9F5177.19317.46DDB8@localhost> Message-ID: On Wed, 12 Sep 2001, A wrote: > How can I create a List of Lists and how I can acess each item in > this List. t=[[1,2],[3,4,5],[6]] print t[0][1],t[1][2],t[2][0] -- Ignacio Vazquez-Abrams From dsh8290@rit.edu Wed Sep 12 11:38:04 2001 From: dsh8290@rit.edu (dman) Date: Wed, 12 Sep 2001 06:38:04 -0400 Subject: [Tutor] string.replace In-Reply-To: References: Message-ID: <20010912063804.A4055@hudson> On Wed, Sep 12, 2001 at 12:56:14AM -0400, Ignacio Vazquez-Abrams wrote: | > The recursive striptabs() call is buggy, but's also intentionally | > recursive: if Jon changes the line from: | > | > striptabs(line) | > | > to: | > | > line = striptabs(line) | > | > and corrects a few more logical bugs, the code should work because | > striptabs should only call itself recursivly if the line still contains | > tags --- his use of recursion is about the same as if he had used an | > explicit while loop. | | That's true, but 95-97% of the time iterative constructs are faster than | recursive mechanisms, plus by definition they don't cause recursion overflows. | Both of those points can be a big advantage if very large documents are being | processed. I just want to mention that, while this is true for Python, C, C++, and Java (and others too I am sure), it is not necessarily true for Common Lisp or Scheme. If a tail-recursive style is used then the Listp/Scheme compiler will optimize out all of the recursive calls and it will be just as fast as an iterative solution. -D From alan.gauld@bt.com Wed Sep 12 11:52:53 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 12 Sep 2001 11:52:53 +0100 Subject: [Tutor] string.replace Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF43@mbtlipnt02.btlabs.bt.co.uk> > That's true, but 95-97% of the time iterative constructs are > faster than recursive mechanisms, I suppose thats true if you consider that every loop can be implemented recursively. However for those cases where recursion is the most natural solution (tree walking being a good example) the recursive approach is usually both much shorter and faster. > plus by definition they don't cause recursion overflows. But this is a valid comment (for Python) because in striptabs() case it could very easily be passed a large file with lots of tags(reading a complete HTML file as a string for example) and the recursion limit(999?) would be burst. Alan G From ajaya@ncoretech.com Wed Sep 12 12:06:56 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Wed, 12 Sep 2001 16:36:56 +0530 Subject: some more doubts:? RE: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: Message-ID: <000001c13b7b$09b64180$6501a8c0@ncoretech.com> Hi, I've some more doubts regarding serilizing objects and converting integer data to binary packed string. First when I use struct module...there is problem I am facing.., My code looks like class EventDial(Event): def __init__(self, Pipe, DigitStr): Event.__init__(self, Pipe) self.DialedNumber = DigitStr print self.DialedNumber self.EventType = 1 def Serialize(self): a = len(self.DialedNumber) data = pack('IIs', self.EventType, len(self.DialedNumber), self.DialedNumber) self.Pipe.SendData(data) but packing data using 'IIs' givign problem when my string size is more than 1. For example if I dail a number 911 my string size is 3 when I pack and receive at the toher end It is giving like this..., 1l, 3l, '9' When i went through the documentation i got a feeling that I should give sring size as a prefix to the 's' parameter. But i've variable string lenght. So How can I use this prefix notation...,? Second thing when I tried using pickle. I confused with the documentation. there is a pcikle.dump(obj, file, bin=0) function.., but it always needs file. If I want to send to network (LAN) then why I need to have a file operation in between it is slow right? If I don't need to do this plese give me example or link to the docs. I quite confused with the pickle..., Thanks and Regards, Ajaya Babu -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Danny Yoo Sent: Wednesday, September 12, 2001 12:34 AM To: Ajaya Babu Cc: PythonTutorlist (E-mail) Subject: Re: [Tutor] How to convert integer to binay packed string...,? On Tue, 11 Sep 2001, Ajaya Babu wrote: > I've a small doubt, How to convert integers into bytestream in python. > What actually I want to do is send integer to another system in the > network. But since there is nothing like integer in python...I am just > wondering how can Actually, Python Integers are 32-bit integers, and we can do bitwise manipulation with them: ### >>> x = 2 >>> x>>2 0 >>> x<<2 8 >>> 0xffffffff & 0x00002000 8192 ### As Ignacio as mentioned, it sounds like you'll want to look at the "struct" module, a module that deals exclusively with packing things into bytes. Alternatively, you might want to look at the "pickle" module: http://python.org/doc/current/lib/module-pickle.html pickle will allow us to preserve integers into strings --- in effect, it turns things into a bytestream. pickle will "serialize" Python objects into something that we can save, or send! If you're sending something across the network to another Python system, pickle might be useful for you. Hope this helps! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From cerulean_rodent@yahoo.co.uk Wed Sep 12 13:50:25 2001 From: cerulean_rodent@yahoo.co.uk (Cerulean Rodent) Date: Wed, 12 Sep 2001 16:50:25 +0400 (MSD) Subject: [Tutor] adding users from a script Message-ID: Hello hello hello, I haven't got the foggiest as to whether introductory messages are obligatory and am moving on to what's been bugging me lately skipping that part. Our existence is all pretty illusionary anyway, so why bother? What I'm trying to do at the moment is writing a script that would add users without creating a home directory, then generating and assigning random passwords. The proggy itself is ugly and messy and I'll have to work on making it presentable; but I would really like to make it functional first. So here goes: #!/usr/bin/python import os import whrandom rnd = whrandom.whrandom() validfirst = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789" pwlen = 8 pw = "" idx = 0 while idx < pwlen: str = validfirst[rnd.randint(0,(len(validfirst)-1))] pw = pw + str idx = idx + 1 print "\nEnter your desired username:\n" nomme = raw_input (">>") os.system ('useradd ' + nomme) Now this is the part I got really stuck on os.system ('passwd ' + nomme) gets me a prompt which I need about as much as I need a hole in my cranium; I want the password to be read from the pw variable directly. How could I possibly accomplish it? From what I have understood from the excellent (but, sadly, a touch arcane) tome by Mark Lutz, I might be better off using os.popen - but the directions on its correct syntax are far from clear. And am I right about useradd -p requiring an encrypted password? Blimey, this script is probably worse off than the Medical Love Song protagonist... Pope Mickey XXIII, Chief Ov Thee Church Police ----------------------------------------------------- " The stars go waltzing out in blue and red, And arbitrary blackness gallops in: I shut my eyes and all the world drops dead. " --Sylvia Plath ----------------------------------------------------- From lonetwin@yahoo.com Wed Sep 12 14:41:29 2001 From: lonetwin@yahoo.com (lonetwin) Date: Wed, 12 Sep 2001 19:11:29 +0530 Subject: [Tutor] adding users from a script In-Reply-To: References: Message-ID: <01091219112903.18667@mercury.worli> Hi, A suggestion ....maybe you should look at the crypt module...it implements the crypt(3) function and returns an encrypted passwd that the 'useradd -p' option expects. references: man useradd // look at the -p option man passwd man 3 crypt // this is the function that the python crypt module implements HTH Peace Steve On Wednesday 12 September 2001 18:20, you wrote: > Hello hello hello, > > I haven't got the foggiest as to whether introductory messages are > obligatory and am moving on to what's been bugging me lately skipping that > part. Our existence is all pretty illusionary anyway, so why bother? > > What I'm trying to do at the moment is writing a script that would add > users without creating a home directory, then generating and assigning > random passwords. The proggy itself is ugly and messy and I'll have to > work on making it presentable; but I would really like to make it > functional first. So here goes: > > #!/usr/bin/python > > import os > > import whrandom > > rnd = whrandom.whrandom() > > validfirst = > "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789" > > pwlen = 8 > > pw = "" > > idx = 0 > > while idx < pwlen: > str = validfirst[rnd.randint(0,(len(validfirst)-1))] > pw = pw + str > idx = idx + 1 > > print "\nEnter your desired username:\n" > > nomme = raw_input (">>") > > os.system ('useradd ' + nomme) > > Now this is the part I got really stuck on > > os.system ('passwd ' + nomme) gets me a prompt which I need about as much > as I need a hole in my cranium; I want the password to be read from the pw > variable directly. How could I possibly accomplish it? From what I have > understood from the excellent (but, sadly, a touch arcane) tome by Mark > Lutz, I might be better off using os.popen - but the directions on its > correct syntax are far from clear. And am I right about useradd -p > requiring an encrypted password? Blimey, this script is probably worse off > than the Medical Love Song protagonist... > > > Pope Mickey XXIII, Chief Ov Thee Church Police > > ----------------------------------------------------- > > " The stars go waltzing out in blue and red, > And arbitrary blackness gallops in: > I shut my eyes and all the world drops dead. " > > --Sylvia Plath From lonetwin@yahoo.com Wed Sep 12 14:46:07 2001 From: lonetwin@yahoo.com (lonetwin) Date: Wed, 12 Sep 2001 19:16:07 +0530 Subject: [Tutor] adding users from a script In-Reply-To: References: Message-ID: <01091219160704.18667@mercury.worli> Hi, A suggestion ....maybe you should look at the crypt module...it implements the crypt(3) function and returns an encrypted passwd that the 'useradd -p' option expects. references: man useradd // look at the -p option man passwd man 3 crypt // this is the function that the python crypt module implements ================================================================== To add to that ealier post ....the url for crypt documentation: http://www.python.org/doc/current/lib/module-crypt.html Peace Steve From ajaya@ncoretech.com Wed Sep 12 14:31:58 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Wed, 12 Sep 2001 19:01:58 +0530 Subject: [Tutor] doubts with socket asychronous doc.., Message-ID: <000001c13b8f$4ca41b70$6501a8c0@ncoretech.com> Hi, I've some dbouts of using asyncore module for asychronous socket service clients and servers. http://www.python.org/doc/current/lib/module-asyncore.html Example is given like this class http_client(asyncore.dispatcher): def __init__(self, host,path): asyncore.dispatcher.__init__(self) self.path = path self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect( (host, 80) ) self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % self.path def handle_connect(self): pass def handle_read(self): data = self.recv(8192) print data def writable(self): return (len(self.buffer) > 0) def handle_write(self): sent = self.send(self.buffer) self.buffer = self.buffer[sent:] from the documentation I understand handle_read will be called when ever new data to be read from the socket..., and handle_write will be called when attempt to write the object. but I did not understand these terms properly. I had a confustion who is going to initiate these events. Like read or write...., For example my C server send some data on port x, suppose my python appliation should recive that data as a asynchronous menas is this just ok if I make a instant of the above class and connect to the server...,(Assuming that handle_read) will be called asynchronously when data arives to that port. but Documentation is telling me it is wraper around the select() fuction. Generally select() function need to be polled as my understanding. It just gives the idea that can performing certain action is worth or not..., but from the above example it is nor clear that who is polling on this function to call handle_read functions. One more thing is if I want to send some data to my C host again.., How do I do it. Do I need to send just like mysocket.send(buffer)...or handle_write() how can I use.., it is not clear from the documentation May be my understanding is poor....since I just started learning python.., Please send me some doc liks or give me suggestion to make my study progress, Thanks allot for great help. with regards, Ajaya From ignacio@openservices.net Wed Sep 12 16:46:37 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 11:46:37 -0400 (EDT) Subject: some more doubts:? RE: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: <000001c13b7b$09b64180$6501a8c0@ncoretech.com> Message-ID: On Wed, 12 Sep 2001, Ajaya Babu wrote: > but packing data using 'IIs' givign problem when my string size is more than > 1. For example if I dail a number 911 my string size is 3 when I pack and > receive at the toher end > > It is giving like this..., > 1l, 3l, '9' > > When i went through the documentation i got a feeling that I should give > sring size as a prefix to the 's' parameter. But i've variable string > lenght. So How can I use this prefix notation...,? Look at using Pascal-style strings whereby the first byte is the length of the string. It restricts your string to 255 characters, but that should be enough for most cases. -- Ignacio Vazquez-Abrams From dsh8290@rit.edu Wed Sep 12 17:09:26 2001 From: dsh8290@rit.edu (dman) Date: Wed, 12 Sep 2001 12:09:26 -0400 Subject: some more doubts:? RE: [Tutor] How to convert integer to binay packed string...,? In-Reply-To: <000001c13b7b$09b64180$6501a8c0@ncoretech.com> References: <000001c13b7b$09b64180$6501a8c0@ncoretech.com> Message-ID: <20010912120926.A1092@hudson> On Wed, Sep 12, 2001 at 04:36:56PM +0530, Ajaya Babu wrote: | Hi, | I've some more doubts regarding serilizing objects and converting integer | data to binary packed string. | | | First when I use struct module...there is problem I am facing.., My code | looks like | | class EventDial(Event): | | def __init__(self, Pipe, DigitStr): | Event.__init__(self, Pipe) | self.DialedNumber = DigitStr | print self.DialedNumber | self.EventType = 1 | | def Serialize(self): | a = len(self.DialedNumber) | data = pack('IIs', self.EventType, len(self.DialedNumber), | self.DialedNumber) | self.Pipe.SendData(data) | | but packing data using 'IIs' givign problem when my string size is more than | 1. For example if I dail a number 911 my string size is 3 when I pack and | receive at the toher end | | It is giving like this..., | 1l, 3l, '9' | | When i went through the documentation i got a feeling that I should give | sring size as a prefix to the 's' parameter. But i've variable string | lenght. So How can I use this prefix notation...,? data = pack('II%ds' % len( self.DialedNumber ) , self.EventType, len(self.DialedNumber), self.DialedNumber) Use string interpolation or addition to add the number in dynamically. Nothing says that the string has to be static. I don't know how this would work on the receiving side though. Perhaps you would have to extract the length integer first, then you would be able to construct the format string to unpack the data string. | Second thing when I tried using pickle. I confused with the documentation. | there is a pcikle.dump(obj, file, bin=0) function.., but it always needs | file. If I want to send to network (LAN) then why I need to have a file | operation in between it is slow right? If I don't need to do this plese give | me example or link to the docs. I quite confused with the pickle..., Does it need a 'file' or a 'file-like object'? (I haven't checked the docs myself) If it is the latter, then a socket connection would work. It definitely needs something that it can write() to to dump the object and something it can read() from to retrieve the object. HTH, -D From alan.gauld@bt.com Wed Sep 12 17:43:53 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 12 Sep 2001 17:43:53 +0100 Subject: [Tutor] adding users from a script Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF52@mbtlipnt02.btlabs.bt.co.uk> > I haven't got the foggiest as to whether introductory messages are > obligatory Nope, just ask quetions :-) > import whrandom > rnd = whrandom.whrandom() > > validfirst = > "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789" You might find it easier in future to use: validfirst = string.letters + string.digits[2:] I notice you disallow 1 and 0 - any reason? > pwlen = 8 > pw = "" > idx = 0 > > while idx < pwlen: > str = validfirst[rnd.randint(0,(len(validfirst)-1))] str = rnd.choice(validfirst) # a bit easier? > pw = pw + str Could combine these two lines: pw = pw + rnd.choice(validfirst) > idx = idx + 1 > > print "\nEnter your desired username:\n" > nomme = raw_input (">>") Why not combine these: nomme = raw_input("\nEnter your desired username:\n>> ") > os.system ('useradd ' + nomme) > > Now this is the part I got really stuck on > os.system ('passwd ' + nomme) gets me a prompt Thats why you need to use popen or popen2. They allow you to write to that prompt. > correct syntax are far from clear. Treat it as a file. In your case open to write - you want to send data to it... Try searching the ActiveState version of this list archive for popen you should find lots of code examples. That should solve it. Alan G From python.tutorial@jarava.org Wed Sep 12 19:45:50 2001 From: python.tutorial@jarava.org (Javier JJ) Date: Wed, 12 Sep 2001 20:45:50 +0200 Subject: [Tutor] test (something seems to be wrong) Message-ID: <007a01c13bbb$25c70e50$0124a8c0@uno> From python.tutorial@jarava.org Wed Sep 12 19:50:57 2001 From: python.tutorial@jarava.org (Javier JJ) Date: Wed, 12 Sep 2001 20:50:57 +0200 Subject: [Tutor] RE: test (something seems to be wrong) Message-ID: <000d01c13bbb$dc69aa00$0124a8c0@uno> ----- Mensaje original ----- De: "Javier JJ" Para: "Lista Python" Enviado: miércoles, 12 de septiembre de 2001 20:45 Asunto: test (something seems to be wrong) > > From csmith@blakeschool.org Wed Sep 12 20:46:37 2001 From: csmith@blakeschool.org (Christopher Smith) Date: Wed, 12 Sep 2001 14:46:37 -0500 Subject: [Tutor] redefining builtin function Message-ID: Hi list, I am trying to redefine a built in function. I can do the following in the interactive window but not in a script. Can anyone help me with the script? >>> from math import floor, log10 >>> def round(x,n=0): ... if n%1==0: ... return __builtins__.round(x,n) ... return __builtins__.round(x,int(10*n)-1-floor(log10(abs(x)))) ... >>> print round(1.234567,2) 1.23 >>> print round(1.234567,0.2) 1.2 >>> When I do the same thing in a script I get an "attribute error" so apparently I am working with a different namespace. Is there a way to make sure that I can get access to the global _builtins__.round no matter where round is defined? /c From shalehperry@home.com Wed Sep 12 20:57:35 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Wed, 12 Sep 2001 12:57:35 -0700 (PDT) Subject: [Tutor] redefining builtin function In-Reply-To: Message-ID: Seems to work here. $ cat test.py #! /usr/bin/python def round(x, n=0): print x, n print __builtins__.round(x,n) round(5.0, 1) round(3.23) $ python test.py 5.0 1 5.0 3.23 0 3.0 This is under 1.5.2. From pobrien@orbtech.com Wed Sep 12 20:59:37 2001 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Wed, 12 Sep 2001 14:59:37 -0500 Subject: [Tutor] redefining builtin function In-Reply-To: Message-ID: You need to explicitly import __builtins__. It is imported by default in the shell, which is why your code worked interactively. You need to add an import statement somewhere, like this: def round(x,n=0): import __builtins__ # Add this. if n%1==0: ... --- Patrick K. O'Brien Orbtech (http://www.orbtech.com) "I am, therefore I think." -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Christopher Smith Sent: Wednesday, September 12, 2001 2:47 PM To: tutor@python.org Subject: [Tutor] redefining builtin function Hi list, I am trying to redefine a built in function. I can do the following in the interactive window but not in a script. Can anyone help me with the script? >>> from math import floor, log10 >>> def round(x,n=0): ... if n%1==0: ... return __builtins__.round(x,n) ... return __builtins__.round(x,int(10*n)-1-floor(log10(abs(x)))) ... >>> print round(1.234567,2) 1.23 >>> print round(1.234567,0.2) 1.2 >>> When I do the same thing in a script I get an "attribute error" so apparently I am working with a different namespace. Is there a way to make sure that I can get access to the global _builtins__.round no matter where round is defined? /c _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From jcosby@mindspring.com Wed Sep 12 21:06:16 2001 From: jcosby@mindspring.com (Jon Cosby) Date: Wed, 12 Sep 2001 13:06:16 -0700 Subject: [Tutor] Thanks Message-ID: Thanks to everybody for all your help the last few days. I've been modifying a search engine originally written for plain text files to search my website. It's been fun, and I've learned a lot in the process. I need to get better at error handling, that might have saved a lot of trouble. If your interested in seeing this, follow the link below. It will be on the Python page. Let me know if you see any bugs. Jon Cosby jcosby@mindspring.com www.jcosby.com From shalehperry@home.com Wed Sep 12 21:11:49 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Wed, 12 Sep 2001 13:11:49 -0700 (PDT) Subject: [Tutor] redefining builtin function In-Reply-To: Message-ID: On 12-Sep-2001 Patrick K. O'Brien wrote: > You need to explicitly import __builtins__. It is imported by default in the > shell, which is why your code worked interactively. You need to add an > import statement somewhere, like this: > odd, importing builtins triggers an exception for me under both 1.5.x and 2.x. From mascher@crg.ha.nw.schule.de Wed Sep 12 21:32:38 2001 From: mascher@crg.ha.nw.schule.de (Christian Mascher) Date: Wed, 12 Sep 2001 22:32:38 +0200 Subject: [Tutor] round() errors Message-ID: <3B9FC666.1EC16FE5@gmx.de> Hi All, I don't understand some response from the round()-function. >>> round(1.4783321399,2) 1.48 >>> round(1.95583,2) # this is the ratio of EURO to DM 1.96 so far, so good, but ... >>> round(10*1.95583,2) 19.559999999999999 >>> round(20*1.95583,2) 39.119999999999997 >>> a=20*1.95583 >>> a 39.116599999999998 >>> round(a,2) 39.119999999999997 I recall reading somebody explain this behaviour with the problem of representing base-10 float-numbers in a binary system. Still, I ask myself, why can't round() be smart enough to handle this on its own (especially the last case)? Since you can do >>> print '%.2f' %a 39.12 >>> why can't round() do the same? Is there any reason? Christian From tim.one@home.com Wed Sep 12 21:42:00 2001 From: tim.one@home.com (Tim Peters) Date: Wed, 12 Sep 2001 16:42:00 -0400 Subject: [Tutor] redefining builtin function In-Reply-To: Message-ID: Tere is no module named __builtins__ The name of the module you want is __builtin__ (note that lack of the letter 's'). So import __builtin__ followed by references to __builtin__.round always works. __builtins__ (with the trailing 's') is an implementation detail you should never use directly (you can read more about that in the Reference Manual, but in the end you'll simply agree you should never use it directly ). From ignacio@openservices.net Wed Sep 12 21:42:44 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 12 Sep 2001 16:42:44 -0400 (EDT) Subject: [Tutor] round() errors In-Reply-To: <3B9FC666.1EC16FE5@gmx.de> Message-ID: On Wed, 12 Sep 2001, Christian Mascher wrote: > Hi All, > > I don't understand some response from the round()-function. > > >>> round(1.4783321399,2) > 1.48 > >>> round(1.95583,2) # this is the ratio of EURO to DM > 1.96 > > so far, so good, but ... > > >>> round(10*1.95583,2) > 19.559999999999999 > >>> round(20*1.95583,2) > 39.119999999999997 > >>> a=20*1.95583 > >>> a > 39.116599999999998 > >>> round(a,2) > 39.119999999999997 > > I recall reading somebody explain this behaviour with the problem of > representing base-10 float-numbers in a binary system. Still, I ask > myself, why can't round() be smart enough to handle this on its own > (especially the last case)? > Since you can do > > >>> print '%.2f' %a > 39.12 > >>> > > why can't round() do the same? Is there any reason? It's because round() returns a floating-point number, whereas format specifiers convert it to a string. -- Ignacio Vazquez-Abrams From kalle@gnupung.net Wed Sep 12 21:54:24 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Wed, 12 Sep 2001 22:54:24 +0200 Subject: [Tutor] round() errors In-Reply-To: <3B9FC666.1EC16FE5@gmx.de>; from christian.mascher@gmx.de on Wed, Sep 12, 2001 at 10:32:38PM +0200 References: <3B9FC666.1EC16FE5@gmx.de> Message-ID: <20010912225424.A19740@gandalf> [Christian Mascher] > I don't understand some response from the round()-function. > > >>> round(1.4783321399,2) > 1.48 > >>> round(1.95583,2) # this is the ratio of EURO to DM > 1.96 > > so far, so good, but ... > > >>> round(10*1.95583,2) > 19.559999999999999 > >>> round(20*1.95583,2) > 39.119999999999997 > >>> a=20*1.95583 > >>> a > 39.116599999999998 > >>> round(a,2) > 39.119999999999997 > > >>> print '%.2f' %a > 39.12 > >>> > > why can't round() do the same? Is there any reason? >>> round(20*1.95583,2) 39.119999999999997 >>> print round(20*1.95583,2) 39.12 >>> repr(round(20*1.95583,2)) '39.119999999999997' >>> str(round(20*1.95583,2)) '39.12' >>> Peace, Kalle -- [ kalle@gnupung.net ][ Thought control, brought to you by the WIPO! ] [ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ] From tutor@python.org Wed Sep 12 21:53:30 2001 From: tutor@python.org (Tim Peters) Date: Wed, 12 Sep 2001 16:53:30 -0400 Subject: [Tutor] round() errors In-Reply-To: <3B9FC666.1EC16FE5@gmx.de> Message-ID: [Christian Mascher] > I don't understand some response from the round()-function. > ... > >>> round(10*1.95583,2) > 19.559999999999999 > >>> round(20*1.95583,2) > 39.119999999999997 > >>> a=20*1.95583 > >>> a > 39.116599999999998 > >>> round(a,2) > 39.119999999999997 Please read http://python.sourceforge.net/devel-docs/tut/node14.html which discusses this specific issue (among others). > ... > Is there any reason? Yes . From pobrien@orbtech.com Wed Sep 12 22:02:33 2001 From: pobrien@orbtech.com (Patrick K. O'Brien) Date: Wed, 12 Sep 2001 16:02:33 -0500 Subject: [Tutor] redefining builtin function In-Reply-To: Message-ID: Sorry, that module is actually __builtin__ with no "s". Not to be confused (as I always do) with the __builtins__ attribute of the module, which is the dictionary you see in the shell. So remove the "s" from all references to __builtins__ in your code. Make sense? --- Patrick K. O'Brien Orbtech (http://www.orbtech.com) "I am, therefore I think." -----Original Message----- From: Sean Perry [mailto:shaleh@one.local]On Behalf Of Sean 'Shaleh' Perry Sent: Wednesday, September 12, 2001 3:12 PM To: Patrick K. O'Brien Cc: tutor@python.org Subject: RE: [Tutor] redefining builtin function On 12-Sep-2001 Patrick K. O'Brien wrote: > You need to explicitly import __builtins__. It is imported by default in the > shell, which is why your code worked interactively. You need to add an > import statement somewhere, like this: > odd, importing builtins triggers an exception for me under both 1.5.x and 2.x. From lco@gofuse.com Wed Sep 12 22:06:21 2001 From: lco@gofuse.com (lco ) Date: Wed, 12 Sep 2001 14:06:21 -0700 Subject: [Tutor] network file copy Message-ID: <200109121406.AA6488536@mail1.gofuse.com> can someone give me some ideas as to how I can copy files to a network share on the Win32 platform? I've tried to copy using the shutil module but it does not recognize share formats such as //server-name/share-name TIA lco From csmith@blakeschool.org Wed Sep 12 22:18:32 2001 From: csmith@blakeschool.org (Christopher Smith) Date: Wed, 12 Sep 2001 16:18:32 -0500 Subject: [Tutor] Re: redefining builtin function In-Reply-To: References: Message-ID: shalehperry@home.com writes: >Seems to work here. hmm...but not here. Here is my IDE header Python 2.1.1 (#97, Aug 2 2001, 21:56:33) [CW CARBON GUSI2 THREADS] Type "copyright", "credits" or "license" for more information. >>> I tried pasting the following script (now like yours) into a fresh script window of a fresh session and still get the AttributeError. #### def round(x,n=0): return __builtins__.round(x,n) print round(1.23,1) #### No problem in the interactive window, though. :-( /c From danny.kohn@systematik.se Thu Sep 13 00:33:07 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Thu, 13 Sep 2001 01:33:07 +0200 Subject: [Tutor] What to choose - database Message-ID: Hi. I am a total newbie having spent the last week to read a lot of stuff = about Python, coming to think that it could be a good language for my = program project. My question is regarding databases. The application I = want to write does probably need some form of database support. It is = very much material to digest and I am a very slow reader so I would like = to get some advice which path that might be most successful or easiest. By background is from 20 years ago when computers, even microcomputers, = had a control panel and you could single step them. The program language = was assembler. Have also done some Basic and also in nearer time some = small tasks in Visual Basic. Now, I have come to like the MySQL concept although I am not attached to = it (yet). Now I'm sure my questions seem unenlightened and they are but = that is what this list is about so here they are. 1. It seems that I can do database access two ways, through the DB-API = spec v2.0 or through ODBC (which I understand is also support in Linux). = Is this a correct understanding? 2. If this is so, what way would be the best choice and why? 3. I need to be able to create tables from the program. But I have not = found any way to do it. How to do this? 4. Does one run SQL to access tables from Python. If so, how is this = done? If not, what does one do instead? Running through the API? But = then, what does one do when one want to access the database(s) when the = "specified" ways are inadequate? H=E4lsningar / Regards (\_/) )) Danny Kohn Tel: +46 (0)708 140 300 =3D('.')=3D// Miau! Systematik Consulting AB ICQ: 1328817 ( ~~~ )/ Rrrrrui! http://www.systematik.se HAM: SM0NBJ `w---w=B4=20 From lkvam@venix.com Thu Sep 13 00:47:45 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Wed, 12 Sep 2001 19:47:45 -0400 Subject: [Tutor] What to choose - database References: Message-ID: <3B9FF421.927B79F4@venix.com> Danny Kohn wrote: > = > Hi. > I am a total newbie having spent the last week to read a lot of stuff a= bout Python, coming to think that it could be a good language for my prog= ram project. My question is regarding databases. The application I want t= o write does probably need some form of database support. It is very much= material to digest and I am a very slow reader so I would like to get so= me advice which path that might be most successful or easiest. > = > By background is from 20 years ago when computers, even microcomputers,= had a control panel and you could single step them. The program language= was assembler. Have also done some Basic and also in nearer time some sm= all tasks in Visual Basic. > = > Now, I have come to like the MySQL concept although I am not attached t= o it (yet). Now I'm sure my questions seem unenlightened and they are but= that is what this list is about so here they are. > = > 1. It seems that I can do database access two ways, through the DB-API = spec v2.0 or through ODBC (which I understand is also support in Linux). = Is this a correct understanding? YES > = > 2. If this is so, what way would be the best choice and why? > = ODBC gives you easy portability between SQL servers. It also allows non-= Python applications access to the database. If you have any of these (e.= g. SAS, Excel, Access) you will wind up doing the ODBC anyway. The DB-API will give slightly better performance. I normally use ODBC. > 3. I need to be able to create tables from the program. But I have not = found any way to do it. How to do this? SQL create table commands. Just pass them to the database using your int= erface using ODBC or whatever. > = > 4. Does one run SQL to access tables from Python. If so, how is this do= ne? If not, what does one do instead? Running through the API? But then, = what does one do when one want to access the database(s) when the "specif= ied" ways are inadequate? For instance: DB.shared_conn=3DODBC.Windows.connect('shared',clear_auto_commit=3D0) cursor =3D DB.shared_conn.cursor() # Start with first Database found cursor.execute("SHOW DATABASES") DB.ds.fromCursor(cursor) This gets a list of available databases into the DB.ds object. > = > H=E4lsningar / Regards (\_/) )) > Danny Kohn Tel: +46 (0)708 140 300 =3D('.')=3D// Miau= ! > Systematik Consulting AB ICQ: 1328817 ( ~~~ )/ Rrrrrui!= > http://www.systematik.se HAM: SM0NBJ `w---w=B4 > = > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- = Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From ajaya@ncoretech.com Thu Sep 13 06:04:57 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Thu, 13 Sep 2001 10:34:57 +0530 Subject: [Tutor] doubts with socket asychronous doc.., In-Reply-To: <000001c13b8f$4ca41b70$6501a8c0@ncoretech.com> Message-ID: <000901c13c11$a30ccc00$6501a8c0@ncoretech.com> Hi my earliar message not seems to catch up any one eye so I am re posting this. Please help me regarding this socket module. Thanks and Regards, Ajaya Hi, I've some dbouts of using asyncore module for asychronous socket service clients and servers. http://www.python.org/doc/current/lib/module-asyncore.html Example is given like this class http_client(asyncore.dispatcher): def __init__(self, host,path): asyncore.dispatcher.__init__(self) self.path = path self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect( (host, 80) ) self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % self.path def handle_connect(self): pass def handle_read(self): data = self.recv(8192) print data def writable(self): return (len(self.buffer) > 0) def handle_write(self): sent = self.send(self.buffer) self.buffer = self.buffer[sent:] from the documentation I understand handle_read will be called when ever new data to be read from the socket..., and handle_write will be called when attempt to write the object. but I did not understand these terms properly. I had a confustion who is going to initiate these events. Like read or write...., For example my C server send some data on port x, suppose my python appliation should recive that data as a asynchronous menas is this just ok if I make a instant of the above class and connect to the server...,(Assuming that handle_read) will be called asynchronously when data arives to that port. but Documentation is telling me it is wraper around the select() fuction. Generally select() function need to be polled as my understanding. It just gives the idea that can performing certain action is worth or not..., but from the above example it is nor clear that who is polling on this function to call handle_read functions. One more thing is if I want to send some data to my C host again.., How do I do it. Do I need to send just like mysocket.send(buffer)...or handle_write() how can I use.., it is not clear from the documentation May be my understanding is poor....since I just started learning python.., Please send me some doc liks or give me suggestion to make my study progress, Thanks allot for great help. with regards, Ajaya _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Thu Sep 13 11:19:03 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Thu, 13 Sep 2001 11:19:03 +0100 Subject: [Tutor] network file copy Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF59@mbtlipnt02.btlabs.bt.co.uk> > can someone give me some ideas as to how I can copy files to > a network share on the Win32 platform? See my recent post about using WSH from within Python. You can do this stuff using the WSH objects, specifically the filesystem object allows access to shares but I think the net object also does it. (I don't have my WSH book to hand right now...) HTH, Alan G. From danny.kohn@systematik.se Thu Sep 13 12:23:03 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Thu, 13 Sep 2001 13:23:03 +0200 Subject: SV: [Tutor] What to choose - database In-Reply-To: <3B9FF421.927B79F4@venix.com> Message-ID: Thanks for ansering so promptly. What ODBC package for Pyhon would be the moste approperiate? /Danny | -----Ursprungligt meddelande----- | Fr=E5n: tutor-admin@python.org [mailto:tutor-admin@python.org]F=F6r = Lloyd | Kvam | Skickat: den 13 september 2001 01:48 | Till: Danny Kohn | Kopia: Python Tutor mailing list | =C4mne: Re: [Tutor] What to choose - database |=20 |=20 | Danny Kohn wrote: | >=20 | > Hi. | > I am a total newbie having spent the last week to read a lot of=20 | stuff about Python, coming to think that it could be a good=20 | language for my program project. My question is regarding=20 | databases. The application I want to write does probably need=20 | some form of database support. It is very much material to digest=20 | and I am a very slow reader so I would like to get some advice=20 | which path that might be most successful or easiest. | >=20 | > By background is from 20 years ago when computers, even=20 | microcomputers, had a control panel and you could single step=20 | them. The program language was assembler. Have also done some=20 | Basic and also in nearer time some small tasks in Visual Basic. | >=20 | > Now, I have come to like the MySQL concept although I am not=20 | attached to it (yet). Now I'm sure my questions seem=20 | unenlightened and they are but that is what this list is about so=20 | here they are. | >=20 | > 1. It seems that I can do database access two ways, through the=20 | DB-API spec v2.0 or through ODBC (which I understand is also=20 | support in Linux). Is this a correct understanding? |=20 | YES | >=20 | > 2. If this is so, what way would be the best choice and why? | >=20 | ODBC gives you easy portability between SQL servers. It also=20 | allows non-Python applications access to the database. If you=20 | have any of these (e.g. SAS, Excel, Access) you will wind up=20 | doing the ODBC anyway. |=20 | The DB-API will give slightly better performance. I normally use = ODBC. |=20 | > 3. I need to be able to create tables from the program. But I=20 | have not found any way to do it. How to do this? |=20 | SQL create table commands. Just pass them to the database using=20 | your interface using ODBC or whatever. | >=20 | > 4. Does one run SQL to access tables from Python. If so, how is=20 | this done? If not, what does one do instead? Running through the=20 | API? But then, what does one do when one want to access the=20 | database(s) when the "specified" ways are inadequate? |=20 | For instance: | =09 | DB.shared_conn=3DODBC.Windows.connect('shared',clear_auto_commit=3D0) | cursor =3D DB.shared_conn.cursor() | # Start with first Database found | cursor.execute("SHOW DATABASES") | DB.ds.fromCursor(cursor) |=20 | This gets a list of available databases into the DB.ds object. |=20 | >=20 | > H=E4lsningar / Regards (\_/) )) | > Danny Kohn Tel: +46 (0)708 140 300 =3D('.')=3D// = Miau! | > Systematik Consulting AB ICQ: 1328817 ( ~~~ )/ = Rrrrrui! | > http://www.systematik.se HAM: SM0NBJ `w---w=B4 | >=20 | > _______________________________________________ | > Tutor maillist - Tutor@python.org | > http://mail.python.org/mailman/listinfo/tutor |=20 | --=20 | Lloyd Kvam | Venix Corp. | 1 Court Street, Suite 378 | Lebanon, NH 03766-1358 |=20 | voice: 603-443-6155 | fax: 801-459-9582 |=20 | _______________________________________________ | Tutor maillist - Tutor@python.org | http://mail.python.org/mailman/listinfo/tutor |=20 From tescoil@irtc.net Fri Sep 14 00:44:15 2001 From: tescoil@irtc.net (Tesla Coil) Date: Thu, 13 Sep 2001 18:44:15 -0500 Subject: [Tutor] [0.75 OT] Congress Mulls Stiff Crypto Laws Message-ID: <3BA144CF.32DEC432@irtc.net> Congress Mulls Stiff Crypto Laws. http://www.wired.com/news/politics/0,1283,46816,00.html Wonder if I've written some soon to be *Illegal* Python: http://www.lowerstandard.com/python/uselesspython1.html Which is much less secure than this standard equipment: http://www.python.org/doc/current/lib/module-rotor.html I'd like to say the US government wouldn't consider these antique methods as qualifying, but... http://www.zdnet.com/zdnn/stories/comment/0,5859,2800985,00.html From dsh8290@rit.edu Fri Sep 14 01:50:48 2001 From: dsh8290@rit.edu (dman) Date: Thu, 13 Sep 2001 20:50:48 -0400 Subject: [Tutor] doubts with socket asychronous doc.., In-Reply-To: <000901c13c11$a30ccc00$6501a8c0@ncoretech.com> References: <000001c13b8f$4ca41b70$6501a8c0@ncoretech.com> <000901c13c11$a30ccc00$6501a8c0@ncoretech.com> Message-ID: <20010913205048.B2565@hudson> I haven't done much socket work, and haven't looked at asyncore at all, but I'll try and add some help, if I can. On Thu, Sep 13, 2001 at 10:34:57AM +0530, Ajaya Babu wrote: | | Hi my earliar message not seems to catch up any one eye so I am re posting | this. Please help me regarding this socket module. | | Thanks and Regards, | Ajaya | | Hi, | | I've some dbouts of using asyncore module for asychronous socket service | clients and servers. | server...,(Assuming that handle_read) will be called asynchronously when | data arives to that port. ... | but Documentation is telling me it is wraper around the select() fuction. | Generally select() function need to be polled as my understanding. It just I would imagine that you need to poll the receiving side of the socket if it is asynchronous. Being asynchronous means that if there is no data ready, then you can go do something else. I think that you would need to check for data when you are ready. I don't think the socket would notify you that data is ready, but I really don't know. Check the docs and play with the code a bit. Try some things. Use print liberally to see what is going on at various points. You can use 'telnet' (if you are on Unix anyways) to interact with the socket. This means you can start programming the server side and use telnet to test it. HTH, -D From cerulean_rodent@yahoo.co.uk Fri Sep 14 13:00:43 2001 From: cerulean_rodent@yahoo.co.uk (Cerulean Rodent) Date: Fri, 14 Sep 2001 16:00:43 +0400 (MSD) Subject: [Tutor] adding users from a script In-Reply-To: Message-ID: So here we go. Thanks to everyone for the tips - I'm posting the functional version of the script I was working at. It might look pretty ugly at times - but it's the first thing halfway resembling a programme that I've written, so maybe all hope is not lost... #!/usr/bin/python import os import re import whrandom rnd = whrandom.whrandom() validfirst = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789" # l, 0, 1 & o omitted so as not to confuse the (l)users pwlen = 8 pw = "" idx = 0 while idx < pwlen: pw = pw + rnd.choice(validfirst) idx = idx + 1 encr = os.popen('mkpasswd ' + pw + ' dread', 'r') z = re.sub(r'\n','',encr.read()) nomme = raw_input("\nPrint your desired username:\n>>") if nomme != '': os.system('useradd -p ' + z + ' -s /bin/false' + ' ' + '-G mail' + ' ' + nomme) else: print "\nYou must enter a valid username!" logfile = open('passlog', 'a') logfile.write(nomme + "\t" + pw + "\n") logfile.close Scary, huh? The gurus must be grinding their teeth in horror wishing to orally decapitate yours truly... newbies are a plague, and something must be done to us - since murder is illegal, one has to think of something else... PM XXIII ----------------------------------------------------- " The stars go waltzing out in blue and red, And arbitrary blackness gallops in: I shut my eyes and all the world drops dead. " --Sylvia Plath ----------------------------------------------------- From wilson@visi.com Fri Sep 14 18:06:43 2001 From: wilson@visi.com (Timothy Wilson) Date: Fri, 14 Sep 2001 12:06:43 -0500 (CDT) Subject: [Tutor] unit testing Message-ID: Hi everyone, I'd like to introduce the concept of unit testing to my beginning progamming students as early in the year as possible. I think they'll be motivated to learn it because our first project was to write a little leap year calculator. They spent a lot of time entering the same years over and over again while testing their program logic. I don't think they're quite ready for PyUnit. Does anyone have any useful resources or hints about doing basic unit testing? -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From shalehperry@home.com Fri Sep 14 18:49:37 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Fri, 14 Sep 2001 10:49:37 -0700 (PDT) Subject: [Tutor] unit testing In-Reply-To: Message-ID: On 14-Sep-2001 Timothy Wilson wrote: > Hi everyone, > > I'd like to introduce the concept of unit testing to my beginning progamming > students as early in the year as possible. I think they'll be motivated to > learn it because our first project was to write a little leap year > calculator. They spent a lot of time entering the same years over and over > again while testing their program logic. > > I don't think they're quite ready for PyUnit. Does anyone have any useful > resources or hints about doing basic unit testing? > Unit testing at its simplest is ensuring that each function acts sanely. So you end up writing things like: value = is_leap('1999') if value != false: print "is_leap failure on parameter 1999" i.e. pass it a value you know the answer for. Now this is a silly case you would really like to make sure they got things like every 400 years or not when the moon is blue. In other words pick places where the algorithm could have been broken. This is not easy for beginners and whether they use pyunit or not it will still be a task for them to learn. What my profs told us was pass values to test every if, else and while. In a language like python what I typically do is write my functions then start the interpreter and load my code as a module and run the functions dynamically. This has spoiled me to no end and makes writing C painful now. From urnerk@qwest.net Fri Sep 14 19:15:59 2001 From: urnerk@qwest.net (Kirby Urner) Date: Fri, 14 Sep 2001 11:15:59 -0700 Subject: [Tutor] unit testing In-Reply-To: References: Message-ID: <4.2.0.58.20010914110934.00b77100@pop3.norton.antivirus> > >In a language like python what I typically do is write my functions then start >the interpreter and load my code as a module and run the functions >dynamically. > This has spoiled me to no end and makes writing C painful now. Yes, by all means take full advantage of the shell. Sometimes beginners (including "beginners" experienced in languages without much of a shell) waste a lot of time prompting themselves for input using raw_input loops, the purpose of which is simply to pass values back to functions in the context of running a script as a program. It's much simpler to just test these functions interactively in shell mode. Another strategy is to put test code in the if __name__ == "__main__": test1 test2 test3 section so that check routines get run if the module is run as a program, vs. imported. This can be useful for informing the reader what the functions are supposed to do, i.e. error tests are also function definitions (provide documentation). Kirby From bsass@freenet.edmonton.ab.ca Fri Sep 14 21:04:19 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 14 Sep 2001 14:04:19 -0600 (MDT) Subject: [Tutor] unit testing In-Reply-To: Message-ID: On Fri, 14 Sep 2001, Sean 'Shaleh' Perry wrote: <...> > i.e. pass it a value you know the answer for. Now this is a silly case you > would really like to make sure they got things like every 400 years or not when > the moon is blue. In other words pick places where the algorithm could have > been broken. This is not easy for beginners and whether they use pyunit or not > it will still be a task for them to learn. What my profs told us was pass > values to test every if, else and while. To expand on what Sean wrote... What you want to test are the so-called `boundry conditions', where the behaviour of the algorithm changes. i.e., if you have a block of code that accepts a range of values, say min to max, you want to test it at: min-1, min, max, and max +1. > In a language like python what I typically do is write my functions then start > the interpreter and load my code as a module and run the functions dynamically. > This has spoiled me to no end and makes writing C painful now. ditto... I think this is where the doctest module comes into play. - Bruce From dyoo@hkn.eecs.berkeley.edu Sat Sep 15 00:04:00 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 14 Sep 2001 16:04:00 -0700 (PDT) Subject: [Tutor] unit testing In-Reply-To: Message-ID: On Fri, 14 Sep 2001, Timothy Wilson wrote: > I'd like to introduce the concept of unit testing to my beginning > progamming students as early in the year as possible. I think they'll > be motivated to learn it because our first project was to write a > little leap year calculator. They spent a lot of time entering the > same years over and over again while testing their program logic. > > I don't think they're quite ready for PyUnit. Does anyone have any > useful resources or hints about doing basic unit testing? One "obvious" tip: if your students are testing a boolean function, then they should show at least that the function has the potential of returning a false value. As a somewhat contrived example, here's a somewhat broken function: ### def isConsonant(letter): return letter != 'aeiou' ### A hasty student could point out that this works pretty well: ### >>> isConsonant('f') 1 ### but it pays to have a student show how to get isConsonant() to return 0 as well. Make sure to tell trigger-happy students to slow down and to make sure their tests make some sort of sense... *grin* Unit testing is good because it emphasises the fact that programming can be something experimental --- most of us are human, and we often need to test our own inventions to increase our confidence. But unit testing depends on the quality of the test. I think it's important to stress that the correctness of a program isn't dependent just in its "positive" results, but also in its "negative" ones. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Sat Sep 15 00:55:22 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Fri, 14 Sep 2001 16:55:22 -0700 (PDT) Subject: [Tutor] adding users from a script In-Reply-To: Message-ID: On Fri, 14 Sep 2001, Cerulean Rodent wrote: > So here we go. Thanks to everyone for the tips - I'm posting the > functional version of the script I was working at. It might look > pretty ugly at times - but it's the first thing halfway resembling a > programme that I've written, so maybe all hope is not lost... Let's take a look. > import os > import re > import whrandom > > rnd = whrandom.whrandom() I see that you're creating a random number generator called "rnd". It's actually ok to use the choice() function of whrandom directly: Python keeps a personal copy of whrandom.whrandom(), and uses it for whrandom.choice(). So: ### >>> whrandom.choice('abcdefghijklmnopquvwxyz') 'g' ### should work as well. > validfirst ="abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\ > 23456789" Looks good. > pwlen = 8 > > pw = "" > > idx = 0 > > while idx < pwlen: > pw = pw + rnd.choice(validfirst) > idx = idx + 1 I see, so this makes up a password of length 'pwlen'. You can also do this with a Python 'for' loop: ### for idx in range(pwlen): pw = pw + rnd.choice(validfirst) ### which has a similar effect to the while loop, and is a line shorter. *grin* > encr = os.popen('mkpasswd ' + pw + ' dread', 'r') > z = re.sub(r'\n','',encr.read()) Good use of regular expressions to strip off newlines from input. You can also use the replace() method of strings: ### z = encr.read().replace(r'\n', '') ### if the pattern is simple enough. Another nice string method, strip(), will remove leading and trailing whitespace from a string: ### z = encr.read().strip() ### > nomme = raw_input("\nPrint your desired username:\n>>") > > if nomme != '': > os.system('useradd -p ' + z + ' -s /bin/false' + ' ' + '-G mail' + ' ' + nomme) > else: > print "\nYou must enter a valid username!" If the user doesn't enter a vaild username, you should probably continue asking them for a good username until they give one to you. At the moment, your program gives a small wrist slap, but then continues on. > logfile = open('passlog', 'a') > > logfile.write(nomme + "\t" + pw + "\n") > > logfile.close Ah; use: ### logfile.close() ### instead --- In Python, functions don't fire off without the parentheses, even if they don't take any arguments. There's a reason why it's this way, and you'll see it when you learn about "callback" functions and functional programming in the future. > Scary, huh? The gurus must be grinding their teeth in horror wishing > to orally decapitate yours truly... newbies are a plague, and Not so! The program works, and it makes sense. Newbies are newcomers, and that's where all of us started from. We're here to make Python fun, not fearful. And don't worry about upsetting us --- we have tough skin. *grin* Thanks for sharing your program with us! From ignacio@openservices.net Sat Sep 15 01:19:46 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 14 Sep 2001 20:19:46 -0400 (EDT) Subject: [Tutor] adding users from a script In-Reply-To: Message-ID: On Fri, 14 Sep 2001, Danny Yoo wrote: > On Fri, 14 Sep 2001, Cerulean Rodent wrote: > > > pwlen = 8 > > > > pw = "" > > > > idx = 0 > > > > while idx < pwlen: > > pw = pw + rnd.choice(validfirst) > > idx = idx + 1 > > > I see, so this makes up a password of length 'pwlen'. You can also do > this with a Python 'for' loop: > > ### > for idx in range(pwlen): > pw = pw + rnd.choice(validfirst) > ### > > which has a similar effect to the while loop, and is a line shorter. > *grin* Or if you want to be even _more_ clever: ;) --- pw=''.join(map(rnd.choice, [validfirst] * pwdlen)) --- -- Ignacio Vazquez-Abrams From gp@familiehaase.de Sat Sep 15 01:59:50 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sat, 15 Sep 2001 02:59:50 +0200 Subject: [Tutor] where is CPAN for python? Message-ID: <3BA2C426.15558.1662C8C2@localhost> Hi, i come from perl and want to do some stuff with python. Now i realize that i'm missing some modules. Where do i get these additional modules from? I found a link at python.org to parnassus, but the site seems to be down? Is there s.th. lke CPAN for perl which is mirrored arund the world? Gerrit -- =^..^= From ignacio@openservices.net Sat Sep 15 02:10:07 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 14 Sep 2001 21:10:07 -0400 (EDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2C426.15558.1662C8C2@localhost> Message-ID: On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > i come from perl and want to do some stuff with python. > Now i realize that i'm missing some modules. > Where do i get these additional modules from? Use Google to find them. > I found a link at python.org to parnassus, > but the site seems to be down? The Vaults are down? Aw nuts... > Is there s.th. lke CPAN for perl which is mirrored > arund the world? No(t yet). -- Ignacio Vazquez-Abrams From ak@silmarill.org Sat Sep 15 02:10:33 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Fri, 14 Sep 2001 21:10:33 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2C426.15558.1662C8C2@localhost> References: <3BA2C426.15558.1662C8C2@localhost> Message-ID: <20010914211032.A10572@sill.silmarill.org> On Sat, Sep 15, 2001 at 02:59:50AM +0200, Gerrit P. Haase wrote: > Hi, > > i come from perl and want to do some stuff with python. > Now i realize that i'm missing some modules. > Where do i get these additional modules from? > I found a link at python.org to parnassus, > but the site seems to be down? Parnassus is the closest thing to CPAN. It works for me right now. What module (or modules) do you need, exactly? > > Is there s.th. lke CPAN for perl which is mirrored > arund the world? > > Gerrit > > > -- > =^..^= > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From gp@familiehaase.de Sat Sep 15 04:01:13 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sat, 15 Sep 2001 05:01:13 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010914211032.A10572@sill.silmarill.org> References: <3BA2C426.15558.1662C8C2@localhost> Message-ID: <3BA2E099.25304.16D1E786@localhost> Andrei Kulakov schrieb am 2001-09-14, 21:10: >On Sat, Sep 15, 2001 at 02:59:50AM +0200, Gerrit P. Haase wrote: >> Hi, >> >> i come from perl and want to do some stuff with python. >> Now i realize that i'm missing some modules. >> Where do i get these additional modules from? >> I found a link at python.org to parnassus, >> but the site seems to be down? > >Parnassus is the closest thing to CPAN. It works for me right now. > >What module (or modules) do you need, exactly? That script says: import resource besides other things, but if i delete it it works (at least script.py --help works). Gerrit -- =^..^= From ak@silmarill.org Sat Sep 15 04:08:11 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Fri, 14 Sep 2001 23:08:11 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2E099.25304.16D1E786@localhost> References: <3BA2C426.15558.1662C8C2@localhost> <3BA2E099.25304.16D1E786@localhost> Message-ID: <20010914230811.A10988@sill.silmarill.org> On Sat, Sep 15, 2001 at 05:01:13AM +0200, Gerrit P. Haase wrote: > Andrei Kulakov schrieb am 2001-09-14, 21:10: > > >On Sat, Sep 15, 2001 at 02:59:50AM +0200, Gerrit P. Haase wrote: > >> Hi, > >> > >> i come from perl and want to do some stuff with python. > >> Now i realize that i'm missing some modules. > >> Where do i get these additional modules from? > >> I found a link at python.org to parnassus, > >> but the site seems to be down? > > > >Parnassus is the closest thing to CPAN. It works for me right now. > > > >What module (or modules) do you need, exactly? > > That script says: > > import resource > > besides other things, but if i delete it it works (at least > script.py --help works). > > Gerrit This sounds like whoever made the script simply forgot to include a helper module. If it was a "public" module, it'd have a more descriptive name! I'd email the author if I were you. [snip] -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From ignacio@openservices.net Sat Sep 15 04:21:46 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 14 Sep 2001 23:21:46 -0400 (EDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2E099.25304.16D1E786@localhost> Message-ID: On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > That script says: > > import resource Is this what you're looking for? http://www.python.org/doc/current/lib/module-resource.html -- Ignacio Vazquez-Abrams From dsh8290@rit.edu Sat Sep 15 04:21:04 2001 From: dsh8290@rit.edu (dman) Date: Fri, 14 Sep 2001 23:21:04 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: References: <3BA2E099.25304.16D1E786@localhost> Message-ID: <20010914232104.B3615@hudson> On Fri, Sep 14, 2001 at 11:21:46PM -0400, Ignacio Vazquez-Abrams wrote: | On Sat, 15 Sep 2001, Gerrit P. Haase wrote: | | > That script says: | > | > import resource | | Is this what you're looking for? | | http://www.python.org/doc/current/lib/module-resource.html I noticed that that module is only available on Unix, but Gerrit is mailing from Windows. If this is the "missing" module, then it means the script will only work on a Unix system. -D From gp@familiehaase.de Sat Sep 15 04:45:18 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sat, 15 Sep 2001 05:45:18 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: References: <3BA2E099.25304.16D1E786@localhost> Message-ID: <3BA2EAEE.32758.16FA4703@localhost> Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:21: >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > >> That script says: >> >> import resource > >Is this what you're looking for? > > http://www.python.org/doc/current/lib/module-resource.html Yes, I think that is it. Where is the download link;) http://www.python.org/doc/current/lib/unix.html Hmmm, seems to be part of the standard library for UNIX. Well, a core module that isn't included in my python. There is surely a good reason why it is like it is... MIST, why am I doomed with this Windo*s *&%^@ Gerrit -- =^..^= From ignacio@openservices.net Sat Sep 15 04:54:16 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 14 Sep 2001 23:54:16 -0400 (EDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010914232104.B3615@hudson> Message-ID: On Fri, 14 Sep 2001, dman wrote: > I noticed that that module is only available on Unix, but Gerrit is > mailing from Windows. If this is the "missing" module, then it means > the script will only work on a Unix system. Based on the language in his latest message, I think that you're right ;) -- Ignacio Vazquez-Abrams From ignacio@openservices.net Sat Sep 15 04:55:27 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 14 Sep 2001 23:55:27 -0400 (EDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2EAEE.32758.16FA4703@localhost> Message-ID: On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > Well, a core module that isn't included in my python. > There is surely a good reason why it is like it is... > ****, why am I doomed with this Windo*s *&%^@ What does the script do? There may be an equivalent for Windows readily available. -- Ignacio Vazquez-Abrams From gp@familiehaase.de Sat Sep 15 04:47:31 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sat, 15 Sep 2001 05:47:31 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010914232104.B3615@hudson> References: Message-ID: <3BA2EB73.11617.16FC4D37@localhost> dman schrieb am 2001-09-14, 23:21: >On Fri, Sep 14, 2001 at 11:21:46PM -0400, Ignacio Vazquez-Abrams wrote: >| On Sat, 15 Sep 2001, Gerrit P. Haase wrote: >| >| > That script says: >| > >| > import resource >| >| Is this what you're looking for? >| >| http://www.python.org/doc/current/lib/module-resource.html > >I noticed that that module is only available on Unix, but Gerrit is >mailing from Windows. If this is the "missing" module, then it means >the script will only work on a Unix system. > >-D Yes, *&%^@. Gerrit -- =^..^= From dsh8290@rit.edu Sat Sep 15 04:55:23 2001 From: dsh8290@rit.edu (dman) Date: Fri, 14 Sep 2001 23:55:23 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA2EAEE.32758.16FA4703@localhost> References: <3BA2E099.25304.16D1E786@localhost> <3BA2EAEE.32758.16FA4703@localhost> Message-ID: <20010914235523.A582@hudson> On Sat, Sep 15, 2001 at 05:45:18AM +0200, Gerrit P. Haase wrote: | Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:21: | | >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: | > | >> That script says: | >> | >> import resource | > | >Is this what you're looking for? | > | > http://www.python.org/doc/current/lib/module-resource.html | | Yes, I think that is it. | Where is the download link;) | | http://www.python.org/doc/current/lib/unix.html | Hmmm, seems to be part of the standard library for UNIX. | | Well, a core module that isn't included in my python. | There is surely a good reason why it is like it is... Yeah, getrlimit() and setrlimit() are Unix system calls. They are prototyped in unistd.h which doesn't exist on windows. | MIST, why am I doomed with this Windo*s *&%^@ I hear you. For temporary relief, install cygwin. It comes with python now and that should have the Unix-only modules available (because cygwin is (to some extent) unix). FYI XFree86 and KDE are available (as precompiled binaries, no less) for cygwin. That's what I'm using at work until I get to install Debian. HTH, -D From gubitz@netcologne.de Sat Sep 15 11:17:56 2001 From: gubitz@netcologne.de (Hans Gubitz) Date: Sat, 15 Sep 2001 12:17:56 +0200 Subject: [Tutor] uid Message-ID: <20010915121756.A5517@redwitz79.de> I want to cp a file and extract it to different users. I can do this as root, but I want extract to be done with the uid of the user. import os, pwd users = ['usera','userb'] def copy(user): list = pwd.getpwnam(user) #uid = list[2] home = list[5] os.chdir(home) os.system('cp /tmp/file.tgz .') os.system('tar -xzf file.tgz') for u in info_1: copy(u) ?????? -- Hans Gubitz From lumbricus@gmx.net Sat Sep 15 13:09:15 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Sat, 15 Sep 2001 14:09:15 +0200 Subject: [Tutor] uid In-Reply-To: <20010915121756.A5517@redwitz79.de>; from gubitz@netcologne.de on Sat, Sep 15, 2001 at 12:17:56PM +0200 References: <20010915121756.A5517@redwitz79.de> Message-ID: <20010915140915.A15664@ID-96242.user.dfncis.de> On Sat, Sep 15, 2001 at 12:17:56PM +0200, Hans Gubitz wrote: > I want to cp a file and extract it to different users. I can do this > as root, but I want extract to be done with the uid of the user. > > import os, pwd > users = ['usera','userb'] > > def copy(user): > list = pwd.getpwnam(user) > #uid = list[2] > home = list[5] > os.chdir(home) > os.system('cp /tmp/file.tgz .') > os.system('tar -xzf file.tgz') > > for u in info_1: > copy(u) > > > ?????? os.suid() > -- > Hans Gubitz > HTH und Gruss J"o! :-) -- The shortest distance between any two puns is a straight line. From rick@niof.net Sat Sep 15 15:58:41 2001 From: rick@niof.net (Rick Pasotto) Date: Sat, 15 Sep 2001 10:58:41 -0400 Subject: [Tutor] uid In-Reply-To: <20010915140915.A15664@ID-96242.user.dfncis.de> References: <20010915121756.A5517@redwitz79.de> <20010915140915.A15664@ID-96242.user.dfncis.de> Message-ID: <20010915105841.A17572@tc.niof.net> On Sat, Sep 15, 2001 at 02:09:15PM +0200, Joerg Woelke wrote: > On Sat, Sep 15, 2001 at 12:17:56PM +0200, Hans Gubitz wrote: > > I want to cp a file and extract it to different users. I can do this > > as root, but I want extract to be done with the uid of the user. > > > > import os, pwd > > users = ['usera','userb'] > > > > def copy(user): > > list = pwd.getpwnam(user) > > #uid = list[2] > > home = list[5] > > os.chdir(home) > > os.system('cp /tmp/file.tgz .') > > os.system('tar -xzf file.tgz') > > > > for u in info_1: > > copy(u) > > > > ?????? > > os.suid() Did you *try* that? It doesn't exist on my system. 'suid' -- meaning 'set user id' -- is not at all what he wants. He simply needs to set the owner of the file so os.chown(user) will do what he wants. -- If man were perfect, if he were infallible, society would present a very different kind of harmony from that which we may actually expect it to offer us. Our idea of harmony is not Fourier's. It does not exclude the existence of evil; it leaves room for discord; and yet we shall recognize that harmony nonetheless exists, provided that discord serves to prepare the way and to lead us back to harmony. -- Frédéric Bastiat (1801-1850) Rick Pasotto rickp@telocity.com http://www.niof.net From lumbricus@gmx.net Sat Sep 15 18:21:14 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Sat, 15 Sep 2001 19:21:14 +0200 Subject: [Tutor] uid In-Reply-To: <20010915105841.A17572@tc.niof.net>; from rick@niof.net on Sat, Sep 15, 2001 at 10:58:41AM -0400 References: <20010915121756.A5517@redwitz79.de> <20010915140915.A15664@ID-96242.user.dfncis.de> <20010915105841.A17572@tc.niof.net> Message-ID: <20010915192114.A16255@ID-96242.user.dfncis.de> On Sat, Sep 15, 2001 at 10:58:41AM -0400, Rick Pasotto wrote: > On Sat, Sep 15, 2001 at 02:09:15PM +0200, Joerg Woelke wrote: > > On Sat, Sep 15, 2001 at 12:17:56PM +0200, Hans Gubitz wrote: > > > I want to cp a file and extract it to different users. I can do this > > > as root, but I want extract to be done with the uid of the user. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > > > os.suid() > > Did you *try* that? It doesn't exist on my system. Aeh sorry - os.setuid() *duck* > > 'suid' -- meaning 'set user id' -- is not at all what he wants. > > He simply needs to set the owner of the file so > > os.chown(user) > > will do what he wants. > Then I misunderstood the marked sentence. Greets J"o! -- It would be illogical to assume that all conditions remain stable. -- Spock, "The Enterprise" Incident", stardate 5027.3 From printers@sendme.cz Sat Sep 15 21:45:18 2001 From: printers@sendme.cz (A) Date: Sat, 15 Sep 2001 22:45:18 +0200 Subject: [Tutor] SMTPLIB module - how to add subject ? Message-ID: <3BA3D9FE.30092.76C3D5@localhost> Hi, I tried 11.11.2 SMTP Example from Python docs. Does anyone know how I can add subject to an email send by this example? Thank you very much for help Ladislav From kalle@gnupung.net Sat Sep 15 22:03:38 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sat, 15 Sep 2001 23:03:38 +0200 Subject: [Tutor] SMTPLIB module - how to add subject ? In-Reply-To: <3BA3D9FE.30092.76C3D5@localhost> References: <3BA3D9FE.30092.76C3D5@localhost> Message-ID: <20010915230338.A27615@sandrew.lysator.liu.se> [A] > Hi, > I tried > 11.11.2 SMTP Example from Python docs. > Does anyone know how I can add subject to an email send by this example? Something like msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, string.join(toaddrs, ", "), subject)) might work. Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From sheila@spamcop.net Sat Sep 15 22:05:40 2001 From: sheila@spamcop.net (Sheila King) Date: Sat, 15 Sep 2001 14:05:40 -0700 Subject: [Tutor] SMTPLIB module - how to add subject ? In-Reply-To: <3BA3D9FE.30092.76C3D5@localhost> References: <3BA3D9FE.30092.76C3D5@localhost> Message-ID: <5FEF7E62AE5@kserver.org> On Sat, 15 Sep 2001 22:45:18 +0200, "A" wrote about [Tutor] SMTPLIB module - how to add subject ?: :Hi, :I tried :11.11.2 SMTP Example from Python docs. :Does anyone know how I can add subject to an email send by this example? :Thank you very much for help :Ladislav I've pasted the example below. Actually, I really dislike this example. They are using "\r\n" as a character for newlines. Whose idea was that??? It should be just "\n" Below this sample code I've pasted some suggested mods: import smtplib import string def prompt(prompt): return raw_input(prompt).strip() fromaddr = prompt("From: ") toaddrs = prompt("To: ").split() print "Enter message, end with ^D:" # Add the From: and To: headers at the start! msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, string.join(toaddrs, ", "))) while 1: try: line = raw_input() except EOFError: break if not line: break msg = msg + line print "Message length is " + `len(msg)` server = smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() Suggested mods: Add a line that prompts for the subject: subj = prompt("Subject: ") Then change this line: msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, string.join(toaddrs, ", "))) To something like this: msg = ("From: %s\r\nTo: %s\r\nSubject:%s\r\n\r\n" % (fromaddr, string.join(toaddrs, ", "), subj)) Caution! untested, but should work. I still don't like the "\r\n" in this example. Bad. :( -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dsh8290@rit.edu Sun Sep 16 01:32:41 2001 From: dsh8290@rit.edu (dman) Date: Sat, 15 Sep 2001 20:32:41 -0400 Subject: [Tutor] SMTPLIB module - how to add subject ? In-Reply-To: <5FEF7E62AE5@kserver.org> References: <3BA3D9FE.30092.76C3D5@localhost> <5FEF7E62AE5@kserver.org> Message-ID: <20010915203241.B2641@hudson> On Sat, Sep 15, 2001 at 02:05:40PM -0700, Sheila King wrote: | On Sat, 15 Sep 2001 22:45:18 +0200, "A" wrote | about [Tutor] SMTPLIB module - how to add subject ?: | | :Hi, | :I tried | :11.11.2 SMTP Example from Python docs. | :Does anyone know how I can add subject to an email send by this example? | :Thank you very much for help | :Ladislav | | I've pasted the example below. Actually, I really dislike this example. | They are using | "\r\n" | as a character for newlines. Whose idea was that??? | It should be just | "\n" Well, in RFC2821 the SMTP protocol states that \r\n is used as the line delimiter. (RFC821 was the original SMTP definition but has been superceded by RFC2821) However, the Subject: of a message is part of the message itself which is defined by RFC822, but I haven't read that RFC. | I still don't like the "\r\n" in this example. Bad. :( See above -- the RFC actually states that being lenient and allowing \n as a line separator (mainly for Unix servers) is highly un-recommended (if I can make up that word). -D From GJuliusCaesar@aol.com Sun Sep 16 01:51:23 2001 From: GJuliusCaesar@aol.com (GJuliusCaesar@aol.com) Date: Sat, 15 Sep 2001 20:51:23 EDT Subject: [Tutor] trying to Learn. Need help. Message-ID: <157.108039c.28d5518b@aol.com> --part1_157.108039c.28d5518b_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hey, I got a book "SAMS TEACH YOURSELF PYTHON" Written by Ivan Van Laningham, and the first excercise for writting a program is the "Hello World" program. I created the simple program and when I try to run it ((using Windows 98)) the DOS box pops up but then is disappears really quick not allowing me to see the program I created. When the program ends I know the DOS box disappears but I want the DOS box to stay so I can see whats happening. how can I do this? ((PS, this is a great book. Thanks Ivan Van Liningham)) --part1_157.108039c.28d5518b_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hey, I got a book "SAMS TEACH YOURSELF PYTHON" Written by Ivan Van Laningham, and the first excercise for writting a program is the "Hello World" program.  I created the simple program and when I try to run it ((using Windows 98))  the DOS box pops up but then is disappears really quick not allowing me to see the program I created.  When the program ends I know the DOS box disappears but I want the DOS box to stay so I can see whats happening.  how can I do this?   ((PS, this is a great book.  Thanks Ivan Van Liningham)) --part1_157.108039c.28d5518b_boundary-- From gp@familiehaase.de Sun Sep 16 02:03:49 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sun, 16 Sep 2001 03:03:49 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: References: <3BA2EAEE.32758.16FA4703@localhost> Message-ID: <3BA41695.11986.1B8CC8E8@localhost> Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:55: >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > >> Well, a core module that isn't included in my python. >> There is surely a good reason why it is like it is... >> ****, why am I doomed with this Windo*s *&%^@ > >What does the script do? There may be an equivalent for Windows readily >available. It is from gnu lilypond: ======================== NAME ly2dvi - manual page for ly2dvi 1.4.7 SYNOPSIS ly2dvi [OPTION]... FILE DESCRIPTION Generate .dvi with LaTeX for LilyPond OPTIONS [...] GNU LilyPond 1.4.7 September 2001 1 Gerrit -- =^..^= From wolf19197@hotmail.com Sat Sep 15 16:21:57 2001 From: wolf19197@hotmail.com (Cameron Stoner) Date: Sat, 15 Sep 2001 10:21:57 -0500 Subject: [Tutor] help Message-ID: Dear Python people, What is wrong with this code? When I ran this in the IDLE it brought up an unhashable type error. I don’t really understand why print dict[sep_letter] is a problem. Would you tell me what would fix it please or what the flaw in the logic is. Thanks Cameron import string y = raw_input('prompt:') while y is not '': sep_letter = (string.split(y[0][-1]))### the ""0"" after the ""y"" is used to seperated the ### first letter of the message from the rest ### need way to split and move to anther variable while sep_letter is not '': dict = {'A':'1','B':'2','C':'3','D':'4','E':'5','F':'6','G':'7','H':'8','I':'9', 'J':'10','K':'11','L':'12','M':'13','N':'14','O':'15','P':'16', 'Q':'17','R':'18','S':'19','T':'20','U':'21','V':'22','W':'23','X': '24','Y':'24','Z':'25','':'','.':'~','?':'`'} print dict[sep_letter] _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp From gp@familiehaase.de Sun Sep 16 02:10:08 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sun, 16 Sep 2001 03:10:08 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010914235523.A582@hudson> References: <3BA2EAEE.32758.16FA4703@localhost> Message-ID: <3BA41810.7632.1B929093@localhost> dman schrieb am 2001-09-14, 23:55: [...] >| ..., why am I doomed with this Windo*s *&%^@ > >I hear you. For temporary relief, install cygwin. It comes with I use cygwin + cygwin-python, but the maintainer seems to have not the time to build python with this extension:( Gerrit -- =^..^= From tbrauch@mindless.com Sun Sep 16 02:08:20 2001 From: tbrauch@mindless.com (Timothy M. Brauch) Date: Sat, 15 Sep 2001 21:08:20 -0400 Subject: [Tutor] trying to Learn. Need help. References: <157.108039c.28d5518b@aol.com> Message-ID: <3BA3FB84.917D3D0D@mindless.com> GJuliusCaesar@aol.com wrote: > > Hey, I got a book "SAMS TEACH YOURSELF PYTHON" Written by Ivan Van > Laningham, and the first excercise for writting a program is the > "Hello World" program. I created the simple program and when I try to > run it ((using Windows 98)) the DOS box pops up but then is > disappears really quick not allowing me to see the program I created. > When the program ends I know the DOS box disappears but I want the > DOS box to stay so I can see whats happening. how can I do this? > ((PS, this is a great book. Thanks Ivan Van Liningham)) Quick solution, add something like dummy=raw_input('Press enter to end this program.') at the end of your code. - Tim From gp@familiehaase.de Sun Sep 16 02:12:09 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sun, 16 Sep 2001 03:12:09 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: References: <3BA2EAEE.32758.16FA4703@localhost> Message-ID: <3BA41889.30116.1B946CB0@localhost> Grimmtooth schrieb am 2001-09-15, 8:25: >You might try the version of Python that comes with CygWin, a Unix API >interface for Windows. I believe that going to Redhat.com will get you >there, but either way a Google search will turn it up in the first 3 or 4 >links. I am on cygwin. But it is not include in cygwin python. I have contacted the maintaner, he promised to take a look at this issue... Best would be to build it local. Gerrit -- =^..^= From kalle@gnupung.net Sun Sep 16 02:16:52 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sun, 16 Sep 2001 03:16:52 +0200 Subject: [Tutor] help In-Reply-To: References: Message-ID: <20010916031652.C27615@sandrew.lysator.liu.se> [Cameron Stoner] > What is wrong with this code? When I ran this in the IDLE it brought up an > unhashable type error. To be used as keys in dictionaries, objects must be hashable. This is a sort of difficult concept to explain and it's past 3 AM here in Sweden, so I'll just leave that to Danny Yoo... Anyway, python lists are *not* hashable. > import string > y = raw_input('prompt:') > while y is not '': > sep_letter = (string.split(y[0][-1])) Try a print sep_letter here, and you'll see what's wrong. > while sep_letter is not '': [snip] Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From rob@jam.rr.com Sun Sep 16 02:21:21 2001 From: rob@jam.rr.com (Rob) Date: Sat, 15 Sep 2001 20:21:21 -0500 Subject: [Tutor] where is CPAN for python? References: <3BA2C426.15558.1662C8C2@localhost> <20010914211032.A10572@sill.silmarill.org> Message-ID: <3BA3FE91.C4A52245@jam.rr.com> Andrei Kulakov wrote: > > On Sat, Sep 15, 2001 at 02:59:50AM +0200, Gerrit P. Haase wrote: > > Hi, > > > > i come from perl and want to do some stuff with python. > > Now i realize that i'm missing some modules. > > Where do i get these additional modules from? > > I found a link at python.org to parnassus, > > but the site seems to be down? > > Parnassus is the closest thing to CPAN. It works for me right now. > > What module (or modules) do you need, exactly? > > > > > Is there s.th. lke CPAN for perl which is mirrored > > arund the world? > > > > Gerrit > > There's also the Python Cookbook (http://aspn.activestate.com/ASPN/Python/Cookbook/), and Useless Python, but a google.com search tends to find any modules I need that exist out there in the void. Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From urnerk@qwest.net Sun Sep 16 02:30:03 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sat, 15 Sep 2001 18:30:03 -0700 Subject: [Tutor] trying to Learn. Need help. In-Reply-To: <3BA3FB84.917D3D0D@mindless.com> References: <157.108039c.28d5518b@aol.com> Message-ID: <4.2.0.58.20010915182754.00bf7800@pop3.norton.antivirus> > > > run it ((using Windows 98)) the DOS box pops up but then is > > disappears really quick not allowing me to see the program I created. I hope this book introduces you to IDLE and has you develop your skills there. Using the DOS box for Python is way inferior -- except for testing specific kinds of program, e.g. involving Tkinter. Kirby PS: yes, there are other useful GUI IDEs in Windows, all superior to the DOS box. From ignacio@openservices.net Sun Sep 16 02:31:46 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 15 Sep 2001 21:31:46 -0400 (EDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA41695.11986.1B8CC8E8@localhost> Message-ID: On Sun, 16 Sep 2001, Gerrit P. Haase wrote: > Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:55: > > >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > > > >> Well, a core module that isn't included in my python. > >> There is surely a good reason why it is like it is... > >> ****, why am I doomed with this Windo*s *&%^@ > > > >What does the script do? There may be an equivalent for Windows readily > >available. > > It is from gnu lilypond: Well I'll be! A GNU package written in Python. It's official folks, I have now seen everything. I downloaded version 1.5.9 and it seems to no longer have a dependency on the resource module. Give it a try. -- Ignacio Vazquez-Abrams From dyoo@hkn.eecs.berkeley.edu Sun Sep 16 02:54:45 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sat, 15 Sep 2001 18:54:45 -0700 (PDT) Subject: [Tutor] help In-Reply-To: Message-ID: On Sat, 15 Sep 2001, Cameron Stoner wrote: > What is wrong with this code? When I ran this in the IDLE it brought > up an unhashable type error. I don't really understand why print > dict[sep_letter] is a problem. Would you tell me what would fix it > please or what the flaw in the logic is. Let's take a look: > import string > y = raw_input('prompt:') > while y is not '': > sep_letter = (string.split(y[0][-1])) If y is a string, then y[0] will be a single letter of that string, and y[0][-1] --- that is, the last letter of y[0] --- will be that same letter: ### >>> name = 'cameron' >>> name[0] 'c' >>> name[0][-1] 'c' >>> name[0][-1][-1] 'c' ### It will be simpler to write: sep_letter = string.split(y[0]) But even then, I'm a little confused, since splitting a single letter is probably not what you were planning. This might be the cause for the "unhashable type error" that you're running into. Hmmm... Do you mean: ### sep_letter = string.split(y)[0][-1] ### instead? This is more effective, since this says: "Split the string into a list of smaller strings. Pull out the first of those strings, and grab at the last character of it." > while sep_letter is not '': > dict = > {'A':'1','B':'2','C':'3','D':'4','E':'5','F':'6','G':'7','H':'8','I':'9', > > 'J':'10','K':'11','L':'12','M':'13','N':'14','O':'15','P':'16', > > 'Q':'17','R':'18','S':'19','T':'20','U':'21','V':'22','W':'23','X': > '24','Y':'24','Z':'25','':'','.':'~','?':'`'} > print dict[sep_letter] It might be good to pull out the definition of the dictionary outside of the while loop, just to emphasise the fact that its definition is not really an important part of the looping. Also, I think there's a small bug, since both 'X' and 'Y' both map to '24'. Here's a small function that might help: ### def makeCodingDictionary(): dict = {} for i in range(26): dict[chr(ord('A') + i)] = str(i+1) dict.update({'' : '', '.' : '~', '?' : '`'}) return dict ### Try making those corrections first, and tell us if it helps. The first fix should repair the bug you were running into. Good luck! From dsh8290@rit.edu Sun Sep 16 02:46:28 2001 From: dsh8290@rit.edu (dman) Date: Sat, 15 Sep 2001 21:46:28 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA41810.7632.1B929093@localhost> References: <3BA2EAEE.32758.16FA4703@localhost> <3BA41810.7632.1B929093@localhost> Message-ID: <20010915214628.B3159@hudson> On Sun, Sep 16, 2001 at 03:10:08AM +0200, Gerrit P. Haase wrote: | dman schrieb am 2001-09-14, 23:55: | | [...] | >| ..., why am I doomed with this Windo*s *&%^@ | > | >I hear you. For temporary relief, install cygwin. It comes with | | I use cygwin + cygwin-python, but the maintainer seems to have not | the time to build python with this extension:( Hmm, could be that or maybe cygwin doesn't support setrlimit/getrlimit. Anyays, have you found XFree86 and KDE? There are prebuilt binaries for running with cygwin. kvt is much better than using a DOS box, and a free X server is cool too. -D From urnerk@qwest.net Sun Sep 16 07:03:03 2001 From: urnerk@qwest.net (Kirby Urner) Date: Sat, 15 Sep 2001 23:03:03 -0700 Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010915214628.B3159@hudson> References: <3BA41810.7632.1B929093@localhost> <3BA2EAEE.32758.16FA4703@localhost> <3BA41810.7632.1B929093@localhost> Message-ID: <4.2.0.58.20010915225813.00d16890@pop3.norton.antivirus> At 09:46 PM 9/15/2001 -0400, dman wrote: >Anyays, have you found XFree86 and KDE? There are prebuilt binaries >for running with cygwin. kvt is much better than using a DOS box, and a >free X server is cool too. > >-D I went the cygwin route on a Windows box once. But if you're going so far as to do X server, KDE and the whole ball of wax, I'd say why not just partition and go with Linux. You can still access your Windows files (including pure Python modules), and you can still boot Windows if you want (yes, there's also the Windows emulator route). Of course this may be completely irrelevant to the initial poster. I'm just sharing my own experience of finding cygwin to be rather cumbersome and not that satisfying. Easier to just add Linux as a boot option. Alternatively, there are way of installing Linux right into a Windows partition, on top of FAT32, if you're willing to take a performance hit. This too might be preferable to cygwin. Anyway, options to consider (I have no idea what CPAN is -- another warning that this may be off-topic). Kirby From dyoo@hkn.eecs.berkeley.edu Sun Sep 16 08:11:27 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Sun, 16 Sep 2001 00:11:27 -0700 (PDT) Subject: [Tutor] where is CPAN for python? In-Reply-To: <4.2.0.58.20010915225813.00d16890@pop3.norton.antivirus> Message-ID: On Sat, 15 Sep 2001, Kirby Urner wrote: > > Anyway, options to consider (I have no idea what CPAN > is -- another warning that this may be off-topic). It's not really off-topic; it's a common question that comes up from people who come from Perl to Python. CPAN is the Comprehensive Perl Archive Network: http://cpan.org and it's a distributed library of Perl modules. No illusions: at the moment, it puts the Vaults of Parnassus at http://www.vex.net/parnassus/ to shame. CPAN is mirrored all over the world, and it's very powerful. CPAN is a Good Idea, and one that Pythonistas are eager to adopt. Toward this end, people are organizing around the "Catalog" Special Interest Group (SIG): http://www.python.org/sigs/catalog-sig/ I just hope I see the fruits of their labours in a couple of years. *grin* From ak@silmarill.org Sun Sep 16 11:32:55 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Sun, 16 Sep 2001 06:32:55 -0400 Subject: [Tutor] help In-Reply-To: References: Message-ID: <20010916063254.A17429@sill.silmarill.org> On Sat, Sep 15, 2001 at 10:21:57AM -0500, Cameron Stoner wrote: > Dear Python people, > > What is wrong with this code? When I ran this in the IDLE it brought up an > unhashable type error. I don?t really understand why print dict[sep_letter] > > is a problem. Would you tell me what would fix it please or what the flaw > in the logic is. > > Thanks > Cameron You got some good answers already, and I just want to add that generally, if you run into some sort of problem, you should try putting print statements in the code to see where you went wrong. If there is an error with a variable, you should look at the code and see where this variable came from, then look at each step that could have changed that value and put prints near it to see if it did what it should have done. Please don't take this in the sense that questions aren't welcome here - even the simplest ones are, but you will often find the problem much faster than asking here if you do a little debugging first. - Andrei [snip] -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From gubitz@netcologne.de Sun Sep 16 11:45:41 2001 From: gubitz@netcologne.de (Hans Gubitz) Date: Sun, 16 Sep 2001 12:45:41 +0200 Subject: [Tutor] uid In-Reply-To: <20010915192114.A16255@ID-96242.user.dfncis.de> References: <20010915121756.A5517@redwitz79.de> <20010915140915.A15664@ID-96242.user.dfncis.de> <20010915105841.A17572@tc.niof.net> <20010915192114.A16255@ID-96242.user.dfncis.de> Message-ID: <20010916124541.A2558@redwitz79.de> On Sat, Sep 15, 2001 at 07:21:14PM +0200, Joerg Woelke wrote: > On Sat, Sep 15, 2001 at 10:58:41AM -0400, Rick Pasotto wrote: > > On Sat, Sep 15, 2001 at 02:09:15PM +0200, Joerg Woelke wrote: > > > On Sat, Sep 15, 2001 at 12:17:56PM +0200, Hans Gubitz wrote: > > > > I want to cp a file and extract it to different users. I can do this > > > > as root, but I want extract to be done with the uid of the user. > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > > > > > os.suid() > > > > Did you *try* that? It doesn't exist on my system. > > Aeh sorry - os.setuid() *duck* I will try it. > > os.chown(user) This way I would have to chown each file in the tar-File. > > Then I misunderstood the marked sentence. I think you understood it the right way. Hans Gubitz -- Hans Gubitz From dsh8290@rit.edu Sun Sep 16 13:01:05 2001 From: dsh8290@rit.edu (dman) Date: Sun, 16 Sep 2001 08:01:05 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <4.2.0.58.20010915225813.00d16890@pop3.norton.antivirus> References: <3BA41810.7632.1B929093@localhost> <3BA2EAEE.32758.16FA4703@localhost> <3BA41810.7632.1B929093@localhost> <4.2.0.58.20010915225813.00d16890@pop3.norton.antivirus> Message-ID: <20010916080105.C911@hudson> On Sat, Sep 15, 2001 at 11:03:03PM -0700, Kirby Urner wrote: | At 09:46 PM 9/15/2001 -0400, dman wrote: | | >Anyays, have you found XFree86 and KDE? There are prebuilt binaries | >for running with cygwin. kvt is much better than using a DOS box, and a | >free X server is cool too. | | I went the cygwin route on a Windows box once. But if | you're going so far as to do X server, KDE and the whole | ball of wax, I'd say why not just partition and go with | Linux. The reason is when it is your employer's machine and he wants Windows on it. Having X is not so bad since it is Free competition to the commercial X servers out there (for remote logins to Unix systems). Fortuantely for me, though, I have permission to install Debian soon :-). I agree with you that installing Linux is preferrable to cygwin for many reasons including performance and stability and completeness. Cygwin is not a complete Unix look-alike yet, but it is quite good when windows is required as the base system. | Alternatively, there are way of installing Linux right | into a Windows partition, on top of FAT32, if you're | willing to take a performance hit. This too might be I've vaguely heard of a couple distros that do this. -D From lha2@columbia.edu Sun Sep 16 15:58:24 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Sun, 16 Sep 2001 10:58:24 -0400 Subject: [Tutor] useless banner challenge (if it's okay w/ rob) Message-ID: <3BA4BE10.DD3B2350@mail.verizon.net> Back in July I had made a program to create an American flag in a small window as a Tkinter Canvas object, in order to learn and teach Tkinter canvas drawing methods etc. I had intended to add buttons so as to reconfigure the flag to its various incarnations--13 star old glory, etc. Didn't get around to it. I seem to recall Eric Raymond saying something about the strength of open source being that projects living past the threshold of a single person's time and motivation. If anyone cares to take this on, the script currently lives on http://www.lowerstandard.com/python/uselesspython7.html or more specifically http://www.lowerstandard.com/python/banner.py it would be really, really cool if they would morph into each other (perhaps animated stars moving from present location to future location) rather than simply blinking from one to the next. This is beyond my current capability. Cheers, LHA From rob@jam.rr.com Sun Sep 16 17:30:17 2001 From: rob@jam.rr.com (Rob) Date: Sun, 16 Sep 2001 11:30:17 -0500 Subject: [Tutor] useless banner challenge (if it's okay w/ rob) References: <3BA4BE10.DD3B2350@mail.verizon.net> Message-ID: <3BA4D399.6C9B2192@jam.rr.com> Lloyd Hugh Allen wrote: > > Back in July I had made a program to create an American flag in a small > window as a Tkinter Canvas object, in order to learn and teach Tkinter > canvas drawing methods etc. > > I had intended to add buttons so as to reconfigure the flag to its > various incarnations--13 star old glory, etc. Didn't get around to it. > > I seem to recall Eric Raymond saying something about the strength of > open source being that projects living past the threshold of a single > person's time and motivation. If anyone cares to take this on, the > script currently lives on > > http://www.lowerstandard.com/python/uselesspython7.html > > or more specifically > > http://www.lowerstandard.com/python/banner.py > > it would be really, really cool if they would morph into each other > (perhaps animated stars moving from present location to future location) > rather than simply blinking from one to the next. This is beyond my > current capability. > > Cheers, > LHA > Anything's fine by me. Provided the Useless server allows me ftp access later on today, I'll upload the latest material, including this new challenge. If anyone can think of a script that does anything particularly uplifting, that would be great. A script that prints the name of a random survivor of violent acts (including, but not limited to, the WTC attack), Pythonic words of peace, or anything that reminds us not to focus exclusively on the profound suffering to which we are often exposed, perhaps. If nothing else, we should remember to keep having some fun hacking Python scripts instead of plotting revenge. Just FYI, all my relatives and friends known to have been in or next to the buildings taken down this week seem to have made it out alive and intact. I'd like to extend a wish of peace to everyone out there, even to the people responsible for the aggression we've all recently witnessed. I think it's a testament to the good hearts of many people that this business hasn't turned any worse than it has. (In fact, I'm frankly amazed at some of these Mississippi country folk who have seen groups of people literally dancing in the streets in joy at the bombing. I haven't heard a single report of these questionable celebrations suffering retaliation from witnesses, and that's nothing short of miraculous here in the Deep South.) Rob -- Aw, c'mon.... You indent ANYWAY! Useless Python! http://www.lowerstandard.com/python From gp@familiehaase.de Sun Sep 16 20:45:01 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sun, 16 Sep 2001 21:45:01 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: References: <3BA41695.11986.1B8CC8E8@localhost> Message-ID: <3BA51D5D.27517.1F8F4879@localhost> Ignacio Vazquez-Abrams schrieb am 2001-09-15, 21:31: >On Sun, 16 Sep 2001, Gerrit P. Haase wrote: > >> Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:55: >> >> >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: >> > >> >> Well, a core module that isn't included in my python. >> >> There is surely a good reason why it is like it is... >> >> ****, why am I doomed with this Windo*s *&%^@ >> > >> >What does the script do? There may be an equivalent for Windows readily >> >available. >> >> It is from gnu lilypond: > >Well I'll be! A GNU package written in Python. It's official folks, I have now >seen everything. > >I downloaded version 1.5.9 and it seems to no longer have a dependency on the >resource module. Give it a try. Aha, that is good news. However, it should be no problem to build python with this extension. Usually it builds OOTB on cygwin, though the maintainer has not that much time to do an update now. But he sent a patch, so I will build it myself here this night. Gerrit -- =^..^= From gp@familiehaase.de Sun Sep 16 20:47:32 2001 From: gp@familiehaase.de (Gerrit P. Haase) Date: Sun, 16 Sep 2001 21:47:32 +0200 Subject: [Tutor] where is CPAN for python? In-Reply-To: <20010915214628.B3159@hudson> References: <3BA41810.7632.1B929093@localhost> Message-ID: <3BA51DF4.13077.1F9192F1@localhost> dman schrieb am 2001-09-15, 21:46: >On Sun, Sep 16, 2001 at 03:10:08AM +0200, Gerrit P. Haase wrote: >| dman schrieb am 2001-09-14, 23:55: >| >| [...] >| >| ..., why am I doomed with this Windo*s *&%^@ >| > >| >I hear you. For temporary relief, install cygwin. It comes with >| >| I use cygwin + cygwin-python, but the maintainer seems to have not >| the time to build python with this extension:( > >Hmm, could be that or maybe cygwin doesn't support >setrlimit/getrlimit. It is patched since december last year to support it. >Anyays, have you found XFree86 and KDE? There are prebuilt binaries >for running with cygwin. kvt is much better than using a DOS box, and >a free X server is cool too. I wonder what it so fascinating with that KDE stuff. I am on windows with full GUI for all I need, so why to use KDE? I have X installed, but I don't use it that much. Maybe it is a difference if you have real Windows (NT) or just w98. Gerrit -- =^..^= From sobesoft@yahoo.com Sun Sep 16 18:28:22 2001 From: sobesoft@yahoo.com (Dave Foderick) Date: Sun, 16 Sep 2001 13:28:22 -0400 Subject: [Tutor] Python and web Message-ID: I found out that my ISP supports Python as an option for programming my web pages. Does anyone have a sample "hello world" python script for the web? I am trying to find a sample script that I could copy up to my web site and find out if it is working. Is python interpreted, or do I need to compile and copy up to the web? Thanks. Dave sobesoft@yahoo.com www.southbeachsoftware.com _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From ignacio@openservices.net Sun Sep 16 21:33:21 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sun, 16 Sep 2001 16:33:21 -0400 (EDT) Subject: [Tutor] Python and web In-Reply-To: Message-ID: On Sun, 16 Sep 2001, Dave Foderick wrote: > Does anyone have a sample "hello world" python script for the web? #! /usr/bin/python print 'Content-type: text/html' print print 'Hello, world!' > I am trying to find a sample script that I could copy up to my web site and > find out if it is working. Is python interpreted, or do I need to compile > and copy up to the web? It's interpreted. There may be other considerations however. Does your ISP support CGIs in any directory, or just in /cgi-bin? Can it have an extension of .py, or is .cgi the only one recognized? -- Ignacio Vazquez-Abrams From alan.gauld@bt.com Sun Sep 16 23:01:02 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sun, 16 Sep 2001 23:01:02 +0100 Subject: [Tutor] adding users from a script Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF67@mbtlipnt02.btlabs.bt.co.uk> > ugly at times - but it's the first thing halfway resembling a > programme that I've written, so maybe all hope is not lost... Looks pretty good for a first useful programming effort. > # l, 0, 1 & o omitted so as not to confuse the (l)users Since you are generating the passwords thats probably good thinking. If the users were entering them it'd have the opposite effect - trying to figure why certain'valid' letters were failing... > logfile = open('passlog', 'a') > logfile.write(nomme + "\t" + pw + "\n") > logfile.close Just remember to clean up the log file from time to time - these things can grow pretty big over time. One trick is to generate a filename from the date(passlog20010916 say), thus you get a new file each day(or month) which makes finding entries easy and archiving old files trivial. Just a thought... > " The stars go waltzing out in blue and red, > And arbitrary blackness gallops in: > I shut my eyes and all the world drops dead. " > > --Sylvia Plath Nice taste in poetry :-) Alan G From dsh8290@rit.edu Mon Sep 17 01:40:27 2001 From: dsh8290@rit.edu (dman) Date: Sun, 16 Sep 2001 20:40:27 -0400 Subject: [Tutor] where is CPAN for python? In-Reply-To: <3BA51DF4.13077.1F9192F1@localhost> References: <3BA41810.7632.1B929093@localhost> <3BA51DF4.13077.1F9192F1@localhost> Message-ID: <20010916204027.H2653@hudson> On Sun, Sep 16, 2001 at 09:47:32PM +0200, Gerrit P. Haase wrote: | dman schrieb am 2001-09-15, 21:46: | | >On Sun, Sep 16, 2001 at 03:10:08AM +0200, Gerrit P. Haase wrote: | >| dman schrieb am 2001-09-14, 23:55: | >| | >| [...] | >| >| ..., why am I doomed with this Windo*s *&%^@ | >| > | >| >I hear you. For temporary relief, install cygwin. It comes with | >| | >| I use cygwin + cygwin-python, but the maintainer seems to have not | >| the time to build python with this extension:( | > | >Hmm, could be that or maybe cygwin doesn't support | >setrlimit/getrlimit. | | It is patched since december last year to support it. Oh, ok. | >Anyays, have you found XFree86 and KDE? There are prebuilt binaries | >for running with cygwin. kvt is much better than using a DOS box, and | >a free X server is cool too. | | I wonder what it so fascinating with that KDE stuff. | I am on windows with full GUI for all I need, so why to use KDE? because KDE is a much better GUI than MS Windows. (I actually prefer GNOME, but it isn't available for cygwin/xfree) | I have X installed, but I don't use it that much. | | Maybe it is a difference if you have real Windows (NT) or just w98. No, I have win2k at work but I prefer to use KDE. I got the latest gvim working with it, but couldn't do that with plain windows (I don't have MS devel tool either though). -D From brian@dorseys.org Mon Sep 17 03:35:39 2001 From: brian@dorseys.org (Brian Dorsey) Date: Sun, 16 Sep 2001 19:35:39 -0700 Subject: [Tutor] ... GNU packages in Python In-Reply-To: ; from ignacio@openservices.net on Sat, Sep 15, 2001 at 09:31:46PM -0400 References: <3BA41695.11986.1B8CC8E8@localhost> Message-ID: <20010916193539.B32002@dorseys.org> Another example which some people may recognize: GNU Mailman http://www.list.org There are probably others as well. Take care, -Brian On Sat, Sep 15, 2001 at 09:31:46PM -0400, Ignacio Vazquez-Abrams wrote: > On Sun, 16 Sep 2001, Gerrit P. Haase wrote: > > > Ignacio Vazquez-Abrams schrieb am 2001-09-14, 23:55: > > > > >On Sat, 15 Sep 2001, Gerrit P. Haase wrote: > > > > > >> Well, a core module that isn't included in my python. > > >> There is surely a good reason why it is like it is... > > >> ****, why am I doomed with this Windo*s *&%^@ > > > > > >What does the script do? There may be an equivalent for Windows readily > > >available. > > > > It is from gnu lilypond: > > Well I'll be! A GNU package written in Python. It's official folks, I have now > seen everything. > > I downloaded version 1.5.9 and it seems to no longer have a dependency on the > resource module. Give it a try. > > -- > Ignacio Vazquez-Abrams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From alan.gauld@bt.com Mon Sep 17 09:33:46 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 17 Sep 2001 09:33:46 +0100 Subject: [Tutor] unit testing Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF69@mbtlipnt02.btlabs.bt.co.uk> If using a command line/teletype interface then they can easily automate teting by relying on stdin redirection. Thus write a little test harness that reads parameters from stdin(raw_input) and then executes the program. This can be used ineractively initially but then regression testing can be done by using redirection from a simple text file: C:> python myprog.py tests interactively C:> python myprog.py < testfile.txt >results.txt You can then compare the results file with previous test runs. Its an easy concept to learn and powerful enough for production use. An interesting excercise is to compare results when they use somweone else's testfile... Of course they need to agree input order and formats. > calculator. They spent a lot of time entering the same years > over and over again while testing their program logic. The above option solves that bit. The other thing to do is *encourage* finding bugs maybe even rewarding in some way evidence of thorough testing. And of course get them to test each others code. Alan G From alan.gauld@bt.com Mon Sep 17 09:37:07 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Mon, 17 Sep 2001 09:37:07 +0100 Subject: [Tutor] unit testing Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF6A@mbtlipnt02.btlabs.bt.co.uk> > >the interpreter and load my code as a module and run the functions > >dynamically. I don't like using the interpreter for formal testing - fine for debugging. You can't repeat the tests consistently or accurately. > Sometimes beginners (including "beginners" experienced in > languages without much of a shell) waste a lot of time > prompting themselves for input using raw_input loops, > the purpose of which is simply to pass values back to > functions in the context of running a script as a program. I actually prefer this approach for formal testing because its easy to do regression testing using text files for input/output Alan G From rick@niof.net Mon Sep 17 13:46:38 2001 From: rick@niof.net (Rick Pasotto) Date: Mon, 17 Sep 2001 08:46:38 -0400 Subject: [Tutor] getting canvas window size Message-ID: <20010917084638.A11891@tc.niof.net> Why do the print statements in the following program show zero? How can I figure out the size of the frame? from Tkinter import * w = Tk() cnv = Canvas(w,bg='white',relief=SUNKEN) cnv.config(width=400,height=200) cnv.pack(side=LEFT,expand=YES,fill=BOTH) f = Frame(cnv,relief=GROOVE,borderwidth=2) for j in range(5): l = Label(f,text='label: %2d' % (j), relief=GROOVE,borderwidth=2,padx=5) l.pack(side=LEFT,expand=YES,fill=X,padx=5,pady=2) f.pack() cw = cnv.create_window(20,20,window=f,anchor=NW) print f.cget('height'),f.cget('width') print cnv.itemcget(cw,'height'), cnv.itemcget(cw,'width') w.mainloop() -- Certain nations seem particularly liable to fall prey to governmental plunder. They are those in which men, lacking faith in their own dignity and capability, would feel themselves lost if they were not governed and administered every step of the way. -- Frédéric Bastiat (1801-1850) Rick Pasotto rickp@telocity.com http://www.niof.net From danny.kohn@systematik.se Mon Sep 17 16:09:50 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Mon, 17 Sep 2001 17:09:50 +0200 Subject: [Tutor] Tuples in tuples Message-ID: Hi. Is it possible to reference tuple in tuple in one expression? Lets say I = have a tuple t =3D ((6, 7, 8, 9, 0), (1, 2, 3, 4, 5)). Can I refer to = the third element (8) in one expression or do I have to do something = like x,y=3Dt and then x[2]? H=E4lsningar / Regards (\_/) )) Danny Kohn Tel: +46 (0)708 140 300 =3D('.')=3D// Miau! Systematik Consulting AB ICQ: 1328817 ( ~~~ )/ Rrrrrui! http://www.systematik.se HAM: SM0NBJ `w---w=B4=20 From ignacio@openservices.net Mon Sep 17 16:20:59 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Mon, 17 Sep 2001 11:20:59 -0400 (EDT) Subject: [Tutor] Tuples in tuples In-Reply-To: Message-ID: On Mon, 17 Sep 2001, Danny Kohn wrote: > Is it possible to reference tuple in tuple in one expression? Lets say I have a tuple t = ((6, 7, 8, 9, 0), (1, 2, 3, 4, 5)). Can I refer to the third element (8) in one expression or do I have to do something like x,y=t and then x[2]? t[0][2] -- Ignacio Vazquez-Abrams From rick@niof.net Mon Sep 17 16:23:56 2001 From: rick@niof.net (Rick Pasotto) Date: Mon, 17 Sep 2001 11:23:56 -0400 Subject: [Tutor] Tuples in tuples In-Reply-To: References: Message-ID: <20010917112356.B32095@tc.niof.net> On Mon, Sep 17, 2001 at 05:09:50PM +0200, Danny Kohn wrote: > Hi. Is it possible to reference tuple in tuple in one expression? > Lets say I have a tuple t = ((6, 7, 8, 9, 0), (1, 2, 3, 4, 5)). Can I > refer to the third element (8) in one expression or do I have to do > something like x,y=t and then x[2]? No problem. t[0][2] -- "The whole aim of practical politics is to keep the populace alarmed -- and thus clamorous to be led to safety -- by menacing it with an endless series of hobgoblins, all of them imaginary." -- H.L. Mencken Rick Pasotto email: rickp@telocity.com web: www.niof.net From urnerk@qwest.net Mon Sep 17 17:31:02 2001 From: urnerk@qwest.net (Kirby Urner) Date: Mon, 17 Sep 2001 09:31:02 -0700 Subject: [Tutor] unit testing In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF6A@mbtlipnt02.btlabs .bt.co.uk> Message-ID: <4.2.0.58.20010917091600.00d1ba20@pop3.norton.antivirus> At 09:37 AM 9/17/2001 +0100, alan.gauld@bt.com wrote: >I actually prefer this approach for formal testing because >its easy to do regression testing using text files for >input/output > >Alan G Sure if you like. You know about the shell option but prefer this other way. I think many beginners waste time doing less formal testing using raw_input loops that would be more easily accomplished in shell mode. Once you get into formal testing, there's a utility called PyUnit that some people like. It has an optional GUI front end, and there's talk of merging that into IDLE at some point (both are Tk apps). http://www.onlamp.com/lpt/a/python/2001/03/28/pythonnews.html Kirby From jessicapolson@yahoo.com Mon Sep 17 20:28:27 2001 From: jessicapolson@yahoo.com (jessica polson) Date: Mon, 17 Sep 2001 12:28:27 -0700 (PDT) Subject: [Tutor] Unsubscribe Please Message-ID: <20010917192827.86957.qmail@web12605.mail.yahoo.com> __________________________________________________ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ From Charlie@begeistert.org Mon Sep 17 20:46:27 2001 From: Charlie@begeistert.org (Charlie Clark) Date: Mon, 17 Sep 2001 21:46:27 +0200 Subject: [Tutor] VUE In-Reply-To: Message-ID: <1000755987_PM_BeOS.Charlie@begeistert.org> >If anyone can think of a script that does anything particularly >uplifting, that would be great. A script that prints the name of a >random survivor of violent acts (including, but not limited to, the WTC >attack), Pythonic words of peace, or anything that reminds us not to >focus exclusively on the profound suffering to which we are often >exposed, perhaps. ooh victims of the VUE (violent unknown event) would make a change in this world of invisible suffering. Should be possible just need to convert the film to an appropriate streaming form. Charli From dyoo@hkn.eecs.berkeley.edu Mon Sep 17 21:41:41 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 17 Sep 2001 13:41:41 -0700 (PDT) Subject: [Tutor] Unsubscribe Please In-Reply-To: <20010917192827.86957.qmail@web12605.mail.yahoo.com> Message-ID: Hi Jessica, You can unsubscribe yourself by visiting the Tutor web site: http://mail.python.org/mailman/listinfo/tutor It's the same website that you use to subscribe --- there's a section on the bottom of the page that will allow you to "Edit Options" on your account. You should be able to unsubscribe from the form there. If you run into more problems while unsubscribing, feel free to email directly to tutor-admin@python.org. Best of wishes to you! From fleet@teachout.org Mon Sep 17 22:57:58 2001 From: fleet@teachout.org (fleet@teachout.org) Date: Mon, 17 Sep 2001 17:57:58 -0400 (EDT) Subject: [Tutor] Python and mail Message-ID: I'm using python 1.5.2 on RH 7.1. I have some files (invoices) that I create once a month. I'd like to create a script that will mail the invoices to each of my customers sort of in a "batch" mode. I can do the mailing using 'mail' manually (except I'm having a problem passing a binary logo file - but I think I can handle that). I anticipate creating a dictionary from a flat file of customer e-mails, the file associated with them, and possibly a "note" to add to the attachments. Is there a (probably better) Python way to accomplish this? I've looked through the modules and find things for retrieving mail, but nothing about sending mail. Thanks, - fleet - From sheila@thinkspot.net Mon Sep 17 23:12:11 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 17 Sep 2001 15:12:11 -0700 Subject: [Tutor] Python and mail In-Reply-To: References: Message-ID: <13DE41E0207@kserver.org> On Mon, 17 Sep 2001 17:57:58 -0400 (EDT), wrote about [Tutor] Python and mail: :Is there a (probably better) Python way to accomplish this? I've looked :through the modules and find things for retrieving mail, but nothing about :sending mail. For sending mail, you will want to use the smtplib. http://www.python.org/doc/current/lib/module-smtplib.html Here's an example of sending mail using the smtplib: http://www.faqts.com/knowledge_base/view.phtml/aid/2607/fid/380 Hope this helps to get you started. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From fleet@teachout.org Tue Sep 18 01:38:07 2001 From: fleet@teachout.org (fleet@teachout.org) Date: Mon, 17 Sep 2001 20:38:07 -0400 (EDT) Subject: [Tutor] Python and mail In-Reply-To: <13DE41E0207@kserver.org> Message-ID: Thanks, Sheila. Yes, I think this will help! It looks like I will need to forego the binary logo (thumbnail) that I have been including - but I'm not upset about that. - fleet - On Mon, 17 Sep 2001, Sheila King wrote: > On Mon, 17 Sep 2001 17:57:58 -0400 (EDT), wrote > about [Tutor] Python and mail: > > :Is there a (probably better) Python way to accomplish this? I've looked > :through the modules and find things for retrieving mail, but nothing about > :sending mail. > > For sending mail, you will want to use the smtplib. > > http://www.python.org/doc/current/lib/module-smtplib.html > > > Here's an example of sending mail using the smtplib: > > http://www.faqts.com/knowledge_base/view.phtml/aid/2607/fid/380 > > > Hope this helps to get you started. > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > From slim_bizkit2001@sbcglobal.net Tue Sep 18 00:36:22 2001 From: slim_bizkit2001@sbcglobal.net (Louie Montelongo) Date: Mon, 17 Sep 2001 18:36:22 -0500 Subject: [Tutor] (no subject) Message-ID: <000901c13fd1$901cb600$7827fea9@computer> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C13FA7.A64347C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I Use Python For School Work But I Don't Know How To Use It For Squaring = And Thngs Like That Please Help Me =20 Louie = Montelongo ------=_NextPart_000_0005_01C13FA7.A64347C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
    I Use Python For School Work But I = Don't Know How=20 To Use It For Squaring And Thngs Like That
    Please Help Me    =
         =    =20             =    =20             =    =20             =    =20 Louie Montelongo
    ------=_NextPart_000_0005_01C13FA7.A64347C0-- From urnerk@qwest.net Tue Sep 18 03:21:53 2001 From: urnerk@qwest.net (Kirby Urner) Date: Mon, 17 Sep 2001 19:21:53 -0700 Subject: [Tutor] (no subject) In-Reply-To: <000901c13fd1$901cb600$7827fea9@computer> Message-ID: <4.2.0.58.20010917191834.00bff700@pop3.norton.antivirus> At 06:36 PM 9/17/2001 -0500, Louie Montelongo wrote: >I Use Python For School Work But I Don't Know How To Use It For Squaring >And Thngs Like That >Please Help Me > Louie Montelongo Hi Louis -- check out http://www.inetarena.com/~pdx4d/ocn/numeracy0.html for some ideas about how to use the Python shell as a way-better-than-a-calculator tool to have at your elbow when studying mathematics. I pity those students who get nothing but a steady diet of TIs (most popular classroom calculator). Also: Python in Education: http://www.python.org/sigs/edu-sig/ More algebra 'n stuff if you dig around in: http://www.oregon-tips.com/tips/Public/PublicHomePage (hit the browse button, center of screen, go to Curricula). Kirby From dsh8290@rit.edu Tue Sep 18 03:05:08 2001 From: dsh8290@rit.edu (dman) Date: Mon, 17 Sep 2001 22:05:08 -0400 Subject: [Tutor] Python and mail In-Reply-To: References: <13DE41E0207@kserver.org> Message-ID: <20010917220508.C1931@hudson> On Mon, Sep 17, 2001 at 08:38:07PM -0400, fleet@teachout.org wrote: | Thanks, Sheila. Yes, I think this will help! It looks like I will need | to forego the binary logo (thumbnail) that I have been including - but I'm | not upset about that. Take a look at 'metasend' in the 'mimetools' package (at least, that's what Debian and FreeBSD call the package). It allows you to send attachments (as MIME types) from the command line. 'mail' only allows sending in-line text. mutt can also send MIME attachments (using the '-a' option). HTH, -D From abhishek_nauti@yahoo.co.in Tue Sep 18 05:38:12 2001 From: abhishek_nauti@yahoo.co.in (=?iso-8859-1?q?Abhishek?=) Date: Tue, 18 Sep 2001 05:38:12 +0100 (BST) Subject: [Tutor] Help!! Message-ID: <20010918043812.91710.qmail@web8006.mail.in.yahoo.com> ____________________________________________________________ Do You Yahoo!? Send a newsletter, share photos & files, conduct polls, organize chat events. Visit http://in.groups.yahoo.com From sheila@thinkspot.net Tue Sep 18 05:45:06 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 17 Sep 2001 21:45:06 -0700 Subject: [Tutor] Help!! In-Reply-To: <20010918043812.91710.qmail@web8006.mail.in.yahoo.com> References: <20010918043812.91710.qmail@web8006.mail.in.yahoo.com> Message-ID: <2A5B76C0BFA@kserver.org> You need to be a little more specific. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Tue, 18 Sep 2001 05:38:12 +0100 (BST), Abhishek wrote about [Tutor] Help!!: : : : :____________________________________________________________ :Do You Yahoo!? :Send a newsletter, share photos & files, conduct polls, organize chat events. Visit http://in.groups.yahoo.com : :_______________________________________________ :Tutor maillist - Tutor@python.org :http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Tue Sep 18 06:28:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 17 Sep 2001 22:28:16 -0700 (PDT) Subject: [Tutor] (no subject) In-Reply-To: <000901c13fd1$901cb600$7827fea9@computer> Message-ID: On Mon, 17 Sep 2001, Louie Montelongo wrote: > I Use Python For School Work But I Don't Know How To Use It For > Squaring And Thngs Like That Please Help Me Forgive us: we cannot give direct answers for what seems like a homework question. However, we can try to point you toward useful information. What sort of school work do you use Python with? What stuff are they teaching? The reason I ask this is because it might be possible to apply something that your class has talked about toward this problem. Also, what do you think of when you square things? What does squaring mean? You might find useful things on the new Beginners site on Python.org here: http://www.python.org/doc/Newbies.html Please feel free to ask us questions as well, and we'll see what we can do to clear things up. From r.b.rigilink@chello.nl Tue Sep 18 08:59:32 2001 From: r.b.rigilink@chello.nl (Roeland Rengelink) Date: Tue, 18 Sep 2001 09:59:32 +0200 Subject: [Tutor] unit testing References: Message-ID: <3BA6FEE4.AEB1C8A@chello.nl> Timothy Wilson wrote: > > Hi everyone, > > I'd like to introduce the concept of unit testing to my beginning progamming > students as early in the year as possible. I think they'll be motivated to > learn it because our first project was to write a little leap year > calculator. They spent a lot of time entering the same years over and over > again while testing their program logic. > I think it's a great idea to introduce unit testing early on. One route may be to introduce the assert statement specifically for testing purposes. Something like: def test_leap() assert is_leap(1991)==0 assert is_leap(1992)==1 Something to impress early on is that testing new functionality in your code should be done by writing new test functions, e.g.: def test_century_leap(): assert is_leap(1900)==0 assert is_leap(2000)==1 I used to modify existing test functions to test new functionality, and never reaped the real benefits of unit testing, which is the assurance that after modifying or extending your code, it still works. Of course you end up with a lot of test functions this way, so some way to automate execution of all the tests would be usefull. See below for a simplified testing framework It may be difficult to convince your student that writing all these tests is benificial. You can easily end up with more code in your tests than in your actual program. One way to convince them may be to tell them to write tests before writing the program. It is an interesting exercise to translate specifications into test code. And although the tests may be longer than the program, they may be shorter than the specification document. For example, let them think about what should happen here: def test_bad_imput(): assert is_leap(0) == ??? assert is_leap('abc') == ??? or here? def test_questionable_input(): assert is_leap(1993.7) == ??? assert is_leap('2000') == ??? assert is_leap('MCMXXXIII') == ??? Although if you want these calls to raise exceptions, you may have to think a little about how to assert that something raises an error. This may be too advanced a subject for beginning students. (For a solution see end of this post) > I don't think they're quite ready for PyUnit. Does anyone have any useful > resources or hints about doing basic unit testing? > PyUnit carries a lot of extra baggage that you don't need. Below you'll find a bare-bones testing framework that does essentially the same thing (and may be a good intro to PyUnit). class TestSuite: '''Create a suite of test functions, which can be tested together suite = TestSuite(func1, func2, ..., funcN) suite.run() calls each function func1,...,funcN in turn The functions should take no argument and return values are ignored. If a function raises an AssertionError it is assumed to have failed. If a funtion raises any other exception it is an error. If no exceptions are raised it is assumed to be a succes. Results are reported to the standard output. If test failures or errors are reported run these function separately to get the traceback and the sepcific error messages ''' def __init__(self, *test_functions): self.test_functions = test_functions def run(self): for test in self.test_functions: print test.__name__+'...', try: test() except AssertionError: print 'FAILED' except: print 'ERROR' else: print 'OK' # Example usage: def test_succes(): assert 1==1 def test_failure(): assert 1==0 def test_error(): assert 1/0 == None suite = TestSuite(test_succes, test_failure, test_error) if __name__=='__main__': suite.run() -- A function to test if a function call raises an exception: def raises(exception, function, *arguments): try: function(*arguments) return 0 except exception: return 1 Use for example with: def raise_ValueError(): raise ValueError def test_raises(): assert raises(ValueError, raise_ValueError) Hope this helps, Roeland -- r.b.rigilink@chello.nl "Half of what I say is nonsense. Unfortunately I don't know which half" From ajaya@ncoretech.com Tue Sep 18 09:38:44 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 18 Sep 2001 14:08:44 +0530 Subject: [Tutor] Problem with the select function with sockets! Message-ID: <001701c1401d$54334540$6501a8c0@ncoretech.com> Hi Dear Good People, I am facing a problem with python sockets..., when I use select function with it. Problem description: I am using python program as a server. When I get a connection from the peer.., I rigister with the Peersocket. Then when I try to see if data present in that (peer) socket....using select function like this def ReciveData(self, length): iwtd = [self.PeerSocket] owtd = [] ewtd = [] buffer = '' readable = select(iwtd, owtd, ewtd, 0.25) if len(readable[0]) != 0: buffer = self.PeerSocket.recv(length) return buffer python is givingthe exception saying socket I passed is not a valid descriptor..., Same function is working for the local sockets when I use python code as a client. I don't know what could be the problem. Any help in this reagrd will be great for me Thanks and Regards, Ajaya From ajaya@ncoretech.com Tue Sep 18 09:42:13 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 18 Sep 2001 14:12:13 +0530 Subject: [Tutor] (no subject) Message-ID: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Hi All, I am using python on windows with IDLE but I want to shift to Linux permanently. Can any one suggest me good editor which supports python, like giving keywords in different colour and auto indentation ). Thanks and Regards, Ajaya From ignacio@openservices.net Tue Sep 18 09:54:17 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 18 Sep 2001 04:54:17 -0400 (EDT) Subject: [Tutor] (no subject) In-Reply-To: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Message-ID: On Tue, 18 Sep 2001, Ajaya Babu wrote: > I am using python on windows with IDLE but I want to shift to Linux > permanently. Can any one suggest me good editor which supports python, > like giving keywords in different colour and auto indentation ). My Editor of Choice(tm) under Linux is vim. It has syntax highlighting for most languages you'll use including Python, but (unfortunately?) only autoindents for C/C++. I use it straight from the command line, but it also comes with a psuedo-GUI version called gvim. -- Ignacio Vazquez-Abrams From scarblac@pino.selwerd.nl Tue Sep 18 10:01:18 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 18 Sep 2001 11:01:18 +0200 Subject: [Tutor] (no subject) In-Reply-To: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com>; from ajaya@ncoretech.com on Tue, Sep 18, 2001 at 02:12:13PM +0530 References: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Message-ID: <20010918110118.A26134@pino.selwerd.nl> On 0, Ajaya Babu wrote: > I am using python on windows with IDLE but I want to shift to Linux > permanently. Can any one suggest me good editor which supports python, > like giving keywords in different colour and auto indentation ). Firstly, IDLE also works on Linux since it was written in portable Python. Secondly, the traditional Big Two of editors are Emacs and vi (usually vim, vi improved, now). They have a different philosophy, vi has two modes, a typing mode and a command mode that you switch between, and emacs has no modes, you type, and the commands are combinations with ctrl- and alt- keys and so on. Both have good Python modes, as far as I know. Personally I am used to Emacs commands, and I use jed, which is a small editor (an emacs installation is huge, emacs is programmable, everything has already been programmed, and it comes with everything included), with a good Python mode and emacs commands. Both Emacs and vi have a learning curve but are extremely powerful once you've mastered them. I've heard that vi can actually be programmed in Python, and I've recently heard rumours of the same for Emacs. -- Remco Gerlich From ak@silmarill.org Tue Sep 18 10:04:13 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Tue, 18 Sep 2001 05:04:13 -0400 Subject: [Tutor] (no subject) In-Reply-To: References: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Message-ID: <20010918050413.A28272@sill.silmarill.org> On Tue, Sep 18, 2001 at 04:54:17AM -0400, Ignacio Vazquez-Abrams wrote: > On Tue, 18 Sep 2001, Ajaya Babu wrote: > > > I am using python on windows with IDLE but I want to shift to Linux > > permanently. Can any one suggest me good editor which supports python, > > like giving keywords in different colour and auto indentation ). > > My Editor of Choice(tm) under Linux is vim. It has syntax highlighting for > most languages you'll use including Python, but (unfortunately?) only > autoindents for C/C++. I use it straight from the command line, but it also > comes with a psuedo-GUI version called gvim. There is a way to do python auto-indenting in vim, observe: autocmd BufNewFile,BufRead *.py set textwidth=79 expandtab smartindent cinw=try,if,def,except,for,while,else,elif,class,finally autocmd BufRead *.py set tabstop=4 autocmd BufRead *.py %retab Note that 1st and 2nd line should be one line. This goes to your .vimrc, of course. Ajaya: vim also allows python scripting. If you're using debian, you can get package called vim-python, which includes scripting support. Vim uses a very unusual technique called "modal editing", it takes some time to get used to but is faster and more powerful in the end (IMHO). There is a more traditional editor on linux that supports python highlighting and autoindent - EMACS (and it's flavor XEMACS). There is a #vim channel on irc.openprojects.net - you can ask questions if you run into problems. There's also a #python channel on that network. - Andrei > > -- > Ignacio Vazquez-Abrams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From alan.gauld@bt.com Tue Sep 18 12:27:01 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 18 Sep 2001 12:27:01 +0100 Subject: [Tutor] Python and web Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF70@mbtlipnt02.btlabs.bt.co.uk> > Does anyone have a sample "hello world" python script for the web? I think if you visit the CGI area of the Python website you'll find a tutorial there with sample scripts. > find out if it is working. Is python interpreted, or do I > need to compile and copy up to the web? No compilation necessary. Alan G From alan.gauld@bt.com Tue Sep 18 12:38:10 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 18 Sep 2001 12:38:10 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF71@mbtlipnt02.btlabs.bt.co.uk> > I am using python on windows with IDLE but I want to shift to Linux > permanently. Can any one suggest me good editor which supports python, > like giving keywords in different colour and auto indentation ). Well if your happy with IDLE just keep using it it works on Linux. Others to lok at are vim/gvim emacs nedit(I'm sure I read that it now has Python support) There are dozens of editors on Linux but those are the most popular for programming. Alan g From alan.gauld@bt.com Tue Sep 18 12:43:40 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 18 Sep 2001 12:43:40 +0100 Subject: [Tutor] (no subject) Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF72@mbtlipnt02.btlabs.bt.co.uk> > emacs has no modes Oooh religious war flame bait ;-) Try typing Esc x x in emacs and tell me it has no modes... But I know what you mean and to all intents and purposes its true. > Personally I am used to Emacs commands, and I use jed, which > is a small editor Yes, good option, I forgot jed and it does do syntax highlighting too ISTR. > I've heard that vi can actually be programmed in Python, vim has such a build but I've never usede it. > heard rumours of the same for Emacs. That would be much more difficult to do - unless somebody implemented a python intrerpreter in lisp... However its true the emacs folks are looking at replacing elisp with Guile/Common Lisp/Scheme but I haven't heard of any moves to a more radical departiure - it would just break too many lisp modules... Anyone got any more info on Python programmed emacs? Alan G From ajaya@ncoretech.com Tue Sep 18 12:47:15 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Tue, 18 Sep 2001 17:17:15 +0530 Subject: [Tutor] (no subject) Message-ID: <001001c14037$a9e39d90$6501a8c0@ncoretech.com> Hi All, I am using Python2.1 with Red Hat Linux 7.1 with Tkinter and Pmw modules. But Now I need to test those modules with Redhat 6.2, I serched for the rpms in the http://www.python.org/2.1.1/rpms.html but I found only rpms related to 7.1.1, can any one give the link to download the corresponding rpms 6.1.1 RPMs i need is Python, Tkinter, Pmw..., Thanks and regards, Ajaya From scarblac@pino.selwerd.nl Tue Sep 18 12:56:43 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 18 Sep 2001 13:56:43 +0200 Subject: [Tutor] (no subject) In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF72@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Tue, Sep 18, 2001 at 12:43:40PM +0100 References: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF72@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <20010918135643.A26455@pino.selwerd.nl> On 0, alan.gauld@bt.com wrote: > That would be much more difficult to do - unless somebody > implemented a python intrerpreter in lisp... However its > true the emacs folks are looking at replacing elisp with > Guile/Common Lisp/Scheme but I haven't heard of any moves > to a more radical departiure - it would just break too > many lisp modules... > > Anyone got any more info on Python programmed emacs? I was thinking of this mail by François Pinard, of which I only saw a headline at the daily Python-URL: http://groups.google.com/groups?selm=mailman.999616296.17057.python-list%40python.org You can import python functions and call them as if they were elisp, e.g. (import-python "os") (os-listdir ".") And you can eval strings of Python code. See the post. (the daily Python URL is cool and is at http://www.secretlabs.com/daily/ ) -- Remco Gerlich From lha2@columbia.edu Tue Sep 18 13:49:14 2001 From: lha2@columbia.edu (Lloyd Hugh Allen) Date: Tue, 18 Sep 2001 08:49:14 -0400 Subject: [Tutor] Squaring And Things Like That References: Message-ID: <3BA742CA.A0E7D2E6@mail.verizon.net> If you want to use exponents, the symbol "**" means "raised to the". So 2**3 == 8 3**2 == 9 5**5 == 625 11**2 == 121 Don't use "^". That means something completely different (as I'm sure you've figured out). You'll also want to "import math" and then "dir(math)" to see what other functions are available, and you can access them by doing stuff like math.sqrt(25) 5. math.pi 3.1415926535897931 math.pi * 5**2 78.539816339744831 and be careful that (for your purposes) you include a decimal point any time that you do division--otherwise python will give you the integer part of the quotient without the remainder (for the current version of Python). So 10/3 3 while 10./3 3.333333333333335 and you know that the last "5" is nonsense. If you want go ahead and use integer division and recover the remainder so as to express your answer as a mixed number, you can do 10/3 3 10%3 1 and know that the answer is three and one third (you will always use the remainder as the numerator and the divisor as the denominator). Assuming that you have Python 2.1. Good luck and stuff. > From: "Louie Montelongo" > To: > Date: Mon, 17 Sep 2001 18:36:22 -0500 > Subject: [Tutor] (no subject) > > This is a multi-part message in MIME format. > > ------=_NextPart_000_0005_01C13FA7.A64347C0 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > I Use Python For School Work But I Don't Know How To Use It For Squaring = > And Thngs Like That > Please Help Me =20 > Louie = > Montelongo From lkvam@venix.com Tue Sep 18 14:33:52 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Tue, 18 Sep 2001 09:33:52 -0400 Subject: [Tutor] Python and mail References: <13DE41E0207@kserver.org> <20010917220508.C1931@hudson> Message-ID: <3BA74D40.8151F70D@venix.com> I have no experience with this module, but MimeWriter is documented in Fredrik Lundh's book, "Python Standard Library". The sample snippet of code looks very straight forward. dman wrote: > > On Mon, Sep 17, 2001 at 08:38:07PM -0400, fleet@teachout.org wrote: > | Thanks, Sheila. Yes, I think this will help! It looks like I will need > | to forego the binary logo (thumbnail) that I have been including - but I'm > | not upset about that. > > Take a look at 'metasend' in the 'mimetools' package (at least, that's > what Debian and FreeBSD call the package). It allows you to send > attachments (as MIME types) from the command line. 'mail' only allows > sending in-line text. mutt can also send MIME attachments (using the > '-a' option). > > HTH, > -D > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From urnerk@qwest.net Tue Sep 18 15:32:47 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 18 Sep 2001 07:32:47 -0700 Subject: [Tutor] (no subject) In-Reply-To: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Message-ID: <4.2.0.58.20010918073238.00bfd8e0@pop3.norton.antivirus> At 02:12 PM 9/18/2001 +0530, Ajaya Babu wrote: >Hi All, > >I am using python on windows with IDLE but I want to shift to Linux >permanently. Can any one suggest me good editor which supports python, > like giving keywords in different colour and auto indentation ). IDLE Kirby From urnerk@qwest.net Tue Sep 18 15:36:13 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 18 Sep 2001 07:36:13 -0700 Subject: [Tutor] Emacs question In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF72@mbtlipnt02.btlabs .bt.co.uk> Message-ID: <4.2.0.58.20010918073433.00c02cb0@pop3.norton.antivirus> > >Anyone got any more info on Python programmed emacs? > >Alan G Yeah, if someone could go over quickly how to mess with the colors and keywording especially, for Python. Some kind of "tag" file? The version of Xemacs I sometimes use doesn't know about 'yield' and I think messes up the triple- quote multi-line strings as well. I did manage to hand-change my copy of Vi to understand about 'yield' (a new keyword as of 2.2). Kirby From fleet@teachout.org Tue Sep 18 15:39:57 2001 From: fleet@teachout.org (fleet@teachout.org) Date: Tue, 18 Sep 2001 10:39:57 -0400 (EDT) Subject: [Tutor] Python and mail Message-ID: > Take a look at 'metasend' in the 'mimetools' package (at least, that's > what Debian and FreeBSD call the package). It allows you to send > attachments (as MIME types) from the command line. 'mail' only allows > sending in-line text. mutt can also send MIME attachments (using the > '-a' option). Thanks! I checked out 'man metasend' and then noticed a reference to 'mailto,' which I also check in the man pages. I think I'll try 'mailto.' I'm assuming I can write a script (which Python can handle) to send the files, including the thumbnail. OT: I'm also thinking of trashing the logo and the html and going back to pure text. Most of my customers run Windows mail packages of one sort or another, but that may change! - fleet - From urnerk@qwest.net Tue Sep 18 15:48:30 2001 From: urnerk@qwest.net (Kirby Urner) Date: Tue, 18 Sep 2001 07:48:30 -0700 Subject: [Tutor] More re IDLE in Linux In-Reply-To: <4.2.0.58.20010918073238.00bfd8e0@pop3.norton.antivirus> References: <001801c1401d$d0cdebf0$6501a8c0@ncoretech.com> Message-ID: <4.2.0.58.20010918074339.00bfeb30@pop3.norton.antivirus> I should add that if you want to use IDLE in Linux you may find that the default font it gives you is too small. You can mess with default fonts in some defaults file to make it bigger. Also, if you ./configure, make, make install a version of Python, it may not put an IDLE in place for you automatically. The files you download will have it in a subdirectory of the original tarball called /Tools I think it is. Use Linux 'find' (one suggestion) to locate the IDLE stuff. Then copy "it" (a whole subdirectory actually) to the appropriate place on your directory tree. Kirby At 07:32 AM 9/18/2001 -0700, Kirby Urner wrote: >At 02:12 PM 9/18/2001 +0530, Ajaya Babu wrote: > >>Hi All, >> >>I am using python on windows with IDLE but I want >>to shift to Linux permanently. From shalehperry@home.com Tue Sep 18 18:03:23 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Tue, 18 Sep 2001 10:03:23 -0700 (PDT) Subject: [Tutor] Emacs question In-Reply-To: <4.2.0.58.20010918073433.00c02cb0@pop3.norton.antivirus> Message-ID: On 18-Sep-2001 Kirby Urner wrote: > >> >>Anyone got any more info on Python programmed emacs? >> >>Alan G > > Yeah, if someone could go over quickly how to > mess with the colors and keywording especially, > for Python. Some kind of "tag" file? The > version of Xemacs I sometimes use doesn't know > about 'yield' and I think messes up the triple- > quote multi-line strings as well. > > I did manage to hand-change my copy of Vi to > understand about 'yield' (a new keyword as of > 2.2). > >From python-mode.el: (defvar python-font-lock-keywords (let ((kw1 (mapconcat 'identity '("and" "assert" "break" "class" "continue" "def" "del" "elif" "else" "except" "exec" "for" "from" "global" "if" "import" "in" "is" "lambda" "not" "or" "pass" "print" "raise" "return" "while" ) "\\|")) (kw2 (mapconcat 'identity '("else:" "except:" "finally:" "try:") "\\|")) ) Hope that helps. From rfbrenar@cs.uchicago.edu Tue Sep 18 18:22:24 2001 From: rfbrenar@cs.uchicago.edu (robert frank brenart) Date: Tue, 18 Sep 2001 12:22:24 -0500 (CDT) Subject: [Tutor] Symbol re question Message-ID: Alright, this should be easy and it's being a pain... I just want to find out if my string is all numbers. So I run... if ((re.match("[0-9]+", mystring)) != None): print "Pass" else: print "Fail" But that matches things like 10:45 and 3f, which I don't want it to. What'm I overlooking? -Rob From shalehperry@home.com Tue Sep 18 18:32:27 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Tue, 18 Sep 2001 10:32:27 -0700 (PDT) Subject: [Tutor] Symbol re question In-Reply-To: Message-ID: On 18-Sep-2001 robert frank brenart wrote: > > Alright, this should be easy and it's being a pain... I just want to find > out if my string is all numbers. > > So I run... > if ((re.match("[0-9]+", mystring)) != None): > print "Pass" > else: > print "Fail" > > But that matches things like 10:45 and 3f, which I don't want it > to. What'm I overlooking? > A regex matches any part of a string. if you want the string to ONLY be numbers you need to say so in the regex. Try this: r"^[0-9]+$" that says "from the start of my string '^', match a string of numbers '[0-9]+' then the end of string '$'". The 'r' before the string tells python to read this as a raw string and should be used before any regex string. From lkvam@venix.com Tue Sep 18 18:39:51 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Tue, 18 Sep 2001 13:39:51 -0400 Subject: [Tutor] Symbol re question References: Message-ID: <3BA786E7.EB830159@venix.com> You want "^[0-9]+$" for your regular expression ^ from the beginning $ to the end. robert frank brenart wrote: > > Alright, this should be easy and it's being a pain... I just want to find > out if my string is all numbers. > > So I run... > if ((re.match("[0-9]+", mystring)) != None): > print "Pass" > else: > print "Fail" > > But that matches things like 10:45 and 3f, which I don't want it > to. What'm I overlooking? > > -Rob > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From dyoo@hkn.eecs.berkeley.edu Tue Sep 18 19:40:45 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Tue, 18 Sep 2001 11:40:45 -0700 (PDT) Subject: [Tutor] Symbol re question In-Reply-To: Message-ID: On Tue, 18 Sep 2001, Sean 'Shaleh' Perry wrote: > > On 18-Sep-2001 robert frank brenart wrote: > > > > Alright, this should be easy and it's being a pain... I just want to find > > out if my string is all numbers. > > > > So I run... > > if ((re.match("[0-9]+", mystring)) != None): > > print "Pass" > > else: > > print "Fail" > > > > But that matches things like 10:45 and 3f, which I don't want it > > to. What'm I overlooking? > > > > A regex matches any part of a string. if you want the string to ONLY be > numbers you need to say so in the regex. Try this: > > r"^[0-9]+$" > > that says "from the start of my string '^', match a string of numbers > '[0-9]+' then the end of string '$'". The 'r' before the string tells > python to read this as a raw string and should be used before any > regex string. Somewhat related: be aware that "match" is somewhat different from "search" in Python's regular expressions: http://www.python.org/doc/lib/matching-searching.html If we're using the anchors '^' and '$', it might be good to use re.search(). From kalle@gnupung.net Tue Sep 18 20:40:19 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Tue, 18 Sep 2001 21:40:19 +0200 Subject: [Tutor] Emacs question In-Reply-To: <4.2.0.58.20010918073433.00c02cb0@pop3.norton.antivirus> References: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF72@mbtlipnt02.btlabs <4.2.0.58.20010918073433.00c02cb0@pop3.norton.antivirus> Message-ID: <20010918214019.A1923@sandrew.lysator.liu.se> [Kirby Urner] > Yeah, if someone could go over quickly how to > mess with the colors and keywording especially, > for Python. Some kind of "tag" file? The > version of Xemacs I sometimes use doesn't know > about 'yield' and I think messes up the triple- > quote multi-line strings as well. yield: Get a new python-mode.el, http://www.python.org/emacs/python-mode/. You could edit your local copy to know about yield, but then you won't get the other enhancements (if any). multi-line strings: These get weird if you have wuotes inside, but should work fine otherwise. It Works For Me (tm). Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From michael@exasource.com Tue Sep 18 21:33:48 2001 From: michael@exasource.com (Michael) Date: Tue, 18 Sep 2001 14:33:48 -0600 Subject: [Tutor] Newbie Question? Message-ID: <01091814334801.01432@orion.andromeda> Hello, I'm new to python and programming and have been through several lessons putting together programs using if, elif, else, while and for loops, etc. These are all math oriented programs. I'm also working with Zope, (I'm a newbie on this too), and would like to be able to write programs for it to control logic decisions. On my site I have a graphics version and a text version. Currently, I'm using two separate headers, one for the text version and another for the graphics. What I would like to be able to do is use one header for both and use python to control the logic of deciding which of two objects to execute based on the page the header is being called from. I am using an index_html page for graphics and an index_text_html page for text. I tried using dtml scripts to do this but have not had much luck. The first one I tried was: This script always executes the first command, , no matter which page the header is being called from. Someone on the Zope list suggested that I try: ` This script always executes the second command, , no matter which page the header is being called from. Can someone suggest a python script that might work in this situation? I think if I can see how this works, I'll be able to use python for something besides a calculator. I know how to write if/else statements but I'm not sure how to define the calling page. Thanks, -- Michael Lewis "Linux - The final solution" From iconoclast@portalofevil.com Tue Sep 18 22:02:47 2001 From: iconoclast@portalofevil.com (Empire Down ) Date: Tue, 18 Sep 2001 17:02:47 -0400 Subject: [Tutor] Copying file to multiple machines. Message-ID: <200109181702.AA960758216@portalofevil.com> I am new to python and am trying to copy a file from my machine to multiple machines on a network (98 machines) I know this can be done simply with a shell script but I have been wanting to learn Python and figured this would be somehting simple I could do, though it is turning out not to be so simple. I have Mark Hammond book.. but i think still need a little assistance. Thanks! James M. _________________________________________________________ Get your own FREE portalofevil.com Email account at... http://www.evilemail.com PortalofEvil.com - Websites by the insane for the insane. _________________________________________________________ From ignacio@openservices.net Tue Sep 18 22:52:20 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 18 Sep 2001 17:52:20 -0400 (EDT) Subject: [Tutor] Copying file to multiple machines. In-Reply-To: <200109181702.AA960758216@portalofevil.com> Message-ID: On Tue, 18 Sep 2001, Empire Down wrote: > I am new to python and am trying to copy a file from my machine to multiple machines on a network (98 machines) I know this can be done simply with a shell script but I have been wanting to learn Python and figured this would be somehting simple I could do, though it is turning out not to be so simple. I have Mark Hammond book.. but i think still need a little assistance. You don't mention how you would do it with shell scripts, so I have no background information to go on. With that in mind, here comes my zany solution.... TCP/IP broadcasting/multicasting. On each of the client machines run a small script that attaches to a socket and waits for an incoming connection. On your server machine, you run a script that broadcasts/multicasts the filename followed by the filecontents. The client then looks at the filename and dumps the filecontents into the file. The client will have to make sure that the connection is authenticated, and that the filename isn't something important, like '/etc/passwd'. -- Ignacio Vazquez-Abrams From iconoclast@portalofevil.com Tue Sep 18 23:13:14 2001 From: iconoclast@portalofevil.com (Empire Down ) Date: Tue, 18 Sep 2001 18:13:14 -0400 Subject: [Tutor] Copying file to multiple machines. Message-ID: <200109181813.AA4048159046@portalofevil.com> I am Sorry, I left out some info. OS is W2K adv Srv and I am admin on all the machines, all the machines are on a LAN, and the target path on all the machines are the same, all going to "all users" start up. James On Tue, 18 Sep 2001, Empire Down wrote: >> I am new to python and am trying to copy a file from my >>machine to >> multiple machines on a network (98 machines) I know this >>can be done >> simply with a shell script but I have been wanting to learn >>Python and >> figured this would be somehting simple I could do, though it >>is >>turning out not to be so simple. I have Mark Hammond book.. >>but i >>think still need a little assistance. >You don't mention how you would do it with shell scripts, so I >have no background information to go on. With that in mind, >here comes my zany solution.... >TCP/IP broadcasting/multicasting. On each of the client >machines run a small script that attaches to a socket and >waits for an incoming connection. On your server machine, you >run a script that broadcasts/multicasts the filename followed >by the filecontents. The client then looks at the filename and >dumps the filecontents into the file. >The client will have to make sure that the connection is >authenticated, and that the filename isn't something >important, like '/etc/passwd'. >-- >Ignacio Vazquez-Abrams _________________________________________________________ Get your own FREE portalofevil.com Email account at... http://www.evilemail.com PortalofEvil.com - Websites by the insane for the insane. _________________________________________________________ From ignacio@openservices.net Tue Sep 18 23:25:43 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 18 Sep 2001 18:25:43 -0400 (EDT) Subject: [Tutor] Copying file to multiple machines. In-Reply-To: <200109181813.AA4048159046@portalofevil.com> Message-ID: On Tue, 18 Sep 2001, Empire Down wrote: > I am Sorry, I left out some info. OS is W2K adv Srv and I am admin on all the machines, all the machines are on a LAN, and the target path on all the machines are the same, all going to "all users" start up. In that case using a login script might be best. If all the machines have Python installed then you can duplicate the effort that the copy command does, but I can't see any good reason for it. -- Ignacio Vazquez-Abrams From lonetwin@yahoo.com Wed Sep 19 06:56:14 2001 From: lonetwin@yahoo.com (lonetwin) Date: Wed, 19 Sep 2001 11:26:14 +0530 Subject: [Tutor] Symbol re question In-Reply-To: References: Message-ID: <01091911261400.05692@mercury.worli> Hi Rob, > Alright, this should be easy and it's being a pain... I just want to find > out if my string is all numbers. > > So I run... > if ((re.match("[0-9]+", mystring)) != None): > <...snip...> > to. What'm I overlooking? > > -Rob How about : ================================================================ Python 2.0 (#1, Apr 11 2001, 19:18:08) [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> import string >>> for c in '43': ... if c not in string.digits: ... print 'fail' ... else: ... print 'pass' ... pass pass ================================================================ I had done this once....just a thought, -- Peace Steve From ajaya@ncoretech.com Wed Sep 19 07:09:43 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Wed, 19 Sep 2001 11:39:43 +0530 Subject: [Tutor] New to Linux and facing path problems :? Message-ID: <000f01c140d1$ae023f90$6501a8c0@ncoretech.com> Hi, I am new to Linux. I installed Pmw rpm in my directory tree. The problem I am facing is from other directories I am not able to import this Pmw. In windows I used to set path for this direcotory to solve this problem. Please suggest me how to fix this problem. Thanks and Regards, Ajaya From ignacio@openservices.net Wed Sep 19 07:25:53 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 19 Sep 2001 02:25:53 -0400 (EDT) Subject: [Tutor] New to Linux and facing path problems :? In-Reply-To: <000f01c140d1$ae023f90$6501a8c0@ncoretech.com> Message-ID: On Wed, 19 Sep 2001, Ajaya Babu wrote: > I am new to Linux. I installed Pmw rpm in my directory tree. The problem I > am facing is from other directories I am not able to import this Pmw. Where did you get this RPM? At Sourceforge they only have tarballs, and Google doesn't show the existence of any PMW RPM. -- Ignacio Vazquez-Abrams From ajaya@ncoretech.com Wed Sep 19 09:08:39 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Wed, 19 Sep 2001 13:38:39 +0530 Subject: [Tutor] New to Linux and facing path problems :? In-Reply-To: Message-ID: <001101c140e2$4ac537f0$6501a8c0@ncoretech.com> Hi, I am sorry I made a mistake...insted tar.....I used rpm by the way....now I am able to import it from any where I want..., What I need to do is ..., I need to untar Pwm to the usr/lib/python1.5(or 2.0)/site-packages/ Thanks allot for your response.. One more doubt I've I want to install Python2.0 or onwards for the 6.1 linux... I am using Redhat linux, I searched in python.org site, but unfortunately I could only find python2.0 rpms for 7.1 onwards, If you have any info please help me Thanks and regards, Ajaya -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Ignacio Vazquez-Abrams Sent: Wednesday, September 19, 2001 11:56 AM To: PythonTutorlist (E-mail) Subject: Re: [Tutor] New to Linux and facing path problems :? On Wed, 19 Sep 2001, Ajaya Babu wrote: > I am new to Linux. I installed Pmw rpm in my directory tree. The problem I > am facing is from other directories I am not able to import this Pmw. Where did you get this RPM? At Sourceforge they only have tarballs, and Google doesn't show the existence of any PMW RPM. -- Ignacio Vazquez-Abrams _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From girishg@india.ti.com Wed Sep 19 10:17:19 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 14:47:19 +0530 Subject: [Tutor] Commenting a big block of code Message-ID: <3BA8629F.62B9D344@india.ti.com> Hi All, I wish to comment out a big block of code. It is rather painful to go and insert a "#" in front of each line of code. Is there any "Block Comment" feature or perhaps someone would just send me a VIM macro which I can use to select a block of code in visual mode & then use some key mapped to the macro & within a blink of an eye find all the lines commented out. For now, I am just cutting out these lines & putting them in a temporary area from where I retrieve them as necessary. Thanks Girish From jyothi@ncoretech.com Wed Sep 19 10:41:25 2001 From: jyothi@ncoretech.com (jyothi Guruprasanna) Date: Wed, 19 Sep 2001 15:11:25 +0530 Subject: [Tutor] doubt ....... Message-ID: Hi, Is there any python Megawidget class which can display directory istings( I mean treeview ). Thanks and Regards, Jyothi. From girishg@india.ti.com Wed Sep 19 11:33:34 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 16:03:34 +0530 Subject: [Tutor] doubt ....... References: <3BA8739B.4325FDF5@india.ti.com> Message-ID: <3BA8747E.BF5B1179@india.ti.com> Check out http://www.handshake.de/~dieter/pyprojects/treewidget.html This link was available at the Vaults of Parnassus, http://www.vex.net/parnassus/ which is a Code repository for Python I had earlier found a link to another treeview class, but could not find it there today. HTH Girish > [Tutor] doubt ....... > > jyothi Guruprasanna jyothi@ncoretech.com > Wed, 19 Sep 2001 15:11:25 +0530 > > > Hi, > > Is there any python Megawidget class which can display directory > istings( I mean treeview ). > > Thanks and Regards, > Jyothi. > From alan.gauld@bt.com Wed Sep 19 11:48:05 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 19 Sep 2001 11:48:05 +0100 Subject: [Tutor] Symbol re question Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF7F@mbtlipnt02.btlabs.bt.co.uk> > >>> import string > >>> for c in '43': > ... if c not in string.digits: > ... print 'fail' > ... else: ... continue # might be more useful? ... print "pass" > pass But the regex route is almost certainly more efficient and more flexible. Alan G From alan.gauld@bt.com Wed Sep 19 11:54:37 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 19 Sep 2001 11:54:37 +0100 Subject: [Tutor] Commenting a big block of code Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF80@mbtlipnt02.btlabs.bt.co.uk> > I wish to comment out a big block of code. It is rather > painful to go and insert a "#" in front of each line of > code. > > Is there any "Block Comment" feature or perhaps someone > would just send me a VIM macro The brute force way in vi[m]: :x,ys/^/# / substitutes '# ' at the beginning of each line between x and y x and y can be line numbers or a range or even a line marker... In other words the usual way of working in vi... Remove by using: :x,ys/^# // Alan G From alan.gauld@bt.com Wed Sep 19 12:06:33 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 19 Sep 2001 12:06:33 +0100 Subject: [Tutor] Copying file to multiple machines. Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF81@mbtlipnt02.btlabs.bt.co.uk> > I am new to python and am trying to copy a file from my > machine to multiple machines on a network (98 machines) You have W2K they have Win98? Do they have sharing turned on for the folders you want to copy to? If so you can use WSH to access the shared drives. Hammonds book shows an example of this. Look under WSH. However for this a simple CMD file would maybe be easier... Although Python might make it easier to discover each machine in the network before running the scroipt with the machine name as a parameter - a hybrid approach? Just some random thoughts. Alan G. From lkvam@venix.com Wed Sep 19 14:32:04 2001 From: lkvam@venix.com (Lloyd Kvam) Date: Wed, 19 Sep 2001 09:32:04 -0400 Subject: [Tutor] Newbie Question? References: <01091814334801.01432@orion.andromeda> Message-ID: <3BA89E54.536A923A@venix.com> You will find it easier to learn Python first and then Zope. Zope tries to make building your web site easier by automatically searching through the URL elements to find the items that are referenced in the HTML/DTML. You normally use the same name for alternative items and count on the URLpath to find the correct item. In your case I think you want two items called header. www.mysite.com/zoo/reptile would get the graphic header www.mysite.com/text/zoo/reptile would find the text header You will need to experiment a bit to find what works for you. I am not actually using Zope right now, so I am not a thoroughly reliable source. Hopefully, you can get good help from the Zope list. Michael wrote: > > Hello, > > I'm new to python and programming and have been through several lessons > putting together programs using if, elif, else, while and for loops, etc. > These are all math oriented programs. I'm also working with Zope, (I'm a > newbie on this too), and would like to be able to write programs for it to > control logic decisions. > > On my site I have a graphics version and a text version. Currently, I'm > using two separate headers, one for the text version and another for the > graphics. What I would like to be able to do is use one header for both and > use python to control the logic of deciding which of two objects to execute > based on the page the header is being called from. I am using an index_html > page for graphics and an index_text_html page for text. > > I tried using dtml scripts to do this but have not had much luck. The first > one I tried was: > > > > > > > > This script always executes the first command, , no > matter which page the header is being called from. > > Someone on the Zope list suggested that I try: > > > > > ` > > > This script always executes the second command, , no > matter which page the header is being called from. > > Can someone suggest a python script that might work in this situation? I > think if I can see how this works, I'll be able to use python for something > besides a calculator. I know how to write if/else statements but I'm not > sure how to define the calling page. > > Thanks, > -- > Michael Lewis > > "Linux - The final solution" > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-443-6155 fax: 801-459-9582 From ignacio@openservices.net Wed Sep 19 14:45:08 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 19 Sep 2001 09:45:08 -0400 (EDT) Subject: [Tutor] New to Linux and facing path problems :? In-Reply-To: <001101c140e2$4ac537f0$6501a8c0@ncoretech.com> Message-ID: On Wed, 19 Sep 2001, Ajaya Babu wrote: > What I need to do is ..., > > I need to untar Pwm to the usr/lib/python1.5(or 2.0)/site-packages/ cd /usr/lib/python1.5/site-packages tar zxvf /path/to/tarball/Pmw.0.8.5.tar.gz > I want to install Python2.0 or onwards for the 6.1 linux... I am using > Redhat linux, > I searched in python.org site, but unfortunately I could only find python2.0 > rpms for 7.1 onwards, If you can, upgrade to 7.1. If not, then you might be better off installing from tarball, although you can try the SRPM if you want. Oh, and install 2.1.1 instead of 2.0. -- Ignacio Vazquez-Abrams From shalehperry@home.com Wed Sep 19 16:18:42 2001 From: shalehperry@home.com (Sean 'Shaleh' Perry) Date: Wed, 19 Sep 2001 08:18:42 -0700 (PDT) Subject: [Tutor] Commenting a big block of code In-Reply-To: <3BA8629F.62B9D344@india.ti.com> Message-ID: On 19-Sep-2001 Girish Gajwani wrote: > Hi All, > > I wish to comment out a big block of code. It is rather > painful to go and insert a "#" in front of each line of > code. > > Is there any "Block Comment" feature or perhaps someone > would just send me a VIM macro which I can use to select a > block of code in visual mode & then use some key mapped to > the macro & within a blink of an eye find all the lines > commented out. > > For now, I am just cutting out these lines & putting them in > a temporary area from where I retrieve them as necessary. > if you could grab the excellent O'reilly vi book you would learn all of this and more. learning your editor can make you marvelously more productive, regardless of the editor. From girishg@india.ti.com Wed Sep 19 16:26:48 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 20:56:48 +0530 Subject: [Tutor] Commenting a big block of code References: Message-ID: <3BA8B938.B229ED7E@india.ti.com> Well, Not that i am pretty bad at using vi ... Only thing was that I was feeling too lazy to do something like that ;-) Thanks for the advice though. Best regards Girish Sean 'Shaleh' Perry wrote: > > On 19-Sep-2001 Girish Gajwani wrote: > > Hi All, > > > > I wish to comment out a big block of code. It is rather > > painful to go and insert a "#" in front of each line of > > code. > > > > Is there any "Block Comment" feature or perhaps someone > > would just send me a VIM macro which I can use to select a > > block of code in visual mode & then use some key mapped to > > the macro & within a blink of an eye find all the lines > > commented out. > > > > For now, I am just cutting out these lines & putting them in > > a temporary area from where I retrieve them as necessary. > > > > if you could grab the excellent O'reilly vi book you would learn all of this > and more. learning your editor can make you marvelously more productive, > regardless of the editor. From ak@silmarill.org Wed Sep 19 16:32:42 2001 From: ak@silmarill.org (Andrei Kulakov) Date: Wed, 19 Sep 2001 11:32:42 -0400 Subject: [Tutor] Commenting a big block of code In-Reply-To: References: <3BA8629F.62B9D344@india.ti.com> Message-ID: <20010919113242.A567@sill.silmarill.org> On Wed, Sep 19, 2001 at 08:18:42AM -0700, Sean 'Shaleh' Perry wrote: > > On 19-Sep-2001 Girish Gajwani wrote: > > Hi All, > > > > I wish to comment out a big block of code. It is rather > > painful to go and insert a "#" in front of each line of > > code. > > > > Is there any "Block Comment" feature or perhaps someone > > would just send me a VIM macro which I can use to select a > > block of code in visual mode & then use some key mapped to > > the macro & within a blink of an eye find all the lines > > commented out. > > > > For now, I am just cutting out these lines & putting them in > > a temporary area from where I retrieve them as necessary. > > > > if you could grab the excellent O'reilly vi book you would learn all of this > and more. learning your editor can make you marvelously more productive, > regardless of the editor. There is a vim book out, too by steve oualline, who also wrote "practical c" book. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From alan.gauld@bt.com Wed Sep 19 17:08:42 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 19 Sep 2001 17:08:42 +0100 Subject: [Tutor] Commenting a big block of code Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF86@mbtlipnt02.btlabs.bt.co.uk> > > if you could grab the excellent O'reilly vi book you would > > There is a vim book out, too by steve oualline, who also There's a very good vi tutor on the net. Its variously called teachvi or learnvi - they are the same thing. It runs under Bourne Shell on Unix - so by extension under Korn shell or Bash too. Which by further extension means it works on Windoze under cygwin... The good thing is it really teaches the principles of operation of vi so that you can pretty much guess how things work even when you can't remember - vi really is intuitive once you understand the philospohy behind it. Its plain vanilla vi but once you understand that vim is easy :-) Alan g. From girishg@india.ti.com Wed Sep 19 17:14:12 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 21:44:12 +0530 Subject: [Tutor] why do I not get a Window Title with the following? Message-ID: <3BA8C454.460AF37B@india.ti.com> Please check the following code: ####################### #! /usr/bin/env python import string from Tkinter import * root = Tk() root.title="girish" root.mainloop() ####################### All I am trying is to change the window title to something else("girish", here) I have seen some other code do something like this and work. However, I could not get this even in this small piece of code. Obviously I must be doing something silly :-). But i could not find out what was the silly thing I was doing. Please help TIA Girish PS: I am trying to learn Tkinter From rick@niof.net Wed Sep 19 17:27:55 2001 From: rick@niof.net (Rick Pasotto) Date: Wed, 19 Sep 2001 12:27:55 -0400 Subject: [Tutor] why do I not get a Window Title with the following? In-Reply-To: <3BA8C454.460AF37B@india.ti.com> References: <3BA8C454.460AF37B@india.ti.com> Message-ID: <20010919122755.B28244@tc.niof.net> On Wed, Sep 19, 2001 at 09:44:12PM +0530, Girish Gajwani wrote: > Please check the following code: > > ####################### > #! /usr/bin/env python > > import string > from Tkinter import * > > root = Tk() > root.title="girish" > root.mainloop() > ####################### > > All I am trying is to change the window title to something > else("girish", here) > I have seen some other code do something like this and work. "Something like this" doesn't cut it. Computers can be very picky. What you want is root.title("girish") -- And why do the political parties aspire to take over the direction of education? Because they know the saying of Leibnitz: "Make me the master of Education by governmental power, and I will undertake to change the world". Education by governmental power, then, is education by a political party, by a sect momentarily triumphant; it is education on behalf of one idea, of one system, to the exclusion of all others. -- Frédéric Bastiat (1801-1850) Rick Pasotto rickp@telocity.com http://www.niof.net From girishg@india.ti.com Wed Sep 19 17:37:27 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 22:07:27 +0530 Subject: [Tutor] why do I not get a Window Title with the following? References: <3BA8C8F2.3D71D6DD@india.ti.com> Message-ID: <3BA8C9C7.E3E6217C@india.ti.com> > Rick Pasotto rick@niof.net > Wed, 19 Sep 2001 12:27:55 -0400 > > ---------------------------------------------------------- > > On Wed, Sep 19, 2001 at 09:44:12PM +0530, Girish Gajwani wrote: > > Please check the following code: > > > > ####################### > > #! /usr/bin/env python > > > > import string > > from Tkinter import * > > > > root = Tk() > > root.title="girish" > > root.mainloop() > > ####################### > > > > All I am trying is to change the window title to something > > else("girish", here) > > I have seen some other code do something like this and work. > > "Something like this" doesn't cut it. Computers can be very picky. > > What you want is root.title("girish") > Right!!! Well, I must be sleepy :) Thanks. You see the "title" looked more obvious to me as a variable than as a function, and i did not copy-paste (my fault) Girish From ravimails@lycos.com Wed Sep 19 18:04:58 2001 From: ravimails@lycos.com (Ravikumar Devarajan) Date: Wed, 19 Sep 2001 12:04:58 -0500 Subject: [Tutor] sockets Message-ID: hi all, im trying to do the following in python i have 2 processes.i need them to communicate.and they will have to send and receive stuff till i close the connection.somehow this doesnt seem to work.im using sockets. and i want to know if theres any way by which i can keep the connection open as long as i want.i wud really appreciate any help in this regard. thanks Ravikumar Make a difference, help support the relief efforts in the U.S. http://clubs.lycos.com/live/events/september11.asp From girishg@india.ti.com Wed Sep 19 18:50:06 2001 From: girishg@india.ti.com (Girish Gajwani) Date: Wed, 19 Sep 2001 23:20:06 +0530 Subject: [Tutor] Commenting a big block of code References: <3BA8629F.62B9D344@india.ti.com> <01091910395705.01245@gandalf> Message-ID: <3BA8DACE.44DF102D@india.ti.com> Yes, sure I could. I had thought of that. But I did not want to use it 'coz I was thinking of some "Block commenting" feature. But yes, this option was surely in mind. I guess I could also try something like a "compile time switch": if 0: Commented out portion of code, right shifted (for Python indentation requirements) easily done by my editor (vim) else: Changes to the code endif Regards Girish Bob Rea wrote: > > On Wednesday 19 September 2001 02:17 am, you wrote: > > Hi All, > > > > I wish to comment out a big block of code. It is rather > > painful to go and insert a "#" in front of each line of > > code. > > Can't you just triple quote it at beginning and end? At > least for now? In the long run, it would be the doc string, > but isn't it ok temporarily? > > -- > Bob Rea > > Fear of Hell is pernicious; > So is fear of Heaven. > > sfpetard@earthlink.net home.earthlink.net/~rear From dyoo@hkn.eecs.berkeley.edu Wed Sep 19 19:05:40 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 19 Sep 2001 11:05:40 -0700 (PDT) Subject: [Tutor] Commenting a big block of code In-Reply-To: <3BA8629F.62B9D344@india.ti.com> Message-ID: On Wed, 19 Sep 2001, Girish Gajwani wrote: > I wish to comment out a big block of code. It is rather > painful to go and insert a "#" in front of each line of > code. For Emacs, block commenting can be done by highlighting the section, then pressing: Ctrl c # Uncommenting is similar: Ctrl - Ctrl c # From rnd@onego.ru Wed Sep 19 20:58:59 2001 From: rnd@onego.ru (Roman Suzi) Date: Wed, 19 Sep 2001 23:58:59 +0400 (MSD) Subject: [Tutor] Commenting a big block of code In-Reply-To: Message-ID: One more way to "comment" block: ''' On Wed, 19 Sep 2001, Danny Yoo wrote: >On Wed, 19 Sep 2001, Girish Gajwani wrote: > >> I wish to comment out a big block of code. It is rather >> painful to go and insert a "#" in front of each line of >> code. > >For Emacs, block commenting can be done by highlighting the section, then >pressing: > > Ctrl c # > >Uncommenting is similar: > > Ctrl - Ctrl c # > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor ''' Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd@onego.ru _/ _/ Wednesday, September 19, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "Shin: A device for finding furniture in the dark." _/ From SWidney@ci.las-vegas.nv.us Wed Sep 19 22:50:26 2001 From: SWidney@ci.las-vegas.nv.us (Scott Widney) Date: Wed, 19 Sep 2001 14:50:26 -0700 Subject: [Tutor] Copying file to multiple machines. Message-ID: > > I am new to python and am trying to copy a file from my > > machine to multiple machines on a network (98 machines) > > You have W2K they have Win98? > > Do they have sharing turned on for the folders you want > to copy to? If so you can use WSH to access the shared drives. > Hammonds book shows an example of this. Look under WSH. > > However for this a simple CMD file would maybe be easier... > Although Python might make it easier to discover each > machine in the network before running the scroipt with the > machine name as a parameter - a hybrid approach? > > Just some random thoughts. If this is a one time deal, take the quick and simple route. You may end up spending a lot of time researching and fine-tuning (not to mention adding error-checking and logging). It's only worth the effort if you're going to be doing this frequently. The copying process will be simple enough once you have a list of machine names over which to iterate. From a command prompt, you could redirect NET VIEW to a file to get a list of machine names (manual cleanup required). i.e. C:\>NET VIEW > MACHINES.TXT To get the list Pythonically, you need ActivePython or the win32 extensions. Then you'd use the win32net module's NetServerEnum() function to get the names (programmatic cleanup required). Hint: look in \Python\win32\Lib\win32netcon.py for the SV_TYPE_* values. The shutil module has the copy() function that you'll want to use. From ignacio@openservices.net Wed Sep 19 23:08:00 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 19 Sep 2001 18:08:00 -0400 (EDT) Subject: [Tutor] Commenting a big block of code In-Reply-To: <3BA8629F.62B9D344@india.ti.com> Message-ID: On Wed, 19 Sep 2001, Girish Gajwani wrote: > Is there any "Block Comment" feature or perhaps someone > would just send me a VIM macro which I can use to select a > block of code in visual mode & then use some key mapped to > the macro & within a blink of an eye find all the lines > commented out. Well, I bothered to go and do the research (and upgrade to vim 6.0aw in the process), and here's what I came up with. Add the following lines to your .vimrc: --- vmap :-1/^#/s/// vmap :-1/^/s//#/ --- Go into visual mode, select the block, then press F12 to comment the block or press F11 to uncomment the block. -- Ignacio Vazquez-Abrams From rufmetal@home.com Thu Sep 20 03:29:03 2001 From: rufmetal@home.com (Chris Keelan) Date: Wed, 19 Sep 2001 21:29:03 -0500 Subject: [Tutor] getopt examples Message-ID: <01091921290300.00996@tygesen> I've been scratching my head over the getopt module. I read the documentation and even scoured the source but can't quite figger out how the dang thing works. Anyone got a good code sample using getopt to take optional command line arguments for a script? Thanks in advance. - Chris From lumbricus@gmx.net Thu Sep 20 04:17:20 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Thu, 20 Sep 2001 05:17:20 +0200 Subject: [Tutor] getopt examples In-Reply-To: <01091921290300.00996@tygesen>; from rufmetal@home.com on Wed, Sep 19, 2001 at 09:29:03PM -0500 References: <01091921290300.00996@tygesen> Message-ID: <20010920051720.A2555@Laplace.localdomain> On Wed, Sep 19, 2001 at 09:29:03PM -0500, Chris Keelan wrote: > I've been scratching my head over the getopt module. I read the documentation > and even scoured the source but can't quite figger out how the dang thing > works. Anyone got a good code sample using getopt to take optional command > line arguments for a script? For example "http://www.lowerstandard.com/python/strings.py" uses getopt. I am sure, there are more :-) > > Thanks in advance. > > - Chris > HTH,HAND Greets J"o! -- Truth never comes into the world but like a bastard, to the ignominy of him that brought her birth. -- Milton From ajaya@ncoretech.com Thu Sep 20 05:02:42 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Thu, 20 Sep 2001 09:32:42 +0530 Subject: [Tutor] More re IDLE in Linux---Thanks In-Reply-To: <4.2.0.58.20010918074339.00bfeb30@pop3.norton.antivirus> Message-ID: <000901c14189$192b5600$6501a8c0@ncoretech.com> Thanks allot now I am havig good development environment on Linux too.., It might have taken more time with out your help.., Thanks and Regards, Ajaya -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Kirby Urner Sent: Tuesday, September 18, 2001 8:19 PM To: tutor@python.org Cc: ajaya@ncoretech.com Subject: [Tutor] More re IDLE in Linux I should add that if you want to use IDLE in Linux you may find that the default font it gives you is too small. You can mess with default fonts in some defaults file to make it bigger. Also, if you ./configure, make, make install a version of Python, it may not put an IDLE in place for you automatically. The files you download will have it in a subdirectory of the original tarball called /Tools I think it is. Use Linux 'find' (one suggestion) to locate the IDLE stuff. Then copy "it" (a whole subdirectory actually) to the appropriate place on your directory tree. Kirby At 07:32 AM 9/18/2001 -0700, Kirby Urner wrote: >At 02:12 PM 9/18/2001 +0530, Ajaya Babu wrote: > >>Hi All, >> >>I am using python on windows with IDLE but I want >>to shift to Linux permanently. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From dyoo@hkn.eecs.berkeley.edu Thu Sep 20 07:48:40 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Wed, 19 Sep 2001 23:48:40 -0700 (PDT) Subject: [Tutor] getopt examples In-Reply-To: <01091921290300.00996@tygesen> Message-ID: On Wed, 19 Sep 2001, Chris Keelan wrote: > I've been scratching my head over the getopt module. I read the documentation > and even scoured the source but can't quite figger out how the dang thing > works. Anyone got a good code sample using getopt to take optional command > line arguments for a script? Hi Chris! I have a small example that uses getopt here: http://hkn.eecs.berkeley.edu/~dyoo/python/mmixviewer.py I use it in the __main__ of my code. Here's a brief fragment that should get you started: ### options, args = getopt(argv[1:], 'bmcl', 'help') for o, a in options: if o == '--help': _help() if o == '-l': linenumbering = 0 ### Hope this helps! From neilb@nbt.co.za Thu Sep 20 09:37:53 2001 From: neilb@nbt.co.za (Neil Beattie) Date: Thu, 20 Sep 2001 10:37:53 +0200 Subject: [Tutor] Printing to a windows network printer Message-ID: Hi, I am a newbie to Python and am looking for a pointer to example code for printing from PythonWin 2.1.1 to a network printer from nt. Thanks, Neil From danny.kohn@systematik.se Thu Sep 20 10:11:46 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Thu, 20 Sep 2001 11:11:46 +0200 Subject: [Tutor] Why use tuples? Message-ID: What I understand about the difference in functionality between lists = and tuples is that tuples are restricted lists. But what why would I = want to use tuples? What is the benifit? H=E4lsningar / Regards (\_/) )) Danny Kohn Tel: +46 (0)708 140 300 =3D('.')=3D// Miau! Systematik Consulting AB ICQ: 1328817 ( ~~~ )/ Rrrrrui! http://www.systematik.se HAM: SM0NBJ `w---w=B4=20 From SBrunning@trisystems.co.uk Thu Sep 20 10:26:31 2001 From: SBrunning@trisystems.co.uk (Simon Brunning) Date: Thu, 20 Sep 2001 10:26:31 +0100 Subject: [Tutor] Why use tuples? Message-ID: <31575A892FF6D1118F5800600846864D78C1AA@intrepid> > From: Danny Kohn [SMTP:danny.kohn@systematik.se] > What I understand about the difference in functionality between lists and > tuples is that tuples are restricted lists. But what why would I want to > use tuples? What is the benifit? See on the FAQ. What this *doesn't* seem to mention is that you can use an immutable tuple as the key of a dictionary, whereas you cannot use a mutable list. Cheers, Simon Brunning TriSystems Ltd. sbrunning@trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From cerulean_rodent@yahoo.co.uk Thu Sep 20 12:00:31 2001 From: cerulean_rodent@yahoo.co.uk (Cerulean Rodent) Date: Thu, 20 Sep 2001 15:00:31 +0400 (MSD) Subject: [Tutor] os.system refuses to print from a script Message-ID: Some data is written to file as the script goes about its business. Printing the file from command line with lpr filename works just fine. Invoke the interpreter from the command line, get a familiar prompt. Enter the following import os os.system('lpr filename') the file gets printed without a glitch. do the same from the script, and I get lpr: unable to print file: client-error-bad-request change os.system('lpr filename') for os.system('pwd') to check whether I'm in the correct directory... I am. But lpr still returns an error when invoked from a script (and so does lp, for that matter). I am probably overlooking something important - any ideas? Cheerio, PM XXIII PS By the by, just how does one dump the results of one's meek attempts at programming to Useless Python? Is it still available? All the links Google returns for "useless python" are as dead as Spandau Ballet. ----------------------------------------------------- " The stars go waltzing out in blue and red, And arbitrary blackness gallops in: I shut my eyes and all the world drops dead. " --Sylvia Plath ----------------------------------------------------- From gyromagnetic@excite.com Thu Sep 20 11:59:54 2001 From: gyromagnetic@excite.com (Leona Euler) Date: Thu, 20 Sep 2001 03:59:54 -0700 (PDT) Subject: [Tutor] capturing 'print'ed output and manipulating it Message-ID: <6971677.1000983594516.JavaMail.imail@pokemon.excite.com> Hi, I'm calling a function written by someone else. This function basically produces its output through a series of 'print' statements. I would like to capture this output and manipulate it. To this end, I have written a wrapper function that redirects stdout coming from the function into a StringIO object like so: def funcwrap(foo, arg): import sys, StringIO saved_stdout = sys.stdout sbuf = StringIO.StringIO() sys.stdout = sbuf # redirect stdout to the stringio object foo(arg) # call function. output should now go into sbuf result = sbuf.getvalue() sys.stdout = saved_stdout # clean up sbuf.close() return result Is there a more efficient or direct way to do this? Thanks. -Brad _______________________________________________________ http://inbox.excite.com From non-feedback-1@lb.bcentral.com Thu Sep 20 12:48:41 2001 From: non-feedback-1@lb.bcentral.com (Âçàèìîâûãäíîå ñîòðóäíè÷åñòâî.) Date: 20 Sep 2001 11:48:41 -0000 Subject: [Tutor] Îòâåò íà çàïðîñ î ïðîäàæå è ïîêóïêå ïðîäóêöèè Message-ID: <1000986521.16128.qmail@ech> Óâàæàåìûå ãîñïîäà! Îðãàíèçàöèÿ ÎÎÎ “ÂÈÝËÜ-Ì” ïðåäëàãàåò Âàøåìó âíèìàíèþ ÷åòûðå âèäà íàøåé äåÿòåëüíîñòè: Ðàäèîýëåêòðîííûå êîìïëåêòóþùèå, ñâàðî÷íûå ýëåêòðîäû(à òàêæå àïïàðàòû ãàçâîäû), ìåòàëë è ýëåêòðîòåõíè÷åñêóþ ïðîäóêöèþ(ñþäà âõîäèò ïðîäàæà ëþñòðû ×èæåâñêîãî). Áîëåå ïîäðîáíî îçíàêîìèòüñÿ ñ íàøåé ïðîäóêöèåé, Âû ìîæåòå íà íàøåì ñàéòå â èíòåðíåò: www.viel.f2s.com Áëàãîäàðÿ îáøèðíûì ñâÿçÿì ñ âåäóùèìè ïðîèçâîäèòåëÿìè è ïîñòàâùèêàìè íå òîëüêî â Ðîññèè, íî è çà ðóáåæîì, ìû èìååì âîçìîæíîñòü âûïîëíÿòü Âàøè çàêàçû íàèáîëåå ïîëíî è â êðàò÷àéøèå ñðîêè. Îáëàñòü ýëåêòðîíèêè, ýòî íå òîëüêî ïîñòàâêè ïðèáîðîâ, àïïàðàòóðû, íî è ðàçëè÷íûå êîìïëåêòóþùèå êàê îòå÷åñòâåííûõ, òàê è çàðóáåæíûõ ïðîèçâîäèòåëåé ýëåêòðîííîé òåõíèêè. Ýòî òàêèå ôèðìû êàê International Rectifier, Epcos, Bourns, Metex, unit-t è äð. Ñâàðî÷íûå ýëåêòðîäû: ìû ïðîäà¸ì ýëåêòðîäû îò âåäóùèõ îòå÷åñòâåííûõ ïðîèçâîäèòåëåé. Âñå ñâàðî÷íûå ýëåêòðîäû ñîîòâåòñòâóþò ÃÎÑÒó è èìåþò ñåðòèôèêàò êà÷åñòâà. Àïïàðàòû ãàçèðîâàííîé âîäû: ÀÃÂ, ÀÂ-2,ÀÂ-3, POST-MIX è äð. äëÿ îõëàæäåíèÿ è âûäà÷è ãàçèðîâàííûõ íàïèòêîâ â îôèñàõ, “ãîðÿ÷èõ” öåõàõ, íà ïðåäïðèÿòèÿõ è ò.ä. Ìåòàëë : Ïðåäëàãàåì Õ/Ê è Ã/Ê ëèñòîâîé ìåòàëëîïðêàò. Ñâåòèëüíèêè: Ïî ñàìûì íèçêèì öåíàì äëÿ äîìà,îôèñà, ñêâåðîâ è ïàðêîâ.  íàñòîÿùåå âðåìÿ ìû ïðåäëàãàåì óíèêàëüíóþ ðàçðàáîòêó îòå÷åñòâåííûõ ó÷åíûõ:êîìïåíñèðóþùèå ïàòðóáêè äëÿ áåçñâàðíîãî ñîåäèíåíèÿ òðóá!!!(D îò 25 äî 1000ìì.) Íàøè ìåíåäæåðû èìåþò áîãàòûé îïûò ïðîäàæ, ìàðêåòèíãîâûõ èññëåäîâàíèé,âåäåíèÿ ïåðåãîâîðîâ ñ êðóïíûìè ïîñòàâùèêàìè è ïîòðåáèòåëÿìè òîâàðîâ,÷òî ïîçâîëÿåò íàì äîñòàòü íóæíóþ Âàì ïðîäóêöèþ ïî âûãîäíûì äëÿ Âàñ öåíàì è â îïòèìàëüíî êîðîòêèå ñðîêè. Âàøó ïîòðåáíîñòü â ïðîäóêöèè ïðåäñòàâëåííîé íà íàøåì ñàéòå, ìîæíî îòïðàâèòü íà íàø ôàêñ: (095) 275-89-94, èëè ïî ýëåêòðîííîé ïî÷òå: vielmos@yahoo.com Ìû æäåì Âàñ è âûðàæàåì óâåðåííîñòü â òîì, ÷òî îáðàòèâøèñü ê íàì, Âû ïîëó÷èòå êâàëèôèöèðîâàííóþ ïîìîùü, âíèìàòåëüíîå îòíîøåíèå ê Âàøèì ïîòðåáíîñòÿì, îïåðàòèâíóþ îáðàáîòêó Âàøåãî çàêàçà. Ïî âñåì âîïðîñàì âû ìîæåòå îáðàùàòüñÿ ïî òåëåôîíàì â ã. Ìîñêâà: (095) 275-89-94, 746-68-78. _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=15203&subid=13B28172795AED1F&msgnum=1 From ajaya@ncoretech.com Thu Sep 20 13:18:56 2001 From: ajaya@ncoretech.com (Anne Ajaya Babu) Date: Thu, 20 Sep 2001 17:48:56 +0530 Subject: [Tutor] How to spawn python appliation from C interface in Linux Message-ID: <3BA9DEB0.B4DE6E83@ncoretech.com> Hi All, I want to spawn the Python GUI appliation from C in linux. I am very new to liux. What actually I want is I want to run the python appliation..., after successfully started that application I should get the control. How can I do this in linux. Thanks allot, with regards, Ajaya From baza_all@email.com Thu Sep 20 16:45:59 2001 From: baza_all@email.com (All emails) Date: Thu, 20 Sep 2001 18:45:59 +0300 Subject: [Tutor] Databases !!! Message-ID: Íîâåéøèå ýêñêëþçèâíûå àâòîðñêèå ñåðòèôèöèðîâàííûå áàçû äàííûõ ýëåêòðîííûõ àäðåñîâ (Email) ñ ïðîãðàììîé ðàññûëêè: - "ôèðìû Ìîñêâû" - 22.500 àäðåñîâ (ñî âñòðîåííûì ðóáðèêàòîðîì) = 50$ - "âñå Emailû Ìîñêâû" - 42.000 àäðåñîâ (ïðåäûäóùèå ôèðìû + 19.500 áåç ðàçáèâêè) =70$ - "ôèðìû Ñàíêò-Ïåòåðáóðãà" (ñî âñòðîåííûì ðóáðèêàòîðîì) = 50$ - "ôèðìû Ðîññèè" (ñî âñòðîåííûì ðóáðèêàòîðîì) = 50$ - "ôèðìû ÑÍÃ" (ñî âñòðîåííûì ðóáðèêàòîðîì) = 50$ - "200.000 ýëåêòðîííûõ àäðåñîâ Ðîññèè è ÑÍÃ" (áåç ðàçáèâêè) = 50$ moscow_email@email.com From non-feedback-2@lb.bcentral.com Thu Sep 20 18:45:01 2001 From: non-feedback-2@lb.bcentral.com (Âçàèìîâûãäíîå ñîòðóäíè÷åñòâî.) Date: 20 Sep 2001 17:45:01 -0000 Subject: [Tutor] ïÔ×ÅÔ ÎÁ ÚÁÐÒÏÓ Ï ÐÒÏÄÁÖÅ É ÐÏËÕÐËÅ ÐÒÏÄÕËÃÉÉ Message-ID: <1001007901.5208.qmail@ech> kodirovra KOI-8R ili Kirilica(windows) õ×ÁÖÁÅÍÙÅ ÇÏÓÐÏÄÁ! ïÒÇÁÎÉÚÁÃÉÑ ïïï “÷éüìø-í” ÐÒÅÄÌÁÇÁÅÔ ÷ÁÛÅÍÕ ×ÎÉÍÁÎÉÀ ÞÅÔÙÒÅ ×ÉÄÁ ÎÁÛÅÊ ÄÅÑÔÅÌØÎÏÓÔÉ: òÁÄÉÏÜÌÅËÔÒÏÎÎÙÅ ËÏÍÐÌÅËÔÕÀÝÉÅ, Ó×ÁÒÏÞÎÙÅ ÜÌÅËÔÒÏÄÙ(Á ÔÁËÖÅ ÁÐÐÁÒÁÔÙ ÇÁÚ×ÏÄÙ), ÍÅÔÁÌÌ É ÜÌÅËÔÒÏÔÅÈÎÉÞÅÓËÕÀ ÐÒÏÄÕËÃÉÀ(ÓÀÄÁ ×ÈÏÄÉÔ ÐÒÏÄÁÖÁ ÌÀÓÔÒÙ þÉÖÅ×ÓËÏÇÏ). âÏÌÅÅ ÐÏÄÒÏÂÎÏ ÏÚÎÁËÏÍÉÔØÓÑ Ó ÎÁÛÅÊ ÐÒÏÄÕËÃÉÅÊ, ÷Ù ÍÏÖÅÔÅ ÎÁ ÎÁÛÅÍ ÓÁÊÔÅ × ÉÎÔÅÒÎÅÔ: www.viel.f2s.com . âÌÁÇÏÄÁÒÑ ÏÂÛÉÒÎÙÍ Ó×ÑÚÑÍ Ó ×ÅÄÕÝÉÍÉ ÐÒÏÉÚ×ÏÄÉÔÅÌÑÍÉ É ÐÏÓÔÁ×ÝÉËÁÍÉ ÎÅ ÔÏÌØËÏ × òÏÓÓÉÉ, ÎÏ É ÚÁ ÒÕÂÅÖÏÍ, ÍÙ ÉÍÅÅÍ ×ÏÚÍÏÖÎÏÓÔØ ×ÙÐÏÌÎÑÔØ ÷ÁÛÉ ÚÁËÁÚÙ ÎÁÉÂÏÌÅÅ ÐÏÌÎÏ É × ËÒÁÔÞÁÊÛÉÅ ÓÒÏËÉ. ïÂÌÁÓÔØ ÜÌÅËÔÒÏÎÉËÉ, ÜÔÏ ÎÅ ÔÏÌØËÏ ÐÏÓÔÁ×ËÉ ÐÒÉÂÏÒÏ×, ÁÐÐÁÒÁÔÕÒÙ, ÎÏ É ÒÁÚÌÉÞÎÙÅ ËÏÍÐÌÅËÔÕÀÝÉÅ ËÁË ÏÔÅÞÅÓÔ×ÅÎÎÙÈ, ÔÁË É ÚÁÒÕÂÅÖÎÙÈ ÐÒÏÉÚ×ÏÄÉÔÅÌÅÊ ÜÌÅËÔÒÏÎÎÏÊ ÔÅÈÎÉËÉ. üÔÏ ÔÁËÉÅ ÆÉÒÍÙ ËÁË International Rectifier, Epcos, Bourns, Metex, unit-t É ÄÒ. ó×ÁÒÏÞÎÙÅ ÜÌÅËÔÒÏÄÙ: ÍÙ ÐÒÏÄÁ£Í ÜÌÅËÔÒÏÄÙ ÏÔ ×ÅÄÕÝÉÈ ÏÔÅÞÅÓÔ×ÅÎÎÙÈ ÐÒÏÉÚ×ÏÄÉÔÅÌÅÊ. ÷ÓÅ Ó×ÁÒÏÞÎÙÅ ÜÌÅËÔÒÏÄÙ ÓÏÏÔ×ÅÔÓÔ×ÕÀÔ çïóôÕ É ÉÍÅÀÔ ÓÅÒÔÉÆÉËÁÔ ËÁÞÅÓÔ×Á. áÐÐÁÒÁÔÙ ÇÁÚÉÒÏ×ÁÎÎÏÊ ×ÏÄÙ: áç÷, á÷-2,á÷-3, POST-MIX É ÄÒ. ÄÌÑ ÏÈÌÁÖÄÅÎÉÑ É ×ÙÄÁÞÉ ÇÁÚÉÒÏ×ÁÎÎÙÈ ÎÁÐÉÔËÏ× × ÏÆÉÓÁÈ, “ÇÏÒÑÞÉÈ” ÃÅÈÁÈ, ÎÁ ÐÒÅÄÐÒÉÑÔÉÑÈ É Ô.Ä. íÅÔÁÌÌ : ðÒÅÄÌÁÇÁÅÍ è/ë É ç/ë ÌÉÓÔÏ×ÏÊ ÍÅÔÁÌÌÏÐÒËÁÔ. ó×ÅÔÉÌØÎÉËÉ: ðÏ ÓÁÍÙÍ ÎÉÚËÉÍ ÃÅÎÁÍ ÄÌÑ ÄÏÍÁ,ÏÆÉÓÁ, ÓË×ÅÒÏ× É ÐÁÒËÏ×. îÁÛÉ ÍÅÎÅÄÖÅÒÙ ÉÍÅÀÔ ÂÏÇÁÔÙÊ ÏÐÙÔ ÐÒÏÄÁÖ, ÍÁÒËÅÔÉÎÇÏ×ÙÈ ÉÓÓÌÅÄÏ×ÁÎÉÊ,×ÅÄÅÎÉÑ ÐÅÒÅÇÏ×ÏÒÏ× Ó ËÒÕÐÎÙÍÉ ÐÏÓÔÁ×ÝÉËÁÍÉ É ÐÏÔÒÅÂÉÔÅÌÑÍÉ ÔÏ×ÁÒÏ×,ÞÔÏ ÐÏÚ×ÏÌÑÅÔ ÎÁÍ ÄÏÓÔÁÔØ ÎÕÖÎÕÀ ÷ÁÍ ÐÒÏÄÕËÃÉÀ ÐÏ ×ÙÇÏÄÎÙÍ ÄÌÑ ÷ÁÓ ÃÅÎÁÍ É × ÏÐÔÉÍÁÌØÎÏ ËÏÒÏÔËÉÅ ÓÒÏËÉ. ÷ÁÛÕ ÐÏÔÒÅÂÎÏÓÔØ × ÐÒÏÄÕËÃÉÉ ÐÒÅÄÓÔÁ×ÌÅÎÎÏÊ ÎÁ ÎÁÛÅÍ ÓÁÊÔÅ, ÍÏÖÎÏ ÏÔÐÒÁ×ÉÔØ ÎÁ ÎÁÛ ÆÁËÓ: (095) 275-89-94, ÉÌÉ ÐÏ ÜÌÅËÔÒÏÎÎÏÊ ÐÏÞÔÅ: vielmos@yahoo.com íÙ ÖÄÅÍ ÷ÁÓ É ×ÙÒÁÖÁÅÍ Õ×ÅÒÅÎÎÏÓÔØ × ÔÏÍ, ÞÔÏ ÏÂÒÁÔÉ×ÛÉÓØ Ë ÎÁÍ, ÷Ù ÐÏÌÕÞÉÔÅ Ë×ÁÌÉÆÉÃÉÒÏ×ÁÎÎÕÀ ÐÏÍÏÝØ, ×ÎÉÍÁÔÅÌØÎÏÅ ÏÔÎÏÛÅÎÉÅ Ë ÷ÁÛÉÍ ÐÏÔÒÅÂÎÏÓÔÑÍ, ÏÐÅÒÁÔÉ×ÎÕÀ ÏÂÒÁÂÏÔËÕ ÷ÁÛÅÇÏ ÚÁËÁÚÁ. ðÏ ×ÓÅÍ ×ÏÐÒÏÓÁÍ ×Ù ÍÏÖÅÔÅ ÏÂÒÁÝÁÔØÓÑ ÐÏ ÔÅÌÅÆÏÎÁÍ × Ç. íÏÓË×Á: (095) 275-89-94, 746-68-78. _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=15203&subid=589A002D010757E8&msgnum=2 From danny.kohn@systematik.se Thu Sep 20 18:54:29 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Thu, 20 Sep 2001 19:54:29 +0200 Subject: SV: [Tutor] Why use tuples? In-Reply-To: <31575A892FF6D1118F5800600846864D78C1AA@intrepid> Message-ID: | -----Ursprungligt meddelande----- | Fr=E5n: Simon Brunning [mailto:SBrunning@trisystems.co.uk] | Skickat: den 20 september 2001 11:27 | > From: Danny Kohn [SMTP:danny.kohn@systematik.se] | > What I understand about the difference in functionality between=20 | lists and | > tuples is that tuples are restricted lists. But what why would I = want to | > use tuples? What is the benifit? | =20 | See on the FAQ. |=20 | What this *doesn't* seem to mention is that you can use an immutable = tuple | as the key of a dictionary, whereas you cannot use a mutable list. Ok. But then again I can not use a tuple as an index which would have = been natural for me to be able to with a datatype of this nature. So = does the statement if col[ColType] =3D=3D IU32: where ColType is a tuple does not work. It is counter intuitive but I = guess I have to get used to not using tuples. Thanks anyhow. /Danny From ignacio@openservices.net Thu Sep 20 19:03:27 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 20 Sep 2001 14:03:27 -0400 (EDT) Subject: SV: [Tutor] Why use tuples? In-Reply-To: Message-ID: On Thu, 20 Sep 2001, Danny Kohn wrote: > Ok. But then again I can not use a tuple as an index which would have been natural for me to be able to with a datatype of this nature. So does the statement > > if col[ColType] == IU32: > > where ColType is a tuple does not work. It is counter intuitive but I guess I have to get used to not using tuples. Have you _tried_ using a tuple as an index? --- >>> a={} >>> a[(1,2)]=3 >>> a {(1, 2): 3} >>> --- -- Ignacio Vazquez-Abrams From danny.kohn@systematik.se Thu Sep 20 21:08:14 2001 From: danny.kohn@systematik.se (Danny Kohn) Date: Thu, 20 Sep 2001 22:08:14 +0200 Subject: SV: SV: [Tutor] Why use tuples? In-Reply-To: Message-ID: Excuse be for being ignorant but this is the tutor group :-) | -----Ursprungligt meddelande----- | Fran: tutor-admin@python.org [mailto:tutor-admin@python.org]For = Ignacio | Vazquez-Abrams | Skickat: den 20 september 2001 20:03 | > Ok. But then again I can not use a tuple as an index which=20 | would have been natural for me to be able to with a datatype of=20 | this nature. So does the statement | > | > if col[ColType] =3D=3D IU32: | > | > where ColType is a tuple does not work. It is counter intuitive=20 | but I guess I have to get used to not using tuples. |=20 | Have you _tried_ using a tuple as an index? Yes, in the above example. It didn't work out. Your example below is = with a dictionary. I understand that it works there. But does it work = generally thorughout Python and if so, how do I get it to work? I = expected that it would make no difference to Python if ColType is an = integer, a list element or a tuple. If this is so, please enlighten me. =20 | --- | >>> a=3D{} | >>> a[(1,2)]=3D3 | >>> a | {(1, 2): 3} | >>> /Danny From ajaya@ncoretech.com Thu Sep 20 21:55:33 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Fri, 21 Sep 2001 02:25:33 +0530 Subject: [Tutor] sockets In-Reply-To: Message-ID: <000a01c14216$97692a50$6501a8c0@ncoretech.com> Hi, I've not understand this problem fully. I really confused what is going wrong.But any way I presume....that you are using sockets as a pipe to send info between two process. For this they are many ways. One way of doing this is using client server model using TCP sockets. It gives reliable flow of information between end points. Simple way of doing this is take one port common in both process make a server in one thread like this from socket import * HOST = '' #this is correct server will accept any host..., PORT = 21568 BUFSIZ = 1024 ServerSocket = socket(AF_INET, SOCK_STREAM) ServerSocket.bind((HOST, PORT)) #it takes tuple...as input ServerSocket.listen() while 1: data = ServerSocket.recv(BUFSIZ) #it is just a example print data ServerSocket.send(data) and in another process make a client like this from socket import * HOST = 'localhost' PORT = 21568 BUFSIZ = 1024 ClientSocket = socket(AF_INET, SOCK_STREAM) ClientSocket.connect((HOST, PORT)) while 1: data = raw_input('>') ClientSocket.send(data) Some precautions..., 1. First you make sure that server starts ...this ensures that smooth establishment of connections between these two. 2. Add your program to above server and client..., other wise it looks like it got hung..., 3. Implement some kind of protocl between these two process I mean how to shutdown the connection...and close..., what I do is I send command from client to server or server to client then I close this connections dipend on my data..., Hope this helps..., If you have any specific doubt feel free. with regards, Ajaya babu -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Ravikumar Devarajan Sent: Wednesday, September 19, 2001 10:35 PM To: tutor@python.org Subject: [Tutor] sockets hi all, im trying to do the following in python i have 2 processes.i need them to communicate.and they will have to send and receive stuff till i close the connection.somehow this doesnt seem to work.im using sockets. and i want to know if theres any way by which i can keep the connection open as long as i want.i wud really appreciate any help in this regard. thanks Ravikumar Make a difference, help support the relief efforts in the U.S. http://clubs.lycos.com/live/events/september11.asp _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From ignacio@openservices.net Thu Sep 20 22:09:55 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 20 Sep 2001 17:09:55 -0400 (EDT) Subject: SV: SV: [Tutor] Why use tuples? In-Reply-To: Message-ID: On Thu, 20 Sep 2001, Danny Kohn wrote: > Excuse be for being ignorant but this is the tutor group :-) > > | -----Ursprungligt meddelande----- > | Fran: tutor-admin@python.org [mailto:tutor-admin@python.org]For Ignacio > | Vazquez-Abrams > | Skickat: den 20 september 2001 20:03 > > | > Ok. But then again I can not use a tuple as an index which > | would have been natural for me to be able to with a datatype of > | this nature. So does the statement > | > > | > if col[ColType] == IU32: > | > > | > where ColType is a tuple does not work. It is counter intuitive > | but I guess I have to get used to not using tuples. > | > | Have you _tried_ using a tuple as an index? > > Yes, in the above example. It didn't work out. Your example below is with a dictionary. I understand that it works there. But does it work generally thorughout Python and if so, how do I get it to work? I expected that it would make no difference to Python if ColType is an integer, a list element or a tuple. If this is so, please enlighten me. Ah, I see what you mean. All sequence types (lists, tuples, or strings) can only use integers or slices for indexes. Dictionaries can use any immutable type (integers, strings, or tuples). -- Ignacio Vazquez-Abrams From dyoo@hkn.eecs.berkeley.edu Thu Sep 20 22:55:20 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 20 Sep 2001 14:55:20 -0700 (PDT) Subject: [Tutor] Why use tuples? In-Reply-To: Message-ID: On Thu, 20 Sep 2001, Danny Kohn wrote: > What I understand about the difference in functionality between lists > and tuples is that tuples are restricted lists. It's a little safer to say that tuples and lists are both "sequences", things that have elements that we're able to pull out. Strings are also sequences, so all of these work: ### >>> for x in (1, 2, 3): print x ... 1 2 3 >>> for x in [1, 2, 3]: print x ... 1 2 3 >>> for x in "123": print x ... 1 2 3 ### Tuples conceptually do a similar thing with lists: they are containers that hold values. > But what why would I want to use tuples? What is the benefit? Good question. Python actually does quite a bunch of tuple stuff behind our backs. For example, when we do something like this: ### >>> x, y = 1, 2 >>> x 1 >>> y 2 ### ... that's all tuples in the background doing the work. What's happening above is called "tuple assignment" because Python first constructs the tuple (1, 2), and then pairwise assigns each value to its corresponding variable. Python also uses tuples whenever we want to return multiple values from a function: ### >>> def quadraticSolver(a, b, c): ... """This is a function that solves the quadradic equation, ... ax**2 + bx + c = 0""" ... discriminant = math.sqrt(b**2 - 4 * a * c) ... return (-b + discriminant)/(2*a), (-b - discriminant)/(2*a) >>> quadraticSolver(5, 2, -3) (0.59999999999999998, -1.0) ### So tuples can be used by Python to quickly stuff multiple things into a "single" container. It's true that lists have more capabilities than tuples, but there's something of an additional cost to them: they're more complicated because they can do so much. Lists have... let's see... ### >>> dir([]) ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] ### ... quite a few methods we can play with. Tuples don't, but sometimes simplicity is a good thing. Compared to lists, tuples are very "lightweight": they support the very minimum that a "sequence" should do, and because of that, they're computationally cheaper to work with. Tuples also correspond nicely with the mathematical concept by the same name, so if you're a mathematician, you'll feel right at home. *grin* But it's not necessarily a terrible thing if we get a tuple and want it as a list: it's actually easy to go from tuples to lists and vice versa because Python gives us a bunch of type-converting functions: ### >>> secret_message = "hello world" >>> list(secret_message) ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] >>> tuple(secret_message) ('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd') >>> list(tuple(list(secret_message))) ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] >>> ''.join(list(tuple(list(secret_message)))) 'hello world' ### If you have more questions, please feel free to ask. From dyoo@hkn.eecs.berkeley.edu Thu Sep 20 23:02:48 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 20 Sep 2001 15:02:48 -0700 (PDT) Subject: SV: SV: [Tutor] Why use tuples? In-Reply-To: Message-ID: On Thu, 20 Sep 2001, Ignacio Vazquez-Abrams wrote: > > | > Ok. But then again I can not use a tuple as an index which > > | would have been natural for me to be able to with a datatype of > > | this nature. So does the statement > > | > > > | > if col[ColType] == IU32: > > | > > > | > where ColType is a tuple does not work. It is counter intuitive > > | but I guess I have to get used to not using tuples. > > | > > | Have you _tried_ using a tuple as an index? > > > > Yes, in the above example. It didn't work out. Your example below is with a dictionary. I understand that it works there. But does it work generally thorughout Python and if so, how do I get it to work? I expected that it would make no difference to Python if ColType is an integer, a list element or a tuple. If this is so, please enlighten me. > > Ah, I see what you mean. > > All sequence types (lists, tuples, or strings) can only use integers > or slices for indexes. Dictionaries can use any immutable type > (integers, strings, or tuples). Yes. One way we can see this is by trying: ### >>> train_station = range(11) >>> train_station [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> train_station[9.75] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer ### It's very difficult to get to train_station Nine and Three Quarters without magic... From ignacio@openservices.net Thu Sep 20 23:11:47 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 20 Sep 2001 18:11:47 -0400 (EDT) Subject: SV: SV: [Tutor] Why use tuples? In-Reply-To: Message-ID: On Thu, 20 Sep 2001, Danny Yoo wrote: > ### > >>> train_station = range(11) > >>> train_station > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > >>> train_station[9.75] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: sequence index must be integer > ### > > It's very difficult to get to train_station Nine and Three Quarters > without magic... Time to call Mr. Conductor! (Sorry, I _had_ to say that ;) ) -- Ignacio Vazquez-Abrams From dyoo@hkn.eecs.berkeley.edu Fri Sep 21 00:34:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 20 Sep 2001 16:34:16 -0700 (PDT) Subject: [Tutor] How to spawn python appliation from C interface in Linux In-Reply-To: <3BA9DEB0.B4DE6E83@ncoretech.com> Message-ID: On Thu, 20 Sep 2001, Anne Ajaya Babu wrote: > I want to spawn the Python GUI appliation from C in linux. I am very new > to liux. What actually I want is I want to run the python appliation..., > after successfully started that application I should get the control. > How can I do this in linux. Hmmm... will the C system() call be appropriate for this? Try: man 3 system at your command prompt, and documentation about the C system() call should pop up. I'm not sure if this is what you're looking for though. system() should allow you to run your Python program from C, and since your program is graphical, you might want to run it in the "background". On Unix, you can tell the system to run something in the background by appending a '&' at the end of the command. For example: $ do_hefty_processing & One question: why do you want to run a Python program from C? Good luck! From dyoo@hkn.eecs.berkeley.edu Fri Sep 21 00:39:08 2001 From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo) Date: Thu, 20 Sep 2001 16:39:08 -0700 (PDT) Subject: [Tutor] capturing 'print'ed output and manipulating it In-Reply-To: <6971677.1000983594516.JavaMail.imail@pokemon.excite.com> Message-ID: On Thu, 20 Sep 2001, Leona Euler wrote: > I'm calling a function written by someone else. This function basically > produces its output through a series of 'print' statements. I would like to > capture this output and manipulate it. To this end, I have written a wrapper > function that redirects stdout coming from the function into a StringIO > object like so: > > def funcwrap(foo, arg): > import sys, StringIO > saved_stdout = sys.stdout > sbuf = StringIO.StringIO() > sys.stdout = sbuf # redirect stdout to the stringio > object > foo(arg) # call function. output should now > go into sbuf > result = sbuf.getvalue() > sys.stdout = saved_stdout # clean up > sbuf.close() > return result > > Is there a more efficient or direct way to do this? Hmmm... I can't think of one offhand. This wrapper looks good. If we want it to work on functions that can take multiple arguments, we can generalize funcwrap() like this: ### def funcwrap(foo, *args, **kwargs): import sys, StringIO saved_stdout = sys.stdout sbuf = StringIO.StringIO() sys.stdout = sbuf foo(*args, **kwargs) result = sbuf.getvalue() sys.stdout = saved_stdout sbuf.close() return result ### From fleet@teachout.org Fri Sep 21 01:15:51 2001 From: fleet@teachout.org (fleet@teachout.org) Date: Thu, 20 Sep 2001 20:15:51 -0400 (EDT) Subject: [Tutor] poplib questions Message-ID: The pop3 mail retrieval module constructed from the example in poplib.py (see below) seems to work REALLY well. I have a couple of "newbie" type questions, though: 1. I need the mail to go to my /var/spool/mail/fleet file. (Linux RH 7.1) Where should I open and close the file? Open (for append) just before the "for i in range" statement and close after "a.quit()" as I have it below? Or should I open the file before the first getmail() call in the main program and close it after the last one? Does it make any difference? 2. Is there any reason for the three spaces before each line printed? 3. Do I have the "import" in the correct place or should it be in within the function? 4. Are there any serious security concerns with this script (other than the fact that the account names and passwords are in a text file)? 5. I've inserted some linefeeds, else the messages become one huge long line in the "testbox" file. Is this going to mess up my procmail filter? 6. And, totally off topic, since there are no instructions activating procmail in my fetchmail script, I'm assuming that procmail "guards" the /var/spool/mail/fleet file and activates if anything shows up. Am I close? 7. Any suggestions to improve this would be greatly appreciated. - fleet - ++++++++++++++++++++++++++++++++++++++++++++ #! /usr/bin/python import getpass, poplib def getmail(MAILSERVER, USER, PASS): """Retrieves mail from pop3 servers""" a = poplib.POP3(MAILSERVER) # print a.getwelcome() a.user(USER) a.pass_(PASS) a.list() (numMsgs, totalSize) = a.stat() if numMsgs == 0: print "\nNo mail for "+USER+" at "+MAILSERVER return else: print "Retrieving "+`numMsgs`+" messages for "+USER+" at "+MAILSERVER f=open("testbox","a") for i in range(1, numMsgs + 1): (header, msg, octets) = a.retr(i) print "Message ", `i`, "("+`octets`+" octets)", ':' for line in msg: f.write(' ' + line +"\n") print ".", # dele(i) # f.write('\n-----------------------\n') a.quit() f.close() return print "\n\n\n\n" getmail("mail.server.com","fleet","secret") getmail("mail.server.com","fleet1","secret") getmail("mail.server.com","fleet2","secret") getmail("mail.server.com","fleet3","secret") getmail("mail.server.com","fleet4","secret") ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ From ignacio@openservices.net Fri Sep 21 01:36:07 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 20 Sep 2001 20:36:07 -0400 (EDT) Subject: [Tutor] poplib questions In-Reply-To: Message-ID: On Thu, 20 Sep 2001 fleet@teachout.org wrote: > 1. I need the mail to go to my /var/spool/mail/fleet file. (Linux RH 7.1) > Where should I open and close the file? Open (for append) just before the > "for i in range" statement and close after "a.quit()" as I have it below? > Or should I open the file before the first getmail() call in the main > program and close it after the last one? Does it make any difference? It doesn't matter as long as you expect to be the only program manipulating it. See the answer to question 6 below. > 2. Is there any reason for the three spaces before each line printed? There shouldn't be. > 3. Do I have the "import" in the correct place or should it be in within > the function? It's fine where it is. > 4. Are there any serious security concerns with this script (other than > the fact that the account names and passwords are in a text file)? It accesses the mail file directly, so you could have a problem if more than one program accesses it. See the answer to question 6 below. > 5. I've inserted some linefeeds, else the messages become one huge long > line in the "testbox" file. Is this going to mess up my procmail filter? ? > 6. And, totally off topic, since there are no instructions activating > procmail in my fetchmail script, I'm assuming that procmail "guards" the > /var/spool/mail/fleet file and activates if anything shows up. Am I > close? You're way, way off. When sendmail receives a message destined for a local mailbox, it pipes it through procmail, and it's then procmail's job to open the local mail file and dump the message into it. > 7. Any suggestions to improve this would be greatly appreciated. One thing that fetchmail as written by Eric S. Raymond does is that instead of going through procmail, it dumps it to the local sendmail daemon. You might want to look at using the smtplib module to do the same thing. -- Ignacio Vazquez-Abrams From SWidney@ci.las-vegas.nv.us Fri Sep 21 02:42:00 2001 From: SWidney@ci.las-vegas.nv.us (Scott Widney) Date: Thu, 20 Sep 2001 18:42:00 -0700 Subject: [Tutor] Copying file to multiple machines. Message-ID: > I am not sure if the other e-mail I wrote had gotten through > or not, so I try again. I would like to think I will only > have to do this once, but I doubt it. I am looking at the > shutil.py right now . I thought maybe something like this > could work, open and read src and write to dst? > > import sys > import os > > machines = [ " Machine Names " ] > > source_file_path = sys.argv[1] > dest_path = sys.argv[2] > > source_file = open( source_file_path , "C:\\stuff\\remote.bat" ) > source_data = source_file.read() > source_file.close() > > for dest in machines : > dest_file = open( dest + "/" + dest_path , "\\C$\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup" ) > dest_file.write( source_data ) > dest_file.close() > > > The problem I am having is how to write a, I guess list and for loop for the machines? I have the machine names already and I believe in Perl it would be done like: > > for my $i (1..40) { > > my $machine = 'smbig0'. sprintf('2d,$i'); > > #do copying and stuff > > } > > > > Thank you for your suggestions. > > > > James You're on the right track. Iterating over a list of machine names and appending a pathname and filename is what I'd do.... I tend to do things from the Interactive Prompt, so I don't normally have an argument list to read from; but here's my test run. Notice below that you get the [list of machine names] in three lines that are very similar to the three lines used to get your "source_data".... src = 'C:\\stuff\\remote.bat' machines = 'C:\\stuff\\list-of-names.txt' # The machines file should have one name per line, # including the leading double backslash dest = '\\c$\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\remote.bat' # Read in the whole source file as one big string src_file = open(src, 'r') src_data = src_file.read() src_file.close() # Next, read in the whole machines file, # returning each line as an item in a list machine_file = open(machines, 'r') machine_list = machine_file.readlines() machines.close() # Finally, iterate through your list, # and create your target files for eachPC in machine_list: # Create the file or overwrite an existing copy dest_file = open(eachPC[:-1] + dest, 'w') # The [:-1] slice operator eliminates the # newline character at the end of each item. # Then we append the destination to the name. dest_file.write(src_data) dest_file.close() ----- Scott From ajaya@ncoretech.com Fri Sep 21 02:40:24 2001 From: ajaya@ncoretech.com (Ajaya Babu) Date: Fri, 21 Sep 2001 07:10:24 +0530 Subject: FW: [Tutor] How to spawn python appliation from C interface in Linux Message-ID: <000001c1423e$62c137c0$6501a8c0@ncoretech.com> Thanks allot for your suggestions. >>One question: why do you want to run a Python program from C? I've earlier application..., for that I've added GUI. These two application talk with each other using sockets. Here my Python application i client and C is server.., So I need to start C application first, After I go to the listen mode only I want to start this python application...., It is for demo...to demonstrate that I can write commmercial GUIs in intime using Tkinter.., Ok..., You may ask why cant python applicatin can be server...., Yes It can be.., But I am facing problem with python server mode..., Python select call is not recognizing peersocket as a socket..it was giving exception. earlier I've sent this to our mailing list. My demo is today..., so I changed this for temparaly so that demo goes well. But unfortunately...I've not got any answer for python select fucntin problem. Thanks allot for your great help. with regards, Ajaya -----Original Message----- From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] Sent: Friday, September 21, 2001 5:04 AM To: Anne Ajaya Babu Cc: tutor@python.org Subject: Re: [Tutor] How to spawn python appliation from C interface in Linux On Thu, 20 Sep 2001, Anne Ajaya Babu wrote: > I want to spawn the Python GUI appliation from C in linux. I am very new > to liux. What actually I want is I want to run the python appliation..., > after successfully started that application I should get the control. > How can I do this in linux. Hmmm... will the C system() call be appropriate for this? Try: man 3 system at your command prompt, and documentation about the C system() call should pop up. I'm not sure if this is what you're looking for though. system() should allow you to run your Python program from C, and since your program is graphical, you might want to run it in the "background". On Unix, you can tell the system to run something in the background by appending a '&' at the end of the command. For example: $ do_hefty_processing & One question: why do you want to run a Python program from C? Good luck! From ramprasad@ncoretech.com Fri Sep 21 07:32:14 2001 From: ramprasad@ncoretech.com (ramprasad) Date: Fri, 21 Sep 2001 12:02:14 +0530 Subject: [Tutor] Re:sound in pyhton Message-ID: <000e01c14267$27a7af10$e101a8c0@ncoretech.com> This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C14295.40AE9C70 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello All, I want an sound module in pyhton. Is there any way that i can get the = speaker sound in python. can anybody help or give some comments = regarding this Thanks in advance, Ramprasad ------=_NextPart_000_000B_01C14295.40AE9C70 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
    Hello All,
     
    I want an sound module in pyhton. = Is there any=20 way that i can get the speaker sound in python. can anybody help or give = some=20 comments regarding this
     
     
    Thanks in advance,
    Ramprasad
     
    ------=_NextPart_000_000B_01C14295.40AE9C70-- From ignacio@openservices.net Fri Sep 21 07:45:13 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 21 Sep 2001 02:45:13 -0400 (EDT) Subject: [Tutor] Re:sound in pyhton In-Reply-To: <000e01c14267$27a7af10$e101a8c0@ncoretech.com> Message-ID: On Fri, 21 Sep 2001, ramprasad wrote: > I want an sound module in pyhton. Is there any way that i can get the speaker sound in python. can anybody help or give some comments regarding this Under what operating system? There are different methods depending on whether you're using Win32, Mac, or *nix. -- Ignacio Vazquez-Abrams From nidhi@ncoretech.com Fri Sep 21 10:14:46 2001 From: nidhi@ncoretech.com (Sreenidhi.B.G) Date: Fri, 21 Sep 2001 14:44:46 +0530 Subject: [Tutor] need some info on creating a Sound module References: Message-ID: <3BAB0506.342DA926@ncoretech.com> Hello All, I want a sound module in pyhton. Is there any way in python , that using the python builtins, i can produce sound. can anybody help or give some comments regarding this Thanks in advance, sreenidhi, From ramprasad@ncoretech.com Fri Sep 21 10:52:35 2001 From: ramprasad@ncoretech.com (ramprasad) Date: Fri, 21 Sep 2001 15:22:35 +0530 Subject: [Tutor] Re:sound in pyhton References: Message-ID: <000c01c14283$24188420$e101a8c0@ncoretech.com> Hi Thanks, I want sound for linux os can u find me one? ----- Original Message ----- From: Ignacio Vazquez-Abrams To: Sent: Friday, September 21, 2001 12:15 PM Subject: Re: [Tutor] Re:sound in pyhton > On Fri, 21 Sep 2001, ramprasad wrote: > > > I want an sound module in pyhton. Is there any way that i can get the speaker sound in python. can anybody help or give some comments regarding this > > Under what operating system? There are different methods depending on whether > you're using Win32, Mac, or *nix. > > -- > Ignacio Vazquez-Abrams > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From nidhi@ncoretech.com Fri Sep 21 11:23:13 2001 From: nidhi@ncoretech.com (Sreenidhi.B.G) Date: Fri, 21 Sep 2001 15:53:13 +0530 Subject: [Tutor] Re:sound in pyhton References: <000c01c14283$24188420$e101a8c0@ncoretech.com> Message-ID: <3BAB1511.3A78E314@ncoretech.com> Hi , is there a function equivavelent to beep in linux that will produce a beep ramprasad wrote: > Hi Thanks, > I want sound for linux os can u find me one? > ----- Original Message ----- > From: Ignacio Vazquez-Abrams > To: > Sent: Friday, September 21, 2001 12:15 PM > Subject: Re: [Tutor] Re:sound in pyhton > > > On Fri, 21 Sep 2001, ramprasad wrote: > > > > > I want an sound module in pyhton. Is there any way that i can get the > speaker sound in python. can anybody help or give some comments regarding > this > > > > Under what operating system? There are different methods depending on > whether > > you're using Win32, Mac, or *nix. > > > > -- > > Ignacio Vazquez-Abrams > > From ramprasad@ncoretech.com Fri Sep 21 12:53:57 2001 From: ramprasad@ncoretech.com (ramprasad) Date: Fri, 21 Sep 2001 17:23:57 +0530 Subject: [Tutor] Re:sound with out sound card Message-ID: <004d01c14294$1b89e720$e101a8c0@ncoretech.com> This is a multi-part message in MIME format. ------=_NextPart_000_004A_01C142C2.326DF480 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello All, I want to play sound in linux with out sound card. Is there any way that = i can play the sound. We have SOUND AND NOSOUND in dos in which we can = specify frequency. do we have any such thing in linux. python supports = sound in windows. wehave to import winsound and then we can play any = wave files etc in that.Please can anybody help me out in solving this = problem.It will be of great help if i can getit ASAP Thanks in advance, Regards Ramprasad ------=_NextPart_000_004A_01C142C2.326DF480 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
    Hello All,
     
    I want to play sound in linux with out = sound card.=20 Is there any way that i can play the sound. We have SOUND AND = NOSOUND  in=20 dos in which we can specify frequency. do we have any such thing in = linux.=20 python supports sound in windows. wehave to import winsound and then we = can play=20 any wave files etc in that.Please can anybody help me out in = solving  this=20 problem.It will be of great help if i can getit ASAP
     
    Thanks in advance,
    Regards
    Ramprasad
    ------=_NextPart_000_004A_01C142C2.326DF480-- From alan.gauld@bt.com Fri Sep 21 13:20:11 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Fri, 21 Sep 2001 13:20:11 +0100 Subject: [Tutor] poplib questions Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF92@mbtlipnt02.btlabs.bt.co.uk> > Where should I open and close the file? Open (for append) > just before the "for i in range" statement and close after > "a.quit()" as I have it below? I'd leave it pretty much as is - definitely open outside any loops! But also add a try/finally block and call close inside the finally section: > if numMsgs == 0: > print "\nNo mail for "+USER+" at "+MAILSERVER > return coz you do a return here you don't really need the else: > else: try: > print "Retrieving "+`numMsgs`+" messages for "+USER+" > at "+MAILSERVER > f=open("testbox","a") > for i in range(1, numMsgs + 1): > (header, msg, octets) = a.retr(i) > print "Message ", `i`, "("+`octets`+" octets)", ':' > for line in msg: > f.write(' ' + line +"\n") > print ".", > # dele(i) > # f.write('\n-----------------------\n') > a.quit() finally: > f.close() > return Just a thought. Alan G. From dsh8290@rit.edu Fri Sep 21 13:17:19 2001 From: dsh8290@rit.edu (dman) Date: Fri, 21 Sep 2001 08:17:19 -0400 Subject: [Tutor] Printing to a windows network printer In-Reply-To: References: Message-ID: <20010921081719.A3167@hudson> On Thu, Sep 20, 2001 at 10:37:53AM +0200, Neil Beattie wrote: | Hi, | I am a newbie to Python and am looking for a pointer to example code for | printing from PythonWin 2.1.1 to a network printer from nt. This probably isn't what you are looking for, but printer = os.popen( "enscript ///" ) printer.write( "Hello World" ) printer.close() del printer If you install the 'enscript' program you can print to windows printers from the commandline, which also works from python via a pipe. I don't know any other way to programmatically print on a windows system ( I don't think "copy /b LPT1" really counts ) but that is because I have no interest in windows programming and haven't had the need yet. -D From dsh8290@rit.edu Fri Sep 21 13:21:55 2001 From: dsh8290@rit.edu (dman) Date: Fri, 21 Sep 2001 08:21:55 -0400 Subject: [Tutor] os.system refuses to print from a script In-Reply-To: References: Message-ID: <20010921082155.B3167@hudson> On Thu, Sep 20, 2001 at 03:00:31PM +0400, Cerulean Rodent wrote: | Some data is written to file as the script goes about its business. | | Printing the file from command line with | | lpr filename | | works just fine. Invoke the interpreter from the command line, get a | familiar prompt. Enter the following | | import os | os.system('lpr filename') | | the file gets printed without a glitch. | | do the same from the script, and I get | | lpr: unable to print file: client-error-bad-request | | change os.system('lpr filename') for os.system('pwd') to check whether I'm | in the correct directory... I am. But lpr still returns an error when | invoked from a script (and so does lp, for that matter). Hmm, I'm not really certain on this, but I think that lpr may not be setup quite right. I use CUPS on my system, and I have found that _sometimes_ I can use lp or lpr without specifying a destination and other times it complains about it. I haven't yet figured out how to make it consistently default correctly (the config looks correct). I recommend researching lpr a bit to see what sort of conditions can trigger that particular error message and then try and work back to see how that condition was created in the script. | PS By the by, just how does one dump the results of one's meek attempts at | programming to Useless Python? Is it still available? All the links Google | returns for "useless python" are as dead as Spandau Ballet. Send a mail to Rob Andrews. He takes care of that. HTH, -D From lumbricus@gmx.net Fri Sep 21 16:11:01 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Fri, 21 Sep 2001 17:11:01 +0200 Subject: [Tutor] Re:sound in pyhton In-Reply-To: <3BAB1511.3A78E314@ncoretech.com>; from nidhi@ncoretech.com on Fri, Sep 21, 2001 at 03:53:13PM +0530 References: <000c01c14283$24188420$e101a8c0@ncoretech.com> <3BAB1511.3A78E314@ncoretech.com> Message-ID: <20010921171101.A1490@Laplace.localdomain> On Fri, Sep 21, 2001 at 03:53:13PM +0530, Sreenidhi.B.G wrote: > Hi , > is there a function equivavelent to beep in linux that will produce a beep print "\a" ? HTH and Greets J"o! :-) -- You have the body of a 19 year old. Please return it before it gets wrinkled. From ignacio@openservices.net Fri Sep 21 17:03:26 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 21 Sep 2001 12:03:26 -0400 (EDT) Subject: [Tutor] Re:sound in pyhton In-Reply-To: <000c01c14283$24188420$e101a8c0@ncoretech.com> Message-ID: On Fri, 21 Sep 2001, ramprasad wrote: > Hi Thanks, > I want sound for linux os can u find me one? Go to http://www.vorbis.com/download_unix.psp and get whatever copy of libao you feel comfortable with. NOTE: if you get the binary RPM, then you also need to get the -devel RPM. Then go to http://www.xiph.org/cvs.html and follow the instructions to get the 'ao-python' module from CVS. The download of ao-python available from the previous URL does not work with that download of libao. Install libao, then go to the directory where ao-python downloaded to and type 'python setup.py install'. Then read the documentation and look at the code examples for both ao-python and libao to learn how to use ao-python. -- Ignacio Vazquez-Abrams From dell2100@prodigy.net Fri Sep 21 15:17:05 2001 From: dell2100@prodigy.net (David L. Lerner) Date: Fri, 21 Sep 2001 14:17:05 -0000 Subject: [Tutor] IDLE Debug References: Message-ID: <004b01c142a8$1b630e20$18f163d8@pavilion> Where can I get elementary info on IDLE Debug? I mean, What is it, What does it do, How do I use it, etc.? I do not know how to use Go, Step, Over. I've tried to use them, and I don't know what I'm getting. I looked for a basic intro on the web, and I can't find one. I found an intro to IDLE by Danny Yoo, http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html, but it is incomplete. Thank you. David L. Lerner From rob@jam.rr.com Sat Sep 22 01:04:00 2001 From: rob@jam.rr.com (Rob Andrews) Date: Fri, 21 Sep 2001 19:04:00 -0500 Subject: [Tutor] Time Warner has bitten me fiercely. Message-ID: <3BABD570.70900@jam.rr.com> If anyone has sent email of any kind to Useless Python during the last week, please send it again. Time Warner accidentally deleted my account during a nearly week-long outage in my area. "Sorry, and we don't know how it happened, but your account was deleted, so all of your data is gone." Woohoo, yippee, Rob From rmardo@yahoo.com Sat Sep 22 09:11:58 2001 From: rmardo@yahoo.com (Rino Mardo) Date: Sat, 22 Sep 2001 16:11:58 +0800 Subject: [Tutor] python newbie need help Message-ID: <20010922161158.A296@amnesiac> --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable hi. i have debian2.2r0 system with python-1.5.2 installed. i went thru the info doc of my python install and just can't seem to find out why my code only runs in interactive mode and not from the shell. Here is my code sample: #! /usr/bin/python # Euclid's method for finding a common factor of two numbers def faktor(a,b): while b !=3D 0: a, b =3D b, a % b return a the code is named "test2.py" from the shell and i was able to import it from the interactive python and was able to call and run it. what i want to do is run it from my shell. what could i be missing? thank you. --=20 "If the only tool you have is a hammer, you tend to see every problem as a nail." -- Abraham Maslow --XsQoSWH+UP9D9v3l Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) iD8DBQE7rEfO8JtvN2Ncyp0RAhGrAJ4vSOxd9ppqqcXa1DNKmYpzHAVAhQCeLq0Q EevEYIuBC8kCVUMFxebdm+Y= =/jSe -----END PGP SIGNATURE----- --XsQoSWH+UP9D9v3l-- _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From kalle@gnupung.net Sat Sep 22 14:02:20 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sat, 22 Sep 2001 15:02:20 +0200 Subject: [Tutor] python newbie need help In-Reply-To: <20010922161158.A296@amnesiac> References: <20010922161158.A296@amnesiac> Message-ID: <20010922150220.A671@sverker.lysator.liu.se> [Rino Mardo] > hi. i have debian2.2r0 system with python-1.5.2 installed. i went > thru the info doc of my python install and just can't seem to find out > why my code only runs in interactive mode and not from the shell. > > Here is my code sample: > > #! /usr/bin/python > # Euclid's method for finding a common factor of two numbers > > def faktor(a,b): > while b != 0: > a, b = b, a % b > return a There are som indentation problems here: def faktor(a,b): while b != 0: a, b = b, a % b return a is probably what you want. > the code is named "test2.py" from the shell and i was able to import > it from the interactive python and was able to call and run it. what > i want to do is run it from my shell. what could i be missing? Have you set the executable bit (chmod +x test2.py)? Otherwise I don't know. What happens when you try to run it from the shell? Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From fleet@teachout.org Sat Sep 22 17:46:18 2001 From: fleet@teachout.org (fleet@teachout.org) Date: Sat, 22 Sep 2001 12:46:18 -0400 (EDT) Subject: [Tutor] popmail script problem Message-ID: In my popmail script, the actual writing of the popmail message to a local file occurs in the following code snippet. In order to view progress of the download, I wanted to "borrow" from the fetchmail program the idea of "progress dots." I was hoping to get a dot displayed on my monitor for every line written to file, but it seems that the dots get stored until the message transfer is completed, then they get dumped to the screen all at once. for line in msg: f.write(' ' + line +"\n") print ".", Would I have to open and close the file for each line in order to get what I want? Ie: for line in msg: f=open("inbox","a") f.write(line+"\n") f.close print ".", This seems a bit harsh on the system somehow. From alan.gauld@bt.com Sat Sep 22 18:02:36 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 22 Sep 2001 18:02:36 +0100 Subject: [Tutor] Printing to a windows network printer Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF93@mbtlipnt02.btlabs.bt.co.uk> > pipe. I don't know any other way to programmatically print on a > windows system ( I don't think "copy /b LPT1" really counts ) You can use GDI to print in Windows for true WYSIWYG style output. Thats how the Windows textbooks tell you to do it - wrap your normal screen onPaint method with a printer device context... The winall MFC classes should provide all the support you need along with an MFC textbook but its horrid and nothing to do with Python its how Windows does printing thats horrible. In practice I usually format my code an some markup type language and use os.system to print it: in postscript using ghostscript in pdf (using pdfgen) and adobe acrobat or ghostscript in html using a browser in RTF and using word or wordpad HTML is easiest but least powerful. However its enough for most things. Alan g From alan.gauld@bt.com Sat Sep 22 18:06:05 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Sat, 22 Sep 2001 18:06:05 +0100 Subject: [Tutor] IDLE Debug Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66BF94@mbtlipnt02.btlabs.bt.co.uk> > Where can I get elementary info on IDLE Debug? I mean, What > is it, What > does it do, How do I use it, etc.? Unashamed plug coming up.... > I do not know how to use Go, Step, Over. I've tried to use > them, and I don't know what I'm getting. My book includes a chapter on debugging (as I have to admit do several others) :-) http://www.crosswinds.net/~agauld for pointers Its one of the chapters not included on the web version(yet). Alan g From ignacio@openservices.net Sat Sep 22 18:12:18 2001 From: ignacio@openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 22 Sep 2001 13:12:18 -0400 (EDT) Subject: [Tutor] popmail script problem In-Reply-To: Message-ID: On Sat, 22 Sep 2001 fleet@teachout.org wrote: > In my popmail script, the actual writing of the popmail message to a local > file occurs in the following code snippet. In order to view progress of > the download, I wanted to "borrow" from the fetchmail program the idea of > "progress dots." I was hoping to get a dot displayed on my monitor for > every line written to file, but it seems that the dots get stored until > the message transfer is completed, then they get dumped to the screen all > at once. call system.stdout.flush() after each dot. -- Ignacio Vazquez-Abrams From lumbricus@gmx.net Sat Sep 22 12:15:15 2001 From: lumbricus@gmx.net (Joerg Woelke) Date: Sat, 22 Sep 2001 13:15:15 +0200 Subject: [Tutor] python newbie need help In-Reply-To: <20010922161158.A296@amnesiac>; from rmardo@yahoo.com on Sat, Sep 22, 2001 at 04:11:58PM +0800 References: <20010922161158.A296@amnesiac> Message-ID: <20010922131515.A2685@Laplace.localdomain> On Sat, Sep 22, 2001 at 04:11:58PM +0800, Rino Mardo wrote: > hi. i have debian2.2r0 system with python-1.5.2 installed. i went > thru the info doc of my python install and just can't seem to find out > why my code only runs in interactive mode and not from the shell. > > Here is my code sample: > > #! /usr/bin/python > # Euclid's method for finding a common factor of two numbers > > def faktor(a,b): > while b != 0: > a, b = b, a % b > return a > > > the code is named "test2.py" from the shell and i was able to import > it from the interactive python and was able to call and run it. what > i want to do is run it from my shell. what could i be missing? You are missing the function main ;-) Until now you defined a function (faktor) but you don't actually call it. add: def main(): # get arguments for faktor() # ... faktor(arg1,arg2) # print result or something # ... # exec main if __name__=="__main__": main() PS: Don't forget chmod(1) bzw. python