Re: [Tutor] Something that Perl can do that Python can't?

2005-07-22 Thread Smith, Jeff
Well, I finally managed to solve it myself by looking at some code.  The
solution in Python is a little non-intuitive but this is how to get it:

while 1:
line = stdout.readline()
if not line:
break
print 'LINE:', line,

If anyone can do it the more Pythonic way with some sort of iteration
over stdout, please let me know.

Jeff

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Smith, Jeff
Sent: Friday, July 22, 2005 4:37 PM
To: Tutor
Subject: [Tutor] Something that Perl can do that Python can't?


So here it is: handle unbuffered output from a child process.

Here is the child process script (bufcallee.py):
import time
print 'START'
time.sleep(10)
print 'STOP'

In Perl, I do:
open(FILE, "python bufcallee.py |");
while ($line = )
{
print "LINE: $line";
}

in which case I get
LINE: START
followed by a 10 second pause and then 
LINE: STOP

The equivalent in Python:
import sys, os

FILE = os.popen('python bufcallee.py')
for line in FILE:
print 'LINE:', line

yields a 10 second pause followed by
LINE: START
LINE: STOP

I have tried the subprocess module, the -u on both the original and
called script, setting bufsize=0 explicitly but to no avail.  I also get
the same behavior on Windows and Linux.

If anyone can disprove me or show me what I'm doing wrong, it would be
appreciated.

Jeff
___
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] Something that Perl can do that Python can't?

2005-07-22 Thread Smith, Jeff
So here it is: handle unbuffered output from a child process.

Here is the child process script (bufcallee.py):
import time
print 'START'
time.sleep(10)
print 'STOP'

In Perl, I do:
open(FILE, "python bufcallee.py |");
while ($line = )
{
print "LINE: $line";
}

in which case I get
LINE: START
followed by a 10 second pause and then 
LINE: STOP

The equivalent in Python:
import sys, os

FILE = os.popen('python bufcallee.py')
for line in FILE:
print 'LINE:', line

yields a 10 second pause followed by
LINE: START
LINE: STOP

I have tried the subprocess module, the -u on both the original and
called script, setting bufsize=0 explicitly but to no avail.  I also get
the same behavior on Windows and Linux.

If anyone can disprove me or show me what I'm doing wrong, it would be
appreciated.

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


Re: [Tutor] tricky eval() problem

2005-07-22 Thread Kent Johnson
Marcus Goldfish wrote:
> Here's a noodler I could use some help on: I need a class that can
> call a user-specified function with arbitrary (unknown) parameter
> lists.  The trick, here, is that the user will dynamically specify the
> funciton to invoke, and each function may differ in the number of
> parameters passed during the call.  For instance, suppose I define two
> dummy functions with different calling signatures:
> 
> def foo1(a1, a2, a3):
>...
> 
> def foo2(a1):
>   ...
> 
> Then I seek a class, Caller
> 
> class Caller(object):
>def execute(self, method, *parms):
>   # some way to execute method
> 
> That can be used in the following manner:
> 
> 
>>>c = Caller();
>>>c.execute("foo1", 8, 9, 10)
>>>c.execute("foo2", "me")
> 
> 
> Any tips on tackling this?

Something like this:
def execute(self, method, *parms):
  fn = locals().get(method) or globals.get(method)
  if fn:
fn(*parms)

Seems like there should be a better way of looking up method but I can't think 
of it right now...if method is an instance method of Caller then you could use
  fn = getattr(self, method)
(which will raise AttributeError if there is no such method)

Kent

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


[Tutor] tricky eval() problem

2005-07-22 Thread Marcus Goldfish
Here's a noodler I could use some help on: I need a class that can
call a user-specified function with arbitrary (unknown) parameter
lists.  The trick, here, is that the user will dynamically specify the
funciton to invoke, and each function may differ in the number of
parameters passed during the call.  For instance, suppose I define two
dummy functions with different calling signatures:

def foo1(a1, a2, a3):
   ...

def foo2(a1):
  ...

Then I seek a class, Caller

