Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411594 Posts in 69387 Topics- by 58445 Members - Latest Member: gravitygat

May 08, 2024, 06:37:41 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Peevish Peruses Python
Pages: 1 [2]
Print
Author Topic: Peevish Peruses Python  (Read 5202 times)
Ravine
Level 0
**


View Profile
« Reply #20 on: February 24, 2009, 08:24:01 PM »

well, if your first message is totally true, you seems to lack some serious basic knowledge about programming, such as the types, data structures, and so on.

You can have a look here (if you want to be afraid by the "WOOOOOO SO MANY" stuff in there), or just stick with the primitive types to begin with.

Then, you can have a look to that page to have a overview of what are functions / methods / procedure are.

To keep it short, you have a program, which holds variables of different types (numbers, chars, etc). This program is subdivided in small portion of codes, its functions. Those functions cant perform on their own, they need some infos. Those infos are passed through the arguments (or parameters, which is another name). Those terms are not python-specific. Nearly all the languages have this kind of concepts in their core.

Hope it helped

(sorry in advance if my english sounds strange, it's 5.20 am here Epileptic and i'm not a native english speaker)
Logged
george
Level 7
**



View Profile
« Reply #21 on: February 24, 2009, 08:47:05 PM »

to elaborate in a Python-specific way on what Ravine said, in Python you do not need to declare the type of variables as you need to do in other languages.

Also I've heard a slight distinction made between parameters and arguments. An argument is passed to a function like when you call function(argument) in your program, while a parameter is declared when you define that function, like def function(parameter): ... etctera.
Logged
gnat
Level 1
*



View Profile WWW
« Reply #22 on: February 24, 2009, 11:22:34 PM »

There's a good glossary of Python terms included in the official Python documentation.
Logged

LAN Party List - The definitive LAN party list. Also Game Jams, etc.
GitHub
J.G. Martins
Level 2
**


AKA anvilfolk


View Profile WWW
« Reply #23 on: February 25, 2009, 06:11:07 AM »

I'd suggest stopping the tutorial for a night or two and finding something really simple that you can do on your own. Just following won't help, you need to set out on your own and try things out. Have you gotten to cycles yet? Fors, whiles?

Either way, you can already do some pretty fun things with ifs and elses. You can actually make a small adventure game already!
Logged

Gold is for the mistress -- silver for the maid --
Copper for the craftsman cunning at his trade.
"Good!" cried the Baron, sitting in his hall,
"But iron, cold iron, is the master of them all."
--- Rudyard Kipling
Peevish
Level 4
****



View Profile WWW
« Reply #24 on: March 02, 2009, 04:42:55 PM »

Peevish thanks all ye who have commented with content and candor; he alliterates with C's to show his gratitude.

THIS WEEK: Peevish consumes himself (IN FIRE) by experience a "social life;" little coding progress. While waiting for a job interview, cracks the laptop from his Magic Satchel and proceeds. Confusion ensues:

code entered:
import sys
print "The command line arguments are:"
for i in sys.argv:
    print i

print "\n\nThe PYTHONPATH is", sys.path, "\n"

output
The command line arguments are:
/Users/admin/Documents/using_sys.py


