Is it possible to pass CSV Reader Object As Argument to another Python File ???

bansi mail2bansi at gmail.com
Wed Jan 26 15:24:33 EST 2011


On Jan 26, 1:31 pm, Chris Rebert <c... at rebertia.com> wrote:
> On Wed, Jan 26, 2011 at 7:51 AM, bansi <mail2ba... at gmail.com> wrote:
> > I have following two python scripts
> > -namelookupWrapper.py
> > -namelookup.py
>
> > The namelookupWrapper.py takes input of "memberId", "memberName" from
> > CLI and has following code snippet
>
> > idf = sys.argv[1]
> > namef = sys.argv[2]
> > real_script = "C:\\Splunk\\etc\\apps\\search\\bin\\namelookup.py"
> > r = csv.reader(sys.stdin)
> > os.execv(python_executable, [ python_executable, real_script ] +
> > sys.argv[1:] )
>
> > Wondering how would i pass csv reader object "r" as an argument using
> > os.execv() to another python script i.e. namelookup.py
>
> It's not possible to pass Python objects between processes in such a
> manner. Given that "independent" scripts can't directly take objects
> as input anyway, I doubt the two scripts are truly independent from
> each other. I would therefore concur with van Sebille that you should
> just rewrite them so that one script imports from the other rather
> than spawning the other. It should not be too hard to port the Python
> 2.6 script to Python 2.7 (or vice-versa if necessary).
>
> Cheers,
> Chris
> --http://blog.rebertia.com- Hide quoted text -
>
> - Show quoted text -

Thanks Chris. Sorry for mis-communicating, the two python scripts are
dependant in a way that
 namelookupWrapper.py needs to pass csv record object to another
python script

If thats not possible then please let me know how to do the workaround
i didnt understood the import thing and not sure if it helps in my
case

Here are the details
namelookupwrapper.py - takes input from stdin. Using csv reader object
i iterate thru the input which looks like as shown below

[MemberId, MemberName]
[123,       ]
[456,       ]
[989,       ]


Now i have another script i.e. namelookup.py running under Python 2.7
using pyodbc to retrieve Member Names from database for a given Member
Id in namelooupWrapper.py

So please let me know how to accomplish this



More information about the Python-list mailing list