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):
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:
>
>
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,
__
[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,
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
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')
>
> 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
"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
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
> 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:
##
>>>
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
> 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
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
> 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
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,
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.
* 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
> > 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
* 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 <[
* 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
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
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!'
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.
* 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
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
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
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
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
28 matches
Mail list logo