Re: [Tutor] httpd in your laptop?!? serve web pages and wikis in your notebook?

2007-03-01 Thread Chris Hengge

I was using Abyss web server for a long time since it has multi-OS support
and a friendly web based UI for administration. Seemed extremely light
weight to me.

On 2/27/07, Luke Paireepinart [EMAIL PROTECTED] wrote:


Kirk Bailey wrote:
 ok, I realized  SOME TIME BACK that to run MANY THINGS in your windows
 computer you need a server in there- and a nice SMALL one if it is going
 to coexist with everything else going on.
You need a server for what now?
Web pages?  FTP? SVN?
I can't think of much else.

I run apache and ftp services on my windows machine, and they're
using... let me check...
4 MB of ram for the FTP server, and 4.6 MB of ram for Apache.  neither
of these are considered 'lightweight' apps.  Both are fully-featured.
Neither are listed as using more than 0% CPU.
My IM client uses 14 MB, my music program uses 32 MB, my browser is
using 63 MB, and my e-mail client is using 47 MB.
I would consider Apache fairly resource-friendly, compared to these
other apps.  Not to mention it's used on over 50% of EVERY web server,
so I'm pretty sure it's reliable.  And I don't see a need to use
anything else.  If your software asked me to install some obscure web
server I've never heard of, I would probably cancel the installation and
forget about it, for fear it would interfere with my already-established
Apache server.
  I found one in python, and
 posted it, and it caused a stirr.
I don't know what you're referring to, maybe it was before I joined the
list.
  Well, I found a LISTING of them, and
 tried all the more promising ones. here is that page:
 http://microsoft.toddverbeek.com/phttpd.html

Can I ask why are you looking into this?
As far as I can tell, the software you're writing (miniwiki) will be
served from the client's computer directly to the client's web
browser.  No actual web stuff is necessary, right?
I don't understand why you'd want to make the user have to install
another webserver to use your program.  You're writing it in Python, why
not use a Python HTTP server library, and have that included in your
distribution when you py2exe it?
It seems by far a better solution.

JMO,
-Luke

___
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] Trying to get a feel

2007-02-05 Thread Chris Hengge

I've asked this on the Turbogears list, but I thought I'd ask here since
there is a larger active user base from what I can tell.

Basically I'm trying to get an idea of how practical streaming data with
something like turbogears would be for going from the client (web site user)
to the server. I know alot of this is most likely based on the connection
speed, but I'll play with perfect world numbers for the connection speed.
I've got some stuff I stream using python, and I'm just trying to figure out
if the same could be essentially done using a website built on something
like turbogears using exposed methods?

Thanks for any feedback that can be offered.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SPE - Stani's Python Editor ?

2007-01-03 Thread Chris Hengge

Pydev Extensions are only about $40. Most of the plugin's are $50 or less if
not free... I'd personally much rather pay for the feature's I want, as I
want them, then be forced bloated software (Visual Studio) that will cost
hundreds to thousands of dollars, which will still require very expensive
add-ons, as well as forces you to live in the MS Languages (Which is fine if
you need that)

I guess I don't see a problem with helping out active projects, I normally
toss open source software that I use for any amount of time atleast one
tip. In the end, its still a ton cheaper then Visual Studio or some of the
other options out there.

On 1/3/07, Mike Hansen [EMAIL PROTECTED] wrote:




 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Chris Hengge
 Sent: Tuesday, January 02, 2007 4:57 PM
 To: Dick Moores
 Cc: tutor@python.org
 Subject: Re: [Tutor] SPE - Stani's Python Editor ?

 I've recently started playing with Eclipse and the two PyDev
 plugin's over the holidays. I'm seriously liking it... but my
 likes are more closely related to Visual Studio as an editor,
 so this is like the perfect environment for me..

 http://www.showmedo.com/videos/series?name=PyDevEclipseList

 This link shows you two video's on how pydev works, and how to setup.


I played with Eclipse a little bit. I got annoyed that the plugins would
nickel and dime you to death. Pydev is free, but the additional features
in Pydev Extensions cost $. I heard there was a plugin for vi emulation.
Unfortunately, it was another plugin that you had to pay for.

I decided to stick with VIM where the plugins are free. I recently
starting using VIM's snippets.emu plugin. It emulates TextMate's
snippets. TextMate is an editor for OS X that is getting a lot of
attention. There are people working on TextMate-like editors for Windows
and Linux.

Mike




-

  NOTICE:  This e-mail transmission and any documents or files attached to
  it contain information for the sole use of the above-identified
individual or entity.

  Its contents may be privileged, confidential, and exempt from disclosure
under the law.
  Any dissemination, distribution, or copying of this communication is
strictly prohibited.

  Please notify the sender immediately if you are not the intended
recipient.

FGNS


___
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] SPE - Stani's Python Editor ?

2007-01-02 Thread Chris Hengge

I've recently started playing with Eclipse and the two PyDev plugin's over
the holidays. I'm seriously liking it... but my likes are more closely
related to Visual Studio as an editor, so this is like the perfect
environment for me..

http://www.showmedo.com/videos/series?name=PyDevEclipseList

This link shows you two video's on how pydev works, and how to setup.

On 12/31/06, Dick Moores [EMAIL PROTECTED] wrote:


 At 04:48 PM 12/31/2006, Vladimir Strycek wrote:

Hi all,
some time ago i instaled SPE with python 2.4... it works very good...
but yesterday my pc crash completly ( some dll went missing somehow :-)
)... so  after format and  reinstalling of windows i begin to install
all my programs back...

When i come to python i download new 2.5 version and only version for
win i could find is SPE-0.8.2.a-wx2.6.1.0-py24 which doesnt work... :-(
newer version ist just rpm and i need exe for win... any idea if there
will be exe or any more development in SPE cause homepage is not running
etc...

Or can you suggest similar IDE for python... ?


I have SPE 0.8.3.c, which is for Python 2.5.  There is a mailing list for
SPE users. See the archive at 
https://lists.berlios.de/pipermail/python-spe-users/.
Stani was looking for another host for the website. His last post, of Wed
Nov 29, says he has found one, and Don't worry the SPE website will come
back.

In the meantime, if anyone wants a copy of the file I downloaded,
SPE-0.8.3.c.win32-py2.5.exe, please contact me.
Program info
Spe version 0.8.3.c
Python version 2.5  (2.3 required)
wxPython version 2.6.3.3.  (2.6.1.0. required)

The size of SPE-0.8.3.c.win32-py2.5.exe is 1,147 KB.

Dick Moores
[EMAIL PROTECTED]



___
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] XML-RPC data transfers.

2007-01-01 Thread Chris Hengge

The main reason I haven't posted to more then one list is because I'm trying
to avoid looking obnoxious, as well as getting redundant information, or
having to keep answering the same things mutliple times... I might ask this
over there though after I try a few more things. Thanks.

On 1/1/07, Tim Golden [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 Going off your thoughts that I'm asking to do something outside the
 realm of the readers here, is there a better place to ask this kind of
 oddball stuff? I've looked around and haven't been able to find any
 support for XML-RPC (might be a good sign to drop it and move to
 something else?) I'm on the win32 list, and python-list, but I mostly
 just read those since in my mind most of what I have questions about are
 noobish things since I'm still trying to get a handle on this
language...

There's obviously nothing hard-and-fast about what fits
on this list and what on the main Python or python-win32
lists. There's not even that clear a distinction between
the latter two, and I suspect there's a good overlap of
experts reading two or more lists.

If I were to suggest something as a *very* broad guideline
it would be this: if you're unfamiliar with Python qua *language*,
the tutor list is perhaps the better list to ask; if you're
having problems with a particular library, whether one that
comes with Python or a third-party one, the main list might
get you more answers. Obviously there's a sort of middle
ground where the problems you're having with a library stem
from an unfamiliarity with language concepts...

I'm sure many people like myself keep track of several lists
as far as time and interest allows, so for a given problem
you might find the same level of expertise available to you.
If you were to ask, for example, about using WMI under
Win32 in Python your best bet would be the python-win32
list. But as it happens, that's my area of modest expertise
so as long as I'm watching this list you'd have a reasonable
chance of an answer. But that's only because it does happen
to be my area.

If you haven't already, I'd be inclined to put your
XMLRPC-Image question on the main python list. Why
not? If no-one can help, you're no worse off than
you were!

TJG
___
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] XML-RPC data transfers.

2006-12-31 Thread Chris Hengge

Boo bloatware! Don't even mention those... heheh.. I even turn off most the
services on my system to keep things clean.. But thats another story..

Going off your thoughts that I'm asking to do something outside the realm of
the readers here, is there a better place to ask this kind of oddball stuff?
I've looked around and haven't been able to find any support for XML-RPC
(might be a good sign to drop it and move to something else?) I'm on the
win32 list, and python-list, but I mostly just read those since in my mind
most of what I have questions about are noobish things since I'm still
trying to get a handle on this language...

On 12/31/06, Alan Gauld [EMAIL PROTECTED] wrote:


Chris Hengge [EMAIL PROTECTED] wrote

 method is a good one. Much like your own answers to most of my
 questions,
 you state several ways varying from probably works to how I'd try
 to do
 it. Personally, I'd rather understand more of the how I know it
 works

One reason may be that you are doing something unusual.
Like sending images directly from memory over an XMLRPC
connection. It should be possible but its not likely something
many perople on this list will have actually done. So you only
get suggestions of how they *might* do it ifd they had to.

Because of the reliability issues with XMLRPC I'd always save
image data to a file and send the file. (As I said earlier I'd try
to avoid sending the file via RPC but thats another story
that we've covered') But the advantages of having a file mean
that the whole process is much more repeatable and resilient
particularly if the object you are trying to send is subject to
change - like a screen shot. If you have to resend because
of RPC errors then the new screen grab might be different
to the original. The alternative involves holding the screen
image in RAM for a longish time which makes your program
into a resource hog which is also bad practice... although
with PCs having hundreds of Meg of RAM nowadays its
sadly becoming more common! Bloatware rules :-(

But I suspect the main reason you aren't getting working examples
is simply that you are trying to do something that is outside
normal programming experience on this list.

But I may be wrong! ;-)

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


___
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] XML-RPC data transfers.

2006-12-30 Thread Chris Hengge

This works...
d = xmlrpclib.Binary(open(C:\\somefile.exe, rb).read())

What I need is more like
screenShot = ImageGrab.Grab()
d = xmlrpclib.Binary(screenShot)

This doesn't work though.

On 12/30/06, Kent Johnson [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 I might have been unclear, or this tid-bit might have been lost in the
 thread... but I'm trying to send directly from ImageGrab.Grab(), without
 saving the data as a file. Thats where I'm getting hung... If it try to
 send an actual stored file, I have no problem. Is this maybe impossible?
 My thought was that I could just save a little process time and file
 fragmentation if I cut out the middle man, plus there really is no
 reason to save the screen capture on the server side.

Can you show the code that works? If you are writing your image data to
a file, then using something like Lee's example below, that just reads
the file data into a Binary object, you should be able to just create
the Binary object from the image data directly.

Kent


 Maybe I really need to look into SOAP for this sort of stuff? I'm just
 playing with the technology, and from the searching I've done, the
 XML-RPC seemed to fit my needs best. I could certainly be wrong though.

 Thanks for both of you giving me feedback.

 On 12/29/06, *Lee Harr* [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:

  
http://www.velocityreviews.com/forums/t343990-xmlrpc-send-file.html
 http://www.velocityreviews.com/forums/t343990-xmlrpc-send-file.html

  
  Using this example I get error's about 'expected binary .read(),
 but got
  instance instead.


 I assume you are using this ...

  d = xmlrpclib.Binary(open(C:\\somefile.exe).read())


 Are you using windows?

 I think you would need to pass the binary flag to open ...

 imagedata = open(filename, 'rb').read()



 It's probably a good idea to use the binary flag if you are
expecting
 binary data just in case it gets ported somewhere else later.


  I've just been using xmlrpclib and simplexmlrpcserver for this,
 but I'm
  wondering if I should perhaps use twisted instead.

 I've used xml-rpc to send image data before. It worked.

 _
 Don't just search. Find. Check out the new MSN Search!
 http://search.msn.com/

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



 

 ___
 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] XML-RPC data transfers.

2006-12-30 Thread Chris Hengge

First off, thanks for the info luke, I'll give these idea's a shot. Second,
I fully understand the wow factor from figuring out stuff on my own, but I
also work fulltime and attend roughly 20 credits of college a term, while
taking care of my family/homelife and this xmas break is one of the few
chances where I got time away from both work and from school, leaving just
my family and my freetime. All I'm trying to do is get the most of my time.
I also prefer examples as answers, not necessarily code... but something
more then you need to figure out how to do X, because more often then not,
I've already come up with that possibility. However, that doesn't mean the
method is a good one. Much like your own answers to most of my questions,
you state several ways varying from probably works to how I'd try to do
it. Personally, I'd rather understand more of the how I know it works so
that later as I get better I can fall back to working methods, and leave
myself open to creating my own ways as I stumble upon them, or have need for
a different approach. It's like cooking.. first you learn how to make a
pizza like everyone else, but after a while you get tired of eating that
pizza, so you make your own variation.

And yes, I'm still messing around with my VNC program, thats what this is in
relation too. I was just trying out XML-RPC because its suited for the job
best I can tell from what I've read and seen it used for. I've got most of
the projects features already done using plain sockets, this is just another
way I was trying, and if you check the other emails I've said a few reasons
why. As for twisted.. Thats next.. I even stated that it might be better,
and tossed it out for critic review, but nobody said otherwise so I figured
I was fine. (I started with sockets for simplicity, then XML-RPC is supposed
to be next easiest with twisted being last for my needs, also the most
overhead)

Anyways, I'll give your suggestions a shot and see what I come up with.

On 12/30/06, Luke Paireepinart [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 if I'm trying to transmit a 'file' that is actually saved on the HD,
 the code from the link in my first post works fine (reading in the
 file using binary mode access). My problem is that I'm trying to
 figure out how to transfer data that isn't yet saved to the drive,
 because I'm wanting to be able to send any sort of data type across
 the connection. This is getting rather frustrating because I'm getting
 so many replies back that aren't even attempts at answers, but rather
 questions about things I'm not trying to do. I'll restate the problem.

 grab image data from server side connection.
 transfer image data to client side
 write image data to file on client side.

 I've already established a working RPC connection, and if I transmit a
 'file' that can be read using binary mode (exact same code as posted
 in both the link in my first email, and by others in this thread) it
 works fine. My problem I'm trying to overcome is that I

 ***do not want to write the image data from the server to a file, just
 to send it, then delete the image file on the server***

And how...

It's clear what you're trying to do.
The problem is this:

1) ImageGrab.grab() - returns image object that has a 'save' method.
You use this method with the following syntax
import Image, ImageGrab
im = ImageGrab.grab()
im.save('filename.jpg')

to save the file .
2)
you read back in the file by doing:
f = file('filename.jpg','rb')
contents = f.read()


3)
you send it with this:
xmlrpclib.Binary(contents)


What you're trying to do is to eliminate step 1 and 2, so that you read
the ImageGrab's data directly into the xmlrpclib.Binary method call
without having to write a file.

Okay.
So the main problem we're having here is that you seem to think that you
should be able to send the ImageGrab object itself over the connection.
What is the problem is that xmlrpclib doesn't understand these class
instances.  you need to give it plain binary data that it can send.
So there's a few ways you can go about this.

But the main strategy is to get the data out of the ImageGrab object.
one way is stated above - use the save method to write to a file.
another possible way is to create a filelike class, implementing 'tell'
'seek' and 'write' methods, that just collects all the data written to
it and keeps it in memory
rather than writing it out to a file.
This is hinted at in the documentation for im.save():
You can use a file object instead of a filename. In this case, you must
always specify the format. The file object must implement the *seek*,
*tell*, and *write* methods, and be opened in binary mode.
(I assume it means you can use a file-like object, also, but it's
possible that you can't, and I leave it to you to test that :) )

a third solution is to convert the data to a string using
*im.tostring().
*send that over your connection, and use im.fromstring() on the other
end to recreate the image.

you could even use

Re: [Tutor] XML-RPC data transfers.

2006-12-29 Thread Chris Hengge

I might have been unclear, or this tid-bit might have been lost in the
thread... but I'm trying to send directly from ImageGrab.Grab(), without
saving the data as a file. Thats where I'm getting hung... If it try to send
an actual stored file, I have no problem. Is this maybe impossible? My
thought was that I could just save a little process time and file
fragmentation if I cut out the middle man, plus there really is no reason to
save the screen capture on the server side.

Maybe I really need to look into SOAP for this sort of stuff? I'm just
playing with the technology, and from the searching I've done, the XML-RPC
seemed to fit my needs best. I could certainly be wrong though.

Thanks for both of you giving me feedback.

On 12/29/06, Lee Harr [EMAIL PROTECTED] wrote:


http://www.velocityreviews.com/forums/t343990-xmlrpc-send-file.html

Using this example I get error's about 'expected binary .read(), but got
instance instead.


I assume you are using this ...

d = xmlrpclib.Binary(open(C:\\somefile.exe).read())


Are you using windows?

I think you would need to pass the binary flag to open ...

imagedata = open(filename, 'rb').read()



It's probably a good idea to use the binary flag if you are expecting
binary data just in case it gets ported somewhere else later.


I've just been using xmlrpclib and simplexmlrpcserver for this, but I'm
wondering if I should perhaps use twisted instead.

I've used xml-rpc to send image data before. It worked.

_
Don't just search. Find. Check out the new MSN Search!
http://search.msn.com/

___
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] XML-RPC data transfers.

2006-12-28 Thread Chris Hengge

I'm trying to figure out how to send data using XML-RPC. Currently my target
is to send a PIL imagegrab.grab() from one side of the connection to the
other. I've got stuff like numbers and strings going back and forth, so I
know my connection is working, but I'm not sure how to send the image.

'Server and Client Connect'
'Server asks client for screen capture, client captures and sends to
server.'

I've been trying to figure it out using this bit of information I found, but
I'm not sure how to map it to what I need:
http://www.velocityreviews.com/forums/t343990-xmlrpc-send-file.html

Using this example I get error's about 'expected binary .read(), but got
instance instead. ' when trying to convert the image data to binary to
transfer, I've also just tried passing the image data directly, but that
gets a return 'None exception.

I've just been using xmlrpclib and simplexmlrpcserver for this, but I'm
wondering if I should perhaps use twisted instead.

Happy Holiday's and Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Python 2.5 (Was Re: Length of longest item in a list, using a list comp)

2006-12-28 Thread Chris Hengge

I hope this is related enough for this thread, but I'm curious why people
didn't seem to unanimously jump into 2.5 upon release. Python seems very
good about holding its backward compatibility vs some other languages I've
dealt with like C# that seems to require applications rewritten with every
patch. Was there just nothing that grand about the new version? I've
personally held back just because most of the documentation I've come across
is for 2.4, and until I get a firmer feel for the language I'm trying to not
mix things up.

On 12/28/06, Alan Gauld [EMAIL PROTECTED] wrote:


Andreas Kostyrka [EMAIL PROTECTED] wrote

 With versions = 2.4 you can omit the []
 With 2.5 you can even do stuff like that:

I missed the announcement somewhere but 2.5 seems to
have been out for a spell now.

What are the must-have new features? (I could read the what's-new
doc but that tells me about stuff I may not see the value in!)

What are the features people are actually using regularly and find
an improvement?

Alan G.

___
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] Best method for filtering lists in lists...

2006-12-15 Thread Chris Hengge

I've got a list of lists that looks like this

[[1,2,3], [4,5,6],[1,2,3]]

I'm looking for a good way to drop the redundant inner lists (thousands of
inner lists)

Someone either have a good way to tackle this? or willing to point me in the
right direction?

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


Re: [Tutor] Best method for filtering lists in lists...

2006-12-15 Thread Chris Hengge

Oops, sorry about not replying to the list. I must have hit the wrong
button.

I'm terming a redundant list just like I posted in the original message:
[[1,2,3], [4,5,6],[1,2,3]]

[0][0] and [0][2] are redundant, so I only want to keep one of them.

Thanks again Luke.

On 12/15/06, Luke Paireepinart [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 Yes, we went over that a bit ago, but I wasn't sure if there were any
 different or more appropriate approaches to this when dealing with
 multidimensional lists.

Well, it depends what you term a redundant list.
Like, is
[[1,2,3],[3,2,1]]
a list with 1 unique elements or two?

If it is 1, then just sort all the lists before you check for redundancy.

I don't think there are any algorithms that are specific to lists of
lists, though there may be.
-Luke

P.S. please reply on-list :)

 On 12/15/06, *Luke Paireepinart* [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:

 Chris Hengge wrote:
  I've got a list of lists that looks like this
 
  [[1,2,3], [4,5,6],[1,2,3]]
 
  I'm looking for a good way to drop the redundant inner lists
  (thousands of inner lists)
 
  Someone either have a good way to tackle this? or willing to
 point me
  in the right direction?
 
  Thanks!
 
 Didn't we give multiple solutions to a similar problem with lists
 with
 redundant elements a few weeks ago?
 Well, the solutions will be the same, regardless that the elements
 inside are lists themselves.

 HTH,
 -Luke




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


Re: [Tutor] Confusing Unicode Conversion Problem.

2006-12-13 Thread Chris Hengge

Thanks for the detailed reply.

The reason I an forcing each line to string and splitting it is because the
pure numeric values coming from the excel sheet all come in a decimal, and
have an appended .0 at the end.
So 123456 in Excel is becoming 123456.0 when using the loop to extract it. I
was told by another person here in the office that Excel and COM aren't the
most intelligent collaborators =P

The destination for the list (you guessed correct) is another loop that
creates SQL commands, and then posts them into a database. Essentially this
script is just reading some 6K rows of data (max column count) from excel
and posting them into SQL tables. The script works fine for just about every
column, which is what has me so puzzled. I guess when MicroStrategies is
pulling this data into Excel format it must be adding extra data or
something.

Anyways, maybe now that I've explained what I'm doing, I could get a little
more focused solution to my problem? I think I've got a full understanding
of what is happening, but I'm still not sure of the fix. If it was in the
last e-mail, it must be over my head and I'll need it pointed out with neon
lights :)

thanks

On 12/13/06, Tim Golden [EMAIL PROTECTED] wrote:


[Chris Hengge]

| 'ascii' codec can't encode character u'\xa0' in position 11:
| ordinal not in range(128)
| Error with: FRAMEMRISER  of type: type 'unicode'
| Excel Row : 6355

OK. Let's get to the basics first:

code
import unicodedata
print unicodedata.name (u'\xa0')
# outputs: NO-BREAK SPACE

/code

So somewhere (maybe at the end) of your unicode
string is a non-breaking space. (Notice that
extra space between FRAMERISER and of in
the message above.

Next, when you print to the screen, you're implicitly
using the sys.stdout encoding, which on my XP machine
is cp437:

code
import sys
print sys.stdout.encoding
# outputs: cp437

print u'\xa0'.encode (sys.stdout.encoding)
# outputs a blank line, presumably including a non-breaking space

/code

But when you convert to a str using str (...) Python
will use an ascii encoding. So let's try that:

code
print str (u'\xa0')
# sure enough: UnicodeError, blah, blah

/code

In essence, when you're using Unicode data, you either
need to encode immediately to a consistent encoding of
your choice (or possibly forced upon you) or to retain
Unicode data throughout until you need to output, to
screen or database or file, and then convert as needed.

Let's take your code (snipped a bit):

1 while xlSht.Cells(row,col).Value != None:
2  tempValue = xlSht.Cells(row,col).Value
3  tempString = str(tempValue).split('.')[0]
4  ExcelValues.append(tempString)
5  Row = 1 + row # Increment Rows.

It's not clear what ExcelValues is, but let's assume
it's a list of things you're going to output later
to a file. Your line 3 is doing an implicit conversion
when it doesn't look like it needs to. Have a look
at this trivial example:

code
import codecs

fake_excel_data = ([uStuff.0, u\xa0and\xa0.1, unonsense.2])
values = []

for data in fake_excel_data:
  pre, post = data.split (.)
  values.append (pre)

#
# later...
#
f = codecs.open (excel_values.txt, w, utf-8)
try:
  f.writelines (values)
finally:
  f.close ()

/code

Notice I haven't done the encoding until I finally
output to a file, where I've used the codecs module
to specify an encoding. You could do this string by
string or some other way.

If I were simply writing back to, say, another
Excel sheet, or any other target which was expecting
Unicode data, I wouldn't encode it anywhere. The Unicode
objects offer nearly all the same methods as the
string objects so you just use them as you would strings.

What you have to look out for is situations like
your str () conversion where an implicit encoding-to-ascii
goes on.

HTH
TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
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] Confusing Unicode Conversion Problem.

2006-12-13 Thread Chris Hengge

You fixed it! Kudos and a cookie! (Name Brand even!)

Thanks a lot, seems to be moving along fine now.. :]

On 12/13/06, Tim Golden [EMAIL PROTECTED] wrote:


[Chris H]
 The reason I an forcing each line to string and splitting it is because
the
 pure numeric values coming from the excel sheet all come in a decimal,
and
 have an appended .0 at the end.

Ah! You're using str to convert a number to a string. I see.
And you're relying on the fact that other data, such as
the mysterious FRAMERISER\xa0 won't be affected by a split
on a dot.

Try using the unicode function as a converter, rather
than str. If the input is already a unicode object, it
won't alter it; if it's a number, it'll convert to a
unicode string, and the split will work as expected.

code snippet
while xlSht.Cells(row,col).Value != None:
 tempValue = xlSht.Cells(row,col).Value
 tempString = unicode (tempValue).split('.')[0]
 # tempString is now a unicode object one way
 # or the other, representing the part of your
 # data before the dot.
/code snippet

You might want to convert numbers back to some kind
of numeric type here (Decimal or float or int)
depending on your requirements later.

 The destination for the list (you guessed correct) is another loop that
 creates SQL commands, and then posts them into a database.

Depending on what your database is expecting, you might need to
encode your Unicode, or not. If you're using sqlite, for example,
it's expecting Unicode in any case. Other databases and interface
modules may vary.

Hope that's a bit clearer. I'm always happy to explain
again, but if my explanation isn't clear this time
round, better if someone else has a go; maybe my style
of explanation doesn't match with your style of
understanding. :)

TJG
___
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] Confusing Unicode Conversion Problem.

2006-12-12 Thread Chris Hengge

I've got a script that uses com to read columns from an excel workbook(very
slow for 6500ish items :/ ) and I'm getting this error:

'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in
range(128)
Error with: FRAMEMRISER  of type: type 'unicode'
Excel Row : 6355

FRAMEMRISER is exactly how the item looks in excel. What I don't get is why
it prints to my screen fine, but I can't get the darn thing to convert to a
string.  I think xa0 is a space (like 'nbsp'), which location 11 puts it at
the end of the of the word, basically invisible.  I've successfully used my
script to import several columns, but this one is being a pain.

My code in question:
try:
   while xlSht.Cells(row,col).Value != None:
tempValue = xlSht.Cells(row,col).Value
tempString = str(tempValue).split('.')[0]
ExcelValues.append(tempString)
Row = 1 + row # Increment Rows.
except UnicodeEncodeError, msg: # Exit the system if error.
   print msg
   print Error with:  + tempValue +  of type:  +
str(type(tempValue))
   print Excel Row :  + str(row)

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


Re: [Tutor] Create a script to make bootable USB device.

2006-12-08 Thread Chris Hengge

Just curious as to why nobody has at least attempted an answer for this. Is
what I'm asking simply unknown? Or it is impossible to do? No big deal
either way... just curious because I'm seriously interested in this. Thanks.

On 12/6/06, Chris Hengge [EMAIL PROTECTED] wrote:


Is this something I can do using just python and libraries? I know I could
automate other utilities, but I'd like to write some kind of neat utility
myself that I could play with for more experience.

Goal:
make USB drive bootable to a dos prompt (dont care what dos, assuming I
need a bootable image for this)
make script prompt for file(s) to move to disk (already know how to do
this)

Thanks!

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


[Tutor] Create a script to make bootable USB device.

2006-12-06 Thread Chris Hengge

Is this something I can do using just python and libraries? I know I could
automate other utilities, but I'd like to write some kind of neat utility
myself that I could play with for more experience.

Goal:
make USB drive bootable to a dos prompt (dont care what dos, assuming I need
a bootable image for this)
make script prompt for file(s) to move to disk (already know how to do this)

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


Re: [Tutor] which file runs

2006-12-05 Thread Chris Hengge

I have a script that makes my python scripts into .pyc files and I can run
those without a .py in the directory or anywhere else on the system for that
matter. No clever tricks needed.

On 12/1/06, Christopher Arndt [EMAIL PROTECTED] wrote:


Addendum: these rules only apply to Python *modules*. AFAIK, when you call
a
Python file as a script, no matching .pyc/.pyo file is used or generated.

There are some clever tricks to run a .pyc file as a script. I think it is
described in the Python CGI FAQ.

Chris
___
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] which file runs

2006-12-05 Thread Chris Hengge

Quick and dirty way to keep people from lookin at the code.

On 12/5/06, Luke Paireepinart [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 I have a script that makes my python scripts into .pyc files and I can
 run those without a .py in the directory or anywhere else on the
 system for that matter. No clever tricks needed.

Why would you want to do this?

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


Re: [Tutor] Best Known Method for Filtering redundant list items.

2006-12-01 Thread Chris Hengge

Somewhat less sarcastic... I did omg find that answer, and I didn't feel
like this was such a unique thing to do that I needed to re-invent the wheel
by building several methods to do something that a common library should
already have.

On 11/30/06, Jordan Greenberg [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 Anyone point me to something more efficient then

 for item in list1:
 if item not in list2:
   list2.append()

 This just seems to take a bit a time when there are thousands or dozens
of
 thousands of records just to filter out the dozen or so copies..

 Thanks.

somewhat unsurprisingly, the first thing google lists for python list
duplicates is a quite good ASPN recipe to do just what you want.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560

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


Re: [Tutor] which file runs

2006-12-01 Thread Chris Hengge

My understanding is that whenever you run a script that has a newer.py, the
.py runs, otherwise it automagically will use the .pyc

On 12/1/06, johnf [EMAIL PROTECTED] wrote:


Hi,
if there is a pyc and a py file within a module and the py file has a
later
date which file will python run?

John
--
John Fabiani
___
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] Best Known Method for Filtering redundant list items.

2006-11-30 Thread Chris Hengge

Anyone point me to something more efficient then

for item in list1:
if item not in list2:
  list2.append()

This just seems to take a bit a time when there are thousands or dozens of
thousands of records just to filter out the dozen or so copies..

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


Re: [Tutor] Best Known Method for Filtering redundant list items.

2006-11-30 Thread Chris Hengge

Nice! Thank you.

Curious as to why this happens though...


list1 = ['1','1','2','3','4']
list2 = list(set(list1))
list2

['1', '3', '2', '4'] -- here the order has changed.

This doesn't matter for my program, its just for a script that takes excel
columns and posts them into a given SQL db column...

On 11/30/06, Python [EMAIL PROTECTED] wrote:


On Thu, 2006-11-30 at 12:51 -0800, Chris Hengge wrote:
 Anyone point me to something more efficient then

list2 = list(set(list1))

Older Pythons will force you to import sets and use sets.Set

 for item in list1:
  if item not in list2:
list2.append()

 This just seems to take a bit a time when there are thousands or
 dozens of thousands of records just to filter out the dozen or so
 copies..

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


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


Re: [Tutor] Best Known Method for Filtering redundant list items.

2006-11-30 Thread Chris Hengge

No problem at all, as I said, this doesn't matter for my needs since I'm
just posting values into a DB. Just curious why it jumbles it all up :)

On 11/30/06, Lloyd Kvam [EMAIL PROTECTED] wrote:


There is a fly in the ointment that hit me after I sent the email.
Using set does not preserve the order.  If you care about the order of
elements in list1, my suggestion will not work.


On Thu, 2006-11-30 at 16:01 -0500, Python wrote:
 On Thu, 2006-11-30 at 12:51 -0800, Chris Hengge wrote:
  Anyone point me to something more efficient then
 
 list2 = list(set(list1))

 Older Pythons will force you to import sets and use sets.Set

  for item in list1:
   if item not in list2:
 list2.append()
 
  This just seems to take a bit a time when there are thousands or
  dozens of thousands of records just to filter out the dozen or so
  copies..
 
  Thanks.
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:  603-653-8139
fax:320-210-3409


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


Re: [Tutor] A Million Sevens

2006-11-18 Thread Chris Hengge

That must be part of Pythons shiny ability of dynamic data types? Must be a
messy operation to change data-types like that.. I think I'll just do my
best to work with the right data-types the whole time ;D

On 11/18/06, Alan Gauld [EMAIL PROTECTED] wrote:


Chris Hengge [EMAIL PROTECTED] wrote

 Not that it changes your reply, but just for my own sanity:
 int('7' * 10 ** 6) - does this not just type-cast a char into an
 int?

Chris, I suspect you may come from a C background?

Type *conversion* in Python is very differentb from
type *casting* in C.

type casting says take the binary data stored at x and treat
it as a different type, thats pretty well instantaneous.

typecasting (int)'77' in C will not give you the number
77(decimal) but will give you the hex value 0x3737
which is entirely different (actually 14135!).

Now typecasting in C++ is somewhat different, especially
if you use dynamic casts and that can involve converting
the type rather than just treating the existing data differently...
Because of this confusion over the word cast I prefer
to refer to Python as doing type conversions.

Type conversion says take the data entity in variable x
and change its internal structure to the representation
of a new type. Thats a much more complex operation.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


___
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] Problem making '.exe' from python.

2006-11-17 Thread Chris Hengge

Whether using py2exe or pyInstaller I've noticed a problem and I'm not sure
how to fix it...

When I create a .exe and then make a shortcut to the file and run it.. the
program will crash without warning.
If I run the .exe directly it runs fine.

My assumption of the problem:
Since it is still built on python and my variables for files or module calls
are designed for they are in the same location I run the script from when
I run the script from a shortcut it will fail finding the wanted pieces.

Is this true? And if so, how do I fix it? I could write fixed paths into my
code, but that is unrealistic and makes running my scripts to test them a
pain.

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


Re: [Tutor] Problem making '.exe' from python.

2006-11-17 Thread Chris Hengge

Awesome! Thank you!

This has been driving me crazy for weeks.
Now to figure out how to tell Inno to add that to a link, and I'm on my way!

On 11/17/06, Jason Massey [EMAIL PROTECTED] wrote:


Check to make sure that under the shortcut properties that you have the
Start in field filled out with the directory the script is located.

On 11/17/06, Chris Hengge [EMAIL PROTECTED] wrote:

 Whether using py2exe or pyInstaller I've noticed a problem and I'm not
 sure how to fix it...

 When I create a .exe and then make a shortcut to the file and run it..
 the program will crash without warning.
 If I run the .exe directly it runs fine.

 My assumption of the problem:
 Since it is still built on python and my variables for files or module
 calls are designed for they are in the same location I run the script from
 when I run the script from a shortcut it will fail finding the wanted
 pieces.

 Is this true? And if so, how do I fix it? I could write fixed paths into
 my code, but that is unrealistic and makes running my scripts to test them a
 pain.

 Thanks.

 ___
 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] Problem making '.exe' from python.

2006-11-17 Thread Chris Hengge

Just wanted to wrap that up so nobody wastes time replying.

I've fixed my Inno scripts and all my packages work now, case closed!

Thanks again Jason.

On 11/17/06, Chris Hengge [EMAIL PROTECTED] wrote:


Awesome! Thank you!

This has been driving me crazy for weeks.
Now to figure out how to tell Inno to add that to a link, and I'm on my
way!

On 11/17/06, Jason Massey [EMAIL PROTECTED] wrote:

 Check to make sure that under the shortcut properties that you have the
 Start in field filled out with the directory the script is located.

 On 11/17/06, Chris Hengge [EMAIL PROTECTED] wrote:

   Whether using py2exe or pyInstaller I've noticed a problem and I'm
  not sure how to fix it...
 
  When I create a .exe and then make a shortcut to the file and run it..
  the program will crash without warning.
  If I run the .exe directly it runs fine.
 
  My assumption of the problem:
  Since it is still built on python and my variables for files or module
  calls are designed for they are in the same location I run the script from
  when I run the script from a shortcut it will fail finding the wanted
  pieces.
 
  Is this true? And if so, how do I fix it? I could write fixed paths
  into my code, but that is unrealistic and makes running my scripts to test
  them a pain.
 
  Thanks.
 
  ___
  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] A Million Sevens

2006-11-17 Thread Chris Hengge

Well, I dont get the point.. its not locking up my system or anything.. its
just crunching away... even while I type this...
I guess your point is that it should stop since a 32 bit O/S can only count
to:
4,294,967,296

On 11/17/06, Thomas [EMAIL PROTECTED] wrote:


Earlier today I typed the following into my pythonwin interactive
interpreter in windows xp:

 int('7' * 10 ** 6)

 I expected either an error message or it to get stuck and require me to
stop the process manually.

 I read that unlike long integers in C, longs in python are only limited
by the amount of memory (and virtual memory) your system has.

Can you guess what it did?

I'm temped to end the post here, but I'm new to this list and its possible
that people might be annoyed by me not getting to the point within my
initial post, so here's what it did:

It thought about it for about 2 seconds then restarted my pc! explanations
welcome.

___
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] A Million Sevens

2006-11-17 Thread Chris Hengge

I'm thinking you either have a problem with a memory leak (my memory isn't
changing, just at 100% CPU), or your CPU overheated from poor cooling since
it is at 100% utilization.

On 11/17/06, Chris Hengge [EMAIL PROTECTED] wrote:


Well, I dont get the point.. its not locking up my system or anything..
its just crunching away... even while I type this...
I guess your point is that it should stop since a 32 bit O/S can only
count to:
4,294,967,296

On 11/17/06, Thomas [EMAIL PROTECTED] wrote:

 Earlier today I typed the following into my pythonwin interactive
 interpreter in windows xp:

  int('7' * 10 ** 6)

  I expected either an error message or it to get stuck and require me to
 stop the process manually.

  I read that unlike long integers in C, longs in python are only limited
 by the amount of memory (and virtual memory) your system has.

 Can you guess what it did?

 I'm temped to end the post here, but I'm new to this list and its
 possible that people might be annoyed by me not getting to the point within
 my initial post, so here's what it did:

 It thought about it for about 2 seconds then restarted my pc!
 explanations welcome.

 ___
 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] A Million Sevens

2006-11-17 Thread Chris Hengge

Not that it changes your reply, but just for my own sanity:
int('7' * 10 ** 6) - does this not just type-cast a char into an int?

Meaning that rather then consuming 1024k as you stated, it would consume
2048k at the peak of the calculation(2bytes per char? * 1m = 2048k) then
typecasting to int would drop it back down to 1k (1byte per int * 1m = 1024k

So, just for sake of getting to a point since I missed the one by the
original poster.. why would you not convert that 7 from a char to an int
first? That calculation is almost instant, and it doesn't require the memory
rollercoaster that this calculation would require..

Anyways.. back to the poster...

Perhaps you wanted an error like this?

print '=' * 10
Traceback (most recent call last):
 File input, line 1, in ?
MemoryError


On 11/17/06, Luke Paireepinart [EMAIL PROTECTED] wrote:


Chris Hengge wrote:
 I'm thinking you either have a problem with a memory leak (my memory
 isn't changing, just at 100% CPU), or your CPU overheated from poor
 cooling since it is at 100% utilization.
yeah I second this...
there's no reason why this would reboot your computer.
At Chris: It's building a string that's 1,000,000 characters long, so it
should be increasing your memory usage by at least 1,000,000 characters,
or 1 mb.  But that's over a probably long period of time, so you just
didn't notice any change.

 On 11/17/06, *Chris Hengge* [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:

 Well, I dont get the point.. its not locking up my system or
 anything.. its just crunching away... even while I type this...
 I guess your point is that it should stop since a 32 bit O/S can
 only count to:
 4,294,967,296

 On 11/17/06, *Thomas*  [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:

 Earlier today I typed the following into my pythonwin
 interactive interpreter in windows xp:

  int('7' * 10 ** 6)

 I expected either an error message or it to get stuck and
 require me to stop the process manually.

 I read that unlike long integers in C, longs in python are
 only limited by the amount of memory (and virtual memory) your
 system has.

 Can you guess what it did?

 I'm temped to end the post here, but I'm new to this list and
 its possible that people might be annoyed by me not getting to
 the point within my initial post, so here's what it did:

 It thought about it for about 2 seconds then restarted my pc!
 explanations welcome.



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


Re: [Tutor] Alternatives to PY2EXE

2006-11-16 Thread Chris Hengge

I'm personally not to picky... I just want the tool to work, and like I
said, for some reason I'm having trouble running very simple scripts from
py2exe, which I dont seem to have while using pyInstaller. I've even written
a drag and drop front-end for it (had one for py2exe too) to make using it
stupidly easy.

It really does boggle my mind how people can be so wierd when asked to run
something that isn't a .exe... Guess its a side-effect of the windows
generation.

On 11/16/06, Tim Golden [EMAIL PROTECTED] wrote:


[Chris Hengge]

| Because alot of the users here at Intel dont want to admit
| you can write usable programs in a scripting language.. so
| when they see a .exe they feel comfy...

One option which could help there -- although your
other considerations might outweigh it -- is
Fredrik Lundh's exemaker:

http://effbot.org/zone/exemaker.htm

It doesn't bundle up Python in the way that py2exe
does: you still need to have python on the target
machine. But it does provide an .exe of your
program (which, behind the scenes, loads up the
Python dll in the same way that the python.exe
would have done in the first place).

Thst way, the .exe-comfortable user sees a .exe
without the extra work of py2exe/installer etc.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

___
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] email content-type: text/plain

2006-11-16 Thread Chris Hengge

Not sure if I'm really helping, but I want to try for all the help I've
gotten...
I took this from: http://docs.python.org/lib/module-email.message.html
##
*class MIMEText*( _text[, _subtype[, _charset]]) Module: email.mime.text

A subclass of MIMENonMultipart, the MIMEText class is used to create MIME
objects of major type text. _text is the string for the payload. _subtype is
the minor type and defaults to plain. _charset is the character set of the
text and is passed as a parameter to the MIMENonMultipart constructor; it
defaults to us-ascii. No guessing or encoding is performed on the text data.

#

Going off this, I'd say you need to change:

msg = MIMEText(message)

to:

msg = MIMEText(message, 'someTypeThatIsn'tPlain')
On 11/16/06, shawn bright [EMAIL PROTECTED] wrote:


hey there all,
i am using the email package and the phone provider i am trying to get a
text message thru has sent me an email that says that they are looking for a
tag that says 'content-type text/plain'

i have tried about everything i can think of to get it in there, but
everything i have tried has failed.

here is what i have so far:
address = '[EMAIL PROTECTED]'
message = 'some text that needs to be delivered via text message'
msg = MIMEText(message)
msg['Subject'] = 'pivots'
msg['From'] = '[EMAIL PROTECTED]'
msg['To'] = address
server.sendmail(msg['From'],msg['To'], msg.as_string())

any ideas ?
thanks

___
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] email content-type: text/plain

2006-11-16 Thread Chris Hengge

I just re-read your email, and I dont think I answered it accurately since
you apparently want plain... so maybe you can still use my example for
force the type?

On 11/16/06, Chris Hengge [EMAIL PROTECTED] wrote:


Not sure if I'm really helping, but I want to try for all the help I've
gotten...
I took this from: http://docs.python.org/lib/module-email.message.html

##
*class  MIMEText*( _text[, _subtype[, _charset]]) Module: email.mime.text

A subclass of MIMENonMultipart, the MIMEText class is used to create MIME
objects of major type text. _text is the string for the payload. _subtypeis the 
minor type and defaults to
plain. _charset is the character set of the text and is passed as a
parameter to the MIMENonMultipart constructor; it defaults to us-ascii. No
guessing or encoding is performed on the text data.


#

Going off this, I'd say you need to change:

msg = MIMEText(message)

to:

msg = MIMEText(message, 'someTypeThatIsn'tPlain')
On 11/16/06, shawn bright [EMAIL PROTECTED] wrote:

 hey there all,
 i am using the email package and the phone provider i am trying to get a
 text message thru has sent me an email that says that they are looking for a
 tag that says 'content-type text/plain'

 i have tried about everything i can think of to get it in there, but
 everything i have tried has failed.

 here is what i have so far:
 address = '[EMAIL PROTECTED]'
 message = 'some text that needs to be delivered via text message'
 msg = MIMEText(message)
 msg['Subject'] = 'pivots'
 msg['From'] = '[EMAIL PROTECTED]'
 msg['To'] = address
 server.sendmail(msg['From'],msg['To'], msg.as_string())

 any ideas ?
 thanks

 ___
 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] email content-type: text/plain

2006-11-16 Thread Chris Hengge

I would start by forcing 'text/plain'.
If that doesn't work maybe take a look at:
*set_type*( type[, header][, requote]) Set the main type and subtype for the
Content-Type: header. type must be a string in the form maintype/subtype,
otherwise a ValueError is raised.

This method replaces the Content-Type: header, keeping all the parameters in
place. If requote is False, this leaves the existing header's quoting as is,
otherwise the parameters will be quoted (the default).

An alternative header can be specified in the header argument. When the
Content-Type: header is set a MIME-Version: header is also added.

New in version 2.2.2.
*
Just out of curiosity, have you tested your message?
msg = MIMEText(message)
print get_content_type(message)

or:

msg = MIMEText(message, 'plain/text')
print get_content_type(message)
*
I'm just tossing out idea's for things I would try. I've not actually used
this module yet.


On 11/16/06, shawn bright [EMAIL PROTECTED] wrote:


use  MIMEText(message, 'someTypeThatIsn'tPlain')  ? but type/plain is what
i am after.
i am a bit confused here. It defaults to plain, but there is not anything
in the message headers that say what type it is. Should i use
MIMEText(message, 'text/plain') ?

thanks
sk

On 11/16/06, Chris Hengge [EMAIL PROTECTED] wrote:

 Not sure if I'm really helping, but I want to try for all the help I've
 gotten...
 I took this from: http://docs.python.org/lib/module-email.message.html

 ##
 *class  MIMEText*( _text[, _subtype[, _charset]]) Module:
 email.mime.text

 A subclass of MIMENonMultipart, the MIMEText class is used to create
 MIME objects of major type text. _text is the string for the payload.
 _subtype is the minor type and defaults to plain. _charset is the
 character set of the text and is passed as a parameter to the
 MIMENonMultipart constructor; it defaults to us-ascii. No guessing or
 encoding is performed on the text data.


 #

 Going off this, I'd say you need to change:

 msg = MIMEText(message)

 to:

 msg = MIMEText(message, 'someTypeThatIsn'tPlain')
 On 11/16/06, shawn bright [EMAIL PROTECTED]  wrote:
 
  hey there all,
  i am using the email package and the phone provider i am trying to get
  a text message thru has sent me an email that says that they are looking for
  a tag that says 'content-type text/plain'
 
  i have tried about everything i can think of to get it in there, but
  everything i have tried has failed.
 
  here is what i have so far:
  address = '[EMAIL PROTECTED]'
  message = 'some text that needs to be delivered via text message'
  msg = MIMEText(message)
  msg['Subject'] = 'pivots'
  msg['From'] = '[EMAIL PROTECTED]'
  msg['To'] = address
  server.sendmail(msg['From'],msg['To'], msg.as_string())
 
  any ideas ?
  thanks
 
  ___
  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] email content-type: text/plain

2006-11-16 Thread Chris Hengge

Just so you can compare...


msg = MIMEText.MIMEText(How are you!?)
email.Message.Message.get_content_type(msg)

'text/plain'

On 11/16/06, Chris Hengge [EMAIL PROTECTED] wrote:


I would start by forcing 'text/plain'.
If that doesn't work maybe take a look at:
* set_type*( type[, header][, requote]) Set the main type and subtype for
the Content-Type: header. type must be a string in the form
maintype/subtype, otherwise a ValueError is raised.

This method replaces the Content-Type: header, keeping all the parameters
in place. If requote is False, this leaves the existing header's quoting
as is, otherwise the parameters will be quoted (the default).

An alternative header can be specified in the header argument. When the
Content-Type: header is set a MIME-Version: header is also added.

New in version 2.2.2.

*
Just out of curiosity, have you tested your message?
msg = MIMEText(message)
print get_content_type(message)

or:

msg = MIMEText(message, 'plain/text')
print get_content_type(message)
*

I'm just tossing out idea's for things I would try. I've not actually used
this module yet.


On 11/16/06, shawn bright  [EMAIL PROTECTED] wrote:

 use  MIMEText(message, 'someTypeThatIsn'tPlain')  ? but type/plain is
 what i am after.
 i am a bit confused here. It defaults to plain, but there is not
 anything in the message headers that say what type it is. Should i use
 MIMEText(message, 'text/plain') ?

 thanks
 sk

 On 11/16/06, Chris Hengge  [EMAIL PROTECTED] wrote:
 
  Not sure if I'm really helping, but I want to try for all the help
  I've gotten...
  I took this from: http://docs.python.org/lib/module-email.message.html
 
  
##
  *class  MIMEText*( _text[, _subtype[, _charset]]) Module:
  email.mime.text
 
  A subclass of MIMENonMultipart, the MIMEText class is used to create
  MIME objects of major type text. _text is the string for the payload.
  _subtype is the minor type and defaults to plain. _charset is the
  character set of the text and is passed as a parameter to the
  MIMENonMultipart constructor; it defaults to us-ascii. No guessing or
  encoding is performed on the text data.
 
 
  
#
 
  Going off this, I'd say you need to change:
 
  msg = MIMEText(message)
 
  to:
 
  msg = MIMEText(message, 'someTypeThatIsn'tPlain')
  On 11/16/06, shawn bright [EMAIL PROTECTED]  wrote:
  
   hey there all,
   i am using the email package and the phone provider i am trying to
   get a text message thru has sent me an email that says that they are 
looking
   for a tag that says 'content-type text/plain'
  
   i have tried about everything i can think of to get it in there, but
   everything i have tried has failed.
  
   here is what i have so far:
   address = '[EMAIL PROTECTED]'
   message = 'some text that needs to be delivered via text message'
   msg =
   MIMEText(message)
   msg['Subject'] = 'pivots'
   msg['From'] = '[EMAIL PROTECTED]'
   msg['To'] = address
   server.sendmail(msg['From'],msg['To'], msg.as_string())
  
   any ideas ?
   thanks
  
   ___
   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] Alternatives to PY2EXE

2006-11-15 Thread Chris Hengge

Because alot of the users here at Intel dont want to admit you can write
usable programs in a scripting language.. so when they see a .exe they
feel comfy...

I'm working on pushing agile language... I personally think its more
appropriate then scripting =D

On 11/15/06, Alan Gauld [EMAIL PROTECTED] wrote:



Etrade Griffiths [EMAIL PROTECTED] wrote
 just finished developing my first app with wxPython and matplotlib
 and now
 trying to create an EXE file using PY2EXE for distribution.
 However, this
 is proving to be an extremely frustrating experience and I am making
 very
 little progress.  Are there any simple alternatives to PY2EXE for
 shipping Python apps to Windows machines?

There are a few more sophisticated tools around but py2exe is
usually considered the easy option.

But are you sure you really need an EXE?
The size of a bundled python install, which can be optionally
loaded if not alteady there, is not excessive in modern PC
software terms and many environments nowadays do not
use pure exe's - VB, .NET, Java Smalltalk, etc

So why not just ship Python? And if you writre a lot of code
installing
python will use up less memory in the long term since you won't
have a copy of the interpreter hiding inside every app!

Alan G.


___
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] free IDE for Python?

2006-11-15 Thread Chris Hengge

I tried it back before I tried SPE. I remember it taking several hours and
being very bloated. Have you watched the showmedo video? Thats what I
used...

http://showmedo.com/videos/series?name=PyDevEclipseList

If I personally had to use something that obnoxious I'd just reinstall
ironpython and use Visual Studio for everything since I already have it for
C# applications. (Yes I understand it makes .net runtime code and not python
code, but I can't justify using that large and resource eating a program to
use a language that is supposed to be quick and easy... )

On 11/15/06, Alan Gauld [EMAIL PROTECTED] wrote:



wesley chun [EMAIL PROTECTED] wrote
 Eclipse
http://pydev.sourceforge.net
http://www.eclipse.org/

Has anyone got an idiot's guide to getting Eclipse working
with python?

I've tried a couple of times but ran out of patience. In fact I
haven't really got vanilla Eclipse working for Java yet, it all
seems a lot of work for an IDE! NetBeans was so much
easier but my friends all laughed at me and said I should
be using Eclipse... :-)

Alan (the impatient) G.

___
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] free IDE for Python?

2006-11-15 Thread Chris Hengge

BTW... that also counts as my vouce for using SPE =D

On 11/15/06, Chris Hengge [EMAIL PROTECTED] wrote:


I tried it back before I tried SPE. I remember it taking several hours and
being very bloated. Have you watched the showmedo video? Thats what I
used...

http://showmedo.com/videos/series?name=PyDevEclipseList

If I personally had to use something that obnoxious I'd just reinstall
ironpython and use Visual Studio for everything since I already have it for
C# applications. (Yes I understand it makes .net runtime code and not python
code, but I can't justify using that large and resource eating a program to
use a language that is supposed to be quick and easy... )

On 11/15/06, Alan Gauld [EMAIL PROTECTED] wrote:


 wesley chun [EMAIL PROTECTED] wrote
  Eclipse
 http://pydev.sourceforge.net
  http://www.eclipse.org/

 Has anyone got an idiot's guide to getting Eclipse working
 with python?

 I've tried a couple of times but ran out of patience. In fact I
 haven't really got vanilla Eclipse working for Java yet, it all
 seems a lot of work for an IDE! NetBeans was so much
 easier but my friends all laughed at me and said I should
 be using Eclipse... :-)

 Alan (the impatient) G.

 ___
 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] Alternatives to PY2EXE

2006-11-15 Thread Chris Hengge

Just want to add to that...

As of the day before yesturday I've been using pyInstaller rather then
py2exe(which I've used the last few months) I've found some bug that I can't
figure out and dont really care to put effort into fixing..

When I run a py.exe using py2exe from the start menu and the user enters any
input.. program crashes without errors.
When I run a py.exe directly from the command line, it runs flawless.
When I run the script from either the start menu or the command line, it
runs flawless.

I appreciate pyInstaller giving a little more interesting icon to my .exe
also... but thats just being picky and lazy.

On 11/15/06, Chris Hengge [EMAIL PROTECTED] wrote:


Because alot of the users here at Intel dont want to admit you can write
usable programs in a scripting language.. so when they see a .exe they
feel comfy...

I'm working on pushing agile language... I personally think its more
appropriate then scripting =D

On 11/15/06, Alan Gauld [EMAIL PROTECTED] wrote:


 Etrade Griffiths [EMAIL PROTECTED] wrote
  just finished developing my first app with wxPython and matplotlib
  and now
  trying to create an EXE file using PY2EXE for distribution.
  However, this
  is proving to be an extremely frustrating experience and I am making
  very
  little progress.  Are there any simple alternatives to PY2EXE for
  shipping Python apps to Windows machines?

 There are a few more sophisticated tools around but py2exe is
 usually considered the easy option.

 But are you sure you really need an EXE?
 The size of a bundled python install, which can be optionally
 loaded if not alteady there, is not excessive in modern PC
 software terms and many environments nowadays do not
 use pure exe's - VB, .NET, Java Smalltalk, etc

 So why not just ship Python? And if you writre a lot of code
 installing
 python will use up less memory in the long term since you won't
 have a copy of the interpreter hiding inside every app!

 Alan G.


 ___
 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] exception problems in socket programming

2006-11-15 Thread Chris Hengge

I ran this code based on yours:

import socket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
   s.connect(('something.com', 5000))
except socket.error, (value, message):
   if s:
   s.close()
   print Could not open socket:  + message
raw_input(\nPress any key)

And I got this result:
Could not open socket: getaddrinfo failed

Press any key

Do you need to put quotes around something.com like I did?

On 11/15/06, Vinay Reddy [EMAIL PROTECTED] wrote:


Hi,
I'm trying to do some simple network programming in Python, but am
stuck with exception problems. Here's the relevant code snippet:

self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  try:
 self.s.connect((something.com, 5000))
  except socket.error, (value, message):
 if self.s:
self.s.close()
 print Could not open socket:  + message
 sys.exit(1)

I was testing for a timeout exception (which is 60 seconds by
default), but after the timeout I get the following error:
  File ./client.py, line 54, in connect
except socket.error, (value, message):
ValueError: need more than 1 value to unpack

I googled and found something on ValueError, but I couldn't see how it
applied here.

I'd appreciate any help.

Thanks,
Vinay
___
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] Syntax when using classes question.

2006-11-11 Thread Chris Hengge
So why did you use two sets of parenthesis here?Are you completely sure you understand everything that's happening here? pyForge.promptForge.prompt()TypeError: unbound method prompt() must be called with promptForge instance as first argument (got nothing instead)
^ Thats why... I have to use :import pyForgepyForge.promptForge().promptDo you want just functions?I haven't seen your pyForge class, but if you're not using any OO features,like the magical 'self' or the different __repr__, __str__,
__getitems__, etc. methods,then why is it in a class in the first place, and not just functions?Because I was trying to get a grip on classes and OOP... =PpyForge for lack of a better description is kinda like my own mini-framework. It's basically all the methods(functions?) that I've basically rewritten in each of my python files that I grouped together into classes by functionality. For example, pyForge has class fileforge which has two methods, one for writing, and one for reading files. Each takes a few different parameters but it makes an entire block of code transparent so that when I'm trying to show someone my code at work its less to look at. There is a class for a console based splashscreen called promptForge which has a EULA mode enabled by bool and takes a few parameters. I've also got zipForge which is very similar to my fileForge, but zips/unzips. I might add a few more things that I've repeated... It was mainly an attempt at learning classes, and I wanted all my re-usable code to be centralized so I didn't keep opening scripts and cutting and pasting. 
On 11/10/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: As for saving memory.. I'm not particularily concerned since all my systems have 2gb... Also, before python I was writing C# database front ends (nothing amazing) and I'm not even going to compare python's 10mb overhead to
 .net's 45mb+. I was mostly just curious if it would save the memory in the same manner. As for using modules... I'm actually looking at my real code right now.. (need to not reply to these emails while at work when I can't
 really see the code) in my pyForge module (simple script to hold my common used objects basically) there is a class promptForge, that contains a method prompt -- I know this is a great name =P
 To call it: import pyForge # module name promptForge.prompt() # Class.method will tell me promptForge is undefined. so I use: promptForge().prompt() will tell me promptForge is undefined
Yeah, it's unidentified because it only exists in the imported module'snamespace. so I use: pyForge.promptForge().prompt() # module.class.methodSo why did you use two sets of parenthesis here?
Are you completely sure you understand everything that's happening here?pyForge. - now we're working in the module's namespace.promptForge - the class you're targeting in the pyForge namespace() - create an instance of the class using the __init__ method.
.prompt - get the method 'prompt' from the instance of the class youjust created.() - execute this method.So why are you creating an instance of promptForge here? this works. (I just did all this while writing this email.)
Yeah, it works, but is it necessary? When I use: import random random.random () #This does its thing... most modules only have module.whateverThisIs(params) in my code I've got 
module.class().method(params)... Am I not conforming to some sort of module standard?You're just creating an instance when you probably don't mean to. Are modules supposed to only be filled with methods,
No.Then they would be called functions :)methods are functions inside classes that act upon the class' datamembers (I.E. variables)They're different terms so that people will know what you're talking about.
 using the module file itself as the seperation layer in place of using a class?Yeah, do that if you want just functions.Do you want just functions?I haven't seen your pyForge class, but if you're not using any OO features,
like the magical 'self' or the different __repr__, __str__,__getitems__, etc. methods,then why is it in a class in the first place, and not just functions?You can have a module of functions if you want.
You can have a module of variables if you want.a module is just the same as having all the stuff declared in yourprogram, except you refer to it all by module name.#- config.pya = 1#-# 
test.pyimport configprint config.a#--etc. FYI... I dont know where it happened, but these last few e-mails are off tutor.Oops, yeah.This one is forwarded to tutor and if anyone wants to see
the previous discussion you can check the reply-stuff below.HTH,-Luke On 11/10/06, *Luke Paireepinart* [EMAIL PROTECTED] mailto:
[EMAIL PROTECTED] wrote: Chris Hengge wrote:  Alright, that all makes sense other then one part...  Okay! I'm shivering with anticipation :)
  I'm all for you saying to just use:  import module  module.class.method ()  I agree this code is easier on the eyes down the road

Re: [Tutor] Syntax when using classes question.

2006-11-11 Thread Chris Hengge
Oops... should have said this... pyForge.promptForge.prompt()TypeError: unbound method prompt() must be called with promptForge instance as first argument (got nothing instead)
^ Thats why... I have to use :import pyForgepyForge.promptForge().prompt()On 11/11/06, Chris Hengge 
[EMAIL PROTECTED] wrote:So why did you use two sets of parenthesis here?
Are you completely sure you understand everything that's happening here? pyForge.promptForge.prompt()TypeError: unbound method prompt() must be called with promptForge instance as first argument (got nothing instead)
^ Thats why... I have to use :import pyForgepyForge.promptForge().promptDo you want just functions?I haven't seen your pyForge class, but if you're not using any OO features,
like the magical 'self' or the different __repr__, __str__,
__getitems__, etc. methods,then why is it in a class in the first place, and not just functions?Because I was trying to get a grip on classes and OOP... =PpyForge for lack of a better description is kinda like my own mini-framework. It's basically all the methods(functions?) that I've basically rewritten in each of my python files that I grouped together into classes by functionality. For example, pyForge has class fileforge which has two methods, one for writing, and one for reading files. Each takes a few different parameters but it makes an entire block of code transparent so that when I'm trying to show someone my code at work its less to look at. There is a class for a console based splashscreen called promptForge which has a EULA mode enabled by bool and takes a few parameters. I've also got zipForge which is very similar to my fileForge, but zips/unzips. I might add a few more things that I've repeated... It was mainly an attempt at learning classes, and I wanted all my re-usable code to be centralized so I didn't keep opening scripts and cutting and pasting. 
On 11/10/06, Luke Paireepinart 
[EMAIL PROTECTED] wrote:
Chris Hengge wrote: As for saving memory.. I'm not particularily concerned since all my systems have 2gb... Also, before python I was writing C# database front ends (nothing amazing) and I'm not even going to compare python's 10mb overhead to
 .net's 45mb+. I was mostly just curious if it would save the memory in the same manner. As for using modules... I'm actually looking at my real code right now.. (need to not reply to these emails while at work when I can't
 really see the code) in my pyForge module (simple script to hold my common used objects basically) there is a class promptForge, that contains a method prompt -- I know this is a great name =P
 To call it: import pyForge # module name promptForge.prompt() # Class.method will tell me promptForge is undefined. so I use: promptForge().prompt() will tell me promptForge is undefined
Yeah, it's unidentified because it only exists in the imported module'snamespace. so I use: pyForge.promptForge().prompt() # module.class.methodSo why did you use two sets of parenthesis here?

Are you completely sure you understand everything that's happening here?pyForge. - now we're working in the module's namespace.promptForge - the class you're targeting in the pyForge namespace() - create an instance of the class using the __init__ method.
.prompt - get the method 'prompt' from the instance of the class youjust created.() - execute this method.So why are you creating an instance of promptForge here? this works. (I just did all this while writing this email.)
Yeah, it works, but is it necessary? When I use: import random random.random () #This does its thing... most modules only have module.whateverThisIs(params) in my code I've got 
module.class().method(params)... Am I not conforming to some sort of module standard?You're just creating an instance when you probably don't mean to. Are modules supposed to only be filled with methods,
No.Then they would be called functions :)methods are functions inside classes that act upon the class' datamembers (I.E. variables)They're different terms so that people will know what you're talking about.
 using the module file itself as the seperation layer in place of using a class?Yeah, do that if you want just functions.Do you want just functions?I haven't seen your pyForge class, but if you're not using any OO features,
like the magical 'self' or the different __repr__, __str__,__getitems__, etc. methods,then why is it in a class in the first place, and not just functions?You can have a module of functions if you want.

You can have a module of variables if you want.a module is just the same as having all the stuff declared in yourprogram, except you refer to it all by module name.#- config.pya = 1#-# 
test.pyimport configprint config.a#--etc. FYI... I dont know where it happened, but these last few e-mails are off tutor.Oops, yeah.This one is forwarded to tutor and if anyone wants to see
the previous discussion you can check the reply-stuff below.HTH,-Luke On 11/10/06, *Luke Paireepinart* 
[EMAIL

Re: [Tutor] Syntax when using classes question.

2006-11-11 Thread Chris Hengge
I guess I'm just lost as to the point of classes... Outside of using them to abstract a collection of methods that have similair roles I dont see the point.. But when I group similar methods together (promptForge is a bad example, but I've got class fileForge which has a few file writing or reading methods), people tell me its overkill (basicaly) =P 
On 11/11/06, Alan Gauld [EMAIL PROTECTED] wrote:
Chris,pyForge.promptForge.prompt() TypeError: unbound method prompt() must be called with promptForge instance as first argument (got nothing instead) ^ Thats why... I have to use :
 import pyForge pyForge.promptForge().prompt()I think the real issue that Luke was raising was why you are usingthat style.Basically you are creating an instance of pyForge just to call the
methodthen it gets deleted again (by garbage collection). Thats a veryinefficientfunction call!The normal usage of classes and objects is that you create aninstance and retain it, thus:
myForge = pyForge.promptForge()myForge.prompt()...# and use it againmyForge.prompt()Thus the myForge instance is retained until you are finished usingany of the methods.The reason for that is that the instance will hold the data used
by the methods and so if you delete it you delete the data too!For examplein your case you could have promptForge hold theprompt message you want to display. That could nbe initialisedin the constructor, thus you could have several promptForge
instances each with a different prompt message, lie this:class promptForge:def __init__(self.,msg = ? ): self.message = msg self.value = None# stores last input value
 def prompt(self):print self.message,self.value = raw_input()return self.valueAnd use it thus:yes_no = promptForge(Continue? [Y/N] )quit = promptForge(Hit Y to quit)
intValue = promptForge(Enter an integer between 0 and 9)if yes_no.prompt() in yY:for n in range(3):x = int(intValue.prompt())print xif quit.prompt
() in yY2: breakBut if you don't have any internal data, you don;t reallyneed instances...Now it looks like you have created some classes with noshared data just functions(methods). In that case you would
be better just using functions inside the module. Its easier touse and also has a lower resource usage and potentiallylower call overhead (no method lookup/dispatch)HTH,--Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___Tutor maillist-
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax when using classes question.

2006-11-11 Thread Chris Hengge
Thanks for the great feedback! I was missing the whole methods that share the same data aspect of a class.. Thats makes them MUCH more clear to understand. Thanks for both of you having the patience to help me figure this out =D Time for me to ditch the classes from my 
pyForge.py!On 11/11/06, Alan Gauld [EMAIL PROTECTED] wrote:
Chris,I guess I'm just lost as to the point of classes... Outside of usingthem to abstract a collection of methods that have similair rolesMost people get hung up on the data aspect of classes
and forget that the behaviour(the methods) are actuallythe most important bit. However you have focused somuch on the methods you haven't noticed the data.The point of classes is that they encapsulate data and the
functions that operate on that data. A classs that only hasfunctions is just a collection of functions that could sitequally well in a module. A class enables you to capturestate between method calls in data that is local and
unique to the instance. If there is no shared data betweenthe methods then there is little need for a class. (There area few exceptions to that rule but not many). You have tothink of the methods of a class as being the operations
on a set of shared data.Consider a string class; of what use would the strip() methodbe if there was no sequence of characters within the classto operate on? or the lower() method etc... Similarly for files.
If there was no file object then what would you read() orwrite() to? But when I group similar methods togetherA class is not a group of *similar* methods, it is a set of*related* methods - related through the data upon which
they operate. Think of a class as an object template, a noun.Think what things you can do to such an object.A common, although not always effective, technique foridentifying classes is to read (or write down if it doesn't
exist) a description of your problem or program. Underlinethe nouns. Those are your classes. Now pick out theverbs and attach them to the nouns. Those are your methods.Finally look at the adjectives, those are likely indicators of
attributes of your classes.Its simple and not always the best analysis technique butits a good way to start. promptForge is a bad example,As I hoped I'd shown a promptForge class would be
entirely appropriate if it had some data that related tothe methods. It could present a standard prompt message,apply consistent error checking, do datya conersions etc etc. people tell me its overkill
OOP can often be overkill, it is frequently abused.OOP is great for bigger programs and good for aiding resuse.But functions can be just as reusable where no intermediateor shared data is involved. If your programs are short there
is less likeliehood that you will find object useful. As yourprograms get longer objects rapidly become powerful tools.But don;t get hung up on them. They are not superior by divineright, they are just one more tool in your toolbox.
--Alan GauldAuthor of the Learn to Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax when using classes question.

2006-11-10 Thread Chris Hengge
is the following dummycode good practice? Or pythonic? or what? I'm just curious because there are several ways I've found to use libraries and classes...Method 1:from lib import classlib().class(param1, param2)
Method 2: (C Style?)from lib import classmyClass = class()myLib.class(param1, param2)Thanks for whatever clarity you can share!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-09 Thread Chris Hengge
Yes, I understand what a loop is, and there was a loop but I didn't write that code into my email because I didn't need commenting on it. Here is the code so its clear incase you really care =Pfrom PIL import Image
from PIL import ImageGrabimport timecapturedFrames = 100count = 0print \nInitializing Engine...newView = ImageGrab.grab()print Engine Initilized Successfully!
raw_input(Press any key to begin...)print \nInitializing capture cycle...startClock = time.clock()for i in range(capturedFrames): # Here is the loop I was timing that I commented is extremely slow using the method you suggested. It does work however. 
 oldView = newView newView = ImageGrab.grab() if oldView.tostring() != newView.tostring(): count = count + 1endClock = time.clock()totalTime = endClock - startClockcalculatedFPS = capturedFrames / totalTime
