0

I just want to have some ideas to know how to do that...

I have a python script that parses log files, the log name I give it as an argument so that when i want to run the script it's like that.. ( python myscript.py LOGNAME ) what I'd like to do is to have two scripts one that contains the functions and another that has only the main function so i don't know how to be able to give the argument when i run it from the second script.


here's my second script's code:

import sys
import os 
path = "/myscript.py"
sys.path.append(os.path.abspath(path))
import myscript 
mainFunction()

the error i have is:

script, name = argv 
valueError: need more than 1 value to unpack
asked May 6, 2013 at 7:26
3
  • path = "./myscript.py"? Also, this error most likely originates from myscript.py and not this script considering you don't even use sys.argv in this script Commented May 6, 2013 at 7:28
  • The error indicates you have 3 arguments in argv but are only unpacking two. Maybe show us more code? (From myscript) Commented May 6, 2013 at 7:29
  • 1
    The answer is: Both scrips share the same sys.argv Commented May 6, 2013 at 7:30

2 Answers 2

1

Python (just as most languages) will share parameters across imports and includes. Meaning that if you do:

python mysecondscript.py heeey that will flow down into myscript.py as well. So, check your arguments that you pass.

Script one

myscript = __import__('myscript')
myscript.mainfunction()

script two

import sys
def mainfunction():
 print sys.argv

And do:

python script_one.py parameter

You should get:

["script_one.py", "parameter"]

answered May 6, 2013 at 7:31
Sign up to request clarification or add additional context in comments.

1 Comment

As mentioned in a comment on snakes solution. If you need to modify the parameter then do so by supplying mainfunction() with a parameter.
0

You have several ways of doing it.

>>> execfile('filename.py')

Check the following link:

How to execute a file within the python interpreter?

answered May 6, 2013 at 7:28

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.