Search Results

Search found 14007 results on 561 pages for 'python embedding'.

Page 24/561 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Programming in python Vs programming in Java

    - by yossale
    I've been writing Java for the last couple of years , and now I've started to write in python (in addition). The problem is that when I look at my Python code it looks like someone tried to hammer Java code into a python format , and it comes out crappy because - well , python ain't Java. Any tips on how to escape this pattern of "Writing Java in Python"? Thanks!

    Read the article

  • What's the meaning of “Monty Python’s Flying Circus” phrase on Python?

    - by Zignd
    I just started studying Python using the Python 3.2 Tutorial and on the introduction is written: By the way, the language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged! But I have to say that I did not understood this part: “Monty Python’s Flying Circus”, I'm Brazilian and even Google Translator don't know how to answer it. Can someone explain me this phrase?

    Read the article

  • best way to deal with python pdb flakiness re/stdout?

    - by YGA
    I love python and hate the pdb debugger. For instance, if I have a program where stdout is redirected, my pdb prompts all go to the redirection, because the library was written to write to stdout. Oftentimes this problem is subtle, causing me to think a program is hanging when it's really waiting for input. How do people work around this? (Unfortunately, using other debuggers like winpdb is not an option). Thanks, /YGA

    Read the article

  • Unit testing in python?

    - by yossi.ittach
    Hey - I'm new to python , and I'm having a hard time grasping the concept of Unit testing in python. I'm coming from Java - so unit testing makes sense because - well , there you actually have a unit - A Class. But a Python class is not necessarily the same as a Java class , and the way I use Python - as a scripting language - is more functional then OOP - So what do you "unit test" in Python ? A flow? Thanks!

    Read the article

  • Easiest way to automatically download required modules in Python?

    - by user248237
    I would like to release a python module I wrote which depends on several packages. What's the easiest way to make it so these packages are programmatically downloaded just in case they are not available on the system that's being run? Most of these modules should be available by easy_install or pip or something like that. I simply want to avoid having the user install each module separately. thanks.

    Read the article

  • Where can I find a large body of *Python3* source code?

    - by Ira Baxter
    I'm testing a Python parser. I have Python 2.6/2.7 firmly under control, and some good (large) code samples on which I've tested it. I'm interested in testing my Python3 variant. I've been to various Python open source web sites (e.g., http://pythonsource.com/), which list lots of packages, but they are pretty unclear as whether these are Python 2.x vs 3.x source files. The several samples that I downloaded all turned out to be Python 2.x. Where can I find a number of large Python 3 software source codes? I don't really want 1000 little separate Python3 files; I prefer big applications.

    Read the article

  • How to write a Python 2.6+ script that does gracefully fail with older pyhton?

    - by Sorin Sbarnea
    I'm using the new print from Python 3.x and I observed that the following code does not compile due to the end=' '. from __future__ import print_function import sys if sys.hexversion < 0x02060000: raise Exception("py too old") ... print("x",end=" ") # fails to compile with py24 How can I continue using the new syntax but make the script fails nicely? Is it mandatory to call another script and use only safe syntax in this one?

    Read the article

  • python mock patch : a method of instance is called?

    - by JuanPablo
    In python 2.7, I have this function from slacker import Slacker def post_message(token, channel, message): channel = '#{}'.format(channel) slack = Slacker(token) slack.chat.post_message(channel, message) with mock and patch, I can check that the token is used in Slacker class import unittest from mock import patch from slacker_cli import post_message class TestMessage(unittest.TestCase): @patch('slacker_cli.Slacker') def test_post_message_use_token(self, mock_slacker): token = 'aaa' channel = 'channel_name' message = 'message string' post_message(token, channel, message) mock_slacker.assert_called_with(token) how I can check the string use in post_message ? I try with mock_slacker.chat.post_message.assert_called_with('#channel') but I get AssertionError: Expected call: post_message('#channel') Not called

    Read the article

  • call a python function in another class from a class?

    - by user3527697
    hi i'am begginer in pYthon and openerp , i want to call a function exists in another class for example: i have 2 class : class a: def notif_personne_event(self, cr, uid,ids,context=None): and import a class b: notifier(self, cr, uid,ids,context=None): self.notifiernotif_personne_event() but when i do this an error is displayed telling me that class b have not an attribute notifiernotif_personne_event() someone help me please

    Read the article

  • Install gettext-0.17-1.el5.i386.rpm on CentOS 5.8 i386 gives "/usr/bin/python is needed" error

    - by viji
    I've removed yum by mistake. So, now I'm installing all the dependencies needed by yum manually. One of those is gettext-0.17-1.el5.i386.rpm and when I try to install it gives the following error, error: Failed dependencies: /usr/bin/python is needed by gettext-0.17-1.el5.i386 which is weird since I've installed python 2.6 already in the system. #python -V Python 2.6.8 #which python /usr/local/bin/python So I copied /usr/local/bin/python to /usr/bin/python and even after that I'm getting the same error. Any help is appreciated.

    Read the article

  • How to compile Python scripts for use in FORTRAN?

    - by Vincent Poirier
    Hello, Although I found many answers and discussions about this question, I am unable to find a solution particular to my situation. Here it is: I have a main program written in FORTRAN. I have been given a set of python scripts that are very useful. My goal is to access these python scripts from my main FORTRAN program. Currently, I simply call the scripts from FORTRAN as such: CALL SYSTEM ('python pyexample.py') Data is read from .dat files and written to .dat files. This is how the python scripts and the main FORTRAN program communicate to each other. I am currently running my code on my local machine. I have python installed with numpy, scipy, etc. My problem: The code needs to run on a remote server. For strictly FORTRAN code, I compile the code locally and send the executable to the server where it waits in a queue. However, the server does not have python installed. The server is being used as a number crunching station between universities and industry. Installing python along with the necessary modules on the server is not an option. This means that my “CALL SYSTEM ('python pyexample.py')” strategy no longer works. Solution?: I found some information on a couple of things in thread http://stackoverflow.com/questions/138521/is-it-feasible-to-compile-python-to-machine-code Shedskin, Psyco, Cython, Pypy, Cpython API These “modules”(? Not sure if that's what to call them) seem to compile python script to C code or C++. Apparently not all python features can be translated to C. As well, some of these appear to be experimental. Is it possible to compile my python scripts with my FORTRAN code? There exists f2py which converts FORTRAN code to python, but it doesn't work the other way around. Any help would be greatly appreciated. Thank you for your time. Vincent PS: I'm using python 2.6 on Ubuntu

    Read the article

  • Language Club – Battle of the Dynamic Languages

    - by Ben Griswold
    After dedicating the last eight weeks to learning Ruby, it’s time to move onto another language.  I really dig Ruby.  I really enjoy its dynamism and expressiveness and always-openness and it’s been the highlight of our coding club for me so far. But that’s just my take on the language.  I know a lot of coders who’s stomachs turn with the mere thought of Ruby.  They say it’s Ruby’s openness which has them feeling uneasy.  I’d say “write a bunch of tests and get over it,” but I figure there must be more to it than always open classes and possible method collisions. Yes, there’s something else to it alright. The folks who didn’t fall head over heals for Ruby are already in love with Python.  You might remember that Python was the first language we tackled in our coding club.  My time with Python was okay but it didn’t feel as natural to me as Ruby.  But let’s say we started with Ruby and then moved onto Python.  Would I see Python in a different light right now.  Might I even prefer Python over Ruby?  I suppose it’s possible but it’s pretty tough to test that theory – unless we visit Python for a second time. That’s right. The language club is going to focus on Python again and in my attempt to learn Python – yet again – in the open, I’ll be posting my solutions here just as I did for Ruby.  We don’t always have second chances so I going about this relearning with two primary goals in mind:  First, I’m going to use IronPython and the IronPython tools which provide a Python code editor, a file-based project system, and an interactive Python interpreter, all inside Visual Studio 2010.  As a note, the IronPython tools are now part of the main IronPython installer which is Version 2.7 Alpha 1 (not the latest stable version, 2.6.1) and I’d be crazy not to use them.  Second, I’d like to make sure I’m still learning Python without a complete MS skew so I’m going to run my code through Eclipse using the PyDev plugin as well.  Heck, I might use IDLE too. I already have this setup on my machine so it’s no big deal. Okay, that’s it for now.  I worked on the first ten Euler problems last night and the solutions will be posted shortly. Wish me luck.

    Read the article

  • How to open python scripts directly by typing in their name in terminal (Mac OS X)

    - by Haffi112
    I'm working on installing django and running it on my system. I have a problem though, in this tutorial creating a project is explained by running the command django-admin.py startproject mysite My issue is that this doesn't work. I changed to the directory where django-admin.py is located and ran the command chmod +x django-admin.py with no results. I tried adding the directory with the file to my path without results. I ended up fixing my problem with this command python /location/of/django-admin.py startproject mysite which yielded the outcome I expected. My problem is: What do I need to change/configure such that command django-admin.py startproject mysite would be sufficient? Here are some experiments: 21:09~/Desktop/HI/NSN/Polls > django-admin.py startproject mysite -bash: django-admin.py: command not found 21:09~/Desktop/HI/NSN/Polls > ./django-admin.py startproject mysite -bash: ./django-admin.py: No such file or directory 21:09~/Desktop/HI/NSN/Polls > python django-admin.py startproject mysite python: can't open file 'django-admin.py': [Errno 2] No such file or directory 21:09~/Desktop/HI/NSN/Polls > /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py startproject prufa1 -bash: /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py: /opt/local/bin: bad interpreter: Permission denied 21:09~/Desktop/HI/NSN/Polls > sudo /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py startproject prufa1Password: sudo: unable to execute /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py: Permission denied 21:09~/Desktop/HI/NSN/Polls > sudo /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py startproject prufa1sudo: unable to execute /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py: Permission denied 21:09~/Desktop/HI/NSN/Polls > python /opt/local/lib/python2.4/site-packages/django/bin/django-admin.py startproject prufa1 21:09~/Desktop/HI/NSN/Polls > ls mysite prufa1 Final edit: The problem is solved, see Ian C's answer for the right solution. Thank you everyone for helping my out, this was very fast!

    Read the article

  • Broken package ubuntuone-control-panel-qt

    - by baale7
    An interrupted installation of updates resulted in ubuntuone-control-panel-qt breaking and now I cannot install or update anything. There seems to be an error in python2.7 - ImportError: No module named _sysconfigdata_nd dpkg: error processing archive ubuntuone-control-panel-qt_13.09-0ubuntu1_all.deb (--install): When I try to reinstall the package via .deb a dpkg --audit yields: The following packages are in a mess due to serious problems during installation. They must be reinstalled for them (and any packages that depend on them) to function properly: ?python-pexpect Python module for automating interactive applications ?ubuntuone-control-panel-qt Ubuntu One Control Panel - Qt frontend ?hplip-data HP Linux Printing and Imaging - data files ?python-libxml2 Python bindings for the GNOME XML library ?apport automatically generate crash reports for debugging The following packages are only half configured, probably due to problems configuring them the first time. The configuration should be retried using dpkg --configure or the configure menu option in dselect: ?python-ubuntuone-client Ubuntu One client Python libraries ?python-ubuntuone-control-panel Ubuntu One Control Panel - Python Libraries --configure or --configure -a doesn't work Any help?

    Read the article

  • How to add "create a new python file" to the registry

    - by Anthony
    I have Python 3.2 on a windows 7 operating system. The other day I thought that it would be convenient to add a link to create a new .py file in the right hand click "new" menu. I had worked with the registry before and looked up how to add an item to the "new" menu, but when I got to the registry under HKEY_CLASSES_ROOT the .py extension key was not there. I only know how to add something to the "new" menu using the extension key. I searched the web, but could not come up with any other ways. Python works perfectly fine, and I don't want to mess anything up by adding the extension key. So here are my questions: Will I mess up python or something else by adding a .py key?( I know it is dangerous to work with the registry, that is why I am looking for a safe solution) If not how can I go about doing this? OR Is there a different way to add "create a new python file" to the "new" menu? If so how can I do it? OR If the only way is very complicated should I forget about it? Thank you in advance. P.S I originally posted on Stack Overflow that they told me to move it over here.

    Read the article

  • A business Case for Enterprise Python

    - by Srirangan
    Hi all, This will not be a "programming" question but more technology / platform related question. I'm trying to figure out whether Python can be a suitable Java alternative for enterprise / web applications. Which are the ideal cases where you would prefer to use Python instead of Java? How would a typical Python web application (databases/sessions/concurrency) perform as compared to a typical Java application? How do specific Python frameworks square up against Java based frameworks (Spring, SEAM, Grails etc.)? For businesses, switching from the Java infrastructure to a Python infrastructure .. is it too hard/expensive/resource intensive/not viable? Also shed some light on the business case for providing a Python + Google AppEngine based solution to the end customer. Will it be cost effective in an typical scenario? Sorry if I am asking too wide a question, I would have liked to keep it specific, but I need your help to evaluate Python as a whole from the perspectives of the programmers, service providing company and end business customer. For an SME, a Python/GoogleAppEngine based technology stack is a clear scalable and affordable platform. But what about a large MNC that already has a lot invested in Java. Thank you so much. I am researching this myself and will gladly share my conclusions here! Thank you, Srirangan

    Read the article

  • instantiate python object within a c function called via ctypes

    - by gwk
    My embedded Python 3.3 program segfaults when I instantiate python objects from a c function called by ctypes. After setting up the interpreter, I can successfully instantiate a python Int (as well as a custom c extension type) from c main: #import <Python/Python.h> #define LOGPY(x) \ { fprintf(stderr, "%s: ", #x); PyObject_Print((PyObject*)(x), stderr, 0); fputc('\n', stderr); } // c function to be called from python script via ctypes. void instantiate() { PyObject* instance = PyObject_CallObject((PyObject*)&PyLong_Type, NULL); LOGPY(instance); } int main(int argc, char* argv[]) { Py_Initialize(); instantiate(); // works fine // run a script that calls instantiate() via ctypes. FILE* scriptFile = fopen("emb.py", "r"); if (!scriptFile) { fprintf(stderr, "ERROR: cannot open script file\n"); return 1; } PyRun_SimpleFileEx(scriptFile, scriptPath, 1); // close on completion return 0; } I then run a python script using PyRun_SimpleFileEx. It appears to run just fine, but when it calls instantiate() via ctypes, the program segfaults inside PyObject_CallObject: import ctypes as ct dy = ct.CDLL('./emb') dy.instantiate() # segfaults lldb output: instance: 0 Process 52068 stopped * thread #1: tid = 0x1c03, 0x000000010000d3f5 Python`PyObject_Call + 69, stop reason = EXC_BAD_ACCESS (code=1, address=0x18) frame #0: 0x000000010000d3f5 Python`PyObject_Call + 69 Python`PyObject_Call + 69: -> 0x10000d3f5: movl 24(%rax), %edx 0x10000d3f8: incl %edx 0x10000d3fa: movl %edx, 24(%rax) 0x10000d3fd: leaq 2069148(%rip), %rax ; _Py_CheckRecursionLimit (lldb) bt * thread #1: tid = 0x1c03, 0x000000010000d3f5 Python`PyObject_Call + 69, stop reason = EXC_BAD_ACCESS (code=1, address=0x18) frame #0: 0x000000010000d3f5 Python`PyObject_Call + 69 frame #1: 0x00000001000d5197 Python`PyEval_CallObjectWithKeywords + 87 frame #2: 0x0000000201100d8e emb`instantiate + 30 at emb.c:9 Why does the call to instantiate() fail from ctypes only? The function only crashes when it calls into the python lib, so perhaps some interpreter state is getting munged by the ctypes FFI call?

    Read the article

  • Python: Best way to check for Python version in program that uses new language features?

    - by Mark Harrison
    If I have a python script that requires at least a particular version of python, what is the correct way to fail gracefully when an earlier version of python is used to launch the script? How do I get control early enough to issue an error message and exit? For example, I have a program that uses the ternery operator (new in 2.5) and "with" blocks (new in 2.6). I wrote a simple little interpreter-version checker routine which is the first thing the script would call ... except it doesn't get that far. Instead, the script fails during python compilation, before my routines are even called. Thus the user of the script sees some very obscure synax error tracebacks - which pretty much require an expert to deduce that it is simply the case of running the wrong version of python. update I know how to check the version of python. The issue is that some syntax is illegal in older versions of python. Consider this program: import sys if sys.version_info < (2, 4): raise "must use python 2.5 or greater" else: # syntax error in 2.4, ok in 2.5 x = 1 if True else 2 print x When run under 2.4, I want this result $ ~/bin/python2.4 tern.py must use python2.5 or greater and not this result: $ ~/bin/python2.4 tern.py File "tern.py", line 5 x = 1 if True else 2 ^ SyntaxError: invalid syntax (channeling for a coworker)

    Read the article

  • emacs: Inferior-mode python-shell appears "lagged"

    - by Begbie00
    Hi all - I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here. Relevant code is pasted below the question. Question: when I click the Hello button (which should call the say_hi function) why does the inferior python shell (i.e. the one I kicked off with C-c C-c) wait to execute the say_hi print function until I either a) click the Quit button or b) close the root widget down? When I try the same in IDLE, each click of the Hello button produces an immediate print in the IDLE python shell, even before I click Quit or close the root widget. Is there some quirk in the way emacs runs the Python shell (vs. IDLE) that causes this "lagged" behavior? I've noticed similar emacs lags vs. IDLE as I've worked through Project Euler problems, but this is the clearest example I've seen yet. FYI: I use python.el and have a relatively clean init.el... (setq python-python-command "d:/bin/python31/python") is the only line in my init.el. Thanks, Mike === Begin Code=== from tkinter import * class App: def __init__(self,master): frame = Frame(master) frame.pack() self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) self.hi_there = Button(frame, text="Hello", command=self.say_hi) self.hi_there.pack(side=LEFT) def say_hi(self): print("hi there, everyone!") root = Tk() app = App(root) root.mainloop()

    Read the article

  • Python C API from C++ app - know when to lock

    - by Alex
    Hi Everyone, I am trying to write a C++ class that calls Python methods of a class that does some I/O operations (file, stdout) at once. The problem I have ran into is that my class is called from different threads: sometimes main thread, sometimes different others. Obviously I tried to apply the approach for Python calls in multi-threaded native applications. Basically everything starts from PyEval_AcquireLock and PyEval_ReleaseLock or just global locks. According to the documentation here when a thread is already locked a deadlock ensues. When my class is called from the main thread or other one that blocks Python execution I have a deadlock. Python Cfunc1() - C++ func that creates threads internally which lead to calls in "my class", It stuck on PyEval_AcquireLock, obviously the Python is already locked, i.e. waiting for C++ Cfunc1 call to complete... It completes fine if I omit those locks. Also it completes fine when Python interpreter is ready for the next user command, i.e. when thread is calling funcs in the background - not inside of a native call I am looking for a workaround. I need to distinguish whether or not the global lock is allowed, i.e. Python is not locked and ready to receive the next command... I tried PyGIL_Ensure, unfortunately I see hang. Any known API or solution for this ? (Python 2.4)

    Read the article

  • Runing bcdedit from python in Windows 2008 SP2

    - by Lee-Man
    I do not know windows well, so that may explain my dilemma ... I am trying to run bcdedit in Windows 2008R2 from Python 2.6. My Python routine to run a command looks like this: def run_program(cmd_str): """Run the specified command, returning its output as an array of lines""" dprint("run_program(%s): entering" % cmd_str) cmd_args = cmd_str.split() subproc = subprocess.Popen(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) (outf, errf) = (subproc.stdout, subproc.stderr) olines = outf.readlines() elines = errf.readlines() if Options.debug: if elines: dprint('Error output:') for line in elines: dprint(line.rstrip()) if olines: dprint('Normal output:') for line in olines: dprint(line.rstrip()) errf.close() outf.close() res = subproc.wait() dprint('wait result=', res) return (res, olines) I call this function thusly: (res, o) = run_program('bcdedit /set {current} MSI forcedisable') This command works when I type it from a cmd window, and it works when I put it in a batch file and run it from a command window (as Administrator, of course). But when I run it from Python (as Administrator), Python claims it can't find the command, returning: bcdedit is not recognized as an internal or external command, operable program or batch file Also, if I trying running my batch file from Python (which works from the command line), it also fails. I've also tried it with the full path to bcdedit, with the same results. What is it about calling bcdedit from Python that makes it not found? Note that I can call other EXE files from Python, so I have some level of confidence that my Python code is sane ... but who knows. Any help would be most appreciated.

    Read the article

  • Passing C++ object to C++ code through Python?

    - by cornail
    Hi all, I have written some physics simulation code in C++ and parsing the input text files is a bottleneck of it. As one of the input parameters, the user has to specify a math function which will be evaluated many times at run-time. The C++ code has some pre-defined function classes for this (they are actually quite complex on the math side) and some limited parsing capability but I am not satisfied with this construction at all. What I need is that both the algorithm and the function evaluation remain speedy, so it is advantageous to keep them both as compiled code (and preferrably, the math functions as C++ function objects). However I thought of glueing the whole simulation together with Python: the user could specify the input parameters in a Python script, while also implementing storage, visualization of the results (matplotlib) and GUI, too, in Python. I know that most of the time, exposing C++ classes can be done, e.g. with SWIG but I still have a question concerning the parsing of the user defined math function in Python: Is it possible to somehow to construct a C++ function object in Python and pass it to the C++ algorithm? E.g. when I call f = WrappedCPPGaussianFunctionClass(sigma=0.5) WrappedCPPAlgorithm(f) in Python, it would return a pointer to a C++ object which would then be passed to a C++ routine requiring such a pointer, or something similar... (don't ask me about memory management in this case, though :S) The point is that no callback should be made to Python code in the algorithm. Later I would like to extend this example to also do some simple expression parsing on the Python side, such as sum or product of functions, and return some compound, parse-tree like C++ object but let's stay at the basics for now. Sorry for the long post and thx for the suggestions in advance.

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >