linux - Why is my Python script writing Windows style carriage returns? -


good day,

i trying write script creates fabfile, saves , runs it. here code far:

#!/usr/bin/python  bakery_internalip = "10.10.15.203"  print "[....] preparing commands run within fabfile.py"  fabfile = open("sfab.py", "w") fabfile.write("from fabric.api import run, sudo, task\n\n@task\ndef myinstall():\n\tsudo('yum install httpd')") fabfile.close  print "running fab commands"  import subprocess subprocess.call(['fab', '-f', 'sfab.py', '-u ec2-user', '-i', 'id_rsa', '-h', bakery_internalip, 'myinstall']) 

the contents of fabfile follows:

[root@ip-10-10-20-82 bakery]# cat sfab.py fabric.api import run, sudo, task  @task def myinstall():         sudo('yum install httpd') 

my script gives following error when run it:

fatal error: fabfile didn't contain commands! 

however, if run dos2unix on file , run following, works fine:

 fab -f sfab.py -h localhost myinstall 

simple typo fabfile.close should fabfile.close()

running without closing give you:

running fab commands  fatal error: fabfile didn't contain commands!  aborting  open("sfab.py", "w") fabfile:     fabfile.write("from fabric.api import run, sudo, task\n\n@task\ndef myinstall():\n\tsudo('yum install httpd')") 

alway use with above open files, automatically close them , avoid these simple errors.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -