Re: [Tutor] please help with sqlite replace function
John, just to add to my previous post. after copying sqlite3.dll (3.6.2) version into Python25\DLLs directory and running import sqlite3 dir(sqlite3) >>> sqlite3.version '2.3.2' >>> sqlite3.version_info (2, 3, 2) >>> sqlite3.sqlite_version_info (3, 6, 2) >>> sqlite3.sqlite_version '3.6.2' and now my scrip happily runs with sqlite replace function. I am just curious why there are so many different version properties and why now they differ from sqlite3.version? Of course it seems Python now is running sqlite version 3.6.2 since my script accepts replace function Thanks, Aivars 2008/11/7 aivars <[EMAIL PROTECTED]>: > Thanks, John, > Yes it seems you are right. The ActiveState python version I have > installed have sqlite 2.3.2 only. I find it strange. > I see that on a python website there is is a new version Python26 > relesed. Should i go on and install Python26? I understand that I can > install pure Python from python website and after that I can install > Mark Hammonds PythonWin to get other things for windows? Or maybe I > will reinstall ActiveState Python25 and install Python25 from the > official website > > Copying dll to c:\python25\DLLs directory did not help - it still > shows version sqlite version 2.3.2. which I also do not understand why > > Re user defined function - it is one of the ways to go probably > quickest but I would like to have newer version of sqlite being > already with python > > I am noob in Python still > > Thanks for your input > > Aivars > > > > 2008/11/6 John Fouhy <[EMAIL PROTECTED]>: >> 2008/11/7 aivars <[EMAIL PROTECTED]>: >>> I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 >> >> Hi Aivars, >> >> I believe python has its own built-in sqlite, rather than using the >> version you installed independently. So it is possible that the >> python version of sqlite is older than 3.6.2 and does not yet have the >> replace() function. >> >> (run 'import sqlite3' and then examine 'sqlite3.sqlite_version' to see >> what version you are using) >> >> You could try replacing sqlite3.dll in your python25\dlls directory >> with the DLL from your sqlite installation (make a backup first :-) ). >> Alternatively, you could define the replace() function in python and >> then add it to your database: see >> http://www.initd.org/pub/software/pysqlite/doc/usage-guide.html#creating-user-defined-functions >> . >> >> HTH. >> >> -- >> John. >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Intermediate/advanced concepts
Hi everyone, I've been teaching myself python for a few months and I'm becoming frustrated because I've kind of hit a wall in terms of learning new information. In an effort to continue to learn I've found some material on more intermediate/advanced topics like linked lists, nodes, trees, etc. However, it's kind of like reading a math textbook - the tutorials do a decent job of explaining the material but it's all kind of theoretical, and I'm not sure how I'd apply these concepts in real world applications, or incorporate them into my code. Does anyone have any suggestions for learning about real world application of more advanced concepts? Also, are there other concepts that I should focus on? Frankly, I'm a bit bored because I've hit this ceiling, and I'm not really sure where to go to next. Thanks, Ben ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with sqlite replace function
Thanks, John, Yes it seems you are right. The ActiveState python version I have installed have sqlite 2.3.2 only. I find it strange. I see that on a python website there is is a new version Python26 relesed. Should i go on and install Python26? I understand that I can install pure Python from python website and after that I can install Mark Hammonds PythonWin to get other things for windows? Or maybe I will reinstall ActiveState Python25 and install Python25 from the official website Copying dll to c:\python25\DLLs directory did not help - it still shows version sqlite version 2.3.2. which I also do not understand why Re user defined function - it is one of the ways to go probably quickest but I would like to have newer version of sqlite being already with python I am noob in Python still Thanks for your input Aivars 2008/11/6 John Fouhy <[EMAIL PROTECTED]>: > 2008/11/7 aivars <[EMAIL PROTECTED]>: >> I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 > > Hi Aivars, > > I believe python has its own built-in sqlite, rather than using the > version you installed independently. So it is possible that the > python version of sqlite is older than 3.6.2 and does not yet have the > replace() function. > > (run 'import sqlite3' and then examine 'sqlite3.sqlite_version' to see > what version you are using) > > You could try replacing sqlite3.dll in your python25\dlls directory > with the DLL from your sqlite installation (make a backup first :-) ). > Alternatively, you could define the replace() function in python and > then add it to your database: see > http://www.initd.org/pub/software/pysqlite/doc/usage-guide.html#creating-user-defined-functions > . > > HTH. > > -- > John. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use function from specific module and then switch to other module
On Thu, Nov 6, 2008 at 5:54 PM, Ertl, John C CIV 63134 <[EMAIL PROTECTED]> wrote: > Classification: UNCLASSIFIED > Caveat (s): FOUO > > I have a program that collects weather data from weather models. I > originally had a module that contained a bunch of function that I used. So > I just added it to the init of the class I was using and inherited the > functions. That worked great but now I have two different models that I can > get weather from. Each Module A and B have the exact same function names > in them but they both do slightly different things. It might help to see a working example of what you did for one model. > > The idea is as I step through a list I want to use a different function > (same name but from a different module) for each element in the list. How > do I have a generic way to do this. > > for example for point 1 I want to use the rain function from Module A and > then for point 2 I want to use the rain function from Module B. At first > though I would just init the class from either A or B for each point but I > need the function from A or B to be able to use function from my main > program...that is why the inheritance thing worked great for just one > module. Don't try to make the model A and B into base classes of the forecast. Just pass the forecast object to the model. So your rain() method will look more like this: def rain(self, fc): fc.calTime() # this function is in the main forecast class fc.rain = do stuff for model A where fc will be the forecast instance. You might also be able to use simple functions rather than classes: def rain(fc): fc.calTime() # this function is in the main forecast class fc.rain = do stuff for model A then just call moduleA.rain(self) or moduleB.rain(self). You might want to read about the Strategy pattern, that is what you are doing. Here is a Python example of a class-based Strategy. http://mail.python.org/pipermail/python-list/2006-April/379188.html This example passes the strategy to the constructor but you can set it in your pointInfo() method if you like. I would just make one function to handle each point though: for each in x.pointList: x.handlePoint(each) where def handlePoint(self, point): pointStrategy = ... pointStrategy.rain(self, point) Kent Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use function from specific module and then switch to other module
2008/11/7 Ertl, John C CIV 63134 <[EMAIL PROTECTED]>: > The idea is as I step through a list I want to use a different function > (same name but from a different module) for each element in the list. How > do I have a generic way to do this. > > for example for point 1 I want to use the rain function from Module A and > then for point 2 I want to use the rain function from Module B. Hi John, You could use a dictionary to store the functions. For example: import module_a import module_b rain_functions = { 1:module_a.get_rain, 2:module_b.get_rain } Then you could call the function as: x = forecast() points = x.getPoints() for point in points: rain_functions[point]() Hope this helps, -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to use function from specific module and then switch to other module
Classification: UNCLASSIFIED Caveat (s): FOUO I have a program that collects weather data from weather models. I originally had a module that contained a bunch of function that I used. So I just added it to the init of the class I was using and inherited the functions. That worked great but now I have two different models that I can get weather from. Each Module A and B have the exact same function names in them but they both do slightly different things. The idea is as I step through a list I want to use a different function (same name but from a different module) for each element in the list. How do I have a generic way to do this. for example for point 1 I want to use the rain function from Module A and then for point 2 I want to use the rain function from Module B. At first though I would just init the class from either A or B for each point but I need the function from A or B to be able to use function from my main program...that is why the inheritance thing worked great for just one module. I have tried to make a very simple and not syntactically correct mockup of the code to help illustrate my problem. class forecast: def __init__(self) def calcTime(self): #calculate some time and date stuff. x.day = time stuff x.time = time stuff def cloths2Wear(self): self.rain() # I wan to make this simple call but somewhere along the line have set which module def getPoint(self): self.pointList = 1,2,3,4,5,6 def pointInfo(self): # get info about the point say which model to use x.model = A or B x = forecast() x.getPoint() for each in x.pointList: x.pointInfo(each) x.rain() # I want to call the correct function based on what was set in pointInfo. module A class A: def __init__(self): self.model=A def rain(self): self.calTime() # this function is in the main forecast class self. rain = do stuff for model A module B class B: def __init__(self): self.model=B def rain(self): self.calTime() # this function is in the main forecast class self. rain = do stuff for model B Thanks for any ideas you might have. John Ertl Meteorologist FNMOC 7 Grace Hopper Ave. Monterey, CA 93943 (831) 656-5704 [EMAIL PROTECTED] Classification: UNCLASSIFIED Caveat (s): FOUO ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with sqlite replace function
2008/11/7 aivars <[EMAIL PROTECTED]>: > I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 Hi Aivars, I believe python has its own built-in sqlite, rather than using the version you installed independently. So it is possible that the python version of sqlite is older than 3.6.2 and does not yet have the replace() function. (run 'import sqlite3' and then examine 'sqlite3.sqlite_version' to see what version you are using) You could try replacing sqlite3.dll in your python25\dlls directory with the DLL from your sqlite installation (make a backup first :-) ). Alternatively, you could define the replace() function in python and then add it to your database: see http://www.initd.org/pub/software/pysqlite/doc/usage-guide.html#creating-user-defined-functions . HTH. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] please help with sqlite replace function
Hello, I am stuck now. I have a sqlite database with a table calendar (which is an auxilary calendar table containing dates, years, months, days) >From sqlite prompt I can run the following query without any problem: SELECT replace( datums,'-','' ) FROM calendar where Y='2008' and M='5' It gives me back date strings in the format MMDD. But when I run it from the python script it gives me the following error: sqlite3.OperationalError: no such function: replace. Script is simple as follows: import sqlite3 spath=r'e:\pythonexamples\aivars2.db' sql="SELECT replace(datums,'-','') FROM Calendar where Y='2008' and M='5'" cn=sqlite3.connect(spath) for row in cn.execute(sql): print row[0] When I run the script without the replace function in select statement it runs OK. I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 Thanks for any tip. maybe I should ask this to sqlite mailing list? Aivars ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Date validation? Correction
bob gailer wrote: Eric Dorsey wrote: Greetings, I have a program where I ask a user to enter a date in format -MM-DD, and get a string like: '2008-10-25' Can anyone tell me how I would verify this is a real date before allowing it to be passed on to the next part of the program? Take a look at the time module and it's strptime function. >>> import time >>> time.strptime("2008-10-25", "%Y-%m-%d") ## CORRECTED (2008, 10, 25, 0, 0, 0, 5, 299, -1) >>> time.strptime("2008-10-125", "%Y-%m-%d") Traceback (most recent call last): File "", line 1, in File "H:\Python25\lib\_strptime.py", line 313, in strptime data_string[found.end():]) ValueError: unconverted data remains: 5 -- Bob Gailer Chapel Hill NC 919-636-4239 When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others. Nonviolent Communication provides tools for this awareness. As a coach and trainer I can assist you in learning this process. What is YOUR biggest relationship challenge? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Date validation?
Eric Dorsey wrote: Greetings, I have a program where I ask a user to enter a date in format -MM-DD, and get a string like: '2008-10-25' Can anyone tell me how I would verify this is a real date before allowing it to be passed on to the next part of the program? Take a look at the time module and it's strptime function. >>> import time >>> time.strptime("2008-10-125", "%Y-%m-%d") (2008, 10, 25, 0, 0, 0, 5, 299, -1) >>> time.strptime("2008-10-125", "%Y-%m-%d") Traceback (most recent call last): File "", line 1, in File "H:\Python25\lib\_strptime.py", line 313, in strptime data_string[found.end():]) ValueError: unconverted data remains: 5 -- Bob Gailer Chapel Hill NC 919-636-4239 When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others. Nonviolent Communication provides tools for this awareness. As a coach and trainer I can assist you in learning this process. What is YOUR biggest relationship challenge? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Date validation?
On Thu, Nov 6, 2008 at 1:27 PM, Eric Dorsey <[EMAIL PROTECTED]> wrote: > Greetings,I have a program where I ask a user to enter a date in format > -MM-DD, and get a string like: '2008-10-25' > > Can anyone tell me how I would verify this is a real date before allowing > it to be passed on to the next part of the program? > I guess it depends on what your definition of "real date" is... Should the year fall in a certain range? How about the month and day? Are you going to require - between each element? Do you know how to split a string and convert the elements to integers? That should give you some clues to your solution... HTH, Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Date validation?
Greetings,I have a program where I ask a user to enter a date in format -MM-DD, and get a string like: '2008-10-25' Can anyone tell me how I would verify this is a real date before allowing it to be passed on to the next part of the program? -- (e) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using Python to replace javascript
"Jim Morcombe" <[EMAIL PROTECTED]> wrote Is there any way to write python code inside a HTML page instead of using Javascript? Yes, but only if you a) are using IE as your browser under Windows. b) Have WSH installed c) Have run the scripting activation script in the Pyhonwin package OR you could write your own browser in Python... Another option is to make Javascript more like Python by using Mochikit... http://mochikit.com/ In general I'd try to stick to vanilla JavaScript for client side web scripting, anything else runs the risk of not working as expected on somebody's browser. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using Python to replace javascript
2008/11/6 Jim Morcombe <[EMAIL PROTECTED]> > Is there any way to write python code inside a HTML page instead of using > Javascript? > There is the KSS project http://kssproject.org/ It uses a css-like markup to write Ajax-functions. juh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using Python to replace javascript
Jim Morcombe wrote: Is there any way to write python code inside a HTML page instead of using Javascript? Not yet - not directly. But there is pyjamas - a Python - javascript translator centered around GWT. http://code.google.com/p/pyjamas/ http://groups.google.com/group/pyjamas-dev?hl=en -- Bob Gailer Chapel Hill NC 919-636-4239 When we take the time to be aware of our feelings and needs we have more satisfying interatctions with others. Nonviolent Communication provides tools for this awareness. As a coach and trainer I can assist you in learning this process. What is YOUR biggest relationship challenge? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Using Python to replace javascript
Is there any way to write python code inside a HTML page instead of using Javascript? Jim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] using rect.inflate()
On Wed, Nov 5, 2008 at 8:14 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > 2008/11/6 Christopher Spears <[EMAIL PROTECTED]>: > > I inserted this code snippet into the Spaceship class: > > > > self.rect = self.image.get_rect() > > print self.rect > > self.rect = self.rect.inflate(-50, -50) > > print self.rect > > > > The following was printed to my console: > > > > > > > > > > I'm assuming that the first two numbers are coordinates for the upper > left corner of the rectangle. The third and fourth numbers are the width > and height of the rectangle from the upper left corner. Am I off base here? > > If that is the case, why does rect.inflate() move the upper left corner? > IIRC - in pygame (and some of the other modules) they use a Q4 type coordinate system. I *think* anyway - it's been a while. But I believe they work from the top left corner, instead of bottom left. So your XY rather than (2, 4) moving right and up moves right and down. Similarly, any manipulations you make will also work from (0,0), rather than (2, 4) like you might expect. I'm not 100% sure on that, so you may want to research for a bit just to either verify or disprove my dim memory of the possible situation. HTH, Wayne > > > At a guess: the inflation (or, in this case, deflation) is centred on > the centre of the figure. So a horizontal change of -50 means the > left edge moves 25 pixels right and the right edge moves 25 pixels > left. (or, rather, the total width drops frrom 70 pixels to 20 > pixels) > > I'm not sure what's going on with the height, though. > > -- > John. > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] validating decimal class
John Fouhy wrote: 2008/11/6 Brian Lane <[EMAIL PROTECTED]>: But you could also compare it to a known type: if not type(price) is type(decimal.Decimal(0)): print "Not Decimal" Easier to just compare with decimal.Decimal: import decimal d = decimal.Decimal(13) type(d) == decimal.Decimal True And since classes are singletons, you can use 'is' instead of '=='. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor