Search Results

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

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

  • 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

  • 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

  • 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

  • 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

  • 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

  • define global in a python module from C api

    - by wiso
    Sorry for the trivial question, but I can't find this infomation from the manual. I am developping a module for python using C api; how can I create a variabile that is seen as global from python? For example if my module is module I want to create a variable g that do this job: import module print module.g in particular g is an integer. Solution from Alex Martelli PyObject *m = Py_InitModule("mymodule", mymoduleMethods); PyObject *v = PyLong_FromLong((long) 23); PyObject_SetAttrString(m, "L", v); Py_DECREF(v);

    Read the article

  • Basic Python While loop compound conditional evaluation

    - by dbjohn
    In Python IDLE Shell it seems I cannot use a compound conditional expression and a while loop. I tried it within brackets too. k=0 m=0 while k<10 & m<10: print k k +=1 m+=1 If I write while k<10: print k k+=1 This does work. Is there a way I could achieve the first block of code with the "and" operator. I have done it in Java. Do I just need to put together "if" statements to achieve the same functionality in Python?

    Read the article

  • Get Python 2.7's 'json' to not throw an exception when it encounters random byte strings

    - by Chris Dutrow
    Trying to encode a a dict object into json using Python 2.7's json (ie: import json). The object has some byte strings in it that are "pickled" data using cPickle, so for json's purposes, they are basically random byte strings. I was using django.utils's simplejson and this worked fine. But I recently switched to Python 2.7 on google app engine and they don't seem to have simplejson available anymore. Now that I am using json, it throws an exception when it encounters bytes that aren't part of UTF-8. The error that I'm getting is: UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte It would be nice if it printed out a string of the character codes like the debugging might do, ie: \u0002]q\u0000U\u001201. But I really don't much care how it handles this data just as long as it doesn't throw an exception and continues serializing the information that it does recognize. How can I make this happen? Thanks!

    Read the article

  • Tabulated log file format with the python logging system

    - by yorjo
    Hi everybody, I'm using the python logging module with the "native" configuration file support (config.fileconfig) as describe in the documentation here : http://docs.python.org/library/logging.html (see the logging.conf file) I was wondering if it's possible to supply a tabulated data format in the configuration file? The sample configuration file is the following: [formatter_simpleFormatter] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s I though that using the \t in the format would be enough but it doesn't. format=%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s\t If I do so it print \t in the result. I tried a couple of thing without success. I suppose it's really easy to do but I don't find it! How can I do that?

    Read the article

  • Running python/ruby script on iPhone?

    - by prosseek
    From the recent news from the Apple, I learned that one has to use C/C++/Objective-C for iPhone App. Accordingly, it's not possible to use MacPython or similar to make iPhone App. But as the python/ruby interpreter itself is written in C, isn't it OK to make python/ruby interpreter for iPhone to run the scripts on iphone? Is this possible? Does Apple support this? Or does someone implemented this? Or, the user should hack to do this?

    Read the article

  • Python: Control timeout length

    - by skylarking
    I have code similar to the following running in a script: try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 seconds on average before sys.exit() appears to be called... I know the 75 seconds is probably very subjective, and dependent on the system this runs on...but is there a way to have python just try this once, and if unsucessful, to exit immediately? The platform I am using for this is Mac OS X 10.5/python 2.5.1.

    Read the article

  • Python text file processing speed issues

    - by Anonymouslemming
    Hi all, I'm having a problem with processing a largeish file in Python. All I'm doing is f = gzip.open(pathToLog, 'r') for line in f: counter = counter + 1 if (counter % 1000000 == 0): print counter f.close This takes around 10m25s just to open the file, read the lines and increment this counter. In perl, dealing with the same file and doing quite a bit more (some regular expression stuff), the whole process takes around 1m17s. Perl Code: open(LOG, "/bin/zcat $logfile |") or die "Cannot read $logfile: $!\n"; while (<LOG>) { if (m/.*\[svc-\w+\].*login result: Successful\.$/) { $_ =~ s/some regex here/$1,$2,$3,$4/; push @an_array, $_ } } close LOG; Can anyone advise what I can do to make the Python solution run at a similar speed to the Perl solution? I've tried just uncompressing the file and dealing with it using open instead of gzip.open, but that made a very small difference to the overall time.

    Read the article

  • Installing Djnajo/Python on IIS6

    - by Sohrab Hejazi
    We are currently installing the latest version of Django and Python on IIS6. We have followed the instructions on the following site: http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer We are receiving a 403 error when trying to access our Django application via the IIS server. We have verified the python installation on IIS6 and it is working property. We have also verified the Django installation. Our application runs fine under the built-in Django server, but we are having difficulties getting it to run under IIS. We presume we could be getting errors from "Linking Django to PyISAPIe" section of the instructions provided on the link above. Thank.

    Read the article

  • Hashing a python function to regenerate output when the function is modified

    - by Seth Johnson
    I have a python function that has a deterministic result. It takes a long time to run and generates a large output: def time_consuming_function(): # lots_of_computing_time to come up with the_result return the_result I modify time_consuming_function from time to time, but I would like to avoid having it run again while it's unchanged. [time_consuming_function only depends on functions that are immutable for the purposes considered here; i.e. it might have functions from Python libraries but not from other pieces of my code that I'd change.] The solution that suggests itself to me is to cache the output and also cache some "hash" of the function. If the hash changes, the function will have been modified, and we have to re-generate the output. Is this possible or ridiculous? Updated: based on the answers, it looks like what I want to do is to "memoize" time_consuming_function, except instead of (or in addition to) arguments passed into an invariant function, I want to account for a function that itself will change.

    Read the article

  • Issue using Python to solve the Coin problem [closed]

    - by challarao
    I'm attempting to solve a problem commonly known as the Coin problem, but using McNuggets. McNuggets come in boxes containing either 6, 9, or 20 nuggets. I want to write a python script that uses Diophantine equations to determine if a given number of McNuggets n can be exactly purchased in these groupings. For example: 26 McNuggets -- Possible: 1 6-pack, 0 9-packs, 1 20-pack 27 McNuggets -- Possible: 0 6-packs, 3 9-packs, 0 20-packs 28 McNuggets -- Not possible This is my current attempt at writing the solution in Python, but the output is incorrect and I'm not sure what's wrong. n=input("Enter the no.of McNuggets:") a,b,c=0,0,0 count=0 for a in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for b in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for c in range(n): if 6*a+9*b+20*c==n: count=count+1 break if count>0: print "It is possible to buy exactly",n,"packs of McNuggetss",a,b,c else: print "It is not possible to buy"

    Read the article

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