I’m new to python and kind of been chucked in the deep end at work.
If i had a script which has creates a list such as below:
test = 'string'
l = []
for i in test:
l.append(i)
print l
How would i send that this to another python script?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m assuming you want to use the variable
some_listdefined in a script calledfirst.pyinto a second script calledsecond.pySo it would be:
The code in a file is declared as code module. To use it, you have to use:
frommoduleimportthingSo in this case the function
demowas defined as a function in the modulefirstIn the second file you import it and use it.
You can run arbitrary code in modules and declare variables but it is better if they are placed in functions ( or classes ) as shown above.
I hope this is what you needed.