Expandable 2D Dictionaries?

2007-07-06 Thread Robert Dailey
Hi,

I am interested in creating an expandable (dynamic) 2D dictionary. For
example:

myvar["cat"]["paw"] = "Some String"

The above example assumes "myvar" is declared. In order for this to
work, I have to know ahead of time the contents of the dictionary. For
the above to work, my declaration must look like:

myvar = {"cat": {"paw":""} }

I would like to not have to declare my dictionary like this, as it
does not allow it to be expandable. I'm very new to Python (I'm a
professional C++ programmer. Any comparisons to C++ would help me
understand concepts).

Is there a way that when I index into my dictionary using an "unknown"
index (string), that python will dynamically add that key/value pair?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Expandable 2D Dictionaries?

2007-07-06 Thread Robert Dailey
On Jul 6, 11:09 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Fri, 06 Jul 2007 15:43:55 -0000, Robert Dailey <[EMAIL PROTECTED]> wrote:
> >Hi,
>
> >I am interested in creating an expandable (dynamic) 2D dictionary. For
> >example:
>
> >myvar["cat"]["paw"] = "Some String"
>
> >The above example assumes "myvar" is declared. In order for this to
> >work, I have to know ahead of time the contents of the dictionary. For
> >the above to work, my declaration must look like:
>
> >myvar = {"cat": {"paw":""} }
>
> >I would like to not have to declare my dictionary like this, as it
> >does not allow it to be expandable. I'm very new to Python (I'm a
> >professional C++ programmer. Any comparisons to C++ would help me
> >understand concepts).
>
> >Is there a way that when I index into my dictionary using an "unknown"
> >index (string), that python will dynamically add that key/value pair?
>
> This gets much easier if you change your structure around a bit:
>
> d = {}
> d["cat", "paw"] = "some string"
>
> Jean-Paul

I like this format. I'm not familiar with it however. In my research
of python I was not aware it was legal to have comma operators inside
of the brackets. What does this mean? Is there some terminology that I
can search for to research this concept? Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Expandable 2D Dictionaries?

2007-07-06 Thread Robert Dailey
On Jul 6, 10:54 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Robert Dailey wrote:
> > Hi,
>
> > I am interested in creating an expandable (dynamic) 2D dictionary. For
> > example:
>
> > myvar["cat"]["paw"] = "Some String"
>
> > The above example assumes "myvar" is declared. In order for this to
> > work, I have to know ahead of time the contents of the dictionary. For
> > the above to work, my declaration must look like:
>
> > myvar = {"cat": {"paw":""} }
>
> > I would like to not have to declare my dictionary like this, as it
> > does not allow it to be expandable. I'm very new to Python (I'm a
> > professional C++ programmer. Any comparisons to C++ would help me
> > understand concepts).
>
> > Is there a way that when I index into my dictionary using an "unknown"
> > index (string), that python will dynamically add that key/value pair?
>
> Not really, unless you know that the first level of values are _always_
> dicts.
>
> What you can do is to use
>
> myvar.setdefault('cat', {})['paw'] = "Some String"
>
> Diez

Could you emphasize what you mean by "unless you know that the first
level of values are _always_ dicts."?

Could I create a class wrapper that automates this? I could have an
insert() method of some sort. However I would have to research if it's
possible to overload operators in python.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Expandable 2D Dictionaries?

2007-07-06 Thread Robert Dailey
Thank you all very much for your valuable replies. I wasn't aware that
tuples were valid keys in a dictionary object. This is actually the
solution I was looking for. Thank you all once again.

-- 
http://mail.python.org/mailman/listinfo/python-list


ImportError: "No Module named xxx"

2007-07-06 Thread Robert Dailey
I created a basic python file and made an attempt to execute it from
the command line, however it gives me a weird error after the python
file has been executed:

Traceback (most recent call last):
  File "C:\Python25\lib\runpy.py", line 87, in run_module
raise ImportError("No module named " + mod_name)
ImportError: No module named compile.py


The command I executed was: "python -m compile.py" (compile.py is my
python script)

Can anyone help me figure out why it's doing this?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: "No Module named xxx"

2007-07-06 Thread Robert Dailey
Never mind, I found the problem. I was doing:

python -m compile.py

I really should have been doing:

python compile.py


The description of -m is confusing in the documentation, what does it
really do?

-- 
http://mail.python.org/mailman/listinfo/python-list


C++ Modules for python: How to?

2007-07-06 Thread Robert Dailey
Hi,

I'm interested in making a C++ library of mine usable through python.
Python does a similar thing with Expat (the non-validating XML
parser). I notice that with Expat, python is importing a C++ header
file into a PY file and the interface is available to python. I've
read through the python documentation as well as done a little bit of
google research and I've not been able to find a tutorial of some sort
on how to do this. Perhaps I just don't know the right words to search
for.

If anyone could lead me in the right direction (possibly an article,
tutorial, etc) I would greatly appreciate it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: "No Module named xxx"

2007-07-06 Thread Robert Dailey
On Jul 6, 4:04 pm, Bjoern Schliessmann  wrote:
> Robert Dailey wrote:
> > The description of -m is confusing in the documentation, what does
> > it really do?
>
> IMHO, it's quite clear. What's unclear with this description:
>
> -m module-nameSearches sys.path for the named module and runs
>   the corresponding .py file as a script.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #191:
>
> Just type 'mv * /dev/null'.

Perhaps the confusing part is their definition of "Script". I figured
any .py file was a "python script", in that it has code to execute-
making it a script.

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C++ Modules for python: How to?

2007-07-06 Thread Robert Dailey
On Jul 6, 3:06 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Robert Dailey schrieb:
>
> > Hi,
>
> > I'm interested in making a C++ library of mine usable through python.
> > Python does a similar thing with Expat (the non-validating XML
> > parser). I notice that with Expat, python is importing a C++ header
> > file into a PY file and the interface is available to python. I've
> > read through the python documentation as well as done a little bit of
> > google research and I've not been able to find a tutorial of some sort
> > on how to do this. Perhaps I just don't know the right words to search
> > for.
>
> > If anyone could lead me in the right direction (possibly an article,
> > tutorial, etc) I would greatly appreciate it.
>
> The best thing to do is to offer your C++-lib with a C-style interface.
> Then you can use python's ctypes (included since python2.5) to access
> the shared library.
>
> If you insist on using C++, you can expose the lib using several
> available wrapper generators. I know of three: SIP, Swig &
> Boost::Python. The first I've got some very good first-hand experience.
> The second is somewhat primitive IHMO. The third I never used.
>
> Use these to google in this group, you'll find plenty of stuff.
>
> Diez

How do I install SIP? I can't seem to do this. I've downloaded the
package and read the README file, but I don't see a way of installing
it on windows. I ran the configure.py file but then it generates
makefiles to run which can't be run on windows. I also attempted to
download QT but it doesn't appear to be free (it's an evaluation and I
don't feel like submitting my personal information to download it).

Am I missing something? Thank you for your reply.

-- 
http://mail.python.org/mailman/listinfo/python-list


Distributing python apps

2007-07-09 Thread Robert Dailey
Hi,

I'm creating a set of command-line tools using Python. These tools
manage resources for a game I'm working on. However, many people that
will be using these tools will not want to install Python on their
machines. This would be a very tedious process (for first time users
of my tools).

Ideally, I would like for someone to be able to use my tools without
having to install Python. For example, if I could put python.exe in a
hidden folder somewhere in my tools directory, and make a batch file
that they run to start the tool, python could be executed from a
relative path in my tools directory. Is this possible? What is an
ideal way of distributing python apps? I would prefer a transparent
and user-friendly approach.

Thanks for any tips.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributing python apps

2007-07-09 Thread Robert Dailey
Thanks a ton guys. You both gave me the exact answers I was looking
for.

-- 
http://mail.python.org/mailman/listinfo/python-list


PyXML not installing?

2007-07-09 Thread Robert Dailey
Hi,

I downloaded the PyXML library and I'm attempting to install it by
following the README file on Windows XP. I currently have Visual
Studio 2005 installed.

>From the command line I type:

C:\PyXML-0.8.4>python setup.py build
running build
running build_py
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible
binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin
installed,
you can try compiling with MingW32, by passing "-c mingw32" to
setup.py.

It gives me the above error message. Any way to fix this?

Thanks ahead of time.

-- 
http://mail.python.org/mailman/listinfo/python-list


How to create new files?

2007-07-12 Thread Robert Dailey
Hi,

I'm trying to create a Python equivalent of the C++ "ifstream" class,
with slight behavior changes.

Basically, I want to have a "filestream" object that will allow you to
overload the '<<' and '>>' operators to stream out and stream in data,
respectively. So far this is what I have:

class filestream:
def __init__( self, filename ):
self.m_file = open( filename, "rwb" )

#   def __del__( self ):
#   self.m_file.close()

def __lshift__( self, data ):
self.m_file.write( data )

def __rshift__( self, data ):
self.m_file.read( data )


So far, I've found that unlike with the C++ version of fopen(), the
Python 'open()' call does not create the file for you when opened
using the mode 'w'. I get an exception saying that the file doesn't
exist. I expected it would create the file for me. Is there a way to
make open() create the file if it doesn't exist, or perhaps there's
another function I can use to create the file? I read the python docs,
I wasn't able to find a solution.

Also, you might notice that my "self.m_file.read()" function is wrong,
according to the python docs at least. read() takes the number of
bytes to read, however I was not able to find a C++ equivalent of
"sizeof()" in Python. If I wanted to read in a 1 byte, 2 byte, or 4
byte value from data into python I have no idea how I would do this.

Any help is greatly appreciated. Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Function parameter type safety?

2007-07-12 Thread Robert Dailey
Hi,

Is there a way to force a specific parameter in a function to be a
specific type? For example, say the first parameter in a function of
mine is required to be a string. If the user passes in an integer, I
want to notify them that they should pass in a string, not an integer.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function parameter type safety?

2007-07-13 Thread Robert Dailey
Good replies.

I'm in the process of learning Python. I'm a native C++ programmer, so
you can see how the question relates. There's a lot of cool things C++
allowed you to do with type-checking, such as function overloading.
With templates + type checking, I can create a STD version of ifstream/
ofstream in Python. However, I found it isn't possible since Python
mainly works with strings in file data instead of bytes. To write a
number 40 to a file in python would take 6 bytes instead of 4, for
example. Anyway, I just wanted to explain why I was asking about type
checking. There's other measures I'm willing to take to get my job
done. Thanks guys.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to create new files?

2007-07-13 Thread Robert Dailey
On Jul 13, 3:04 am, Bruno Desthuilliers  wrote:
> Robert Dailey a écrit :
>
> > Hi,
>
> > I'm trying to create a Python equivalent of the C++ "ifstream" class,
> > with slight behavior changes.
>
> > Basically, I want to have a "filestream" object that will allow you to
> > overload the '<<' and '>>' operators to stream out and stream in data,
> > respectively. So far this is what I have:
>
> > class filestream:
>
> class Filestream(object):
>
> >def __init__( self, filename ):
> >self.m_file = open( filename, "rwb" )
>
> You don't need this C++ 'm_' prefix here - since the use of self is
> mandatory, it's already quite clear that it's an attribute.
>
>
>
> > #  def __del__( self ):
> > #  self.m_file.close()
>
> >def __lshift__( self, data ):
> >self.m_file.write( data )
>
> >def __rshift__( self, data ):
> >self.m_file.read( data )
>
> > So far, I've found that unlike with the C++ version of fopen(), the
> > Python 'open()' call does not create the file for you when opened
> > using the mode 'w'.
>
> It does. But you're not using 'w', but 'rw'.
>
> > I get an exception saying that the file doesn't
> > exist.
>
> Which is what happens when trying to open an inexistant file in read mode.
>
> > I expected it would create the file for me. Is there a way to
> > make open() create the file if it doesn't exist
>
> yes : open it in write mode.
>
> def __init__( self, filename ):
>  try:
>  self._file = open( filename, "rwb" )
>  except IOError:
>  # looks like filename doesn't exist
>  f = open(filename, 'w')
>  f.close()
>  self._file = open( filename, "rwb" )
>
> Or you can first test with os.path.exists:
>
> def __init__( self, filename ):
>  if not os.path.exists(filename):
>  # looks like filename doesn't exist
>  f = open(filename, 'w')
>  f.close()
>  self._file = open( filename, "rwb" )
>
> HTH

Thanks for the variable naming tips. Is it normal for Python
programmers to create class members with a _ prefixed?

I also figured out why it wasn't creating the file after I had posted,
I realized I was doing "rw" instead of just "w". Thank you for
verifying. Thanks to everyone else for your replies as well.

-- 
http://mail.python.org/mailman/listinfo/python-list

Pass by reference or by value?

2007-07-13 Thread Robert Dailey
Hi,

I noticed in Python all function parameters seem to be passed by
reference. This means that when I modify the value of a variable of a
function, the value of the variable externally from the function is
also modified.

Sometimes I wish to work with "copies", in that when I pass in an
integer variable into a function, I want the function to be modifying
a COPY, not the reference. Is this possible?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference or by value?

2007-07-13 Thread Robert Dailey
On Jul 13, 2:10 pm, Robert Dailey <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I noticed in Python all function parameters seem to be passed by
> reference. This means that when I modify the value of a variable of a
> function, the value of the variable externally from the function is
> also modified.
>
> Sometimes I wish to work with "copies", in that when I pass in an
> integer variable into a function, I want the function to be modifying
> a COPY, not the reference. Is this possible?
>
> Thanks.

Correction:

I ran a few more tests and python actually does a pass by value,
meaning that a "copy" is made and the external variable that was
passed in remains unchanged. I actually want to know how to "pass by
reference", in that any changes made to a parameter inside of a
function also changes the variable passed in.

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


The ** operator ambiguous?

2007-07-16 Thread Robert Dailey
I noticed that the ** operator is used as the power operator, however
I've seen it used when passing variables into a function. For example,
I was researching a way to combine dictionaries. I found that if you
do this:

a = {"t1":"a", "t2":"b"}
b = {"t3":"c"}
dict( a, **b )


This combines the two dictionaries. However, I have no idea what the
** operator is here. I know that when you specify ** as a parameter in
a function definition, it represents a dictionary of parameters passed
in. However, in this example it is NOT being used in a function
definition. It is being used when passing variables into a function.
Can someone explain what this means? I looked in the documentation but
I couldn't find anything.

-- 
http://mail.python.org/mailman/listinfo/python-list


Confused with csv.reader copies

2007-07-23 Thread Robert Dailey
First, take a look at my example code:
-
import csv

def pass1( reader ):
print reader.next()
print reader.next()

def pass2( reader ):
print reader.next()
print reader.next()

reader = csv.reader( open( "C:/IT/Method/SpaceImpact/code/tools/
ProfileViewer/performance_profile.csv", "rb" ) )

pass1( reader )
pass2( reader )
-

The output is as follows:
-
['0', 'root', '00:01:32.793591', '1']
['1', 'Engine::Tick', '00:00:25.886411', '1851']
['2', 'Sprite::Tick', '00:00:00.001495', '385']
['2', 'Entity::Tick', '00:00:00.001485', '45']
-

I expected the output to be this:
-
['0', 'root', '00:01:32.793591', '1']
['1', 'Engine::Tick', '00:00:25.886411', '1851']
['0', 'root', '00:01:32.793591', '1']
['1', 'Engine::Tick', '00:00:25.886411', '1851']
-

My understanding is that objects are passed by reference, meaning
there is no hard copy of the data, however the copies passed to
functions do not affect the version passed in. In other words, when I
call "next" on the reference passed into each function, it should not
affect the variable that was originally passed in.

I'm attempting to use recursion to build a TreeCtrl in wxPython using
this data, and I can't get it to work properly if the variable outside
of the function call ends up having its state (e.g., its "next"
pointer) modified by passing it into other functions.

Any tips on getting this to work? I'm a native C++ programmer still
learning Python, so I apologize for any confusion. Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython - How to add sorting to a ListCtrl?

2007-07-24 Thread Robert Dailey
Hi,

I have 3 columns in my list control, each with a different "type" of
data (for example, one column has names, the other has dates, etc).
Can anyone reference a tutorial for solving this issue? I've done my
share of googling to no avail. I need the user to be able to click any
of the column headers and sort the rows of data by that column in
ascending or descending order.

Thanks for your time.

-- 
http://mail.python.org/mailman/listinfo/python-list


datetime.time() class - How to pass it a time string?

2007-07-24 Thread Robert Dailey
Hi,

I have a string in the following format:

"00:00:25.886411"

I would like to pass this string into the datetime.time() class and
have it parse the string and use the values. However, the __init__()
method only takes integers (which means I'd be forced to parse the
string myself). Does anyone know of a way I can make it use the
string? Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


128 or 96 bit integer types?

2007-07-27 Thread Robert Dailey
Hi,

Is there build-in or third party support for large integer types, such
as 96 or 128 bits in size? I require such large sizes for precision
issues (nanoseconds). Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ Modules for python: How to?

2007-07-27 Thread Robert Dailey
On Jul 6, 7:39 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 7, 9:26 am,RobertDailey<[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 6, 3:06 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> > >RobertDaileyschrieb:
>
> > > > Hi,
>
> > > > I'm interested in making a C++ library of mine usable through python.
> > > > Python does a similar thing with Expat (the non-validating XML
> > > > parser). I notice that with Expat, python is importing a C++ header
> > > > file into a PY file and the interface is available to python. I've
> > > > read through the python documentation as well as done a little bit of
> > > > google research and I've not been able to find a tutorial of some sort
> > > > on how to do this. Perhaps I just don't know the right words to search
> > > > for.
>
> > > > If anyone could lead me in the right direction (possibly an article,
> > > > tutorial, etc) I would greatly appreciate it.
>
> > > The best thing to do is to offer your C++-lib with a C-style interface.
> > > Then you can use python's ctypes (included since python2.5) to access
> > > the shared library.
>
> > > If you insist on using C++, you can expose the lib using several
> > > available wrapper generators. I know of three: SIP, Swig &
> > > Boost::Python. The first I've got some very good first-hand experience.
> > > The second is somewhat primitive IHMO. The third I never used.
>
> > > Use these to google in this group, you'll find plenty of stuff.
>
> > > Diez
>
> > How do I install SIP? I can't seem to do this. I've downloaded the
> > package and read the README file, but I don't see a way of installing
> > it on windows. I ran the configure.py file but then it generates
> > makefiles to run which can't be run on windows. I also attempted to
> > download QT but it doesn't appear to be free (it's an evaluation and I
> > don't feel like submitting my personal information to download it).
>
> > Am I missing something?
>
> Probably.
>
> "makefiles ... which can't be run on windows"??? Have you acquired a
> make program [if necessary] and tried it? What happened?
>
> The free Borland compiler comes with a make.exe. If you plan to use
> GCC, you will probably need this:
>http://gnuwin32.sourceforge.net/packages/make.htm
> I understand that if you have a Microsoft compiler, you should have an
> nmake.exe.
>
> If all else fails, e-mail the package author, supplying some relevant
> information, like what compiler you are using, what options you used
> on the configure.py run, which "make" you are using, what happened
> when you ran that make, ...

The documentation is as follows:

"The next step is to build SIP by running your platform's make
command. For example:

make"

I ran "nmake" from the command line and it spammed:

cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make
cd sipgen
make:  Error code 194, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'
make:  Error code 255, while making 'all'

I used 'python configure.py -p win32-msvc2005'

Any idea why this is failing?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ Modules for python: How to?

2007-07-27 Thread Robert Dailey
Okay I've actually got it compiling now, however it is saying it can't
find "stdio.h" (No such file or directory). This means it doesn't know
where the include directories are. How do I specify include
directories?

-- 
http://mail.python.org/mailman/listinfo/python-list


Iteration over strings

2007-07-31 Thread Robert Dailey
Hi,

I have the following code:

str = "C:/somepath/folder/file.txt"

for char in str:
if char == "\\":
char = "/"

The above doesn't modify the variable 'str' directly. I'm still pretty new
to Python so if someone could explain to me why this isn't working and what
I can do to achieve the same effect I would greatly appreciate it.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Iteration over strings

2007-07-31 Thread Robert Dailey
Hey,

Thanks a lot for your answers guys. I had already known that strings are
immutable, but having been a C++ programmer for years I'm still trying to
get over the fact that it's not std::string :) The python documentation
isn't that easy to navigate in my opinion, so I wasn't able to find the
'replace()' function you guys are talking about. It's actually the perfect
solution for the problem.

I appreciate your time.

On 7/31/07, Hexamorph <[EMAIL PROTECTED]> wrote:
>
> Jay Loden schrieb:
> > Robert Dailey wrote:
> >> str = "C:/somepath/folder/file.txt"
> >>
> >> for char in str:
> >> if char == "\\":
> >> char = "/"
>
> > strings in Python are immutable - in other words, they cannot be updated
> in place as you're doing above. However, that doesn't mean you can't achieve
> what you're after. In Python, the way to approach this problem since you
> cannot modify the string in place, is to create a new string object with the
> desired content:
>
> Also note, that you are just extracting one char from the string
> into another variable (which you then change) and you are *not*
> getting any "reference" to the char in the string.
>
> As has been alreagy told, use the str.replace() function
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Wing IDE for Python v. 3.0 beta1 released

2007-07-31 Thread Robert Dailey
Too bad it's not free. I'll stick with PSPad & IPython

On 7/31/07, Wingware <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm happy to announce the first beta release of Wing IDE 3.0.  It is
> available from http://wingware.com/wingide/beta
>
> Wing IDE is a commercial IDE designed specifically for Python programmers.
> More information about the product and free trials are available at
> http://wingware.com/
>
> The major new features introduced in Wing 3.0 are:
>
> * Multi-threaded debugger
> * Debug value tooltips in editor, debug probe, and interactive shell
> * Autocompletion in debug probe and interactive shell
> * Automatically updating project directories
> * Testing tool, currently supporting unittest derived tests (*)
> * OS Commands tool for executing and interacting with external commands
> (*)
> * Rewritten indentation analysis and conversion
>
> (*)'d items are available in Wing IDE Professional only.
>
> The CHANGELOG.txt file in the installation provides additional details.
>
> System requirements are Windows 2000 or later, OS X 10.3.9 or later for
> PPC or
> Intel (requires X11 Server), or a recent Linux system (either 32 or 64
> bit).
>
> Reporting Bugs
> --
>
> Please report bugs using the Submit Bug Report item in the Help menu or by
> emailing support at wingware dot com.  This is beta quality software that
> installs side-by-side with Wing 2.x or 1.x. We advise you to make frequent
> backups of your work when using any pre-release version of Wing IDE.
>
> Upgrading
> -
>
> To upgrade a 2.x license or purchase a new 3.x license:
>
> Upgradehttps://wingware.com/store/upgrade
> Purchase   https://wingware.com/store/purchase
>
> Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost
> 1/2 normal price to upgrade.
>
> Thanks!
>
> The Wingware Team
> Wingware | Python IDE
> Advancing Software Development
>
> www.wingware.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Time object?

2007-08-01 Thread Robert Dailey
Hi,

I'm well aware of the datetime module, however it is really inconsistent and
useless to me. In order to do any arithmetic on time objects, I have to use
the 'timedelta' class, which doesn't even allow me to do all the math I want
to do.

For example, I want to do "1 / timeobj", where timeobj might represent a
time in the format of "00:00:00.00". Do I have to code my own class for
this, or is there some other third party library out there that will allow
me to do this?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Checking object types

2007-08-01 Thread Robert Dailey
Hi,

I'm currently interested in creating an __add__() operator for one of my
classes. This class handles both integers and objects its own type, however
I don't know how I can perform special add operations depending on which is
passed in. Since I haven't seen any evidence of function overloading, I'm
assuming I'll have to check the types of the variables passed in inside of
my __add__() method.

Take the two following examples:

vector3(3,4,2) + 5 = vector3(8,9,7)
vector3(3,2,1) + vector3(4,5,6) = vector3(7,7,7)

Any tips? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Wing IDE for Python v. 3.0 beta1 released

2007-08-01 Thread Robert Dailey
He's secretly an employee of Wing IDE in disguise!!!

On 8/1/07, Joshua J. Kugler <[EMAIL PROTECTED]> wrote:
>
> On Wednesday 01 August 2007 13:28, John K Masters wrote:
>
> > On 15:34 Tue 31 Jul , Wingware wrote:
> >> Hi,
> >>
> >> I'm happy to announce the first beta release of Wing IDE 3.0.  It is
> >> available from http://wingware.com/wingide/beta
> > If their support for paid customers is anything like their support for
> > prospective customers then I would leave well alone.
>
> I've had excellent support from them.  I'm sorry to hear your experiences
> have not been stellar.  Questions submitted to the bug or comment list
> usually get a response in one day or less.  And there are frequently
> respones by WingWare people to just about every question asked on the
> WingWare mailing list.
>
> > I have been trying wing for a few days but have noticed that
> > auto-completion does not work on all modules. I submitted this to wing
> > and was told that probably my PYTHONPATH was wrong.
>
> It may also not work if the IDE isn't sure what kind of object you are
> dealing with.  You can "clarify" this as documented with an
> assert(isinstance()) statement.
>
> > I subsequently submitted a question about the licensing, i.e. whether I
> > could use wing on a home setup using Debian Etch, where I develop my
> > apps, and a work setup, using Debian Etch, with no net access.
>
> From http://www.wingware.com/wingide/license:
>
> "Each Wing IDE user may run Wing on as many machines as needed for their
> own
> work, for all the operating systems which they have licensed. In order to
> reduce casual license sharing, which is a unfortunately a problem for
> small
> businesses like Wingware, licenses must be activated after installation on
> each machine."
>
> "We've worked hard to make this flexible and forgiving for valid
> customers.
> For example, reinstalling an OS and/or altering hardware usually should
> not
> break your activation. Also, activation can be done directly from Wing IDE
> and off-line activation is available if your machine does not have TCP
> port
> 80 (http) access to wingware.com. Each license is allowed three
> activations
> by default and more can be obtained on request from identifiable
> customers."
>
> > So far I have had no response
>
> I tend to let questions slide when they are answered in the documentation
> or
> on the web site.  Maybe the Wing developers/support personnel are the same
> way.
>
> j
>
> --
> Joshua Kugler
> Lead System Admin -- Senior Programmer
> http://www.eeinternet.com
> PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: XML Processing

2007-08-02 Thread Robert Dailey
Both strings in your example are exactly the same, unless I'm missing
something.

On 8/2/07, Roman <[EMAIL PROTECTED]> wrote:
>
> Is there a package that converts a string that contains special
> characters in xml to to literal value.  For instance, converts string
> http://myhome/¶m to http://myhome/¶m.
>
> Thanks in advance
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I am giving up perl because of assholes on clpm -- switching to Python

2007-08-11 Thread Robert Dailey
I had this very same problem with the doxygen mailing list... doxygen is
such a great tool but full of assholes in their mailing list.

On 8/2/07, Jamie <[EMAIL PROTECTED]> wrote:
>
> In <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] mentions:
> >Python is a better language, with php support, anyway, but I am fed up
> >with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin
> >Perl experience for everyone. Instead of being helpful, snide remarks,
> >back-biting, scare tactings, and so on proliferate and self
> >reinforce. All honest people have left this sad newsgroup. Buy bye,
> >assholes, I am not going to miss you!!!
> >
> >Martha
>
> I've heard people tell the same story, that perl folks are... rude.
>
> Actually, I've pretty much heard (and noticed) that about linux, too.
>
> Yet, linux is still a good operating environment, so is perl.
>
> You'll find rude people everywhere you look. While it may be true that
> there is a higher percentage of hard-core tech folks who might lack
> social skills, at least they don't err.. well, maybe they do.. byte. :-)
>
> Seriously, it is one of the problems facing perl (and linux) people ARE
> turned away by the attitude. It is rather embarassing/unflattering when
> someone is critical of your work.
>
> I see a lot of ideas about things should be "made easier" but I think
> thats the wrong course. We really just need to be nicer to new folks.
>
> Jamie
> --
> http://www.geniegate.comCustom web programming
> Perl * Java * UNIXUser Management Solutions
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Binary, Hex, and Decimal string conversions

2007-08-11 Thread Robert Dailey
Hi, I was wondering if there is a built in module that supports conversion
in any direction between Binary, Hex, and Decimal strings? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I am giving up perl because of assholes on clpm -- switching to Python

2007-08-12 Thread Robert Dailey
That's a bit hard given the unpredictability of each person on that list.
What seems like a simple question one minute suddenly turns into a flamewar
because someone had a bad day at work and needed to vent at my expense. This
is beyond phrasing your questions properly. It has to do with just pure
stupidity.

On 8/11/07, Greg Donald <[EMAIL PROTECTED]> wrote:
>
> On 8/11/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> > I had this very same problem with the doxygen mailing list... doxygen is
> > such a great tool but full of assholes in their mailing list.
>
> I'm not defending any assholes you may have ran into, but I find the
> thing to do is only ask questions in such a way that no one can
> possibly have a reason to be an asshole.
>
> http://catb.org/~esr/faqs/smart-questions.html
>
>
> --
> Greg Donald
> http://destiney.com/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Binary, Hex, and Decimal string conversions

2007-08-12 Thread Robert Dailey
Well, I decided to implement my own way of doing this. I've attached the
source. You're all welcome :)

On 8/12/07, Michael Bentley <[EMAIL PROTECTED]> wrote:
>
> Hi Robert,
> On Aug 11, 2007, at 3:59 PM, Robert Dailey wrote:
>
> Hi, I was wondering if there is a built in module that supports conversion
> in any direction between Binary, Hex, and Decimal strings? Thanks.
>
>
> Shouldn't be too hard to build one.  Here's a little incantation to
> convert from base 10 to another base:
>
> import string
>
> def to_base(number, base):
> 'converts base 10 integer to another base'
>
> number = int(number)
> base = int(base)
> if base < 2 or base > 36:
> raise ValueError, "Base must be between 2 and 36"
> if not number:
> return 0
>  symbols = string.digits + string.lowercase[:26]
> answer = []
> while number:
> number, remainder = divmod(number, base)
> answer.append(symbols[remainder])
> return ''.join(reversed(answer))
>
> How 'bout you hack a from_base function and email it back to me? (hint:
> type 'help(int)' in the python interpreter).
>
> Peace,
> Michael
>
> ---
> Let the wookie win.
>
>
>
>

###

def hex2dec( hex ):
return str( int( hex, 16 ) )

###

def hex2bin( hex ):

nibbles =   {
"0":"", "1":"0001", "2":"0010", "3":"0011",
"4":"0100", "5":"0101", "6":"0110", "7":"0111",
"8":"1000", "9":"1001", "A":"1010", "B":"1011",
"C":"1100", "D":"1101", "E":"1110", "F":""
}

# Check for '0x' in front of the string & remove it
if hex[:2] == "0x":
hex = hex[2:]

try:
return str().join([nibbles[c] for c in hex.upper()]).lstrip("0")

except KeyError:
print "ERROR --> Non-hexadecimal character specified."

###

def dec2hex( dec ):
result = hex( int( dec ) )
return result[:2] + result[2:].upper()

###

def dec2bin( dec ):
return hex2bin( dec2hex( dec ) )

###

def bin2dec( bin ):
return str( int( bin, 2 ) )

###

def bin2hex( bin ):
return dec2hex( bin2dec( bin ) )

###-- 
http://mail.python.org/mailman/listinfo/python-list

Python script for mobile platforms -- suggested?

2007-08-12 Thread Robert Dailey
Hi,

I'm currently developing a game for a cell phone. The game has a GUI system
that's currently using XML to define the individual menus. Basically this
means that for every single menu the user goes to, it loads and parses an
XML file. Would using Python Script instead of XML be a reasonable
replacement, or would it be even slower? I've read various articles online
but I'm still curious to hear what everyone has to say here.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Binary, Hex, and Decimal string conversions

2007-08-13 Thread Robert Dailey
Just curious Dick, why are you making your own to_base method? Doesn't the
source I provided in my earlier email give you all that you need? I was
hoping my source might be useful to a few people, even though it's pretty
trivial code.

On 8/12/07, Dick Moores <[EMAIL PROTECTED]> wrote:
>
> At 07:04 PM 8/12/2007, Michael Bentley wrote:
>
> >On Aug 12, 2007, at 6:28 PM, Dick Moores wrote:
> >
> >>n = 12
> >>base = 36
> >>print to_base(n, base)
> >>==
> >>This seems to work fine for n >= base, but not for n < base. For
> >>example, the code shown returns "c". Is my indentation wrong, or
> >>the code? It seems to me that the code should work for the general
> >>case, not just for n >= base.
> >
> >Isn't 'c' the correct answer?
>
> Yes, of course. Stupid of me.
>
> Dick
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Problem with Thread.join()

2007-08-13 Thread Robert Dailey
Hi,

I have a class that derives from threading.Thread. To signal the thread to
exit its infinite loop, I set an Event. Once the thread checks Event.isSet()
and it is true, it proceeds to break out of the loop and exit the function.
In the main thread, right after calling Event.set(), I call Thread.join() to
wait on the thread to exit. However, if I call Thread.join() the application
locks up because for some reason calling Thread.join() prevents the thread
from exiting. I don't know why. Any help? Thanks...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python script for mobile platforms -- suggested?

2007-08-13 Thread Robert Dailey
*bump*

On 8/12/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm currently developing a game for a cell phone. The game has a GUI
> system that's currently using XML to define the individual menus. Basically
> this means that for every single menu the user goes to, it loads and parses
> an XML file. Would using Python Script instead of XML be a reasonable
> replacement, or would it be even slower? I've read various articles online
> but I'm still curious to hear what everyone has to say here.
>
> Thanks.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python script for mobile platforms -- suggested?

2007-08-14 Thread Robert Dailey
Hi Jay,

I apologize for not having been detailed enough. Right now I'm using a C++
library known as TinyXML to parse my XML files. When a menu is to be
displayed, the XML is parsed and the appropriate images, text, etc that will
display on the menu is loaded based on the data in that XML. Note that the
XML parsing happens before the menu is drawn and only happens once per menu
as to avoid performance overhead during the menu drawing.

For example, to create a menu that has an image in the center of the screen,
the XML would be this:










The "Origin" and "Justification" elements act sort of like function calls,
and the "Frame" element defines an "Object" kind of. Each Frame is a visual
element in the Menu.

I'm not sure if you'll agree or not, but even in this simple example it's
very hard to read just given the nature of the XML syntax. Secondly, I'm not
using XML as it was intended to be used. I'm using it as a script instead of
a representation of data. Most of the real menus are 600+ lines of XML much
like above, however it is not nearly as simplistic. I will paste a real
example of a menu below this email for those curious to look at it.

I haven't decided on what the Python version of the example above would look
like, that would probably happen sometime after I decided to go with Python
for a menu scripting replacement (If I do, that is). I might mix XML and
Python much like World of Warcraft mixes XML with LUA script. Again, this
all depends on design. The important points I wanted to get across is that
the Python script wont' be executed past the construction of a menu. The
Python/XML script would be simply there to allow the game to create the menu
and other important things.

I hope I've given enough examples and details. If I haven't, please let me
know and I'll answer any questions you may have. Thanks for following up.

On 8/13/07, Jay Loden <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > I'm currently developing a game for a cell phone. The game has a GUI
> > system that's currently using XML to define the individual menus.
> > Basically this means that for every single menu the user goes to, it
> > loads and parses an XML file. Would using Python Script instead of
> > XML be a reasonable replacement, or would it be even slower? I've
> > read various articles online but I'm still curious to hear what
> > everyone has to say here.
>
> A number of questions come to mind...for starters:
>
> 1) What is parsing the XML now? C code? Python?
> 2) What is the proposed python script supposed to do when they load the
> menu? without knowing that or seeing some sample code or details, that's an
> impossible question to answer, since an arbitrary Python script might take
> milliseconds, seconds, hours, or days to complete running.
>
> It might help if you give a concrete example (code is always welcome!) and
> explained exactly what the options are that you're considering and why. Then
> the folks on the list can try to give you a rough estimate or possibly
> suggest alternative methods you may not have considered.
>
> -Jay
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Pass by reference or by value?

2007-08-16 Thread Robert Dailey
Hi,

I previously created a topic named "Pass by reference or by value" where I
inquired on how python's function parameters work. I received a lot of nice
responses, however I'm still confused on the topic. Note that I come from a
C++ background to Python, so any comparisons to C++ would be very helpful.

I ran a few tests. There's two tests in particular I wanted to show you
guys:

myvar = []

def changeme( param ):
param.append( "blah" )
print param

changeme( myvar )

print myvar

The above code yields the following output:
['blah']
['blah']

This means that the list passed in was modified by the function.

Now test case 2:

myvar = 4

def changeme( param ):
param = 5
print param

changeme( myvar )

print myvar

The above code yields the following output:
5
4

This means that the integer passed in was NOT modified by the function.


Between these two tests, both types passed in are mutable objects. I'm
having trouble figuring out what mandates an object to be changed from
within a function versus not. What is happening in test case 2 to cause it
to not be modified?

Thanks for reading guys. Hopefully one day I'll understand this lol.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pass by reference or by value?

2007-08-16 Thread Robert Dailey
So immutable objects cannot be modified directly? I guess this means
integers are immutable and the act of assigning to one is a completely new
definition? So if I were to create a class called Integer and give it a
.set() method, this would allow me to create mutable integers, and thus
passing in an object of type class Integer would allow me to modify the
value from inside the function?

On 8/16/07, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > Hi,
> >
> > I previously created a topic named "Pass by reference or by value" where
> > I inquired on how python's function parameters work. I received a lot of
> > nice responses, however I'm still confused on the topic. Note that I
> > come from a C++ background to Python, so any comparisons to C++ would be
> > very helpful.
> >
> > I ran a few tests. There's two tests in particular I wanted to show you
> > guys:
> >
> 
> > myvar = []
> >
> > def changeme( param ):
> > param.append( "blah" )
> > print param
> >
> > changeme( myvar )
> >
> > print myvar
> >
> > The above code yields the following output:
> > ['blah']
> > ['blah']
> >
> > This means that the list passed in was modified by the function.
> >
> 
> > Now test case 2:
> >
> > myvar = 4
> >
> > def changeme( param ):
> > param = 5
> > print param
> >
> > changeme( myvar )
> >
> > print myvar
> >
> > The above code yields the following output:
> > 5
> > 4
> >
> > This means that the integer passed in was NOT modified by the function.
> >
> 
> >
> > Between these two tests, both types passed in are mutable objects. I'm
> > having trouble figuring out what mandates an object to be changed from
> > within a function versus not. What is happening in test case 2 to cause
> > it to not be modified?
> >
> > Thanks for reading guys. Hopefully one day I'll understand this lol.
> >
> The first thin to realise is that all Python names are just bindings to
> values. In C++ terms you can think of them all as pointers.
> De-referencing is automatic when a value is to be retrieved.
>
>
> >>> def changeme( param ):
> ... param = 3
> ... print param
> ...
> >>> myvar = []
> >>> changeme(myvar)
> 3
> >>> myvar
> []
> >>>
>
> In this case there is no attempt to mutate the argument, the argument
> name is simply bound to another value. Since the argument is a name
> local to the function, this does not result in any change outside the
> function.
>
> In this case the argument is bound to a mutable value, so the call to
> append mutates the object (a list) referenced by the argument.
>
> Unlike C++ and similar languages a variable does not hold a value, it
> holds a pointer to a value. When a list is passed as a function argument
> the reference to the list is copied into the argument. Does this help at
> all?
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd   http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pass by reference or by value?

2007-08-16 Thread Robert Dailey
Thanks Steve for your explanation. It was very helpful. I think I understand
it now. By the way, by the .set method I meant:

class Integer:
def __init__( self, number=0 ):
   self._int = number

def set( self, number ):
   self._int = number


# later on

mutableInt = Integer( 5 )
def change_me( var ):
var.set( 6 )


Of course, I'd probably use overloaded operators in a more realized example.


On 8/16/07, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > So immutable objects cannot be modified directly? I guess this means
> > integers are immutable and the act of assigning to one is a completely
> > new definition?
>
> Correct. A new value is bound to the name or item on the left-hand side
> - remember, all variables are pointers to values, there's no way to
> replace the value of a variable because of the automatic dereferencing.
> And yes, immutable objects can't be modified. At all, period. Hence the
> name.
>
> > So if I were to create a class called Integer and give
> > it a .set() method, this would allow me to create mutable integers, and
> > thus passing in an object of type class Integer would allow me to modify
> > the value from inside the function?
> >
> Well, the .set() method wouldn't be called automatically on an
> assignment statement but yes, if you passed an Integer object into your
> function and called its .set() method from inside then it should work.
>
> As long as you get your mutable integer implementation correct, of
> course ;-). I'd suggest delegating everything except the .set() method
> to the underlying integer value.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd   http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with directory recursion!

2007-08-17 Thread Robert Dailey
Here's part of the output that's incorrect:

models\W_BoomerEdge
BYOS_C.entity.xml
BYOS_C_Collision.entity.xml

Notice that the file BYOS_C.entity.xml is showing up as a file in the
directory W_BoomerEdge. This file does not exist in this folder, but yet in
a different folder. The output is consistent with the 'print' statements you
will see in the function I posted earlier.

On 8/17/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I've created a function that is used to recurse a directory tree in
> Windows XP using os.walk(). For the most part it works, however in some
> instances the data is incorrect and I'm getting invalid sub-directory paths.
> Here's the function:
>
>
> def __doSearch( root_dir, sub_path, restype, ext ):
> print sub_path
> # Searches the specified directory and generates a
> # list of files to preload.
> complete_path = osp.normpath( osp.join( root_dir, sub_path ) )
> for root, dirs, files in os.walk( complete_path ):
>
> # Record the list of file hash ID's
> for file in files:
> split = __resType( file )
> if split[1] == restype:
> #print sub_path
> print "\t", file
> __appendResource( ext, sub_path, split[0] )
>
> # Remove .svn subdirectories; we don't walk these.
> if ".svn" in dirs:
> dirs.remove( ".svn" )
>
> # Recurse child directories
> for dir in dirs:
> __doSearch( root_dir, osp.join( sub_path, dir ), restype, ext
> )
>
> Does anyone see anything immediately suspicious about the code? I'm
> assuming that in Python, every time a function is called recursively it gets
> its own copy of local variables. For some reason the sub_path variable isn't
> consistent depending on where I use it. For example, if you notice the print
> call at the very start of the function, it will output something like
> "models/ships". However, after passing it into __appendResource(), it
> appears to be just "models".
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Problem with directory recursion!

2007-08-17 Thread Robert Dailey
Hi,

I've created a function that is used to recurse a directory tree in Windows
XP using os.walk(). For the most part it works, however in some instances
the data is incorrect and I'm getting invalid sub-directory paths. Here's
the function:


def __doSearch( root_dir, sub_path, restype, ext ):
print sub_path
# Searches the specified directory and generates a
# list of files to preload.
complete_path = osp.normpath( osp.join( root_dir, sub_path ) )
for root, dirs, files in os.walk( complete_path ):

# Record the list of file hash ID's
for file in files:
split = __resType( file )
if split[1] == restype:
#print sub_path
print "\t", file
__appendResource( ext, sub_path, split[0] )

# Remove .svn subdirectories; we don't walk these.
if ".svn" in dirs:
dirs.remove( ".svn" )

# Recurse child directories
for dir in dirs:
__doSearch( root_dir, osp.join( sub_path, dir ), restype, ext )

Does anyone see anything immediately suspicious about the code? I'm assuming
that in Python, every time a function is called recursively it gets its own
copy of local variables. For some reason the sub_path variable isn't
consistent depending on where I use it. For example, if you notice the print
call at the very start of the function, it will output something like
"models/ships". However, after passing it into __appendResource(), it
appears to be just "models".
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with directory recursion!

2007-08-17 Thread Robert Dailey
I figured it out.

I was doing a recursive function call when I didn't have to. The walk()
method already walks into every possible sub-directory for you!

On 8/17/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Here's part of the output that's incorrect:
>
> models\W_BoomerEdge
> BYOS_C.entity.xml
> BYOS_C_Collision.entity.xml
>
> Notice that the file BYOS_C.entity.xml is showing up as a file in the
> directory W_BoomerEdge. This file does not exist in this folder, but yet in
> a different folder. The output is consistent with the 'print' statements you
> will see in the function I posted earlier.
>
> On 8/17/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I've created a function that is used to recurse a directory tree in
> > Windows XP using os.walk(). For the most part it works, however in some
> > instances the data is incorrect and I'm getting invalid sub-directory paths.
> > Here's the function:
> >
> >
> > def __doSearch( root_dir, sub_path, restype, ext ):
> > print sub_path
> > # Searches the specified directory and generates a
> > # list of files to preload.
> > complete_path = osp.normpath( osp.join( root_dir, sub_path ) )
> > for root, dirs, files in os.walk( complete_path ):
> >
> > # Record the list of file hash ID's
> > for file in files:
> > split = __resType( file )
> > if split[1] == restype:
> > #print sub_path
> > print "\t", file
> > __appendResource( ext, sub_path, split[0] )
> >
> > # Remove .svn subdirectories; we don't walk these.
> > if ".svn" in dirs:
> > dirs.remove( ".svn" )
> >
> > # Recurse child directories
> > for dir in dirs:
> > __doSearch( root_dir, osp.join( sub_path, dir ), restype,
> > ext )
> >
> > Does anyone see anything immediately suspicious about the code? I'm
> > assuming that in Python, every time a function is called recursively it gets
> > its own copy of local variables. For some reason the sub_path variable isn't
> > consistent depending on where I use it. For example, if you notice the print
> > call at the very start of the function, it will output something like
> > "models/ships". However, after passing it into __appendResource(), it
> > appears to be just "models".
> >
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Question about 'for' loop

2007-08-17 Thread Robert Dailey
Hi,

I noticed that the 'for' loop can be used inline with a list definition. For
example:

print [i for i in mylist]

My first question is what is the name for this? I couldn't find this usage
in the python docs; I only managed to learn about it through code samples on
the internet.

Secondly, I'm wondering how I can use this method of a for loop to append
strings to strings in a list. For example:

mylist = [
"Hello ",
"Hello again "
]

I should be able to do this:

print [ i + "World" for i in mylist ]

Which should yield the output:

["Hello World", "Hello again world"]

However, instead I get an error message saying "TypeError: cannot
concatenate 'str' and 'list' objects"

How can I achieve the above? Thanks for reading.
-- 
http://mail.python.org/mailman/listinfo/python-list

str().join() isn't working

2007-08-20 Thread Robert Dailey
Hi,

First have a look at the following code:


In main.py:
---
space = " "

includes = space.join( system._user_includes ) + " " + space.join(
system._system_includes )


In system.py:
---
_user_includes = [
]

_system_includes = [
]


The above does not work. The interpreter states: "TypeError: sequence item
0: expected string, list found". I'm not sure what this means. Can anyone
help me figure out what I'm doing wrong? Thanks.

PS: I've also tried putting strings in the lists above just to make sure
that them being empty wasn't the problem. I got no different results.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Thread.join()

2007-08-20 Thread Robert Dailey
Hey guys,

Sorry for taking so long to respond. I had actually figured out what
this issue is over on the wxPython mailing list. The issue was that I
was attempting to configure wxPython controls from a remote thread,
which is apparently illegal due to some state persistance issues.

Thanks all for responding and I do apologize for not having given
proper code snippets on my first post. Take care all.

On 8/20/07, James Matthews <[EMAIL PROTECTED]> wrote:
> Post some code so we can see the issue! I would say that the issue is where
> your function that you are calling isn't exiting!
>
>
> On 8/20/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> > En Mon, 13 Aug 2007 20:10:53 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi�:
> >
> > > I have a class that derives from threading.Thread. To signal the thread
> > > to
> > > exit its infinite loop, I set an Event. Once the thread checks
> > > Event.isSet()
> > > and it is true, it proceeds to break out of the loop and exit the
> > > function.
> > > In the main thread, right after calling Event.set(), I call
> > > Thread.join() to
> > > wait on the thread to exit. However, if I call Thread.join() the
> > > application
> > > locks up because for some reason calling Thread.join() prevents the
> > > thread
> > > from exiting. I don't know why. Any help? Thanks...
> >
> > Conceptually you're doing it the right way. Post some code demonstrating
> > the problem...
> >
> > --
> > Gabriel Genellina
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> http://www.goldwatches.com/
> http://www.jewelerslounge.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: str().join() isn't working

