Re: [Tutor] Finding the version # of a module, and py module problem
I should have mentioned I use windows. import numpy numpy.__version__ It's now written in my Py book! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the version # of a module, and py module problem
On Thu, Aug 5, 2010 at 8:53 PM, David Hutto wrote: > On Thu, Aug 5, 2010 at 7:33 PM, Wayne Watson > wrote: >> It's been awhile since I've used python, and I recall there is a way to find >> the version number from the IDLE command line prompt. dir, help, >> __version.__? >> >> I made the most minimal change to a program, and it works for me, but not my >> partner. He gets >> >> Traceback (most recent call last): >> File "C:\Documents and >> Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py", >> line 40, in >> from scipy import stats as stats # scoreatpercentile >> File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in >> >> from stats import * >> File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in >> >> import scipy.special as special >> File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, >> in >> from numpy.testing import NumpyTest >> ImportError: cannot import name NumpyTest >> >> Here are the first few lines of code. >> >> import sys, os, glob >> import string >> from numpy import * >> from datetime import datetime, timedelta >> import time >> from scipy import stats as stats # scoreatpercentile >> >> I'm pretty sure he has the same version of Python, 2.5, but perhaps not the >> numpy or scipy modules. I need to find out his version numbers. >> >> -- >> Wayne Watson (Watson Adventures, Prop., Nevada City, CA) >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet >> >> "Republicans are always complaining that government is >> out of control. If they get into power, they will >> prove it." -- R. J. Rourke >> >> >> Web Page: >> >> ___ >> Tutor maillist - tu...@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> > > I'm pretty sure their might be an easier way, but since no one has > replied just yet. You can go into your command prompt and type pydoc > -p 1234(noth the python interpreter, and you might have to cd to the > Lib directory with pydoc in it). Then use a browser and go to > localhost:1234, and in the sight packages section click on the numpy, > or scipy, and it shows the version in parentheses beside the name at > top. > And not sure if this works in 2.5, I only have 2.6, 2.7, and 3.1 to test on. >>> from setup import * >>> print __version__ $Revision: 77217 $ >>> So for you should be: from numpy import * print __version__ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the version # of a module, and py module problem
On Thu, Aug 5, 2010 at 7:33 PM, Wayne Watson wrote: > It's been awhile since I've used python, and I recall there is a way to find > the version number from the IDLE command line prompt. dir, help, > __version.__? > > I made the most minimal change to a program, and it works for me, but not my > partner. He gets > > Traceback (most recent call last): > File "C:\Documents and > Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py", > line 40, in > from scipy import stats as stats # scoreatpercentile > File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in > > from stats import * > File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in > > import scipy.special as special > File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, > in > from numpy.testing import NumpyTest > ImportError: cannot import name NumpyTest > > Here are the first few lines of code. > > import sys, os, glob > import string > from numpy import * > from datetime import datetime, timedelta > import time > from scipy import stats as stats # scoreatpercentile > > I'm pretty sure he has the same version of Python, 2.5, but perhaps not the > numpy or scipy modules. I need to find out his version numbers. > > -- >Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet > > "Republicans are always complaining that government is > out of control. If they get into power, they will > prove it." -- R. J. Rourke > > > Web Page: > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > I'm pretty sure their might be an easier way, but since no one has replied just yet. You can go into your command prompt and type pydoc -p 1234(noth the python interpreter, and you might have to cd to the Lib directory with pydoc in it). Then use a browser and go to localhost:1234, and in the sight packages section click on the numpy, or scipy, and it shows the version in parentheses beside the name at top. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to do excel in python
On Thu, 5 Aug 2010 10:08:59 -0400 invincible patriot wrote: > hi, > can any one tell me how can I access MS excel worksheet in python and > how can I access itz individual cells..?? > I have had good luck with the xlrd and xlwt modules, you can get them at www.python-excel.org. The Google Group for those packages is reasonably helpful as well. tom ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Finding the version # of a module, and py module problem
It's been awhile since I've used python, and I recall there is a way to find the version number from the IDLE command line prompt. dir, help, __version.__? I made the most minimal change to a program, and it works for me, but not my partner. He gets Traceback (most recent call last): File "C:\Documents and Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py", line 40, in from scipy import stats as stats # scoreatpercentile File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in from stats import * File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in import scipy.special as special File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, in from numpy.testing import NumpyTest ImportError: cannot import name NumpyTest Here are the first few lines of code. import sys, os, glob import string from numpy import * from datetime import datetime, timedelta import time from scipy import stats as stats # scoreatpercentile I'm pretty sure he has the same version of Python, 2.5, but perhaps not the numpy or scipy modules. I need to find out his version numbers. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "Republicans are always complaining that government is out of control. If they get into power, they will prove it." -- R. J. Rourke Web Page:___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to do excel in python
"invincible patriot" wrote hi, can any one tell me how can I access MS excel worksheet in python and how can I access itz individual cells..?? There are several Excel specific modules - try Google - or, using the standard library, and if its practical for your case, you can use CSV files - just save the spreadsheet as CSV - and manipulate it that way using the standard csv module. HTH -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to do excel in python
There are many ways. The simplest is to export the file to CSV and load that, but you'll only get one worksheet, and it's a big hassle to update the Excel file that way. You can save the spreadsheet as an ODF file, which is a fully documented XML format that Python can read and write easily, but you might give up some Excel features (but a lot fewer than with CSV format). You can also have the spreadsheet open in excel and talk to it from Python via COM. If you're on Windows and have Excel, this approach can be the most flexible. http://docs.python.org/library/csv.html http://www.linuxjournal.com/article/9347 http://www.google.com/search?q=excel+com+python Cheers On Thursday 05 August 2010, invincible patriot wrote: > hi, can any one tell me how can I access MS excel worksheet in python and > how can I access itz individual cells..?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to do excel in python
> hi, > can any one tell me how can I access MS excel worksheet in python and how > can I access itz individual cells..?? let me google that for you... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
Speaking of which, is there some place you or anyone can recommend on picking up all the constructs for list comprehension & generator comprehension. I've perused the python.org documents and have just been building them according to example. How can I pick up more advanced usage? I mostly catch myself using it to return a list of functions like: >>> class foo(object): ... def __init__(self, bar): ... self.bar = bar ... >>> [(foo(i)) for i in range(0,10)] [<__main__.foo object at 0x00C54FD0>, <__main__.foo object at 0x00C54FF0>, <__ma in__.foo object at 0x00C54F50>, <__main__.foo object at 0x00C54F30>, <__main__.f oo object at 0x00C59050>, <__main__.foo object at 0x00C59070>, <__main__.foo obj ect at 0x00C590B0>, <__main__.foo object at 0x00C590D0>, <__main__.foo object at 0x00C59110>, <__main__.foo object at 0x00C59130>] On Thu, Aug 5, 2010 at 3:25 AM, James Mills wrote: > On Thu, Aug 5, 2010 at 2:38 PM, Vikram K wrote: > > Suppose i have this string: > > z = 'AT/CG' > > > > How do i get this list: > > > > zlist = ['A','T/C','G'] > > >>> import re > >>> z = 'AT/CG' > >>> [x for x in re.split("([A-Z]\/[A-Z])|([A-Z])", z) if x] > ['A', 'T/C', 'G'] > >>> > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to do excel in python
On 05/08/2010 15:08, invincible patriot wrote: hi, can any one tell me how can I access MS excel worksheet in python and how can I access itz individual cells..?? http://www.python-excel.org/ (First hit for python excel in Google) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getattr()
On 8/4/2010 4:32 PM, Huy Ton That wrote: I have a side question, I am using python 2.7. Why do you use class A: instead of class A(object): ? My example does not depend on old / new style classes. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to do excel in python
hi, can any one tell me how can I access MS excel worksheet in python and how can I access itz individual cells..?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Rép. : string to list
Try this: >>> def f(mystring): charlist = list(mystring) tmplist = [ [''] ] for a in charlist: if tmplist[-1][-1] == '/' or a == '/': tmplist[-1].append(a) else: tmplist.append( [a] ) return [''.join(a) for a in tmplist][1:] >>> #Thusly: >>> f('AT/CG') ['A', 'T/C', 'G'] >>> f('CATAT/T/CATA/C/AC/TACGAA/AGT/GGTC/GGGTCTACGATTT/A/A/GC/T/GA/C/A/T/GA/G/C/ACAAG/CC/GAGGTG/GACTCA/G/TTT/TAGT/AGAC/AT/CC/GG/CG/G/A') ['C', 'A', 'T', 'A', 'T/T/C', 'A', 'T', 'A/C/A', 'C/T', 'A', 'C', 'G', 'A', 'A/A', 'G', 'T/G', 'G', 'T', 'C/G', 'G', 'G', 'T', 'C', 'T', 'A', 'C', 'G', 'A', 'T', 'T', 'T/A/A/G', 'C/C', 'C', 'C', 'C', 'T/G', 'A/C/A/T/G', 'A/G/C/A', 'C', 'A', 'A', 'G/C', 'C/G', 'A', 'G', 'G', 'T', 'G/G', 'A', 'C', 'T', 'C', 'A/G/T', 'T', 'T/T', 'A', 'G', 'T/A', 'G', 'A', 'C/A', 'T/C', 'C/G', 'G/C', 'G/G/A'] --- En date de : Mer, 4.8.10, Vikram K a écrit : De : Vikram K Objet : [Tutor] string to list À : tutor@python.org Date: mercredi 4 août 2010 21 h 38 Suppose i have this string: z = 'AT/CG' How do i get this list: zlist = ['A','T/C','G'] -La pièce jointe associée suit- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
Just a minor related/tangential suggestion -- O'Reilly had a stand at the recent EuroPython conference I attended and I was paging through "Bioinformatics Programming using Python", Book reference: http://oreilly.com/catalog/9780596154516 Just thought I'd mention it as it seems relevant to the current question/domain from which the question comes from. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
"Vikram K" wrote Suppose i have this string: z = 'AT/CG' How do i get this list: zlist = ['A','T/C','G'] There are lots of ways and it really needs a tighter specification of yhow you split. What would "AT/C/DGH" give for example? But in general there are several approaches, I suspect regex is the best solution here but for simple solutions splitting by the / then splitting the sublists then joining the last to the first element of each sublist using / might work too. But regex is probably faster, although more complex. And you could use a parser if the rules are very complex. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] access class through indexing?
"Alex Hall" wrote Since you never call super(), the init of the base class never happens. ... actual object you're supposed to be initializing, and you immediately overwrite it (self) with another object. As a result, everything else you do in that method is thrown out when the method returns. That makes sense, and doing so has fixed everything. I am still not clear on the whole super() thing; I saw it in another project and tried to find out about it, but what I found was very confusing, and super() did not seem terribly important, so I did not pursue the matter further. Apparently it is important... It is critical. Methods are not simply functions that happen to be defined in a class structure. They are intended to be part of a complete heirarchical calling mechanism. It is normal when writing a method of a derived class that over-rides an inherited method to call the inherited method somehwhere in the body of your method. class C(A): def myAmethod(self) # put local initialisation code here # call the superclass version of the method here # call local tidy-up code here The initialisation and tidy-up code is what is unique to your version of the class (and are optional but if neither exists you don't need to override the method!). But to get the inherited functionality (including init*() ) to work you must call the inherited method. If you don't you replace the inherited functionality and talke full responsibility for doing everything that it used to do yourself. Using super() is the approved way of doing it, but for single inheritance you can call the parent class directly A.myAmethod(self) if you find that less mind bending. But calling the superclass version of your method is vital if you want to get the benefits of inheritance. Finally, if you did want to replace what self was you can do that by writing your own __new__ method rather than an __init__ but you very rarely want to do that! Python gives you a lot of tools to mess with how objects work. Unless you really know what you are doing it's usually best to ignore the temptation! :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get str() to use my function?
"Alex Hall" wrote It worked, thanks. Is there a list of these functions somewhere? Learn to use the dir() and help() functions in Python at the >>> prompt. dir(obj) will show all the standard methods for that object. For the math operators try dir(5) - or any other number, 5.0 for a float etc. The advantage of dir() is a nice short listing, easy to scan. For a detailed description use the help function: help(5) Help on int object: class int(object) | int(x[, base]) -> integer | | Convert a string or number to an integer, if possible. A floating point | argument will be truncated towards zero (this does not include a string | representation of a floating point number!) When converting a string, use | the optional base. It is an error to supply a base when converting a | non-string. If the argument is outside the integer range a long object | will be returned instead. | | Methods defined here: | | __abs__(...) | x.__abs__() <==> abs(x) | | __add__(...) | x.__add__(y) <==> x+y | | __and__(...) | x.__and__(y) <==> x&y | | __cmp__(...) -- More -- HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
On Thu, 5 Aug 2010 03:40:55 -0400 Sander Sweers wrote: > On 5 August 2010 06:38, Vikram K wrote: > > Suppose i have this string: > > z = 'AT/CG' > > > > How do i get this list: > > > > zlist = ['A','T/C','G'] > > If you know the format of the string is always the same you can do > something like this. This fails when you have strings that do not have > the '/' in the middle and has 2 characters on either side. > > def parseString(s): > n = s.find('/') > l = [] > if n: > l = [s[0],s[n-1:n+2], s[-1]] > return l > > >>> parseString(s) > ['A', 'T/C', 'G'] > > Greets > Sander Much better than my original thought on this! If the data is stereotypic couldn't you simplify it though? ... z='AT/CG' zlist=[z[0],z[1:4],z[-1]] tom ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
On 5 August 2010 06:38, Vikram K wrote: > Suppose i have this string: > z = 'AT/CG' > > How do i get this list: > > zlist = ['A','T/C','G'] If you know the format of the string is always the same you can do something like this. This fails when you have strings that do not have the '/' in the middle and has 2 characters on either side. def parseString(s): n = s.find('/') l = [] if n: l = [s[0],s[n-1:n+2], s[-1]] return l >>> parseString(s) ['A', 'T/C', 'G'] Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string to list
On Thu, Aug 5, 2010 at 2:38 PM, Vikram K wrote: > Suppose i have this string: > z = 'AT/CG' > > How do i get this list: > > zlist = ['A','T/C','G'] >>> import re >>> z = 'AT/CG' >>> [x for x in re.split("([A-Z]\/[A-Z])|([A-Z])", z) if x] ['A', 'T/C', 'G'] >>> cheers James -- -- James Mills -- -- "Problems are solved by method" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor