[Tutor] general import VS importing inside a function

2009-08-28 Thread Fidel Sanchez-Bueno
What is the best aproach when it comes to import??, is allways better to make all the import calls in the global scope, making the overall runtime of the program better because the program is not going to import something everytime a function is called, or is better to make specific import's in

Re: [Tutor] Sending an email alert

2009-08-28 Thread Marc
> On Fri, Aug 28, 2009 at 3:00 PM, Marc wrote: > > Hello, > > > > > > > > I am trying to code an email alert and am running into the following > error: > > > >     s = smtplib.SMTP('smtp.marcd.org') > > > > AttributeError: 'module' object has no attribute 'SMTP' > > Your file 'email.py' is hiding

Re: [Tutor] NLTK

2009-08-28 Thread Ishan Puri
Hi, Thanks for the confirmation. IM50re.txt is a plain text corpus. Let us say that we want to count the words in this corpus. In the NLTK book, there is an example. >>> import nltk >>> nltk.corpus.gutenberg.fileids() ['austen-emma.txt', 'austen-persuasion.txt', 'austen-sense.txt', 'bible-k

Re: [Tutor] NLTK

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 7:29 PM, Ishan Puri wrote: > Hi, from nltk.corpus import PlaintextCorpusReader corpus_root='C:\Users\Ishan\Documents' wordlists = PlaintextCorpusReader(corpus_root, 'IM50re.txt') wordlists.fileids() > ['IM50re.txt'] > > This is the result I get. That see

Re: [Tutor] Sending an email alert

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 3:00 PM, Marc wrote: > Hello, > > > > I am trying to code an email alert and am running into the following error: > > Connecting to server > > Traceback (most recent call last): > >   File "C:\Users\Marc1\Documents\Python\email test\email.py", line 1, in > > >     import sm

Re: [Tutor] Store Class in Tuple Before Defining it ...

2009-08-28 Thread Alan Gauld
"Damon Timm" wrote Anyhow, I would like to have a tuple defined at the beginning of my code that includes classes *before* they are defined ... as such (this is on-the-fly-hack-code just for demonstrating my question): See another recent thread - you can't do it. What you could do is put y

Re: [Tutor] Store Class in Tuple Before Defining it ...

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 5:21 PM, Damon Timm wrote: > Sorry for the double post!  Went off by mistake before I was done ... > > Anyhow, I would like to have a tuple defined at the beginning of my > code that includes classes *before* they are defined ... as such (this > is on-the-fly-hack-code just

Re: [Tutor] NLTK

2009-08-28 Thread Ishan Puri
Hi, >>> from nltk.corpus import PlaintextCorpusReader >>> corpus_root='C:\Users\Ishan\Documents' >>> wordlists = PlaintextCorpusReader(corpus_root, 'IM50re.txt') >>> wordlists.fileids() ['IM50re.txt'] This is the result I get. I was wondering how I can use the packages on IM50re.txt? I followed s

Re: [Tutor] NLTK

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 6:09 PM, Ishan Puri wrote: > Hi, >     Thanks for your response. I tried this and got to the 3rd line. However, > when I type in the fourth: > wordlists.fileids() > > a blank comes as a result. When I try the len() function it only counts the > letters in title of the >

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Serdar Tumgoren
class A: > instances = {} > def __new__(self,ID): > if ID in self.instances: > return self.instances[ID] > else: > self.instances[ID] = self > return self > def __init__(self, ID): > if ID not in self.instances: > print("unregistered instance!") > def __del__(self): > del(self.instances[self.I

[Tutor] Using my own corpus with NLTK

2009-08-28 Thread Ishan Puri
Hi, Thanks for your response. I tried this and got to the 3rd line. However, when I type in the fourth: >>> wordlists.fileids() a blank comes as a result. When I try the len() function it only counts the letters in title of the text document IM50re.txt. How do I get it to open and analyze

Re: [Tutor] Making sense of "'python' is not recognized as an internalor external command...

2009-08-28 Thread Alan Gauld
"Eduardo Vieira" wrote Hello, list. Sorry, for this basic question. But why in Windows (XP) command prompt I get this message if, for example I type "python myscript.py"? But it works if I simply type myscript.py? In the latter case Windows usees a registry setting to pick up what program

Re: [Tutor] Running two applications at once

2009-08-28 Thread Alan Gauld
"Dirk Wangsadirdja" wrote Is it possible if I run two applications at once? Yes, you just run two instances of the python interpreter. They will happuily run independantly of one another or communicate with each other as you wish. Its exactly the same as with Java or Visual Basic or any ot

[Tutor] Sending an email alert

2009-08-28 Thread Marc
Hello, I am trying to code an email alert and am running into the following error: Connecting to server Traceback (most recent call last): File "C:\Users\Marc1\Documents\Python\email test\email.py", line 1, in import smtplib File "C:\Python26\lib\smtplib.py", line 46, in imp

[Tutor] Running two applications at once

2009-08-28 Thread Dirk Wangsadirdja
hi, I'm new to python, and I'm starting with Python 3.1 directly. I have been learning python for about 2 weeks now. And I have few questions. Is it possible if I run two applications at once? For example, if I make a clock/timer application with alarm etc, then I want exercise with my pytho

Re: [Tutor] Store Class in Tuple Before Defining it ...

2009-08-28 Thread Damon Timm
Sorry for the double post! Went off by mistake before I was done ... Anyhow, I would like to have a tuple defined at the beginning of my code that includes classes *before* they are defined ... as such (this is on-the-fly-hack-code just for demonstrating my question): VIDEO_TYPES = ( (SyncYo

[Tutor] Store Class in Tuple Before Defining it ...

2009-08-28 Thread Damon Timm
Hi - I would like to have a tuple that holds information, as such: VIDEO_TYPES = ( (SyncYoutube, re.compile(r'([^(]|^)http://www\.youtube\.com/watch\?\S*v=(?P[A-Za-z0-9_-]+)\S*'),), ) ___ Tutor maillist - Tutor@python.org http://mail.python.org/m

[Tutor] Running two applications at once

2009-08-28 Thread Dirk Wangsadirdja
hi, I'm new to python, and I'm starting with Python 3.1 directly. I have been learning python for about 2 weeks now. And I have few questions. Is it possible if I run two applications at once? For example, if I make a clock/timer application with alarm etc, then I want exercise with my python,

[Tutor] Making sense of "'python' is not recognized as an internal or external command...

2009-08-28 Thread Eduardo Vieira
Hello, list. Sorry, for this basic question. But why in Windows (XP) command prompt I get this message if, for example I type "python myscript.py"? But it works if I simply type myscript.py? Maybe by getting an answer for this question I could know how to make commands "grep, diff" work from any fo

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Serdar Tumgoren
I was able to resolve the error by explicitly naming the class in the dictionary lookup inside __new__: if candid in CandidateAuto.instances: return candid I'm curious why this is necessary though. From our earlier dicussions (and from other reading), I thought that by declari

Re: [Tutor] packing a list of lists

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 10:28 AM, kevin parks wrote: > Interestingly changing: >                out_list.append(ll) > > to > >                out_list.append(list(ll)) > > > seems to work. The part of my brain that understood why that is must have > sleeping. Because it makes a new list instead of

Re: [Tutor] packing a list of lists

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 11:20 AM, vince spicer wrote: > Or even cleaner with list comprehension > > def pack(foo): >     return [x for x in enumerate(foo, 1)] Or just list(enumerate(foo, 1)) For Python 2.5 use [ [i+1, x] for i, x in enumerate(foo) ] Kent

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
On Aug 29, 2009, at 12:23 AM, Michael M Mason wrote: i wrote: def pack(in_seq): out_list=[] x = 1 ll=[1, 1] for each in in_seq: ll[0] = x ll[1] = each out_list.append(ll) #print ll x

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
Interestingly changing: out_list.append(ll) to out_list.append(list(ll)) seems to work. The part of my brain that understood why that is must have sleeping. -k On Aug 28, 2009, at 11:05 PM, i wrote: Back to python after a long long layoff. So i am running

[Tutor] thread causes idle to crash

2009-08-28 Thread Jeff Peery
hello, I've been working on threads and queues and I think I have it working well. The problem seems to be that when I run a thread via the IDLE it crashes. if I simply double click the file it appears to run ok. I'm not sure if I'm doing something incorrectly or not. it seems pretty straight fo

Re: [Tutor] packing a list of lists

2009-08-28 Thread Dave Angel
kevin parks wrote: Back to python after a long long layoff. So i am running into some beginner's confusion... I am trying to plot a list of numbers in gnuplot.py. To do that I am trying to pack the list with an index by iterating over the list so i can get something like: foo = [12, 11, 9,

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Alan Gauld
"Serdar Tumgoren" wrote Given those requirements, is the Mixin approach the way to go? Either way, have I implemented these correctly? I haven't looked at your code but you could use a mixin here however I find using mixins for insantiation can bend your brain. I tend to use them for instan

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
I think this is b/c I am running 2.5. I also have 2.6 but i am using 2.5 for gnupoly and an older audio lib i have. I ran the listcom below on 2.6 and it worked, so i just have to figure out how that can be written for 2.5. I guess 2.6 has an update to enumerate. -k On Aug 29, 2009, at 2:2

Re: [Tutor] What does it mean to create separate applications?

2009-08-28 Thread Alan Gauld
"Kristina Ambert" wrote inventory, it's my internship project for the semester. My boss asked me to break down each form (e.g. product information entry, store inventory list) into separate small applications. I'm having a hard time understanding what she means by this. Does it mean each for

Re: [Tutor] What does it mean to create separate applications?

2009-08-28 Thread Dave Angel
Kristina Ambert wrote: Hi, I'm new to python and frankly new to programming. This is my first question post, so I hope everyone could bear with me. I'm working on a small database application which basically handles a store inventory, it's my internship project for the semester. My boss asked me

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Alan Gauld
"Mac Ryan" wrote I am not sure I understood the difference between staticmethod end classmethod, though, even if I can guess it has to do with subclassing, I think it is mainly historical. staticmethod came first (I think) and classmethod was an improvement a couple of versions later. I th

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 10:49 AM, kevin parks wrote: > > Thanks for the replies. Though the list comprehension does not work: > > TypeError: enumerate() takes exactly 1 argument (2 given) > > > On Aug 29, 2009, at 12:20 AM, vince spicer wrote: > > >> >> #print foohough I didn't test your co

Re: [Tutor] packing a list of lists

2009-08-28 Thread kevin parks
Thanks for the replies. Though the list comprehension does not work: TypeError: enumerate() takes exactly 1 argument (2 given) On Aug 29, 2009, at 12:20 AM, vince spicer wrote: #print foohough I didn't test your code, I think what you are trying to accomplish can be done using enu

Re: [Tutor] Callbacks in Python

2009-08-28 Thread Dave Angel
Jramak wrote: Thanks everyone for your excellent insights. I think I understand the callback concept better. So, it is like passing a function as an argument to another function. I am interested in learning more about how callbacks can be applied in GUIs, using wxPython as an example. Would appr

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Dave Angel
Mac Ryan wrote: On Fri, 2009-08-28 at 08:55 -0400, Dave Angel wrote: Mac Ryan wrote: On Wed, 2009-08-26 at 21:32 -0400, Dave Angel wrote: Now there are a couple of decorators that are in the standard library that everyone should know about:classmethod() and staticmethod(

[Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Serdar Tumgoren
Hi everyone, Based on some earlier list advice, I went back to the drawing board and started testing various approaches to adding the "flyweight" pattern to my classes. To recap, I have a bunch of campaign finance-related classes and subclasses (Committee, HouseCommittee, PresidentialCommittee, C

Re: [Tutor] packing a list of lists

2009-08-28 Thread Michael M Mason
Kevin Parks wrote: > def pack(in_seq): > out_list=[] > x = 1 > ll=[1, 1] > for each in in_seq: > ll[0] = x > ll[1] = each > out_list.append(ll) > #print ll > x = x + 1 > print out_list Variable out

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 9:18 AM, vince spicer wrote: > > > On Fri, Aug 28, 2009 at 8:05 AM, kevin parks wrote: > >> Back to python after a long long layoff. So i am running into some >> beginner's confusion... >> >> I am trying to plot a list of numbers in gnuplot.py. To do that I am >> trying t

Re: [Tutor] packing a list of lists

2009-08-28 Thread vince spicer
On Fri, Aug 28, 2009 at 8:05 AM, kevin parks wrote: > Back to python after a long long layoff. So i am running into some > beginner's confusion... > > I am trying to plot a list of numbers in gnuplot.py. To do that I am trying > to pack the list with an index by iterating over the list so i can g

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Mac Ryan
On Fri, 2009-08-28 at 08:55 -0400, Dave Angel wrote: > Mac Ryan wrote: > > On Wed, 2009-08-26 at 21:32 -0400, Dave Angel wrote: > > > > > >> Now there are a couple of decorators that are in the standard library > >> that everyone should know about:classmethod() and staticmethod(). > >> Th

[Tutor] packing a list of lists

2009-08-28 Thread kevin parks
Back to python after a long long layoff. So i am running into some beginner's confusion... I am trying to plot a list of numbers in gnuplot.py. To do that I am trying to pack the list with an index by iterating over the list so i can get something like: foo = [12, 11, 9, 6, 2, 9, 3, 8, 12

[Tutor] What does it mean to create separate applications?

2009-08-28 Thread Kristina Ambert
Hi, I'm new to python and frankly new to programming. This is my first question post, so I hope everyone could bear with me. I'm working on a small database application which basically handles a store inventory, it's my internship project for the semester. My boss asked me to break down each form

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Dave Angel
Mac Ryan wrote: On Wed, 2009-08-26 at 21:32 -0400, Dave Angel wrote: Now there are a couple of decorators that are in the standard library that everyone should know about:classmethod() and staticmethod(). They wrap a method in a new one (which ends up having the same name), such that

Re: [Tutor] NLTK

2009-08-28 Thread Kent Johnson
On Fri, Aug 28, 2009 at 3:14 AM, Ishan Puri wrote: > Hello, >     I have successfully downloaded NLTK and the toy grammars. I want to run > a few of the packages that come with NLTK on corpora that I have. How do I > do this? What commands would I use? The corpora are text files; should I put > the

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Mac Ryan
On Wed, 2009-08-26 at 21:32 -0400, Dave Angel wrote: > Now there are a couple of decorators that are in the standard library > that everyone should know about:classmethod() and staticmethod(). > They wrap a method in a new one (which ends up having the same name), > such that the first arg

[Tutor] NLTK

2009-08-28 Thread Ishan Puri
Hello, I have successfully downloaded NLTK and the toy grammars. I want to run a few of the packages that come with NLTK on corpora that I have. How do I do this? What commands would I use? The corpora are text files; should I put them in the Python25 folder (is that the so called same direc