Re: [Tutor] StringIO

2006-05-23 Thread Kent Johnson
kakada wrote:
> Actually, what I want is creating a kind of file that is just located in
> memory not file system.
> I want to have a filename for my convert(inputFileName, outputFileName)
> How can I get filename?
> doing:
> fin.name() is impossible!

Rewrite convert so it takes file-like objects as arguments rather than 
file names. Then you can pass StringIO objects for input and output in 
your unittests.

Alternately you might want to write convert so it can take *either* a 
file name or an open file as an argument. Here is a snippet from a 
function that does that (ElementTree.parse()):
 def parse(self, source, parser=None):
 if not hasattr(source, "read"):
 source = open(source, "rb")

> All above, I want to test it in unittest.

Good idea!

Kent

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


[Tutor] I'm drawing a blank on a simple (?) regex

2006-05-23 Thread R. Alan Monroe
I'm searching through SQL logs and want to find lines that have
WHERE-less (unbounded) queries. I can't come up with a regex to say:

SELECT.*FROM.*(the word WHERE must not exist anywhere in the remainder
of the line)

Am I forgetting something simple or would this take two passes?

Alan

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


Re: [Tutor] I'm drawing a blank on a simple (?) regex

2006-05-23 Thread Kent Johnson
R. Alan Monroe wrote:
> I'm searching through SQL logs and want to find lines that have
> WHERE-less (unbounded) queries. I can't come up with a regex to say:
> 
> SELECT.*FROM.*(the word WHERE must not exist anywhere in the remainder
> of the line)
> 
> Am I forgetting something simple or would this take two passes?

Try using a negative look-ahead:
SELECT.*FROM(?!.*WHERE)

Kent

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


Re: [Tutor] OT: any good newsgroup or other forum for MP3 internals discussions?

2006-05-23 Thread Terry Carroll
On Mon, 22 May 2006, [ISO-8859-1] Hugo Gonz?lez Monteverde wrote:

> Are you using any kind of prefabricated Python module for this? Maybe 
> their implementation of MP3 tagging is enlightening to you.

I started to; I started using the mp3.py module found here: 
http://www.dotfunk.com/projects/mp3 , but there were a lot of files that 
it fails on (giving incorrect results or throwing an exception), and the 
files are playable and give readable ID3 tags in multiple MP3 apps (e.g., 
Magnus Brading's Mp3/Tag Studio and WinAmp).  So I decided to try to write 
my own.

My first cut was to try to modify that module, but it's a little bit 
idiosyncratic, and at least one part of it (apparently in a part that's 
not actually reached, or maybe whose result is not used) is incorrect.

I thought it would be kind of fun to write my own, too; I'm just running 
into issues where a header does not seem (I say "seem," because I'm 
very aware the problem might be my interpretation) to conform to the 
specs, but which are handled just fine by other utilities I check against 
it.

> Remember that ID3 in MP3 was a dirty hack at the beginning, so it is 
> likely that may files are nonconformant or that many different programs 
> simply follow their gut, as there was no specification.

ID3V2 seems to be very clearly specified, though; and ID3V1 is simple 
enough that i isn't a problem.  But some of my questions will be going to 
the MP3 frame data itself, even apart from the ID3 stuff.

But yesterday, while looking again for a newsgroup where my discussion 
would be on-topic, I saw numerous mentions of a Python package called 
eye3D, and tracked it down to http://eyed3.nicfit.net/ .  I'll see if that 
meets my needs.

Thanks, Hugo.

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


Re: [Tutor] I'm drawing a blank on a simple (?) regex

2006-05-23 Thread R. Alan Monroe
> R. Alan Monroe wrote:
>> I'm searching through SQL logs and want to find lines that have
>> WHERE-less (unbounded) queries. I can't come up with a regex to say:
>> 
>> SELECT.*FROM.*(the word WHERE must not exist anywhere in the remainder
>> of the line)
>> 
>> Am I forgetting something simple or would this take two passes?

> Try using a negative look-ahead:
> SELECT.*FROM(?!.*WHERE)

Brilliant - works in python redemo, and grep too w/ -P switch.

Alan

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


Re: [Tutor] problem with class - get message that self is not defined

2006-05-23 Thread Bob Gailer
Alan Gauld wrote:
>> When I try to use the class listed below, I get the statement that 
>> self
>> is not defined.
>>
>> test=TriggerMessage(data)
>> var = test.decode(self.qname)
>>
>> I would have thought that self would have carried forward when I 
>> grabbed
>> an instance of TriggerMessage.
>> 
>
> self is a special varianble 
"special variable" could be confusing. Python has no "special 
variables". "self" is used by convention. One could use "this" as an 
alternative, or any other variable. When defining a method in a class 
one writes def abc(self, a,b,c) OR def abc(this, a,b,c). Then one refers 
to "self" or "this" within the method to refer to the instance calling 
the method.

-- 
Bob Gailer
510-978-4454

Broadband Phone Service for local and long distance $19.95/mo plus 1 mo Free 


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


Re: [Tutor] problem with class - get message that self is not defined

2006-05-23 Thread Alan Gauld
>> self is a special varianble
> "special variable" could be confusing. Python has no "special 
> variables". "self" is used by convention.

Good point. The name self is not special it is its role that is 
special.

thus

class C:
def m(s,p):
print p

c = C()
c.m(42)

Thus we define method m to have two parameters s and p
but when we call m we only pass in one argument. Python
then takes this and turns it into

C.m(c,42)

The specialness of 'self' is that although we specify it, and can 
access it,
in the method definition we do not specify it in the message to the 
class
that invokes the method.

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