Re: [Tutor] opts and try except

2005-11-17 Thread Danny Yoo
On Thu, 17 Nov 2005, Eric Walker wrote: > I have a program now that works just like I want it. Now I want to > integerate something to say print usage info when the user puts in the > wrong number or type of options. Also print usage say if you type > program name and -h or -H. I currently just

Re: [Tutor] displaying properties/methods

2005-11-17 Thread Alan Gauld
> Hi all, i'm a newbie to python and now learning OOP. How do i display > methods or properties that is owned by a class or a module? for example: i > know that module sys has a property/method called path. i want to know > what other methods it has, how do i find them from python command line?

Re: [Tutor] building nonbinary trees

2005-11-17 Thread Alan Gauld
> I'v got a start but I'm stuck because I don't understand how to call > a tree's nodes by name. Every time you see call by name, think dictionary. class Node: def __init__(self): self.children = {} def addChild(self,child,name): self.children[name] = child etc.

[Tutor] displaying properties/methods

2005-11-17 Thread Gregorius Gede Wiranarada
Hi all, i'm a newbie to python and now learning OOP. How do i display methods or properties that is owned by a class or a module? for example: i know that module sys has a property/method called path. i want to know what other methods it has, how do i find them from python command line? thx. r

[Tutor] building non binary trees CLARIFIED

2005-11-17 Thread Vincent Wan
Let me try to clarify my problem. I would like to have a tree data structure with trees whose nodes could have an arbitrary number of descendants and that I could iterate over by the names of nodes this is the first time I've used objects. I tried to model my code on a binary tree data struc

Re: [Tutor] building nonbinary trees

2005-11-17 Thread Liam Clarke-Hutchinson
Erm, a dictionary of names to references? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vincent Wan Sent: Friday, 18 November 2005 2:21 p.m. To: tutor@python.org Subject: [Tutor] building nonbinary trees I would like to have a tree data structure w

[Tutor] building nonbinary trees

2005-11-17 Thread Vincent Wan
I would like to have a tree data structure with trees whose nodes could have an arbitrary number of descendants and that I could iterate over by the names of nodes I'v got a start but I'm stuck because I don't understand how to call a tree's nodes by name. Here is the code I have so far: i

[Tutor] opts and try except

2005-11-17 Thread Eric Walker
All, I have a program now that works just like I want it. Now I want to integerate something to say print usage info when the user puts in the wrong number or type of options. Also print usage say if you type program name and -h or -H. I currently just have functions defined and at the bottom ma

Re: [Tutor] new topic draft

2005-11-17 Thread Christopher Arndt
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Johan Geldenhuys schrieb: > This script was not intended to be used from the command line, but to > be called from elsewhere. It was only a test piece of code. > If you use the ping command with the args that you are calling it with, > there is no nee

Re: [Tutor] compiled images

2005-11-17 Thread John Fouhy
On 18/11/05, Fred Lionetti <[EMAIL PROTECTED]> wrote: > Anyone have any idea as to how I could basically "compile" all my > artwork into a data file for a python application? Would this require > compiling them into a *.dll/*.so? It seems like there must be any > easier way--Also, I need my appli

Re: [Tutor] Newb ?

2005-11-17 Thread Christian Wyglendowski
Orri said: > Or you could just do the following: > > >>> print "\n\nWelcome to the Backwards Message Display." > >>> print > >>> message = raw_input("\nPlease Enter a Message.") > >>> print message[::-1] Interesting. I forgot about the 'step' option when slicing. > This is the equivalent of pr

Re: [Tutor] Newb ?

2005-11-17 Thread Orri Ganel
Christian Wyglendowski wrote: >Liam said: > > >>How about - >>print "\n\nWelcome to the Backwards Message Display." >>print >>message = raw_input("\nPlease Enter a Message.") >>msgAsList = [ char for char in message] >> >> > >You could also do: > >msgAsList = list(message) > >list() takes an

Re: [Tutor] compiled images

2005-11-17 Thread Christian Wyglendowski
Fred said: > [snip] > I've got another question I think you may have come across before. > I'm planning on purchasing a license to use some stock icons in an > application I'm developing. The problem is the license requires this: > > "Where an application is to be distributed, the graphical me

Re: [Tutor] Newb ?

2005-11-17 Thread Liam Clarke-Hutchinson
>list() takes any iterable and returns a list object. Hmm, I did not know that the list(str) thing worked that way.That'll reduce the list comprehensions, but is it intuitive? Would a newbie see that and think that list("Hi") returns ["Hi"] or ["H","i"] ? >reversedMessage = ''.join(reversed(list

Re: [Tutor] Newb ?

2005-11-17 Thread Christian Wyglendowski
Liam said: > > How about - > print "\n\nWelcome to the Backwards Message Display." > print > message = raw_input("\nPlease Enter a Message.") > msgAsList = [ char for char in message] You could also do: msgAsList = list(message) list() takes any iterable and returns a list object. > msgAsList.

Re: [Tutor] compiled images

2005-11-17 Thread Liam Clarke-Hutchinson
Hehe, Sounds like someone's license was designed for C/C++. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fred Lionetti Sent: Friday, 18 November 2005 8:29 a.m. To: tutor@python.org Subject: [Tutor] compiled images Hi everyone, Thanks everyone fo

Re: [Tutor] Newb ?

2005-11-17 Thread Liam Clarke-Hutchinson
How about - print "\n\nWelcome to the Backwards Message Display." print message = raw_input("\nPlease Enter a Message.") msgAsList = [ char for char in message] msgAsList.reverse() reversedMessage = ''.join(msgAsList) I can't test that, but it should work. But, with regard to - > print "\n\nWel

[Tutor] compiled images

2005-11-17 Thread Fred Lionetti
Hi everyone, Thanks everyone for the help with lambda expressions! Your suggestions and discussions were great! I've got another question I think you may have come across before. I'm planning on purchasing a license to use some stock icons in an application I'm developing. The problem is the l

Re: [Tutor] How to remove Html from list.

2005-11-17 Thread Alan Gauld
> I can not figure out what kind of expresion I need to use to find Html > code. Take a look at the regular expressions topic in my tutorial which gives an example of stripping stuff from HTML> However be aware that using regular expressions on html is never reliable and a proper parser like B

Re: [Tutor] new topic draft

2005-11-17 Thread Johan Geldenhuys
This script was not intended to be used from the command line, but to be called from elsewhere. It was only a test piece of code. If you use the ping command with the args that you are calling it with, there is no need to kill the process, it will terminate after 10 requests.  8-) Johan Ch

Re: [Tutor] new topic draft

2005-11-17 Thread Christopher Arndt
Johan Geldenhuys wrote: > What is this line supposedto do? > > cmd.run('www.python.org') Run the command that was defined at object creation ('ping -c 10') with the argument 'www.python.org'. Chris ___ Tutor maillist - Tutor@python.org http://mail.py

Re: [Tutor] new topic draft

2005-11-17 Thread Johan Geldenhuys
What is this line supposedto do? cmd.run('www.python.org') Christopher Arndt wrote: Alan Gauld schrieb: Thanks, I may use that as one of the example programs if you don't mind? I took the liberty of refactoring Johan's example a bit, to make it more reusable. See attac

Re: [Tutor] new topic draft

2005-11-17 Thread Johan Geldenhuys
That will be great. In the "@TODO" part you will see that I still need to take the output from the command and capture that into a file. Can you help me with that? Johan Alan Gauld wrote: > Thanks, I may use that as one of the example programs if > you don't mind? > > Alan G. > > > - Orig

Re: [Tutor] slices

2005-11-17 Thread Will Harris
Blah brain freeze I saw my mistake as I hit send. It should just be word[-2:] So #!/usr/bin/python import sys for word in sys.argv[1:]: print word[-2:] Works now. Thanks! On 11/17/05, Will Harris <[EMAIL PROTECTED]> wrote: Is there an easy way to slice the last set of characters off a

[Tutor] slices

2005-11-17 Thread Will Harris
Is there an easy way to slice the last set of characters off a string when I don't know the length of the string? For example say I have a list of words like    this    though    weather I want to get the last 2 characters from each. But so far nothing I have tried has seeme

[Tutor] How to remove Html from list.

2005-11-17 Thread Laszlo Antal
Hi, This is what I would like to do.: 1: Read in an Html file as a list with readlines, 2: Loop through the list, 3: Take out the text or number that is between the Html, 4: Insert the text or number into a new list, 5: print out the new list with the text. I have a problem with section 3 ! I ca

Re: [Tutor] Newb ?

2005-11-17 Thread Ed Singleton
These both work (though neither is very graceful). text = "hello" message = "" for i in range(len(text)): message = message + text[(len(text)-i-1)] print message lst = list(text) newstr = "" for item in text: newstr += (lst.pop()) print newstr On 16/11/05, Chad Everett <[EMAIL

Re: [Tutor] Using lists as table-like structure

2005-11-17 Thread Bernard Lebel
Thanks to everyone for the answers. I'll definitely check Numeric Python. Cheers Bernard On 11/16/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 16 Nov 2005, Bernard Lebel wrote: > > > Let say I have a list of lists. Each individual lists have a bunch of > > elements. Now I would like

Re: [Tutor] split a tuple

2005-11-17 Thread János Juhász
Hi Chris, Thanks your response. I have just found another way. >>> import math >>> l = (1,2,3,4,5,1,2,3,4,5,1,2,3,4,5) >>> n = 4 >>> extended = l + ('default',)*int(n - math.fmod(len(l),n)) >>> [extended[i:i+n] for i in range(0,len(extended),n)] [(1, 2, 3, 4), (5, 1, 2, 3), (4, 5, 1, 2), (3, 4,

Re: [Tutor] how to identify a list element is in the range of a tuple element or a list element

2005-11-17 Thread Pujo Aji
for b you can use this code:     a = [10,3,4.6,2.3,4.8,10.8,4.1]    b = ['1-4','4.1-8','8.1-12','12.1-16']    for x in a:    for y in b:    low,up = y.split('-')    if  float(low) < x < float(up):     print '%s   %s - %s' % (x, low, up)    break    Ch

Re: [Tutor] lambda in a loop

2005-11-17 Thread Christian Wyglendowski
Fred said: > >> Obviously, the lambda is using "value" at the end of the loop (4), > >>rather than what I want, "value" during the loop (0,1,2,3). Christian said: > > Right. I think the issue is that your lambda calls another funtion. > > However, the function isn't called until the lambda is c

Re: [Tutor] how to identify a list element is in the range of a tuple element or a list element

2005-11-17 Thread Kent Johnson
Srinivas Iyyer wrote: > Dear group, > > I have a list of numbers: > > a = [10,3,4.6,2.3,4.8,10.8,4.1] > b = ['1-4','4.1-8','8.1-12','12.1-16'] > c = ((1,4),(4.1,8),(8.1-12),(12.1,16)) > > Now I want to find if elements of list a are in the > range of list b and in the range of tuple b. > > I

[Tutor] how to identify a list element is in the range of a tuple element or a list element

2005-11-17 Thread Srinivas Iyyer
Dear group, I have a list of numbers: a = [10,3,4.6,2.3,4.8,10.8,4.1] b = ['1-4','4.1-8','8.1-12','12.1-16'] c = ((1,4),(4.1,8),(8.1-12),(12.1,16)) Now I want to find if elements of list a are in the range of list b and in the range of tuple b. I know (and my limited knowledge on range functi

Re: [Tutor] Passing HTTP commands through Telnet using Python for web site testing?

2005-11-17 Thread Kent Johnson
Adisegna wrote: > So far this is what I have come up with doing some research. > > import urllib > for line in urllib.urlopen('http://mywebsit.com/folder/folder/test.asp'): > if '400 Bad Request' in line: > > text_file = open("mysite.log", "a") > text_file.writelines(line) > text_file.w

Re: [Tutor] split a tuple

2005-11-17 Thread Chris or Leslie Smith
| Hi, | | I couldn't get idea how to make the next thing | n=4 #split into so long parts l = (1,2,3,4,5,1,2,3,4,5,1,2,3,4,5) #this is the tuple to split [l[i:i+n] for i in range(0,len(l),n)] | [(1, 2, 3, 4), (5, 1, 2, 3), (4, 5, 1, 2), (3, 4, 5)] | | But I have to make it like thi

Re: [Tutor] Passing HTTP commands through Telnet using Python for website testing?

2005-11-17 Thread Alan Gauld
> Anyway, Can someone point me in the right direction on getting the Telnet > working? Or if you have a better way to get what I am trying to do > accomplished. Is there a Python Telnet module? I think the urllib module will be easier. Just open the url and read the output into a list. check the

Re: [Tutor] Passing HTTP commands through Telnet using Python forweb site testing?

2005-11-17 Thread Alan Gauld
Looks like you pretty well figured it out. for the timestamp there is the basic timemodule, the datetime module or the extra module mxdatetime. Each more sophisticated than the last... Alan G - Original Message - From: "Adisegna" <[EMAIL PROTECTED]> To: Sent: Thursday, November 17, 2005

Re: [Tutor] Passing HTTP commands through Telnet using Python for web site testing?

2005-11-17 Thread Kent Johnson
Adisegna wrote: > Hi, > > I just started learning Python and would like to try writing a > monitoring script. > > What I would like to do is use Telnet to send a GET via port 80 to a > status page in a directory to verify my site is up. I use httplib for this. You can probably do it with urlli