LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2008, 12:34 AM   #1
UpLink2008
Member
 
Registered: Aug 2008
Posts: 30

Rep: Reputation: 15
calling functions python


Right now I am going through some tutorials, This website in particular

http://www.sthurlow.com/python/lesson05/


And it talks about calling functions. What I am trying to do is make a simple function, Lets saying multiplying 5(70)

Then opening up a file and executing that program. I can't get it to work, I have searched the net to try to answer this question on my own, and all the information is advanced. Thanks alot guys!
 
Old 08-29-2008, 12:46 AM   #2
UpLink2008
Member
 
Registered: Aug 2008
Posts: 30

Original Poster
Rep: Reputation: 15
For example I wrote a simple program

a = 0
while a < 10:
a = a + 1
print a

I named this program myprogram.py

Now what I want to do is open up another file, and tell that file to execute that program, How do I do that? Thanks!
 
Old 08-29-2008, 12:49 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I don't code in Python, so can't help with the technical things. Your post, however, doesn't include much useful information to be able to help with the problem.

Quote:
Originally Posted by UpLink2008 View Post
And it talks about calling functions. What I am trying to do is make a simple function, Lets saying multiplying 5(70)
Can you post some code? Is there something on that page that you don't understand?

Quote:
Then opening up a file and executing that program. I can't get it to work
What does "I can't get it to work" mean? What have you tried and what happens? Post error messages if appropriate.
 
Old 08-29-2008, 12:57 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by UpLink2008 View Post
For example I wrote a simple program

a = 0
while a < 10:
a = a + 1
print a

I named this program myprogram.py

Now what I want to do is open up another file, and tell that file to execute that program, How do I do that? Thanks!
In a shell script, e.g.

Code:
#!/bin/bash

./myprogram.py
Of course, this assumes that myprogram.py is in the current directory and has executable permissions.

In a Python program, you can use os.system, e.g.

Code:
#!/usr/bin/python

import os
os.system("./myprogram.py")
Again, myprogram.py will need executable permissions.

Last edited by Nylex; 08-29-2008 at 01:09 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
QT calling functions ... How? Four Programming 3 02-11-2007 10:32 AM
Calling one of metacity's functions kiruxa Linux - General 0 11-25-2006 06:06 PM
calling functions outside the body(in c or c++).. bastin_gh Programming 1 07-06-2005 02:09 AM
Calling KDE/C++ functions from python/perl and vice versa yogeshm02 Programming 1 04-30-2005 11:54 AM
Calling functions in C++ oulevon Programming 3 01-28-2005 03:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration