https://ipython.readthedocs.io/en/stable/interactive/reference.html#system-shell-access says that shell commands (for example, your line prefixed with a "!") are interpreted literally. When you type "file", it sees "file", not the value of your file
variable.
Any input line beginning with a ! character is passed verbatim (minus the !, of course) to the underlying operating system.
But it also says you can use braces or a dollar sign to "expand" a value.
IPython also allows you to expand the value of python variables when making system calls. Wrap variables or expressions in {braces}:
In [1]: pyvar = 'Hello world'
In [2]: !echo "A python variable: {pyvar}"
A python variable: Hello world
In [3]: import math
In [4]: x = 8
In [5]: !echo {math.factorial(x)}
40320
For simple cases, you can alternatively prepend $ to a variable name:
In [6]: !echo $sys.argv
[/home/fperez/usr/bin/ipython]
In [7]: !echo "A system variable: $$HOME" # Use $$ for literal $
A system variable: /home/fperez
In your case, try !python ../iupred2a.py $file long
or !python ../iupred2a.py {file} long
.
... All that said, I think it would be better to just import
your other Python file and call its functions directly. This may require a little redesigning, because importing from a file from one directory up is somewhat tricky, and the command-line interface for a module is usually different from its programming interface.
If you can get your current file and iupred2a.py into the same directory, and figure out the name of the function that you actually want to call, then your code would end up looking something like:
import os
import iupred2a as iup
for file in os.listdir():
if file.endswith('.fasta'):
iup.do_the_thing(file, mode="long")