PDA

View Full Version : Problema su python


ciaox1
17-08-2010, 17:49
Salve a tutti.Ho compilato una shell in batch che si chiama win-dos.ora pero la vorrei fare in python.Codice scritto,ma non funziona bene!ve lo faccio vedere:
a="pydos"
print " PY-DOS 0.1 "
print "Welcome to PY-DOS,A Distro of WIN-DOS.Type creditsPY,licensePY,infoPY,ThanksPY or helpPY for various info"
if a=="licensePY":
print "THIS PROGRAM IS OPEN SOURCE.YOU ARE ALLOWED TO REDISTRIBUTE VERBATIM COPIES OF THIS SCRIPT."
if a== "creditsPY":
print " © Tech Develop X 2010."
if a=="infoPY":
print "This program Is a modification of WIN-DOS,Created be Tech Develop X.You'll need IDLE(PHYTON GUI) 2.X to run this script, personalize the App launcher And The Text creating."
if a=="ThanksPY":
print "Thanks to Guido van rossum,Creator of Phyton Programming Language."
if a=="helpPY":
print "COMMANDS;Calculator:type calc(Addition type +;Subtraction type -;Multiplication type x;Division type /);App Launcher:type apps;Type something in a text file:txt;Any other word:Close Py-Dos."
if a=="calc":
b=raw_input("Operation?")
if b=="+":
num1=input("Number?")
num2=input("Number?")
num3=input("Number?")
print"Total sum of inserted numbers is:",num1+num2+num3
if b=="-":
num1=input("Number?")
num2=input("Number?")
num3=input("Number?")
print"Total sum of inserted numbers is:",num1-num1-num1
if b=="x":
num1=input("Number?")
num2=input("Number?")
num3=input("Number?")
print"Total sum of inserted numbers is:",num1*num2*num3
if b=="/":
num1=input("Number?")
num2=input("Number?")
num3=input("Number?")
print"Total sum of inserted numbers is:",num1/num2/num3
if a=="apps":
import os
os.chdir('C:\program files\Mozilla Firefox')
os.startfile("firefox.exe")
if a=="txt":
fileHandle = open ( 'testexample.txt', 'wb' )
fileHandle.write ( 'EXAMPLE.' )
fileHandle.close()



si avvia ma...

Welcome to PY-DOS,A Distro of WIN-DOS.Type creditsPY,licensePY,infoPY,ThanksPY or helpPY for various info
Number?1
Number?1
Number?1
Total sum of inserted numbers is: 3
Total sum of inserted numbers is: -1
Total sum of inserted numbers is: 1
Total sum of inserted numbers is: 1
Traceback (most recent call last):
File "C:\Documents and Settings\GIORGIO\Desktop\WIN-DOS\winpy.py", line 38, in <module>
os.chdir('C:\program files\Mozilla Firefox')
NameError: name 'os' is not defined

Grazie in anticipo =)

Mulder90
17-08-2010, 19:33
scritto così non credo che riceverai risposte perchè appena lo vedi ti passa la voglia anche solo di leggerlo.
Cerca di indentare per bene il codice e di metterlo nell'apposito tag.
Esempio:

class Esempio:
def __init__(self, ecc, ecc):
self.prova = pippo
self.riprova = pluto
def nonsopiùchescrivere(self, x):
self.lol(x)

Ryuzaki_Eru
18-08-2010, 10:10
scritto così non credo che riceverai risposte perchè appena lo vedi ti passa la voglia anche solo di leggerlo.


Esattamente.