Re: basic output question



John Deas wrote:
Hi, I am very new to Python (1 evening...)
I need to process a series of files (toto-1.txt toto-2.txt toto-3.txt
toto-4.txt), and as such I created a small program to go through the
files in a directory. I want to call the script with arguments, like

python script.py toto- 1 1 4

my script is as follow :

import sys
sys.argv
header= sys.argv[1]
start =eval(sys.argv[2])
step =eval(sys.argv[3])
nbit =eval(sys.argv[4])

Style note: You should probably use int() instead of eval. Not only is this safer (as in security), it is also safer (as in robust), because it will throw an error early if you feed it something other than an int.


for i in range(nbit):
filename=header+str(start+i*step)+'.txt'
f=open(filename,'r')
f.read()
f.close()

My problem is that f.read() outputs nothing, and should I print
filename, I can check that they are well formed, and the files sits in
the same directory as my script.

f.read() spills the text into nothingness. You may want to write its output to a variable. ;)

/W
.



Relevant Pages

  • Feedback on scripting design
    ... At the start of the game, a startup script is called, which is responsible for setting up all the initial game values, selecting the starting map, and any other miscellaneous things you want taken care of at the beginning of the game. ... Interface_NewMap(int Width, int Height); ... Interface_Hurt(int MonsterID, int Damage, int DamageTypeFlags); ...
    (rec.games.roguelike.development)
  • Scheduler fairness problem on 2.6 series (Attn: Nick Piggin and others)
    ... latest kernel, so I tried 2.6.7 but it shows the same signs. ... I managed to create a test program to reproduce it. ... I run in one shell a script to check for slowdowns: ... int iterations = 0; ...
    (Linux-Kernel)
  • Re: MySQL to SQL
    ... BIOS_RELEASE_DATE datetime default NULL, ... NUM_PROCESSORS int NOT NULL default '0', ... Copyright 1985-2001 Microsoft Corp. ... Microsoft Windows Script Host Version 5.6 ...
    (microsoft.public.scripting.wsh)
  • Ruby Versions and other languages performane comparison
    ... I ran this simple ruby script ... perl, python and C. ... int max = 5000; ...
    (comp.lang.ruby)
  • Re: MySQL to SQL
    ... How does this VBScript recognize the ... MySQL.sql script to do the compare? ... bigint without the size spec following them? ... to just int. ...
    (microsoft.public.scripting.wsh)