2007-08-20 Thread Robert Dailey
here is a more realized example of the lists I'm trying to join:


_user_includes = [
"../src",
"../resource",
"../inc",
"../src",
"../data",
"../gui",
"../script",
"../script/actions",
"../gui/dispatch",
"../gui/factories",
"../gui/frames",
"../gui/getters",
"../gui/localization",
"../gui/player",
"../gui/setters",
"../gui/utilities",
"../sis",
"../player",
"../platform/ngi",
"../../engine",
"../../engine/audio/NGI",
"../../engine/io",
"../../engine/io\NGI",
"../../engine/math",
"../../engine/math/fixed",
"../../engine/path/NGI",
"../../engine/text/NGI",
"../../engine/mem",
"../../engine/text",
"../../engine/observer",
"../../sdk/tiny_xml",
"../../sdk/zlib",
"../../sdk/lpng",
"../../sdk/IFDLib/Source/Precompile",
"../../sdk/IFDLib/Source/CoreLib",
"../../sdk/IFDLib/inc",
"../../sdk/IFDLib/Source/UtilLib",
"../../sdk/IFDLib/Source/GameLib",
"../../sdk/IFDlib/Source/OSLib/_NGI",
"../../sdk/stl-port/NGI",
"../../sdk/mini-boost/NGI",
"../../sdk/mini-boost/COMMON",
]

_system_includes = [
"../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include",

"../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/rga",

"../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/stdapis",

"../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/stdapis/stlport",
"../../../../../../Symbian/9.1/NGAGE_SDK_1.1/epoc32/include/variant"
]





On 8/20/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> Hi,
>
> First have a look at the following code:
>
>
> In main.py:
> ---
> space = " "
>
> includes = space.join ( system._user_includes ) + " " + space.join(
> system._system_includes )
>
>
> In system.py:
> ---
> _user_includes = [
> ]
>
> _system_includes = [
> ]
>
>
> The above does not work. The interpreter states: "TypeError: sequence item
> 0: expected string, list found". I'm not sure what this means. Can anyone
> help me figure out what I'm doing wrong? Thanks.
>
> PS: I've also tried putting strings in the lists above just to make sure
> that them being empty wasn't the problem. I got no different results.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: str().join() isn't working

2007-08-20 Thread Robert Dailey
Hi all,

Thanks for your response. I figured out the issue. I was using
list.append() to append another list, when I should have been using
expand(). Sorry for the confusion.

On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Aug 20, 1:16 pm, "Robert Dailey" <[EMAIL PROTECTED]> wrote:
> > here is a more realized example of the lists I'm trying to join:
> >
> > _user_includes = [
> > "../src",
> > "../resource",
> > "../inc",
> > "../src",
> > "../data",
> > "../gui",
> > "../script",
> > "../script/actions",
> > "../gui/dispatch",
> > "../gui/factories",
> > "../gui/frames",
> > "../gui/getters",
> > "../gui/localization",
> > "../gui/player",
> > "../gui/setters",
> > "../gui/utilities",
> > "../sis",
> > "../player",
> > "../platform/ngi",
> > "../../engine",
> > "../../engine/audio/NGI",
> > "../../engine/io",
> > "../../engine/io\NGI",
> > "../../engine/math",
> > "../../engine/math/fixed",
> > "../../engine/path/NGI",
> > "../../engine/text/NGI",
> > "../../engine/mem",
> > "../../engine/text",
> > "../../engine/observer",
> > "../../sdk/tiny_xml",
> > "../../sdk/zlib",
> > "../../sdk/lpng",
> > "../../sdk/IFDLib/Source/Precompile",
> > "../../sdk/IFDLib/Source/CoreLib",
> > "../../sdk/IFDLib/inc",
> > "../../sdk/IFDLib/Source/UtilLib",
> > "../../sdk/IFDLib/Source/GameLib",
> > "../../sdk/IFDlib/Source/OSLib/_NGI",
> > "../../sdk/stl-port/NGI",
> > "../../sdk/mini-boost/NGI",
> > "../../sdk/mini-boost/COMMON",
> > ]
> >
> > _system_includes = [
> > "../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include",
> > 
> > "../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/rga",
> > 
> > "../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/stdapis",
> > 
> > "../../../../../../Symbian/9.1/NGAGE_SDK_1.1/EPOC32/include/osextensions/stdapis/stlport",
> > "../../../../../../Symbian/9.1/NGAGE_SDK_1.1/epoc32/include/variant"
> > ]
> >
> > On 8/20/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > First have a look at the following code:
> >
> > > In main.py:
> > > ---
> > > space = " "
> >
> > > includes = space.join ( system._user_includes ) + " " + space.join(
> > > system._system_includes )
> >
> > > In system.py:
> > > ---
> > > _user_includes = [
> > > ]
> >
> > > _system_includes = [
> > > ]
> >
> > > The above does not work. The interpreter states: "TypeError: sequence item
> > > 0: expected string, list found". I'm not sure what this means. Can anyone
> > > help me figure out what I'm doing wrong? Thanks.
> >
> > > PS: I've also tried putting strings in the lists above just to make sure
> > > that them being empty wasn't the problem. I got no different results.
>
> When you use join, you join the items in the list with each other to
> form one long string. In your statement, your script tries to
> concatenate 2 lists to each other before it does the join, which is
> impossible in Python. The "+" operator is only for addition and for
> two or more strings.
>
> See http://www.faqs.org/docs/diveintopython/odbchelper_join.html for
> more information on joins.
>
> Mike
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


optparse - required options

2007-08-20 Thread Robert Dailey
Hi,

I've been reading through the python documentation on the optparse module
and I was unable to find out how to specify if an option is optional or
required. The documentation vaguely states that actions can be used to do
this, however I was not able to figure out how. If anyone could help I'd
greatly appreciate it.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: optparse - required options

2007-08-20 Thread Robert Dailey
Well, I don't know what is wrong with people then. I don't see how required
arguments are of bad design. Some command-line applications are built around
performing tasks based on information received. Compilers, for example. A
compiler can't do much of anything unless you give it at the very least a
filename. So, a --file command would most definitely be one required
argument. Anyway, I'm not trying to start a debate on this issue. I have my
own implementation for required arguments at the moment, I am just a little
bit surprised that this module doesn't make it convenient. It would
definitely help on code duplication.

Thanks for your response.

On 8/20/07, Jay Loden <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > Hi,
> >
> > I've been reading through the python documentation on the optparse
> > module and I was unable to find out how to specify if an option is
> > optional or required. The documentation vaguely states that actions can
> > be used to do this, however I was not able to figure out how. If anyone
> > could help I'd greatly appreciate it.
> >
>
> According to the optparse docs:
>
> required option
> an option that must be supplied on the command-line; note that the
> phrase ``required option'' is self-contradictory in English. optparse
> doesn't prevent you from implementing required options, but doesn't
> give you much help at it either. See examples/required_1.py and
> examples/required_2.py in the optparse source distribution for two
> ways to implement required options with optparse.
>
>
> And from what I can see, this seems to be somewhat intentional, see
> http://wiki.python.org/moin/OptParse the note at the bottom with a link to
> a mailing list thread. As far as I can tell, evidently some people feel that
> required options are indicative of a bad design and therefore optparse was
> designed not to make this easy on the programmer.
>
> -Jay
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: datetime in microseconds

2007-08-20 Thread Robert Dailey
A small off topic question. Why use divmod() instead of the modulus
operator?

On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> On Aug 20, 4:17 pm, [EMAIL PROTECTED] wrote:
> > On Aug 20, 3:15 pm, John Machin <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > On Aug 20, 9:52 pm, [EMAIL PROTECTED] wrote:
> >
> > > > Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I
> > > > want this to a normal view in hh:mm:ss DD:MM:. I tried with
> > > > datetime, but it only takes a max of 100 microseconds is there
> > > > another solution?
> >
> > > Your question can be interpreted in two possible ways:
> >
> > > 1. You have an interval or duration (independent of a calendar point)
> > > and you want to express it in years, months, days, hours, etc. This is
> > > not possible, due to the variable number of days in a month. The best
> > > that you can do is express it as days, hours, etc.
> >
> > > >>> microsecs = 0x8C905CBA7F84AF4
> > > >>> secs = microsecs // 100 # or round to nearest if you prefer
> > > >>> mins, secs = divmod(secs, 60)
> > > >>> hrs, mins = divmod(mins, 60)
> > > >>> days, hrs = divmod(hrs, 24)
> > > >>> days, hrs, mins, secs
> >
> > > (7326893L, 11L, 1L, 16L)
> >
> > > 2. You want to know the (Gregorian) calendar point that is
> > > 0x8C905CBA7F84AF4 microseconds after some epoch. In this case you need
> > > to specify what the epoch is. Then you can try something like:
> >
> > > >>> datetime.datetime.fromordinal(1) + datetime.timedelta
> (microseconds=microsecs
> >
> > > )
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > > OverflowError: date value out of range
> >
> > > >>> # Whoops!
> > > >>> years_approx = days / 365.25
> > > >>> years_approx
> > > 20059.939767282682
> >
> > > Hmmm, one of us seems to be missing something ...
> >
> > Sorry,  sorry, sorry it was the wrong value, it should be
> > 0xE0E6FAC3FF3AB2.
>
> The solution I made, with thanks to John. Maybe someone a better one??
> def DecodeDateTime(self,dateTime):
> dateTime = self.Rotate(dateTime)
> microsecs = int(hexlify(dateTime),16)
> microsecs -= 315360   # -1 Year
> microsecs -= 11232# -13 Days (magic?)
> secs = microsecs // 100
> mins, secs = divmod(secs, 60)
> hrs, mins = divmod(mins, 60)
> days, hrs = divmod(hrs, 24)
> timed = datetime.datetime.fromordinal(1) +
> datetime.timedelta(days)
> return "%02d-%02d-%02d %02d:%02d:%02d"%(timed.day,
> timed.month, timed.year, hrs, mins, secs)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: str().join() isn't working

2007-08-20 Thread Robert Dailey
Yeah! That's it lol. Sorry, I wasn't looking at the documentation. At least
you got the point!

Thanks again guys.

On 8/20/07, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
>
> "Robert Dailey" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> | Hi all,
> |
> | Thanks for your response. I figured out the issue. I was using
> | list.append() to append another list, when I should have been using
> | expand(). Sorry for the confusion.
>
> The method is .extend, not .expand ;=)
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Python is removing my quotes!

2007-08-21 Thread Robert Dailey
Hi,

Note: I'm using Python on Windows

I have an application that allows a user to submit a password as a command
line parameter. The password of choice may contain any characters the user
wishes, including quotes. If I do the following:

python password.py ""MyPassword

The resulting output when I print this inside the script is:

MyPassword

Notice how the quotations have been stripped. Is it DOS doing this, or
Python? Is there a way I can fix it?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python is removing my quotes!

2007-08-21 Thread Robert Dailey
Thank you for your response. The back slashes work! It's a bit annoying; but
I have Microsoft to thank for that.

On 8/21/07, Gary Herron <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > Hi,
> >
> > Note: I'm using Python on Windows
> >
> > I have an application that allows a user to submit a password as a
> > command line parameter. The password of choice may contain any
> > characters the user wishes, including quotes. If I do the following:
> >
> > python password.py ""MyPassword
> >
> > The resulting output when I print this inside the script is:
> >
> > MyPassword
> >
> > Notice how the quotations have been stripped. Is it DOS doing this, or
> > Python? Is there a way I can fix it?
> >
> > Thanks.
>
> Not Python.  It never even sees those quotes.  Whatever system you are
> using for entering the text is stripping them.  Is it the command prompt
> (cmd.exe)?  If so then you can escape the quote by preceding it with a
> backslash.  (This is true of the DOS prompt and all the unix shells, and
> their windows ports, that I know about.)
>
> Gary Herron
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Tokenizer for python?

2007-08-21 Thread Robert Dailey
Hi,

I am looking for a sort of "tokenizer" for python. I've taken a look at the
tokenize module, but that seems to parse python code from what I read. I
want a tokenizer that works a little like boost::tokenizer, however for
python. Basically I want to be able to pass in an arbitrary string (or line
from readline()) and specify tokens that cause the string to be separated
into parts, much like the regular expression split() method (I think that's
the name of it). Is there anything that already exists that does this, or do
I need to implement it myself with regular expressions?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Latest models of Gibson guitars

