Python core Note: The file in python how to call other python script file, you certainly will not

Introduction

text and pictures of this article from the network, only to learn, exchange, not for any commercial purposes, belongs to original author, if any questions, please contact us for treatment.

Author: zhujuyu


I taught myself python when it came to such a practice questions: the two python script file merge, one readTextFile.py, one makeTextFile.py, merged into readNwriteTextFile.py. But I have written a while do not want to write it, there must be two files any way you can call directly. After a search, the answer is: os.system (filename), if you have not learned here, you can go to small series of Python exchange dress: a long time Wu and flow down a thought (homonym digital) converter which may be found , and there are new Python tutorial project, can talk about progress faster Oh!

  1.  
    import os
  2.  
    def read():
  3.  
    os.system( "./readFileText.py")
  4.  
    def write():
  5.  
    os.system( "./writeFileText.py")

After setting the input command python readNwriteTextFile.py do encounter such a problem at runtime:

./readTextFile.py: Permission denied

This means there is no authority, and that is the lack of any power? We use ls -l command to display the file attributes

You can see -rw-rw-r-- these documents are also not authorized to perform, then we need to add execute permissions to the file, if you have not learned yet unfamiliar here or Python, Python can go small series of exchanges skirt: a long time and its military and under a stream of thought (digital homonym) conversion can be found, there are new Python tutorial project, can talk about progress faster Oh!

Change the command chmod + x readTextFile.py in Terminal input permission, and then successfully execute python readNwriteFileText.py friends. writeTextFile.py as well.

 

Guess you like

Origin www.cnblogs.com/chengxuyuanaa/p/11991239.html