Shinyshell Community Forums > Coding > I've got an issue with Python... |
||||||
Sign Up | Member List | New Posts | Help |
[1]
July 23 02009, 20:53 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
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 Location: US Post count: 99 |
The same dilemma has appeared to me.
|
July 30 02009, 23:56 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
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 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 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 Location: Brisbane, Australia Post count: 78 |
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 Location: Varaždin, Croatia Post count: 173 |
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 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". 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"?> I forgot to mention two things:
|
July 31 02009, 17:25 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
electron said Oops! I mean to say "layout.py" I had that in a folder called stuff. electron said ______________________________ Linux | Chrome | Python | Chuck |
July 31 02009, 17:49 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
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! Location: California Post count: 50 |
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"] 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 Location: Varaždin, Croatia Post count: 173 |
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 |
August 03 02009, 03:04 GMT | ||||
Pikachu Kelp is good! Location: California Post count: 50 |
Thanks, that did the trick.
(coding in python is so fun) EDIT: MySQL issue. #!/home/aiiro_pikachu/bin/python 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 Location: Varaždin, Croatia Post count: 173 |
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 Location: Varaždin, Croatia Post count: 173 |
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! Location: California Post count: 50 |
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 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 Location: Varaždin, Croatia Post count: 173 |
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() 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! Location: California Post count: 50 |
O_O
I'm speechless. The same mistake, twice. Hehe, thanks. That worked. ______________________________ Linux | Chrome | Python | Chuck |
[1]
Forum Information |
||||||||||
|