hexagon logo

Simple input in python script

Hello everyone, i am learning python, and trying simple programs using python in Adams.
My problem is how to ask for input string:
 
Something like:
name=input()
 
is giving error such:
 
File "<string>", line 1, in <module>
EOFError: EOF when reading a line
 
or macros in adams python should be just script without input?
 
Jozef
Parents
  • Hi Jozef,
     
    This area needs some improvement, I believe. Here's the current way to do this:
    • Write a function in your file, perhaps like this (please excuse the formatting - it's wrong..):
     
    def make_some_parts(num_parts=10, some_prefix='part')
    <do some python stuff in here>
     
    • Then either execfile() your file or import your file on the View command line. That puts the function into your python namespace in View.
    • Now you can run your function on the python command line like: make_some_parts(99, 'my_part')
     
    Or maybe you'd type this in the python command line:
    x=99
    pre = 'my_part'
    and then call your function like:
    make_some_parts(x, pre)
     
    Hope I've understood what you're after here,
    Kent
     
     
     
Reply
  • Hi Jozef,
     
    This area needs some improvement, I believe. Here's the current way to do this:
    • Write a function in your file, perhaps like this (please excuse the formatting - it's wrong..):
     
    def make_some_parts(num_parts=10, some_prefix='part')
    <do some python stuff in here>
     
    • Then either execfile() your file or import your file on the View command line. That puts the function into your python namespace in View.
    • Now you can run your function on the python command line like: make_some_parts(99, 'my_part')
     
    Or maybe you'd type this in the python command line:
    x=99
    pre = 'my_part'
    and then call your function like:
    make_some_parts(x, pre)
     
    Hope I've understood what you're after here,
    Kent
     
     
     
Children
No Data