Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread spir
Le Wed, 18 Feb 2009 22:01:34 -0500,
Kent Johnson  s'exprima ainsi:

> Hmm. I guess this is Python 3? In 2.6, open is a function and trying
> to subclass it gives an error:
> 
> In [10]: open
> Out[10]: 
> 
> In [11]: class myopen(open): pass
> 
>:
> 
> TypeError: Error when calling the metaclass bases
> cannot create 'builtin_function_or_method' instances

But... why not use the proper type instead:

class F(file):
def __init__(self, file_name):
self.file_name = file_name
f = F("/home/prog/io/test.py")
print dir(f)
print isinstance(f,types.FileType)
==>
['__class__', '__delattr__', '__dict__', '__doc__', '__enter__', '__exit__', 
'__getattribute__', '__hash__', '__init__', '__iter__', '__module__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'close', 'closed', 'encoding', 'file_name', 'fileno', 'flush', 'isatty', 
'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 
'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 
'xreadlines']
True

Then, overload the proper method the call of which you need to catch. Or there 
is a "detail" I do not "catch" ;-)

Denis
--
la vita e estrany
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Oxymoron
Thanks for the answers everyone.

Denis, I wish to wrap an already open file handle basically, so simply
extending and overriding doesn't help - my proxy won't be instantiated
like a file, just used like one and if not intercepting I need to
delegate down to the proxied "real" handle. If I'm missing something,
please let me know. Here's the actual scenario:

1. The script is called within a CGI environment, so I get sys.stdin
which I wish to wrap
2. On calls to read, I wish to perform certain actions (I am not the
one doing the reading - I pass my proxy to the reader process - very
trojan horse like), but the read is still done by the sys.stdin
object.

So far I've gone with Kent's suggestion, I have been a bit lazy and
did not look up new-style classes, got it working with the old-style
get attr, like so:

class FileProxy:
def __init__(self, wrappedfp, readhook):
"""wrappedfp is the fp we delegate down to, readhook is a
callable(proxy) which is called
on read operations"""
self.fp = wrappedfp
self.readhook = readhook
self.bytecount = 0

def __getattr__(self, attrib):
return getattr(self.fp, attrib)

def read(self, size=-1):
d = self.fp.read(size)
self.readhook(self)
return d

def readline(self, size=-1):
d = self.fp.readline(size)
self.readhook(self)
return d

It seems to do what I want. I suppose extending from the actual type
is 'safer' in that code that relies on it being a subtype won't
break... hmm, fairly narrow scenario I have here though :-).

Thanks.

-- Kamal

On Thu, Feb 19, 2009 at 7:56 PM, spir  wrote:
>
> But... why not use the proper type instead:
>
> class F(file):
>def __init__(self, file_name):
>self.file_name = file_name
> f = F("/home/prog/io/test.py")
> print dir(f)
> print isinstance(f,types.FileType)
> ==>
> ['__class__', '__delattr__', '__dict__', '__doc__', '__enter__', '__exit__', 
> '__getattribute__', '__hash__', '__init__', '__iter__', '__module__', 
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
> '__str__', 'close', 'closed', 'encoding', 'file_name', 'fileno', 'flush', 
> 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 
> 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 
> 'xreadlines']
> True
>
> Then, overload the proper method the call of which you need to catch. Or 
> there is a "detail" I do not "catch" ;-)
>
> Denis
> --
> la vita e estrany
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] extracting a column from many files

2009-02-19 Thread Bala subramanian
Dear friends,

I want to extract certain 6 different columns from a many files and write it
to 6 separate output files. I took some help from the following link

http://mail.python.org/pipermail/tutor/2004-November/033475.html

to write one column from many input files to a particular output file. Since
i have to extract 6 such columns, i wanted to loop the output file writing
part. This block of the script is shown in bold below. I see some odd output
file names.  Kindly suggest me i ) how best or should i do this loop part
ii) explanation of the working *row=map(None,*value) *below which i adopted
from the above tutor-mail list link.

Thanks in advance,
Bala

 #!/usr/bin/env python
from sys import argv
lst_files=argv[1:]

sh=[];st=[];sta=[];buc=[];pro=[];ope=[]

def extract(fname)*:*
A=[];B=[];C=[];D=[];E=[];F=[]
data=open(fname).readlines()
for number, line in enumerate(data):
if "  Duplex" and " Shear" in line:
number=number+3
for x in range(0,8):
new=data[number]
A.append(new[19:26])
B.append(new[27:34])
C.append(new[37:42])
D.append(new[44:54])
E.append(new[56:63])
F.append(new[69:75])
number = number + 1
sh.append(A)
st.append(B)
sta.append(C)
buc.append(D)
pro.append(E)
ope.append(F)

for x in lst_files:
  extract(x)

*list=[sh,st,sta,buc,pro,ope]*
*for value in list:*
*row=map(None,*value)*
*out=open(str(value) + '.txt','w')
for num in row:
  out.write('\t'.join(num))
  out.write('\n')
out.close()*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Lie Ryan
On Thu, 19 Feb 2009 20:12:57 +1100, Oxymoron wrote:

> Thanks for the answers everyone.
> 
> Denis, I wish to wrap an already open file handle basically, so simply
> extending and overriding doesn't help - my proxy won't be instantiated
> like a file, just used like one and if not intercepting I need to
> delegate down to the proxied "real" handle. If I'm missing something,
> please let me know. Here's the actual scenario:
> 

If you replace sys.stdin with your own file object, you don't need to 
define all of the file object interface, just the one that generates an 
error if not defined (i.e. the ones that you use).

Alternatively, you may also consider using subprocess.

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


Re: [Tutor] extracting a column from many files

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 5:41 AM, Bala subramanian
 wrote:
> Dear friends,
>
> I want to extract certain 6 different columns from a many files and write it
> to 6 separate output files. I took some help from the following link
>
> http://mail.python.org/pipermail/tutor/2004-November/033475.html
>
> to write one column from many input files to a particular output file. Since
> i have to extract 6 such columns, i wanted to loop the output file writing
> part.

Do you want the resulting files to have a single column, or one column
per input file? The mail you cite has one column per file.

> This block of the script is shown in bold below. I see some odd output
> file names.

You are using the string representation of the values as the file
name! What do you want to call the files?

>  Kindly suggest me i ) how best or should i do this loop part
> ii) explanation of the working row=map(None,*value) below which i adopted
> from the above tutor-mail list link.

Please clarify what you want to do first.
Kent

>
> Thanks in advance,
> Bala
>
>  #!/usr/bin/env python
> from sys import argv
> lst_files=argv[1:]
>
> sh=[];st=[];sta=[];buc=[];pro=[];ope=[]
>
> def extract(fname):
> A=[];B=[];C=[];D=[];E=[];F=[]
> data=open(fname).readlines()
> for number, line in enumerate(data):
> if "  Duplex" and " Shear" in line:
> number=number+3
> for x in range(0,8):
> new=data[number]
> A.append(new[19:26])
> B.append(new[27:34])
> C.append(new[37:42])
> D.append(new[44:54])
> E.append(new[56:63])
> F.append(new[69:75])
> number = number + 1
> sh.append(A)
> st.append(B)
> sta.append(C)
> buc.append(D)
> pro.append(E)
> ope.append(F)
>
> for x in lst_files:
>   extract(x)
>
> list=[sh,st,sta,buc,pro,ope]
> for value in list:
> row=map(None,*value)
> out=open(str(value) + '.txt','w')
> for num in row:
>   out.write('\t'.join(num))
>   out.write('\n')
> out.close()
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 6:03 AM, Lie Ryan  wrote:

> If you replace sys.stdin with your own file object, you don't need to
> define all of the file object interface, just the one that generates an
> error if not defined (i.e. the ones that you use).

Yes, probably just defining read() and readline() are enough, you
might be able to leave __getattr__() out of your wrapper class.

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


Re: [Tutor] extracting a column from many files

2009-02-19 Thread Bala subramanian
Hi,

I have to extract say column 1, column 2 . column 6 (six different
columns) from 10 different input files. The function "extract" to extract
the columns works fine. For each column  extracted from the input files, i
have to write it in one output file. I have to make 6 output files
correspondingly. How should i loop the writing of output files.

Also, you had suggested previously the following way of creating list of row
lists from the list of column lists

rows = map(None, *listOfColumns)

I am not getting how this works.

Thanks,
Bala

On Thu, Feb 19, 2009 at 12:38 PM, Kent Johnson  wrote:

> On Thu, Feb 19, 2009 at 5:41 AM, Bala subramanian
>  wrote:
> > Dear friends,
> >
> > I want to extract certain 6 different columns from a many files and write
> it
> > to 6 separate output files. I took some help from the following link
> >
> > http://mail.python.org/pipermail/tutor/2004-November/033475.html
> >
> > to write one column from many input files to a particular output file.
> Since
> > i have to extract 6 such columns, i wanted to loop the output file
> writing
> > part.
>
> Do you want the resulting files to have a single column, or one column
> per input file? The mail you cite has one column per file.
>
> > This block of the script is shown in bold below. I see some odd output
> > file names.
>
> You are using the string representation of the values as the file
> name! What do you want to call the files?
>
> >  Kindly suggest me i ) how best or should i do this loop part
> > ii) explanation of the working row=map(None,*value) below which i adopted
> > from the above tutor-mail list link.
>
> Please clarify what you want to do first.
> Kent
>
> >
> > Thanks in advance,
> > Bala
> >
> >  #!/usr/bin/env python
> > from sys import argv
> > lst_files=argv[1:]
> >
> > sh=[];st=[];sta=[];buc=[];pro=[];ope=[]
> >
> > def extract(fname):
> > A=[];B=[];C=[];D=[];E=[];F=[]
> > data=open(fname).readlines()
> > for number, line in enumerate(data):
> > if "  Duplex" and " Shear" in line:
> > number=number+3
> > for x in range(0,8):
> > new=data[number]
> > A.append(new[19:26])
> > B.append(new[27:34])
> > C.append(new[37:42])
> > D.append(new[44:54])
> > E.append(new[56:63])
> > F.append(new[69:75])
> > number = number + 1
> > sh.append(A)
> > st.append(B)
> > sta.append(C)
> > buc.append(D)
> > pro.append(E)
> > ope.append(F)
> >
> > for x in lst_files:
> >   extract(x)
> >
> > list=[sh,st,sta,buc,pro,ope]
> > for value in list:
> > row=map(None,*value)
> > out=open(str(value) + '.txt','w')
> > for num in row:
> >   out.write('\t'.join(num))
> >   out.write('\n')
> > out.close()
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Wayne Watson
Title: Signature.html




Hi, actually I had two aims with the pseudo code, 1. print it, and 2.
check to see if it would pull in the two modules. I pulled it into
Word, and quickly formatted it to get the line wrap out, and put it in
some sort of readable format. After that, I thought why not just take
it as it was, and scoop it into IDLE.  My plan was to right a test
program to get a better understanding of how to use ConfigObj rather
than just try it through the program I plan to use it in. 

I've tried to keep to IDLE for no reason other than the author
recommended it. Well, OK, I had gotten comfortable with the editor. 
I'll try wxPython.

I took a quick look look at where Python was installed and found it was
directly under C:, and not under Program Files. That's a surprise. Now
I recall where I found something about classes and paths. It's on the
File menu of IDLE, Class Browser and Path Browser. 

I thought, in the last post, I asked about items like: show_real_time =
boolean(default=False) and hourly_rate = integer(min=0, default=0);
but, apparently, I accidentally knocked it out.  Anyway, here's the
question.  Where is the syntax for items like boolean,  integer, and
others described?  The doc I have barely refers to them. 

Off to find wx...

Marc Tompkins wrote:

  On Wed, Feb 18, 2009 at 7:42 PM, Wayne
Watson 
wrote:
  
I took your "starter" code,
and formatted it to be what I hope is an
acceptable program, Gobal_Config.py. See attached.  I'm using Python
2.5.2. I put the two modules in the same folder with it, and executed
it in IDLE. I got this:
  ...
  File
"C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py",
line 1637, in _parse
    ParseError, infile, cur_index)
  File
"C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py",
line 1748, in _handle_error
    raise error
ParseError: Invalid line at line "1".

As far as I can tell, line 1 of config.obj looks OK. It's a comment.
Something is amiss.

  
  
I hate to say it, but IDLE is really holding you back.  It's convenient
because it installs automagically with Python, but it does funky,
confusing things - as in this case, where it's somehow stepped on the
real error and assigned blame in the wrong place; you've already
experienced its internal conflicts with Tkinter...  I use wxPython for
my GUI goodness, and swear by SPE (Stani's Python Editor).  I don't
want to re-ignite the IDE wars, but I definitely think you need to do
yourself a favor and move away from IDLE.
  
Anyway, I didn't mean for that to be a standalone program, but to be
picked apart into chunks and dropped into an existing program (or,
actually, just to be used as an example - maybe of what _not_ to do,
but an example...)  
First error: 
    if argv is None:
       argv = sys.argv  <<== you haven't imported "sys"
  
Second error:
    app = MyApp(0)  <<== you haven't defined a class called
"MyApp", so you can't do this...
  
So I cut it down to just this bit:
test = Global.cfgFile.validate(Global.vtor, copy=True)
Global.cfgFile.write()
  
(unindented all the way to the left, so that it executes as the main
body of the program) and it works just fine... except:
Third error (well, issue not error):
Take all my comments out!  They weren't meant to be included in final
code.  ConfigObj allows inline comments in your config file, and in the
configspec - so my comments show up in there too.  Here's what
Initial.sen ends up looking like:
  
  mask_file_name = None
gray_scale = True
post_event_stack = False
post_event_format = Tiff 2
show_real_time = False
hourly_rate = 0
slowdown = 1    # I don't know what
#   this value is/does, so this is probably wrong
start_time = 00:00:00    # or you could make the default None?
stop_time = 00:00:00
    #   as a default latitude, if any...
  
I've cut everything down; I'm attaching it as Global_Config1.py (just
to avoid confusion with the earlier version).  If you do actually want
to use it as the basis of anything, you'll want to place the call to
.validate() somewhere near the beginning of the action - remember, the
call to .write() just afterward is completely optional; I had it in
there for testing and have kept it in there for the same reason.
    
 
  
Does PYTHONPATH apply in Win
XP? I haven't played at the level of paths
for a long time in any OS. We can worry about an install "package"
later for the modules. It might be best for the users of this program. 

  
  
Ya know, I have no idea anymore.  I thought I knew - but I just did a
SET from a command prompt, and I don't have a PYTHONPATH variable.  I
seem to reacall something from a year or two ago... (looking now)  Oh
yes - there's a directory under your Python directory (Python25 in my
case) called "Lib", and a folder under that called "site-packages"; any
text files with the extension ".pth" will be scaned for the names of
folders 

[Tutor] verify the email

2009-02-19 Thread jitendra gupta
hello
here is my code for sending the mail, using this code email is going
'CODE
''
import smtplib
from time import strftime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.Utils import COMMASPACE, formatdate


# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = " is sending the mail"
msg['From'] = 'jitu.ic...@domain.com'
msg['Date'] = formatdate(localtime=True)
msg['To'] = 'jitu.ic...@gmail.com'

# Create the body of the message (a plain-text and an HTML version).
#text = "jitendra kya huy a!\nHow are you?\nHere is the link you
wanted:\nhttp://www.python.org";
html = """\

  
  
Hi!
   How are you?
   This mail is send by wjitenrda
   Here is the http://www.python.org";>link you wanted.

  

"""

part2 = MIMEText(html, 'html')


msg.attach(part2)

# Send the message via local SMTP server.
s = smtplib.SMTP('smtp.domain name.com')
s.login("user","password")
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
'CODE  END
 
''
using this code i am able to send the email , but problem is
when i am changing
msg['To'] = "wrongu...@wrongdomain.comddsdjsdsdsjdh"
some wrong email then i am getting back failure notice in my inbox, which i
dont want..
is there any way so that i can identify wrong email during the run time
(when i am sending  the email)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
I want a regex to remove control characters (< chr(32) and > chr(126)) from 
strings ie.

line = re.sub(r"[^a-z0-9-';.]", " ", line)   # replace all chars NOT A-Z, a-z, 
0-9, [-';.] with " " 

1.  What is the best way to include all the required chars rather than list 
them all within the r"" ?
2.  How do you handle the inclusion of the quotation mark " ?

Cheers

Dinesh

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 10:14 AM, Dinesh B Vadhia
 wrote:
> I want a regex to remove control characters (< chr(32) and > chr(126)) from
> strings ie.
>
> line = re.sub(r"[^a-z0-9-';.]", " ", line)   # replace all chars NOT A-Z,
> a-z, 0-9, [-';.] with " "
>
> 1.  What is the best way to include all the required chars rather than list
> them all within the r"" ?

You have to list either the chars you want, as you have done, or the
ones you don't want. You could use
r'[\x00-\x1f\x7f-\xff]' or
r'[^\x20-\x7e]'

> 2.  How do you handle the inclusion of the quotation mark " ?

Use \", that works even in a raw string.

By the way string.translate() is likely to be faster for this purpose
than re.sub(). This recipe might help:
http://code.activestate.com/recipes/303342/

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Mark Tolonen
A regex isn't always the best solution:

>>> a=''.join(chr(n) for n in range(256))
>>> a
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
 
!"#$%&\'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
>>> b=''.join(n for n in a if ord(n) >= 32 and ord(n) <= 126)
>>> b
' 
!"#$%&\'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

-Mark

  "Dinesh B Vadhia"  wrote in message 
news:col103-ds55714842811febeb4a97ca3...@phx.gbl...
  I want a regex to remove control characters (< chr(32) and > chr(126)) from 
strings ie.

  line = re.sub(r"[^a-z0-9-';.]", " ", line)   # replace all chars NOT A-Z, 
a-z, 0-9, [-';.] with " " 

  1.  What is the best way to include all the required chars rather than list 
them all within the r"" ?
  2.  How do you handle the inclusion of the quotation mark " ?

  Cheers

  Dinesh




--


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


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Wayne Watson




I now have wxPython, IDLE and Vim installed. IDLE didn't disappear
during the wx install.  It looks as though wxPython re-compiled library
files. I'll be exploring vim now. 

Wayne Watson wrote:

  
Hi, actually I had two aims with the pseudo code, 1. print it, and 2.
check to see if it would pull in the two modules. I pulled it into
Word, and quickly formatted it to get the line wrap out, and put it in
some sort of readable format. After that, I thought why not just take
it as it was, and scoop it into IDLE.  My plan was to right a test
program to get a better understanding of how to use ConfigObj rather
than just try it through the program I plan to use it in. 
  
I've tried to keep to IDLE for no reason other than the author
recommended it. Well, OK, I had gotten comfortable with the editor. 
I'll try wxPython.
  
I took a quick look look at where Python was installed and found it was
directly under C:, and not under Program Files. That's a surprise. Now
I recall where I found something about classes and paths. It's on the
File menu of IDLE, Class Browser and Path Browser. 
  
I thought, in the last post, I asked about items like: show_real_time =
boolean(default=False) and hourly_rate = integer(min=0, default=0);
but, apparently, I accidentally knocked it out.  Anyway, here's the
question.  Where is the syntax for items like boolean,  integer, and
others described?  The doc I have barely refers to them. 
  
Off to find wx...


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


"Nature, to be commanded, must be obeyed."
   -- Sir Francis Bacon 




Web Page: 




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


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 4:51 AM, Wayne Watson
wrote:

>  Hi, actually I had two aims with the pseudo code, 1. print it, and 2.
> check to see if it would pull in the two modules. I pulled it into Word, and
> quickly formatted it to get the line wrap out, and put it in some sort of
> readable format. After that, I thought why not just take it as it was, and
> scoop it into IDLE.  My plan was to right a test program to get a better
> understanding of how to use ConfigObj rather than just try it through the
> program I plan to use it in.
>
> I've tried to keep to IDLE for no reason other than the author recommended
> it. Well, OK, I had gotten comfortable with the editor.  I'll try wxPython.
>

I wasn't very clear (and I shouldn't have mentioned wx at all, for
clarity!)  wxPython is not an alternative to IDLE, it's an alternative to
Tkinter.  SPE happens to have been written using wx (as IDLE uses Tkinter).
As I say, I should have left wx out of that... my point was that IDLE was
messing with the error somewhow and leading you to think it was a problem
with ConfigObj, when in fact it was probably the missing "import sys".
Since IDLE does that sort of thing A LOT, and also has known issues with
Tkinter (which you've experienced firsthand), I thought I'd slip in a gentle
suggestion to change tools.


>
> I took a quick look look at where Python was installed and found it was
> directly under C:, and not under Program Files. That's a surprise. Now I
> recall where I found something about classes and paths. It's on the File
> menu of IDLE, Class Browser and Path Browser.
>
> I thought, in the last post, I asked about items like: show_real_time =
> boolean(default=False) and hourly_rate = integer(min=0, default=0); but,
> apparently, I accidentally knocked it out.  Anyway, here's the question.
> Where is the syntax for items like boolean,  integer, and others described?
> The doc I have barely refers to them.
>

I posted it a few messages back - here's the link again:
http://www.voidspace.org.uk/python/validate.html
In particular you want this section:
http://www.voidspace.org.uk/python/validate.html#the-standard-functions


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


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 9:58 AM, Wayne Watson
wrote:

>  I now have wxPython, IDLE and Vim installed. IDLE didn't disappear during
> the wx install.  It looks as though wxPython re-compiled library files. I'll
> be exploring vim now.
>

wxPython doesn't replace or remove anything - I still have IDLE on my
machine, I just don't use it.  The wxPython installer wasn't re-compiling
Python - it was using Python to compile its own scripts for use on your
machine.

Once again, to be clear: wxPython is an alternative to Tkinter, not to IDLE
- it's a different toolkit for creating GUI applications.
The upsides:
 - it's a good deal more sophisticated and powerful (I feel) than Tkinter,
and the apps you produce using it will look a lot more "native" (on Windows,
they'll look like Windows apps; on OS X they'll have the Apple look and
feel, etc.) and therefore more professional/less hobbyist-like.
 - the syntax of working with wxPython widgets feels more Pythonic (to me).
It's a matter of personal taste, but I tried Tkinter for a few days and
hated it; I tried wxPython and got hooked.
The downsides:
 - it's not part of Python proper, so it's an extra dependency (although
there's a great install-package creator called Gui2Exe that will bundle your
program along with Python and all other dependencies into a Windows-style
installer, so you can distribute just one file to your potential users.)
 - it's not part of Python proper, so most tutorials/Python books barely
mention its existence.  There's (1) excellent book, "wxPython in Action", a
couple of very active mailing lists, an excellent and gigantic demo program
with sample code for almost every widget, and Google.  Other than that,
you're on your own.
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extracting a column from many files

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 5:41 AM, Bala subramanian
 wrote:
> Dear friends,
>
> I want to extract certain 6 different columns from a many files and write it
> to 6 separate output files.
>
>  #!/usr/bin/env python
> from sys import argv
> lst_files=argv[1:]
>
> sh=[];st=[];sta=[];buc=[];pro=[];ope=[]
>
> def extract(fname):
> A=[];B=[];C=[];D=[];E=[];F=[]
> data=open(fname).readlines()
> for number, line in enumerate(data):
> if "  Duplex" and " Shear" in line:
> number=number+3
> for x in range(0,8):
> new=data[number]
> A.append(new[19:26])
> B.append(new[27:34])
> C.append(new[37:42])
> D.append(new[44:54])
> E.append(new[56:63])
> F.append(new[69:75])
> number = number + 1
> sh.append(A)
> st.append(B)
> sta.append(C)
> buc.append(D)
> pro.append(E)
> ope.append(F)

I think you want to use extend() rather than append() here so you end
up with flat lists of values. Using append() creates lists of lists
which I don't think you want.
>
> for x in lst_files:
>   extract(x)
>
> list=[sh,st,sta,buc,pro,ope]

Don't use the names of built-ins (e.g. 'list') as variable names, it
shadows the built-in name.

> for value in list:
> row=map(None,*value)

Don't do this. You just want one column of data. The program you took
this from was writing one column *per input file* which I don't think
you want.

> out=open(str(value) + '.txt','w')

Value is a list, not a file name. I think you want something like this:

# List of pairs of (value list, name)
lists = [ (sh, 'sh'), (st, 'st'), ...]
for values, name in lists:
  out = open(name + '.txt', 'w')
  for value in values:
out.write(str(value))
out.write('\n')
  out.close()

Kent

> for num in row:
>   out.write('\t'.join(num))
>   out.write('\n')
> out.close()
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Wayne Watson
Title: Signature.html




Ok, I now understand the role of wx. I'm going to un-install wx. I want
to keep this program as close to the original as I can, which means I
will use Tkinter from here on out.  GUIs of different sorts seem to be
a burgeoning industry. 

I'm willing to give vim a shot. I believe in an earlier thread
unrelated to this, Alan suggested it. I'm perhaps incorrectly assuming
vim will take care of the Tkinter problem. If these editors aren't
really the source of some the error reporting problem, then I'm going
to have to come up with new thinking or some tactic that will get to
the real errors. If there is an influence of the editors, then I would
think it has something to do with the interface to Python, so it comes
down to which editor has the best or most stable interface with
Python.  When Alan suggested it, there was something about the apparent
awkwardness of executing the code, which made me pass on it. I'm going
back to find out what that was. 

Yep, I missed this in your other post:
"In particular you want this section: http://www.voidspace.org.uk/python/validate.html#the-standard-functions"

Marc Tompkins wrote:

  On Thu, Feb 19, 2009 at 9:58 AM, Wayne
Watson 
wrote:
  
I now have wxPython, IDLE and
Vim installed. IDLE didn't disappear
during the wx install.  It looks as though wxPython re-compiled library
files. I'll be exploring vim now. 


  
  
  
wxPython doesn't replace or remove anything - I still have IDLE on my
machine, I just don't use it.  The wxPython installer wasn't
re-compiling Python - it was using Python to compile its own scripts
for use on your machine.
  
Once again, to be clear: wxPython is an alternative to Tkinter, not to
IDLE - it's a different toolkit for creating GUI applications.  
The upsides:
 - it's a good deal more sophisticated and powerful (I feel) than
Tkinter, and the apps you produce using it will look a lot more
"native" (on Windows, they'll look like Windows apps; on OS X they'll
have the Apple look and feel, etc.) and therefore more
professional/less hobbyist-like.  
 - the syntax of working with wxPython widgets feels more Pythonic (to
me).  It's a matter of personal taste, but I tried Tkinter for a few
days and hated it; I tried wxPython and got hooked.
The downsides: 
 - it's not part of Python proper, so it's an extra dependency
(although there's a great install-package creator called Gui2Exe that
will bundle your program along with Python and all other dependencies
into a Windows-style installer, so you can distribute just one file to
your potential users.)
 - it's not part of Python proper, so most tutorials/Python books
barely mention its existence.  There's (1) excellent book, "wxPython in
Action", a couple of very active mailing lists, an excellent and
gigantic demo program with sample code for almost every widget, and
Google.  Other than that, you're on your own.
-- 
  www.fsrtechnologies.com
  

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


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


"Nature, to be commanded, must be obeyed."
   -- Sir Francis Bacon 




Web Page: 



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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-19 Thread Eric Dorsey
Still doesnt work.. I just get this when I hit the up arrow:>>> ^[[A

Bah. It works in the 2.5 version that came packaged with it. Thanks for
trying :)

On Wed, Feb 18, 2009 at 11:27 PM, زياد بن عبدالعزيز الباتلي <
ziyad.alba...@gmail.com> wrote:

> On Wed, 18 Feb 2009 20:19:56 -0700
> Eric Dorsey  wrote:
> > I did an aptitute install of  ibreadline5-dev and then
> > did ./configure and make again, and still don't have any
> > functionality to be able to hit up-arrow and get a command repeated
> > while inside the interpreter. Any ideas?
> >
> >
> I don't know what's wrong, Python should pickup "libreadline" and use
> it automatically if it was installed.
>
> Try passing "--with-readline" to the "configure" script.
>
> If that doesn't help, then I'm sorry, I'm out of ideas.
>
> Hope that help.
> Ziyad.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
At the bottom of the link http://code.activestate.com/recipes/303342/ there are 
list comprehensions for string manipulation ie.

import string

str = 'Chris Perkins : 224-7992'
set = '0123456789'
r = '$'

# 1) Keeping only a given set of characters.

print  ''.join([c for c in str if c in set])

> '2247992'

# 2) Deleting a given set of characters.

print  ''.join([c for c in str if c not in set])

> 'Chris Perkins : -'

The missing one is

# 3) Replacing a set of characters with a single character ie.

for c in str:
if c in set:
string.replace (c, r)

to give

> 'Chris Perkins : $$$-'

My solution is:

print ''.join[string.replace(c, r) for c in str if c in set]

But, this returns a syntax error.  Any idea why?

Ta!

Dinesh




From: Kent Johnson 
Sent: Thursday, February 19, 2009 8:03 AM
To: Dinesh B Vadhia 
Cc: tutor@python.org 
Subject: Re: [Tutor] Removing control characters


On Thu, Feb 19, 2009 at 10:14 AM, Dinesh B Vadhia
 wrote:
> I want a regex to remove control characters (< chr(32) and > chr(126)) from
> strings ie.
>
> line = re.sub(r"[^a-z0-9-';.]", " ", line)   # replace all chars NOT A-Z,
> a-z, 0-9, [-';.] with " "
>
> 1.  What is the best way to include all the required chars rather than list
> them all within the r"" ?

You have to list either the chars you want, as you have done, or the
ones you don't want. You could use
r'[\x00-\x1f\x7f-\xff]' or
r'[^\x20-\x7e]'

> 2.  How do you handle the inclusion of the quotation mark " ?

Use \", that works even in a raw string.

By the way string.translate() is likely to be faster for this purpose
than re.sub(). This recipe might help:
http://code.activestate.com/recipes/303342/

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


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 10:59 AM, Wayne Watson  wrote:


> I'm willing to give vim a shot. I believe in an earlier thread unrelated to
> this, Alan suggested it. I'm perhaps incorrectly assuming vim will take care
> of the Tkinter problem. If these editors aren't really the source of some
> the error reporting problem, then I'm going to have to come up with new
> thinking or some tactic that will get to the real errors. If there is an
> influence of the editors, then I would think it has something to do with the
> interface to Python, so it comes down to which editor has the best or most
> stable interface with Python.  When Alan suggested it, there was something
> about the apparent awkwardness of executing the code, which made me pass on
> it. I'm going back to find out what that was.
>

The problem is not with IDLE as an editor, but with IDLE as a shell.
You can edit your code in any editor, and as long as it doesn't slip funky
hidden characters into your file (not an issue with any normal text editor
AFAIK, but you definitely don't want to use Word!) it will make NO
difference to your code.  The problem with IDLE is that it tries to be an
IDE (Integrated Development Environment - in other words, you can edit the
code, execute it, debug it, get rudimentary language help all in one
program) and it does a p#$$-poor job of it.  Alan's advice is to avoid the
IDE approach and get used to editing your program in one window and running
it in another - after all, that's how your users will see it.  And it's good
advice and a valid approach.  Myself, I like using an IDE - the one thing I
used to like about using Visual Studio was the integration.  So I use SPE,
which is an IDE and (IMHO) a good one.  It does not matter in the slightest
which tool you use, as long as that tool does not get in your way.

(Actually, I may be misrepresenting Alan and Vim a bit - I don't use it
myself.  You can run external programs from inside of vim, so Alan's desktop
may look more like a traditional IDE than I'm imagining.)
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Removing control characters

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 11:25 AM, Dinesh B Vadhia  wrote:

> My solution is:
>
> print ''.join[string.replace(c, r) for c in str if c in set]
>
> But, this returns a syntax error.  Any idea why?
>

Probably because you didn't use parentheses - join() is a function.

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


[Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Isaac Eiland-Hall
http://python.pastebin.com/m26864a1b

 

Traceback (most recent call last):

File "./loopy", line 328, in 

 
set[current_set][current_section][current_key] = current_value

KeyError: 'DEFAULT'

 

 

 

First, apologies for the formatting - I'm teaching myself python after
having taught myself PHP, so I probably make amateur mistakes. I'm currently
working in a 120-character-wide environment for my own purposes, with plans
to perhaps change this later.

 

The purpose of this program, as it stands now, is to read an INI file and
parse it, line by line. Doing this by hand because my program will take the
INI file and generate multiple INI files for another program, and loop
through them (hence "Loopy" - I didn't come up with the name.)

 

My "Loopy" commands are lines in the INI that begin with a colon, e.g.
":SET=somename" starts a new set.

 

Lines 294-335 are where I've determined that the input line contains a
key-value pair. Well, I should backtrack.

 

"set" contains not only the various sets, but I track where I'm at in
set["+current+"] - I have to track the current set and section (INI section,
e.g. [DEFAULT]).

 

So what I'm trying to do on line 328 is to store the current key/value pair
in a dictionary under the proper section, which is in the proper set. Hence,
set[setname][section][key]=value

 

You can see my insanely-verbose log here:

http://python.pastebin.com/m6dcfb96d

 

That was from a run where I commented out line 328. (that dos the actual

 

Googling "KeyError" seems to indicate problems while trying to *retrieve*
values from a dictionary, whereas I'm trying to *set* values.

 

Does anyone have any insight?

 

Also, although I'm not formally requesting feedback on my coding style,
that's mainly because I don't want to waste anyone's time. But if you have
suggestions, please - I'm open. I'm self-taught and I'm sure I'm doing lots
of stupid things. I just hope it's not all bad. ;-)

 

Thank you most sincerely,

-Isaac Eiland-Hall

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


Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 11:34 AM, Isaac Eiland-Hall wrote:

>  http://python.pastebin.com/m26864a1b
>
>
>
> Traceback (most recent call last):
>
> File "./loopy", line 328, in 
>
>
> set[current_set][current_section][current_key] = current_value
>
> KeyError: 'DEFAULT'
>
One thing pops out at me - I'm not quite done reviewing yet, but...
Don't use reserved words as variable names!  "set" is a built-in type in
Python, and set() is a constructor for sets.
By doing this:

> set = {}
>
the best you can hope for is to confuse your fellow programmers - worse,
there may be some ambiguity at runtime.

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 2:25 PM, Dinesh B Vadhia
 wrote:

> # 3) Replacing a set of characters with a single character ie.
>
> for c in str:
> if c in set:
> string.replace (c, r)
>
> to give
>
>> 'Chris Perkins : $$$-'
> My solution is:
>
> print ''.join[string.replace(c, r) for c in str if c in set]

With the syntax corrected this will not do what you want; the "if c in
set" filters the characters in the result, so the result will contain
only the replacement characters. You would need something like
''.join([ (r if c in set else c) for c in str])

Note that both 'set' and 'str' are built-in names and therefore poor
choices for variable names.

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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-19 Thread Robert Berman




Eric,

I am running under Ubuntu 8.10. 

If I use IDLE the up arrow key gives me nothing at all. It does work
using iPython which for most testing of ideas and code snippets has
replaced IDLE.

My GUI of choice is WING-personal which cost  $30.00 and is by far the
best investment I have made for a  very high powered python developing
environment and yes of course the open arrow works in that environment
also. 

Consider, at the least, using iPython.

Good luck,



Robert Berman



Eric Dorsey wrote:
Still doesnt work.. I just get this when I hit the up
arrow:
  >>> ^[[A
  
  
  Bah. It works in the 2.5 version that came packaged with it.
Thanks for trying :)
  
  
  On Wed, Feb 18, 2009 at 11:27 PM, زياد بن
عبدالعزيز الباتلي 
wrote:
  On
Wed, 18 Feb 2009 20:19:56 -0700
Eric Dorsey  wrote:

> I did an aptitute install of
 ibreadline5-dev and then
> did ./configure and make again, and still don't have any
> functionality to be able to hit up-arrow and get a command repeated
> while inside the interpreter. Any ideas?
>
>

I don't know what's wrong, Python should pickup "libreadline" and use
it automatically if it was installed.

Try passing "--with-readline" to the "configure" script.

If that doesn't help, then I'm sorry, I'm out of ideas.

Hope that help.
Ziyad.
  
  
  
  
  
  

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



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


Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 2:34 PM, Isaac Eiland-Hall  wrote:
> http://python.pastebin.com/m26864a1b
>
>
>
> Traceback (most recent call last):
>
> File "./loopy", line 328, in 
>
>
> set[current_set][current_section][current_key] = current_value
>
> KeyError: 'DEFAULT'

> So what I'm trying to do on line 328 is to store the current key/value pair
> in a dictionary under the proper section, which is in the proper set. Hence,
> set[setname][section][key]=value
>
>
>
> You can see my insanely-verbose log here:
>
> http://python.pastebin.com/m6dcfb96d
>
>
>
> That was from a run where I commented out line 328… (that dos the actual
>
>
>
> Googling "KeyError" seems to indicate problems while trying to *retrieve*
> values from a dictionary, whereas I'm trying to *set* values…

Yes, KeyError happens on retrieval. Maybe you don't realize you are
doing two retrievals, then a set:
  set[current_set][current_section][current_key] = current_value
means:
- retrieve the value of set[current_set]
- from the above value, retrieve the value associated with current_section
- in the above value, set the value associated with current_key.

I haven't looked at the code, but maybe current_set or current_section
is 'DEFAULT
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Kent Johnson
Oops, hit send by mistake...continued below.

On Thu, Feb 19, 2009 at 3:40 PM, Kent Johnson  wrote:
> On Thu, Feb 19, 2009 at 2:34 PM, Isaac Eiland-Hall  
> wrote:
>> http://python.pastebin.com/m26864a1b
>>
>>
>>
>> Traceback (most recent call last):
>>
>> File "./loopy", line 328, in 
>>
>>
>> set[current_set][current_section][current_key] = current_value
>>
>> KeyError: 'DEFAULT'
>
>> So what I'm trying to do on line 328 is to store the current key/value pair
>> in a dictionary under the proper section, which is in the proper set. Hence,
>> set[setname][section][key]=value
>>
>>
>>
>> You can see my insanely-verbose log here:
>>
>> http://python.pastebin.com/m6dcfb96d
>>
>>
>>
>> That was from a run where I commented out line 328… (that dos the actual
>>
>>
>>
>> Googling "KeyError" seems to indicate problems while trying to *retrieve*
>> values from a dictionary, whereas I'm trying to *set* values…
>
> Yes, KeyError happens on retrieval. Maybe you don't realize you are
> doing two retrievals, then a set:
>  set[current_set][current_section][current_key] = current_value
> means:
> - retrieve the value of set[current_set]
> - from the above value, retrieve the value associated with current_section
> - in the above value, set the value associated with current_key.
>
> I haven't looked at the code, but maybe current_set or current_section
> is 'DEFAULT
>

is 'DEFAULT' and that value hasn't been added yet. You have to
create/add the dicts at the top of the hierarchy before you can set
values at the lower part. Take a look at dict.setdefault() or
collections.defaultdict for some possible fixes.

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


Re: [Tutor] Looking for ConfigObj Documentation

2009-02-19 Thread Wayne Watson




Actually, I had gotten comfortable with using IDLE a few weeks ago, and
just put a short cut to the program within easy reach. I'd edit then
execute with the icon. One day, I happened to hit F5 and it executed
the program properly. Somehow I drifted back to the old way,
unsuspectingly. Not good. Maybe there's a way to disable F5!!! Maybe
it's just too close to F3! 

Marc Tompkins wrote:

  On Thu, Feb 19, 2009 at 10:59 AM, Wayne
Watson 
wrote:
   
  
I'm willing to give vim a
shot. I believe in an earlier thread
unrelated to this, Alan suggested it. I'm perhaps incorrectly assuming
vim will take care of the Tkinter problem. If these editors aren't
really the source of some the error reporting problem, then I'm going
to have to come up with new thinking or some tactic that will get to
the real errors. If there is an influence of the editors, then I would
think it has something to do with the interface to Python, so it comes
down to which editor has the best or most stable interface with
Python.  When Alan suggested it, there was something about the apparent
awkwardness of executing the code, which made me pass on it. I'm going
back to find out what that was. 

  
  
The problem is not with IDLE as an editor, but with IDLE as a shell.
You can edit your code in any editor, and as long as it doesn't slip
funky hidden characters into your file (not an issue with any normal
text editor AFAIK, but you definitely don't want to use Word!) it will
make NO difference to your code.  The problem with IDLE is that it
tries to be an IDE (Integrated Development Environment - in other
words, you can edit the code, execute it, debug it, get rudimentary
language help all in one program) and it does a p#$$-poor job of it. 
Alan's advice is to avoid the IDE approach and get used to editing your
program in one window and running it in another - after all, that's how
your users will see it.  And it's good advice and a valid approach. 
Myself, I like using an IDE - the one thing I used to like about using
Visual Studio was the integration.  So I use SPE, which is an IDE and
(IMHO) a good one.  It does not matter in the slightest which tool you
use, as long as that tool does not get in your way.
  
  
  
(Actually, I may be misrepresenting Alan and Vim a bit - I don't use it
myself.  You can run external programs from inside of vim, so Alan's
desktop may look more like a traditional IDE than I'm imagining.)
-- 
  www.fsrtechnologies.com
  

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


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


"Nature, to be commanded, must be obeyed."
   -- Sir Francis Bacon 




Web Page: 



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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-19 Thread Roel Schroeven
Robert Berman schreef:
> Eric,
> 
> I am running under Ubuntu 8.10.
> 
> If I use IDLE the up arrow key gives me nothing at all. It does work
> using iPython which for most testing of ideas and code snippets has
> replaced IDLE.

FYI, in Idle the keys for going back and forth in the history are Alt-P
(previous) and Alt-N (next).


-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
Okay, here is a combination of Mark's suggestions and yours:

> # string of all chars
> a = ''.join([chr(n) for n in range(256)])
> a
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f
 
!"#$%&\'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'

> # string of wanted chars
> b = ''.join([n for n in a if ord(n) >= 32 and ord(n) <= 126])
> b
' 
!"#$%&\'()*+,-./0123456789:;<=>?...@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

> # string of unwanted chars > ord(126)
> c = ''.join([n for n in a if ord(n) < 32 or ord(n) > 126])
> c
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'

> # the string to process
> s = "Product Concepts\xe2\x80\x94Hard candy with an innovative twist, 
> Internet Archive: Wayback Machine. [online] Mar. 25, 2004. Retrieved from the 
> Internet http://www.confectionery-innovations.com>."

> # replace unwanted chars in string s with " "
> t = "".join([(" " if n in c else n) for n in s if n not in c])
> t
'Product ConceptsHard candy with an innovative twist, Internet Archive: Wayback 
Machine. [online] Mar. 25, 2004. Retrieved from the Internet http://www.confectionery-innovations.com>.'

This last bit doesn't work ie. replacing the unwanted chars with " " - eg. 
'ConceptsHard'.  What's missing?

Dinesh



From: Kent Johnson 
Sent: Thursday, February 19, 2009 12:36 PM
To: Dinesh B Vadhia 
Cc: tutor@python.org 
Subject: Re: [Tutor] Removing control characters


On Thu, Feb 19, 2009 at 2:25 PM, Dinesh B Vadhia
 wrote:

> # 3) Replacing a set of characters with a single character ie.
>
> for c in str:
> if c in set:
> string.replace (c, r)
>
> to give
>
>> 'Chris Perkins : $$$-'
> My solution is:
>
> print ''.join[string.replace(c, r) for c in str if c in set]

With the syntax corrected this will not do what you want; the "if c in
set" filters the characters in the result, so the result will contain
only the replacement characters. You would need something like
''.join([ (r if c in set else c) for c in str])

Note that both 'set' and 'str' are built-in names and therefore poor
choices for variable names.

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 5:41 PM, Dinesh B Vadhia
 wrote:
> Okay, here is a combination of Mark's suggestions and yours:

>> # replace unwanted chars in string s with " "
>> t = "".join([(" " if n in c else n) for n in s if n not in c])
>> t
> 'Product ConceptsHard candy with an innovative twist, Internet Archive:
> Wayback Machine. [online] Mar. 25, 2004. Retrieved from the Internet  http://www.confectionery-innovations.com>.'
>
> This last bit doesn't work ie. replacing the unwanted chars with " " - eg.
> 'ConceptsHard'.  What's missing?

The "if n not in c" at the end of the list comp rejects the unwanted
characters from the result immediately. What you wrote is the same as
t = "".join([n for n in s if n not in c])

because "n in c" will never be true in the first conditional.

BTW if you care about performance, this is the wrong approach. At
least use a set for c; better would be to use translate().

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


Re: [Tutor] Removing control characters

2009-02-19 Thread Mark Tolonen


"Kent Johnson"  wrote in message 
news:1c2a2c590902191500y71600feerff0b73a88fb49...@mail.gmail.com...

On Thu, Feb 19, 2009 at 5:41 PM, Dinesh B Vadhia
 wrote:

Okay, here is a combination of Mark's suggestions and yours:



# replace unwanted chars in string s with " "
t = "".join([(" " if n in c else n) for n in s if n not in c])
t

'Product ConceptsHard candy with an innovative twist, Internet Archive:
Wayback Machine. [online] Mar. 25, 2004. Retrieved from the Internet 

http://www.confectionery-innovations.com>.'

This last bit doesn't work ie. replacing the unwanted chars with " " - 
eg.

'ConceptsHard'.  What's missing?


The "if n not in c" at the end of the list comp rejects the unwanted
characters from the result immediately. What you wrote is the same as
t = "".join([n for n in s if n not in c])

because "n in c" will never be true in the first conditional.

BTW if you care about performance, this is the wrong approach. At
least use a set for c; better would be to use translate().


Sorry, I didn't catch the "replace with space" part.  Kent is right, 
translate is what you want.  The join is still nice for making the 
translation table:


table = ''.join(' ' if n < 32 or n > 126 else chr(n) for n in 
xrange(256))

string.translate('here is\x01my\xffstring',table)

'here is my string'

-Mark


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


[Tutor] I have a question plz help

2009-02-19 Thread rev pacce
My mom and I have been trying to hack into the administrator account on our 
laptop my mom got from her job awile ago so we can update the computer and 
itunes and stuff but we have failed many times. We had a pro hacker from 
colorado try and do it and he also failed my mom told me. i dont no if the 
computer is hack proof or what but its getting annoying. Does anyone no an easy 
way to get onto the admin account and change the password



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


Re: [Tutor] I have a question plz help

2009-02-19 Thread Kent Johnson
On Thu, Feb 19, 2009 at 8:29 PM, rev pacce  wrote:
> My mom and I have been trying to hack into the administrator account on our
> laptop my mom got from her job awile ago so we can update the computer and
> itunes and stuff but we have failed many times. We had a pro hacker from
> colorado try and do it and he also failed my mom told me. i dont no if the
> computer is hack proof or what but its getting annoying. Does anyone no an
> easy way to get onto the admin account and change the password

Sorry, wrong list.

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


[Tutor] wxPython dialog problem

2009-02-19 Thread Garry Willgoose
I'm just porting an old code from a GUI in Tkinter to one in wxPython  
and am having a problem with one of the dialog widgets. This is on  
OSX. The code below gives the result


result= 5104 5103 5104

as expected but if I substitute the single line form that is commented  
out (as per the wxPython book) I get


result= 2 5103 5104

can anyone enlighten me as to what is going on? I;m on OSX python  
2.5.2 and wxPython 2.8.9.1


code fragment

  dlg=wx.MessageDialog(None,text,title,wx.YES_NO | wx.ICON_QUESTION)
  result=dlg.ShowModal()
#  result=wx.MessageBox(text,title,wx.YES_NO | wx.ICON_QUESTION)
  print 'result=',result,wx.ID_YES,wx.ID_NO

end code fragment




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


Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Lie Ryan
On Thu, 19 Feb 2009 11:45:52 -0800, Marc Tompkins wrote:
> Don't use reserved words as variable names!  


str, set is built-in function not reserved words. Reserved words are like 
if, for, from, as (see the whole list type keywords in help() )

Nevertheless, it is a bad idea to use built-in function names.




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


Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Marc Tompkins
On Thu, Feb 19, 2009 at 8:39 PM, Lie Ryan  wrote:

> On Thu, 19 Feb 2009 11:45:52 -0800, Marc Tompkins wrote:
> > Don't use reserved words as variable names!
>
> 
> str, set is built-in function not reserved words. Reserved words are like
> if, for, from, as (see the whole list type keywords in help() )
>
> Nevertheless, it is a bad idea to use built-in function names.
> 
>

Fair 'nuff.

Furthermore, there _are_ cases when you want to use built-in type or
function names: when you're overloading them with your own versions.  That's
why Python lets you use them in the first place... but if that wasn't what
you wanted to do, then avoid them like the plaque.  (A little dental humor
there.)
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor