Search Results

Search found 13693 results on 548 pages for 'python metaprogramming'.

Page 38/548 | < Previous Page | 34 35 36 37 38 39 40 41 42 43 44 45  | Next Page >

  • How to create an application which embeds and runs Python code without local Python installation?

    - by Robert
    Hello fellow software developers. I want to distribute a program which is scriptable by embedding the Python interpreter. What I don't want is that the user has to install Python first. So I'm looking for a solution where I distribute only the following components: my program executable and its libraries the Python library (dll/so) a ZIP-file containing all necessary Python modules and libraries. How can I accomplish this? Do you have a step-by-step recipe for me? The solution should be suitable for both Windows and Linux. Thanks in advance.

    Read the article

  • Problem in printing array of char pointer passing from Python

    - by Yan Cheng CHEOK
    My following C code works quite well, till my Python code trying to pass an array of char pointer to it. The output I obtain is The file_name is python-file Another 3 string is not being printed out. Anything I had missed out? C Code #include <iostream> #include "c_interface.h" int foo(const char* file_name, const char** names) { std::cout << "The file_name is " << file_name << std::endl; while (*names) { std::cout << "The name is " << *names << std::endl; names++; } return 0; } /* int main() { const char *c[] = {"123gh", "456443432", "789", 0}; foo("hello", c); getchar(); } */ Python Code #!c:/Python27/python.exe -u from ctypes import * name0 = "NAME0" name1 = "NAME1" name2 = "NAME2" names = ((c_char_p * 1024) * 4)() names[0].value = name0 names[1].value = name1 names[2].value = name2 names[3].value = 0 libc = CDLL("foo.dll") libc.foo("python-file", names)

    Read the article

  • Code indentation helper for gedit (python).

    - by aviraldg
    See the little vertical lines? They're damn helpful when writing Python code. Any chance I could get something similar for gedit? I wouldn't mind having to write my own plugin, as long as it's in Python... So: Is there a plugin for this in gedit? If not, would it be possible to write one in Python.

    Read the article

  • Python+Windows+GStreamer = Impossible (for me)?

    - by james
    Hi :) essentially, my problem is, ater a long time searching, finding only this other question, i decided i was just going to ask my own... i am on windows 7 with python 2.6 and ossbuild GStreamer, but i am trying to get the python binding for it, and struggling. i have got gst-python from http://gstreamer.freedesktop.org/src/gst-python/ but as my eyes and research tell me, it does not work in the setup.py way, and the other question has a link to a site that he says has a binary avaiable, which no longer does, http://www.gstreamer-winbuild.ylatuya.es/doku.php?id=download and even the sdk is gone, and ossbuild dont seem to have anything useful either. so essentially, my question is, can anyone tell me a method, however convoluted, of getting my setup so if i write a script for (py)gst, with an import gst it will work? not the best of explanations... im tired k? xxx :)

    Read the article

  • Issue with making python program executable

    - by Sam
    I'm trying to make a program so that I can run it through the command line with the following format: ./myProgram I made it executable and put #!/usr/bin/env python in the header, but it's giving me the following error. env: python\r: No such file or directory However, when I run "python myProgram", it runs fine. Can someone tell me what I'm doing wrong?

    Read the article

  • Want procmail to run a custom python script, everytime a new mail shows up

    - by Maddy
    I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content: :0 * ^To.*@myhost | /usr/bin/python /work/scripts/privilege_emails_forward.py Wherein my custom python script(privilege_emails_forward.py) will be scanning through the email currently received and do some operations on the mail content. But I am unable to get the script getting executed at the first shot(let alone scanning through the mail content). Is this a correct way of invoking an external program(python) as soon as new mail arrives? And how does my python program(privilege_emails_forward.py) will receive the mail as input? I mean as sys.argv or stdin????

    Read the article

  • How do I write an RSpec test to unit-test this interesting metaprogramming code?

    - by Kyle Kaitan
    Here's some simple code that, for each argument specified, will add specific get/set methods named after that argument. If you write attr_option :foo, :bar, then you will see #foo/foo= and #bar/bar= instance methods on Config: module Configurator class Config def initialize() @options = {} end def self.attr_option(*args) args.each do |a| if not self.method_defined?(a) define_method "#{a}" do @options[:"#{a}"] ||= {} end define_method "#{a}=" do |v| @options[:"#{a}"] = v end else throw Exception.new("already have attr_option for #{a}") end end end end end So far, so good. I want to write some RSpec tests to verify this code is actually doing what it's supposed to. But there's a problem! If I invoke attr_option :foo in one of the test methods, that method is now forever defined in Config. So a subsequent test will fail when it shouldn't, because foo is already defined: it "should support a specified option" do c = Configurator::Config c.attr_option :foo # ... end it "should support multiple options" do c = Configurator::Config c.attr_option :foo, :bar, :baz # Error! :foo already defined # by a previous test. # ... end Is there a way I can give each test an anonymous "clone" of the Config class which is independent of the others?

    Read the article

  • Rails Metaprogramming: How to add instance methods at runtime?

    - by Larry K
    I'm defining my own AR class in Rails that will include dynamically created instance methods for user fields 0-9. The user fields are not stored in the db directly, they'll be serialized together since they'll be used infrequently. Is the following the best way to do this? Alternatives? Where should the start up code for adding the methods be called from? class Info < ActiveRecord::Base end # called from an init file to add the instance methods parts = [] (0..9).each do |i| parts.push "def user_field_#{i}" # def user_field_0 parts.push "get_user_fields && @user_fields[#{i}]" parts.push "end" end Info.class_eval parts.join

    Read the article

  • Web hooks in Python: Any particular library?

    - by Gopal
    Hi .. somewhat of a noob here to web programming. Just getting my feet wet in python. I wanted to implement web hooks in python. Both at server end and client end. Is there any particular library for implementing web hooks? Or does django or twisted python handle this?

    Read the article

  • keep open windows console after a python syntax error

    - by basweber
    File associations on my machine (winxp home) are such that a python script is directly opened with the python interpreter. If I double click on a python script a console window runs and every thing is fine - as long as there is no syntax error in the script. In that case the console window opens up for a moment but it is closed immediately. Too fast to read the error message. Of course their would be the possibility to manually open a console window and to execute the script by typing python myscript.py but I am sure that there is a more convenient (i.e. "double click based") solution.

    Read the article

  • python UTF16LE file to UTF8 encoding

    - by Qiao
    I have big file with utf16le (BOM) encoding. Is it possible to convert it to usual UTF8 by python? Something like file_old = open('old.txt', mode='r', encoding='utf_16_le') file_new = open('new.txt', mode='w', encoding='utf-8') text = file_old.read() file_new.write(text.encode('utf-8')) http://docs.python.org/release/2.3/lib/node126.html (-- utf_16_le UTF-16LE) Not working. Can't understand "TypeError: must be str, not bytes" error. python 3

    Read the article

  • Indent guide plugin for gedit (python).

    - by aviraldg
    See the indent guides? They're damn helpful when writing Python code. Any chance I could get something similar for gedit? I wouldn't mind having to write my own plugin, as long as it's in Python... So: Is there a plugin for this which works with gedit? If not, would it be possible to write one in Python.

    Read the article

  • Gathering mac addresses with Python

    - by William
    Hi, is there a good way to gather the mac addresses of machines on a local network using Python. If it helps I'm trying to execute this python script from the DHCP server for the network. I'm new to Python but would it be a bad idea to look at the DHCP leases file for this info? I'd like to use this inside a Django app eventually. Thanks.

    Read the article

  • stting environment variables in powershell by calling python script that prints $env:myVar=myvalue

    - by leeg
    I have some legacy python scripts that manage my shell environment for all the programs and plugins I am running on Linux (bash) and windows (cmd.exe). I want to port this to powershell. How do I set environment variables in powershell by calling python script that prints $env:myVar=myvalue and causes my environment variable to persist in the powershell. In Bash I can use a bash function to call my python script which prints export var=value to stdout and the function will set the environment variables in my shell. This will also work in windows cmd shell by calling a .bat file. I cannot figure out how to do this in powershell. I think it should be something like this: setvar.ps1: function SETVAR {c:\python26\python.exe varconfig.py } varconfig.py: import sys print >> sys.stdout, '$env:myVar=foo'

    Read the article

  • How to build and deploy Python web applications

    - by sverrejoh
    I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers? Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go for a more Python based solution. I've been looking a bit into zc.buildout, but it's not clear for me what I can/should use it for.

    Read the article

  • What are Class methods in Python for?

    - by Dave Webb
    I'm teaching myself Python and my most recent lesson was that Python is not Java, and so I've just spent a while turning all my Class methods into functions. I now realise that I don't need to use Class methods for what I would done with static methods in Java, but now I'm not sure when I would use them. All the advice I can find about Python Class methods is along the lines of newbies like me should steer clear of them, and the standard documentation is at its most opaque when discussing them. Does anyone have a good example of using a Class method in Python or at least can someone tell me when Class methods can be sensibly used?

    Read the article

  • Python script run via cron does not execute occassionally

    - by gcorne
    I have a simple python script for fetching tweets and caching them to disk that is configured to run every two minutes via cron. */2 * * * * (date ; /usr/bin/python /path/get_tweets.py) >> /path/log/get_tweets.log 2>&1 The script runs successfully most of the time. However, every so often the script doesn't execute. In addition to other logging, I added a simple print statement above the meat of the script and nothing except the output from the initial date command makes it to the log. #!/usr/bin/python # Script for fetching tweets and then storing them as an HTML snippet for inclusion using SSI print "Starting get_tweets.py" Any ideas? The system is a VPS running Centos 5.3 with python 2.4.

    Read the article

  • python dictionary with constant value-type

    - by s.kap
    hi there, I bumped into a case where I need a big (=huge) python dictionary, which turned to be quite memory-consuming. However, since all of the values are of a single type (long) - as well as the keys, I figured I can use python (or numpy, doesn't really matter) array for the values ; and wrap the needed interface (in: x ; out: d[x]) with an object which actually uses these arrays for the keys and values storage. I can use a index-conversion object (input -- index, of 1..n, where n is the different-values counter), and return array[index]. I can elaborate on some techniques of how to implement such an indexing-methods with reasonable memory requirement, it works and even pretty good. However, I wonder if there is such a data-structure-object already exists (in python, or wrapped to python from C/++), in any package (I checked collections, and some Google searches). Any comment will be welcome, thanks.

    Read the article

  • Writing a Python extension in Go (golang)

    - by tehwalrus
    I currently use Cython to link C and Python, and get speedup in slow bits of python code. However, I'd like to use go routines to implement a really slow (and very parallelizable) bit of code, but it must be callable from python. (I've already seen this question) I'm (sort of) happy to go via C (or Cython) to set up data structures etc if necessary, but avoiding this extra layer would be good from a bug fix/avoidance point of view. What is the simplest way to do this without having to reinvent any wheels?

    Read the article

< Previous Page | 34 35 36 37 38 39 40 41 42 43 44 45  | Next Page >