Search Results

Search found 14486 results on 580 pages for 'python idle'.

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

  • Reliably converting C preprocessor macros to python code

    - by manual-manuel
    Hi, I have a bunch of C macros the operation of which I need to simulate in python. I saw some pointers to pygccxml or ctypeslib etc. Are these the ways to go ? Or is there something out there that is better ? The C macros if and when they change, I would like the python implementation to be auto generated rather than having to make manual modifications. Hence the question. <my_c_header.h> /* #defines type 1 */ #ifdef OS #define NUM_FLAGS (uint16_t)(3) #define NUM_BITS (uint16_t)(8) #else #define NUM_FLAGS (uint16_t)(6) #define NUM_BITS (uint16_t)(16) #endif #define MAKE_SUB_FLAGS (uint16_t)((1<<NUMFLAGS) -1) #define MAKE_TOTAL_FLAGS(x) (uint16_t)((x & MAKE_SUB_FLAGS) >> NUM_BITS) /* #defines type 2 */ #ifdef OS #DO_SOMETHING(X) os_specifc_process(x) #else #DO_SOMETHING(x) #endif /* #defines type 3 */ enum { CASE0, CASE1, CASE2 } #define MY_CASE_0 ((uint16_t)CASE0) #define MY_CASE_1 ((uint16_t)CASE1) #define MY_CASE_2 ((uint16_t)CASE2) #define /*End of file <my_c_header.h> */ Thanks M

    Read the article

  • python dictionary conversion from string?

    - by shahjapan
    if I've string like "{ partner_name = test_partner}" OR " { partner_name : test_partner } its an example string will be very complex with several special characters included like =, [ , ] , { , } what will be the best way to convert it into a python object - so I can process it I tried with eval but it requires " ' " for string, but how can we add this special character \' before starting and ending of every word, I tried regular express re.findal('\w+') but it fails when my string contains ' _ ' or like characters as it will separate the string by ' _ ' Object of this question is my application needs, user friendly language as input - and I thought Json Dict will be good - but user is lazzy to put " ' " before and after of each string... then I thought for yaml but its also complex, if anybody can suggest better user friendly input which I use as python object - then please help me out.

    Read the article

  • Fastest Way to generate 1,000,000+ random numbers in python

    - by Sandro
    I am currently writing an app in python that needs to generate large amount of random numbers, FAST. Currently I have a scheme going that uses numpy to generate all of the numbers in a giant batch (about ~500,000 at a time). While this seems to be faster than python's implementation. I still need it to go faster. Any ideas? I'm open to writing it in C and embedding it in the program or doing w/e it takes. Constraints on the random numbers: A Set of numbers 7 numbers that can all have different bounds: eg: [0-X1, 0-X2, 0-X3, 0-X4, 0-X5, 0-X6, 0-X7] Currently I am generating a list of 7 numbers with random values from [0-1) then multiplying by [X1..X7] A Set of 13 numbers that all add up to 1 Currently just generating 13 numbers then dividing by their sum Any ideas? Would pre calculating these numbers and storing them in a file make this faster? Thanks!

    Read the article

  • Simple addition calculator in python

    - by Krysten
    I built a very simple addition calculator in python: #This program will add two numbers entered in by the user print "Welcome!" num1 = input("Please enter in the first number to be added.") num2 = input("Please enter in the second number to be added.") sum = num1 + num2 print "The sum of the two numbers entered is: ", sum I haven't setup python yet, so I'm using codepad.org (an online compiler). I get the following error: Welcome! Please enter in the first number to be addeded.Traceback (most recent call last): Line 5, in num1 = input("Please enter in the first number to be addeded.") EOFError

    Read the article

  • Replace URL with a link using regex in python

    - by user122750
    how do I convert some text to a link? Back in PHP, I used this piece of code that worked well for my purpose: $text = preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\3</a>", $text); $text = preg_replace("#(^|[\n ])(((www|ftp)\.[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\3</a>", $text); I tried around in Python, but was unable to get it to work.. Would be very nice if someone could translate this to Python :)..

    Read the article

  • Binomial test in Python for very large numbers

    - by Morlock
    I need to do a binomial test in Python that allows calculation for 'n' numbers of the order of 10000. I have implemented a quick binomial_test function using scipy.misc.comb, however, it is pretty much limited around n = 1000, I guess because it reaches the biggest representable number while computing factorials or the combinatorial itself. Here is my function: from scipy.misc import comb def binomial_test(n, k): """Calculate binomial probability """ p = comb(n, k) * 0.5**k * 0.5**(n-k) return p How could I use a native python (or numpy, scipy...) function in order to calculate that binomial probability? If possible, I need scipy 0.7.2 compatible code. Many thanks!

    Read the article

  • Python: Data Object or class

    - by arg20
    I enjoy all the python libraries for scraping websites and I am experimenting with BeautifulSoup and IMDB just for fun. As I come from Java, I have some Java-practices incorporated into my programming styles. I am trying to get the info of a certain movie, I can either create a Movie class or just use a dictionary with keys for the attributes. My question is, should I just use dictionaries when a class will only contain data and perhaps almost no behaviour? In other languages creating a type will help you enforce certain restrictions and because of type checks the IDE will help you program, this is not always the case in python, so what should I do? Should I resort to creating a class only when there's both, behaviour and data? Or create a movie class even though it'll probably be just a data container? This all depends on your model, in this particular case either one is fine but I'm wondering about what's a good practice.

    Read the article

  • python processs complete list files matched

    - by thomytheyon
    Hi All, I'm trying to get a simple code working, unfortunatly im a python beginner. My script should return a list of files that doesn't match a pattern, more information here : http://stackoverflow.com/questions/2910106/python-grep-reverse-matching/2910288#2910288 My code is running but doesn't process the complete list of files found as it should : import sys,os filefilter = ['.xml','java','.jsp','lass'] path= "/home/patate/code/project" s = "helloworld" for path, subdirs, files in os.walk(path): for name in files: if name[-4:] in filefilter : f = str(os.path.join(path, name)) with open(f) as fp: if s in fp.read(): print "%s has the string" % f else: print "%s doesn't have the string" % f This code return : /home/patate/code/project/blabla/blabla/build.xml doesn't have the string None If i change f = str(os.path.join(path, name)) for print str(os.path.join(path, name)) I can see the whole list being printed. How can i process the whole list as i which to ? :( Thanks again.

    Read the article

  • Check if a MediaWiki page exists (Python)

    - by compie
    I'm working on a Python script that transforms this: foo bar Into this: [[Component foo]] [[bar]] The script checks (per input line) if the page "Component foo" exists. If it exists then a link to that page is created, if it doesn't exist then a direct link is created. The problem is that I need a quick & cheap way to check if a lot of wiki pages exist.I don't want to (try to) download all the 'Component' pages. I already figured out a fast way to do this by hand: Edit a new wiki page. paste all the 'component' links into the page, press preview, and then save the resulting preview HTML page. The resulting HTML file contains a different link for existing pages than for non-existing pages. So to rephrase my question: How can I save a mediawiki preview page in Python?

    Read the article

  • Creating an interface and swappable implementations in python

    - by Blankman
    Hi, Would it be possible to create a class interface in python and various implementations of the interface. Example: I want to create a class for pop3 access (and all methods etc.). If I go with a commercial component, I want to wrap it to adhere to a contract. In the future, if I want to use another component or code my own, I want to be able to swap things out and not have things very tightly coupled. Possible? I'm new to python.

    Read the article

  • MySQLdb rowcount Returns Nothing

    - by Alec K.
    I am trying to log into my table called acounts using MySQLdb in Python, but it does not work for me. I keep getting my message "Not Logged In". Here is my code: database = MySQLdb.connect("127.0.0.1", "root", "pswd", "Kazzah") cursor = database.cursor() cursor.execute("SELECT * FROM Accounts WHERE Email=%s AND Password=%s", (_Email, _Password)) database.commit() numrows = cursor.rowcount if numrows == 1: msg = "Logged In" else: msg = "Not Logged In" cursor.close() database.close() What am I doing wrong? Thanks.

    Read the article

  • Hidden line removal in JavaScript or Python?

    - by feklee
    I have the following task: Input: A 3D scene comprised of a set of cuboids. Could be broken down to a set of triangles. A description of a camera: position, direction, focal length. Output: 2D wire frame projection of the scene as a set of lines. Important: Hidden lines removal should have been applied. Platform: Web app running on Google App Engine for Python. Any idea if there is a JavaScript or Python library that does this?

    Read the article

  • Copy and pasting code into the Python interpreter

    - by wpeters
    There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a file. This is just an small example but if there is a lot of code I would like to avoid typing everything from the definition of the function or copy and pasting line by line. class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' def disable(self): self.HEADER = '' # I think stuff gets mangled because of the extra level of indentation self.OKBLUE = '' self.OKGREEN = '' self.WARNING = '' self.FAIL = '' self.ENDC = ''

    Read the article

  • After C++ - Python or Java?

    - by carleeto
    I'm fast approaching the point in my coding where I would like to quickly write object oriented code in languages other than C++ for a variety of reasons. After a lot of research, my choices have pretty much narrowed down to Python and Java. I'm leaning towards Python because of its relationship to C, but with Java, from what I can see, I get a good introduction to using and creating test suites with Eclipse - there is also Processing which is pulling me towards Java. I'm not the kind of guy to tackle two languages at once, so which one would you recommend and why? What I want at the end is to have an additional language I can use for rapid development. Ease of learning isn't important to me as I'm willing to put in the time regardless. Ability to use the new language widely is.

    Read the article

  • Forced naming of parameters in python

    - by Mark Mayo
    In python you may have a function definition: def info(object, spacing=10, collapse=1) which could be called in any of the following ways: info(odbchelper) info(odbchelper, 12) info(odbchelper, collapse=0) info(spacing=15, object=odbchelper) thanks to python's allowing of any-order arguments, so long as they're named. The problem we're having is as some of our larger functions grow, people might be adding parameters between spacing and collapse, meaning that the wrong values may be going to parameters that aren't named. In addition sometimes it's not always clear as to what needs to go in. We're after a way to force people to name certain parameters - not just a coding standard, but ideally a flag or pydev plugin? so that in the above 4 examples, only the last would pass the check as all the parameters are named. Odds are we'll only turn it on for certain functions, but any suggestions as to how to implement this - or if it's even possible would be appreciated.

    Read the article

  • Python: Time a code segment for testing performance (with timeit)

    - by Mestika
    Hi, I've a python script which works just as it should but I need to write the time for the execution. I've gooled that I should use timeit but I can't seem to get it to work. My Python script looks like this: import sys import getopt import timeit import random import os import re import ibm_db import time from string import maketrans myfile = open("results_update.txt", "a") for r in range(100): rannumber = random.randint(0, 100) update = "update TABLE set val = %i where MyCount >= '2010' and MyCount < '2012' and number = '250'" % rannumber #print rannumber conn = ibm_db.pconnect("dsn=myDB","usrname","secretPWD") for r in range(5): print "Run %s\n" % r ibm_db.execute(query_stmt) query_stmt = ibm_db.prepare(conn, update) myfile.close() ibm_db.close(conn) What I need it the time it takes the execution of the query and written to the file "results_update.txt". The purpose is to test an update statement for my database with different indexes and tuning mechanisms. Sincerely Mestika

    Read the article

  • Controlling a browser from Python

    - by Noio
    I am looking for a way to control a browser from Python, i.e. fill out form fields and submit them, possibly call JS functions. I've looked around a bit, but as far as I could see PyWebKitGtk only lets you show the browser as a GUI element, not interface with it. Is there a way to do this easily? I wrote my program logic in Python, and I would hate to port it to JS. Besides that, even if I'd use pure JS "bookmarklets", those wouldn't be able to read/write to my local filesystem, would they? P.S. to quell your suspicions, I'm not trying to automatically fill out forum account creation forms or something similarly spammious, though the task is technically similar. I need to crawl/scrape sites for my research project.

    Read the article

  • Execute python code inside browser without Jython

    - by proportional
    Is there a way to execute python code in a browser, other than using Jython and an applet? The execution does not have to deal with anything related to graphics. For example, just sum all the digits of a binary 1Gb file (chosen by the browser user) and then return the result to the server. I am aware that python can be executed remotely outside a browser, but my requirement is to be done inside a browser. For sure, I take for granted the user will keep the right to execute or not, and will be asked to do so, and all this security stuff... but that is not my question.

    Read the article

  • Porting library from Java to Python

    - by Mike Griffith
    I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world. I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results. Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch? If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another.

    Read the article

  • Optimization Techniques in Python

    - by fear-matrix
    Recently i have developed a billing application for my company with Python/Django. For few months everything was fine but now i am observing that the performance is dropping because of more and more users using that applications. Now the problem is that the application is now very critical for the finance team. Now the finance team are after my life for sorting out the performance issue. I have no other option but to find a way to increase the performance of the billing application. So do you guys know any performance optimization techniques in python that will really help me with the scalability issue

    Read the article

  • Directory layout for a Python project with C extension modules

    - by Kamil Kisiel
    We have numerous projects in our organization that are mixed Python/C. Currently we're trying to standardize on a directory layout for our projects and are trying to come up with a convenient scheme. One point of contention is where to put C extension modules in the tree. We're tossing around a couple of options (relative to project root): ./src/package/subpackage/module.c or alongside the python modules in the package tree: ./package/subpackage/module.c or in a src directory in the subpackage: ./package/subpackage/src/module.c One reason for keeping them out of the package directories could be because it will lead to clutter, especially if there are other .c and .h files which aren't themselves modules but still need to be compiled. Also in the "integrated" scheme, what do you do with headers and files that are used by more than one module? Put them in a common top-level directory? I'd be interested to know what other people are using, or if there are any established best practices for this.

    Read the article

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