Search Results

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

Page 72/548 | < Previous Page | 68 69 70 71 72 73 74 75 76 77 78 79  | Next Page >

  • Controlling processes from Python

    - by Nathan
    Hi, I want to control several subprocesses of the same type from python (I am under linux). I want to: Start them. Stop them. Ask if they are still running. I can start a processes with with spawnl, and get the pid. Using this pid I can stop it with kill. And I am sure there is also a way to ask if it is running with the pid. The problem is, what if the following happens: I start a process, remember the pid. The process ends without me noticing and another completely different process starts getting assigned the same pid. I attempt to kill my process, I kill a completely different one. What is the better way to start and control processes in python? Thanks!

    Read the article

  • Capturing Mac OS X System Audio output with Python

    - by richbs
    Hello, I've been trying to "hijack" the Mac OS X system audio using PyAudio and save to a wav in python. That is, I do not want to record from an input device such as a microphone. I want to grab the sound output from any or all applications. I have followed the tutorials on the PyAudio site but these do not appear to cover my use case and when I try to read from the output stream I unsurprisingly get the paCanNotReadFromAnOutputOnlyStream exception. Fair enough! Is there a way to do what I am proposing with the PyAudio or other FOSS Python Library?

    Read the article

  • Django Template - Convert python list into a javascript object

    - by amcashcow
    I am working on a django / python website I have a page where I want to display a table of search results The list of results is passed in to the template as normal I also want to make this list of objects accessible to the javascript code My first solution was just create another view that returned json format. But each page load required calling the query twice. So then I tried only downloading the data using the json view and printing the table using javascript. but this is also not desirable as now the presentation layer is mixed into the javascript code. is there a way to create a javascript object from the python list as the page is rendered?

    Read the article

  • Python Class Variables Question

    - by zyq524
    I have some doubt about python's class variables. As my understanding, if I define a class variable, which is declared outside the init() function, this variable will create only once as a static variable in C++. This seems right for some python types, for instance, dict and list type, but for those base type, e.g. int,float, is not the same. For example: class A: dict1={} list1=list() int1=3 def add_stuff(self, k, v): self.dict1[k]=v self.list1.append(k) self.int1=k def print_stuff(self): print self.dict1,self.list1,self.int1 a1 = A() a1.add_stuff(1, 2) a1.print_stuff() a2=A() a2.print_stuff() The output is: {1: 2} [1] 1 {1: 2} [1] 3 I understand the results of dict1 and list1, but why does int1 behavior different?

    Read the article

  • Python configuration file generator

    - by Stan
    I want to use Python to make a configuration file generator. My roughly idea is feeding input with template files and some XML files with the real settings. Then use the program to generate the real configuration files. I got several questions: Is there any open source configuration generator program? (what could be the keyword), I wonder if there's anything can be added/modified in the design. Does Python have good XML parser module? Is it good idea to use XML file to save the original settings? I've been thinking to use Excel since it's more intuitive to maintain, but harder for program to parse. Not sure how people deal with this. Hope the community can give me some suggestions. Thanks a lot!

    Read the article

  • Strange python error

    - by Werner
    Hi, I am trying to write a python program that calculates a histogram, given a list of numbers like: 1 3 2 3 4 5 3.2 4 2 2 so the input parameters are the filename and the number of intervals. The program code is: #!/usr/bin/env python import os, sys, re, string, array, math import numpy Lista = [] db = sys.argv[1] db_file = open(db,"r") ic=0 nintervals= int(sys.argv[2]) while 1: line = db_file.readline() if not line: break ll=string.split(line) #print ll[6] Lista.insert(ic,float(ll[0])) ic=ic+1 lmin=min(Lista) print "min= ",lmin lmax=max(Lista) print "max= ",lmax width=666.666 width=(lmax-lmin)/nintervals print "width= ",width nelements=len(Lista) print "nelements= ",nelements print " " Histogram = numpy.zeros(shape=(nintervals)) for item in Lista: #print item int_number = 1 + int((item-lmin)/width) print " " print "item,lmin= ",item,lmin print "(item-lmin)/width= ",(item-lmin)," / ",width," ====== ",(float(item)-float(lmin))/float(width) print "int((item-lmin)/width)= ",int((item-lmin)/width) print item , " belongs to interval ", int_number, " which is from ", lmin+width*(int_number-1), " to ",lmin+width*int_number Histogram[int_number] = Histogram[int_number] + 1 4 but somehow I am completely lost, I get strange errors, can anybody help¿ Thanks

    Read the article

  • python's `with` statement

    - by Prestel Nué
    Hi there, seems like I do not understand something with---the python with statement. Consider this class: class test(object): def __enter__(self): pass def __exit__(self, *ignored): pass now, when using it with with, like in with test() as michael: print repr(michael) I would expect some output like <test instance at memore blah>. But I get None. Something wrong here? Any suggestions would help. (I am using Python 2.6.6.) EDIT: Thanks to ephement for pointing me to the documentation. The __enter__ method should read def __enter__(self): return self

    Read the article

  • categorizing items in a list with python

    - by jtc99
    Just as a heads up, I'm really new to python. Currently I have a list of 110,000 donors in Excel. One of the pieces of information they give to us is their occupation. I would like to condense this list down to say 10 or 20 categories that I define. Normally I would just chug through this, going line by line, but since I have to do this for a years worth of data, I don't really have the time to do a line by line of 1,000,000+ rows. Is there anyway to define my 10 or 20 categories and then have python sort it out from there?

    Read the article

  • Python - read numbers from text file and put into list

    - by user1647372
    So like the title says im starting to learn some python and im having trouble picking up on this technique. What I need to accomplish is to read in some numbers and store them in a list. The text file looks like the following: 0 0 3 50 50 100 4 20 Basically these are coordinates and directions to be used for python's turtle to make shapes. I got that part down the only problem is getting them in a correct format. So what I can not figure out is how to get those numbers from the file into [ [0, 0, 3, 50], [50, 100, 4, 20] ] A list, with each four coordinates being a list in that one big list. Heres my attempt but it as I said I need some help - thank you. polyShape=[] infile = open(name,"r") num = int(infile.readline(2)) while num != "": polyShape.append(num) num = int(infile.readline(2)) infile.close()

    Read the article

  • finding elements in python association lists efficiently

    - by user248237
    I have a set of lists that look like this: conditions = [ ["condition1", ["sample1", "sample2", "sample3"]], ["condition2", ["sample4", "sample5", "sample6"], ...] how can I do the following things efficiently and elegantly in Python? Find all the elements in a certain condition? e.g. get all the samples in condition2. Right now I can do: for cond in conditions: cond_name, samples = cond if cond_name == requested_cond: return samples but that's clunky. Find the ordered union of a list of conditions? E.g. ordered_union(["condition1", "condition2"], conditions) should return: ["sample1", "sample2", "sample3", "sample4", "sample5", "sample6"] How can I do this efficiently in Python? There are probably clever one liners?

    Read the article

  • Python "string_escape" vs "unicode_escape"

    - by Mike Boers
    According to the docs, the builtin string encoding string_escape: Produce[s] a string that is suitable as string literal in Python source code ...while the unicode_escape: Produce[s] a string that is suitable as Unicode literal in Python source code So, they should have roughly the same behaviour. BUT, they appear to treat single quotes differently: >>> print """before '" \0 after""".encode('string-escape') before \'" \x00 after >>> print """before '" \0 after""".encode('unicode-escape') before '" \x00 after The string_escape escapes the single quote while the Unicode one does not. Is it safe to assume that I can simply: >>> escaped = my_string.encode('unicode-escape').replace("'", "\\'") ...and get the expected behaviour?

    Read the article

  • Python read files in directory and concatenate

    - by JJ Beck
    I want to write a Python script that searches all folders in the current directory, looks for all .txt files, and creates a file that is a concatenation of all those files (in any order) in the current directory. If folders have subfolders, it should not search those subfolders. An example is main_folder folder_1 sub_folder file1.txt file2.txt folder_2 file3.txt The script is placed inside main_folder. It should create a file that is a concatenation of file2.txt and file3.txt (in any order) inside main_folder. My question is: How can I tell Python to traverse through the folders, look for .txt files, without going into the subfolders?

    Read the article

  • Reboot windows machines at a certain time of day and automatically login with Python

    - by Tom
    I know how to reboot machines remotely, so that's the easy part. However, the complexity of the issue is trying to setup the following. I'd like to control machines on a network for after-hours use such that when users logoff and go home, or shutdown their computers, whatever, python or some combination of python + windows could restart their machines (for cleanliness) and automatically login, running a process for the night, then in the morning, stop said process and restart the machine so the user could easily login like normal. I've looked around, haven't had too terribly much luck, though it looks like one could do it with a changing of the registry. That sounds like a rough idea though, modifying the registry on a per-day basis. Is there an easier way?

    Read the article

  • Python: Matching & Stripping port number from socket data

    - by tobywuk
    Hello, I have data coming in to a python server via a socket. Within this data is the string '<port>80</port>' or which ever port is being used. I wish to extract the port number into a variable. The data coming in is not XML, I just used the tag approach to identifying data for future XML use if needed. I do not wish to use an XML python library, but simply use something like regexp and strings. What would you recommend is the best way to match and strip this data? I am currently using this code with no luck: p = re.compile('<port>\w</port>') m = p.search(data) print m Thank you :)

    Read the article

< Previous Page | 68 69 70 71 72 73 74 75 76 77 78 79  | Next Page >