[Tutor] objects becoming pointers

2009-07-15 Thread chris Hynes

I guess I have to start somewhere to ask

I want the user to input a name, say "Chris". I know I can use the code:

name=raw_input()

I now want:

"Chris"=zeros((3,3))

so that when I type:

print Chris

the return will be an array of zero's 3x3

So that I can understand this deeper, I know that "name" is just a pointer to 
the object "Chris". I don't want to just change the pointer to something else, 
like "zeros((3,3))" but I want to make "Chris" become the pointer or the name 
of the pointer. At least that's what I think I want.

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] interactive naming of pointers

2009-07-16 Thread chris Hynes

Yeah, I'm not sure if I'm explaining myself well or maybe I'm just trying to 
make the code too interactive.

in my code I would type something like:

x=zeros((3,3))

so the pointer called "x" is created by the programmer, but within the code. 
What if I wanted to prompt my keyboard user to type in a word, like "Chris" and 
then the program would create:

Chris=zeros((3,3))

Whatever code could make this happen I could loop through it several times, 
create various array names, and when the operator was done, they would have 
several arrays created with names of their choosing. When I'm in ipython mode, 
I would have to type Chris=zeros((3,3)), then Bob=zeros((3,3)) and then 
Kent=zero((3,3)), three separate statements (and gosh what if I wanted more 
than just these three?). I want my user to create names for their pointers 
instead of it already being in the code.

> I'm not sure you have really thought this through. The user typed
> "Chris", and that value is stored in 'name'. It might just as well
> have been "Bob" or "Kent". So you can't really say
>   print Chris
> you need something like
>   print the_thing_called(name)
> which you might as well spell as
>   print values[name]
> 
> Kent

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] objects becoming pointers

2009-07-16 Thread chris Hynes

That's just it, you won't know in advance what names the user will type in. 
Maybe I mean to say dynamically create pointers. For instance,

In the morning, I might be working with data regarding methanol and do several 
iterations and save those iterations in separate arrays with some type of 
methanol basename (I guess I could just save everything in a huge 
multidimensional array but it helps me to compartmentalize in to separate 
smaller arrays by name), later that afternoon I might we doing some 
formaldehyde calculations so I want those arrays to have some kind of aldehyde 
name associated with it. I could recall an earlier methanol array that was 
created. 

I could go back in to my code and change names. Or I thought I could just leave 
my program running and just keep on typing in new names as I need them, kind of 
like giving birth to as many arrays with whatever names as I see fit.

Several people have suggested I use dictionary function, and I'll probably do 
that. Hmmm, is it possible to concantenate a raw_input on to a pointer?

Oh well, in the end I think I'm just going to create a mutidimensional array 
and just access sub parts of it as I need to. Thanks for your help.

> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Thu, 16 Jul 2009 19:25:51 +0100
> Subject: Re: [Tutor] objects becoming pointers
> 
> 
> "chris Hynes"  wrote
> 
> > I want the user to input a name, say "Chris". I know I can use the code:
> > 
> > name=raw_input()
> >
> > I now want:
> >
> > "Chris"=zeros((3,3))
> >
> > so that when I type:
> >
> > print Chris
> 
> 
> This is a common misapprehension by beginners. 
> But let me ask you something. Since you will be writing your 
> program code, including the 
> 
> print Chris 
> 
> line, how will you know in advance what names your userrs are 
> going to input?
> 
> I think you will find it easier to create a dictiobnary of user names 
> with their associated values:
> 
> name = raw_input()
> names[name] = value
> 
> name = raw_input("Which name was it?")
> print names[name]
> 
> or even:
> 
> for name in names:
>print names[name]
> 
> HTH,
> 
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

_
Windows Live™ SkyDrive™: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reading data

2009-07-23 Thread chris Hynes

I have a data file in which the first line is made up of words. Here is the 
original data file:

#Column density-scaled with production rate 3.16227766016838e+25
-10. 0.000e+00  0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 
-9.9000 0.000e+00  0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
0.000e+00 0.000e+00 0.000e+00 0.000e+00 

I'd like to my program to skip any lines that begin with words and move on to 
lines that contain numbers. Right now I just cheat and delete the first line 
and resave the data file, but I was hoping that I could avoid these types of 
things in the future. Here is my code for reading the file and figuring out how 
many rows and columns to dimensionalize my array, then I read the data into the 
array:

from numpy import *
row=0
columnindex=0
x=open('halfmethanol.col','rt')
for line in x.readlines(): 
data=line.split()
columnindex=len(data)
row=row+1
temp=ones((row,columnindex))
row=0
x=open('halfmethanol.col','rt')
for line in x.readlines():
data=line.split()
for column in range(columnindex):
temp[row,column]=data[column]
row=row+1

_
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor