473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_packages'
group_name = 'sgeiger'
repo = '/var/svn'

def create(repo=repo,group_name=group_name,project_nam e=project_name):
#def create():
#os.system("sudo mkdir -p " + repo )
#os.system("sudo svnadmin create " + repo)
#os.system("sudo 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
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy
May 8 '07 #1
1 1103
In <ma***************************************@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_packages'
group_name = 'sgeiger'
repo = '/var/svn'

def create(repo=repo,group_name=group_name,project_nam e=project_name):
#def create():
#os.system("sudo mkdir -p " + repo )
#os.system("sudo svnadmin create " + repo)
#os.system("sudo 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
May 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2253
by: Ville Vainio | last post by:
Pythonic Nirvana - towards a true Object Oriented Environment ============================================================= IPython (by Francois Pinard) recently (next release - changes are...
16
2213
by: Kenneth McDonald | last post by:
For unfortunate reasons, I'm considering switching back to Win XP (from OS X) as my "main" system. Windows has so many annoyances that I can only compare it to driving in the Bay Area at rush hour...
0
1311
by: Todd D. Levy | last post by:
IF I have a database developed in the following environment: Windows XP Professional (all security patches and critical fixes installed) Office XP Professional (Access 2000 file format in Access...
3
1105
by: Tony Johansson | last post by:
Hello! I have some questions and I want to be sure about the :NET environment.. Question number 1: Is this right C++/CLI hasn't existed until in VS++ 2005(VC8) Question number 2: When you...
0
1270
by: Fernando Perez | last post by:
Hi all, The IPython team is happy to release version 0.7.2, with a lot of new enhancements, as well as many bug fixes. We hope you all enjoy it, and please report any problems as usual. ...
5
3275
by: Lou Pecora | last post by:
I installed the SciPy superpackage and have pylab, matplotlib, scipy, and numpy apparently running well. But I want to use matplotlib/pylab interactively. The instructions suggest doing this in...
0
1050
by: Ville Vainio | last post by:
Hi all, The IPython team is happy to release version 0.7.3, with a lot of new enhancements, as well as many bug fixes (including full Python 2.5 support). We hope you all enjoy it, and please...
2
2346
by: Greg Donald | last post by:
Anyone know what's up with environment variables when using ipython? When I type 'env' and hit return I get a dictionary full of useful information (trimmed for brevity): In : env Out:...
12
2099
by: thomas.guest | last post by:
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. .... Traceback (most recent call last): File "<stdin>", line 1, in <module>...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.