Re: [Tutor] Confused about "import Numeric" vs "import numpy" for Arrays
> Another reason not to use "from xx import *" is that it can make it > very difficult to discover where a name is defined. If you have > several "from xx import *" lines and then later you use a function > "foo()" there is no easy way to tell which module foo came from. > > An alternative is to list just the names you want to import: > from xx import foo > > Kent > Kent - Another great point. Thanks for contributing to the list. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Confused about "import Numeric" vs "import numpy" forArrays
> A useful tip is that if you have a long module name you can also use > > import module as shortname > > eg > > import numpy as n > > and then access numpy.foo() as > > n.foo() > > Sacves a lot of typing for a slight loss of clarity in > maintenance - you have to remember which module the > short names refer to! I tend to use full names in real code > and use the abbreviated form when using the >>> prompt. > Alan - Great suggestion! As I'm reading through the numpy documentation, there are a lot of great functions that I'd like to learn to use so your advice definitely helps. I was getting tired of constantly having to type "numpy.array" or "numpy.ones" all the time. Thanks again. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Confused about "import Numeric" vs "import numpy" for Arrays
> In general "from import *" is a very bad idea. > > import imports a module into its own namespace (e.g., to > access its functionality you would have to do ".foo() and > .bar()" The form that you chose to use imports all of a > module's contents into the current namespace. This means you can call > "foo()" and "bar()" directly, but it also means that if you have coded > a "foo()" and a "bar()" you will not have access to the functions in > the module you just imported. > Timothy, Thanks for the clarification. I had always wondered what the difference was. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Confused about "import Numeric" vs "import numpy" for Arrays
> No, they are not the same. Numeric is older; NumArray is another older > package. You should use Numpy if you can. > http://numpy.scipy.org/#older_array > > > Now you should be able to import numpy. > > Kent > Thanks, Kent. I ended up using: >>> from numpy import * I wasn't sure what the difference was between this and >>> import numpy Thanks! Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Confused about "import Numeric" vs "import numpy" for Arrays
Hi Everyone, I would like to create a two-dimensional array but am confused as to how to go about it. I've read about Numeric Python and Numpy. Are they one and the same? Also, how do I install them? I am working on a Windows machine. I've been getting the following error messages: >>> import Numeric Traceback (most recent call last): File "", line 1, in import Numeric ImportError: No module named Numeric >>> from Numeric import * Traceback (most recent call last): File "", line 1, in from Numeric import * ImportError: No module named Numeric I then downloaded and installed release 1.1.1 of the Numpy package from this site: http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103 After restarting the shell, I still get the same errors above (though I do have this directory now: C:\Python25\Lib\site-packages\numpy). Anyone know how to correctly install and use this package? Thanks in advance. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading List from File
Emile, Amin: Thank you both for your replies. I was able to get it working using: >>> f = open(r'c:\test.txt', 'r') >>> foo = f.readline().split(',') Samir On Thu, Jul 31, 2008 at 3:00 PM, <[EMAIL PROTECTED]> wrote: > Emile is rigth, there should be a () there. > I'm sorry, im writing this from my cellphone and there's not a pc around XD. > I didn,t know about the csv module either and had to do over complicated > things to deal with embedded commas, thx for that too :). > > -- > Amin Rainmaker > > -- Forwarded message -- > From: Emile van Sebille <[EMAIL PROTECTED]> > To: tutor@python.org > Date: Thu, 31 Jul 2008 11:34:56 -0700 > Subject: Re: [Tutor] Reading List from File > S Python wrote: >>>>> >>>>> f = open(r'C:\test.txt', 'r') >>>>> foo = f.readline.split(',') > > readline is the function/method name > readline() executes that function/method and returns a value > > try typing in 'type(f.readline)' vs 'type(f.readline())' > > you can't .split() a function but you may split its return value. > >> but it fails when I try: >> >>>>> import csv >>>>> myfile = open(r'c:\test.txt', 'r') >>>>> data = csv.Reader(myfile, delimeter = ',') >> > > Python is case sensitive -- reader is different from Reader. > > HTH, > > Emile > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading List from File
Monika, Thanks for your help. I got it to work using the following (also had to spell "delimiter"): >>> import csv >>> myfile = open(r'c:\test.txt', 'r') >>> data = csv.reader(myfile, delimiter=',') >>> print data <_csv.reader object at 0x00D41870> >>> for item in data: print item ['aaa', 'bbb', 'ccc'] I think it was referred to in another post, but I have found this page to be helpful: http://docs.python.org/lib/csv-examples.html Thanks. Samir On Thu, Jul 31, 2008 at 2:20 PM, Monika Jisswel <[EMAIL PROTECTED]> wrote: > oops it is reader not Reader (all lower case), so this line : data = > csv.Reader(myfile, delimeter = ',') > should be data = csv.reader(myfile, delimeter = ',') > > > 2008/7/31 S Python <[EMAIL PROTECTED]> >> >> Hi Everyone, >> >> Thanks for the variety of responses in such a short amount of time. >> This distribution list is incredible. >> >> Sorry for the delayed reply as I wanted to test what everyone >> suggested, so here goes: >> >> --- >> >> @Amin: I tried your suggestion, but perhaps I don't understand your >> syntax. Here is what I tried and the resulting error message: >> >> >>> f = open(r'C:\test.txt', 'r') >> >>> foo = f.readline.split(',') >> >> Traceback (most recent call last): >> File "", line 1, in >>foo = f.readline.split(',') >> AttributeError: 'builtin_function_or_method' object has no attribute >> 'split' >> >> Do you know what I did wrong? >> >> --- >> >> @Emad, Brett: Thank you for your solutions. They do exactly what I >> was looking for. >> >> --- >> >> @Chad: Thanks for your suggestion. I think I like it best for its >> simplicity. >> >> --- >> >> @Emile, Monika, kinuthi: The CSV standard library looks interesting >> but I am having mixed results in implementing it. For example, it >> works when I try this: >> >> >>> reader = csv.reader(open(r'c:\test.txt', 'rb')) >> >>> for row in reader: >>print row >> >> >> ['aaa', 'bbb', 'ccc'] >> >> but it fails when I try: >> >> >>> import csv >> >>> myfile = open(r'c:\test.txt', 'r') >> >>> data = csv.Reader(myfile, delimeter = ',') >> >> Traceback (most recent call last): >> File "", line 1, in >>data = csv.Reader(myfile, delimeter = ',') >> AttributeError: 'module' object has no attribute 'Reader' >> >> The error looks similar to what I received when I tried Amin's >> approach. Am I missing something? >> >> --- >> >> It's interesting to note that for the solutions to work correctly, I >> had to remove the quotation marks from the input file. >> >> Thanks again to EVERYONE who took the time to respond. I appreciate your >> help. >> >> Samir >> ___ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading List from File
Hi Everyone, Thanks for the variety of responses in such a short amount of time. This distribution list is incredible. Sorry for the delayed reply as I wanted to test what everyone suggested, so here goes: --- @Amin: I tried your suggestion, but perhaps I don't understand your syntax. Here is what I tried and the resulting error message: >>> f = open(r'C:\test.txt', 'r') >>> foo = f.readline.split(',') Traceback (most recent call last): File "", line 1, in foo = f.readline.split(',') AttributeError: 'builtin_function_or_method' object has no attribute 'split' Do you know what I did wrong? --- @Emad, Brett: Thank you for your solutions. They do exactly what I was looking for. --- @Chad: Thanks for your suggestion. I think I like it best for its simplicity. --- @Emile, Monika, kinuthi: The CSV standard library looks interesting but I am having mixed results in implementing it. For example, it works when I try this: >>> reader = csv.reader(open(r'c:\test.txt', 'rb')) >>> for row in reader: print row ['aaa', 'bbb', 'ccc'] but it fails when I try: >>> import csv >>> myfile = open(r'c:\test.txt', 'r') >>> data = csv.Reader(myfile, delimeter = ',') Traceback (most recent call last): File "", line 1, in data = csv.Reader(myfile, delimeter = ',') AttributeError: 'module' object has no attribute 'Reader' The error looks similar to what I received when I tried Amin's approach. Am I missing something? --- It's interesting to note that for the solutions to work correctly, I had to remove the quotation marks from the input file. Thanks again to EVERYONE who took the time to respond. I appreciate your help. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Reading List from File
Hi Everyone, I am trying to read a comma-delimitted list ("aaa","bbb","ccc") from a text file and assign those values to a list, x, such that: x = ["aaa", "bbb", "ccc"] The code that I have come up with looks like this: >>> x = [] >>> f = open(r'c:\test.txt', 'r') >>> x.extend(f.readlines()) >>> x ['"aaa","bbb","ccc"'] If you look closely, there is an extra pair of single quotes (') that encapsulates the string. Therefore, len(x) returns 1, instead of 3. Is there a function to "separate" this list out? I hope my question makes sense. Thanks in advance. Samir ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Hi Morgan, Have you installed Python on your computer? If you are using Microsoft Windows, you can download and install Python from here: http://python.org/download/releases/2.5.2/ and select "python-2.5.2.msi". Once it's installed, you should have a directory on your machine called "C:\python25". If you save your program with a .py extension in that folder (for example, call it morgan.py), then all you have to do is open a command window (Start > Run and enter "cmd"), go to the C:\python25 directory, and type: python morgan.py Personally, if you are just staring out to program, I would recommend using the Python shell that comes with the package I referred to. Alan's tutorial, found here: http://www.freenetpages.co.uk/hp/alan.gauld/ is very helpful, as is this site, which is what I used to start learning Python: http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/ Hope that helps. Good luck! Samir On Tue, Jul 29, 2008 at 7:27 AM, Morgan Thorpe <[EMAIL PROTECTED]>wrote: > Hello. > > I'm am very new to the whole programming sence. > I am trying to catch on but as soon as i want to write a program i've been > told to use like 'notepad' in windows XP and save it as a .py file > i have gotten this far. Am i wrong so far? > If i am right why is it that i can't run it in anyway besides it opening in > 'notepad' i've tried opening with Python but it doesn't work. > > Thanks, >Morgan > -- > This message has been scanned for viruses and dangerous content by the BCEC > Security Gateway, and is believed to be clean. Brisbane Catholic Education > however gives no warranties that this e-mail is free from computer viruses > or other defects. Except for responsibilities implied by law that cannot be > excluded, Brisbane Catholic Education, its employees and agents will not be > responsible for any loss, damage or consequence arising from this e-mail. > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor