Re: [Tutor] smtplib mail header problem

2005-12-07 Thread w chun
 It has been great for 11ish months, now all my mail is classed as
 spam  junked :(

dave,

i'm a little surprised by this.  if your code has been working for
almost a year and suddently breaks, that can only be explained by 1 or
2 things:

1. your code was modified
2. the server was modified

(or both).  things just don't all of a sudden break.  do you know what
changed in the system?


 Apparently the reason for it being junked is ...
 'No subject' and 'No Sender'
:
 from_ = 'Dave Selby[EMAIL PROTECTED]'

from just observing your From line, it looks like you need a space
between your name and the '' that begins the e-mail address.  i don't
think that without the space, it's a valid RFC2822 e-mail address.

i don't know if this is the entire problem, but it can't hurt to
remedy it and see if it helps.

good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Exceptions vs. Status Codes

2005-12-07 Thread Alan Gauld
 not have an answer.  Is it a better practice to have a function raise
 an exception on error, so that the error can be caught; or return a
 status code indicating that the function was unsuccessful?

Exceptions are nearly always better.
For some of the reasons why, see my tutorial topic on Error Handling

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Exceptions vs. Status Codes

2005-12-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 Hi,
 
 I have a general question regarding programming style which may or may
 not have an answer.  Is it a better practice to have a function raise
 an exception on error, so that the error can be caught; or return a
 status code indicating that the function was unsuccessful?

Hmm, this is a harder question than I thought :-)

My first response was to say, in general using exceptions to indicate
errors is more useful. But after a little reflection I realized that I
use status codes of a sort quite a bit as well.

Long ago and far away I programmed for Mac OS 9. This OS was meticulous
about returning status codes from every system call. Well-written client
code had to be equally meticulous about checking the codes and returning
them back to callers. As a result, any function that used the OS would
return an error code; actual return values would be returned by
reference in a parameter to the function. Client code ended up looking
like this:

int errno;
if (errno=doSomethingImportant() != noError)
   return errno;

int param;
if (errno=getParameter(param) != noError)
   return errno;

if (errno=doSomethingWithParam(param) != noError)
   return errno;

etc. As you can see, the code is dominated by the error handling, even
though all it does is return the error codes to the caller, it doesn't
actually handle any errors.

The same code written using exceptions would be stripped of all the
error handling code, like this:

doSomethingImportant();
int param = getParameter();
doSomethingWithParam(param);

This is *far* more readable and much easier to write.

Also consider the consequences of forgetting to check an error code.
Suppose that due to ignorance or lazinesss the first code had been
written like the second, ignoring the error codes. If an error does
occur, it won't be recognized until some secondary failure occurs; maybe
  doSomethingWithParam() will crash catastrophically because
doSomethingImportant() didn't suceed.

The second code doesn't have to do anything special to handle
exceptions; at some higher level in the code it can catch exceptions and
deal with them. If there is no exception handler an uncaught exception
will terminate the program with a stack trace showing the location of
the error.


On the other hand, when a function is returning a value and there is a
reasonable sentinal value for failure (such as None) and the caller
can't reasonably proceed without the returned value, I will sometimes
return None to signify failure instead of raising an exception.

For example, suppose our program needs to load a Foo resource that may 
be found in one of two places. We have functions getFooFromA() and 
getFooFromB() that return either a Foo or None. Client code is simple:

foo = getFooFromA()
if foo is None:
   foo = getFooFromB()
if foo is None:
   raise FooNotFoundError

If the getFooFromX() functions raised FooNotFoundError themselves, the 
client code would be

try:
   foo = getFooFromA()
except FooNotFoundError:
   foo = getFooFromB()

Hmm, not a very convincing example! Maybe I should be using exceptions 
more :-)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regular expressions

2005-12-07 Thread ps python
hi, 
 I am a new python learner. i am trying to parse a
file using regular expressions. 


LOCUS   NM_005417   4145 bpmRNA   
linear   PRI 04-DEC-2005
DEFINITION  Homo sapiens v-src sarcoma (Schmidt-Ruppin
A-2) viral oncogene
homolog (avian) (SRC), transcript variant
1, mRNA.
ACCESSION   NM_005417
VERSION NM_005417.3  GI:38202215

 CDS 450..2060
 /gene=SRC
 /EC_number=2.7.1.112
 /note=v-src avian sarcoma
(Schmidt-Ruppin A-2) viral
 oncogene homolog; protooncogene
SRC, Rous sarcoma;
 tyrosine-protein kinase SRC-1;
tyrosine kinase pp60c-src;
  go_component: ubiquitin ligase
complex [goid 151]
 [evidence NAS] [pmid 14976165];
 go_function: ATP binding [goid
0005524] [evidence IEA];
 go_function: nucleotide binding
[goid 166] [evidence
 IEA];
 go_function: protein binding
[goid 0005515] [evidence IPI]
 [pmid 15546919];
 go_function: protein binding
[goid 0005515] [evidence IPI]
 [pmid 15749833];
 go_function: transferase activity
[goid 0016740] [evidence
 IEA];
 go_function: SH3/SH2 adaptor
activity [goid 0005070]
 [evidence TAS] [pmid 9020193];
 go_function: protein-tyrosine
kinase activity [goid
 0004713] [evidence IEA];
 go_function: protein-tyrosine
kinase activity [goid
 0004713] [evidence TAS] [pmid
9020193];
 go_process: protein kinase
cascade [goid 0007243]
 [evidence TAS] [pmid 9020193];
 go_process: signal complex
formation [goid 0007172]
 [evidence TAS] [pmid 9924018];
 go_process: protein amino acid
phosphorylation [goid
 0006468] [evidence IEA]
 /codon_start=1
 /product=proto-oncogene
tyrosine-protein kinase SRC


I want to pullout LOCUS, go_process, go_function,
go_compartment into columns so that i can fill my
postgres tables. although i know well to some extenet
sql stuff, i am finding it difficult to get these
elements from this raw text. 

an idea that might have worked however, due to
incompetence it did not work. i seek help of this
forum. 


import re
f1  = open('this_raw_text','r')
dat = f1.readlines()
pat1 = re.compile('LOCUS')
pat2 = re.compile('go_component')
pat3 = re.compile('go_process')
pat4 = re.compile('go_function')


for line in dat:
 a = pat1.match(line)
 b = pat2.match(line)
 c = pat3.match(line)
 d = pat4.match(line)
 loc = a.group(1)
 comp =b.group(1)
 proc = c. group(1)
 func = d. group(1)
 print loc+'\t'+func
 print loc+'\t'+comp
 print loc+'\t'+func
 print loc+'\t'+proc
Traceback (most recent call last):
  File pyshell#12, line 6, in ?
loc = a.group(1)
IndexError: no such group


In the second attempt:
for line in dat:
 a = pat1.match(line)
 b = pat2.match(line)
 c = pat3.match(line)
 d = pat4.match(line)
 print a, b, c, d

 
_sre.SRE_Match object at 0x00D53330 None None None

rest all lines are NONE. However, b,c,d are there in
the file. 


I do not know if this is the correct procedure. 

Can any one help me please.

thanks a  lot. 
M



__ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cas and python

2005-12-07 Thread Cedric BRINER
hi,

does one of you knows if there is a python module which implements CAS(Central 
Authentication Service):
https://clearinghouse.ja-sig.org/wiki/display/CAS/Home

thanks in advance

Ced.
-- 

Cedric BRINER
Geneva - Switzerland
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read XML

2005-12-07 Thread Joseph Quigley
Joseph Quigley wrote: How do I read xml? The python documentation doesn't help me.
 Or, how can I remove the (tags?) stuff in these things?If you want to strip out all the tags and just leave the text,Strip-o-Gram might do it.
http://www.zope.org/Members/chrisw/StripOGramThere was a thread here recently about other tools for stripping textout of HTML but I can't find it.Kent

Thanks. This looks like it will do the trick.
-- There are 10 different types of people in the world.Those who understand binary and those who don't.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] to process data from several dictionaries

2005-12-07 Thread Andrzej Kolinski

Let's forget for the time being my previous
topic (files - strings - lists). As a result of (not only) my efforts I
arrived to the point that I have data I need but I do not know how to process
them. Form each (game) file a dictionary is created containing player names
(key) and the scores + boards played (tuple), ex.:
from file 1 -
{'Chrabalowski': [(21.0, 24)], 'Stankiewicz': [(-28.0, 24)], ... more ...}
from file 2 -
{'Chrabalowski': [(45.0, 25)], 'Orlicka':
[(-27.0, 25)], ... more ...}
from file 3 -
{'Chrabalowski': [(-23.0, 25)], 'Stankiewicz':
[(20.0, 25)], ... more ...}, etc.

Eventually I will have 10 files to process.
I need help how to calculate a final ranking for each player using individual
data. Many names will be repeated but there will be some that appear only
once or twice. So for Chrabalowski we'll have:

   
   (21.0 + 45.0 - 23.0)/(24 + 25 + 25),
and for Stankiewicz:

   
   (- 28.0 + 20.0)/(24 + 25)

I have no clue how to do it. Maybe dictionaries
are not good for that, maybe I should be using lists of lists? Please help.

_/_/   _/   _/
  _/_/ _/  _/
 _/_/_/_/ _/ _/
 _/   _/ _/  _/
_/   _/ _/   _/

Andrzej Kolinski___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] to process data from several dictionaries

2005-12-07 Thread Kent Johnson
Andrzej Kolinski wrote:
 
 Let's forget for the time being my previous topic (files - strings - 
 lists). As a result of (not only) my efforts I arrived to the point that 
 I have data I need but I do not know how to process them. Form each 
 (game) file a dictionary is created containing player names (key) and 
 the scores + boards played (tuple), ex.:
 from file 1 -
 {'Chrabalowski': [(21.0, 24)], 'Stankiewicz': [(-28.0, 24)], ... more ...}
 from file 2 -
 {'Chrabalowski': [(45.0, 25)], 'Orlicka': [(-27.0, 25)], ... more ...}
 from file 3 -
 {'Chrabalowski': [(-23.0, 25)], 'Stankiewicz': [(20.0, 25)], ... more 
 ...}, etc.
 
 Eventually I will have 10 files to process. I need help how to calculate 
 a final ranking for each player using  individual data. Many names will 
 be repeated but there will be some that appear only once or twice. So 
 for Chrabalowski we'll have:
 (21.0 + 45.0 - 23.0)/(24 + 25 + 25),
 and for Stankiewicz:
 (- 28.0 + 20.0)/(24 + 25)

I think you would be better off creating a single dictionary whose keys 
are the player names and values are a list of tuples of game data. In 
your example the dict would be

{'Chrabalowski': [(21.0, 24),(45.0, 25),(-23.0, 25)], 'Stankiewicz': 
[(-28.0, 24)(20.0, 25)], 'Orlicka': [(-27.0, 25)], ... more ...}

Then it will be much simpler to process each player because all his data 
will be in one place.

There is a compact idiom for creating a dict where the values are 
accumulated in lists. Imagine you have a dict, key and value d, k, v and 
you want to append v to the list associated with k. A simple approach 
might be something like this:
lst = d.get(k)
if lst is None:
   lst = []
   d[k] = lst
lst.append(v)

Note there is no need to assign d[k] = lst in the case where d[k] is 
already defined, because the list returned by get() is still in the dict 
and will be modified by the append(). (See the recent thread How to 
Pass lists by value if you don't understand this part.)

dicts actually have a (confusingly named) method which already does most 
of the above - dict.setdefault(). Using setdefault() the above code can 
be written as
lst = d.setdefault(k, [])
lst.append(v)

or even simpler:
d.setdefault(k, []).append(v)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expressions

2005-12-07 Thread ps python
sorry for repost. awaiting to hear from some members. 
a scientist suggested me to try biopython. This point
is not just with genbank sequences. what will i do if
i have to parse a paragraph for some expression. 
thanks again. 




hi, 
 I am a new python learner. i am trying to parse a
file using regular expressions. 


LOCUS   NM_005417   4145 bpmRNA   
linear   PRI 04-DEC-2005
DEFINITION  Homo sapiens v-src sarcoma (Schmidt-Ruppin
A-2) viral oncogene
homolog (avian) (SRC), transcript variant
1, mRNA.
ACCESSION   NM_005417
VERSION NM_005417.3  GI:38202215

 CDS 450..2060
 /gene=SRC
 /EC_number=2.7.1.112
 /note=v-src avian sarcoma
(Schmidt-Ruppin A-2) viral
 oncogene homolog; protooncogene
SRC, Rous sarcoma;
 tyrosine-protein kinase SRC-1;
tyrosine kinase pp60c-src;
  go_component: ubiquitin ligase
complex [goid 151]
 [evidence NAS] [pmid 14976165];
 go_function: ATP binding [goid
0005524] [evidence IEA];
 go_function: nucleotide binding
[goid 166] [evidence
 IEA];
 go_function: protein binding
[goid 0005515] [evidence IPI]
 [pmid 15546919];
 go_function: protein binding
[goid 0005515] [evidence IPI]
 [pmid 15749833];
 go_function: transferase activity
[goid 0016740] [evidence
 IEA];
 go_function: SH3/SH2 adaptor
activity [goid 0005070]
 [evidence TAS] [pmid 9020193];
 go_function: protein-tyrosine
kinase activity [goid
 0004713] [evidence IEA];
 go_function: protein-tyrosine
kinase activity [goid
 0004713] [evidence TAS] [pmid
9020193];
 go_process: protein kinase
cascade [goid 0007243]
 [evidence TAS] [pmid 9020193];
 go_process: signal complex
formation [goid 0007172]
 [evidence TAS] [pmid 9924018];
 go_process: protein amino acid
phosphorylation [goid
 0006468] [evidence IEA]
 /codon_start=1
 /product=proto-oncogene
tyrosine-protein kinase SRC


I want to pullout LOCUS, go_process, go_function,
go_compartment into columns so that i can fill my
postgres tables. although i know well to some extenet
sql stuff, i am finding it difficult to get these
elements from this raw text. 

an idea that might have worked however, due to
incompetence it did not work. i seek help of this
forum. 


import re
f1  = open('this_raw_text','r')
dat = f1.readlines()
pat1 = re.compile('LOCUS')
pat2 = re.compile('go_component')
pat3 = re.compile('go_process')
pat4 = re.compile('go_function')


for line in dat:
 a = pat1.match(line)
 b = pat2.match(line)
 c = pat3.match(line)
 d = pat4.match(line)
 loc = a.group(1)
 comp =b.group(1)
 proc = c. group(1)
 func = d. group(1)
 print loc+'\t'+func
 print loc+'\t'+comp
 print loc+'\t'+func
 print loc+'\t'+proc
Traceback (most recent call last):
  File pyshell#12, line 6, in ?
loc = a.group(1)
IndexError: no such group


In the second attempt:
for line in dat:
 a = pat1.match(line)
 b = pat2.match(line)
 c = pat3.match(line)
 d = pat4.match(line)
 print a, b, c, d

 
_sre.SRE_Match object at 0x00D53330 None None None

rest all lines are NONE. However, b,c,d are there in
the file. 


I do not know if this is the correct procedure. 

Can any one help me please.

thanks a  lot. 
M



 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expressions

2005-12-07 Thread Danny Yoo


On Wed, 7 Dec 2005, ps python wrote:

  I am a new python learner. i am trying to parse a file using regular
 expressions.


Hello,

Just as an aside: parsing Genbank flat files like this is not such a good
idea, because you can get the Genbank XML files instead.  For example,
your locus NM_005417 has a perfectly good XML representation (using the
GBSeq XML format):

http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=nucleotideqty=1c_start=1list_uids=38202215dopt=gbxdispmax=5sendto=

This format contains the same content as the human-readable text report,
but structured in a way that makes it easier to extract elements if we use
an XML parser like ElementTree.

http://effbot.org/zone/element-index.htm


And even if that weren't avaliable, we might also consider using the
parsers that come with the BioPython project:

http://www2.warwick.ac.uk/fac/sci/moac/currentstudents/peter_cock/python/genbank/
http://www.biopython.org/docs/tutorial/Tutorial004.html#toc13

I guess I'm trying to say: you might not want to reinvent the wheel:
it's been done several times already.  *grin*



If you're doing this to learn regular expressions, that's fine too.  Just
be aware that those other modules are out there.

Let's look at the code.


 for line in dat:
  a = pat1.match(line)
  b = pat2.match(line)
  c = pat3.match(line)
  d = pat4.match(line)

Use the search() method, not the match() method.  match() always assumes
that the match must start at the very beginning of the line, and it'll
miss things if your pattern is in the middle somewhere.

There's a discussion about this in the Regex HOWTO:

http://www.amk.ca/python/howto/regex/
http://www.amk.ca/python/howto/regex/regex.html#SECTION00072



If you have more questions, please feel free to ask.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-12-07 Thread Brian van den Broek
david said unto the world upon 2005-12-03 20:36:
 hello again. i think my dig function is working correctly now.
 any input on how to save and restore all the rooms and descriptions?
 thanks for helping.

Hi David,

I'm catching up on mail backlog, so I'm a bit late, but I've a 
suggestion or two about other aspects of your code.

 class Room:
 def __init__(self,coords):

# sniped code

 def nextdoor(self,direction):
 if direction == 'n':
 nextdoor =  (self.coords[0], self.coords[1] + 1)
 return list(nextdoor)
 elif direction == 's':
 nextdoor =  list((self.coords[0], self.coords[1] - 1))
 return nextdoor
 elif direction == 'e':
 nextdoor =  list((self.coords[0] +1, self.coords[1]))
 return nextdoor
 elif direction == 'w':
 nextdoor =  (self.coords[0] -1, self.coords[1])
 return list(nextdoor)


This looks a bit ugly to me :-)

First, I think it's a bad thing that some of your if clauses convert 
the value to a list in the nextdoor assignment, and others in the 
return. It is easier to grok what is going on if the like operations 
are effected in the same way.

Further, why not just

return list((self.coords[0], self.coords[1] - 1))

and so forth, dispensing with the nextdoor assignment? (I get that the 
name has documentation value, but I think it'd be better to do without 
and put the documentation in a docstring.)

If that is changed, then all four clauses are almost identical. That 
is often a sign that there is a better way. I'd suggest:

def nextdoor(self,direction):
 '''direction - list of co-ordinates for next location

 (Perhaps more description here.)
 '''
 xy_difs = {'n':(0, 1), 's':(0, -1), 'e':(1, 0), 'w':(-1, 0)}
 x_dif, y_dif = xy_difs[direction]
 return list(self.coords[0] + x_dif, self.coords[1] + y_dif)


Once you get used to it, this style is often easier to understand 
quickly than is a list of if tests. Perhaps best of all, this way 
makes it much easier to add other directions like 'nw'.


Likewise, where you have:

 def opdir(direction):
 if direction == 'n':
 return 's'
 if direction == 's':
 return 'n'
 if direction == 'e':
 return 'w'
 if direction == 'w':
 return 'e'

I'd suggest

def opdir(direction):
 return {'n':'s', 's':'n', 'e':'w', 'w':'e'}[direction]

Since that has dropped it down to a single line, it might even be 
better to dispense with the function entirely. But, I'd likely leave 
it, as the function provides a good place to document just what the 
point of the code is.

A further advantage with what I've given over yours is what occurs if 
an unexpected value is passed to opdir(). Your version will return 
None (i.e. fail silently). Mine will raise an exception immediately.

  {'n':'s', 's':'n', 'e':'w', 'w':'e'}['bad']

