Re: [Tutor] python clusters
When you say "text file" and variables, you mean you have a file with n records and m fields? Isn't the following what you are searching for? http://docs.scipy.org/doc/scipy/reference/cluster.html___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to develop a python exe file in windows using python3.1
I am using python3.1 in windows environment.How can I create a python executable file? I tried with py2exe package but it is not compatible with python3.1.Is there any other way... pls help me... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to develop a python exe file in windows using python3.1
We literally just answered this question a couple days ago, but if you need to make an executable in 3.1, CX freeze i believe should work. On Thu, Apr 14, 2011 at 9:42 AM, ema francis wrote: > I am using python3.1 in windows environment.How can I create a python > executable file? > I tried with py2exe package but it is not compatible with python3.1.Isthere > any other way... > pls help me... > > ___ > 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] Need help with the property function
Steven D'Aprano wrote: Jim Byrnes wrote: I'm trying to teach myself OOP in python (again). The following code from Dawson's book runs fine, unaltered [1]. What's Dawson's book? Python Programming for the absolute beginner, by Michael Dawson Thanks for the explanation. It was exactly with I was hoping for. The book and a couple of other resources I looked at didn't lay it out so completely. They all assumed I knew more than I did. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with the property function
Dave Angel wrote: On 01/-10/-28163 02:59 PM, Jim Byrnes wrote: I'm trying to teach myself OOP in python (again). The following code from Dawson's book runs fine, unaltered [1]. class Critter(object): """ A virtual pet """ def __init__(self, name): print "A new critter is born" self.name = name def get_name(self): return self.__name def set_name(self, new_name): if new_name == "": print "A critters name cant be the empty string" else: self.__name = new_name print "Name change successful" name = property(get_name, set_name) #[1] # name = property(get_name) #[2] #different_name = property(get_name) #[3] def talk(self): print "Hi. I'm", self.name If I change [1] to [2] I get: Traceback (most recent call last): File "propertycritter.py", line 26, in crit = Critter("Poochie") File "propertycritter.py", line 7, in __init__ self.name = name AttributeError: can't set attribute If I change [1] to [3] the program runs with no errors. Could someone please explain why I am seeing these results. Thanks, Jim In case#2 you're making name a read-only property. So why on earth would you expect to be able to modify that property? DaveA Because I was confused and didn't fully understand the process. I was experimenting and trying understand it to use it something else I was writing. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] super() with Multiple Inheritance
Why does user.params() not return all the params up the inheritance chain? -- It's not including the params defined in Person() -- notice Vertex() does not have a params() method. class Element(object): def __init__(self,element_type): self.oid = None self.uuid = uuid.uuid4() self.key = None self.element_type = element_type def params(self): return dict(uuid=self.uuid, key=self.key) class Vertex(Element): def __init__(self): super(Vertex,self).__init__("vertex") class Person(Vertex): def __init__(self,name=None,uri=None,email=None): self.s = super(Person,self) self.s.__init__() self.name=name self.uri=uri self.email = email def params(self): params = dict(name=self.name,uri=self.uri,email=self.email) params.update(self.s.params()) return params class User(Person): def __init__(self, name=None, uri=None, email=None, first_name=None, last_name=None, facebook_id=None, facebook_link=None, facebook_username=None, gender=None, locale=None): self.s = super(User,self) self.s.__init__(name,uri,email) self.first_name = first_name self.last_name = last_name self.facebook_id = facebook_id self.facebook_link = facebook_link self.facebook_username = facebook_username self.gender = gender self.locale = locale def params(self): params = dict(first_name=self.first_name, last_name=self.last_name, facebook_id=self.facebook_id, facebook_link=self.facebook_link, facebook_username=self.facebook_username, gender=self.gender, locale=self.locale) print self.s.params() params.update(self.s.params()) return params ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python clusters
Thank you very much. This is exactly what I'm looking for. Do I have to install numpy and Scipy? It throws an error No module named numpy. I'm completely new to Python programming, trying to convert SAS code to python. I am able to do some simple steps, but this one is the clustering program in SAS enterprise miner and I don't have any idea of how to start with inb Python, that's the reason I did not post any code. I just used SAS language like variables. Thanks, Sree. --- On Thu, 4/14/11, Luc Kesters wrote: From: Luc Kesters Subject: Re: [Tutor] python clusters To: tutor@python.org Date: Thursday, April 14, 2011, 4:02 PM When you say "text file" and variables, you mean you have a file with n records and m fields? Isn't the following what you are searching for? http://docs.scipy.org/doc/scipy/reference/cluster.html -Inline Attachment Follows- ___ 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] python clusters
"nookasree ponamala" wrote ...trying to convert SAS code to python. this one is the clustering program in SAS enterprise miner OK, I tried Google and got a 3Meg SAS PDF file that didn't help much. :-( I'm curious. Could someone post the elevator pitch on SAS Clustering? What on earth is it? Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
"James Thornton" wrote Why does user.params() not return all the params up the inheritance chain? -- It's not including the params defined in Person() -- notice Vertex() does not have a params() method. class Element(object): def params(self): return dict(uuid=self.uuid, key=self.key) class Vertex(Element): class Person(Vertex): def params(self): params = dict(name=self.name,uri=self.uri,email=self.email) params.update(self.s.params()) return params class User(Person): def params(self): params = dict(first_name=self.first_name, locale=self.locale) print self.s.params() params.update(self.s.params()) return params Where does User.params call Person.params? Or for that matter Person.params call its super class? It doesn't happen automatically(thank goodness) you have to do it explicitly. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): self.s = super(User,self) self.s.__init__(name,uri,email) def params(self): params = dict(name=self.name) params.update(self.s.params()) ...but this won't work. You have to use super each time you want to make a call to a parent's function. It returns an object with an internal queue. If you use this object twice, you will only call the method of the top class (in this case, Element). super does not return an object from the parent class. It is a mechanism from managing multiple inheritance On Thu, Apr 14, 2011 at 12:25 PM, Alan Gauld wrote: > > "James Thornton" wrote > >> Why does user.params() not return all the params up the inheritance >> chain? -- It's not including the params defined in Person() -- notice >> Vertex() does not have a params() method. > >> class Element(object): >> def params(self): >> return dict(uuid=self.uuid, key=self.key) >> >> class Vertex(Element): >> >> class Person(Vertex): >> def params(self): >> params = dict(name=self.name,uri=self.uri,email=self.email) >> params.update(self.s.params()) >> return params >> >> class User(Person): >> def params(self): >> params = dict(first_name=self.first_name, >> locale=self.locale) >> print self.s.params() >> params.update(self.s.params()) >> return params > > Where does User.params call Person.params? > Or for that matter Person.params call its super class? > It doesn't happen automatically(thank goodness) you > have to do it explicitly. > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Latest Blog: http://jamesthornton.com/blog/how-to-get-to-genius ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python clusters
Here is the link which explains Clustering in SAS clearly. Copy and paste it in browser. http://www.hstathome.com/tjziyuan/SAS%20Data%20Mining%20Using%20Sas%20Enterprise%20Miner%20-%20A%20Case%20Study%20Appro.pdf Sree. --- On Thu, 4/14/11, Alan Gauld wrote: > From: Alan Gauld > Subject: Re: [Tutor] python clusters > To: tutor@python.org > Date: Thursday, April 14, 2011, 10:50 PM > > "nookasree ponamala" > wrote > > > ...trying to convert SAS code to python. this > one > > is the clustering program in SAS enterprise miner > > OK, I tried Google and got a 3Meg SAS PDF file that didn't > help much. :-( > > I'm curious. Could someone post the elevator pitch on SAS > Clustering? > What on earth is it? > > Alan G. > > > > > > ___ > 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] Python on TV
Same here. I did not realize I was living in an internet censored country here in Texas! On Mon, Apr 11, 2011 at 16:04, bob gailer wrote: > On 4/11/2011 4:20 PM, Alan Gauld wrote: > >> I've just watched the Channel 5 programme "The Gadget Show" >> where the presenters set a new Guinness world record for operating >> the heaviest machine(*) using mind power. The software behind >> this feat - was written in Python of course! :-) >> >> (*)The machine in question was a 50 ton industrial crane... used >> to move a car from one end of a warehouse to the other. >> >> The show should be here - Pause at 1 minute 20 for the >> Python screnshot: >> >> >> http://fwd.channel5.com/gadget-show/videos/challenge/surprise-special-part-4 >> > > I am told "the video ... cannot be viewed from your currrent country ..." > > Sigh. > > > -- > 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to develop a python exe file in windows using python3.1
On Thu, Apr 14, 2011 at 08:42, ema francis wrote: > I am using python3.1 in windows environment.How can I create a python > executable file? > I tried with py2exe package but it is not compatible with python3.1.Isthere > any other way... > pls help me... > > cxfreeze works quite well for producing stand-alone Python apps. The only issue I have had is the occasional file or files from a third party module that do not get automatically brought over into the distribution target folder. However, in all those cases the error messages when the program was run gave me enough information to know what files I needed to go copy from my Python folders over into the distribution folder so it could find them. I use cxfreeze regularly for situations that are best served with a stand-alone Python program. However, I do recommend carefully evaluating if you need stand-alone or if installing the interpreter is more appropriate. I have found that not every program is best served by being converted to stand-alone. http://cx-freeze.sourceforge.net/ Good Luck, Bill Allen ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python on TV
I don't see how a content provider preventing you from accessing content internationally that they probably don't have international distribution rights to as censorship. It's not like your ISP is blocking your access. - Sent from a mobile device. Apologies for brevity and top-posting. - On Apr 14, 2011, at 3:25 PM, Bill Allen wrote: > Same here. I did not realize I was living in an internet censored country > here in Texas! > > > > On Mon, Apr 11, 2011 at 16:04, bob gailer wrote: > On 4/11/2011 4:20 PM, Alan Gauld wrote: > I've just watched the Channel 5 programme "The Gadget Show" > where the presenters set a new Guinness world record for operating > the heaviest machine(*) using mind power. The software behind > this feat - was written in Python of course! :-) > > (*)The machine in question was a 50 ton industrial crane... used > to move a car from one end of a warehouse to the other. > > The show should be here - Pause at 1 minute 20 for the > Python screnshot: > > http://fwd.channel5.com/gadget-show/videos/challenge/surprise-special-part-4 > > I am told "the video ... cannot be viewed from your currrent country ..." > > Sigh. > > > -- > 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 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] Python on TV
On Thu, Apr 14, 2011 at 4:25 PM, Bill Allen wrote: > Same here. I did not realize I was living in an internet censored country > here in Texas! > > > > > On Mon, Apr 11, 2011 at 16:04, bob gailer wrote: > >> On 4/11/2011 4:20 PM, Alan Gauld wrote: >> >>> I've just watched the Channel 5 programme "The Gadget Show" >>> where the presenters set a new Guinness world record for operating >>> the heaviest machine(*) using mind power. The software behind >>> this feat - was written in Python of course! :-) >>> >>> (*)The machine in question was a 50 ton industrial crane... used >>> to move a car from one end of a warehouse to the other. >>> >>> The show should be here - Pause at 1 minute 20 for the >>> Python screnshot: >>> >>> >>> http://fwd.channel5.com/gadget-show/videos/challenge/surprise-special-part-4 >>> >> >> I am told "the video ... cannot be viewed from your currrent country ..." >> >> Sigh. >> >> >> -- >> Bob Gailer >> 919-636-4239 >> Chapel Hill NC >> >> I'm guessing that this is caused by copyright restrictions > >> ___ >> 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 > > -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python on TV
On Thu, Apr 14, 2011 at 15:33, Luke Paireepinart wrote: > I don't see how a content provider preventing you from accessing content > internationally that they probably don't have international distribution > rights to as censorship. It's not like your ISP is blocking your access. > > Seriously, I was only joking!:-) --Bill ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
"James Thornton" wrote I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): ...but this won't work. No, because super returns whatever the superclass method returns. Which in init() is usually None. You have to use super each time you want to make a call to a parent's function. It returns an object with an internal queue. It should return the result of the superclasses method, whatever that is. mechanism from managing multiple inheritance Or even single inheritance if you want to... Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
James, Your subject line is misleading: you ask about *multiple* inheritance, but the code you use is *single* inheritance: object -> Element -> Vertex -> Person -> User Multiple inheritance occurs when you have a class that inherits from two or more parent classes: class Spam(Ham, ManufacturedMeatProduct): [...] This is often problematic, so much so that many object oriented languages prohibit it, or limit it to a subset of MI where the second parent shares no methods with the first ("mixins"). Python allows almost unrestricted MI, but I strongly recommend that you avoid it unless absolutely necessary. Also, it's quite unusual in Python to build long inheritance chains like this. We're a pragmatic people, we Python coders, and if a class only exists to satisfy some sense of theoretical object-hierarchy purity, more often than not we prefer the Zen of Python: >>> import this [...] Practicality beats purity. I'd consider reducing the hierarchy to: object -> Element -> User unless you have real need for the other classes. James Thornton wrote: Why does user.params() not return all the params up the inheritance chain? -- It's not including the params defined in Person() -- notice Vertex() does not have a params() method. You do something fairly unusual here: class Person(Vertex): def __init__(self,name=None,uri=None,email=None): self.s = super(Person,self) self.s.__init__() I've never seen anyone *store* a super object before! Normally people generate it as needed: super(Person, self).__init__() This leads to your mistake: class User(Person): def __init__(self, [...]) self.s = super(User,self) self.s.__init__(name,uri,email) So you store the User's super object as attribute "s", and then call the superclasses' __init__ method... but Person's __init__ in turn *also* stores its super object as "s", thus *over-writing* the "s" you just saved. Then, when you call params: def params(self): params = dict(...) print self.s.params() params.update(self.s.params()) return params self.s is the super object for Person, not User, and so it skips Person and goes directly to Vertex, Element and object. TL;DR: don't save super objects for later use, they're not that expensive to make. Just regenerate them as needed. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
Alan Gauld wrote: "James Thornton" wrote I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): ...but this won't work. No, because super returns whatever the superclass method returns. Which in init() is usually None. No, super returns a proxy object that encapsulates knowledge of the superclasses of the argument (usually "self", but not necessarily). >>> class A(object): ... attr = "Nobody expects the SPANISH INQUISITION!" ... >>> class B(A): ... attr = "something else" ... >>> b = B() >>> s = super(B, b) >>> s , > What you do with that proxy object is then lookup attributes (usually methods, but data attributes are fine too): >>> s.attr 'Nobody expects the SPANISH INQUISITION!' If you look up a method, and *call* that method, then of course the complete chain of super::method lookup::method call will return whatever the method itself returns. But that's different from saying that super itself returns (say) None. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] super() with Multiple Inheritance
"Steven D'Aprano" wrote No, because super returns whatever the superclass method returns. Which in init() is usually None. No, super returns a proxy object that encapsulates knowledge of the superclasses of the argument (usually "self", but not necessarily). >>> b = B() >>> s = super(B, b) >>> s , > I stand corrected. And I'm sure Guido knows why he did it that way, but it adds to the complexity in the way Python handles this stuff. I know SmallTalk has it simpler because it only has to deal with single inheritance but the Python super() implementation really, really feels flaky to me, its one of the few Python features I don't enjoy using. If you look up a method, and *call* that method, then of course the complete chain of super::method lookup::method call will return whatever the method itself returns. But that's different from saying that super itself returns (say) None. True, although it feels like that to the programmer. But under the hood its different and potentially acts different. Thanks for pointing that out - I'm gonna have to give it some (more) thought. I keep trying to embrace super() but every time I try I just find more issues with it. yek! Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python on TV
Luke Paireepinart wrote: I don't see how a content provider preventing you from accessing content internationally that they probably don't have international distribution rights to as censorship. It's not like your ISP is blocking your access. There is nothing about censorship that means it can only be performed by government. Your parents probably censored what you saw and read when you were a child. Fox News censors; private companies and entities of all sizes and forms censor, with varying degrees of success and different motives. As Bill Cole once said: "Here in the US, we are so schizoid and deeply opposed to government censorship that we insist on having unaccountable private parties to do it instead." Not all censorship is bad, nor is it always from a desire to hide information or keep people ignorant. Often it is from a desire to make money by restricting information. Sometimes the entity doing the censorship doesn't gain from it at all, but does so on behalf of another party. Sometimes the party doing the censorship doesn't even realise that they are censoring, because they themselves are equally victims of censorship. It's all still censorship. As for international distribution rights, that concept no longer makes sense in the 21st century. It's well past time that they have their business models catch up to reality. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Writing to the file system and verify the files written out.
Hi, all: I'm doing a tutorial online and I have run across an assignment to write a unit test. One of the tests is working fine, the other one is failing. The goal of this particular one is: 1) Create a directory 2) Create files in the directory that are listed in the text files 3) Create a set with the filenames of all the files that were created 3) List the files files, using os.listdir 4) Create a set with the above list 5) Compare the two sets to ensure that no files were created that weren't in the text files The setUp() method and the tearDown() method work fine, as well as test_2(), but test_1, is failing the unittest, with: FAIL: test_1 (setupDemo.FileTest) Verify creation of files is possible -- Traceback (most recent call last): File "V:\workspace\Python2_Homework02\src\setupDemo.py", line 33, in test_1 self.assertEqual(dir_list, text_files, "The filelist is not equal") AssertionError: The filelist is not equal I'm not sure why the lists would not be equal Here is the code: """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) def test_1(self): "Verify creation of files is possible" text_files = set() for filename in ("this.txt", "that.txt", "the_other.txt"): f = open(filename, "w") f.write("Some text\n") text_files.add(filename) f.close() self.assertTrue(f.closed) dir_list = os.listdir(self.dirname) dir_set = set() for file in dir_list: dir_set.add(file) self.assertEqual(dir_list, text_files, "The filelist is not equal") def test_2(self): "Verify that the current directory is empty" self.assertEqual(glob.glob("*"), [], "Directory not empty") def tearDown(self): os.chdir(self.origdir) shutil.rmtree(self.dirname) if __name__ == "__main__": unittest.main() Any help greatly appreciated! Becky ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor