question about YADE doing work with PYTHON

Asked by Fu zuoguang on 2013-06-27

Dear all users:
     There is now a very long script for me to run my simulation, So I want to divide it into some small py modules and use "import" command to call these modules one by one. At the first, I have employed some small cases to test steps. There are two py modules that can be used, one is the basic command mudule, which can be described as that(named exam.py):
###################################################################################################
def print():

    print ('hello')
###################################################################################################
Another is executive module, which can be described as that(named test.py):
###################################################################################################
import exam

exam.print()

print ('hello')
###################################################################################################

My procedures can be shown one bu one as:
(1).start the terminal of Ubuntu and specify the path of folder including these two scripts.
(2).In this shell, input "yade-stable test.py". And the shell notices that "no modules ex"
(3).Then in this shell, input "python test.py". Nothing is wrong at this time and the shell shows that:
####################################################################################################
hello
hello
##################################################################################################

I do not know what is wrong with my operations and how can I do only for my purpose. Seeking for your help!

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Fu zuoguang
Solved:
2013-06-27
Last query:
2013-06-27
Last reply:
2013-06-27
Christian Jakob (jakob-ifgt) said : #1

This is not a question about yade. So this is not the right place to post...
Nethertheless I wrote a nice script, that may help you:

c=-1

def choose():
 if c == 0:
  print 'Try this one: http://docs.python.org/2/tutorial/'
 elif c==1:
  print 'Maybe this helps you: http://www.learnpython.org/'
 elif c==2:
  print 'Give it a try: http://www.tutorialspoint.com/python/'
 elif c==3:
  print 'go to http://www.google.de/ and type: python tutorial'

c=input('Please choose a value between 0 and 3: ')
choose()

Fu zuoguang (zgfu1985) said : #2

Dear Christian Jakob:
          You are perfect right, now I fully understand what the mistake is in this done.
#########################################################################################
import sys
sys.path.append('/home/fzg/fu/qq')
import ex
ex.fzg()
print ('There is nothing wrong with it')
########################################################################################
Before importing the ex.py, path assignation should be finished first, just like this. now all things are fine.