Re: [Tutor] defined()

2006-04-03 Thread János Juhász
Dear Tim, Dear Alan, >> I can't find the defined() function in python, so I used >>'variable name' in dir() > >> Is it really missing, or I am just so simple ? > > It is really missing, just as it is for most programming languages. > Which language(s) do you know that has such a feature? I shou

[Tutor] Hi

2006-04-03 Thread Kaushal Shriyan
Hi ALL A simple query is that the python mailing List is python powered What does "python powered" means thanks Regards Kaushal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Orri Ganel
My only comment is that this considers spaces and punctuation (like parentheses, brackets, etc.), too, which I assume you don't want seeing as how that has little to do with natural languages.  My suggestion would be to remove the any punctuation or whitespace keys from the dictionary after you've

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Michael Broe
Well coming up with this has made me really love Python. I worked on this with my online pythonpenpal Kyle, and here is what we came up with. Thanks to all for input so far. My first idea was to use a C-type indexing for-loop, to grab a two- element sequence [i, i+1]: dict = {} for i in rang

Re: [Tutor] file?

2006-04-03 Thread David Rock
* kakada <[EMAIL PROTECTED]> [2006-04-04 09:32]: > Hi all, > > How can we know that one specific file is already exist in filesystem? > for instance, I want to read zipfile by issuing code: > > import zipfile > ziparchive = zipfile.ZipFile(inputfilename, "r") > > if the inputfilename doesn't exi

Re: [Tutor] file?

2006-04-03 Thread Kent Johnson
kakada wrote: > Hi all, > > How can we know that one specific file is already exist in filesystem? > for instance, I want to read zipfile by issuing code: > > import zipfile > ziparchive = zipfile.ZipFile(inputfilename, "r") > > if the inputfilename doesn't exist then an error would be occurred.

Re: [Tutor] file?

2006-04-03 Thread John Fouhy
On 04/04/06, kakada <[EMAIL PROTECTED]> wrote: > How can we know that one specific file is already exist in filesystem? Have a look in the os and os.path modules. In this case, os.path.exists is probably what you want: if not os.path.exists(inputfilename): print 'Oops, file does not exist!'

[Tutor] file?

2006-04-03 Thread kakada
Hi all, How can we know that one specific file is already exist in filesystem? for instance, I want to read zipfile by issuing code: import zipfile ziparchive = zipfile.ZipFile(inputfilename, "r") if the inputfilename doesn't exist then an error would be occurred. I want to catch up this special

Re: [Tutor] defined()

2006-04-03 Thread Tim Johnson
* Danny Yoo <[EMAIL PROTECTED]> [060403 18:14]: > > > > I'm interested in what use you would make of such a thing? > > My business partner is a perl programmer. He uses defined() a lot, I > > think, I've seen it in his code > > Now, if your business partner doesn't have the line 'use stri

Re: [Tutor] defined()

2006-04-03 Thread Tim Johnson
* Bob Gailer <[EMAIL PROTECTED]> [060403 17:12]: > > def defined(name): > return name in globals() > Hah! Good tip. I'll call it value() I think "language wars" are a waste of time, but I like the way that using different languages inform the programmer. cheers tj -- Tim Johnson <[

Re: [Tutor] defined()

2006-04-03 Thread Danny Yoo
> > I'm interested in what use you would make of such a thing? > My business partner is a perl programmer. He uses defined() a lot, I > think, I've seen it in his code Hello! The common idiom in Perl, I think, is to at least declare the variable, even if one doesn't give an initial value

Re: [Tutor] defined()

2006-04-03 Thread Tim Johnson
* Alan Gauld <[EMAIL PROTECTED]> [060403 09:10]: > > > I can't find the defined() function in python, so I used > >'variable name' in dir() > > > Is it really missing, or I am just so simple ? > > It is really missing, just as it is for most programming languages. > Which language(s) do you know

Re: [Tutor] defined()

2006-04-03 Thread Bob Gailer
Hugo González Monteverde wrote: > Alan Gauld wrote: > > >> Which language(s) do you know that has such a feature? >> And why do you consider it so useful that you expect to find >> it in Python? >> > > I'm not the original poster, but being a perlhead before, I can say it > exists in Perl.

Re: [Tutor] defined()

2006-04-03 Thread Hugo González Monteverde
Alan Gauld wrote: > Which language(s) do you know that has such a feature? > And why do you consider it so useful that you expect to find > it in Python? I'm not the original poster, but being a perlhead before, I can say it exists in Perl. It is very often used too. I used to miss it at first,

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread stv
> So don't write: > [adds.add_changes('foo', path) for path in filelist] > but: > for path in filelist: adds.add_changes('foo', path) Excellent point; new toy, got carrid away :) I feel silly on that one. And now that I've made the return list.extend(foo) mistake, I'll surely neve- ... er, wa

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Victor Bouffier
On Mon, 2006-04-03 at 11:39 -0700, Danny Yoo wrote: > > You can check if the dictionary key exists prior to assigning to it: > > > > >>> if not D.has_key('c'): > > ...D['c'] = {} > > >>> D['c']['a'] = 1 > > > Hi Victor, > > Another approach is to use the badly-named "setdefault()" method whi

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Alan Gauld
> On Wed, 2006-03-29 at 00:15 -0500, Michael Broe wrote: > You can check if the dictionary key exists prior to assigning to it: > if not D.has_key('c'): > ...D['c'] = {} D['c']['a'] = 1 And since 2.4? if 'c' in D: ... Alan G. ___ Tutor

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread Kent Johnson
stv wrote: > # return all changes, deletes first > return dels.extend(adds) > > Since extend returns None, I ran into a lot of not-iterable errors > when calling this code. So I fixed this with > > dels.extend(adds) > return dels > > And all is good, although it took way more head scratc

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Danny Yoo
> You can check if the dictionary key exists prior to assigning to it: > > >>> if not D.has_key('c'): > ...D['c'] = {} > >>> D['c']['a'] = 1 Hi Victor, Another approach is to use the badly-named "setdefault()" method which is a close analogue to Perl's "autovivification" feature: ## >>>

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Victor Bouffier
On Wed, 2006-03-29 at 00:15 -0500, Michael Broe wrote: > Aha! John wrote: > > "Are you sure you haven't mistakenly assigned something other than a > dict to D or D['d'] ?" > > Thanks for the tip! Yup that was it (and apologies for not reporting > the problem more precisely). I hadn't initiali

Re: [Tutor] oserror [errno 20]

2006-04-03 Thread Alan Gauld
"k r fry" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, I am new to this list, and also to Python. > I am trying to get Python to loop through the directory DATADIR which > contains the data I want to read. I get an error: "oserror [errno 20] > : Not a directory: "Katiescint

Re: [Tutor] defined()

2006-04-03 Thread Alan Gauld
> I can't find the defined() function in python, so I used >'variable name' in dir() > Is it really missing, or I am just so simple ? It is really missing, just as it is for most programming languages. Which language(s) do you know that has such a feature? And why do you consider it so useful th

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread Karl Pflästerer
On 3 Apr 2006, [EMAIL PROTECTED] wrote: > I had several list comprehensions that I was mucking with; these lists > are working on a simple subclass of the built-in list object. They > looked liked this: > > filelist = getFilesToAdd() > filelist2 = getFilesToDel() > > adds = MyList('foo') >

[Tutor] List methods/comps Best Practices

2006-04-03 Thread stv
I just thumped my head against the wall for a few hours on something, and I was wondering if it's just my green-ness in Python, or if I'm doing something unsavory. I had several list comprehensions that I was mucking with; these lists are working on a simple subclass of the built-in list object. T

Re: [Tutor] defined()

2006-04-03 Thread Tim Golden
[János Juhász] | I can't find the defined() function in python, so I used | | 'variable name' in dir() | | for check if the variable defined. | | >>> name = 'Joe' | >>> if 'name' in dir(): | ... print name | ... I'm not entirely sure where you'd want to use this,

[Tutor] defined()

2006-04-03 Thread János Juhász
Hi All, I can't find the defined() function in python, so I used         'variable name' in dir() for check if the variable defined. >>> name = 'Joe' >>> if 'name' in dir(): ...         print name ...         Joe Is it really missing, or I am just so simple ? Yours sincerely, __

Re: [Tutor] oserror [errno 20]

2006-04-03 Thread Ewald Ertl
Hi, k r fry wrote: > Hi, I am new to this list, and also to Python. > I am trying to get Python to loop through the directory DATADIR which > contains the data I want to read. I get an error: "oserror [errno 20] > : Not a directory: "Katiescint.py" > > The section of code is shown below: > >

[Tutor] oserror [errno 20]

2006-04-03 Thread k r fry
Hi, I am new to this list, and also to Python. I am trying to get Python to loop through the directory DATADIR which contains the data I want to read. I get an error: "oserror [errno 20] : Not a directory: "Katiescint.py" The section of code is shown below: for subdir in os.listdir(DATADIR):