質問

In a Jython script I am trying to replace an entire line of a text file (the 2nd line in this case) with a directory address that contains a variable (VAR).

obsids=str(obsids[i])
print type(obsids)
os.system('sed -i "2 s:.*:/usr/data/$obsids/:" /usr/software/file.txt')

Where obsids was a unicode of a whole number, then a string (usually something like 1342204440).

Please can you show me the error in my script.

Thanks.

役に立ちましたか?

解決

We got it in the comments:

obsids=str(obsids[i])
print type(obsids)
os.environ['obsids']=obsids  # this makes the Python variable behave inside UNIX
os.system('sed -i "2 s:.*:/usr/data/$obsids/:" /usr/software/file.txt')
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top