class Caller(object):
   def execute(self, method, *parms):
  # some way to execute method

That can be used in the following manner:

>> c = Caller();
>> c.execute("foo1", 8, 9, 10)
>> c.execute("foo2", "me")

Any tips on tackling this?

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


Re: [Tutor] redirecting output to logfile and logrotate

2005-07-22 Thread Danny Yoo


On Fri, 22 Jul 2005, Winfried Tilanus wrote:

> I am installing a server-like python program that opens a logfile in the
> following way:
>
> # redirect output for logging to file
> applog = open(config.log, 'a', 1)
> sys.stdout = applog
> sys.stderr = sys.stdout
>
> Througout the program are lines like:
>
> print '[', time.asctime(),']', message[:3]
>
> The logfiles of the program can grow quite a big, so I decided to
> include them in logrotate.


Hi Winfried,

You may want to look at the 'logging' module:

http://docs.python.org/lib/module-logging.html

because it comes with a RotatingFileHandler that behaves like logrotate
for Python programs.


> How can I make the logging (including stderr) 'logrotate-proof'?

The approach to keep the log file open throughout the lifetime of the
program is what's causing issues with logrotate.  logrotate doesn't work
nicely with persistant server programs, because the server keeps the file
object open during the rotation, and that's bad.


(Just as an aside: the Mailman folks run into a similar issue:
http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq04.007.htp)


So if it's possible, I'd recommend using the RotatingFileHandler logger
from Python's 'logging' Standard Library module instead of 'logrotate'.


Hope this helps!

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


Re: [Tutor] HELP ME DUDE

2005-07-22 Thread byron
Quoting Suranga Sarukkali <[EMAIL PROTECTED]>:

> Hay, you know what? when I connect to the internet the modem software(Error
> Free Software for Sure)  say's a around 50-53.3Kbps connected though when I
> download a file from a server not p2ps or any of the kind service the
> downloads are even when connection is idle without any other method of
> bandwidth usage the downloads are at 4 Kilobytes per second but that should
> be around 8 Kilobytes per second as a thumb rule, you know that right? so I
> wonder is it's the malware or any type or WHAT could be the reason or even
> not how to get the said 53.3k (8KBs per second) download rate to my pc? oh
> remember to reply to me as soon as possible.


Hi Suranga,

This is a Python programming group.  If you have any Python questions, then this
is the place to ask them.  However, Anything outside of that scope will
probably not get you too much help.  ;-)

Byron
---



This message was sent using IMP, the Internet Messaging Program.

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


Re: [Tutor] Please Help: Hacking

2005-07-22 Thread byron
Quoting Jeremy Jones <[EMAIL PROTECTED]>:
> Here you go.  This should be enlightening:
>
> http://www.catb.org/~esr/writings/unix-koans/script-kiddie.html

Hi Jeremy,

That's great...  Thanks for sharing the link.

Byron
---



This message was sent using IMP, the Internet Messaging Program.

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


Re: [Tutor] Please Help: Hacking

2005-07-22 Thread Jeremy Jones
Suranga Sarukkali wrote:

> Python's Great fro Hacking Right? Please tell me more like when you 
> tell it to a College Student (That tell's What I'm) and since I 
> Sort of new to Programming in Python it's going be easy if done so. 
> Please reply to me at your earliest convenience and by the way General 
> Hacking Education will be Cool since the only hacking I've done is on 
> a Hacking Simulation Game I downloaded yeas ago from 
> http://g1.acid-play.com/download/a599b964/Hackerv1.zip witch got all 
> the tools like Password Crackers Inbuilt to Simulate Hacking Large 
> Company's and making cash from it. You can privately email me on 
> [EMAIL PROTECTED] 
>  
> I've been on the Mailing List some time and It's Great! Thanks for the 
> People Developed it.
>
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>  
>
Here you go.  This should be enlightening:

http://www.catb.org/~esr/writings/unix-koans/script-kiddie.html


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


Re: [Tutor] Please Help: Hacking

2005-07-22 Thread Adam Bark
How to become a hackerOn 7/17/05, Suranga Sarukkali <
[EMAIL PROTECTED]> wrote:






Python's Great fro Hacking Right? Please tell me more like 
when you tell it to a College Student (That tell's What I'm) 
and since I Sort of new to Programming in Python it's going be 
easy if done so. Please reply to me at your earliest convenience and by the way 
General Hacking Education will be Cool since the only hacking I've done is on a 
Hacking Simulation Game I downloaded yeas ago from http://g1.acid-play.com/download/a599b964/Hackerv1.zip
 witch 
got all the tools like Password Crackers Inbuilt to Simulate Hacking Large 
Company's and making cash from it. You can privately email me on [EMAIL PROTECTED] 
 
I've been on the Mailing List some time and It's Great! Thanks 
for the People Developed it. 

___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] HELP ME DUDE

2005-07-22 Thread Suranga Sarukkali



Hay, you know what? when I connect to the internet the modem 
software(Error Free Software for Sure)  say's a around 50-53.3Kbps 
connected though when I download a file from a server not p2ps or any of the 
kind service the downloads are even when connection is idle without any other 
method of bandwidth usage the downloads are at 4 Kilobytes per second but that 
should be around 8 Kilobytes per second as a thumb rule, you know that right? so 
I wonder is it's the malware or any type or WHAT could be the reason or even not 
how to get the said 53.3k (8KBs per second) download rate to my pc? oh remember 
to reply to me as soon as possible.
BEGIN:VCARD
VERSION:2.1
N:Sarukkali;Suranga;;Ms
FN:Suranga Sarukkali
NICKNAME:saruk
TEL;HOME;VOICE:0942610560
ADR;HOME:;;12B, 4th Cross Lane, Borupana Road,;Ratmalana,;WP,;10345;Sri Lanka
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:12B, 4th Cross Lane, Borupana Road,=0D=0ARatmalana,, WP, 10345=0D=0ASri Lank=
a
X-WAB-GENDER:2
BDAY:19891011
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20050720T155521Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Please Help: Hacking

2005-07-22 Thread Suranga Sarukkali



Python's Great fro Hacking Right? Please tell me more like 
when you tell it to a College Student (That tell's What I'm) 
and since I Sort of new to Programming in Python it's going be 
easy if done so. Please reply to me at your earliest convenience and by the way 
General Hacking Education will be Cool since the only hacking I've done is on a 
Hacking Simulation Game I downloaded yeas ago from http://g1.acid-play.com/download/a599b964/Hackerv1.zip witch 
got all the tools like Password Crackers Inbuilt to Simulate Hacking Large 
Company's and making cash from it. You can privately email me on [EMAIL PROTECTED] 
 
I've been on the Mailing List some time and It's Great! Thanks 
for the People Developed it. 
BEGIN:VCARD
VERSION:2.1
N:Sarukkali;Suranga;;Ms
FN:Suranga Sarukkali
NICKNAME:saruk
TEL;HOME;VOICE:0942610560
ADR;HOME:;;12B, 4th Cross Lane, Borupana Road,;Ratmalana,;WP,;10345;Sri Lanka
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:12B, 4th Cross Lane, Borupana Road,=0D=0ARatmalana,, WP, 10345=0D=0ASri Lank=
a
X-WAB-GENDER:2
BDAY:19891011
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20050717T062640Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] redirecting output to logfile and logrotate

2005-07-22 Thread Winfried Tilanus
Hi,

I am installing a server-like python program that opens a logfile in
the following way:

# redirect output for logging to file
applog = open(config.log, 'a', 1)
sys.stdout = applog
sys.stderr = sys.stdout

Througout the program are lines like:

print '[', time.asctime(),']', message[:3]

The logfiles of the program can grow quite a big, so I decided to
include them in logrotate. That is where the problem started: everytime
the logfile gets rotated python loses track of it and stops logging.
The program is running on a linux server with python 2.2.

How can I make the logging (including stderr) 'logrotate-proof'?

thanks
&
Best wishes,
Winfried

-- 
http://www.xs4all.nl/~wtilanus/

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