Hi folks,
Im running python2.4 on linux.
I have many python scripts in various directories of varying depth under my
home directory, and I need to change one line in each of these files.
I thought about using os.walk with os.path.join eg
>>> for r,d,f in os.walk('.'):
... print os.path.joi
>>From: Ryan Davis [mailto:[EMAIL PROTECTED]
??
>>I think you want to be doing something like:
>>
>>>for r,d,f in os.walk('.'):
>>... for filename in f:
>>... print os.path.join(r,filename)
>>
>>I think that would give you the full path of every file, and then you can
open it, do a rege
Hello,
I sent this reply a few days ago, but it doesn't seem to have appeared on
the list, so Im resending it.
Many thanks
Nick .
-Original Message-
From: Nick Lunt [mailto:[EMAIL PROTECTED]
Sent: 08 January 2005 19:44
To: 'python tutor'
Subject: RE: [Tutor] walk
Nr 3. If your using python sockets try socket.settimeout(x)
Nick .
On Sat, 2005-02-26 at 15:12 +0200, Mark Kels wrote:
> Hi list.
>
> Here are the questions (-:
> 1. How do I make a progress bar in Tkinter ?
> 2. I got a while loop which does the port scan itself. How can I end
> it while its
Richard,
if you try to print sys.argv[1:] when sys.argv only contain sys.argv[0]
then you are bound to get an empty list returned, [] .
Im not sure I understand the problem you think you've got but here's
what happens with sys.argv for me, and it's correct.
[argl.py]
$ cat argl.py
#!/usr/bin/py
Hi folks,
I've been pondering how to get python to read from a pipe outside of
itself, sort of.
For example I tried a simple python prog to do a grep, eg
# ps -e | myprog.py cron
would give this output
3778 ?00:00:00 crond
same as
# ps -e | grep cron
The way I did this was to use sy
On Tue, 2005-03-01 at 14:14 -0800, Sean Perry wrote:
>
> unless you want the output for some other reason, a more idiomatic way
> is:
>
> for line in sys.stdin.readlines():
> # handle the line
>
> I tend to use xreadlines() which does not read the entire input at once.
> For stdin this
On Tue, 2005-03-01 at 22:20 +, Max Noel wrote:
> I don't think you are. You're using readlines(), which means your
> program won't execute until ps terminates.
> UNIX philosophy is to have programs start acting as soon as possible
> -- in that case, as soon as the first line is a
On Wed, 2005-03-02 at 11:22 +1300, [EMAIL PROTECTED] wrote:
> Quoting Sean Perry <[EMAIL PROTECTED]>:
>
> > for line in sys.stdin.readlines():
> > # handle the line
> >
> > I tend to use xreadlines() which does not read the entire input at once.
>
> xreadlines() these days just does 'return sel
Thanks to everyone who helped me with this.
It's certainly given me something to think about :)
Cheers
Nick .
On Tue, 2005-03-01 at 23:13 -0600, David Rock wrote:
> * Nick Lunt <[EMAIL PROTECTED]> [2005-03-01 22:23]:
> > On Tue, 2005-03-01 at 14:14 -08
in "\n"
> you'll have to do it char by char =( AFAIK, there's no way to redefine a
> separator por readlines() (other than \n..)
>
> Hugo
>
> Nick Lunt wrote:
> > Hi folks,
> >
> > I've been pondering how to get python to read from a
I've gotten into the habit of just using the os.?_OK stuff.
eg
>>> import os
>>> os.access('/', os.W_OK)
False
>>> os.access('/tmp', os.W_OK)
True
Thats gotta be simple if I understand it lol :)
Nick .
Alan Gauld wrote:
The simplest, IMHO, is :
try:
f = file(filename, "w")
[...]
except IOError:
Shidai Liu wrote:
I found out in the following situation, it fails to work.
Say, 'somefile.csv' is opened by EXCEL,
os.access('somefile.csv', os.W_OK)
True
file('somefile.csv', 'w')
IOError: [Errno 13] Permission denied: 'somefile.csv'
By the way, using os.stat & stat a
Feziwe Mpondo wrote:
>clock.py,problem is to get the last two digits to be random.her's what i
>tried
>from time import time,ctime
>prev_time = ""
>while(1):
>the_time = ctime()
>if (prev_time != the_time):
> print "The time is :",ctime(time())
>prev_time = the_time
>guess = 0
>nu
Hi John,
you can use 'pass' . This works the same as with exceptions, eg
try:
open('somefile')
except IOError:
pass
so we can have
class doNothing:
def __init__(self):
pass
def boring(self, other):
pass
Hope that helps :)
Nick
--
Hello folks,
I have the following code taken from the Twisted examples -
[code]
# filewatcher.py
from twisted.application import internet
def watch(fp):
fp.seek(fp.tell())
for line in fp.readlines():
sys.stdout.write(line)
import sys
from twisted.internet import
Hi Kent,
> >
> > [code]
> > # filewatcher.py
> > from twisted.application import internet
> >
> > def watch(fp):
> > fp.seek(fp.tell())
> > for line in fp.readlines():
> > sys.stdout.write(line)
> >
> > import sys
> > from twisted.internet import reactor
> > s = in
Hi Alberto,
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> Alberto Troiano
> Sent: 31 August 2005 22:01
> To: tutor@python.org
> Subject: [Tutor] Tail -f problem
>
>
> Hey
>
I thought about tail-f
> /var/log/radacct/max/detail but this thing opens a
Hi Olexiy,
> I'm really confused on the issue how to create windows, forms, etc. in
> Python & can't find any manual for that.
> Could you possibly advise me smth useful?
> --
> Best regards,
>
> Olexiy Kharchyshyn
this has come up quite a bit recently on the list.
I would recommend that you go
Hi marc,
>
> i create a list of all JPG files with:
> >>> list = glob.glob('*.JPG')
> the content of 'list' is now:
> >>> print list
> ['DSC1.JPG', 'DSC2.JPG', 'DSC3.JPG']
>
> but what i want is this type of list:
> ['DSC1', 'DSC2', 'DSC3']
> i.e. the names w/o the file e
Hi Andy,
> Behalf Of Andy Dani
>
> Python 2.3.2 came with the linux distribution which is located in
> /usr/lib.
>
> Installed 2.4.1 in /usr/local/Python-2.4.1
>
> updated /etc/profile path so IDLE or "python" would point to the
> latest version (2.4.1).
>
> PATH="$PATH:/usr/local/Python-2.4.
Hi Andy,
Andy Dani wrote:
>Thanks Nick,
>
>Any idea about the second question? When I python from
>/usr/loca/Python-2.4.1/bin, it does launch the interpreter but with an
>traceback error saying there is some conflict with "import readline" line on
>pythonrc.py file located somewhere in /etc/
Hi Folks,
messing about with classes I've come across something basic that I don't
understand.
Take this class
class T:
def p(self):
print x
if __name__ == '__main__':
x = 1
t = T()
t.p()
This outputs 1
Now this
class T:
def p(self):
Alan Gauld wrote:
>> messing about with classes I've come across something basic that I
>> don't understand.
>
>
> As you say this has nothing to do with classes its more basic. Its
> about namespaces. Try reading the namespaces topic in my tutor for
> more info.
>
> Meanwhile lets simplify by
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Alan Gauld
>
>
> I've just added an incomplete draft copy of my latest tutorial topic
> on using the Operating System from Python. The material that's
> there discusses the role of the OS and looks at fi
Hi Adisegna,
Lets say that you are [EMAIL PROTECTED] and you want to send email to
[EMAIL PROTECTED], [EMAIL PROTECTED] and [EMAIL PROTECTED] .
You setup SMTPLib to talk to the MX server for abc.com which all users on
abc.com use to send email.
SMTP connects to that email server and you can send
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> >>> def f(x, y):
> ... return x + y
> ...
> >>> arr = range(10)
> >>> sum(arr) # Our target
> 45
> >>> tmp = [0]
> >>> [f(x, y) for x in arr for y in [tmp[-1]] if tmp.append(f(x,
> y)) or True][-1]
>
Web/Network programming here
http://www.amazon.com/gp/product/0596100329/qid=1135198935/sr=2-1/ref=pd_bbs
_b_2_1/103-4720029-4050242?s=books&v=glance&n=283155
Not CGI specific, and I haven't bought it yet, but I bet it's a blinder :)
> -Original Message-
> From: [EMAIL PROTECTED] [mailt
Hi Richard,
I myself just about know enough python to help me in my job occasionally and
to do some cool little hobby projects.
When it comes to creating GUI's for my programs I always use pythoncard, see
here www.pythoncard.org .
It's very simple to use, and the tutorials on their site will have
Hi Brian,
it's the ^M characters that are catching you out here.
Often files from a windows PC will have ^M as the newline char when viewed
in linux/unix.
On linux you should be able to check if a file has ^M in by running either
'vi -b filename' or 'sed -n l filename'.
Try this with the file
Take no notice of this, others have already answered.
My emails to the tutor list seem to take about 5 hours to get thru for some
reason.
Nick .
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Nick Lunt
> Sent: 16 February 2006 14:27
>
31 matches
Mail list logo