Forum Archive

How to call a text file from my iPad to pythonista script?

ankit.agniho3

Hi Guys,

I recently joined pythonista community. I need your help in executing a script on pythonista which I am able to run on my linux system. First find my below script :-

#Script to print lines using functions

from sys import argv

script, input = argv

def print_all(f):
    print f.read()

def rewind(f):
    f.seek(0)

def print_a_line(line_count, f):
      print line_count, f.readline()

current_file = open(input)

print "First lets print the whole file:\n"
print_all(current_file)

print "Now lets rewind the file like tape"
rewind(current_file)

print "Lets print three Lines"
current_count = 1
print_a_line(current_count, current_file)
current_count = current_count + 1
print_a_line(current_count, current_file)
current_count = current_count + 1
print_a_line(current_count, current_file)

#END

On my linux system I use:-

$ python script-name file-name

Where file-name is a text file which is saved on my linux system.
Here I want to execute the same script in pythonista but don't know from where I can call the text file into the script.
Please help me understand.

dgelessus

To pass extra runtime arguments to your script, press and hold the play button. You'll get a popup window where you can type the extra arguments like in the Unix shell. (python myscript.py a b c in the Unix shell is the same as putting a b c in the arguments in Pythonista.)