Re: [Tutor] A class that instantiates conditionally ?

2011-03-02 Thread Izz ad-Din Ruhulessin
Of course that would be: > foo = lambda condition: MyClass() if condition else None 2011/3/3 Izz ad-Din Ruhulessin > Maybe: > > foo = lambda x: MyClass() if condition else None > > > 2011/3/3 David > > Another classic case of trying something not the best way, due to >> inexperience. >> But

Re: [Tutor] A class that instantiates conditionally ?

2011-03-02 Thread Izz ad-Din Ruhulessin
Maybe: foo = lambda x: MyClass() if condition else None 2011/3/3 David > Another classic case of trying something not the best way, due to > inexperience. > But it has been a good process: I learned something new from > setting myself the initial puzzle and then finding a solution,and then >

Re: [Tutor] A class that instantiates conditionally ?

2011-03-02 Thread David
Another classic case of trying something not the best way, due to inexperience. But it has been a good process: I learned something new from setting myself the initial puzzle and then finding a solution,and then learned more from the great tutoring here. Thanks very much for all the replies. On 2

Re: [Tutor] Alternatives to pymssql to work with MS SQL Server

2011-03-02 Thread Alan Gauld
"Emmanuel Ruellan" wrote Steven, sorry if my question was slightly off topic. ... I should stop considering that my questions fall into the 'beginner' category, now that I've been dabbling in Python for a few years. Steven's point was, I think, more that your question was not really about

[Tutor] python simplejson decoding

2011-03-02 Thread Arthur Mc Coy
Hi all, I'm trying an example (in attached file). First, I create a list of 3 objects. Then I do: PutJSONObjects(objects) objects = GetJSONObjects() PutJSONObjects(objects, "objects2.json") 1) PutJSONObjects(objects) method creates objects.json file (by default). It works fine. 2) Then obje

Re: [Tutor] A class that instantiates conditionally ?

2011-03-02 Thread Knacktus
Am 01.03.2011 07:49, schrieb David: I have an idea that might clean up my code slightly, if I can make one of my classes clever enough to refuse to instantiate itself if a necessary condition is not met. I think that's too clever ;-). Instead, you could create a function which has the only and

Re: [Tutor] Alternatives to pymssql to work with MS SQL Server

2011-03-02 Thread Emmanuel Ruellan
Tim, it's raw SQL queries I want to use. Pyodbc looks fine, thanks for suggesting it to me. I'll have to test it on the specific machine on which I encountered the problem with pymssql. Raúl, thanks for the link to a list of alternatives to pymssql. You suggested that I try and change the order of

Re: [Tutor] A class that instantiates conditionally ?

2011-03-02 Thread Steven D'Aprano
Alan Gauld wrote: "David" wrote clever enough to refuse to instantiate itself if a necessary condition is not met. class MyClass_2(object): def __new__(self, condition): if condition: return object.__new__(self) else: return None Thats

Re: [Tutor] Alternatives to pymssql to work with MS SQL Server

2011-03-02 Thread Steven D'Aprano
Emmanuel Ruellan wrote: What alternatives to pymssql do you recommend? I just want to be able to perform some simple queries on an MS SQL Server database. This is a mailing list for teaching beginners how to program in Python. While we're happy to help with other Python-related questions, you

Re: [Tutor] Alternatives to pymssql to work with MS SQL Server

2011-03-02 Thread Tim Golden
On 02/03/2011 09:22, Emmanuel Ruellan wrote: I installed Python 2.6 and pymssql on a machine, but as soon as I import pymssql, it crashes. It looks like this is a known problem: http://code.google.com/p/pymssql/issues/detail?id=2 What alternatives to pymssql do you recommend? I just want to be

[Tutor] Alternatives to pymssql to work with MS SQL Server

2011-03-02 Thread Emmanuel Ruellan
Hi tutors, I installed Python 2.6 and pymssql on a machine, but as soon as I import pymssql, it crashes. It looks like this is a known problem: http://code.google.com/p/pymssql/issues/detail?id=2 What alternatives to pymssql do you recommend? I just want to be able to perform some simple queries