Mar-13-2019, 02:50 PM
Just beginning to learn about classes (I have been reading automate the boring).
Anyway I am using windows running IIS localhost to try out python in a web environment. I think I have managed to set it up to run python, struggling a bit with getting it to read a database. But before I need the database, I would like to write some classes in files and be able to import them.
However it seems it not as easy as just write the py file and import it... or perhaps it is and I`m doing it wrong.
I have got python 2.7 and 3.7 installed, as I couldnt get the python 3 to use mysql/mssql... So I mapped the scripts py2 for python 2.7 and py3 for python 3.7
File Structure:
py3
---- whattodo.py3
---- classes
-------- Person.py
whattodo.py3
Anyway I am using windows running IIS localhost to try out python in a web environment. I think I have managed to set it up to run python, struggling a bit with getting it to read a database. But before I need the database, I would like to write some classes in files and be able to import them.
However it seems it not as easy as just write the py file and import it... or perhaps it is and I`m doing it wrong.
I have got python 2.7 and 3.7 installed, as I couldnt get the python 3 to use mysql/mssql... So I mapped the scripts py2 for python 2.7 and py3 for python 3.7
File Structure:
py3
---- whattodo.py3
---- classes
-------- Person.py
whattodo.py3
# get a passed command and do something with it... ''' class Person: def __init__(self, name, age): self.name = name self.age = age ''' from classes import Person print('Content-Type: text/html') print('CharSet: ISO-8859-1') print('') print('<meta charset="ISO-8859-1" content="charset=ISO-8859-1">') print('<html><head><title>.P.</title></head><body>') p = Person('John',42) print(p.name+' '+str(p.age)) print('</body') print('</html>')and the person.py:
class Person: def __init__(self, name, age): self.name = name self.age = ageSo obviously I've done something wrong... is it an easy fix?