|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Mind Refresher :D
Sorry i kinda been really really busy and i kinda forgot somethings about python
so alittle mind refreshment will help me alot Code:
#!/usr/sbin/env python
def shows(var1,var2):
showdata[var1,var2]
for c in range(len(showdata)):
print c, showdata[c]
shows("hi","ho")
I get an error here & im tring to remember how to fix it Error---| Code:
Traceback (most recent call last):
File "1.py", line 9, in ?
shows("hi","ho")
File "1.py", line 4, in shows
showdata[var1,var2]
NameError: global name 'showdata' is not defined
I kinda forgot python cause i got hired to do some php work for a long time.. but i CANT FORGET ABOUT python so now im back from start kinda still i can refresh my mem ![]()
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev Last edited by xlordt : March 4th, 2004 at 01:24 PM. |
|
#2
|
||||
|
||||
|
Welcome back
, I can tell you've spent too much time on other langauges! I guess you are trying to create a local variable and assign a list to it. showdata = [var1,var2] will do the trick ![]() Because of that little buglet the local variable has not been created so the compiler looks in the global scope to find out what showdata might be and can't find it. I suspect it does not even get as far as trying to figure out what showdata[var1,var2] would compute to ![]() Here is one possibility: Code:
>>> a = {}
>>> a[1,2]="test"
>>> a
{(1, 2): 'test'}
Where a tuple is the key! Grim
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Code:
for c in range(len(showdata)):
print c, showdata[c]
Also, if you're using Python 2.3, the New Way(tm) of tidying up that range(len(x)) code is the 'enumerate' method, like so: Code:
for index, value in enumerate(showdata):
print index, value
![]() |
|
#4
|
||||
|
||||
|
nice thanx... & ya php/c got my head blowded lol
thanx again |
|
#5
|
|||
|
|||
|
It might be easier (read: better) to write:
Code:
for index, value in enumerate(showdata):
print index, value
|
|
#6
|
||||
|
||||
|
Hi perc, isn't that... exactly what sfb just said
. Look up ![]() Mark. |
|
#7
|
|||
|
|||
|
Quote:
*sigh* |
|
#8
|
|||
|
|||
|
Quote:
OMG I never knew you could do that! I've been using whiles! Well I guess you learn something new every day ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Mind Refresher :D |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|