Traceback (most recent call last):
   File pyshell#6, line 1, in -toplevel-
 {'n':'s', 's':'n', 'e':'w', 'w':'e'}['bad']
KeyError: 'bad'
 

It often helps track down bugs if you try to arrange things so that 
the problem surfaces as soon as possible.

HTH,

Brian vdB

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cas and python

2005-12-07 Thread Danny Yoo


On Wed, 7 Dec 2005, Cedric BRINER wrote:

 does one of you knows if there is a python module which implements
 CAS(Central Authentication Service):
 https://clearinghouse.ja-sig.org/wiki/display/CAS/Home

Hi Cedric,

Not certain, but most likely.  See:

http://www.zope.org/Members/mrlex/ACUF

which appears to be an implementation of a CAS client for Zope.  It might
be possible to extract their CAS client out of that package.


The protocol's documentation in:

https://clearinghouse.ja-sig.org/wiki/display/CAS/CAS+2.0+Architecture

also looks fairly straightforward, at least at a casual glance.  *grin*

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expressions

2005-12-07 Thread Danny Yoo


On Wed, 7 Dec 2005, ps python wrote:

 sorry for repost. awaiting to hear from some members.  a scientist
 suggested me to try biopython. This point is not just with genbank
 sequences. what will i do if i have to parse a paragraph for some
 expression.  thanks again.

Hello,

I just want to clarify: we're a volunteer group, so getting answers within
two hours is not a guarantee, nor should that level of response be
expected.

We'll do what we can to help, but some answers take some careful
consideration and research.  We don't want to spit out the first thing
that comes into our heads; otherwise, that could encourage some rude
responses like RTFW, and that would be a terrible way to mess the
atmosphere here.

The page How to Ask Questions the Smart Way talks about this in less
diplomatic language:

http://www.catb.org/~esr/faqs/smart-questions.html#urgent

But the idea is: we see your question.  At least one of us here on Tutor
will reply when we have the time to contribute.  If no one responds in
some time, we'll say that we don't think we can help you, but we'll try to
point you to people who can.

Just try not hurry people to answer your questions here.  Some of us have
day jobs, and others haven't gotten out of their classrooms yet!  *grin*


Good luck to you.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expressions

2005-12-07 Thread Alan Gauld
 a scientist suggested me to try biopython. This point
 is not just with genbank sequences. what will i do if
 i have to parse a paragraph for some expression. 

One thing to watch is that re.match() only checks if the pattern 
is at the beginning of the line. You should maybe consider using 
re.search()?

But I haven't looked in detail so that nay be way off beam...

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] file permissions

2005-12-07 Thread Eric Walker
Looking for easiest way to get a files permissions in linux.

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file permissions

2005-12-07 Thread Danny Yoo


On Wed, 7 Dec 2005, Eric Walker wrote:

 Looking for easiest way to get a files permissions in linux.

Hi Eric,

What have you looked at so far?

One of the first hits to the Google query file permission python  comes
up with some good information:

http://www.faqts.com/knowledge_base/view.phtml/aid/5707/fid/552

Forgive me: I'm giving you a hard time only because it didn't look like
you did anything yourself yet.  Next time you ask a question, also try to
show what you've tried so far to find an answer, so that we know we're not
following avenues that you've already pursued.

We want to make sure you know how to look for answers.  If the existing
documentation sucks (and some of Python's documentation does need more
work!), then we want to know that too so that we can help improve it by
sending comments to the Documentation team.


In summary, there's file permission stuff we can extract using the
'stat()' function in the 'os' module:

http://www.python.org/doc/lib/os-file-dir.html#l2h-1629

The values we get back from os.stat() are a little obscure, but we can
interpret the results using the 'stat' module:

http://www.python.org/doc/lib/module-stat.html

I'm not sure if there's nicer interface to the permission bits; most
material I see on it looks fairly low-level.


If you have more questions, please feel free to ask.  (But please show
what work you've tried so far; that way, we have a better idea of your
context.)  Good luck!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Run script automatically in IDLE shell

2005-12-07 Thread Yann Le Du
Hello,

I'd like to have some scripts run directly inside the IDLE shell when I 
double click on some properly built shortcut, and not inside the DOS 
window. I've managed to do that under win98, but failed in win2000 and 
winXP.

I dont' want to have to run module inside the idle editor, just direct 
execution when double clicking on some shortcut.

In win98 my shortcut is :

C:\Python22\pythonw.exe C:\PYTHON24\Tools\idle\idle.py prog.py

and this opens an IDLE shell window in which my script is executed.

Anyone knows how to do that in win2000 and winXP, with python24 ?

P.S. I do all this to have accentuated characters (French) correctly 
displayed, and this is done in the IDLE Shell, but fails inside the DOS 
window. So this is why I want to have my scripts run directly inside the 
IDLE shell...

--
Yann Le Du
http://yledu.free.fr
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file permissions

2005-12-07 Thread Gabriel Farrell
On Wed, Dec 07, 2005 at 11:52:20AM -0800, Danny Yoo wrote:
 On Wed, 7 Dec 2005, Eric Walker wrote:
 
  Looking for easiest way to get a files permissions in linux.
 
 Hi Eric,
 
 What have you looked at so far?

I agree with Danny, the question lacks any evidence of prior
investigation on the part of the poster, and that makes it a lousy
candidate for the helpful guidance of the python tutor list.  The
documentation on this aspect of python, however, is pretty sparse, and
the answer's not exactly intuitive, so I thought I'd mention the
effbot's page about the os module as a good place to look, in addition
to the documentation Danny listed.

http://effbot.org/librarybook/os.htm

What he's written there should be able to answer your question.

If I may hijack the thread, does anyone more knowledgeable than me
know why os.stat and stat are so low-level and esoteric?  Am I crazy
for wanting to replace

oct(stat.S_IMODE(os.stat(thefile)[stat.ST_MODE]))

with, say,

stat.getmode(os.stat(thefile))

or even

os.getmode(thefile)

?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file permissions

2005-12-07 Thread Eric Walker
Sorry for the bad question.
I did google and found the same pages that Danny mentioned. Just couldn't get 
the stuff to work, or understand what modules needed to be imported to get 
them to work. I typically use the tutor list as a last resort. After 4+ hours 
of playing around with this I made the futile post.





On Wednesday 07 December 2005 01:42 pm, Gabriel Farrell wrote:
 On Wed, Dec 07, 2005 at 11:52:20AM -0800, Danny Yoo wrote:
  On Wed, 7 Dec 2005, Eric Walker wrote:
   Looking for easiest way to get a files permissions in linux.
 
  Hi Eric,
 
  What have you looked at so far?

 I agree with Danny, the question lacks any evidence of prior
 investigation on the part of the poster, and that makes it a lousy
 candidate for the helpful guidance of the python tutor list.  The
 documentation on this aspect of python, however, is pretty sparse, and
 the answer's not exactly intuitive, so I thought I'd mention the
 effbot's page about the os module as a good place to look, in addition
 to the documentation Danny listed.

   http://effbot.org/librarybook/os.htm

 What he's written there should be able to answer your question.

 If I may hijack the thread, does anyone more knowledgeable than me
 know why os.stat and stat are so low-level and esoteric?  Am I crazy
 for wanting to replace

   oct(stat.S_IMODE(os.stat(thefile)[stat.ST_MODE]))

 with, say,

   stat.getmode(os.stat(thefile))

 or even

   os.getmode(thefile)

 ?
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

-- 
Eric Walker
EDA/CAD Engineer
Work: 208-368-2573
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file permissions

2005-12-07 Thread Gabriel Farrell
On Wed, Dec 07, 2005 at 02:51:55PM -0700, Eric Walker wrote:
 After 4+ hours 
 of playing around with this I made the futile post.

Don't let the post be futile!  Post what you've tried so far and
you'll get help.

gsf
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib mail header problem

2005-12-07 Thread dave s
On Tuesday 06 December 2005 22:23, Liam Clarke-Hutchinson wrote:
 Okay, just checked the docs -

 sendmail( from_addr, to_addrs, msg[, mail_options, rcpt_options])

 Note: The from_addr and to_addrs parameters are used to construct the
 message envelope used by the transport agents. The SMTP does not modify the
 message headers in any way.

 So my guess is that the spam agent is checking that from_addr, and getting
 an invalid email address and spitting the dummy.
 Most ISPs won't allow an invalid from_addr, although mine does..

 Regards,

 Liam Clarke-Hutchinson


Thanks for that I 'pydoc smtplib' but got somewhat confused :)

Dave
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file permissions

2005-12-07 Thread Alan Gauld

 Looking for easiest way to get a files permissions in linux.
 

look at the os.stat function.

I'm in the middle of documenting its use but you might like to 
peruse the later sections of the following draft topic

http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Run script automatically in IDLE shell

2005-12-07 Thread Alan Gauld

The IDLE documentation (run idle -h) says that 

idle -r file.py 

runs the commands in the file.
Is that what you are doing? It looks different to your Win98 version.

 P.S. I do all this to have accentuated characters (French) correctly 
 displayed, and this is done in the IDLE Shell, but fails inside the DOS 
 window. So this is why I want to have my scripts run directly inside the 
 IDLE shell...

Do you have the correct language and locale settings set up in your 
DOS environment? It should be able to display French characters 
(and any other Western alphabet - not sure about unicode stuff though)
just fine.

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] My First Program

2005-12-07 Thread Trent Rigsbee
Hi! My first ever program that I've created is a simple game called State 
Capitals. It's straight forward; 5 simple questions about state capitals in 
a non-GUI format. Can someone look over my code and offer tips, suggestions, 
criticism? Also, I'd like to be able to end the program if the user misses 3 
questions (i.e., kick them out after the 3rd wrong answer). How can I do 
this? Thanks!


print \nState Capitals! Answer a or b to the following questions.\n
question = raw_input(Question 1 - What is the capital of NC, a: Raleigh or 
b: Atlanta? )
if question == a:
print Yes\n
else:
print WRONG\n

question = raw_input(Question 2 - What is the capital of SC, a: Greenville 
or b: Columbia? )
if question == b:
print Yes\n
else:
print WRONG\n

question = raw_input(Question 3 - What is the capital of NY, a: Albany or 
b: Buffalo?)
if question == a:
print Yes\n
else:
print WRONG\n

question = raw_input(Question 4 - What is the capital of OH, a: Cleveland 
or b: Columbus? )
if question == b:
print Yes\n
else:
print WRONG\n

question = raw_input(Question 5 - What is the capital of TX, a: Houston or 
b: Austin? )
if question == b:
print Yes\n
else:
print WRONG\n


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Escaping double quotes

2005-12-07 Thread Tim Johnson
* Tim Johnson [EMAIL PROTECTED] [051207 15:56]:
 I must be having a Senior Moment here, but the following
 baffles me:
  label = 'this is quoted'
  label.replace('','\')
 'this is quoted'
 ## This works
  label.replace('','\'')
 this is 'quoted'
 
  blush
  What I should have been using is
  label.replace('','\\')
  :-) Nevermind.
  tj
  
 What am I missing here?
 thanks
 tim
 
 -- 
 Tim Johnson [EMAIL PROTECTED]
   http://www.alaska-internet-solutions.com

-- 
Tim Johnson [EMAIL PROTECTED]
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Escaping double quotes

2005-12-07 Thread Tim Johnson
I must be having a Senior Moment here, but the following
baffles me:
 label = 'this is quoted'
 label.replace('','\')
'this is quoted'
## This works
 label.replace('','\'')
this is 'quoted'

What am I missing here?
thanks
tim

-- 
Tim Johnson [EMAIL PROTECTED]
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor