Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Alan Gauld
>I have a large volume of files to change so I need to
> automate the search and replace. I'll be replacing
> bits of text with other bits of text. This is working
> for now but I'd like to know how a real programmer
> would do it. 

A "real programmer" would use the right tool for the job, 
hence he/she would use sed!

Not re-inventing the wheel is part of being a "real 
programmer"

http://www.guidenet.net/resources/programmers.html

:-)

Alan G.

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


Re: [Tutor] GUI Programing

2006-09-01 Thread Amadeo Bellotti
thank you all im reading up on it all its a diffreent mindset that i have tog et used toOn 9/1/06, Terry Carroll <[EMAIL PROTECTED]
> wrote:On Fri, 1 Sep 2006, Alan Gauld wrote:> Fred Lundh's tutorial is much better nowadays - although longer.
Tkinter docs are tough enough to come by that, in my view, longer isbetter.___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] GUI Programing

2006-09-01 Thread Terry Carroll
On Fri, 1 Sep 2006, Alan Gauld wrote:

> Fred Lundh's tutorial is much better nowadays - although longer.

Tkinter docs are tough enough to come by that, in my view, longer is 
better.

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


Re: [Tutor] GUI Programing

2006-09-01 Thread Alan Gauld
> Tkinter is (IMO) easier to learn.  In particular, check out 
> "Thinking
> in Tkinter" (google for it); it's an excellent way to learn Tkinter.

Last time I looked that was very out of date and still recommended
the now obsolete parameters by dictionary stuyle of widget
configuration.

Fred Lundh's tutorial is much better nowadays - although longer.

Alan G.

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


Re: [Tutor] GUI Programing

2006-09-01 Thread Alan Gauld

> I'm going to try some GUI programming does anyone know where the 
> start like
> using tk or wx or what ever i want it to it will run on Windows UNIX 
> and Mac
> systems can you tell me whats best to use and give me a link to a 
> good
> tutorial?

This is like asking which programming language is best,
or which editor/IDE to use. Everyone has their own favourite.

My personal view is:

If you have used any GUI before then use wxPython - it looks
better and has more widgets.

But if you have never used a GUI toolkit before use Tkinter,
its easier to learn (and use IMHO) and has much more documentation.
Once you know Tkinter moving to wxPythobn is relatively
straightforward because the underlying prionciples of all GUIs
are the same.

And of course Tkinter is based on Tk whicgh is also available
for Perl and Tcl/Tk and Scheme. So its worth learning for its
portability too.

You can start with my GUI intro topic which teahches Tkinter
but finishes with a wxPython example so you can quickly switch
if you want to.

BTW I strongly recommend startiung out with the raw toolkit
and manual programming to understand how itall hangs
together. Later you can pick up a GUI Builder like
Glade/Blackadder/SpecTix etc. But its best to understand
what these tools are doing first IMHO...

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


Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Kent Johnson
Lanky Nibs wrote:
> I have a large volume of files to change so I need to
> automate the search and replace. I'll be replacing
> bits of text with other bits of text. This is working
> for now but I'd like to know how a real programmer
> would do it. The hard coded strings will eventually
> come from a list. All sugestions welcome and
> appreciated.
>
> #read all file lines into list and close
> allLines = fh.readlines()
> fh.close()
> 
> #use split and join to replace a unique item
> chunk = allLines[0]
>   
Is the data to be replaced always in the first line? You only look at 
the first line.
> splitChunk = chunk.split('xVAR1x')
> newChunk = 'my shoes fell off'.join(splitChunk)
>   
This is a very awkward way to replace part of a string. Try
newChunk = chunk.replace('xVAR1x', 'my shoes fell off')
>   #write to a file
> file = open('test.html', 'w')
> for eachLine in newChunk:
>   print 'writing  line in text file'
>   file.write(eachLine)
> file.close()
>   
Are you sure this is doing what you want? newChunk is just the first 
line of the file, iterating over it gives you each character from the file.

If I wanted to replace every instance of 'xVAR1x' in a single file with 
'my shoes fell off', I would do it like this:

f = open(...)
data = f.read()
f.close()

data = data.replace('xVAR1x', 'my shoes fell off')

f = open(..., 'w')
f.write(data)
f.close()

Variations are possible depending on exactly what you want to do, but 
this is the basic idea. No need to read a line at a time unless you 
actually need to process by lines, or if the file is too big to fit in 
memory (in which case your solution still needs a rewrite).

Kent
>
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.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


Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Dave Kuhlman
On Fri, Sep 01, 2006 at 09:26:36AM -0700, Lanky Nibs wrote:
> I have a large volume of files to change so I need to
> automate the search and replace. I'll be replacing
> bits of text with other bits of text. This is working
> for now but I'd like to know how a real programmer
> would do it. The hard coded strings will eventually
> come from a list. All sugestions welcome and
> appreciated.
> 
> #read all file lines into list and close
> allLines = fh.readlines()
> fh.close()
> 
> #use split and join to replace a unique item
> chunk = allLines[0]
> splitChunk = chunk.split('xVAR1x')
> newChunk = 'my shoes fell off'.join(splitChunk)

Instead, consider the following:

for line in allLines:
line = line.replace('xVAR1x', 'my shoes fell off')
outfile.write(line)

Dave

> 
>   #write to a file
> file = open('test.html', 'w')
> for eachLine in newChunk:
>   print 'writing  line in text file'
>   file.write(eachLine)
> file.close()
> 

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Lanky Nibs
I have a large volume of files to change so I need to
automate the search and replace. I'll be replacing
bits of text with other bits of text. This is working
for now but I'd like to know how a real programmer
would do it. The hard coded strings will eventually
come from a list. All sugestions welcome and
appreciated.

#read all file lines into list and close
allLines = fh.readlines()
fh.close()

#use split and join to replace a unique item
chunk = allLines[0]
splitChunk = chunk.split('xVAR1x')
newChunk = 'my shoes fell off'.join(splitChunk)

#write to a file
file = open('test.html', 'w')
for eachLine in newChunk:
print 'writing  line in text file'
file.write(eachLine)
file.close()


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Securing a Computer...

2006-09-01 Thread Danny Yoo
>> I just got into high school, and the network and all the computers 
>> aren't secure at all...I'm trying to make a program that password 
>> protects the computer after an inactivity time, but there are some 
>> specific things I can't find how I'm supposed to do it.
>
> Windoze has this feature built in.  It's called 'locking' the computer. 
> Look into it.

Just as another non-Python comment: you should be using Control-Alt-Delete 
when logging into a Windows machine.  It's the only key combination that's 
untrappable by other programs besdies the Windows kernel.  See:

 http://en.wikipedia.org/wiki/Control-Alt-Delete#Windows_NT
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] logging module, how to print line numbers?

2006-09-01 Thread Kent Johnson
Hans Fangohr wrote:
> Hi Kent (and others),
>
> On 01/09/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
>   
>> How are you running the program? What OS? What Python (2.3.??)
>> 
> This is python 2.3.5 on Debian etch. Same results with python 2.4.4 on
> Debian etch (although 'the linenumber' is 1072 instead of 988).
>   
Running from the command line or in IDLE or ??
>   
>> Looking at the source (Python23\Lib\logging\__init__.py), the line
>> number is pulled out of the stack by walking up the stack looking for a
>> frame whose filename is different from _srcfile. What do you get if you
>> print logging._srcfile and logging.__file__?
>> 
> /usr/lib/python2.4/logging/__init__.py
> /usr/lib/python2.4/logging/__init__.pyc
>
> I guess these files should rather be my source file(?). But they aren't.
>   
No, they seem correct, they are the source file of the logging module.

I'm perplexed, the values above seem correct.

The way the logging module finds the line number is, it walks up through 
the stack looking for a stack frame that references a file different 
from the file containing the module itself. It uses the file and line 
number from that stack frame for the log.

For some reason your stack frame has something different. One thing you 
could do is add a print to the logging module itself to see what it is 
seeing. In Python 2.3, there is a findCaller() method at lin 961 of 
logging/__init__.py. You could add
  print filename
just after the line
  filename = os.path.normcase(co.co_filename)

Then run your program again and see what it prints out.

Kent

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


Re: [Tutor] Tkinter: 'explanation text' when the mouse is over an image button ?

2006-09-01 Thread Kent Johnson
learner404 wrote:
> Hello,
>
> With a Tkinter app I have buttons with an image filling each button like
> this,
>
> bu10=Button(frame2, image=picPlay, bg="white", command=play)
>
> I want to give a small explanation of each button when the user puts the
> mouse over the picture (something like the title tag in a hyperlink).
> I thougth I saw this in Tkinter but can't find it here:
> http://effbot.org/tkinterbook/button.htm

You want a tooltip for the button. There is nothing built-in to Tkinter 
to do this. Here are a couple of possibilities:
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_07_01.shtml#e387
http://tkinter.unpythonic.net/wiki/ToolTip

Kent

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


[Tutor] Tkinter: 'explanation text' when the mouse is over an image button ?

2006-09-01 Thread learner404
Hello,With a Tkinter app I have buttons with an image filling each button like this,bu10=Button(frame2, image=picPlay, bg="white", command=play)I want to give a small explanation of each button when the user puts the mouse over the picture (something like the title tag in a hyperlink).
I thougth I saw this in Tkinter but can't find it here:http://effbot.org/tkinterbook/button.htmThanks for any suggestions to achieve this.learner404

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