Try using 'sys.exit()' where you want the script to stop if you haven't
supplied enough arguments.
in you example, it looks like it will go on to the else anyway AND print
the string at the end.
HTH,
Johan
Roy Bleasdale wrote:
>Hi
>
>In the example below I would like the program to stop if I
Hi
In the example below I would like the program to stop if I forgot to
provide an argument . Though I could do all my processing indented under
the else statement, I was wondering if there was a command that would allow
me to halt the program execution early.
Regards,
Roy
# Example program
Found it. This is what I was looking for:
"""
>>> print ('file'+'dir'.center(20))+('\n'+'='*15)
file dir
===
>>>
"""
It's actually a string operator 'center(width)' that I was
looking for.
I saw the '%', but that is wahat I wanted to use.
Johan
Colin J. Williams wrote:
[snip] Colin: your replies to 2 e-mails indicate that you have either not
read the e-mails or the prior responses. Please consider the work others
put into replying before replying.
Example: I suggested % formatting in a reply. You replied to that by saying
the same thing.
Colin J. Williams wrote:
> No, I was thinking of exec. The given statement can be executed in a
> specified environment.
> You might say "The rogue code can dodge that with an import statement
> with an import".
>
> True, but it seems to me that a user specified __import__ function can
> prote
Danny Yoo wrote:
>>You make some good points here but I suggest that, in the real world,
>>the risks are small.
>>
>>
>
>Hi Colin,
>
>But that's the point I'm trying to make; eval() is appropriate only for
>toy code. In real world code that's exposed to the world, using eval() is
>usually the
> You make some good points here but I suggest that, in the real world,
> the risks are small.
Hi Colin,
But that's the point I'm trying to make; eval() is appropriate only for
toy code. In real world code that's exposed to the world, using eval() is
usually the wrong thing to do, because it re
Michael Haft wrote:
>Hello,
> I tried the following code:
>
>def readSOMNETM(inputName):
>input = open(inputName, "r")
>result = []
>for line in input:
>fields = line.split()
>data = fields[1] + fields[2] + fields[7]
>result.append(data)
>input.close()
>
bob wrote:
>At 11:31 AM 11/3/2005, Johan Geldenhuys wrote:
>
>
>>Hi all,
>>Just a quick question;
>>
>>How do I code this output:
>>"""
>>files dirs
>>==
>>"""
>>
>>I want to print something a few space away from the left side or in the
>>middle of the line.
>>
>>
>
>In the
Danny Yoo wrote:
>>>I have a dynamic functions which created by some algorithms during
>>>runtime. These functions are in string type. When I want to use it, I
>>>can use eval command. But can someone give me more suggestion about
>>>how to handle this problem, I want to avoid eval.
>>>
>>>
> You cannot run any function at all in your script after you do the exec
> call, it is no longer your program, but the one you exec-ed. popen
> actually runs the subprocess, you don't have to call it manually. Popen
> is the most used way to get the output, and looks like it is the only
> one
Michael Haft wrote:
> Hello,
> I tried the following code:
>
> def readSOMNETM(inputName):
> input = open(inputName, "r")
> result = []
> for line in input:
> fields = line.split()
> data = fields[1] + fields[2] + fields[7]
> result.append(data)
> input
Mike:
I see two issues here:
First, do you really want to apply your field selection logic to ALL the
lines in each file? It seems to me that the first five lines of the file
are header information that you want to ignore. If so, and if all the files
have the same format, you can use a loop to
Hi Mike,
Same file, eh?
>From the docs for split()
"If sep is not specified or is None, a different splitting algorithm is
applied. First, whitespace characters (spaces, tabs, newlines, returns, and
formfeeds) are stripped from both ends. Then, words are separated by
arbitrary length strings
Woah, that's way simpler than mine.
Liam Clarke-Hutchinson
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of bob
Sent: Friday, 4 November 2005 11:01 a.m.
To: [EMAIL PROTECTED]; tutor@python.org
Subject: Re: [Tutor] File IO
At 01:34 PM 11/3/2005, Michael
I did that and got this:
Here goes
Enter filename:
Name:LAU73M.MET
Line too short Monthly Weather Data, LAU73M.MET, converted from:
Line too short BAD LAUCHSTAEDT; DAILY METEOROLOGICAL DATA FOR
01/01/1973-31/12/1973
Line too short
*
At 01:34 PM 11/3/2005, Michael Haft wrote:
>Hello,
> I tried the following code:
>
>def readSOMNETM(inputName):
> input = open(inputName, "r")
> result = []
> for line in input:
> fields = line.split()
# add this; it will show you what line(s) have less than 8 f
At 11:31 AM 11/3/2005, Johan Geldenhuys wrote:
>Hi all,
>Just a quick question;
FWIW saying that does not help. It takes time to read it, and I can judge
the question length by reading the question. The real concern is what does
it take to construct an answer.
_
At 11:31 AM 11/3/2005, Johan Geldenhuys wrote:
>Hi all,
>Just a quick question;
>
>How do I code this output:
>"""
>files dirs
>==
>"""
>
>I want to print something a few space away from the left side or in the
>middle of the line.
In the Python Library Reference look up 2.3.6.2 S
Hello,
I tried the following code:
def readSOMNETM(inputName):
input = open(inputName, "r")
result = []
for line in input:
fields = line.split()
data = fields[1] + fields[2] + fields[7]
result.append(data)
input.close()
return result
print "Here g
+++ Bernard Lebel [03-11-05 14:16 -0500]:
| I use plink
| http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
|
| Basically you send a system command (os.system) to the plink
| executable. The actuall command will take this form:
|
| os.system( 'plink -pw %s -ssh [EMAIL PROTECTED] %s'
Hi,
Here's the docs for the popen2 module in python 2.2, the Popen2 object
allows you to get the pid. The popen2() call allows you to get the
output in a filehandle.
http://www.python.org/doc/2.2.3/lib/module-popen2.html
You cannot run any function at all in your script after you do the exec
> > I have a dynamic functions which created by some algorithms during
> > runtime. These functions are in string type. When I want to use it, I
> > can use eval command. But can someone give me more suggestion about
> > how to handle this problem, I want to avoid eval.
>
> Why avoid? It seems th
Title: Message
I
recommend using pyparsing or similar parser to parse it; if merely to ensure
that it's a valid algorithim.
Liam
Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic Development DDI +64 3 962 2639 | Fax +64
3 962 6220www.med.govt.nz
-Original Message-
Hi all,
Just a quick question;
How do I code this output:
"""
files dirs
==
"""
I want to print something a few space away from the left side or in the
middle of the line.
Thanks,
Johan
___
Tutor maillist - Tutor@python.org
http://m
Title: Message
Oops,
I see I just doubled up on Danny's advice.
Liam
Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic Development DDI +64 3 962 2639 | Fax +64
3 962 6220www.med.govt.nz
-Original Message-From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Beh
I use plink
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Basically you send a system command (os.system) to the plink
executable. The actuall command will take this form:
os.system( 'plink -pw %s -ssh [EMAIL PROTECTED] %s' % ( password, user, hostIP,
command ) )
Now, if you
On Thu, 3 Nov 2005, Pujo Aji wrote:
> I have a dynamic functions which created by some algorithms during
> runtime. These functions are in string type. When I want to use it, I
> can use eval command. But can someone give me more suggestion about how
> to handle this problem, I want to avoid eval
Anyone know of a way to have Python run a command on a remote machine? In my
particular case, I want to run a python program on Windows and run a command on
VMS. Would the telnetlib module do it, or is there something better?
Mike
___
Tutor maillist
try pyro.
Cheers,
pujo
On 11/3/05, Mike Hansen <[EMAIL PROTECTED]> wrote:
Anyone know of a way to have Python run a command on a remote machine? In myparticular case, I want to run a python program on Windows and run a command on
VMS. Would the telnetlib module do it, or is there something bette
Pujo Aji wrote:
> Hello
>
> I have a dynamic functions which created by some algorithms during
> runtime.
> These functions are in string type.
> When I want to use it, I can use eval command.
> But can someone give me more suggestion about how to handle this
> problem, I want to avoid eval.
Jan Eden wrote:
> Hi,
>
> the module Data.py stores a number of data attributes. I'd like to structure
> the storage of these attributes, either in subclasses or in dictionaries.
>
> My first attempt was this:
>
> class A:
> templates['attr1'] = 'string'
> queries['children'] = ...
>
Hi,
the module Data.py stores a number of data attributes. I'd like to structure
the storage of these attributes, either in subclasses or in dictionaries.
My first attempt was this:
class A:
templates['attr1'] = 'string'
queries['children'] = ...
class B(A):
templates['attr2']
Bookpool.com has all O'Reilly titles on sale 47% off. So if you have been
wanting to pick up a copy of Learning Python, Python in a Nutshell or Python
Cookbook this is a good time.
Kent
--
http://www.kentsjohnson.com
___
Tutor maillist - Tutor@pyt
The version of python that I have is 2.2.2 and I can't upgrade, sorry.
As far as I know this only from version 2.4.2??
Johan
Kent Johnson wrote:
Johan Geldenhuys wrote:
I've been musy with the os command on how to kill a process. That's been
sorted out to an extend. Many thanks
Johan Geldenhuys wrote:
> I've been musy with the os command on how to kill a process. That's been
> sorted out to an extend. Many thanks for your input.
>
> Now I have a question in the same direction:
>
> I use os.execpv(cmd, [cmd, args]). That executes the command that have
> output. This wa
Hello
I have a dynamic functions which created by some algorithms during runtime.
These functions are in string type.
When I want to use it, I can use eval command.
But can someone give me more suggestion about how to handle this problem, I want to avoid eval.
Example :
L = ['x+sin(x)', '1/(2.2
37 matches
Mail list logo