|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have many scripts that I want to convert to exes but it just does not work because it always says that a EOF Error has come in this script:
while 1: print "calc for a calculator" print "fib for the Fibonacci Sequnence" a= raw_input("Which option would you like to choose?") if a== "calc": import Calc print Calc elif a== "fib": import Fibonacci print Fibonacci in the fifth line by the raw_input("Which option would you like to choose") And an other question how do u exit a module but then u can go into it again is it with "reload" but i dont understand. please help me ![]() |
|
#2
|
||||
|
||||
|
Hmm, I would like to help you with your raw_input problem only your question doesn't seem to make much sense. Also the line, "in the fifth line by the line "raw_input("Which option would you like to choose")" seems to be randomly placed. Because of this I have no clue what exactly you need help with.
|
|
#3
|
||||
|
||||
|
You are using the import command to run code in your modules. This is the problem.
![]() You are right; the only way to re-execute the module would be to use the reload command. But this is not necessary. Normally, code run at import time is only used to configure the module or prepare things for later execution. Your modules need some functions that you can call after the module is imported... I suggest you investigate writing functions, you can then do things like: Code:
import fibonacci
import calc
while True:
a = raw_input("Type 'calc'' or 'fib' or 'quit'")
if a not in ['calc','fib','quit']:
continue
if a == 'quit':
break
if a == 'fib':
fibonacci.do_fibonacci() # do_fibonacci is a function you write in the fibonacci module.
elif a =='calc':
calc.do_calc() #do_calc is a function in the calc module
In your calc module you could have a function like this: Code:
def do_calc():
#the code to do calculations
I hope this helps ![]() grim ![]() p.s. use code tags!
__________________
*** Experimental Python Markup CGI V2 *** |
|
#4
|
|||
|
|||
|
ya but could you please explian the "def" thingy because i dont understand it
and please some examples |
|
#5
|
||||
|
||||
|
Quote:
Code:
def show(something):
print something
show("A string")
A string
list = [1, 2, 3]
show(list)
[1, 2, 3]
You gotta have parentheses after the function name, even if there are no parameters to the function, gotta have a colon after parentheses, and the body of the function has to be consistently indented. Code:
def multiply(a, b):
return a*b
multiply(2.5, 4)
10.0
|
|
#6
|
|||
|
|||
|
hm i get it a bit but wait
is it just like a thing name and then it just if u type that it asks u for the (a, b)and then it multiplys them like that oh ok thats good i am going to try something and then put the script put here thanks |
|
#7
|
||||
|
||||
|
No, this does not ask the user for a, b, but you could make it so
Code:
x = input("Please enter the first number: ")
y = input("Please enter the second number: ")
And then you can call the multiply(a, b) function like this: Code:
multiply(x, y)
__________________
Am I supposed to sign here?
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > raw_input (???) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|