[Tutor] Detecting my own IP address?

2005-06-05 Thread Simon Gerber
G'day, I'm currently blundering through a script that will let me configure and then connect to PPTP VPNs from a Linux box. Just a text-based front-end to pptp-client, really. Adding in new VPN configurations was simple. Connecting is a little harder. From the command-line I would normally

Re: [Tutor] Detecting my own IP address?

2005-06-05 Thread Terry Carroll
The Python Cookbook (1st ed) suggests this, in recipe 10.4 (Finding Your Own Name and Address): import socket myname = socket.getfqdn(socket.gethostname()) myaddr = socket.gethostbyname(myname) myaddr '192.168.1.120' ___ Tutor maillist -

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-05 Thread Kent Johnson
Lee Cullens wrote: Well, I've tried both and can't produce what I was doing with the for construct. With a listpl = ['a', 'b', 'c', 'd'] of the path components I'm trying to add justified non repeated path elements, say pl[2] and pl [3] to csvline so that csvline would end up ','*x

Re: [Tutor] Detecting my own IP address?

2005-06-05 Thread Lee Harr
At present, the only thing I can think of is to redirect the output of 'ifconfig' into a temporary file, then read it back in and use Python and regular expressions to try and extract the IP info from that. That is basically how I do it. See here:

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-05 Thread Liam Clarke
There is no need for the if(dlst); if the list is empty the iteration will do nothing. You can write this as for dlf in os.listdir(pname): Though it is quite distant, there is an else statement which makesthe if construct a requierement.Javier You could just do - if not len(dlst): #Your

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-05 Thread Lee Cullens
Such would serve to pull the test and the reason for it together - more obvious. Which is a good point in writing code that others may read. Thanks Liam On Jun 5, 2005, at 9:29 AM, Liam Clarke wrote: There is no need for the if(dlst); if the list is empty the iteration will do

Re: [Tutor] Pythonese/Efficiency/Generalese critique please

2005-06-05 Thread Lee Cullens
OK Kent - got it:My little formating function could be written as  (tested)  def cellpos(pname, alvl, blvl, clvl):        # breakout path components into list           pl = pname.split('/')        # insert empty cells for repeated names and        #  add new path components (cells) to csvline 

Re: [Tutor] Detecting my own IP address?

2005-06-05 Thread Bill Campbell
On Sun, Jun 05, 2005, Lee Harr wrote: At present, the only thing I can think of is to redirect the output of 'ifconfig' into a temporary file, then read it back in and use Python and regular expressions to try and extract the IP info from that. Why go to a temporary file when you can open a pipe?

Re: [Tutor] Iterate through a list calling functions

2005-06-05 Thread Kent Johnson
David Pratt wrote: Hi Kent. Thank you for your reply. I gave this a go but get the following traceback: ... result = validator(name, value) TypeError: 'str' object is not callable Have put validators in list and iterate over it as in following: validator_list =

[Tutor] [Fwd: Re: Iterate through a list calling functions]

2005-06-05 Thread Kent Johnson
Sorry, forwarded to the wrong list. Kent Original Message Subject: Re: [Tutor] Iterate through a list calling functions Date: Sun, 05 Jun 2005 21:53:16 -0400 From: Kent Johnson [EMAIL PROTECTED] To: Python Tutor tutor@python.org References: [EMAIL PROTECTED] David Pratt wrote:

Re: [Tutor] Detecting my own IP address?

2005-06-05 Thread Simon Gerber
Thank you for your suggestions everyone. I do wish to parse ifconfig, as I'm specifically after the address of ppp0. At this stage, I'm only writing the script for my own machine, so the downside to parsing ifconfig does not yet apply. I'm a little curious, however. When you say 'varies depending

Re: [Tutor] Detecting my own IP address?

2005-06-05 Thread Bill Campbell
On Mon, Jun 06, 2005, Simon Gerber wrote: Thank you for your suggestions everyone. I do wish to parse ifconfig, as I'm specifically after the address of ppp0. At this stage, I'm only writing the script for my own machine, so the downside to parsing ifconfig does not yet apply. I'm a little