Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 1st, 2008, 10:32 PM
Member
 
Join Date: Sep 2008
Posts: 35
Default how do i start my agrument?

hello, i am new to python and programming in general, i would like to know how to
use the "call" command

my code is something like this

Code:
def con():
    input = raw_input('Press y to start:')
    if input == "y" or "Y":
        return(menu_1())
    else:
        print 'OMG YA NOOB I SAID PRESS y!'
        return    
def menu_1():
    print '(1) Write noob to start "Stupid Program"' 
    print '(2) Write calc to start "Talking"'
    print '(3) This section is under construction'
    print '(4) This section is under construction'
    input2 = raw_input('Insert text here \n'*1)
now, how do i make it work when i activate it's .py file???
it just won't start, i think i need to make it activate automaticlly without the need to write the con() at the start, how do i do that?
do i need to use the __init__ or __call__ thingy i have no idea how to use it, yes i searched the web, but it wasnt very newby-friendly!
please help me!
Reply
  #2  
Old September 2nd, 2008, 12:41 AM
Expert
 
Join Date: Sep 2007
Posts: 844
Default

You can run your files from the command line with
Code:
python filename.py args
, where filename.py is the name of the file with your code in it and args are any command line arguments to the file. As to how you call a function, you simply use function(params).

For example:
[CODE=python]
def hello():
print "Hello, world!"

def sum(x, y):
return x+y

if '__name__' == '__main__': not strictly necessary, but a useful trick to know
hello() #calls hello
z = sum(3, 4) #returns 3+4=7
print z
[/code]
Reply
  #3  
Old September 2nd, 2008, 02:10 AM
Member
 
Join Date: Sep 2008
Posts: 35
Default

thank you, that was very helpful, another question, how do i use py2exe on that?
what do i need to do so it will start like that automaticlly so i can make it exe?
(just wondering)
Reply
  #4  
Old September 2nd, 2008, 03:35 AM
Member
 
Join Date: Sep 2008
Posts: 35
Exclamation

PS,
i am suppused to write "start Taco.py Base()" in the cmd????
(aftter i "cd" to the folder which the file is in)
im frustrated...

for the code
Code:
def Base():
    input=raw_input('Enter X here to start playing X-')
    if input=="X":
        return(Game())
    elif input=="q":
             exit(0) ...
Reply
  #5  
Old September 2nd, 2008, 02:28 PM
Expert
 
Join Date: Sep 2007
Posts: 844
Default

No, the command is 'python Taco.py' because the name of your file is Taco.py. To make it start by running that code, remove the indentation (and take it out of that function while you're at it).

I don't know anything about py2exe, sorry. I stick to Linux for my Python work...
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles