Embedded Boost.Python Enum

2007-10-17 Thread Cory
Hi,

I have a hopefully quick question about how to use Boost.Python to
export an Enum.
I am embedding python in C++ and am currently exporting my classes in
the following way:

nameSpace["OBJECT"] = class_("OBJECT")
.def("getType", &OBJECT::getType)
.def("setSprite", &OBJECT::setSprite);

So following this, I assumed that when exporting an enum the following
should work:

nameSpace["OBJECT_TYPE"] = enum_("OBJECT_TYPE")
.value("GENERIC_OBJECT",GENERIC_OBJECT)
.value("MAP_OBJECT",MAP_OBJECT)
.value("TOTAL_OBJECT_TYPES",TOTAL_OBJECT_TYPES)
.export_values();

while the above compiles, it causes the following run time exception:

AttributeError: 'NoneType' object has no attribute 'OBJECT_TYPE'

I took a look at the documentation and the only explanation I found
for enum appeared to be for extending python with modules. using the
following form:

BOOST_PYTHON_MODULE(enums)
{
enum_("color")
.value("red", red)
.value("green", green)
.export_values()
.value("blue", blue)
;

}

I COULD do the above, I would prefer the first method if possible. I
however do not know how to import the module if it is statically
linked because doing a simple import does not work and I am not
familiar enough with the boost.python library, Python C API, or Python
itself to know how to set it up. So My question is this:

How can I either make the first method of adding an enum work and not
throw the exception, OR once I create the BOOST_PYTHON_MODULE in an
embedded python c++ program how to I then import that module into my
embedded python?

Thanks in advance for any help

-Cory

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


Re: Embedded Boost.Python Enum

2007-10-18 Thread Cory
Ok, I finally got it figured out. The secret which no one told me what
that if you're doing embedding, you have to initialize your modules!

BOOST_PYTHON_MODULE(Enums){ ... } defines the function initEnums()
which must be called before you can import the module. Finally figured
it out by looking here: 
http://members.gamedev.net/sicrane/articles/EmbeddingPythonPart1.html

It's odd to me that little tidbit got left out of the boost.python
tutorial page on embedding... I must have looked at it 100 times.


On Oct 18, 12:59 am, Cory <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a hopefully quick question about how to use Boost.Python to
> export an Enum.
> I am embedding python in C++ and am currently exporting my classes in
> the following way:
>
> nameSpace["OBJECT"] = class_("OBJECT")
> .def("getType", &OBJECT::getType)
> .def("setSprite", &OBJECT::setSprite);
>
> So following this, I assumed that when exporting an enum the following
> should work:
>
> nameSpace["OBJECT_TYPE"] = enum_("OBJECT_TYPE")
> .value("GENERIC_OBJECT",GENERIC_OBJECT)
> .value("MAP_OBJECT",MAP_OBJECT)
> .value("TOTAL_OBJECT_TYPES",TOTAL_OBJECT_TYPES)
> .export_values();
>
> while the above compiles, it causes the following run time exception:
>
> AttributeError: 'NoneType' object has no attribute 'OBJECT_TYPE'
>
> I took a look at the documentation and the only explanation I found
> for enum appeared to be for extending python with modules. using the
> following form:
>
> BOOST_PYTHON_MODULE(enums)
> {
> enum_("color")
> .value("red", red)
> .value("green", green)
> .export_values()
> .value("blue", blue)
> ;
>
> }
>
> I COULD do the above, I would prefer the first method if possible. I
> however do not know how to import the module if it is statically
> linked because doing a simple import does not work and I am not
> familiar enough with the boost.python library, Python C API, or Python
> itself to know how to set it up. So My question is this:
>
> How can I either make the first method of adding an enum work and not
> throw the exception, OR once I create the BOOST_PYTHON_MODULE in an
> embedded python c++ program how to I then import that module into my
> embedded python?
>
> Thanks in advance for any help
>
> -Cory


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


distutils linux script installation broken?

2005-01-12 Thread Cory Davis
Hi all,
I have been successfully deploying my own python package with distutils 
for some time now, but lately, with Python 2.4, the build_scripts 
command has been behaving badly.  In the part where it is supposed to 
adjust the first line of the script it now produces

#!None
instead of
#!/whereverpythonis/python
Has anyone else encountered this?
Cheers,
Cory.
--
http://mail.python.org/mailman/listinfo/python-list


Re: distutils linux script installation broken?

2005-01-12 Thread Cory Davis
Thanks Albert.
I already do use #!/usr/bin/env python in my package directory, but the 
build_scripts part of "setup.py install" changes this line to #!None 
before copying to my bin directory.

Cheers,
Cory.
Albert Hofkamp wrote:
On Wed, 12 Jan 2005 10:09:03 +, Cory Davis <[EMAIL PROTECTED]> wrote:
command has been behaving badly.  In the part where it is supposed to 
adjust the first line of the script it now produces

#!None
instead of
#!/whereverpythonis/python
Has anyone else encountered this?

I haven't (as I am not using 2.4 :-) )
However, there is an easy way around this, just use
#!/usr/bin env python
instead.
Albert
--
http://mail.python.org/mailman/listinfo/python-list


Re: distutils linux script installation broken?

2005-01-12 Thread Cory Davis
Hi Christopher
distutils should replace that first line with the location of the
binary used to run setup.py. Are you running setup with the following
command line?
python setup.py install
Yes.
A possible complication is that I also have python 2.3.? on that 
machine, which I am reluctant to remove incase it disturbs my linux 
distribution (Fedora Core 2).
Its also possible that I have done something silly to an environment 
variable.  To check this I will try installing my package either as root 
or another user.

Cheers,
Cory.
--
http://mail.python.org/mailman/listinfo/python-list


Re: distutils linux script installation broken?

2005-01-13 Thread Cory Davis
Thanks for the help Chris. I tried the -E option, and also installing as 
root with no change - the scripts in the bin directory still end up with 
#!None on the first line.  Next step is to reinstall Python 2.4, and if 
that doesn't work I'll just stick with 2.3.4.

Cheers,
Cory.
Christopher De Vries wrote:
I've got python 2.3.3, 2.4, and 1.5.2 (which came preinstalled) on my
linux box. It's redhat 7.2 (I know... I would upgrade, but it would
void my service contract, so I just install things in /usr/local). You
can check if PYTHONHOME or PYTHONPATH are set, which may somehow be
interfering. I don't have those variables set. If they are set, you
could try running:
python -E setup.py install
The -E option should make python ignore those environment variables.
Good luck, I hope this helps.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: distutils linux script installation broken? Sorted

2005-01-14 Thread Cory Davis
Problem solved.  I was actually using scipy_distutils and not distutils, 
without good reason.  Changing setup.py to use distutils made the 
problem go away.

Cory.
Cory Davis wrote:
Hi all,
I have been successfully deploying my own python package with distutils 
for some time now, but lately, with Python 2.4, the build_scripts 
command has been behaving badly.  In the part where it is supposed to 
adjust the first line of the script it now produces

#!None
instead of
#!/whereverpythonis/python
Has anyone else encountered this?
Cheers,
Cory.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: Check first two non-whitespace characters

2015-12-31 Thread Cory Madden
I would personally use re here.

test_string = '  [{blah blah blah'
matches = re.findall(r'[^\s]', t)
result = ''.join(matches)[:2]
>> '[{'

On Thu, Dec 31, 2015 at 10:18 AM,   wrote:
> I need to check a string over which I have no control for the first 2 
> non-white space characters (which should be '[{').
>
> The string would ideally be: '[{...' but could also be something like
> '  [  {  '.
>
> Best to use re and how? Something else?
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Parsing an html line and pulling out only numbers that meet a certain criteria

2013-09-11 Thread Cory Mottice
I am using line.rfind to parse a particular line of html code. For example, 
this is the line of html code I am parsing:

79°Lo 56°

and this is the code I use to split the line to (in this case) pull out the 
'79'.

position0 = line.rfind('{}'.format(date1.strftime("%a")))
if position0 > 0 :
self.high0 = lines[line_number + 4].split('')[0].split('">')[-1]

Now I need to only pull out that number if it is >=94 and <=37. If it does not 
meet this criteria, I don't want anything to happen. Any ideas? Thank you in 
advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Python won't run

2010-02-18 Thread Nardin, Cory L.
Quickly, I have a Mac Intel with Windows XP installed.  Tried installing
Python 2.6.4 from the binary and also ActivePython 2.6.4.10.  Both
installations acted the same.  There seemed to be no problems during
installation (used default options), but when I try to run Python I get
an error message: "This application has failed to start because the
application configuration is incorrect.  Reinstalling the application
may fix this problem."

 

Of course I searched on that error and it seems to be related to a MS
library.  In a few different places it was recommended to install the MS
Visual Studio redistributable package, which I did with no change in
outcome.  I really have no idea what to do.

 

Any help is appreciated.

 

Thanks,

Cory

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


RE: Python won't run

2010-02-23 Thread Nardin, Cory L.
Thanks so much for that suggestion.  I used the tool and found two
missing libraries: MSVCR90.DLL and DWMAPI.DLL.  I located and copied the
first library to my python directory (and resolved that dependency), but
I am still missing the other.  I have done a Google search and found
that DWMAPI is a Vista library.  I am have XP, so I am not sure why it
is a required dependency?  I made sure that I have all the MS updates
(presumably MS would include a new library in an update if it became a
required library) and that did not solve the problem.  Is this a bug or
should I have that library on my computer and the fact that it isn't
there is the sign of some other problem?

 

Thanks

Cory

 



From: Sridhar Ratnakumar [mailto:sridh...@activestate.com] 
Sent: Monday, February 22, 2010 11:54 AM
To: Nardin, Cory L.
Cc: python-list@python.org
Subject: Re: Python won't run

 

Have you tried using  <http://dependencywalker.com/> 
http://dependencywalker.com/ ?

 

-srid

 

On 2010-02-18, at 1:00 PM, Nardin, Cory L. wrote:





Quickly, I have a Mac Intel with Windows XP installed.  Tried installing
Python 2.6.4 from the binary and also ActivePython 2.6.4.10.  Both
installations acted the same.  There seemed to be no problems during
installation (used default options), but when I try to run Python I get
an error message: "This application has failed to start because the
application configuration is incorrect.  Reinstalling the application
may fix this problem."

 

Of course I searched on that error and it seems to be related to a MS
library.  In a few different places it was recommended to install the MS
Visual Studio redistributable package, which I did with no change in
outcome.  I really have no idea what to do.

 

Any help is appreciated.

 

Thanks,

Cory

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

 

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