2007-08-21 Thread Robert Dailey
lol...

On 8/21/07, Tony <[EMAIL PROTECTED]> wrote:
>
> I don't who is posting here stupid shit about guitars
> who ever is do self fever hang your self with one of strings
>
>
> "kaldrenon" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Aug 20, 8:54 pm, Twisted <[EMAIL PROTECTED]> wrote:
> >> If the message then
> >> says something absurd, like "this is a newsgroup about Python" when
> >> I'm reading it in cljp, well, what do you expect? :P
> >
> > I think most would expect you to go, "WTF?" but then, like a rational
> > person, click the helpful little "More options" link that GG provides
> > (I'm assuming you use GG to read as well as to post, forgive me if I'm
> > wrong) and double-check before harassing someone because you jumped to
> > conclusions.
> >
> >> though nothing in the headers would indicate this.
> >
> > Newsgroups: comp.lang.java.programmer,
> > microsoft.public.dotnet.framework.aspnet, comp.lang.python,
> > rec.photo.digital, alt.home.repair
> > From: [EMAIL PROTECTED]
> > Date: Sun, 19 Aug 2007 17:34:58 -
> > Local: Sun, Aug 19 2007 1:34 pm
> > Subject: Latest models of Gibson guitars
> >
> > That's the header GG shows. Prtty clear.
> >
> > Just a tip for future reference - all's fair if you weren't aware of
> > this feature of GG's interface.
> >
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Class destruction

2007-08-22 Thread Robert Dailey
Hi,

I'm wondering where the most appropriate location is to cleanup class
objects. For example, i have a file handle as an instance attribute in one
of my classes and I need to call f.close() on it when the class object falls
out of scope. Any ideas? I've tried __del__() but I don't remember this
working for some reason. I might try it again later just to be positive.

Below is the source code to the class I'm attempting to add a destructor to:


import struct

#

class fout:
def __init__( self, filename ):
self._file = open( filename, "wb" )

def write32( self, data ):
# write out a 32-bit integer value
self._file.write( struct.pack( "I", data ) )

def write16( self, data ):
# write out a 16-bit integer value
self._file.write( struct.pack( "H", data ) )

def write8( self, data ):
# write out an 8-bit integer value
self._file.write( struct.pack( "B", data ) )

def write( self, data ):
# write out a string literal
self.write32( len( data ) )
self._file.write( data )
self._file.flush()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Class destruction

2007-08-22 Thread Robert Dailey
Thanks; I'll give it a try.

On 8/22/07, Nils Oliver Kröger <[EMAIL PROTECTED]> wrote:
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Robert Dailey schrieb:
> > Hi,
> >
> > I'm wondering where the most appropriate location is to cleanup class
> > objects. For example, i have a file handle as an instance attribute in
> one
> > of my classes and I need to call f.close() on it when the class object
> falls
> > out of scope. Any ideas? I've tried __del__() but I don't remember this
> > working for some reason. I might try it again later just to be positive.
>
> __del__(self) is the perfectly right place for such cleanup ... it gets
> called once your instance is either deleted explicitly by you or it's
> handled by the garbage collector when there are no more references.
>
> The possible problem why this did not work four you is, that the
> destruction by the garbage collector cannot be predicted ... it may well
> take some time. If you try to open the same file from another class
> before yours gets cleaned you run into trouble.
>
> If you want to "reuse" the file, you will have to delete your classes
> instance explicitly using the del statement ... this will also call the
> destructor.
>
> The below code works fine:
>
> def __del__( self ):
> self._file.close()
> print "File closed"
>
> Hope that helps ... Nils
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGzISBzvGJy8WEGTcRAiOwAJ94fJza4/GVQsFmbXwsP8kdvQjV5wCfQktw
> F/zPJAw0ayjYe5MGxPR1YqI=
> =4Hl6
> -END PGP SIGNATURE-
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: optparse - required options

2007-08-24 Thread Robert Dailey
Thank you VERY much for mentioning argparse- this is EXACTLY what I needed!
Thank you!

On 8/23/07, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
> Omari Norman wrote:
> > On Mon, Aug 20, 2007 at 05:31:00PM -0400, Jay Loden wrote:
> >> Robert Dailey wrote:
> >>> Well, I don't know what is wrong with people then. I don't see how
> >>> required arguments are of bad design.
> >
> >> I tend to agree...while "required option" may be an oxymoron in
> >> English, I can think of quite a few scripts I've written myself (in
> >> various languages) that needed at least some kind of user input to
> >> operate.
> >
> > The idea with optparse is not that programs should not require certain
> > information on the command line; rather, the idea is that this
> > information should be positional arguments, not 'options'.
> >
> > That is, to use the compiler example:
> >
> > compiler file
> >
> > is preferred if a file argument is necessary.
> >
> > compiler --file file
> >
> > is not preferred.
>
> I agree with the optparse philosophy, but Practicality Beats Purity.
> That's why I was convinced to add "required options" to argparse --
> there are too many applications that want that kind of interface.
> *I* don't write applications with interfaces like that, but enough
> people do that the use case should really be supported.
>
> STeVe
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Rendering API for python?

2007-09-04 Thread Robert Dailey
Hi,

I'm developing a quick python script to test an algorithm of mine. I would
like to be able to plot the algorithm results to a diagram (much like you
can do in Matlab). I was wondering if there's an API around that would allow
me to quickly do this? Perhaps some sort of rendering API or plotting API
for python? Any help is greatly appreciated. Thanks.

PS: I'm using Python on Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rendering API for python?

2007-09-04 Thread Robert Dailey
Well, I guess I wrote too soon. I found this:
http://matplotlib.sourceforge.net/

I'm going to try it out and see if it is what I'm looking for, however I'm
pretty confident!

On 9/4/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm developing a quick python script to test an algorithm of mine. I would
> like to be able to plot the algorithm results to a diagram (much like you
> can do in Matlab). I was wondering if there's an API around that would allow
> me to quickly do this? Perhaps some sort of rendering API or plotting API
> for python? Any help is greatly appreciated. Thanks.
>
> PS: I'm using Python on Windows.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Python script to optimize XML text

2007-09-24 Thread Robert Dailey
Hi,

I'm currently seeking a python script that provides a way of optimizing out
useless characters in an XML document to provide the optimal size for the
file. For example, assume the following XML script:








By running this through an XML optimizer, the file would appear as:



Note that the following were changed:
- All comments were stripped from the XML
- All spaces, tabs, carriage returns, and other forms of unimportant
whitespace are removed
- Elements that contain no text or children that are in the form of
 use the short-hand method for ending an element body:


Anyone know of a tool or python script that can perform optimizations like
explained above? I realize I could probably do this with regular expressions
in python, however I was hoping someone already did this work.
-- 
http://mail.python.org/mailman/listinfo/python-list

Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
Hi,

I'm attempting to create a regular expression that removes redundancy in
empty XML elements. For example:



The regular expression would convert the XML above into:



And another complex example:



would be:




So far I've been unsuccessful in creating a regular expression to do this.
Below are outlined various guarantees:

- The XML to be parsed shall have NO comments in it
- The XML to be parsed shall have NO whitespace (spaces, tabs, carriage
returns, etc) between elements. The examples above represent what this
means.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
Thanks.

Any easier way to do a 'replace' then using start(), end(), and slicing
operations? I'm currently doing it manually.

On 9/24/07, Miles <[EMAIL PROTECTED]> wrote:
>
> On 9/24/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I'm attempting to create a regular expression that removes redundancy in
> > empty XML elements. For example:
> >
> > 
> >
> > The regular expression would convert the XML above into:
> >
> >  
>
> If you can guarantee that the XML is well-formed, then this should work:
>
> pattern = r'<([^/>][^>]*(?]+>'
> replace = r'<\1/>'
>
> -Miles
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> Yes: forget about regular expressions. ElementTree does that for free:
>

That's not an option.
-- 
http://mail.python.org/mailman/listinfo/python-list

re: Confused about 'positive lookbehind assertion'

2007-09-24 Thread Robert Dailey
Hi,

I've been reading the python documentation on 'positive lookbehind
assertion' and I don't understand at all how it works. The python docs give
the following example:

"**(?<=abc)def will find a match in "abcdef", since the lookbehind will back
up 3 characters and check if the contained pattern matches."

Can anyone emphasize more on what this RE operation does? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
What I meant was that it's not an option because I'm trying to learn regular
expressions. RE is just as built in as anything else.

On 9/24/07, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> >
> >
> > On 9/24/07, *Gabriel Genellina* <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
> >
> > Yes: forget about regular expressions. ElementTree does that for
> free:
> >
> >
> > That's not an option.
> >
> Even though it's built into Python 2.5? That's a strange requirement.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python script to optimize XML text

2007-09-25 Thread Robert Dailey
Hey guys,

Thanks for everyone's input. I wanted to learn regular expressions, however
I'm finding them to be quite evil. I think I've learned that it's always a
good idea to make regex a very LAST resort. This is my opinion I'm
developing on. In any case, I like the ideas mentioned here concerning using
the XML parser to do the job for me. Thanks again everyone, I think I'll be
going with the XML parser to do what I need.

Have a good day everyone.

On 9/25/07, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> Gabriel Genellina wrote:
> > En Mon, 24 Sep 2007 17:36:05 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi�:
> >
> >> I'm currently seeking a python script that provides a way of
> >> optimizing out
> >> useless characters in an XML document to provide the optimal size for
> the
> >> file. For example, assume the following XML script:
> >>
> >> 
> >> 
> >> 
> >>
> >> 
> >> 
> >>
> >> By running this through an XML optimizer, the file would appear as:
> >>
> >> 
> >
> > ElementTree does that almost for free.
>
> As the OP is currently using lxml.etree (and as this was a cross-post to
> c.l.py and lxml-dev), I already answered on the lxml list.
>
> This is just to mention that the XMLParser of lxml.etree accepts keyword
> options to ignore plain whitespace content, comments and processing
> instructions, and that you can provide a DTD to tell it what
> whitespace-only
> content really is "useless" in the sense of your specific application.
>
> Stefan
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Confused about 'positive lookbehind assertion'

2007-09-25 Thread Robert Dailey
I think I get it... it's really just a way (so it seems) to make characters
get added to the found groups as they're matched. Thanks for your help.

On 9/25/07, Andrew Durdin <[EMAIL PROTECTED]> wrote:
>
> On 9/25/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I've been reading the python documentation on 'positive lookbehind
> > assertion' and I don't understand at all how it works. The python docs
> give
> > the following example:
> >
> > " (?<=abc)def will find a match in "abcdef", since the lookbehind will
> back
> > up 3 characters and check if the contained pattern matches."
> >
> > Can anyone emphasize more on what this RE operation does? Thanks.
>
> It ensures that the regex will only match following the string in the
> lookbehind group, but without capturing that string.
>
> As the docs say, "(?<=abc)def" will match "abcdef"; but it will not
> match "def" (as the "abc" is not there).  If it does match,  the 0th
> group in the match object will be "def".
>
> In contrast, the regex "abcdef" will also match "abcdef" and not
> "def", but the 0th group will be "abcdef".
>
> The negative lookbehind is the opposite -- e.g. "(? match "def" but not "abcdef".
>
> Cheers,
>
> Andrew
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Awesome description. This was more than helpful. I'm really grateful that
you took the time to outline that for me. I really understand it now.
However, as I mentioned in the lxml mailing list, I'm starting to learn more
towards regular expressions being a very LAST resort to solving problems
like this. In my specific case, I have a better choice which is the etree
parser. It does all of this for me (as you so kindly stated before). I hope
this is the correct attitude to have. Being a C++ developer, I normally
don't admire unmanageable and unreadable code (this is especially true with
regular expressions). They're very useful, but again I believe it should be
a last resort.

Thanks again for your help.

On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> escribi�:
>
> > What I meant was that it's not an option because I'm trying to learn
> > regular
> > expressions. RE is just as built in as anything else.
>
> Ok, let's analyze what you want. You have for instance this text:
> ""
> which should become
> ""
>
> You have to match:
> (opening angle bracket)(any word)(closing angle bracket)(opening angle
> bracket)(slash)(same word as before)(closing angle bracket)
>
> This translates rather directly into this regular expression:
>
> r"<(\w+)>"
>
> where \w+ means "one or more alphanumeric characters or _", and being
> surrounded in () creates a group (group number one), which is
> back-referenced as \1 to express "same word as before"
> The matched text should be replaced by (opening <)(the word
> found)(slash)(closing >), that is: r"<\1/>"
> Using the sub function in module re:
>
> py> import re
> py> source = """
> ... 
> ... 
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)>", r"<\1/>", source)
>
> 
> 
> 
> 
>
> Now, a more complex example, involving tags with attributes:
>   -->  
>
> You have to match:
> (opening angle bracket)(any word)(any sequence of words,spaces,other
> symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> angle bracket)(slash)(same word as before)(closing angle bracket)
>
> r"<(\w+)([^>]*)>"
>
> [^>] means "anything but a >", the * means "may occur many times, maybe
> zero", and it's enclosed in () to create group 2.
>
> py> source = """
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
>
> 
> 
>
> Next step would be to allow whitespace wherever it is legal to appear -
> left as an exercise to the reader. Hint: use \s*
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Fortunately I don't have any XML that complex, however you make a good
point.

On 9/25/07, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
> On Sep 24, 11:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
> > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi?:
> >
> > > What I meant was that it's not an option because I'm trying to learn
> > > regular
> > > expressions. RE is just as built in as anything else.
> >
> > Ok, let's analyze what you want. You have for instance this text:
> > ""
> > which should become
> > ""
> >
> > You have to match:
> > (opening angle bracket)(any word)(closing angle bracket)(opening angle
> > bracket)(slash)(same word as before)(closing angle bracket)
> >
> > This translates rather directly into this regular expression:
> >
> > r"<(\w+)>"
> >
> > where \w+ means "one or more alphanumeric characters or _", and being
> > surrounded in () creates a group (group number one), which is
> > back-referenced as \1 to express "same word as before"
> > The matched text should be replaced by (opening <)(the word
> > found)(slash)(closing >), that is: r"<\1/>"
> > Using the sub function in module re:
> >
> > py> import re
> > py> source = """
> > ... 
> > ... 
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)>", r"<\1/>", source)
> >
> > 
> > 
> > 
> > 
> >
> > Now, a more complex example, involving tags with attributes:
> >   -->  
> >
> > You have to match:
> > (opening angle bracket)(any word)(any sequence of words,spaces,other
> > symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> > angle bracket)(slash)(same word as before)(closing angle bracket)
> >
> > r"<(\w+)([^>]*)>"
> >
> > [^>] means "anything but a >", the * means "may occur many times, maybe
> > zero", and it's enclosed in () to create group 2.
> >
> > py> source = """
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
> >
> > 
> > 
> >
> > Next step would be to allow whitespace wherever it is legal to appear -
> > left as an exercise to the reader. Hint: use \s*
> >
> > --
> > Gabriel Genellina
>
> And let's hope the OP doesn't have to parse anything truly nasty like:
>
>  esolang:language>
>
> -- Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Invoking python through C++: How to?

2007-09-25 Thread Robert Dailey
Hi,

I have a python script that I would like to invoke through my C++
application. Does anyone know of a trivial way of doing this? Right now the
only idea I can come up with is using system("python myscript.py") in C++.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
One thing I noticed is that it is placing an arbitrary space between " and
/>. For example:




Notice that there's a space between "image" and />

Any way to fix this? Thanks.

On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> escribi�:
>
> > What I meant was that it's not an option because I'm trying to learn
> > regular
> > expressions. RE is just as built in as anything else.
>
> Ok, let's analyze what you want. You have for instance this text:
> ""
> which should become
> ""
>
> You have to match:
> (opening angle bracket)(any word)(closing angle bracket)(opening angle
> bracket)(slash)(same word as before)(closing angle bracket)
>
> This translates rather directly into this regular expression:
>
> r"<(\w+)>"
>
> where \w+ means "one or more alphanumeric characters or _", and being
> surrounded in () creates a group (group number one), which is
> back-referenced as \1 to express "same word as before"
> The matched text should be replaced by (opening <)(the word
> found)(slash)(closing >), that is: r"<\1/>"
> Using the sub function in module re:
>
> py> import re
> py> source = """
> ... 
> ... 
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)>", r"<\1/>", source)
>
> 
> 
> 
> 
>
> Now, a more complex example, involving tags with attributes:
>   -->  
>
> You have to match:
> (opening angle bracket)(any word)(any sequence of words,spaces,other
> symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> angle bracket)(slash)(same word as before)(closing angle bracket)
>
> r"<(\w+)([^>]*)>"
>
> [^>] means "anything but a >", the * means "may occur many times, maybe
> zero", and it's enclosed in () to create group 2.
>
> py> source = """
> ... 
> ... 
> ... """
> py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
>
> 
> 
>
> Next step would be to allow whitespace wherever it is legal to appear -
> left as an exercise to the reader. Hint: use \s*
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Hmm, ElementTree.tostring() also adds a space between the last character of
the element name and the />. Not sure why it is doing this.

Something like  will become  after the tostring().

On 9/25/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> One thing I noticed is that it is placing an arbitrary space between " and
> />. For example:
>
>
> 
>
> Notice that there's a space between "image" and />
>
> Any way to fix this? Thanks.
>
> On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> >
> > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi�:
> >
> > > What I meant was that it's not an option because I'm trying to learn
> > > regular
> > > expressions. RE is just as built in as anything else.
> >
> > Ok, let's analyze what you want. You have for instance this text:
> > ""
> > which should become
> > ""
> >
> > You have to match:
> > (opening angle bracket)(any word)(closing angle bracket)(opening angle
> > bracket)(slash)(same word as before)(closing angle bracket)
> >
> > This translates rather directly into this regular expression:
> >
> > r"<(\w+)>"
> >
> > where \w+ means "one or more alphanumeric characters or _", and being
> > surrounded in () creates a group (group number one), which is
> > back-referenced as \1 to express "same word as before"
> > The matched text should be replaced by (opening <)(the word
> > found)(slash)(closing >), that is: r"<\1/>"
> > Using the sub function in module re:
> >
> > py> import re
> > py> source = """
> > ... 
> > ... 
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)>", r"<\1/>", source)
> >
> > 
> > 
> > 
> > 
> >
> > Now, a more complex example, involving tags with attributes:
> >   -->  
> >
> > You have to match:
> > (opening angle bracket)(any word)(any sequence of words,spaces,other
> > symbols,but NOT a closing angle bracket)(closing angle bracket)(opening
> > angle bracket)(slash)(same word as before)(closing angle bracket)
> >
> > r"<(\w+)([^>]*)>"
> >
> > [^>] means "anything but a >", the * means "may occur many times, maybe
> > zero", and it's enclosed in () to create group 2.
> >
> > py> source = """
> > ... 
> > ... 
> > ... """
> > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source)
> >
> > 
> > 
> >
> > Next step would be to allow whitespace wherever it is legal to appear -
> > left as an exercise to the reader. Hint: use \s*
> >
> > --
> > Gabriel Genellina
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Missing documentation for ElementTree?

2007-09-25 Thread Robert Dailey
Hi,

for the _ElementInterface class, there is no documentation for most of the
members of this class such as .tail and .text. There's a brief description
of these things on the front page of the ElementTree docs but nothing
helpful. I have no idea what Tail is vs Text and I wanted to figure this out
myself, however I don't think I can now. Anyone know if I'm just missing
something in the documentation or if it really isn't in there?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
On 9/25/07, J. Cliff Dyer <[EMAIL PROTECTED]> wrote:
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Robert Dailey top posted:
> > Hmm, ElementTree.tostring() also adds a space between the last
> > character of the element name and the />. Not sure why it is doing
> > this.
> >
> > Something like  will become  after the tostring().
>
>
> The space was common practice in pseudo-XHTML code when people still
> had to routinely support browsers like Netscape 4, which had no clue
> about XML.  It basically makes a uniquely XML construct into valid
> HTML.  Basically, the space makes unaware parsers treat the / as the
> next attribute.  Being an attribute with unknown meaning, the standard
> practice is to ignore it, and hence, it is parsed properly in both
> XHTML parsers and plain HTML parsers.  I guess the practice just
> caught on beyond the XHTML world.
>
> I don't know if there's a flag to get rid of it, but you can always
> dig into the code
>
> Cheers,
> Cliff
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.7 (MingW32)
>
> iD8DBQFG+ZXyGI3CK/MIt30RAkvhAJ0TAz4Y5ngDEVo9wnRwPhESh+D64QCcDjdM
> JKT6H37LgX1Fk7665+Mqwh0=
> =GcvK
> -END PGP SIGNATURE-
>
>
Right now I just run a trivial regular expression on the result of
tostring() to remove the spaces.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Invoking python through C++: How to?

2007-09-25 Thread Robert Dailey
On 9/25/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> If you don't want to "share" objects between Python and C++, that's the
> simplest way.
> Or, look at the document "Extending and Embedding the Python Interpreter"
> 
>
> --
> Gabriel Genellina


Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Missing documentation for ElementTree?

2007-09-26 Thread Robert Dailey
This is the documentation for 3.0a1? This is exactly what I was looking for.
Thank you.

@Gabriel
Your documentation is also useful, it never occurred to me to check the
ElementTree website for documentation. Since it came with Python I expected
it to be covered by the python documentation. Thanks.

On 9/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> On Sep 26, 4:00 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
> > En Tue, 25 Sep 2007 19:39:33 -0300, Robert Dailey <[EMAIL PROTECTED]>
> > escribi?:
> >
> > > for the _ElementInterface class, there is no documentation for most of
> > > the
> > > members of this class such as .tail and .text. There's a brief
> > > description
> > > of these things on the front page of the ElementTree docs but nothing
> > > helpful. I have no idea what Tail is vs Text and I wanted to figure
> this
> > > out
> > > myself, however I don't think I can now. Anyone know if I'm just
> missing
> > > something in the documentation or if it really isn't in there?
> >
> > Start here:http://www.effbot.org/zone/element-index.htm
> >
> > --
> > Gabriel Genellina
>
> Check out the development version of the documentation
>
> http://docs.python.org/dev/library/xml.etree.elementtree.html#module-xml.etree.ElementTree
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-26 Thread Robert Dailey
Even better! Now I can drop the regular expression that did the same thing
:)

Thanks!

On 9/26/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
>
> > Hmm, ElementTree.tostring() also adds a space between the last character
> > of the element name and the />. Not sure why it is doing this.
>
> ET is commonly used to generate (X)HTML fragments, and that space
> provides partial HTML compatibility.
>
> since the default serializer never generates CDATA sections, it should
> be safe to simply do a text.replace(" />", "/>") on the resulting string.
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

RegEx question

2007-10-04 Thread Robert Dailey
Hi,

The following regex (Not including the end quotes):

"@param\[in|out\] \w+ "

Should match any of the following:

@param[in] variable
@param[out] state
@param[in] foo
@param[out] bar


Correct? (Note the trailing whitespace in the regex as well as in the
examples)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RegEx question

2007-10-04 Thread Robert Dailey
It should also match:

@param[out] state Some description of this variable


On 10/4/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> The following regex (Not including the end quotes):
>
> "@param\[in|out\] \w+ "
>
> Should match any of the following:
>
> @param[in] variable
> @param[out] state
> @param[in] foo
> @param[out] bar
>
>
> Correct? (Note the trailing whitespace in the regex as well as in the
> examples)
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RegEx question

2007-10-04 Thread Robert Dailey
On 10/4/07, Adam Lanier <[EMAIL PROTECTED]> wrote:
>
>
> try @param\[(in|out)\] \w+
>

This didn't work either :(

The tool using this regular expression (Comment Reflower for VS2005) May be
broken...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RegEx question

2007-10-04 Thread Robert Dailey
On 10/4/07, J. Clifford Dyer <[EMAIL PROTECTED]> wrote:
>
> You *are* talking about python regular expressions, right?  There are a
> number of different dialects.  Also, there could be issues with the quoting
> method (are you using raw strings?)
>
> The more specific you can get, the more we can help you.


As far as the dialect, I can't be sure. I am unable to find documentation
for Comment Reflower and thus cannot figure out what type of regex it is
using. What exactly do you mean by your question, "are you using raw
strings?". Thanks for your response and I apologize for the lack of detail.
-- 
http://mail.python.org/mailman/listinfo/python-list

Off Topic: Gmail hates newsgroups!!!

2007-10-04 Thread Robert Dailey
I don't know how many other people subscribe to the python mailing list and
use the mailing list using the web-based interface for Gmail, but I do. I
use it mainly because Gmail doesn't support IMAP and I use my email from
multiple locations. Gmail web based works fine except that it starts your
caret off BEFORE the reply instead of AFTER it. They don't even have an
option to change this either. I'm just ranting this because it upsets me :)

If anyone might know of a firefox plugin or something to fix this I'd be
more than willing to use it. I've looked a bit myself for such an extension
and I've been unsuccessful in finding one.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RegEx question

2007-10-04 Thread Robert Dailey
I am not a regex expert, I simply assumed regex was standardized to follow
specific guidelines. I also made the assumption that this was a good place
to pose the question since regular expressions are a feature of Python. The
question concerned regular expressions in general, not really the
application. However, now that I know that regex can be different, I'll try
to contact the author directly to find out the dialect and then find the
appropriate location for my question from there. I do appreciate everyone's
help. I've tried the various suggestions offered here, however none of them
work. I can only assume at this point that this regex is drastically
different or the application reading the regex is just broken.

Thanks again for everyones help!
-- 
http://mail.python.org/mailman/listinfo/python-list

csv module and Unicode

2007-10-05 Thread Robert Dailey
Hi,

According to the Python 2.5 documentation, Unicode is not supported through
the CSV module. Is there some third-party CSV module I can use that has
Unicode support? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: csv module and Unicode

2007-10-08 Thread Robert Dailey
Wow; I guess this is a REAL problem! I would have thought that something as
common as Unicode CSV would have been supported by SOMEONE.

On 10/5/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> According to the Python 2.5 documentation, Unicode is not supported
> through the CSV module. Is there some third-party CSV module I can use that
> has Unicode support? Thanks.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

for loop question

2007-10-10 Thread Robert Dailey
Hi,

I'm currently writing my own CSV parser since the built in one doesn't
support Unicode. I'm wondering if there's a way to iterate over the
characters in a unicode string and have access to both the 'current' and the
'next' characters each iteration. For example:

test = u"Hello World"

for cur,next in test:
print cur,next

Ideally, this would output:

'H', 'e'
'e', 'l'
'l', 'l'
'l', 'o'
etc...

Of course, the for loop above isn't valid at all. I am just giving an
example of what I'm trying to accomplish. Anyone know how I can achieve the
goal in the example above? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: for loop question

2007-10-10 Thread Robert Dailey
All the ideas presented here are workable. I definitely have a lot of
solutions to choose from. Thanks everyone for your help. I wasn't sure if
there was some sort of language feature to naturally do this, so I had to
post on the mailing list to make sure.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: for loop question

2007-10-10 Thread Robert Dailey
I've tried everything to make the original CSV module work. It just doesn't.
I've tried UTF-16 encoding (which works fine with codecs.open()) but when I
pass in the file object returned from codecs.open() into csv.reader(), the
call to reader.next() fails because it says something isnt' in the range of
range(128) or something (Not really an expert on Unicode so I'm not sure of
the meaning). I would use CSV if I could!

On 10/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> On Wed, 2007-10-10 at 15:27 -0500, Robert Dailey wrote:
> > I'm using CSV for localization in a game I'm involved with.
>
> That doesn't tell me why you think you need a CSV parser that supports
> Unicode. There is no such thing as a Unicode file. The file contains a
> stream of octets that represent some encoding of Unicode code points. If
> the encoding is chosen properly, such as UTF-8, the standard CSV parser
> should be able to parse the resulting stream.
>
> -Carsten
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: for loop question

2007-10-10 Thread Robert Dailey
On 10/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> Instead of passing the file object directly to the csv parser, pass in a
> generator that reads from the file and explicitly encodes the strings
> into UTF-8, along these lines:
>
> def encode_to_utf8(f):
> for line in f:
> yield line.encode("utf-8")
>
> There may be a fundamental problem with this approach that I can't
> foresee at the moment, but it's worth a try when your alternative is to
> build a Unicode-aware CSV parser from scratch.
>
> Hope this helps,


I did the following:


#

def encode_utf8( f ):
for line in f:
yield line.encode( "utf-8" )

#

def BeginLocalizationParsing( outputDir, inputRoot, inputFile ):
f = codecs.open( inputFile, "rb", encoding="utf-16" )

r = csv.reader( encode_utf8( f ) )
print r.next()

#

It worked perfectly! Thank you! I guess I don't have to make a CSV parser
after all :P
-- 
http://mail.python.org/mailman/listinfo/python-list

How to "dereference" an iterator?

2007-10-10 Thread Robert Dailey
Hi,

Suppose I wanted to manually iterate over a container, for example:

mylist = [1,2,3,4,5,6]

it = iter(mylist)
while True:
print it
it.next()

In the example above, the print doesn't print the VALUE that the iterator
currently represents, it prints the iterator itself. How can I get the value
'it' represents so I can either modify that value or print it? Thanks.

PS: Yes, I know that the While loop is messy and I should be prepared to
handle the StopIteration exception. However, if you guys can think of a
better alternative than the while loop I'd really appreciate it. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Problems with struct.pack()

2007-10-10 Thread Robert Dailey
Hi,

I have opened a unicode file for writing:

import codecs
file = codecs.open( "somefile.dat", "wb", "utf-16" )

and I attempt to do this:

file.write( struct.pack( "I", 5000 ) )

However, this won't work because the encoding of the string returned by
"pack" isn't unicode. I'm a bit confused right now as to how I can get this
to work. I can't allow the unicode-ness of the file interfere with the
actual order of the bytes that pack() is returning (In other words, don't
pack NULL characters in there)

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problems with struct.pack()

2007-10-10 Thread Robert Dailey
Hi,

Thanks for responding. I apologize about my lack of details, I was in a
hurry when I wrote the initial question. I'll provide more details.

Basically, I'm attempting to write out unicode strings (16 bits per
character) to a file. Before each string, I write out 4 bytes containing the
number of characters (NOT BYTES) the string contains. I suppose the
confusion comes in because I'm writing out both text information AND binary
data at the same time. I suppose the consistent thing to do would be to
write out the strings as binary instead of as text? I'm originally a C++
programmer and I'm still learning Python, so figuring out this problem is a
little difficult for me.

In my initial inquiry, I was writing out 5000 as an example, however this
number would realistically be the number of characters in the string: len(
u"Hello World" ). Once I write out these 4 bytes, I then write out the
string "Hello World" immediately after the 4 bytes. You may be wondering why
the crazy file format. The reason is because this python script is writing
out data that will later be read in by a C++ application.

The following works fine for ASCII strings:

mystring = "Hello World"
file = open( "somefile.txt", "wb" )
file.write( struct.pack ( "I", len(mystring) ) )
file.write( mystring )

Again I do apologize for the lack of detail. If I've still been unclear
please don't hesitate to ask for more details.

On 10/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> On Wed, 2007-10-10 at 19:00 -0500, Robert Dailey wrote:
> > Hi,
> >
> > I have opened a unicode file for writing:
> >
> > import codecs
> > file = codecs.open( "somefile.dat", "wb", "utf-16" )
> >
> > and I attempt to do this:
> >
> > file.write( struct.pack ( "I", 5000 ) )
> >
> > However, this won't work because the encoding of the string returned
> > by "pack" isn't unicode. I'm a bit confused right now as to how I can
> > get this to work. I can't allow the unicode-ness of the file interfere
> > with the actual order of the bytes that pack() is returning (In other
> > words, don't pack NULL characters in there)
>
> Please start at the beginning. What are you actually trying to
> accomplish and why do you think you need to write arbitrary binary data
> into a file that is supposed to be a UTF-16 encoded Unicode text file?
>
> --
> Carsten Haese
> http://informixdb.sourceforge.net
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to "dereference" an iterator?

2007-10-10 Thread Robert Dailey
Hi,

I suppose my question in general is goofy to native python programmers. I'm
originally a C++ programmer and I have a hard time not relating iterators in
python to iterators in STL lol. What I was actually trying to accomplish was
to iterate over 2 iterators using 1 for loop, however I found that the zip()
function allows me to do this quite easily:

list1 = [1,2,3]
list2 = [4,5,6]

for i1,i2 in zip( list1, list2 ):
# do something here...

In one of my earlier threads in this group someone had ended up using zip().
After reviewing that thread again I found that I could also use it to solve
this problem as well. Sorry for lack of details. Thanks for everyone's help.

On 10/10/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>
> The original post seems to have been eaten, so I'm replying via a reply.
> Sorry for breaking threading.
>
> > On Wed, 2007-10-10 at 18:01 -0500, Robert Dailey wrote:
> >> Hi,
> >>
> >> Suppose I wanted to manually iterate over a container, for example:
> >>
> >> mylist = [1,2,3,4,5,6]
> >>
> >> it = iter(mylist)
> >> while True:
> >> print it
> >> it.next()
> >>
> >> In the example above, the print doesn't print the VALUE that the
> >> iterator currently represents, it prints the iterator itself. How can I
> >> get the value 'it' represents so I can either modify that value or
> >> print it? Thanks.
>
> it = iter(mylist)
> while True:
> print it.next()
>
> but that will eventually end with an exception. Better to let Python
> handle that for you:
>
> it = iter(mylist)
> for current in it:
> print current
>
> Actually, since mylist is already iterable, you could just do this:
>
> for current in mylist:
> print current
>
> but you probably know that already.
>
>
> --
> Steven.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to "dereference" an iterator?

2007-10-10 Thread Robert Dailey
Thanks! Yellow is my favorite color!

On 10/10/07, Pablo Ziliani <[EMAIL PROTECTED]> wrote:
>
> Robert Dailey wrote:
> > (...)
> > What I was actually trying to accomplish was to iterate over 2
> > iterators using 1 for loop, however I found that the zip() function
> > allows me to do this quite easily:
> >
> > list1 = [1,2,3]
> > list2 = [4,5,6]
> >
> > for i1,i2 in zip( list1, list2 ):
> > # do something here...
> >
> > In one of my earlier threads in this group someone had ended up using
> > zip(). After reviewing that thread again I found that I could also use
> > it to solve this problem as well. Sorry for lack of details. Thanks
> > for everyone's help.
>
> Robert,
>
> You get one warning for top-posting and a yellow card for not being able
> to state your needs correctly (so we can help you). Think pythonicly:
> nobody actually *needs* to "dereference an iterator", but to get a
> certain value from a some given sequences.
>
> Despite the subject, you ended up using a "iterator-less" solution.
> There are reasons to use an iterator, though. You might want to take a
> look at itertools.izip:
>
> class izip(__builtin__.object)
> |  izip(iter1 [,iter2 [...]]) --> izip object
> |
> |  Return a izip object whose .next() method returns a tuple where
> |  the i-th element comes from the i-th iterable argument.  The .next()
> |  method continues until the shortest iterable in the argument sequence
> |  is exhausted and then it raises StopIteration.  Works like the zip()
> |  function but consumes less memory by returning an iterator instead of
> |  a list
>
>
> Lame example follows:
>
> >>> from itertools import izip
> >>> from string import lowercase
> >>> for (i, l) in izip(range(len(lowercase)), lowercase):
> ... print "do something with i = %s and l = %s" % (i, l)
> ...
> do something with i = 0 and l = a
> do something with i = 1 and l = b
> do something with i = 2 and l = c
> do something with i = 3 and l = d
> do something with i = 4 and l = e
> do something with i = 5 and l = f
> do something with i = 6 and l = g
> do something with i = 7 and l = h
> do something with i = 8 and l = i
> do something with i = 9 and l = j
> do something with i = 10 and l = k
> do something with i = 11 and l = l
> do something with i = 12 and l = m
> do something with i = 13 and l = n
> do something with i = 14 and l = o
> do something with i = 15 and l = p
> do something with i = 16 and l = q
> do something with i = 17 and l = r
> do something with i = 18 and l = s
> do something with i = 19 and l = t
> do something with i = 20 and l = u
> do something with i = 21 and l = v
> do something with i = 22 and l = w
> do something with i = 23 and l = x
> do something with i = 24 and l = y
> do something with i = 25 and l = z
>
>
> HTH,
> Pablo
>
-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   >