LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2005, 08:05 AM   #1
DiagonalArg
LQ Newbie
 
Registered: Mar 2004
Posts: 23

Rep: Reputation: 15
Assigning names in Python


Hi. I'm having a problem with a Python program I'm trying to write, and I was wondering if any of you could help. I guess it's a pretty elementary question, but I'm a programming newbie, so there you go.

I have a for loop in my program and I would like on each iteration to assign a name. So, for example, the first time through I want the statement x1=some_function(1), the second x2=some_function(2) etc. I realise that I can't just write

for i in range(y):
xi=some_function(i)

as that will just keep assigning xi. So I'd really like to be able to write something like

for i in range(y):
'x'+str(i)=some_function(i)

but that that's not allowed. What's the best way round this problem?
 
Old 07-27-2005, 08:23 AM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Why not use an array? Then you'd have your data stored at x[0], x[1] etc.

use x[i] instead of xi.
 
Old 07-27-2005, 08:51 AM   #3
DiagonalArg
LQ Newbie
 
Registered: Mar 2004
Posts: 23

Original Poster
Rep: Reputation: 15
Yeah, I realised an array was the way to go about 2 minutes after posting this. D'oh.
 
Old 07-27-2005, 03:09 PM   #4
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
More specifically use a list which, as Proud pointed out, is denoted by the [ and ]. Tuples could also be considered arrays but since they are immutable they wouldn't work in this situation.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
Logical device names and instant names Gins Linux - General 8 11-30-2004 08:17 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration