Results 1 to 4 of 4

Thread: Pass a variable for one script to another in python

  1. #1
    Member AljoshaNL's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    230

    Pass a variable for one script to another in python

    Hello programmers,

    I'm writing a vocabulary application, and I'm trying to do it in components. I started of with a check_voca.py script which checks the validity of a given vocabulary file. After the script is executed I need a way to pass the information to the next script executed. I think the solution in C/C++ would be pointers.

    But there are no such things in Python, or at least that's what I've read. So how can I pass the variable to another script

    Aljosha

    Post-Scriptum: This is NOT a homework help request, in fact, I don't get anything in school that you could help with
    Eat your l33t skillz!
    My home page: http://www.inter.nl.net/users/alexeif/

  2. #2
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630
    You can pass arguments when calling a python script:

    Code:
    #!/usr/bin/python
    #
    # filename: testarg.py
    #
    import sys
    
    print 'the first argument passed to me is: %s' % (sys.argv[1])

    Code:
    #!/usr/bin/python
    #
    # filename: passarg.py
    #
    # pass bob to testarg script
    import os
    
    my_cmd = './testarg.py bob'
    os.system(my_cmd)
    Code:
    radar@saturn:~$ ./passarg.py
    the first argument passed to me is: bob
    However, it seems this is ugly and your best bet is to make modules:

    http://www.ibiblio.org/g2swap/byteof...d/modules.html

  3. #3
    Member AljoshaNL's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    230
    Thanks Outlaw
    Do you program for your bread?
    Eat your l33t skillz!
    My home page: http://www.inter.nl.net/users/alexeif/

  4. #4
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630
    Quote Originally Posted by AljoshaNL
    Do you program for your bread?
    No, I don't. I'm a sysadmin by trade and cobble stuff together in shell and sometimes python. I'm a python noob.

Similar Threads

  1. SSH and bash script
    By vwgtiturbo in forum Programming
    Replies: 7
    Last Post: 12-25-2008, 04:40 AM
  2. Firewall script in RHEL 4
    By sud.tech in forum Programming
    Replies: 8
    Last Post: 06-12-2008, 01:07 PM
  3. Rsync incremental backup script
    By vwgtiturbo in forum Programming
    Replies: 6
    Last Post: 06-07-2006, 08:19 PM
  4. Shell Script to modify apachectl
    By gaxprels in forum Programming
    Replies: 6
    Last Post: 07-23-2002, 07:18 PM
  5. pf.conf in OpenBSD
    By Schotty in forum BSD
    Replies: 20
    Last Post: 06-08-2002, 08:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •