Volume of CSG (constructive solid geometry) objects
>From python, I need to be able to create CSG objects and calculate their volume (and from that their mass). It looks like their are plenty of packages to create and display CSG objects, however, I can not seem to find any API to get to the object's volume. If anyone has any ideas/tips/pointers/etc., I would be very grateful. Thanks, Charlie -- http://mail.python.org/mailman/listinfo/python-list
dynamic data types
Hi, The description of Python always mentions "very high level dynamic data types". Now, I can't seem to find any examples of these (nothing described with this term anyway). Is this simply refering to built-in dynamic data structures such as lists and dictionaries, with a great deal of operators defined on? Or is there something else meant by "dynamic data types" in Python? Regards, Charlie -- http://mail.python.org/mailman/listinfo/python-list
Obtaining glyph width in Python
Hi, I'm looking for a way to obtain the width of a string, either in actual inches/centimeters, or pixels will also work. Unfortunately this seems difficult as I'd like to keep things as close to the stock Python install as possible, and I'm not working with Graphics or X at all. Here are the options I've found, and why they're less than optimal for my use: PIL = Huge for only using one function. I'm not working with any graphics. PyFT = Everyone uses FreeType2 now, and PyFT seems dead anyhow. PyFT2 = Does not exist. tkinter.text() = Works with X, creates windows no matter what you do. t1lib = Separate package, no TTF support. t1python = Same thing as t1lib? Ultimately, I'm looking to take a stream of text, and break it up into lines based on page width... and I need to know how wide (and ultimately how tall, for page breaks) the individual glyphs are so I can break properly. If there's an easier way to do this than calculating individual glyph width, I'm open to that too. I was really just looking to see if there was anything out there that wasn't too large or too obscure/dated. Maybe there's something lower level that could be done to achieve this? Is there metadata in the font that holds this information that could be extracted? Thanks in advance, -Charlie -- http://mail.python.org/mailman/listinfo/python-list
MsiLib
Hi, I am trying to figure out how to use msilib to extract the registry information from an MSI file and I really could use a good example of how that is accomplished or even just an example using msilib in general. Does anybody happen to know of an example for this as I wasn't able to find one? If there isn't one, would anybody be willing to throw one together? Thanks Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: MsiLib
Thanks for the help. That definitely gets me on the right track. I am having an issue though. I keep getting the error that MSIDBOPEN_READONLY is not defined. Here is my code for testing. Am I missing something really obvious or is something just not working that should and my system is screwed up somewhere? Thanks. import msilib c = msilib.OpenDatabase('test.msi', MSIDBOPEN_READONLY) view = c.OpenView("SELECT * FROM Registry") record = view.Fetch() -- http://mail.python.org/mailman/listinfo/python-list
Re: MsiLib
Thanks for pointing that out. It solved the one problem and along came another. Now I get the following error when I try running it. Thanks for the help. Traceback (most recent call last): File "msi.py", line 7, in record = view.Fetch() _msi.MSIError: function failed -- http://mail.python.org/mailman/listinfo/python-list
Re: MsiLib
This doesn't seem to be my day for this. When I add view.Execute() to the script, it gives me an error of Execute() takes exactly 1 argument (0 given). I can't seem to find anything on the Microsoft page that concerns the execute function that states what exactly needs to be included as an argument, especially for a select statement. Thanks for the help. Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: MsiLib
Thank you everybody for your help. It finally runs without errors and I should be able to use this as I figure out more of it. I am curios if there is any idea as to when GetString will be implemented? Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: MsiLib
Quoting "Martin v. Löwis" <[EMAIL PROTECTED]>: > Charlie schrieb: >> Thank you everybody for your help. It finally runs without errors and I >> should be able to use this as I figure out more of it. I am curios if >> there is any idea as to when GetString will be implemented? > > If I can find the time, it may be for Python 2.6. If not, Python 2.7, > 3.1, or so. Faster if a patch is contributed. > > Regards, > Martin > Thank you. I would be willing to help out, but as of now I have no idea how to get started on it. If you would be willing to provide some guidance, then I would be fine with giving it a shot if nothing more. My guess is that it would have to implement the MsiRecordGetString function so that it is accessible, but I don't know beyond that. Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: How would I compile a Python file to a exe
Quoting Lamonte Harris <[EMAIL PROTECTED]>: > Been a while and I'm wondering how I would go about doing it. > py2exe seems to be a fairly good option for this, at least in the world of Windows. -- http://mail.python.org/mailman/listinfo/python-list
C Function Pointer Wrapping Example not working
Hi All, I am new to using swig/C++/python. I got some problem with function pointers. I posted in swig-user, but got no response. So I forwarded it here. You help is greatly appreciated. Thanks! -- Forwarded message -- Hi All, Yesterday I posted about the question I had of template function. This time I worked step step from examples in Doc 1.3 to reach my ultimate goal. But as I worked on the Function Pointer Example in 5.4.9 in Doc 1.3, it doesn't work. My platform is a Ubuntu linux with swig 1.3.36, python 2.5.2 and gcc 4.2.3. The compiling and linking has no errors: swig -python -c++ -o test_wrap.cpp test.i python setup-test.py build running build running build_py copying test.py -> build/lib.linux-i686-2.5 running build_ext building '_test' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_wrap.cpp -o build/temp.linux-i686-2.5/test_wrap.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux- i686-2.5/test_wrap.o build/temp.linux-i686-2.5/test.o -o build/ lib.linux-i686-2.5/_test.so But when I try to import test in python, it complains: import _test ImportError: ./_test.so undefined symbol: _Z9binary_opiiPFiiiE My test.i is: %module test %{ #include "test.h" %} %include "test.h" %callback("%s_cb"); int add( int, int ); //add_cb int sub( int, int ); //sub_cb int mul( int, int ); //mul_cb %nocallback; My test.h is: int binary_op(int a, int b, int (*op)(int,int) ); int add( int a, int b ) { return a+b; } int sub( int a, int b ) { return a-b; } int mul( int a, int b ) { return a*b; } // NOTE: this is func ptr from example in Doc 1.3: 5.4.9 It is really strange to me. I am a novice swigger but I really need its power to accelerate my development. Could anybody point out where my problem is? TIA Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: C Function Pointer Wrapping Example not working
> > > But when I try to import test in python, it complains: > > import _test > > ImportError: ./_test.so undefined symbol: _Z9binary_opiiPFiiiE > > The above is a mangled name so you've got some C vs C++ problems I'd > say. > > You could try putting some extern "C" {} in around all the functions > which are imported and exported. Have a look at the code SWIG > generates and see if it puts some extern "C" in and match what it > does in your code. > > We used to use SWIG in for python embedding in our C++ project, but we > found that using ctypes is a lot easier. You just write C .so/.dll > and use ctypes to access them. You can do callbacks and embedding > python like this too. Thanks Nick. I tried your method, if I am right(please see the attached details), and I still got the undefined symbol error like previous. The only difference is "_Z9binary_opiiPFiiiE" changed to "binary_op". Could you help me more on this. It seems to have a mixed problems here and I guess what you've pointed out is one of them. But really, what I do now is just try to reproduce the example, how can this fails? What my ultimate need is wrapping up a template function taking template function pointer as argument. Did you ever try that? Many thanks already anyway. FILE and ERROR details: -test.i-- %module test %{ #include "test.h" %} %include "test.h" %callback("%s_cb"); int myadd( int, int ); //myadd_cb int mysub( int, int ); //mysub_cb int mymul( int, int ); //mymul_cb %nocallback; ---test.h-- extern "C"{ int binary_op(int a, int b, int (*op)(int,int) ); int myadd( int a, int b ) { return a+b; }; int mysub( int a, int b ) { return a-b; }; int mymul( int a, int b ) { return a*b; }; } - --error message-- Traceback (most recent call last): File "", line 1, in File "test.py", line 7, in import _test ImportError: ./_test.so: undefined symbol: binary_op -- ---compiling message- swig -v -python -c++ -o test_wrap.cpp test.i LangSubDir: python Search paths: ./ ./swig_lib/python/ /usr/local/share/swig/1.3.36/python/ ./swig_lib/ /usr/local/share/swig/1.3.36/ Preprocessing... Starting language-specific parse... Processing types... C++ analysis... Generating wrappers... python setup-test.py build running build running build_py copying test.py -> build/lib.linux-i686-2.5 running build_ext building '_test' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_wrap.cpp -o build/temp.linux-i686-2.5/test_wrap.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux- i686-2.5/test_wrap.o build/temp.linux-i686-2.5/test.o -o build/ lib.linux-i686-2.5/_test.so - -- http://mail.python.org/mailman/listinfo/python-list
Re: C Function Pointer Wrapping Example not working
> Nowhere in your code is the definition of binary_op - that is why you > get a linker error. > > Is it defined in another C file? If so you need to link it with the > swig wrapper before you make the .so > Thanks for pointing out. I sorted the code out finally! Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimizing math functions
Steven D'Aprano REMOVE-THIS-cybersource.com.au> writes: > > On Sat, 23 May 2009 09:22:59 -0400, Esmail wrote: > > > Hello all, > > > > I would like to maximize or minimize a given math function over a > > specific set of values, in Python preferably. > ... > > What it apparently can't do is for maximize (or minimize) functions that > > contain two variables, x and y, or more. You might also look at: http://pyparasol.sourceforge.net/example_1.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Optimizing math functions
Esmail hotmail.com> writes: > > Charlie wrote: > > > > You might also look at: > > http://pyparasol.sourceforge.net/example_1.html > > Thanks for this lead, I had never heard of parasol before. Do you know > if this also works under Linux? The docs mention only the Windows platform, > but given that this is Python perhaps it is save to assume this would also > work under Linux? > > Esmail > It might work under Linux, however, it was developed under Windows and, to my knowledge, has never been tested on a Linux machine. Basic operation only depends on installations of matplotlib, numpy, and scipy. Those packages are all available on Linux. If you try it, I'd like to know the outcome. The parasol options to launch Microsoft Office apps Excel, Power Point, and Word; or the ray tracing app POV-Ray, will very likely fail. Charlie -- http://mail.python.org/mailman/listinfo/python-list
Biggles on Windows with python2.5
Has anyone installed a version of biggles on Windows with python 2.5? The Martin Lamar version for python 2.3 was a big help, but I finally upgraded to python 2.5 and I am having trouble with the biggles build. Thanks, Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Excel
If it helps, I started a similar project a few years ago on SourceForge when I was just learning python called python2xlw. I haven't supported it for quite a while, however, I still use it a lot in my own work. I needed to create Excel files with scatter charts in them for a web interface so I went through the excercise of disassembling the BIFF codes of the older XLW format of excel and creating a byte stream representation of the spreadsheet that could be saved to file or sent directly to the web user as an excel application in there browser. The newer XLS format is a bit more complex and I didn't have enough documentation to create the charts I needed directly from python in the newer XLS format. (the current version of excel still understands XLW, however, so you're just a "SAVE AS" away from XLS.) As I think was mentioned in another post, you can create charts etc. using the COM interface for a client-type application, however, my goal was to create them on-the-fly directly from the web server without launching a server-side excel application. There is a nice Perl project called Spreadsheet::WriteExcel that John McNamara created that was very helpful to me at that time, however, it only created the worksheets, not charts. -- http://mail.python.org/mailman/listinfo/python-list
Defending Python
I perhaps rather foolishly wrote two article that mentioned Python as a good alternative language to more popular tools such as C# or Java. I encountered more resistance than I had expected. If someone who really knows a lot about Python would like to go over to the CodeFez website and defend Python a bit better than I can, that would be appreciated. The articles are called "The War of the Virtual Bills," and "Ranking Languages: Fear as a Career Move." Here are the links: http://www.codefez.com http://www.codefez.com/Home/tabid/36/articleType/ArticleView/articleId/135/RankingLanguagesFearasaCareerMove.aspx http://www.codefez.com/Home/tabid/36/articleType/ArticleView/articleId/134/TheWaroftheVirtualBills.aspx Thanks. - Charlie -- http://mail.python.org/mailman/listinfo/python-list
embedded python and interpreter threads
So, I have an amazing, functioning foobar class that embeds python. Only trouble is, I want to be able to have multiple foobar objects at once, each with their own interpreters, stdouts, and stderrs. My initialization of the python interpreter in the class "x" is as follows: [snip] if (!Py_IsInitialized()) { PyEval_InitThreads(); Py_Initialize(); } // Start and switch to a new interpreter thread. x->thread = Py_NewInterpreter(); // initialize the module 'logMethods', defined elsewhere, // which contains my stdout and stderr definitions Py_InitModule("log", logMethods); // overwrite Python's stdout and stderr PyRun_SimpleString( "import log\n" "import sys\n" "class StdoutCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStdout(str)\n" "class StderrCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStderr(str)\n" "sys.stdout = StdoutCatcher()\n" "sys.stderr = StderrCatcher()\n"); PyEval_ReleaseThread(x->thread); [snip] Everything seems to work as expected - each object seems to have its own interpreter (if I evaluate "tree = 'a larch'" in one of them, 'tree' is not thusly defined in the others). Since I store the threadstate as a property of the object, I can easily juggle the interpreter lock between objects when evaluating python code. However, the last foobar object to be instantiated collects the stdout and stderr of all the other objects (as though the stdout and stderr definitions were shared over all the objects). This seems strange, as the docs say that if I start a "Py_NewInterpreter()" I get new copies of all the modules, particuarly 'sys', and explicitly 'stdout' and 'stderr'. I thought of the possibility that the 'logMethods' structure which includes my versions of stdout and stderr might be behaving statically. But I didn't define it as static... I am new to C, so there might be something basic I am missing. Any suggestions or ideas? Thanks, Charlie DeTar -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python and interpreter threads
Quick correction, sorry - the command should read like this (I had omitted the "log" before 'CaptureStdout' and 'CaptureStderr'). Same problems exist. PyRun_SimpleString( "import log\n" "import sys\n" "class StdoutCatcher:\n" "\tdef write(self, str):\n" "\t\tlog.CaptureStdout(str)\n" "class StderrCatcher:\n" "\tdef write(self, str):\n" "\t\tlog.CaptureStderr(str)\n" "sys.stdout = StdoutCatcher()\n" "sys.stderr = StderrCatcher()\n"); =Charlie Charlie DeTar wrote: So, I have an amazing, functioning foobar class that embeds python. Only trouble is, I want to be able to have multiple foobar objects at once, each with their own interpreters, stdouts, and stderrs. My initialization of the python interpreter in the class "x" is as follows: [snip] if (!Py_IsInitialized()) { PyEval_InitThreads(); Py_Initialize(); } // Start and switch to a new interpreter thread. x->thread = Py_NewInterpreter(); // initialize the module 'logMethods', defined elsewhere, // which contains my stdout and stderr definitions Py_InitModule("log", logMethods); // overwrite Python's stdout and stderr PyRun_SimpleString( "import log\n" "import sys\n" "class StdoutCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStdout(str)\n" "class StderrCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStderr(str)\n" "sys.stdout = StdoutCatcher()\n" "sys.stderr = StderrCatcher()\n"); -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python and interpreter threads
Woohoo, fixed my problem. It had to do with the way I was handling the methods which overwrote stderr and stdout. Yeehaw! =Charlie Charlie DeTar wrote: Quick correction, sorry - the command should read like this (I had omitted the "log" before 'CaptureStdout' and 'CaptureStderr'). Same problems exist. PyRun_SimpleString( "import log\n" "import sys\n" "class StdoutCatcher:\n" "\tdef write(self, str):\n" "\t\tlog.CaptureStdout(str)\n" "class StderrCatcher:\n" "\tdef write(self, str):\n" "\t\tlog.CaptureStderr(str)\n" "sys.stdout = StdoutCatcher()\n" "sys.stderr = StderrCatcher()\n"); =Charlie Charlie DeTar wrote: So, I have an amazing, functioning foobar class that embeds python. Only trouble is, I want to be able to have multiple foobar objects at once, each with their own interpreters, stdouts, and stderrs. My initialization of the python interpreter in the class "x" is as follows: [snip] if (!Py_IsInitialized()) { PyEval_InitThreads(); Py_Initialize(); } // Start and switch to a new interpreter thread. x->thread = Py_NewInterpreter(); // initialize the module 'logMethods', defined elsewhere, // which contains my stdout and stderr definitions Py_InitModule("log", logMethods); // overwrite Python's stdout and stderr PyRun_SimpleString( "import log\n" "import sys\n" "class StdoutCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStdout(str)\n" "class StderrCatcher:\n" "\tdef write(self, str):\n" "\t\t.CaptureStderr(str)\n" "sys.stdout = StdoutCatcher()\n" "sys.stderr = StderrCatcher()\n"); -- http://mail.python.org/mailman/listinfo/python-list
Is this a good use for lambda
I find that I use lambda functions mainly for callbacks to things like integration or root finding routines as follows. flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd) root = findRoot(xBeg, xEnd, lambda x: y2+ lp*(x-x2) -wallFunc( x )[0], tolerance=1.0E-15) I have tried using named functions instead of using lambda functions, however, I always end up with a convoluted, hard to follow mess. Is there a better solution than a lambda in the above situations? -- http://mail.python.org/mailman/listinfo/python-list
Calculator Problem
Hey Guys i Need Help , When i run this program i get the 'None' Under the program, see what i mean by just running it , can someone help me fix this def Addition(): print('Addition: What are two your numbers?') 1 = float(input('First Number:')) 2 = float(input('Second Number:')) print('Your Final Result is:', 1 + 2) def Subtraction(): print('Subtraction: What are two your numbers?') 3 = float(input('First Number:')) 4 = float(input('Second Number:')) print('Your Final Result is:', 3 - 4) def Multiplication(): print('Multiplication: What are two your numbers?') 5 = float(input('First Number:')) 6 = float(input('Second Number:')) print('Your Final Result is:', 5 * 6) def Division(): print('Division: What are your two numbers?') 7 = float(input('First Number:')) 8 = float(input('Second Number:')) print('Your Final Result is:', 7 / 8) print('What type of calculation would you like to do?') Question = input('(Add, Subtract, Divide or Multiply)') if Question.lower().startswith('a'): print(Addition()) elif Question.lower().startswith('s'): print(Subtraction()) elif Question.lower().startswith('d'): print(Division()) elif Question.lower().startswith('m'): print(Multiplication()) else: print('Please Enter The First Letter Of The Type Of Calculation You Would Like To Use') while Question == 'test': Question() -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculator Problem
On Sunday, February 2, 2014 9:46:24 PM UTC, Gary Herron wrote: > On 02/02/2014 01:16 PM, Charlie Winn wrote: > > > Hey Guys i Need Help , When i run this program i get the 'None' Under the > > program, see what i mean by just running it , can someone help me fix this > > > > > > def Addition(): > > > print('Addition: What are two your numbers?') > > > 1 = float(input('First Number:')) > > > 2 = float(input('Second Number:')) > > > print('Your Final Result is:', 1 + 2) > > > > > > > > > def Subtraction(): > > > print('Subtraction: What are two your numbers?') > > > 3 = float(input('First Number:')) > > > 4 = float(input('Second Number:')) > > > print('Your Final Result is:', 3 - 4) > > > > > > > > > def Multiplication(): > > > print('Multiplication: What are two your numbers?') > > > 5 = float(input('First Number:')) > > > 6 = float(input('Second Number:')) > > > print('Your Final Result is:', 5 * 6) > > > > > > > > > def Division(): > > > print('Division: What are your two numbers?') > > > 7 = float(input('First Number:')) > > > 8 = float(input('Second Number:')) > > > print('Your Final Result is:', 7 / 8) > > > > > > > > > > > > print('What type of calculation would you like to do?') > > > Question = input('(Add, Subtract, Divide or Multiply)') > > > if Question.lower().startswith('a'): > > > print(Addition()) > > > elif Question.lower().startswith('s'): > > > print(Subtraction()) > > > elif Question.lower().startswith('d'): > > > print(Division()) > > > elif Question.lower().startswith('m'): > > > print(Multiplication()) > > > else: > > > print('Please Enter The First Letter Of The Type Of Calculation > > You Would Like To Use') > > > > > > while Question == 'test': > > > Question() > > > > Sorry, but in fact you did *not* run this program as you claim. It's > > full of syntax errors. Any attempt to run it will display syntax errors > > immediately, and never actually run. So please tell us what really > > happened. > > > > But even without an accurate description of what you did, I can say this: > > > > Lines like > > 1 = float(...) > > don't make sense. It's as if you are trying to change the value of the > > number one, but that's nonsense. > > > > And lines like > > print('Your Final Result is:', 5 * 6) > > had better print out 30 (since that is what 5 times 6 is) but that's > > clearly not what you intended. > > > > Gary Herron excuse me but don't be so *** rude , i did run this program and it did run correctly and if you want me to prove it with screenshots so be it , so don't make accusations ** Gary ** i only came here for some help not to be accused of not even running my program Charlie :D -- https://mail.python.org/mailman/listinfo/python-list
Re: Calculator Problem
On Monday, February 3, 2014 6:17:44 PM UTC, Joel Goldstick wrote: > On Feb 3, 2014 1:05 PM, "Charlie Winn" wrote: > > > > > > On Sunday, February 2, 2014 9:46:24 PM UTC, Gary Herron wrote: > > > > On 02/02/2014 01:16 PM, Charlie Winn wrote: > > > > > > > > > Hey Guys i Need Help , When i run this program i get the 'None' Under > > > > the program, see what i mean by just running it , can someone help me > > > > fix this > > > > > > > > > > > > > > > > > > def Addition(): > > > > > > > > > print('Addition: What are two your numbers?') > > > > > > > > > 1 = float(input('First Number:')) > > You can't name a variable a number > > > > > > > > > 2 = float(input('Second Number:')) > > > > > > > > > print('Your Final Result is:', 1 + 2) > > You should a result, then print it after the function. > > > > > > > > > > > > > > > > > > > > > > > def Subtraction(): > > > > > > > > > print('Subtraction: What are two your numbers?') > > > > > > > > > 3 = float(input('First Number:')) > > > > > > > > > 4 = float(input('Second Number:')) > > > > > > > > > print('Your Final Result is:', 3 - 4) > > > > > > > > > > > > > > > > > > > > > > > > > > > def Multiplication(): > > > > > > > > > print('Multiplication: What are two your numbers?') > > > > > > > > > 5 = float(input('First Number:')) > > > > > > > > > 6 = float(input('Second Number:')) > > > > > > > > > print('Your Final Result is:', 5 * 6) > > > > > > > > > > > > > > > > > > > > > > > > > > > def Division(): > > > > > > > > > print('Division: What are your two numbers?') > > > > > > > > > 7 = float(input('First Number:')) > > > > > > > > > 8 = float(input('Second Number:')) > > > > > > > > > print('Your Final Result is:', 7 / 8) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > print('What type of calculation would you like to do?') > > > > > > > > > Question = input('(Add, Subtract, Divide or Multiply)') > > > > > > > > > if Question.lower().startswith('a'): > > > > > > > > > print(Addition()) > > > > > > > > > elif Question.lower().startswith('s'): > > > > > > > > > print(Subtraction()) > > > > > > > > > elif Question.lower().startswith('d'): > > > > > > > > > print(Division()) > > > > > > > > > elif Question.lower().startswith('m'): > > > > > > > > > print(Multiplication()) > > > > > > > > > else: > > > > > > > > > print('Please Enter The First Letter Of The Type Of > > > > Calculation You Would Like To Use') > > > > > > > > > > > > > > > > > > while Question == 'test': > > > > > > > > > Question() > > > > > > > > > > > > > > > > Sorry, but in fact you did *not* run this program as you claim. It's > > > > > > > > full of syntax errors. Any attempt to run it will display syntax errors > > > > > > > > immediately, and never actually run. So please tell us what really > > > > > > > > happened. > > > > > > > > > > > > > > > > But even without an accurate description of what you did, I can say this: > > > > > > > > > > > > > > > > Lines like > > > > > > > > 1 = float(...) > > > > > > > > don't make sense. It's as if you are trying to change the value of the > > > > > > > > number one, but that's nonsense. > > > > > > > > > > > > > > > > And lines like > > > > > > > > print('Your Final Result is:', 5 * 6) > > > > > > > > had better print out 30 (since that is what 5 times 6 is) but that's > > > > > > > > clearly not what you intended. > > > > > > > > > > > > > > > > Gary Herron > > > > > > excuse me but don't be so *** rude , i did run this program and it did > > run correctly and if you want me to prove it with screenshots so be it , so > > don't make accusations ** Gary ** i only came here for some help not to be > > accused of not even running my program > > > If you can run this, cut and paste the results > > > > > > Charlie :D > > > -- > > > https://mail.python.org/mailman/listinfo/python-list Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> RESTART >>> What type of calculation would you like to do? (Add, Subtract, Divide or Multiply)a Addition: What are two your numbers? First Number:5 Second Number:96 Your Final Result is: 101.0 None >>> -- https://mail.python.org/mailman/listinfo/python-list
Peculiarity of '@' in logging.Formatter
This is what seems like an odd bug, but in code I'd thing often-enough used it must be the expected behavior and I just don't understand. Please, sirs/mesdames, is this a bug? Example code: begin code --- #!/usr/bin/env python """ @-character WTF? """ import sys import os import logging, logging.handlers import socket log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) fmtColon = logging.Formatter('[%(module)s:%(lineno)03d]:%(message)s') strC = logging.handlers.SysLogHandler(address='/dev/log') strC.setFormatter(fmtColon) strC.setLevel(logging.DEBUG) log.addHandler(strC) fmtAt = logging.Formatter('[%(module)s@%(lineno)03d]:%(message)s') strA = logging.handlers.SysLogHandler(address='/dev/log') strA.setFormatter(fmtAt) strA.setLevel(logging.DEBUG) log.addHandler(strA) log.info("My log message:isn't it special?") end code produces these entries in the syslog messages: begin results -- Nov 21 16:09:56 crmartin [atSign: 026]:My log message:isn't it special? Nov 21 16:09:56 crmartin [atSign@026]: My log message:isn't it special? end results Observe: * in the first entry, "[atSign: 026]:My" with space after the first ":"; that space isn't in the format string. * in the second entry "[atSign@026]: My" again has an additional space after the first ":" the colons following are unchanged. This **seems** like it must be some obscure bug, but perhaps it's some undocumented feature? -- http://mail.python.org/mailman/listinfo/python-list
Re: Peculiarity of '@' in logging.Formatter
Oops, forgot the python version etc: bash $ /usr/bin/env python -V Python 2.7 On SuSE 11.4 bash $ uname -a Linux crmartin 2.6.37.6-0.9-desktop #1 SMP PREEMPT 2011-10-19 22:33:27 +0200 x86_64 x86_64 x86_64 GNU/Linux -- http://mail.python.org/mailman/listinfo/python-list
Is this a bug? Python intermittently stops dead for seconds
Below is a simple program that will cause python to intermittently stop executing for a few seconds. it's 100% reproducible on my machine. I'd be tempted to say this is a nasty garbage collection performance issue except that there is no major memory to be garbage collected in this script. I'd be tempted to say it was a unix virtual memory issue except this is occuring at around 1/5th of my physical memory size. So something else unexplained is going on Class Foo instances create and hold a list of size nfoo of integers. (nfoo =10) Class Bar instances create and hold a list of size nbar of Foo objects. (nbar =100) When the code runs it starts creating and storing Bar objects in a list while watching for real-time glitches in how long it takes to create the next Foo object. If this is longer than 1/2 of a second then it reports it. On my computer after creating 1500 Bar objects, the rate of creation of new Foo suddenly has a periodic glitch. This glitch re- occurs about every 300 Bar Objects, and the duration of the glitch keeps getting longer--growing to many seconds Platform: 800Mhz powermac g 4 1Gb of memory python: python 2.4.2 Note: since I an using absolute time threshold for reporting the glitches, the first one may take more iterations before it occurs on a fast computer. You may need to increase nbar or nfoo. import sys from time import time class Foo(object): def __init__(me,nfoo): me.memory = [1]*nfoo class Bar(object): def __init__(me,nbar,nfoo): tgx.set_tag("Bar") # timer b = [None]*nbar for i in xrange(nbar): b[i]=Foo(nfoo) # make a foo, add it to list tgx.jump("Bar"+`i`) #timer me.b = b #store the list in my instance memory # just a utility class to time things. class gtime: def __init__(me,f=sys.stderr): me.last = time() me.f=f me.tag = "" me.ticks = 0 def set_tag(me,tag): me.tag = tag me.ticks = 0 def reset(me): me.ticks = 0 def jump(me,tag="NONE",allowed_gap=0.5): me.t = time() me.ticks +=1 if me.t-me.last>allowed_gap: print >>me.f,"Big Gap:",me.t-me.last,"seconds ",me.tag,tag,me.ticks me.last = time() tgx = gtime() # instance of the timer # main loop nbar = 100 nfoo = 10 ad_nauseum = 2 final = [None]*ad_nauseum for i in xrange(ad_nauseum ): if i%100 == 0 :print >>sys.stderr,"Bars Made: ",i final[i] = Bar(nbar,nfoo) sample Output: Bars Made: 0 Bars Made: 100 Bars Made: 200 Bars Made: 300 Bars Made: 400 Bars Made: 500 Bars Made: 600 Bars Made: 700 Bars Made: 800 Bars Made: 900 Bars Made: 1000 Bars Made: 1100 Bars Made: 1200 Bars Made: 1300 Bars Made: 1400 Bars Made: 1500 Big Gap: 0.618862867355 secondsBar Bar5 6 Bars Made: 1600 Bars Made: 1700 Bars Made: 1800 Big Gap: 0.748915195465 secondsBar Bar76 77 Bars Made: 1900 Bars Made: 2000 Bars Made: 2100 Big Gap: 0.809149980545 secondsBar Bar45 46 Bars Made: 2200 Bars Made: 2300 Bars Made: 2400 Big Gap: 0.898494958878 secondsBar Bar15 16 Bars Made: 2500 Bars Made: 2600 Bars Made: 2700 Big Gap: 1.01110696793 secondsBar Bar86 87 Bars Made: 2800 Bars Made: 2900 Bars Made: 3000 Big Gap: 1.12396192551 secondsBar Bar55 56 Bars Made: 3100 Bars Made: 3200 Bars Made: 3300 Big Gap: 1.39006495476 secondsBar Bar25 26 Bars Made: 3400 Bars Made: 3500 Bars Made: 3600 Big Gap: 1.55699706078 secondsBar Bar96 97 Bars Made: 3700 Bars Made: 3800 Bars Made: 3900 Big Gap: 1.49929594994 secondsBar Bar65 66 Bars Made: 4000 Bars Made: 4100 Bars Made: 4200 Big Gap: 1.64840602875 secondsBar Bar35 36 Bars Made: 4300 Bars Made: 4400 Bars Made: 4500 Big Gap: 1.728484869 secondsBar Bar5 6 Bars Made: 4600 Bars Made: 4700 Bars Made: 4800 -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Steve and other good folks who replied: I want to clarify that, on my computer, the first instance of the gap occurs way before the memory if filled. (at about 20% of physical ram). Additionally the process monitor shows no page faults. Yes if you let the as-written demo program run to completetion (all 20,000 iterations) then on many computers it would not be surprising that your computer eventually goes into forced page swapping at some point. That would be expected and is not the issue than the one I am concerned with. in my case starts glicthing at around iteration 1000. 1000(bars) x 100(foos)x(10 integers in array) is nominally 100,000 class objects and 1,000,000 array elements. (note that the array if filled as [1]*10, so there is actually only one "integer", but 10 array elements refering to it, per foo class.) However steve may have put his finger on the reason why the duration grows with time. Here is my current hypothesis. The design of the program does not have and points where significant amounts of memory are released: all objects have held references till the end. But prehaps there are some implicitly created objects of the same size created along the way??? For example when I write me.memory = [1]*nfoo perhaps internally, python is allocating an array of size foo and then __copying__ it into me.memory??? Since there is no reference to the intermediate it would then marked for future garbage collection. If that were true then the memory would have interleaved entities of things to GC and things with references held in me.memory. Then to remove these would require GC to scan the entire set of existing objects, which is growing. Turning off GC would prevent this. In any case I don't think what I'm doing is very unusual. The original program that trigger my investigation of the bug was doing this: foo was an election ballot holding 10 outcomes, and bar was a set of 100 ballots from 100 voting machines, and the total array was holding the ballot sets from a few thousand voting machines. Almost any inventory program is likely to have such a simmilar set of nested array, so it hardly seems unusual. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
By the way if you are on a fast computer, and an OS whose time.time() function can resolve less than 0.5 seconds then you can see this problem on your machine at lower memory utilizations by changing the value of the default "allowed_gap" in the gtime class from 0.5 seconds down to say 0.1 second. This is the threshold for which the computer program flags the time it takes to create a "foo" object. on a fast computer it should take much less than 0.1 sec. -Original Message- >From: charlie strauss <[EMAIL PROTECTED]> >Sent: Oct 1, 2006 10:33 AM >To: Steve Holden <[EMAIL PROTECTED]>, python-list@python.org >Subject: Re: Is this a bug? Python intermittently stops dead for seconds > >Steve and other good folks who replied: > >I want to clarify that, on my computer, the first instance of the gap occurs >way before the memory if filled. (at about 20% of physical ram). Additionally >the process monitor shows no page faults. > > Yes if you let the as-written demo program run to completetion (all 20,000 > iterations) then on many computers it would not be surprising that your > computer eventually goes into forced page swapping at some point. That would > be expected and is not the issue than the one I am concerned with. > >in my case starts glicthing at around iteration 1000. > >1000(bars) x 100(foos)x(10 integers in array) > >is nominally >100,000 class objects and >1,000,000 array elements. > >(note that the array if filled as [1]*10, so there is actually only one >"integer", but 10 array elements refering to it, per foo class.) > > >However steve may have put his finger on the reason why the duration grows >with time. Here is my current hypothesis. The design of the program does not >have and points where significant amounts of memory are released: all objects >have held references till the end. But prehaps there are some implicitly >created objects of the same size created along the way??? For example when I >write > >me.memory = [1]*nfoo > >perhaps internally, python is allocating an array of size foo and then >__copying__ it into me.memory??? Since there is no reference to the >intermediate it would then marked for future garbage collection. > >If that were true then the memory would have interleaved entities of things to >GC and things with references held in me.memory. > >Then to remove these would require GC to scan the entire set of existing >objects, which is growing. > >Turning off GC would prevent this. > > >In any case I don't think what I'm doing is very unusual. The original >program that trigger my investigation of the bug was doing this: > >foo was an election ballot holding 10 outcomes, and bar was a set of 100 >ballots from 100 voting machines, and the total array was holding the ballot >sets from a few thousand voting machines. > >Almost any inventory program is likely to have such a simmilar set of nested >array, so it hardly seems unusual. > > > > > >-- >http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
>> >I think the point you are missing is that the garbage collector is >triggered from time to time to ensure that no cyclical garbage remains >uncollected, IIRC. The more data that's been allocated, the longer it >takes the collector to scan all of memory to do its job. > >If you can find a way to avoid the behaviour I'm sure the development >team would be interested to hear it :-) > >I think you'll find that most programs that eat through memory in this >way will exhibit pretty much the same behaviour. If you *know* your >program isn't creating data cycles, just turn the GC off and rely on >reference counting. That won't save you from paging when you eventually >exhaust physical memory. Nothing can. Could you clarify that for me. GC really has three components two it: 1) finding and freeing unrefernced memory by refer counts 2) cycle removal and 3) defragementing the storage stack. If I turn off GC, don't I lose all of these? >From a user perspective, turning off GC and then managing it yourself is >unappealing. What would be preferrable would be to be able to simply turn >down it's threshold. That is, what I really want is to tell GC it can hold >off and checks other than reference counts until X% of the memory is filled. >At some point I want it to kick in, and I don't want to have to >programatically manage that, but simply specify a simple tolerance. Even better , I'd like to keep 1 and 3 and turn off just 2 and just use weak reference in the few cases I really need them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
Steve, digging into the gc docs a bit more, I think the behaviour I am seeing is still not expected. Namely, the program I offered has no obvious place where objects are deallocated. The way GC is supposed to work is thate there are three levels of objects level0: newly created objects level1: objects that survived 1 round of garbage collection level2: objects that survivied 2+ rounds of gargbage collection Since all of my numerous objects are level2 objects, and none of them are every deallocated, then I should never trip the GC for these. Your explanation would require this to be tripped so I can't explain it. For your explanation to be correct then there as to be some non-obvious step in the program that is deallocating level2 items in sufficient numbers to trip the GC. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a bug? Python intermittently stops dead for seconds
On Oct 1, 2006, at 9:48 AM, Fredrik Lundh wrote: > charlie strauss wrote: > >> level0: newly created objects >> level1: objects that survived 1 round of garbage collection >> level2: objects that survivied 2+ rounds of gargbage collection >> >> Since all of my numerous objects are level2 objects, and none of >> them are every deallocated, then I should never trip the GC for >> these. > > your understanding of generational GC is a bit fuzzy, it seems. > that an > object is promoted to a higher level means that it's not inspected > quite > as often as lower-level objects, not that it's never inspected at all. As I understand it, level2 (and level1) objects only undergo gc when more than 10 of them is deallocated. Since I never deallocate, this should not be tripped right? In any case regarding your other comments: >> Could you clarify that for me. GC really has three components >> two it: 1) finding and freeing unrefernced memory by refer >> refer counts 2) cycle removal and 3) defragementing the >> storage stack. If I turn off GC, don't I lose all of these? >> > > CPython always does (1), only does (2) if cycle-breaking GC isn't > disabled, and never does (3). Never does 3? then how does it compact it's memory allocation area? Surely it does not rely on the OS to manage every small object as a separate memory allocation. And just to be clear: are you saying that when I do a gc.disable this only turns off 2 and not 1? The docs don't say that as far as I can tell. > in your case, it's (2) that takes more and more time, simply because > you're creating tons of non-trivial objects. to see what's going > on in > there, add > > import gc > gc.set_debug(gc.DEBUG_STATS) > > to the top of your program, and look at the status messages that > appear > just before each "Big Gap" message. Could you be a bit more explicit. I'm new to the gc module. Sorry to be slow but I don't know what "looking at the status message" means. > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python on mac - can't extend interpreter with "catch_exception_raise" wrapper.
Hi. I've run into a very strange problem with Python on the mac. I'm trying to write a python script which will monitor an application for exceptions. It turns out on a mac, to do this you want to use the Mach IPC interface, see: http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/ http://www.wodeveloper.com/omniLists/macosx-dev/2000/June/msg00137.html Once set up, you call the mach function exc_server which then calls "catch_raise_exception" which you provide. This works great in C, so I thought I'd wrap it for python. But, it turns out the python interpreter already has a symbol named "catch_raise_exception", (in my case at 0x2030 under gdb). The problem is when exc_server calls catch_raise_exception it calls the one from the python binary and not the one I provided and dies. Does anyone have any ideas on how to deal with this perplexing problem?!? Thanks!!! Charlie -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
That hardware battle was fought long ago. Von Neumann machine vs. the Lisp machine. Guess who won? http://en.wikipedia.org/wiki/Lisp_machine It would be very hard to fight that war all over again. Charlie On Fri, Jun 6, 2008 at 4:59 PM, Jan Claeys <[EMAIL PROTECTED]> wrote: > Op Fri, 23 May 2008 14:00:33 -0700, schreef [EMAIL PROTECTED]: > > > Now this I can tell is false. The problem is not that it's difficult to > > "make a native compiler for" dynamic languages, the problem is that it's > > difficult to write native compiler for dynamic languages that generates > > code that beats the VM/byte-code interpreter/whatever you name it to be > > wotrh the effort. > > Well, it would be much easier if there would be hardware that was > designed for object oriented & dynamic programming... ;-) > > (Most current hardware is designed for use with C & similar languages, or > sometimes for massively parrallel computing (e.g. GPUs), but the last > tries to design hardware to fit something like Python date back to the > 1980s AFAIK...) > > > -- > JanC > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
a questions about thread-safety of boolean variables
Hi,if I have a class A that contains a boolean variable named x, is it safe to read and change it from different threads without using locks? Is it guaranteed that A.x will be always True or False, and not any other weird value that that causes it to be inconsistent (assuming I only set it to True or False) ? I have a = A() first thread does: if a.x is True : pass 2nd thread does: a.x = False is it safe? and what if x was a dict ? especially if the only values that are set in the dictionary are simple: booleans, integers, floats, strings -- http://mail.python.org/mailman/listinfo/python-list
Re: a questions about thread-safety of boolean variables
What about dictionaries? Reading values, adding new ones and the most important: changing an existing value - can it corrupt the state of the dictionary or that it is guaranteed that if I try to read the value of this key, I can only get the old one or the new one, but not something weird instead (because a different thread changed the value while this thread was trying to read it). About your remark that I don't need to check if a.x is True, I do need, and indeed it is acceptable that doSomething() will run, because this logic resides inside a loop, and it is only important for me that it will stop entering the loop sometime (I don't care if there are n iterations or n+1 or even n+m) Thanks On Wed, Sep 30, 2009 at 10:44 AM, steve wrote: > Hi, > > On 09/30/2009 01:53 PM, Charlie Dickens wrote: > >> Hi, >> if I have a class A that contains a boolean variable named x, is it safe >> to read and change it from different threads without using locks? >> Is it guaranteed that A.x will be always True or False, and not any >> other weird value that that causes it to be inconsistent (assuming I >> only set it to True or False) ? >> >> The guarantee for A.x being only True or False, is independent of whether > you use locks or not. It depends entirely on code that assigns to A.x. > > I have a = A() >> first thread does: >> if a.x is True : >> pass >> >> 2nd thread does: >> a.x = False >> >> is it safe? >> > > what if you have code like this: > > Thread 1 > if a.x is True: >doSomething() > > Thread 2 > a.x == False > > ..and thread 2 executes *after* thread 1's 'if' condition but *before* > doSomething(). If that behavior is acceptable in your application, you > possibly don't even need a.x. > > >> and what if x was a dict ? especially if the only values that are set in >> the dictionary are simple: booleans, integers, floats, strings >> >> Same logic applies. > > hth, > cheers, > - steve > > -- > random non tech spiel: http://lonetwin.blogspot.com/ > tech randomness: http://lonehacks.blogspot.com/ > what i'm stumbling into: http://lonetwin.stumbleupon.com/ > -- http://mail.python.org/mailman/listinfo/python-list