horRes = str(newView.getbbox()[2])verRes = str(newView.getbbox()[3])print Frame Resolution : %sx%s % (horRes.rjust(4), verRes.rjust(4))print Frames Captured : %s % str(capturedFrames).rjust(9)
print Capture Time (sec) : %s % str(totalTime)[:4].rjust(9)print Calculated FPS : %s % str(calculatedFPS)[:4].rjust(9)print Changes Registered : %s % str(count).rjust(9)
raw_input(\nPress Any Key...)On 11/8/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: alist = difference(image1,image2) a = [b for b in 
alist.getdata() if b != (0,0,0)] if len(a) != 0:print Not the same is much slower then (9x) if im1.tostring() != im2.tostring()print something changed!
 This loop itself is fairly slow by itself though.. I'm going to try and see if there is a faster way.Chris,are you sure you know what a loop is?The only loop here is in the list comprehension.
'if' is not a loop.'for' and 'while' are.In computer science, it's important to be clear in your use of terminology.It makes sense that my example was slow.I didn't really think to try converting them to strings.
Any time you're trying to compare pixel values, it's going to take a while,cause remember, a 1024X768 image has 786,432 different pixels.I think your tostring comparison may be your best bet.

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


Re: [Tutor] Questions about PIL

2006-11-09 Thread Chris Hengge
What I want to do with the data shouldn't really matter. I'm not completely sure what I want to do with the image data anyways, but for sake of arguement everything is happening in memory at this point, so 'objects' is correct. Images start in memory, and are being evaluated in memory, never written to disk.. 
On 11/8/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Thanks for the detailed examples again Luke. Sorry I wasn't more clear with my implimentation. The loop I was refering to was the one in the start of my post but using im.tostring
() instead. I saw an example to make a webcam motion detector that used tostring(), but couldn't get the program to see a difference.I'm glad the examples helped.See my other response about your use of the term 'loop.'
 As for just capturing a section of the screen. I'm not looking to make faster captures, so I think your sample was on the ball. Your example however wasn't quite what I had in mind when I was thinking up the
 question and again I take fault for this. I was thinking more of a way to create quadrants of the screenshot. (Or any number of area's) that I could independantly interact with. I know this isn't a CPU friendly
 task, but just humor me please =POnce again, you're not being explicit enough in explaining what you'retrying to do.Specifically, your sentence (Or any number of area's) that I couldindependently interact with
How are you trying to interact with them?Do you want them split into actual separate image files, into separateimage objects, or what?The crop method I showed you will do any kind of splitting you want,
you just have to think through what exactly you need to crop in anygiven situation.For example,(pseudocode)width = 1024/2height = 768/2image = load_image('imagename')quad1 = image.crop((0,0,width,height))
quad2 = image.crop((width,0,width,height))quad3 = image.crop((0,height,width,height))quad4 = image.crop((width,height,width,height))note that width and height are the w/h of the quadrants, not of the
image itself.since there are 4 quadrants (get it? quad = 4 ;)each width/height would be original_image_width or height * (.5)HTH,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which is the latest version of Python for windows

2006-11-09 Thread Chris Hengge
I've been trying to look for a roadmap or something from them that would show estimated product release dates. Does this not exist?On 11/9/06, Terry Carroll
 [EMAIL PROTECTED] wrote:On Thu, 9 Nov 2006, Simon Brunning wrote:
 On 11/9/06, Asrarahmed Kadri [EMAIL PROTECTED] wrote:  I am so sorry to disturb you. I hope u dont mind.  I cannot find the version 
2.5 for Active Python.Activestate is still on 2.4.3.I'm awaiting a 2.5 version ofActivePython, myself.You can install the Windows version of Python 2.5, but you'll have to addin a lot of the stuff you're accustomed to Activestate doing for you.
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


[Tutor] Looking for some constructive peer review.

2006-11-09 Thread Chris Hengge
I write this little IM style client the other night based on some sample socket and threading examples I found plus a little of my own twist just to make it more interesting.. I'd like some constructive peer review just to help me make sure I'm doing this correctly / well.
You can test it by connecting to localhost if you want to run the code to help with review. One thing I'd like to know how to do is fix the output to the screen. Currently it interrupts typing when a message is recieved which as I understand is because my typing a line is basically letting the client thread sleep, and recieving a message triggers the server thread while I'm typing... Maybe there is some sort of better thread management for this? Or is this just a limiting factor since I'm playing in the console world? The other issue I have is when the other person types DSC to end their session, I should be able to put the thread to sleep, or trash it or something so I dont have to close the app to use it again. It also isn't going through the entire 
I was hoping to actually make something more like an IRC server / client, but I'm not sure I've got this thing down well enough to try that. Thanks!from socket import *import Queue, threading, os 
class ServerThread ( threading.Thread ): def run ( self ): while True: client = clientPool.get() clientName = client[0].recv(1024) print '\n' + ('=' * 40)
 print 'Connection Established by %s...' % clientName client[0].send('Connection Established!') while True: try: data = ""
 except: print Connection to %s terminated! % clientName break if data: if 'DSC' not in data: print data
 else: print ('=' * 40) client[0].send('Connection Terminated...') print '\nClosed connection to %s... ' % clientName
 return False else: client[0].send('Closing connection.') return False client[0].close() class ClientThread ( 
threading.Thread ):  def run ( self ): print Type 'DSC' to disconnect... print '=' * 40 myServer = raw_input('Server Name / IP: ') myName = os.environ.items
()[1][1].title() server = socket(AF_INET, SOCK_STREAM) try: server.connect((myServer, 2000)) server.send(myName) msg = '' while True:
 data = ""> print data print '=' * 40 while msg != 'DSC': msg = raw_input() server.send(myName + ': ' + msg)
 data = ""> print data server.close() except: server.close() # Create our Queue:clientPool = Queue.Queue
 ( 0 )# Start threads:print '=' * 40print Initializing Listening Device...ServerThread().start()myPort = 2000myIP = gethostbyname(os.environ.items()[1][1])print Listening for %s on port %s % (myIP,myPort)
ClientThread().start()# Set up the server:myServer = socket(AF_INET, SOCK_STREAM)myServer.bind(('', myPort))myServer.listen(5)# Have the server serve forever:while True:
 clientPool.put(myServer.accept())
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for some constructive peer review.

2006-11-09 Thread Chris Hengge
Yeah, I'm trying to hold out on gui stuff at the moment. I'm trying to get a grasp on classes and threads at the moment because nothing I've made to date in python really calls for anything outside of what a console can offer. Kinda keeping it simple for now I guess... I'll probably rebuild this application with a gui in the not-so-far future though.. would make a great starter for gui's project. (I'm pretty good in C# with gui's so I might just go with IronPython so I can use the windows libs for the interface controls, well see =D )
As for the IRC style (as in I know I could just get a library, but I wouldn't really learn anything. I also know fairly well how IRC should act, so its a good model for my learning) project, I dont need to reinvent it, but basically a threaded multiuser experience would be cool... I'm also interested in programming the server (threaded project for more practice). My original trials with the code I posted for this thread where seperate client and server code, and I ran several threads so I could get multiple connections and print content to the server console from the client console, and then return fixed messages back, but I am not sure how I'd go about letting multiple users communicate to each other, or forward messages. Does this involve traversing threads? or sockets? or something else? Thanks. 
On 11/9/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: I write this little IM style client the other night based on some sample socket and threading examples I found plus a little of my own twist just to make it more interesting..
 I'd like some constructive peer review just to help me make sure I'm doing this correctly / well. You can test it by connecting to localhost if you want to run the code to help with review. One thing I'd like to know how to do is fix the
 output to the screen. Currently it interrupts typing when a message is recieved which as I understand is because my typing a line is basically letting the client thread sleep, and recieving a message
 triggers the server thread while I'm typing... Maybe there is some sort of better thread management for this? Or is this just a limiting factor since I'm playing in the console world? The other issue I have
 is when the other person types DSC to end their session, I should be able to put the thread to sleep, or trash it or something so I dont have to close the app to use it again. It also isn't going through the
 entire I was hoping to actually make something more like an IRC server / client, but I'm not sure I've got this thing down well enough to try that. Thanks!Sorry, I'm too tired to read your code right now.
A few things I'd like to point out...yeah, it's tough to show output and get input in the same consolewindow.A simple TKInter gui would not be all that hard to put together.Just a textbox and an entry widget.
wouldn't even need a 'send' button if you just bind 'enter' to the sendcommand from the entry widget.Also, IRC is not as complicated as you may think.The messages are allin ascii.Basically you just say
import socketsock = socket.socket()sock.connect(('irc.freenode.net',6667))sock.send(NICK Bob\r\n)sock.send(USER Bob 
irc.freenode.net bla :realname\r\n)sock.send(JOIN #test\r\n)sock.send(PRIVMSG #test HELLO!\r\n)sock.send(LEAVE #test\r\n)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
I'm trying to figure out how to compare im1 to im2 and recognize the difference. I dont care what the difference is... something likeif im1 is not im2: print Not sameI've tried im.tostring
() but that doesn't ever enter the loop either. ***Second question is this:Is there a way to divide the screen so I only grab maybe the lower right 200x200 pixels or some such?
Or possibly a way to seperate the image into a grid so I could just take the grid I wanted?Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions about PIL

2006-11-08 Thread Chris Hengge
Thanks for the detailed examples again Luke. Sorry I wasn't more clear with my implimentation. The loop I was refering to was the one in the start of my post but using im.tostring() instead. I saw an example to make a webcam motion detector that used tostring(), but couldn't get the program to see a difference.
As for just capturing a section of the screen. I'm not looking to make faster captures, so I think your sample was on the ball. Your example however wasn't quite what I had in mind when I was thinking up the question and again I take fault for this. I was thinking more of a way to create quadrants of the screenshot. (Or any number of area's) that I could independantly interact with. I know this isn't a CPU friendly task, but just humor me please =P
On 11/8/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: I'm trying to figure out how to compare im1 to im2 and recognize the difference. I dont care what the difference is... something like if im1 is not im2:
print Not sameHey, Chris.I'm supposing here that you are checking if the images are _visually_different,not if they are different objects or files.Remember when we were talking about the VNC?
Specifically, the linediff = ImageChops.difference(self.prevscr,self.currscr)that I sent to you?To sum it up, in the ImageChops module,(which comes with PIL)there's a function called difference that returns a list with the
different pixel values for each coordinate of the image.I would suggest the following course of action:1) Check if the file format is the same.If it's a PNG vs a JPG vs aBMP or whatever, the compression routines
will have an effect on the image, so your difference test won't work.2) Check if the resolution is the same.If one's 640X480 and theother's 800X600, you're going to have a difference.3) do the following ( or something equivalent):
from ImageChops import differencealist = difference(image1,image2)a = [b for b in alist.getdata() if b != (0,0,0)]if len(a) != 0:print Not the same I've tried im.tostring
 () but that doesn't ever enter the loop either.I have no idea what 'that doesn't ever enter the loop' means. ***
 Second question is this: Is there a way to divide the screen so I only grab maybe the lower right 200x200 pixels or some such? Or possibly a way to seperate the image into a grid so I could just
 take the grid I wanted?You're referring to when you're using ImageGrab.grab() I assume,but you should have said this.It's better to be explicit thanimplicit, after all :)Yes, it's possible to grab only part of the screen.
ImageGrab.grab(), if you read the help information on it,says that it takes a bbox argument with a default value of none.so override this value with your own bounding box.I.E. ImageGrab.grab((0,0,200,200)) will grab a square from the
upper-left corner of the screen.Separating the image into a grid would also be quite easy.If you have an Image instance, just use its crop method to get the areayou want.example:import Image
im = Image.open('test.bmp')im.crop((0,0,200,200)).save('test.bmp')Should overwrite the old image with a new one.Also, note that the code:ImageGrab.grab().crop((0,0,200,200))is equivalent to
ImageGrab.grab((0,0,200,200))In other words,the ImageGrab always takesa screenshot of the entire working area.so if you're expecting this bounding-box to speed anything up, it won't.HTH,-Luke
 Thanks!  ___ 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] Questions about PIL

2006-11-08 Thread Chris Hengge
I tried the .tostring again, seems to be working using != instead of is not... Thanks for that thread link, very helpful. I'll look more into im.transform and see what I can come up with. I'm not sure I fully understand what it does, but I'm reading it as I'll remove the wanted section of im and trash the rest. I'm more-so looking for a way to maybe divide an image into quantrants for individual manipulation without having to split and rebuild the image. 
My goal with these two features is I'd like to create a way to compare an image for changes based on an area of the image, rather then the entire image. Lets use the quadrants for example (mental code).1,2
3,4^ this is how the quad appears on the image (upper left, upper right, etc...)for space in quad: if newpic[space].tostring() != oldpic[space].tostring(): oldpic[space] = newpic[space]
 else : # Dont really care because this [space] isn't important.  On 11/8/06, Danny Yoo 
[EMAIL PROTECTED] wrote:On Wed, 8 Nov 2006, Chris Hengge wrote:
 I'm trying to figure out how to compare im1 to im2 and recognize the difference. I dont care what the difference is... something like if im1 is not im2:print Not same
Do not use 'is' here.It is not doing any kind of equality testing atall.We had a discussion about 'is' just a few days ago: 
http://mail.python.org/pipermail/tutor/2006-November/050680.htmlAccording to: http://www.pythonware.com/library/pil/handbook/image.htm
the im.getdata() function looks interesting. I've tried im.tostring() but that doesn't ever enter the loop either.This should have worked.I'm not sure if you tried comparingtwo strings using 'is' or not.
 Second question is this: Is there a way to divide the screen so I only grab maybe the lower right 200x200 pixels or some such? Or possibly a way to seperate the image into a grid so I could just take the
 grid I wanted?im.transform() from the documentation link above looks relevant.Is thatwhat you're looking for?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars (was: Amazing power of Regular Expressions...)

2006-11-06 Thread Chris Hengge
Wow... I had to click this e-mail just because I saw the first posts on the mentioned thread and could see it turning for the worst..  I'm serious, if you think ^[0-9A-Za-z_.-]*$ is unclear and complex, go away
 and relearn regales. Michael.If this is your method to helping people, you should be the one to step back and go away. While your at it, go an take an educated look at debates.. You might learn that your tactics for trying to sway your side of the opinion are harsh and completely self killing. Any point you were trying to make just became invalid because of this childish b/s. 
On 11/6/06, Carroll, Barry [EMAIL PROTECTED] wrote:
Greetings, all: -Original Message- Date: Mon, 6 Nov 2006 10:32:32 + From: Michael Sparks [EMAIL PROTECTED] Subject: Re: [Tutor] Amazing power of Regular Expressions...
 To: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain;charset=iso-8859-1
 On Monday 06 November 2006 01:08, Alan Gauld wrote:  While using a dictionary is probably overkill, so is a rage. No, in this case it's absolutely the right choice.
  A simple string holding all characters and an 'in' test wouldprobably  be both easier to read and faster. I'm stunned you think this. It's precisely this sort of naivete that baffles
 me with regard to regales.  Which kind of illustrates the point of the thread I think! :-) Actually, no, it doesn't.snip I'm serious, if you think ^[0-9A-Za-z_.-]*$ is unclear and complex, go
 away and relearn regales. Michael.With the final sentence above, this thread has ceased to be anintellectual discussion and become a religious argument.Until then, I
was enjoying an informative discussion by knowledgeable people on atopic of considerable interest.Now I'm upset by the implications ofthe statement and embarrassed on behalf of the writer.When a person his so convinced of his/her rightness that they feel
justified in insulting those in opposition, that person has substitutedflaming for advocacy.They have also, in my opinion, seriously weakenedtheir position on the subject.Why would someone resort to such an
attack if they were, in fact, correct?I am disappointed to see such behavior on this list, and I hope it'soccurrence will continue to be vanishingly small.Regards,Barry
[EMAIL PROTECTED]541-302-1107We who cut mere stones must always be envisioning cathedrals.-Quarry worker's creed___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Print Screen

2006-11-04 Thread Chris Hengge
Wow, that hasn't come up in my searching, thanks! Looks like you are right and the project is dead, but the author did toss there code up for viewing so I can stumble around a bit there. 
On 11/3/06, Jonathon Sisson [EMAIL PROTECTED] wrote:
Chris,I don't know if this has been mentioned yet, but this site might be useful:http://bdash.net.nz/blog/2003/12/24/python-vnc-client/
The code base has (last I heard) fallen stagnant, but it may very wellbe worth a look as a starting point for your VNC project idea.JonathonChris Hengge wrote: Wow.. I have visions of writing a little wanna-be VNC client/server now
 using the ImageGrab.grab() =D This ImageGrab trick does exactly what I wanted. Thanks for the tip! Actually, I want to write a little package for the learning experience sometime over the holidays (plus I use VNC fairly often), but I can't
 find any direction, or any already made packages for python for the VNC protocol (no libs?). On 11/2/06, *Luke Paireepinart* [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote: Anyone know of a way to capture special keys like Print Screen?
 I have a small script to grab all they keycodes, but it doesn't seem to catch several keys on the keyboard. I've got a utility that I'd like to be able to automagically get a screenshot when something goes
 wrong so I dont have to hope the user can re-create the error. Universal support would be best, but WinXP is the main OS
 I'm not exactly sure what you want here :-) but if you want to capture when the 'Print Screen' key (or any other key) has actually been pressed, try pyHook. Note: pyHook only works on Windows!
 Also note that if you want all of the keypresses, but you _don't_ care about the application with focus receiving the input, you can do a complete key grab using TKInter or
 Pygame, and probably the other GUI packages too. But, like I said, if you were, for example, typing an e-mail and you started a script that did a complete grab like this, you'd no longer be
 able to type into the e-mail window.Using pyHook, your program could see all the keypresses, but they'd also still be sent to the e-mail program. Actually, I've never tried it, but I'm pretty sure that's how the GUI
 packages' key capturing works. You may be asking 'well, it sounds like pyHook does a better job of this anyway!' Yeah, you're right. However, as Alan exclaimed, pyHook works only on Windows!
 So the solution I offered would be more portable. Hope that helps, -Luke 
 ___ 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] Print Screen

2006-11-03 Thread Chris Hengge
Wow.. I have visions of writing a little wanna-be VNC client/server now using the ImageGrab.grab() =DThis ImageGrab trick does exactly what I wanted. Thanks for the tip!Actually, I want to write a little package for the learning experience sometime over the holidays (plus I use VNC fairly often), but I can't find any direction, or any already made packages for python for the VNC protocol (no libs?).
On 11/2/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
 Anyone know of a way to capture special keys like Print Screen? I have a small script to grab all they keycodes, but it doesn't seem to catch several keys on the keyboard. I've got a utility that I'd like to
 be able to automagically get a screenshot when something goes wrong so I dont have to hope the user can re-create the error. Universal support would be best, but WinXP is the main OS
 I'm not exactly sure what you want here :-) but if you want to capture when the 'Print Screen' key (or any other key) has actually been pressed, try pyHook. Note: pyHook only works on Windows!
Also note that if you want all of the keypresses, but you _don't_ careabout the application with focusreceiving the input, you can do a complete key grab using TKInter orPygame, and probably the other GUI packages too.
But, like I said, if you were, for example, typing an e-mail and youstarted a script that did a complete grab like this, you'd no longer beable to typeinto the e-mail window.Using pyHook, your program could see all the
keypresses, but they'd also still be sent to the e-mail program.Actually, I've never tried it, but I'm pretty sure that's how the GUIpackages' key capturing works.You may be asking 'well, it sounds like pyHook does a better job of this
anyway!'Yeah, you're right.However, as Alan exclaimed, pyHook works only on Windows!So the solution I offered would be more portable.Hope that helps,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Print Screen

2006-11-03 Thread Chris Hengge
Oh wow! That is great trick for lowering network requirements. Have you actually implimented that into a working app for test? You could shave a bit more from the bandwidth using that trick if you locked to a specific window for transfer *thinking blinking tray icons etc would get stripped*. How are you doing the intelligent transfer? Did you setup a grid on the screen and only update if gridX has changes? Other then that, are there any resources you can share for getting me started with my own VNC? Or do you by chance have any design docs you created/followed I could review to get an idea of the process for this? I'm thinking I'll probably have to find something in another language and just try to duplicate it with python to get me started. 
On 11/3/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Wow.. I have visions of writing a little wanna-be VNC client/server now using the ImageGrab.grab() =D This ImageGrab trick does exactly what I wanted. Thanks for the tip!
 Actually, I want to write a little package for the learning experience sometime over the holidays (plus I use VNC fairly often), but I can't find any direction, or any already made packages for python for the
 VNC protocol (no libs?).Heh, I was actually writing my own VNC, that's when I ran into theImageGrab function.I also did something cool, which is :self.prevscr = self.currscrself.currscr
 = ImageGrab.grab().resize((800,600))diff = ImageChops.difference(self.prevscr,self.currscr)Obviously you need a currscr before you start, which I declared duringthe initialization of the class.
The cool part of this is that the ImageChops difference will returnblack pixels in any area of the screen that hasn't changed.so you can just send the changed parts over the network (if you have agood algorithm to discard the unchanged portions).
Would be much faster than sending the whole screen every frame, obviously.Not CPU-faster, but network-faster.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI with Designer

2006-11-03 Thread Chris Hengge
I vouch for the SPE with wxGlade and XRC! (packaged together with IDE)On 11/3/06, Carlos Daniel Ruvalcaba Valenzuela 
[EMAIL PROTECTED] wrote:wxPython is good for cross-platform stuff and has a few gui designers
(Boa Constructor and others comes to mind), I don't know much aboutPyQT state in this, but PyGtk + Glade (Gui Designer) is a very goodcombo.Is about choise, I suggest you to do some simple tests with everything
until you find something to be confortable with.* PyGtk + Glade* Boa Contructor* SPE + wxPythonOn 11/3/06, Todd Dahl [EMAIL PROTECTED] wrote:
 I am wanting to get into some GUI coding with Python and have heard about PyQT and wxPython. Now I am definately not looking for some type of holy war but can anyone give me a good reason to pick one over the other.
 Also I would like to have a designer with it or a seperate designer that could be used with either. I plan on coding in Windows XP. Thanks, -Todd ___
 Tutor maillist-Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] GUI with Designer

2006-11-03 Thread Chris Hengge
Well, I use SPE which comes with wxGlade and XRC. For the small amount of gui I've done with python I think SPE offers the best IDE coder experience (coming from a VS world). The tools make sense to me.wxGlade is a GUI designer written in Python with the popular GUI toolkit 
wxPython,
that helps you create wxWidgets/wxPython user interfaces. At the moment
it can generate Python, C++, Perl and XRC (wxWidgets' XML resources)
code.XRC(wxWidgets' XML resources) is nice because it allows you to abstract your interface design (think of any program that uses XML to format skins). Overall, I think everyone using python should give SPE a try, even without gui programming its a great tool for writing code. It's free, and written in python using wxPython.. Stani (the Dev) is a great person for helping out with questions on using his package, he puts out regular updates and fixes. He's got some help from a few other people so its packaged in .exe, .rpm and standalone .zip formats. It's also on the standard repo's for Ubuntu. 
If you like it, be kind and toss the guy a few bucks for his efforts. If you do, you will get your name mentioned on the SPE news page and get a nice copy of his user manual (pdf).If you want to know more about SPE, check out:
http://www.serpia.org/speor video demonstations at:http://showmedo.com/videos/series?name=PythonDevelopmentWithSPE
On 11/3/06, Dick Moores [EMAIL PROTECTED] wrote:


At 02:10 PM 11/3/2006, Chris Hengge wrote:
I vouch for the SPE with wxGlade
and XRC! (packaged together with IDE)
I'd be very interested in hearing why you suggest that
combination.
Dick Moores

On 11/3/06, Carlos Daniel
Ruvalcaba Valenzuela 
[EMAIL PROTECTED] wrote:


wxPython is good for cross-platform stuff and has a few gui designers


(Boa Constructor and others comes to mind), I don't know much
about

PyQT state in this, but PyGtk + Glade (Gui Designer) is a very
good

combo.

Is about choise, I suggest you to do some simple tests with
everything 

until you find something to be confortable with.

* PyGtk + Glade

* Boa Contructor

* SPE + wxPython

On 11/3/06, Todd Dahl
[EMAIL PROTECTED]
wrote:

 I am wanting to get into some GUI coding with Python and have
heard about

 PyQT and wxPython. Now I am definately not looking for some type
of holy war

 but can anyone give me a good reason to pick one over the other.




 Also I would like to have a designer with it or a seperate
designer that

 could be used with either. I plan on coding in Windows XP.



 Thanks,



 -Todd



 ___ 

 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 maillist - Tutor@python.org

http://mail.python.org/mailman/listinfo/tutor




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


[Tutor] Print Screen

2006-11-02 Thread Chris Hengge
I posted this in a similar thread a few days ago, and no replies so I think it needs its own listing. Anyone know of a way to capture special keys like Print Screen?I
have a small script to grab all they keycodes, but it doesn't seem to
catch several keys on the keyboard. I've got a utility that I'd like to
be able to automagically get a screenshot when something goes wrong so
I dont have to hope the user can re-create the error. Universal support
would be best, but WinXP is the main OSThanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to capture 'Ctrl+c' in Python

2006-11-02 Thread Chris Hengge
I've got your code at home, and I know it picks up shift and ctrl modified items, but it wont register print screen (among a few others). I can post the code I have at home later if you want to verify it. I've been given a few methods to try in my other thread I just started on here which are more practical, but I'm still interested in this. 
On 11/2/06, Alan Gauld [EMAIL PROTECTED] wrote:
Chris Hengge [EMAIL PROTECTED] wrote Do you by chance know of a way to capture special keys like Print Screen?Try the key capture code in my Event Driven topic.
So far as I know it works for all keys including the special ones.It also points out that those keys have a two part code...--Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___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] How to capture 'Ctrl+c' in Python

2006-11-02 Thread Chris Hengge
I'm not sure where I got this from, but I think its from your site.. import msvcrtdef doKeyEvent(key): if key == '\x00' or key == '\xe0': # non ASCII key = msvcrt.getch() # fetch second character
 print ord(key)def doQuitEvent(key): raise SystemExit# First, clear the screen of clutter then warn the user # of what to do to quitlines = 25 # set to number of lines in console
for line in range(lines): printprint Hit space to end...print# Now mainloop runs foreverwhile True: ky = msvcrt.getch() length = len(ky) if length != 0:
 # send events to event handling functions if ky ==  : # check for quit event doQuitEvent(ky) else:  doKeyEvent(ky)On 11/2/06, 
Alan Gauld [EMAIL PROTECTED] wrote:
Chris Hengge [EMAIL PROTECTED] wrote Do you by chance know of a way to capture special keys like Print Screen?Try the key capture code in my Event Driven topic.
So far as I know it works for all keys including the special ones.It also points out that those keys have a two part code...--Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___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] How to capture 'Ctrl+c' in Python

2006-11-02 Thread Chris Hengge
Nevermind, I just realised my problem with the script I just sent. I'm using a laptop right now and the print screen key is FN+ Insert FN isn't mappable. Works fine on an external keyboard, so I guess I'll try one of the other recommendations. 
Thanks alot for the time guys. On 11/2/06, Chris Hengge [EMAIL PROTECTED] wrote:
I'm not sure where I got this from, but I think its from your site.. import msvcrtdef doKeyEvent(key): if key == '\x00' or key == '\xe0': # non ASCII key = msvcrt.getch() # fetch second character
 print ord(key)def doQuitEvent(key): raise SystemExit# First, clear the screen of clutter then warn the user # of what to do to quitlines = 25 # set to number of lines in console

for line in range(lines): printprint Hit space to end...print# Now mainloop runs foreverwhile True: ky = msvcrt.getch() length = len(ky) if length != 0:

 # send events to event handling functions if ky ==  : # check for quit event doQuitEvent(ky) else:  doKeyEvent(ky)
On 11/2/06, 
Alan Gauld [EMAIL PROTECTED] wrote:

Chris Hengge [EMAIL PROTECTED] wrote Do you by chance know of a way to capture special keys like Print
 Screen?Try the key capture code in my Event Driven topic.
So far as I know it works for all keys including the special ones.It also points out that those keys have a two part code...--Alan GauldAuthor of the Learn to Program web site

http://www.freenetpages.co.uk/hp/alan.gauld___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] One million and counting

2006-10-31 Thread Chris Hengge
Very cool! Congrats!On 10/31/06, Alan Gauld [EMAIL PROTECTED] wrote:
Hi folks,In just thought I'd mention that my web tutor has now passedthe million visitors mark. Thanks to all those on the tutorlist who have paid a visit.Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___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] Using sys.exit()

2006-10-30 Thread Chris Hengge
Try using SPE, I've really liked it for some of extra features inside it like TODO tags that are automanaged. Also, its written in python, so thats kinda cool factor. It's also free. 
On 10/30/06, Dick Moores [EMAIL PROTECTED] wrote:
At 05:06 PM 10/30/2006, Dick Moores wrote:I'd like to know how to use sys.exit() to quit a program.Here's a simple example:import sysc = 0while True:c += 1
if c  1: sys.exit()Now, this will certainly exit, but not without a lot of extra noise.Is there a way to use it the way I want to? Maybe with an argument?I'm writing a script, which in a couple of places I can't use break to quit.
I just found this:http://www.velocityreviews.com/forums/t359590-how-to-terminate-a-main-script.html
So the noise from sys.exit() is from using it inside Wing IDE. Atthe command line, the exit is silent.Sorry for the disturbance.DickThanks,Dick Moores
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


[Tutor] VNC library for python

2006-10-28 Thread Chris Hengge
Does this exist? I see projects talking about writing viewers in python, and talking about their flaws or potential, but I've not seen a single library.Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why is this only catching one occurance?

2006-10-27 Thread Chris Hengge
Here is my code:for unWantedItem in directoryList: try: if hex in unWantedItem.lower(): if not bmc in unWantedItem.lower(): print unWantedItem +  removed!
 directoryList.remove(unWantedItem)This only seems to loop through once, and removes 1 of 2 occurances from this list that should be captured. Should for keep the list going through each instance?
Thanks alot. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is this only catching one occurance?

2006-10-27 Thread Chris Hengge
Thats for this very humorous reply =DOn 10/26/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Here is my code: for unWantedItem in directoryList: try:
 if hex in unWantedItem.lower(): if not bmc in unWantedItem.lower():print unWantedItem +  removed!
directoryList.remove(unWantedItem) This only seems to loop through once, and removes 1 of 2 occurances from this list that should be captured. Should for keep the list
 going through each instance?You're removing stuff from something you're iterating over!*slaps your fingers with a ruler*Make a copy of the list!HTH,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is this only catching one occurance?

2006-10-27 Thread Chris Hengge
I've tried to use your example:for unWantedItem in directoryList[,,-1]:but I get an error:for unWantedItem in directoryList[,,-1]:  ^SyntaxError: invalid syntax
I understand what you are saying to do, and it makes sense, but I'm not sure how to impliment it. On 10/27/06, Bob Gailer 
[EMAIL PROTECTED] wrote:Chris Hengge wrote: Here is my code: for unWantedItem in directoryList:
 try: if hex in unWantedItem.lower(): if not bmc in unWantedItem.lower():print unWantedItem +  removed!
directoryList.remove(unWantedItem) This only seems to loop through once, and removes 1 of 2 occurances from this list that should be captured. Should for keep the list
 going through each instance?for goes thru the list accessing item[0], item[1], item[2], etc. Let'ssay for is on item[1] and you remove item[1]. All the subsequent itemsmove left, so item[2] becomes item[1], item[3] becomes item[2], etc.
for then steps to item[2], skipping the original item[2].There are several ways around this. The easiest is to process the listbackwards: for unWantedItem in directoryList[,,-1]:--Bob Gailer
510-978-4454
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is this only catching one occurance?

2006-10-27 Thread Chris Hengge
That was supposed to say Thanks for this but I was in a hurry.Anyways, here is my solution:# Remove any copies of .hex that aren't BMC for foundItem in directoryList: try:
 if .hex in foundItem.lower(): if bmc in foundItem.lower(): wantedList.append(foundItem) else: 
 print foundItem +  removed! else: wantedList.append(foundItem) except: print Failed to strip excess hex files.
On 10/27/06, Chris Hengge [EMAIL PROTECTED] wrote:
Thats for this very humorous reply =DOn 10/26/06, Luke Paireepinart 
[EMAIL PROTECTED] wrote:
Chris Hengge wrote: Here is my code: for unWantedItem in directoryList:
 try:
 if hex in unWantedItem.lower(): if not bmc in unWantedItem.lower():print unWantedItem +  removed!

directoryList.remove(unWantedItem) This only seems to loop through once, and removes 1 of 2 occurances from this list that should be captured. Should for keep the list
 going through each instance?You're removing stuff from something you're iterating over!*slaps your fingers with a ruler*Make a copy of the list!HTH,-Luke



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


Re: [Tutor] New to programming and Python

2006-10-26 Thread Chris Hengge
I'm sure I speak for us all when I ask what sort of things are giving you problems? Maybe that would help us point you in the right direction. Good Luck!On 10/25/06, 
Jorge Azedo [EMAIL PROTECTED] wrote:
Hi guys ( and gals )I'm totally new to the whole programming scene (I decided to enter itfor many reasons, one of which is the fact that I *want* to know how toprogram my computer) and I decided to start out with Python. I'm reading
lots of tutorials on it, trying to understand how to work with it, butfor some reason or another, it all seems a great mess to me. Am I doingsomething wrong? Also, can anyone give me any pointers on how to start
working with Python?Thanks in advance for any help you can give me- Jorge___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] OOP and Python.. a gentle remark

2006-10-25 Thread Chris Hengge
I dont know about the rest of you, but this thread posting from Alan cleared up some fuzzyness I've had about classes. /me is happier using this. instead of self. =DGreat post!
On 10/25/06, Alan Gauld [EMAIL PROTECTED] wrote:
Asrarahmed Kadri [EMAIL PROTECTED] wrote Why is it necessary to explicity use self argument in the class functionsBecause Guido made it that way. :-)
But he did it for good reasons which others have pointed out already.Although languages like C++ and Java use implicit object references,you can make them explicit with the 'this' keyword and most industrial
coding standards mandate that 'this' be used when referencing classlevel variables inside methods. As in so many things Python simplytakes best practice and makes it mandatory. the function? Isnt it ? (the use of 'self' keyword really confuses
 me. andIf its the actual term 'self' then you can change it to anythingyou prefer. C++/Java programmers might prefer 'this', someothers have used 'my':class C:def __init__(my, aValue):
 my.value = aValueis perfectly valid Python. to make matter worse the variables can be accessed from outside teh class. Isnt it a violation of the OOP principle of ENCAPSULATION)
The original OOP concept of encapsulation refers to the abilityto bind functions and data together in a single unit - a class orobject - and had nothing to do with data hiding which is the abilityto conceal the implementation details behind an API.
It was only after C++ came out with its gazillion accesscontrols (public, private, protected, friend etc) that people startedto confuse data hiding and encapsulation. Many early OOPlanguages (most Lisps included) do not offer explicit or strict
data hiding. Also please let me know hwo can we declare PRIVATE VARIABLES in Python...??Why do you think you need them?Do you frequently hit bugs because you couldn't resist theurge to access members directly? While there can be problems
with badly behaved programmers on large projects, in thethings Python is typically used for its very rarely a problem.And it can add significantly to the complexity of the codewhen you try to derive a class from one with private data.
Very few designers are sufficiently ppsychic to predictexactly how all future users will want to modify their class!The result is they supply get/set methods for all data whichare simply pass through methods. In doing so they
completely annull any benefit of private members andintroduce potential performance problems.HTH,--Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___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] Best way to replace items in a list.

2006-10-21 Thread Chris Hengge
I like it because it different.. and it reads cleanly... =PAs far as the first occurance.. I'm not concerned about checking extra, because the first occurance is the only one I should ever need. 
On 10/20/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: I'm trying to build a little piece of code that replaces an item in a list. Here is a sample of what I'd like to do. str = This was replaced
 ff item in list:replace item with str I know I can do list.remove(item), but how do I place str back into that exact location? Is this how / best way?This is almost definitely not the best way to do that, though it depends
what results you're looking for.This way will only replace the first occurrence of the item.I don't know why you like the 'if item in ...' syntax so much ( ;) ),but you could do this with a loop pretty easily.
#examplefor index,item in enumerate(lst):if item == 'Item To Replace': lst[index] = 'Replaced!'#HTH,-Luke if item in list:loc = list.index(item)
list.remove(item)list.insert(loc, str) Thanks.  ___
 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] My first real python project: LOLLERSKATES

2006-10-21 Thread Chris Hengge
All I can say to this... LOLLERSKATES =DOn 10/20/06, Tracy R Reed [EMAIL PROTECTED] wrote:
-BEGIN PGP SIGNED MESSAGE-Hash: SHA1I have been a sysadmin for quite a while now and used to do a lot of
perl. I haven't done much programming at all in the last couple of yearsbut have been meaning to dump perl for python anyhow (for the usualreasons) and have finally gotten around to doing it.The first itch that I wanted to scratch was something to help me find
anomalies in our system logs. We have a lot of servers and need someautomation for watching over them including logfiles. I have usedlogwatch and logcheck but they are both too complicated for what Ireally need not to mention practically unmaintained these days. So I
decided to write my own.Features I wanted were:1. A basic grep -v sort of functionality on the logfile where I have afile full of regexes/lines to be ignored that are applied to thelogfiles to filter everything uninteresting out and whatever is left
gets emailed to the admin.2. A sort of macro system where I can substitute nasty long commonlyused regexes in my filter/ignore file with something more easily readand typed.3. Simplicity. Logcheck had several different levels of logfile events
which it could report back on and if you wanted something ignored youhad to put it in the right config file for whatever level it was poppingup in. This drove me nuts because I often got the wrong one. Logwatch
tries to analyze your logs and provide various summaries and statisticsand other things I don't care about. I just want to see the interestinglines from the logfile.My code seems to have all of the above and a silly name as well:
http://ultraviolet.org/Members/treed/lollerskatesIt has a list of logfiles to look at, a list of regexes to compare toeach line to know what is uninteresting and to filter out/ignore, and
emails anything left to the admin, and a simple macro facility.I would appreciate it if anyone interested would download and critiquemy code. Am I doing anything terribly un-pythonic?Questions/problems/TODO's:
This is a fairly simple structured programming implementation. No OO.Should I be using some classes somewhere?The config file is just a module which I import which causes all of myconfigs to become globals. Globals are bad. Is there a better way or
would just about anything else be overkill? A singleton config class orsomething? Overkill?I have several loops in this code for processing the logfiles. I oncetried to convert these for loops to list comprehensions and totally
confused myself and backed out the change (yeay svn!). Is there anybenefit to list comprehensions in this case?I would kinda like to play with unit tests. Not sure how I wouldconstruct unit tests for this. And again, perhaps overkill. But some
people tell me you should write the unit tests before you even begincoding and code until the tests are satisfied. So even on a smallproject you would have tests. I run into a couple nasty bugs I createdwhich caused the script to never return anything from the logfile (so
you don't immediately realize something is broken) where I thought Itsure would be nice to have a test to catch that if it ever happens again.Stuff tends to build up in the ignore file. If a line is typo'd and
never gets used/matched you will never know. If a service is no longerrunning that we had lines in the ignore file for they will be thereforever unused. I don't like this sort of clutter. I am really tempted
to somehow make it keep track of when a rule is matched and if itdoesn't match in a whole month email the admin because it doesn't needto be there. I am wondering if this is needless complexity or somethinguseful. I think it could be useful. If so, how to save the info on when
each line was last matched? I am thinking maybe of just having adictionary keyed on the compiled regex object and the value being atuple of the uncompiled regex string from the ignore file and a datestring containing when it was last matched and pickling this data
structure to disk to be read in each start of the program. Comments?I am currently pushing this code to around 20 systems with cfengineusing just one ignore file for them all. If I use the scheme mentioned
in the previous paragraph to alert me of unused rules in the ignore file I will get tons of such messages from machines not running a servicethat other machines of mine are. I guess that means perhaps I should
split my ignore file out into ignore.hostname.conf or something likethat so there is a separate one for each host.Anyhow, I appreciate any feedback on this potentially very handysysadmin tool. Thanks in advance!
- --Tracy R Reedhttp://ultraviolet.org-BEGIN PGP SIGNATURE-Version: GnuPG v1.4.5 (GNU/Linux)Comment: Using GnuPG with Fedora - 
http://enigmail.mozdev.orgiD8DBQFFObPK9PIYKZYVAq0RAiflAJ9jprJgGnNRXkB+nKsljFUsAUGnFwCgiJg/M3U24dNDtH+hAgSh7kZ40hQ==nxQS-END PGP SIGNATURE-___
Tutor 

[Tutor] Best way to replace items in a list.

2006-10-20 Thread Chris Hengge
I'm trying to build a little piece of code that replaces an item in a list. Here is a sample of what I'd like to do.str = This was replacedff item in list: replace item with str
I know I can do list.remove(item), but how do I place str back into that exact location?Is this how / best way?if item in list: loc = list.index(item) list.remove(item) list.insert(loc, str)
Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Generic Application Frameworks?

2006-10-19 Thread Chris Hengge
I was curious if there are any frameworks around like carbon/razor implimented in razor? Here's a link with information about razor (.net 1.1 versin of carbon)
http://www.codeproject.com/cs/design/razorpt1.aspIf not, is there any reason why? (limitation of python?)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of found item in list.

2006-10-19 Thread Chris Hengge
This is the solution I came up with.  for dirItem in directoryList: directoryListLower.append(dirItem.lower()) #---Loop for file name comparison. for item in lineList: # For every item in the 'lineList'
 if item in directoryList: # If the item is also in 'directoryList' # Print out so I know it is found. print match.ljust(20) + item.ljust(20) \ + directoryList[directoryList.index
(item)] else: # If it isn't found, print what didn't match. # Use the lowercase form from each list to find what didn't match. if item.lower() in directoryListLower:  # Print out so I can see why it failed. 
 print fail.ljust(20) + item.ljust(20) + \ directoryList[directoryListLower.index(item.lower())] os.rename(pathName + \ directoryList[directoryListLower.index
(item.lower())], \ pathName + item)On 10/18/06, Luke Paireepinart [EMAIL PROTECTED]
 wrote:Chris Hengge wrote: If that last post to Luke didn't clear anything up.. lets try this at
 a smaller level... I'm going to ignore the fact that my program already renames the file properly.. I have list1 of filenames I have list2 of filenames Item from list 1 needs to be found in list2, but I can't change cases,
 because thats what I'm looking for. I suppose, I could .sort each list after chopping the extra files names out of list2 that aren't in list1. then all I have to do is list1[count] = list2[count]
 What I'd like to know, is why my program works, if I can't get it to display the proper filename in the 3rd output column. I guess os.rename(notcasesensitive, iscasesensitive) ?I doubt 
os.rename is case insensitive for the first argument.Okay, here is what you're trying to do.Assuming I haven't seen your code before and I'm writing it from scratch.I have a list of filenames.list1 = ['
a.exe', 'b.exe', 'c.exe', 'e.exe']I could've read these in from a file, or anything.It doesn't matter where they came from.The important thing is that they have the case that I want.Say I also have another list.
list2 = ['a.ExE',' B.exe', 'C.EXE', 'd.EXE','E.eXe']we got this list maybe from a directory listing or something.Itdoesn't matter.What we're trying to do is: apply any case changes that are necessary to
make all of list1's items' counterpartsin list2 be the same.I.E., 'a.ExE' in list2 becomes 'a.exe' from list1.We'll assume that if there is an item in list2 that doesn't have acounterpart in list1,
that we just don't care.So 'd.EXE' is going to be 'd.EXE' after theprogram is run,because there is no corresponding item in list1.In other words,if there are extra files in the directory that we don't need to fix the
case for, we'll just ignore them.So, without thinking about the implementation, what is it we want to do?for every item in list1,check it against each item in list2.if the case-insensitive version of the list1 item is equal to the
case-insensitive version of list2,and the case-sensitive versions aren't equal,we know we need to change the case.Otherwise, if the case-sensitive versions are equal,we don't need to change case, but we'll tell them so.
if the case-insensitive version of list1 item is not equal to thecase-insensitive version of the list2 item,we don't care.It's one of the things that we don't need to change.So what would this look like in python code?
for item1 in list1:for item2 in list2: if item1.lower() == item2.lower(): #they're the same file if youignore caseif item1 != item2: #but there's some case error, 
os.rename(item1,item2) print %s is not %s % (item1, item2)else: print %s is %s % (item1,item1)# or (item1, item1), or(item2,item2), since they're equivalent.
I think this is what you wanted.The way you were trying to explain it just confused everyone.Hope that helps,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
I'd personally do something like this. file = open(myfile, 'r')fileContents = file.readlines() # read the entire document into memory for speed.file.close()print fileContents[-1] # This is the last line.
On 10/19/06, Asrarahmed Kadri [EMAIL PROTECTED] wrote:
My algorithm is like this:
first count the number of lines in the file by using a loop.
Use a second loop and when teh counter reaches the num_of_lines values: take the line.

Is there any other way to do it??

On 10/19/06, Danny Yoo [EMAIL PROTECTED]
 wrote:
On Thu, 19 Oct 2006, Asrarahmed Kadri wrote: I want to extract the last line of the text file. Any idea ???
Hi Asrarahmed,Ok, so what part do you get stuck on when you try to do this?That is,what sort of things do you already know how to do with files?
-- To HIM you shall return. 

___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] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
Not to hijack the thread, but what stops you from just putting a file.close() after your example line?On 10/19/06, Chad Crabtree 
[EMAIL PROTECTED] wrote:file('filename.txt').readlines()[-1]
Some will say that this is no good because the file is still open. However I've been told that when the object is cleaned the file is closed so it should be fine.


___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] Generic Application Frameworks?

2006-10-19 Thread Chris Hengge
Just incase anyone doesn't want to see that document to know what I'm asking about...Razor/Carbon includes:Auto UpdatePlugin System with managementError reportingIts got a few other features, but these are my focus.
On 10/19/06, Chris Hengge [EMAIL PROTECTED] wrote:
I was curious if there are any frameworks around like carbon/razor implimented in razor? Here's a link with information about razor (.net 1.1 versin of carbon)

http://www.codeproject.com/cs/design/razorpt1.aspIf not, is there any reason why? (limitation of python?)


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


Re: [Tutor] Generic Application Frameworks?

2006-10-19 Thread Chris Hengge
I ran a couple searches for one, and mostly got scientific or web based projects.. I was just looking for a basic desktop framework to handle common tasks that aren't so easy to impliment like the ones I mentioned.
Thanks for that repository! I hadn't seen that before.. I'm looking at plugboard now, that might be atleast a step in the right direction. I don't believe there's any limitation in python. I suspect it's mostly
philosophical. -- What did you mean by this Mike?On 10/19/06, Mike Hansen [EMAIL PROTECTED]
 wrote:From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Chris HenggeSent: Thursday, October 19, 2006 1:22 PMTo: PyTutorSubject: Re: [Tutor] Generic Application Frameworks?
Just incase anyone doesn't want to see that document to knowwhat I'm asking about...Razor/Carbon includes:Auto UpdatePlugin System with managementError reporting
Its got a few other features, but these are my focus.On 10/19/06, Chris Hengge [EMAIL PROTECTED] wrote:I was curious if there are any frameworks around like
carbon/razor implimented in razor?Here's a link with information about razor (.net 1.1versin of carbon)http://www.codeproject.com/cs/design/razorpt1.asp
If not, is there any reason why? (limitation of python?)---You might ask on comp.lang.python.You might also do a search at 
http://cheeseshop.python.org/pypiI did a search for 'application framework' and came up withhttp://cheeseshop.python.org/pypi/PlugBoard/0.2
Most of the other hits were for web application frameworks.Do you feel you need an application framework?I don't believe there's any limitation in python. I suspect it's mostlyphilosophical.
Mike___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Generic Application Frameworks?

2006-10-19 Thread Chris Hengge
http://dabodev.com/aboutHere we go... 3 tier application framework.. Thats almost perfect.. I suppose I could figure out the auto update thing myself... since that is all that it is missing for what I was wanting..
Thanks again! On 10/19/06, Chris Hengge [EMAIL PROTECTED] wrote:
I ran a couple searches for one, and mostly got scientific or web based projects.. I was just looking for a basic desktop framework to handle common tasks that aren't so easy to impliment like the ones I mentioned.

Thanks for that repository! I hadn't seen that before.. I'm looking at plugboard now, that might be atleast a step in the right direction. I don't believe there's any limitation in python. I suspect it's mostly
philosophical. -- What did you mean by this Mike?On 10/19/06, Mike Hansen 
[EMAIL PROTECTED]
 wrote:From: 
[EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Chris HenggeSent: Thursday, October 19, 2006 1:22 PM
To: PyTutorSubject: Re: [Tutor] Generic Application Frameworks?
Just incase anyone doesn't want to see that document to knowwhat I'm asking about...Razor/Carbon includes:Auto UpdatePlugin System with managementError reporting
Its got a few other features, but these are my focus.On 10/19/06, Chris Hengge 
[EMAIL PROTECTED] wrote:I was curious if there are any frameworks around like
carbon/razor implimented in razor?Here's a link with information about razor (.net 1.1versin of carbon)
http://www.codeproject.com/cs/design/razorpt1.asp
If not, is there any reason why? (limitation of python?)---You might ask on comp.lang.python.You might also do a search at 

http://cheeseshop.python.org/pypiI did a search for 'application framework' and came up with
http://cheeseshop.python.org/pypi/PlugBoard/0.2
Most of the other hits were for web application frameworks.Do you feel you need an application framework?I don't believe there's any limitation in python. I suspect it's mostlyphilosophical.

Mike___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] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
Oh wow.. I totally missed that... nevermind.. ignore that question =DOn 10/19/06, Danny Yoo [EMAIL PROTECTED]
 wrote: file('filename.txt').readlines()[-1] Not to hijack the thread, but what stops you from just putting a
 file.close() after your example line?Which file should file.close() close?The problem is that we don't have ahandle on the particular file we want to close off.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generic Application Frameworks?

2006-10-19 Thread Chris Hengge
About frameworks being complicated... I'm sure there are exceptions to this, but my experience is that if you think of a framework as a tool, sure , you gotta learn how to use it first, which means it will slow you down upfront..
But.. once you know how to use the tool in theory it will make your job easier... again, there are always exceptions.. :]Thanks for your feedback.On 10/19/06, 
Mike Hansen [EMAIL PROTECTED] wrote:
 [...]I don't believe there's any limitation in python. I suspect it'smostlyphilosophical. -- What did you mean by this Mike?import thisSimple is better than complex.
Complex is better than complicated.I'm kind of torn on using frameworks. I'm but a simple cavemanprogrammer(*), and some of these frameworks seem pretty complicated. Onthe other hand, they sound like they can speed up development. One of
these days I'll probably take a good look at Django(**), and see if Ican whip out a CRUD(***) web app.* - Phil Hartman SNL(I'm but a simple caveman lawyer)** - A web application framework
*** - CRUD...Create Update DeleteMike___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] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
Very informative and creative reply! Thanks for sharing :]On 10/19/06, Danny Yoo [EMAIL PROTECTED]
 wrote:  file('filename.txt').readlines()[-1]
  Not to hijack the thread, but what stops you from just putting a  file.close() after your example line? Which file should file.close() close?The problem is that we don't
 have a handle on the particular file we want to close off. Oh wow.. I totally missed that... nevermind.. ignore that question =DHi Chris,No, no, it's an interesting one.It turns out that there IS a way to
sorta do what you're thinking:class FilePool: A small demo class to show how we might keep track of files opened with us.
 def __init__(self): self.pool = [] def open(self, filename): f = open(filename) self.pool.append(f) return f def closeAll(self): for f in 
self.pool: f.close() self.pool = []fp = FilePool()Once we have FilePool, we might say something like:##
print the last line is:, fp.open('filename.txt').readlines()[-1]fp.closeAll()##This is similar in spirit to the idea of autorelease memory pools used
by the Objective C language.We use some resource manager that doeskeep a handle on resources.That manager then has the power andresponsiblity to call close() at some point.So one might imagine doing
something like:create a managertry: ... # use resources that the manager doles outfinally: use the manager to close everything down
So your question may have seemed like a dumb one, but it's actually a goodone.*grin*Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
I thought my solution was the easiest.. but I guess everyone skipped it =POn 10/19/06, Kent Johnson [EMAIL PROTECTED]
 wrote:Danny Yoo wrote: file('filename.txt').readlines()[-1]
 Not to hijack the thread, but what stops you from just putting a file.close() after your example line? Which file should file.close() close?The problem is that we don't
 have a handle on the particular file we want to close off. Oh wow.. I totally missed that... nevermind.. ignore that question =D Hi Chris, No, no, it's an interesting one.It turns out that there IS a way to
 sorta do what you're thinking:  class FilePool:A small demo class to show how we might keep track of
files opened with us.def __init__(self):self.pool = []def open(self, filename):f = open(filename)self.pool.append
(f)return fdef closeAll(self):for f in self.pool:f.close()self.pool = [] fp = FilePool() 
 Once we have FilePool, we might say something like: ## print the last line is:, fp.open('filename.txt
').readlines()[-1] fp.closeAll() ##Wow, that seems like overkill when you can just writef = open('filename.txt')f.readlines()
f.close()In CPython (the regular Python that we usually talk about here,implemented in C) a file will be closed automatically as soon as thereare no references to the file because CPython garbage collects objects
immediately. This behaviour is not guaranteed by the language though andit is different in Jython. This is similar in spirit to the idea of autorelease memory pools used by the Objective C language.We use some resource manager that does
 keep a handle on resources.That manager then has the power and responsiblity to call close() at some point.So one might imagine doing something like: 
 create a manager try:... # use resources that the manager doles out finally:use the manager to close everything down 
In Python 2.5 you can use with: to do this:with open('filename.txt') as f: f.readlines()f is guaranteed to be closed when the block exits.Kent___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
I dont care for slow... I dont use computers with less then 1gb of ram.. (all my systems have 2gb), I hate to wait... =D If I've got memory to use, I intend to use it!As for reading 100 20mb files, I'd do one at a time, then dump the variable storing the data, or reset/re-use. Just my take though.
On 10/19/06, Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: I thought my solution was the easiest.. but I guess everyone skipped it =PNo, we didn't skip it,but as we're all programmers here, we showed alternate ways that itcould be done.
Your post is the one that sparked the whole 'garbage collection' thing,you'll notice.Now, I don't want to be left out of the loop on this,and the first thing I thought of when I read his question about how to
read the last line was:Well, what if he wants to read the last line of 100 20 mb files?Does he really want to read all of these into memory just to get thelast line?I wouldn't think so!So I've made an alternate solution using seek.
The last line can't be more than 1000 chars long, or whatever the Pythonmaximum recursion depth happens to be at runtime,but you could easily change this into a non-recursive implementation ifyou so desired.
I just wanted to be cool :)#read_last_line.pyf = file('wii.txt','r')f.seek(-1,2)#start at end of file.if f.read(1) == '\n':#if file ends with a newline:f.seek(-3,1)#start at right before the newline.
else:f.seek(-1,1)#just start at the end.def prevchar(fileobj):achar = fileobj.read(1)if achar == '\n': return ''else:fileobj.seek(-2,1)return prevchar(fileobj)+achar
print prevchar(f)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
More on that.. some of the file I work with are thousands of lines long... one is even 10's of thousands.. so reading the entire thing into ram is MUCH faster then reading line by line with the filestream open. 
On 10/19/06, Chris Hengge [EMAIL PROTECTED] wrote:
I dont care for slow... I dont use computers with less then 1gb of ram.. (all my systems have 2gb), I hate to wait... =D If I've got memory to use, I intend to use it!As for reading 100 20mb files, I'd do one at a time, then dump the variable storing the data, or reset/re-use. Just my take though.
On 10/19/06, Luke Paireepinart 
[EMAIL PROTECTED] wrote:
Chris Hengge wrote: I thought my solution was the easiest.. but I guess everyone skipped it =PNo, we didn't skip it,but as we're all programmers here, we showed alternate ways that itcould be done.

Your post is the one that sparked the whole 'garbage collection' thing,you'll notice.Now, I don't want to be left out of the loop on this,and the first thing I thought of when I read his question about how to
read the last line was:Well, what if he wants to read the last line of 100 20 mb files?Does he really want to read all of these into memory just to get thelast line?I wouldn't think so!So I've made an alternate solution using seek.
The last line can't be more than 1000 chars long, or whatever the Pythonmaximum recursion depth happens to be at runtime,but you could easily change this into a non-recursive implementation ifyou so desired.
I just wanted to be cool :)#read_last_line.pyf = file('wii.txt','r')f.seek(-1,2)#start at end of file.if f.read(1) == '\n':#if file ends with a newline:f.seek(-3,1)#start at right before the newline.
else:f.seek(-1,1)#just start at the end.def prevchar(fileobj):achar = fileobj.read(1)if achar == '\n': return ''else:fileobj.seek(-2,1)return prevchar(fileobj)+achar
print prevchar(f)


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


Re: [Tutor] Trying to extract the last line of a text file

2006-10-19 Thread Chris Hengge
Oops, my mistake, I did read your code, as well as all the others and I had your code mixed with another submission. In that case, excellent contribution =DOn 10/19/06, 
Luke Paireepinart [EMAIL PROTECTED] wrote:
Chris Hengge wrote: More on that.. some of the file I work with are thousands of lines long... one is even 10's of thousands.. so reading the entire thing into ram is MUCH faster then reading line by line with the filestream
 open.Did you look at my code?It doesn't read the whole thing into ram, nor does it read line by line.It seeks to the end of the file (should be extremely fast)and reads backwards until it gets to a newline char.
In other words: Very fast, and no extra ram usage.HTH,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[
count].ljust(20) else: print fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[
count], pathName + limitedLineList[count]) count = count + 1Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. 
The code is actually doing what I want correctly, (cheated a test by hand changing variables), but I need to find the directory location.Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
Still no progress with this myself. For clarification if I didn't provide enough earlier, for item in list1: if item in list2: print item and list[object at location where matched item] -- need this location.
On 10/18/06, Chris Hengge [EMAIL PROTECTED] wrote:
I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[

count].ljust(20) else: print fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[
count], pathName + limitedLineList[count]) count = count + 1Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. 
The code is actually doing what I want correctly, (cheated a test by hand changing variables), but I need to find the directory location.Thanks.


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


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
What that should have saidFor clarification if I didn't provide enough earlier, for item in list1: if item in list2: print item and list2[object that matched item] -- need this location.
On 10/18/06, Chris Hengge [EMAIL PROTECTED] wrote:
Still no progress with this myself. For clarification if I didn't provide enough earlier, for item in list1: if item in list2: print item and list[object at location where matched item] -- need this location.
On 10/18/06, Chris Hengge 
[EMAIL PROTECTED] wrote:
I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[


count].ljust(20) else: print fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[
count], pathName + limitedLineList[count]) count = count + 1Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. 
The code is actually doing what I want correctly, (cheated a test by hand changing variables), but I need to find the directory location.Thanks.




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


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
Tried your first suggestion.AttributeError: 'list' object has no attribute 'find'Perhaps a better explanation... for word in paragraph: if word in sentence: print word + sentence
Assume that the word is only used once per paragraph. I can't figure out how to tell it to print the right sentence (using this example) because python does the search internally and doesn't seem to have a way to return the list location where the match occurred. 
On 10/18/06, Kent Johnson [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Still no progress with this myself. For clarification if I didn't provide enough earlier, for item in list1: if item in list2:print item and list[object at location where matched item] --
 need this location.I still don't understand your question. If you want the index in list2of the item that matches, use list2.find(item).If you want to enumerate over a list and have the list indices available
as well as the list values, use enumerate() e.g.for i, item in enumerate(list1): # i is the index of item in list1Kent On 10/18/06, *Chris Hengge* 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: I'm looking for a way to do the following. for item in limitedLineList:
 if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[ count].ljust(20) else: print 
fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[ count], pathName + limitedLineList[count]) count = count + 1
 Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. The code is actually doing what I want correctly, (cheated a test by
 hand changing variables), but I need to find the directory location. Thanks. 
 ___ Tutor maillist-Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
___Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
The point of this script is to read a text file that has a bunch of code that calls external files. Then read the directory where all the files are.. I build a list from the text file (this works correct), and I build a list from the directory (this works correct). I want to print out the result of a match..
Here is sample output. Tested: Textname: DirectoryName:Match! a.exe a.exeFail! A.exe a.exeMy program works, it will find where they match and where they dont, but I can't get the darn thing to output the correct item to the 3rd column because:
if item in list:does not return the list location, so I can't write it out to the screen. On 10/18/06, Chris Hengge 
[EMAIL PROTECTED] wrote:Tried your first suggestion.AttributeError: 'list' object has no attribute 'find'
Perhaps a better explanation... for word in paragraph: if word in sentence: print word + sentence
Assume that the word is only used once per paragraph. I can't figure out how to tell it to print the right sentence (using this example) because python does the search internally and doesn't seem to have a way to return the list location where the match occurred. 
On 10/18/06, Kent Johnson 
[EMAIL PROTECTED] wrote:
Chris Hengge wrote: Still no progress with this myself. For clarification if I didn't provide enough earlier, for item in list1: if item in list2:print item and list[object at location where matched item] --
 need this location.I still don't understand your question. If you want the index in list2of the item that matches, use list2.find(item).If you want to enumerate over a list and have the list indices available
as well as the list values, use enumerate() e.g.for i, item in enumerate(list1): # i is the index of item in list1Kent On 10/18/06, *Chris Hengge* 

[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: I'm looking for a way to do the following.
 for item in limitedLineList:
 if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[ count].ljust(20) else: print 
fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[ count], pathName + limitedLineList[count]) count = count + 1
 Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. The code is actually doing what I want correctly, (cheated a test by
 hand changing variables), but I need to find the directory location. Thanks. 
 ___ 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 maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
Why even try to use the 'in' syntax if it's not working correctly?Maybe I still don't understand.
-LukeBecause I've been up for 40 hours... 5 days of the week I'm up at 8:45AM and I dont get home until 10PM, once I'm home, I do homework trying to finish my senior year, on the weekends I am either trying to catch up on lost work time from classes I have to go to across town, or I'm working on my senior project. =P
That, and I'm running tests on 14 servers(at work), and only look at this code when I'm between tasks because they refuse to hire another intern to do this job, so I'm basically trying to balance two jobs, school.. and on occassion I try to find time for my spouce.. =P

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


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
Ok the example I gave here wasn't written as I had it in my head.. you are right, the example only had 1 sentence. Inputs:List1 ['a.exe','b.exe',c.exe']List2 ['A.exe',B.eXe',c.EXE']for item in List1:
 if item in List2: print item +   + list2thing that matched.I can't force to upper or lower, that would break the already working code.. Its just this darn output for list2 that isn't working. 
I tried the suggested list.index(item) but that wont work if there isn't a match.Right now my code works when there is a match, and if there isnt'...It also works for renaming the actual file to match the file call from the document. 
I'm about to take the display out, since I dont honestly care that it works, but now that I've been working with it I'm being stubborn and want the darn thing to show me =POn 10/18/06, 
Kent Johnson [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Tried your first suggestion. AttributeError: 'list' object has no attribute 'find'Sorry, it's index() not find(). Strings have both but lists only haveindex() Perhaps a better explanation...
 for word in paragraph:if word in sentence: print word + sentence Assume that the word is only used once per paragraph.Still not clear - the above looks like it would actually run.
 I can't figure out how to tell it to print the right sentence (using this example) because python does the search internally and doesn't seem to have a way to return the list location where the match occurred.
There is only one sentence in the above example.I think you want index(). If not, maybe you could show a small sample ofthe data and the result you want. On 10/18/06, *Kent Johnson* 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Chris Hengge wrote: Still no progress with this myself.
 For clarification if I didn't provide enough earlier, for item in list1: if item in list2:print item and list[object at location where matched
 item] -- need this location. I still don't understand your question. If you want the index in list2 of the item that matches, use list2.find(item).
 If you want to enumerate over a list and have the list indices available as well as the list values, use enumerate() e.g. for i, item in enumerate(list1):# i is the index of item in list1
 Kent On 10/18/06, *Chris Hengge*  [EMAIL PROTECTED] mailto:
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
 I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList: print 
match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[ count].ljust(20) else: print fail.ljust(20) + limitedLineList[count].ljust(20)
 + directoryList[count].ljust(20) os.rename(pathName + directoryList[ count], pathName + limitedLineList[count]) count = count + 1
 Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. The code is actually doing what I want correctly, (cheated a
 test by hand changing variables), but I need to find the directory location. Thanks.
  ___ Tutor maillist-
Tutor@python.org mailto:Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
 http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist-
Tutor@python.org mailto:Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
 http://mail.python.org/mailman/listinfo/tutor___Tutor maillist-
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
For all who dont get what I'm trying to do... I've bolded what needs to change... This is the code...wanted result of the comparisons works, but I am unable to display correctly.. count = 0 for item in limitedLineList:
 if item in directoryList: print match.ljust(20) + item.ljust(20) + item.ljust(20) else: print fail.ljust(20) + item.ljust(20) + 
item.ljust(20) #os.rename(pathName + item, pathName + limitedLineList[count]) count = count + 1This is a pretty capture of the real output this script provides... (its formatted on the screen, but drops when I past here)
Tested: File Name: Directory Name:Fail! SL_39.sdr SL_39.sdrMatch! PSL_MBD5.FRU PSL_MBD5.FRU
Match! XSL_MBD3.FRU XSL_MBD3.FRUMatch! RA_MBD4.FRU RA_MBD4.FRUMatch! XVN_MBD3.FRU XVN_MBD3.FRUMatch! P_R24BP.FRU P_R24BP.FRU
Match! P_R26BP.FRU P_R26BP.FRUMatch! P_R24BPE.FRU P_R24BPE.FRUMatch! P_R26BPE.FRU P_R26BPE.FRUMatch! S_R24BP.FRU S_R24BP.FRU
Match! S_R26BP.FRU S_R26BP.FRUMatch! S_R24BPE.FRU S_R24BPE.FRUMatch! S_R26BPE.FRU S_R26BPE.FRUOk, I bolded the line that is my example. 
3rd column should say SL_39.SDR (because I just changed it to that so it would flag as failed)if you look at my code for both match and fail, I printed item... (just to make the darn thing work for now) the 3rd column needs to be the value from the 2nd list (directoryList) 
This list item is what I can't get to print.If I uncomment the underlined line of my script, it will infact rename the lowercase extension to uppercase, as it should. 
On 10/18/06, Chris Hengge [EMAIL PROTECTED] wrote:
I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList: print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[

count].ljust(20) else: print fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) os.rename(pathName + directoryList[
count], pathName + limitedLineList[count]) count = count + 1Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. 
The code is actually doing what I want correctly, (cheated a test by hand changing variables), but I need to find the directory location.Thanks.


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


Re: [Tutor] Location of found item in list.

2006-10-18 Thread Chris Hengge
I just replied to my original thread with output and real working code and bolding and underlined items all over the place.. I dont see what is so hard to explain... Please refer to that post, so I dont end up just copying and pasting. 
On 10/18/06, Kent Johnson [EMAIL PROTECTED] wrote:
Chris Hengge wrote: Ok the example I gave here wasn't written as I had it in my head.. you are right, the example only had 1 sentence. Inputs: List1 ['a.exe','b.exe',c.exe'] List2 ['
A.exe',B.eXe',c.EXE'] for item in List1:if item in List2:print item +   + list2thing that matched.But the list2thing that matched is the same as item! In this example
nothing will match because nothing in list1 is also in list2. I stilldon't have a clue what you want. I can't force to upper or lower, that would break the already working code..
 Its just this darn output for list2 that isn't working. I tried the suggested list.index(item) but that wont work if there isn't a match.It raises an exception if there is no match, but you want to print only
if there is a match. John Fouhy showed how to catch the exception.I'm done guessing what you want. If you can't state the problem so I canunderstand it I give up.Kent Right now my code works when there is a match, and if there isnt'...
 It also works for renaming the actual file to match the file call from the document. I'm about to take the display out, since I dont honestly care that it works, but now that I've been working with it I'm being stubborn and
 want the darn thing to show me =P On 10/18/06, *Kent Johnson* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
 Chris Hengge wrote: Tried your first suggestion. AttributeError: 'list' object has no attribute 'find' Sorry, it's index() not find(). Strings have both but lists only have
 index() Perhaps a better explanation... for word in paragraph:if word in sentence: print word + sentence
 Assume that the word is only used once per paragraph. Still not clear - the above looks like it would actually run. I can't figure out how to tell it to print the right sentence (using
 this example) because python does the search internally and doesn't seem to have a way to return the list location where the match occurred. There is only one sentence in the above example.
 I think you want index(). If not, maybe you could show a small sample of the data and the result you want. On 10/18/06, *Kent Johnson*  
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:
[EMAIL PROTECTED] wrote: Chris Hengge wrote: Still no progress with this myself. For clarification if I didn't provide enough earlier,
 for item in list1: if item in list2:print item and list[object at location where matched item] --
 need this location. I still don't understand your question. If you want the index in list2 of the item that matches, use 
list2.find(item). If you want to enumerate over a list and have the list indices available as well as the list values, use enumerate() e.g
. for i, item in enumerate(list1):# i is the index of item in list1 Kent On 10/18/06, *Chris Hengge*  
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto: [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
 I'm looking for a way to do the following. for item in limitedLineList: if item in directoryList:
 print match.ljust(20) + limitedLineList[count].ljust(20) + directoryList[ count].ljust(20) else:
 print fail.ljust(20) + limitedLineList[count].ljust(20) + directoryList[count].ljust(20) 
os.rename(pathName + directoryList[ count], pathName + limitedLineList[count]) count = count + 1
 Where I have underlined, needs to be the item from the directoryList, and I'm unable to find a way to return that. The code is actually doing what I want correctly,
 (cheated a test by hand changing variables), but I need to find the directory location. Thanks.
 
 ___ Tutor maillist- Tutor@python.org mailto:
Tutor@python.org mailto:Tutor@python.org mailto:Tutor@python.org 
http://mail.python.org/mailman/listinfo/tutor http://mail.python.org/mailman/listinfo/tutor 
http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist- 
Tutor@python.org mailto:Tutor@python.org mailto:Tutor@python.org mailto:
Tutor@python.org http://mail.python.org/mailman/listinfo/tutor 
http://mail.python.org/mailman/listinfo/tutor http://mail.python.org/mailman/listinfo/tutor
 ___ Tutor maillist- Tutor@python.org mailto:Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor___Tutor maillist-
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  1   2   >