Shinyshell Community Forums > Coding >
I've got an issue with Python...


[1]


July 23 02009, 20:53 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
Okay, I really want to learn Python. Real bad, too. I've been using Think Python along with the Python Interpreter/Komodo Edit and I still can't put two and two together.

Are there any books I can read that will help me in my Python quest? Or more preferably, PDFs?

I've gotten a hang of Perl and I want to try something that doesn't look like PHP.


EDIT: nevermind
______________________________

Linux | Chrome | Python | Chuck

July 24 02009, 18:36 GMT
Peter*
A Pythonic One

Peter's avatar
Location: US
Post count: 99

The same dilemma has appeared to me.

July 30 02009, 23:56 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
Okay, starting Python again...

Well, I've been trying to use Python's modular capabilities to my advantage. Using something Electron suggested:

#!/usr/bin/python 

print "Content-type: text/html\n"

import stuff.layout
print stuff.layout.top
#!/usr/bin/python

print "Content-type: text/html\n"

import stuff.layout
print stuff.layout.top
]]>


That was the content of test.py. This is the content of layout.py (it's actually much larger, but I shrunk it for this purpose)
#!/usr/bin/python 

print "Content-type: text/html\n"
top = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
"""
#!/usr/bin/python

print "Content-type: text/html\n"
top = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
"""
]]>


I have a few questions:
1. Am I supposed to put the import before or after the content header?
2. Do I need the shebang in stuff.py
3. Is there anything else I'm doing wrong?
______________________________

Linux | Chrome | Python | Chuck

July 31 02009, 09:49 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
1. It doesn't matter, I shouldn't think. As long as you print the content header before you print anything at all, it should be fine.
2. It should be like a PHP include, so you don't need the #!/usr/bin/python thing at all. Just go straight into the code
3. I'm not sure.
______________________________
Lazurane

July 31 02009, 09:53 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
The test.py file is okay, though I'd print the content type not at the start of the script, but there where you need it. It's also not a requirement, but a good convention to put your imports at the start of the script.

#!/usr/bin/python  

import stuff.layout

print "Content-type: text/html\n"
print stuff.layout.top
#!/usr/bin/python

import stuff.layout

print "Content-type: text/html\n"
print stuff.layout.top
]]>


That's fine. However, you say - the content of stuff.py ? Nope, you called

import stuff.layout 
import stuff.layout
]]>


Python looks for a module called "stuff" (in our case a folder in the same directory as test.py). You have to have a folder called "stuff".

Then, within that module, it looks for a "layout.py". That's why it needs to be layout.py. You could call it whatever you want, but it's important that it's import directory.file

Next, the layout.py file itself. You should realise that Content-type:text/html is a header. Headers tell the browser what kind of content follows them. Since you are printing your content from test.py, you sent a header already. You only need to send headers once.

Thus the code should be simply:
top = """<?xml version="1.0" encoding="utf-8"?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
"""
top = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
"""
]]>


I forgot to mention two things:

  1. You don't need a shebang line in modules, only in the script you run first (test.py), as Nick said. Anything test.py includes does not require a shebang.
  2. For python to recognise your "stuff" folder as a module, you need to (apart from your own files) put an __init__.py file in it. It doesn't matter if it's completely empty, it just needs to be there.

July 31 02009, 17:25 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
electron said

That's fine. However, you say - the content of stuff.py ? Nope, you called

import stuff.layout 




Python looks for a module called "stuff" (in our case a folder in the same directory as test.py). You have to have a folder called "stuff".

Oops! I mean to say "layout.py" I had that in a folder called stuff.
electron said
For python to recognise your "stuff" folder as a module, you need to (apart from your own files) put an __init__.py file in it. It doesn't matter if it's completely empty, it just needs to be there.

Oh, so I would just create a new .py file in Komodo, change the line endings, and placed it into "stuff"? Nevermind, I got it working.
______________________________

Linux | Chrome | Python | Chuck

July 31 02009, 17:49 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Hehe, good-oh :D

Also, line endings aren't important in modules, apparently. They also don't have to have chmod 755, because they're not really getting executed, only read.

August 02 02009, 21:10 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
Another question!
I've been working on a sprite generator thingy that generates sprites based on the game, generation, and frame that the user chooses.
names = ["bulbasaur", "ivysaur", "venusaur", "charmander", "charmeleon", "charizard", "squirtle", "wartortle", "blastoise", "caterpie", "metapod", "butterfree", "weedle", "kakuna", "beedrill", "pidgey", "pidgeotto", "pidgeot", "rattata", "raticate", "spearow", "fearow", "ekans", "arbok", "pikachu", "raichu", "sandshrew", "sandslash", "nidoranf", "nidorina", "nidoqueen", "nidoranm", "nidorino", "nidoking", "clefairy", "clefable", "vulpix", "ninetales", "jigglypuff", "wigglytuff", "zubat", "golbat", "oddish", "gloom", "vileplume", "paras", "parasect", "venonat", "venomoth", "diglett", "dugtrio", "meowth", "persian", "psyduck", "golduck", "mankey", "primeape", "growlithe", "arcanine", "poliwag", "poliwhirl", "poliwrath", "abra", "kadabra", "alakazam", "machop", "machoke", "machamp", "bellsprout", "weepinbell", "victreebel", "tentacool", "tentacruel", "geodude", "graveler", "golem", "ponyta", "rapidash", "slowpoke", "slowbro", "magnemite", "magneton", "farfetchd", "doduo", "dodrio", "seel", "dewgong", "grimer", "muk", "shellder", "cloyster", "gastly", "haunter", "gengar", "onix", "drowzee", "hypno", "krabby", "kingler", "voltorb", "electrode", "exeggcute", "exeggutor", "cubone", "marowak", "hitmonlee", "hitmonchan", "lickitung", "koffing", "weezing", "rhyhorn", "rhydon", "chansey", "tangela", "kangaskhan", "horsea", "seadra", "goldeen", "seaking", "staryu", "starmie", "mrmime", "scyther", "jynx", "electabuzz", "magmar", "pinsir", "tauros", "magikarp", "gyarados", "lapras", "ditto", "eevee", "vaporeon", "jolteon", "flareon", "porygon", "omanyte", "omastar", "kabuto", "kabutops", "aerodactyl", "snorlax", "articuno", "zapdos", "moltres", "dratini", "dragonair", "dragonite", "mewtwo", "mew", "chikorita", "bayleef", "meganium", "cyndaquil", "quilava", "typhlosion", "totodile", "croconaw", "feraligatr", "sentret", "furret", "hoothoot", "noctowl", "ledyba", "ledian", "spinarak", "ariados", "crobat", "chinchou", "lanturn", "pichu", "cleffa", "igglybuff", "togepi", "togetic", "natu", "xatu", "mareep", "flaaffy", "ampharos", "bellossom", "marill", "azumarill", "sudowoodo", "politoed", "hoppip", "skiploom", "jumpluff", "aipom", "sunkern", "sunflora", "yanma", "wooper", "quagsire", "espeon", "umbreon", "murkrow", "slowking", "misdreavus", "unown", "wobbuffet", "girafarig", "pineco", "forretress", "dunsparce", "gligar", "steelix", "snubbull", "granbull", "qwilfish", "scizor", "shuckle", "heracross", "sneasel", "teddiursa", "ursaring", "slugma", "magcargo", "swinub", "piloswine", "corsola", "remoraid", "octillery", "delibird", "mantine", "skarmory", "houndour", "houndoom", "kingdra", "phanpy", "donphan", "porygon2", "stantler", "smeargle", "tyrogue", "hitmontop", "smoochum", "elekid", "magby", "miltank", "blissey", "raikou", "entei", "suicune", "larvitar", "pupitar", "tyranitar", "lugia", "hooh", "celebi", "treecko", "grovyle", "sceptile", "torchic", "combusken", "blaziken", "mudkip", "marshtomp", "swampert", "poochyena", "mightyena", "zigzagoon", "linoone", "wurmple", "silcoon", "beautifly", "cascoon", "dustox", "lotad", "lombre", "ludicolo", "seedot", "nuzleaf", "shiftry", "taillow", "swellow", "wingull", "pelipper", "ralts", "kirlia", "gardevoir", "surskit", "masquerain", "shroomish", "breloom", "slakoth", "vigoroth", "slaking", "nincada", "ninjask", "shedinja", "whismur", "loudred", "exploud", "makuhita", "hariyama", "azurill", "nosepass", "skitty", "delcatty", "sableye", "mawile", "aron", "lairon", "aggron", "meditite", "medicham", "electrike", "manectric", "plusle", "minun", "volbeat", "illumise", "roselia", "gulpin", "swalot", "carvanha", "sharpedo", "wailmer", "wailord", "numel", "camerupt", "torkoal", "spoink", "grumpig", "spinda", "trapinch", "vibrava", "flygon", "cacnea", "cacturne", "swablu", "altaria", "zangoose", "seviper", "lunatone", "solrock", "barboach", "whiscash", "corphish", "crawdaunt", "baltoy", "claydol", "lileep", "cradily", "anorith", "armaldo", "feebas", "milotic", "castform", "kecleon", "shuppet", "banette", "duskull", "dusclops", "tropius", "chimecho", "absol", "wynaut", "snorunt", "glalie", "spheal", "sealeo", "walrein", "clamperl", "huntail", "gorebyss", "relicanth", "luvdisc", "bagon", "shelgon", "salamence", "beldum", "metang", "metagross", "regirock", "regice", "registeel", "latias", "latios", "kyogre", "groudon", "rayquaza", "jirachi", "deoxys", "turtwig", "grotle", "torterra", "chimchar", "monferno", "infernape", "piplup", "prinplup", "empoleon", "starly", "staravia", "staraptor", "bidoof", "bibarel", "kricketot", "kricketune", "shinx", "luxio", "luxray", "budew", "roserade", "cranidos", "rampardos", "shieldon", "bastiodon", "burmy", "wormadam", "mothim", "combee", "vespiquen", "pachirisu", "buizel", "floatzel", "cherubi", "cherrim", "shellos", "gastrodon", "ambipom", "drifloon", "drifblim", "buneary", "lopunny", "mismagius", "honchkrow", "glameow", "purugly", "chingling", "stunky", "skuntank", "bronzor", "bronzong", "bonsly", "mimejr", "happiny", "chatot", "spiritomb", "gible", "gabite", "garchomp", "munchlax", "riolu", "lucario", "hippopotas", "hippowdon", "skorupi", "drapion", "croagunk", "toxicroak", "carnivine", "finneon", "lumineon", "mantyke", "snover", "abomasnow", "weavile", "magnezone", "lickilicky", "rhyperior", "tangrowth", "electivire", "magmortar", "togekiss", "yanmega", "leafeon", "glaceon", "gliscor", "mamoswine", "porygonz", "gallade", "probopass", "dusknoir", "froslass", "rotom", "rotom-fire", "rotom-flying", "rotom-grass", "rotom-ice", "rotom-water", "uxie", "mesprit", "azelf", "dialga", "palkia", "heatran", "regigigas", "giratina", "giratina-origin", "cresselia", "phione", "manaphy", "darkrai", "shaymin", "shaymin-sky", "arceus", "arceus-bug", "arceus-dark", "arceus-dragon", "arceus-electric", "arceus-fighting", "arceus-fire", "arceus-flying", "arceus-ghost", "arceus-grass", "arceus-ground", "arceus-ice", "arceus-poison", "arceus-psychic", "arceus-rock", "arceus-steel", "arceus-unknown", "arceus-water"] 
count = 0
while (count <= 250):
print """<img src="/sprites/%s%s/%s.png" alt="" />""" % (game, frame, names[count])
count = count + 1
names = ["bulbasaur", "ivysaur", "venusaur", "charmander", "charmeleon", "charizard", "squirtle", "wartortle", "blastoise", "caterpie", "metapod", "butterfree", "weedle", "kakuna", "beedrill", "pidgey", "pidgeotto", "pidgeot", "rattata", "raticate", "spearow", "fearow", "ekans", "arbok", "pikachu", "raichu", "sandshrew", "sandslash", "nidoranf", "nidorina", "nidoqueen", "nidoranm", "nidorino", "nidoking", "clefairy", "clefable", "vulpix", "ninetales", "jigglypuff", "wigglytuff", "zubat", "golbat", "oddish", "gloom", "vileplume", "paras", "parasect", "venonat", "venomoth", "diglett", "dugtrio", "meowth", "persian", "psyduck", "golduck", "mankey", "primeape", "growlithe", "arcanine", "poliwag", "poliwhirl", "poliwrath", "abra", "kadabra", "alakazam", "machop", "machoke", "machamp", "bellsprout", "weepinbell", "victreebel", "tentacool", "tentacruel", "geodude", "graveler", "golem", "ponyta", "rapidash", "slowpoke", "slowbro", "magnemite", "magneton", "farfetchd", "doduo", "dodrio", "seel", "dewgong", "grimer", "muk", "shellder", "cloyster", "gastly", "haunter", "gengar", "onix", "drowzee", "hypno", "krabby", "kingler", "voltorb", "electrode", "exeggcute", "exeggutor", "cubone", "marowak", "hitmonlee", "hitmonchan", "lickitung", "koffing", "weezing", "rhyhorn", "rhydon", "chansey", "tangela", "kangaskhan", "horsea", "seadra", "goldeen", "seaking", "staryu", "starmie", "mrmime", "scyther", "jynx", "electabuzz", "magmar", "pinsir", "tauros", "magikarp", "gyarados", "lapras", "ditto", "eevee", "vaporeon", "jolteon", "flareon", "porygon", "omanyte", "omastar", "kabuto", "kabutops", "aerodactyl", "snorlax", "articuno", "zapdos", "moltres", "dratini", "dragonair", "dragonite", "mewtwo", "mew", "chikorita", "bayleef", "meganium", "cyndaquil", "quilava", "typhlosion", "totodile", "croconaw", "feraligatr", "sentret", "furret", "hoothoot", "noctowl", "ledyba", "ledian", "spinarak", "ariados", "crobat", "chinchou", "lanturn", "pichu", "cleffa", "igglybuff", "togepi", "togetic", "natu", "xatu", "mareep", "flaaffy", "ampharos", "bellossom", "marill", "azumarill", "sudowoodo", "politoed", "hoppip", "skiploom", "jumpluff", "aipom", "sunkern", "sunflora", "yanma", "wooper", "quagsire", "espeon", "umbreon", "murkrow", "slowking", "misdreavus", "unown", "wobbuffet", "girafarig", "pineco", "forretress", "dunsparce", "gligar", "steelix", "snubbull", "granbull", "qwilfish", "scizor", "shuckle", "heracross", "sneasel", "teddiursa", "ursaring", "slugma", "magcargo", "swinub", "piloswine", "corsola", "remoraid", "octillery", "delibird", "mantine", "skarmory", "houndour", "houndoom", "kingdra", "phanpy", "donphan", "porygon2", "stantler", "smeargle", "tyrogue", "hitmontop", "smoochum", "elekid", "magby", "miltank", "blissey", "raikou", "entei", "suicune", "larvitar", "pupitar", "tyranitar", "lugia", "hooh", "celebi", "treecko", "grovyle", "sceptile", "torchic", "combusken", "blaziken", "mudkip", "marshtomp", "swampert", "poochyena", "mightyena", "zigzagoon", "linoone", "wurmple", "silcoon", "beautifly", "cascoon", "dustox", "lotad", "lombre", "ludicolo", "seedot", "nuzleaf", "shiftry", "taillow", "swellow", "wingull", "pelipper", "ralts", "kirlia", "gardevoir", "surskit", "masquerain", "shroomish", "breloom", "slakoth", "vigoroth", "slaking", "nincada", "ninjask", "shedinja", "whismur", "loudred", "exploud", "makuhita", "hariyama", "azurill", "nosepass", "skitty", "delcatty", "sableye", "mawile", "aron", "lairon", "aggron", "meditite", "medicham", "electrike", "manectric", "plusle", "minun", "volbeat", "illumise", "roselia", "gulpin", "swalot", "carvanha", "sharpedo", "wailmer", "wailord", "numel", "camerupt", "torkoal", "spoink", "grumpig", "spinda", "trapinch", "vibrava", "flygon", "cacnea", "cacturne", "swablu", "altaria", "zangoose", "seviper", "lunatone", "solrock", "barboach", "whiscash", "corphish", "crawdaunt", "baltoy", "claydol", "lileep", "cradily", "anorith", "armaldo", "feebas", "milotic", "castform", "kecleon", "shuppet", "banette", "duskull", "dusclops", "tropius", "chimecho", "absol", "wynaut", "snorunt", "glalie", "spheal", "sealeo", "walrein", "clamperl", "huntail", "gorebyss", "relicanth", "luvdisc", "bagon", "shelgon", "salamence", "beldum", "metang", "metagross", "regirock", "regice", "registeel", "latias", "latios", "kyogre", "groudon", "rayquaza", "jirachi", "deoxys", "turtwig", "grotle", "torterra", "chimchar", "monferno", "infernape", "piplup", "prinplup", "empoleon", "starly", "staravia", "staraptor", "bidoof", "bibarel", "kricketot", "kricketune", "shinx", "luxio", "luxray", "budew", "roserade", "cranidos", "rampardos", "shieldon", "bastiodon", "burmy", "wormadam", "mothim", "combee", "vespiquen", "pachirisu", "buizel", "floatzel", "cherubi", "cherrim", "shellos", "gastrodon", "ambipom", "drifloon", "drifblim", "buneary", "lopunny", "mismagius", "honchkrow", "glameow", "purugly", "chingling", "stunky", "skuntank", "bronzor", "bronzong", "bonsly", "mimejr", "happiny", "chatot", "spiritomb", "gible", "gabite", "garchomp", "munchlax", "riolu", "lucario", "hippopotas", "hippowdon", "skorupi", "drapion", "croagunk", "toxicroak", "carnivine", "finneon", "lumineon", "mantyke", "snover", "abomasnow", "weavile", "magnezone", "lickilicky", "rhyperior", "tangrowth", "electivire", "magmortar", "togekiss", "yanmega", "leafeon", "glaceon", "gliscor", "mamoswine", "porygonz", "gallade", "probopass", "dusknoir", "froslass", "rotom", "rotom-fire", "rotom-flying", "rotom-grass", "rotom-ice", "rotom-water", "uxie", "mesprit", "azelf", "dialga", "palkia", "heatran", "regigigas", "giratina", "giratina-origin", "cresselia", "phione", "manaphy", "darkrai", "shaymin", "shaymin-sky", "arceus", "arceus-bug", "arceus-dark", "arceus-dragon", "arceus-electric", "arceus-fighting", "arceus-fire", "arceus-flying", "arceus-ghost", "arceus-grass", "arceus-ground", "arceus-ice", "arceus-poison", "arceus-psychic", "arceus-rock", "arceus-steel", "arceus-unknown", "arceus-water"]
count = 0
while (count <= 250):
print """<img src="/sprites/%s%s/%s.png" alt="" />""" % (game, frame, names[count])
count = count + 1
]]>

I've already got it so that if they pick generation II, it'll show the sprites from not only Johto (values 151-250), but Kanto (values 0-150) as well. How to I make it so that it skips values 0-150 and just show values 151-250? I've looked at break and continue, but I didn't really get them.
______________________________

Linux | Chrome | Python | Chuck

August 02 02009, 21:52 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Break ends the loop you are in, and continues with the rest of the code (as if the looping condition has been satisfied, without actually being satisfied).

Continue just skips to the next loop. It would be useful in your example:

johto = True 

while (count <= 250):
# if you only want johto sprites but the current
# sprite is Kanto, increase count and continue looping
if johto and count <= 150:
count += 1
continue

print """<img src="/sprites/%s%s/%s.png" alt="" />""" % (game, frame, names[count])
count += 1
johto = True

while (count <= 250):
# if you only want johto sprites but the current
# sprite is Kanto, increase count and continue looping
if johto and count <= 150:
count += 1
continue

print """<img src="/sprites/%s%s/%s.png" alt="" />""" % (game, frame, names[count])
count += 1
]]>

August 03 02009, 03:04 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
Thanks, that did the trick.

(coding in python is so fun)

EDIT: MySQL issue.

#!/home/aiiro_pikachu/bin/python 

import MySQLdb

print "Content-type: text/html\n"
db = MySQLdb.connect("mysql.aiirodeign.com","aiiro_pikachu","*******","aiiro_pikachu_sql" )
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()

import MySQLdb

print "Content-type: text/html\n"
db = MySQLdb.connect("mysql.aiirodeign.com","aiiro_pikachu","*******","aiiro_pikachu_sql" )
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()]]>

This doesn't seem to work because I get a big 500 server error. What am I doing wrong? The page

I need help fast so I can work on my site.
______________________________

Linux | Chrome | Python | Chuck

August 04 02009, 09:54 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
The code itself is fine, except:
"mysql.aiirodeign.com" 

should be
"mysql.aiirodesign.com" 

However, this doesn't fix the issue. Apparently, something has happened to the Python installation I set up for you. I can't understand it, because it worked just yesterday. I'll have to sort this out...

August 04 02009, 10:12 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Okay, I recompiled and reinstalled Python. I supplied the proper path to the configurer this time, so the install went smoother than last time. I expect you won't have these problems any more.

I also took the liberty of fixing that bug for you (to check whether I've solved the problem), so now your script works. :D

P.S. I love your beta site & layout so far!

August 04 02009, 20:08 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
Thanks again. *showers electron with even more thanks*

I've got another problem. I'm trying to embed the MySQL query into the body of my HTML page, but instead of giving me the version number, it completely destroys the page. I have a feeling that the MySQL stuff isn't supposed to be under the header, but this is the only way (it seems) that I don't get a big fat server error.
#!/home/aiiro_pikachu/bin/python 

import stuff.layout
import MySQLdb

print "Content-type: text/html\n"
print stuff.layout.top
print "<title>Pikachu's Plaza Beta</title>"
print stuff.layout.mid
print """<h1>Pok&eacute;tracker</h1>"""
db = MySQLdb.connect("mysql.aiirodeign.com","aiiro_pikachu","wi#d45P","aiiro_pikachu_sql")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()
print """<p class="last_modified">Last Modified on August 1<sup>st</sup> 2009 at 12:02 PM PST</p>
"""
print stuff.layout.bottom
#!/home/aiiro_pikachu/bin/python

import stuff.layout
import MySQLdb

print "Content-type: text/html\n"
print stuff.layout.top
print "<title>Pikachu's Plaza Beta</title>"
print stuff.layout.mid
print """<h1>Pok&eacute;tracker</h1>"""
db = MySQLdb.connect("mysql.aiirodeign.com","aiiro_pikachu","wi#d45P","aiiro_pikachu_sql")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()
print """<p class="last_modified">Last Modified on August 1<sup>st</sup> 2009 at 12:02 PM PST</p>
"""
print stuff.layout.bottom
]]>


Also, in PHP, if you screw up it gives you the line number of where the screw up is. In Python, it doesn't, just a server error. Is there any way I can do that in Python?
______________________________

Linux | Chrome | Python | Chuck

August 04 02009, 23:31 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Once again, you seem to be referring to your MySQL host as "aiirodeign" xD.

I expect once you fix that, your script will work fine.

Python is versatile and easy. There are very little if any rules as to how you should structure your code. Of course you could have done the MySQL stuff before printing the page - it might have made for cleaner code, but this way will work just as well.

There is a module for python called cgitb. If you import it before your code, it will generate a CGI-friendly error message (and a very comprehensive one of that) identifying the error that happened.

import cgitb; cgitb.enable() 
import cgitb; cgitb.enable()
]]>


Just stick that near the top of your code (it's best to put it before any custom-written modules are imported). You'll get nice error messages, but they might be a bit of a security concern (it shows a few lines of your code, showing you where the error was, and there could be passwords in the code or other things you don't want people to see), so you might want to remove that line once you think you've fixed any problems with a script.

August 05 02009, 01:24 GMT
Pikachu
Kelp is good!

Pikachu's avatar
Location: California
Post count: 50
us
O_O

I'm speechless. The same mistake, twice.

Hehe, thanks. That worked.
______________________________

Linux | Chrome | Python | Chuck


[1]



Forum Information
  Currently Active Members [detailed] (0 members and ? guests)
-
Forum Statistics
Topics: 0, Posts: 0, Members: 108.
Welcome to our newest member, adamthephantump
Most members online was 5, on August 28 2009, at 21:49:28.
Legend
    Forums with unread topics in them are indicated by a strong yellow colouring around the forum icon.
    Forums with no unread topics have the standard pale yellow colouring around the forum icon.
    Forums with a blue arrow icon will redirect you to a non-forum page.
    Locked forums have a little padlock by their icon. You won't be able to post in these forums.
Shinyshell Home | Contact | Staff List | Archive | Top 

Conventional Login

Don't have an account? You may want to create one.

OpenID Login
OpenID login and registration is usable, but not finished.
What is OpenID?
Search

(advanced search)
Site Stats
  Total members: 108
  Latest member: adamthephantump
  Members currently online: 0
  Most online: 5 - Aug 28, 2009 (21:49)
  Front page hits: 88121
Developer info
  Site version: 3.5 Alpha
  16 queries - 9 templates
Under the Spotlight
Collide Site
Collide make fabulously dreamy electronic-industrial music, they're one of my favourite bands! Give them a chance to take control of your life - myspace | youtube - "Euphoria".

Collide Site - Hits: 4926

5/5 (2) | Rate this site?