The PYTHONPATH is ['/Users/admin/Documents', '/Applications/Python 2.6/IDLE.app/Contents/Resources', ... ETC ETC ETC

EXPECTED output
The command line arguments are:
using_sys.py
we
are
arguments

The PYTHONPATH is ['/Users/admin/Documents', '/Applications/Python 2.6/IDLE.app/Contents/Resources', ... AND YET STILL MORE ETC


Double-, triple-, septuple-checked tutorial, code is entered correctly, but Peevish wonders, where did that cheeky little "we are arguments" bit go? He imagines, if put to music, it would sound like Kraftwerk. But don't most things?

Peevish, in exposing isolated swatches of n00bage, feels somewhat nude, and not simply because he's typing in the shower.

Cheekiness == False
Don't worry, several of the little programs I've mentioned so far haven't been in the tutorial but were made for my own amusement; the tutorial definitely didn't use the term "go fuck yourself" at any point (...yet). I am familiar enough with ifs, elifs, elses, and cycles that I could probably do some basic IF, if inelegantly. Job hunting cramps my coding-steaz.
Logged
Lynx
Level 5
*****


Upstart Feline Miscreant


View Profile WWW
« Reply #25 on: March 02, 2009, 05:04:33 PM »

Code works for me.

Note that argv[0] will always be the fully qualified program name.  If you want just the base name:

import os
import sys
progname = os.path.basename(sys.argv[0])

You might need to explain how you are running your script, since you might not be inputting the arguments correctly.
Logged

Currently developing dot sneak - a minimalist stealth game
Peevish
Level 4
****



View Profile WWW
« Reply #26 on: March 14, 2009, 10:25:04 AM »

Hey! That was a long time not to see each other!

Peevish is dadadadada banter banter-

Cheekiness == False

Okay, I've completed the tutorial and skimmed back through some of the early stuff to refresh my memory, and make an incredibly simple one-room text adventure to test my knowledge of class and when to call global variables and the like (oh the joys of being unemployed again!). Going back through a bit is helping to solidify a lot of stuff; I love how coders will try to explain things to a layperson by using analogies, but their analogies are just more code. Starting to understand it, starting to think I should write a tutorial of my own that speaks plain English.

Anyway, my sole interest in coding is making games so I thought what the hell, start messing with pyglet (yes, I settled on pyglet over PyGame), and my Hello World made me dance around the kitchen!

Now I'm learning both Python and pyglet in tandem here, and I know the first response from most coders will be "oh, you should know everything about python before you touch pyglet," but barring that advice, I have the following dilemma:

----

import pyglet
window = pyglet.window.Window()
image = pyglet.resource.image("kitten.jpg")

@window.event
def on_draw():
    window.clear()
    image.blit(0, 0)

pyglet.app.run()

----

This doesn't work properly, Python freezes without displaying the image. I'm assuming it can't find kitten.jpg, though the documentation seems to think it can. I'm assuming the folder hasn't been placed on my Python path, which was a section of the tutorial I couldn't decipher since it was written by a Linux user who had no interest in explaining how point Python to a directory on a Mac. Or is it something else? I know full-well where kitten.jpg is, but Python doesn't. Docs say to use pyglet.image.load, but no hints as to HOW. I know I can dig around a ton in some documentation for the answer, and I will, but I thought I'd ask here firsties.

Preemptive thanks!

Cheekiness == True

Peevish's stray observations:

-accidentally omitting quotes Peevish receives the message 'Peevish' is not defined, NO YOU'RE NOT DEFINED!
-in typing %H%M%S Peevish must resist adding %Pinafore
-apparently Yahtzee did not invent the word "unpickle"
-every time Peevish writes a program that is supposed to call an error message, it works perfectly, for Peevish is without flaw and full of bravado
-tutorial is typical of coders: written about code, out of code, and into code
Logged
Lynx
Level 5
*****


Upstart Feline Miscreant


View Profile WWW
« Reply #27 on: March 14, 2009, 11:46:36 AM »

Try:

image = pyglet.image.load("kitten.jpg")
Logged

Currently developing dot sneak - a minimalist stealth game
george
Level 7
**



View Profile
« Reply #28 on: March 14, 2009, 11:48:09 AM »

image = pyglet.resource.image("kitten.jpg")


This doesn't work properly, Python freezes without displaying the image. I'm assuming it can't find kitten.jpg, though the documentation seems to think it can. I'm assuming the folder hasn't been placed on my Python path

If your resource isn't in the same folder as your game's .py file, then yes you need to declare this explicitly.

Looking at the 'Application resources/Specifying the resource path' section of the pyglet programming guide, you'll find roughly this:

pyglet.resource.path = ['write the name of the directory where the image is here']
pyglet.resource.reindex()


You use pyglet.resource.reindex because if you change the pyglet.resource.path list, you want your program to keep up with those changes.

Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic