ipython environment question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shane Geiger

    #1

    ipython environment question

    """
    I'm trying to import ipython shell (which works great!) to set some
    variables and then run a function (which doesn't work).
    It seems like such a simple thing. Here's an example script to show
    what I'm trying to do.

    Run the script and then try to change the variable project_name from the
    ipython prompt and then type create()
    and the new value you assigned will *not* be used. I tried to use "def
    create(project_ name = project_name):" Even that didn't work.

    What slight of hand is necessary?



    import os, sys

    project_name = 'python_package s'
    group_name = 'sgeiger'
    repo = '/var/svn'

    def create(repo=rep o,group_name=gr oup_name,projec t_name=project_ name):
    #def create():
    #os.system("sud o mkdir -p " + repo )
    #os.system("sud o svnadmin create " + repo)
    #os.system("sud o chown -R " + group_name + " " + repo)
    print "sudo mkdir -p " + repo + '/' + project_name
    print "sudo svnadmin create " + repo + '/' + project_name
    print "sudo chown -R " + group_name + " " + repo + '/' + project_name

    if __name__ == '__main__':
    sys.argv.append ('-cl')
    from IPython.Shell import IPShellEmbed
    ipshell = IPShellEmbed()
    print "Please set these variables: project_name, group_name ...and
    then type create()"
    ### I even tried to put all my
    ipshell() # this call anywhere in your program will start IPython

    --
    Shane Geiger
    IT Director
    National Council on Economic Education
    sgeiger@ncee.ne t | 402-438-8958 | http://www.ncee.net

    Leading the Campaign for Economic and Financial Literacy


  • Marc 'BlackJack' Rintsch

    #2
    Re: ipython environment question

    In <mailman.7420.1 178634651.32031 .python-list@python.org >, Shane Geiger
    wrote:
    Run the script and then try to change the variable project_name from the
    ipython prompt and then type create()
    and the new value you assigned will *not* be used. I tried to use "def
    create(project_ name = project_name):" Even that didn't work.
    >
    What slight of hand is necessary?
    >
    import os, sys
    >
    project_name = 'python_package s'
    group_name = 'sgeiger'
    repo = '/var/svn'
    >
    def create(repo=rep o,group_name=gr oup_name,projec t_name=project_ name):
    #def create():
    #os.system("sud o mkdir -p " + repo )
    #os.system("sud o svnadmin create " + repo)
    #os.system("sud o chown -R " + group_name + " " + repo)
    print "sudo mkdir -p " + repo + '/' + project_name
    print "sudo svnadmin create " + repo + '/' + project_name
    print "sudo chown -R " + group_name + " " + repo + '/' + project_name
    >
    if __name__ == '__main__':
    sys.argv.append ('-cl')
    from IPython.Shell import IPShellEmbed
    ipshell = IPShellEmbed()
    print "Please set these variables: project_name, group_name ...and
    then type create()"
    ### I even tried to put all my
    ipshell() # this call anywhere in your program will start IPython
    You have to call the function with arguments. The default values are only
    evaluated once when the ``def`` statement is executed, not every time the
    function is called.

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    Working...