The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Mind Refresher :D
Discuss Mind Refresher :D in the Python Programming forum on Dev Shed. Mind Refresher :D Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 4th, 2004, 01:20 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
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 
Last edited by xlordt : March 4th, 2004 at 01:24 PM.
|

March 4th, 2004, 02:41 PM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
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
|

March 4th, 2004, 05:08 PM
|
|
|
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

|

March 4th, 2004, 05:59 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
nice thanx... & ya php/c got my head blowded lol  thanx again
|

March 5th, 2004, 02:14 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
It might be easier (read: better) to write:
Code:
for index, value in enumerate(showdata):
print index, value
This will only work if you're using Python 2.3.
|

March 5th, 2004, 05:23 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Hi perc, isn't that... exactly what sfb just said  . Look up
Mark.
__________________
programming language development: www.netytan.com – Hula
|

March 5th, 2004, 12:13 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by netytan Hi perc, isn't that... exactly what sfb just said  . Look up
Mark. |
*sigh*
|

March 5th, 2004, 01:10 PM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 217
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by percivall It might be easier (read: better) to write:
Code:
for index, value in enumerate(showdata):
print index, value
This will only work if you're using Python 2.3. |
OMG I never knew you could do that! I've been using whiles! Well I guess you learn something new every day 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|