Regular expression issue

2010-08-08 Thread genxtech
I am trying to learn regular expressions in python3 and have an issue
with one of the examples I'm working with.
The code is:

#! /usr/bin/env python3

import re

search_string = "[^aeiou]y$"
print()

in_string = 'vacancy'
if re.search(search_string, in_string) != None:
print(" ay, ey, iy, oy and uy are not at the end of
{0}.".format(in_string))
else:
print(" ay, ey, iy, oy or uy were found at the end of
{0}.".format(in_string))
print()

in_string = 'boy'
if re.search(search_string, in_string) != None:
print(" ay, ey, iy, oy and uy are not at the end of
{0}.".format(in_string))
else:
print(" ay, ey, iy, oy or uy were found at the end of
{0}.".format(in_string))
print()

in_string = 'day'
if re.search(search_string, in_string) != None:
print(" ay, ey, iy, oy and uy are not at the end of
{0}.".format(in_string))
else:
print(" ay, ey, iy, oy or uy were found at the end of
{0}.".format(in_string))
print()

in_string = 'pita'
if re.search(search_string, in_string) != None:
print(" ay, ey, iy, oy and uy are not at the end of
{0}.".format(in_string))
else:
print(" ay, ey, iy, oy or uy were found at the end of
{0}.".format(in_string))
print()

The output that I am getting is:
   ay, ey, iy, oy and uy are not at the end of vacancy.
   ay, ey, iy, oy or uy were found at the end of boy.
   ay, ey, iy, oy or uy were found at the end of day.
   ay, ey, iy, oy or uy were found at the end of pita.

The last line of the output is the opposite of what I expected to see,
and I'm having trouble figuring out what the issue is.  Any help would
be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression issue

2010-08-09 Thread genxtech
On Aug 8, 7:34 pm, Tim Chase  wrote:
> On 08/08/10 17:20, genxtech wrote:
>
> > if re.search(search_string, in_string) != None:
>
> While the other responses have addressed some of the big issues,
> it's also good to use
>
>    if thing_to_test is None:
>
> or
>
>    if thing_to_test is not None:
>
> instead of "== None" or "!= None".
>
> -tkc

I would like to thank all of you for your responses.  I understand
what the regular expression means, and am aware of the double negative
nature of the test.  I guess what I am really getting at is why the
last test returns a value of None, and even when using the syntax
suggested in this quoted solution, the code for the last test is doing
the opposite of the previous 2 tests that also returned a value of
None.  I hope this makes sense and clarifies what I am trying to ask.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression issue

2010-08-09 Thread genxtech
I have it now. Had to beat my head over it a couple times.  Thanks
everybody.
-- 
http://mail.python.org/mailman/listinfo/python-list


Assert statements in python 3.1

2010-08-19 Thread genxtech
This is more of a curiosity question then anything else...  I was just
wondering why in version 3 of python assertions weren't converted to
use parenthesis, since print was.

I am just asking because it seems the following line of code would
seem more readable as a function:
   assert 2 + 2 == 5, "Only for very large values of 2."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overload print

2010-08-27 Thread genxtech
On Aug 25, 5:18 pm, Ross Williamson 
wrote:
> Hi All
>
> Is there anyway in a class to overload the print function?
>
> >> class foo_class():
> >>      pass
> >> cc = foo_class()
> >> print cc
>
> Gives:
>
> <__main__.foo_class instance at >
>
> Can I do something like:
>
> >> class foo_class():
> >>     def __print__(self):
> >>           print "hello"
> >> cc = foo_class()
> >> print cc
>
> Gives:
>
> hello
>
> I'm looking at finding nice way to print variables in a class just by
> asking to print it
>
> Cheers
>
> Ross
>
> --
> Ross Williamson
> University of Chicago
> Department of Astronomy & Astrophysics
> 773-834-9785 (office)
> 312-504-3051 (Cell)

Are you talking about overriding print(), kind of like overloading the
<< operator in c++ so that you can determine how the foo_class gets
printed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about Reading Files

2010-09-04 Thread genxtech
Hello.  I am still really new to python and I have a project where I
am trying to use the data files from another program and write a new
program with new user interface and all.  My first step was to open
one of the files in 'rb' mode and print the contents, but I am
unfamiliar with the format.  Here is what was printed to the terminal:

b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f
\x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y
\x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$
\x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n
\x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc
\x00\x00\x0c\x19\x00\x00'

I am using Python 3.1 on a Fedora 13 box if that makes any difference.
Any advise on how to decode the data would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about Reading Files

2010-09-04 Thread genxtech
I forgot to mention that the output was the first 100 bytes of the
output
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about Reading Files

2010-09-04 Thread genxtech
On Sep 4, 7:23 pm, Mats Rauhala  wrote:
> On 2010-09-04, genxtech  wrote:
>
> > Hello.  I am still really new to python and I have a project where I
> > am trying to use the data files from another program and write a new
> > program with new user interface and all.  My first step was to open
> > one of the files in 'rb' mode and print the contents, but I am
> > unfamiliar with the format.  Here is what was printed to the terminal:
>
> > I am using Python 3.1 on a Fedora 13 box if that makes any difference.
> > Any advise on how to decode the data would be greatly appreciated.
>
> It's difficult to elaborate with only that information. What you have
> done now is opened a file in read binary mode (r = read, b = binary) and
> then tried to print it. Python has escaped the data as hex (\x01) and is
> basically a hex dump of the data file.
>
> For decoding the data, you either need to somehow figure out the format
> of the data and then decode it accordingly. If you're on unix box the
> 'file' command might be of help.
>
> If you're not on a unix box, you could check out how the file command
> tries to find the type of the file. The man page for magic [1] could be
> of help. Also see list of magic numbers [2]
>
> [1]http://linux.die.net/man/5/magic
> [2]http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html

I am using Fedora 13.  When I run the file command the response is
that it is a 'data' file.  If there are any tips on how to
programatically figure out the format, I would greatly appreciate it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about Reading Files

2010-09-05 Thread genxtech
On Sep 5, 4:16 am, Peter Otten <__pete...@web.de> wrote:
> genxtech wrote:
> > Hello.  I am still really new to python and I have a project where I
> > am trying to use the data files from another program and write a new
> > program with new user interface and all.  My first step was to open
> > one of the files in 'rb' mode and print the contents, but I am
> > unfamiliar with the format.  Here is what was printed to the terminal:
>
> > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f
> > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y
> > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$
> > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n
> > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc
> > \x00\x00\x0c\x19\x00\x00'
>
> > I am using Python 3.1 on a Fedora 13 box if that makes any difference.
> > Any advise on how to decode the data would be greatly appreciated.
>
> What's the name of the file?
> What's the program that uses the file?
> If the source code is available, what library does that program use to read
> the file?
>
> Peter

Unfortunately the source code isn't available, so I'm trying to figure
out a way to get the format of the file on my own.
-- 
http://mail.python.org/mailman/listinfo/python-list